From 334d99f48439f25bd0b18759ff65b8623f226102 Mon Sep 17 00:00:00 2001 From: IgorA Date: Mon, 5 Jan 2015 19:13:01 +0000 Subject: [PATCH] some fixes & optimizations git-svn-id: svn://kolibrios.org@5353 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../develop/libraries/TinyGL/asm_fork/api.asm | 24 ++++-- .../libraries/TinyGL/asm_fork/arrays.asm | 22 ++++-- .../libraries/TinyGL/asm_fork/clip.asm | 71 ++++++++--------- .../TinyGL/asm_fork/examples/test_array0.asm | 2 +- .../libraries/TinyGL/asm_fork/matrix.asm | 4 + .../libraries/TinyGL/asm_fork/tinygl.asm | 77 ++++++++----------- .../libraries/TinyGL/asm_fork/vertex.asm | 16 ++-- .../libraries/TinyGL/asm_fork/zmath.asm | 18 +++-- 8 files changed, 128 insertions(+), 106 deletions(-) diff --git a/programs/develop/libraries/TinyGL/asm_fork/api.asm b/programs/develop/libraries/TinyGL/asm_fork/api.asm index 1ea2a46e28..1b94310a6e 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/api.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/api.asm @@ -27,6 +27,13 @@ proc glVertex2f, x:dword, y:dword ret endp +align 4 +proc glVertex2fv uses eax, v:dword + mov eax,[v] + stdcall glVertex4f,[eax],[eax+4],0.0,1.0 + ret +endp + align 4 proc glVertex3f, x:dword, y:dword, z:dword stdcall glVertex4f,[x],[y],[z],1.0 @@ -40,6 +47,13 @@ proc glVertex3fv uses eax, v:dword ret endp +align 4 +proc glVertex4fv uses eax, v:dword + mov eax,[v] + stdcall glVertex4f,[eax],[eax+4],[eax+8],[eax+12] + ret +endp + ; glNormal align 4 @@ -548,7 +562,7 @@ endl ret endp -;/* lightening */ +; lightening align 4 proc glMaterialfv uses eax ecx, mode:dword, type:dword, v:dword @@ -721,7 +735,7 @@ endl ret endp -;/* clear */ +; clear align 4 proc glClear uses eax, mask:dword @@ -775,7 +789,7 @@ endl ret endp -;/* textures */ +; textures align 4 proc glTexImage2D uses ecx edi esi,\ @@ -879,7 +893,7 @@ endl ret endp -;/* selection */ +; selection align 4 proc glInitNames uses eax @@ -954,7 +968,7 @@ endl ret endp -;/* Special Functions */ +; Special Functions align 4 proc glCallList uses eax, list:dword diff --git a/programs/develop/libraries/TinyGL/asm_fork/arrays.asm b/programs/develop/libraries/TinyGL/asm_fork/arrays.asm index 2bf6e7ba35..ddc9da05fb 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/arrays.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/arrays.asm @@ -174,18 +174,23 @@ align 4 add esi,[edx+offs_cont_color_array] ;esi = &context.color_array[i] mov edi,ebp sub edi,28 ;edi = &p[1] - movsd ;p[1].f = context.color_array[i] - movsd - movsd + mov ebx,[esi+8] + mov [edi],ebx ;p[1].f = context.color_array[i+2] + mov ebx,[esi+4] + mov [edi+4],ebx ;p[2].f = context.color_array[i+1] + mov ebx,[esi] + mov [edi+8],ebx ;p[3].f = context.color_array[i] + add edi,12 cmp dword[size],3 jle .e1 + add esi,12 movsd - sub edi,20 ;&p[0] jmp .e2 .e1: mov dword[edi],1.0 ;если задано 3 параметра, то 4-й ставим по умолчанию 1.0 - sub edi,16 ;&p[0] .e2: + mov edi,ebp + sub edi,32 ;edi = &p[0] mov ebx,ebp sub ebx,12 ;ebp-12 = &p[5] push ebx @@ -256,6 +261,7 @@ align 4 .e6: mov dword[edi],0.0 ;если задано 2 параметра, то 3-й ставим по умолчанию 0.0 add edi,4 + jmp .e8 ;и 4-й тоже ставим по умолчанию .e7: cmp dword[size],3 jle .e8 @@ -302,7 +308,7 @@ endp align 4 proc glopDrawElements uses eax ebx edx, context:dword, param:dword locals - p rd 5 + p rd 8 endl mov edx,[context] @@ -318,7 +324,7 @@ endl mov eax,[ebx+4] mov [p+4],eax ;p[1].i = param[1].i mov eax,ebp - sub eax,20 ;=sizeof(dd)*5 + sub eax,32 ;=sizeof(dd)*8 stdcall glopBegin, edx,eax ; for (int ii=0; ii norm @@: mov edi,[context] mov eax,dword[edi+offs_cont_current_front_face] xor dword[front],eax ;front ^= context.current_front_face - ; back face culling cmp dword[edi+offs_cont_cull_face_enabled],0 je .els_1 @@ -765,8 +768,8 @@ pushad ;eax = cc[2] and eax,[cc] and eax,[cc+4] ;eax = c_and = cc[0] & cc[1] & cc[2] - cmp eax,0 ;if (c_and==0) - jne .end_f + or eax,eax ;if (c_and==0) + jnz .end_f stdcall gl_draw_triangle_clip, [context],ebx,ecx,edx,0 .end_f: popad @@ -799,8 +802,8 @@ pushad or edi,eax mov [co],edi ;co = cc[0] | cc[1] | cc[2] - cmp edi,0 ;if (co == 0) - jne .els_0 + or edi,edi ;if (co == 0) + jnz .els_0 stdcall gl_draw_triangle, [context],ebx,ecx,edx jmp .end_f .els_0: @@ -809,8 +812,8 @@ pushad and eax,[cc+4] ;c_and = cc[0] & cc[1] & cc[2] ; the triangle is completely outside - cmp eax,0 ;if (c_and!=0) return - jne .end_f + or eax,eax ;if (c_and!=0) return + jnz .end_f ; find the next direction to clip .cycle_0: ;while (clip_bit < 6 && (co & (1 << clip_bit)) == 0) @@ -821,8 +824,8 @@ pushad mov ecx,[clip_bit] shl eax,cl and eax,[co] - cmp eax,0 - jne .cycle_0_end + or eax,eax + jnz .cycle_0_end inc dword[clip_bit] jmp .cycle_0 .cycle_0_end: @@ -854,13 +857,13 @@ end if mov ecx,[p1] ;востанавливаем после shl ___,cl - cmp eax,0 ;if (co1) - je .els_1 + or eax,eax ;if (co1) + jz .els_1 ; one point outside mov eax,[cc] and eax,[clip_mask] - cmp eax,0 ;if (cc[0] & clip_mask) - je .els_2 + or eax,eax ;if (cc[0] & clip_mask) + jz .els_2 ;q[0]=p0 q[1]=p1 q[2]=p2 mov [q],ebx mov [q+4],ecx @@ -869,8 +872,8 @@ end if .els_2: mov eax,[cc+4] and eax,[clip_mask] - cmp eax,0 ;else if (cc[1] & clip_mask) - je .els_3 + or eax,eax ;else if (cc[1] & clip_mask) + jz .els_3 ;q[0]=p1 q[1]=p2 q[2]=p0 mov [q],ecx mov [q+4],edx @@ -917,7 +920,7 @@ end if stdcall updateTmp,[context],edi,ebx,edx,eax ;updateTmp(c,&tmp2,q[0],q[2],tt) mov eax,[ebx+offs_vert_edge_flag] - mov [tmp1+offs_vert_edge_flag],eax ;q[0].edge_flag + mov [tmp1.edge_flag],eax ;q[0].edge_flag mov eax,[edx+offs_vert_edge_flag] mov [edge_flag_tmp],eax ;q[2].edge_flag mov dword[edx+offs_vert_edge_flag],0 ;q[2].edge_flag=0 @@ -992,11 +995,9 @@ end if sub edi,offs_vert_pc stdcall updateTmp,[context],edi,[q],[q+8],eax - mov edx,[q+8] - - mov dword[tmp1+offs_vert_edge_flag],1 - mov eax,[edx+offs_vert_edge_flag] - mov dword[tmp1+offs_vert_edge_flag],eax ;tmp2.edge_flag = q[2].edge_flag + mov dword[tmp1.edge_flag],1 + mov eax,[edx+offs_vert_edge_flag-offs_vert_pc] + mov dword[tmp2.edge_flag],eax ;tmp2.edge_flag = q[2].edge_flag mov eax,[clip_bit] inc eax push eax diff --git a/programs/develop/libraries/TinyGL/asm_fork/examples/test_array0.asm b/programs/develop/libraries/TinyGL/asm_fork/examples/test_array0.asm index 66d8312c22..1262a6f666 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/examples/test_array0.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/examples/test_array0.asm @@ -192,7 +192,7 @@ err_message_import db 'Error on load import library tinygl.obj',0 ;-------------------------------------------------- i_end: - rb 1024 + rb 4096 stacktop: cur_dir_path: rb 4096 diff --git a/programs/develop/libraries/TinyGL/asm_fork/matrix.asm b/programs/develop/libraries/TinyGL/asm_fork/matrix.asm index 06a0e3fd2e..600ed33130 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/matrix.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/matrix.asm @@ -384,11 +384,13 @@ proc glopScale uses eax ebx ecx, context:dword, p:dword loop @b if DEBUG ;glopScale +pushad stdcall dbg_print,txt_gl_scal,txt_nl mov ebx,[eax+offs_cont_matrix_mode] shl ebx,2 add ebx,eax stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4 +popad end if gl_matrix_update eax,ebx ret @@ -429,11 +431,13 @@ proc glopTranslate uses eax ebx ecx, context:dword, p:dword fincstp if DEBUG ;glopTranslate +pushad stdcall dbg_print,txt_gl_tran,txt_nl mov ebx,[eax+offs_cont_matrix_mode] shl ebx,2 add ebx,eax stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4 +popad end if gl_matrix_update eax,ebx ret diff --git a/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm b/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm index a1f769d529..3bd33d1a84 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm @@ -12,9 +12,9 @@ include 'zmath.asm' include 'clip.asm' include 'vertex.asm' include 'api.asm' -include 'list.asm' +include 'list.asm' ;gl_add_op include 'init.asm' -include 'matrix.asm' +include 'matrix.asm' ;gl_print_matrix include 'texture.asm' include 'misc.asm' include 'clear.asm' @@ -36,42 +36,7 @@ include 'glu.asm' if DEBUG include 'info_fun_float.inc' -end if -; *** -glVertex2d: ;(double ,double) -glVertex2fv: ;(float *) -glVertex2dv: ;(double *) -glVertex3d: ;(double ,double ,double) -glVertex3dv: ;(double *) -glVertex4d: ;(double ,double ,double, double ) -glVertex4fv: ;(float *) -glVertex4dv: ;(double *) -glColor3d: ;(double ,double ,double) -glColor3dv: ;(double *) -glColor4d: ;(double ,double ,double, double ) -glColor4dv: ;(double *) -glNormal3d: ;(double ,double ,double) -glNormal3dv: ;(double *) -glTexCoord1f: ;(float) -glTexCoord1d: ;(double) -glTexCoord1fv: ;(float *) -glTexCoord1dv: ;(double *) -glTexCoord2d: ;(double ,double) -glTexCoord2dv: ;(double *) -glTexCoord3f: ;(float ,float ,float) -glTexCoord3d: ;(double ,double ,double) -glTexCoord3fv: ;(float *) -glTexCoord3dv: ;(double *) -glTexCoord4d: ;(double ,double ,double, double ) -glTexCoord4fv: ;(float *) -glTexCoord4dv: ;(double *) -glGenTextures: ;(int n, unsigned int *textures) -glDeleteTextures: ;(int n, const unsigned int *textures) -glGetIntegerv: ;(int pname,int *params) -glGetFloatv: ;(int pname, float *v) - -if DEBUG align 4 txt_nl db 13,10,0 txt_sp db ' ',0 @@ -140,6 +105,37 @@ align 4 ret ;пока в стеке храниться кол-во вызовов то столько раз мы и будем вызываться end if +; *** +glVertex2d: ;(double ,double) +glVertex2dv: ;(double *) +glVertex3d: ;(double ,double ,double) +glVertex3dv: ;(double *) +glVertex4d: ;(double ,double ,double, double ) +glVertex4dv: ;(double *) +glColor3d: ;(double ,double ,double) +glColor3dv: ;(double *) +glColor4d: ;(double ,double ,double, double ) +glColor4dv: ;(double *) +glNormal3d: ;(double ,double ,double) +glNormal3dv: ;(double *) +glTexCoord1f: ;(float) +glTexCoord1d: ;(double) +glTexCoord1fv: ;(float *) +glTexCoord1dv: ;(double *) +glTexCoord2d: ;(double ,double) +glTexCoord2dv: ;(double *) +glTexCoord3f: ;(float ,float ,float) +glTexCoord3d: ;(double ,double ,double) +glTexCoord3fv: ;(float *) +glTexCoord3dv: ;(double *) +glTexCoord4d: ;(double ,double ,double, double ) +glTexCoord4fv: ;(float *) +glTexCoord4dv: ;(double *) +glGenTextures: ;(int n, unsigned int *textures) +glDeleteTextures: ;(int n, const unsigned int *textures) +glGetIntegerv: ;(int pname,int *params) +glGetFloatv: ;(int pname, float *v) + align 4 f_kosgl_1 db 'kosglMakeCurrent',0 err_0 db 'Error while initializing Z buffer',13,10,0 @@ -151,20 +147,13 @@ f_vp db ' glViewport',0 err_4 db 'error while resizing display',13,10,0 err_5 db 'size too small',13,10,0 f_clipcode db ' gl_clipcode',0 -f_ttv db ' gl_transform_to_viewport',0 -f_vt db ' gl_vertex_transform',0 -f_ev db ' gl_eval_viewport',0 f_zbz db ' ZB_line_z',0 f_zb db ' ZB_line',0 -f_m4m db 'gl_M4_Mul',0 -f_m4ml db 'gl_M4_MulLeft',0 f_find_l db 'find_list',0 f_alloc_l db 'alloc_list',0 f_is_l db 'glIsList',0 f_gen_l db 'glGenLists',0 f_end_l db 'glEndList',0 -;f_fill_trf db 'ZB_fillTriangleFlat',0 -;f_fill_trrgb db 'ZB_fillTriangleSmooth',0 f_fill_tr db 'ZB_fillTriangle...',0 f_fill_tr_nl db ' lines',0 f_fill_tr_nll db ' len',0 diff --git a/programs/develop/libraries/TinyGL/asm_fork/vertex.asm b/programs/develop/libraries/TinyGL/asm_fork/vertex.asm index 25aea3a32c..07f54168a6 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/vertex.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/vertex.asm @@ -1,3 +1,6 @@ +if DEBUG +f_vt db ' gl_vertex_transform',0 +end if align 4 proc glopNormal uses ecx esi edi, context:dword, p:dword @@ -117,7 +120,7 @@ proc glopBegin uses eax ebx ecx edx, context:dword, p:dword locals tmp M4 endl -; assert(c->in_begin == 0); +;assert(context.in_begin == 0) mov edx,[context] mov ebx,[p] @@ -137,7 +140,7 @@ if DEBUG ;context.matrix_stack_ptr[0] end if ; precompute inverse modelview mov ebx,ebp - sub ebx,64 + sub ebx,sizeof.M4 stdcall gl_M4_Inv, ebx,dword[edx+offs_cont_matrix_stack_ptr] if DEBUG ;tmp stdcall dbg_print,txt_sp,txt_nl @@ -165,18 +168,21 @@ end if fcomp st1 fstsw ax sahf - jne .end_if_0 + jne @f fld dword[ecx+13*4] fcomp st1 fstsw ax sahf - jne .end_if_0 + jne @f fld dword[ecx+14*4] fcomp st1 fstsw ax sahf - jne .end_if_0 + jne @f mov dword[edx+offs_cont_matrix_model_projection_no_w_transform],1 + @@: + ffree st0 ;0.0 + fincstp .end_if_0: ; test if the texture matrix is not Identity diff --git a/programs/develop/libraries/TinyGL/asm_fork/zmath.asm b/programs/develop/libraries/TinyGL/asm_fork/zmath.asm index a681cb28f1..612ac16297 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/zmath.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/zmath.asm @@ -3,6 +3,11 @@ ; ******* Gestion des matrices 4x4 ****** +if DEBUG +f_m4m db 'gl_M4_Mul',0 +f_m4ml db 'gl_M4_MulLeft',0 +end if + align 4 proc gl_M4_Id uses eax ecx edi, a:dword mov edi,[a] @@ -115,23 +120,21 @@ pushad mov edx,[c] mov dword[i],0 + mov eax,ebp + sub eax,sizeof.M4 .cycle_0: ;i - xor ebx,ebx + xor ebx,ebx ;j=0 .cycle_1: ;j - finit fldz ;sum=0 - xor ecx,ecx - mov eax,ebp - sub eax,sizeof.M4 + xor ecx,ecx ;k=0 M4_reg edi,eax,dword[i],0 .cycle_2: ;k fld dword[edi] add edi,4 M4_reg esi,[b],ecx,ebx fmul dword[esi] - fadd st0,st1 ;sum += a[i][k] * b[k][j] + faddp ;sum += a[i][k] * b[k][j] inc ecx - add eax,4 cmp ecx,4 jl .cycle_2 fstp dword[edx] ;c[i][j] = sum @@ -142,7 +145,6 @@ pushad inc dword[i] cmp dword[i],4 jl .cycle_0 - finit if DEBUG ;gl_M4_MulLeft stdcall dbg_print,f_m4ml,txt_nl stdcall gl_print_matrix,[c],4