Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
6108 IgorA 1
;
2
; Макрос DRAW_LINE имеет параметр code, от которого зависит
3
; будет ли включен код или объявлены переменные.
4
; В версии на C++ параметра code нет, потому что там переменные
5
; можно ставить в любом месте функции, в asm версии такое не проходит.
6
;
5153 IgorA 7
 
8
INTERP_Z equ 1
9
 
10
macro DRAW_INIT
11
{
12
if TGL_FEATURE_RENDER_BITS eq 24
13
	mov ecx,[p2]
14
	mov eax,[ecx+offs_zbup_r]
5208 IgorA 15
	mov [colorR],ah ;colorR=p2.r>>8
5153 IgorA 16
	mov eax,[ecx+offs_zbup_g]
5208 IgorA 17
	mov [colorG],ah ;colorG=p2.g>>8
5153 IgorA 18
	mov eax,[ecx+offs_zbup_b]
5208 IgorA 19
	mov [colorB],ah ;colorB=p2.b>>8
5187 IgorA 20
;else
5153 IgorA 21
;  color=RGB_TO_PIXEL(p2->r,p2->g,p2->b);
22
end if
23
}
24
 
25
macro PUT_PIXEL _a
26
{
5175 IgorA 27
local .end_0
28
	mov eax,[z]
29
	shr eax, ZB_POINT_Z_FRAC_BITS
30
	mov [zz],eax
31
	mov ebx,[pz]
32
	cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
33
	jl .end_0
34
		;edi = pp
5187 IgorA 35
		mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
5153 IgorA 36
if TGL_FEATURE_RENDER_BITS eq 24
5175 IgorA 37
		mov cl,[colorR]
38
		mov ch,[colorG]
39
		mov word[edi+3*_a],cx
40
		mov cl,[colorB]
41
		mov byte[edi+3*_a +2],cl
5187 IgorA 42
;else
5153 IgorA 43
;      pp[_a]=color;
44
end if
5175 IgorA 45
	.end_0:
46
	mov eax,[dzdx]
47
	add [z],eax
5153 IgorA 48
}
49
 
50
align 4
51
proc ZB_fillTriangleFlat, zb:dword, p0:dword, p1:dword, p2:dword
52
locals
53
if TGL_FEATURE_RENDER_BITS eq 24
54
	colorR db ?
55
	colorG db ?
56
	colorB db ? ;unsigned char
57
else
58
	color dd ? ;int
59
end if
60
include 'ztriangle.inc'
61
 
62
;
63
; Smooth filled triangle.
64
; The code below is very tricky :)
65
;
66
 
67
INTERP_Z equ 1
68
INTERP_RGB equ 1
69
 
70
macro DRAW_INIT
71
{
72
if TGL_FEATURE_RENDER_BITS eq 16
73
;  _drgbdx=((drdx / (1<<6)) << 22) & 0xFFC00000;
74
;  _drgbdx|=(dgdx / (1<<5)) & 0x000007FF;
75
;  _drgbdx|=((dbdx / (1<<7)) << 12) & 0x001FF000;
76
end if
77
}
78
 
79
macro PUT_PIXEL _a
80
{
5187 IgorA 81
local .end_0
5175 IgorA 82
	mov eax,[z]
83
	shr eax,ZB_POINT_Z_FRAC_BITS
84
	mov [zz],eax
5187 IgorA 85
	mov ebx,[pz]
86
	cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
87
	jl .end_0
88
		;edi = pp
89
		mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
5153 IgorA 90
if TGL_FEATURE_RENDER_BITS eq 24
5922 IgorA 91
		mov ecx,[og1]
5187 IgorA 92
		mov eax,[or1]
93
		mov cl,ah
94
		mov word[edi+3*_a],cx
95
		mov eax,[ob1]
96
		mov byte[edi+3*_a +2],ah
97
end if
98
if TGL_FEATURE_RENDER_BITS eq 16
5153 IgorA 99
;      tmp=rgb & 0xF81F07E0;
100
;      pp[_a]=tmp | (tmp >> 16);
5187 IgorA 101
;else
5153 IgorA 102
;      pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);
5187 IgorA 103
end if
104
	.end_0:
5175 IgorA 105
	mov eax,[dzdx]
106
	add [z],eax
5187 IgorA 107
if TGL_FEATURE_RENDER_BITS eq 16
108
;    rgb=(rgb+drgbdx) & ( ~ 0x00200800);
5153 IgorA 109
end if
5187 IgorA 110
if TGL_FEATURE_RENDER_BITS <> 16
111
	mov eax,[dgdx]
112
	add [og1],eax
113
	mov eax,[drdx]
114
	add [or1],eax
115
	mov eax,[dbdx]
116
	add [ob1],eax
117
end if
5153 IgorA 118
}
119
 
5175 IgorA 120
macro DRAW_LINE code
5153 IgorA 121
{
5187 IgorA 122
local .cycle_0
123
local .cycle_1
5153 IgorA 124
if TGL_FEATURE_RENDER_BITS eq 16
5175 IgorA 125
if code eq 0
5187 IgorA 126
	tmp dd ? ;uint
127
	rgb dd ? ;uint
128
	drgbdx dd ? ;uint
5175 IgorA 129
end if
130
if code eq 1
5187 IgorA 131
	mov eax,[x2]
5208 IgorA 132
	sar eax,16
5187 IgorA 133
	sub eax,[x1]
134
	mov [n],eax ;n = (x2 >> 16) - x1
6108 IgorA 135
	mov edi,[pp1]
136
	add edi,[x1] ;pp = pp1 + x1
137
	mov eax,[pz1]
138
	add eax,[x1]
139
	mov [pz],eax ;pz = pz1 + x1
140
	mov eax,[z1]
141
	mov [z],eax ;z = z1
142
	mov eax,[r1]
143
	shl eax,16
144
	and eax,0xFFC00000
145
	mov [rgb],eax ;rgb = (r1 << 16) & 0xFFC00000
146
	mov eax,[g1]
147
	shr eax,5
148
	and eax,0x000007FF
149
	or [rgb],eax ;rgb |= (g1 >> 5) & 0x000007FF
150
	mov eax,[b1]
151
	shl eax,5
152
	and eax,0x001FF000
153
	or [rgb],eax ;rgb |= (b1 << 5) & 0x001FF000
154
	mov eax,[_drgbdx]
155
	mov [drgbdx],eax ;drgbdx = _drgbdx
5187 IgorA 156
align 4
157
	.cycle_0: ;while (n>=3)
158
	cmp dword[n],3
159
	jl .cycle_1
160
		PUT_PIXEL 0
161
		PUT_PIXEL 1
162
		PUT_PIXEL 2
163
		PUT_PIXEL 3
164
		add dword[pz],8
6108 IgorA 165
		add edi,4*3
5187 IgorA 166
		sub [n],4
167
	jmp .cycle_0
168
	.cycle_1: ;while (n>=0)
169
	cmp dword[n],0
170
	jl .cycle_1_end
171
		PUT_PIXEL 0
172
		add dword[pz],2
6108 IgorA 173
		add edi,3
5187 IgorA 174
		dec dword[n]
175
		jmp .cycle_1
176
	.cycle_1_end:
5153 IgorA 177
end if
178
end if
179
}
180
 
181
align 4
182
proc ZB_fillTriangleSmooth, zb:dword, p0:dword, p1:dword, p2:dword
183
locals
184
if TGL_FEATURE_RENDER_BITS eq 16
185
	_drgbdx dd ? ;int
186
end if
187
include 'ztriangle.inc'
188
 
189
align 4
190
proc ZB_setTexture uses eax ebx, zb:dword, texture:dword
191
	mov eax,[zb]
192
	mov ebx,[texture]
193
	mov dword[eax+offs_zbuf_current_texture],ebx
194
	ret
195
endp
196
 
197
INTERP_Z equ 1
198
INTERP_ST equ 1
199
 
200
macro DRAW_INIT
201
{
5187 IgorA 202
	mov eax,[zb]
203
	mov eax,[eax+offs_zbuf_current_texture]
204
	mov [texture],eax
5153 IgorA 205
}
206
 
207
macro PUT_PIXEL _a
208
{
5187 IgorA 209
local .end_0
210
	mov eax,[z]
211
	shr eax,ZB_POINT_Z_FRAC_BITS
212
	mov [zz],eax
213
	mov ebx,[pz]
214
	cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
215
	jl .end_0
5922 IgorA 216
		;edi = pp
217
		mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
5153 IgorA 218
if TGL_FEATURE_RENDER_BITS eq 24
6108 IgorA 219
		mov ebx,[t]
220
		and ebx,0x3fc00000
221
		or ebx,[s]
222
		shr ebx,14
223
		imul ebx,3
224
		add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | s) >> 14) * 3
225
		mov ax,word[ebx]
226
		mov word[edi+3*_a],ax ;pp[3 * _a]= ptr[0,1]
227
		mov al,byte[ebx+2]
228
		mov byte[edi+3*_a +2],al ;pp[3 * _a + 2]= ptr[2]
5153 IgorA 229
else
230
;       pp[_a]=texture[((t & 0x3FC00000) | s) >> 14];
231
end if
5187 IgorA 232
	.end_0:
5175 IgorA 233
	mov eax,[dzdx]
234
	add [z],eax
235
	mov eax,[dsdx]
236
	add [s],eax
237
	mov eax,[dtdx]
238
	add [t],eax
5153 IgorA 239
}
240
 
241
align 4
242
proc ZB_fillTriangleMapping, zb:dword, p0:dword, p1:dword, p2:dword
243
locals
244
	texture dd ? ;PIXEL*
245
include 'ztriangle.inc'
246
 
247
;
248
; Texture mapping with perspective correction.
249
; We use the gradient method to make less divisions.
250
; TODO: pipeline the division
251
;
252
if 1
253
 
254
INTERP_Z equ 1
255
INTERP_STZ equ 1
256
 
257
NB_INTERP equ 8
258
 
259
macro DRAW_INIT
260
{
5187 IgorA 261
	mov eax,[zb]
262
	mov eax,[eax+offs_zbuf_current_texture]
263
	mov [texture],eax
6108 IgorA 264
	mov dword[esp-4],NB_INTERP
265
	fild dword[esp-4]
5187 IgorA 266
	fild dword[dzdx]
6108 IgorA 267
	fst dword[fdzdx] ;fdzdx = (float)dzdx
268
	fmul st0,st1
269
	fstp dword[fndzdx] ;fndzdx = NB_INTERP * fdzdx
270
	fld dword[fdzdx]
271
	fmul st0,st1
272
	fstp dword[ndszdx] ;ndszdx = NB_INTERP * dszdx
273
	fmul dword[dtzdx]
274
	fstp dword[ndtzdx] ;ndtzdx = NB_INTERP * dtzdx
5153 IgorA 275
}
276
 
277
macro PUT_PIXEL _a
278
{
5187 IgorA 279
local .end_0
280
	mov eax,[z]
281
	shr eax,ZB_POINT_Z_FRAC_BITS
282
	mov [zz],eax
283
	mov ebx,[pz]
284
	cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
285
	jl .end_0
5922 IgorA 286
		;edi = pp
287
		mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
5153 IgorA 288
if TGL_FEATURE_RENDER_BITS eq 24
6108 IgorA 289
		mov ebx,[t]
290
		and ebx,0x3fc00000
291
		mov eax,[s]
292
		and eax,0x003fc000
293
		or ebx,eax
294
		shr ebx,14
295
		imul ebx,3
296
		add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | (s & 0x003FC000)) >> 14) * 3
297
		mov ax,word[ebx]
298
		mov word[edi+3*_a],ax ;pp[3 * _a]= ptr[0,1]
299
		mov al,byte[ebx+2]
300
		mov byte[edi+3*_a +2],al ;pp[3 * _a + 2]= ptr[2]
5153 IgorA 301
else
302
;       pp[_a]=*(PIXEL *)((char *)texture+
5187 IgorA 303
;           (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));
5153 IgorA 304
end if
5187 IgorA 305
	.end_0:
5175 IgorA 306
	mov eax,[dzdx]
307
	add [z],eax
308
	mov eax,[dsdx]
309
	add [s],eax
310
	mov eax,[dtdx]
311
	add [t],eax
5153 IgorA 312
}
313
 
5175 IgorA 314
DRAW_LINE_M equ 1
315
 
316
macro DRAW_LINE code
317
{
318
if TGL_FEATURE_RENDER_BITS eq 24
319
if code eq 0
320
	s dd ? ;uint
321
	t dd ? ;uint
5187 IgorA 322
	n1 dd ? ;int - длинна горизонтальной линии в пикселях
5175 IgorA 323
	dsdx dd ? ;int
324
	dtdx dd ? ;int
325
	fz dd ? ;float
326
	zinv dd ? ;float
327
end if
328
if code eq 1
6108 IgorA 329
	mov eax,[x2]
330
	sar eax,16
331
	sub eax,[x1]
332
	mov [n1],eax ;n1 = (x2 >> 16) - x1
333
fld1
334
	fild dword[z1]
335
	fst dword[fz] ;fz = (float)z1
336
	;fld1
337
	fdivp
338
	fstp dword[zinv] ;zinv = 1.0 / fz
339
	mov edi,[x1]
340
	imul edi,PSZB
341
	add edi,[pp1] ;pp = (pp1 + x1 * PSZB)
342
	mov eax,[pz1]
343
	add eax,[x1]
344
	mov [pz],eax ;pz = pz1 + x1
345
	mov eax,[z1]
346
	mov [z],eax ;z = z1
347
	mov eax,[sz1]
348
	mov [s_z],eax ;sz = sz1
349
	mov eax,[tz1]
350
	mov [t_z],eax ;tz = tz1
351
align 4
352
	.cycle_2: ;while (n1>=(NB_INTERP-1))
353
	cmp dword[n1],NB_INTERP-1
354
	jl .cycle_2_end
355
		fld dword[zinv]
356
		fld st0
357
		fmul dword[s_z] ;ss = (sz * zinv)
358
		fist dword[s] ;s = (int) ss
359
		fmul dword[fdzdx]
360
		fchs
361
		fadd dword[dszdx]
362
		fmul dword[zinv]
363
		fistp dword[dsdx] ;dsdx = (int)( (dszdx - ss*fdzdx)*zinv )
364
		fmul dword[t_z] ;tt = (tz * zinv)
365
		fist dword[t] ;t = (int) tt
366
		fmul dword[fdzdx]
367
		fchs
368
		fadd dword[dtzdx]
369
		fmul dword[zinv]
370
		fistp dword[dtdx] ;dtdx = (int)( (dtzdx - tt*fdzdx)*zinv )
371
fld1
372
		fld dword[fz]
373
		fadd dword[fndzdx]
374
		fst dword[fz] ;fz += fndzdx
375
		;fld1
376
		fdivp
377
		fstp dword[zinv] ;zinv = 1.0 / fz
378
		PUT_PIXEL 0
379
		PUT_PIXEL 1
380
		PUT_PIXEL 2
381
		PUT_PIXEL 3
382
		PUT_PIXEL 4
383
		PUT_PIXEL 5
384
		PUT_PIXEL 6
385
		PUT_PIXEL 7
386
		add dword[pz],2*NB_INTERP ;pz += NB_INTERP
387
		add edi,NB_INTERP*PSZB ;pp += NB_INTERP * PSZB
388
		sub dword[n1],NB_INTERP ;n1 -= NB_INTERP
389
		fld dword[ndszdx]
390
		fadd dword[s_z]
391
		fstp dword[s_z] ;s_z += ndszdx
392
		fld dword[ndtzdx]
393
		fadd dword[t_z]
394
		fstp dword[t_z] ;tz += ndtzdx
395
		jmp .cycle_2
396
	.cycle_2_end:
397
	fld dword[zinv]
398
	fld st0
399
	fmul dword[s_z] ;ss = (sz * zinv)
400
	fist dword[s] ;s = (int) ss
401
	fmul dword[fdzdx]
402
	fchs
403
	fadd dword[dszdx]
404
	fmul dword[zinv]
405
	fistp dword[dsdx] ;dsdx = (int)( (dszdx - ss*fdzdx)*zinv )
406
	fmul dword[t_z] ;tt = (tz * zinv)
407
	fist dword[t] ;t = (int) tt
408
	fmul dword[fdzdx]
409
	fchs
410
	fadd dword[dtzdx]
411
	fmul dword[zinv]
412
	fistp dword[dtdx] ;dtdx = (int)( (dtzdx - tt*fdzdx)*zinv )
413
align 4
414
	.cycle_3: ;while (n1>=0)
415
	cmp dword[n1],0
416
	jl .cycle_3_end
417
		PUT_PIXEL 0
418
		add dword[pz],2 ;pz += 1
419
		add edi,PSZB ;pp += PSZB
5187 IgorA 420
		dec dword[n1]
6108 IgorA 421
		jmp .cycle_3
422
	.cycle_3_end:
5175 IgorA 423
end if
424
end if
425
}
426
 
5153 IgorA 427
align 4
428
proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
429
locals
5175 IgorA 430
	texture dd ? ;PIXEL *
431
	fdzdx dd ? ;float
5187 IgorA 432
	fndzdx dd ? ;float
433
	ndszdx dd ? ;float
434
	ndtzdx dd ? ;float
5153 IgorA 435
include 'ztriangle.inc'
436
 
437
end if
438
 
439
if 0
440
 
441
; slow but exact version (only there for reference, incorrect for 24
442
; bits)
443
 
444
INTERP_Z equ 1
445
INTERP_STZ equ 1
446
 
447
macro DRAW_INIT
448
{
5187 IgorA 449
	mov eax,[zb]
450
	mov eax,[eax+offs_zbuf_current_texture]
451
	mov [texture],eax
5153 IgorA 452
}
453
 
454
macro PUT_PIXEL _a
455
{
5187 IgorA 456
local .end_0
5153 IgorA 457
;   int s,t;
5187 IgorA 458
	mov eax,[z]
459
	shr eax,ZB_POINT_Z_FRAC_BITS
460
	mov [zz],eax
461
	mov ebx,[pz]
462
	cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
463
	jl .end_0
5922 IgorA 464
		;edi = pp
465
		mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
5187 IgorA 466
		fild dword[z]
467
		fld dword[s_z]
468
		fdiv st0,st1
469
		;fistp dword[...s...] ;s = (int) (s_z / (float) z)
470
;       t= (int) (t_z / (float) z);
5153 IgorA 471
;       pp[_a]=texture[((t & 0x3FC00000) | s) >> 14];
5187 IgorA 472
	.end_0:
5175 IgorA 473
	mov eax,[dzdx]
474
	add [z],eax
5187 IgorA 475
	fld dword[dszdx]
476
	fadd dword[s_z]
477
	fstp dword[s_z]
478
	fld dword,[dtzdx]
479
	fadd dword[t_z]
480
	fstp dword[t_z]
5153 IgorA 481
}
482
 
483
align 4
484
proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
485
locals
486
	texture dd ? ;PIXEL*
487
include 'ztriangle.inc'
488
 
489
end if