Subversion Repositories Kolibri OS

Rev

Rev 5256 | Rev 6101 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5256 IgorA 1
 
2
proc calc_buf uses ebx ecx, buf:dword, shininess:dword
3
locals
4
	val dd ? ;float
5
	f_inc dd ? ;float
6
endl
7
	mov dword[val],0.0f
8
	mov dword[f_inc],SPECULAR_BUFFER_SIZE
9
	fld1
10
	fidiv dword[f_inc]
11
	fstp dword[f_inc] ;f_inc = 1.0f/SPECULAR_BUFFER_SIZE
12
	mov ebx,[buf]
5262 IgorA 13
	add ebx,offs_spec_buf
14
	xor ecx,ecx
5256 IgorA 15
align 4
16
	.cycle_0: ;for (i = 0; i <= SPECULAR_BUFFER_SIZE; i++)
17
	cmp ecx,SPECULAR_BUFFER_SIZE
18
	jg @f
19
		;Вычисляем x^y
20
		fld dword[shininess]
21
		fld dword[val]
22
		fyl2x ;Стек FPU теперь содержит: st0=z=y*log2(x):
23
		;Теперь считаем 2**z:
24
		fld st0 ;Создаем еще одну копию z
25
		frndint ;Округляем
26
		fsubr st0,st1  ;st1=z, st0=z-trunc(z)
27
		f2xm1  ;st1=z, st0=2**(z-trunc(z))-1
28
		fld1
29
		faddp  ;st1=z, st0=2**(z-trunc(z))
30
		fscale ;st1=z, st0=(2**trunc(z))*(2**(z-trunc(z)))=2**t
31
		fxch st1
32
		fstp st ;Результат остается на вершине стека st0
33
34
 
35
		add ebx,4
5262 IgorA 36
5256 IgorA 37
 
38
		fadd dword[f_inc]
39
		fstp dword[val] ;val += f_inc
40
	inc ecx
41
	jmp .cycle_0
42
	@@:
43
	ret
44
endp
45
46
 
47
proc specbuf_get_buffer uses ebx ecx edx, context:dword, shininess_i:dword, shininess:dword
48
locals
49
	found dd ? ;GLSpecBuf *
50
	oldest dd ? ;GLSpecBuf *
51
endl
52
	mov edx,[context]
53
	mov eax,[edx+offs_cont_specbuf_first]
54
	mov [found],eax
55
	mov [oldest],eax
56
	mov ebx,[shininess_i]
57
	.cycle_0:
58
	or eax,eax ;while (found)
59
	jz @f
60
	cmp [eax+offs_spec_shininess_i],ebx ;while (found.shininess_i != shininess_i)
61
	je @f
62
		mov ecx,[oldest]
63
		mov ecx,[ecx+offs_spec_last_used]
64
		cmp [eax+offs_spec_last_used],ecx ;if (found.last_used < oldest.last_used)
65
		jge .end_0
66
			mov [oldest],eax ;oldest = found
67
		.end_0:
68
		mov eax,[eax+offs_spec_next] ;found = found.next
69
		jmp .cycle_0
70
	@@:
71
	cmp dword[found],0 ;if (found) /* hey, found one! */
72
	je @f
73
		mov eax,[found]
74
		mov ecx,[edx+offs_cont_specbuf_used_counter]
75
		mov [eax+offs_spec_last_used],ecx ;found.last_used = context.specbuf_used_counter
76
		inc dword[edx+offs_cont_specbuf_used_counter]
77
		jmp .end_f ;return found
78
	@@:
79
	cmp dword[oldest],0 ;if (oldest == NULL || context.specbuf_num_buffers < MAX_SPECULAR_BUFFERS)
80
	je @f
81
	cmp dword[edx+offs_cont_specbuf_num_buffers],MAX_SPECULAR_BUFFERS
82
	jl @f
83
		jmp .end_1
84
	@@:
85
		; create new buffer
86
	stdcall gl_malloc, sizeof.GLSpecBuf
87
;if (!eax) gl_fatal_error("could not allocate specular buffer")
88
	inc dword[edx+offs_cont_specbuf_num_buffers]
89
	mov ecx,[edx+offs_cont_specbuf_first]
90
	mov [eax+offs_spec_next],ecx
91
	mov [edx+offs_cont_specbuf_first],eax
92
	mov ecx,[edx+offs_cont_specbuf_used_counter]
93
	mov [eax+offs_spec_last_used],ecx
94
	inc dword[edx+offs_cont_specbuf_used_counter]
95
	mov [eax+offs_spec_shininess_i],ebx
96
	stdcall calc_buf, eax,dword[shininess]
97
	jmp .end_f
98
	.end_1:
99
	; overwrite the lru buffer
100
	;tgl_trace("overwriting spec buffer :(\n");
101
	mov eax,[oldest]
102
	mov [eax+offs_spec_shininess_i],ebx
103
	mov ecx,[edx+offs_cont_specbuf_used_counter]
104
	mov [eax+offs_spec_last_used],ecx
105
	inc dword[edx+offs_cont_specbuf_used_counter]
106
	stdcall calc_buf, eax,dword[shininess]
107
	.end_f:
108
	ret
109
endp
110