Subversion Repositories Kolibri OS

Rev

Rev 5153 | Rev 5269 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5153 IgorA 1
 
2
align 4
3
proc gl_print_matrix uses eax ebx ecx edi, m:dword, rows:dword
4
	mov ecx,[rows]
5
	cmp ecx,1
6
	jl .end_f
7
	mov ebx,[m]
8
	mov word[NumberSymbolsAD],3
9
	finit
10
	@@:
11
		lea edi,[buf_param]
12
		mov byte[edi],0
13
14
 
15
		fstp qword[Data_Double]
16
		call DoubleFloat_to_String
17
		stdcall str_cat, edi,Data_String
18
19
 
20
		stdcall str_len,edi
21
		add edi,eax
22
23
 
24
		fstp qword[Data_Double]
25
		call DoubleFloat_to_String
26
		stdcall str_cat, edi,Data_String
27
28
 
29
		stdcall str_len,edi
30
		add edi,eax
31
32
 
33
		fstp qword[Data_Double]
34
		call DoubleFloat_to_String
35
		stdcall str_cat, edi,Data_String
36
37
 
38
		stdcall str_len,edi
39
		add edi,eax
40
41
 
42
		fstp qword[Data_Double]
43
		call DoubleFloat_to_String
44
		stdcall str_cat, edi,Data_String
45
46
 
47
		stdcall dbg_print,txt_sp,buf_param
48
49
 
50
	dec ecx
51
	cmp ecx,0
52
	jg @b
53
	.end_f:
54
	ret
55
endp
56
end if
57
58
 
59
{
60
	local .end_0
61
	xor reg,reg
62
	cmp dword[context+offs_cont_matrix_mode],1
63
	jg .end_0
64
		inc reg
65
	.end_0:
66
	mov dword[context+offs_cont_matrix_model_projection_updated],reg
67
}
68
69
 
70
proc glopMatrixMode uses eax ebx, context:dword, p:dword
71
	mov eax,[context]
72
	mov ebx,[p]
73
74
 
75
	jne @f
76
		mov dword[eax+offs_cont_matrix_mode],0
77
		jmp .end_f
78
	@@:
79
	cmp dword[ebx+4],GL_PROJECTION
80
	jne @f
81
		mov dword[eax+offs_cont_matrix_mode],1
82
		jmp .end_f
83
	@@:
84
	cmp dword[ebx+4],GL_TEXTURE
85
	jne .def
86
		mov dword[eax+offs_cont_matrix_mode],2
87
		jmp .end_f
88
	.def:
89
;assert(0);
90
	.end_f:
91
	ret
92
endp
93
94
 
95
proc glopLoadMatrix uses eax edi esi, context:dword, p:dword
96
	mov eax,[context]
97
	mov edi,[eax+offs_cont_matrix_mode]
98
	shl edi,2
99
	add edi,eax
100
	mov edi,dword[edi+offs_cont_matrix_stack_ptr]
101
102
 
103
	add esi,4
104
	stdcall gl_M4_Transpose,edi,esi ;транспонируем входную матрицу в матрицу context.matrix_stack_ptr[context.matrix_mode]
105
106
 
107
	ret
108
endp
109
110
 
111
proc glopLoadIdentity uses eax ebx, context:dword, p:dword
112
	mov eax,[context]
113
	mov ebx,[eax+offs_cont_matrix_mode]
114
	shl ebx,2
115
	add ebx,eax
116
117
 
118
if DEBUG ;glopLoadIdentity
119
	stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4
120
end if
121
	gl_matrix_update eax,ebx
122
	ret
123
endp
124
125
 
126
proc glopMultMatrix uses eax edi esi, context:dword, p:dword
127
locals
128
	m M4
129
endl
130
	mov esi,[p]
131
	add esi,4
132
	mov edi,ebp
133
	sub edi,sizeof.M4
134
	stdcall gl_M4_Transpose,edi,esi ;транспонируем входную матрицу в локальную матрицу m
135
136
 
137
	mov esi,[eax+offs_cont_matrix_mode]
138
	shl esi,2
139
	add esi,eax
140
	stdcall gl_M4_MulLeft,dword[esi+offs_cont_matrix_stack_ptr],edi
141
142
 
143
	ret
144
endp
145
146
 
147
proc glopPushMatrix uses eax ebx, context:dword, p:dword
148
	mov eax,[context]
149
	mov ebx,[eax+offs_cont_matrix_mode]
150
151
 
152
;	   < c->matrix_stack_depth_max[ebx] );
153
154
 
155
	add ebx,eax
156
	add ebx,offs_cont_matrix_stack_ptr
157
	add dword[ebx],sizeof.M4
158
	mov ebx,[ebx] ;ebx = ++context.matrix_stack_ptr[context.matrix_mode]
159
160
 
161
	push ebx
162
	add ebx,sizeof.M4
163
	stdcall gl_M4_Move, ebx
164
165
 
166
	ret
167
endp
168
169
 
170
proc glopPopMatrix uses eax ebx, context:dword, p:dword
171
	mov eax,[context]
172
	mov ebx,[eax+offs_cont_matrix_mode]
173
174
 
175
176
 
177
	add ebx,eax
178
	sub dword[ebx+offs_cont_matrix_stack_ptr],sizeof.M4
179
180
 
181
	ret
182
endp
183
184
 
185
proc glopRotate uses eax ebx ecx, context:dword, p:dword
186
locals
187
	u0 dd ?
188
	u1 dd ?
189
	u2 dd ?
190
	angle dd ?
191
	cost dd ?
192
	sint dd ?
193
	m M4
194
endl
195
196
 
197
	mov ebx,[p]
198
	mov ecx,ebp
199
	sub ecx,sizeof.M4 ;ecx=&m
200
	finit
201
	fldpi
202
	fmul dword[ebx+4]
203
	fdiv dword[an180f]
204
	fst dword[angle] ;angle = p[1].f * M_PI / 180.0
205
	;st0 = angle
206
207
 
208
	fild dword[ebx+8]
209
	fstp dword[u0]
210
	fild dword[ebx+12]
211
	fstp dword[u1]
212
	fild dword[ebx+16]
213
	fst dword[u2]
214
215
 
216
	xor ebx,ebx
217
	fcomp st1 ;u2 ... 0
218
	fstsw ax
219
	sahf
220
	je @f
221
		inc ebx
222
	@@:
223
	fcom dword[u1] ;0 ... u1
224
	fstsw ax
225
	sahf
226
	je @f
227
		or ebx,2
228
	@@:
229
	fcom dword[u0] ;0 ... u0
230
	fstsw ax
231
	sahf
232
	je @f
233
		or ebx,4
234
	@@:
235
	;st0 = 0, st1 = angle
236
237
 
238
	cmp ebx,0
239
	je .end_f ;если нет поворотов выход из функции
240
	cmp ebx,4
241
	jne @f
242
		fcomp dword[u0] ;0 ... u0
243
		fstsw ax
244
		sahf
245
		jae .u0ch
246
			fchs
247
			fstp dword[angle] ;if (u0 < 0) angle *= -1
248
		.u0ch:
249
		stdcall gl_M4_Rotate, ecx,[angle],0
250
		jmp .end_sw
251
	@@:
252
	cmp ebx,2
253
	jne @f
254
		fcomp dword[u1] ;0 ... u1
255
		fstsw ax
256
		sahf
257
		jae .u1ch
258
			fchs
259
			fstp dword[angle] ;if (u1 < 0) angle *= -1
260
		.u1ch:
261
		stdcall gl_M4_Rotate, ecx,[angle],1
262
		jmp .end_sw
263
	@@:
264
	cmp ebx,1
265
	jne @f
266
		fcomp dword[u2] ;0 ... u2
267
		fstsw ax
268
		sahf
269
		jae .u2ch
270
			fchs
271
			fstp dword[angle] ;if (u2 < 0) angle *= -1
272
		.u2ch:
273
		stdcall gl_M4_Rotate, ecx,[angle],2
274
		jmp .end_sw
275
	@@: ;default:
276
if DEBUG ;glopRotete
277
		stdcall dbg_print,txt_sp,m_1
278
end if
279
280
 
281
		fld dword[u0]
282
		fmul st0,st0
283
		fld dword[u1]
284
		fmul st0,st0
285
		fld dword[u2]
286
		fmul st0,st0
287
		fadd st0,st1
288
		fadd st0,st2
289
;		fst dword[len] ;len = u0*u0+u1*u1+u2*u2
290
		fcom st1
291
		fstsw ax
292
		sahf
293
		je .end_f ;if (len == 0.0f) return
294
		fsqrt
295
		fld1
296
		fdiv st0,st1
297
;		fst dword[len] ;len = 1.0f / sqrt(len)
298
		fld dword[u0]
299
		fmul st0,st1
300
		fstp dword[u0] ;u0 *= len
301
		fld dword[u1]
302
		fmul st0,st1
303
		fstp dword[u1] ;u1 *= len
304
		fld dword[u2]
305
		fmul st0,st1
306
		fstp dword[u2] ;u2 *= len
307
		;st0 = len, st1=..., st2=..., st3 = 0, st4 = angle
308
309
 
310
		finit
311
		fld dword[angle]
312
		fcos
313
		fst dword[cost] ;cost=cos(angle)
314
		fld dword[angle]
315
		fsin
316
		fst dword[sint] ;sint=sin(angle)
317
318
 
319
		mov ebx,0.0
320
		mov [ecx+3*16   ],ebx ;m[3][0]
321
		mov [ecx+3*16 +4],ebx ;m[3][1]
322
		mov [ecx+3*16 +8],ebx ;m[3][2]
323
		mov [ecx+     12],ebx ;m[0][3]
324
		mov [ecx+  16+12],ebx ;m[1][3]
325
		mov [ecx+2*16+12],ebx ;m[2][3]
326
		mov ebx,1.0
327
		mov [ecx+3*16+12],ebx ;m[3][3]
328
329
 
330
;      m.m[0][0]=u[0]*u[0]+cost*(1-u[0]*u[0]);
331
;      m.m[1][0]=u[0]*u[1]*(1-cost)-u[2]*sint;
332
;      m.m[2][0]=u[2]*u[0]*(1-cost)+u[1]*sint;
333
;      m.m[0][1]=u[0]*u[1]*(1-cost)+u[2]*sint;
334
;      m.m[1][1]=u[1]*u[1]+cost*(1-u[1]*u[1]);
335
;      m.m[2][1]=u[1]*u[2]*(1-cost)-u[0]*sint;
336
;      m.m[0][2]=u[2]*u[0]*(1-cost)-u[1]*sint;
337
;      m.m[1][2]=u[1]*u[2]*(1-cost)+u[0]*sint;
338
;      m.m[2][2]=u[2]*u[2]+cost*(1-u[2]*u[2]);
339
	.end_sw:
340
341
 
342
	mov ebx,[eax+offs_cont_matrix_mode]
343
	shl ebx,2
344
	add ebx,eax
345
	stdcall gl_M4_MulLeft,dword[ebx+offs_cont_matrix_stack_ptr],ecx
346
if DEBUG ;glopRotete
347
		stdcall gl_print_matrix,ecx,4
348
end if
349
	gl_matrix_update eax,ebx
350
	.end_f:
351
	ret
352
endp
353
354
 
355
proc glopScale uses eax ebx ecx, context:dword, p:dword
356
	mov ecx,[p]
357
358
 
359
	mov ebx,[eax+offs_cont_matrix_mode]
360
	shl ebx,2
361
	add ebx,eax
362
	mov ebx,[ebx+offs_cont_matrix_stack_ptr] ;ebx = &m[0]
363
364
 
365
	fld dword[ecx+ 8] ;y
366
	fld dword[ecx+12] ;z
367
	mov ecx,4
368
	@@:
369
	fld dword[ebx]   ;m[0]
370
	fmul st0,st3     ;m[0] * x
371
	fstp dword[ebx]  ;m[0] *= x
372
	fld dword[ebx+4] ;m[1]
373
	fmul st0,st2     ;m[1] * y
374
	fstp dword[ebx+4];m[1] *= y
375
	fld dword[ebx+8] ;m[2]
376
	fmul st0,st1     ;m[2] * z
377
	fstp dword[ebx+8];m[2] *= z
378
	add ebx,16
379
	loop @b
380
381
 
382
	mov ebx,[eax+offs_cont_matrix_mode]
383
	shl ebx,2
384
	add ebx,eax
385
	stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4
386
end if
387
	gl_matrix_update eax,ebx
388
	ret
389
endp
390
391
 
392
proc glopTranslate uses eax ebx ecx, context:dword, p:dword
393
	mov ecx,[p]
394
395
 
396
	mov ebx,[eax+offs_cont_matrix_mode]
397
	shl ebx,2
398
	add ebx,eax
399
	mov ebx,[ebx+offs_cont_matrix_stack_ptr] ;ebx = &m[0]
400
401
 
402
	fld dword[ecx+ 8] ;y
403
	fld dword[ecx+12] ;z
404
	mov ecx,4
405
	@@:
406
		fld dword[ebx]   ;m[0]
407
		fmul st0,st3     ;m[0] * x
408
		fld dword[ebx+4] ;m[1]
409
		fmul st0,st3     ;m[1] * y
410
		fld dword[ebx+8] ;m[2]
411
		fmul st0,st3     ;m[2] * z
412
		faddp
5175 IgorA 413
		faddp
414
		fadd dword[ebx+12] ;m[3]
5153 IgorA 415
		fstp dword[ebx+12] ;m[3] = m[0] * x + m[1] * y + m[2] * z + m[3]
416
		add ebx,16
417
	loop @b
418
	ffree st0
5175 IgorA 419
	fincstp
420
	ffree st0
421
	fincstp
422
	ffree st0
423
	fincstp
424
5153 IgorA 425
 
426
	mov ebx,[eax+offs_cont_matrix_mode]
427
	shl ebx,2
428
	add ebx,eax
429
	stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4
430
end if
431
	gl_matrix_update eax,ebx
432
	ret
433
endp
434
435
 
436
proc glopFrustum uses eax ebx ecx, context:dword, p:dword
437
locals
438
	x dd ?
439
	y dd ?
440
	A dd ?
441
	B dd ?
442
	C dd ?
443
	D dd ?
444
	m M4
445
endl
446
	mov eax,[context]
447
	mov ebx,[p]
448
449
 
450
	fsub dword[ebx+4]  ;st0 = (right-left)
451
	fld dword[ebx+20]  ;st0 = near
452
	fadd st0,st0
453
	fdiv st0,st1
454
	fstp dword[x]      ;x = (2.0*near) / (right-left)
455
	fld dword[ebx+16]
456
	fsub dword[ebx+12] ;st0 = (top-bottom)
457
	fld dword[ebx+20]  ;st0 = near
458
	fadd st0,st0
459
	fdiv st0,st1
460
	fstp dword[y]      ;y = (2.0*near) / (top-bottom)
461
	fld dword[ebx+8]
462
	fadd dword[ebx+4]  ;st0 = (right+left)
463
	fdiv st0,st2       ;st2 = (right-left)
464
	fstp dword[A]      ;A = (right+left) / (right-left)
465
	fld dword[ebx+16]
466
	fadd dword[ebx+12] ;st0 = (top+bottom)
467
	fdiv st0,st1       ;st1 = (top-bottom)
468
	fstp dword[B]      ;B = (top+bottom) / (top-bottom)
469
	fld dword[ebx+24]
470
	fsub dword[ebx+20] ;st0 = (farp-near)
471
	fldz
472
	fsub dword[ebx+24]
473
	fsub dword[ebx+20] ;st0 = -(farp+near)
474
	fdiv st0,st1
475
	fstp dword[C]      ;C = -(farp+near) / (farp-near)
476
	fld dword[ebx+24]
477
	fmul dword[ebx+20] ;st0 = farp*near
478
	fadd st0,st0
479
	fchs               ;st0 = -(2.0*farp*near)
480
	fdiv st0,st1
481
	fstp dword[D]      ;D = -(2.0*farp*near) / (farp-near)
482
483
 
484
	sub ecx,sizeof.M4
485
486
 
487
	mov dword[ecx],ebx
488
	mov dword[ecx+4],0.0
489
	mov ebx,[A]
490
	mov dword[ecx+8],ebx
491
	mov dword[ecx+12],0.0
492
	mov dword[ecx+16],0.0
493
	mov ebx,[y]
494
	mov dword[ecx+20],ebx
495
	mov ebx,[B]
496
	mov dword[ecx+24],ebx
497
	mov dword[ecx+28],0.0
498
	mov dword[ecx+32],0.0
499
	mov dword[ecx+36],0.0
500
	mov ebx,[C]
501
	mov dword[ecx+40],ebx
502
	mov ebx,[D]
503
	mov dword[ecx+44],ebx
504
	mov dword[ecx+48],0.0
505
	mov dword[ecx+52],0.0
506
	mov dword[ecx+56],-1.0
507
	mov dword[ecx+60],0.0
508
509
 
510
	shl ebx,2
511
	add ebx,eax
512
	stdcall gl_M4_MulLeft,dword[ebx+offs_cont_matrix_stack_ptr],ecx
513
514
 
515
	stdcall gl_print_matrix,ecx,4
516
	stdcall gl_print_matrix,dword[ebx+offs_cont_matrix_stack_ptr],4
517
end if
518
	gl_matrix_update eax,ebx
519
	ret
520
endp
521