Subversion Repositories Kolibri OS

Rev

Rev 6523 | 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+GLContext.matrix_mode],1
6523 IgorA 63
	jg .end_0
5153 IgorA 64
		inc reg
65
	.end_0:
66
	mov dword[context+GLContext.matrix_model_projection_updated],reg
6523 IgorA 67
}
5153 IgorA 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+GLContext.matrix_mode],0
6523 IgorA 77
		jmp .end_f
5153 IgorA 78
	@@:
79
	cmp dword[ebx+4],GL_PROJECTION
80
	jne @f
81
		mov dword[eax+GLContext.matrix_mode],1
6523 IgorA 82
		jmp .end_f
5153 IgorA 83
	@@:
84
	cmp dword[ebx+4],GL_TEXTURE
85
	jne .def
86
		mov dword[eax+GLContext.matrix_mode],2
6523 IgorA 87
		jmp .end_f
5153 IgorA 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+GLContext.matrix_mode]
6523 IgorA 98
	lea edi,[eax+4*edi]
8062 IgorA 99
	mov edi,dword[edi+GLContext.matrix_stack_ptr]
6523 IgorA 100
5153 IgorA 101
 
102
	add esi,4
103
	stdcall gl_M4_Transpose,edi,esi ;транспонируем входную матрицу в матрицу context.matrix_stack_ptr[context.matrix_mode]
104
105
 
106
	ret
107
endp
108
109
 
110
proc glopLoadIdentity uses eax ebx, context:dword, p:dword
111
	mov eax,[context]
112
	mov ebx,[eax+GLContext.matrix_mode]
6523 IgorA 113
	lea ebx,[eax+4*ebx]
8062 IgorA 114
5153 IgorA 115
 
6523 IgorA 116
	gl_matrix_update eax,ebx
5153 IgorA 117
	ret
118
endp
119
120
 
121
proc glopMultMatrix uses eax edi esi, context:dword, p:dword
122
locals
123
	m M4
124
endl
125
	mov esi,[p]
126
	add esi,4
127
	lea edi,[ebp-sizeof.M4]
8062 IgorA 128
	stdcall gl_M4_Transpose,edi,esi ;транспонируем входную матрицу в локальную матрицу m
5153 IgorA 129
130
 
131
	mov esi,[eax+GLContext.matrix_mode]
6523 IgorA 132
	lea esi,[eax+4*esi]
8062 IgorA 133
	stdcall gl_M4_MulLeft,dword[esi+GLContext.matrix_stack_ptr],edi
6523 IgorA 134
5153 IgorA 135
 
136
	ret
137
endp
138
139
 
140
proc glopPushMatrix uses eax ebx, context:dword, p:dword
141
	mov eax,[context]
142
	mov ebx,[eax+GLContext.matrix_mode]
6523 IgorA 143
5153 IgorA 144
 
145
;	   < c->matrix_stack_depth_max[ebx] );
146
147
 
8062 IgorA 148
	add dword[ebx],sizeof.M4
5153 IgorA 149
	mov ebx,[ebx] ;ebx = ++context.matrix_stack_ptr[context.matrix_mode]
150
151
 
152
	push ebx
153
	add ebx,sizeof.M4
154
	stdcall gl_M4_Move, ebx
155
156
 
157
	ret
158
endp
159
160
 
161
proc glopPopMatrix uses eax ebx, context:dword, p:dword
162
	mov eax,[context]
163
	mov ebx,[eax+GLContext.matrix_mode]
6523 IgorA 164
5153 IgorA 165
 
166
167
 
8062 IgorA 168
	sub dword[ebx+GLContext.matrix_stack_ptr],sizeof.M4
6523 IgorA 169
5153 IgorA 170
 
171
	ret
172
endp
173
174
 
175
proc glopRotate uses eax ebx ecx edx, context:dword, p:dword
5415 IgorA 176
locals
5153 IgorA 177
	u0 dd ?
178
	u1 dd ?
179
	u2 dd ?
180
	angle dd ?
181
	cost dd ?
182
	sint dd ?
183
	m M4
184
endl
185
186
 
187
	mov ebx,[p]
188
	lea ecx,[ebp-sizeof.M4] ;ecx=&m
8062 IgorA 189
	finit
5153 IgorA 190
	fldpi
191
	fmul dword[ebx+4]
192
	fdiv dword[an180f]
193
	fst dword[angle] ;angle = p[1].f * M_PI / 180.0
194
	;st0 = angle
195
196
 
197
	xor edx,edx
5415 IgorA 198
	fld dword[ebx+16]
199
	ftst
200
	fstsw ax
5153 IgorA 201
	sahf
202
	je @f
203
		inc edx
5415 IgorA 204
	@@:
5153 IgorA 205
	fstp dword[u2]
5415 IgorA 206
	fld dword[ebx+12]
207
	ftst
208
	fstsw ax
5153 IgorA 209
	sahf
210
	je @f
211
		or edx,2
5415 IgorA 212
	@@:
5153 IgorA 213
	fstp dword[u1]
5415 IgorA 214
	fld dword[ebx+8]
215
	ftst
216
	fstsw ax
5153 IgorA 217
	sahf
218
	je @f
219
		or edx,4
5415 IgorA 220
	@@:
5153 IgorA 221
	fstp dword[u0]
5415 IgorA 222
5153 IgorA 223
 
5415 IgorA 224
	;ebx = ((u0 != 0)<<2) | ((u1 != 0)<<1) | (u2 != 0)
5153 IgorA 225
	or edx,edx
5415 IgorA 226
	jz .end_f ;если нет поворотов выход из функции
227
	cmp edx,4
228
	jne @f
5153 IgorA 229
		fld dword[u0]
5415 IgorA 230
		ftst
231
		fstsw ax
5153 IgorA 232
		ffree st0
5415 IgorA 233
		fincstp
234
		sahf
5153 IgorA 235
		jae .u0ch
236
			fchs ;if (u0 < 0) angle *= -1
5415 IgorA 237
		.u0ch:
5153 IgorA 238
		push dword 0
5415 IgorA 239
		fstp dword[esp-4]
240
		sub esp,4
241
		stdcall gl_M4_Rotate, ecx
242
		jmp .end_sw
5153 IgorA 243
	@@:
244
	cmp edx,2
5415 IgorA 245
	jne @f
5153 IgorA 246
		fld dword[u1]
5415 IgorA 247
		ftst
248
		fstsw ax
5153 IgorA 249
		ffree st0
5415 IgorA 250
		fincstp
251
		sahf
5153 IgorA 252
		jae .u1ch
253
			fchs ;if (u1 < 0) angle *= -1
5415 IgorA 254
		.u1ch:
5153 IgorA 255
		push dword 1
5415 IgorA 256
		fstp dword[esp-4]
257
		sub esp,4
258
		stdcall gl_M4_Rotate, ecx
259
		jmp .end_sw
5153 IgorA 260
	@@:
261
	cmp edx,1
5415 IgorA 262
	jne @f
5153 IgorA 263
		fld dword[u2]
5415 IgorA 264
		ftst
265
		fstsw ax
5153 IgorA 266
		ffree st0
5415 IgorA 267
		fincstp
268
		sahf
5153 IgorA 269
		jae .u2ch
270
			fchs ;if (u2 < 0) angle *= -1
5415 IgorA 271
		.u2ch:
5153 IgorA 272
		push dword 2
5415 IgorA 273
		fstp dword[esp-4]
274
		sub esp,4
275
		stdcall gl_M4_Rotate, ecx
276
		jmp .end_sw
5153 IgorA 277
	@@: ;default:
278
279
 
280
		fld dword[u0]
281
		fmul st0,st0
282
		fld dword[u1]
283
		fmul st0,st0
284
		faddp
5415 IgorA 285
		fld dword[u2]
5153 IgorA 286
		fmul st0,st0
287
		faddp
5415 IgorA 288
;		fst dword[len] ;len = u0*u0+u1*u1+u2*u2
5153 IgorA 289
		ftst
5415 IgorA 290
		fstsw ax
5153 IgorA 291
		sahf
292
		je .f2 ;if (len == 0.0f) return
5415 IgorA 293
		fsqrt
5153 IgorA 294
		fld1
295
		fxch
5415 IgorA 296
		fdivp ;len = 1.0f / sqrt(len)
297
;		fst dword[len]
298
		fld dword[u0]
5153 IgorA 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 = angle
5415 IgorA 308
		ffree st0
309
		fincstp
310
5153 IgorA 311
 
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
		fld dword[u0]
5415 IgorA 331
		fmul st0,st0
332
		fld1
333
		fsub st0,st1
334
		fmul st0,st3 ;st0 = cost*(1-u0^2)
335
		faddp
336
		fstp dword[ecx] ;m[0][0] = u0*u0+cost*(1-u0*u0)
337
338
 
339
		fsub st0,st2 ;st0 = 1-cost
340
341
 
342
		fmul dword[u0]
343
		fmul dword[u1]
344
		fld dword[u2]
345
		fmul st0,st3 ;st0 = u2*sint
346
		fchs
347
		faddp
348
		fstp dword[ecx+16] ;m[1][0] = u0*u1*(1-cost)-u2*sint
349
350
 
351
		fmul dword[u0]
352
		fmul dword[u2]
353
		fld dword[u1]
354
		fmul st0,st3 ;st0 = u1*sint
355
		faddp
356
		fstp dword[ecx+32] ;m.m[2][0]=u[2]*u[0]*(1-cost)+u[1]*sint
357
358
 
359
		fmul dword[u0]
360
		fmul dword[u1]
361
		fld dword[u2]
362
		fmul st0,st3 ;st0 = u2*sint
363
		faddp
364
		fstp dword[ecx+4] ;m.m[0][1]=u[0]*u[1]*(1-cost)+u[2]*sint
365
366
 
367
		fmul st0,st0
368
		fld1
369
		fsub st0,st1
370
		fmul st0,st4 ;st0 = cost*(1-u1^2)
371
		faddp
372
		fstp dword[ecx+20] ;m.m[1][1]=u[1]*u[1]+cost*(1-u[1]*u[1])
373
374
 
375
		fmul dword[u1]
376
		fmul dword[u2]
377
		fld dword[u0]
378
		fmul st0,st3 ;st0 = u0*sint
379
		fchs
380
		faddp
381
		fstp dword[ecx+36] ;m.m[2][1]=u[1]*u[2]*(1-cost)-u[0]*sint
382
383
 
384
		fmul dword[u0]
385
		fmul dword[u2]
386
		fld dword[u1]
387
		fmul st0,st3 ;st0 = u1*sint
388
		fchs
389
		faddp
390
		fstp dword[ecx+8] ;m.m[0][2]=u[2]*u[0]*(1-cost)-u[1]*sint
391
392
 
393
		fmul dword[u1]
394
		fmul dword[u2]
395
		fld dword[u0]
396
		fmul st0,st3 ;st0 = u0*sint
397
		faddp
398
		fstp dword[ecx+24] ;m.m[1][2]=u[1]*u[2]*(1-cost)+u[0]*sint
399
400
 
401
		fincstp
402
403
 
404
		fmul st0,st0
405
		fld1
406
		fsub st0,st1
407
		fmul st0,st3 ;st0 = cost*(1-u2^2)
408
		faddp
409
		fstp dword[ecx+40] ;m[2][2] = u2*u2+cost*(1-u2*u2)
410
411
 
412
  fincstp
413
		ffree st0 ;cost
414
  fincstp
415
	.end_sw:
5153 IgorA 416
417
 
418
	mov ebx,[eax+GLContext.matrix_mode]
6523 IgorA 419
	lea ebx,[eax+4*ebx]
8062 IgorA 420
	stdcall gl_M4_MulLeft,dword[ebx+GLContext.matrix_stack_ptr],ecx
6523 IgorA 421
	gl_matrix_update eax,ebx
5153 IgorA 422
	jmp .end_f
5415 IgorA 423
	.f2:
424
		ffree st0 ;len
425
		fincstp
426
		ffree st0 ;angle
427
		fincstp
428
	.end_f:
5153 IgorA 429
	ret
430
endp
431
432
 
433
proc glopScale uses eax ebx ecx, context:dword, p:dword
434
	mov ecx,[p]
435
436
 
437
	mov ebx,[eax+GLContext.matrix_mode]
6523 IgorA 438
	lea ebx,[eax+4*ebx]
8062 IgorA 439
	mov ebx,[ebx+GLContext.matrix_stack_ptr] ;ebx = &m[0]
6523 IgorA 440
5153 IgorA 441
 
442
	fld dword[ecx+ 8] ;y
443
	fld dword[ecx+12] ;z
444
	mov ecx,4
445
	@@:
446
	fld dword[ebx]   ;m[0]
447
	fmul st0,st3     ;m[0] * x
448
	fstp dword[ebx]  ;m[0] *= x
449
	fld dword[ebx+4] ;m[1]
450
	fmul st0,st2     ;m[1] * y
451
	fstp dword[ebx+4];m[1] *= y
452
	fld dword[ebx+8] ;m[2]
453
	fmul st0,st1     ;m[2] * z
454
	fstp dword[ebx+8];m[2] *= z
455
	add ebx,16
456
	loop @b
457
	ffree st0
5415 IgorA 458
	fincstp
459
	ffree st0
460
	fincstp
461
	ffree st0
462
	fincstp
463
5153 IgorA 464
 
465
	ret
466
endp
467
468
 
469
proc glopTranslate uses eax ebx ecx, context:dword, p:dword
470
	mov ecx,[p]
471
472
 
473
	mov ebx,[eax+GLContext.matrix_mode]
6523 IgorA 474
	lea ebx,[eax+4*ebx]
8062 IgorA 475
	mov ebx,[ebx+GLContext.matrix_stack_ptr] ;ebx = &m[0]
6523 IgorA 476
5153 IgorA 477
 
478
	fld dword[ecx+ 8] ;y
479
	fld dword[ecx+12] ;z
480
	mov ecx,4
481
	@@:
482
		fld dword[ebx]   ;m[0]
483
		fmul st0,st3     ;m[0] * x
484
		fld dword[ebx+4] ;m[1]
485
		fmul st0,st3     ;m[1] * y
486
		faddp
5269 IgorA 487
		fld dword[ebx+8] ;m[2]
5153 IgorA 488
		fmul st0,st2     ;m[2] * z
5269 IgorA 489
		faddp
5175 IgorA 490
		fadd dword[ebx+12] ;m[3]
5153 IgorA 491
		fstp dword[ebx+12] ;m[3] = m[0] * x + m[1] * y + m[2] * z + m[3]
492
		add ebx,16
493
	loop @b
494
	ffree st0
5175 IgorA 495
	fincstp
496
	ffree st0
497
	fincstp
498
	ffree st0
499
	fincstp
500
5153 IgorA 501
 
502
	ret
503
endp
504
505
 
506
proc glopFrustum uses eax ebx ecx, context:dword, p:dword
507
locals
508
	x dd ?
509
	y dd ?
510
	A dd ?
511
	B dd ?
512
	C dd ?
513
	D dd ?
514
	m M4
515
endl
516
	mov eax,[context]
517
	mov ebx,[p]
518
519
 
520
	fsub dword[ebx+4]  ;st0 = (right-left)
521
	fld dword[ebx+20]  ;st0 = near
522
	fadd st0,st0
523
	fdiv st0,st1
524
	fstp dword[x]      ;x = (2.0*near) / (right-left)
525
	fld dword[ebx+16]
526
	fsub dword[ebx+12] ;st0 = (top-bottom)
527
	fld dword[ebx+20]  ;st0 = near
528
	fadd st0,st0
529
	fdiv st0,st1
530
	fstp dword[y]      ;y = (2.0*near) / (top-bottom)
531
	fld dword[ebx+8]
532
	fadd dword[ebx+4]  ;st0 = (right+left)
533
	fdiv st0,st2       ;st2 = (right-left)
534
	fstp dword[A]      ;A = (right+left) / (right-left)
535
	fld dword[ebx+16]
536
	fadd dword[ebx+12] ;st0 = (top+bottom)
537
	fdiv st0,st1       ;st1 = (top-bottom)
538
	fstp dword[B]      ;B = (top+bottom) / (top-bottom)
539
	fld dword[ebx+24]
540
	fsub dword[ebx+20] ;st0 = (farp-near)
541
	fld dword[ebx+24]
5418 IgorA 542
	fadd dword[ebx+20]
543
	fchs ;st0 = -(farp+near)
544
	fdiv st0,st1
5153 IgorA 545
	fstp dword[C]      ;C = -(farp+near) / (farp-near)
546
	fld dword[ebx+24]
547
	fmul dword[ebx+20] ;st0 = farp*near
548
	fadd st0,st0
549
	fchs               ;st0 = -(2.0*farp*near)
550
	fdiv st0,st1
551
	fstp dword[D]      ;D = -(2.0*farp*near) / (farp-near)
552
	ffree st0
5418 IgorA 553
	fincstp
554
	ffree st0
555
	fincstp
556
	ffree st0
557
	fincstp
558
5153 IgorA 559
 
560
	sub ecx,sizeof.M4
561
562
 
563
	mov dword[ecx],ebx
564
	mov dword[ecx+4],0.0
565
	mov ebx,[A]
566
	mov dword[ecx+8],ebx
567
	mov dword[ecx+12],0.0
568
	mov dword[ecx+16],0.0
569
	mov ebx,[y]
570
	mov dword[ecx+20],ebx
571
	mov ebx,[B]
572
	mov dword[ecx+24],ebx
573
	mov dword[ecx+28],0.0
574
	mov dword[ecx+32],0.0
575
	mov dword[ecx+36],0.0
576
	mov ebx,[C]
577
	mov dword[ecx+40],ebx
578
	mov ebx,[D]
579
	mov dword[ecx+44],ebx
580
	mov dword[ecx+48],0.0
581
	mov dword[ecx+52],0.0
582
	mov dword[ecx+56],-1.0
583
	mov dword[ecx+60],0.0
584
585
 
6523 IgorA 586
	shl ebx,2
5153 IgorA 587
	add ebx,eax
588
	stdcall gl_M4_MulLeft,dword[ebx+GLContext.matrix_stack_ptr],ecx
6523 IgorA 589
5153 IgorA 590
 
591
	stdcall gl_print_matrix,ecx,4
592
	stdcall gl_print_matrix,dword[ebx+GLContext.matrix_stack_ptr],4
6523 IgorA 593
end if
5153 IgorA 594
	gl_matrix_update eax,ebx
595
	ret
596
endp
597
598
 
8062 IgorA 599
proc glopOrtho uses eax ebx ecx, context:dword, p:dword
600
locals
601
	x dd ?
602
	y dd ?
603
	A dd ?
604
	B dd ?
605
	C dd ?
606
	D dd ?
607
	m M4
608
endl
609
	mov eax,[context]
610
	mov ebx,[p]
611
612
 
613
	fsub dword[ebx+4]  ;st0 = (right-left)
614
	fld1
615
	fadd st0,st0       ;st0 = 2.0
616
	fdiv st0,st1
617
	fstp dword[x]      ;x = 2.0 / (right-left)
618
	fld dword[ebx+16]
619
	fsub dword[ebx+12] ;st0 = (top-bottom)
620
	fld1
621
	fadd st0,st0       ;st0 = 2.0
622
	fdiv st0,st1
623
	fstp dword[y]      ;y = 2.0 / (top-bottom)
624
	fld dword[ebx+8]
625
	fadd dword[ebx+4]
626
	fchs               ;st0 = -(right+left)
627
	fdiv st0,st2       ;st2 = (right-left)
628
	fstp dword[A]      ;A = -(right+left) / (right-left)
629
	fld dword[ebx+16]
630
	fadd dword[ebx+12]
631
	fchs               ;st0 = -(top+bottom)
632
	fdiv st0,st1       ;st1 = (top-bottom)
633
	fstp dword[B]      ;B = -(top+bottom) / (top-bottom)
634
	fld dword[ebx+24]
635
	fsub dword[ebx+20] ;st0 = (farp-near)
636
	fld1
637
	fadd st0,st0
638
	fchs ;st0 = -2.0
639
	fdiv st0,st1
640
	fstp dword[C]      ;C = -2.0 / (farp-near)
641
	fld dword[ebx+24]
642
	fadd dword[ebx+20] ;st0 = farp+near
643
	fchs               ;st0 = -(farp+near)
644
	fdiv st0,st1
645
	fstp dword[D]      ;D = -(farp*near) / (farp-near)
646
	ffree st0
647
	fincstp
648
	ffree st0
649
	fincstp
650
	ffree st0
651
	fincstp
652
653
 
654
655
 
656
	mov dword[ecx],ebx
657
	mov dword[ecx+4],0.0
658
	mov dword[ecx+8],0.0
659
	mov ebx,[A]
660
	mov dword[ecx+12],ebx
661
	mov dword[ecx+16],0.0
662
	mov ebx,[y]
663
	mov dword[ecx+20],ebx
664
	mov dword[ecx+24],0.0
665
	mov ebx,[B]
666
	mov dword[ecx+28],ebx
667
	mov dword[ecx+32],0.0
668
	mov dword[ecx+36],0.0
669
	mov ebx,[C]
670
	mov dword[ecx+40],ebx
671
	mov ebx,[D]
672
	mov dword[ecx+44],ebx
673
	mov dword[ecx+48],0.0
674
	mov dword[ecx+52],0.0
675
	mov dword[ecx+56],0.0
676
	mov dword[ecx+60],1.0
677
678
 
679
	lea ebx,[eax+4*ebx]
680
	stdcall gl_M4_MulLeft,dword[ebx+GLContext.matrix_stack_ptr],ecx
681
682
 
683
	stdcall gl_print_matrix,ecx,4
684
	stdcall gl_print_matrix,dword[ebx+GLContext.matrix_stack_ptr],4
685
end if
686
	gl_matrix_update eax,ebx
687
	ret
688
endp
689