Subversion Repositories Kolibri OS

Rev

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

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