diff --git a/programs/develop/libraries/TinyGL/asm_fork/clip.asm b/programs/develop/libraries/TinyGL/asm_fork/clip.asm index 0931023187..9107fbc748 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/clip.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/clip.asm @@ -10,9 +10,6 @@ CLIP_ZMAX equ (1<<5) align 16 proc gl_transform_to_viewport uses eax ebx ecx, context:dword,v:dword -locals - point dd ? -endl mov eax,[context] mov ebx,[v] @@ -64,17 +61,19 @@ align 4 ; texture cmp dword[eax+offs_cont_texture_2d_enabled],0 je @f - mov dword[point],dword(ZB_POINT_S_MAX - ZB_POINT_S_MIN) - fild dword[point] - fmul dword[ebx+offs_vert_tex_coord] ;st0 *= v.tex_coord.X - fistp dword[ebx+offs_vert_zp+offs_zbup_s] - add dword[ebx+offs_vert_zp+offs_zbup_s],ZB_POINT_S_MIN + mov eax,[eax+offs_cont_current_texture] ;eax = &context.current_texture + mov eax,[eax] ;eax = context.current_texture + ;[eax+offs_text_images] = im = &context.current_texture.images[0] - mov dword[point],dword(ZB_POINT_T_MAX - ZB_POINT_T_MIN) - fild dword[point] - fmul dword[ebx+offs_vert_tex_coord+offs_Y] ;st0 *= v.tex_coord.Y + fild dword[eax+offs_text_images+offs_imag_s_bound] + fmul dword[ebx+offs_vert_tex_coord+offs_X] + fistp dword[ebx+offs_vert_zp+offs_zbup_s] + ;v.zp.s=(int)(v.tex_coord.X * im.s_bound) + + fild dword[eax+offs_text_images+offs_imag_t_bound] + fmul dword[ebx+offs_vert_tex_coord+offs_Y] fistp dword[ebx+offs_vert_zp+offs_zbup_t] - add dword[ebx+offs_vert_zp+offs_zbup_t],ZB_POINT_T_MIN + ;v.zp.t=(int)(v.tex_coord.Y * im.t_bound) @@: ret endp @@ -1042,10 +1041,11 @@ end if if PROFILE eq 1 inc dword[count_triangles_textured] end if - mov eax,dword[edx+offs_cont_current_texture] + mov eax,[edx+offs_cont_current_texture] mov eax,[eax] ;переход по указателю ;так как offs_text_images+offs_imag_pixmap = 0 то context.current_texture.images[0].pixmap = [eax] - stdcall ZB_setTexture, dword[edx+offs_cont_zb],dword[eax] + stdcall ZB_setTexture, [edx+offs_cont_zb], [eax],\ + [eax+offs_imag_s_bound],[eax+offs_imag_t_bound],[eax+offs_imag_xsize_log2] mov eax,[p0] add eax,offs_vert_zp push ecx diff --git a/programs/develop/libraries/TinyGL/asm_fork/image_util.asm b/programs/develop/libraries/TinyGL/asm_fork/image_util.asm index 0eaf1e4b6d..bfb66d3617 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/image_util.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/image_util.asm @@ -243,4 +243,21 @@ align 4 jnz .cycyle_0 popad ret +endp + +align 4 +proc gl_getPervPowerOfTwo uses ebx, n:dword + mov ebx,[n] + mov eax,(1 shl ZB_POINT_TEXEL_SIZE) ;max size + cmp ebx,eax + jge .set + @@: + shr eax,1 + cmp ebx,eax + jl @b + cmp eax,8 ;min size + jge .set + mov eax,8 + .set: + ret endp \ No newline at end of file diff --git a/programs/develop/libraries/TinyGL/asm_fork/light.asm b/programs/develop/libraries/TinyGL/asm_fork/light.asm index 189209a14e..75bc3d3487 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/light.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/light.asm @@ -32,24 +32,28 @@ proc glopMaterial uses eax ebx ecx edi esi, context:dword, p:dword ;add edi,offs_mate_emission ;offs_mate_emission=0 rep movsd jmp .end_f +align 4 @@: cmp ebx,GL_AMBIENT jne @f add edi,offs_mate_ambient rep movsd jmp .end_f +align 4 @@: cmp ebx,GL_DIFFUSE jne @f add edi,offs_mate_diffuse rep movsd jmp .end_f +align 4 @@: cmp ebx,GL_SPECULAR jne @f add edi,offs_mate_specular rep movsd jmp .end_f +align 4 @@: cmp ebx,GL_SHININESS jne @f @@ -61,6 +65,7 @@ proc glopMaterial uses eax ebx ecx edi esi, context:dword, p:dword fimul dword[edi] fistp dword[edi] ;m.shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION jmp .end_f +align 4 @@: cmp ebx,GL_AMBIENT_AND_DIFFUSE jne @f @@ -71,6 +76,7 @@ proc glopMaterial uses eax ebx ecx edi esi, context:dword, p:dword mov ecx,4 rep movsd jmp .end_f +align 4 @@: ;default ; assert(0); .end_f: @@ -115,6 +121,7 @@ pushad mov ecx,4 rep movsd ;l.ambient=v jmp .end_f +align 4 @@: cmp ecx,GL_DIFFUSE jne @f @@ -125,6 +132,7 @@ pushad mov ecx,4 rep movsd ;l.diffuse=v jmp .end_f +align 4 @@: cmp ecx,GL_SPECULAR jne @f @@ -135,6 +143,7 @@ pushad mov ecx,4 rep movsd ;l.specular=v jmp .end_f +align 4 @@: cmp ecx,GL_POSITION jne @f @@ -168,6 +177,7 @@ pushad ffree st0 fincstp jmp .end_f +align 4 @@: cmp ecx,GL_SPOT_DIRECTION jne @f @@ -188,12 +198,14 @@ pushad add edx,offs_ligh_norm_spot_direction stdcall gl_V3_Norm,edx jmp .end_f +align 4 @@: cmp ecx,GL_SPOT_EXPONENT jne @f mov ecx,[ebx+12] mov [edi+offs_ligh_spot_exponent],ecx ;l.spot_exponent=p[3] jmp .end_f +align 4 @@: cmp ecx,GL_SPOT_CUTOFF jne .end_spot_c @@ -214,24 +226,28 @@ pushad ffree st0 fincstp jmp .end_f +align 4 .end_spot_c: cmp ecx,GL_CONSTANT_ATTENUATION jne @f mov ecx,[ebx+12] mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3] jmp .end_f +align 4 @@: cmp ecx,GL_LINEAR_ATTENUATION jne @f mov ecx,[ebx+12] mov [edi+offs_ligh_attenuation+4],ecx ;l->attenuation[1]=p[3] jmp .end_f +align 4 @@: cmp ecx,GL_QUADRATIC_ATTENUATION jne @f mov ecx,[ebx+12] mov [edi+offs_ligh_attenuation+8],ecx ;l->attenuation[2]=p[3] jmp .end_f +align 4 @@: ;default: ; assert(0); .end_f: @@ -254,18 +270,21 @@ proc glopLightModel uses ebx ecx esi edi, context:dword, p:dword add edi,offs_cont_ambient_light_model rep movsd ;for(i=0;i<4;i++) context.ambient_light_model.v[i]=v[i] jmp .end_f +align 4 @@: cmp ebx,GL_LIGHT_MODEL_LOCAL_VIEWER jne @f fld dword[esi] ;st0 = p[2] fistp dword[edi+offs_cont_local_light_model] jmp .end_f +align 4 @@: cmp ebx,GL_LIGHT_MODEL_TWO_SIDE jne @f fld dword[esi] ;st0 = p[2] fistp dword[edi+offs_cont_light_model_two_side] jmp .end_f +align 4 @@: ;default: ; tgl_warning("glopLightModel: illegal pname: 0x%x\n", ebx); ; //assert(0); @@ -287,6 +306,7 @@ local .end_m fincstp mov eax,0.0 jmp .end_m ;return 0.0 +align 4 .o_1: fld1 ;else if (a>=1.0) fcompp @@ -295,6 +315,7 @@ local .end_m ja .o_2 mov eax,1.0 jmp .end_m ;return 1.0 +align 4 .o_2: mov eax,dword a ;else return a .end_m: @@ -323,6 +344,7 @@ proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dwo mov [eax+offs_cont_first_light],ebx ;context.first_light = l mov dword[ebx+offs_ligh_prev],0 ;l.prev = NULL jmp .end_f +align 4 @@: xor ecx,ecx cmp dword[v],0 @@ -339,6 +361,7 @@ proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dwo jne .els_0 mov [eax+offs_cont_first_light],ecx ;context.first_light = l.next jmp @f +align 4 .els_0: mov eax,[ebx+offs_ligh_prev] mov [eax+offs_ligh_next],ecx ;l.prev.next = l.next @@ -356,7 +379,7 @@ align 4 fl_1e_3 dd 1.0e-3 ; non optimized lightening model -align 4 +align 16 proc gl_shade_vertex, context:dword, v:dword locals R dd ? ;float ebp-96 @@ -452,6 +475,7 @@ pushad mov [d+offs_Z],eax ;d.Z=l.norm_position.v[2] mov dword[att],1.0 jmp .els_0_end +align 4 .els_0: ; distance attenuation ffree st0 ;l.position.v[3] @@ -577,6 +601,7 @@ pushad fincstp mov ebx,[ebx+offs_ligh_next] jmp .cycle_0 ;continue +align 4 .els_1: ; TODO: optimize fld dword[ebx+offs_ligh_spot_exponent] @@ -602,6 +627,7 @@ pushad fmul dword[att] fstp dword[att] ;att=att*pow(dot_spot,l.spot_exponent) jmp .if1_end_f1 +align 4 @@: ffree st0 ;l.spot_exponent fincstp @@ -632,6 +658,7 @@ pushad fsub dword[vcoord+offs_Z] fstp dword[s+offs_Z] ;s.Z=d.Z-vcoord.Z jmp .els_2_end +align 4 .els_2: mov eax,[d] mov [s],eax ;s.X=d.X @@ -734,6 +761,7 @@ pushad fincstp mov ebx,[ebx+offs_ligh_next] jmp .cycle_0 +align 4 .cycle_0_end: clampf [R],0,1 diff --git a/programs/develop/libraries/TinyGL/asm_fork/texture.asm b/programs/develop/libraries/TinyGL/asm_fork/texture.asm index fbb93599f6..d06484370e 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/texture.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/texture.asm @@ -209,6 +209,8 @@ proc glopTexImage2D, context:dword, p:dword locals pixels1 dd ? do_free dd ? + aligned_width dd ? + aligned_height dd ? endl pushad mov edi,[p] @@ -236,22 +238,30 @@ pushad stdcall dbg_print,sz_glTexImage2D,err_8 ;"glTexImage2D: combinaison of parameters not handled" @@: + stdcall gl_getPervPowerOfTwo,edx + mov [aligned_width],eax + stdcall gl_getPervPowerOfTwo,esi + mov [aligned_height],eax + mov dword[do_free],0 - cmp edx,256 + cmp edx,[aligned_width] jne .else - cmp esi,256 + cmp esi,[aligned_height] jne .else mov eax,[edi+36] mov [pixels1],eax ;pixels1=pixels jmp @f - .else: ;if (width != 256 || height != 256) - stdcall gl_malloc, 256*256*3 - mov [pixels1],eax ;pixels1 = gl_malloc(256 * 256 * 3) +align 4 + .else: ;if (width != aligned_width || height != aligned_height) + imul eax,[aligned_width] + imul eax,3 + stdcall gl_malloc, eax + mov [pixels1],eax ;pixels1 = gl_malloc(aligned_width * aligned_height * 3) ; no interpolation is done here to respect the original image aliasing ! - stdcall gl_resizeImage, eax,256,256,[edi+36],edx,esi + stdcall gl_resizeImage, eax,[aligned_width],[aligned_height],[edi+36],edx,esi mov dword[do_free],1 - mov edx,256 - mov esi,256 + mov edx,[aligned_width] + mov esi,[aligned_height] @@: mov ecx,[context] @@ -259,8 +269,29 @@ pushad add ecx,offs_text_images imul ebx,sizeof.GLTexture add ecx,ebx ;ecx = &context.current_texture.images[level] - mov dword[ecx+offs_imag_xsize],edx ;im.xsize=width - mov dword[ecx+offs_imag_ysize],esi ;im.ysize=height + mov [ecx+offs_imag_xsize],edx ;im.xsize=width + mov [ecx+offs_imag_ysize],esi ;im.ysize=height + mov ebx,edx + dec ebx + shl ebx,ZB_POINT_TEXEL_SIZE + mov [ecx+offs_imag_s_bound],ebx ;im.s_bound = (unsigned int)(width-1) + shr ebx,ZB_POINT_TEXEL_SIZE + + mov dword[ecx+offs_imag_xsize_log2],ZB_POINT_TEXEL_SIZE + or ebx,ebx + jz .set_l2 + @@: + dec dword[ecx+offs_imag_xsize_log2] + shr ebx,1 + or ebx,ebx + jnz @b + .set_l2: + ;im.xsize_log2 = ZB_POINT_TEXEL_SIZE-log_2(width) + dec esi + shl esi,ZB_POINT_TEXEL_SIZE + mov [ecx+offs_imag_t_bound],esi ;im.t_bound = (unsigned int)(height-1) + shr esi,ZB_POINT_TEXEL_SIZE + inc esi cmp dword[ecx+offs_imag_pixmap],0 ;if (im.pixmap!=NULL) je @f stdcall gl_free, [ecx+offs_imag_pixmap] diff --git a/programs/develop/libraries/TinyGL/asm_fork/zbuffer.inc b/programs/develop/libraries/TinyGL/asm_fork/zbuffer.inc index f72e987f7b..5deb3ee361 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/zbuffer.inc +++ b/programs/develop/libraries/TinyGL/asm_fork/zbuffer.inc @@ -8,10 +8,8 @@ ZB_Z_BITS equ 16 ZB_POINT_Z_FRAC_BITS equ 14 -ZB_POINT_S_MIN equ (1 shl 13) -ZB_POINT_S_MAX equ ( (1 shl 22)-(1 shl 13) ) -ZB_POINT_T_MIN equ (1 shl 21) -ZB_POINT_T_MAX equ ( (1 shl 30)-(1 shl 21) ) +ZB_POINT_TEXEL_SIZE equ 12 ;точность множителя для вычисления координат текселя + ;влияет на максимальный размер текстуры ZB_POINT_RED_MIN equ (1 shl 8) ZB_POINT_RED_MAX equ ( (1 shl 16)-1 ) @@ -27,26 +25,7 @@ ZB_MODE_RGBA equ 3 ; 32 bit rgba mode ZB_MODE_RGB24 equ 4 ; 24 bit rgb mode ZB_NB_COLORS equ 225 ; number of colors for 8 bit display -if TGL_FEATURE_RENDER_BITS eq 15 - -;#define RGB_TO_PIXEL(r,g,b) \ -; ((((r) >> 1) & 0x7c00) | (((g) >> 6) & 0x03e0) | ((b) >> 11)) -;typedef unsigned short PIXEL; -; bytes per pixel -;PSZB equ 2 -; bits per pixel = (1 << PSZH) -;PSZSH equ 4 - -else if TGL_FEATURE_RENDER_BITS eq 16 - -; 16 bit mode -;#define RGB_TO_PIXEL(r,g,b) \ -; (((r) & 0xF800) | (((g) >> 5) & 0x07E0) | ((b) >> 11)) -;typedef unsigned short PIXEL; -;PSZB equ 2 -;PSZSH equ 4 - -else if TGL_FEATURE_RENDER_BITS eq 24 +if TGL_FEATURE_RENDER_BITS eq 24 macro RGB_TO_PIXEL r,g,b { @@ -94,6 +73,9 @@ struct ZBuffer dctable dd ? ;*unsigned char ctable dd ? ;*int current_texture dd ? ;*PIXEL + s_log2 dd ? ;unsigned int + s_bound dd ? ;unsigned int + t_bound dd ? ;unsigned int ends offs_zbuf_xsize equ 0 @@ -107,6 +89,9 @@ offs_zbuf_nb_colors equ 32 offs_zbuf_dctable equ 36 offs_zbuf_ctable equ 40 offs_zbuf_current_texture equ 44 +offs_zbuf_s_log2 equ 48 +offs_zbuf_s_bound equ 52 +offs_zbuf_t_bound equ 56 struct ZBufferPoint x dd ? ;int ;integer coordinates in the zbuffer diff --git a/programs/develop/libraries/TinyGL/asm_fork/zgl.inc b/programs/develop/libraries/TinyGL/asm_fork/zgl.inc index afcb592989..fd84da677c 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/zgl.inc +++ b/programs/develop/libraries/TinyGL/asm_fork/zgl.inc @@ -169,11 +169,17 @@ struct GLImage pixmap dd ? ;void* xsize dd ? ;int ysize dd ? ;int + xsize_log2 dd ? ;unsigned int + s_bound dd ? ;unsigned int + t_bound dd ? ;unsigned int ends offs_imag_pixmap equ 0 offs_imag_xsize equ 4 offs_imag_ysize equ 8 +offs_imag_xsize_log2 equ 12 +offs_imag_s_bound equ 16 +offs_imag_t_bound equ 20 ; textures diff --git a/programs/develop/libraries/TinyGL/asm_fork/ztriangle.asm b/programs/develop/libraries/TinyGL/asm_fork/ztriangle.asm index 21bf073803..5a3d2b9880 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/ztriangle.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/ztriangle.asm @@ -133,10 +133,17 @@ locals include 'ztriangle.inc' align 16 -proc ZB_setTexture uses eax ebx, zb:dword, texture:dword +proc ZB_setTexture uses eax ebx, zb:dword, texture:dword,\ + s_bound:dword, t_bound:dword, s_log2:dword mov eax,[zb] mov ebx,[texture] mov dword[eax+offs_zbuf_current_texture],ebx + mov ebx,[s_log2] + mov dword[eax+offs_zbuf_s_log2],ebx + mov ebx,[s_bound] + mov dword[eax+offs_zbuf_s_bound],ebx + mov ebx,[t_bound] + mov dword[eax+offs_zbuf_t_bound],ebx ret endp @@ -146,8 +153,14 @@ INTERP_ST equ 1 macro DRAW_INIT { mov eax,[zb] - mov eax,[eax+offs_zbuf_current_texture] - mov [texture],eax + mov ebx,[eax+offs_zbuf_current_texture] + mov [texture],ebx + mov ebx,[eax+offs_zbuf_s_log2] + mov [s_log2],ebx ;s_log2 = zb.s_log2 + mov ebx,[eax+offs_zbuf_s_bound] + mov [s_bound],ebx ;s_bound = zb.s_bound + mov ebx,[eax+offs_zbuf_t_bound] + mov [t_bound],ebx ;t_bound = zb.t_bound } macro PUT_PIXEL _a @@ -161,11 +174,13 @@ local .end_0 mov word[esi+2*_a],ax ;пишем в буфер глубины новое значение if TGL_FEATURE_RENDER_BITS eq 24 mov ebx,[t] - and ebx,0x3fc00000 + and ebx,[t_bound] + mov ecx,[s_log2] + shr ebx,cl ;(t & t_bound) >> s_log2 mov eax,[s] - and eax,0x003fc000 + and eax,[s_bound] + shr eax,ZB_POINT_TEXEL_SIZE or ebx,eax - shr ebx,14 imul ebx,3 add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | s) >> 14) * 3 mov ax,word[ebx] @@ -188,6 +203,9 @@ align 16 proc ZB_fillTriangleMapping, zb:dword, p0:dword, p1:dword, p2:dword locals texture dd ? ;PIXEL* + s_log2 dd ? ;unsigned int + s_bound dd ? ;unsigned int + t_bound dd ? ;unsigned int include 'ztriangle.inc' ; @@ -195,7 +213,6 @@ include 'ztriangle.inc' ; We use the gradient method to make less divisions. ; TODO: pipeline the division ; -if 1 INTERP_Z equ 1 INTERP_STZ equ 1 @@ -205,8 +222,14 @@ NB_INTERP equ 8 macro DRAW_INIT { mov eax,[zb] - mov eax,[eax+offs_zbuf_current_texture] - mov [texture],eax + mov ebx,[eax+offs_zbuf_current_texture] + mov [texture],ebx + mov ebx,[eax+offs_zbuf_s_log2] + mov [s_log2],ebx ;s_log2 = zb.s_log2 + mov ebx,[eax+offs_zbuf_s_bound] + mov [s_bound],ebx ;s_bound = zb.s_bound + mov ebx,[eax+offs_zbuf_t_bound] + mov [t_bound],ebx ;t_bound = zb.t_bound mov dword[esp-4],NB_INTERP fild dword[esp-4] fild dword[dzdx] @@ -231,11 +254,13 @@ local .end_0 mov word[esi+2*_a],ax ;пишем в буфер глубины новое значение if TGL_FEATURE_RENDER_BITS eq 24 mov ebx,[t] - and ebx,0x3fc00000 + and ebx,[t_bound] + mov ecx,[s_log2] + shr ebx,cl ;(t & t_bound) >> s_log2 mov eax,[s] - and eax,0x003fc000 + and eax,[s_bound] + shr eax,ZB_POINT_TEXEL_SIZE or ebx,eax - shr ebx,14 imul ebx,3 add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | (s & 0x003FC000)) >> 14) * 3 mov ax,word[ebx] @@ -367,64 +392,7 @@ locals ndtzdx dd ? ;float zinv dd ? ;float f_z dd ? ;float - переменная отвечающая за геометрию текстуры + s_log2 dd ? ;unsigned int + s_bound dd ? ;unsigned int + t_bound dd ? ;unsigned int include 'ztriangle.inc' - -end if - -if 0 - -; slow but exact version (only there for reference, incorrect for 24 -; bits) - -INTERP_Z equ 1 -INTERP_STZ equ 1 - -macro DRAW_INIT -{ - mov eax,[zb] - mov eax,[eax+offs_zbuf_current_texture] - mov [texture],eax -} - -macro PUT_PIXEL _a -{ -local .end_0 - mov eax,[z] - shr eax,ZB_POINT_Z_FRAC_BITS - cmp ax,word[esi+2*_a] ;if (zz >= pz[_a]) - jl .end_0 - ;edi = pp - mov word[esi+2*_a],ax ;пишем в буфер глубины новое значение - fild dword[z] - fld dword[s_z] - fdiv st0,st1 - fistp dword[esp-4] ;s = (int) (s_z / (float) z) - fld dword[t_z] - fdiv st0,st1 - fistp dword[esp-8] ;t = (int) (t_z / (float) z) - mov eax,dword[esp-8] - and eax,0x3FC00000 - or eax,dword[esp-4] - shr eax,12 ;14 - add eax,[texture] - mov eax,[eax] - stosd ;pp[_a] = texture[((t & 0x3FC00000) | s) >> 14] - sub edi,4 - .end_0: - mov eax,[dzdx] - add [z],eax - fld dword[dszdx] - fadd dword[s_z] - fstp dword[s_z] - fld dword,[dtzdx] - fadd dword[t_z] - fstp dword[t_z] -} - -align 16 -proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword -locals - texture dd ? ;PIXEL* -include 'ztriangle.inc' - -end if