Subversion Repositories Kolibri OS

Rev

Rev 5415 | Rev 6523 | 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
	gl_matrix_update eax,ebx
119
	ret
120
endp
121
122
 
123
proc glopMultMatrix uses eax edi esi, context:dword, p:dword
124
locals
125
	m M4
126
endl
127
	mov esi,[p]
128
	add esi,4
129
	mov edi,ebp
130
	sub edi,sizeof.M4
131
	stdcall gl_M4_Transpose,edi,esi ;транспонируем входную матрицу в локальную матрицу m
132
133
 
134
	mov esi,[eax+offs_cont_matrix_mode]
135
	shl esi,2
136
	add esi,eax
137
	stdcall gl_M4_MulLeft,dword[esi+offs_cont_matrix_stack_ptr],edi
138
139
 
140
	ret
141
endp
142
143
 
144
proc glopPushMatrix uses eax ebx, context:dword, p:dword
145
	mov eax,[context]
146
	mov ebx,[eax+offs_cont_matrix_mode]
147
148
 
149
;	   < c->matrix_stack_depth_max[ebx] );
150
151
 
152
	add ebx,eax
153
	add ebx,offs_cont_matrix_stack_ptr
154
	add dword[ebx],sizeof.M4
155
	mov ebx,[ebx] ;ebx = ++context.matrix_stack_ptr[context.matrix_mode]
156
157
 
158
	push ebx
159
	add ebx,sizeof.M4
160
	stdcall gl_M4_Move, ebx
161
162
 
163
	ret
164
endp
165
166
 
167
proc glopPopMatrix uses eax ebx, context:dword, p:dword
168
	mov eax,[context]
169
	mov ebx,[eax+offs_cont_matrix_mode]
170
171
 
172
173
 
174
	add ebx,eax
175
	sub dword[ebx+offs_cont_matrix_stack_ptr],sizeof.M4
176
177
 
178
	ret
179
endp
180
181
 
182
proc glopRotate uses eax ebx ecx edx, context:dword, p:dword
5415 IgorA 183
locals
5153 IgorA 184
	u0 dd ?
185
	u1 dd ?
186
	u2 dd ?
187
	angle dd ?
188
	cost dd ?
189
	sint dd ?
190
	m M4
191
endl
192
193
 
194
	mov ebx,[p]
195
	mov ecx,ebp
196
	sub ecx,sizeof.M4 ;ecx=&m
197
	finit
198
	fldpi
199
	fmul dword[ebx+4]
200
	fdiv dword[an180f]
201
	fst dword[angle] ;angle = p[1].f * M_PI / 180.0
202
	;st0 = angle
203
204
 
205
	xor edx,edx
5415 IgorA 206
	fld dword[ebx+16]
207
	ftst
208
	fstsw ax
5153 IgorA 209
	sahf
210
	je @f
211
		inc edx
5415 IgorA 212
	@@:
5153 IgorA 213
	fstp dword[u2]
5415 IgorA 214
	fld dword[ebx+12]
215
	ftst
216
	fstsw ax
5153 IgorA 217
	sahf
218
	je @f
219
		or edx,2
5415 IgorA 220
	@@:
5153 IgorA 221
	fstp dword[u1]
5415 IgorA 222
	fld dword[ebx+8]
223
	ftst
224
	fstsw ax
5153 IgorA 225
	sahf
226
	je @f
227
		or edx,4
5415 IgorA 228
	@@:
5153 IgorA 229
	fstp dword[u0]
5415 IgorA 230
5153 IgorA 231
 
5415 IgorA 232
	;ebx = ((u0 != 0)<<2) | ((u1 != 0)<<1) | (u2 != 0)
5153 IgorA 233
	or edx,edx
5415 IgorA 234
	jz .end_f ;если нет поворотов выход из функции
235
	cmp edx,4
236
	jne @f
5153 IgorA 237
		fld dword[u0]
5415 IgorA 238
		ftst
239
		fstsw ax
5153 IgorA 240
		ffree st0
5415 IgorA 241
		fincstp
242
		sahf
5153 IgorA 243
		jae .u0ch
244
			fchs ;if (u0 < 0) angle *= -1
5415 IgorA 245
		.u0ch:
5153 IgorA 246
		push dword 0
5415 IgorA 247
		fstp dword[esp-4]
248
		sub esp,4
249
		stdcall gl_M4_Rotate, ecx
250
		jmp .end_sw
5153 IgorA 251
	@@:
252
	cmp edx,2
5415 IgorA 253
	jne @f
5153 IgorA 254
		fld dword[u1]
5415 IgorA 255
		ftst
256
		fstsw ax
5153 IgorA 257
		ffree st0
5415 IgorA 258
		fincstp
259
		sahf
5153 IgorA 260
		jae .u1ch
261
			fchs ;if (u1 < 0) angle *= -1
5415 IgorA 262
		.u1ch:
5153 IgorA 263
		push dword 1
5415 IgorA 264
		fstp dword[esp-4]
265
		sub esp,4
266
		stdcall gl_M4_Rotate, ecx
267
		jmp .end_sw
5153 IgorA 268
	@@:
269
	cmp edx,1
5415 IgorA 270
	jne @f
5153 IgorA 271
		fld dword[u2]
5415 IgorA 272
		ftst
273
		fstsw ax
5153 IgorA 274
		ffree st0
5415 IgorA 275
		fincstp
276
		sahf
5153 IgorA 277
		jae .u2ch
278
			fchs ;if (u2 < 0) angle *= -1
5415 IgorA 279
		.u2ch:
5153 IgorA 280
		push dword 2
5415 IgorA 281
		fstp dword[esp-4]
282
		sub esp,4
283
		stdcall gl_M4_Rotate, ecx
284
		jmp .end_sw
5153 IgorA 285
	@@: ;default:
286
287
 
288
		fld dword[u0]
289
		fmul st0,st0
290
		fld dword[u1]
291
		fmul st0,st0
292
		faddp
5415 IgorA 293
		fld dword[u2]
5153 IgorA 294
		fmul st0,st0
295
		faddp
5415 IgorA 296
;		fst dword[len] ;len = u0*u0+u1*u1+u2*u2
5153 IgorA 297
		ftst
5415 IgorA 298
		fstsw ax
5153 IgorA 299
		sahf
300
		je .f2 ;if (len == 0.0f) return
5415 IgorA 301
		fsqrt
5153 IgorA 302
		fld1
303
		fxch
5415 IgorA 304
		fdivp ;len = 1.0f / sqrt(len)
305
;		fst dword[len]
306
		fld dword[u0]
5153 IgorA 307
		fmul st0,st1
308
		fstp dword[u0] ;u0 *= len
309
		fld dword[u1]
310
		fmul st0,st1
311
		fstp dword[u1] ;u1 *= len
312
		fld dword[u2]
313
		fmul st0,st1
314
		fstp dword[u2] ;u2 *= len
315
		;st0 = len, st1 = angle
5415 IgorA 316
		ffree st0
317
		fincstp
318
5153 IgorA 319
 
320
		fcos
321
		fst dword[cost] ;cost=cos(angle)
322
		fld dword[angle]
323
		fsin
324
		fst dword[sint] ;sint=sin(angle)
325
326
 
327
		mov ebx,0.0
328
		mov [ecx+3*16   ],ebx ;m[3][0]
329
		mov [ecx+3*16 +4],ebx ;m[3][1]
330
		mov [ecx+3*16 +8],ebx ;m[3][2]
331
		mov [ecx+     12],ebx ;m[0][3]
332
		mov [ecx+  16+12],ebx ;m[1][3]
333
		mov [ecx+2*16+12],ebx ;m[2][3]
334
		mov ebx,1.0
335
		mov [ecx+3*16+12],ebx ;m[3][3]
336
337
 
338
		fld dword[u0]
5415 IgorA 339
		fmul st0,st0
340
		fld1
341
		fsub st0,st1
342
		fmul st0,st3 ;st0 = cost*(1-u0^2)
343
		faddp
344
		fstp dword[ecx] ;m[0][0] = u0*u0+cost*(1-u0*u0)
345
346
 
347
		fsub st0,st2 ;st0 = 1-cost
348
349
 
350
		fmul dword[u0]
351
		fmul dword[u1]
352
		fld dword[u2]
353
		fmul st0,st3 ;st0 = u2*sint
354
		fchs
355
		faddp
356
		fstp dword[ecx+16] ;m[1][0] = u0*u1*(1-cost)-u2*sint
357
358
 
359
		fmul dword[u0]
360
		fmul dword[u2]
361
		fld dword[u1]
362
		fmul st0,st3 ;st0 = u1*sint
363
		faddp
364
		fstp dword[ecx+32] ;m.m[2][0]=u[2]*u[0]*(1-cost)+u[1]*sint
365
366
 
367
		fmul dword[u0]
368
		fmul dword[u1]
369
		fld dword[u2]
370
		fmul st0,st3 ;st0 = u2*sint
371
		faddp
372
		fstp dword[ecx+4] ;m.m[0][1]=u[0]*u[1]*(1-cost)+u[2]*sint
373
374
 
375
		fmul st0,st0
376
		fld1
377
		fsub st0,st1
378
		fmul st0,st4 ;st0 = cost*(1-u1^2)
379
		faddp
380
		fstp dword[ecx+20] ;m.m[1][1]=u[1]*u[1]+cost*(1-u[1]*u[1])
381
382
 
383
		fmul dword[u1]
384
		fmul dword[u2]
385
		fld dword[u0]
386
		fmul st0,st3 ;st0 = u0*sint
387
		fchs
388
		faddp
389
		fstp dword[ecx+36] ;m.m[2][1]=u[1]*u[2]*(1-cost)-u[0]*sint
390
391
 
392
		fmul dword[u0]
393
		fmul dword[u2]
394
		fld dword[u1]
395
		fmul st0,st3 ;st0 = u1*sint
396
		fchs
397
		faddp
398
		fstp dword[ecx+8] ;m.m[0][2]=u[2]*u[0]*(1-cost)-u[1]*sint
399
400
 
401
		fmul dword[u1]
402
		fmul dword[u2]
403
		fld dword[u0]
404
		fmul st0,st3 ;st0 = u0*sint
405
		faddp
406
		fstp dword[ecx+24] ;m.m[1][2]=u[1]*u[2]*(1-cost)+u[0]*sint
407
408
 
409
		fincstp
410
411
 
412
		fmul st0,st0
413
		fld1
414
		fsub st0,st1
415
		fmul st0,st3 ;st0 = cost*(1-u2^2)
416
		faddp
417
		fstp dword[ecx+40] ;m[2][2] = u2*u2+cost*(1-u2*u2)
418
419
 
420
  fincstp
421
		ffree st0 ;cost
422
  fincstp
423
	.end_sw:
5153 IgorA 424
425
 
426
	mov ebx,[eax+offs_cont_matrix_mode]
427
	shl ebx,2
428
	add ebx,eax
429
	stdcall gl_M4_MulLeft,dword[ebx+offs_cont_matrix_stack_ptr],ecx
430
	gl_matrix_update eax,ebx
431
	jmp .end_f
5415 IgorA 432
	.f2:
433
		ffree st0 ;len
434
		fincstp
435
		ffree st0 ;angle
436
		fincstp
437
	.end_f:
5153 IgorA 438
	ret
439
endp
440
441
 
442
proc glopScale uses eax ebx ecx, context:dword, p:dword
443
	mov ecx,[p]
444
445
 
446
	mov ebx,[eax+offs_cont_matrix_mode]
447
	shl ebx,2
448
	add ebx,eax
449
	mov ebx,[ebx+offs_cont_matrix_stack_ptr] ;ebx = &m[0]
450
451
 
452
	fld dword[ecx+ 8] ;y
453
	fld dword[ecx+12] ;z
454
	mov ecx,4
455
	@@:
456
	fld dword[ebx]   ;m[0]
457
	fmul st0,st3     ;m[0] * x
458
	fstp dword[ebx]  ;m[0] *= x
459
	fld dword[ebx+4] ;m[1]
460
	fmul st0,st2     ;m[1] * y
461
	fstp dword[ebx+4];m[1] *= y
462
	fld dword[ebx+8] ;m[2]
463
	fmul st0,st1     ;m[2] * z
464
	fstp dword[ebx+8];m[2] *= z
465
	add ebx,16
466
	loop @b
467
	ffree st0
5415 IgorA 468
	fincstp
469
	ffree st0
470
	fincstp
471
	ffree st0
472
	fincstp
473
5153 IgorA 474
 
475
	ret
476
endp
477
478
 
479
proc glopTranslate uses eax ebx ecx, context:dword, p:dword
480
	mov ecx,[p]
481
482
 
483
	mov ebx,[eax+offs_cont_matrix_mode]
484
	shl ebx,2
485
	add ebx,eax
486
	mov ebx,[ebx+offs_cont_matrix_stack_ptr] ;ebx = &m[0]
487
488
 
489
	fld dword[ecx+ 8] ;y
490
	fld dword[ecx+12] ;z
491
	mov ecx,4
492
	@@:
493
		fld dword[ebx]   ;m[0]
494
		fmul st0,st3     ;m[0] * x
495
		fld dword[ebx+4] ;m[1]
496
		fmul st0,st3     ;m[1] * y
497
		faddp
5269 IgorA 498
		fld dword[ebx+8] ;m[2]
5153 IgorA 499
		fmul st0,st2     ;m[2] * z
5269 IgorA 500
		faddp
5175 IgorA 501
		fadd dword[ebx+12] ;m[3]
5153 IgorA 502
		fstp dword[ebx+12] ;m[3] = m[0] * x + m[1] * y + m[2] * z + m[3]
503
		add ebx,16
504
	loop @b
505
	ffree st0
5175 IgorA 506
	fincstp
507
	ffree st0
508
	fincstp
509
	ffree st0
510
	fincstp
511
5153 IgorA 512
 
513
	ret
514
endp
515
516
 
517
proc glopFrustum uses eax ebx ecx, context:dword, p:dword
518
locals
519
	x dd ?
520
	y dd ?
521
	A dd ?
522
	B dd ?
523
	C dd ?
524
	D dd ?
525
	m M4
526
endl
527
	mov eax,[context]
528
	mov ebx,[p]
529
530
 
531
	fsub dword[ebx+4]  ;st0 = (right-left)
532
	fld dword[ebx+20]  ;st0 = near
533
	fadd st0,st0
534
	fdiv st0,st1
535
	fstp dword[x]      ;x = (2.0*near) / (right-left)
536
	fld dword[ebx+16]
537
	fsub dword[ebx+12] ;st0 = (top-bottom)
538
	fld dword[ebx+20]  ;st0 = near
539
	fadd st0,st0
540
	fdiv st0,st1
541
	fstp dword[y]      ;y = (2.0*near) / (top-bottom)
542
	fld dword[ebx+8]
543
	fadd dword[ebx+4]  ;st0 = (right+left)
544
	fdiv st0,st2       ;st2 = (right-left)
545
	fstp dword[A]      ;A = (right+left) / (right-left)
546
	fld dword[ebx+16]
547
	fadd dword[ebx+12] ;st0 = (top+bottom)
548
	fdiv st0,st1       ;st1 = (top-bottom)
549
	fstp dword[B]      ;B = (top+bottom) / (top-bottom)
550
	fld dword[ebx+24]
551
	fsub dword[ebx+20] ;st0 = (farp-near)
552
	fld dword[ebx+24]
5418 IgorA 553
	fadd dword[ebx+20]
554
	fchs ;st0 = -(farp+near)
555
	fdiv st0,st1
5153 IgorA 556
	fstp dword[C]      ;C = -(farp+near) / (farp-near)
557
	fld dword[ebx+24]
558
	fmul dword[ebx+20] ;st0 = farp*near
559
	fadd st0,st0
560
	fchs               ;st0 = -(2.0*farp*near)
561
	fdiv st0,st1
562
	fstp dword[D]      ;D = -(2.0*farp*near) / (farp-near)
563
	ffree st0
5418 IgorA 564
	fincstp
565
	ffree st0
566
	fincstp
567
	ffree st0
568
	fincstp
569
5153 IgorA 570
 
571
	sub ecx,sizeof.M4
572
573
 
574
	mov dword[ecx],ebx
575
	mov dword[ecx+4],0.0
576
	mov ebx,[A]
577
	mov dword[ecx+8],ebx
578
	mov dword[ecx+12],0.0
579
	mov dword[ecx+16],0.0
580
	mov ebx,[y]
581
	mov dword[ecx+20],ebx
582
	mov ebx,[B]
583
	mov dword[ecx+24],ebx
584
	mov dword[ecx+28],0.0
585
	mov dword[ecx+32],0.0
586
	mov dword[ecx+36],0.0
587
	mov ebx,[C]
588
	mov dword[ecx+40],ebx
589
	mov ebx,[D]
590
	mov dword[ecx+44],ebx
591
	mov dword[ecx+48],0.0
592
	mov dword[ecx+52],0.0
593
	mov dword[ecx+56],-1.0
594
	mov dword[ecx+60],0.0
595
596
 
597
	shl ebx,2
598
	add ebx,eax
599
	stdcall gl_M4_MulLeft,dword[ebx+offs_cont_matrix_stack_ptr],ecx
600
601
 
602
	stdcall gl_print_matrix,ecx,4
603
	stdcall gl_print_matrix,dword[ebx+offs_cont_matrix_stack_ptr],4
604
end if
605
	gl_matrix_update eax,ebx
606
	ret
607
endp
608