Subversion Repositories Kolibri OS

Rev

Rev 5218 | Rev 5262 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5218 Rev 5256
Line 1... Line -...
1
;include 'msghandling.inc'
-
 
Line 2... Line 1...
2
 
1
align 4
3
align 4
2
proc glopMaterial uses eax ebx ecx edi esi, context:dword, p:dword
4
proc glopMaterial, context:dword, p:dword
3
; edi -> GLMaterial *m
5
;  int mode=p[1].i;
-
 
6
;  int type=p[2].i;
4
	mov eax,[context]
7
;  float *v=&p[3].f;
5
	mov ebx,[p]
8
;  int i;
6
	mov ecx,[ebx+4] ;ecx = p[1]
9
;  GLMaterial *m;
7
 
10
 
8
	cmp ecx,GL_FRONT_AND_BACK ;if (mode == GL_FRONT_AND_BACK)
-
 
9
	jne @f
11
;  if (mode == GL_FRONT_AND_BACK) {
10
		mov dword[ebx+4],GL_FRONT ;p[1].i=GL_FRONT
-
 
11
		mov edi,ebp
-
 
12
		add edi,12
12
;    p[1].i=GL_FRONT;
13
		stdcall glopMaterial,eax,edi
13
;    glopMaterial(c,p);
14
		mov ecx,GL_BACK
14
;    mode=GL_BACK;
15
	@@:
-
 
16
	mov edi,[eax+offs_cont_materials]
15
;  }
17
	cmp ecx,GL_FRONT ;if (mode == GL_FRONT) m=&context.materials[0]
-
 
18
	je @f
16
;  if (mode == GL_FRONT) m=&c->materials[0];
19
		add edi,sizeof.GLMaterial ;else m=&context.materials[1]
-
 
20
	@@:
17
;  else m=&c->materials[1];
21
 
-
 
22
	mov ecx,4
18
 
23
	mov esi,ebx ;esi = &p
-
 
24
	add esi,12 ;esi = &p[3]
-
 
25
	mov ebx,[ebx+8] ;ebx = p[2]
19
;  switch(type) {
26
	cmp ebx,GL_EMISSION
20
;  case GL_EMISSION:
27
	jne @f
21
;    for(i=0;i<4;i++)
28
		;add edi,offs_mate_emission ;offs_mate_emission=0
-
 
29
		rep movsd
22
;      m->emission.v[i]=v[i];
30
		jmp .end_f
-
 
31
	@@:
23
;    break;
32
	cmp ebx,GL_AMBIENT
-
 
33
	jne @f
24
;  case GL_AMBIENT:
34
		add edi,offs_mate_ambient
25
;    for(i=0;i<4;i++)
35
		rep movsd
26
;      m->ambient.v[i]=v[i];
36
		jmp .end_f
-
 
37
	@@:
27
;    break;
38
	cmp ebx,GL_DIFFUSE
-
 
39
	jne @f
28
;  case GL_DIFFUSE:
40
		add edi,offs_mate_diffuse
29
;    for(i=0;i<4;i++)
41
		rep movsd
30
;      m->diffuse.v[i]=v[i];
42
		jmp .end_f
-
 
43
	@@:
31
;    break;
44
	cmp ebx,GL_SPECULAR
32
;  case GL_SPECULAR:
45
	jne @f
33
;    for(i=0;i<4;i++)
46
		add edi,offs_mate_specular
-
 
47
		rep movsd
34
;      m->specular.v[i]=v[i];
48
		jmp .end_f
-
 
49
	@@:
35
;    break;
50
	cmp ebx,GL_SHININESS
-
 
51
	jne @f
-
 
52
		fld dword[esi]
36
;  case GL_SHININESS:
53
		add edi,offs_mate_shininess
-
 
54
		movsd
-
 
55
		mov dword[edi],SPECULAR_BUFFER_RESOLUTION
-
 
56
		fdiv dword[an180f]
-
 
57
		fimul dword[edi]
37
;    m->shininess=v[0];
58
		fistp dword[edi] ;m.shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION
38
;    m->shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION;
59
		jmp .end_f
-
 
60
	@@:
39
;    break;
61
	cmp ebx,GL_AMBIENT_AND_DIFFUSE
-
 
62
	jne @f
40
;  case GL_AMBIENT_AND_DIFFUSE:
63
		add edi,offs_mate_ambient
-
 
64
		rep movsd
-
 
65
		sub esi,16
41
;    for(i=0;i<4;i++)
66
		;edi = &offs_mate_diffuse
42
;      m->diffuse.v[i]=v[i];
67
		mov ecx,4
43
;    for(i=0;i<4;i++)
68
		rep movsd
44
;      m->ambient.v[i]=v[i];
69
		jmp .end_f
45
;    break;
70
	@@: ;default
46
;  default:
71
;    assert(0);
47
;    assert(0);
72
	.end_f:
48
;  }
73
	ret
49
	ret
74
endp
Line 50... Line 75...
50
endp
75
 
51
 
76
align 4
Line 59... Line 84...
59
	mov dword[eax+offs_cont_current_color_material_type],ecx
84
	ret
60
	ret
85
endp
61
endp
86
 
Line 62... Line 87...
62
 
87
align 4
63
align 4
88
proc glopLight context:dword, p:dword
-
 
89
locals
-
 
90
	pos V4
-
 
91
endl
-
 
92
pushad
64
proc glopLight uses eax ebx ecx edx, context:dword, p:dword
93
	mov eax,[context]
65
	mov eax,[context]
94
	mov ebx,[p]
66
	mov ebx,[p]
95
	mov edx,[ebx+4] ;edx = p[1]
Line 67... Line -...
67
	mov edx,[ebx+4] ;edx = p[1]
-
 
68
 
-
 
69
;  V4 v;
96
 
Line 70... Line 97...
70
 
97
;  assert(edx >= GL_LIGHT0 && edx < GL_LIGHT0+MAX_LIGHTS );
71
;  assert(edx >= GL_LIGHT0 && edx < GL_LIGHT0+MAX_LIGHTS );
98
 
72
 
99
	sub edx,GL_LIGHT0
Line 106... Line 133...
106
		rep movsd ;l.specular=v
133
		jmp .end_f
107
		jmp .end_f
134
	@@:
108
	@@:
135
	cmp ecx,GL_POSITION
109
	cmp ecx,GL_POSITION
136
	jne @f
110
	jne @f
137
		mov edi,ebx ;ebx = [ebp+12] = [p] = &p[0]
-
 
138
		add edi,12 ;&p[3]
111
;    {
139
		mov esi,ebp
112
;  for(i=0;i<4;i++) v.v[i]=p[3+i].f;
140
		sub esi,16 ;&pos
113
;      V4 pos;
141
		stdcall gl_M4_MulV4, esi,dword[eax+offs_cont_matrix_stack_ptr],edi
114
;      gl_M4_MulV4(&pos,c->matrix_stack_ptr[0],&v);
142
		mov edi,edx
-
 
143
		add edi,offs_ligh_position
-
 
144
		mov ecx,4
115
;
145
		rep movsd ;l.position=pos
116
;      l->position=pos;
146
 
117
;
147
		fld dword[edi-4] ;if(l.position.v[3] == 0)
118
;      if (l->position.v[3] == 0) {
148
		ftst
-
 
149
		fstsw ax
-
 
150
		sahf
-
 
151
		jne .end_i
-
 
152
			;mov esi,ebp
-
 
153
			sub esi,16 ;&pos
119
;        l->norm_position.X=pos.X;
154
			mov edi,edx
-
 
155
			add edi,offs_ligh_norm_position
120
;        l->norm_position.Y=pos.Y;
156
			mov ecx,3
-
 
157
			rep movsd ;l.norm_position=pos[1,2,3]
121
;        l->norm_position.Z=pos.Z;
158
 
122
;        
159
			;mov edi,edx
-
 
160
			;add edi,offs_ligh_norm_position
-
 
161
			sub edi,12
-
 
162
			stdcall gl_V3_Norm,edi ;&l.norm_position
123
;        gl_V3_Norm(&l->norm_position);
163
		.end_i:
124
;      }
164
		ffree st0
-
 
165
		fincstp
125
;    }
166
		jmp .end_f
126
		jmp .end_f
167
	@@:
127
	@@:
168
	cmp ecx,GL_SPOT_DIRECTION
128
	cmp ecx,GL_SPOT_DIRECTION
169
	jne @f
129
	jne @f
170
		mov esi,ebx ;&p[0]
130
		mov esi,ebx
171
		add esi,12
131
		add esi,12
172
		mov edi,edx
132
		mov edi,edx
173
		add edi,offs_ligh_spot_direction
133
		add edi,offs_ligh_spot_direction
174
		mov ecx,3
134
		mov ecx,3
175
		rep movsd ;l.spot_direction=v[0,1,2]
135
		rep movsd ;l.spot_direction=v[0,1,2]
176
		mov esi,ebx
Line 148... Line 189...
148
		mov ecx,[ebx+12]
189
		mov [edi+offs_ligh_spot_exponent],ecx ;l.spot_exponent=p[3]
149
		mov [edi+offs_ligh_spot_exponent],ecx ;l.spot_exponent=p[3]
190
		jmp .end_f
150
		jmp .end_f
191
	@@:
151
	@@:
192
	cmp ecx,GL_SPOT_CUTOFF
152
	cmp ecx,GL_SPOT_CUTOFF
193
	jne .end_spot_c
153
	jne @f
194
		fld dword[ebp+12] ;float a=v.v[0]
154
;    {
-
 
155
;      float a=v.v[0];
195
;      assert(a == 180 || (a>=0 && a<=90));
156
;      assert(a == 180 || (a>=0 && a<=90));
196
		fst dword[edi+offs_ligh_spot_cutoff] ;l.spot_cutoff=a
157
;      l->spot_cutoff=a;
197
		fcom dword[an180f] ;if (a != 180)
158
;      if (a != 180) l->cos_spot_cutoff=cos(a * M_PI / 180.0);
198
		fstsw ax
-
 
199
		sahf
159
;    }
200
		jne @f
-
 
201
			fldpi
-
 
202
			fmulp
-
 
203
			fdiv dword[an180f]
-
 
204
			fcos
-
 
205
			fstp dword[edi+offs_ligh_spot_cutoff] ;l.cos_spot_cutoff=cos(a * M_PI / 180.0)
-
 
206
			jmp .end_f
160
		jmp .end_f
207
		@@:
161
	@@:
208
		ffree st0
-
 
209
		fincstp
-
 
210
		jmp .end_f
-
 
211
	.end_spot_c:
-
 
212
	cmp ecx,GL_CONSTANT_ATTENUATION
162
	cmp ecx,GL_CONSTANT_ATTENUATION
213
		mov ecx,[ebx+12]
163
		mov ecx,[ebx+12]
214
		mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3]
164
		mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3]
215
		jmp .end_f
165
		jmp .end_f
216
	@@:
166
	@@:
217
	cmp ecx,GL_LINEAR_ATTENUATION
Line 174... Line 225...
174
		mov [edi+offs_ligh_attenuation+8],ecx ;l->attenuation[2]=p[3]
225
		jmp .end_f
175
		jmp .end_f
226
	@@: ;default:
176
	@@: ;default:
227
;    assert(0);
177
;    assert(0);
228
	.end_f:
178
	.end_f:
229
popad
-
 
230
	ret
179
	ret
231
endp
180
endp
232
 
Line 181... Line 233...
181
 
233
  
182
  
234
align 4
183
align 4
235
proc glopLightModel uses ebx ecx esi edi, context:dword, p:dword
184
proc glopLightModel uses ebx ecx esi edi, context:dword, p:dword
236
	mov edi,[context]
185
	mov edi,[context]
237
	mov ebx,[p]
-
 
238
	mov ebx,[ebx+4]
-
 
239
	mov esi,[ebp+12] ;&p[0]
Line 186... Line 240...
186
	mov ebx,[p]
240
	add esi,8 ;&p[2]
187
	mov esi,[ebx+8]
241
 
188
 
242
	cmp ebx,GL_LIGHT_MODEL_AMBIENT
189
	cmp dword[ebx+4],GL_LIGHT_MODEL_AMBIENT
243
	jne @f
190
	jne @f
244
		mov ecx,4
191
		mov ecx,4
245
		add edi,offs_cont_ambient_light_model
192
		mov edi,dword[edi+offs_cont_ambient_light_model]
246
		rep movsd ;for(i=0;i<4;i++) context.ambient_light_model.v[i]=v[i]
193
		rep movsd ;for(i=0;i<4;i++) context.ambient_light_model.v[i]=v[i]
247
		jmp .end_f
194
		jmp .end_f
248
	@@:
195
	@@:
249
	cmp ebx,GL_LIGHT_MODEL_LOCAL_VIEWER
196
	cmp dword[ebx+4],GL_LIGHT_MODEL_LOCAL_VIEWER
250
	jne @f
197
	jne @f
251
		fld dword[esi] ;st0 = p[2]
198
		fld dword[esi] ;st0 = p[2].v[0]
252
		fistp dword[edi+offs_cont_local_light_model]
199
		fistp dword[edi+offs_cont_local_light_model]
253
		jmp .end_f
200
		jmp .end_f
254
	@@:
201
	@@:
255
	cmp ebx,GL_LIGHT_MODEL_TWO_SIDE
202
	cmp dword[ebx+4],GL_LIGHT_MODEL_TWO_SIDE
256
	jne @f
203
	jne @f
257
		fld dword[esi] ;st0 = p[2]
204
		fld dword[esi] ;st0 = p[2].v[0]
258
		fistp dword[edi+offs_cont_light_model_two_side]
205
		fistp dword[edi+offs_cont_light_model_two_side]
259
		jmp .end_f
206
		jmp .end_f
260
	@@: ;default:
207
	@@: ;default:
261
;    tgl_warning("glopLightModel: illegal pname: 0x%x\n", ebx);
208
;    tgl_warning("glopLightModel: illegal pname: 0x%x\n", dword[ebx+4]);
262
;    //assert(0);
209
;    //assert(0);
263
	.end_f:
Line 210... Line 264...
210
	.end_f:
264
	ret
211
	ret
265
endp
-
 
266
 
-
 
267
macro clampf a, min, max
-
 
268
{
-
 
269
local .o_1
-
 
270
local .o_2
-
 
271
local .end_m
-
 
272
	fld dword a ;if (a<=0.0)
-
 
273
	ftst
-
 
274
	fstsw ax
-
 
275
	sahf
-
 
276
	ja .o_1
212
endp
277
		ffree st0
-
 
278
		fincstp
-
 
279
		mov eax,0.0
-
 
280
		jmp .end_m ;return 0.0
-
 
281
	.o_1:
-
 
282
	fld1 ;else if (a>=1.0)
-
 
283
	fcompp
-
 
284
	fstsw ax
213
 
285
	sahf
-
 
286
	jb .o_2
214
;static inline float clampf(float a,float min,float max)
287
		mov eax,1.0
-
 
288
		jmp .end_m ;return 1.0
215
;{
289
	.o_2:
Line 216... Line 290...
216
;  if (a
290
	mov eax,dword a ;else return a
217
;  else if (a>max) return max;
291
	.end_m:
218
;  else return a;
292
}
219
;}
293
 
220
 
294
align 4
-
 
295
proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dword
221
align 4
296
	mov eax,[context]
Line 222... Line 297...
222
proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dword
297
	mov ebx,[light]
223
	mov eax,[context]
298
	imul ebx,sizeof.GLLight
224
	mov ebx,[light]
299
	add ebx,eax
225
	imul ebx,sizeof.GLLight
300
	add ebx,offs_cont_lights
226
	add ebx,[eax+offs_cont_lights]
301
 
227
 
302
	xor ecx,ecx
228
	xor ecx,ecx
303
	cmp dword[ebx+offs_ligh_enabled],0
229
	cmp dword[ebx+offs_ligh_enabled],0
304
	jne @f
230
	jne @f
305
		not ecx
231
		not ecx
306
	@@:
232
	@@:
307
	and ecx,[v]
233
	and ecx,[v]
308
	or ecx,ecx
234
	cmp ecx,0
309
	jz @f
Line 245... Line 320...
245
	cmp dword[v],0
320
	jne @f
246
	jne @f
321
		not ecx
247
		not ecx
322
	@@:
248
	@@:
323
	and ecx,[ebx+offs_ligh_enabled]
249
	and ecx,[ebx+offs_ligh_enabled]
324
	or ecx,ecx
250
	cmp ecx,0
325
	jz .end_f
251
	je .end_f
326
		;else if (!v && l.enabled)
252
		;else if (!v && l.enabled)
327
		mov dword[ebx+offs_ligh_enabled],0 ;l.enabled = 0
253
		mov dword[ebx+offs_ligh_enabled],0 ;l.enabled = 0
328
		mov ecx,[ebx+offs_ligh_next]
254
		mov ecx,[ebx+offs_ligh_next]
329
		cmp dword[ebx+offs_ligh_prev],0 ;if (l.prev == NULL)
255
		cmp dword[ebx+offs_ligh_prev],0 ;if (l.prev == NULL)
330
		jne .els_0
256
		jne .els_0
331
			mov [eax+offs_cont_first_light],ecx	;context.first_light = l.next
Line 267... Line 342...
267
			mov [eax+offs_ligh_prev],ecx ;l.next.prev = l.prev
342
	.end_f:
268
	.end_f:
343
	ret
269
	ret
344
endp
270
endp
345
 
Line -... Line 346...
-
 
346
align 4
-
 
347
fl_1e_3 dd 1.0e-3
-
 
348
 
271
 
349
; non optimized lightening model
272
; non optimized lightening model
350
align 4
273
align 4
351
proc gl_shade_vertex, context:dword, v:dword
-
 
352
locals
-
 
353
	R dd ? ;float
-
 
354
	G dd ? ;float
-
 
355
	B dd ? ;float
-
 
356
	A dd ? ;float
-
 
357
	s V3
-
 
358
	d V3
-
 
359
	dist dd ? ;float
-
 
360
	tmp dd ? ;float
-
 
361
	att dd ? ;float
-
 
362
	dot_spot dd ? ;float
-
 
363
	lR dd ? ;float
-
 
364
	lB dd ? ;float
-
 
365
	lG dd ? ;float
-
 
366
	twoside dd ? ;int
-
 
367
	idx dd ? ;int
-
 
368
	n V3 ;ebp-24
-
 
369
	vcoord V3 ;ebp-12
-
 
370
endl
-
 
371
pushad
-
 
372
; ebx -> GLLight *l
-
 
373
; ecx -> GLMaterial *m
-
 
374
; esi -> GLVertex *v
-
 
375
	mov esi,[v]
-
 
376
	mov edx,[context]
-
 
377
	mov ecx,[edx+offs_cont_materials] ;ecx(m) = &context.materials[0]
-
 
378
	mov eax,[edx+offs_cont_light_model_two_side]
-
 
379
	mov [twoside],eax
-
 
380
 
-
 
381
	add esi,offs_vert_normal
-
 
382
	mov edi,ebp
-
 
383
	sub edi,24 ;edi = &n
-
 
384
	movsd ;n.X=v.normal.X
-
 
385
	movsd ;n.Y=v.normal.Y
-
 
386
	movsd ;n.Z=v.normal.Z
-
 
387
	mov esi,[v]
-
 
388
 
-
 
389
	fld dword[edx+offs_cont_ambient_light_model]
-
 
390
	fmul dword[ecx+offs_mate_ambient]
-
 
391
	fadd dword[ecx] ;offs_mate_emission=0
-
 
392
	fstp dword[R] ;R=m.emission.v[0]+m.ambient.v[0]*context.ambient_light_model.v[0]
-
 
393
	fld dword[edx+offs_cont_ambient_light_model+4]
-
 
394
	fmul dword[ecx+offs_mate_ambient+4]
-
 
395
	fadd dword[ecx+offs_mate_emission+4]
-
 
396
	fstp dword[G]
-
 
397
	fld dword[edx+offs_cont_ambient_light_model+8]
-
 
398
	fmul dword[ecx+offs_mate_ambient+8]
-
 
399
	fadd dword[ecx+offs_mate_emission+8]
-
 
400
	fstp dword[B]
-
 
401
	clampf [ecx+offs_mate_diffuse+12],0,1
-
 
402
	mov [A],eax ;A=clampf(m.diffuse.v[3],0,1)
-
 
403
 
-
 
404
	mov ebx,[edx+offs_cont_first_light]
-
 
405
	.cycle_0: ;for(l=context.first_light;l!=NULL;l=l.next)
-
 
406
		or ebx,ebx
-
 
407
		jz .cycle_0_end
-
 
408
 
-
 
409
		; ambient
-
 
410
		fld dword[ecx+offs_mate_ambient]
-
 
411
		fmul dword[ebx+offs_ligh_ambient]
-
 
412
		fstp dword[lR] ;lR=l.ambient.v[0] * m.ambient.v[0]
-
 
413
		fld dword[ecx+offs_mate_ambient+4]
-
 
414
		fmul dword[ebx+offs_ligh_ambient+4]
-
 
415
		fstp dword[lG] ;lG=l.ambient.v[1] * m.ambient.v[1]
-
 
416
		fld dword[ecx+offs_mate_ambient+8]
-
 
417
		fmul dword[ebx+offs_ligh_ambient+8]
-
 
418
		fstp dword[lB] ;lB=l.ambient.v[2] * m.ambient.v[2]
Line 394... Line 727...
394
;  v->color.v[2]=clampf(B,0,1);
727
popad
395
;  v->color.v[3]=A;
728
	ret