Subversion Repositories Kolibri OS

Rev

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

Rev 5269 Rev 5278
1
align 4
1
align 4
2
sp128f dd 128.0
2
sp128f dd 128.0
3
 
3
 
4
align 4
4
align 4
5
proc glopMaterial uses eax ebx ecx edi esi, context:dword, p:dword
5
proc glopMaterial uses eax ebx ecx edi esi, context:dword, p:dword
6
; edi -> GLMaterial *m
6
; edi -> GLMaterial *m
7
	mov eax,[context]
7
	mov eax,[context]
8
	mov ebx,[p]
8
	mov ebx,[p]
9
	mov ecx,[ebx+4] ;ecx = p[1]
9
	mov ecx,[ebx+4] ;ecx = p[1]
10
 
10
 
11
	cmp ecx,GL_FRONT_AND_BACK ;if (mode == GL_FRONT_AND_BACK)
11
	cmp ecx,GL_FRONT_AND_BACK ;if (mode == GL_FRONT_AND_BACK)
12
	jne @f
12
	jne @f
13
		mov dword[ebx+4],GL_FRONT ;p[1].i=GL_FRONT
13
		mov dword[ebx+4],GL_FRONT ;p[1].i=GL_FRONT
14
		mov edi,ebp
14
		mov edi,ebp
15
		add edi,12
15
		add edi,12
16
		stdcall glopMaterial,eax,edi
16
		stdcall glopMaterial,eax,edi
17
		mov ecx,GL_BACK
17
		mov ecx,GL_BACK
18
	@@:
18
	@@:
19
	mov edi,eax
19
	mov edi,eax
20
	add edi,offs_cont_materials
20
	add edi,offs_cont_materials
21
	cmp ecx,GL_FRONT ;if (mode == GL_FRONT) m=&context.materials[0]
21
	cmp ecx,GL_FRONT ;if (mode == GL_FRONT) m=&context.materials[0]
22
	je @f
22
	je @f
23
		add edi,sizeof.GLMaterial ;else m=&context.materials[1]
23
		add edi,sizeof.GLMaterial ;else m=&context.materials[1]
24
	@@:
24
	@@:
25
 
25
 
26
	mov ecx,4
26
	mov ecx,4
27
	mov esi,ebx ;esi = &p
27
	mov esi,ebx ;esi = &p
28
	add esi,12 ;esi = &p[3]
28
	add esi,12 ;esi = &p[3]
29
	mov ebx,[ebx+8] ;ebx = p[2]
29
	mov ebx,[ebx+8] ;ebx = p[2]
30
	cmp ebx,GL_EMISSION
30
	cmp ebx,GL_EMISSION
31
	jne @f
31
	jne @f
32
		;add edi,offs_mate_emission ;offs_mate_emission=0
32
		;add edi,offs_mate_emission ;offs_mate_emission=0
33
		rep movsd
33
		rep movsd
34
		jmp .end_f
34
		jmp .end_f
35
	@@:
35
	@@:
36
	cmp ebx,GL_AMBIENT
36
	cmp ebx,GL_AMBIENT
37
	jne @f
37
	jne @f
38
		add edi,offs_mate_ambient
38
		add edi,offs_mate_ambient
39
		rep movsd
39
		rep movsd
40
		jmp .end_f
40
		jmp .end_f
41
	@@:
41
	@@:
42
	cmp ebx,GL_DIFFUSE
42
	cmp ebx,GL_DIFFUSE
43
	jne @f
43
	jne @f
44
		add edi,offs_mate_diffuse
44
		add edi,offs_mate_diffuse
45
		rep movsd
45
		rep movsd
46
		jmp .end_f
46
		jmp .end_f
47
	@@:
47
	@@:
48
	cmp ebx,GL_SPECULAR
48
	cmp ebx,GL_SPECULAR
49
	jne @f
49
	jne @f
50
		add edi,offs_mate_specular
50
		add edi,offs_mate_specular
51
		rep movsd
51
		rep movsd
52
		jmp .end_f
52
		jmp .end_f
53
	@@:
53
	@@:
54
	cmp ebx,GL_SHININESS
54
	cmp ebx,GL_SHININESS
55
	jne @f
55
	jne @f
56
		fld dword[esi]
56
		fld dword[esi]
57
		add edi,offs_mate_shininess
57
		add edi,offs_mate_shininess
58
		movsd
58
		movsd
59
		mov dword[edi],SPECULAR_BUFFER_RESOLUTION
59
		mov dword[edi],SPECULAR_BUFFER_RESOLUTION
60
		fdiv dword[sp128f]
60
		fdiv dword[sp128f]
61
		fimul dword[edi]
61
		fimul dword[edi]
62
		fistp dword[edi] ;m.shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION
62
		fistp dword[edi] ;m.shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION
63
		jmp .end_f
63
		jmp .end_f
64
	@@:
64
	@@:
65
	cmp ebx,GL_AMBIENT_AND_DIFFUSE
65
	cmp ebx,GL_AMBIENT_AND_DIFFUSE
66
	jne @f
66
	jne @f
67
		add edi,offs_mate_ambient
67
		add edi,offs_mate_ambient
68
		rep movsd
68
		rep movsd
69
		sub esi,16
69
		sub esi,16
70
		;edi = &offs_mate_diffuse
70
		;edi = &offs_mate_diffuse
71
		mov ecx,4
71
		mov ecx,4
72
		rep movsd
72
		rep movsd
73
		jmp .end_f
73
		jmp .end_f
74
	@@: ;default
74
	@@: ;default
75
;    assert(0);
75
;    assert(0);
76
	.end_f:
76
	.end_f:
77
	ret
77
	ret
78
endp
78
endp
79
 
79
 
80
align 4
80
align 4
81
proc glopColorMaterial uses eax ebx ecx, context:dword, p:dword
81
proc glopColorMaterial uses eax ebx ecx, context:dword, p:dword
82
	mov eax,[context]
82
	mov eax,[context]
83
	mov ebx,[p]
83
	mov ebx,[p]
84
	mov ecx,[ebx+4] ;ecx = p[1]
84
	mov ecx,[ebx+4] ;ecx = p[1]
85
	mov dword[eax+offs_cont_current_color_material_mode],ecx
85
	mov dword[eax+offs_cont_current_color_material_mode],ecx
86
	mov ecx,[ebx+8] ;ecx = p[2]
86
	mov ecx,[ebx+8] ;ecx = p[2]
87
	mov dword[eax+offs_cont_current_color_material_type],ecx
87
	mov dword[eax+offs_cont_current_color_material_type],ecx
88
	ret
88
	ret
89
endp
89
endp
90
 
90
 
91
align 4
91
align 4
92
proc glopLight context:dword, p:dword
92
proc glopLight context:dword, p:dword
93
locals
93
locals
94
	pos V4
94
	pos V4
95
endl
95
endl
96
pushad
96
pushad
97
	mov eax,[context]
97
	mov eax,[context]
98
	mov ebx,[p]
98
	mov ebx,[p]
99
	mov edx,[ebx+4] ;edx = p[1]
99
	mov edx,[ebx+4] ;edx = p[1]
100
 
100
 
101
;  assert(edx >= GL_LIGHT0 && edx < GL_LIGHT0+MAX_LIGHTS );
101
;  assert(edx >= GL_LIGHT0 && edx < GL_LIGHT0+MAX_LIGHTS );
102
 
102
 
103
	sub edx,GL_LIGHT0
103
	sub edx,GL_LIGHT0
104
	imul edx,sizeof.GLLight
104
	imul edx,sizeof.GLLight
105
	add edx,eax
105
	add edx,eax
106
	add edx,offs_cont_lights
106
	add edx,offs_cont_lights
107
 
107
 
108
	mov ecx,[ebx+8] ;ecx = p[2]
108
	mov ecx,[ebx+8] ;ecx = p[2]
109
	cmp ecx,GL_AMBIENT
109
	cmp ecx,GL_AMBIENT
110
	jne @f
110
	jne @f
111
		mov esi,ebx
111
		mov esi,ebx
112
		add esi,12
112
		add esi,12
113
		mov edi,edx
113
		mov edi,edx
114
		;add edi,offs_ligh_ambient ;offs_ligh_ambient = 0
114
		;add edi,offs_ligh_ambient ;offs_ligh_ambient = 0
115
		mov ecx,4
115
		mov ecx,4
116
		rep movsd ;l.ambient=v
116
		rep movsd ;l.ambient=v
117
		jmp .end_f
117
		jmp .end_f
118
	@@:
118
	@@:
119
	cmp ecx,GL_DIFFUSE
119
	cmp ecx,GL_DIFFUSE
120
	jne @f
120
	jne @f
121
		mov esi,ebx
121
		mov esi,ebx
122
		add esi,12
122
		add esi,12
123
		mov edi,edx
123
		mov edi,edx
124
		add edi,offs_ligh_diffuse
124
		add edi,offs_ligh_diffuse
125
		mov ecx,4
125
		mov ecx,4
126
		rep movsd ;l.diffuse=v
126
		rep movsd ;l.diffuse=v
127
		jmp .end_f
127
		jmp .end_f
128
	@@:
128
	@@:
129
	cmp ecx,GL_SPECULAR
129
	cmp ecx,GL_SPECULAR
130
	jne @f
130
	jne @f
131
		mov esi,ebx
131
		mov esi,ebx
132
		add esi,12
132
		add esi,12
133
		mov edi,edx
133
		mov edi,edx
134
		add edi,offs_ligh_specular
134
		add edi,offs_ligh_specular
135
		mov ecx,4
135
		mov ecx,4
136
		rep movsd ;l.specular=v
136
		rep movsd ;l.specular=v
137
		jmp .end_f
137
		jmp .end_f
138
	@@:
138
	@@:
139
	cmp ecx,GL_POSITION
139
	cmp ecx,GL_POSITION
140
	jne @f
140
	jne @f
141
		mov edi,ebx ;ebx = [ebp+12] = [p] = &p[0]
141
		mov edi,ebx ;ebx = [ebp+12] = [p] = &p[0]
142
		add edi,12 ;&p[3]
142
		add edi,12 ;&p[3]
143
		mov esi,ebp
143
		mov esi,ebp
144
		sub esi,16 ;&pos
144
		sub esi,16 ;&pos
145
		stdcall gl_M4_MulV4, esi,dword[eax+offs_cont_matrix_stack_ptr],edi
145
		stdcall gl_M4_MulV4, esi,dword[eax+offs_cont_matrix_stack_ptr],edi
146
		mov edi,edx
146
		mov edi,edx
147
		add edi,offs_ligh_position
147
		add edi,offs_ligh_position
148
		mov ecx,4
148
		mov ecx,4
149
		rep movsd ;l.position=pos
149
		rep movsd ;l.position=pos
150
 
150
 
151
		fld dword[edi-4] ;if(l.position.v[3] == 0)
151
		fld dword[edi-4] ;if(l.position.v[3] == 0)
152
		ftst
152
		ftst
153
		fstsw ax
153
		fstsw ax
154
		sahf
154
		sahf
155
		jne .end_i
155
		jne .end_i
156
			;mov esi,ebp
156
			;mov esi,ebp
157
			sub esi,16 ;&pos
157
			sub esi,16 ;&pos
158
			mov edi,edx
158
			mov edi,edx
159
			add edi,offs_ligh_norm_position
159
			add edi,offs_ligh_norm_position
160
			mov ecx,3
160
			mov ecx,3
161
			rep movsd ;l.norm_position=pos[1,2,3]
161
			rep movsd ;l.norm_position=pos[1,2,3]
162
 
162
 
163
			;mov edi,edx
163
			;mov edi,edx
164
			;add edi,offs_ligh_norm_position
164
			;add edi,offs_ligh_norm_position
165
			sub edi,12
165
			sub edi,12
166
			stdcall gl_V3_Norm,edi ;&l.norm_position
166
			stdcall gl_V3_Norm,edi ;&l.norm_position
167
		.end_i:
167
		.end_i:
168
		ffree st0
168
		ffree st0
169
		fincstp
169
		fincstp
170
		jmp .end_f
170
		jmp .end_f
171
	@@:
171
	@@:
172
	cmp ecx,GL_SPOT_DIRECTION
172
	cmp ecx,GL_SPOT_DIRECTION
173
	jne @f
173
	jne @f
174
		mov esi,ebx ;&p[0]
174
		mov esi,ebx ;&p[0]
175
		add esi,12
175
		add esi,12
176
		mov edi,edx
176
		mov edi,edx
177
		add edi,offs_ligh_spot_direction
177
		add edi,offs_ligh_spot_direction
178
		mov ecx,3
178
		mov ecx,3
179
		rep movsd ;l.spot_direction=v[0,1,2]
179
		rep movsd ;l.spot_direction=v[0,1,2]
180
		;mov esi,ebx
180
		;mov esi,ebx
181
		;add esi,12
181
		;add esi,12
182
		sub esi,12
182
		sub esi,12
183
		;mov edi,edx
183
		;mov edi,edx
184
		;add edi,offs_ligh_norm_spot_direction
184
		;add edi,offs_ligh_norm_spot_direction
185
		add edi,offs_ligh_norm_spot_direction-(offs_ligh_spot_direction+12)
185
		add edi,offs_ligh_norm_spot_direction-(offs_ligh_spot_direction+12)
186
		mov ecx,3
186
		mov ecx,3
187
		rep movsd ;l.norm_spot_direction=v[0,1,2]
187
		rep movsd ;l.norm_spot_direction=v[0,1,2]
188
		add edx,offs_ligh_norm_spot_direction
188
		add edx,offs_ligh_norm_spot_direction
189
		stdcall gl_V3_Norm,edx
189
		stdcall gl_V3_Norm,edx
190
		jmp .end_f
190
		jmp .end_f
191
	@@:
191
	@@:
192
	cmp ecx,GL_SPOT_EXPONENT
192
	cmp ecx,GL_SPOT_EXPONENT
193
	jne @f
193
	jne @f
194
		mov ecx,[ebx+12]
194
		mov ecx,[ebx+12]
195
		mov [edi+offs_ligh_spot_exponent],ecx ;l.spot_exponent=p[3]
195
		mov [edi+offs_ligh_spot_exponent],ecx ;l.spot_exponent=p[3]
196
		jmp .end_f
196
		jmp .end_f
197
	@@:
197
	@@:
198
	cmp ecx,GL_SPOT_CUTOFF
198
	cmp ecx,GL_SPOT_CUTOFF
199
	jne .end_spot_c
199
	jne .end_spot_c
200
		fld dword[ebp+12] ;float a=v.v[0]
200
		fld dword[ebp+12] ;float a=v.v[0]
201
;      assert(a == 180 || (a>=0 && a<=90));
201
;      assert(a == 180 || (a>=0 && a<=90));
202
		fst dword[edi+offs_ligh_spot_cutoff] ;l.spot_cutoff=a
202
		fst dword[edi+offs_ligh_spot_cutoff] ;l.spot_cutoff=a
203
		fcom dword[an180f] ;if (a != 180)
203
		fcom dword[an180f] ;if (a != 180)
204
		fstsw ax
204
		fstsw ax
205
		sahf
205
		sahf
206
		jne @f
206
		je @f
207
			fldpi
207
			fldpi
208
			fmulp
208
			fmulp
209
			fdiv dword[an180f]
209
			fdiv dword[an180f]
210
			fcos
210
			fcos
211
			fstp dword[edi+offs_ligh_spot_cutoff] ;l.cos_spot_cutoff=cos(a * M_PI / 180.0)
211
			fstp dword[edi+offs_ligh_spot_cutoff] ;l.cos_spot_cutoff=cos(a * M_PI / 180.0)
212
			jmp .end_f
212
			jmp .end_f
213
		@@:
213
		@@:
214
		ffree st0
214
		ffree st0
215
		fincstp
215
		fincstp
216
		jmp .end_f
216
		jmp .end_f
217
	.end_spot_c:
217
	.end_spot_c:
218
	cmp ecx,GL_CONSTANT_ATTENUATION
218
	cmp ecx,GL_CONSTANT_ATTENUATION
219
		mov ecx,[ebx+12]
219
		mov ecx,[ebx+12]
220
		mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3]
220
		mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3]
221
		jmp .end_f
221
		jmp .end_f
222
	@@:
222
	@@:
223
	cmp ecx,GL_LINEAR_ATTENUATION
223
	cmp ecx,GL_LINEAR_ATTENUATION
224
		mov ecx,[ebx+12]
224
		mov ecx,[ebx+12]
225
		mov [edi+offs_ligh_attenuation+4],ecx ;l->attenuation[1]=p[3]
225
		mov [edi+offs_ligh_attenuation+4],ecx ;l->attenuation[1]=p[3]
226
		jmp .end_f
226
		jmp .end_f
227
	@@:
227
	@@:
228
	cmp ecx,GL_QUADRATIC_ATTENUATION
228
	cmp ecx,GL_QUADRATIC_ATTENUATION
229
		mov ecx,[ebx+12]
229
		mov ecx,[ebx+12]
230
		mov [edi+offs_ligh_attenuation+8],ecx ;l->attenuation[2]=p[3]
230
		mov [edi+offs_ligh_attenuation+8],ecx ;l->attenuation[2]=p[3]
231
		jmp .end_f
231
		jmp .end_f
232
	@@: ;default:
232
	@@: ;default:
233
;    assert(0);
233
;    assert(0);
234
	.end_f:
234
	.end_f:
235
popad
235
popad
236
	ret
236
	ret
237
endp
237
endp
238
 
238
 
239
  
239
  
240
align 4
240
align 4
241
proc glopLightModel uses ebx ecx esi edi, context:dword, p:dword
241
proc glopLightModel uses ebx ecx esi edi, context:dword, p:dword
242
	mov edi,[context]
242
	mov edi,[context]
243
	mov ebx,[p]
243
	mov ebx,[p]
244
	mov ebx,[ebx+4]
244
	mov ebx,[ebx+4]
245
	mov esi,[ebp+12] ;&p[0]
245
	mov esi,[ebp+12] ;&p[0]
246
	add esi,8 ;&p[2]
246
	add esi,8 ;&p[2]
247
 
247
 
248
	cmp ebx,GL_LIGHT_MODEL_AMBIENT
248
	cmp ebx,GL_LIGHT_MODEL_AMBIENT
249
	jne @f
249
	jne @f
250
		mov ecx,4
250
		mov ecx,4
251
		add edi,offs_cont_ambient_light_model
251
		add edi,offs_cont_ambient_light_model
252
		rep movsd ;for(i=0;i<4;i++) context.ambient_light_model.v[i]=v[i]
252
		rep movsd ;for(i=0;i<4;i++) context.ambient_light_model.v[i]=v[i]
253
		jmp .end_f
253
		jmp .end_f
254
	@@:
254
	@@:
255
	cmp ebx,GL_LIGHT_MODEL_LOCAL_VIEWER
255
	cmp ebx,GL_LIGHT_MODEL_LOCAL_VIEWER
256
	jne @f
256
	jne @f
257
		fld dword[esi] ;st0 = p[2]
257
		fld dword[esi] ;st0 = p[2]
258
		fistp dword[edi+offs_cont_local_light_model]
258
		fistp dword[edi+offs_cont_local_light_model]
259
		jmp .end_f
259
		jmp .end_f
260
	@@:
260
	@@:
261
	cmp ebx,GL_LIGHT_MODEL_TWO_SIDE
261
	cmp ebx,GL_LIGHT_MODEL_TWO_SIDE
262
	jne @f
262
	jne @f
263
		fld dword[esi] ;st0 = p[2]
263
		fld dword[esi] ;st0 = p[2]
264
		fistp dword[edi+offs_cont_light_model_two_side]
264
		fistp dword[edi+offs_cont_light_model_two_side]
265
		jmp .end_f
265
		jmp .end_f
266
	@@: ;default:
266
	@@: ;default:
267
;    tgl_warning("glopLightModel: illegal pname: 0x%x\n", ebx);
267
;    tgl_warning("glopLightModel: illegal pname: 0x%x\n", ebx);
268
;    //assert(0);
268
;    //assert(0);
269
	.end_f:
269
	.end_f:
270
	ret
270
	ret
271
endp
271
endp
272
 
272
 
273
macro clampf a, min, max
273
macro clampf a, min, max
274
{
274
{
275
local .o_1
275
local .o_1
276
local .o_2
276
local .o_2
277
local .end_m
277
local .end_m
278
	fld dword a ;if (a<=0.0)
278
	fld dword a ;if (a<=0.0)
279
	ftst
279
	ftst
280
	fstsw ax
280
	fstsw ax
281
	sahf
281
	sahf
282
	ja .o_1
282
	ja .o_1
283
		ffree st0
283
		ffree st0
284
		fincstp
284
		fincstp
285
		mov eax,0.0
285
		mov eax,0.0
286
		jmp .end_m ;return 0.0
286
		jmp .end_m ;return 0.0
287
	.o_1:
287
	.o_1:
288
	fld1 ;else if (a>=1.0)
288
	fld1 ;else if (a>=1.0)
289
	fcompp
289
	fcompp
290
	fstsw ax
290
	fstsw ax
291
	sahf
291
	sahf
292
	jb .o_2
292
	ja .o_2
293
		mov eax,1.0
293
		mov eax,1.0
294
		jmp .end_m ;return 1.0
294
		jmp .end_m ;return 1.0
295
	.o_2:
295
	.o_2:
296
	mov eax,dword a ;else return a
296
	mov eax,dword a ;else return a
297
	.end_m:
297
	.end_m:
298
}
298
}
299
 
299
 
300
align 4
300
align 4
301
proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dword
301
proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dword
302
	mov eax,[context]
302
	mov eax,[context]
303
	mov ebx,[light]
303
	mov ebx,[light]
304
	imul ebx,sizeof.GLLight
304
	imul ebx,sizeof.GLLight
305
	add ebx,eax
305
	add ebx,eax
306
	add ebx,offs_cont_lights
306
	add ebx,offs_cont_lights
307
 
307
 
308
	xor ecx,ecx
308
	xor ecx,ecx
309
	cmp dword[ebx+offs_ligh_enabled],0
309
	cmp dword[ebx+offs_ligh_enabled],0
310
	jne @f
310
	jne @f
311
		not ecx
311
		not ecx
312
	@@:
312
	@@:
313
	and ecx,[v]
313
	and ecx,[v]
314
	or ecx,ecx
314
	or ecx,ecx
315
	jz @f
315
	jz @f
316
		;if (v && !l.enabled)
316
		;if (v && !l.enabled)
317
		mov dword[ebx+offs_ligh_enabled],1
317
		mov dword[ebx+offs_ligh_enabled],1
318
		mov ecx,[eax+offs_cont_first_light]
318
		mov ecx,[eax+offs_cont_first_light]
319
		mov [ebx+offs_ligh_next],ecx
319
		mov [ebx+offs_ligh_next],ecx
320
		mov [eax+offs_cont_first_light],ebx ;context.first_light = l
320
		mov [eax+offs_cont_first_light],ebx ;context.first_light = l
321
		mov dword[ebx+offs_ligh_prev],0 ;l.prev = NULL
321
		mov dword[ebx+offs_ligh_prev],0 ;l.prev = NULL
322
		jmp .end_f
322
		jmp .end_f
323
	@@:
323
	@@:
324
	xor ecx,ecx
324
	xor ecx,ecx
325
	cmp dword[v],0
325
	cmp dword[v],0
326
	jne @f
326
	jne @f
327
		not ecx
327
		not ecx
328
	@@:
328
	@@:
329
	and ecx,[ebx+offs_ligh_enabled]
329
	and ecx,[ebx+offs_ligh_enabled]
330
	or ecx,ecx
330
	or ecx,ecx
331
	jz .end_f
331
	jz .end_f
332
		;else if (!v && l.enabled)
332
		;else if (!v && l.enabled)
333
		mov dword[ebx+offs_ligh_enabled],0 ;l.enabled = 0
333
		mov dword[ebx+offs_ligh_enabled],0 ;l.enabled = 0
334
		mov ecx,[ebx+offs_ligh_next]
334
		mov ecx,[ebx+offs_ligh_next]
335
		cmp dword[ebx+offs_ligh_prev],0 ;if (l.prev == NULL)
335
		cmp dword[ebx+offs_ligh_prev],0 ;if (l.prev == NULL)
336
		jne .els_0
336
		jne .els_0
337
			mov [eax+offs_cont_first_light],ecx	;context.first_light = l.next
337
			mov [eax+offs_cont_first_light],ecx	;context.first_light = l.next
338
			jmp @f
338
			jmp @f
339
		.els_0:
339
		.els_0:
340
			mov eax,[ebx+offs_ligh_prev]
340
			mov eax,[ebx+offs_ligh_prev]
341
			mov [eax+offs_ligh_next],ecx ;l.prev.next = l.next
341
			mov [eax+offs_ligh_next],ecx ;l.prev.next = l.next
342
		@@:
342
		@@:
343
		cmp dword[ebx+offs_ligh_next],0
343
		cmp dword[ebx+offs_ligh_next],0
344
		je .end_f
344
		je .end_f
345
			mov ecx,[ebx+offs_ligh_prev]
345
			mov ecx,[ebx+offs_ligh_prev]
346
			mov eax,[ebx+offs_ligh_next]
346
			mov eax,[ebx+offs_ligh_next]
347
			mov [eax+offs_ligh_prev],ecx ;l.next.prev = l.prev
347
			mov [eax+offs_ligh_prev],ecx ;l.next.prev = l.prev
348
	.end_f:
348
	.end_f:
349
	ret
349
	ret
350
endp
350
endp
351
 
351
 
352
align 4
352
align 4
353
fl_1e_3 dd 1.0e-3
353
fl_1e_3 dd 1.0e-3
354
 
354
 
355
if DEBUG
355
if DEBUG
356
txt_mate db 'Material',0
356
txt_mate db 'Material',0
357
txt_colo db 'Color',0
357
txt_colo db 'Color',0
-
 
358
txt_rgba db 'R, G, B',0
358
end if
359
end if
359
 
360
 
360
; non optimized lightening model
361
; non optimized lightening model
361
align 4
362
align 4
362
proc gl_shade_vertex, context:dword, v:dword
363
proc gl_shade_vertex, context:dword, v:dword
363
locals
364
locals
364
	R dd ? ;float ebp-100
365
	R dd ? ;float ebp-96
365
	G dd ? ;float ebp-96
366
	G dd ? ;float ebp-92
366
	B dd ? ;float ebp-92
367
	B dd ? ;float ebp-88
367
	A dd ? ;float ebp-88
368
	A dd ? ;float ebp-84
368
	s V3 ;ebp-84
369
	s V3 ;ebp-80
369
	d V3 ;ebp-72
370
	d V3 ;ebp-68
370
	dist dd ? ;float ebp-60
-
 
371
	tmp dd ? ;float ebp-56
371
	tmp dd ? ;float ebp-56
372
	att dd ? ;float ebp-52
372
	att dd ? ;float ebp-52
373
	dot_spot dd ? ;float ebp-48
373
	dot_spot dd ? ;float ebp-48
374
	lR dd ? ;float ebp-44
374
	lR dd ? ;float ebp-44
375
	lB dd ? ;float ebp-40
375
	lB dd ? ;float ebp-40
376
	lG dd ? ;float ebp-36
376
	lG dd ? ;float ebp-36
377
	twoside dd ? ;int ebp-32
377
	twoside dd ? ;int ebp-32
378
	idx dd ? ;int ebp-28
378
	idx dd ? ;int ebp-28
379
	n V3 ;ebp-24
379
	n V3 ;ebp-24
380
	vcoord V3 ;ebp-12
380
	vcoord V3 ;ebp-12
381
endl
381
endl
382
pushad
382
pushad
383
; ebx -> GLLight *l
383
; ebx -> GLLight *l
384
; ecx -> GLMaterial *m
384
; ecx -> GLMaterial *m
385
; esi -> GLVertex *v
385
; esi -> GLVertex *v
386
	mov esi,[v]
386
	mov esi,[v]
387
	mov edx,[context]
387
	mov edx,[context]
388
	mov ecx,edx
388
	mov ecx,edx
389
	add ecx,offs_cont_materials ;ecx(m) = &context.materials[0]
389
	add ecx,offs_cont_materials ;ecx(m) = &context.materials[0]
390
	mov eax,[edx+offs_cont_light_model_two_side]
390
	mov eax,[edx+offs_cont_light_model_two_side]
391
	mov [twoside],eax
391
	mov [twoside],eax
392
 
392
 
393
	add esi,offs_vert_normal
393
	add esi,offs_vert_normal
394
	mov edi,ebp
394
	mov edi,ebp
395
	sub edi,24 ;edi = &n
395
	sub edi,24 ;edi = &n
396
	movsd ;n.X=v.normal.X
396
	movsd ;n.X=v.normal.X
397
	movsd ;n.Y=v.normal.Y
397
	movsd ;n.Y=v.normal.Y
398
	movsd ;n.Z=v.normal.Z
398
	movsd ;n.Z=v.normal.Z
399
	mov esi,[v]
399
	mov esi,[v]
400
 
400
 
401
if DEBUG ;offs_mate_emission, offs_mate_ambient, offs_mate_specular, offs_mate_diffuse
401
if DEBUG ;offs_mate_emission, offs_mate_ambient, offs_mate_specular, offs_mate_diffuse
402
push ecx
402
push ecx
403
	stdcall dbg_print,txt_mate,txt_nl
403
	stdcall dbg_print,txt_mate,txt_nl
404
	add ecx,offs_mate_emission
404
	add ecx,offs_mate_emission
405
	stdcall gl_print_matrix,ecx,1
405
	stdcall gl_print_matrix,ecx,1
406
	add ecx,offs_mate_ambient-offs_mate_emission
406
	add ecx,offs_mate_ambient-offs_mate_emission
407
	stdcall gl_print_matrix,ecx,1
407
	stdcall gl_print_matrix,ecx,1
408
	add ecx,offs_mate_specular-offs_mate_ambient
408
	add ecx,offs_mate_specular-offs_mate_ambient
409
	stdcall gl_print_matrix,ecx,1
409
	stdcall gl_print_matrix,ecx,1
410
	add ecx,offs_mate_diffuse-offs_mate_specular
410
	add ecx,offs_mate_diffuse-offs_mate_specular
411
	stdcall gl_print_matrix,ecx,1
411
	stdcall gl_print_matrix,ecx,1
412
pop ecx
412
pop ecx
413
end if
413
end if
414
 
414
 
415
	fld dword[edx+offs_cont_ambient_light_model]
415
	fld dword[edx+offs_cont_ambient_light_model]
416
	fmul dword[ecx+offs_mate_ambient]
416
	fmul dword[ecx+offs_mate_ambient]
417
	fadd dword[ecx] ;offs_mate_emission=0
417
	fadd dword[ecx] ;offs_mate_emission=0
418
	fstp dword[R] ;R=m.emission.v[0]+m.ambient.v[0]*context.ambient_light_model.v[0]
418
	fstp dword[R] ;R=m.emission.v[0]+m.ambient.v[0]*context.ambient_light_model.v[0]
419
	fld dword[edx+offs_cont_ambient_light_model+4]
419
	fld dword[edx+offs_cont_ambient_light_model+4]
420
	fmul dword[ecx+offs_mate_ambient+4]
420
	fmul dword[ecx+offs_mate_ambient+4]
421
	fadd dword[ecx+offs_mate_emission+4]
421
	fadd dword[ecx+offs_mate_emission+4]
422
	fstp dword[G]
422
	fstp dword[G]
423
	fld dword[edx+offs_cont_ambient_light_model+8]
423
	fld dword[edx+offs_cont_ambient_light_model+8]
424
	fmul dword[ecx+offs_mate_ambient+8]
424
	fmul dword[ecx+offs_mate_ambient+8]
425
	fadd dword[ecx+offs_mate_emission+8]
425
	fadd dword[ecx+offs_mate_emission+8]
426
	fstp dword[B]
426
	fstp dword[B]
427
	clampf [ecx+offs_mate_diffuse+12],0,1
427
	clampf [ecx+offs_mate_diffuse+12],0,1
428
	mov [A],eax ;A=clampf(m.diffuse.v[3],0,1)
428
	mov [A],eax ;A=clampf(m.diffuse.v[3],0,1)
429
 
429
 
430
	mov ebx,[edx+offs_cont_first_light]
430
	mov ebx,[edx+offs_cont_first_light]
431
	.cycle_0: ;for(l=context.first_light;l!=NULL;l=l.next)
431
	.cycle_0: ;for(l=context.first_light;l!=NULL;l=l.next)
432
		or ebx,ebx
432
		or ebx,ebx
433
		jz .cycle_0_end
433
		jz .cycle_0_end
434
 
434
 
435
		; ambient
435
		; ambient
436
		fld dword[ecx+offs_mate_ambient]
436
		fld dword[ecx+offs_mate_ambient]
437
		fmul dword[ebx] ;offs_ligh_ambient=0
437
		fmul dword[ebx] ;offs_ligh_ambient=0
438
		fstp dword[lR] ;lR=l.ambient.v[0] * m.ambient.v[0]
438
		fstp dword[lR] ;lR=l.ambient.v[0] * m.ambient.v[0]
439
		fld dword[ecx+offs_mate_ambient+4]
439
		fld dword[ecx+offs_mate_ambient+4]
440
		fmul dword[ebx+offs_ligh_ambient+4]
440
		fmul dword[ebx+offs_ligh_ambient+4]
441
		fstp dword[lG] ;lG=l.ambient.v[1] * m.ambient.v[1]
441
		fstp dword[lG] ;lG=l.ambient.v[1] * m.ambient.v[1]
442
		fld dword[ecx+offs_mate_ambient+8]
442
		fld dword[ecx+offs_mate_ambient+8]
443
		fmul dword[ebx+offs_ligh_ambient+8]
443
		fmul dword[ebx+offs_ligh_ambient+8]
444
		fstp dword[lB] ;lB=l.ambient.v[2] * m.ambient.v[2]
444
		fstp dword[lB] ;lB=l.ambient.v[2] * m.ambient.v[2]
445
 
445
 
446
		fld dword[ebx+offs_ligh_position+offs_W]
446
		fld dword[ebx+offs_ligh_position+offs_W]
447
		ftst ;if (l.position.v[3] == 0)
447
		ftst ;if (l.position.v[3] == 0)
448
		fstsw ax
448
		fstsw ax
449
		sahf
449
		sahf
450
		jne .els_0
450
		jne .els_0
451
			; light at infinity
451
			; light at infinity
452
			ffree st0 ;l.position.v[3]
452
			ffree st0 ;l.position.v[3]
453
			fincstp
453
			fincstp
454
			mov eax,[ebx+offs_ligh_position]
454
			mov eax,[ebx+offs_ligh_position]
455
			mov [d],eax ;d.X=l.position.v[0]
455
			mov [d],eax ;d.X=l.position.v[0]
456
			mov eax,[ebx+offs_ligh_position+offs_Y]
456
			mov eax,[ebx+offs_ligh_position+offs_Y]
457
			mov [d+offs_Y],eax ;d.Y=l.position.v[1]
457
			mov [d+offs_Y],eax ;d.Y=l.position.v[1]
458
			mov eax,[ebx+offs_ligh_position+offs_Z]
458
			mov eax,[ebx+offs_ligh_position+offs_Z]
459
			mov [d+offs_Z],eax ;d.Z=l.position.v[2]
459
			mov [d+offs_Z],eax ;d.Z=l.position.v[2]
460
			mov dword[att],1.0
460
			mov dword[att],1.0
461
			jmp .els_0_end
461
			jmp .els_0_end
462
		.els_0:
462
		.els_0:
463
			; distance attenuation
463
			; distance attenuation
464
			ffree st0 ;l.position.v[3]
464
			ffree st0 ;l.position.v[3]
465
			fincstp
465
			fincstp
466
			fld dword[ebx+offs_ligh_position]
466
			fld dword[ebx+offs_ligh_position]
467
			fsub dword[esi+offs_vert_ec]
467
			fsub dword[esi+offs_vert_ec]
468
			fstp dword[d] ;d.X=l.position.v[0]-v.ec.v[0]
468
			fstp dword[d] ;d.X=l.position.v[0]-v.ec.v[0]
469
			fld dword[ebx+offs_ligh_position+offs_Y]
469
			fld dword[ebx+offs_ligh_position+offs_Y]
470
			fsub dword[esi+offs_vert_ec+offs_Y]
470
			fsub dword[esi+offs_vert_ec+offs_Y]
471
			fstp dword[d+offs_Y] ;d.Y=l.position.v[1]-v.ec.v[1]
471
			fstp dword[d+offs_Y] ;d.Y=l.position.v[1]-v.ec.v[1]
472
			fld dword[ebx+offs_ligh_position+offs_Z]
472
			fld dword[ebx+offs_ligh_position+offs_Z]
473
			fsub dword[esi+offs_vert_ec+offs_Z]
473
			fsub dword[esi+offs_vert_ec+offs_Z]
474
			fstp dword[d+offs_Z] ;d.Z=l.position.v[2]-v.ec.v[2]
474
			fstp dword[d+offs_Z] ;d.Z=l.position.v[2]-v.ec.v[2]
475
			fld dword[d]
475
			fld dword[d]
476
			fmul st0,st0
476
			fmul st0,st0
477
			fld dword[d+offs_Y]
477
			fld dword[d+offs_Y]
478
			fmul st0,st0
478
			fmul st0,st0
479
			faddp
479
			faddp
480
			fld dword[d+offs_Z]
480
			fld dword[d+offs_Z]
481
			fmul st0,st0
481
			fmul st0,st0
482
			faddp
482
			faddp
483
			fsqrt
-
 
484
			fst dword[dist] ;dist=sqrt(d.X^2+d.Y^2+d.Z^2)
483
			fsqrt ;dist=sqrt(d.X^2+d.Y^2+d.Z^2)
485
			fcom dword[fl_1e_3]
484
			fcom dword[fl_1e_3]
486
			fstsw ax
485
			fstsw ax
487
			sahf
486
			sahf
488
			jbe @f ;if (dist>1.0e-3)
487
			jbe @f ;if (dist>1.0e-3)
489
				fld1
488
				fld1
490
				fdiv st0,st1
489
				fdiv st0,st1
491
				fld dword[d]
490
				fld dword[d]
492
				fmul st0,st1
491
				fmul st0,st1
493
				fstp dword[d]
492
				fstp dword[d]
494
				fld dword[d+offs_Y]
493
				fld dword[d+offs_Y]
495
				fmul st0,st1
494
				fmul st0,st1
496
				fstp dword[d+offs_Y]
495
				fstp dword[d+offs_Y]
497
				fld dword[d+offs_Z]
496
				fld dword[d+offs_Z]
498
				fmul st0,st1
497
				fmul st0,st1
499
				fstp dword[d+offs_Z]
498
				fstp dword[d+offs_Z]
500
				ffree st0 ;1.0/dist
499
				ffree st0 ;1.0/dist
501
				fincstp
500
				fincstp
502
			@@:
501
			@@:
503
			fld dword[ebx+offs_ligh_attenuation+8]
502
			fld dword[ebx+offs_ligh_attenuation+8]
504
			fmul st0,st1 ;st0 = dist * l.attenuation[2]
503
			fmul st0,st1 ;st0 = dist * l.attenuation[2]
505
			fadd dword[ebx+offs_ligh_attenuation+4]
504
			fadd dword[ebx+offs_ligh_attenuation+4]
506
			fmul st0,st1
505
			fmul st0,st1
507
			fadd dword[ebx+offs_ligh_attenuation]
506
			fadd dword[ebx+offs_ligh_attenuation]
508
			fld1
507
			fld1
509
			fdiv st0,st1
508
			fdiv st0,st1
510
			fstp dword[att] ;att = 1.0f/(l.attenuation[0]+dist*(l.attenuation[1]+dist*l.attenuation[2]))
509
			fstp dword[att] ;att = 1.0f/(l.attenuation[0]+dist*(l.attenuation[1]+dist*l.attenuation[2]))
511
			ffree st0 ;1.0
510
			ffree st0 ;1.0
512
			fincstp
511
			fincstp
513
			ffree st0 ;dist
512
			ffree st0 ;dist
514
			fincstp
513
			fincstp
515
		.els_0_end:
514
		.els_0_end:
516
		fld dword[d]
515
		fld dword[d]
517
		fmul dword[n]
516
		fmul dword[n]
518
		fld dword[d+offs_Y]
517
		fld dword[d+offs_Y]
519
		fmul dword[n+offs_Y]
518
		fmul dword[n+offs_Y]
520
		faddp
519
		faddp
521
		fld dword[d+offs_Z]
520
		fld dword[d+offs_Z]
522
		fmul dword[n+offs_Z]
521
		fmul dword[n+offs_Z]
523
		faddp ;dot = d.X*n.X+d.Y*n.Y+d.Z*n.Z
522
		faddp ;dot = d.X*n.X+d.Y*n.Y+d.Z*n.Z
524
		cmp dword[twoside],0 ;if (twoside && dot < 0)
523
		cmp dword[twoside],0 ;if (twoside && dot < 0)
525
		je @f
524
		je @f
526
		ftst ;if (dot<0)
525
		ftst ;if (dot<0)
527
		fstsw ax
526
		fstsw ax
528
		sahf
527
		sahf
529
		jae @f
528
		jae @f
530
			fchs ;dot = -dot
529
			fchs ;dot = -dot
531
		@@:
530
		@@:
532
		ftst ;if (dot>0)
531
		ftst ;if (dot>0)
533
		fstsw ax
532
		fstsw ax
534
		sahf
533
		sahf
535
		jbe .if0_end
534
		jbe .if0_end
536
			; diffuse light
535
			; diffuse light
537
			fld dword[ecx+offs_mate_diffuse]
536
			fld dword[ecx+offs_mate_diffuse]
538
			fmul dword[ebx+offs_ligh_diffuse]
537
			fmul dword[ebx+offs_ligh_diffuse]
539
			fmul st0,st1
538
			fmul st0,st1
540
			fadd dword[lR]
539
			fadd dword[lR]
541
			fstp dword[lR] ;lR+=dot * l.diffuse.v[0] * m.diffuse.v[0]
540
			fstp dword[lR] ;lR+=dot * l.diffuse.v[0] * m.diffuse.v[0]
542
			fld dword[ecx+offs_mate_diffuse+4]
541
			fld dword[ecx+offs_mate_diffuse+4]
543
			fmul dword[ebx+offs_ligh_diffuse+4]
542
			fmul dword[ebx+offs_ligh_diffuse+4]
544
			fmul st0,st1
543
			fmul st0,st1
545
			fadd dword[lG]
544
			fadd dword[lG]
546
			fstp dword[lG] ;lG+=dot * l.diffuse.v[1] * m.diffuse.v[1]
545
			fstp dword[lG] ;lG+=dot * l.diffuse.v[1] * m.diffuse.v[1]
547
			fld dword[ecx+offs_mate_diffuse+8]
546
			fld dword[ecx+offs_mate_diffuse+8]
548
			fmul dword[ebx+offs_ligh_diffuse+8]
547
			fmul dword[ebx+offs_ligh_diffuse+8]
549
			fmul st0,st1
548
			fmul st0,st1
550
			fadd dword[lB]
549
			fadd dword[lB]
551
			fstp dword[lB] ;lB+=dot * l.diffuse.v[2] * m.diffuse.v[2]
550
			fstp dword[lB] ;lB+=dot * l.diffuse.v[2] * m.diffuse.v[2]
552
			ffree st0 ;dot
551
			ffree st0 ;dot
553
			fincstp
552
			fincstp
554
 
553
 
555
			; spot light
554
			; spot light
556
			fld dword[ebx+offs_ligh_spot_cutoff]
555
			fld dword[ebx+offs_ligh_spot_cutoff]
557
			fcomp dword[an180f] ;if (l.spot_cutoff != 180)
556
			fcomp dword[an180f] ;if (l.spot_cutoff != 180)
558
			fstsw ax
557
			fstsw ax
559
			sahf
558
			sahf
560
			jne .if1_end
559
			je .if1_end
561
				fld dword[ebx+offs_ligh_norm_spot_direction]
560
				fld dword[ebx+offs_ligh_norm_spot_direction]
562
				fmul dword[d]
561
				fmul dword[d]
563
				fld dword[ebx+offs_ligh_norm_spot_direction+4]
562
				fld dword[ebx+offs_ligh_norm_spot_direction+4]
564
				fmul dword[d+offs_Y]
563
				fmul dword[d+offs_Y]
565
				faddp
564
				faddp
566
				fld dword[ebx+offs_ligh_norm_spot_direction+8]
565
				fld dword[ebx+offs_ligh_norm_spot_direction+8]
567
				fmul dword[d+offs_Z]
566
				fmul dword[d+offs_Z]
568
				faddp
567
				faddp
569
				fchs
568
				fchs
570
				fst dword[dot_spot]
569
				fst dword[dot_spot]
571
				cmp dword[twoside],0 ;if (twoside && dot_spot < 0)
570
				cmp dword[twoside],0 ;if (twoside && dot_spot < 0)
572
				je @f
571
				je @f
573
				ftst ;if (dot_spot<0)
572
				ftst ;if (dot_spot<0)
574
				fstsw ax
573
				fstsw ax
575
				sahf
574
				sahf
576
				jae @f
575
				jae @f
577
					fchs ;dot_spot = -dot_spot
576
					fchs ;dot_spot = -dot_spot
578
				@@:
577
				@@:
579
				fcom dword[ebx+offs_ligh_cos_spot_cutoff] ;if (dot_spot < l.cos_spot_cutoff)
578
				fcom dword[ebx+offs_ligh_cos_spot_cutoff] ;if (dot_spot < l.cos_spot_cutoff)
580
				fstsw ax
579
				fstsw ax
581
				sahf
580
				sahf
582
				jae .els_1
581
				jae .els_1
583
					; no contribution
582
					; no contribution
584
					ffree st0 ;dot_spot
583
					ffree st0 ;dot_spot
585
					fincstp
584
					fincstp
586
					mov ebx,[ebx+offs_ligh_next]
585
					mov ebx,[ebx+offs_ligh_next]
587
					jmp .cycle_0 ;continue
586
					jmp .cycle_0 ;continue
588
				.els_1:
587
				.els_1:
589
					; TODO: optimize
588
					; TODO: optimize
590
					fld dword[ebx+offs_ligh_spot_exponent]
589
					fld dword[ebx+offs_ligh_spot_exponent]
591
					ftst ;if (l.spot_exponent > 0)
590
					ftst ;if (l.spot_exponent > 0)
592
					fstsw ax
591
					fstsw ax
593
					sahf
592
					sahf
594
					jbe @f
593
					jbe @f
595
						fxch st1 ;dot_spot <--> l.spot_exponent
594
						fxch st1 ;dot_spot <--> l.spot_exponent
596
						;Вычисляем x^y
595
						;Вычисляем x^y
597
						;fld y
596
						;fld y
598
						;fld x
597
						;fld x
599
						fyl2x ;Стек FPU теперь содержит: st0=z=y*log2(x):
598
						fyl2x ;Стек FPU теперь содержит: st0=z=y*log2(x):
600
						;Теперь считаем 2**z:
599
						;Теперь считаем 2**z:
601
						fld st0 ;Создаем еще одну копию z
600
						fld st0 ;Создаем еще одну копию z
602
						frndint ;Округляем
601
						frndint ;Округляем
603
						fsubr st0,st1  ;st1=z, st0=z-trunc(z)
602
						fsubr st0,st1  ;st1=z, st0=z-trunc(z)
604
						f2xm1  ;st1=z, st0=2**(z-trunc(z))-1
603
						f2xm1  ;st1=z, st0=2**(z-trunc(z))-1
605
						fld1
604
						fld1
606
						faddp  ;st1=z, st0=2**(z-trunc(z))
605
						faddp  ;st1=z, st0=2**(z-trunc(z))
607
						fscale ;st1=z, st0=(2**trunc(z))*(2**(z-trunc(z)))=2**t
606
						fscale ;st1=z, st0=(2**trunc(z))*(2**(z-trunc(z)))=2**t
608
						fxch st1
607
						fxch st1
609
						fstp st ;Результат остается на вершине стека st0
608
						fstp st ;Результат остается на вершине стека st0
610
						fmul dword[att]
609
						fmul dword[att]
611
						fstp dword[att] ;att=att*pow(dot_spot,l.spot_exponent)
610
						fstp dword[att] ;att=att*pow(dot_spot,l.spot_exponent)
612
						jmp .if1_end
611
						jmp .if1_end
613
					@@:
612
					@@:
614
					ffree st0 ;l.spot_exponent
613
					ffree st0 ;l.spot_exponent
615
					fincstp
614
					fincstp
616
					ffree st0 ;dot_spot
615
					ffree st0 ;dot_spot
617
					fincstp
616
					fincstp
618
			.if1_end:
617
			.if1_end:
619
 
618
 
620
			; specular light
619
			; specular light
621
			cmp dword[edx+offs_cont_local_light_model],0 ;if (c.local_light_model)
620
			cmp dword[edx+offs_cont_local_light_model],0 ;if (c.local_light_model)
622
			je .els_2
621
			je .els_2
623
				mov eax,[esi+offs_vert_ec]
622
				mov eax,[esi+offs_vert_ec]
624
				mov [vcoord],eax ;vcoord.X=v.ec.X
623
				mov [vcoord],eax ;vcoord.X=v.ec.X
625
				mov eax,[esi+offs_vert_ec+offs_Y]
624
				mov eax,[esi+offs_vert_ec+offs_Y]
626
				mov [vcoord+offs_Y],eax ;vcoord.Y=v.ec.Y
625
				mov [vcoord+offs_Y],eax ;vcoord.Y=v.ec.Y
627
				mov eax,[esi+offs_vert_ec+offs_Z]
626
				mov eax,[esi+offs_vert_ec+offs_Z]
628
				mov [vcoord+offs_Z],eax ;vcoord.Z=v.ec.Z
627
				mov [vcoord+offs_Z],eax ;vcoord.Z=v.ec.Z
629
				mov eax,ebp
628
				mov eax,ebp
630
				sub eax,12 ;eax = &vcoord
629
				sub eax,12 ;eax = &vcoord
631
				stdcall gl_V3_Norm, eax
630
				stdcall gl_V3_Norm, eax
632
				fld dword[d]
631
				fld dword[d]
633
				fsub dword[vcoord]
632
				fsub dword[vcoord]
634
				fstp dword[s] ;s.X=d.X-vcoord.X
633
				fstp dword[s] ;s.X=d.X-vcoord.X
635
				fld dword[d+offs_Y]
634
				fld dword[d+offs_Y]
636
				fsub dword[vcoord+offs_Y]
635
				fsub dword[vcoord+offs_Y]
637
				fstp dword[s+offs_Y] ;s.Y=d.Y-vcoord.Y
636
				fstp dword[s+offs_Y] ;s.Y=d.Y-vcoord.Y
638
				fld dword[d+offs_Z]
637
				fld dword[d+offs_Z]
639
				fsub dword[vcoord+offs_Z]
638
				fsub dword[vcoord+offs_Z]
640
				fstp dword[s+offs_Z] ;s.Z=d.Z-vcoord.Z
639
				fstp dword[s+offs_Z] ;s.Z=d.Z-vcoord.Z
641
				jmp .els_2_end
640
				jmp .els_2_end
642
			.els_2:
641
			.els_2:
643
				mov eax,[d]
642
				mov eax,[d]
644
				mov [s],eax ;s.X=d.X
643
				mov [s],eax ;s.X=d.X
645
				mov eax,[d+offs_Y]
644
				mov eax,[d+offs_Y]
646
				mov [s+offs_Y],eax ;s.Y=d.Y
645
				mov [s+offs_Y],eax ;s.Y=d.Y
647
				fld1
646
				fld1
648
				fadd dword[d+offs_Z]
647
				fadd dword[d+offs_Z]
649
				fstp dword[s+offs_Z] ;s.Z=d.Z+1.0
648
				fstp dword[s+offs_Z] ;s.Z=d.Z+1.0
650
			.els_2_end:
649
			.els_2_end:
651
			fld dword[n]
650
			fld dword[n]
652
			fmul st0,st0
651
			fmul st0,st0
653
			fld dword[n+offs_Y]
652
			fld dword[n+offs_Y]
654
			fmul st0,st0
653
			fmul st0,st0
655
			faddp
654
			faddp
656
			fld dword[n+offs_Z]
655
			fld dword[n+offs_Z]
657
			fmul st0,st0
656
			fmul st0,st0
658
			faddp ;dot_spec = n.X^2 +n.Y^2 +n.Z^2
657
			faddp ;dot_spec = n.X^2 +n.Y^2 +n.Z^2
659
			cmp dword[twoside],0 ;if (twoside && dot_spec < 0)
658
			cmp dword[twoside],0 ;if (twoside && dot_spec < 0)
660
			je @f
659
			je @f
661
			ftst ;if (dot_spec < 0)
660
			ftst ;if (dot_spec < 0)
662
			fstsw ax
661
			fstsw ax
663
			sahf
662
			sahf
664
			jae @f
663
			jae @f
665
				fchs ;dot_spec = -dot_spec
664
				fchs ;dot_spec = -dot_spec
666
			@@:
665
			@@:
667
			ftst ;if (dot_spec > 0)
666
			ftst ;if (dot_spec > 0)
668
			fstsw ax
667
			fstsw ax
669
			sahf
668
			sahf
670
			jbe .if0_end
669
			jbe .if0_end
671
				fld dword[s]
670
				fld dword[s]
672
				fmul st0,st0
671
				fmul st0,st0
673
				fld dword[s+offs_Y]
672
				fld dword[s+offs_Y]
674
				fmul st0,st0
673
				fmul st0,st0
675
				faddp
674
				faddp
676
				fld dword[s+offs_Z]
675
				fld dword[s+offs_Z]
677
				fmul st0,st0
676
				fmul st0,st0
678
				faddp
677
				faddp ;st0 = s.X^2 +s.Y^2 +s.Z^2
679
				fsqrt
678
				fsqrt
680
				fcom dword[fl_1e_3]
679
				fcom dword[fl_1e_3]
681
				fstsw ax
680
				fstsw ax
682
				sahf
681
				sahf
683
				jbe @f ;if (tmp > 1.0e-3)
682
				jbe @f ;if (tmp > 1.0e-3)
684
					fdiv st1,st0 ;dot_spec /= tmp
683
					fdiv st1,st0 ;dot_spec /= tmp
685
				@@:
684
				@@:
686
				ffree st0 ;tmp
685
				ffree st0 ;tmp
687
				fincstp
686
				fincstp
688
 
687
 
689
				; TODO: optimize
688
				; TODO: optimize
690
				; testing specular buffer code
689
				; testing specular buffer code
691
				; dot_spec= pow(dot_spec,m.shininess)
690
				; dot_spec= pow(dot_spec,m.shininess)
692
				stdcall specbuf_get_buffer, edx, dword[ecx+offs_mate_shininess_i], dword[ecx+offs_mate_shininess]
691
				stdcall specbuf_get_buffer, edx, dword[ecx+offs_mate_shininess_i], dword[ecx+offs_mate_shininess]
693
				mov edi,eax ;edi = specbuf
692
				mov edi,eax ;edi = specbuf
694
				mov dword[idx],SPECULAR_BUFFER_SIZE ;idx = SPECULAR_BUFFER_SIZE
693
				mov dword[idx],SPECULAR_BUFFER_SIZE ;idx = SPECULAR_BUFFER_SIZE
695
				fld1
694
				fld1
696
				fcomp
695
				fcomp
697
				fstsw ax
696
				fstsw ax
698
				fild dword[idx]
697
				fild dword[idx]
699
				sahf
698
				sahf
700
				jae @f ;if(dot_spec < 1.0)
699
				jbe @f ;if(dot_spec < 1.0) st0=1 st1=dot_spec
701
					fmul st0,st1 ;idx *= dot_spec
700
					fmul st0,st1 ;idx *= dot_spec
702
				@@:
701
				@@:
703
				fistp dword[idx]
702
				fistp dword[idx]
704
				ffree st0 ;dot_spec
703
				ffree st0 ;dot_spec
705
				fincstp
704
				fincstp
706
				shl dword[idx],2
705
				shl dword[idx],2
707
				add edi,dword[idx]
706
				add edi,dword[idx]
708
				fld dword[edi+offs_spec_buf] ;dot_spec = specbuf.buf[idx]
707
				fld dword[edi+offs_spec_buf] ;dot_spec = specbuf.buf[idx]
709
				fld dword[ebx+offs_ligh_specular]
708
				fld dword[ebx+offs_ligh_specular]
710
				fmul st0,st1
709
				fmul st0,st1
711
				fmul dword[ecx+offs_mate_specular]
710
				fmul dword[ecx+offs_mate_specular]
712
				fadd dword[lR]
711
				fadd dword[lR]
713
				fstp dword[lR] ;lR+=dot_spec * l.specular.v[0] * m.specular.v[0]
712
				fstp dword[lR] ;lR+=dot_spec * l.specular.v[0] * m.specular.v[0]
-
 
713
;ffree st0
-
 
714
;fincstp
714
				fld dword[ebx+offs_ligh_specular+4]
715
				fld dword[ebx+offs_ligh_specular+4]
715
				fmul st0,st1
716
				fmul st0,st1
716
				fmul dword[ecx+offs_mate_specular+4]
717
				fmul dword[ecx+offs_mate_specular+4]
717
				fadd dword[lG]
718
				fadd dword[lG]
718
				fstp dword[lG] ;lG+=dot_spec * l.specular.v[1] * m.specular.v[1]
719
				fstp dword[lG] ;lG+=dot_spec * l.specular.v[1] * m.specular.v[1]
-
 
720
;ffree st0
-
 
721
;fincstp
719
				fld dword[ebx+offs_ligh_specular+8]
722
				fld dword[ebx+offs_ligh_specular+8]
720
				fmul st0,st1
723
				fmul st0,st1
721
				fmul dword[ecx+offs_mate_specular+8]
724
				fmul dword[ecx+offs_mate_specular+8]
722
				fadd dword[lB]
725
				fadd dword[lB]
723
				fstp dword[lB] ;lB+=dot_spec * l.specular.v[2] * m.specular.v[2]
726
				fstp dword[lB] ;lB+=dot_spec * l.specular.v[2] * m.specular.v[2]
-
 
727
;ffree st0
-
 
728
;fincstp
724
				ffree st0 ;dot_spec
729
				ffree st0 ;dot_spec
725
				fincstp
730
				fincstp
726
			jmp .if2_end
731
			jmp .if2_end
727
		.if0_end:
732
		.if0_end:
728
		ffree st0 ;dot [or] dot_spec
733
		ffree st0 ;dot [or] dot_spec
729
		fincstp
734
		fincstp
730
		.if2_end:
735
		.if2_end:
731
 
736
 
732
		fld dword[att]
737
		fld dword[att]
733
		fld dword[lR]
738
		fld dword[lR]
734
		fmul st0,st1
739
		fmul st0,st1
735
		fadd dword[R]
740
		fadd dword[R]
736
		fstp dword[R] ;R += att * lR
741
		fstp dword[R] ;R += att * lR
737
		fld dword[lG]
742
		fld dword[lG]
738
		fmul st0,st1
743
		fmul st0,st1
739
		fadd dword[G]
744
		fadd dword[G]
740
		fstp dword[G] ;G += att * lG
745
		fstp dword[G] ;G += att * lG
741
		fld dword[lB]
746
		fld dword[lB]
742
		fmul st0,st1
747
		fmul st0,st1
743
		fadd dword[B]
748
		fadd dword[B]
744
		fstp dword[B] ;B += att * lB
749
		fstp dword[B] ;B += att * lB
745
		ffree st0 ;att
750
		ffree st0 ;att
746
		fincstp
751
		fincstp
747
		mov ebx,[ebx+offs_ligh_next]
752
		mov ebx,[ebx+offs_ligh_next]
748
		jmp .cycle_0
753
		jmp .cycle_0
749
	.cycle_0_end:
754
	.cycle_0_end:
750
 
755
 
751
	clampf [R],0,1
756
	clampf [R],0,1
752
	mov [esi+offs_vert_color],eax ;v.color.v[0]=clampf(R,0,1)
757
	mov [esi+offs_vert_color],eax ;v.color.v[0]=clampf(R,0,1)
753
	clampf [G],0,1
758
	clampf [G],0,1
754
	mov [esi+offs_vert_color+4],eax ;v.color.v[1]=clampf(G,0,1)
759
	mov [esi+offs_vert_color+4],eax ;v.color.v[1]=clampf(G,0,1)
755
	clampf [B],0,1
760
	clampf [B],0,1
756
	mov [esi+offs_vert_color+8],eax ;v.color.v[2]=clampf(B,0,1)
761
	mov [esi+offs_vert_color+8],eax ;v.color.v[2]=clampf(B,0,1)
757
	mov eax,[A]
762
	mov eax,[A]
758
	mov [esi+offs_vert_color+12],eax ;v.color.v[3]=A
763
	mov [esi+offs_vert_color+12],eax ;v.color.v[3]=A
759
if DEBUG ;offs_vert_color
764
if DEBUG ;offs_vert_color
760
push esi
765
push esi
761
	stdcall dbg_print,txt_colo,txt_nl
766
	stdcall dbg_print,txt_colo,txt_nl
762
	add esi,offs_vert_color
767
	add esi,offs_vert_color
763
	stdcall gl_print_matrix,esi,1
768
	stdcall gl_print_matrix,esi,1
764
pop esi
769
pop esi
765
end if
770
end if
766
popad
771
popad
767
	ret
772
	ret
768
endp
773
endp
769
>
774
>
770
>
775
>
771
>
776
>
772
>
777
>