Subversion Repositories Kolibri OS

Rev

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