Subversion Repositories Kolibri OS

Rev

Rev 5256 | Rev 6101 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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