Subversion Repositories Kolibri OS

Rev

Rev 5218 | Rev 5262 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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