Subversion Repositories Kolibri OS

Rev

Rev 6145 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5153 IgorA 1
;
2
; We draw a triangle with various interpolations
3
;
5922 IgorA 4
; Порядок преобразований цветов вершин:
5
; ZBufferPoint.r -> r1 (+drdl_min or +drdl_max) -> or1 (+drdx) -> [pixel buffer]
6
; ZBufferPoint.g -> g1 (+dgdl_min or +dgdl_max) -> og1 (+dgdx) -> [pixel buffer]
7
; ZBufferPoint.b -> b1 (+dbdl_min or +dbdl_max) -> ob1 (+dbdx) -> [pixel buffer]
8
;
9
; В некоторых случаях значения цвета (во 2-м байте переменных: or1,og1,ob1)
10
; может становиться < 0 или > 255, тогда появляються пиксели не правильного
11
; цвета. Скорее всего это связано с ошибками округления дробных чисел,
12
; при вычислении коэфициентов для плавного перехода цвета.
13
;
14
; Для лечения этой проблемы в версии на C++ специально ограничиваються
15
; минимальные и максимальные значения цвета точек (например от 3 до 252).
16
; Потому цвета граней могут немного отличаться от указанных в программе.
17
;
18
; В даной версии алгоритм немного другой. В наиболее вероятных местах появления
19
; пикселей не правильного цвета (обычно начало и конец линии) иправляеться
20
; цвет испорченных пикселей. Цвет получаеться наиболее близким к указанному
21
; пользователем.
22
 
5153 IgorA 23
	pr1 dd ? ;ZBufferPoint*
24
	pr2 dd ? ;ZBufferPoint*
25
	l1 dd ? ;ZBufferPoint*
26
	l2 dd ? ;ZBufferPoint*
5175 IgorA 27
	fdx1 dd ? ;float
28
	fdx2 dd ? ;float
29
	fdy1 dd ? ;float
30
	fdy2 dd ? ;float
6113 IgorA 31
	fz dd ? ;float - переменная отвечающая за геометрию фигуры
5175 IgorA 32
	d1 dd ? ;float
33
	d2 dd ? ;float
5153 IgorA 34
	pz1 dd ? ;unsigned short*
35
	pp1 dd ? ;PIXEL*
36
	part dd ?
37
	update_left dd ?
38
	update_right dd ?
39
 
5187 IgorA 40
	nb_lines dd ? ;число горизонтальных линий в половине треугольника
5153 IgorA 41
	dx1 dd ?
42
	dy1 dd ?
5187 IgorA 43
	;dx2 dd ?
5153 IgorA 44
	dy2 dd ?
45
 
5187 IgorA 46
	error dd ? ;int
47
	derror dd ? ;int
48
	x1 dd ? ;int
49
	dxdy_min dd ? ;int
50
	dxdy_max dd ? ;int
5153 IgorA 51
	; warning: x2 is multiplied by 2^16
5187 IgorA 52
	x2 dd ? ;int
53
	dx2dy2 dd ? ;int
5153 IgorA 54
 
6108 IgorA 55
	z dd ? ;uint
6113 IgorA 56
	n dd ? ;int - длинна горизонтальной линии в пикселях
57
 
5153 IgorA 58
if INTERP_Z eq 1
5187 IgorA 59
	z1 dd ? ;int
60
	dzdx dd ? ;int
61
	dzdy dd ? ;int
62
	dzdl_min dd ? ;int
63
	dzdl_max dd ? ;int
5153 IgorA 64
end if
65
if INTERP_RGB eq 1
66
	r1 dd ? ;int
67
	drdx dd ?
68
	drdy dd ?
69
	drdl_min dd ?
70
	drdl_max dd ?
71
	g1 dd ?
72
	dgdx dd ?
73
	dgdy dd ?
74
	dgdl_min dd ?
75
	dgdl_max dd ?
76
	b1 dd ?
77
	dbdx dd ?
78
	dbdy dd ?
79
	dbdl_min dd ?
80
	dbdl_max dd ?
6113 IgorA 81
	or1 dd ? ;uint
82
	og1 dd ? ;uint
83
	ob1 dd ? ;uint
5153 IgorA 84
end if
85
if INTERP_ST eq 1
5187 IgorA 86
	s1 dd ? ;int
87
	dsdy dd ? ;int
88
	dsdl_min dd ? ;int
89
	dsdl_max dd ? ;int
90
	t1 dd ? ;int
91
	dtdy dd ? ;int
92
	dtdl_min dd ? ;int
93
	dtdl_max dd ? ;int
5153 IgorA 94
end if
95
if INTERP_STZ eq 1
5175 IgorA 96
	sz1 dd ? ;float
97
	dszdx dd ? ;float
98
	dszdy dd ? ;float
99
	dszdl_min dd ? ;float
100
	dszdl_max dd ? ;float
101
	tz1 dd ? ;float
102
	dtzdx dd ? ;float
103
	dtzdy dd ? ;float
104
	dtzdl_min dd ? ;float
105
	dtzdl_max dd ? ;float
6108 IgorA 106
	s_z dd ? ;float
107
	t_z dd ? ;float
5153 IgorA 108
end if
6113 IgorA 109
if (INTERP_ST eq 1) | (DRAW_LINE_M eq 1)
5175 IgorA 110
	s dd ? ;uint
111
	t dd ? ;uint
6113 IgorA 112
	dsdx dd ? ;int
113
	dtdx dd ? ;int
5175 IgorA 114
end if
5153 IgorA 115
endl
5187 IgorA 116
pushad
5153 IgorA 117
 
5175 IgorA 118
	; we sort the vertex with increasing y
119
	mov ebx,[p0]
120
	mov ecx,[p1]
121
	mov edx,[p2]
8069 IgorA 122
	mov eax,[edx+ZBufferPoint.y]
123
	cmp [ecx+ZBufferPoint.y],eax ;(2-1)
5187 IgorA 124
	jle @f
125
		xchg edx,ecx
5175 IgorA 126
	@@:
8069 IgorA 127
	mov eax,[ecx+ZBufferPoint.y]
128
	cmp [ebx+ZBufferPoint.y],eax ;(1-0)
5187 IgorA 129
	jle @f
130
		xchg ecx,ebx
131
	@@:
8069 IgorA 132
	mov eax,[edx+ZBufferPoint.y]
133
	cmp [ecx+ZBufferPoint.y],eax ;(2-1)
5187 IgorA 134
	jle @f
135
		xchg edx,ecx
136
	@@:
137
	mov [p0],ebx
138
	mov [p1],ecx
139
	mov [p2],edx
5153 IgorA 140
 
141
	; we compute dXdx and dXdy for all interpolated values
8069 IgorA 142
	mov eax,[ecx+ZBufferPoint.x]
143
	sub eax,[ebx+ZBufferPoint.x]
5175 IgorA 144
	mov [fdx1],eax ;p1.x - p0.x
8069 IgorA 145
	mov eax,[ecx+ZBufferPoint.y]
146
	sub eax,[ebx+ZBufferPoint.y]
5175 IgorA 147
	mov [fdy1],eax ;p1.y - p0.y
5153 IgorA 148
 
8069 IgorA 149
	mov eax,[edx+ZBufferPoint.x]
150
	sub eax,[ebx+ZBufferPoint.x]
5175 IgorA 151
	mov [fdx2],eax ;p2.x - p0.x
8069 IgorA 152
	mov eax,[edx+ZBufferPoint.y]
153
	sub eax,[ebx+ZBufferPoint.y]
5175 IgorA 154
	mov [fdy2],eax ;p2.y - p0.y
5153 IgorA 155
 
5187 IgorA 156
	fild dword[fdx1]
6141 IgorA 157
	fimul dword[fdy2]
5175 IgorA 158
	fild dword[fdx2]
6141 IgorA 159
	fimul dword[fdy1]
5187 IgorA 160
	fsubp ;st0 = st1-st0
5175 IgorA 161
	fst dword[fz] ;fz = fdx1 * fdy2 - fdx2 * fdy1
162
	fldz
5187 IgorA 163
	fcompp ;if (fz == 0) return
5175 IgorA 164
	fstsw ax
165
	sahf
166
	je .end_f
5189 IgorA 167
 
5175 IgorA 168
	fld1
169
	fdiv dword[fz] ;fz = 1.0 / fz
170
	fst dword[fz]  ;st0 = fz
5153 IgorA 171
 
6141 IgorA 172
	fild dword[fdx1]
5175 IgorA 173
	fmul st0,st1
174
	fstp dword[fdx1] ;fdx1 *= fz
6141 IgorA 175
	fild dword[fdy1]
5175 IgorA 176
	fmul st0,st1
177
	fstp dword[fdy1] ;fdy1 *= fz
6141 IgorA 178
	fild dword[fdx2]
5175 IgorA 179
	fmul st0,st1
180
	fstp dword[fdx2] ;fdx2 *= fz
6141 IgorA 181
	fild dword[fdy2]
182
	fmulp
5175 IgorA 183
	fstp dword[fdy2] ;fdy2 *= fz
5153 IgorA 184
 
185
if INTERP_Z eq 1
8069 IgorA 186
	mov eax,[ecx+ZBufferPoint.z]
187
	sub eax,[ebx+ZBufferPoint.z]
5175 IgorA 188
	mov [d1],eax
8069 IgorA 189
	mov eax,[edx+ZBufferPoint.z]
190
	sub eax,[ebx+ZBufferPoint.z]
5175 IgorA 191
	mov [d2],eax
5187 IgorA 192
	fild dword[d1] ;d1 = p1.z - p0.z
193
	fild dword[d2] ;d2 = p2.z - p0.z
5175 IgorA 194
 
6141 IgorA 195
	;dzdx = (int) (fdy2*d1 - fdy1*d2)
196
	;dzdy = (int) (fdx1*d2 - fdx2*d1)
197
	calc_d1d2 fi, dzdx, dzdy
5153 IgorA 198
end if
199
 
200
if INTERP_RGB eq 1
8069 IgorA 201
	mov eax,[ecx+ZBufferPoint.r]
202
	sub eax,[ebx+ZBufferPoint.r]
5175 IgorA 203
	mov [d1],eax
8069 IgorA 204
	mov eax,[edx+ZBufferPoint.r]
205
	sub eax,[ebx+ZBufferPoint.r]
5175 IgorA 206
	mov [d2],eax
5187 IgorA 207
	fild dword[d1] ;d1 = p1.r - p0.r
208
	fild dword[d2] ;d2 = p2.r - p0.r
5153 IgorA 209
 
6141 IgorA 210
	;drdx = (int) (fdy2*d1 - fdy1*d2)
211
	;drdy = (int) (fdx1*d2 - fdx2*d1)
212
	calc_d1d2 fi, drdx, drdy
5153 IgorA 213
 
8069 IgorA 214
	mov eax,[ecx+ZBufferPoint.g]
215
	sub eax,[ebx+ZBufferPoint.g]
5175 IgorA 216
	mov [d1],eax
8069 IgorA 217
	mov eax,[edx+ZBufferPoint.g]
218
	sub eax,[ebx+ZBufferPoint.g]
5175 IgorA 219
	mov [d2],eax
5187 IgorA 220
	fild dword[d1] ;d1 = p1.g - p0.g
221
	fild dword[d2] ;d2 = p2.g - p0.g
5153 IgorA 222
 
6141 IgorA 223
	;dgdx = (int) (fdy2*d1 - fdy1*d2)
224
	;dgdy = (int) (fdx1*d2 - fdx2*d1)
225
	calc_d1d2 fi, dgdx, dgdy
5175 IgorA 226
 
8069 IgorA 227
	mov eax,[ecx+ZBufferPoint.b]
228
	sub eax,[ebx+ZBufferPoint.b]
5175 IgorA 229
	mov [d1],eax
8069 IgorA 230
	mov eax,[edx+ZBufferPoint.b]
231
	sub eax,[ebx+ZBufferPoint.b]
5175 IgorA 232
	mov [d2],eax
5187 IgorA 233
	fild dword[d1] ;d1 = p1.b - p0.b
234
	fild dword[d2] ;d2 = p2.b - p0.b
5175 IgorA 235
 
6141 IgorA 236
	;dbdx = (int) (fdy2*d1 - fdy1*d2)
237
	;dbdy = (int) (fdx1*d2 - fdx2*d1)
238
	calc_d1d2 fi, dbdx, dbdy
5153 IgorA 239
end if
240
 
241
if INTERP_ST eq 1
8069 IgorA 242
	mov eax,[ecx+ZBufferPoint.s]
243
	sub eax,[ebx+ZBufferPoint.s]
5175 IgorA 244
	mov [d1],eax
8069 IgorA 245
	mov eax,[edx+ZBufferPoint.s]
246
	sub eax,[ebx+ZBufferPoint.s]
5175 IgorA 247
	mov [d2],eax
5187 IgorA 248
	fild dword[d1] ;d1 = p1.s - p0.s
249
	fild dword[d2] ;d2 = p2.s - p0.s
5153 IgorA 250
 
6141 IgorA 251
	;dsdx = (int) (fdy2*d1 - fdy1*d2)
252
	;dsdy = (int) (fdx1*d2 - fdx2*d1)
253
	calc_d1d2 fi, dsdx, dsdy
5175 IgorA 254
 
8069 IgorA 255
	mov eax,[ecx+ZBufferPoint.t]
256
	sub eax,[ebx+ZBufferPoint.t]
5175 IgorA 257
	mov [d1],eax
8069 IgorA 258
	mov eax,[edx+ZBufferPoint.t]
259
	sub eax,[ebx+ZBufferPoint.t]
5175 IgorA 260
	mov [d2],eax
5187 IgorA 261
	fild dword[d1] ;d1 = p1.t - p0.t
262
	fild dword[d2] ;d2 = p2.t - p0.t
5175 IgorA 263
 
6141 IgorA 264
	;dtdx = (int) (fdy2*d1 - fdy1*d2)
265
	;dtdy = (int) (fdx1*d2 - fdx2*d1)
266
	calc_d1d2 fi, dtdx, dtdy
5153 IgorA 267
end if
268
 
269
if INTERP_STZ eq 1
8069 IgorA 270
	fild dword[ebx+ZBufferPoint.z]
271
	fild dword[ebx+ZBufferPoint.s]
5175 IgorA 272
	fmul st0,st1
8069 IgorA 273
	fstp dword[ebx+ZBufferPoint.fsz] ;p0.sz = (float) p0.s * p0.z
274
	fild dword[ebx+ZBufferPoint.t]
5187 IgorA 275
	fmulp
8069 IgorA 276
	fstp dword[ebx+ZBufferPoint.tz] ;p0.tz = (float) p0.t * p0.z
5153 IgorA 277
 
8069 IgorA 278
	fild dword[ecx+ZBufferPoint.z]
279
	fild dword[ecx+ZBufferPoint.s]
5175 IgorA 280
	fmul st0,st1
8069 IgorA 281
	fstp dword[ecx+ZBufferPoint.fsz] ;p1.sz = (float) p1.s * p1.z
282
	fild dword[ecx+ZBufferPoint.t]
5187 IgorA 283
	fmulp
8069 IgorA 284
	fstp dword[ecx+ZBufferPoint.tz] ;p1.tz = (float) p1.t * p1.z
5153 IgorA 285
 
8069 IgorA 286
	fild dword[edx+ZBufferPoint.z]
287
	fild dword[edx+ZBufferPoint.s]
5175 IgorA 288
	fmul st0,st1
8069 IgorA 289
	fstp dword[edx+ZBufferPoint.fsz] ;p2.sz = (float) p2.s * p2.z
290
	fild dword[edx+ZBufferPoint.t]
5187 IgorA 291
	fmulp
8069 IgorA 292
	fstp dword[edx+ZBufferPoint.tz] ;p2.tz = (float) p2.t * p2.z
5175 IgorA 293
 
8069 IgorA 294
	fld dword[ecx+ZBufferPoint.fsz]
295
	fsub dword[ebx+ZBufferPoint.fsz] ;d1 = p1.sz - p0.sz
296
	fld dword[edx+ZBufferPoint.fsz]
297
	fsub dword[ebx+ZBufferPoint.fsz] ;d2 = p2.sz - p0.sz
5175 IgorA 298
 
6141 IgorA 299
	;dszdx = (fdy2*d1 - fdy1*d2)
300
	;dszdy = (fdx1*d2 - fdx2*d1)
301
	calc_d1d2 f, dszdx, dszdy
5175 IgorA 302
 
8069 IgorA 303
	fld dword[ecx+ZBufferPoint.tz]
304
	fsub dword[ebx+ZBufferPoint.tz] ;d1 = p1.tz - p0.tz
305
	fld dword[edx+ZBufferPoint.tz]
306
	fsub dword[ebx+ZBufferPoint.tz] ;d2 = p2.tz - p0.tz
5175 IgorA 307
 
6141 IgorA 308
	;dtzdx = (fdy2*d1 - fdy1*d2)
309
	;dtzdy = (fdx1*d2 - fdx2*d1)
310
	calc_d1d2 f, dtzdx, dtzdy
5153 IgorA 311
end if
312
 
313
	; screen coordinates
5175 IgorA 314
	mov eax,[zb]
8069 IgorA 315
	mov edx,[eax+ZBuffer.linesize]
316
	imul edx,[ebx+ZBufferPoint.y]
317
	add edx,[eax+ZBuffer.pbuf]
5175 IgorA 318
	mov [pp1],edx ;pp1 = zb.pbuf + zb.linesize * p0.y
8069 IgorA 319
	mov edx,[eax+ZBuffer.xsize]
320
	imul edx,[ebx+ZBufferPoint.y]
5175 IgorA 321
	shl edx,1
8069 IgorA 322
	add edx,[eax+ZBuffer.zbuf]
5175 IgorA 323
	mov [pz1],edx ;pz1 = zb.zbuf + zb.xsize * p0.y
5153 IgorA 324
 
325
	DRAW_INIT
326
 
5175 IgorA 327
	mov dword[part],0
328
	.cycle_0:
329
		mov ebx,[p0]
330
		mov ecx,[p1]
331
		mov edx,[p2]
5187 IgorA 332
		cmp dword[part],0 ;if (part == 0)
5175 IgorA 333
		jne .els_0
334
			mov dword[update_left],1
335
			mov dword[update_right],1
336
			mov [l1],ebx
337
			mov [pr1],ebx
338
			fldz
339
			fld dword[fz]
340
			fcompp ;if (fz > 0)
341
			fstsw ax
342
			sahf
343
			jbe .els_1
344
				mov [l2],edx
345
				mov [pr2],ecx
346
				jmp .end_1
6141 IgorA 347
align 4
5175 IgorA 348
			.els_1:
349
				mov [l2],ecx
350
				mov [pr2],edx
351
			.end_1:
8069 IgorA 352
			mov eax,[ecx+ZBufferPoint.y]
353
			sub eax,[ebx+ZBufferPoint.y]
5175 IgorA 354
			mov [nb_lines],eax ;nb_lines = p1.y - p0.y
355
			jmp .end_0
6141 IgorA 356
align 4
5175 IgorA 357
		.els_0:
358
			; second part
359
			fldz
360
			fld dword[fz]
361
			fcompp ;if (fz > 0)
362
			fstsw ax
363
			sahf
364
			jbe .els_2
5187 IgorA 365
				mov dword[update_left],0
366
				mov dword[update_right],1
5175 IgorA 367
				mov [pr1],ecx
368
				mov [pr2],edx
369
				jmp .end_2
6141 IgorA 370
align 4
5175 IgorA 371
			.els_2:
5187 IgorA 372
				mov dword[update_left],1
373
				mov dword[update_right],0
5175 IgorA 374
				mov [l1],ecx
375
				mov [l2],edx
376
			.end_2:
8069 IgorA 377
			mov eax,[edx+ZBufferPoint.y]
378
			sub eax,[ecx+ZBufferPoint.y]
5175 IgorA 379
			inc eax
380
			mov [nb_lines],eax ;nb_lines = p2.y - p1.y + 1
381
		.end_0:
5153 IgorA 382
 
383
	; compute the values for the left edge
5175 IgorA 384
	cmp dword[update_left],0 ;if (update_left)
385
	je .end_upd_l
386
		mov ebx,[l1]
387
		mov ecx,[l2]
8069 IgorA 388
		mov edx,[ecx+ZBufferPoint.y]
389
		sub edx,[ebx+ZBufferPoint.y]
5187 IgorA 390
		mov [dy1],edx ;dy1 = l2.y - l1.y
8069 IgorA 391
		mov eax,[ecx+ZBufferPoint.x]
392
		sub eax,[ebx+ZBufferPoint.x]
5175 IgorA 393
		mov [dx1],eax ;dx1 = l2.x - l1.x
5187 IgorA 394
		cmp edx,0 ;if (dy1 > 0)
5175 IgorA 395
		jle .els_3
5187 IgorA 396
			xor edx,edx
397
			cmp eax,0
398
			jl .otr_dx1
5175 IgorA 399
			shl eax,16
400
			div dword[dy1] ;eax = (dx1 << 16) / dy1
401
			jmp .end_3
6141 IgorA 402
align 4
5187 IgorA 403
			.otr_dx1:
404
			neg eax
405
			inc eax
406
			shl eax,16
407
			div dword[dy1] ;eax = (-dx1 << 16) / dy1
408
			neg eax
409
			inc eax
410
			jmp .end_3
6141 IgorA 411
align 4
5175 IgorA 412
		.els_3:
413
			xor eax,eax
414
		.end_3:
8069 IgorA 415
		mov edx,[ebx+ZBufferPoint.x]
5187 IgorA 416
		mov [x1],edx ;x1 = l1.x
417
		mov dword[error],0 ;error = 0
5175 IgorA 418
		mov dword[derror],eax
5187 IgorA 419
		and dword[derror],0xffff ;derror = eax & 0x0000ffff
5208 IgorA 420
		sar eax,16
5187 IgorA 421
		mov [dxdy_min],eax ;dxdy_min = eax >> 16
5175 IgorA 422
		inc eax
423
		mov [dxdy_max],eax
5153 IgorA 424
 
425
if INTERP_Z eq 1
5175 IgorA 426
	mov eax,[l1]
8069 IgorA 427
	mov eax,[eax+ZBufferPoint.z]
5175 IgorA 428
	mov [z1],eax ;z1 = l1.z
429
	mov eax,[dzdx]
430
	imul eax,[dxdy_min]
431
	add eax,[dzdy]
432
	mov [dzdl_min],eax ;dzdl_min = (dzdy +dzdx*dxdy_min)
433
	add eax,[dzdx]
434
	mov [dzdl_max],eax ;dzdl_max = dzdl_min +dzdx
5153 IgorA 435
end if
436
if INTERP_RGB eq 1
5175 IgorA 437
	mov ebx,[l1]
8069 IgorA 438
	mov eax,[ebx+ZBufferPoint.r]
5175 IgorA 439
	mov [r1],eax ;r1 = l1.r
440
	mov eax,[drdx]
441
	imul eax,[dxdy_min]
442
	add eax,[drdy]
443
	mov [drdl_min],eax ;drdl_min = (drdy +drdx*dxdy_min)
444
	add eax,[drdx]
445
	mov [drdl_max],eax ;drdl_max = drdl_min +drdx
5153 IgorA 446
 
8069 IgorA 447
	mov eax,[ebx+ZBufferPoint.g]
5175 IgorA 448
	mov [g1],eax ;g1 = l1.g
449
	mov eax,[dgdx]
450
	imul eax,[dxdy_min]
451
	add eax,[dgdy]
452
	mov [dgdl_min],eax ;dgdl_min = (dgdy +dgdx*dxdy_min)
453
	add eax,[dgdx]
454
	mov [dgdl_max],eax ;dgdl_max = dgdl_min +dgdx
5153 IgorA 455
 
8069 IgorA 456
	mov eax,[ebx+ZBufferPoint.b]
5175 IgorA 457
	mov [b1],eax ;b1 = l1.b
458
	mov eax,[dbdx]
459
	imul eax,[dxdy_min]
460
	add eax,[dbdy]
461
	mov [dbdl_min],eax ;dbdl_min = (dbdy +dbdx*dxdy_min)
462
	add eax,[dbdx]
463
	mov [dbdl_max],eax ;dbdl_max = dbdl_min +dbdx
5153 IgorA 464
end if
465
if INTERP_ST eq 1
5175 IgorA 466
	mov ebx,[l1]
8069 IgorA 467
	mov eax,[ebx+ZBufferPoint.s]
5175 IgorA 468
	mov [s1],eax ;s1 = l1.s
469
	mov eax,[dsdx]
470
	imul eax,[dxdy_min]
471
	add eax,[dsdy]
472
	mov [dsdl_min],eax ;dsdl_min = (dsdy +dsdx*dxdy_min)
473
	add eax,[dsdx]
474
	mov [dsdl_max],eax ;dsdl_max = dsdl_min +dsdx
5153 IgorA 475
 
8069 IgorA 476
	mov eax,[ebx+ZBufferPoint.t]
5175 IgorA 477
	mov [t1],eax ;t1 = l1.t
478
	mov eax,[dtdx]
479
	imul eax,[dxdy_min]
480
	add eax,[dtdy]
481
	mov [dtdl_min],eax ;dtdl_min = (dtdy +dtdx*dxdy_min)
482
	add eax,[dtdx]
483
	mov [dtdl_max],eax ;dtdl_max = dtdl_min +dtdx
5153 IgorA 484
end if
485
if INTERP_STZ eq 1
5175 IgorA 486
	mov ebx,[l1]
8069 IgorA 487
	mov eax,[ebx+ZBufferPoint.fsz]
5175 IgorA 488
	mov [sz1],eax ;sz1 = l1.sz - преобразований нет, потому без сопроцессора
489
	fild dword[dxdy_min]
490
	fmul dword[dszdx]
491
	fadd dword[dszdy]
492
	fst dword[dszdl_min] ;dszdl_min = (dszdy +dszdx*dxdy_min)
493
	fadd dword[dszdx]
494
	fstp dword[dszdl_max] ;dszdl_max = dszdl_min +dszdx
5153 IgorA 495
 
8069 IgorA 496
	mov eax,[ebx+ZBufferPoint.tz]
5175 IgorA 497
	mov [tz1],eax ;tz1 = l1.tz - преобразований нет, потому без сопроцессора
498
	fild dword[dxdy_min]
499
	fmul dword[dtzdx]
500
	fadd dword[dtzdy]
501
	fst dword[dtzdl_min] ;dtzdl_min = (dtzdy +dtzdx*dxdy_min)
502
	fadd dword[dtzdx]
503
	fstp dword[dtzdl_max] ;dtzdl_max = dtzdl_min +dtzdx
5153 IgorA 504
end if
5175 IgorA 505
	.end_upd_l:
5153 IgorA 506
 
5175 IgorA 507
	; compute values for the right edge
5153 IgorA 508
 
5175 IgorA 509
	cmp dword[update_right],0 ;if(update_right)
510
	je .end_upd_r
511
		mov ebx,[pr1]
512
		mov ecx,[pr2]
8069 IgorA 513
		mov edx,[ebx+ZBufferPoint.x]
514
		mov eax,[ecx+ZBufferPoint.x]
5187 IgorA 515
		sub eax,edx
516
		;mov [dx2],eax ;dx2 = pr2.x - pr1.x
517
		shl edx,16
518
		mov [x2],edx ; x2 = pr1.x << 16
8069 IgorA 519
		mov edx,[ecx+ZBufferPoint.y]
520
		sub edx,[ebx+ZBufferPoint.y]
5187 IgorA 521
		mov [dy2],edx ;dy2 = pr2.y - pr1.y
522
		cmp edx,0 ;if (dy2 > 0)
5175 IgorA 523
		jle .els_4
5187 IgorA 524
			xor edx,edx
525
			cmp eax,0
526
			jl .otr_dx2
5175 IgorA 527
			shl eax,16
528
			div dword[dy2] ;eax = (dx2 << 16) / dy2
529
			jmp .end_4
6141 IgorA 530
align 4
5187 IgorA 531
			.otr_dx2:
532
			neg eax
533
			inc eax ;dx2 *= -1
534
			shl eax,16
535
			div dword[dy2] ;eax = (-dx2 << 16) / dy2
536
			neg eax
537
			inc eax
538
			jmp .end_4
6141 IgorA 539
align 4
5175 IgorA 540
		.els_4:
541
			xor eax,eax
542
		.end_4:
543
		mov [dx2dy2],eax
544
	.end_upd_r:
5153 IgorA 545
 
5175 IgorA 546
	; we draw all the scan line of the part
5187 IgorA 547
if DEBUG ;[nb_lines]
548
push ecx edi
549
	mov eax,[nb_lines]
550
	mov ecx,80
551
	lea edi,[buf_param]
552
	stdcall convert_int_to_str,ecx
5153 IgorA 553
 
5187 IgorA 554
	stdcall str_n_cat,edi,txt_nl,2
555
	stdcall dbg_print,f_fill_tr_nl,buf_param
556
pop edi ecx
557
end if
558
 
5175 IgorA 559
	.beg_w_lin:
560
	cmp dword[nb_lines],0 ;while (nb_lines>0)
561
	jle .end_w_lin
562
		dec dword[nb_lines]
563
if DRAW_LINE_M eq 1
6113 IgorA 564
		DRAW_LINE
5175 IgorA 565
else
566
		; generic draw line
567
		mov eax,[x2]
5208 IgorA 568
		sar eax,16
5175 IgorA 569
		mov edi,[x1]
570
		sub eax,edi
571
		mov [n],eax ;n = (x2 >> 16) - x1
572
		imul edi,PSZB
573
		add edi,[pp1] ;pp = pp1 + x1 * PSZB
5187 IgorA 574
 
5153 IgorA 575
if INTERP_Z eq 1
6126 IgorA 576
		mov esi,[x1]
577
		shl esi,1
578
		add esi,[pz1]
5175 IgorA 579
		mov eax,[z1]
580
		mov [z],eax
5153 IgorA 581
end if
582
if INTERP_RGB eq 1
5175 IgorA 583
		mov eax,[r1]
5922 IgorA 584
		bt eax,31 ; коректирование испорченных пикселей (в начале линии)
585
		jnc @f
586
			xor eax,eax
587
		@@:
588
		bt eax,16
589
		jnc @f
590
			mov eax,0xff00
591
		@@:
5175 IgorA 592
		mov [or1],eax
593
		mov eax,[g1]
5922 IgorA 594
		bt eax,31
595
		jnc @f
596
			xor eax,eax
597
		@@:
598
		bt eax,16
599
		jnc @f
600
			mov eax,0xff00
601
		@@:
5175 IgorA 602
		mov [og1],eax
603
		mov eax,[b1]
5922 IgorA 604
		bt eax,31
605
		jnc @f
606
			xor eax,eax
607
		@@:
608
		bt eax,16
609
		jnc @f
610
			mov eax,0xff00
611
		@@:
5175 IgorA 612
		mov [ob1],eax
5153 IgorA 613
end if
614
if INTERP_ST eq 1
5175 IgorA 615
		mov eax,[s1]
616
		mov [s],eax
617
		mov eax,[t1]
618
		mov [t],eax
5153 IgorA 619
end if
620
if INTERP_STZ eq 1
5175 IgorA 621
		mov eax,[sz1]
622
		mov [s_z],eax
623
		mov eax,[tz1]
624
		mov [t_z],eax
5153 IgorA 625
end if
5187 IgorA 626
 
627
align 4
5175 IgorA 628
		.cycle_1: ;while (n>=3)
5922 IgorA 629
if INTERP_RGB eq 1
630
		cmp dword[n],5
631
		jl .cycle_2
632
else
5187 IgorA 633
		cmp dword[n],3
634
		jl .cycle_2
5922 IgorA 635
end if
5175 IgorA 636
			PUT_PIXEL 0
637
			PUT_PIXEL 1
638
			PUT_PIXEL 2
639
			PUT_PIXEL 3
5153 IgorA 640
if INTERP_Z eq 1
6126 IgorA 641
			add esi,8 ;=4*sizeof(uint)
5153 IgorA 642
end if
5175 IgorA 643
			add edi,4*PSZB
644
			sub dword[n],4
5187 IgorA 645
		jmp .cycle_1
6141 IgorA 646
align 4
5175 IgorA 647
		.cycle_2: ;while (n>=0)
5939 IgorA 648
		cmp dword[n],0
649
		jl .cycle_2_end
5922 IgorA 650
if INTERP_RGB eq 1
651
		; коректирование испорченных пикселей (в конце линии)
652
		bt dword[or1],31
653
		jnc @f
654
			mov dword[or1],0
655
			jmp .end_r
6141 IgorA 656
align 4
5922 IgorA 657
		@@:
658
		bt dword[or1],16
659
		jnc .end_r
660
			mov dword[or1],0xff00
661
		.end_r:
662
		bt dword[og1],31
663
		jnc @f
664
			mov dword[og1],0
665
			jmp .end_g
6141 IgorA 666
align 4
5922 IgorA 667
		@@:
668
		bt dword[og1],16
669
		jnc .end_g
670
			mov dword[og1],0xff00
671
		.end_g:
672
		bt dword[ob1],31
673
		jnc @f
674
			mov dword[ob1],0
675
			jmp .end_b
6141 IgorA 676
align 4
5922 IgorA 677
		@@:
678
		bt dword[ob1],16
679
		jnc .end_b
680
			mov dword[ob1],0xff00
681
		.end_b:
682
end if
5175 IgorA 683
			PUT_PIXEL 0
5153 IgorA 684
if INTERP_Z eq 1
6126 IgorA 685
			add esi,2 ;=sizeof(uint)
5153 IgorA 686
end if
5175 IgorA 687
			add edi,PSZB
688
			dec dword[n]
5187 IgorA 689
		jmp .cycle_2
6141 IgorA 690
align 4
5187 IgorA 691
		.cycle_2_end:
692
end if ;проверка от макроса DRAW_LINE
5175 IgorA 693
 
694
	; left edge
695
	mov eax,[derror]
696
	add [error],eax
5187 IgorA 697
	cmp dword[error],0 ;if (error > 0)
5175 IgorA 698
	jle .els_er
699
		sub dword[error],0x10000
700
		mov eax,[dxdy_max]
701
		add [x1],eax
5153 IgorA 702
if INTERP_Z eq 1
5175 IgorA 703
		mov eax,[dzdl_max]
704
		add [z1],eax
5153 IgorA 705
end if
706
if INTERP_RGB eq 1
5175 IgorA 707
		mov eax,[drdl_max]
708
		add [r1],eax
709
		mov eax,[dgdl_max]
710
		add [g1],eax
711
		mov eax,[dbdl_max]
712
		add [b1],eax
5153 IgorA 713
end if
714
if INTERP_ST eq 1
5175 IgorA 715
		mov eax,[dsdl_max]
716
		add [s1],eax
717
		mov eax,[dtdl_max]
718
		add [t1],eax
5153 IgorA 719
end if
720
if INTERP_STZ eq 1
5175 IgorA 721
		fld dword[dszdl_max]
722
		fadd dword[sz1]
723
		fstp dword[sz1]
724
		fld dword[dtzdl_max]
725
		fadd dword[tz1]
726
		fstp dword[tz1]
5153 IgorA 727
end if
5175 IgorA 728
		jmp .end_er
6141 IgorA 729
align 4
5175 IgorA 730
	.els_er:
731
		mov eax,[dxdy_min]
732
		add [x1],eax
5153 IgorA 733
if INTERP_Z eq 1
5175 IgorA 734
		mov eax,[dzdl_min]
735
		add [z1],eax
5153 IgorA 736
end if
737
if INTERP_RGB eq 1
5175 IgorA 738
		mov eax,[drdl_min]
739
		add [r1],eax
740
		mov eax,[dgdl_min]
741
		add [g1],eax
742
		mov eax,[dbdl_min]
743
		add [b1],eax
5153 IgorA 744
end if
745
if INTERP_ST eq 1
5175 IgorA 746
		mov eax,[dsdl_min]
747
		add [s1],eax
748
		mov eax,[dtdl_min]
749
		add [t1],eax
5153 IgorA 750
end if
751
if INTERP_STZ eq 1
5175 IgorA 752
		fld dword[dszdl_min]
753
		fadd dword[sz1]
754
		fstp dword[sz1]
755
		fld dword[dtzdl_min]
756
		fadd dword[tz1]
757
		fstp dword[tz1]
5153 IgorA 758
end if
5175 IgorA 759
	.end_er:
760
			; right edge
761
			mov eax,[dx2dy2]
762
			add [x2],eax
763
 
764
			; screen coordinates
765
			mov ebx,[zb]
8069 IgorA 766
			mov eax,[ebx+ZBuffer.linesize]
5175 IgorA 767
			add [pp1],eax
8069 IgorA 768
			mov eax,[ebx+ZBuffer.xsize]
5175 IgorA 769
			shl eax,1
770
			add [pz1],eax
771
			jmp .beg_w_lin
6141 IgorA 772
align 4
5175 IgorA 773
		.end_w_lin:
774
		inc dword[part]
775
		cmp dword[part],2
776
		jl .cycle_0
777
	.end_f:
5187 IgorA 778
popad
5175 IgorA 779
	ret
780
endp
781
 
5153 IgorA 782
restore INTERP_Z
783
restore INTERP_RGB
784
restore INTERP_ST
785
restore INTERP_STZ
5175 IgorA 786
restore DRAW_LINE_M
5153 IgorA 787
 
788
purge DRAW_INIT
5175 IgorA 789
purge DRAW_LINE
5153 IgorA 790
purge PUT_PIXEL