diff --git a/programs/develop/libraries/TinyGL/asm_fork/clear.asm b/programs/develop/libraries/TinyGL/asm_fork/clear.asm index 697a0da68e..3522e7d875 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/clear.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/clear.asm @@ -18,17 +18,30 @@ proc glopClearDepth uses eax ebx, context:dword, p:dword ret endp -;void glopClear(GLContext *c,GLParam *p) -;{ -; int mask=p[1].i; -; int z=0; -; int r=(int)(c->clear_color.v[0]*65535); -; int g=(int)(c->clear_color.v[1]*65535); -; int b=(int)(c->clear_color.v[2]*65535); -; -; /* TODO : correct value of Z */ -; -; ZB_clear(c->zb,mask & GL_DEPTH_BUFFER_BIT,z, -; mask & GL_COLOR_BUFFER_BIT,r,g,b); -;} +align 4 +proc glopClear uses eax ebx, context:dword, p:dword + mov eax,[context] + mov ebx,[eax+offs_cont_clear_color+8] ;context.clear_color.v[2] + shl ebx,16 + push ebx + mov ebx,[eax+offs_cont_clear_color+4] ;context.clear_color.v[1] + shl ebx,16 + push ebx + mov ebx,[eax+offs_cont_clear_color] ;context.clear_color.v[0] + shl ebx,16 + push ebx + + mov ebx,[p] + mov ebx,[ebx+4] ;ebx = p[1] + and ebx,GL_COLOR_BUFFER_BIT + push ebx + mov ebx,[p] + mov ebx,[ebx+4] ;ebx = p[1] + and ebx,GL_DEPTH_BUFFER_BIT + + ; TODO : correct value of Z + stdcall ZB_clear,[eax+offs_cont_zb],ebx,0 ;,...,r,g,b + ret +endp + diff --git a/programs/develop/libraries/TinyGL/asm_fork/examples/test0.asm b/programs/develop/libraries/TinyGL/asm_fork/examples/test0.asm new file mode 100644 index 0000000000..5f07992119 --- /dev/null +++ b/programs/develop/libraries/TinyGL/asm_fork/examples/test0.asm @@ -0,0 +1,173 @@ +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 + +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 + + ;178 ;Up + ;177 ;Down + 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: + mcall -1 + + +align 4 +caption db 'Test tinygl library, [Esc] - exit, [<-] and [->] - 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 [glPushMatrix] + stdcall [glRotatef], [angle_z],0.0,0.0,1.0 + + stdcall [glColor3f],1.0, 0.0, 0.0 + stdcall [glBegin],GL_POINTS + stdcall [glVertex3f], 0.0, 0.5, 0.1 + stdcall [glVertex3f], 0.354, 0.354, 0.1 + stdcall [glVertex3f], 0.5, 0.0, 0.1 + stdcall [glVertex3f], 0.354, -0.354, 0.1 + stdcall [glVertex3f], 0.0, -0.5, 0.1 + stdcall [glVertex3f], -0.354,-0.354, 0.1 + stdcall [glVertex3f], -0.5, 0.0, 0.1 + stdcall [glVertex3f], -0.354, 0.354, 0.1 + stdcall [glEnd] + + stdcall [glBegin],GL_LINES + stdcall [glVertex3f], 0, 0.7, 0.3 + stdcall [glVertex3f], 0.495, 0.495, 0.7 + stdcall [glVertex3f], 0.7, 0.0, 0.3 + stdcall [glColor3f],1.0, 1.0, 0.0 + stdcall [glVertex3f], 0.495, -0.495, 0.7 + stdcall [glVertex3f], 0.0, -0.7, 0.3 + stdcall [glVertex3f], -0.495,-0.495, 0.7 + stdcall [glVertex3f], -0.7, 0.0, 0.3 + stdcall [glColor3f],1.0, 0.0, 0.0 + stdcall [glVertex3f], -0.495, 0.495, 0.7 + stdcall [glEnd] + +stdcall [glPopMatrix] +ret + +angle_z 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: \ No newline at end of file diff --git a/programs/develop/libraries/TinyGL/asm_fork/examples/test1.asm b/programs/develop/libraries/TinyGL/asm_fork/examples/test1.asm new file mode 100644 index 0000000000..b8ef4de948 --- /dev/null +++ b/programs/develop/libraries/TinyGL/asm_fork/examples/test1.asm @@ -0,0 +1,174 @@ +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 + +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 + + ;178 ;Up + ;177 ;Down + 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: + mcall -1 + + +align 4 +caption db 'Test tinygl library, [Esc] - exit, [<-] and [->] - 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 [glPushMatrix] + stdcall [glRotatef], [angle_z],0.0,0.0,1.0 + + stdcall [glScalef], 0.3,0.3,0.3 + + stdcall [glColor3f],1.0, 0.0, 0.0 + stdcall [glBegin],GL_LINE_LOOP + stdcall [glVertex3f], 0, 0.9, 0.1 + stdcall [glVertex3f], 0.636, 0.636, 0.1 + stdcall [glVertex3f], 0.9, 0.0, 0.1 + stdcall [glVertex3f], 0.636, -0.636, 0.1 + stdcall [glColor3f],0.0, 0.0, 1.0 + stdcall [glVertex3f], 0.0, -0.9, 0.1 + stdcall [glVertex3f], -0.636,-0.636, 0.1 + stdcall [glVertex3f], -0.9, 0.0, 0.1 + stdcall [glVertex3f], -0.636, 0.636, 0.1 + stdcall [glEnd] + + stdcall [glBegin],GL_LINE_LOOP + stdcall [glVertex3f], 0.0, 1.1, 0.1 + stdcall [glVertex3f], 0.778, 0.778, 0.1 + stdcall [glVertex3f], 2.1, 0.0, 0.1 + stdcall [glVertex3f], 0.778, -0.778, 0.1 + stdcall [glVertex3f], 0.0, -1.1, 0.1 + stdcall [glVertex3f], -0.778, -0.778, 0.1 + stdcall [glVertex3f], -2.1, 0.0, 0.1 + stdcall [glVertex3f], -0.778, 0.778, 0.1 + stdcall [glEnd] + +stdcall [glPopMatrix] +ret + +angle_z 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/tinygl.asm b/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm index db481bfaaa..e9db133998 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/tinygl.asm @@ -74,7 +74,6 @@ glGetFloatv: ;(int pname, float *v) ; *** glopLight: -glopClear: glopCallList: if DEBUG diff --git a/programs/develop/libraries/TinyGL/asm_fork/zbuffer.asm b/programs/develop/libraries/TinyGL/asm_fork/zbuffer.asm index 85a799e5e3..8ef1774173 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/zbuffer.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/zbuffer.asm @@ -57,7 +57,7 @@ end if mov ecx,[edi+offs_zbuf_xsize] imul ecx,[edi+offs_zbuf_ysize] - shl ecx,2 ;*= sizeof(unsigned short) + shl ecx,1 ;*= sizeof(unsigned short) stdcall gl_malloc, ecx mov [edi+offs_zbuf_zbuf],eax @@ -115,7 +115,7 @@ proc ZB_resize uses eax ebx ecx edi esi, zb:dword, frame_buffer:dword, xsize:dwo mov ecx,edi imul ecx,esi - shl ecx,2 ;*= sizeof(unsigned short) + shl ecx,1 ;*= sizeof(unsigned short) stdcall gl_free,dword[ebx+offs_zbuf_zbuf] stdcall gl_malloc,ecx @@ -432,114 +432,135 @@ endp ;} ; ;#endif /* TGL_FEATURE_RENDER_BITS == 32 */ + + ; +; adr must be aligned on an 'int' ; -;/* -; * adr must be aligned on an 'int' -; */ -;void memset_s(void *adr, int val, int count) -;{ -; int i, n, v; -; unsigned int *p; -; unsigned short *q; -; -; p = adr; -; v = val | (val << 16); -; -; n = count >> 3; -; for (i = 0; i < n; i++) { -; p[0] = v; -; p[1] = v; -; p[2] = v; -; p[3] = v; -; p += 4; -; } -; -; q = (unsigned short *) p; -; n = count & 7; -; for (i = 0; i < n; i++) -; *q++ = val; -;} -; -;void memset_l(void *adr, int val, int count) -;{ -; int i, n, v; -; unsigned int *p; -; -; p = adr; -; v = val; -; n = count >> 2; -; for (i = 0; i < n; i++) { -; p[0] = v; -; p[1] = v; -; p[2] = v; -; p[3] = v; -; p += 4; -; } -; -; n = count & 3; -; for (i = 0; i < n; i++) -; *p++ = val; -;} -; -;/* count must be a multiple of 4 and >= 4 */ -;void memset_RGB24(void *adr,int r, int v, int b,long count) -;{ -; long i, n; -; register long v1,v2,v3,*pt=(long *)(adr); -; unsigned char *p,R=(unsigned char)r,V=(unsigned char)v,B=(unsigned char)b; -; -; p=(unsigned char *)adr; -; *p++=R; -; *p++=V; -; *p++=B; -; *p++=R; -; *p++=V; -; *p++=B; -; *p++=R; -; *p++=V; -; *p++=B; -; *p++=R; -; *p++=V; -; *p++=B; -; v1=*pt++; -; v2=*pt++; -; v3=*pt++; -; n = count >> 2; -; for(i=1;izbuf, z, zb->xsize * zb->ysize); -; } -; if (clear_color) { -; pp = zb->pbuf; -; for (y = 0; y < zb->ysize; y++) { -;#if TGL_FEATURE_RENDER_BITS == 15 || TGL_FEATURE_RENDER_BITS == 16 -; color = RGB_TO_PIXEL(r, g, b); -; memset_s(pp, color, zb->xsize); -;#elif TGL_FEATURE_RENDER_BITS == 32 -; color = RGB_TO_PIXEL(r, g, b); -; memset_l(pp, color, zb->xsize); -;#elif TGL_FEATURE_RENDER_BITS == 24 -; memset_RGB24(pp,r>>8,g>>8,b>>8,zb->xsize); -;#else -;#error TODO -;#endif -; pp = (PIXEL *) ((char *) pp + zb->linesize); -; } -; } -;} +align 4 +proc memset_s uses eax ecx edi, adr:dword, val:dword, count:dword + mov eax,[val] + mov di,ax + ror eax,16 + mov ax,di + mov ecx,[count] + shr ecx,1 + mov edi,[adr] + rep stosd + + bt dword[count],0 + jnc @f + stosw + @@: + ret +endp + +align 4 +proc memset_l uses eax ecx edi, adr:dword, val:dword, count:dword + mov eax,[val] + mov ecx,[count] + mov edi,[adr] + rep stosd + ret +endp + +; count must be a multiple of 4 and >= 4 +align 4 +proc memset_RGB24 uses eax ecx edi esi, adr:dword, r:dword, g:dword, b:dword, count:dword + mov esi,[adr] + mov eax,[r] ;копируем в буфер первые 12 байт (минимальное число кратное 3 и 4) + mov byte[esi],al + mov byte[esi+3],al + mov byte[esi+6],al + mov byte[esi+9],al + mov eax,[g] + mov byte[esi+1],al + mov byte[esi+4],al + mov byte[esi+7],al + mov byte[esi+10],al + mov eax,[b] + mov byte[esi+2],al + mov byte[esi+5],al + mov byte[esi+8],al + mov byte[esi+11],al + + mov ecx,[count] + shr ecx,2 + cmp ecx,1 + jle .end_f ;если ширина буфера меньше 12 байт, то выходим + dec ecx + mov edi,esi + add edi,12 + + mov eax,[esi] + cmp eax,[esi+4] + jne @f + ;если r=g и g=b и b=r + mov esi,ecx + shl ecx,2 + sub ecx,esi ;ecx*=3 + rep stosd + jmp .end_f + @@: + + ;если r!=g или g!=b или b!=r + @@: + movsd + movsd + movsd + sub esi,12 + loop @b + .end_f: + ret +endp + +align 4 +proc ZB_clear uses eax ebx ecx, zb:dword, clear_z:dword, z:dword, clear_color:dword,\ + r:dword, g:dword, b:dword +;if TGL_FEATURE_RENDER_BITS != 24 +; color dd ? +;end if + + mov eax,[zb] + cmp dword[clear_z],0 + je @f + mov ebx,[eax+offs_zbuf_xsize] + imul ebx,[eax+offs_zbuf_ysize] + stdcall memset_s, [eax+offs_zbuf_zbuf],[z],ebx + @@: + cmp dword[clear_color],0 + je @f +if TGL_FEATURE_RENDER_BITS eq 24 + mov ebx,[eax+offs_zbuf_xsize] + push ebx + mov ebx,[b] + shr ebx,8 + push ebx + mov ebx,[g] + shr ebx,8 + push ebx + mov ebx,[r] + shr ebx,8 + push ebx + add esp,16 +end if + mov ebx,[eax+offs_zbuf_pbuf] + mov ecx,[eax+offs_zbuf_ysize] + .cycle_0: +if (TGL_FEATURE_RENDER_BITS eq 15) ;or (TGL_FEATURE_RENDER_BITS eq 16) + ;color = RGB_TO_PIXEL(r, g, b); + ;memset_s(ebx, color, zb->xsize); +end if +if TGL_FEATURE_RENDER_BITS eq 32 + ;color = RGB_TO_PIXEL(r, g, b); + ;memset_l(ebx, color, zb->xsize); +end if +if TGL_FEATURE_RENDER_BITS eq 24 + sub esp,16 + stdcall memset_RGB24,ebx +end if + add ebx,[eax+offs_zbuf_linesize] + loop .cycle_0 + @@: + ret +endp diff --git a/programs/develop/libraries/TinyGL/asm_fork/zline.asm b/programs/develop/libraries/TinyGL/asm_fork/zline.asm index 2c9b57a592..032c012abc 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/zline.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/zline.asm @@ -6,6 +6,7 @@ proc ZB_plot uses eax ebx ecx edx edi, zb:dword, p:dword mov ecx,[ebx+offs_zbup_y] imul ecx,[eax+offs_zbuf_xsize] add ecx,[ebx+offs_zbup_x] + shl ecx,1 add ecx,[eax+offs_zbuf_zbuf] mov edx,[eax+offs_zbuf_linesize] imul edx,[ebx+offs_zbup_y] @@ -15,7 +16,7 @@ proc ZB_plot uses eax ebx ecx edx edi, zb:dword, p:dword add edx,[eax+offs_zbuf_pbuf] mov edi,[ebx+offs_zbup_z] shr edi,ZB_POINT_Z_FRAC_BITS - cmp edi,[ecx] + cmp di,word[ecx] jl .end_f if TGL_FEATURE_RENDER_BITS eq 24 mov eax,[ebx+offs_zbup_r] @@ -27,7 +28,7 @@ if TGL_FEATURE_RENDER_BITS eq 24 else ; *pp = RGB_TO_PIXEL(p->r, p->g, p->b); end if - mov [ecx],edi + mov word[ecx],di .end_f: ret endp diff --git a/programs/develop/libraries/TinyGL/asm_fork/zline.inc b/programs/develop/libraries/TinyGL/asm_fork/zline.inc index dc23d52b0a..8196e7b57e 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/zline.inc +++ b/programs/develop/libraries/TinyGL/asm_fork/zline.inc @@ -50,6 +50,7 @@ if INTERP_Z eq 1 mov edx,[ecx+offs_zbup_y] imul edx,[sx] add edx,[ecx+offs_zbup_x] + shl edx,1 add edx,[eax+offs_zbuf_zbuf] mov [pz],edx ;pz = zb.zbuf + (p1.y*sx + p1.x) mov edx,[ecx+offs_zbup_z] @@ -98,28 +99,51 @@ local .end_0 mov eax,[z] shr eax, ZB_POINT_Z_FRAC_BITS mov [zz],eax - cmp eax,[pz] + mov ebx,[pz] + cmp ax,word[ebx] jl .end_0 RGBPIXEL mov eax,dword[zz] - mov [pz],eax + mov ebx,[pz] + mov word[ebx],ax .end_0: -else ; INTERP_Z +else RGBPIXEL -end if ; INTERP_Z +end if } macro DRAWLINE d_x,d_y,inc_1,inc_2 { +local .mz_0 +local .mz_1 +local .mz_2 + mov eax,d_x mov [n],eax if INTERP_Z eq 1 mov ebx,[p1] mov eax,[p2] mov eax,[eax+offs_zbup_z] + cmp eax,[ebx+offs_zbup_z] + jg .mz_0 + je .mz_1 + ;if(p2.z