Subversion Repositories Kolibri OS

Rev

Rev 6108 | Rev 6113 | 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
6111 IgorA 37
		mov al,[colorR]
38
		mov ah,[colorG]
39
		mov word[edi+3*_a],ax
40
		mov al,[colorB]
41
		mov byte[edi+3*_a +2],al
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
}
73
 
74
macro PUT_PIXEL _a
75
{
5187 IgorA 76
local .end_0
5175 IgorA 77
	mov eax,[z]
78
	shr eax,ZB_POINT_Z_FRAC_BITS
79
	mov [zz],eax
5187 IgorA 80
	mov ebx,[pz]
81
	cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
82
	jl .end_0
83
		;edi = pp
84
		mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
5153 IgorA 85
if TGL_FEATURE_RENDER_BITS eq 24
6111 IgorA 86
		mov ebx,[or1]
87
		mov eax,[og1]
88
		mov al,bh
89
		mov word[edi+3*_a],ax
5187 IgorA 90
		mov eax,[ob1]
91
		mov byte[edi+3*_a +2],ah
92
end if
6111 IgorA 93
;if TGL_FEATURE_RENDER_BITS eq 32
5153 IgorA 94
;      pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);
6111 IgorA 95
;end if
5187 IgorA 96
	.end_0:
5175 IgorA 97
	mov eax,[dzdx]
98
	add [z],eax
5187 IgorA 99
	mov eax,[dgdx]
100
	add [og1],eax
101
	mov eax,[drdx]
102
	add [or1],eax
103
	mov eax,[dbdx]
104
	add [ob1],eax
5153 IgorA 105
}
106
 
5187 IgorA 107
align 4
5153 IgorA 108
proc ZB_fillTriangleSmooth, zb:dword, p0:dword, p1:dword, p2:dword
109
locals
110
include 'ztriangle.inc'
111
 
112
align 4
113
proc ZB_setTexture uses eax ebx, zb:dword, texture:dword
114
	mov eax,[zb]
115
	mov ebx,[texture]
116
	mov dword[eax+offs_zbuf_current_texture],ebx
117
	ret
118
endp
119
 
120
INTERP_Z equ 1
121
INTERP_ST equ 1
122
 
123
macro DRAW_INIT
124
{
5187 IgorA 125
	mov eax,[zb]
126
	mov eax,[eax+offs_zbuf_current_texture]
127
	mov [texture],eax
5153 IgorA 128
}
129
 
130
macro PUT_PIXEL _a
131
{
5187 IgorA 132
local .end_0
133
	mov eax,[z]
134
	shr eax,ZB_POINT_Z_FRAC_BITS
135
	mov [zz],eax
136
	mov ebx,[pz]
137
	cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
138
	jl .end_0
5922 IgorA 139
		;edi = pp
140
		mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
5153 IgorA 141
if TGL_FEATURE_RENDER_BITS eq 24
6108 IgorA 142
		mov ebx,[t]
143
		and ebx,0x3fc00000
144
		or ebx,[s]
145
		shr ebx,14
146
		imul ebx,3
147
		add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | s) >> 14) * 3
148
		mov ax,word[ebx]
149
		mov word[edi+3*_a],ax ;pp[3 * _a]= ptr[0,1]
150
		mov al,byte[ebx+2]
151
		mov byte[edi+3*_a +2],al ;pp[3 * _a + 2]= ptr[2]
5153 IgorA 152
else
153
;       pp[_a]=texture[((t & 0x3FC00000) | s) >> 14];
154
end if
5187 IgorA 155
	.end_0:
5175 IgorA 156
	mov eax,[dzdx]
157
	add [z],eax
158
	mov eax,[dsdx]
159
	add [s],eax
160
	mov eax,[dtdx]
161
	add [t],eax
5153 IgorA 162
}
163
 
164
align 4
165
proc ZB_fillTriangleMapping, zb:dword, p0:dword, p1:dword, p2:dword
166
locals
167
	texture dd ? ;PIXEL*
168
include 'ztriangle.inc'
169
 
170
;
171
; Texture mapping with perspective correction.
172
; We use the gradient method to make less divisions.
173
; TODO: pipeline the division
174
;
175
if 1
176
 
177
INTERP_Z equ 1
178
INTERP_STZ equ 1
179
 
180
NB_INTERP equ 8
181
 
182
macro DRAW_INIT
183
{
5187 IgorA 184
	mov eax,[zb]
185
	mov eax,[eax+offs_zbuf_current_texture]
186
	mov [texture],eax
6108 IgorA 187
	mov dword[esp-4],NB_INTERP
188
	fild dword[esp-4]
5187 IgorA 189
	fild dword[dzdx]
6108 IgorA 190
	fst dword[fdzdx] ;fdzdx = (float)dzdx
191
	fmul st0,st1
192
	fstp dword[fndzdx] ;fndzdx = NB_INTERP * fdzdx
193
	fld dword[fdzdx]
194
	fmul st0,st1
195
	fstp dword[ndszdx] ;ndszdx = NB_INTERP * dszdx
196
	fmul dword[dtzdx]
197
	fstp dword[ndtzdx] ;ndtzdx = NB_INTERP * dtzdx
5153 IgorA 198
}
199
 
200
macro PUT_PIXEL _a
201
{
5187 IgorA 202
local .end_0
203
	mov eax,[z]
204
	shr eax,ZB_POINT_Z_FRAC_BITS
205
	mov [zz],eax
206
	mov ebx,[pz]
207
	cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
208
	jl .end_0
5922 IgorA 209
		;edi = pp
210
		mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
5153 IgorA 211
if TGL_FEATURE_RENDER_BITS eq 24
6108 IgorA 212
		mov ebx,[t]
213
		and ebx,0x3fc00000
214
		mov eax,[s]
215
		and eax,0x003fc000
216
		or ebx,eax
217
		shr ebx,14
218
		imul ebx,3
219
		add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | (s & 0x003FC000)) >> 14) * 3
220
		mov ax,word[ebx]
221
		mov word[edi+3*_a],ax ;pp[3 * _a]= ptr[0,1]
222
		mov al,byte[ebx+2]
223
		mov byte[edi+3*_a +2],al ;pp[3 * _a + 2]= ptr[2]
5153 IgorA 224
else
225
;       pp[_a]=*(PIXEL *)((char *)texture+
5187 IgorA 226
;           (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));
5153 IgorA 227
end if
5187 IgorA 228
	.end_0:
5175 IgorA 229
	mov eax,[dzdx]
230
	add [z],eax
231
	mov eax,[dsdx]
232
	add [s],eax
233
	mov eax,[dtdx]
234
	add [t],eax
5153 IgorA 235
}
236
 
5175 IgorA 237
DRAW_LINE_M equ 1
238
 
239
macro DRAW_LINE code
240
{
241
if TGL_FEATURE_RENDER_BITS eq 24
242
if code eq 0
243
	s dd ? ;uint
244
	t dd ? ;uint
245
	dsdx dd ? ;int
246
	dtdx dd ? ;int
247
	fz dd ? ;float
248
	zinv dd ? ;float
249
end if
250
if code eq 1
6108 IgorA 251
	mov eax,[x2]
252
	sar eax,16
253
	sub eax,[x1]
6111 IgorA 254
	mov [n],eax ;n = (x2 >> 16) - x1
6108 IgorA 255
fld1
256
	fild dword[z1]
257
	fst dword[fz] ;fz = (float)z1
258
	;fld1
259
	fdivp
260
	fstp dword[zinv] ;zinv = 1.0 / fz
261
	mov edi,[x1]
262
	imul edi,PSZB
263
	add edi,[pp1] ;pp = (pp1 + x1 * PSZB)
6111 IgorA 264
	mov eax,[x1]
265
	shl eax,1
266
	add eax,[pz1]
6108 IgorA 267
	mov [pz],eax ;pz = pz1 + x1
268
	mov eax,[z1]
269
	mov [z],eax ;z = z1
270
	mov eax,[sz1]
271
	mov [s_z],eax ;sz = sz1
272
	mov eax,[tz1]
273
	mov [t_z],eax ;tz = tz1
274
align 4
6111 IgorA 275
	.cycle_2: ;while (n>=(NB_INTERP-1))
276
	cmp dword[n],NB_INTERP-1
6108 IgorA 277
	jl .cycle_2_end
278
		fld dword[zinv]
279
		fld st0
280
		fmul dword[s_z] ;ss = (sz * zinv)
281
		fist dword[s] ;s = (int) ss
282
		fmul dword[fdzdx]
283
		fchs
284
		fadd dword[dszdx]
285
		fmul dword[zinv]
286
		fistp dword[dsdx] ;dsdx = (int)( (dszdx - ss*fdzdx)*zinv )
287
		fmul dword[t_z] ;tt = (tz * zinv)
288
		fist dword[t] ;t = (int) tt
289
		fmul dword[fdzdx]
290
		fchs
291
		fadd dword[dtzdx]
292
		fmul dword[zinv]
293
		fistp dword[dtdx] ;dtdx = (int)( (dtzdx - tt*fdzdx)*zinv )
294
fld1
295
		fld dword[fz]
296
		fadd dword[fndzdx]
297
		fst dword[fz] ;fz += fndzdx
298
		;fld1
299
		fdivp
300
		fstp dword[zinv] ;zinv = 1.0 / fz
301
		PUT_PIXEL 0
302
		PUT_PIXEL 1
303
		PUT_PIXEL 2
304
		PUT_PIXEL 3
305
		PUT_PIXEL 4
306
		PUT_PIXEL 5
307
		PUT_PIXEL 6
308
		PUT_PIXEL 7
309
		add dword[pz],2*NB_INTERP ;pz += NB_INTERP
310
		add edi,NB_INTERP*PSZB ;pp += NB_INTERP * PSZB
6111 IgorA 311
		sub dword[n],NB_INTERP ;n -= NB_INTERP
6108 IgorA 312
		fld dword[ndszdx]
313
		fadd dword[s_z]
6111 IgorA 314
		fstp dword[s_z] ;sz += ndszdx
6108 IgorA 315
		fld dword[ndtzdx]
316
		fadd dword[t_z]
317
		fstp dword[t_z] ;tz += ndtzdx
318
		jmp .cycle_2
319
	.cycle_2_end:
320
	fld dword[zinv]
321
	fld st0
322
	fmul dword[s_z] ;ss = (sz * zinv)
323
	fist dword[s] ;s = (int) ss
324
	fmul dword[fdzdx]
325
	fchs
326
	fadd dword[dszdx]
327
	fmul dword[zinv]
328
	fistp dword[dsdx] ;dsdx = (int)( (dszdx - ss*fdzdx)*zinv )
329
	fmul dword[t_z] ;tt = (tz * zinv)
330
	fist dword[t] ;t = (int) tt
331
	fmul dword[fdzdx]
332
	fchs
333
	fadd dword[dtzdx]
334
	fmul dword[zinv]
335
	fistp dword[dtdx] ;dtdx = (int)( (dtzdx - tt*fdzdx)*zinv )
336
align 4
6111 IgorA 337
	.cycle_3: ;while (n>=0)
338
	cmp dword[n],0
6108 IgorA 339
	jl .cycle_3_end
340
		PUT_PIXEL 0
341
		add dword[pz],2 ;pz += 1
342
		add edi,PSZB ;pp += PSZB
6111 IgorA 343
		dec dword[n]
6108 IgorA 344
		jmp .cycle_3
345
	.cycle_3_end:
5175 IgorA 346
end if
347
end if
348
}
349
 
5153 IgorA 350
align 4
351
proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
352
locals
5175 IgorA 353
	texture dd ? ;PIXEL *
354
	fdzdx dd ? ;float
5187 IgorA 355
	fndzdx dd ? ;float
356
	ndszdx dd ? ;float
357
	ndtzdx dd ? ;float
5153 IgorA 358
include 'ztriangle.inc'
359
 
360
end if
361
 
362
if 0
363
 
364
; slow but exact version (only there for reference, incorrect for 24
365
; bits)
366
 
367
INTERP_Z equ 1
368
INTERP_STZ equ 1
369
 
370
macro DRAW_INIT
371
{
5187 IgorA 372
	mov eax,[zb]
373
	mov eax,[eax+offs_zbuf_current_texture]
374
	mov [texture],eax
5153 IgorA 375
}
376
 
377
macro PUT_PIXEL _a
378
{
5187 IgorA 379
local .end_0
5153 IgorA 380
;   int s,t;
5187 IgorA 381
	mov eax,[z]
382
	shr eax,ZB_POINT_Z_FRAC_BITS
383
	mov [zz],eax
384
	mov ebx,[pz]
385
	cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
386
	jl .end_0
5922 IgorA 387
		;edi = pp
388
		mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
5187 IgorA 389
		fild dword[z]
390
		fld dword[s_z]
391
		fdiv st0,st1
6111 IgorA 392
		fistp dword[esp-4] ;s = (int) (s_z / (float) z)
393
		fld dword[t_z]
394
		fdiv st0,st1
395
		fistp dword[esp-8] ;t = (int) (t_z / (float) z)
396
		mov eax,dword[esp-8]
397
		and eax,0x3FC00000
398
		or eax,dword[esp-4]
399
		shr eax,12 ;14
400
		add eax,[texture]
401
		mov eax,[eax]
402
		stosd ;pp[_a] = texture[((t & 0x3FC00000) | s) >> 14]
403
		sub edi,4
5187 IgorA 404
	.end_0:
5175 IgorA 405
	mov eax,[dzdx]
406
	add [z],eax
5187 IgorA 407
	fld dword[dszdx]
408
	fadd dword[s_z]
409
	fstp dword[s_z]
410
	fld dword,[dtzdx]
411
	fadd dword[t_z]
412
	fstp dword[t_z]
5153 IgorA 413
}
414
 
415
align 4
416
proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
417
locals
418
	texture dd ? ;PIXEL*
419
include 'ztriangle.inc'
420
 
421
end if