Subversion Repositories Kolibri OS

Rev

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