prepare texture functions (need to be finalized)

git-svn-id: svn://kolibrios.org@6108 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2016-01-28 19:22:54 +00:00
parent 81924b284f
commit c64bf3d60e
10 changed files with 498 additions and 329 deletions

View File

@ -165,6 +165,7 @@ E_LIB gluNewQuadric
E_LIB gluDeleteQuadric
E_LIB gluQuadricDrawStyle
E_LIB gluQuadricOrientation
E_LIB gluQuadricTexture
E_LIB gluSphere
;

View File

@ -75,7 +75,7 @@ proc gluQuadricDrawStyle uses eax ebx, qobj:dword, drawStyle:dword
mov dword[eax+offs_qobj_DrawStyle],ebx
jmp @f
.err_q:
;quadric_error(qobj, GLU_INVALID_ENUM, "qluQuadricDrawStyle")
stdcall dbg_print,sz_gluQuadricDrawStyle,err_9
@@:
ret
endp
@ -98,7 +98,26 @@ proc gluQuadricOrientation uses eax ebx, qobj:dword, orientation:dword
mov dword[eax+offs_qobj_Orientation],ebx
jmp @f
.err_q:
;quadric_error(qobj, GLU_INVALID_ENUM, "qluQuadricOrientation")
stdcall dbg_print,sz_gluQuadricOrientation,err_9
@@:
ret
endp
align 4
proc gluQuadricTexture uses eax ebx, qobj:dword, texture:dword
mov eax,[qobj]
or eax,eax
jz .err_q
mov ebx,[texture]
cmp ebx,GL_TRUE
je @f
cmp ebx,GL_FALSE
je @f
@@:
mov dword[eax+offs_qobj_TextureFlag],ebx
jmp @f
.err_q:
stdcall dbg_print,sz_gluQuadricTexture,err_9
@@:
ret
endp
@ -179,7 +198,7 @@ pushad
@@:
cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
je @f
;glTexCoord2f(0.5,0.0)
stdcall glTexCoord2f, 0.5,0.0
@@:
sub esp,4
fld dword[nsign]
@ -320,7 +339,11 @@ align 4
@@:
cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
je @f
;glTexCoord2f(s,1-t)
fld1
fsub dword[t]
fstp dword[esp-4]
sub esp,4
stdcall glTexCoord2f, [s] ;,1-t
@@:
fld dword[radius]
fld dword[z]
@ -368,7 +391,12 @@ align 4
@@:
cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
je @f
;glTexCoord2f(s,1-(t-dt))
fld1
fsub dword[t]
fadd dword[d_t]
fstp dword[esp-4]
sub esp,4
stdcall glTexCoord2f, [s] ;,1-(t-dt)
fld dword[s]
fadd dword[d_s]
fstp dword[s]
@ -404,7 +432,7 @@ align 4
@@:
cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
je @f
;glTexCoord2f(0.5,1.0)
stdcall glTexCoord2f, 0.5,1.0
mov dword[s],1.0
mov ebx,[d_t]
mov [t],ebx
@ -463,7 +491,11 @@ align 4
@@:
cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
je @f
;glTexCoord2f(s,1-t)
fld1
fsub dword[t]
fstp dword[esp-4]
sub esp,4
stdcall glTexCoord2f, [s] ;,1-t
fld dword[s]
fsub dword[d_s]
fstp dword[s]

View File

@ -14,11 +14,11 @@ ends
;KOSGLContext kosglCreateContext(KOSGLContext shareList, int flags)
;{
; TinyGLContext *ctx;
;
; if (shareList != NULL) {
; gl_fatal_error("No sharing available in TinyGL");
; }
;
; ctx=gl_malloc(sizeof(TinyGLContext));
; if (!ctx)
; return NULL;
@ -99,9 +99,9 @@ proc kosglMakeCurrent uses ebx ecx, win_x0:dword, win_y0:dword, win_x:dword, win
xor eax,eax
stdcall ZB_open, dword[win_x], dword[win_y], dword ZB_MODE_RGB24, eax,eax,eax,eax ;NULL,NULL,NULL
cmp eax,0
jne @f
stdcall dbg_print,f_kosgl_1,err_0
or eax,eax
jnz @f
stdcall dbg_print,sz_kosglMakeCurrent,err_0
xor eax,eax
jmp .err_f
@@:

View File

@ -263,9 +263,9 @@ proc glopCallList uses eax ebx ecx edx edi, context:dword, p:dword
mov ebx,[p]
stdcall find_list,edx,[ebx+4]
cmp eax,0
jne @f
;if (eax == NULL) gl_fatal_error("list %d not defined",[ebx+4])
or eax,eax
jnz @f
;gl_fatal_error("list %d not defined",[ebx+4])
@@:
mov edi,[eax] ;edi = &GLList.first_op_buffer.ops

View File

@ -54,7 +54,7 @@ endl
stdcall dword[edx+offs_cont_gl_resize_viewport], edx ;gl_resize_viewport(context,&xsize_req,&ysize_req)
cmp eax,0
je @f
stdcall dbg_print,f_vp,err_4
stdcall dbg_print,sz_glViewport,err_4
@@:
mov ecx,[xsize_req]
@ -67,40 +67,8 @@ endl
jg @f
cmp dword[xsize],0
jg @f
stdcall dbg_print,f_vp,err_5
stdcall dbg_print,sz_glViewport,err_5
@@:
if DEBUG ;glopViewport
push edi
mov ecx,80
mov eax,[xmin]
lea edi,[buf_param]
stdcall convert_int_to_str,ecx
stdcall str_n_cat,edi,txt_zp_sp,2
stdcall str_len,edi
add edi,eax
sub ecx,eax
mov eax,[ymin]
stdcall convert_int_to_str,ecx
stdcall str_n_cat,edi,txt_zp_sp,2
stdcall str_len,edi
add edi,eax
sub ecx,eax
mov eax,[xsize]
stdcall convert_int_to_str,ecx
stdcall str_n_cat,edi,txt_zp_sp,2
stdcall str_len,edi
add edi,eax
sub ecx,eax
mov eax,[ysize]
stdcall convert_int_to_str,ecx
stdcall str_n_cat,edi,txt_nl,2
stdcall dbg_print,f_vp,buf_param
pop edi
end if
mov ecx,[xmin]
mov dword[edx+offs_cont_viewport+offs_vpor_xmin],ecx
mov ecx,[ymin]

View File

@ -9,7 +9,7 @@ proc find_texture uses ebx ecx, context:dword, h:dword
mov eax,[h]
and eax,0xff
shl eax,2
add eax,[ebx] ;eax = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
add eax,ebx ;eax = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
; [eax] - указатель на текстуру, получаемую через хеш таблицу
mov ecx,[h] ; ecx - указатель на искомую текстуру
@ -27,29 +27,50 @@ proc find_texture uses ebx ecx, context:dword, h:dword
ret
endp
;static void free_texture(GLContext *c,int h)
;{
; GLTexture *t,**ht;
; GLImage *im;
; int i;
;
; t=find_texture(c,h);
; if (t->prev==NULL) {
; ht=&c->shared_state.texture_hash_table
; [t->handle % TEXTURE_HASH_TABLE_SIZE];
; *ht=t->next;
; } else {
; t->prev->next=t->next;
; }
; if (t->next!=NULL) t->next->prev=t->prev;
;
; for(i=0;i<MAX_TEXTURE_LEVELS;i++) {
; im=&t->images[i];
; if (im->pixmap != NULL) gl_free(im->pixmap);
; }
;
; gl_free(t);
;}
align 4
proc free_texture uses eax ebx ecx edx, context:dword, h:dword
mov edx,[context]
stdcall find_texture,edx,[h] ;t=find_texture(context,h)
cmp dword[eax+offs_text_prev],0 ;if (t.prev==NULL)
jne .else
mov edx,[edx+offs_cont_shared_state+4] ;edx = &context.shared_state.texture_hash_table[0]
mov ebx,[eax+offs_text_handle]
and ebx,0xff
shl ebx,2
add edx,ebx ;edx = &context.shared_state.texture_hash_table[t.handle % TEXTURE_HASH_TABLE_SIZE]
mov ebx,[eax+offs_text_next]
mov [edx],ebx ;*ht=t.next
jmp @f
.else:
mov ebx,[eax+offs_text_prev]
mov ecx,[eax+offs_text_next]
mov [ebx+offs_text_next],ecx ;t.prev.next=t.next
@@:
cmp dword[eax+offs_text_next],0 ;if (t.next!=NULL)
je @f
mov ebx,[eax+offs_text_next]
mov ecx,[eax+offs_text_prev]
mov [ebx+offs_text_prev],ecx ;t.next.prev=t.prev
@@:
xor ebx,ebx
mov ecx,[eax+offs_text_images] ;im=&t.images[0]
.cycle_0: ;for(i=0;i<MAX_TEXTURE_LEVELS;i++)
cmp ebx,MAX_TEXTURE_LEVELS
jge .cycle_0_end
cmp dword[ecx+offs_imag_pixmap],0 ;if (im.pixmap != NULL)
je @f
stdcall gl_free,[ecx+offs_imag_pixmap]
@@:
add ecx,sizeof.GLImage
inc ebx
jmp .cycle_0
.cycle_0_end:
stdcall gl_free,eax
ret
endp
;output:
; eax - указатель на память
@ -63,7 +84,7 @@ proc alloc_texture uses ebx ecx, context:dword, h:dword
mov ecx,[h]
and ecx,0xff
shl ecx,2
add ecx,[ebx] ;ecx = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
add ecx,ebx ;ecx = &context.shared_state.texture_hash_table[h % TEXTURE_HASH_TABLE_SIZE]
mov ebx,[ecx]
mov [eax+offs_text_next],ebx
@ -90,56 +111,94 @@ proc glInitTextures uses eax edx, context:dword
ret
endp
;void glGenTextures(int n, unsigned int *textures)
;{
; GLContext *c=gl_get_context();
; int max,i;
; GLTexture *t;
;
; max=0;
; for(i=0;i<TEXTURE_HASH_TABLE_SIZE;i++) {
; t=c->shared_state.texture_hash_table[i];
; while (t!=NULL) {
; if (t->handle>max) max=t->handle;
; t=t->next;
; }
;
; }
; for(i=0;i<n;i++) {
; textures[i]=max+i+1;
; }
;}
;
;
;void glDeleteTextures(int n, const unsigned int *textures)
;{
; GLContext *c=gl_get_context();
; int i;
; GLTexture *t;
;
; for(i=0;i<n;i++) {
; t=find_texture(c,textures[i]);
; if (t!=NULL && t!=0) {
; if (t==c->current_texture) {
; glBindTexture(GL_TEXTURE_2D,0);
; }
; free_texture(c,textures[i]);
; }
; }
;}
align 4
proc glGenTextures uses eax ebx ecx edx esi, n:dword, textures:dword
;edx - GLTexture *t
call gl_get_context
add eax,offs_cont_shared_state+4 ;offset texture_hash_table = 4
xor ebx,ebx ;max=0
xor ecx,ecx ;i=0
.cycle_0: ;for(i=0;i<TEXTURE_HASH_TABLE_SIZE;i++)
cmp ecx,TEXTURE_HASH_TABLE_SIZE
jge .cycle_0_end
mov esi,ecx
shl esi,2
add esi,[eax]
mov edx,dword[esi] ;t=context.shared_state.texture_hash_table[i]
.cycle_1: ;while (t!=NULL)
or edx,edx
jz .cycle_1_end
cmp [edx+offs_text_handle],ebx ;if (t.handle>max)
jle @f
mov ebx,[edx+offs_text_handle] ;max=t.handle
@@:
mov edx,[edx+offs_text_next] ;t=t.next
jmp .cycle_1
.cycle_1_end:
inc ecx
jmp .cycle_0
.cycle_0_end:
xor ecx,ecx ;i=0
mov esi,[textures]
.cycle_2: ;for(i=0;i<n;i++)
cmp ecx,[n]
jge .cycle_2_end
inc ebx
mov [esi],ebx ;textures[i]=max+i+1
add esi,4
inc ecx
jmp .cycle_2
.cycle_2_end:
ret
endp
align 4
proc glDeleteTextures uses eax ebx ecx edx, n:dword, textures:dword
call gl_get_context
mov edx,eax
mov ecx,[textures]
xor ebx,ebx
.cycle_0: ;for(i=0;i<n;i++)
cmp ebx,[n]
jge .cycle_0_end
stdcall find_texture,edx,[ecx] ;t=find_texture(context,textures[i])
or eax,eax ;if (t!=0)
jz @f
cmp eax,[edx+offs_cont_current_texture] ;if (t==context.current_texture)
jne .end_1
stdcall glBindTexture,GL_TEXTURE_2D,0
.end_1:
stdcall free_texture, edx,[ecx]
@@:
add ecx,4
inc ebx
jmp .cycle_0
.cycle_0_end:
ret
endp
align 4
proc glopBindTexture uses eax ebx edx, context:dword, p:dword
mov ebx,[p]
mov edx,[context]
; assert(p[1].i == GL_TEXTURE_2D && texture >= 0);
cmp dword[ebx+4],GL_TEXTURE_2D
je @f
;jne .error
;cmp dword[ebx+8],0
;jge @f
.error:
stdcall dbg_print,sz_glBindTexture,err_7
@@:
;[ebx+8] = p[2]
stdcall find_texture, edx,dword[ebx+8]
cmp eax,0 ;NULL
jne @f
stdcall alloc_texture, edx,dword[ebx+8]
mov ebx,[ebx+8] ;ebx = p[2]
stdcall find_texture, edx,ebx
or eax,eax ;if(t==NULL)
jnz @f
stdcall alloc_texture, edx,ebx
@@:
mov [edx+offs_cont_current_texture],eax
ret
@ -147,114 +206,170 @@ endp
align 4
proc glopTexImage2D, context:dword, p:dword
;{
; int target=p[1].i;
; int level=p[2].i;
; int components=p[3].i;
; int width=p[4].i;
; int height=p[5].i;
; int border=p[6].i;
; int format=p[7].i;
; int type=p[8].i;
; void *pixels=p[9].p;
; GLImage *im;
; unsigned char *pixels1;
; int do_free;
;
; if (!(target == GL_TEXTURE_2D && level == 0 && components == 3 &&
; border == 0 && format == GL_RGB &&
; type == GL_UNSIGNED_BYTE)) {
; gl_fatal_error("glTexImage2D: combinaison of parameters not handled");
; }
;
; do_free=0;
; if (width != 256 || height != 256) {
; pixels1 = gl_malloc(256 * 256 * 3);
; /* no interpolation is done here to respect the original image aliasing ! */
; gl_resizeImageNoInterpolate(pixels1,256,256,pixels,width,height);
; do_free=1;
; width=256;
; height=256;
; } else {
; pixels1=pixels;
; }
;
; im=&c->current_texture->images[level];
; im->xsize=width;
; im->ysize=height;
; if (im->pixmap!=NULL) gl_free(im->pixmap);
;#if TGL_FEATURE_RENDER_BITS == 24
; im->pixmap=gl_malloc(width*height*3);
; if(im->pixmap) {
; memcpy(im->pixmap,pixels1,width*height*3);
; }
;#elif TGL_FEATURE_RENDER_BITS == 32
; im->pixmap=gl_malloc(width*height*4);
; if(im->pixmap) {
; gl_convertRGB_to_8A8R8G8B(im->pixmap,pixels1,width,height);
; }
;#elif TGL_FEATURE_RENDER_BITS == 16
; im->pixmap=gl_malloc(width*height*2);
; if(im->pixmap) {
; gl_convertRGB_to_5R6G5B(im->pixmap,pixels1,width,height);
; }
;#else
;#error TODO
;#endif
; if (do_free) gl_free(pixels1);
locals
pixels1 dd ?
do_free dd ?
endl
pushad
mov edi,[p]
mov eax,[edi+4] ;target=p[1].i
mov ebx,[edi+8] ;level=p[2].i
mov ecx,[edi+12] ;components=p[3].i;
mov edx,[edi+16] ;width=p[4].i;
mov esi,[edi+20] ;height=p[5].i;
cmp eax,GL_TEXTURE_2D ;if (param != GL_TEXTURE_2D)
jne .error
or ebx,ebx ;if (level != 0)
jnz .error
cmp ecx,3 ;if (components != 3)
jne .error
cmp dword[edi+24],0 ;if (border != 0)
jne .error
cmp dword[edi+28],GL_RGB ;if (format != GL_RGB)
jne .error
cmp dword[edi+32],GL_UNSIGNED_BYTE ;if (type != GL_UNSIGNED_BYTE)
jne .error
jmp @f
.error:
stdcall dbg_print,sz_glTexImage2D,err_8 ;"glTexImage2D: combinaison of parameters not handled"
@@:
mov dword[do_free],0
cmp edx,256
jne .else
cmp esi,256
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)
; no interpolation is done here to respect the original image aliasing !
;gl_resizeImageNoInterpolate(eax,256,256,[edi+36],edx,esi)
mov dword[do_free],1
mov edx,256
mov esi,256
@@:
mov ecx,[context]
mov ecx,[ecx+offs_cont_current_texture]
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
cmp dword[ecx+offs_imag_pixmap],0 ;if (im.pixmap!=NULL)
je @f
stdcall gl_free, [ecx+offs_imag_pixmap]
@@:
if TGL_FEATURE_RENDER_BITS eq 24
imul edx,esi
imul edx,3
stdcall gl_malloc,edx
mov [ecx+offs_imag_pixmap],eax ;im.pixmap = gl_malloc(width*height*3)
or eax,eax ;if(im.pixmap)
jz @f
mov edi,eax
mov esi,[pixels1]
mov ecx,edx
rep movsb ;memcpy(im.pixmap,pixels1,width*height*3)
@@:
end if
if TGL_FEATURE_RENDER_BITS eq 32
mov ebx,edx
imul edx,esi
shl edx,2
stdcall gl_malloc,edx
mov [ecx+offs_imag_pixmap],eax ;im.pixmap = gl_malloc(width*height*4)
or eax,eax ;if(im.pixmap)
jz @f
;gl_convertRGB_to_8A8R8G8B(eax,[pixels1],ebx,esi)
@@:
end if
if TGL_FEATURE_RENDER_BITS eq 16
mov ebx,edx
imul edx,esi
shl edx,1
stdcall gl_malloc,edx
mov [ecx+offs_imag_pixmap],eax ;im.pixmap = gl_malloc(width*height*2)
or eax,eax ;if(im.pixmap)
jz @f
;gl_convertRGB_to_5R6G5B(eax,[pixels1],ebx,esi)
@@:
end if
cmp dword[do_free],0 ;if (do_free)
je @f
stdcall gl_free, [pixels1]
@@:
popad
ret
endp
; TODO: not all tests are done
align 4
proc glopTexEnv, context:dword, p:dword
proc glopTexEnv uses eax ebx ecx, context:dword, p:dword
mov ecx,[p]
mov eax,[ecx+4] ;target=p[1].i
mov ebx,[ecx+8] ;pname=p[2].i
mov ecx,[ecx+12] ;param=p[3].i
; int target=p[1].i;
; int pname=p[2].i;
; int param=p[3].i;
;
; if (target != GL_TEXTURE_ENV) {
; error:
; gl_fatal_error("glTexParameter: unsupported option");
; }
;
; if (pname != GL_TEXTURE_ENV_MODE) goto error;
;
; if (param != GL_DECAL) goto error;
cmp eax,GL_TEXTURE_ENV ;if (target != GL_TEXTURE_ENV)
jne .error
cmp ebx,GL_TEXTURE_ENV_MODE ;if (pname != GL_TEXTURE_ENV_MODE)
jne .error
cmp ecx,GL_DECAL ;if (param != GL_DECAL)
jne .error
jmp @f
.error:
stdcall dbg_print,sz_glTexParameteri,err_6
@@:
ret
endp
; TODO: not all tests are done
align 4
proc glopTexParameter, context:dword, p:dword
proc glopTexParameter uses eax ebx ecx, context:dword, p:dword
mov ecx,[p]
mov eax,[ecx+4] ;target=p[1].i
mov ebx,[ecx+8] ;pname=p[2].i
mov ecx,[ecx+12] ;param=p[3].i
; int target=p[1].i;
; int pname=p[2].i;
; int param=p[3].i;
;
; if (target != GL_TEXTURE_2D) {
; error:
; gl_fatal_error("glTexParameter: unsupported option");
; }
;
; switch(pname) {
; case GL_TEXTURE_WRAP_S:
; case GL_TEXTURE_WRAP_T:
; if (param != GL_REPEAT) goto error;
; break;
; }
cmp eax,GL_TEXTURE_2D ;if (target != GL_TEXTURE_2D)
jne .error
cmp ebx,GL_TEXTURE_WRAP_S
je @f
cmp ebx,GL_TEXTURE_WRAP_T
je @f
jmp .error
@@:
cmp ecx,GL_REPEAT ;if (param != GL_REPEAT)
jne .error
jmp @f
.error:
stdcall dbg_print,sz_glTexParameteri,err_6
@@:
ret
endp
align 4
proc glopPixelStore, context:dword, p:dword
proc glopPixelStore uses eax ebx, context:dword, p:dword
mov ebx,[p]
mov eax,[ebx+4] ;pname=p[1].i
mov ebx,[ebx+8] ;param=p[2].i
; int pname=p[1].i;
; int param=p[2].i;
;
; if (pname != GL_UNPACK_ALIGNMENT ||
; param != 1) {
; gl_fatal_error("glPixelStore: unsupported option");
; }
cmp eax,GL_UNPACK_ALIGNMENT ;if (pname != GL_UNPACK_ALIGNMENT)
jne .error
cmp ebx,1 ;if (param != 1)
jne .error
jmp @f
.error:
stdcall dbg_print,sz_glPixelStorei,err_6
@@:
ret
endp

View File

@ -86,13 +86,12 @@ endp
align 4
.str:
mov ecx,0x0a ;задается система счисления изменяются регистры ebx,eax,ecx,edx входные параметры eax - число
;преревод числа в ASCII строку взодные данные ecx=система счисленя edi адрес куда записывать, будем строку, причем конец переменной
;преревод числа в ASCII строку входные данные ecx=система счисленя edi адрес куда записывать, будем строку, причем конец переменной
cmp eax,ecx ;сравнить если в eax меньше чем в ecx то перейти на @@-1 т.е. на pop eax
jb @f
xor edx,edx ;очистить edx
div ecx ;разделить - остаток в edx
push edx ;положить в стек
;dec edi ;смещение необходимое для записи с конца строки
call .str ;перейти на саму себя т.е. вызвать саму себя и так до того момента пока в eax не станет меньше чем в ecx
pop eax
@@: ;cmp al,10 ;проверить не меньше ли значение в al чем 10 (для системы счисленя 10 данная команда - лишная))
@ -131,22 +130,21 @@ 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
f_zb_opn db ' ZB_open',0
err_1 db 'gl_malloc(sizeof.ZBuffer)==0',13,10,0
err_2 db 'gl_malloc(xsize*ysize*4)==0',13,10,0
err_3 db 'bit mode not correct',13,10,0
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
err_6 db 'unsupported option',13,10,0
err_7 db 'assert(target == GL_TEXTURE_2D && texture >= 0)',13,10,0
err_8 db 'combinaison of parameters not handled',13,10,0
err_9 db 'GL_INVALID_ENUM',13,10,0
f_zbz db ' ZB_line_z',0
f_zb db ' ZB_line',0
f_find_l db 'find_list',0

View File

@ -172,6 +172,8 @@ struct GLImage
ends
offs_imag_pixmap equ 0
offs_imag_xsize equ 4
offs_imag_ysize equ 8
; textures
@ -477,15 +479,6 @@ proc gl_clipcode uses ebx, x:dword, y:dword, z:dword, w1:dword
fincstp
mov eax,ebx
if DEBUG ;gl_clipcode
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_clipcode,buf_param
pop edi
end if
ret
endp

View File

@ -1,3 +1,9 @@
;
; Макрос DRAW_LINE имеет параметр code, от которого зависит
; будет ли включен код или объявлены переменные.
; В версии на C++ параметра code нет, потому что там переменные
; можно ставить в любом месте функции, в asm версии такое не проходит.
;
INTERP_Z equ 1
@ -111,34 +117,42 @@ if TGL_FEATURE_RENDER_BITS <> 16
end if
}
;;;DRAW_LINE_M equ 1
macro DRAW_LINE code
{
local .cycle_0
local .cycle_1
if TGL_FEATURE_RENDER_BITS eq 16
if code eq 0
pz dd ? ;uint*
tmp dd ? ;uint
z dd ? ;uint
zz dd ? ;uint
rgb dd ? ;uint
drgbdx dd ? ;uint
n dd ? ;int
end if
if code eq 1
mov eax,[x2]
sar eax,16
sub eax,[x1]
mov [n],eax ;n = (x2 >> 16) - x1
; pp=pp1+x1;
; pz=pz1+x1;
; z=z1;
; rgb=(r1 << 16) & 0xFFC00000;
; rgb|=(g1 >> 5) & 0x000007FF;
; rgb|=(b1 << 5) & 0x001FF000;
; drgbdx=_drgbdx;
mov edi,[pp1]
add edi,[x1] ;pp = pp1 + x1
mov eax,[pz1]
add eax,[x1]
mov [pz],eax ;pz = pz1 + x1
mov eax,[z1]
mov [z],eax ;z = z1
mov eax,[r1]
shl eax,16
and eax,0xFFC00000
mov [rgb],eax ;rgb = (r1 << 16) & 0xFFC00000
mov eax,[g1]
shr eax,5
and eax,0x000007FF
or [rgb],eax ;rgb |= (g1 >> 5) & 0x000007FF
mov eax,[b1]
shl eax,5
and eax,0x001FF000
or [rgb],eax ;rgb |= (b1 << 5) & 0x001FF000
mov eax,[_drgbdx]
mov [drgbdx],eax ;drgbdx = _drgbdx
align 4
.cycle_0: ;while (n>=3)
cmp dword[n],3
@ -148,7 +162,7 @@ align 4
PUT_PIXEL 2
PUT_PIXEL 3
add dword[pz],8
add edi,4
add edi,4*3
sub [n],4
jmp .cycle_0
.cycle_1: ;while (n>=0)
@ -156,7 +170,7 @@ align 4
jl .cycle_1_end
PUT_PIXEL 0
add dword[pz],2
inc edi
add edi,3
dec dword[n]
jmp .cycle_1
.cycle_1_end:
@ -202,11 +216,16 @@ local .end_0
;edi = pp
mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
if TGL_FEATURE_RENDER_BITS eq 24
; unsigned char *ptr;
; ptr = texture + (((t & 0x3FC00000) | s) >> 14) * 3;
; pp[3 * _a]= ptr[0];
; pp[3 * _a + 1]= ptr[1];
; pp[3 * _a + 2]= ptr[2];
mov ebx,[t]
and ebx,0x3fc00000
or ebx,[s]
shr ebx,14
imul ebx,3
add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | s) >> 14) * 3
mov ax,word[ebx]
mov word[edi+3*_a],ax ;pp[3 * _a]= ptr[0,1]
mov al,byte[ebx+2]
mov byte[edi+3*_a +2],al ;pp[3 * _a + 2]= ptr[2]
else
; pp[_a]=texture[((t & 0x3FC00000) | s) >> 14];
end if
@ -242,11 +261,17 @@ macro DRAW_INIT
mov eax,[zb]
mov eax,[eax+offs_zbuf_current_texture]
mov [texture],eax
mov dword[esp-4],NB_INTERP
fild dword[esp-4]
fild dword[dzdx]
fstp dword[fdzdx]
; fndzdx=NB_INTERP * fdzdx;
; ndszdx=NB_INTERP * dszdx;
; ndtzdx=NB_INTERP * dtzdx;
fst dword[fdzdx] ;fdzdx = (float)dzdx
fmul st0,st1
fstp dword[fndzdx] ;fndzdx = NB_INTERP * fdzdx
fld dword[fdzdx]
fmul st0,st1
fstp dword[ndszdx] ;ndszdx = NB_INTERP * dszdx
fmul dword[dtzdx]
fstp dword[ndtzdx] ;ndtzdx = NB_INTERP * dtzdx
}
macro PUT_PIXEL _a
@ -261,11 +286,18 @@ local .end_0
;edi = pp
mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
if TGL_FEATURE_RENDER_BITS eq 24
; unsigned char *ptr;
; ptr = texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> 14) * 3;
; pp[3 * _a]= ptr[0];
; pp[3 * _a + 1]= ptr[1];
; pp[3 * _a + 2]= ptr[2];
mov ebx,[t]
and ebx,0x3fc00000
mov eax,[s]
and eax,0x003fc000
or ebx,eax
shr ebx,14
imul ebx,3
add ebx,[texture] ;ptr = texture + (((t & 0x3fc00000) | (s & 0x003FC000)) >> 14) * 3
mov ax,word[ebx]
mov word[edi+3*_a],ax ;pp[3 * _a]= ptr[0,1]
mov al,byte[ebx+2]
mov byte[edi+3*_a +2],al ;pp[3 * _a + 2]= ptr[2]
else
; pp[_a]=*(PIXEL *)((char *)texture+
; (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));
@ -285,69 +317,109 @@ macro DRAW_LINE code
{
if TGL_FEATURE_RENDER_BITS eq 24
if code eq 0
pz dd ? ;uint *
s dd ? ;uint
t dd ? ;uint
z dd ? ;uint
zz dd ? ;uint
n1 dd ? ;int - длинна горизонтальной линии в пикселях
dsdx dd ? ;int
dtdx dd ? ;int
s_z dd ? ;float
t_z dd ? ;float
fz dd ? ;float
zinv dd ? ;float
end if
if code eq 1
; n1=(x2>>16)-x1;
; fz=(float)z1;
; zinv=1.0 / fz;
; pp=(pp1 + x1 * PSZB);
; pz=pz1+x1;
; z=z1;
; sz=sz1;
; tz=tz1;
; while (n1>=(NB_INTERP-1)) {
; {
; float ss,tt;
; ss=(sz * zinv);
; tt=(tz * zinv);
; s=(int) ss;
; t=(int) tt;
; dsdx= (int)( (dszdx - ss*fdzdx)*zinv );
; dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );
; fz+=fndzdx;
; zinv=1.0 / fz;
; }
; PUT_PIXEL(0);
; PUT_PIXEL(1);
; PUT_PIXEL(2);
; PUT_PIXEL(3);
; PUT_PIXEL(4);
; PUT_PIXEL(5);
; PUT_PIXEL(6);
; PUT_PIXEL(7);
; pz+=NB_INTERP;
; pp=(pp + NB_INTERP * PSZB);
; n1-=NB_INTERP;
; sz+=ndszdx;
; tz+=ndtzdx;
; }
; {
; float ss,tt;
; ss=(sz * zinv);
; tt=(tz * zinv);
; s=(int) ss;
; t=(int) tt;
; dsdx= (int)( (dszdx - ss*fdzdx)*zinv );
; dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );
; }
; while (n1>=0) {
;;; PUT_PIXEL 0
; pz+=1;
; pp=(PIXEL *)((char *)pp + PSZB);
mov eax,[x2]
sar eax,16
sub eax,[x1]
mov [n1],eax ;n1 = (x2 >> 16) - x1
fld1
fild dword[z1]
fst dword[fz] ;fz = (float)z1
;fld1
fdivp
fstp dword[zinv] ;zinv = 1.0 / fz
mov edi,[x1]
imul edi,PSZB
add edi,[pp1] ;pp = (pp1 + x1 * PSZB)
mov eax,[pz1]
add eax,[x1]
mov [pz],eax ;pz = pz1 + x1
mov eax,[z1]
mov [z],eax ;z = z1
mov eax,[sz1]
mov [s_z],eax ;sz = sz1
mov eax,[tz1]
mov [t_z],eax ;tz = tz1
align 4
.cycle_2: ;while (n1>=(NB_INTERP-1))
cmp dword[n1],NB_INTERP-1
jl .cycle_2_end
fld dword[zinv]
fld st0
fmul dword[s_z] ;ss = (sz * zinv)
fist dword[s] ;s = (int) ss
fmul dword[fdzdx]
fchs
fadd dword[dszdx]
fmul dword[zinv]
fistp dword[dsdx] ;dsdx = (int)( (dszdx - ss*fdzdx)*zinv )
fmul dword[t_z] ;tt = (tz * zinv)
fist dword[t] ;t = (int) tt
fmul dword[fdzdx]
fchs
fadd dword[dtzdx]
fmul dword[zinv]
fistp dword[dtdx] ;dtdx = (int)( (dtzdx - tt*fdzdx)*zinv )
fld1
fld dword[fz]
fadd dword[fndzdx]
fst dword[fz] ;fz += fndzdx
;fld1
fdivp
fstp dword[zinv] ;zinv = 1.0 / fz
PUT_PIXEL 0
PUT_PIXEL 1
PUT_PIXEL 2
PUT_PIXEL 3
PUT_PIXEL 4
PUT_PIXEL 5
PUT_PIXEL 6
PUT_PIXEL 7
add dword[pz],2*NB_INTERP ;pz += NB_INTERP
add edi,NB_INTERP*PSZB ;pp += NB_INTERP * PSZB
sub dword[n1],NB_INTERP ;n1 -= NB_INTERP
fld dword[ndszdx]
fadd dword[s_z]
fstp dword[s_z] ;s_z += ndszdx
fld dword[ndtzdx]
fadd dword[t_z]
fstp dword[t_z] ;tz += ndtzdx
jmp .cycle_2
.cycle_2_end:
fld dword[zinv]
fld st0
fmul dword[s_z] ;ss = (sz * zinv)
fist dword[s] ;s = (int) ss
fmul dword[fdzdx]
fchs
fadd dword[dszdx]
fmul dword[zinv]
fistp dword[dsdx] ;dsdx = (int)( (dszdx - ss*fdzdx)*zinv )
fmul dword[t_z] ;tt = (tz * zinv)
fist dword[t] ;t = (int) tt
fmul dword[fdzdx]
fchs
fadd dword[dtzdx]
fmul dword[zinv]
fistp dword[dtdx] ;dtdx = (int)( (dtzdx - tt*fdzdx)*zinv )
align 4
.cycle_3: ;while (n1>=0)
cmp dword[n1],0
jl .cycle_3_end
PUT_PIXEL 0
add dword[pz],2 ;pz += 1
add edi,PSZB ;pp += PSZB
dec dword[n1]
; }
jmp .cycle_3
.cycle_3_end:
end if
end if
}

View File

@ -20,7 +20,6 @@
; цвет испорченных пикселей. Цвет получаеться наиболее близким к указанному
; пользователем.
t dd ? ;ZBufferPoint*
pr1 dd ? ;ZBufferPoint*
pr2 dd ? ;ZBufferPoint*
l1 dd ? ;ZBufferPoint*
@ -53,6 +52,10 @@
x2 dd ? ;int
dx2dy2 dd ? ;int
pz dd ? ;unsigned short *
z dd ? ;uint
zz dd ? ;uint
if INTERP_Z eq 1
z1 dd ? ;int
dzdx dd ? ;int
@ -100,18 +103,10 @@ if INTERP_STZ eq 1
dtzdy dd ? ;float
dtzdl_min dd ? ;float
dtzdl_max dd ? ;float
s_z dd ? ;float
t_z dd ? ;float
end if
if DRAW_LINE_M eq 1
DRAW_LINE 0 ;переменные делаются в макросе
else
n dd ? ;int - длинна горизонтальной линии в пикселях
if INTERP_Z eq 1
pz dd ? ;unsigned short *
z dd ? ;uint
zz dd ? ;uint
end if
if INTERP_RGB eq 1
or1 dd ? ;uint
og1 dd ? ;uint
@ -121,19 +116,14 @@ if INTERP_ST eq 1
s dd ? ;uint
t dd ? ;uint
end if
if INTERP_STZ eq 1
s_z dd ? ;float
t_z dd ? ;float
end if
if DRAW_LINE_M eq 1
DRAW_LINE 0 ;переменные делаются в макросе
end if
endl
pushad
if DEBUG ;(1)
stdcall dbg_print,f_fill_tr,m_1
end if
; we sort the vertex with increasing y
mov ebx,[p0]
mov ecx,[p1]