Subversion Repositories Kolibri OS

Rev

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

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