Subversion Repositories Kolibri OS

Rev

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

Rev 6523 Rev 8063
1
; fill triangle profile
1
; fill triangle profile
2
; #define PROFILE
2
; #define PROFILE
3
 
3
 
4
CLIP_XMIN equ (1<<0)
4
CLIP_XMIN equ (1<<0)
5
CLIP_XMAX equ (1<<1)
5
CLIP_XMAX equ (1<<1)
6
CLIP_YMIN equ (1<<2)
6
CLIP_YMIN equ (1<<2)
7
CLIP_YMAX equ (1<<3)
7
CLIP_YMAX equ (1<<3)
8
CLIP_ZMIN equ (1<<4)
8
CLIP_ZMIN equ (1<<4)
9
CLIP_ZMAX equ (1<<5)
9
CLIP_ZMAX equ (1<<5)
10
 
10
 
11
align 16
11
align 16
12
proc gl_transform_to_viewport uses eax ebx ecx, context:dword,v:dword
12
proc gl_transform_to_viewport uses eax ebx ecx, context:dword,v:dword
13
	mov eax,[context]
13
	mov eax,[context]
14
	mov ebx,[v]
14
	mov ebx,[v]
15
 
15
 
16
	; coordinates
16
	; coordinates
17
	fld1
17
	fld1
18
	fdiv dword[ebx+offs_vert_pc+offs_W] ;st0 = 1/v.pc.W
18
	fdiv dword[ebx+GLVertex.pc+offs_W] ;st0 = 1/v.pc.W
19
 
19
 
20
	fld dword[ebx+offs_vert_pc+offs_X] ;st0 = v.pc.X
20
	fld dword[ebx+GLVertex.pc+offs_X] ;st0 = v.pc.X
21
	fmul st0,st1
21
	fmul st0,st1
22
	fmul dword[eax+GLContext.viewport+offs_vpor_scale+offs_X]
22
	fmul dword[eax+GLContext.viewport+offs_vpor_scale+offs_X]
23
	fadd dword[eax+GLContext.viewport+offs_vpor_trans+offs_X]
23
	fadd dword[eax+GLContext.viewport+offs_vpor_trans+offs_X]
24
	fistp dword[ebx+offs_vert_zp] ;v.zp.x = st0, st0 = st1
24
	fistp dword[ebx+GLVertex.zp] ;v.zp.x = st0, st0 = st1
25
 
25
 
26
	fld dword[ebx+offs_vert_pc+offs_Y] ;st0 = v.pc.Y
26
	fld dword[ebx+GLVertex.pc+offs_Y] ;st0 = v.pc.Y
27
	fmul st0,st1
27
	fmul st0,st1
28
	fmul dword[eax+GLContext.viewport+offs_vpor_scale+offs_Y]
28
	fmul dword[eax+GLContext.viewport+offs_vpor_scale+offs_Y]
29
	fadd dword[eax+GLContext.viewport+offs_vpor_trans+offs_Y]
29
	fadd dword[eax+GLContext.viewport+offs_vpor_trans+offs_Y]
30
	fistp dword[ebx+offs_vert_zp+offs_zbup_y] ;v.zp.y = st0, st0 = st1
30
	fistp dword[ebx+GLVertex.zp+offs_zbup_y] ;v.zp.y = st0, st0 = st1
31
 
31
 
32
	fld dword[ebx+offs_vert_pc+offs_Z] ;st0 = v.pc.Z
32
	fld dword[ebx+GLVertex.pc+offs_Z] ;st0 = v.pc.Z
33
	fmulp
33
	fmulp
34
	fmul dword[eax+GLContext.viewport+offs_vpor_scale+offs_Z]
34
	fmul dword[eax+GLContext.viewport+offs_vpor_scale+offs_Z]
35
	fadd dword[eax+GLContext.viewport+offs_vpor_trans+offs_Z]
35
	fadd dword[eax+GLContext.viewport+offs_vpor_trans+offs_Z]
36
	fistp dword[ebx+offs_vert_zp+offs_zbup_z] ;v.zp.z = st0, st0 = st1
36
	fistp dword[ebx+GLVertex.zp+offs_zbup_z] ;v.zp.z = st0, st0 = st1
37
 
37
 
38
	; color
38
	; color
39
	cmp dword[eax+GLContext.lighting_enabled],0 ;if (context.lighting_enabled)
39
	cmp dword[eax+GLContext.lighting_enabled],0 ;if (context.lighting_enabled)
40
	je @f
40
	je @f
41
		mov ecx,ebx
-
 
42
		add ecx,offs_vert_zp+offs_zbup_b
41
		lea ecx,[ebx+GLVertex.zp+offs_zbup_b]
43
		push ecx
42
		push ecx
44
		add ecx,offs_zbup_g-offs_zbup_b
43
		add ecx,offs_zbup_g-offs_zbup_b
45
		push ecx
44
		push ecx
46
		add ecx,offs_zbup_r-offs_zbup_g
45
		add ecx,offs_zbup_r-offs_zbup_g
47
		push ecx
46
		push ecx
48
		stdcall RGBFtoRGBI, dword[ebx+offs_vert_color],dword[ebx+offs_vert_color+4],dword[ebx+offs_vert_color+8]
47
		stdcall RGBFtoRGBI, dword[ebx+GLVertex.color],dword[ebx+GLVertex.color+4],dword[ebx+GLVertex.color+8]
49
		jmp .end_if
48
		jmp .end_if
50
align 4
49
align 4
51
	@@:
50
	@@:
52
		; no need to convert to integer if no lighting : take current color
51
		; no need to convert to integer if no lighting : take current color
53
		mov ecx,[eax+GLContext.longcurrent_color]
52
		mov ecx,[eax+GLContext.longcurrent_color]
54
		mov dword[ebx+offs_vert_zp+offs_zbup_r],ecx
53
		mov dword[ebx+GLVertex.zp+offs_zbup_r],ecx
55
		mov ecx,[eax+GLContext.longcurrent_color+4]
54
		mov ecx,[eax+GLContext.longcurrent_color+4]
56
		mov dword[ebx+offs_vert_zp+offs_zbup_g],ecx
55
		mov dword[ebx+GLVertex.zp+offs_zbup_g],ecx
57
		mov ecx,[eax+GLContext.longcurrent_color+8]
56
		mov ecx,[eax+GLContext.longcurrent_color+8]
58
		mov dword[ebx+offs_vert_zp+offs_zbup_b],ecx
57
		mov dword[ebx+GLVertex.zp+offs_zbup_b],ecx
59
	.end_if:
58
	.end_if:
60
  
59
  
61
	; texture
60
	; texture
62
	cmp dword[eax+GLContext.texture_2d_enabled],0
61
	cmp dword[eax+GLContext.texture_2d_enabled],0
63
	je @f
62
	je @f
64
		mov eax,[eax+GLContext.current_texture] ;eax = &context.current_texture
63
		mov eax,[eax+GLContext.current_texture] ;eax = &context.current_texture
65
		mov eax,[eax] ;eax = context.current_texture
64
		mov eax,[eax] ;eax = context.current_texture
66
		;[eax+offs_text_images] = im = &context.current_texture.images[0]
65
		;[eax+offs_text_images] = im = &context.current_texture.images[0]
67
 
66
 
68
		fild dword[eax+offs_text_images+offs_imag_s_bound]
67
		fild dword[eax+offs_text_images+offs_imag_s_bound]
69
		fmul dword[ebx+offs_vert_tex_coord+offs_X]
68
		fmul dword[ebx+GLVertex.tex_coord+offs_X]
70
		fistp dword[ebx+offs_vert_zp+offs_zbup_s]
69
		fistp dword[ebx+GLVertex.zp+offs_zbup_s]
71
		;v.zp.s=(int)(v.tex_coord.X * im.s_bound)
70
		;v.zp.s=(int)(v.tex_coord.X * im.s_bound)
72
 
71
 
73
		fild dword[eax+offs_text_images+offs_imag_t_bound]
72
		fild dword[eax+offs_text_images+offs_imag_t_bound]
74
		fmul dword[ebx+offs_vert_tex_coord+offs_Y]
73
		fmul dword[ebx+GLVertex.tex_coord+offs_Y]
75
		fistp dword[ebx+offs_vert_zp+offs_zbup_t]
74
		fistp dword[ebx+GLVertex.zp+offs_zbup_t]
76
		;v.zp.t=(int)(v.tex_coord.Y * im.t_bound)
75
		;v.zp.t=(int)(v.tex_coord.Y * im.t_bound)
77
	@@:
76
	@@:
78
	ret
77
	ret
79
endp
78
endp
80
 
79
 
81
align 16
80
align 16
82
proc gl_add_select1 uses eax ebx ecx, context:dword, z1:dword,z2:dword,z3:dword
81
proc gl_add_select1 uses eax ebx ecx, context:dword, z1:dword,z2:dword,z3:dword
83
	mov eax,[z1]
82
	mov eax,[z1]
84
	mov ebx,eax
83
	mov ebx,eax
85
	cmp [z2],eax
84
	cmp [z2],eax
86
	jge @f
85
	jge @f
87
		mov eax,[z2]
86
		mov eax,[z2]
88
	@@:
87
	@@:
89
	cmp [z3],eax
88
	cmp [z3],eax
90
	jge @f
89
	jge @f
91
		mov eax,[z3]
90
		mov eax,[z3]
92
	@@:
91
	@@:
93
	cmp [z2],ebx
92
	cmp [z2],ebx
94
	jle @f
93
	jle @f
95
		mov ebx,[z2]
94
		mov ebx,[z2]
96
	@@:
95
	@@:
97
	cmp [z3],ebx
96
	cmp [z3],ebx
98
	jle @f
97
	jle @f
99
		mov ebx,[z3]
98
		mov ebx,[z3]
100
	@@:
99
	@@:
101
	mov ecx,0xffffffff
100
	mov ecx,0xffffffff
102
	sub ecx,ebx
101
	sub ecx,ebx
103
	push ecx
102
	push ecx
104
	mov ecx,0xffffffff
103
	mov ecx,0xffffffff
105
	sub ecx,eax
104
	sub ecx,eax
106
	push ecx
105
	push ecx
107
	stdcall gl_add_select, [context] ;,0xffffffff-eax,0xffffffff-ebx
106
	stdcall gl_add_select, [context] ;,0xffffffff-eax,0xffffffff-ebx
108
	ret
107
	ret
109
endp
108
endp
110
 
109
 
111
; point
110
; point
112
 
111
 
113
align 16
112
align 16
114
proc gl_draw_point uses eax ebx, context:dword, p0:dword
113
proc gl_draw_point uses eax ebx, context:dword, p0:dword
115
	mov ebx,[p0]
114
	mov ebx,[p0]
116
	cmp dword[ebx+offs_vert_clip_code],0 ;if (p0.clip_code == 0)
115
	cmp dword[ebx+GLVertex.clip_code],0 ;if (p0.clip_code == 0)
117
	jne @f
116
	jne @f
118
	mov eax,[context]
117
	mov eax,[context]
119
	cmp dword[eax+GLContext.render_mode],GL_SELECT
118
	cmp dword[eax+GLContext.render_mode],GL_SELECT
120
	jne .els
119
	jne .els
121
		stdcall gl_add_select, eax,dword[ebx+offs_vert_zp+offs_zbup_z],dword[ebx+offs_vert_zp+offs_zbup_z] ;p0.zp.z,p0.zp.z
120
		stdcall gl_add_select, eax,dword[ebx+GLVertex.zp+offs_zbup_z],dword[ebx+GLVertex.zp+offs_zbup_z] ;p0.zp.z,p0.zp.z
122
		jmp @f
121
		jmp @f
123
align 4
122
align 4
124
	.els:
123
	.els:
125
		add ebx,offs_vert_zp
124
		add ebx,GLVertex.zp
126
		stdcall ZB_plot, dword[eax+GLContext.zb],ebx
125
		stdcall ZB_plot, dword[eax+GLContext.zb],ebx
127
	@@:
126
	@@:
128
	ret
127
	ret
129
endp
128
endp
130
 
129
 
131
; line
130
; line
132
 
131
 
133
;input:
132
;input:
134
;q - регистр с адресом вершины для интерполяции
133
;q - регистр с адресом вершины для интерполяции
135
;p0 - регистр с адресом 1-й вершины
134
;p0 - регистр с адресом 1-й вершины
136
;p1 - регистр с адресом 2-й вершины
135
;p1 - регистр с адресом 2-й вершины
137
;t - float
136
;t - float
138
macro interpolate q, p0, p1, t
137
macro interpolate q, p0, p1, t
139
{
138
{
140
	fld dword[t]
139
	fld dword[t]
141
 
140
 
142
	; интерполяция по координатам
141
	; интерполяция по координатам
143
	fld dword[p1+offs_vert_pc]
142
	fld dword[p1+GLVertex.pc]
144
	fsub dword[p0+offs_vert_pc]
143
	fsub dword[p0+GLVertex.pc]
145
	fmul st0,st1
144
	fmul st0,st1
146
	fadd dword[p0+offs_vert_pc]
145
	fadd dword[p0+GLVertex.pc]
147
	fstp dword[q+offs_vert_pc] ;q.pc.X = p0.pc.X + (p1.pc.X - p0.pc.X) * t
146
	fstp dword[q+GLVertex.pc] ;q.pc.X = p0.pc.X + (p1.pc.X - p0.pc.X) * t
148
 
147
 
149
	fld dword[p1+offs_vert_pc+offs_Y]
148
	fld dword[p1+GLVertex.pc+offs_Y]
150
	fsub dword[p0+offs_vert_pc+offs_Y]
149
	fsub dword[p0+GLVertex.pc+offs_Y]
151
	fmul st0,st1
150
	fmul st0,st1
152
	fadd dword[p0+offs_vert_pc+offs_Y]
151
	fadd dword[p0+GLVertex.pc+offs_Y]
153
	fstp dword[q+offs_vert_pc+offs_Y]
152
	fstp dword[q+GLVertex.pc+offs_Y]
154
 
153
 
155
	fld dword[p1+offs_vert_pc+offs_Z]
154
	fld dword[p1+GLVertex.pc+offs_Z]
156
	fsub dword[p0+offs_vert_pc+offs_Z]
155
	fsub dword[p0+GLVertex.pc+offs_Z]
157
	fmul st0,st1
156
	fmul st0,st1
158
	fadd dword[p0+offs_vert_pc+offs_Z]
157
	fadd dword[p0+GLVertex.pc+offs_Z]
159
	fstp dword[q+offs_vert_pc+offs_Z]
158
	fstp dword[q+GLVertex.pc+offs_Z]
160
 
159
 
161
	fld dword[p1+offs_vert_pc+offs_W]
160
	fld dword[p1+GLVertex.pc+offs_W]
162
	fsub dword[p0+offs_vert_pc+offs_W]
161
	fsub dword[p0+GLVertex.pc+offs_W]
163
	fmul st0,st1
162
	fmul st0,st1
164
	fadd dword[p0+offs_vert_pc+offs_W]
163
	fadd dword[p0+GLVertex.pc+offs_W]
165
	fstp dword[q+offs_vert_pc+offs_W]
164
	fstp dword[q+GLVertex.pc+offs_W]
166
 
165
 
167
	; интерполяция по цвету
166
	; интерполяция по цвету
168
	fld dword[p1+offs_vert_color]
167
	fld dword[p1+GLVertex.color]
169
	fsub dword[p0+offs_vert_color]
168
	fsub dword[p0+GLVertex.color]
170
	fmul st0,st1
169
	fmul st0,st1
171
	fadd dword[p0+offs_vert_color]
170
	fadd dword[p0+GLVertex.color]
172
	fstp dword[q+offs_vert_color]
171
	fstp dword[q+GLVertex.color]
173
 
172
 
174
	fld dword[p1+offs_vert_color+4]
173
	fld dword[p1+GLVertex.color+4]
175
	fsub dword[p0+offs_vert_color+4]
174
	fsub dword[p0+GLVertex.color+4]
176
	fmul st0,st1
175
	fmul st0,st1
177
	fadd dword[p0+offs_vert_color+4]
176
	fadd dword[p0+GLVertex.color+4]
178
	fstp dword[q+offs_vert_color+4]
177
	fstp dword[q+GLVertex.color+4]
179
 
178
 
180
	fld dword[p1+offs_vert_color+8]
179
	fld dword[p1+GLVertex.color+8]
181
	fsub dword[p0+offs_vert_color+8]
180
	fsub dword[p0+GLVertex.color+8]
182
	fmulp
181
	fmulp
183
	fadd dword[p0+offs_vert_color+8]
182
	fadd dword[p0+GLVertex.color+8]
184
	fstp dword[q+offs_vert_color+8]
183
	fstp dword[q+GLVertex.color+8]
185
}
184
}
186
 
185
 
187
;
186
;
188
; Line Clipping 
187
; Line Clipping 
189
;
188
;
190
 
189
 
191
; Line Clipping algorithm from 'Computer Graphics', Principles and
190
; Line Clipping algorithm from 'Computer Graphics', Principles and
192
; Practice
191
; Practice
193
; tmin,tmax -> &float
192
; tmin,tmax -> &float
194
align 16
193
align 16
195
proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword
194
proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword
196
	fld dword[denom]
195
	fld dword[denom]
197
	ftst
196
	ftst
198
	fstsw ax
197
	fstsw ax
199
	sahf
198
	sahf
200
	jbe .els_0 ;if (denom>0)
199
	jbe .els_0 ;if (denom>0)
201
		fld dword[num]
200
		fld dword[num]
202
		fxch st1
201
		fxch st1
203
		fdivp ;t=num/denom
202
		fdivp ;t=num/denom
204
		mov ebx,[tmax]
203
		mov ebx,[tmax]
205
		fcom dword[ebx]
204
		fcom dword[ebx]
206
		fstsw ax
205
		fstsw ax
207
		sahf
206
		sahf
208
		ja .r0_f1 ;if (t>*tmax) return 0
207
		ja .r0_f1 ;if (t>*tmax) return 0
209
		mov ebx,[tmin]
208
		mov ebx,[tmin]
210
		fcom dword[ebx]
209
		fcom dword[ebx]
211
		fstsw ax
210
		fstsw ax
212
		sahf
211
		sahf
213
		jbe .r1_f1 ;if (t>*tmin) *tmin=t
212
		jbe .r1_f1 ;if (t>*tmin) *tmin=t
214
			fstp dword[ebx] 
213
			fstp dword[ebx] 
215
		jmp .r1
214
		jmp .r1
216
align 4
215
align 4
217
	.els_0: ;else if (denom<0)
216
	.els_0: ;else if (denom<0)
218
		jae .els_1
217
		jae .els_1
219
		fld dword[num]
218
		fld dword[num]
220
		fxch st1
219
		fxch st1
221
		fdivp ;t=num/denom
220
		fdivp ;t=num/denom
222
		mov ebx,[tmin]
221
		mov ebx,[tmin]
223
		fcom dword[ebx]
222
		fcom dword[ebx]
224
		fstsw ax
223
		fstsw ax
225
		sahf
224
		sahf
226
		jb .r0_f1 ;if (t<*tmin) return 0
225
		jb .r0_f1 ;if (t<*tmin) return 0
227
		mov ebx,[tmax]
226
		mov ebx,[tmax]
228
		fcom dword[ebx]
227
		fcom dword[ebx]
229
		fstsw ax
228
		fstsw ax
230
		sahf
229
		sahf
231
		jae .r1_f1
230
		jae .r1_f1
232
			fstp dword[ebx] ;if (t<*tmin) *tmax=t
231
			fstp dword[ebx] ;if (t<*tmin) *tmax=t
233
		jmp .r1
232
		jmp .r1
234
align 4
233
align 4
235
	.els_1: ;else if (num>0)
234
	.els_1: ;else if (num>0)
236
		ffree st0 ;denom
235
		ffree st0 ;denom
237
		fincstp
236
		fincstp
238
		fld dword[num]
237
		fld dword[num]
239
		ftst
238
		ftst
240
		fstsw ax
239
		fstsw ax
241
		sahf
240
		sahf
242
		ja .r0_f1 ;if (num>0) return 0
241
		ja .r0_f1 ;if (num>0) return 0
243
		jmp .r1_f1
242
		jmp .r1_f1
244
align 4
243
align 4
245
	.r0_f1: ;return 0 & free st0
244
	.r0_f1: ;return 0 & free st0
246
		ffree st0
245
		ffree st0
247
		fincstp
246
		fincstp
248
	.r0: ;return 0
247
	.r0: ;return 0
249
		xor eax,eax
248
		xor eax,eax
250
		jmp .end_f
249
		jmp .end_f
251
align 4
250
align 4
252
	.r1_f1: ;return 1 & free st0
251
	.r1_f1: ;return 1 & free st0
253
		ffree st0
252
		ffree st0
254
		fincstp
253
		fincstp
255
	.r1: ;return 1
254
	.r1: ;return 1
256
		xor eax,eax
255
		xor eax,eax
257
		inc eax
256
		inc eax
258
	.end_f:
257
	.end_f:
259
	ret
258
	ret
260
endp
259
endp
261
 
260
 
262
align 16
261
align 16
263
proc gl_draw_line, context:dword, p1:dword, p2:dword
262
proc gl_draw_line, context:dword, p1:dword, p2:dword
264
locals
263
locals
265
	d_x dd ?
264
	d_x dd ?
266
	d_y dd ?
265
	d_y dd ?
267
	d_z dd ?
266
	d_z dd ?
268
	d_w dd ?
267
	d_w dd ?
269
	x1 dd ?
268
	x1 dd ?
270
	y1 dd ?
269
	y1 dd ?
271
	z1 dd ?
270
	z1 dd ?
272
	w1 dd ?
271
	w1 dd ?
273
	q1 GLVertex ?
272
	q1 GLVertex ?
274
	q2 GLVertex ?
273
	q2 GLVertex ?
275
	tmin dd ? ;ebp-8
274
	tmin dd ? ;ebp-8
276
	tmax dd ? ;ebp-4
275
	tmax dd ? ;ebp-4
277
endl
276
endl
278
pushad
277
pushad
279
	mov edx,[context]
278
	mov edx,[context]
280
	mov edi,[p1]
279
	mov edi,[p1]
281
	mov esi,[p2]
280
	mov esi,[p2]
282
 
281
 
283
	cmp dword[edi+offs_vert_clip_code],0
282
	cmp dword[edi+GLVertex.clip_code],0
284
	jne .els_i
283
	jne .els_i
285
	cmp dword[esi+offs_vert_clip_code],0
284
	cmp dword[esi+GLVertex.clip_code],0
286
	jne .els_i
285
	jne .els_i
287
		;if ( (p1.clip_code | p2.clip_code) == 0)
286
		;if ( (p1.clip_code | p2.clip_code) == 0)
288
		cmp dword[edx+GLContext.render_mode],GL_SELECT ;if (context.render_mode == GL_SELECT)
287
		cmp dword[edx+GLContext.render_mode],GL_SELECT ;if (context.render_mode == GL_SELECT)
289
		jne .els_1
288
		jne .els_1
290
			stdcall gl_add_select1, edx,dword[edi+offs_vert_zp+offs_zbup_z],\
289
			stdcall gl_add_select1, edx,dword[edi+GLVertex.zp+offs_zbup_z],\
291
				dword[esi+offs_vert_zp+offs_zbup_z],dword[esi+offs_vert_zp+offs_zbup_z]
290
				dword[esi+GLVertex.zp+offs_zbup_z],dword[esi+GLVertex.zp+offs_zbup_z]
292
			jmp .end_f
291
			jmp .end_f
293
align 4
292
align 4
294
		.els_1:
293
		.els_1:
295
			add edi,offs_vert_zp
294
			add edi,GLVertex.zp
296
			add esi,offs_vert_zp
295
			add esi,GLVertex.zp
297
			push esi
296
			push esi
298
			push edi
297
			push edi
299
			push dword[edx+GLContext.zb]
298
			push dword[edx+GLContext.zb]
300
			cmp dword[edx+GLContext.depth_test],0
299
			cmp dword[edx+GLContext.depth_test],0
301
			je .els_2
300
			je .els_2
302
				;if (context.depth_test)
301
				;if (context.depth_test)
303
				call ZB_line_z ;, dword[edx+GLContext.zb],edi,esi
302
				call ZB_line_z ;, dword[edx+GLContext.zb],edi,esi
304
				jmp .end_f
303
				jmp .end_f
305
align 4
304
align 4
306
			.els_2:
305
			.els_2:
307
				call ZB_line ;, dword[edx+GLContext.zb],edi,esi
306
				call ZB_line ;, dword[edx+GLContext.zb],edi,esi
308
				jmp .end_f
307
				jmp .end_f
309
align 4
308
align 4
310
	.els_i:
309
	.els_i:
311
		;else if ( (p1.clip_code & p2.clip_code) != 0 )
310
		;else if ( (p1.clip_code & p2.clip_code) != 0 )
312
		mov eax,[edi+offs_vert_clip_code]
311
		mov eax,[edi+GLVertex.clip_code]
313
		and eax,[esi+offs_vert_clip_code]
312
		and eax,[esi+GLVertex.clip_code]
314
		or eax,eax
313
		or eax,eax
315
		jnz .end_f
314
		jnz .end_f
316
	.els_0:
315
	.els_0:
317
 
316
 
318
	fld dword[esi+offs_vert_pc+offs_X]
317
	fld dword[esi+GLVertex.pc+offs_X]
319
	fsub dword[edi+offs_vert_pc+offs_X]
318
	fsub dword[edi+GLVertex.pc+offs_X]
320
	fstp dword[d_x] ;d_x = p2.pc.X - p1.pc.X
319
	fstp dword[d_x] ;d_x = p2.pc.X - p1.pc.X
321
	fld dword[esi+offs_vert_pc+offs_Y]
320
	fld dword[esi+GLVertex.pc+offs_Y]
322
	fsub dword[edi+offs_vert_pc+offs_Y]
321
	fsub dword[edi+GLVertex.pc+offs_Y]
323
	fstp dword[d_y] ;d_y = p2.pc.Y - p1.pc.Y
322
	fstp dword[d_y] ;d_y = p2.pc.Y - p1.pc.Y
324
	fld dword[esi+offs_vert_pc+offs_Z]
323
	fld dword[esi+GLVertex.pc+offs_Z]
325
	fsub dword[edi+offs_vert_pc+offs_Z]
324
	fsub dword[edi+GLVertex.pc+offs_Z]
326
	fstp dword[d_z] ;d_z = p2.pc.Z - p1.pc.Z
325
	fstp dword[d_z] ;d_z = p2.pc.Z - p1.pc.Z
327
	fld dword[esi+offs_vert_pc+offs_W]
326
	fld dword[esi+GLVertex.pc+offs_W]
328
	fsub dword[edi+offs_vert_pc+offs_W]
327
	fsub dword[edi+GLVertex.pc+offs_W]
329
	fstp dword[d_w] ;d_w = p2.pc.W - p1.pc.W
328
	fstp dword[d_w] ;d_w = p2.pc.W - p1.pc.W
330
 
329
 
331
	mov eax,[edi+offs_vert_pc+offs_X]
330
	mov eax,[edi+GLVertex.pc+offs_X]
332
	mov [x1],eax ;x1 = p1.pc.X
331
	mov [x1],eax ;x1 = p1.pc.X
333
	mov eax,[edi+offs_vert_pc+offs_Y]
332
	mov eax,[edi+GLVertex.pc+offs_Y]
334
	mov [y1],eax ;y1 = p1.pc.Y
333
	mov [y1],eax ;y1 = p1.pc.Y
335
	mov eax,[edi+offs_vert_pc+offs_Z]
334
	mov eax,[edi+GLVertex.pc+offs_Z]
336
	mov [z1],eax ;z1 = p1.pc.Z
335
	mov [z1],eax ;z1 = p1.pc.Z
337
	mov eax,[edi+offs_vert_pc+offs_W]
336
	mov eax,[edi+GLVertex.pc+offs_W]
338
	mov [w1],eax ;w1 = p1.pc.W
337
	mov [w1],eax ;w1 = p1.pc.W
339
 
338
 
340
	mov dword[tmin],0.0
339
	mov dword[tmin],0.0
341
	mov dword[tmax],1.0
340
	mov dword[tmax],1.0
342
 
341
 
343
	mov eax,ebp
-
 
344
	sub eax,4
342
	lea eax,[ebp-4]
345
	push eax ;толкаем в стек адрес &tmax
343
	push eax ;толкаем в стек адрес &tmax
346
	sub eax,4
344
	sub eax,4
347
	push eax ;толкаем в стек адрес &tmin
345
	push eax ;толкаем в стек адрес &tmin
348
	fld dword[x1]
346
	fld dword[x1]
349
	fadd dword[w1]
347
	fadd dword[w1]
350
	fchs
348
	fchs
351
	fstp dword[esp-4]
349
	fstp dword[esp-4]
352
	fld dword[d_x]
350
	fld dword[d_x]
353
	fadd dword[d_w]
351
	fadd dword[d_w]
354
	fstp dword[esp-8]
352
	fstp dword[esp-8]
355
	sub esp,8
353
	sub esp,8
356
	call ClipLine1 ;d_x+d_w,-x1-w1,&tmin,&tmax
354
	call ClipLine1 ;d_x+d_w,-x1-w1,&tmin,&tmax
357
	bt eax,0
355
	bt eax,0
358
	jnc .end_f
356
	jnc .end_f
359
 
357
 
360
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
358
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
361
	fld dword[x1]
359
	fld dword[x1]
362
	fsub dword[w1]
360
	fsub dword[w1]
363
	fstp dword[esp-4]
361
	fstp dword[esp-4]
364
	fld dword[d_w]
362
	fld dword[d_w]
365
	fsub dword[d_x]
363
	fsub dword[d_x]
366
	fstp dword[esp-8]
364
	fstp dword[esp-8]
367
	sub esp,8
365
	sub esp,8
368
	call ClipLine1 ;-d_x+d_w,x1-w1,&tmin,&tmax
366
	call ClipLine1 ;-d_x+d_w,x1-w1,&tmin,&tmax
369
	bt eax,0
367
	bt eax,0
370
	jnc .end_f
368
	jnc .end_f
371
 
369
 
372
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
370
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
373
	fld dword[y1]
371
	fld dword[y1]
374
	fadd dword[w1]
372
	fadd dword[w1]
375
	fchs
373
	fchs
376
	fstp dword[esp-4]
374
	fstp dword[esp-4]
377
	fld dword[d_y]
375
	fld dword[d_y]
378
	fadd dword[d_w]
376
	fadd dword[d_w]
379
	fstp dword[esp-8]
377
	fstp dword[esp-8]
380
	sub esp,8
378
	sub esp,8
381
	call ClipLine1 ;d_y+d_w,-y1-w1,&tmin,&tmax
379
	call ClipLine1 ;d_y+d_w,-y1-w1,&tmin,&tmax
382
	bt eax,0
380
	bt eax,0
383
	jnc .end_f
381
	jnc .end_f
384
 
382
 
385
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
383
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
386
	fld dword[y1]
384
	fld dword[y1]
387
	fsub dword[w1]
385
	fsub dword[w1]
388
	fstp dword[esp-4]
386
	fstp dword[esp-4]
389
	fld dword[d_w]
387
	fld dword[d_w]
390
	fsub dword[d_y]
388
	fsub dword[d_y]
391
	fstp dword[esp-8]
389
	fstp dword[esp-8]
392
	sub esp,8
390
	sub esp,8
393
	call ClipLine1 ;-d_y+d_w,y1-w1,&tmin,&tmax
391
	call ClipLine1 ;-d_y+d_w,y1-w1,&tmin,&tmax
394
	bt eax,0
392
	bt eax,0
395
	jnc .end_f
393
	jnc .end_f
396
 
394
 
397
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
395
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
398
	fld dword[z1]
396
	fld dword[z1]
399
	fadd dword[w1]
397
	fadd dword[w1]
400
	fchs
398
	fchs
401
	fstp dword[esp-4]
399
	fstp dword[esp-4]
402
	fld dword[d_z]
400
	fld dword[d_z]
403
	fadd dword[d_w]
401
	fadd dword[d_w]
404
	fstp dword[esp-8]
402
	fstp dword[esp-8]
405
	sub esp,8
403
	sub esp,8
406
	call ClipLine1 ;d_z+d_w,-z1-w1,&tmin,&tmax
404
	call ClipLine1 ;d_z+d_w,-z1-w1,&tmin,&tmax
407
	bt eax,0
405
	bt eax,0
408
	jnc .end_f
406
	jnc .end_f
409
 
407
 
410
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
408
	sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
411
	fld dword[z1]
409
	fld dword[z1]
412
	fsub dword[w1]
410
	fsub dword[w1]
413
	fstp dword[esp-4]
411
	fstp dword[esp-4]
414
	fld dword[d_w]
412
	fld dword[d_w]
415
	fsub dword[d_z]
413
	fsub dword[d_z]
416
	fstp dword[esp-8]
414
	fstp dword[esp-8]
417
	sub esp,8
415
	sub esp,8
418
	call ClipLine1 ;-d_z+d_w,z1-w1,&tmin,&tmax
416
	call ClipLine1 ;-d_z+d_w,z1-w1,&tmin,&tmax
419
	bt eax,0
417
	bt eax,0
420
	jnc .end_f
418
	jnc .end_f
421
 
-
 
422
	mov eax,ebp
419
 
423
	sub eax,8+2*sizeof.GLVertex ;eax = &q1
420
	lea eax,[ebp-8-2*sizeof.GLVertex] ;eax = &q1
424
	interpolate eax,edi,esi,tmin
421
	interpolate eax,edi,esi,tmin
425
	stdcall gl_transform_to_viewport, edx,eax
422
	stdcall gl_transform_to_viewport, edx,eax
426
	add eax,sizeof.GLVertex ;eax = &q2
423
	add eax,sizeof.GLVertex ;eax = &q2
427
	interpolate eax,edi,esi,tmax
424
	interpolate eax,edi,esi,tmax
428
	stdcall gl_transform_to_viewport, edx,eax
425
	stdcall gl_transform_to_viewport, edx,eax
429
 
426
 
430
	sub eax,sizeof.GLVertex ;eax = &q1
427
	sub eax,sizeof.GLVertex ;eax = &q1
431
	mov ebx,eax
-
 
432
	add ebx,offs_vert_zp+offs_zbup_b
428
	lea ebx,[eax+GLVertex.zp+offs_zbup_b]
433
	push ebx
429
	push ebx
434
	add ebx,offs_zbup_g-offs_zbup_b
430
	add ebx,offs_zbup_g-offs_zbup_b
435
	push ebx
431
	push ebx
436
	add ebx,offs_zbup_r-offs_zbup_g
432
	add ebx,offs_zbup_r-offs_zbup_g
437
	push ebx
433
	push ebx
438
	stdcall RGBFtoRGBI, dword[eax+offs_vert_color],dword[eax+offs_vert_color+4],dword[eax+offs_vert_color+8]
434
	stdcall RGBFtoRGBI, dword[eax+GLVertex.color],dword[eax+GLVertex.color+4],dword[eax+GLVertex.color+8]
439
 
435
 
440
	add eax,sizeof.GLVertex ;eax = &q2
-
 
441
	mov ebx,eax
436
	add eax,sizeof.GLVertex ;eax = &q2
442
	add ebx,offs_vert_zp+offs_zbup_b
437
	lea ebx,[eax+GLVertex.zp+offs_zbup_b]
443
	push ebx
438
	push ebx
444
	add ebx,offs_zbup_g-offs_zbup_b
439
	add ebx,offs_zbup_g-offs_zbup_b
445
	push ebx
440
	push ebx
446
	add ebx,offs_zbup_r-offs_zbup_g
441
	add ebx,offs_zbup_r-offs_zbup_g
447
	push ebx
442
	push ebx
448
	stdcall RGBFtoRGBI, dword[eax+offs_vert_color],dword[eax+offs_vert_color+4],dword[eax+offs_vert_color+8]
443
	stdcall RGBFtoRGBI, dword[eax+GLVertex.color],dword[eax+GLVertex.color+4],dword[eax+GLVertex.color+8]
449
 
444
 
450
	add eax,offs_vert_zp ;eax = &q2.zp
445
	add eax,GLVertex.zp ;eax = &q2.zp
451
	push eax
446
	push eax
452
	sub eax,sizeof.GLVertex ;eax = &q1.zp
447
	sub eax,sizeof.GLVertex ;eax = &q1.zp
453
	push eax
448
	push eax
454
	push dword[edx+GLContext.zb]
449
	push dword[edx+GLContext.zb]
455
	cmp dword[edx+GLContext.depth_test],0
450
	cmp dword[edx+GLContext.depth_test],0
456
	je .els_3
451
	je .els_3
457
		call ZB_line_z ;(context.zb,&q1.zp,&q2.zp)
452
		call ZB_line_z ;(context.zb,&q1.zp,&q2.zp)
458
		jmp .end_f
453
		jmp .end_f
459
align 4
454
align 4
460
	.els_3:
455
	.els_3:
461
		call ZB_line ;(context.zb,&q1.zp,&q2.zp)
456
		call ZB_line ;(context.zb,&q1.zp,&q2.zp)
462
	.end_f:
457
	.end_f:
463
popad
458
popad
464
	ret
459
	ret
465
endp
460
endp
466
 
461
 
467
; triangle
462
; triangle
468
 
463
 
469
;
464
;
470
; Clipping
465
; Clipping
471
;
466
;
472
 
467
 
473
; We clip the segment [a,b] against the 6 planes of the normal volume.
468
; We clip the segment [a,b] against the 6 planes of the normal volume.
474
; We compute the point 'c' of intersection and the value of the parameter 't'
469
; We compute the point 'c' of intersection and the value of the parameter 't'
475
; of the intersection if x=a+t(b-a). 
470
; of the intersection if x=a+t(b-a). 
476
;
471
;
477
; sign: 0 -> '-', 1 -> '+'
472
; sign: 0 -> '-', 1 -> '+'
478
macro clip_func sign,dir,dir1,dir2
473
macro clip_func sign,dir,dir1,dir2
479
{
474
{
480
locals
475
locals
481
	t dd ?
476
	t dd ?
482
	d_X dd ?
477
	d_X dd ?
483
	d_Y dd ?
478
	d_Y dd ?
484
	d_Z dd ?
479
	d_Z dd ?
485
	d_W dd ?
480
	d_W dd ?
486
endl
481
endl
487
	mov edx,[a]
482
	mov edx,[a]
488
	mov ebx,[b]
483
	mov ebx,[b]
489
	mov ecx,[c]
484
	mov ecx,[c]
490
	fld dword[ebx+offs_X]
485
	fld dword[ebx+offs_X]
491
	fsub dword[edx+offs_X]
486
	fsub dword[edx+offs_X]
492
	fstp dword[d_X] ;d_X = (b.X - a.X)
487
	fstp dword[d_X] ;d_X = (b.X - a.X)
493
	fld dword[ebx+offs_Y]
488
	fld dword[ebx+offs_Y]
494
	fsub dword[edx+offs_Y]
489
	fsub dword[edx+offs_Y]
495
	fstp dword[d_Y] ;d_Y = (b.Y - a.Y)
490
	fstp dword[d_Y] ;d_Y = (b.Y - a.Y)
496
	fld dword[ebx+offs_Z]
491
	fld dword[ebx+offs_Z]
497
	fsub dword[edx+offs_Z]
492
	fsub dword[edx+offs_Z]
498
	fstp dword[d_Z] ;d_Z = (b.Z - a.Z)
493
	fstp dword[d_Z] ;d_Z = (b.Z - a.Z)
499
	fld dword[ebx+offs_W]
494
	fld dword[ebx+offs_W]
500
	fsub dword[edx+offs_W]
495
	fsub dword[edx+offs_W]
501
	fst dword[d_W] ;d_W = (b.W - a.W)
496
	fst dword[d_W] ;d_W = (b.W - a.W)
502
if sign eq 0
497
if sign eq 0
503
	fadd dword[d#dir]
498
	fadd dword[d#dir]
504
else
499
else
505
	fsub dword[d#dir]
500
	fsub dword[d#dir]
506
end if
501
end if
507
 
502
 
508
	ftst
503
	ftst
509
	fstsw ax
504
	fstsw ax
510
	sahf
505
	sahf
511
	jne @f
506
	jne @f
512
		fldz
507
		fldz
513
		fst dword[t] ;t=0
508
		fst dword[t] ;t=0
514
		jmp .e_zero
509
		jmp .e_zero
515
align 4
510
align 4
516
	@@: ;else
511
	@@: ;else
517
		fld dword[edx+offs#dir]
512
		fld dword[edx+offs#dir]
518
if sign eq 0		
513
if sign eq 0		
519
		fchs
514
		fchs
520
end if
515
end if
521
		fsub dword[edx+offs_W]
516
		fsub dword[edx+offs_W]
522
		fdiv st0,st1
517
		fdiv st0,st1
523
		fst dword[t] ;t = ( sign a.dir - a.W) / den
518
		fst dword[t] ;t = ( sign a.dir - a.W) / den
524
	.e_zero:
519
	.e_zero:
525
 
520
 
526
	fmul dword[d#dir1] ;st0 = t * d.dir1
521
	fmul dword[d#dir1] ;st0 = t * d.dir1
527
	fadd dword[edx+offs#dir1]
522
	fadd dword[edx+offs#dir1]
528
	fstp dword[ecx+offs#dir1] ;c.dir1 = a.dir1 + t * d.dir1
523
	fstp dword[ecx+offs#dir1] ;c.dir1 = a.dir1 + t * d.dir1
529
 
524
 
530
	ffree st0
525
	ffree st0
531
	fincstp
526
	fincstp
532
 
527
 
533
	fld dword[t]
528
	fld dword[t]
534
	fmul dword[d#dir2] ;st0 = t * d.dir2
529
	fmul dword[d#dir2] ;st0 = t * d.dir2
535
	fadd dword[edx+offs#dir2]
530
	fadd dword[edx+offs#dir2]
536
	fstp dword[ecx+offs#dir2] ;c.dir2 = a.dir2 + t * d.dir2
531
	fstp dword[ecx+offs#dir2] ;c.dir2 = a.dir2 + t * d.dir2
537
 
532
 
538
	fld dword[t]
533
	fld dword[t]
539
	fmul dword[d_W]
534
	fmul dword[d_W]
540
	fadd dword[edx+offs_W]
535
	fadd dword[edx+offs_W]
541
	fst dword[ecx+offs_W] ;c.W = a.W + t * d_W
536
	fst dword[ecx+offs_W] ;c.W = a.W + t * d_W
542
 
537
 
543
if sign eq 0		
538
if sign eq 0		
544
		fchs
539
		fchs
545
end if
540
end if
546
	fstp dword[ecx+offs#dir] ;c.dir = sign c.W
541
	fstp dword[ecx+offs#dir] ;c.dir = sign c.W
547
	mov eax,[t]
542
	mov eax,[t]
548
}
543
}
549
 
544
 
550
align 16
545
align 16
551
proc clip_xmin uses ebx ecx edx, c:dword, a:dword, b:dword
546
proc clip_xmin uses ebx ecx edx, c:dword, a:dword, b:dword
552
	clip_func 0,_X,_Y,_Z
547
	clip_func 0,_X,_Y,_Z
553
	ret
548
	ret
554
endp
549
endp
555
 
550
 
556
align 16
551
align 16
557
proc clip_xmax uses ebx ecx edx, c:dword, a:dword, b:dword
552
proc clip_xmax uses ebx ecx edx, c:dword, a:dword, b:dword
558
	clip_func 1,_X,_Y,_Z
553
	clip_func 1,_X,_Y,_Z
559
	ret
554
	ret
560
endp
555
endp
561
 
556
 
562
align 16
557
align 16
563
proc clip_ymin uses ebx ecx edx, c:dword, a:dword, b:dword
558
proc clip_ymin uses ebx ecx edx, c:dword, a:dword, b:dword
564
	clip_func 0,_Y,_X,_Z
559
	clip_func 0,_Y,_X,_Z
565
	ret
560
	ret
566
endp
561
endp
567
 
562
 
568
align 16
563
align 16
569
proc clip_ymax uses ebx ecx edx, c:dword, a:dword, b:dword
564
proc clip_ymax uses ebx ecx edx, c:dword, a:dword, b:dword
570
	clip_func 1,_Y,_X,_Z
565
	clip_func 1,_Y,_X,_Z
571
	ret
566
	ret
572
endp
567
endp
573
 
568
 
574
align 16
569
align 16
575
proc clip_zmin uses ebx ecx edx, c:dword, a:dword, b:dword
570
proc clip_zmin uses ebx ecx edx, c:dword, a:dword, b:dword
576
	clip_func 0,_Z,_X,_Y
571
	clip_func 0,_Z,_X,_Y
577
	ret
572
	ret
578
endp
573
endp
579
 
574
 
580
align 16
575
align 16
581
proc clip_zmax uses ebx ecx edx, c:dword, a:dword, b:dword
576
proc clip_zmax uses ebx ecx edx, c:dword, a:dword, b:dword
582
	clip_func 1,_Z,_X,_Y
577
	clip_func 1,_Z,_X,_Y
583
	ret
578
	ret
584
endp
579
endp
585
 
580
 
586
align 4
581
align 4
587
clip_proc dd clip_xmin,clip_xmax, clip_ymin,clip_ymax, clip_zmin,clip_zmax
582
clip_proc dd clip_xmin,clip_xmax, clip_ymin,clip_ymax, clip_zmin,clip_zmax
588
 
583
 
589
;input:
584
;input:
590
;edi - q
585
;edi - q
591
align 16
586
align 16
592
proc updateTmp uses eax ecx edx, context:dword, p0:dword, p1:dword, t:dword
587
proc updateTmp uses eax ecx edx, context:dword, p0:dword, p1:dword, t:dword
593
	mov edx,[context]
588
	mov edx,[context]
594
	mov eax,[p0]
589
	mov eax,[p0]
595
	cmp dword[edx+GLContext.current_shade_model],GL_SMOOTH ;if (context.current_shade_model == GL_SMOOTH)
590
	cmp dword[edx+GLContext.current_shade_model],GL_SMOOTH ;if (context.current_shade_model == GL_SMOOTH)
596
	jne .els_0
591
	jne .els_0
597
		mov ecx,[p1]
592
		mov ecx,[p1]
598
		fld dword[ecx+offs_vert_color]
593
		fld dword[ecx+GLVertex.color]
599
		fsub dword[eax+offs_vert_color]
594
		fsub dword[eax+GLVertex.color]
600
		fmul dword[t]
595
		fmul dword[t]
601
		fadd dword[eax+offs_vert_color]
596
		fadd dword[eax+GLVertex.color]
602
		fstp dword[edi+offs_vert_color] ;q.color.v[0]=p0.color.v[0] + (p1.color.v[0]-p0.color.v[0])*t
597
		fstp dword[edi+GLVertex.color] ;q.color.v[0]=p0.color.v[0] + (p1.color.v[0]-p0.color.v[0])*t
603
		fld dword[ecx+offs_vert_color+4]
598
		fld dword[ecx+GLVertex.color+4]
604
		fsub dword[eax+offs_vert_color+4]
599
		fsub dword[eax+GLVertex.color+4]
605
		fmul dword[t]
600
		fmul dword[t]
606
		fadd dword[eax+offs_vert_color+4]
601
		fadd dword[eax+GLVertex.color+4]
607
		fstp dword[edi+offs_vert_color+4] ;q.color.v[1]=p0.color.v[1] + (p1.color.v[1]-p0.color.v[1])*t
602
		fstp dword[edi+GLVertex.color+4] ;q.color.v[1]=p0.color.v[1] + (p1.color.v[1]-p0.color.v[1])*t
608
		fld dword[ecx+offs_vert_color+8]
603
		fld dword[ecx+GLVertex.color+8]
609
		fsub dword[eax+offs_vert_color+8]
604
		fsub dword[eax+GLVertex.color+8]
610
		fmul dword[t]
605
		fmul dword[t]
611
		fadd dword[eax+offs_vert_color+8]
606
		fadd dword[eax+GLVertex.color+8]
612
		fstp dword[edi+offs_vert_color+8] ;q.color.v[2]=p0.color.v[2] + (p1.color.v[2]-p0.color.v[2])*t
607
		fstp dword[edi+GLVertex.color+8] ;q.color.v[2]=p0.color.v[2] + (p1.color.v[2]-p0.color.v[2])*t
613
		jmp @f
608
		jmp @f
614
align 4
609
align 4
615
	.els_0:
610
	.els_0:
616
		mov ecx,[eax+offs_vert_color]
611
		mov ecx,[eax+GLVertex.color]
617
		mov [edi+offs_vert_color],ecx ;q.color.v[0]=p0.color.v[0]
612
		mov [edi+GLVertex.color],ecx ;q.color.v[0]=p0.color.v[0]
618
		mov ecx,[eax+offs_vert_color+4]
613
		mov ecx,[eax+GLVertex.color+4]
619
		mov [edi+offs_vert_color+4],ecx ;q.color.v[1]=p0.color.v[1]
614
		mov [edi+GLVertex.color+4],ecx ;q.color.v[1]=p0.color.v[1]
620
		mov ecx,[eax+offs_vert_color+8]
615
		mov ecx,[eax+GLVertex.color+8]
621
		mov [edi+offs_vert_color+8],ecx ;q.color.v[2]=p0.color.v[2]
616
		mov [edi+GLVertex.color+8],ecx ;q.color.v[2]=p0.color.v[2]
622
	@@:
617
	@@:
623
 
618
 
624
	cmp dword[edx+GLContext.texture_2d_enabled],0 ;if (context.texture_2d_enabled)
619
	cmp dword[edx+GLContext.texture_2d_enabled],0 ;if (context.texture_2d_enabled)
625
	je @f
620
	je @f
626
		mov ecx,[p1]
621
		mov ecx,[p1]
627
		fld dword[ecx+offs_vert_tex_coord+offs_X]
622
		fld dword[ecx+GLVertex.tex_coord+offs_X]
628
		fsub dword[eax+offs_vert_tex_coord+offs_X]
623
		fsub dword[eax+GLVertex.tex_coord+offs_X]
629
		fmul dword[t]
624
		fmul dword[t]
630
		fadd dword[eax+offs_vert_tex_coord+offs_X]
625
		fadd dword[eax+GLVertex.tex_coord+offs_X]
631
		fstp dword[edi+offs_vert_tex_coord+offs_X] ;q.tex_coord.X=p0.tex_coord.X + (p1.tex_coord.X-p0.tex_coord.X)*t
626
		fstp dword[edi+GLVertex.tex_coord+offs_X] ;q.tex_coord.X=p0.tex_coord.X + (p1.tex_coord.X-p0.tex_coord.X)*t
632
		fld dword[ecx+offs_vert_tex_coord+offs_Y]
627
		fld dword[ecx+GLVertex.tex_coord+offs_Y]
633
		fsub dword[eax+offs_vert_tex_coord+offs_Y]
628
		fsub dword[eax+GLVertex.tex_coord+offs_Y]
634
		fmul dword[t]
629
		fmul dword[t]
635
		fadd dword[eax+offs_vert_tex_coord+offs_Y]
630
		fadd dword[eax+GLVertex.tex_coord+offs_Y]
636
		fstp dword[edi+offs_vert_tex_coord+offs_Y] ;q.tex_coord.Y=p0.tex_coord.Y + (p1.tex_coord.Y-p0.tex_coord.Y)*t
631
		fstp dword[edi+GLVertex.tex_coord+offs_Y] ;q.tex_coord.Y=p0.tex_coord.Y + (p1.tex_coord.Y-p0.tex_coord.Y)*t
637
	@@:
632
	@@:
638
 
633
 
639
	stdcall gl_clipcode, [edi+offs_vert_pc+offs_X],[edi+offs_vert_pc+offs_Y],\
634
	stdcall gl_clipcode, [edi+GLVertex.pc+offs_X],[edi+GLVertex.pc+offs_Y],\
640
		[edi+offs_vert_pc+offs_Z],[edi+offs_vert_pc+offs_W]
635
		[edi+GLVertex.pc+offs_Z],[edi+GLVertex.pc+offs_W]
641
	mov dword[edi+offs_vert_clip_code],eax
636
	mov dword[edi+GLVertex.clip_code],eax
642
	or eax,eax ;if (q.clip_code==0)
637
	or eax,eax ;if (q.clip_code==0)
643
	jnz @f
638
	jnz @f
644
		stdcall gl_transform_to_viewport,[context],edi
639
		stdcall gl_transform_to_viewport,[context],edi
645
		mov eax,edi
-
 
646
		add eax,offs_vert_zp+offs_zbup_b
640
		lea eax,[edi+GLVertex.zp+offs_zbup_b]
647
		push eax
641
		push eax
648
		add eax,offs_zbup_g-offs_zbup_b
642
		add eax,offs_zbup_g-offs_zbup_b
649
		push eax
643
		push eax
650
		add eax,offs_zbup_r-offs_zbup_g
644
		add eax,offs_zbup_r-offs_zbup_g
651
		push eax
645
		push eax
652
		stdcall RGBFtoRGBI, dword[edi+offs_vert_color],dword[edi+offs_vert_color+4],dword[edi+offs_vert_color+8]
646
		stdcall RGBFtoRGBI, dword[edi+GLVertex.color],dword[edi+GLVertex.color+4],dword[edi+GLVertex.color+8]
653
	@@:
647
	@@:
654
	ret
648
	ret
655
endp
649
endp
656
 
650
 
657
align 16
651
align 16
658
proc gl_draw_triangle, context:dword, p0:dword, p1:dword, p2:dword
652
proc gl_draw_triangle, context:dword, p0:dword, p1:dword, p2:dword
659
locals
653
locals
660
	cc rd 3
654
	cc rd 3
661
	front dd ?
655
	front dd ?
662
	norm dd ? ;float
656
	norm dd ? ;float
663
endl
657
endl
664
pushad
658
pushad
665
	mov ebx,[p0]
659
	mov ebx,[p0]
666
	mov ecx,[p1]
660
	mov ecx,[p1]
667
	mov edx,[p2]
661
	mov edx,[p2]
668
	mov edi,[ebx+offs_vert_clip_code]
662
	mov edi,[ebx+GLVertex.clip_code]
669
	mov dword[cc],edi
663
	mov dword[cc],edi
670
	mov eax,[ecx+offs_vert_clip_code]
664
	mov eax,[ecx+GLVertex.clip_code]
671
	mov dword[cc+4],eax
665
	mov dword[cc+4],eax
672
	or edi,eax
666
	or edi,eax
673
	mov eax,[edx+offs_vert_clip_code]
667
	mov eax,[edx+GLVertex.clip_code]
674
	mov dword[cc+8],eax
668
	mov dword[cc+8],eax
675
	or edi,eax ;co = cc[0] | cc[1] | cc[2]
669
	or edi,eax ;co = cc[0] | cc[1] | cc[2]
676
 
670
 
677
	; we handle the non clipped case here to go faster
671
	; we handle the non clipped case here to go faster
678
	;or edi,___ - было выше
672
	;or edi,___ - было выше
679
	jnz .els_0
673
	jnz .els_0
680
		;if (co==0)
674
		;if (co==0)
681
		mov edi,dword[edx+offs_vert_zp+offs_zbup_x]
675
		mov edi,dword[edx+GLVertex.zp+offs_zbup_x]
682
		sub edi,dword[ebx+offs_vert_zp+offs_zbup_x]
676
		sub edi,dword[ebx+GLVertex.zp+offs_zbup_x]
683
		mov dword[norm],edi ;p2.x-p0.x
677
		mov dword[norm],edi ;p2.x-p0.x
684
		fild dword[norm]
678
		fild dword[norm]
685
		mov edi,dword[ecx+offs_vert_zp+offs_zbup_y]
679
		mov edi,dword[ecx+GLVertex.zp+offs_zbup_y]
686
		sub edi,dword[ebx+offs_vert_zp+offs_zbup_y]
680
		sub edi,dword[ebx+GLVertex.zp+offs_zbup_y]
687
		mov dword[norm],edi ;p1.y-p0.y
681
		mov dword[norm],edi ;p1.y-p0.y
688
		fimul dword[norm]
682
		fimul dword[norm]
689
		fchs
683
		fchs
690
		mov edi,dword[ecx+offs_vert_zp+offs_zbup_x]
684
		mov edi,dword[ecx+GLVertex.zp+offs_zbup_x]
691
		sub edi,dword[ebx+offs_vert_zp+offs_zbup_x]
685
		sub edi,dword[ebx+GLVertex.zp+offs_zbup_x]
692
		mov dword[norm],edi ;p1.x-p0.x
686
		mov dword[norm],edi ;p1.x-p0.x
693
		fild dword[norm]
687
		fild dword[norm]
694
		mov edi,dword[edx+offs_vert_zp+offs_zbup_y]
688
		mov edi,dword[edx+GLVertex.zp+offs_zbup_y]
695
		sub edi,dword[ebx+offs_vert_zp+offs_zbup_y]
689
		sub edi,dword[ebx+GLVertex.zp+offs_zbup_y]
696
		mov dword[norm],edi ;p2.y-p0.y
690
		mov dword[norm],edi ;p2.y-p0.y
697
		fimul dword[norm]
691
		fimul dword[norm]
698
		faddp
692
		faddp
699
		;st0 = (p1.zp.x-p0.zp.x)*(p2.zp.y-p0.zp.y) - (p2.zp.x-p0.zp.x)*(p1.zp.y-p0.zp.y)
693
		;st0 = (p1.zp.x-p0.zp.x)*(p2.zp.y-p0.zp.y) - (p2.zp.x-p0.zp.x)*(p1.zp.y-p0.zp.y)
700
 
694
 
701
		mov dword[front],0
695
		mov dword[front],0
702
		ftst
696
		ftst
703
		fstsw ax
697
		fstsw ax
704
		ffree st0
698
		ffree st0
705
		fincstp
699
		fincstp
706
		sahf
700
		sahf
707
		je .end_f
701
		je .end_f
708
		jae @f
702
		jae @f
709
			inc dword[front] ;front = norm < 0.0
703
			inc dword[front] ;front = norm < 0.0
710
		@@:
704
		@@:
711
		mov edi,[context]
705
		mov edi,[context]
712
		mov eax,dword[edi+GLContext.current_front_face]
706
		mov eax,dword[edi+GLContext.current_front_face]
713
		xor dword[front],eax ;front ^= context.current_front_face
707
		xor dword[front],eax ;front ^= context.current_front_face
714
 
708
 
715
		; back face culling
709
		; back face culling
716
		cmp dword[edi+GLContext.cull_face_enabled],0
710
		cmp dword[edi+GLContext.cull_face_enabled],0
717
		je .els_1
711
		je .els_1
718
			; most used case first
712
			; most used case first
719
			cmp dword[edi+GLContext.current_cull_face],GL_BACK
713
			cmp dword[edi+GLContext.current_cull_face],GL_BACK
720
			jne @f
714
			jne @f
721
				cmp dword[front],0
715
				cmp dword[front],0
722
				je .end_f
716
				je .end_f
723
					stdcall dword[edi+GLContext.draw_triangle_front], edi,ebx,ecx,edx
717
					stdcall dword[edi+GLContext.draw_triangle_front], edi,ebx,ecx,edx
724
				jmp .end_f
718
				jmp .end_f
725
align 4
719
align 4
726
			@@:
720
			@@:
727
			cmp dword[edi+GLContext.current_cull_face],GL_FRONT
721
			cmp dword[edi+GLContext.current_cull_face],GL_FRONT
728
			jne .end_f
722
			jne .end_f
729
				cmp dword[front],0
723
				cmp dword[front],0
730
				jne .end_f
724
				jne .end_f
731
					stdcall dword[edi+GLContext.draw_triangle_back], edi,ebx,ecx,edx
725
					stdcall dword[edi+GLContext.draw_triangle_back], edi,ebx,ecx,edx
732
			jmp .end_f
726
			jmp .end_f
733
align 4
727
align 4
734
		.els_1:
728
		.els_1:
735
			; no culling
729
			; no culling
736
			cmp dword[front],0
730
			cmp dword[front],0
737
			je @f
731
			je @f
738
				stdcall dword[edi+GLContext.draw_triangle_front], edi,ebx,ecx,edx
732
				stdcall dword[edi+GLContext.draw_triangle_front], edi,ebx,ecx,edx
739
				jmp .end_f
733
				jmp .end_f
740
align 4
734
align 4
741
			@@:
735
			@@:
742
				stdcall dword[edi+GLContext.draw_triangle_back], edi,ebx,ecx,edx
736
				stdcall dword[edi+GLContext.draw_triangle_back], edi,ebx,ecx,edx
743
		jmp .end_f
737
		jmp .end_f
744
align 4
738
align 4
745
	.els_0:
739
	.els_0:
746
		;eax = cc[2]
740
		;eax = cc[2]
747
		and eax,[cc]
741
		and eax,[cc]
748
		and eax,[cc+4] ;eax = c_and = cc[0] & cc[1] & cc[2]
742
		and eax,[cc+4] ;eax = c_and = cc[0] & cc[1] & cc[2]
749
		or eax,eax ;if (c_and==0)
743
		or eax,eax ;if (c_and==0)
750
		jnz .end_f
744
		jnz .end_f
751
			stdcall gl_draw_triangle_clip, [context],ebx,ecx,edx,0
745
			stdcall gl_draw_triangle_clip, [context],ebx,ecx,edx,0
752
	.end_f:
746
	.end_f:
753
popad
747
popad
754
	ret
748
	ret
755
endp
749
endp
756
 
750
 
757
align 16
751
align 16
758
proc gl_draw_triangle_clip, context:dword, p0:dword, p1:dword, p2:dword, clip_bit:dword
752
proc gl_draw_triangle_clip, context:dword, p0:dword, p1:dword, p2:dword, clip_bit:dword
759
locals
753
locals
760
	co dd ?
754
	co dd ?
761
	cc rd 3
755
	cc rd 3
762
	edge_flag_tmp dd ?
756
	edge_flag_tmp dd ?
763
	clip_mask dd ?
757
	clip_mask dd ?
764
	q rd 3 ;GLVertex*
758
	q rd 3 ;GLVertex*
765
	tmp1 GLVertex ?
759
	tmp1 GLVertex ?
766
	tmp2 GLVertex ?
760
	tmp2 GLVertex ?
767
endl
761
endl
768
pushad
762
pushad
769
	mov ebx,[p0]
763
	mov ebx,[p0]
770
	mov ecx,[p1]
764
	mov ecx,[p1]
771
	mov edx,[p2]
765
	mov edx,[p2]
772
 
766
 
773
	mov edi,[ebx+offs_vert_clip_code]
767
	mov edi,[ebx+GLVertex.clip_code]
774
	mov [cc],edi
768
	mov [cc],edi
775
	mov eax,[ecx+offs_vert_clip_code]
769
	mov eax,[ecx+GLVertex.clip_code]
776
	mov [cc+4],eax
770
	mov [cc+4],eax
777
	or edi,eax
771
	or edi,eax
778
	mov eax,[edx+offs_vert_clip_code]
772
	mov eax,[edx+GLVertex.clip_code]
779
	mov [cc+8],eax
773
	mov [cc+8],eax
780
	or edi,eax
774
	or edi,eax
781
	mov [co],edi ;co = cc[0] | cc[1] | cc[2]
775
	mov [co],edi ;co = cc[0] | cc[1] | cc[2]
782
 
776
 
783
	or edi,edi ;if (co == 0)
777
	or edi,edi ;if (co == 0)
784
	jnz .els_0
778
	jnz .els_0
785
		stdcall gl_draw_triangle, [context],ebx,ecx,edx
779
		stdcall gl_draw_triangle, [context],ebx,ecx,edx
786
		jmp .end_f
780
		jmp .end_f
787
align 4
781
align 4
788
	.els_0:
782
	.els_0:
789
		;eax = cc[2]
783
		;eax = cc[2]
790
		and eax,[cc]
784
		and eax,[cc]
791
		and eax,[cc+4] ;c_and = cc[0] & cc[1] & cc[2]
785
		and eax,[cc+4] ;c_and = cc[0] & cc[1] & cc[2]
792
 
786
 
793
		; the triangle is completely outside
787
		; the triangle is completely outside
794
		or eax,eax ;if (c_and!=0) return
788
		or eax,eax ;if (c_and!=0) return
795
		jnz .end_f
789
		jnz .end_f
796
 
790
 
797
		; find the next direction to clip
791
		; find the next direction to clip
798
		.cycle_0: ;while (clip_bit < 6 && (co & (1 << clip_bit)) == 0)
792
		.cycle_0: ;while (clip_bit < 6 && (co & (1 << clip_bit)) == 0)
799
		cmp dword[clip_bit],6
793
		cmp dword[clip_bit],6
800
		jge .cycle_0_end
794
		jge .cycle_0_end
801
		xor eax,eax
795
		xor eax,eax
802
		inc eax
796
		inc eax
803
		mov ecx,[clip_bit]
797
		mov ecx,[clip_bit]
804
		shl eax,cl
798
		shl eax,cl
805
		and eax,[co]
799
		and eax,[co]
806
		or eax,eax
800
		or eax,eax
807
		jnz .cycle_0_end
801
		jnz .cycle_0_end
808
			inc dword[clip_bit]
802
			inc dword[clip_bit]
809
			jmp .cycle_0
803
			jmp .cycle_0
810
align 4
804
align 4
811
		.cycle_0_end:
805
		.cycle_0_end:
812
 
806
 
813
	; this test can be true only in case of rounding errors
807
	; this test can be true only in case of rounding errors
814
	cmp dword[clip_bit],6
808
	cmp dword[clip_bit],6
815
if 0
809
if 0
816
	jne @f
810
	jne @f
817
;      printf("Error:\n");
811
;      printf("Error:\n");
818
;      printf("%f %f %f %f\n",p0->pc.X,p0->pc.Y,p0->pc.Z,p0->pc.W);
812
;      printf("%f %f %f %f\n",p0->pc.X,p0->pc.Y,p0->pc.Z,p0->pc.W);
819
;      printf("%f %f %f %f\n",p1->pc.X,p1->pc.Y,p1->pc.Z,p1->pc.W);
813
;      printf("%f %f %f %f\n",p1->pc.X,p1->pc.Y,p1->pc.Z,p1->pc.W);
820
;      printf("%f %f %f %f\n",p2->pc.X,p2->pc.Y,p2->pc.Z,p2->pc.W);
814
;      printf("%f %f %f %f\n",p2->pc.X,p2->pc.Y,p2->pc.Z,p2->pc.W);
821
		jmp .end_f
815
		jmp .end_f
822
	@@:
816
	@@:
823
end if
817
end if
824
if 1
818
if 1
825
	je .end_f
819
	je .end_f
826
end if
820
end if
827
 
821
 
828
	xor eax,eax
822
	xor eax,eax
829
	inc eax
823
	inc eax
830
	mov ecx,[clip_bit]
824
	mov ecx,[clip_bit]
831
	shl eax,cl
825
	shl eax,cl
832
	mov [clip_mask],eax ;1 << clip_bit
826
	mov [clip_mask],eax ;1 << clip_bit
833
	mov edi,[cc]
827
	mov edi,[cc]
834
	xor edi,[cc+4]
828
	xor edi,[cc+4]
835
	xor edi,[cc+8]
829
	xor edi,[cc+8]
836
	and eax,edi ;eax = co1 = (cc[0] ^ cc[1] ^ cc[2]) & clip_mask
830
	and eax,edi ;eax = co1 = (cc[0] ^ cc[1] ^ cc[2]) & clip_mask
837
 
831
 
838
	mov ecx,[p1] ;востанавливаем после shl ___,cl
832
	mov ecx,[p1] ;востанавливаем после shl ___,cl
839
 
833
 
840
	or eax,eax ;if (co1)
834
	or eax,eax ;if (co1)
841
	jz .els_1
835
	jz .els_1
842
		; one point outside
836
		; one point outside
843
		mov eax,[cc]
837
		mov eax,[cc]
844
		and eax,[clip_mask]
838
		and eax,[clip_mask]
845
		or eax,eax ;if (cc[0] & clip_mask)
839
		or eax,eax ;if (cc[0] & clip_mask)
846
		jz .els_2
840
		jz .els_2
847
			;q[0]=p0 q[1]=p1 q[2]=p2
841
			;q[0]=p0 q[1]=p1 q[2]=p2
848
			mov [q],ebx
842
			mov [q],ebx
849
			mov [q+4],ecx
843
			mov [q+4],ecx
850
			mov [q+8],edx
844
			mov [q+8],edx
851
			jmp .els_2_end
845
			jmp .els_2_end
852
align 4
846
align 4
853
		.els_2:
847
		.els_2:
854
		mov eax,[cc+4]
848
		mov eax,[cc+4]
855
		and eax,[clip_mask]
849
		and eax,[clip_mask]
856
		or eax,eax ;else if (cc[1] & clip_mask)
850
		or eax,eax ;else if (cc[1] & clip_mask)
857
		jz .els_3
851
		jz .els_3
858
			;q[0]=p1 q[1]=p2 q[2]=p0
852
			;q[0]=p1 q[1]=p2 q[2]=p0
859
			mov [q],ecx
853
			mov [q],ecx
860
			mov [q+4],edx
854
			mov [q+4],edx
861
			mov [q+8],ebx
855
			mov [q+8],ebx
862
			jmp .els_2_end
856
			jmp .els_2_end
863
align 4
857
align 4
864
		.els_3:
858
		.els_3:
865
			;q[0]=p2 q[1]=p0 q[2]=p1
859
			;q[0]=p2 q[1]=p0 q[2]=p1
866
			mov [q],edx
860
			mov [q],edx
867
			mov [q+4],ebx
861
			mov [q+4],ebx
868
			mov [q+8],ecx
862
			mov [q+8],ecx
869
		.els_2_end:
863
		.els_2_end:
870
 
864
 
871
		mov ebx,[q]
865
		mov ebx,[q]
872
		add ebx,offs_vert_pc
866
		add ebx,GLVertex.pc
873
		mov ecx,[q+4]
867
		mov ecx,[q+4]
874
		add ecx,offs_vert_pc
868
		add ecx,GLVertex.pc
875
		mov edx,[q+8]
869
		mov edx,[q+8]
876
		add edx,offs_vert_pc
870
		add edx,GLVertex.pc
877
 
871
 
878
		lea eax,[clip_proc]
872
		lea eax,[clip_proc]
879
		mov edi,[clip_bit]
873
		mov edi,[clip_bit]
880
		shl edi,2
-
 
881
		add eax,edi
874
		lea eax,[eax+4*edi]
882
		mov edi,ebp
-
 
883
		sub edi,(2*sizeof.GLVertex)-offs_vert_pc
875
		lea edi,[ebp-(2*sizeof.GLVertex)+GLVertex.pc]
884
		stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc)
876
		stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc)
885
		sub edi,offs_vert_pc
877
		sub edi,GLVertex.pc
886
 
878
 
887
		sub ebx,offs_vert_pc
879
		sub ebx,GLVertex.pc
888
		sub ecx,offs_vert_pc
880
		sub ecx,GLVertex.pc
889
		stdcall updateTmp,[context],ebx,ecx,eax ;(c,&tmp1,q[0],q[1],tt)
881
		stdcall updateTmp,[context],ebx,ecx,eax ;(c,&tmp1,q[0],q[1],tt)
890
		add ebx,offs_vert_pc
882
		add ebx,GLVertex.pc
891
 
883
 
892
		lea eax,[clip_proc]
884
		lea eax,[clip_proc]
893
		mov edi,[clip_bit]
885
		mov edi,[clip_bit]
894
		shl edi,2
-
 
895
		add eax,edi
886
		lea eax,[eax+4*edi]
896
		mov edi,ebp
-
 
897
		sub edi,sizeof.GLVertex-offs_vert_pc
887
		lea edi,[ebp-sizeof.GLVertex+GLVertex.pc]
898
		stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc)
888
		stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc)
899
		sub edi,offs_vert_pc
889
		sub edi,GLVertex.pc
900
		sub ebx,offs_vert_pc
890
		sub ebx,GLVertex.pc
901
		sub edx,offs_vert_pc
891
		sub edx,GLVertex.pc
902
		stdcall updateTmp,[context],ebx,edx,eax ;(c,&tmp2,q[0],q[2],tt)
892
		stdcall updateTmp,[context],ebx,edx,eax ;(c,&tmp2,q[0],q[2],tt)
903
 
893
 
904
		mov eax,[ebx+offs_vert_edge_flag]
894
		mov eax,[ebx+GLVertex.edge_flag]
905
		mov [tmp1.edge_flag],eax ;q[0].edge_flag
895
		mov [tmp1.edge_flag],eax ;q[0].edge_flag
906
		mov eax,[edx+offs_vert_edge_flag]
896
		mov eax,[edx+GLVertex.edge_flag]
907
		mov [edge_flag_tmp],eax	;q[2].edge_flag
897
		mov [edge_flag_tmp],eax	;q[2].edge_flag
908
		mov dword[edx+offs_vert_edge_flag],0 ;q[2].edge_flag=0
898
		mov dword[edx+GLVertex.edge_flag],0 ;q[2].edge_flag=0
909
		mov eax,[clip_bit]
899
		mov eax,[clip_bit]
910
		inc eax
900
		inc eax
911
		push eax ;для вызова нижней функции
901
		push eax ;для вызова нижней функции
912
		mov edi,ebp
-
 
913
		sub edi,2*sizeof.GLVertex
902
		lea edi,[ebp-2*sizeof.GLVertex]
914
		stdcall gl_draw_triangle_clip,[context],edi,ecx,edx,eax ;gl_draw_triangle_clip(c,&tmp1,q[1],q[2],clip_bit+1)
903
		stdcall gl_draw_triangle_clip,[context],edi,ecx,edx,eax ;gl_draw_triangle_clip(c,&tmp1,q[1],q[2],clip_bit+1)
915
 
904
 
916
		mov dword[tmp2.edge_flag],0
905
		mov dword[tmp2.edge_flag],0
917
		mov dword[tmp1.edge_flag],0
906
		mov dword[tmp1.edge_flag],0
918
		mov eax,[edge_flag_tmp]
907
		mov eax,[edge_flag_tmp]
919
		mov [edx+offs_vert_edge_flag],eax ;q[2].edge_flag=edge_flag_tmp
908
		mov [edx+GLVertex.edge_flag],eax ;q[2].edge_flag=edge_flag_tmp
920
		push edx
909
		push edx
921
		push edi
910
		push edi
922
		add edi,sizeof.GLVertex ;edi = &tmp2
911
		add edi,sizeof.GLVertex ;edi = &tmp2
923
		stdcall gl_draw_triangle_clip,[context],edi ;gl_draw_triangle_clip(c,&tmp2,&tmp1,q[2],clip_bit+1)
912
		stdcall gl_draw_triangle_clip,[context],edi ;gl_draw_triangle_clip(c,&tmp2,&tmp1,q[2],clip_bit+1)
924
		jmp .end_f
913
		jmp .end_f
925
align 4
914
align 4
926
	.els_1:
915
	.els_1:
927
		; two points outside
916
		; two points outside
928
		mov eax,[cc]
917
		mov eax,[cc]
929
		and eax,[clip_mask]
918
		and eax,[clip_mask]
930
		cmp eax,0 ;if (cc[0] & clip_mask)==0
919
		cmp eax,0 ;if (cc[0] & clip_mask)==0
931
		jne .els_4
920
		jne .els_4
932
			;q[0]=p0 q[1]=p1 q[2]=p2
921
			;q[0]=p0 q[1]=p1 q[2]=p2
933
			mov [q],ebx
922
			mov [q],ebx
934
			mov [q+4],ecx
923
			mov [q+4],ecx
935
			mov [q+8],edx
924
			mov [q+8],edx
936
			jmp .els_4_end
925
			jmp .els_4_end
937
align 4
926
align 4
938
		.els_4:
927
		.els_4:
939
		mov eax,[cc+4]
928
		mov eax,[cc+4]
940
		and eax,[clip_mask]
929
		and eax,[clip_mask]
941
		cmp eax,0 ;else if (cc[1] & clip_mask)==0
930
		cmp eax,0 ;else if (cc[1] & clip_mask)==0
942
		jne .els_5
931
		jne .els_5
943
			;q[0]=p1 q[1]=p2 q[2]=p0
932
			;q[0]=p1 q[1]=p2 q[2]=p0
944
			mov [q],ecx
933
			mov [q],ecx
945
			mov [q+4],edx
934
			mov [q+4],edx
946
			mov [q+8],ebx
935
			mov [q+8],ebx
947
			jmp .els_4_end
936
			jmp .els_4_end
948
align 4
937
align 4
949
		.els_5:
938
		.els_5:
950
			;q[0]=p2 q[1]=p0 q[2]=p1
939
			;q[0]=p2 q[1]=p0 q[2]=p1
951
			mov [q],edx
940
			mov [q],edx
952
			mov [q+4],ebx
941
			mov [q+4],ebx
953
			mov [q+8],ecx
942
			mov [q+8],ecx
954
		.els_4_end:
943
		.els_4_end:
955
 
944
 
956
		mov ebx,[q]
945
		mov ebx,[q]
957
		add ebx,offs_vert_pc
946
		add ebx,GLVertex.pc
958
		mov ecx,[q+4]
947
		mov ecx,[q+4]
959
		add ecx,offs_vert_pc
948
		add ecx,GLVertex.pc
960
		mov edx,[q+8]
949
		mov edx,[q+8]
961
		add edx,offs_vert_pc
950
		add edx,GLVertex.pc
962
 
951
 
963
		lea eax,[clip_proc]
952
		lea eax,[clip_proc]
964
		mov edi,[clip_bit]
953
		mov edi,[clip_bit]
965
		shl edi,2
-
 
966
		add eax,edi
954
		lea eax,[eax+4*edi]
967
		mov edi,ebp
-
 
968
		sub edi,(2*sizeof.GLVertex)-offs_vert_pc
955
		lea edi,[ebp-(2*sizeof.GLVertex)+GLVertex.pc]
969
		stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc)
956
		stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc)
970
		sub edi,offs_vert_pc
957
		sub edi,GLVertex.pc
971
		stdcall updateTmp,[context],[q],[q+4],eax
958
		stdcall updateTmp,[context],[q],[q+4],eax
972
 
959
 
973
		lea eax,[clip_proc]
960
		lea eax,[clip_proc]
974
		mov edi,[clip_bit]
961
		mov edi,[clip_bit]
975
		shl edi,2
-
 
976
		add eax,edi
962
		lea eax,[eax+4*edi]
977
		mov edi,ebp
-
 
978
		sub edi,sizeof.GLVertex-offs_vert_pc
963
		lea edi,[ebp-sizeof.GLVertex+GLVertex.pc]
979
		stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc)
964
		stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc)
980
		sub edi,offs_vert_pc
965
		sub edi,GLVertex.pc
981
		stdcall updateTmp,[context],[q],[q+8],eax
966
		stdcall updateTmp,[context],[q],[q+8],eax
982
 
967
 
983
		mov dword[tmp1.edge_flag],1
968
		mov dword[tmp1.edge_flag],1
984
		mov eax,[edx+offs_vert_edge_flag-offs_vert_pc]
969
		mov eax,[edx+GLVertex.edge_flag-GLVertex.pc]
985
		mov dword[tmp2.edge_flag],eax ;tmp2.edge_flag = q[2].edge_flag
970
		mov dword[tmp2.edge_flag],eax ;tmp2.edge_flag = q[2].edge_flag
986
		mov eax,[clip_bit]
971
		mov eax,[clip_bit]
987
		inc eax
972
		inc eax
988
		push eax
973
		push eax
989
		push edi
974
		push edi
990
		sub edi,sizeof.GLVertex
975
		sub edi,sizeof.GLVertex
991
		stdcall gl_draw_triangle_clip,[context],[q],edi ;gl_draw_triangle_clip(c,q[0],&tmp1,&tmp2,clip_bit+1)
976
		stdcall gl_draw_triangle_clip,[context],[q],edi ;gl_draw_triangle_clip(c,q[0],&tmp1,&tmp2,clip_bit+1)
992
	.end_f:
977
	.end_f:
993
popad
978
popad
994
	ret
979
	ret
995
endp
980
endp
996
 
981
 
997
align 16
982
align 16
998
proc gl_draw_triangle_select uses eax, context:dword, p0:dword,p1:dword,p2:dword
983
proc gl_draw_triangle_select uses eax, context:dword, p0:dword,p1:dword,p2:dword
999
	mov eax,[p2]
984
	mov eax,[p2]
1000
	push dword[eax+offs_vert_zp+offs_Z]
985
	push dword[eax+GLVertex.zp+offs_Z]
1001
	mov eax,[p1]
986
	mov eax,[p1]
1002
	push dword[eax+offs_vert_zp+offs_Z]
987
	push dword[eax+GLVertex.zp+offs_Z]
1003
	mov eax,[p0]
988
	mov eax,[p0]
1004
	push dword[eax+offs_vert_zp+offs_Z]
989
	push dword[eax+GLVertex.zp+offs_Z]
1005
	stdcall gl_add_select1, [context] ;,p0.zp.z, p1.zp.z, p2.zp.z
990
	stdcall gl_add_select1, [context] ;,p0.zp.z, p1.zp.z, p2.zp.z
1006
	ret
991
	ret
1007
endp
992
endp
1008
 
993
 
1009
if PROFILE eq 1
994
if PROFILE eq 1
1010
	count_triangles dd ?
995
	count_triangles dd ?
1011
	count_triangles_textured dd ?
996
	count_triangles_textured dd ?
1012
	count_pixels dd ?
997
	count_pixels dd ?
1013
end if
998
end if
1014
 
999
 
1015
align 16
1000
align 16
1016
proc gl_draw_triangle_fill, context:dword, p0:dword,p1:dword,p2:dword
1001
proc gl_draw_triangle_fill, context:dword, p0:dword,p1:dword,p2:dword
1017
pushad
1002
pushad
1018
if PROFILE eq 1
1003
if PROFILE eq 1
1019
;    int norm;
1004
;    int norm;
1020
;    assert(p0->zp.x >= 0 && p0->zp.x < c->zb->xsize);
1005
;    assert(p0->zp.x >= 0 && p0->zp.x < c->zb->xsize);
1021
;    assert(p0->zp.y >= 0 && p0->zp.y < c->zb->ysize);
1006
;    assert(p0->zp.y >= 0 && p0->zp.y < c->zb->ysize);
1022
;    assert(p1->zp.x >= 0 && p1->zp.x < c->zb->xsize);
1007
;    assert(p1->zp.x >= 0 && p1->zp.x < c->zb->xsize);
1023
;    assert(p1->zp.y >= 0 && p1->zp.y < c->zb->ysize);
1008
;    assert(p1->zp.y >= 0 && p1->zp.y < c->zb->ysize);
1024
;    assert(p2->zp.x >= 0 && p2->zp.x < c->zb->xsize);
1009
;    assert(p2->zp.x >= 0 && p2->zp.x < c->zb->xsize);
1025
;    assert(p2->zp.y >= 0 && p2->zp.y < c->zb->ysize);
1010
;    assert(p2->zp.y >= 0 && p2->zp.y < c->zb->ysize);
1026
    
1011
    
1027
;    norm=(p1->zp.x-p0->zp.x)*(p2->zp.y-p0->zp.y)-
1012
;    norm=(p1->zp.x-p0->zp.x)*(p2->zp.y-p0->zp.y)-
1028
;      (p2->zp.x-p0->zp.x)*(p1->zp.y-p0->zp.y);
1013
;      (p2->zp.x-p0->zp.x)*(p1->zp.y-p0->zp.y);
1029
;    count_pixels+=abs(norm)/2;
1014
;    count_pixels+=abs(norm)/2;
1030
	inc dword[count_triangles]
1015
	inc dword[count_triangles]
1031
end if
1016
end if
1032
 
1017
 
1033
	mov ebx,[p1]
1018
	mov ebx,[p1]
1034
	add ebx,offs_vert_zp
1019
	add ebx,GLVertex.zp
1035
	mov ecx,[p2]
1020
	mov ecx,[p2]
1036
	add ecx,offs_vert_zp
1021
	add ecx,GLVertex.zp
1037
	mov edx,[context]
1022
	mov edx,[context]
1038
	cmp dword[edx+GLContext.texture_2d_enabled],0
1023
	cmp dword[edx+GLContext.texture_2d_enabled],0
1039
	je .els_i
1024
	je .els_i
1040
		;if (context.texture_2d_enabled)
1025
		;if (context.texture_2d_enabled)
1041
if PROFILE eq 1
1026
if PROFILE eq 1
1042
	inc dword[count_triangles_textured]
1027
	inc dword[count_triangles_textured]
1043
end if
1028
end if
1044
		mov eax,[edx+GLContext.current_texture]
1029
		mov eax,[edx+GLContext.current_texture]
1045
		mov eax,[eax] ;переход по указателю
1030
		mov eax,[eax] ;переход по указателю
1046
		;так как offs_text_images+offs_imag_pixmap = 0 то context.current_texture.images[0].pixmap = [eax]
1031
		;так как offs_text_images+offs_imag_pixmap = 0 то context.current_texture.images[0].pixmap = [eax]
1047
		stdcall ZB_setTexture, [edx+GLContext.zb], [eax],\
1032
		stdcall ZB_setTexture, [edx+GLContext.zb], [eax],\
1048
			[eax+offs_imag_s_bound],[eax+offs_imag_t_bound],[eax+offs_imag_xsize_log2]
1033
			[eax+offs_imag_s_bound],[eax+offs_imag_t_bound],[eax+offs_imag_xsize_log2]
1049
		mov eax,[p0]
1034
		mov eax,[p0]
1050
		add eax,offs_vert_zp
1035
		add eax,GLVertex.zp
1051
		push ecx
1036
		push ecx
1052
		push ebx
1037
		push ebx
1053
		push eax
1038
		push eax
1054
		push dword[edx+GLContext.zb]
1039
		push dword[edx+GLContext.zb]
1055
		cmp dword[edx+GLContext.matrix_model_projection_no_w_transform],0
1040
		cmp dword[edx+GLContext.matrix_model_projection_no_w_transform],0
1056
		je @f
1041
		je @f
1057
			call ZB_fillTriangleMappingPerspective
1042
			call ZB_fillTriangleMappingPerspective
1058
			jmp .end_f
1043
			jmp .end_f
1059
align 4
1044
align 4
1060
		@@:
1045
		@@:
1061
			call ZB_fillTriangleMapping
1046
			call ZB_fillTriangleMapping
1062
		jmp .end_f
1047
		jmp .end_f
1063
align 4
1048
align 4
1064
	.els_i:
1049
	.els_i:
1065
		mov eax,[p0]
1050
		mov eax,[p0]
1066
		add eax,offs_vert_zp
1051
		add eax,GLVertex.zp
1067
		cmp dword[edx+GLContext.current_shade_model],GL_SMOOTH
1052
		cmp dword[edx+GLContext.current_shade_model],GL_SMOOTH
1068
		jne .els
1053
		jne .els
1069
			;else if (context.current_shade_model == GL_SMOOTH)
1054
			;else if (context.current_shade_model == GL_SMOOTH)
1070
			stdcall ZB_fillTriangleSmooth, dword[edx+GLContext.zb],eax,ebx,ecx
1055
			stdcall ZB_fillTriangleSmooth, dword[edx+GLContext.zb],eax,ebx,ecx
1071
			jmp .end_f
1056
			jmp .end_f
1072
align 4
1057
align 4
1073
		.els:
1058
		.els:
1074
			stdcall ZB_fillTriangleFlat, dword[edx+GLContext.zb],eax,ebx,ecx
1059
			stdcall ZB_fillTriangleFlat, dword[edx+GLContext.zb],eax,ebx,ecx
1075
	.end_f:
1060
	.end_f:
1076
popad
1061
popad
1077
	ret
1062
	ret
1078
endp
1063
endp
1079
 
1064
 
1080
; Render a clipped triangle in line mode
1065
; Render a clipped triangle in line mode
1081
 
1066
 
1082
align 16
1067
align 16
1083
proc gl_draw_triangle_line uses eax ebx ecx edx, context:dword, p0:dword,p1:dword,p2:dword
1068
proc gl_draw_triangle_line uses eax ebx ecx edx, context:dword, p0:dword,p1:dword,p2:dword
1084
	mov edx,[context]
1069
	mov edx,[context]
1085
	cmp dword[edx+GLContext.depth_test],0
1070
	cmp dword[edx+GLContext.depth_test],0
1086
	je .els
1071
	je .els
1087
		lea ecx,[ZB_line_z]
1072
		lea ecx,[ZB_line_z]
1088
		jmp @f
1073
		jmp @f
1089
align 4
1074
align 4
1090
	.els:
1075
	.els:
1091
		lea ecx,[ZB_line]
1076
		lea ecx,[ZB_line]
1092
	@@:
1077
	@@:
1093
 
1078
 
1094
	;if (p0.edge_flag) ZB_line_z(context.zb,&p0.zp,&p1.zp)
1079
	;if (p0.edge_flag) ZB_line_z(context.zb,&p0.zp,&p1.zp)
1095
	mov eax,[p0]
1080
	mov eax,[p0]
1096
	cmp dword[eax+offs_vert_edge_flag],0
1081
	cmp dword[eax+GLVertex.edge_flag],0
1097
	je @f
1082
	je @f
1098
		mov ebx,eax
-
 
1099
		add ebx,offs_vert_zp
1083
		lea ebx,[eax+GLVertex.zp]
1100
		mov eax,[p1]
1084
		mov eax,[p1]
1101
		add eax,offs_vert_zp
1085
		add eax,GLVertex.zp
1102
		stdcall ecx,dword[edx+GLContext.zb],ebx,eax
1086
		stdcall ecx,dword[edx+GLContext.zb],ebx,eax
1103
	@@:
1087
	@@:
1104
	;if (p1.edge_flag) ZB_line_z(context.zb,&p1.zp,&p2.zp)
1088
	;if (p1.edge_flag) ZB_line_z(context.zb,&p1.zp,&p2.zp)
1105
	mov eax,[p1]
1089
	mov eax,[p1]
1106
	cmp dword[eax+offs_vert_edge_flag],0
1090
	cmp dword[eax+GLVertex.edge_flag],0
1107
	je @f
1091
	je @f
1108
		mov ebx,eax
-
 
1109
		add ebx,offs_vert_zp
1092
		lea ebx,[eax+GLVertex.zp]
1110
		mov eax,[p2]
1093
		mov eax,[p2]
1111
		add eax,offs_vert_zp
1094
		add eax,GLVertex.zp
1112
		stdcall ecx,dword[edx+GLContext.zb],ebx,eax
1095
		stdcall ecx,dword[edx+GLContext.zb],ebx,eax
1113
	@@:
1096
	@@:
1114
	;if (p2.edge_flag) ZB_line_z(context.zb,&p2.zp,&p0.zp);
1097
	;if (p2.edge_flag) ZB_line_z(context.zb,&p2.zp,&p0.zp);
1115
	mov eax,[p2]
1098
	mov eax,[p2]
1116
	cmp dword[eax+offs_vert_edge_flag],0
1099
	cmp dword[eax+GLVertex.edge_flag],0
1117
	je @f
1100
	je @f
1118
		mov ebx,eax
-
 
1119
		add ebx,offs_vert_zp
1101
		lea ebx,[eax+GLVertex.zp]
1120
		mov eax,[p0]
1102
		mov eax,[p0]
1121
		add eax,offs_vert_zp
1103
		add eax,GLVertex.zp
1122
		stdcall ecx,dword[edx+GLContext.zb],ebx,eax
1104
		stdcall ecx,dword[edx+GLContext.zb],ebx,eax
1123
	@@:
1105
	@@:
1124
 
1106
 
1125
	ret
1107
	ret
1126
endp
1108
endp
1127
 
1109
 
1128
; Render a clipped triangle in point mode
1110
; Render a clipped triangle in point mode
1129
align 16
1111
align 16
1130
proc gl_draw_triangle_point uses eax ebx edx, context:dword, p0:dword,p1:dword,p2:dword
1112
proc gl_draw_triangle_point uses eax edx, context:dword, p0:dword,p1:dword,p2:dword
1131
	mov edx,[context]
1113
	mov edx,[context]
1132
	mov eax,[p0]
1114
	mov eax,[p0]
1133
	cmp dword[eax+offs_vert_edge_flag],0
1115
	cmp dword[eax+GLVertex.edge_flag],0
1134
	je @f
1116
	je @f
1135
		mov ebx,eax
-
 
1136
		add ebx,offs_vert_zp
1117
		lea eax,[eax+GLVertex.zp]
1137
		stdcall ZB_plot,dword[edx+GLContext.zb],ebx
1118
		stdcall ZB_plot,dword[edx+GLContext.zb],eax
1138
	@@:
1119
	@@:
1139
	mov eax,[p1]
1120
	mov eax,[p1]
1140
	cmp dword[eax+offs_vert_edge_flag],0
1121
	cmp dword[eax+GLVertex.edge_flag],0
1141
	je @f
1122
	je @f
1142
		mov ebx,eax
-
 
1143
		add ebx,offs_vert_zp
1123
		lea eax,[eax+GLVertex.zp]
1144
		stdcall ZB_plot,dword[edx+GLContext.zb],ebx
1124
		stdcall ZB_plot,dword[edx+GLContext.zb],eax
1145
	@@:
1125
	@@:
1146
	mov eax,[p2]
1126
	mov eax,[p2]
1147
	cmp dword[eax+offs_vert_edge_flag],0
1127
	cmp dword[eax+GLVertex.edge_flag],0
1148
	je @f
1128
	je @f
1149
		mov ebx,eax
-
 
1150
		add ebx,offs_vert_zp
1129
		lea eax,[eax+GLVertex.zp]
1151
		stdcall ZB_plot,dword[edx+GLContext.zb],ebx
1130
		stdcall ZB_plot,dword[edx+GLContext.zb],eax
1152
	@@:
1131
	@@:
1153
	ret
1132
	ret
1154
endp
1133
endp
1155
>
1134
>
1156
 
1135
 
1157
align>
1136
align>
1158
 
1137
 
1159
align>
1138
align>
1160
CLIP_ZMAX>
1139
CLIP_ZMAX>
1161
CLIP_ZMAX>
1140
CLIP_ZMAX>
1162
CLIP_ZMIN>
1141
CLIP_ZMIN>
1163
CLIP_ZMIN>
1142
CLIP_ZMIN>
1164
CLIP_YMAX>
1143
CLIP_YMAX>
1165
CLIP_YMAX>
1144
CLIP_YMAX>
1166
CLIP_YMIN>
1145
CLIP_YMIN>
1167
CLIP_YMIN>
1146
CLIP_YMIN>
1168
CLIP_XMAX>
1147
CLIP_XMAX>
1169
CLIP_XMAX>
1148
CLIP_XMAX>