From ea910a143ce3a3809a8dc91cf10d51753e079134 Mon Sep 17 00:00:00 2001 From: IgorA Date: Fri, 5 Dec 2014 21:12:56 +0000 Subject: [PATCH] 1) fix and optimizations 2) add quadric object 'Sphere' git-svn-id: svn://kolibrios.org@5218 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../libraries/TinyGL/asm_fork/clip.asm | 41 +- .../TinyGL/asm_fork/examples/test_glu0.asm | 202 ++++++++ .../libraries/TinyGL/asm_fork/export.inc | 8 + .../develop/libraries/TinyGL/asm_fork/glu.asm | 452 ++++++++++++++++++ .../libraries/TinyGL/asm_fork/light.asm | 146 ++++-- .../libraries/TinyGL/asm_fork/tinygl.asm | 5 +- .../libraries/TinyGL/asm_fork/vertex.asm | 104 ++-- .../libraries/TinyGL/asm_fork/zbuffer.inc | 16 +- .../libraries/TinyGL/asm_fork/zmath.asm | 56 ++- 9 files changed, 901 insertions(+), 129 deletions(-) create mode 100644 programs/develop/libraries/TinyGL/asm_fork/examples/test_glu0.asm create mode 100644 programs/develop/libraries/TinyGL/asm_fork/glu.asm diff --git a/programs/develop/libraries/TinyGL/asm_fork/clip.asm b/programs/develop/libraries/TinyGL/asm_fork/clip.asm index 988b4f93f8..5839a23041 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/clip.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/clip.asm @@ -252,13 +252,13 @@ proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword fcom dword[ebx] fstsw ax sahf - ja .r0 ;if (t>*tmax) return 0 + ja .r0_f2 ;if (t>*tmax) return 0 mov ebx,[tmin] fcom dword[ebx] fstsw ax sahf - jbe .r1 + jbe .r1_f2 fstp dword[ebx] ;if (t>*tmin) *tmin=t jmp .r1 @@ -270,40 +270,36 @@ proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword fcom dword[ebx] fstsw ax sahf - jb .r0 ;if (t<*tmin) return 0 + jb .r0_f2 ;if (t<*tmin) return 0 mov ebx,[tmax] fcom dword[ebx] fstsw ax sahf - jae .r1 + jae .r1_f2 fstp dword[ebx] ;if (t<*tmin) *tmax=t jmp .r1 - .r0: ;return 0 + .r0_f2: ;return 0 & free st0,st1 + ffree st0 + fincstp + .r0: ;return 0 & free st0 xor eax,eax jmp .end_f - .r1: ;return 1 + .r1_f2: ;return 1 & free st0,st1 + ffree st0 + fincstp + .r1: ;return 1 & free st0 xor eax,eax inc eax .end_f: -if DEBUG ;ClipLine1 -push edi - mov ecx,80 - lea edi,[buf_param] - stdcall convert_int_to_str,ecx - - stdcall str_n_cat,edi,txt_nl,2 - stdcall dbg_print,f_cl1,buf_param -pop edi -end if - ffree st0 ;профилактика для очистки стека - fincstp ;как минимум одно значение в стеке уже есть + ffree st0 + fincstp ret endp align 4 -proc gl_draw_line uses eax ebx edx edi esi, context:dword, p1:dword, p2:dword +proc gl_draw_line, context:dword, p1:dword, p2:dword locals d_x dd ? d_y dd ? @@ -318,7 +314,7 @@ locals tmin dd ? ;ebp-8 tmax dd ? ;ebp-4 endl - +pushad mov edx,[context] mov edi,[p1] mov esi,[p2] @@ -355,7 +351,6 @@ endl jne .end_f .els_0: - finit fld dword[esi+offs_vert_pc+offs_X] fsub dword[edi+offs_vert_pc+offs_X] fstp dword[d_x] ;d_x = p2.pc.X - p1.pc.X @@ -500,6 +495,7 @@ endl .els_3: call ZB_line ;(context.zb,&q1.zp,&q2.zp) .end_f: +popad ret endp @@ -544,8 +540,7 @@ else fsub dword[d#dir] end if - fldz - fcomp + ftst fstsw ax sahf jne @f diff --git a/programs/develop/libraries/TinyGL/asm_fork/examples/test_glu0.asm b/programs/develop/libraries/TinyGL/asm_fork/examples/test_glu0.asm new file mode 100644 index 0000000000..58354e8572 --- /dev/null +++ b/programs/develop/libraries/TinyGL/asm_fork/examples/test_glu0.asm @@ -0,0 +1,202 @@ +use32 + org 0x0 + db 'MENUET01' + dd 0x1 + dd start + dd i_end + dd mem,stacktop + dd 0,cur_dir_path + +include '../../../../../../programs/proc32.inc' +include '../../../../../../programs/macros.inc' +include '../../../../../../programs/develop/libraries/box_lib/load_lib.mac' +include '../../../../../../programs/dll.inc' +include '../opengl_const.inc' + +@use_library + +align 4 +start: + load_library name_tgl, cur_dir_path, library_path, system_path, \ + err_message_found_lib, head_f_l, import_lib_tinygl, err_message_import, head_f_i + cmp eax,-1 + jz button.exit + + mcall 40,0x27 + +stdcall [kosglMakeCurrent], 10,10,300,225,ctx1 +stdcall [glEnable], GL_DEPTH_TEST +stdcall [gluNewQuadric] +mov [qObj],eax + +stdcall [glClearColor], 0.5,0.5,0.5,0.0 + +call draw_3d + +align 4 +red_win: + call draw_window + +align 4 +still: + mcall 10 + cmp al,1 + jz red_win + cmp al,2 + jz key + cmp al,3 + jz button + jmp still + +align 4 +draw_window: + pushad + mcall 12,1 + + mov edx,0x33ffffff ;0x73ffffff + mcall 0,(50 shl 16)+330,(30 shl 16)+275,,,caption + stdcall [kosglSwapBuffers] + + mcall 12,2 + popad + ret + +align 4 +key: + mcall 2 + + cmp ah,27 ;Esc + je button.exit + + cmp ah,61 ;+ + jne @f + fld dword[scale] + fadd dword[delt_sc] + fstp dword[scale] + call draw_3d + stdcall [kosglSwapBuffers] + @@: + cmp ah,45 ;- + jne @f + fld dword[scale] + fsub dword[delt_sc] + fstp dword[scale] + call draw_3d + stdcall [kosglSwapBuffers] + @@: + cmp ah,178 ;Up + jne @f + fld dword[angle_y] + fadd dword[delt_size] + fstp dword[angle_y] + call draw_3d + stdcall [kosglSwapBuffers] + @@: + cmp ah,177 ;Down + jne @f + fld dword[angle_y] + fsub dword[delt_size] + fstp dword[angle_y] + call draw_3d + stdcall [kosglSwapBuffers] + @@: + cmp ah,176 ;Left + jne @f + fld dword[angle_z] + fadd dword[delt_size] + fstp dword[angle_z] + call draw_3d + stdcall [kosglSwapBuffers] + @@: + cmp ah,179 ;Right + jne @f + fld dword[angle_z] + fsub dword[delt_size] + fstp dword[angle_z] + call draw_3d + stdcall [kosglSwapBuffers] + @@: + + jmp still + +align 4 +button: + mcall 17 + cmp ah,1 + jne still +.exit: + stdcall [gluDeleteQuadric], [qObj] + mcall -1 + + +align 4 +caption db 'Test gluSphere, [Esc] - exit, [<-],[->],[Up],[Down] - rotate',0 +align 4 +ctx1 db 28 dup (0) ;TinyGLContext or KOSGLContext +;sizeof.TinyGLContext = 28 + +align 4 +draw_3d: +stdcall [glClear], GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT ;очистим буфер цвета и глубины + +stdcall [glColor3f], 1.0, 1.0, 0.0 + +stdcall [glPushMatrix] + stdcall [glTranslatef], 0.0,0.0,0.5 + stdcall [glScalef], [scale], [scale], [scale] + + stdcall [glRotatef], [angle_z],0.0,0.0,1.0 + stdcall [glRotatef], [angle_y],0.0,1.0,0.0 + stdcall [gluSphere], [qObj], 1.0, 16,16 + + stdcall [glColor3f], 1.0, 0.0, 0.0 + stdcall [glTranslatef], -1.6,0.0,0.0 + stdcall [gluSphere], [qObj], 0.55, 8,8 + + stdcall [glColor3f], 0.0, 0.0, 1.0 + stdcall [glTranslatef], 3.2,0.0,0.0 + stdcall [gluSphere], [qObj], 0.55, 8,8 +stdcall [glPopMatrix] +ret + +qObj dd 0 + +scale dd 0.4 +delt_sc dd 0.05 +angle_z dd 0.0 +angle_y dd 0.0 +delt_size dd 3.0 + +;-------------------------------------------------- +align 4 +import_lib_tinygl: + +macro E_LIB n +{ + n dd sz_#n +} +include '../export.inc' + dd 0,0 +macro E_LIB n +{ + sz_#n db `n,0 +} +include '../export.inc' + +;-------------------------------------------------- +system_path db '/sys/lib/' +name_tgl db 'tinygl.obj',0 +err_message_found_lib db 'Sorry I cannot load library tinygl.obj',0 +head_f_i: +head_f_l db 'System error',0 +err_message_import db 'Error on load import library tinygl.obj',0 +;-------------------------------------------------- + +i_end: + rb 1024 +stacktop: +cur_dir_path: + rb 4096 +library_path: + rb 4096 +mem: diff --git a/programs/develop/libraries/TinyGL/asm_fork/export.inc b/programs/develop/libraries/TinyGL/asm_fork/export.inc index 09b5e5800f..5da2d1b90e 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/export.inc +++ b/programs/develop/libraries/TinyGL/asm_fork/export.inc @@ -154,6 +154,14 @@ E_LIB glDebug ;(int mode) E_LIB glInit ;(void *zbuffer) E_LIB glClose ;(void) +; +; glu functions +; + +E_LIB gluNewQuadric +E_LIB gluDeleteQuadric +E_LIB gluSphere + ; ; Kolibri OS functions ; diff --git a/programs/develop/libraries/TinyGL/asm_fork/glu.asm b/programs/develop/libraries/TinyGL/asm_fork/glu.asm new file mode 100644 index 0000000000..406345e849 --- /dev/null +++ b/programs/develop/libraries/TinyGL/asm_fork/glu.asm @@ -0,0 +1,452 @@ +struct GLUquadricObj + DrawStyle dd ? ; GLU_FILL, LINE, SILHOUETTE, or POINT + Orientation dd ? ; GLU_INSIDE or GLU_OUTSIDE + TextureFlag dd ? ; Generate texture coords? + Normals dd ? ; GLU_NONE, GLU_FLAT, or GLU_SMOOTH + ErrorFunc dd ? ; Error handler callback function +ends + +offs_qobj_DrawStyle equ 0 +offs_qobj_Orientation equ 4 +offs_qobj_TextureFlag equ 8 +offs_qobj_Normals equ 12 +offs_qobj_ErrorFunc equ 16 + +;void drawTorus(float rc, int numc, float rt, int numt) +;{ +;} + +;static void normal3f(GLfloat x, GLfloat y, GLfloat z ) +;{ +;} + +;void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ) +;{ +;} + +;void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, +; GLdouble centerx, GLdouble centery, GLdouble centerz, +; GLdouble upx, GLdouble upy, GLdouble upz) +;{ +;} + +align 4 +gluNewQuadric: + stdcall gl_malloc, sizeof.GLUquadricObj + or eax,eax + jz @f + mov dword[eax+offs_qobj_DrawStyle],GLU_FILL + mov dword[eax+offs_qobj_Orientation],GLU_OUTSIDE + mov dword[eax+offs_qobj_TextureFlag],GL_FALSE + mov dword[eax+offs_qobj_Normals],GLU_SMOOTH + mov dword[eax+offs_qobj_ErrorFunc],0 ;NULL + @@: + ret + +align 4 +proc gluDeleteQuadric, state:dword + cmp dword[state],0 + je @f + stdcall gl_free,[state] + @@: + ret +endp + +;void gluQuadricDrawStyle(GLUquadricObj *obj, int style) +;{ +;} + +;void gluCylinder(GLUquadricObj *qobj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLint slices, GLint stacks ) +;{ +;} + +; Disk (adapted from Mesa) + +;void gluDisk(GLUquadricObj *qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops ) +;{ +;} + +; +; Sphere (adapted from Mesa) +; + +;input: +; float radius, int slices, int stacks +align 4 +proc gluSphere qobj:dword, radius:dword, slices:dword, stacks:dword +locals + rho dd ? ;float + drho dd ? + theta dd ? + dtheta dd ? + x dd ? ;float + y dd ? ;float + z dd ? ;float + s dd ? ;float + t dd ? ;float + d_s dd ? ;float + d_t dd ? ;float + i dd ? ;int + j dd ? ;int + imax dd ? ;int + normals dd ? ;int + nsign dd ? ;float +endl +pushad + + mov eax,[qobj] + cmp dword[eax+offs_qobj_Normals],GLU_NONE ;if (qobj.Normals==GLU_NONE) + jne .els_0 + mov dword[normals],GL_FALSE + jmp @f + .els_0: + mov dword[normals],GL_TRUE + @@: + cmp dword[eax+offs_qobj_Orientation],GLU_INSIDE ;if (qobj.Orientation==GLU_INSIDE) + jne .els_1 + mov dword[nsign],-1.0 + jmp @f + .els_1: + mov dword[nsign],1.0 + @@: + + fldpi + fidiv dword[stacks] + fstp dword[drho] + fld1 + fldpi + fscale + fidiv dword[slices] + fstp dword[dtheta] + ffree st0 + fincstp + + ; draw +Z end as a triangle fan + stdcall glBegin,GL_TRIANGLE_FAN + cmp dword[normals],GL_TRUE + jne @f + stdcall glNormal3f, 0.0, 0.0, 1.0 + @@: + cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag) + je @f +;glTexCoord2f(0.5,0.0) + @@: + sub esp,4 + fld dword[nsign] + fmul dword[radius] + fstp dword[esp] + stdcall glVertex3f, 0.0, 0.0 ;, nsign * radius + fld dword[drho] + fcos + fmul dword[nsign] + fstp dword[z] ;z = nsign * cos(drho) + mov dword[j],0 + mov ecx,[slices] +align 4 + .cycle_0: ;for (j=0;j<=slices;j++) + cmp dword[j],ecx + jg .cycle_0_end + fld dword[drho] + fsin + je @f + fild dword[j] + fmul dword[dtheta] + jmp .t0_end + @@: + fldz + .t0_end: + fst dword[theta] ;theta = (j==slices) ? 0.0 : j * dtheta + fsin + fchs + fmul st0,st1 + fstp dword[x] ;x = -sin(theta) * sin(drho) + fld dword[theta] + fcos + fmulp + fstp dword[y] ;y = cos(theta) * sin(drho) + cmp dword[normals],GL_TRUE + jne @f + fld dword[nsign] + fld dword[z] + fmul st0,st1 + fstp dword[esp-4] + fld dword[y] + fmul st0,st1 + fstp dword[esp-8] + fld dword[x] + fmul st0,st1 + fstp dword[esp-12] + sub esp,12 + ffree st0 + fincstp + stdcall glNormal3f ;x*nsign, y*nsign, z*nsign + @@: + fld dword[radius] + fld dword[z] + fmul st0,st1 + fstp dword[esp-4] + fld dword[y] + fmul st0,st1 + fstp dword[esp-8] + fld dword[x] + fmul st0,st1 + fstp dword[esp-12] + sub esp,12 + ffree st0 + fincstp + call glVertex3f ;x*radius, y*radius, z*radius + inc dword[j] + jmp .cycle_0 + .cycle_0_end: + stdcall glEnd + + fld1 + fidiv dword[slices] + fstp dword[d_s] ;1.0 / slices + fld1 + fidiv dword[stacks] + fstp dword[d_t] ;1.0 / stacks + mov dword[t],1.0 ; because loop now runs from 0 + mov ebx,[stacks] + cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag) + je .els_2 + mov dword[i],0 + mov [imax],ebx + jmp @f + .els_2: + mov dword[i],1 + dec ebx + mov [imax],ebx + @@: + + ; draw intermediate stacks as quad strips + mov ebx,[imax] +align 4 + .cycle_1: ;for (i=imin;i=0;j--) + cmp dword[j],0 + jl .cycle_3_end + fld dword[rho] + fsin + je @f + fild dword[j] + fmul dword[dtheta] + jmp .t2_end + @@: + fldz + .t2_end: + fst dword[theta] ;theta = (j==slices) ? 0.0 : j * dtheta + fsin + fchs + fmul st0,st1 + fstp dword[x] ;x = -sin(theta) * sin(rho) + fld dword[theta] + fcos + fmulp + fstp dword[y] ;y = cos(theta) * sin(rho) + cmp dword[normals],GL_TRUE + jne @f + fld dword[nsign] + fld dword[z] + fmul st0,st1 + fstp dword[esp-4] + fld dword[y] + fmul st0,st1 + fstp dword[esp-8] + fld dword[x] + fmul st0,st1 + fstp dword[esp-12] + sub esp,12 + ffree st0 + fincstp + stdcall glNormal3f ;x*nsign, y*nsign, z*nsign + @@: + cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag) + je @f +;glTexCoord2f(s,1-t) + fld dword[s] + fsub dword[d_s] + fstp dword[s] + @@: + fld dword[radius] + fld dword[z] + fmul st0,st1 + fstp dword[esp-4] + fld dword[y] + fmul st0,st1 + fstp dword[esp-8] + fld dword[x] + fmul st0,st1 + fstp dword[esp-12] + sub esp,12 + ffree st0 + fincstp + call glVertex3f ;x*radius, y*radius, z*radius + dec dword[j] + jmp .cycle_3 + .cycle_3_end: + stdcall glEnd +popad + ret +endp diff --git a/programs/develop/libraries/TinyGL/asm_fork/light.asm b/programs/develop/libraries/TinyGL/asm_fork/light.asm index 641803cd67..546bcd0307 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/light.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/light.asm @@ -60,32 +60,56 @@ proc glopColorMaterial uses eax ebx ecx, context:dword, p:dword ret endp -;void glopLight(GLContext *c,GLParam *p) -;{ -; int light=p[1].i; -; int type=p[2].i; +align 4 +proc glopLight uses eax ebx ecx edx, context:dword, p:dword + mov eax,[context] + mov ebx,[p] + mov edx,[ebx+4] ;edx = p[1] + ; V4 v; -; GLLight *l; -; int i; -; -; assert(light >= GL_LIGHT0 && light < GL_LIGHT0+MAX_LIGHTS ); -; -; l=&c->lights[light-GL_LIGHT0]; -; -; for(i=0;i<4;i++) v.v[i]=p[3+i].f; -; -; switch(type) { -; case GL_AMBIENT: -; l->ambient=v; -; break; -; case GL_DIFFUSE: -; l->diffuse=v; -; break; -; case GL_SPECULAR: -; l->specular=v; -; break; -; case GL_POSITION: + +; assert(edx >= GL_LIGHT0 && edx < GL_LIGHT0+MAX_LIGHTS ); + + sub edx,GL_LIGHT0 + imul edx,sizeof.GLLight + add edx,eax + add edx,offs_cont_lights + + mov ecx,[ebx+8] ;ecx = p[2] + cmp ecx,GL_AMBIENT + jne @f + mov esi,ebx + add esi,12 + mov edi,edx + ;add edi,offs_ligh_ambient ;offs_ligh_ambient = 0 + mov ecx,4 + rep movsd ;l.ambient=v + jmp .end_f + @@: + cmp ecx,GL_DIFFUSE + jne @f + mov esi,ebx + add esi,12 + mov edi,edx + add edi,offs_ligh_diffuse + mov ecx,4 + rep movsd ;l.diffuse=v + jmp .end_f + @@: + cmp ecx,GL_SPECULAR + jne @f + mov esi,ebx + add esi,12 + mov edi,edx + add edi,offs_ligh_specular + mov ecx,4 + rep movsd ;l.specular=v + jmp .end_f + @@: + cmp ecx,GL_POSITION + jne @f ; { +; for(i=0;i<4;i++) v.v[i]=p[3+i].f; ; V4 pos; ; gl_M4_MulV4(&pos,c->matrix_stack_ptr[0],&v); ; @@ -99,38 +123,62 @@ endp ; gl_V3_Norm(&l->norm_position); ; } ; } -; break; -; case GL_SPOT_DIRECTION: -; for(i=0;i<3;i++) { -; l->spot_direction.v[i]=v.v[i]; -; l->norm_spot_direction.v[i]=v.v[i]; -; } -; gl_V3_Norm(&l->norm_spot_direction); -; break; -; case GL_SPOT_EXPONENT: -; l->spot_exponent=v.v[0]; -; break; -; case GL_SPOT_CUTOFF: + jmp .end_f + @@: + cmp ecx,GL_SPOT_DIRECTION + jne @f + mov esi,ebx + add esi,12 + mov edi,edx + add edi,offs_ligh_spot_direction + mov ecx,3 + rep movsd ;l.spot_direction=v[0,1,2] + mov esi,ebx + add esi,12 + mov edi,edx + add edi,offs_ligh_norm_spot_direction + mov ecx,3 + rep movsd ;l.norm_spot_direction=v[0,1,2] + add edx,offs_ligh_norm_spot_direction + stdcall gl_V3_Norm,edx + jmp .end_f + @@: + 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 + @@: + cmp ecx,GL_SPOT_CUTOFF + jne @f ; { ; float a=v.v[0]; ; assert(a == 180 || (a>=0 && a<=90)); ; l->spot_cutoff=a; ; if (a != 180) l->cos_spot_cutoff=cos(a * M_PI / 180.0); ; } -; break; -; case GL_CONSTANT_ATTENUATION: -; l->attenuation[0]=v.v[0]; -; break; -; case GL_LINEAR_ATTENUATION: -; l->attenuation[1]=v.v[0]; -; break; -; case GL_QUADRATIC_ATTENUATION: -; l->attenuation[2]=v.v[0]; -; break; -; default: + jmp .end_f + @@: + cmp ecx,GL_CONSTANT_ATTENUATION + mov ecx,[ebx+12] + mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3] + jmp .end_f + @@: + cmp ecx,GL_LINEAR_ATTENUATION + mov ecx,[ebx+12] + mov [edi+offs_ligh_attenuation+4],ecx ;l->attenuation[1]=p[3] + jmp .end_f + @@: + cmp ecx,GL_QUADRATIC_ATTENUATION + mov ecx,[ebx+12] + mov [edi+offs_ligh_attenuation+8],ecx ;l->attenuation[2]=p[3] + jmp .end_f + @@: ;default: ; assert(0); -; } -;} + .end_f: + ret +endp + align 4 proc glopLightModel uses ebx ecx esi edi, context:dword, p:dword diff --git a/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm b/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm index 31bb6126bb..9e6bb7243b 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm @@ -31,6 +31,7 @@ include 'ztriangle.asm' include 'arrays.asm' include 'kosgl.asm' +include 'glu.asm' if DEBUG include 'info_fun_float.inc' @@ -69,9 +70,6 @@ glDeleteTextures: ;(int n, const unsigned int *textures) glGetIntegerv: ;(int pname,int *params) glGetFloatv: ;(int pname, float *v) -; *** -glopLight: - if DEBUG align 4 txt_nl db 13,10,0 @@ -157,7 +155,6 @@ 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_cl1 db ' ClipLine1',0 f_m4m db 'gl_M4_Mul',0 f_m4ml db 'gl_M4_MulLeft',0 f_find_l db 'find_list',0 diff --git a/programs/develop/libraries/TinyGL/asm_fork/vertex.asm b/programs/develop/libraries/TinyGL/asm_fork/vertex.asm index 8d7cc4e6e8..09585fb5da 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/vertex.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/vertex.asm @@ -5,9 +5,9 @@ proc glopNormal uses ecx esi edi, context:dword, p:dword add esi,4 mov edi,[context] add edi,offs_cont_current_normal - mov ecx,4 + mov ecx,3 rep movsd - mov dword[esi],0.0 ;context.current_normal.W = 0.0 + mov dword[edi],0.0 ;context.current_normal.W = 0.0 ret endp @@ -171,12 +171,12 @@ endl .end_if_0: ; test if the texture matrix is not Identity - stdcall gl_M4_IsId,edx+offs_cont_matrix_stack_ptr+8 - xor edx,1 - mov ebx,[context] - mov dword[ebx+offs_cont_apply_texture_matrix],edx + mov eax,edx + add eax,offs_cont_matrix_stack_ptr+8 + stdcall gl_M4_IsId,eax + xor eax,1 + mov dword[edx+offs_cont_apply_texture_matrix],eax - mov edx,[context] mov dword[edx+offs_cont_matrix_model_projection_updated],0 .end_mmpu: @@ -253,11 +253,17 @@ pushad add ebx,16 ;следущая строка матрицы add edx,4 ;следущая координата вектора loop .cycle_0 + ffree st0 + fincstp + ffree st0 + fincstp + ffree st0 + fincstp ; projection coordinates mov ebx,dword[eax+offs_cont_matrix_stack_ptr+4] mov edx,[v] - finit + fld dword[edx+offs_vert_ec+offs_X] fld dword[edx+offs_vert_ec+offs_Y] fld dword[edx+offs_vert_ec+offs_Z] @@ -277,27 +283,33 @@ pushad add ebx,16 ;следущая строка матрицы add edx,4 ;следущая координата вектора loop .cycle_1 + ffree st0 + fincstp + ffree st0 + fincstp + ffree st0 + fincstp mov ebx,eax add ebx,offs_cont_matrix_model_view_inv mov edi,eax add edi,offs_cont_current_normal mov edx,[v] - finit + fld dword[edi+offs_X] fld dword[edi+offs_Y] fld dword[edi+offs_Z] mov ecx,3 .cycle_2: - fld dword[ebx] ;st0 = m[0] - fmul st0,st3 ;st0 *= n.X - fld dword[ebx+4] ;st0 = m[1] - fmul st0,st3 ;st0 *= n.Y - fld dword[ebx+8] ;st0 = m[2] - fmul st0,st3 ;st0 *= n.Z - faddp ;st0 += n.Z * m[2] - faddp ;st0 += n.Y * m[1] + fld dword[ebx] ;st0 = m[0] + fmul st0,st3 ;st0 *= n.X + fld dword[ebx+4] ;st0 = m[1] + fmul st0,st3 ;st0 *= n.Y + fld dword[ebx+8] ;st0 = m[2] + fmul st0,st3 ;st0 *= n.Z + faddp ;st0 += n.Z * m[2] + faddp ;st0 += n.Y * m[1] fstp dword[edx+offs_vert_normal] ;v.normal.X = n.X * m[0] + n.Y * m[1] + n.Z * m[2] add ebx,16 ;следущая строка матрицы add edx,4 ;следущая координата вектора @@ -305,7 +317,9 @@ pushad cmp dword[eax+offs_cont_normalize_enabled],0 je .end_els -;stdcall gl_V3_Norm(&v->normal) + mov edx,[v] + add edx,offs_vert_normal + stdcall gl_V3_Norm,edx jmp .end_els .els_0: ; no eye coordinates needed, no normal @@ -516,11 +530,10 @@ pushad jne .end_f ;else if (n == 2) mov eax,[edx+offs_cont_vertex] push eax + mov edi,eax add eax,sizeof.GLVertex + mov esi,eax stdcall gl_draw_line, edx, eax - mov edi,[edx+offs_cont_vertex] - mov esi,edi - add esi,sizeof.GLVertex mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb rep movsd ;context.vertex[0] = context.vertex[1] mov dword[n],1 @@ -531,11 +544,13 @@ pushad cmp dword[n],3 jne .end_f mov eax,[edx+offs_cont_vertex] - push eax + mov [esp-4],eax add eax,sizeof.GLVertex - push eax + mov [esp-8],eax add eax,sizeof.GLVertex - stdcall gl_draw_triangle, edx, eax + mov [esp-12],eax + sub esp,12 + stdcall gl_draw_triangle, edx xor eax,eax mov dword[n],eax jmp .end_f @@ -560,10 +575,20 @@ pushad @@: cmp dword[edx+offs_cont_begin_type],GL_TRIANGLE_FAN jne @f - cmp dword[n],2 + cmp dword[n],3 jne .end_f -; gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); -; c->vertex[1] = c->vertex[2]; + mov eax,[edx+offs_cont_vertex] + mov [esp-4],eax + add eax,sizeof.GLVertex + mov [esp-8],eax + mov edi,eax + add eax,sizeof.GLVertex + mov [esp-12],eax + mov esi,eax + sub esp,12 + stdcall gl_draw_triangle, edx + mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb + rep movsd ;context.vertex[1] = context.vertex[2] mov dword[n],2 jmp .end_f @@: @@ -594,12 +619,27 @@ pushad @@: cmp dword[edx+offs_cont_begin_type],GL_QUAD_STRIP jne @f - cmp dword[n],2 + cmp dword[n],4 jne .end_f -; gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); -; gl_draw_triangle(c, &c->vertex[1], &c->vertex[3], &c->vertex[2]); -; for (i = 0; i < 2; i++) -; c->vertex[i] = c->vertex[i + 2]; + mov eax,[edx+offs_cont_vertex] + mov [esp-4],eax + mov edi,eax + add eax,sizeof.GLVertex + mov [esp-8],eax + add eax,sizeof.GLVertex + mov [esp-12],eax + mov esi,eax + sub esp,12 + stdcall gl_draw_triangle, edx ;v0,v1,v2 + mov [esp-12],eax + add eax,sizeof.GLVertex + mov [esp-8],eax + sub eax,2*sizeof.GLVertex + mov [esp-4],eax + sub esp,12 + stdcall gl_draw_triangle, edx ;v1,v3,v2 + mov ecx,(sizeof.GLVertex)/2 ;((...)/2) копируем 2 вершины + rep movsd ;context.vertex[0] = context.vertex[2], context.vertex[1] = context.vertex[3] mov dword[n],2 jmp .end_f @@: diff --git a/programs/develop/libraries/TinyGL/asm_fork/zbuffer.inc b/programs/develop/libraries/TinyGL/asm_fork/zbuffer.inc index e79c9cea4d..f72e987f7b 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/zbuffer.inc +++ b/programs/develop/libraries/TinyGL/asm_fork/zbuffer.inc @@ -32,14 +32,14 @@ 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 */ +; bytes per pixel ;PSZB equ 2 -;/* bits per pixel = (1 << PSZH) */ +; bits per pixel = (1 << PSZH) ;PSZSH equ 4 else if TGL_FEATURE_RENDER_BITS eq 16 -;/* 16 bit mode */ +; 16 bit mode ;#define RGB_TO_PIXEL(r,g,b) \ ; (((r) & 0xF800) | (((g) >> 5) & 0x07E0) | ((b) >> 11)) ;typedef unsigned short PIXEL; @@ -142,12 +142,12 @@ offs_zbup_tz equ 36 ; modify these functions so that they suit your needs align 4 -proc gl_free uses ebx ecx, mptr:dword +proc gl_free uses eax ebx ecx, mptr:dword mov ecx,[mptr] or ecx,ecx jz @f - @@: - mcall 68, 13 + mcall 68, 13 + @@: ret endp @@ -165,8 +165,8 @@ align 4 proc gl_zalloc uses ebx ecx edi, size:dword mov ecx,[size] stdcall gl_malloc,ecx - cmp eax,0 - je @f + or eax,eax + jz @f mov ebx,eax mov edi,eax xor eax,eax diff --git a/programs/develop/libraries/TinyGL/asm_fork/zmath.asm b/programs/develop/libraries/TinyGL/asm_fork/zmath.asm index 6873b02ee7..61f91e79c4 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/zmath.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/zmath.asm @@ -42,6 +42,8 @@ proc gl_M4_IsId uses ebx ecx, a:dword test ah,0x40 je .not_1 ; 1.0 @@: + ffree st0 + fincstp add eax,4 inc ebx btr ebx,2 @@ -53,6 +55,8 @@ proc gl_M4_IsId uses ebx ecx, a:dword mov eax,1 jmp @f .not_1: + ffree st0 + fincstp xor eax,eax @@: ret @@ -235,7 +239,7 @@ proc gl_M4_Transpose uses eax ecx edx, a:dword, b:dword ret endp -;/* inversion of an orthogonal matrix of type Y=M.X+P */ +; inversion of an orthogonal matrix of type Y=M.X+P ;void gl_M4_InvOrtho(M4 *a,M4 b) ;{ ; int i,j; @@ -250,8 +254,8 @@ endp ; } ;} -;/* Inversion of a general nxn matrix. -; Note : m is destroyed */ +; Inversion of a general nxn matrix. +; Note : m is destroyed align 4 proc Matrix_Inv uses ecx, r:dword, m:dword, n:dword ;(float *r,float *m,int n) @@ -401,16 +405,42 @@ endp ; vector arithmetic -;int gl_V3_Norm(V3 *a) -;{ -; float n; -; n=sqrt(a->X*a->X+a->Y*a->Y+a->Z*a->Z); -; if (n==0) return 1; -; a->X/=n; -; a->Y/=n; -; a->Z/=n; -; return 0; -;} +align 4 +proc gl_V3_Norm uses ebx, a:dword + mov ebx,[a] + fld dword[ebx] + fmul dword[ebx] + fld dword[ebx+4] + fmul dword[ebx+4] + faddp + fld dword[ebx+8] + fmul dword[ebx+8] + faddp + fsqrt ;st0 = sqrt(a.X^2 +a.Y^2 +a.Z^2) + fldz + fcomp + fstsw ax + sahf + je .r1 ;if (sqrt(...)==0) return 1 + fld dword[ebx] ;offs_X = 0 + fdiv st0,st1 + fstp dword[ebx] ;a.X/=sqrt(...) + fld dword[ebx+4] + fdiv st0,st1 + fstp dword[ebx+4] ;a.Y/=sqrt(...) + fld dword[ebx+8] + fdiv st0,st1 + fstp dword[ebx+8] ;a.Z/=sqrt(...) + xor eax,eax + jmp @f + .r1: + xor eax,eax + inc eax + @@: + ffree st0 + fincstp + ret +endp macro gl_V3_New p_mem, x, y, z {