Subversion Repositories Kolibri OS

Rev

Rev 6101 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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