Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
5153 IgorA 1
 
2
proc glopNormal uses ecx esi edi, context:dword, p:dword
3
	mov esi,[p]
4
	add esi,4
5
	mov edi,[context]
6
	add edi,offs_cont_current_normal
7
	mov ecx,3
5218 IgorA 8
	rep movsd
5153 IgorA 9
	mov dword[edi],0.0 ;context.current_normal.W = 0.0
5218 IgorA 10
	ret
5153 IgorA 11
endp
12
13
 
14
proc glopTexCoord uses ecx esi edi, context:dword, p:dword
15
	mov esi,[p]
16
	add esi,4
17
	mov edi,[context]
18
	add edi,offs_cont_current_tex_coord
19
	mov ecx,4
20
	rep movsd
21
	ret
22
endp
23
24
 
25
proc glopEdgeFlag uses eax ebx, context:dword, p:dword
26
	mov eax,[context]
27
	mov ebx,[p]
28
	mov ebx,[ebx+4] ;ebx = p[1]
29
	mov dword[eax+offs_cont_current_edge_flag],ebx
30
	ret
31
endp
32
33
 
34
proc glopColor uses eax ecx esi edi, context:dword, p:dword
35
locals
36
	q rd 7
37
endl
38
	;current_color[3] = p[1-4]
39
	;longcurrent_color[2] = p[5-7]
40
	mov esi,[p]
41
	add esi,4
42
	mov edi,[context]
43
	add edi,offs_cont_current_color
44
	mov ecx,7
45
	rep movsd
46
47
 
48
	cmp dword[eax+offs_cont_color_material_enabled],0
5213 IgorA 49
	je @f
50
		mov dword[q],OP_Material
5153 IgorA 51
		mov ecx,[eax+offs_cont_current_color_material_mode]
52
		mov dword[q+4],ecx
53
		mov ecx,[eax+offs_cont_current_color_material_type]
54
		mov dword[q+8],ecx
55
		mov esi,[p]
56
		add esi,4
57
		mov edi,ebp
5213 IgorA 58
		sub edi,16 ;edi = &q[3]
59
		mov ecx,4
5153 IgorA 60
		rep movsd
61
		;mov edi,ebp
5262 IgorA 62
		sub edi,28 ;edi = &q
63
		stdcall glopMaterial, eax,edi
64
	@@:
5153 IgorA 65
	ret
66
endp
67
68
 
69
proc gl_eval_viewport uses eax, context:dword
70
locals
71
	zsize dd ? ;float
72
endl
73
	mov eax,[context]
74
	add eax,offs_cont_viewport ;eax = (GLViewport*) v
75
76
 
77
	fild dword[zsize]
78
	fstp dword[zsize]
79
80
 
81
	fld1
82
	fadd st1,st0 ;st1 = 2.0
83
	fdiv st0,st1 ;st0 = 0.5
84
85
 
86
	fsub st0,st1
87
	fdiv st0,st2
88
	fst dword[eax+offs_vpor_scale+offs_X]
89
	fiadd dword[eax+offs_vpor_xmin]
90
	fstp dword[eax+offs_vpor_trans+offs_X]
91
92
 
93
	fsub st0,st1
94
	fdiv st0,st2
95
	fchs
96
	fst dword[eax+offs_vpor_scale+offs_Y]
97
	fchs
98
	fiadd dword[eax+offs_vpor_ymin]
99
	fstp dword[eax+offs_vpor_trans+offs_Y]
100
101
 
102
	fsub st0,st1
103
	fdiv st0,st2
104
	fchs
105
	fst dword[eax+offs_vpor_scale+offs_Z]
106
	fchs
107
	mov dword[zsize],(1 shl ZB_POINT_Z_FRAC_BITS) / 2
108
	fiadd dword[zsize]
109
	fstp dword[eax+offs_vpor_trans+offs_Z]
110
	ret
111
endp
112
113
 
114
 
115
proc glopBegin uses eax ebx ecx edx, context:dword, p:dword
116
locals
117
	tmp M4
118
endl
119
;    assert(c->in_begin == 0);
120
121
 
122
	mov ebx,[p]
123
	mov ebx,[ebx+4] ;ebx = p[1]
124
	mov [edx+offs_cont_begin_type],ebx
125
	mov dword[edx+offs_cont_in_begin],1
126
	mov dword[edx+offs_cont_vertex_n],0
127
	mov dword[edx+offs_cont_vertex_cnt],0
128
129
 
130
	jnc .end_mmpu
131
132
 
133
	je @f
134
if DEBUG ;context.matrix_stack_ptr[0]
5256 IgorA 135
	stdcall gl_print_matrix,dword[edx+offs_cont_matrix_stack_ptr],4
136
end if
137
		; precompute inverse modelview
5153 IgorA 138
		mov ebx,ebp
139
		sub ebx,64
140
		stdcall gl_M4_Inv, ebx,dword[edx+offs_cont_matrix_stack_ptr]
5256 IgorA 141
if DEBUG ;tmp
142
	stdcall dbg_print,txt_sp,txt_nl
143
	stdcall gl_print_matrix,ebx,4
144
end if
145
		push ebx
146
		mov ebx,edx
147
		add ebx,offs_cont_matrix_model_view_inv
148
		stdcall gl_M4_Transpose, ebx
149
if DEBUG ;context.matrix_model_view_inv
150
	stdcall dbg_print,txt_sp,txt_nl
151
	stdcall gl_print_matrix,ebx,4
152
end if
153
		jmp .end_if_0
5153 IgorA 154
	@@:
155
		mov ecx,edx
156
		add ecx,offs_cont_matrix_model_projection
157
		; precompute projection matrix
158
		stdcall gl_M4_Mul, ecx,dword[edx+offs_cont_matrix_stack_ptr+4],dword[edx+offs_cont_matrix_stack_ptr]
159
5213 IgorA 160
 
5153 IgorA 161
		mov dword[edx+offs_cont_matrix_model_projection_no_w_transform],0
162
		fldz
163
		fld dword[ecx+12*4]
164
		fcomp st1
165
		fstsw ax
166
		sahf
167
		jne .end_if_0
168
		fld dword[ecx+13*4]
169
		fcomp st1
170
		fstsw ax
171
		sahf
172
		jne .end_if_0
173
		fld dword[ecx+14*4]
174
		fcomp st1
175
		fstsw ax
176
		sahf
177
		jne .end_if_0
178
			mov dword[edx+offs_cont_matrix_model_projection_no_w_transform],1
179
	.end_if_0:
180
181
 
182
		mov eax,edx
5218 IgorA 183
		add eax,offs_cont_matrix_stack_ptr+8
184
		stdcall gl_M4_IsId,eax
185
		xor eax,1
186
		mov dword[edx+offs_cont_apply_texture_matrix],eax
187
5153 IgorA 188
 
189
	.end_mmpu:
190
191
 
192
	cmp dword[edx+offs_cont_viewport+offs_vpor_updated],0 ;if (context.viewport.updated)
193
	je @f
194
		stdcall gl_eval_viewport,edx
195
		mov dword[edx+offs_cont_viewport+offs_vpor_updated],0
196
	@@:
197
	; triangle drawing functions
198
	cmp dword[edx+offs_cont_render_mode],GL_SELECT
199
	jne @f
200
		mov dword[edx+offs_cont_draw_triangle_front],gl_draw_triangle_select
201
		mov dword[edx+offs_cont_draw_triangle_back],gl_draw_triangle_select
202
		jmp .end_if_2
203
	@@:
204
205
 
206
	jne @f
207
		mov dword[edx+offs_cont_draw_triangle_front],gl_draw_triangle_point
208
		jmp .end_if_1
209
	@@:
210
	cmp dword[edx+offs_cont_polygon_mode_front],GL_LINE
211
	jne @f
212
		mov dword[edx+offs_cont_draw_triangle_front],gl_draw_triangle_line
213
		jmp .end_if_1
214
	@@: ;default:
215
		mov dword[edx+offs_cont_draw_triangle_front],gl_draw_triangle_fill
216
	.end_if_1:
217
218
 
219
	jne @f
220
		mov dword[edx+offs_cont_draw_triangle_back],gl_draw_triangle_point
221
		jmp .end_if_2
222
	@@:
223
	cmp dword[edx+offs_cont_polygon_mode_back],GL_LINE
224
	jne @f
225
		mov dword[edx+offs_cont_draw_triangle_back],gl_draw_triangle_line
226
		jmp .end_if_2
227
	@@: ;default:
228
	    mov dword[edx+offs_cont_draw_triangle_back],gl_draw_triangle_fill
229
	.end_if_2:
230
	ret
231
endp
232
233
 
234
; TODO : handle all cases
235
align 4
236
proc gl_vertex_transform, context:dword, v:dword
237
pushad
238
	mov eax,[context]
239
	mov edx,[v]
240
	cmp dword[eax+offs_cont_lighting_enabled],0 ;if (context.lighting_enabled)
241
	je .els_0
242
		; eye coordinates needed for lighting
243
		mov ebx,dword[eax+offs_cont_matrix_stack_ptr]
244
		finit
245
		fld dword[edx+offs_vert_coord+offs_X]
246
		fld dword[edx+offs_vert_coord+offs_Y]
247
		fld dword[edx+offs_vert_coord+offs_Z]
248
249
 
250
		.cycle_0:
251
			fld dword[ebx]     ;st0 = m[0]
252
			fmul st0,st3       ;st0 *= v.coord.X
253
			fld dword[ebx+4]   ;st0 = m[1]
254
			fmul st0,st3       ;st0 *= v.coord.Y
255
			faddp              ;st0 = v.coord.X * m[0] + v.coord.Y * m[1]
5269 IgorA 256
			fld dword[ebx+8]   ;st0 = m[2]
5153 IgorA 257
			fmul st0,st2       ;st0 *= v.coord.Z
5269 IgorA 258
			fadd dword[ebx+12] ;st0 += m[3]
5153 IgorA 259
			faddp              ;st0 += v.ec.X
5269 IgorA 260
			fstp dword[edx+offs_vert_ec] ;v.ec.X = v.coord.X * m[0] + v.coord.Y * m[1] + v.coord.Z * m[2] + m[3]
5153 IgorA 261
			add ebx,16 ;следущая строка матрицы
262
			add edx,4  ;следущая координата вектора
263
		loop .cycle_0
264
		ffree st0
5218 IgorA 265
		fincstp
266
		ffree st0
267
		fincstp
268
		ffree st0
269
		fincstp
270
5153 IgorA 271
 
272
		mov ebx,dword[eax+offs_cont_matrix_stack_ptr+4]
273
		mov edx,[v]
274
5218 IgorA 275
 
5153 IgorA 276
		fld dword[edx+offs_vert_ec+offs_Y]
277
		fld dword[edx+offs_vert_ec+offs_Z]
278
279
 
280
		.cycle_1:
281
			fld dword[ebx]     ;st0 = m[0]
282
			fmul st0,st3       ;st0 *= v.ec.X
283
			fld dword[ebx+4]   ;st0 = m[1]
284
			fmul st0,st3       ;st0 *= v.ec.Y
285
			faddp              ;st0 = v.ec.X * m[0] + v.ec.Y * m[1]
5269 IgorA 286
			fld dword[ebx+8]   ;st0 = m[2]
5153 IgorA 287
			fmul st0,st2       ;st0 *= v.ec.Z
5269 IgorA 288
			fadd dword[ebx+12] ;st0 += m[3]
5153 IgorA 289
			faddp              ;st0 = v.pc.X
5269 IgorA 290
			fstp dword[edx+offs_vert_pc] ;v.pc.X = v.ec.X * m[0] + v.ec.Y * m[1] + v.ec.Z * m[2] + m[3]
5153 IgorA 291
			add ebx,16 ;следущая строка матрицы
292
			add edx,4  ;следущая координата вектора
293
		loop .cycle_1
294
		ffree st0
5218 IgorA 295
		fincstp
296
		ffree st0
297
		fincstp
298
		ffree st0
299
		fincstp
300
5153 IgorA 301
 
302
		add ebx,offs_cont_matrix_model_view_inv
303
		mov edi,eax
304
		add edi,offs_cont_current_normal
305
		mov edx,[v]
306
5218 IgorA 307
 
5256 IgorA 308
		fld dword[edi+offs_Y]
5153 IgorA 309
		fld dword[edi+offs_Z]
310
311
 
312
		add edx,offs_vert_normal
5269 IgorA 313
		.cycle_2:
5153 IgorA 314
			fld dword[ebx]   ;st0 = m[0]
5218 IgorA 315
			fmul st0,st3     ;st0 *= n.X
316
			fld dword[ebx+4] ;st0 = m[1]
317
			fmul st0,st3     ;st0 *= n.Y
318
			faddp            ;st0 = n.X * m[0] + n.Y * m[1]
5269 IgorA 319
			fld dword[ebx+8] ;st0 = m[2]
5218 IgorA 320
			fmul st0,st2     ;st0 *= n.Z
5269 IgorA 321
			faddp            ;st0 = v.normal.X
322
			fstp dword[edx]  ;v.normal.X = n.X * m[0] + n.Y * m[1] + n.Z * m[2]
323
			add ebx,16 ;следущая строка матрицы
5153 IgorA 324
			add edx,4  ;следущая координата вектора
325
		loop .cycle_2
326
327
 
328
		je .end_els
329
			sub edx,12
5269 IgorA 330
			stdcall gl_V3_Norm,edx
5218 IgorA 331
		jmp .end_els
5153 IgorA 332
	.els_0:
333
		; no eye coordinates needed, no normal
334
		; NOTE: W = 1 is assumed
335
		mov ebx,eax
336
		add ebx,offs_cont_matrix_model_projection
337
338
 
339
		fld dword[edx+offs_vert_coord+offs_X]
340
		fld dword[edx+offs_vert_coord+offs_Y]
341
		fld dword[edx+offs_vert_coord+offs_Z]
342
343
 
344
		add esi,offs_vert_pc
345
346
 
347
		fmul st0,st3       ;st0 *= v.coord.X
348
		fld dword[ebx+4]   ;st0 = m[1]
349
		fmul st0,st3       ;st0 *= v.coord.Y
350
		faddp              ;st0 = v.coord.X * m[0] + v.coord.Y * m[1]
5269 IgorA 351
		fld dword[ebx+8]   ;st0 = m[2]
5153 IgorA 352
		fmul st0,st2       ;st0 *= v.coord.Z
5269 IgorA 353
		fadd dword[ebx+12] ;st0 += m[3]
5153 IgorA 354
		faddp              ;st0 = v.pc.X
5269 IgorA 355
		fstp dword[esi]    ;v.pc.X = v.coord.X * m[0] + v.coord.Y * m[1] + v.coord.Z * m[2] + m[3]
5153 IgorA 356
5175 IgorA 357
 
5153 IgorA 358
		fmul st0,st3       ;st0 *= v.coord.X
359
		fld dword[ebx+20]  ;st0 = m[5]
360
		fmul st0,st3       ;st0 *= v.coord.Y
361
		faddp              ;st0 = v.coord.X * m[4] + v.coord.Y * m[5]
5269 IgorA 362
		fld dword[ebx+24]  ;st0 = m[6]
5153 IgorA 363
		fmul st0,st2       ;st0 *= v.coord.Z
5269 IgorA 364
		fadd dword[ebx+28] ;st0 += m[7]
5153 IgorA 365
		faddp              ;st0 = v.pc.Y
5269 IgorA 366
		fstp dword[esi+4]  ;v.pc.Y = v.coord.X * m[4] + v.coord.Y * m[5] + v.coord.Z * m[6] + m[7]
367
5175 IgorA 368
 
5153 IgorA 369
		fmul st0,st3       ;st0 *= v.coord.X
370
		fld dword[ebx+36]  ;st0 = m[9]
371
		fmul st0,st3       ;st0 *= v.coord.Y
372
		faddp              ;st0 = v.coord.X * m[8] + v.coord.Y * m[9]
5269 IgorA 373
		fld dword[ebx+40]  ;st0 = m[10]
5153 IgorA 374
		fmul st0,st2       ;st0 *= v.coord.Z
5269 IgorA 375
		fadd dword[ebx+44] ;st0 += m[11]
5153 IgorA 376
		faddp              ;st0 = v.pc.Z
5269 IgorA 377
		fstp dword[esi+8]  ;v.pc.Z = v.coord.X * m[8] + v.coord.Y * m[9] + v.coord.Z * m[10] + m[11]
378
5153 IgorA 379
 
380
		je .els_1
381
			;if (context.matrix_model_projection_no_w_transform)
382
			mov ebx,dword[ebx+60] ;ebx = m[15]
383
			mov dword[esi+12],ebx ;v.pc.W = m[15]
384
			jmp .end_els
385
		.els_1:
386
			fld dword[ebx+48]  ;st0 = m[12]
387
			fmul st0,st3       ;st0 *= v.coord.X
388
			fld dword[ebx+52]  ;st0 = m[13]
389
			fmul st0,st3       ;st0 *= v.coord.Y
390
			faddp              ;st0 = v.coord.X * m[12] + v.coord.Y * m[13]
5269 IgorA 391
			fld dword[ebx+56]  ;st0 = m[14]
5153 IgorA 392
			fmul st0,st2       ;st0 *= v.coord.Z
5269 IgorA 393
			fadd dword[ebx+60] ;st0 += m[15]
5153 IgorA 394
			faddp              ;st0 = v.pc.W
5269 IgorA 395
			fstp dword[esi+12] ;v.pc.W = v.coord.X * m[12] + v.coord.Y * m[13] + v.coord.Z * m[14] + m[15]
5153 IgorA 396
	.end_els:
397
	ffree st0
5175 IgorA 398
	fincstp
399
	ffree st0
400
	fincstp
401
	ffree st0
402
	fincstp
403
404
 
5153 IgorA 405
	stdcall dbg_print,f_vt,txt_nl
406
	mov edx,[v]
407
	add edx,offs_vert_pc
408
	stdcall gl_print_matrix,edx,1
409
end if
410
	mov edx,[v]
411
	stdcall gl_clipcode, dword[edx+offs_vert_pc+offs_X], dword[edx+offs_vert_pc+offs_Y],\
412
		dword[edx+offs_vert_pc+offs_Z], dword[edx+offs_vert_pc+offs_W]
413
	mov dword[edx+offs_vert_clip_code],eax
414
popad
415
	ret
416
endp
417
418
 
419
proc glopVertex, context:dword, p:dword
420
locals
421
	;ebx = GLVertex * v
422
	n dd ? ;ebp-4
423
endl
424
pushad
425
	mov edx,[context]
426
427
 
428
429
 
430
	mov [n],ecx
431
	inc dword[edx+offs_cont_vertex_cnt]
432
433
 
434
	mov ecx,[edx+offs_cont_vertex_max]
435
	cmp dword[n],ecx
436
	jl @f
437
		shl dword[edx+offs_cont_vertex_max],1 ; just double size
438
		imul ecx,2*sizeof.GLVertex
439
		stdcall gl_malloc,ecx
440
		cmp eax,0
441
		jne .no_err
442
;gl_fatal_error("unable to allocate GLVertex array.\n");
443
		.no_err:
444
		mov edi,eax
445
		mov ebx,eax
446
		mov esi,[edx+offs_cont_vertex]
447
		mov ecx,[n]
448
		imul ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
449
		rep movsd
450
		stdcall gl_free,dword[edx+offs_cont_vertex]
451
		mov dword[edx+offs_cont_vertex],ebx
452
	@@:
453
	; new vertex entry
454
	mov ebx,[n]
455
	imul ebx,sizeof.GLVertex
456
	add ebx,[edx+offs_cont_vertex]
457
	inc dword[n]
458
459
 
460
	add esi,4
461
	mov edi,ebx
462
	add edi,offs_vert_coord ;edi = &v.coord
463
	mov ecx,4
464
	rep movsd
465
466
 
467
468
 
469
	cmp dword[edx+offs_cont_lighting_enabled],0
470
	je .els_0
471
		stdcall gl_shade_vertex, edx,ebx
472
		jmp @f
473
	.els_0:
474
		mov eax,[edx+offs_cont_current_color]
475
		mov [ebx+offs_vert_color],eax
476
		mov eax,[edx+offs_cont_current_color+4]
5213 IgorA 477
		mov [ebx+offs_vert_color+4],eax
478
		mov eax,[edx+offs_cont_current_color+8]
479
		mov [ebx+offs_vert_color+8],eax
480
	@@:
5153 IgorA 481
482
 
483
	cmp dword[edx+offs_cont_texture_2d_enabled],0
484
	je @f
485
		cmp dword[edx+offs_cont_apply_texture_matrix],0
486
		je .els_1
487
			mov eax,edx
5269 IgorA 488
			add eax,offs_cont_current_tex_coord
489
			push eax ;&context.current_tex_coord
490
			mov eax,ebx
491
			add eax,offs_vert_tex_coord
492
			stdcall gl_M4_MulV4, eax, dword[edx+offs_cont_matrix_stack_ptr+8]
493
			jmp @f
5153 IgorA 494
		.els_1:
495
			mov esi,edx
5269 IgorA 496
			add esi,offs_cont_current_tex_coord
497
			mov edi,ebx
498
			add edi,offs_vert_tex_coord
499
			mov ecx,4
500
			rep movsd
501
	@@:
5153 IgorA 502
503
 
504
	cmp dword[ebx+offs_vert_clip_code],0
505
	jne @f
506
		stdcall gl_transform_to_viewport, edx,ebx
507
	@@:
508
509
 
510
	mov eax,[edx+offs_cont_current_edge_flag]
511
	mov dword[ebx+offs_vert_edge_flag],eax ;v.edge_flag = context.current_edge_flag
512
513
 
514
	jne @f
515
		stdcall gl_draw_point, edx, dword[edx+offs_cont_vertex] ;dword[edx+...] = &context.vertex[0]
516
		mov dword[n],0
517
		jmp .end_f
518
	@@:
519
	cmp dword[edx+offs_cont_begin_type],GL_LINES
520
	jne @f
521
		cmp dword[n],2
522
		jne .end_f
523
			mov eax,[edx+offs_cont_vertex]
524
			push eax
525
			add eax,sizeof.GLVertex
526
			stdcall gl_draw_line, edx, eax
5175 IgorA 527
			xor eax,eax
5153 IgorA 528
			mov dword[n],eax
529
		jmp .end_f
530
	@@:
531
	cmp dword[edx+offs_cont_begin_type],GL_LINE_STRIP
532
	je .li_loop
533
	cmp dword[edx+offs_cont_begin_type],GL_LINE_LOOP
534
	jne @f
535
		.li_loop:
536
		cmp dword[n],1
537
		jne .els_2
538
			mov esi,[edx+offs_cont_vertex]
539
			mov edi,esi
540
			add edi,2*sizeof.GLVertex
541
			mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
542
			rep movsd ;context.vertex[2] = context.vertex[0]
543
			jmp .end_f
544
		.els_2:
545
		cmp dword[n],2
546
		jne .end_f ;else if (n == 2)
547
			mov eax,[edx+offs_cont_vertex]
548
			push eax
549
			mov edi,eax
5218 IgorA 550
			add eax,sizeof.GLVertex
5153 IgorA 551
			mov esi,eax
5218 IgorA 552
			stdcall gl_draw_line, edx, eax
5175 IgorA 553
			mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
5153 IgorA 554
			rep movsd ;context.vertex[0] = context.vertex[1]
555
			mov dword[n],1
556
		jmp .end_f
557
	@@:
558
	cmp dword[edx+offs_cont_begin_type],GL_TRIANGLES
559
	jne @f
560
		cmp dword[n],3
561
		jne .end_f
562
			mov eax,[edx+offs_cont_vertex]
5175 IgorA 563
			mov [esp-4],eax
5218 IgorA 564
			add eax,sizeof.GLVertex
5175 IgorA 565
			mov [esp-8],eax
5218 IgorA 566
			add eax,sizeof.GLVertex
5175 IgorA 567
			mov [esp-12],eax
5218 IgorA 568
			sub esp,12
569
			stdcall gl_draw_triangle, edx
570
			xor eax,eax
5153 IgorA 571
			mov dword[n],eax
572
		jmp .end_f
573
	@@:
574
	cmp dword[edx+offs_cont_begin_type],GL_TRIANGLE_STRIP
575
	jne @f
576
		cmp dword[edx+offs_cont_vertex_cnt],3 ;if (context.vertex_cnt >= 3)
5269 IgorA 577
		jl .end_f
578
			cmp dword[n],3
579
			jne .ts3
580
				xor eax,eax
581
				mov dword[n],eax
582
			.ts3:
583
			; needed to respect triangle orientation
584
			mov eax,[edx+offs_cont_vertex]
585
			bt dword[edx+offs_cont_vertex_cnt],0
586
			jc .case_1
587
				mov [esp-12],eax
588
				add eax,sizeof.GLVertex
589
				mov [esp-8],eax
590
				add eax,sizeof.GLVertex
591
				mov [esp-4],eax
592
				sub esp,12
593
				stdcall gl_draw_triangle, edx ;&v[2],&v[1],&v[0]
594
				jmp .end_f
595
			.case_1:
596
				mov [esp-4],eax
597
				add eax,sizeof.GLVertex
598
				mov [esp-8],eax
599
				add eax,sizeof.GLVertex
600
				mov [esp-12],eax
601
				sub esp,12
602
				stdcall gl_draw_triangle, edx ;&v[0],&v[1],&v[2]
603
		jmp .end_f
5153 IgorA 604
	@@:
605
	cmp dword[edx+offs_cont_begin_type],GL_TRIANGLE_FAN
606
	jne @f
607
		cmp dword[n],3
5218 IgorA 608
		jne .end_f
5153 IgorA 609
			mov eax,[edx+offs_cont_vertex]
5218 IgorA 610
			mov [esp-4],eax
611
			add eax,sizeof.GLVertex
612
			mov [esp-8],eax
613
			mov edi,eax
614
			add eax,sizeof.GLVertex
615
			mov [esp-12],eax
616
			mov esi,eax
617
			sub esp,12
618
			stdcall gl_draw_triangle, edx
619
			mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
620
			rep movsd ;context.vertex[1] = context.vertex[2]
621
			mov dword[n],2
5153 IgorA 622
		jmp .end_f
623
	@@:
624
	cmp dword[edx+offs_cont_begin_type],GL_QUADS
625
	jne @f
626
		cmp dword[n],4
627
		jne .end_f
628
			mov eax,[edx+offs_cont_vertex]
5213 IgorA 629
			add eax,2*sizeof.GLVertex
630
			mov dword[eax+offs_vert_edge_flag],0 ;context.vertex[2].edge_flag = 0
631
			push eax
632
			sub eax,sizeof.GLVertex
633
			push eax
634
			sub eax,sizeof.GLVertex
635
			stdcall gl_draw_triangle, edx,eax ;v0,v1,v2
636
			mov dword[eax+offs_vert_edge_flag],0 ;context.vertex[0].edge_flag = 0
637
			add eax,2*sizeof.GLVertex
638
			mov dword[eax+offs_vert_edge_flag],1 ;context.vertex[2].edge_flag = 1
639
			add eax,sizeof.GLVertex
640
			push eax
641
			sub eax,sizeof.GLVertex
642
			push eax
643
			sub eax,2*sizeof.GLVertex
644
			stdcall gl_draw_triangle, edx,eax ;v0,v2,v3
645
			xor eax,eax
5153 IgorA 646
			mov dword[n],eax
647
		jmp .end_f
648
	@@:
649
	cmp dword[edx+offs_cont_begin_type],GL_QUAD_STRIP
650
	jne @f
651
		cmp dword[n],4
5218 IgorA 652
		jne .end_f
5153 IgorA 653
			mov eax,[edx+offs_cont_vertex]
5218 IgorA 654
			mov [esp-4],eax
655
			mov edi,eax
656
			add eax,sizeof.GLVertex
657
			mov [esp-8],eax
658
			add eax,sizeof.GLVertex
659
			mov [esp-12],eax
660
			mov esi,eax
661
			sub esp,12
662
			stdcall gl_draw_triangle, edx ;v0,v1,v2
663
			mov [esp-12],eax
664
			add eax,sizeof.GLVertex
665
			mov [esp-8],eax
666
			sub eax,2*sizeof.GLVertex
667
			mov [esp-4],eax
668
			sub esp,12
669
			stdcall gl_draw_triangle, edx ;v1,v3,v2
670
			mov ecx,(sizeof.GLVertex)/2 ;((...)/2) копируем 2 вершины
671
			rep movsd ;context.vertex[0] = context.vertex[2], context.vertex[1] = context.vertex[3]
672
			mov dword[n],2
5153 IgorA 673
		jmp .end_f
674
	@@:
675
	cmp dword[edx+offs_cont_begin_type],GL_POLYGON
676
	je .end_f
5213 IgorA 677
;    default:
5153 IgorA 678
;       gl_fatal_error("glBegin: type %x not handled\n", c->begin_type);
679
;    }
680
	.end_f:
681
682
 
683
	mov [edx+offs_cont_vertex_n],ecx
684
popad
685
	ret
686
endp
687
688
 
689
proc glopEnd uses eax ebx ecx, context:dword, p:dword
5213 IgorA 690
	mov eax,[context]
5153 IgorA 691
;    assert(c->in_begin == 1);
692
693
 
694
	jne .else_i
695
		cmp dword[eax+offs_cont_vertex_cnt],3
696
		jl .end_i
697
			mov ebx,[eax+offs_cont_vertex]
698
			push ebx
699
			add ebx,2*sizeof.GLVertex
700
			push ebx
701
			stdcall gl_draw_line, eax
702
		jmp .end_i
703
	.else_i:
704
	cmp dword[eax+offs_cont_begin_type],GL_POLYGON
705
	jne .end_i
706
		mov ebx,dword[eax+offs_cont_vertex_cnt]
707
		@@: ;while (ebx >= 3)
708
		cmp ebx,3
709
		jl .end_i
710
			dec ebx
5213 IgorA 711
			mov ecx,ebx
712
			imul ecx,sizeof.GLVertex
713
			add ecx,[eax+offs_cont_vertex]
714
			push ecx ;ecx = &context.vertex[i]
715
			sub ecx,sizeof.GLVertex
716
			push ecx ;ecx = &context.vertex[i-1]
717
			stdcall gl_draw_triangle, eax,[eax+offs_cont_vertex]
718
		jmp @b
5153 IgorA 719
	.end_i:
720
	mov dword[eax+offs_cont_in_begin],0
721
	ret
722
endp
723