Subversion Repositories Kolibri OS

Rev

Rev 6523 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6523 Rev 8063
Line 9... Line 9...
9
	mov ecx,[ebx+4] ;ecx = p[1]
9
	mov ecx,[ebx+4] ;ecx = p[1]
Line 10... Line 10...
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
-
 
15
		add edi,12
14
		lea edi,[ebp+12]
16
		stdcall glopMaterial,eax,edi
15
		stdcall glopMaterial,eax,edi
17
		mov ecx,GL_BACK
16
		mov ecx,GL_BACK
18
	@@:
-
 
19
	mov edi,eax
17
	@@:
20
	add edi,GLContext.materials
18
	lea edi,[eax+GLContext.materials]
21
	cmp ecx,GL_FRONT ;if (mode == GL_FRONT) m=&context.materials[0]
19
	cmp ecx,GL_FRONT ;if (mode == GL_FRONT) m=&context.materials[0]
22
	je @f
20
	je @f
23
		add edi,sizeof.GLMaterial ;else m=&context.materials[1]
21
		add edi,sizeof.GLMaterial ;else m=&context.materials[1]
Line 24... Line 22...
24
	@@:
22
	@@:
25
 
-
 
26
	mov ecx,4
23
 
27
	mov esi,ebx ;esi = &p
24
	mov ecx,4
28
	add esi,12 ;esi = &p[3]
25
	lea esi,[ebx+12] ;esi = &p[3]
29
	mov ebx,[ebx+8] ;ebx = p[2]
26
	mov ebx,[ebx+8] ;ebx = p[2]
30
	cmp ebx,GL_EMISSION
27
	cmp ebx,GL_EMISSION
31
	jne @f
28
	jne @f
32
		;add edi,offs_mate_emission ;offs_mate_emission=0
29
		;add edi,GLMaterial.emission ;GLMaterial.emission=0
33
		rep movsd
30
		rep movsd
34
		jmp .end_f
31
		jmp .end_f
35
align 4
32
align 4
36
	@@:
33
	@@:
37
	cmp ebx,GL_AMBIENT
34
	cmp ebx,GL_AMBIENT
38
	jne @f
35
	jne @f
39
		add edi,offs_mate_ambient
36
		add edi,GLMaterial.ambient
40
		rep movsd
37
		rep movsd
41
		jmp .end_f
38
		jmp .end_f
42
align 4
39
align 4
43
	@@:
40
	@@:
44
	cmp ebx,GL_DIFFUSE
41
	cmp ebx,GL_DIFFUSE
45
	jne @f
42
	jne @f
46
		add edi,offs_mate_diffuse
43
		add edi,GLMaterial.diffuse
47
		rep movsd
44
		rep movsd
48
		jmp .end_f
45
		jmp .end_f
49
align 4
46
align 4
50
	@@:
47
	@@:
51
	cmp ebx,GL_SPECULAR
48
	cmp ebx,GL_SPECULAR
52
	jne @f
49
	jne @f
53
		add edi,offs_mate_specular
50
		add edi,GLMaterial.specular
54
		rep movsd
51
		rep movsd
55
		jmp .end_f
52
		jmp .end_f
56
align 4
53
align 4
57
	@@:
54
	@@:
58
	cmp ebx,GL_SHININESS
55
	cmp ebx,GL_SHININESS
59
	jne @f
56
	jne @f
60
		fld dword[esi]
57
		fld dword[esi]
61
		add edi,offs_mate_shininess
58
		add edi,GLMaterial.shininess
62
		movsd
59
		movsd
63
		mov dword[edi],SPECULAR_BUFFER_RESOLUTION
60
		mov dword[edi],SPECULAR_BUFFER_RESOLUTION
64
		fdiv dword[sp128f]
61
		fdiv dword[sp128f]
65
		fimul dword[edi]
62
		fimul dword[edi]
66
		fistp dword[edi] ;m.shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION
63
		fistp dword[edi] ;m.shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION
67
		jmp .end_f
64
		jmp .end_f
68
align 4
65
align 4
69
	@@:
66
	@@:
70
	cmp ebx,GL_AMBIENT_AND_DIFFUSE
67
	cmp ebx,GL_AMBIENT_AND_DIFFUSE
71
	jne @f
68
	jne @f
72
		add edi,offs_mate_ambient
69
		add edi,GLMaterial.ambient
73
		rep movsd
70
		rep movsd
74
		sub esi,16
71
		sub esi,16
75
		;edi = &offs_mate_diffuse
72
		;edi = &GLMaterial.diffuse
76
		mov ecx,4
73
		mov ecx,4
77
		rep movsd
74
		rep movsd
78
		jmp .end_f
75
		jmp .end_f
Line 106... Line 103...
106
 
103
 
Line 107... Line 104...
107
;  assert(edx >= GL_LIGHT0 && edx < GL_LIGHT0+MAX_LIGHTS );
104
;  assert(edx >= GL_LIGHT0 && edx < GL_LIGHT0+MAX_LIGHTS );
108
 
105
 
109
	sub edx,GL_LIGHT0
-
 
110
	imul edx,sizeof.GLLight
106
	sub edx,GL_LIGHT0
Line 111... Line 107...
111
	add edx,eax
107
	imul edx,sizeof.GLLight
112
	add edx,GLContext.lights
108
	lea edx,[eax+edx+GLContext.lights]
113
 
109
 
114
	mov ecx,[ebx+8] ;ecx = p[2]
110
	mov ecx,[ebx+8] ;ecx = p[2]
115
	cmp ecx,GL_AMBIENT
-
 
116
	jne @f
111
	cmp ecx,GL_AMBIENT
117
		mov esi,ebx
112
	jne @f
118
		add esi,12
113
		lea esi,[ebx+12]
119
		mov edi,edx
114
		mov edi,edx
120
		;add edi,offs_ligh_ambient ;offs_ligh_ambient = 0
115
		;add edi,GLLight.ambient ;GLLight.ambient = 0
121
		mov ecx,4
116
		mov ecx,4
122
		rep movsd ;l.ambient=v
117
		rep movsd ;l.ambient=v
123
		jmp .end_f
118
		jmp .end_f
124
align 4
119
align 4
125
	@@:
120
	@@:
126
	cmp ecx,GL_DIFFUSE
-
 
127
	jne @f
-
 
128
		mov esi,ebx
121
	cmp ecx,GL_DIFFUSE
129
		add esi,12
122
	jne @f
130
		mov edi,edx
123
		lea esi,[ebx+12]
131
		add edi,offs_ligh_diffuse
124
		lea edi,[edx+GLLight.diffuse]
132
		mov ecx,4
125
		mov ecx,4
133
		rep movsd ;l.diffuse=v
126
		rep movsd ;l.diffuse=v
134
		jmp .end_f
127
		jmp .end_f
135
align 4
128
align 4
136
	@@:
129
	@@:
137
	cmp ecx,GL_SPECULAR
-
 
138
	jne @f
-
 
139
		mov esi,ebx
130
	cmp ecx,GL_SPECULAR
140
		add esi,12
131
	jne @f
141
		mov edi,edx
132
		lea esi,[ebx+12]
142
		add edi,offs_ligh_specular
133
		lea edi,[edx+GLLight.specular]
143
		mov ecx,4
134
		mov ecx,4
144
		rep movsd ;l.specular=v
135
		rep movsd ;l.specular=v
145
		jmp .end_f
136
		jmp .end_f
146
align 4
137
align 4
147
	@@:
-
 
148
	cmp ecx,GL_POSITION
138
	@@:
149
	jne @f
-
 
150
		mov edi,ebx ;ebx = [ebp+12] = [p] = &p[0]
139
	cmp ecx,GL_POSITION
151
		add edi,12 ;&p[3]
140
	jne @f
152
		mov esi,ebp
-
 
153
		sub esi,16 ;&pos
141
		lea edi,[ebx+12] ;&p[3]
154
		stdcall gl_M4_MulV4, esi,dword[eax+GLContext.matrix_stack_ptr],edi
142
		lea esi,[ebp-16] ;&pos
155
		mov edi,edx
143
		stdcall gl_M4_MulV4, esi,dword[eax+GLContext.matrix_stack_ptr],edi
Line 156... Line 144...
156
		add edi,offs_ligh_position
144
		lea edi,[edx+GLLight.position]
157
		mov ecx,4
145
		mov ecx,4
158
		rep movsd ;l.position=pos
146
		rep movsd ;l.position=pos
159
 
147
 
160
		fld dword[edi-4] ;if(l.position.v[3] == 0)
148
		fld dword[edi-4] ;if(l.position.v[3] == 0)
161
		ftst
149
		ftst
162
		fstsw ax
150
		fstsw ax
163
		sahf
-
 
164
		jne .end_i
151
		sahf
165
			;mov esi,ebp
152
		jne .end_i
166
			sub esi,16 ;&pos
153
			;mov esi,ebp
Line 167... Line -...
167
			mov edi,edx
-
 
168
			add edi,offs_ligh_norm_position
154
			sub esi,16 ;&pos
169
			mov ecx,3
155
			lea edi,[edx+GLLight.norm_position]
170
			rep movsd ;l.norm_position=pos[1,2,3]
156
			mov ecx,3
171
 
157
			rep movsd ;l.norm_position=pos[1,2,3]
172
			;mov edi,edx
158
 
173
			;add edi,offs_ligh_norm_position
159
			;lea edi,[edx+GLLight.norm_position]
174
			sub edi,12
160
			sub edi,12
175
			stdcall gl_V3_Norm,edi ;&l.norm_position
161
			stdcall gl_V3_Norm,edi ;&l.norm_position
176
		.end_i:
162
		.end_i:
177
		ffree st0
163
		ffree st0
178
		fincstp
164
		fincstp
179
		jmp .end_f
165
		jmp .end_f
180
align 4
-
 
181
	@@:
-
 
182
	cmp ecx,GL_SPOT_DIRECTION
166
align 4
183
	jne @f
167
	@@:
184
		mov esi,ebx ;&p[0]
168
	cmp ecx,GL_SPOT_DIRECTION
185
		add esi,12
169
	jne @f
186
		mov edi,edx
-
 
187
		add edi,offs_ligh_spot_direction
170
		lea esi,[ebx+12] ;&p[3]
188
		mov ecx,3
-
 
189
		rep movsd ;l.spot_direction=v[0,1,2]
171
		lea edi,[edx+GLLight.spot_direction]
190
		;mov esi,ebx
172
		mov ecx,3
191
		;add esi,12
173
		rep movsd ;l.spot_direction=v[0,1,2]
192
		sub esi,12
174
		;lea esi,[ebx+12]
193
		;mov edi,edx
175
		sub esi,12
194
		;add edi,offs_ligh_norm_spot_direction
176
		;lea edi,[edx+GLLight.norm_spot_direction]
195
		add edi,offs_ligh_norm_spot_direction-(offs_ligh_spot_direction+12)
177
		add edi,GLLight.norm_spot_direction-(GLLight.spot_direction+12)
196
		mov ecx,3
178
		mov ecx,3
197
		rep movsd ;l.norm_spot_direction=v[0,1,2]
179
		rep movsd ;l.norm_spot_direction=v[0,1,2]
198
		add edx,offs_ligh_norm_spot_direction
180
		add edx,GLLight.norm_spot_direction
199
		stdcall gl_V3_Norm,edx
181
		stdcall gl_V3_Norm,edx
200
		jmp .end_f
182
		jmp .end_f
201
align 4
183
align 4
202
	@@:
184
	@@:
203
	cmp ecx,GL_SPOT_EXPONENT
185
	cmp ecx,GL_SPOT_EXPONENT
204
	jne @f
186
	jne @f
205
		mov ecx,[ebx+12]
187
		mov ecx,[ebx+12]
206
		mov [edi+offs_ligh_spot_exponent],ecx ;l.spot_exponent=p[3]
188
		mov [edi+GLLight.spot_exponent],ecx ;l.spot_exponent=p[3]
207
		jmp .end_f
189
		jmp .end_f
208
align 4
190
align 4
209
	@@:
191
	@@:
210
	cmp ecx,GL_SPOT_CUTOFF
192
	cmp ecx,GL_SPOT_CUTOFF
211
	jne .end_spot_c
193
	jne .end_spot_c
212
		fld dword[ebp+12] ;float a=v.v[0]
194
		fld dword[ebp+12] ;float a=v.v[0]
213
;      assert(a == 180 || (a>=0 && a<=90));
195
;      assert(a == 180 || (a>=0 && a<=90));
214
		fst dword[edi+offs_ligh_spot_cutoff] ;l.spot_cutoff=a
196
		fst dword[edi+GLLight.spot_cutoff] ;l.spot_cutoff=a
215
		fcom dword[an180f] ;if (a != 180)
197
		fcom dword[an180f] ;if (a != 180)
216
		fstsw ax
198
		fstsw ax
217
		sahf
199
		sahf
218
		je @f
200
		je @f
219
			fldpi
201
			fldpi
220
			fmulp
202
			fmulp
221
			fdiv dword[an180f]
203
			fdiv dword[an180f]
222
			fcos
204
			fcos
223
			fstp dword[edi+offs_ligh_cos_spot_cutoff] ;l.cos_spot_cutoff=cos(a * M_PI / 180.0)
205
			fstp dword[edi+GLLight.cos_spot_cutoff] ;l.cos_spot_cutoff=cos(a * M_PI / 180.0)
224
			jmp .end_f
206
			jmp .end_f
225
		@@:
207
		@@:
226
		ffree st0
208
		ffree st0
227
		fincstp
209
		fincstp
228
		jmp .end_f
210
		jmp .end_f
229
align 4
211
align 4
230
	.end_spot_c:
212
	.end_spot_c:
231
	cmp ecx,GL_CONSTANT_ATTENUATION
213
	cmp ecx,GL_CONSTANT_ATTENUATION
232
	jne @f
214
	jne @f
233
		mov ecx,[ebx+12]
215
		mov ecx,[ebx+12]
234
		mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3]
216
		mov [edi+GLLight.attenuation],ecx ;l->attenuation[0]=p[3]
235
		jmp .end_f
217
		jmp .end_f
236
align 4
218
align 4
237
	@@:
219
	@@:
238
	cmp ecx,GL_LINEAR_ATTENUATION
220
	cmp ecx,GL_LINEAR_ATTENUATION
239
	jne @f
221
	jne @f
240
		mov ecx,[ebx+12]
222
		mov ecx,[ebx+12]
241
		mov [edi+offs_ligh_attenuation+4],ecx ;l->attenuation[1]=p[3]
223
		mov [edi+GLLight.attenuation+4],ecx ;l->attenuation[1]=p[3]
242
		jmp .end_f
224
		jmp .end_f
243
align 4
225
align 4
244
	@@:
226
	@@:
245
	cmp ecx,GL_QUADRATIC_ATTENUATION
227
	cmp ecx,GL_QUADRATIC_ATTENUATION
246
	jne @f
228
	jne @f
247
		mov ecx,[ebx+12]
229
		mov ecx,[ebx+12]
248
		mov [edi+offs_ligh_attenuation+8],ecx ;l->attenuation[2]=p[3]
230
		mov [edi+GLLight.attenuation+8],ecx ;l->attenuation[2]=p[3]
Line 324... Line 306...
324
align 4
306
align 4
325
proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dword
307
proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dword
326
	mov eax,[context]
308
	mov eax,[context]
327
	mov ebx,[light]
309
	mov ebx,[light]
328
	imul ebx,sizeof.GLLight
310
	imul ebx,sizeof.GLLight
329
	add ebx,eax
-
 
330
	add ebx,GLContext.lights
311
	lea ebx,[eax+ebx+GLContext.lights]
Line 331... Line 312...
331
 
312
 
332
	xor ecx,ecx
313
	xor ecx,ecx
333
	cmp dword[ebx+offs_ligh_enabled],0
314
	cmp dword[ebx+GLLight.enabled],0
334
	jne @f
315
	jne @f
335
		not ecx
316
		not ecx
336
	@@:
317
	@@:
337
	and ecx,[v]
318
	and ecx,[v]
338
	or ecx,ecx
319
	or ecx,ecx
339
	jz @f
320
	jz @f
340
		;if (v && !l.enabled)
321
		;if (v && !l.enabled)
341
		mov dword[ebx+offs_ligh_enabled],1
322
		mov dword[ebx+GLLight.enabled],1
342
		mov ecx,[eax+GLContext.first_light]
323
		mov ecx,[eax+GLContext.first_light]
343
		mov [ebx+offs_ligh_next],ecx
324
		mov [ebx+GLLight.next],ecx
344
		mov [eax+GLContext.first_light],ebx ;context.first_light = l
325
		mov [eax+GLContext.first_light],ebx ;context.first_light = l
345
		mov dword[ebx+offs_ligh_prev],0 ;l.prev = NULL
326
		mov dword[ebx+GLLight.prev],0 ;l.prev = NULL
346
		jmp .end_f
327
		jmp .end_f
347
align 4
328
align 4
348
	@@:
329
	@@:
349
	xor ecx,ecx
330
	xor ecx,ecx
350
	cmp dword[v],0
331
	cmp dword[v],0
351
	jne @f
332
	jne @f
352
		not ecx
333
		not ecx
353
	@@:
334
	@@:
354
	and ecx,[ebx+offs_ligh_enabled]
335
	and ecx,[ebx+GLLight.enabled]
355
	or ecx,ecx
336
	or ecx,ecx
356
	jz .end_f
337
	jz .end_f
357
		;else if (!v && l.enabled)
338
		;else if (!v && l.enabled)
358
		mov dword[ebx+offs_ligh_enabled],0 ;l.enabled = 0
339
		mov dword[ebx+GLLight.enabled],0 ;l.enabled = 0
359
		mov ecx,[ebx+offs_ligh_next]
340
		mov ecx,[ebx+GLLight.next]
360
		cmp dword[ebx+offs_ligh_prev],0 ;if (l.prev == NULL)
341
		cmp dword[ebx+GLLight.prev],0 ;if (l.prev == NULL)
361
		jne .els_0
342
		jne .els_0
362
			mov [eax+GLContext.first_light],ecx	;context.first_light = l.next
343
			mov [eax+GLContext.first_light],ecx	;context.first_light = l.next
363
			jmp @f
344
			jmp @f
364
align 4
345
align 4
365
		.els_0:
346
		.els_0:
366
			mov eax,[ebx+offs_ligh_prev]
347
			mov eax,[ebx+GLLight.prev]
367
			mov [eax+offs_ligh_next],ecx ;l.prev.next = l.next
348
			mov [eax+GLLight.next],ecx ;l.prev.next = l.next
368
		@@:
349
		@@:
369
		cmp dword[ebx+offs_ligh_next],0
350
		cmp dword[ebx+GLLight.next],0
370
		je .end_f
351
		je .end_f
371
			mov ecx,[ebx+offs_ligh_prev]
352
			mov ecx,[ebx+GLLight.prev]
372
			mov eax,[ebx+offs_ligh_next]
353
			mov eax,[ebx+GLLight.next]
373
			mov [eax+offs_ligh_prev],ecx ;l.next.prev = l.prev
354
			mov [eax+GLLight.prev],ecx ;l.next.prev = l.prev
374
	.end_f:
355
	.end_f:
375
	ret
356
	ret
Line 376... Line 357...
376
endp
357
endp
Line 418... Line 399...
418
	mov ecx,edx
399
	mov ecx,edx
419
	add ecx,GLContext.materials ;ecx(m) = &context.materials[0]
400
	add ecx,GLContext.materials ;ecx(m) = &context.materials[0]
420
	mov eax,[edx+GLContext.light_model_two_side]
401
	mov eax,[edx+GLContext.light_model_two_side]
421
	mov [twoside],eax
402
	mov [twoside],eax
Line 422... Line 403...
422
 
403
 
423
	add esi,offs_vert_normal
-
 
424
	mov edi,ebp
404
	add esi,GLVertex.normal
425
	sub edi,24 ;edi = &n
405
	lea edi,[ebp-24] ;edi = &n
426
	movsd ;n.X=v.normal.X
406
	movsd ;n.X=v.normal.X
427
	movsd ;n.Y=v.normal.Y
407
	movsd ;n.Y=v.normal.Y
428
	movsd ;n.Z=v.normal.Z
408
	movsd ;n.Z=v.normal.Z
Line 429... Line 409...
429
	mov esi,[v]
409
	mov esi,[v]
430
 
410
 
431
	fld dword[edx+GLContext.ambient_light_model]
411
	fld dword[edx+GLContext.ambient_light_model]
432
	fmul dword[ecx+offs_mate_ambient]
412
	fmul dword[ecx+GLMaterial.ambient]
433
	fadd dword[ecx] ;offs_mate_emission=0
413
	fadd dword[ecx] ;GLMaterial.emission=0
434
	fstp dword[R] ;R=m.emission.v[0]+m.ambient.v[0]*context.ambient_light_model.v[0]
414
	fstp dword[R] ;R=m.emission.v[0]+m.ambient.v[0]*context.ambient_light_model.v[0]
435
	fld dword[edx+GLContext.ambient_light_model+4]
415
	fld dword[edx+GLContext.ambient_light_model+4]
436
	fmul dword[ecx+offs_mate_ambient+4]
416
	fmul dword[ecx+GLMaterial.ambient+4]
437
	fadd dword[ecx+offs_mate_emission+4]
417
	fadd dword[ecx+GLMaterial.emission+4]
438
	fstp dword[G]
418
	fstp dword[G]
439
	fld dword[edx+GLContext.ambient_light_model+8]
419
	fld dword[edx+GLContext.ambient_light_model+8]
440
	fmul dword[ecx+offs_mate_ambient+8]
420
	fmul dword[ecx+GLMaterial.ambient+8]
441
	fadd dword[ecx+offs_mate_emission+8]
421
	fadd dword[ecx+GLMaterial.emission+8]
442
	fstp dword[B]
422
	fstp dword[B]
Line 443... Line 423...
443
	clampf [ecx+offs_mate_diffuse+12],0,1
423
	clampf [ecx+GLMaterial.diffuse+12],0,1
444
	mov [A],eax ;A=clampf(m.diffuse.v[3],0,1)
424
	mov [A],eax ;A=clampf(m.diffuse.v[3],0,1)
445
 
425
 
446
	mov ebx,[edx+GLContext.first_light]
426
	mov ebx,[edx+GLContext.first_light]
Line 447... Line 427...
447
	.cycle_0: ;for(l=context.first_light;l!=NULL;l=l.next)
427
	.cycle_0: ;for(l=context.first_light;l!=NULL;l=l.next)
448
		or ebx,ebx
428
		or ebx,ebx
449
		jz .cycle_0_end
429
		jz .cycle_0_end
450
 
430
 
451
		; ambient
431
		; ambient
452
		fld dword[ecx+offs_mate_ambient]
432
		fld dword[ecx+GLMaterial.ambient]
453
		fmul dword[ebx] ;offs_ligh_ambient=0
433
		fmul dword[ebx] ;GLLight.ambient=0
454
		fstp dword[lR] ;lR=l.ambient.v[0] * m.ambient.v[0]
434
		fstp dword[lR] ;lR=l.ambient.v[0] * m.ambient.v[0]
455
		fld dword[ecx+offs_mate_ambient+4]
435
		fld dword[ecx+GLMaterial.ambient+4]
456
		fmul dword[ebx+offs_ligh_ambient+4]
436
		fmul dword[ebx+GLLight.ambient+4]
Line 457... Line 437...
457
		fstp dword[lG] ;lG=l.ambient.v[1] * m.ambient.v[1]
437
		fstp dword[lG] ;lG=l.ambient.v[1] * m.ambient.v[1]
458
		fld dword[ecx+offs_mate_ambient+8]
438
		fld dword[ecx+GLMaterial.ambient+8]
459
		fmul dword[ebx+offs_ligh_ambient+8]
439
		fmul dword[ebx+GLLight.ambient+8]
460
		fstp dword[lB] ;lB=l.ambient.v[2] * m.ambient.v[2]
440
		fstp dword[lB] ;lB=l.ambient.v[2] * m.ambient.v[2]
461
 
441
 
462
		fld dword[ebx+offs_ligh_position+offs_W]
442
		fld dword[ebx+GLLight.position+offs_W]
463
		ftst ;if (l.position.v[3] == 0)
443
		ftst ;if (l.position.v[3] == 0)
464
		fstsw ax
444
		fstsw ax
465
		sahf
445
		sahf
466
		jne .els_0
446
		jne .els_0
467
			; light at infinity
447
			; light at infinity
468
			ffree st0 ;l.position.v[3]
448
			ffree st0 ;l.position.v[3]
469
			fincstp
449
			fincstp
470
			mov eax,[ebx+offs_ligh_norm_position]
450
			mov eax,[ebx+GLLight.norm_position]
471
			mov [d],eax ;d.X=l.norm_position.v[0]
451
			mov [d],eax ;d.X=l.norm_position.v[0]
472
			mov eax,[ebx+offs_ligh_norm_position+offs_Y]
452
			mov eax,[ebx+GLLight.norm_position+offs_Y]
473
			mov [d+offs_Y],eax ;d.Y=l.norm_position.v[1]
453
			mov [d+offs_Y],eax ;d.Y=l.norm_position.v[1]
474
			mov eax,[ebx+offs_ligh_norm_position+offs_Z]
454
			mov eax,[ebx+GLLight.norm_position+offs_Z]
475
			mov [d+offs_Z],eax ;d.Z=l.norm_position.v[2]
455
			mov [d+offs_Z],eax ;d.Z=l.norm_position.v[2]
476
			mov dword[att],1.0
456
			mov dword[att],1.0
477
			jmp .els_0_end
457
			jmp .els_0_end
478
align 4
458
align 4
479
		.els_0:
459
		.els_0:
480
			; distance attenuation
460
			; distance attenuation
481
			ffree st0 ;l.position.v[3]
461
			ffree st0 ;l.position.v[3]
482
			fincstp
462
			fincstp
483
			fld dword[ebx+offs_ligh_position]
463
			fld dword[ebx+GLLight.position]
484
			fsub dword[esi+offs_vert_ec]
464
			fsub dword[esi+GLVertex.ec]
485
			fstp dword[d] ;d.X=l.position.v[0]-v.ec.v[0]
465
			fstp dword[d] ;d.X=l.position.v[0]-v.ec.v[0]
486
			fld dword[ebx+offs_ligh_position+offs_Y]
466
			fld dword[ebx+GLLight.position+offs_Y]
487
			fsub dword[esi+offs_vert_ec+offs_Y]
467
			fsub dword[esi+GLVertex.ec+offs_Y]
488
			fstp dword[d+offs_Y] ;d.Y=l.position.v[1]-v.ec.v[1]
468
			fstp dword[d+offs_Y] ;d.Y=l.position.v[1]-v.ec.v[1]
489
			fld dword[ebx+offs_ligh_position+offs_Z]
469
			fld dword[ebx+GLLight.position+offs_Z]
490
			fsub dword[esi+offs_vert_ec+offs_Z]
470
			fsub dword[esi+GLVertex.ec+offs_Z]
Line 514... Line 494...
514
				fmul st0,st1
494
				fmul st0,st1
515
				fstp dword[d+offs_Z]
495
				fstp dword[d+offs_Z]
516
				ffree st0 ;1.0/dist
496
				ffree st0 ;1.0/dist
517
				fincstp
497
				fincstp
518
			@@:
498
			@@:
519
			fld dword[ebx+offs_ligh_attenuation+8]
499
			fld dword[ebx+GLLight.attenuation+8]
520
			fmul st0,st1 ;st0 = dist * l.attenuation[2]
500
			fmul st0,st1 ;st0 = dist * l.attenuation[2]
521
			fadd dword[ebx+offs_ligh_attenuation+4]
501
			fadd dword[ebx+GLLight.attenuation+4]
522
			fmul st0,st1
502
			fmul st0,st1
523
			fadd dword[ebx+offs_ligh_attenuation]
503
			fadd dword[ebx+GLLight.attenuation]
524
			fld1
504
			fld1
525
			fdiv st0,st1
505
			fdiv st0,st1
526
			fstp dword[att] ;att = 1.0f/(l.attenuation[0]+dist*(l.attenuation[1]+dist*l.attenuation[2]))
506
			fstp dword[att] ;att = 1.0f/(l.attenuation[0]+dist*(l.attenuation[1]+dist*l.attenuation[2]))
527
			ffree st0 ;1.0
507
			ffree st0 ;1.0
528
			fincstp
508
			fincstp
Line 548... Line 528...
548
		ftst ;if (dot>0)
528
		ftst ;if (dot>0)
549
		fstsw ax
529
		fstsw ax
550
		sahf
530
		sahf
551
		jbe .if0_end
531
		jbe .if0_end
552
			; diffuse light
532
			; diffuse light
553
			fld dword[ecx+offs_mate_diffuse]
533
			fld dword[ecx+GLMaterial.diffuse]
554
			fmul dword[ebx+offs_ligh_diffuse]
534
			fmul dword[ebx+GLLight.diffuse]
555
			fmul st0,st1
535
			fmul st0,st1
556
			fadd dword[lR]
536
			fadd dword[lR]
557
			fstp dword[lR] ;lR+=dot * l.diffuse.v[0] * m.diffuse.v[0]
537
			fstp dword[lR] ;lR+=dot * l.diffuse.v[0] * m.diffuse.v[0]
558
			fld dword[ecx+offs_mate_diffuse+4]
538
			fld dword[ecx+GLMaterial.diffuse+4]
559
			fmul dword[ebx+offs_ligh_diffuse+4]
539
			fmul dword[ebx+GLLight.diffuse+4]
560
			fmul st0,st1
540
			fmul st0,st1
561
			fadd dword[lG]
541
			fadd dword[lG]
562
			fstp dword[lG] ;lG+=dot * l.diffuse.v[1] * m.diffuse.v[1]
542
			fstp dword[lG] ;lG+=dot * l.diffuse.v[1] * m.diffuse.v[1]
563
			fld dword[ecx+offs_mate_diffuse+8]
543
			fld dword[ecx+GLMaterial.diffuse+8]
564
			fmul dword[ebx+offs_ligh_diffuse+8]
544
			fmul dword[ebx+GLLight.diffuse+8]
565
			fmul st0,st1
545
			fmul st0,st1
566
			fadd dword[lB]
546
			fadd dword[lB]
567
			fstp dword[lB] ;lB+=dot * l.diffuse.v[2] * m.diffuse.v[2]
547
			fstp dword[lB] ;lB+=dot * l.diffuse.v[2] * m.diffuse.v[2]
568
			ffree st0 ;dot
548
			ffree st0 ;dot
569
			fincstp
549
			fincstp
Line 570... Line 550...
570
 
550
 
571
			; spot light
551
			; spot light
572
			fld dword[ebx+offs_ligh_spot_cutoff]
552
			fld dword[ebx+GLLight.spot_cutoff]
573
			fcomp dword[an180f] ;if (l.spot_cutoff != 180)
553
			fcomp dword[an180f] ;if (l.spot_cutoff != 180)
574
			fstsw ax
554
			fstsw ax
575
			sahf
555
			sahf
576
			je .if1_end
556
			je .if1_end
577
				fld dword[ebx+offs_ligh_norm_spot_direction]
557
				fld dword[ebx+GLLight.norm_spot_direction]
578
				fmul dword[d]
558
				fmul dword[d]
579
				fld dword[ebx+offs_ligh_norm_spot_direction+offs_Y]
559
				fld dword[ebx+GLLight.norm_spot_direction+offs_Y]
580
				fmul dword[d+offs_Y]
560
				fmul dword[d+offs_Y]
581
				faddp
561
				faddp
582
				fld dword[ebx+offs_ligh_norm_spot_direction+offs_Z]
562
				fld dword[ebx+GLLight.norm_spot_direction+offs_Z]
583
				fmul dword[d+offs_Z]
563
				fmul dword[d+offs_Z]
584
				faddp
564
				faddp
585
				fchs
565
				fchs
586
				fst dword[dot_spot]
566
				fst dword[dot_spot]
Line 590... Line 570...
590
				fstsw ax
570
				fstsw ax
591
				sahf
571
				sahf
592
				jae @f
572
				jae @f
593
					fchs ;dot_spot = -dot_spot
573
					fchs ;dot_spot = -dot_spot
594
				@@:
574
				@@:
595
				fcom dword[ebx+offs_ligh_cos_spot_cutoff] ;if (dot_spot < l.cos_spot_cutoff)
575
				fcom dword[ebx+GLLight.cos_spot_cutoff] ;if (dot_spot < l.cos_spot_cutoff)
596
				fstsw ax
576
				fstsw ax
597
				sahf
577
				sahf
598
				jae .els_1
578
				jae .els_1
599
					; no contribution
579
					; no contribution
600
					ffree st0 ;dot_spot
580
					ffree st0 ;dot_spot
601
					fincstp
581
					fincstp
602
					mov ebx,[ebx+offs_ligh_next]
582
					mov ebx,[ebx+GLLight.next]
603
					jmp .cycle_0 ;continue
583
					jmp .cycle_0 ;continue
604
align 4
584
align 4
605
				.els_1:
585
				.els_1:
606
					; TODO: optimize
586
					; TODO: optimize
607
					fld dword[ebx+offs_ligh_spot_exponent]
587
					fld dword[ebx+GLLight.spot_exponent]
608
					ftst ;if (l.spot_exponent > 0)
588
					ftst ;if (l.spot_exponent > 0)
609
					fstsw ax
589
					fstsw ax
610
					sahf
590
					sahf
611
					jbe @f
591
					jbe @f
612
						fxch st1 ;dot_spot <--> l.spot_exponent
592
						fxch st1 ;dot_spot <--> l.spot_exponent
Line 637... Line 617...
637
			.if1_end:
617
			.if1_end:
Line 638... Line 618...
638
 
618
 
639
			; specular light
619
			; specular light
640
			cmp dword[edx+GLContext.local_light_model],0 ;if (c.local_light_model)
620
			cmp dword[edx+GLContext.local_light_model],0 ;if (c.local_light_model)
641
			je .els_2
621
			je .els_2
642
				mov eax,[esi+offs_vert_ec]
622
				mov eax,[esi+GLVertex.ec]
643
				mov [vcoord],eax ;vcoord.X=v.ec.X
623
				mov [vcoord],eax ;vcoord.X=v.ec.X
644
				mov eax,[esi+offs_vert_ec+offs_Y]
624
				mov eax,[esi+GLVertex.ec+offs_Y]
645
				mov [vcoord+offs_Y],eax ;vcoord.Y=v.ec.Y
625
				mov [vcoord+offs_Y],eax ;vcoord.Y=v.ec.Y
646
				mov eax,[esi+offs_vert_ec+offs_Z]
626
				mov eax,[esi+GLVertex.ec+offs_Z]
647
				mov [vcoord+offs_Z],eax ;vcoord.Z=v.ec.Z
-
 
648
				mov eax,ebp
627
				mov [vcoord+offs_Z],eax ;vcoord.Z=v.ec.Z
649
				sub eax,12 ;eax = &vcoord
628
				lea eax,[ebp-12] ;eax = &vcoord
650
				stdcall gl_V3_Norm, eax
629
				stdcall gl_V3_Norm, eax
651
				fld dword[d]
630
				fld dword[d]
652
				fsub dword[vcoord]
631
				fsub dword[vcoord]
653
				fstp dword[s] ;s.X=d.X-vcoord.X
632
				fstp dword[s] ;s.X=d.X-vcoord.X
Line 707... Line 686...
707
				fincstp
686
				fincstp
Line 708... Line 687...
708
 
687
 
709
				; TODO: optimize
688
				; TODO: optimize
710
				; testing specular buffer code
689
				; testing specular buffer code
711
				; dot_spec= pow(dot_spec,m.shininess)
690
				; dot_spec= pow(dot_spec,m.shininess)
712
				stdcall specbuf_get_buffer, edx, dword[ecx+offs_mate_shininess_i], dword[ecx+offs_mate_shininess]
691
				stdcall specbuf_get_buffer, edx, dword[ecx+GLMaterial.shininess_i], dword[ecx+GLMaterial.shininess]
713
				mov edi,eax ;edi = specbuf
692
				mov edi,eax ;edi = specbuf
Line 714... Line 693...
714
				mov dword[idx],SPECULAR_BUFFER_SIZE ;idx = SPECULAR_BUFFER_SIZE
693
				mov dword[idx],SPECULAR_BUFFER_SIZE ;idx = SPECULAR_BUFFER_SIZE
715
 
694
 
Line 722... Line 701...
722
					mov dword[idx],SPECULAR_BUFFER_SIZE
701
					mov dword[idx],SPECULAR_BUFFER_SIZE
723
				@@:
702
				@@:
724
				shl dword[idx],2
703
				shl dword[idx],2
725
				add edi,dword[idx]
704
				add edi,dword[idx]
726
				fld dword[edi+offs_spec_buf] ;dot_spec = specbuf.buf[idx]
705
				fld dword[edi+offs_spec_buf] ;dot_spec = specbuf.buf[idx]
727
				fld dword[ebx+offs_ligh_specular]
706
				fld dword[ebx+GLLight.specular]
728
				fmul st0,st1
707
				fmul st0,st1
729
				fmul dword[ecx+offs_mate_specular]
708
				fmul dword[ecx+GLMaterial.specular]
730
				fadd dword[lR]
709
				fadd dword[lR]
731
				fstp dword[lR] ;lR+=dot_spec * l.specular.v[0] * m.specular.v[0]
710
				fstp dword[lR] ;lR+=dot_spec * l.specular.v[0] * m.specular.v[0]
732
				fld dword[ebx+offs_ligh_specular+4]
711
				fld dword[ebx+GLLight.specular+4]
733
				fmul st0,st1
712
				fmul st0,st1
734
				fmul dword[ecx+offs_mate_specular+4]
713
				fmul dword[ecx+GLMaterial.specular+4]
735
				fadd dword[lG]
714
				fadd dword[lG]
736
				fstp dword[lG] ;lG+=dot_spec * l.specular.v[1] * m.specular.v[1]
715
				fstp dword[lG] ;lG+=dot_spec * l.specular.v[1] * m.specular.v[1]
737
				fld dword[ebx+offs_ligh_specular+8]
716
				fld dword[ebx+GLLight.specular+8]
738
				fmul st0,st1
717
				fmul st0,st1
739
				fmul dword[ecx+offs_mate_specular+8]
718
				fmul dword[ecx+GLMaterial.specular+8]
740
				fadd dword[lB]
719
				fadd dword[lB]
741
				fstp dword[lB] ;lB+=dot_spec * l.specular.v[2] * m.specular.v[2]
720
				fstp dword[lB] ;lB+=dot_spec * l.specular.v[2] * m.specular.v[2]
742
		.if0_end:
721
		.if0_end:
743
		ffree st0 ;dot [or] dot_spec
722
		ffree st0 ;dot [or] dot_spec
744
		fincstp
723
		fincstp
Line 757... Line 736...
757
		fmul st0,st1
736
		fmul st0,st1
758
		fadd dword[B]
737
		fadd dword[B]
759
		fstp dword[B] ;B += att * lB
738
		fstp dword[B] ;B += att * lB
760
		ffree st0 ;att
739
		ffree st0 ;att
761
		fincstp
740
		fincstp
762
		mov ebx,[ebx+offs_ligh_next]
741
		mov ebx,[ebx+GLLight.next]
763
		jmp .cycle_0
742
		jmp .cycle_0
764
align 4
743
align 4
765
	.cycle_0_end:
744
	.cycle_0_end:
Line 766... Line 745...
766
 
745
 
767
	clampf [R],0,1
746
	clampf [R],0,1
768
	mov [esi+offs_vert_color],eax ;v.color.v[0]=clampf(R,0,1)
747
	mov [esi+GLVertex.color],eax ;v.color.v[0]=clampf(R,0,1)
769
	clampf [G],0,1
748
	clampf [G],0,1
770
	mov [esi+offs_vert_color+4],eax ;v.color.v[1]=clampf(G,0,1)
749
	mov [esi+GLVertex.color+4],eax ;v.color.v[1]=clampf(G,0,1)
771
	clampf [B],0,1
750
	clampf [B],0,1
772
	mov [esi+offs_vert_color+8],eax ;v.color.v[2]=clampf(B,0,1)
751
	mov [esi+GLVertex.color+8],eax ;v.color.v[2]=clampf(B,0,1)
773
	mov eax,[A]
752
	mov eax,[A]
774
	mov [esi+offs_vert_color+12],eax ;v.color.v[3]=A
753
	mov [esi+GLVertex.color+12],eax ;v.color.v[3]=A
775
popad
754
popad
776
	ret
755
	ret