forked from KolibriOS/kolibrios
some fixes
git-svn-id: svn://kolibrios.org@5256 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
f8f660cfef
commit
40df1da8cf
@ -0,0 +1,230 @@
|
|||||||
|
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
|
||||||
|
stdcall [glShadeModel], GL_SMOOTH
|
||||||
|
|
||||||
|
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]
|
||||||
|
call SetLight
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
align 4
|
||||||
|
SetLight:
|
||||||
|
stdcall [glLightfv], GL_LIGHT0, GL_POSITION, light_position
|
||||||
|
stdcall [glLightfv], GL_LIGHT0, GL_SPOT_DIRECTION, light_dir
|
||||||
|
|
||||||
|
stdcall [glLightfv], GL_LIGHT0, GL_DIFFUSE, white_light
|
||||||
|
stdcall [glLightfv], GL_LIGHT0, GL_SPECULAR, white_light
|
||||||
|
|
||||||
|
stdcall [glEnable], GL_COLOR_MATERIAL
|
||||||
|
stdcall [glColorMaterial], GL_FRONT, GL_AMBIENT_AND_DIFFUSE
|
||||||
|
stdcall [glMaterialfv], GL_FRONT, GL_SPECULAR, mat_specular
|
||||||
|
stdcall [glMaterialf], GL_FRONT, GL_SHININESS, mat_shininess
|
||||||
|
stdcall [glLightModelfv], GL_LIGHT_MODEL_AMBIENT, lmodel_ambient
|
||||||
|
|
||||||
|
stdcall [glEnable],GL_LIGHTING
|
||||||
|
stdcall [glEnable],GL_LIGHT0
|
||||||
|
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
|
||||||
|
|
||||||
|
light_position dd 0.0, 0.0, 2.0, 1000.0 ; Расположение источника [0][1][2], чем ближе [3] к 0, тем ярче свет
|
||||||
|
light_dir dd 0.0,0.0,0.0 ;направление лампы
|
||||||
|
mat_specular dd 0.3, 0.3, 0.3, 1.0 ; Цвет блика
|
||||||
|
mat_shininess dd 3.0 ; Размер блика (обратная пропорция)
|
||||||
|
white_light dd 0.8, 0.8, 0.8, 1.0 ; Цвет и интенсивность освещения, генерируемого источником
|
||||||
|
lmodel_ambient dd 0.2, 0.2, 0.2, 1.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:
|
@ -1,51 +1,76 @@
|
|||||||
;include 'msghandling.inc'
|
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc glopMaterial, context:dword, p:dword
|
proc glopMaterial uses eax ebx ecx edi esi, context:dword, p:dword
|
||||||
; int mode=p[1].i;
|
; edi -> GLMaterial *m
|
||||||
; int type=p[2].i;
|
mov eax,[context]
|
||||||
; float *v=&p[3].f;
|
mov ebx,[p]
|
||||||
; int i;
|
mov ecx,[ebx+4] ;ecx = p[1]
|
||||||
; GLMaterial *m;
|
|
||||||
|
|
||||||
; if (mode == GL_FRONT_AND_BACK) {
|
cmp ecx,GL_FRONT_AND_BACK ;if (mode == GL_FRONT_AND_BACK)
|
||||||
; p[1].i=GL_FRONT;
|
jne @f
|
||||||
; glopMaterial(c,p);
|
mov dword[ebx+4],GL_FRONT ;p[1].i=GL_FRONT
|
||||||
; mode=GL_BACK;
|
mov edi,ebp
|
||||||
; }
|
add edi,12
|
||||||
; if (mode == GL_FRONT) m=&c->materials[0];
|
stdcall glopMaterial,eax,edi
|
||||||
; else m=&c->materials[1];
|
mov ecx,GL_BACK
|
||||||
|
@@:
|
||||||
|
mov edi,[eax+offs_cont_materials]
|
||||||
|
cmp ecx,GL_FRONT ;if (mode == GL_FRONT) m=&context.materials[0]
|
||||||
|
je @f
|
||||||
|
add edi,sizeof.GLMaterial ;else m=&context.materials[1]
|
||||||
|
@@:
|
||||||
|
|
||||||
; switch(type) {
|
mov ecx,4
|
||||||
; case GL_EMISSION:
|
mov esi,ebx ;esi = &p
|
||||||
; for(i=0;i<4;i++)
|
add esi,12 ;esi = &p[3]
|
||||||
; m->emission.v[i]=v[i];
|
mov ebx,[ebx+8] ;ebx = p[2]
|
||||||
; break;
|
cmp ebx,GL_EMISSION
|
||||||
; case GL_AMBIENT:
|
jne @f
|
||||||
; for(i=0;i<4;i++)
|
;add edi,offs_mate_emission ;offs_mate_emission=0
|
||||||
; m->ambient.v[i]=v[i];
|
rep movsd
|
||||||
; break;
|
jmp .end_f
|
||||||
; case GL_DIFFUSE:
|
@@:
|
||||||
; for(i=0;i<4;i++)
|
cmp ebx,GL_AMBIENT
|
||||||
; m->diffuse.v[i]=v[i];
|
jne @f
|
||||||
; break;
|
add edi,offs_mate_ambient
|
||||||
; case GL_SPECULAR:
|
rep movsd
|
||||||
; for(i=0;i<4;i++)
|
jmp .end_f
|
||||||
; m->specular.v[i]=v[i];
|
@@:
|
||||||
; break;
|
cmp ebx,GL_DIFFUSE
|
||||||
; case GL_SHININESS:
|
jne @f
|
||||||
; m->shininess=v[0];
|
add edi,offs_mate_diffuse
|
||||||
; m->shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION;
|
rep movsd
|
||||||
; break;
|
jmp .end_f
|
||||||
; case GL_AMBIENT_AND_DIFFUSE:
|
@@:
|
||||||
; for(i=0;i<4;i++)
|
cmp ebx,GL_SPECULAR
|
||||||
; m->diffuse.v[i]=v[i];
|
jne @f
|
||||||
; for(i=0;i<4;i++)
|
add edi,offs_mate_specular
|
||||||
; m->ambient.v[i]=v[i];
|
rep movsd
|
||||||
; break;
|
jmp .end_f
|
||||||
; default:
|
@@:
|
||||||
|
cmp ebx,GL_SHININESS
|
||||||
|
jne @f
|
||||||
|
fld dword[esi]
|
||||||
|
add edi,offs_mate_shininess
|
||||||
|
movsd
|
||||||
|
mov dword[edi],SPECULAR_BUFFER_RESOLUTION
|
||||||
|
fdiv dword[an180f]
|
||||||
|
fimul dword[edi]
|
||||||
|
fistp dword[edi] ;m.shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION
|
||||||
|
jmp .end_f
|
||||||
|
@@:
|
||||||
|
cmp ebx,GL_AMBIENT_AND_DIFFUSE
|
||||||
|
jne @f
|
||||||
|
add edi,offs_mate_ambient
|
||||||
|
rep movsd
|
||||||
|
sub esi,16
|
||||||
|
;edi = &offs_mate_diffuse
|
||||||
|
mov ecx,4
|
||||||
|
rep movsd
|
||||||
|
jmp .end_f
|
||||||
|
@@: ;default
|
||||||
; assert(0);
|
; assert(0);
|
||||||
; }
|
.end_f:
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
@ -61,13 +86,15 @@ proc glopColorMaterial uses eax ebx ecx, context:dword, p:dword
|
|||||||
endp
|
endp
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc glopLight uses eax ebx ecx edx, context:dword, p:dword
|
proc glopLight context:dword, p:dword
|
||||||
|
locals
|
||||||
|
pos V4
|
||||||
|
endl
|
||||||
|
pushad
|
||||||
mov eax,[context]
|
mov eax,[context]
|
||||||
mov ebx,[p]
|
mov ebx,[p]
|
||||||
mov edx,[ebx+4] ;edx = p[1]
|
mov edx,[ebx+4] ;edx = p[1]
|
||||||
|
|
||||||
; V4 v;
|
|
||||||
|
|
||||||
; assert(edx >= GL_LIGHT0 && edx < GL_LIGHT0+MAX_LIGHTS );
|
; assert(edx >= GL_LIGHT0 && edx < GL_LIGHT0+MAX_LIGHTS );
|
||||||
|
|
||||||
sub edx,GL_LIGHT0
|
sub edx,GL_LIGHT0
|
||||||
@ -108,26 +135,40 @@ proc glopLight uses eax ebx ecx edx, context:dword, p:dword
|
|||||||
@@:
|
@@:
|
||||||
cmp ecx,GL_POSITION
|
cmp ecx,GL_POSITION
|
||||||
jne @f
|
jne @f
|
||||||
; {
|
mov edi,ebx ;ebx = [ebp+12] = [p] = &p[0]
|
||||||
; for(i=0;i<4;i++) v.v[i]=p[3+i].f;
|
add edi,12 ;&p[3]
|
||||||
; V4 pos;
|
mov esi,ebp
|
||||||
; gl_M4_MulV4(&pos,c->matrix_stack_ptr[0],&v);
|
sub esi,16 ;&pos
|
||||||
;
|
stdcall gl_M4_MulV4, esi,dword[eax+offs_cont_matrix_stack_ptr],edi
|
||||||
; l->position=pos;
|
mov edi,edx
|
||||||
;
|
add edi,offs_ligh_position
|
||||||
; if (l->position.v[3] == 0) {
|
mov ecx,4
|
||||||
; l->norm_position.X=pos.X;
|
rep movsd ;l.position=pos
|
||||||
; l->norm_position.Y=pos.Y;
|
|
||||||
; l->norm_position.Z=pos.Z;
|
fld dword[edi-4] ;if(l.position.v[3] == 0)
|
||||||
;
|
ftst
|
||||||
; gl_V3_Norm(&l->norm_position);
|
fstsw ax
|
||||||
; }
|
sahf
|
||||||
; }
|
jne .end_i
|
||||||
|
;mov esi,ebp
|
||||||
|
sub esi,16 ;&pos
|
||||||
|
mov edi,edx
|
||||||
|
add edi,offs_ligh_norm_position
|
||||||
|
mov ecx,3
|
||||||
|
rep movsd ;l.norm_position=pos[1,2,3]
|
||||||
|
|
||||||
|
;mov edi,edx
|
||||||
|
;add edi,offs_ligh_norm_position
|
||||||
|
sub edi,12
|
||||||
|
stdcall gl_V3_Norm,edi ;&l.norm_position
|
||||||
|
.end_i:
|
||||||
|
ffree st0
|
||||||
|
fincstp
|
||||||
jmp .end_f
|
jmp .end_f
|
||||||
@@:
|
@@:
|
||||||
cmp ecx,GL_SPOT_DIRECTION
|
cmp ecx,GL_SPOT_DIRECTION
|
||||||
jne @f
|
jne @f
|
||||||
mov esi,ebx
|
mov esi,ebx ;&p[0]
|
||||||
add esi,12
|
add esi,12
|
||||||
mov edi,edx
|
mov edi,edx
|
||||||
add edi,offs_ligh_spot_direction
|
add edi,offs_ligh_spot_direction
|
||||||
@ -150,15 +191,25 @@ proc glopLight uses eax ebx ecx edx, context:dword, p:dword
|
|||||||
jmp .end_f
|
jmp .end_f
|
||||||
@@:
|
@@:
|
||||||
cmp ecx,GL_SPOT_CUTOFF
|
cmp ecx,GL_SPOT_CUTOFF
|
||||||
jne @f
|
jne .end_spot_c
|
||||||
; {
|
fld dword[ebp+12] ;float a=v.v[0]
|
||||||
; float a=v.v[0];
|
|
||||||
; assert(a == 180 || (a>=0 && a<=90));
|
; assert(a == 180 || (a>=0 && a<=90));
|
||||||
; l->spot_cutoff=a;
|
fst dword[edi+offs_ligh_spot_cutoff] ;l.spot_cutoff=a
|
||||||
; if (a != 180) l->cos_spot_cutoff=cos(a * M_PI / 180.0);
|
fcom dword[an180f] ;if (a != 180)
|
||||||
; }
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jne @f
|
||||||
|
fldpi
|
||||||
|
fmulp
|
||||||
|
fdiv dword[an180f]
|
||||||
|
fcos
|
||||||
|
fstp dword[edi+offs_ligh_spot_cutoff] ;l.cos_spot_cutoff=cos(a * M_PI / 180.0)
|
||||||
jmp .end_f
|
jmp .end_f
|
||||||
@@:
|
@@:
|
||||||
|
ffree st0
|
||||||
|
fincstp
|
||||||
|
jmp .end_f
|
||||||
|
.end_spot_c:
|
||||||
cmp ecx,GL_CONSTANT_ATTENUATION
|
cmp ecx,GL_CONSTANT_ATTENUATION
|
||||||
mov ecx,[ebx+12]
|
mov ecx,[ebx+12]
|
||||||
mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3]
|
mov [edi+offs_ligh_attenuation],ecx ;l->attenuation[0]=p[3]
|
||||||
@ -176,6 +227,7 @@ proc glopLight uses eax ebx ecx edx, context:dword, p:dword
|
|||||||
@@: ;default:
|
@@: ;default:
|
||||||
; assert(0);
|
; assert(0);
|
||||||
.end_f:
|
.end_f:
|
||||||
|
popad
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
@ -184,46 +236,69 @@ align 4
|
|||||||
proc glopLightModel uses ebx ecx esi edi, context:dword, p:dword
|
proc glopLightModel uses ebx ecx esi edi, context:dword, p:dword
|
||||||
mov edi,[context]
|
mov edi,[context]
|
||||||
mov ebx,[p]
|
mov ebx,[p]
|
||||||
mov esi,[ebx+8]
|
mov ebx,[ebx+4]
|
||||||
|
mov esi,[ebp+12] ;&p[0]
|
||||||
|
add esi,8 ;&p[2]
|
||||||
|
|
||||||
cmp dword[ebx+4],GL_LIGHT_MODEL_AMBIENT
|
cmp ebx,GL_LIGHT_MODEL_AMBIENT
|
||||||
jne @f
|
jne @f
|
||||||
mov ecx,4
|
mov ecx,4
|
||||||
mov edi,dword[edi+offs_cont_ambient_light_model]
|
add edi,offs_cont_ambient_light_model
|
||||||
rep movsd ;for(i=0;i<4;i++) context.ambient_light_model.v[i]=v[i]
|
rep movsd ;for(i=0;i<4;i++) context.ambient_light_model.v[i]=v[i]
|
||||||
jmp .end_f
|
jmp .end_f
|
||||||
@@:
|
@@:
|
||||||
cmp dword[ebx+4],GL_LIGHT_MODEL_LOCAL_VIEWER
|
cmp ebx,GL_LIGHT_MODEL_LOCAL_VIEWER
|
||||||
jne @f
|
jne @f
|
||||||
fld dword[esi] ;st0 = p[2].v[0]
|
fld dword[esi] ;st0 = p[2]
|
||||||
fistp dword[edi+offs_cont_local_light_model]
|
fistp dword[edi+offs_cont_local_light_model]
|
||||||
jmp .end_f
|
jmp .end_f
|
||||||
@@:
|
@@:
|
||||||
cmp dword[ebx+4],GL_LIGHT_MODEL_TWO_SIDE
|
cmp ebx,GL_LIGHT_MODEL_TWO_SIDE
|
||||||
jne @f
|
jne @f
|
||||||
fld dword[esi] ;st0 = p[2].v[0]
|
fld dword[esi] ;st0 = p[2]
|
||||||
fistp dword[edi+offs_cont_light_model_two_side]
|
fistp dword[edi+offs_cont_light_model_two_side]
|
||||||
jmp .end_f
|
jmp .end_f
|
||||||
@@: ;default:
|
@@: ;default:
|
||||||
; tgl_warning("glopLightModel: illegal pname: 0x%x\n", dword[ebx+4]);
|
; tgl_warning("glopLightModel: illegal pname: 0x%x\n", ebx);
|
||||||
; //assert(0);
|
; //assert(0);
|
||||||
.end_f:
|
.end_f:
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
;static inline float clampf(float a,float min,float max)
|
macro clampf a, min, max
|
||||||
;{
|
{
|
||||||
; if (a<min) return min;
|
local .o_1
|
||||||
; else if (a>max) return max;
|
local .o_2
|
||||||
; else return a;
|
local .end_m
|
||||||
;}
|
fld dword a ;if (a<=0.0)
|
||||||
|
ftst
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
ja .o_1
|
||||||
|
ffree st0
|
||||||
|
fincstp
|
||||||
|
mov eax,0.0
|
||||||
|
jmp .end_m ;return 0.0
|
||||||
|
.o_1:
|
||||||
|
fld1 ;else if (a>=1.0)
|
||||||
|
fcompp
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jb .o_2
|
||||||
|
mov eax,1.0
|
||||||
|
jmp .end_m ;return 1.0
|
||||||
|
.o_2:
|
||||||
|
mov eax,dword a ;else return a
|
||||||
|
.end_m:
|
||||||
|
}
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dword
|
proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dword
|
||||||
mov eax,[context]
|
mov eax,[context]
|
||||||
mov ebx,[light]
|
mov ebx,[light]
|
||||||
imul ebx,sizeof.GLLight
|
imul ebx,sizeof.GLLight
|
||||||
add ebx,[eax+offs_cont_lights]
|
add ebx,eax
|
||||||
|
add ebx,offs_cont_lights
|
||||||
|
|
||||||
xor ecx,ecx
|
xor ecx,ecx
|
||||||
cmp dword[ebx+offs_ligh_enabled],0
|
cmp dword[ebx+offs_ligh_enabled],0
|
||||||
@ -231,8 +306,8 @@ proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dwo
|
|||||||
not ecx
|
not ecx
|
||||||
@@:
|
@@:
|
||||||
and ecx,[v]
|
and ecx,[v]
|
||||||
cmp ecx,0
|
or ecx,ecx
|
||||||
je @f
|
jz @f
|
||||||
;if (v && !l.enabled)
|
;if (v && !l.enabled)
|
||||||
mov dword[ebx+offs_ligh_enabled],1
|
mov dword[ebx+offs_ligh_enabled],1
|
||||||
mov ecx,[eax+offs_cont_first_light]
|
mov ecx,[eax+offs_cont_first_light]
|
||||||
@ -247,8 +322,8 @@ proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dwo
|
|||||||
not ecx
|
not ecx
|
||||||
@@:
|
@@:
|
||||||
and ecx,[ebx+offs_ligh_enabled]
|
and ecx,[ebx+offs_ligh_enabled]
|
||||||
cmp ecx,0
|
or ecx,ecx
|
||||||
je .end_f
|
jz .end_f
|
||||||
;else if (!v && l.enabled)
|
;else if (!v && l.enabled)
|
||||||
mov dword[ebx+offs_ligh_enabled],0 ;l.enabled = 0
|
mov dword[ebx+offs_ligh_enabled],0 ;l.enabled = 0
|
||||||
mov ecx,[ebx+offs_ligh_next]
|
mov ecx,[ebx+offs_ligh_next]
|
||||||
@ -269,130 +344,388 @@ proc gl_enable_disable_light uses eax ebx ecx, context:dword, light:dword, v:dwo
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
align 4
|
||||||
|
fl_1e_3 dd 1.0e-3
|
||||||
|
|
||||||
; non optimized lightening model
|
; non optimized lightening model
|
||||||
align 4
|
align 4
|
||||||
proc gl_shade_vertex, context:dword, v:dword
|
proc gl_shade_vertex, context:dword, v:dword
|
||||||
|
locals
|
||||||
|
R dd ? ;float
|
||||||
|
G dd ? ;float
|
||||||
|
B dd ? ;float
|
||||||
|
A dd ? ;float
|
||||||
|
s V3
|
||||||
|
d V3
|
||||||
|
dist dd ? ;float
|
||||||
|
tmp dd ? ;float
|
||||||
|
att dd ? ;float
|
||||||
|
dot_spot dd ? ;float
|
||||||
|
lR dd ? ;float
|
||||||
|
lB dd ? ;float
|
||||||
|
lG dd ? ;float
|
||||||
|
twoside dd ? ;int
|
||||||
|
idx dd ? ;int
|
||||||
|
n V3 ;ebp-24
|
||||||
|
vcoord V3 ;ebp-12
|
||||||
|
endl
|
||||||
|
pushad
|
||||||
|
; ebx -> GLLight *l
|
||||||
|
; ecx -> GLMaterial *m
|
||||||
|
; esi -> GLVertex *v
|
||||||
|
mov esi,[v]
|
||||||
|
mov edx,[context]
|
||||||
|
mov ecx,[edx+offs_cont_materials] ;ecx(m) = &context.materials[0]
|
||||||
|
mov eax,[edx+offs_cont_light_model_two_side]
|
||||||
|
mov [twoside],eax
|
||||||
|
|
||||||
; float R,G,B,A;
|
add esi,offs_vert_normal
|
||||||
; GLMaterial *m;
|
mov edi,ebp
|
||||||
; GLLight *l;
|
sub edi,24 ;edi = &n
|
||||||
; V3 n,s,d;
|
movsd ;n.X=v.normal.X
|
||||||
; float dist,tmp,att,dot,dot_spot,dot_spec;
|
movsd ;n.Y=v.normal.Y
|
||||||
; int twoside = c->light_model_two_side;
|
movsd ;n.Z=v.normal.Z
|
||||||
|
mov esi,[v]
|
||||||
|
|
||||||
; m=&c->materials[0];
|
fld dword[edx+offs_cont_ambient_light_model]
|
||||||
|
fmul dword[ecx+offs_mate_ambient]
|
||||||
|
fadd dword[ecx] ;offs_mate_emission=0
|
||||||
|
fstp dword[R] ;R=m.emission.v[0]+m.ambient.v[0]*context.ambient_light_model.v[0]
|
||||||
|
fld dword[edx+offs_cont_ambient_light_model+4]
|
||||||
|
fmul dword[ecx+offs_mate_ambient+4]
|
||||||
|
fadd dword[ecx+offs_mate_emission+4]
|
||||||
|
fstp dword[G]
|
||||||
|
fld dword[edx+offs_cont_ambient_light_model+8]
|
||||||
|
fmul dword[ecx+offs_mate_ambient+8]
|
||||||
|
fadd dword[ecx+offs_mate_emission+8]
|
||||||
|
fstp dword[B]
|
||||||
|
clampf [ecx+offs_mate_diffuse+12],0,1
|
||||||
|
mov [A],eax ;A=clampf(m.diffuse.v[3],0,1)
|
||||||
|
|
||||||
; n.X=v->normal.X;
|
mov ebx,[edx+offs_cont_first_light]
|
||||||
; n.Y=v->normal.Y;
|
.cycle_0: ;for(l=context.first_light;l!=NULL;l=l.next)
|
||||||
; n.Z=v->normal.Z;
|
or ebx,ebx
|
||||||
|
jz .cycle_0_end
|
||||||
|
|
||||||
; R=m->emission.v[0]+m->ambient.v[0]*c->ambient_light_model.v[0];
|
; ambient
|
||||||
; G=m->emission.v[1]+m->ambient.v[1]*c->ambient_light_model.v[1];
|
fld dword[ecx+offs_mate_ambient]
|
||||||
; B=m->emission.v[2]+m->ambient.v[2]*c->ambient_light_model.v[2];
|
fmul dword[ebx+offs_ligh_ambient]
|
||||||
; A=clampf(m->diffuse.v[3],0,1);
|
fstp dword[lR] ;lR=l.ambient.v[0] * m.ambient.v[0]
|
||||||
|
fld dword[ecx+offs_mate_ambient+4]
|
||||||
|
fmul dword[ebx+offs_ligh_ambient+4]
|
||||||
|
fstp dword[lG] ;lG=l.ambient.v[1] * m.ambient.v[1]
|
||||||
|
fld dword[ecx+offs_mate_ambient+8]
|
||||||
|
fmul dword[ebx+offs_ligh_ambient+8]
|
||||||
|
fstp dword[lB] ;lB=l.ambient.v[2] * m.ambient.v[2]
|
||||||
|
|
||||||
; for(l=c->first_light;l!=NULL;l=l->next) {
|
cmp dword[ebx+offs_ligh_position+12],0 ;if (l.position.v[3] == 0)
|
||||||
; float lR,lB,lG;
|
jne .els_0
|
||||||
|
; light at infinity
|
||||||
|
mov eax,[ebx+offs_ligh_position]
|
||||||
|
mov [d],eax ;d.X=l.position.v[0]
|
||||||
|
mov eax,[ebx+offs_ligh_position+4]
|
||||||
|
mov [d+4],eax ;d.Y=l.position.v[1]
|
||||||
|
mov eax,[ebx+offs_ligh_position+8]
|
||||||
|
mov [d+8],eax ;d.Z=l.position.v[2]
|
||||||
|
mov dword[att],1.0
|
||||||
|
jmp .els_0_end
|
||||||
|
.els_0:
|
||||||
|
; distance attenuation
|
||||||
|
fld dword[ebx+offs_ligh_position]
|
||||||
|
fsub dword[esi+offs_vert_ec]
|
||||||
|
fstp dword[d] ;d.X=l.position.v[0]-v.ec.v[0]
|
||||||
|
fld dword[ebx+offs_ligh_position+offs_Y]
|
||||||
|
fsub dword[esi+offs_vert_ec+offs_Y]
|
||||||
|
fstp dword[d+offs_Y] ;d.Y=l.position.v[1]-v.ec.v[1]
|
||||||
|
fld dword[ebx+offs_ligh_position+offs_Z]
|
||||||
|
fsub dword[esi+offs_vert_ec+offs_Z]
|
||||||
|
fstp dword[d+offs_Z] ;d.Z=l.position.v[2]-v.ec.v[2]
|
||||||
|
fld dword[d]
|
||||||
|
fmul st0,st0
|
||||||
|
fld dword[d+offs_Y]
|
||||||
|
fmul st0,st0
|
||||||
|
faddp
|
||||||
|
fld dword[d+offs_Z]
|
||||||
|
fmul st0,st0
|
||||||
|
faddp
|
||||||
|
fsqrt
|
||||||
|
fst dword[dist] ;dist=sqrt(d.X^2+d^2+d^2)
|
||||||
|
fcom dword[fl_1e_3]
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jbe @f ;if (dist>1.0e-3)
|
||||||
|
fld1
|
||||||
|
fdiv st0,st1
|
||||||
|
fld dword[d]
|
||||||
|
fmul st0,st1
|
||||||
|
fstp dword[d]
|
||||||
|
fld dword[d+offs_Y]
|
||||||
|
fmul st0,st1
|
||||||
|
fstp dword[d+offs_Y]
|
||||||
|
fld dword[d+offs_Z]
|
||||||
|
fmul st0,st1
|
||||||
|
fstp dword[d+offs_Z]
|
||||||
|
ffree st0 ;1.0/dist
|
||||||
|
fincstp
|
||||||
|
@@:
|
||||||
|
fld dword[ebx+offs_ligh_attenuation+8]
|
||||||
|
fmul st0,st1 ;st0 = dist * l.attenuation[2]
|
||||||
|
fadd dword[ebx+offs_ligh_attenuation+4]
|
||||||
|
fmul st0,st1
|
||||||
|
fadd dword[ebx+offs_ligh_attenuation]
|
||||||
|
fld1
|
||||||
|
fdiv st0,st1
|
||||||
|
fstp dword[att] ;att = 1.0f/(l.attenuation[0]+dist*(l.attenuation[1]+dist*l.attenuation[2]))
|
||||||
|
ffree st0 ;1.0
|
||||||
|
fincstp
|
||||||
|
ffree st0 ;dist
|
||||||
|
fincstp
|
||||||
|
.els_0_end:
|
||||||
|
fld dword[d]
|
||||||
|
fmul dword[n]
|
||||||
|
fld dword[d+offs_Y]
|
||||||
|
fmul dword[n+offs_Y]
|
||||||
|
faddp
|
||||||
|
fld dword[d+offs_Z]
|
||||||
|
fmul dword[n+offs_Z]
|
||||||
|
faddp ;dot = d.X*n.X+d.Y*n.Y+d.Z*n.Z
|
||||||
|
cmp dword[twoside],0 ;if (twoside && dot < 0)
|
||||||
|
je @f
|
||||||
|
ftst ;if (dot<0)
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jae @f
|
||||||
|
fchs ;dot = -dot
|
||||||
|
@@:
|
||||||
|
ftst ;if (dot>0)
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jle .if0_end
|
||||||
|
; diffuse light
|
||||||
|
fld dword[ecx+offs_mate_diffuse]
|
||||||
|
fmul dword[ebx+offs_ligh_diffuse]
|
||||||
|
fmul st0,st1
|
||||||
|
fadd dword[lR]
|
||||||
|
fstp dword[lR] ;lR+=dot * l.diffuse.v[0] * m.diffuse.v[0]
|
||||||
|
fld dword[ecx+offs_mate_diffuse+4]
|
||||||
|
fmul dword[ebx+offs_ligh_diffuse+4]
|
||||||
|
fmul st0,st1
|
||||||
|
fadd dword[lG]
|
||||||
|
fstp dword[lG] ;lG+=dot * l.diffuse.v[1] * m.diffuse.v[1]
|
||||||
|
fld dword[ecx+offs_mate_diffuse+8]
|
||||||
|
fmul dword[ebx+offs_ligh_diffuse+8]
|
||||||
|
fmul st0,st1
|
||||||
|
fadd dword[lB]
|
||||||
|
fstp dword[lB] ;lB+=dot * l.diffuse.v[2] * m.diffuse.v[2]
|
||||||
|
ffree st0 ;dot
|
||||||
|
fincstp
|
||||||
|
|
||||||
; /* ambient */
|
; spot light
|
||||||
; lR=l->ambient.v[0] * m->ambient.v[0];
|
fld dword[ebx+offs_ligh_spot_cutoff]
|
||||||
; lG=l->ambient.v[1] * m->ambient.v[1];
|
fcomp dword[an180f] ;if (l.spot_cutoff != 180)
|
||||||
; lB=l->ambient.v[2] * m->ambient.v[2];
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jne .if1_end
|
||||||
|
fld dword[ebx+offs_ligh_norm_spot_direction]
|
||||||
|
fmul dword[d]
|
||||||
|
fld dword[ebx+offs_ligh_norm_spot_direction+4]
|
||||||
|
fmul dword[d+offs_Y]
|
||||||
|
faddp
|
||||||
|
fld dword[ebx+offs_ligh_norm_spot_direction+8]
|
||||||
|
fmul dword[d+offs_Z]
|
||||||
|
faddp
|
||||||
|
fchs
|
||||||
|
fst dword[dot_spot]
|
||||||
|
cmp dword[twoside],0 ;if (twoside && dot_spot < 0)
|
||||||
|
je @f
|
||||||
|
ftst ;if (dot_spot<0)
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jae @f
|
||||||
|
fchs ;dot_spot = -dot_spot
|
||||||
|
@@:
|
||||||
|
fcom dword[ebx+offs_ligh_cos_spot_cutoff] ;if (dot_spot < l.cos_spot_cutoff)
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jae .els_1
|
||||||
|
; no contribution
|
||||||
|
ffree st0 ;dot_spot
|
||||||
|
fincstp
|
||||||
|
mov ebx,[ebx+offs_ligh_next]
|
||||||
|
jmp .cycle_0 ;continue
|
||||||
|
.els_1:
|
||||||
|
; TODO: optimize
|
||||||
|
fld dword[ebx+offs_ligh_spot_exponent]
|
||||||
|
ftst ;if (l.spot_exponent > 0)
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jbe @f
|
||||||
|
fxch st1 ;dot_spot <--> l.spot_exponent
|
||||||
|
;Вычисляем x^y
|
||||||
|
;fld y
|
||||||
|
;fld x
|
||||||
|
fyl2x ;Стек FPU теперь содержит: st0=z=y*log2(x):
|
||||||
|
;Теперь считаем 2**z:
|
||||||
|
fld st0 ;Создаем еще одну копию z
|
||||||
|
frndint ;Округляем
|
||||||
|
fsubr st0,st1 ;st1=z, st0=z-trunc(z)
|
||||||
|
f2xm1 ;st1=z, st0=2**(z-trunc(z))-1
|
||||||
|
fld1
|
||||||
|
faddp ;st1=z, st0=2**(z-trunc(z))
|
||||||
|
fscale ;st1=z, st0=(2**trunc(z))*(2**(z-trunc(z)))=2**t
|
||||||
|
fxch st1
|
||||||
|
fstp st ;Результат остается на вершине стека st0
|
||||||
|
fmul dword[att]
|
||||||
|
fstp dword[att] ;att=att*pow(dot_spot,l.spot_exponent)
|
||||||
|
jmp .if1_end
|
||||||
|
@@:
|
||||||
|
ffree st0 ;l.spot_exponent
|
||||||
|
fincstp
|
||||||
|
ffree st0 ;dot_spot
|
||||||
|
fincstp
|
||||||
|
.if1_end:
|
||||||
|
|
||||||
; if (l->position.v[3] == 0) {
|
; specular light
|
||||||
; /* light at infinity */
|
cmp dword[edx+offs_cont_local_light_model],0 ;if (c.local_light_model)
|
||||||
; d.X=l->position.v[0];
|
je .els_2
|
||||||
; d.Y=l->position.v[1];
|
mov eax,[esi+offs_vert_ec]
|
||||||
; d.Z=l->position.v[2];
|
mov [vcoord],eax ;vcoord.X=v.ec.X
|
||||||
; att=1;
|
mov eax,[esi+offs_vert_ec+offs_Y]
|
||||||
; } else {
|
mov [vcoord+offs_Y],eax ;vcoord.Y=v.ec.Y
|
||||||
; /* distance attenuation */
|
mov eax,[esi+offs_vert_ec+offs_Z]
|
||||||
; d.X=l->position.v[0]-v->ec.v[0];
|
mov [vcoord+offs_Z],eax ;vcoord.Z=v.ec.Z
|
||||||
; d.Y=l->position.v[1]-v->ec.v[1];
|
mov eax,ebp
|
||||||
; d.Z=l->position.v[2]-v->ec.v[2];
|
sub eax,12 ;eax = &vcoord
|
||||||
; dist=sqrt(d.X*d.X+d.Y*d.Y+d.Z*d.Z);
|
stdcall gl_V3_Norm, eax
|
||||||
; if (dist>1E-3) {
|
fld dword[d]
|
||||||
; tmp=1/dist;
|
fsub dword[vcoord]
|
||||||
; d.X*=tmp;
|
fstp dword[s] ;s.X=d.X-vcoord.X
|
||||||
; d.Y*=tmp;
|
fld dword[d+offs_Y]
|
||||||
; d.Z*=tmp;
|
fsub dword[vcoord+offs_Y]
|
||||||
; }
|
fstp dword[s+offs_Y] ;s.Y=d.Y-vcoord.Y
|
||||||
; att=1.0f/(l->attenuation[0]+dist*(l->attenuation[1]+
|
fld dword[d+offs_Z]
|
||||||
; dist*l->attenuation[2]));
|
fsub dword[vcoord+offs_Z]
|
||||||
; }
|
fstp dword[s+offs_Z] ;s.Z=d.Z-vcoord.Z
|
||||||
; dot=d.X*n.X+d.Y*n.Y+d.Z*n.Z;
|
jmp .els_2_end
|
||||||
; if (twoside && dot < 0) dot = -dot;
|
.els_2:
|
||||||
; if (dot>0) {
|
mov eax,[d]
|
||||||
; /* diffuse light */
|
mov [s],eax ;s.X=d.X
|
||||||
; lR+=dot * l->diffuse.v[0] * m->diffuse.v[0];
|
mov eax,[d+offs_Y]
|
||||||
; lG+=dot * l->diffuse.v[1] * m->diffuse.v[1];
|
mov [s+offs_Y],eax ;s.Y=d.Y
|
||||||
; lB+=dot * l->diffuse.v[2] * m->diffuse.v[2];
|
fld1
|
||||||
;
|
fadd dword[d+offs_Z]
|
||||||
; /* spot light */
|
fstp dword[s+offs_Z] ;s.Z=d.Z+1.0
|
||||||
; if (l->spot_cutoff != 180) {
|
.els_2_end:
|
||||||
; dot_spot=-(d.X*l->norm_spot_direction.v[0]+
|
fld dword[n]
|
||||||
; d.Y*l->norm_spot_direction.v[1]+
|
fmul st0,st0
|
||||||
; d.Z*l->norm_spot_direction.v[2]);
|
fld dword[n+offs_Y]
|
||||||
; if (twoside && dot_spot < 0) dot_spot = -dot_spot;
|
fmul st0,st0
|
||||||
; if (dot_spot < l->cos_spot_cutoff) {
|
faddp
|
||||||
; /* no contribution */
|
fld dword[n+offs_Z]
|
||||||
; continue;
|
fmul st0,st0
|
||||||
; } else {
|
faddp ;dot_spec = n.X^2 +n.Y^2 +n.Z^2
|
||||||
; /* TODO: optimize */
|
cmp dword[twoside],0 ;if (twoside && dot_spec < 0)
|
||||||
; if (l->spot_exponent > 0) {
|
je @f
|
||||||
; att=att*pow(dot_spot,l->spot_exponent);
|
ftst ;if (dot_spec < 0)
|
||||||
; }
|
fstsw ax
|
||||||
; }
|
sahf
|
||||||
; }
|
jae @f
|
||||||
|
fchs ;dot_spec = -dot_spec
|
||||||
|
@@:
|
||||||
|
ftst ;if (dot_spec > 0)
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jae .if0_end
|
||||||
|
fld dword[s]
|
||||||
|
fmul st0,st0
|
||||||
|
fld dword[s+offs_Y]
|
||||||
|
fmul st0,st0
|
||||||
|
faddp
|
||||||
|
fld dword[s+offs_Z]
|
||||||
|
fmul st0,st0
|
||||||
|
faddp
|
||||||
|
fsqrt
|
||||||
|
fcom dword[fl_1e_3]
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jbe @f ;if (tmp > 1.0e-3)
|
||||||
|
fdiv st1,st0 ;dot_spec /= tmp
|
||||||
|
@@:
|
||||||
|
ffree st0 ;tmp
|
||||||
|
fincstp
|
||||||
|
|
||||||
; /* specular light */
|
; TODO: optimize
|
||||||
|
; testing specular buffer code
|
||||||
|
; dot_spec= pow(dot_spec,m.shininess)
|
||||||
|
stdcall specbuf_get_buffer, edx, dword[ecx+offs_mate_shininess_i], dword[ecx+offs_mate_shininess]
|
||||||
|
;eax = specbuf
|
||||||
|
mov dword[idx],SPECULAR_BUFFER_SIZE
|
||||||
|
fild dword[idx]
|
||||||
|
fld1
|
||||||
|
fcomp
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jae @f
|
||||||
|
fmul st0,st1
|
||||||
|
@@:
|
||||||
|
fistp dword[idx] ;if (dot_spec < 1.0) idx = (int)(dot_spec*SPECULAR_BUFFER_SIZE)
|
||||||
|
;else idx = SPECULAR_BUFFER_SIZE;
|
||||||
|
ffree st0 ;dot_spec
|
||||||
|
fincstp
|
||||||
|
shl dword[idx],2
|
||||||
|
add eax,dword[idx]
|
||||||
|
fld dword[eax+offs_spec_buf] ;dot_spec = specbuf.buf[idx]
|
||||||
|
fld dword[ebx+offs_ligh_specular]
|
||||||
|
fmul st0,st1
|
||||||
|
fmul dword[ecx+offs_mate_specular]
|
||||||
|
fadd dword[lR]
|
||||||
|
fstp dword[lR] ;lR+=dot_spec * l.specular.v[0] * m.specular.v[0]
|
||||||
|
fld dword[ebx+offs_ligh_specular+offs_Y]
|
||||||
|
fmul st0,st1
|
||||||
|
fmul dword[ecx+offs_mate_specular+offs_Y]
|
||||||
|
fadd dword[lG]
|
||||||
|
fstp dword[lG] ;lG+=dot_spec * l.specular.v[1] * m.specular.v[1]
|
||||||
|
fld dword[ebx+offs_ligh_specular+offs_Z]
|
||||||
|
fmul st0,st1
|
||||||
|
fmul dword[ecx+offs_mate_specular+offs_Z]
|
||||||
|
fadd dword[lB]
|
||||||
|
fstp dword[lB] ;lB+=dot_spec * l.specular.v[2] * m.specular.v[2]
|
||||||
|
ffree st0 ;dot_spec
|
||||||
|
fincstp
|
||||||
|
jmp .if2_end
|
||||||
|
.if0_end:
|
||||||
|
ffree st0 ;dot [or] dot_spec
|
||||||
|
fincstp
|
||||||
|
.if2_end:
|
||||||
|
|
||||||
; if (c->local_light_model) {
|
fld dword[att]
|
||||||
; V3 vcoord;
|
fld dword[lR]
|
||||||
; vcoord.X=v->ec.X;
|
fmul st0,st1
|
||||||
; vcoord.Y=v->ec.Y;
|
fadd dword[R]
|
||||||
; vcoord.Z=v->ec.Z;
|
fstp dword[R] ;R += att * lR
|
||||||
; gl_V3_Norm(&vcoord);
|
fld dword[lG]
|
||||||
; s.X=d.X-vcoord.X;
|
fmul st0,st1
|
||||||
; s.Y=d.Y-vcoord.X;
|
fadd dword[G]
|
||||||
; s.Z=d.Z-vcoord.X;
|
fstp dword[G] ;G += att * lG
|
||||||
; } else {
|
fld dword[lB]
|
||||||
; s.X=d.X;
|
fmul st0,st1
|
||||||
; s.Y=d.Y;
|
fadd dword[B]
|
||||||
; s.Z=d.Z+1.0;
|
fstp dword[B] ;B += att * lB
|
||||||
; }
|
ffree st0 ;att
|
||||||
; dot_spec=n.X*s.X+n.Y*s.Y+n.Z*s.Z;
|
fincstp
|
||||||
; if (twoside && dot_spec < 0) dot_spec = -dot_spec;
|
mov ebx,[ebx+offs_ligh_next]
|
||||||
; if (dot_spec>0) {
|
jmp .cycle_0
|
||||||
; GLSpecBuf *specbuf;
|
.cycle_0_end:
|
||||||
; int idx;
|
|
||||||
; tmp=sqrt(s.X*s.X+s.Y*s.Y+s.Z*s.Z);
|
|
||||||
; if (tmp > 1E-3) {
|
|
||||||
; dot_spec=dot_spec / tmp;
|
|
||||||
; }
|
|
||||||
|
|
||||||
; /* TODO: optimize */
|
clampf [R],0,1
|
||||||
; /* testing specular buffer code */
|
mov [esi+offs_vert_color],eax ;v.color.v[0]=clampf(R,0,1)
|
||||||
; /* dot_spec= pow(dot_spec,m->shininess);*/
|
clampf [G],0,1
|
||||||
; specbuf = specbuf_get_buffer(c, m->shininess_i, m->shininess);
|
mov [esi+offs_vert_color+4],eax ;v.color.v[1]=clampf(G,0,1)
|
||||||
; idx = (int)(dot_spec*SPECULAR_BUFFER_SIZE);
|
clampf [B],0,1
|
||||||
; if (idx > SPECULAR_BUFFER_SIZE) idx = SPECULAR_BUFFER_SIZE;
|
mov [esi+offs_vert_color+8],eax ;v.color.v[2]=clampf(B,0,1)
|
||||||
; dot_spec = specbuf->buf[idx];
|
mov eax,[A]
|
||||||
; lR+=dot_spec * l->specular.v[0] * m->specular.v[0];
|
mov [esi+offs_vert_color+12],eax ;v.color.v[3]=A
|
||||||
; lG+=dot_spec * l->specular.v[1] * m->specular.v[1];
|
popad
|
||||||
; lB+=dot_spec * l->specular.v[2] * m->specular.v[2];
|
|
||||||
; }
|
|
||||||
; }
|
|
||||||
|
|
||||||
; R+=att * lR;
|
|
||||||
; G+=att * lG;
|
|
||||||
; B+=att * lB;
|
|
||||||
; }
|
|
||||||
|
|
||||||
; v->color.v[0]=clampf(R,0,1);
|
|
||||||
; v->color.v[1]=clampf(G,0,1);
|
|
||||||
; v->color.v[2]=clampf(B,0,1);
|
|
||||||
; v->color.v[3]=A;
|
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
@ -186,7 +186,8 @@ proc glopEnableDisable uses eax ebx ecx, context:dword, p:dword
|
|||||||
jl .els_0
|
jl .els_0
|
||||||
cmp ebx,GL_LIGHT0+MAX_LIGHTS
|
cmp ebx,GL_LIGHT0+MAX_LIGHTS
|
||||||
jge .els_0 ;if (GL_LIGHT0 <= ebx < GL_LIGHT0+MAX_LIGHTS)
|
jge .els_0 ;if (GL_LIGHT0 <= ebx < GL_LIGHT0+MAX_LIGHTS)
|
||||||
stdcall gl_enable_disable_light, eax,ebx-GL_LIGHT0,ecx
|
sub ebx,GL_LIGHT0
|
||||||
|
stdcall gl_enable_disable_light, eax,ebx,ecx
|
||||||
jmp .end_f
|
jmp .end_f
|
||||||
.els_0:
|
.els_0:
|
||||||
;//fprintf(stderr,"glEnableDisable: 0x%X not supported.\n",code);
|
;//fprintf(stderr,"glEnableDisable: 0x%X not supported.\n",code);
|
||||||
|
111
programs/develop/libraries/TinyGL/asm_fork/specbuf.asm
Normal file
111
programs/develop/libraries/TinyGL/asm_fork/specbuf.asm
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
|
||||||
|
align 4
|
||||||
|
proc calc_buf uses ebx ecx, buf:dword, shininess:dword
|
||||||
|
locals
|
||||||
|
val dd ? ;float
|
||||||
|
f_inc dd ? ;float
|
||||||
|
endl
|
||||||
|
mov dword[val],0.0f
|
||||||
|
mov dword[f_inc],SPECULAR_BUFFER_SIZE
|
||||||
|
fld1
|
||||||
|
fidiv dword[f_inc]
|
||||||
|
fstp dword[f_inc] ;f_inc = 1.0f/SPECULAR_BUFFER_SIZE
|
||||||
|
xor ecx,ecx
|
||||||
|
align 4
|
||||||
|
.cycle_0: ;for (i = 0; i <= SPECULAR_BUFFER_SIZE; i++)
|
||||||
|
cmp ecx,SPECULAR_BUFFER_SIZE
|
||||||
|
jg @f
|
||||||
|
;Вычисляем x^y
|
||||||
|
fld dword[shininess]
|
||||||
|
fld dword[val]
|
||||||
|
fyl2x ;Стек FPU теперь содержит: st0=z=y*log2(x):
|
||||||
|
;Теперь считаем 2**z:
|
||||||
|
fld st0 ;Создаем еще одну копию z
|
||||||
|
frndint ;Округляем
|
||||||
|
fsubr st0,st1 ;st1=z, st0=z-trunc(z)
|
||||||
|
f2xm1 ;st1=z, st0=2**(z-trunc(z))-1
|
||||||
|
fld1
|
||||||
|
faddp ;st1=z, st0=2**(z-trunc(z))
|
||||||
|
fscale ;st1=z, st0=(2**trunc(z))*(2**(z-trunc(z)))=2**t
|
||||||
|
fxch st1
|
||||||
|
fstp st ;Результат остается на вершине стека st0
|
||||||
|
|
||||||
|
mov ebx,ecx
|
||||||
|
shl ebx,2
|
||||||
|
add ebx,offs_spec_buf
|
||||||
|
add ebx,[buf]
|
||||||
|
fstp dword[ebx] ;buf.buf[i] = pow(val, shininess)
|
||||||
|
|
||||||
|
fld dword[val]
|
||||||
|
fadd dword[f_inc]
|
||||||
|
fstp dword[val] ;val += f_inc
|
||||||
|
inc ecx
|
||||||
|
jmp .cycle_0
|
||||||
|
@@:
|
||||||
|
ret
|
||||||
|
endp
|
||||||
|
|
||||||
|
align 4
|
||||||
|
proc specbuf_get_buffer uses ebx ecx edx, context:dword, shininess_i:dword, shininess:dword
|
||||||
|
locals
|
||||||
|
found dd ? ;GLSpecBuf *
|
||||||
|
oldest dd ? ;GLSpecBuf *
|
||||||
|
endl
|
||||||
|
mov edx,[context]
|
||||||
|
mov eax,[edx+offs_cont_specbuf_first]
|
||||||
|
mov [found],eax
|
||||||
|
mov [oldest],eax
|
||||||
|
mov ebx,[shininess_i]
|
||||||
|
.cycle_0:
|
||||||
|
or eax,eax ;while (found)
|
||||||
|
jz @f
|
||||||
|
cmp [eax+offs_spec_shininess_i],ebx ;while (found.shininess_i != shininess_i)
|
||||||
|
je @f
|
||||||
|
mov ecx,[oldest]
|
||||||
|
mov ecx,[ecx+offs_spec_last_used]
|
||||||
|
cmp [eax+offs_spec_last_used],ecx ;if (found.last_used < oldest.last_used)
|
||||||
|
jge .end_0
|
||||||
|
mov [oldest],eax ;oldest = found
|
||||||
|
.end_0:
|
||||||
|
mov eax,[eax+offs_spec_next] ;found = found.next
|
||||||
|
jmp .cycle_0
|
||||||
|
@@:
|
||||||
|
cmp dword[found],0 ;if (found) /* hey, found one! */
|
||||||
|
je @f
|
||||||
|
mov eax,[found]
|
||||||
|
mov ecx,[edx+offs_cont_specbuf_used_counter]
|
||||||
|
mov [eax+offs_spec_last_used],ecx ;found.last_used = context.specbuf_used_counter
|
||||||
|
inc dword[edx+offs_cont_specbuf_used_counter]
|
||||||
|
jmp .end_f ;return found
|
||||||
|
@@:
|
||||||
|
cmp dword[oldest],0 ;if (oldest == NULL || context.specbuf_num_buffers < MAX_SPECULAR_BUFFERS)
|
||||||
|
je @f
|
||||||
|
cmp dword[edx+offs_cont_specbuf_num_buffers],MAX_SPECULAR_BUFFERS
|
||||||
|
jl @f
|
||||||
|
jmp .end_1
|
||||||
|
@@:
|
||||||
|
; create new buffer
|
||||||
|
stdcall gl_malloc, sizeof.GLSpecBuf
|
||||||
|
;if (!eax) gl_fatal_error("could not allocate specular buffer")
|
||||||
|
inc dword[edx+offs_cont_specbuf_num_buffers]
|
||||||
|
mov ecx,[edx+offs_cont_specbuf_first]
|
||||||
|
mov [eax+offs_spec_next],ecx
|
||||||
|
mov [edx+offs_cont_specbuf_first],eax
|
||||||
|
mov ecx,[edx+offs_cont_specbuf_used_counter]
|
||||||
|
mov [eax+offs_spec_last_used],ecx
|
||||||
|
inc dword[edx+offs_cont_specbuf_used_counter]
|
||||||
|
mov [eax+offs_spec_shininess_i],ebx
|
||||||
|
stdcall calc_buf, eax,dword[shininess]
|
||||||
|
jmp .end_f
|
||||||
|
.end_1:
|
||||||
|
; overwrite the lru buffer
|
||||||
|
;tgl_trace("overwriting spec buffer :(\n");
|
||||||
|
mov eax,[oldest]
|
||||||
|
mov [eax+offs_spec_shininess_i],ebx
|
||||||
|
mov ecx,[edx+offs_cont_specbuf_used_counter]
|
||||||
|
mov [eax+offs_spec_last_used],ecx
|
||||||
|
inc dword[edx+offs_cont_specbuf_used_counter]
|
||||||
|
stdcall calc_buf, eax,dword[shininess]
|
||||||
|
.end_f:
|
||||||
|
ret
|
||||||
|
endp
|
@ -29,6 +29,7 @@ include 'ztriangle.asm'
|
|||||||
;include 'image_util.asm'
|
;include 'image_util.asm'
|
||||||
;include 'msghandling.asm'
|
;include 'msghandling.asm'
|
||||||
include 'arrays.asm'
|
include 'arrays.asm'
|
||||||
|
include 'specbuf.asm'
|
||||||
|
|
||||||
include 'kosgl.asm'
|
include 'kosgl.asm'
|
||||||
include 'glu.asm'
|
include 'glu.asm'
|
||||||
|
@ -137,11 +137,25 @@ endl
|
|||||||
|
|
||||||
cmp dword[edx+offs_cont_lighting_enabled],0 ;if(context.lighting_enabled)
|
cmp dword[edx+offs_cont_lighting_enabled],0 ;if(context.lighting_enabled)
|
||||||
je @f
|
je @f
|
||||||
|
if DEBUG ;context.matrix_stack_ptr[0]
|
||||||
|
stdcall gl_print_matrix,dword[edx+offs_cont_matrix_stack_ptr],4
|
||||||
|
end if
|
||||||
; precompute inverse modelview
|
; precompute inverse modelview
|
||||||
mov ebx,ebp
|
mov ebx,ebp
|
||||||
sub ebx,64
|
sub ebx,64
|
||||||
stdcall gl_M4_Inv, ebx, edx+offs_cont_matrix_stack_ptr
|
stdcall gl_M4_Inv, ebx,dword[edx+offs_cont_matrix_stack_ptr]
|
||||||
stdcall gl_M4_Transpose, edx+offs_cont_matrix_model_view_inv, ebx
|
if DEBUG ;tmp
|
||||||
|
stdcall dbg_print,txt_sp,txt_nl
|
||||||
|
stdcall gl_print_matrix,ebx,4
|
||||||
|
end if
|
||||||
|
push ebx
|
||||||
|
mov ebx,edx
|
||||||
|
add ebx,offs_cont_matrix_model_view_inv
|
||||||
|
stdcall gl_M4_Transpose, ebx
|
||||||
|
if DEBUG ;context.matrix_model_view_inv
|
||||||
|
stdcall dbg_print,txt_sp,txt_nl
|
||||||
|
stdcall gl_print_matrix,ebx,4
|
||||||
|
end if
|
||||||
jmp .end_if_0
|
jmp .end_if_0
|
||||||
@@:
|
@@:
|
||||||
mov ecx,edx
|
mov ecx,edx
|
||||||
@ -296,7 +310,7 @@ pushad
|
|||||||
add edi,offs_cont_current_normal
|
add edi,offs_cont_current_normal
|
||||||
mov edx,[v]
|
mov edx,[v]
|
||||||
|
|
||||||
fld dword[edi+offs_X]
|
fld dword[edi] ;edi = &n
|
||||||
fld dword[edi+offs_Y]
|
fld dword[edi+offs_Y]
|
||||||
fld dword[edi+offs_Z]
|
fld dword[edi+offs_Z]
|
||||||
|
|
||||||
@ -458,7 +472,6 @@ pushad
|
|||||||
stdcall gl_vertex_transform, edx, ebx
|
stdcall gl_vertex_transform, edx, ebx
|
||||||
|
|
||||||
; color
|
; color
|
||||||
|
|
||||||
cmp dword[edx+offs_cont_lighting_enabled],0
|
cmp dword[edx+offs_cont_lighting_enabled],0
|
||||||
je .els_0
|
je .els_0
|
||||||
stdcall gl_shade_vertex, edx,ebx
|
stdcall gl_shade_vertex, edx,ebx
|
||||||
|
@ -47,6 +47,11 @@ struct GLSpecBuf
|
|||||||
next dd ? ;struct GLSpecBuf*
|
next dd ? ;struct GLSpecBuf*
|
||||||
ends
|
ends
|
||||||
|
|
||||||
|
offs_spec_shininess_i equ 0
|
||||||
|
offs_spec_last_used equ 4
|
||||||
|
offs_spec_buf equ 8
|
||||||
|
offs_spec_next equ 8+4*(SPECULAR_BUFFER_SIZE+1)
|
||||||
|
|
||||||
struct GLLight
|
struct GLLight
|
||||||
ambient V4
|
ambient V4
|
||||||
diffuse V4
|
diffuse V4
|
||||||
|
@ -70,7 +70,6 @@ pushad
|
|||||||
.cycle_0: ;i
|
.cycle_0: ;i
|
||||||
xor ebx,ebx
|
xor ebx,ebx
|
||||||
.cycle_1: ;j
|
.cycle_1: ;j
|
||||||
finit
|
|
||||||
fldz ;sum=0
|
fldz ;sum=0
|
||||||
xor ecx,ecx
|
xor ecx,ecx
|
||||||
M4_reg edi,[a],eax,0
|
M4_reg edi,[a],eax,0
|
||||||
@ -79,7 +78,7 @@ pushad
|
|||||||
add edi,4
|
add edi,4
|
||||||
M4_reg esi,[b],ecx,ebx
|
M4_reg esi,[b],ecx,ebx
|
||||||
fmul dword[esi]
|
fmul dword[esi]
|
||||||
fadd st0,st1 ;sum += a[i][k] * b[k][j]
|
faddp ;sum += a[i][k] * b[k][j]
|
||||||
inc ecx
|
inc ecx
|
||||||
cmp ecx,4
|
cmp ecx,4
|
||||||
jl .cycle_2
|
jl .cycle_2
|
||||||
@ -91,7 +90,6 @@ pushad
|
|||||||
inc eax
|
inc eax
|
||||||
cmp eax,4
|
cmp eax,4
|
||||||
jl .cycle_0
|
jl .cycle_0
|
||||||
finit
|
|
||||||
if DEBUG ;gl_M4_Mul
|
if DEBUG ;gl_M4_Mul
|
||||||
stdcall dbg_print,f_m4m,txt_nl
|
stdcall dbg_print,f_m4m,txt_nl
|
||||||
stdcall gl_print_matrix,[c],4
|
stdcall gl_print_matrix,[c],4
|
||||||
@ -187,13 +185,42 @@ endp
|
|||||||
; a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z;
|
; a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z;
|
||||||
;}
|
;}
|
||||||
|
|
||||||
;void gl_M4_MulV4(V4 *a,M4 *b,V4 *c)
|
align 4
|
||||||
;{
|
proc gl_M4_MulV4 uses ebx ecx edx, a:dword, b:dword, c:dword ;V4 *a, M4 *b, V4 *c
|
||||||
; a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z+b->m[0][3]*c->W;
|
mov ebx,[b]
|
||||||
; a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z+b->m[1][3]*c->W;
|
mov edx,[c]
|
||||||
; a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z+b->m[2][3]*c->W;
|
fld dword[edx]
|
||||||
; a->W=b->m[3][0]*c->X+b->m[3][1]*c->Y+b->m[3][2]*c->Z+b->m[3][3]*c->W;
|
fld dword[edx+4]
|
||||||
;}
|
fld dword[edx+8]
|
||||||
|
fld dword[edx+12]
|
||||||
|
mov edx,[a]
|
||||||
|
mov ecx,4
|
||||||
|
.cycle_1:
|
||||||
|
fld dword[ebx] ;st0 = m[_][0]
|
||||||
|
fmul st0,st4 ;st0 *= c.X
|
||||||
|
fld dword[ebx+4] ;st0 = m[_][1]
|
||||||
|
fmul st0,st4 ;st0 *= c.Y
|
||||||
|
faddp
|
||||||
|
fld dword[ebx+8] ;st0 = m[_][2]
|
||||||
|
fmul st0,st3 ;st0 *= c.Z
|
||||||
|
faddp
|
||||||
|
fld dword[ebx+12] ;st0 += m[_][3]
|
||||||
|
fmul st0,st2 ;st0 *= c.Z
|
||||||
|
faddp
|
||||||
|
fstp dword[edx] ;a.X = b.m[_][0]*c.X +b.m[_][1]*c.Y +b.m[_][2]*c.Z +b.m[_][3]*c.W
|
||||||
|
add ebx,16 ;ñëåäóùàÿ ñòðîêà ìàòðèöû
|
||||||
|
add edx,4 ;ñëåäóùàÿ êîîðäèíàòà âåêòîðà
|
||||||
|
loop .cycle_1
|
||||||
|
ffree st0
|
||||||
|
fincstp
|
||||||
|
ffree st0
|
||||||
|
fincstp
|
||||||
|
ffree st0
|
||||||
|
fincstp
|
||||||
|
ffree st0
|
||||||
|
fincstp
|
||||||
|
ret
|
||||||
|
endp
|
||||||
|
|
||||||
; transposition of a 4x4 matrix
|
; transposition of a 4x4 matrix
|
||||||
align 4
|
align 4
|
||||||
@ -258,58 +285,219 @@ endp
|
|||||||
; Note : m is destroyed
|
; Note : m is destroyed
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc Matrix_Inv uses ecx, r:dword, m:dword, n:dword ;(float *r,float *m,int n)
|
proc Matrix_Inv uses ebx ecx edx edi esi, r:dword, m:dword, n:dword ;(float *r,float *m,int n)
|
||||||
; int i,j,k,l;
|
locals
|
||||||
; float max,tmp,t;
|
max dd ? ;float
|
||||||
|
tmp dd ?
|
||||||
|
endl
|
||||||
|
|
||||||
; /* identitée dans r */
|
; identitée dans r
|
||||||
; for(i=0;i<n*n;i++) r[i]=0;
|
mov eax,0.0
|
||||||
; for(i=0;i<n;i++) r[i*n+i]=1;
|
mov ecx,[n]
|
||||||
|
imul ecx,ecx
|
||||||
|
mov edi,[r]
|
||||||
|
rep stosd ;for(i=0;i<n*n;i++) r[i]=0
|
||||||
|
mov eax,1.0
|
||||||
|
xor ebx,ebx
|
||||||
|
mov edi,[r]
|
||||||
|
mov ecx,[n]
|
||||||
|
shl ecx,2
|
||||||
|
@@: ;for(i=0;i<n;i++)
|
||||||
|
cmp ebx,[n]
|
||||||
|
jge .end_0
|
||||||
|
stosd ;r[i*n+i]=1
|
||||||
|
add edi,ecx
|
||||||
|
inc ebx
|
||||||
|
jmp @b
|
||||||
|
.end_0:
|
||||||
|
|
||||||
; for(j=0;j<n;j++) {
|
; ebx -> n
|
||||||
|
; ecx -> j
|
||||||
|
; edx -> k
|
||||||
|
; edi -> i
|
||||||
|
; esi -> l
|
||||||
|
mov ebx,[n]
|
||||||
|
xor ecx,ecx
|
||||||
|
.cycle_0: ;for(j=0;j<n;j++)
|
||||||
|
cmp ecx,ebx
|
||||||
|
jge .cycle_0_end
|
||||||
|
; recherche du nombre de plus grand module sur la colonne j
|
||||||
|
mov eax,ecx
|
||||||
|
imul eax,ebx
|
||||||
|
add eax,ecx
|
||||||
|
shl eax,2
|
||||||
|
add eax,[m]
|
||||||
|
mov eax,[eax]
|
||||||
|
mov [max],eax ;max=m[j*n+j]
|
||||||
|
mov edx,ecx ;k=j
|
||||||
|
mov edi,ecx
|
||||||
|
inc edi
|
||||||
|
.cycle_1: ;for(i=j+1;i<n;i++)
|
||||||
|
cmp edi,ebx
|
||||||
|
jge .cycle_1_end
|
||||||
|
mov eax,edi
|
||||||
|
imul eax,ebx
|
||||||
|
add eax,ecx
|
||||||
|
shl eax,2
|
||||||
|
add eax,[m]
|
||||||
|
fld dword[eax]
|
||||||
|
fcom dword[max] ;if (fabs(m[i*n+j])>fabs(max))
|
||||||
|
fstsw ax
|
||||||
|
sahf
|
||||||
|
jbe @f
|
||||||
|
mov edx,edi ;k=i
|
||||||
|
fst dword[max]
|
||||||
|
@@:
|
||||||
|
ffree st0
|
||||||
|
fincstp
|
||||||
|
inc edi
|
||||||
|
jmp .cycle_1
|
||||||
|
.cycle_1_end:
|
||||||
|
|
||||||
; /* recherche du nombre de plus grand module sur la colonne j */
|
; non intersible matrix
|
||||||
; max=m[j*n+j];
|
fld dword[max]
|
||||||
; k=j;
|
ftst ;if (max==0)
|
||||||
; for(i=j+1;i<n;i++)
|
fstsw ax
|
||||||
; if (fabs(m[i*n+j])>fabs(max)) {
|
ffree st0
|
||||||
; k=i;
|
fincstp
|
||||||
; max=m[i*n+j];
|
sahf
|
||||||
; }
|
jne @f
|
||||||
|
xor eax,eax
|
||||||
|
inc eax
|
||||||
|
jmp .end_f ;return 1
|
||||||
|
@@:
|
||||||
|
|
||||||
; /* non intersible matrix */
|
; permutation des lignes j et k
|
||||||
; if (max==0) return 1;
|
cmp ecx,edx ;if (j!=k)
|
||||||
|
je .cycle_2_end
|
||||||
|
xor edi,edi
|
||||||
|
.cycle_2: ;for(i=0;i<n;i++)
|
||||||
|
cmp edi,ebx
|
||||||
|
jge .cycle_2_end
|
||||||
|
;òóò ïîêà esi != l
|
||||||
|
mov eax,ecx
|
||||||
|
imul eax,ebx
|
||||||
|
add eax,edi
|
||||||
|
shl eax,2
|
||||||
|
add eax,[m]
|
||||||
|
mov esi,[eax]
|
||||||
|
mov [tmp],esi ;tmp=m[j*n+i]
|
||||||
|
mov esi,edx
|
||||||
|
imul esi,ebx
|
||||||
|
add esi,edi
|
||||||
|
shl esi,2
|
||||||
|
add esi,[m]
|
||||||
|
m2m dword[eax],dword[esi] ;m[j*n+i]=m[k*n+i]
|
||||||
|
mov eax,[tmp]
|
||||||
|
mov [esi],eax ;m[k*n+i]=tmp
|
||||||
|
|
||||||
; /* permutation des lignes j et k */
|
mov eax,ecx
|
||||||
; if (k!=j) {
|
imul eax,ebx
|
||||||
; for(i=0;i<n;i++) {
|
add eax,edi
|
||||||
; tmp=m[j*n+i];
|
shl eax,2
|
||||||
; m[j*n+i]=m[k*n+i];
|
add eax,[r]
|
||||||
; m[k*n+i]=tmp;
|
mov esi,[eax]
|
||||||
;
|
mov [tmp],esi ;tmp=r[j*n+i]
|
||||||
; tmp=r[j*n+i];
|
mov esi,edx
|
||||||
; r[j*n+i]=r[k*n+i];
|
imul esi,ebx
|
||||||
; r[k*n+i]=tmp;
|
add esi,edi
|
||||||
; }
|
shl esi,2
|
||||||
; }
|
add esi,[r]
|
||||||
|
m2m dword[eax],dword[esi] ;r[j*n+i]=r[k*n+i]
|
||||||
|
mov eax,[tmp]
|
||||||
|
mov [esi],eax ;r[k*n+i]=tmp
|
||||||
|
inc edi
|
||||||
|
jmp .cycle_2
|
||||||
|
.cycle_2_end:
|
||||||
|
|
||||||
; /* multiplication de la ligne j par 1/max */
|
; multiplication de la ligne j par 1/max
|
||||||
; max=1/max;
|
fld1
|
||||||
; for(i=0;i<n;i++) {
|
fdiv dword[max]
|
||||||
; m[j*n+i]*=max;
|
fst dword[max] ;max=1/max
|
||||||
; r[j*n+i]*=max;
|
xor edi,edi
|
||||||
; }
|
mov eax,ecx
|
||||||
|
imul eax,ebx
|
||||||
|
shl eax,2
|
||||||
|
.cycle_3: ;for(i=0;i<n;i++)
|
||||||
|
cmp edi,ebx
|
||||||
|
jge .cycle_3_end
|
||||||
|
add eax,[m]
|
||||||
|
fld dword[eax]
|
||||||
|
fmul st0,st1
|
||||||
|
fstp dword[eax] ;m[j*n+i]*=max
|
||||||
|
sub eax,[m]
|
||||||
|
add eax,[r]
|
||||||
|
fld dword[eax]
|
||||||
|
fmul st0,st1
|
||||||
|
fstp dword[eax] ;r[j*n+i]*=max
|
||||||
|
sub eax,[r]
|
||||||
|
add eax,4
|
||||||
|
inc edi
|
||||||
|
jmp .cycle_3
|
||||||
|
.cycle_3_end:
|
||||||
|
ffree st0 ;max
|
||||||
|
fincstp
|
||||||
|
|
||||||
; for(l=0;l<n;l++) if (l!=j) {
|
xor esi,esi
|
||||||
; t=m[l*n+j];
|
.cycle_4: ;for(l=0;l<n;l++)
|
||||||
; for(i=0;i<n;i++) {
|
cmp esi,ebx
|
||||||
; m[l*n+i]-=m[j*n+i]*t;
|
jge .cycle_4_end
|
||||||
; r[l*n+i]-=r[j*n+i]*t;
|
cmp esi,ecx ;if (l!=j)
|
||||||
; }
|
je .cycle_5_end
|
||||||
; }
|
mov eax,esi
|
||||||
; }
|
imul eax,ebx
|
||||||
|
add eax,ecx
|
||||||
|
shl eax,2
|
||||||
|
add eax,[m]
|
||||||
|
fld dword[eax] ;t=m[l*n+j]
|
||||||
|
xor edi,edi
|
||||||
|
.cycle_5: ;for(i=0;i<n;i++)
|
||||||
|
cmp edi,ebx
|
||||||
|
jge .cycle_5_end
|
||||||
|
mov eax,ecx
|
||||||
|
imul eax,ebx
|
||||||
|
add eax,edi
|
||||||
|
shl eax,2
|
||||||
|
add eax,[m]
|
||||||
|
fld dword[eax]
|
||||||
|
fmul st0,st1
|
||||||
|
mov eax,esi
|
||||||
|
imul eax,ebx
|
||||||
|
add eax,edi
|
||||||
|
shl eax,2
|
||||||
|
add eax,[m]
|
||||||
|
fsub dword[eax]
|
||||||
|
fchs
|
||||||
|
fstp dword[eax] ;m[l*n+i]-=m[j*n+i]*t
|
||||||
|
mov eax,ecx
|
||||||
|
imul eax,ebx
|
||||||
|
add eax,edi
|
||||||
|
shl eax,2
|
||||||
|
add eax,[r]
|
||||||
|
fld dword[eax]
|
||||||
|
fmul st0,st1
|
||||||
|
mov eax,esi
|
||||||
|
imul eax,ebx
|
||||||
|
add eax,edi
|
||||||
|
shl eax,2
|
||||||
|
add eax,[r]
|
||||||
|
fsub dword[eax]
|
||||||
|
fchs
|
||||||
|
fstp dword[eax] ;r[l*n+i]-=r[j*n+i]*t
|
||||||
|
inc edi
|
||||||
|
jmp .cycle_5
|
||||||
|
.cycle_5_end:
|
||||||
|
ffree st0 ;t
|
||||||
|
fincstp
|
||||||
|
inc esi
|
||||||
|
jmp .cycle_4
|
||||||
|
.cycle_4_end:
|
||||||
|
inc ecx
|
||||||
|
jmp .cycle_0
|
||||||
|
.cycle_0_end:
|
||||||
|
|
||||||
; return 0;
|
xor eax,eax ;return 0
|
||||||
|
.end_f:
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
@ -409,12 +597,12 @@ align 4
|
|||||||
proc gl_V3_Norm uses ebx, a:dword
|
proc gl_V3_Norm uses ebx, a:dword
|
||||||
mov ebx,[a]
|
mov ebx,[a]
|
||||||
fld dword[ebx]
|
fld dword[ebx]
|
||||||
fmul dword[ebx]
|
fmul st0,st0
|
||||||
fld dword[ebx+4]
|
fld dword[ebx+4]
|
||||||
fmul dword[ebx+4]
|
fmul st0,st0
|
||||||
faddp
|
faddp
|
||||||
fld dword[ebx+8]
|
fld dword[ebx+8]
|
||||||
fmul dword[ebx+8]
|
fmul st0,st0
|
||||||
faddp
|
faddp
|
||||||
fsqrt ;st0 = sqrt(a.X^2 +a.Y^2 +a.Z^2)
|
fsqrt ;st0 = sqrt(a.X^2 +a.Y^2 +a.Z^2)
|
||||||
fldz
|
fldz
|
||||||
|
Loading…
Reference in New Issue
Block a user