fix in textures

git-svn-id: svn://kolibrios.org@6134 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2016-02-04 09:24:21 +00:00
parent fc65c2518c
commit 5398730057
3 changed files with 122 additions and 34 deletions

View File

@ -8,7 +8,7 @@ CLIP_YMAX equ (1<<3)
CLIP_ZMIN equ (1<<4)
CLIP_ZMAX equ (1<<5)
align 4
align 16
proc gl_transform_to_viewport uses eax ebx ecx, context:dword,v:dword
locals
point dd ?
@ -53,6 +53,7 @@ endl
push ecx
stdcall RGBFtoRGBI, dword[ebx+offs_vert_color],dword[ebx+offs_vert_color+4],dword[ebx+offs_vert_color+8]
jmp .end_if
align 4
@@:
; no need to convert to integer if no lighting : take current color
mov ecx,[eax+offs_cont_longcurrent_color]
@ -74,14 +75,14 @@ endl
mov dword[point],dword(ZB_POINT_T_MAX - ZB_POINT_T_MIN)
fild dword[point]
fmul dword[ebx+offs_vert_tex_coord+4] ;st0 *= v.tex_coord.Y
fmul dword[ebx+offs_vert_tex_coord+offs_Y] ;st0 *= v.tex_coord.Y
fistp dword[ebx+offs_vert_zp+offs_zbup_t]
add dword[ebx+offs_vert_zp+offs_zbup_s],ZB_POINT_T_MIN
@@:
ret
endp
align 4
align 16
proc gl_add_select1 uses eax ebx ecx, context:dword, z1:dword,z2:dword,z3:dword
mov eax,[z1]
mov ebx,eax
@ -113,7 +114,7 @@ endp
; point
align 4
align 16
proc gl_draw_point uses eax ebx, context:dword, p0:dword
mov ebx,[p0]
cmp dword[ebx+offs_vert_clip_code],0 ;if (p0.clip_code == 0)
@ -123,6 +124,7 @@ proc gl_draw_point uses eax ebx, context:dword, p0:dword
jne .els
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
jmp @f
align 4
.els:
add ebx,offs_vert_zp
stdcall ZB_plot, dword[eax+offs_cont_zb],ebx
@ -132,7 +134,7 @@ endp
; line
align 4
align 16
proc interpolate uses eax ebx ecx, q:dword,p0:dword,p1:dword,t:dword
mov eax,[q]
mov ebx,[p0]
@ -195,7 +197,7 @@ endp
; Line Clipping algorithm from 'Computer Graphics', Principles and
; Practice
; tmin,tmax -> &float
align 4
align 16
proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword
fld dword[denom]
ftst
@ -217,6 +219,7 @@ proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword
jbe .r1_f1 ;if (t>*tmin) *tmin=t
fstp dword[ebx]
jmp .r1
align 4
.els_0: ;else if (denom<0)
jae .els_1
fld dword[num]
@ -234,6 +237,7 @@ proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword
jae .r1_f1
fstp dword[ebx] ;if (t<*tmin) *tmax=t
jmp .r1
align 4
.els_1: ;else if (num>0)
ffree st0 ;denom
fincstp
@ -243,13 +247,14 @@ proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword
sahf
ja .r0_f1 ;if (num>0) return 0
jmp .r1_f1
align 4
.r0_f1: ;return 0 & free st0
ffree st0
fincstp
.r0: ;return 0
xor eax,eax
jmp .end_f
align 4
.r1_f1: ;return 1 & free st0
ffree st0
fincstp
@ -260,7 +265,7 @@ proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword
ret
endp
align 4
align 16
proc gl_draw_line, context:dword, p1:dword, p2:dword
locals
d_x dd ?
@ -291,6 +296,7 @@ pushad
stdcall gl_add_select1, edx,dword[edi+offs_vert_zp+offs_zbup_z],\
dword[esi+offs_vert_zp+offs_zbup_z],dword[esi+offs_vert_zp+offs_zbup_z]
jmp .end_f
align 4
.els_1:
add edi,offs_vert_zp
add esi,offs_vert_zp
@ -302,15 +308,17 @@ pushad
;if (context.depth_test)
call ZB_line_z ;, dword[edx+offs_cont_zb],edi,esi
jmp .end_f
align 4
.els_2:
call ZB_line ;, dword[edx+offs_cont_zb],edi,esi
jmp .end_f
align 4
.els_i:
;else if ( (p1.clip_code & p2.clip_code) != 0 )
mov eax,[edi+offs_vert_clip_code]
and eax,[esi+offs_vert_clip_code]
cmp eax,0
jne .end_f
or eax,eax
jnz .end_f
.els_0:
fld dword[esi+offs_vert_pc+offs_X]
@ -454,6 +462,7 @@ pushad
je .els_3
call ZB_line_z ;(context.zb,&q1.zp,&q2.zp)
jmp .end_f
align 4
.els_3:
call ZB_line ;(context.zb,&q1.zp,&q2.zp)
.end_f:
@ -509,6 +518,7 @@ end if
fldz
fst dword[t] ;t=0
jmp .e_zero
align 4
@@: ;else
fld dword[edx+offs#dir]
if sign eq 0
@ -543,37 +553,37 @@ end if
mov eax,[t]
}
align 4
align 16
proc clip_xmin uses ebx ecx edx, c:dword, a:dword, b:dword
clip_func 0,_X,_Y,_Z
ret
endp
align 4
align 16
proc clip_xmax uses ebx ecx edx, c:dword, a:dword, b:dword
clip_func 1,_X,_Y,_Z
ret
endp
align 4
align 16
proc clip_ymin uses ebx ecx edx, c:dword, a:dword, b:dword
clip_func 0,_Y,_X,_Z
ret
endp
align 4
align 16
proc clip_ymax uses ebx ecx edx, c:dword, a:dword, b:dword
clip_func 1,_Y,_X,_Z
ret
endp
align 4
align 16
proc clip_zmin uses ebx ecx edx, c:dword, a:dword, b:dword
clip_func 0,_Z,_X,_Y
ret
endp
align 4
align 16
proc clip_zmax uses ebx ecx edx, c:dword, a:dword, b:dword
clip_func 1,_Z,_X,_Y
ret
@ -582,7 +592,7 @@ endp
align 4
clip_proc dd clip_xmin,clip_xmax, clip_ymin,clip_ymax, clip_zmin,clip_zmax
align 4
align 16
proc updateTmp uses eax ebx ecx edx, context:dword, q:dword, p0:dword, p1:dword, t:dword
mov ebx,[q]
mov edx,[context]
@ -606,6 +616,7 @@ proc updateTmp uses eax ebx ecx edx, context:dword, q:dword, p0:dword, p1:dword,
fadd dword[eax+offs_vert_color+8]
fstp dword[ebx+offs_vert_color+8] ;q.color.v[2]=p0.color.v[2] + (p1.color.v[2]-p0.color.v[2])*t
jmp @f
align 4
.els_0:
mov ecx,[eax+offs_vert_color]
mov [ebx+offs_vert_color],ecx ;q.color.v[0]=p0.color.v[0]
@ -648,7 +659,7 @@ proc updateTmp uses eax ebx ecx edx, context:dword, q:dword, p0:dword, p1:dword,
ret
endp
align 4
align 16
proc gl_draw_triangle, context:dword, p0:dword, p1:dword, p2:dword
locals
cc rd 3
@ -716,6 +727,7 @@ pushad
je .end_f
stdcall dword[edi+offs_cont_draw_triangle_front], edi,ebx,ecx,edx
jmp .end_f
align 4
@@:
cmp dword[edi+offs_cont_current_cull_face],GL_FRONT
jne .end_f
@ -723,15 +735,18 @@ pushad
jne .end_f
stdcall dword[edi+offs_cont_draw_triangle_back], edi,ebx,ecx,edx
jmp .end_f
align 4
.els_1:
; no culling
cmp dword[front],0
je @f
stdcall dword[edi+offs_cont_draw_triangle_front], edi,ebx,ecx,edx
jmp .end_f
align 4
@@:
stdcall dword[edi+offs_cont_draw_triangle_back], edi,ebx,ecx,edx
jmp .end_f
align 4
.els_0:
;eax = cc[2]
and eax,[cc]
@ -744,7 +759,7 @@ popad
ret
endp
align 4
align 16
proc gl_draw_triangle_clip, context:dword, p0:dword, p1:dword, p2:dword, clip_bit:dword
locals
co dd ?
@ -774,6 +789,7 @@ pushad
jnz .els_0
stdcall gl_draw_triangle, [context],ebx,ecx,edx
jmp .end_f
align 4
.els_0:
;eax = cc[2]
and eax,[cc]
@ -796,6 +812,7 @@ pushad
jnz .cycle_0_end
inc dword[clip_bit]
jmp .cycle_0
align 4
.cycle_0_end:
; this test can be true only in case of rounding errors
@ -837,6 +854,7 @@ end if
mov [q+4],ecx
mov [q+8],edx
jmp .els_2_end
align 4
.els_2:
mov eax,[cc+4]
and eax,[clip_mask]
@ -847,6 +865,7 @@ end if
mov [q+4],edx
mov [q+8],ebx
jmp .els_2_end
align 4
.els_3:
;q[0]=p2 q[1]=p0 q[2]=p1
mov [q],edx
@ -908,6 +927,7 @@ end if
add edi,sizeof.GLVertex ;edi = &tmp2
stdcall gl_draw_triangle_clip,[context],edi ;gl_draw_triangle_clip(c,&tmp2,&tmp1,q[2],clip_bit+1)
jmp .end_f
align 4
.els_1:
; two points outside
mov eax,[cc]
@ -919,6 +939,7 @@ end if
mov [q+4],ecx
mov [q+8],edx
jmp .els_4_end
align 4
.els_4:
mov eax,[cc+4]
and eax,[clip_mask]
@ -929,6 +950,7 @@ end if
mov [q+4],edx
mov [q+8],ebx
jmp .els_4_end
align 4
.els_5:
;q[0]=p2 q[1]=p0 q[2]=p1
mov [q],edx
@ -977,7 +999,7 @@ popad
ret
endp
align 4
align 16
proc gl_draw_triangle_select uses eax, context:dword, p0:dword,p1:dword,p2:dword
mov eax,[p2]
push dword[eax+offs_vert_zp+offs_Z]
@ -995,7 +1017,7 @@ if PROFILE eq 1
count_pixels dd ?
end if
align 4
align 16
proc gl_draw_triangle_fill, context:dword, p0:dword,p1:dword,p2:dword
pushad
if PROFILE eq 1
@ -1030,8 +1052,19 @@ end if
stdcall ZB_setTexture, dword[edx+offs_cont_zb],dword[eax]
mov eax,[p0]
add eax,offs_vert_zp
stdcall ZB_fillTriangleMappingPerspective, dword[edx+offs_cont_zb],eax,ebx,ecx
push ecx
push ebx
push eax
push dword[edx+offs_cont_zb]
cmp dword[edx+offs_cont_matrix_model_projection_no_w_transform],0
je @f
call ZB_fillTriangleMappingPerspective
jmp .end_f
align 4
@@:
call ZB_fillTriangleMapping
jmp .end_f
align 4
.els_i:
mov eax,[p0]
add eax,offs_vert_zp
@ -1040,6 +1073,7 @@ end if
;else if (context.current_shade_model == GL_SMOOTH)
stdcall ZB_fillTriangleSmooth, dword[edx+offs_cont_zb],eax,ebx,ecx
jmp .end_f
align 4
.els:
stdcall ZB_fillTriangleFlat, dword[edx+offs_cont_zb],eax,ebx,ecx
.end_f:
@ -1049,13 +1083,14 @@ endp
; Render a clipped triangle in line mode
align 4
align 16
proc gl_draw_triangle_line uses eax ebx ecx edx, context:dword, p0:dword,p1:dword,p2:dword
mov edx,[context]
cmp dword[edx+offs_cont_depth_test],0
je .els
lea ecx,[ZB_line_z]
jmp @f
align 4
.els:
lea ecx,[ZB_line]
@@:
@ -1095,7 +1130,7 @@ proc gl_draw_triangle_line uses eax ebx ecx edx, context:dword, p0:dword,p1:dwor
endp
; Render a clipped triangle in point mode
align 4
align 16
proc gl_draw_triangle_point uses eax ebx edx, context:dword, p0:dword,p1:dword,p2:dword
mov edx,[context]
mov eax,[p0]

View File

@ -0,0 +1,38 @@
if not exist bin mkdir bin
if not exist bin\text_1.png @copy text_1.png bin\text_1.png
if not exist bin\toolb_1.png @copy toolb_1.png bin\toolb_1.png
if not exist bin\font8x9.bmp @copy ..\..\..\..\..\fs\kfar\trunk\font8x9.bmp bin\font8x9.bmp
if not exist bin\tinygl.obj @fasm.exe -m 16384 ..\tinygl.asm bin\tinygl.obj
@fasm.exe -m 16384 test0.asm bin\test0.kex
@fasm.exe -m 16384 test1.asm bin\test1.kex
@fasm.exe -m 16384 test2.asm bin\test2.kex
@fasm.exe -m 16384 test3.asm bin\test3.kex
@fasm.exe -m 16384 test_array0.asm bin\test_array0.kex
@fasm.exe -m 16384 test_array1.asm bin\test_array1.kex
@fasm.exe -m 16384 test_glu0.asm bin\test_glu0.kex
@fasm.exe -m 16384 test_glu1.asm bin\test_glu1.kex
@fasm.exe -m 16384 test_glu2.asm bin\test_glu2.kex
@fasm.exe -m 16384 gears.asm bin\gears.kex
@fasm.exe -m 16384 textures0.asm bin\textures0.kex
@kpack bin\test0.kex
@kpack bin\test1.kex
@kpack bin\test2.kex
@kpack bin\test3.kex
@kpack bin\test_array0.kex
@kpack bin\test_array1.kex
@kpack bin\test_glu0.kex
@kpack bin\test_glu1.kex
@kpack bin\test_glu2.kex
@kpack bin\gears.kex
@kpack bin\textures0.kex
pause

View File

@ -39,7 +39,7 @@ end if
add [z],eax
}
align 4
align 16
proc ZB_fillTriangleFlat, zb:dword, p0:dword, p1:dword, p2:dword
locals
if TGL_FEATURE_RENDER_BITS eq 24
@ -94,12 +94,12 @@ end if
add [ob1],eax
}
align 4
align 16
proc ZB_fillTriangleSmooth, zb:dword, p0:dword, p1:dword, p2:dword
locals
include 'ztriangle.inc'
align 4
align 16
proc ZB_setTexture uses eax ebx, zb:dword, texture:dword
mov eax,[zb]
mov ebx,[texture]
@ -120,6 +120,7 @@ macro DRAW_INIT
macro PUT_PIXEL _a
{
local .end_0
local .in_mem
mov eax,[z]
shr eax,ZB_POINT_Z_FRAC_BITS
cmp ax,word[esi+2*_a] ;if (zz >= pz[_a])
@ -131,6 +132,10 @@ if TGL_FEATURE_RENDER_BITS eq 24
and ebx,0x3fc00000
or ebx,[s]
shr ebx,14
cmp ebx,256*256-1 ;проверка на выход за пределы текстуры
jl .in_mem ;координата 1.0,1.0 может выползать
mov ebx,256*256-1 ;переход на последний пиксель текстуры
.in_mem:
imul ebx,3
add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | s) >> 14) * 3
mov ax,word[ebx]
@ -149,7 +154,7 @@ end if
add [t],eax
}
align 4
align 16
proc ZB_fillTriangleMapping, zb:dword, p0:dword, p1:dword, p2:dword
locals
texture dd ? ;PIXEL*
@ -188,6 +193,7 @@ macro DRAW_INIT
macro PUT_PIXEL _a
{
local .end_0
local .in_mem
mov eax,[z]
shr eax,ZB_POINT_Z_FRAC_BITS
cmp ax,word[esi+2*_a] ;if (zz >= pz[_a])
@ -201,6 +207,15 @@ if TGL_FEATURE_RENDER_BITS eq 24
and eax,0x003fc000
or ebx,eax
shr ebx,14
if 1
; не знаю нужна ли сдесь эта проверка
; функция ZB_fillTriangleMapping без нее не работает
; на всякий случай делаю и тут такое же
cmp ebx,256*256-1 ;проверка на выход за пределы текстуры
jl .in_mem ;координата 1.0,1.0 может выползать
mov ebx,256*256-1 ;переход на последний пиксель текстуры
.in_mem:
end if
imul ebx,3
add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | (s & 0x003FC000)) >> 14) * 3
mov ax,word[ebx]
@ -230,10 +245,9 @@ if TGL_FEATURE_RENDER_BITS eq 24
mov edi,[x1]
sub eax,edi
mov [n],eax ;n = (x2 >> 16) - x1
fld1
fld1
fild dword[z1]
fst dword[f_z] ;fz = (float)z1
;fld1
fdivp
fstp dword[zinv] ;zinv = 1.0 / fz
imul edi,PSZB
@ -267,11 +281,10 @@ align 4
fadd dword[dtzdx]
fmul dword[zinv]
fistp dword[dtdx] ;dtdx = (int)( (dtzdx - tt*fdzdx)*zinv )
fld1
fld1
fld dword[f_z]
fadd dword[fndzdx]
fst dword[f_z] ;fz += fndzdx
;fld1
fdivp
fstp dword[zinv] ;zinv = 1.0 / fz
PUT_PIXEL 0
@ -292,6 +305,7 @@ fld1
fadd dword[t_z]
fstp dword[t_z] ;tz += ndtzdx
jmp .cycle_2
align 4
.cycle_2_end:
fld dword[zinv]
fld st0
@ -318,11 +332,12 @@ align 4
add edi,PSZB ;pp += PSZB
dec dword[n]
jmp .cycle_3
align 4
.cycle_3_end:
end if
}
align 4
align 16
proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
locals
texture dd ? ;PIXEL *
@ -386,7 +401,7 @@ local .end_0
fstp dword[t_z]
}
align 4
align 16
proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
locals
texture dd ? ;PIXEL*