/programs/develop/libraries/TinyGL/asm_fork/light.asm |
---|
1,5 → 1,3 |
align 4 |
sp128f dd 128.0 |
align 4 |
proc glopMaterial uses eax ebx ecx edi esi, context:dword, p:dword |
16,8 → 14,7 |
stdcall glopMaterial,eax,edi |
mov ecx,GL_BACK |
@@: |
mov edi,eax |
add edi,offs_cont_materials |
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] |
57,7 → 54,7 |
add edi,offs_mate_shininess |
movsd |
mov dword[edi],SPECULAR_BUFFER_RESOLUTION |
fdiv dword[sp128f] |
fdiv dword[an180f] |
fimul dword[edi] |
fistp dword[edi] ;m.shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION |
jmp .end_f |
177,12 → 174,10 |
add edi,offs_ligh_spot_direction |
mov ecx,3 |
rep movsd ;l.spot_direction=v[0,1,2] |
;mov esi,ebx |
;add esi,12 |
sub esi,12 |
;mov edi,edx |
;add edi,offs_ligh_norm_spot_direction |
add edi,offs_ligh_norm_spot_direction-(offs_ligh_spot_direction+12) |
mov esi,ebx |
add esi,12 |
mov edi,edx |
add edi,offs_ligh_norm_spot_direction |
mov ecx,3 |
rep movsd ;l.norm_spot_direction=v[0,1,2] |
add edx,offs_ligh_norm_spot_direction |
385,8 → 380,7 |
; esi -> GLVertex *v |
mov esi,[v] |
mov edx,[context] |
mov ecx,edx |
add ecx,offs_cont_materials ;ecx(m) = &context.materials[0] |
mov ecx,[edx+offs_cont_materials] ;ecx(m) = &context.materials[0] |
mov eax,[edx+offs_cont_light_model_two_side] |
mov [twoside],eax |
443,26 → 437,19 |
fmul dword[ebx+offs_ligh_ambient+8] |
fstp dword[lB] ;lB=l.ambient.v[2] * m.ambient.v[2] |
fld dword[ebx+offs_ligh_position+offs_W] |
ftst ;if (l.position.v[3] == 0) |
fstsw ax |
sahf |
cmp dword[ebx+offs_ligh_position+12],0 ;if (l.position.v[3] == 0) |
jne .els_0 |
; light at infinity |
ffree st0 ;l.position.v[3] |
fincstp |
mov eax,[ebx+offs_ligh_position] |
mov [d],eax ;d.X=l.position.v[0] |
mov eax,[ebx+offs_ligh_position+offs_Y] |
mov [d+offs_Y],eax ;d.Y=l.position.v[1] |
mov eax,[ebx+offs_ligh_position+offs_Z] |
mov [d+offs_Z],eax ;d.Z=l.position.v[2] |
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 |
ffree st0 ;l.position.v[3] |
fincstp |
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] |
481,7 → 468,7 |
fmul st0,st0 |
faddp |
fsqrt |
fst dword[dist] ;dist=sqrt(d.X^2+d.Y^2+d.Z^2) |
fst dword[dist] ;dist=sqrt(d.X^2+d^2+d^2) |
fcom dword[fl_1e_3] |
fstsw ax |
sahf |
532,7 → 519,7 |
ftst ;if (dot>0) |
fstsw ax |
sahf |
jbe .if0_end |
jle .if0_end |
; diffuse light |
fld dword[ecx+offs_mate_diffuse] |
fmul dword[ebx+offs_ligh_diffuse] |
667,7 → 654,7 |
ftst ;if (dot_spec > 0) |
fstsw ax |
sahf |
jbe .if0_end |
jae .if0_end |
fld dword[s] |
fmul st0,st0 |
fld dword[s+offs_Y] |
691,16 → 678,17 |
; dot_spec= pow(dot_spec,m.shininess) |
stdcall specbuf_get_buffer, edx, dword[ecx+offs_mate_shininess_i], dword[ecx+offs_mate_shininess] |
mov edi,eax ;edi = specbuf |
mov dword[idx],SPECULAR_BUFFER_SIZE ;idx = SPECULAR_BUFFER_SIZE |
mov dword[idx],SPECULAR_BUFFER_SIZE |
fild dword[idx] |
fld1 |
fcomp |
fstsw ax |
fild dword[idx] |
sahf |
jae @f ;if(dot_spec < 1.0) |
fmul st0,st1 ;idx *= dot_spec |
jae @f |
fmul st0,st1 |
@@: |
fistp dword[idx] |
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 |
/programs/develop/libraries/TinyGL/asm_fork/vertex.asm |
---|
108,6 → 108,13 |
mov dword[zsize],(1 shl ZB_POINT_Z_FRAC_BITS) / 2 |
fiadd dword[zsize] |
fstp dword[eax+offs_vpor_trans+offs_Z] |
if DEBUG ;gl_eval_viewport |
stdcall dbg_print,f_ev,txt_nl |
add eax,offs_vpor_scale |
stdcall gl_print_matrix,eax,1 |
add eax,8 |
stdcall gl_print_matrix,eax,1 |
end if |
ret |
endp |
253,11 → 260,11 |
fmul st0,st3 ;st0 *= v.coord.X |
fld dword[ebx+4] ;st0 = m[1] |
fmul st0,st3 ;st0 *= v.coord.Y |
faddp ;st0 = v.coord.X * m[0] + v.coord.Y * m[1] |
fld dword[ebx+8] ;st0 = m[2] |
fmul st0,st2 ;st0 *= v.coord.Z |
fmul st0,st3 ;st0 *= v.coord.Z |
fadd dword[ebx+12] ;st0 += m[3] |
faddp ;st0 += v.ec.X |
faddp ;st0 += v.coord.Z * m[2] |
faddp ;st0 += v.coord.Y * m[1] |
fstp dword[edx+offs_vert_ec] ;v.ec.X = v.coord.X * m[0] + v.coord.Y * m[1] + v.coord.Z * m[2] + m[3] |
add ebx,16 ;следущая строка матрицы |
add edx,4 ;следущая координата вектора |
283,11 → 290,11 |
fmul st0,st3 ;st0 *= v.ec.X |
fld dword[ebx+4] ;st0 = m[1] |
fmul st0,st3 ;st0 *= v.ec.Y |
faddp ;st0 = v.ec.X * m[0] + v.ec.Y * m[1] |
fld dword[ebx+8] ;st0 = m[2] |
fmul st0,st2 ;st0 *= v.ec.Z |
fmul st0,st3 ;st0 *= v.ec.Z |
fadd dword[ebx+12] ;st0 += m[3] |
faddp ;st0 = v.pc.X |
faddp ;st0 += v.ec.Z * m[2] |
faddp ;st0 += v.ec.Y * m[1] |
fstp dword[edx+offs_vert_pc] ;v.pc.X = v.ec.X * m[0] + v.ec.Y * m[1] + v.ec.Z * m[2] + m[3] |
add ebx,16 ;следущая строка матрицы |
add edx,4 ;следущая координата вектора |
310,17 → 317,16 |
fld dword[edi+offs_Z] |
mov ecx,3 |
add edx,offs_vert_normal |
.cycle_2: |
fld dword[ebx] ;st0 = m[0] |
fmul st0,st3 ;st0 *= n.X |
fld dword[ebx+4] ;st0 = m[1] |
fmul st0,st3 ;st0 *= n.Y |
faddp ;st0 = n.X * m[0] + n.Y * m[1] |
fld dword[ebx+8] ;st0 = m[2] |
fmul st0,st2 ;st0 *= n.Z |
faddp ;st0 = v.normal.X |
fstp dword[edx] ;v.normal.X = n.X * m[0] + n.Y * m[1] + n.Z * m[2] |
fmul st0,st3 ;st0 *= n.Z |
faddp ;st0 += n.Z * m[2] |
faddp ;st0 += n.Y * m[1] |
fstp dword[edx+offs_vert_normal] ;v.normal.X = n.X * m[0] + n.Y * m[1] + n.Z * m[2] |
add ebx,16 ;следущая строка матрицы |
add edx,4 ;следущая координата вектора |
loop .cycle_2 |
327,7 → 333,8 |
cmp dword[eax+offs_cont_normalize_enabled],0 |
je .end_els |
sub edx,12 |
mov edx,[v] |
add edx,offs_vert_normal |
stdcall gl_V3_Norm,edx |
jmp .end_els |
.els_0: |
348,11 → 355,11 |
fmul st0,st3 ;st0 *= v.coord.X |
fld dword[ebx+4] ;st0 = m[1] |
fmul st0,st3 ;st0 *= v.coord.Y |
faddp ;st0 = v.coord.X * m[0] + v.coord.Y * m[1] |
fld dword[ebx+8] ;st0 = m[2] |
fmul st0,st2 ;st0 *= v.coord.Z |
fmul st0,st3 ;st0 *= v.coord.Z |
fadd dword[ebx+12] ;st0 += m[3] |
faddp ;st0 = v.pc.X |
faddp ;st0 += v.coord.Z * m[2] |
faddp ;st0 += v.coord.Y * m[1] |
fstp dword[esi] ;v.pc.X = v.coord.X * m[0] + v.coord.Y * m[1] + v.coord.Z * m[2] + m[3] |
fld dword[ebx+16] ;st0 = m[4] |
359,23 → 366,23 |
fmul st0,st3 ;st0 *= v.coord.X |
fld dword[ebx+20] ;st0 = m[5] |
fmul st0,st3 ;st0 *= v.coord.Y |
faddp ;st0 = v.coord.X * m[4] + v.coord.Y * m[5] |
fld dword[ebx+24] ;st0 = m[6] |
fmul st0,st2 ;st0 *= v.coord.Z |
fmul st0,st3 ;st0 *= v.coord.Z |
fadd dword[ebx+28] ;st0 += m[7] |
faddp ;st0 = v.pc.Y |
fstp dword[esi+4] ;v.pc.Y = v.coord.X * m[4] + v.coord.Y * m[5] + v.coord.Z * m[6] + m[7] |
faddp ;st0 += v.coord.Z * m[6] |
faddp ;st0 += v.coord.Y * m[5] |
fstp dword[esi+4] ;v.pc.X = v.coord.X * m[4] + v.coord.Y * m[5] + v.coord.Z * m[6] + m[7] |
fld dword[ebx+32] ;st0 = m[8] |
fmul st0,st3 ;st0 *= v.coord.X |
fld dword[ebx+36] ;st0 = m[9] |
fmul st0,st3 ;st0 *= v.coord.Y |
faddp ;st0 = v.coord.X * m[8] + v.coord.Y * m[9] |
fld dword[ebx+40] ;st0 = m[10] |
fmul st0,st2 ;st0 *= v.coord.Z |
fmul st0,st3 ;st0 *= v.coord.Z |
fadd dword[ebx+44] ;st0 += m[11] |
faddp ;st0 = v.pc.Z |
fstp dword[esi+8] ;v.pc.Z = v.coord.X * m[8] + v.coord.Y * m[9] + v.coord.Z * m[10] + m[11] |
faddp ;st0 += v.coord.Z * m[10] |
faddp ;st0 += v.coord.Y * m[9] |
fstp dword[esi+8] ;v.pc.X = v.coord.X * m[8] + v.coord.Y * m[9] + v.coord.Z * m[10] + m[11] |
cmp dword[eax+offs_cont_matrix_model_projection_no_w_transform],0 |
je .els_1 |
388,11 → 395,11 |
fmul st0,st3 ;st0 *= v.coord.X |
fld dword[ebx+52] ;st0 = m[13] |
fmul st0,st3 ;st0 *= v.coord.Y |
faddp ;st0 = v.coord.X * m[12] + v.coord.Y * m[13] |
fld dword[ebx+56] ;st0 = m[14] |
fmul st0,st2 ;st0 *= v.coord.Z |
fmul st0,st3 ;st0 *= v.coord.Z |
fadd dword[ebx+60] ;st0 += m[15] |
faddp ;st0 = v.pc.W |
faddp ;st0 += v.coord.Z * m[14] |
faddp ;st0 += v.coord.Y * m[13] |
fstp dword[esi+12] ;v.pc.W = v.coord.X * m[12] + v.coord.Y * m[13] + v.coord.Z * m[14] + m[15] |
.end_els: |
ffree st0 |
485,20 → 492,11 |
je @f |
cmp dword[edx+offs_cont_apply_texture_matrix],0 |
je .els_1 |
mov eax,edx |
add eax,offs_cont_current_tex_coord |
push eax ;&context.current_tex_coord |
mov eax,ebx |
add eax,offs_vert_tex_coord |
stdcall gl_M4_MulV4, eax, dword[edx+offs_cont_matrix_stack_ptr+8] |
; gl_M4_MulV4(&v->tex_coord, c->matrix_stack_ptr[2], &c->current_tex_coord); |
jmp @f |
.els_1: |
mov esi,edx |
add esi,offs_cont_current_tex_coord |
mov edi,ebx |
add edi,offs_vert_tex_coord |
mov ecx,4 |
rep movsd |
mov eax,[edx+offs_cont_current_tex_coord] |
mov [ebx+offs_vert_tex_coord],eax |
@@: |
; precompute the mapping to the viewport |
574,34 → 572,21 |
@@: |
cmp dword[edx+offs_cont_begin_type],GL_TRIANGLE_STRIP |
jne @f |
cmp dword[edx+offs_cont_vertex_cnt],3 ;if (context.vertex_cnt >= 3) |
jl .end_f |
cmp dword[n],3 |
jne .ts3 |
xor eax,eax |
mov dword[n],eax |
.ts3: |
; needed to respect triangle orientation |
mov eax,[edx+offs_cont_vertex] |
bt dword[edx+offs_cont_vertex_cnt],0 |
jc .case_1 |
mov [esp-12],eax |
add eax,sizeof.GLVertex |
mov [esp-8],eax |
add eax,sizeof.GLVertex |
mov [esp-4],eax |
sub esp,12 |
stdcall gl_draw_triangle, edx ;&v[2],&v[1],&v[0] |
; if (c->vertex_cnt >= 3) { |
; if (n == 3) |
; n = 0; |
; /* needed to respect triangle orientation */ |
; switch(c->vertex_cnt & 1) { |
; case 0: |
; gl_draw_triangle(c,&c->vertex[2],&c->vertex[1],&c->vertex[0]); |
; break; |
; default: |
; case 1: |
; gl_draw_triangle(c,&c->vertex[0],&c->vertex[1],&c->vertex[2]); |
; break; |
; } |
; } |
jmp .end_f |
.case_1: |
mov [esp-4],eax |
add eax,sizeof.GLVertex |
mov [esp-8],eax |
add eax,sizeof.GLVertex |
mov [esp-12],eax |
sub esp,12 |
stdcall gl_draw_triangle, edx ;&v[0],&v[1],&v[2] |
jmp .end_f |
@@: |
cmp dword[edx+offs_cont_begin_type],GL_TRIANGLE_FAN |
jne @f |
/programs/develop/libraries/TinyGL/asm_fork/examples/test_glu1.asm |
---|
24,9 → 24,8 |
mcall 40,0x27 |
stdcall [kosglMakeCurrent], 10,10,400,325,ctx1 |
stdcall [kosglMakeCurrent], 10,10,300,225,ctx1 |
stdcall [glEnable], GL_DEPTH_TEST |
stdcall [glEnable], GL_NORMALIZE ;делам нормали одинаковой величины во избежание артефактов |
stdcall [gluNewQuadric] |
mov [qObj],eax |
56,7 → 55,7 |
mcall 12,1 |
mov edx,0x33ffffff ;0x73ffffff |
mcall 0,(50 shl 16)+430,(30 shl 16)+375,,,caption |
mcall 0,(50 shl 16)+330,(30 shl 16)+275,,,caption |
stdcall [kosglSwapBuffers] |
mcall 12,2 |
151,15 → 150,15 |
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, 32,32 |
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, 16,16 |
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, 16,16 |
stdcall [gluSphere], [qObj], 0.55, 8,8 |
stdcall [glPopMatrix] |
ret |
/programs/develop/libraries/TinyGL/asm_fork/zmath.asm |
---|
605,7 → 605,8 |
fmul st0,st0 |
faddp |
fsqrt ;st0 = sqrt(a.X^2 +a.Y^2 +a.Z^2) |
ftst |
fldz |
fcomp |
fstsw ax |
sahf |
je .r1 ;if (sqrt(...)==0) return 1 |
/programs/develop/libraries/TinyGL/asm_fork/matrix.asm |
---|
1,10 → 1,6 |
if DEBUG |
align 4 |
txt_gl_scal db 'glopScale',0 |
txt_gl_tran db 'glopTranslate',0 |
align 4 |
proc gl_print_matrix uses eax ebx ecx edi, m:dword, rows:dword |
mov ecx,[rows] |
cmp ecx,1 |
384,7 → 380,6 |
loop @b |
if DEBUG ;glopScale |
stdcall dbg_print,txt_gl_scal,txt_nl |
mov ebx,[eax+offs_cont_matrix_mode] |
shl ebx,2 |
add ebx,eax |
413,10 → 408,10 |
fmul st0,st3 ;m[0] * x |
fld dword[ebx+4] ;m[1] |
fmul st0,st3 ;m[1] * y |
faddp |
fld dword[ebx+8] ;m[2] |
fmul st0,st2 ;m[2] * z |
fmul st0,st3 ;m[2] * z |
faddp |
faddp |
fadd dword[ebx+12] ;m[3] |
fstp dword[ebx+12] ;m[3] = m[0] * x + m[1] * y + m[2] * z + m[3] |
add ebx,16 |
429,7 → 424,6 |
fincstp |
if DEBUG ;glopTranslate |
stdcall dbg_print,txt_gl_tran,txt_nl |
mov ebx,[eax+offs_cont_matrix_mode] |
shl ebx,2 |
add ebx,eax |
/programs/develop/libraries/TinyGL/asm_fork/init.asm |
---|
39,9 → 39,8 |
mov dword[edx+offs_cont_vertex],eax |
; viewport |
xor eax,eax |
mov dword[edx+offs_cont_viewport+offs_vpor_xmin],eax |
mov dword[edx+offs_cont_viewport+offs_vpor_ymin],eax |
mov dword[edx+offs_cont_viewport+offs_vpor_xmin],0 |
mov dword[edx+offs_cont_viewport+offs_vpor_ymin],0 |
mov eax,[ecx+offs_zbuf_xsize] |
mov dword[edx+offs_cont_viewport+offs_vpor_xsize],eax |
mov eax,[ecx+offs_zbuf_ysize] |
72,7 → 71,9 |
gl_V3_New eax+offs_ligh_norm_spot_direction, 0.0,0.0,-1.0 |
mov dword[eax+offs_ligh_spot_exponent],0.0 |
mov dword[eax+offs_ligh_spot_cutoff],180.0 |
gl_V3_New eax+offs_ligh_attenuation, 1.0,0.0,0.0 |
mov dword[eax+offs_ligh_attenuation],1.0 |
mov dword[eax+offs_ligh_attenuation+4],0.0 |
mov dword[eax+offs_ligh_attenuation+8],0.0 |
mov dword[eax+offs_ligh_enabled],0 |
add eax,sizeof.GLLight |
dec ecx |
106,14 → 107,25 |
stdcall glInitTextures,edx |
; default state |
gl_V4_New edx+offs_cont_current_color, 1.0,1.0,1.0,1.0 |
gl_V3_New edx+offs_cont_longcurrent_color, 65535,65535,65535 |
mov dword[edx+offs_cont_current_color],1.0 |
mov dword[edx+offs_cont_current_color+4],1.0 |
mov dword[edx+offs_cont_current_color+8],1.0 |
mov dword[edx+offs_cont_current_color+12],1.0 |
mov dword[edx+offs_cont_longcurrent_color],65535 |
mov dword[edx+offs_cont_longcurrent_color+4],65535 |
mov dword[edx+offs_cont_longcurrent_color+8],65535 |
gl_V4_New edx+offs_cont_current_normal, 1.0,0.0,0.0,0.0 |
mov dword[edx+offs_cont_current_normal],1.0 |
mov dword[edx+offs_cont_current_normal+4],0.0 |
mov dword[edx+offs_cont_current_normal+8],0.0 |
mov dword[edx+offs_cont_current_normal+12],0.0 |
mov dword[edx+offs_cont_current_edge_flag],1 |
gl_V4_New edx+offs_cont_current_tex_coord, 0.0,0.0,0.0,1.0 |
mov dword[edx+offs_cont_current_tex_coord],0.0 |
mov dword[edx+offs_cont_current_tex_coord+4],0.0 |
mov dword[edx+offs_cont_current_tex_coord+8],0.0 |
mov dword[edx+offs_cont_current_tex_coord+12],1.0 |
mov dword[edx+offs_cont_polygon_mode_front],GL_FILL |
mov dword[edx+offs_cont_polygon_mode_back],GL_FILL |
124,7 → 136,10 |
mov dword[edx+offs_cont_cull_face_enabled],0 |
; clear |
gl_V4_New edx+offs_cont_clear_color, 0.0,0.0,0.0,0.0 |
mov dword[edx+offs_cont_clear_color],0.0 |
mov dword[edx+offs_cont_clear_color+4],0.0 |
mov dword[edx+offs_cont_clear_color+8],0.0 |
mov dword[edx+offs_cont_clear_color+12],0.0 |
mov dword[edx+offs_cont_clear_depth],0 |
; selection |
135,8 → 150,9 |
; matrix |
mov dword[edx+offs_cont_matrix_mode],0 |
gl_V3_New edx+offs_cont_matrix_stack_depth_max,\ |
MAX_MODELVIEW_STACK_DEPTH,MAX_PROJECTION_STACK_DEPTH,MAX_TEXTURE_STACK_DEPTH |
mov dword[edx+offs_cont_matrix_stack_depth_max],MAX_MODELVIEW_STACK_DEPTH |
mov dword[edx+offs_cont_matrix_stack_depth_max+4],MAX_PROJECTION_STACK_DEPTH |
mov dword[edx+offs_cont_matrix_stack_depth_max+8],MAX_TEXTURE_STACK_DEPTH |
mov ecx,3 ;for(i=0;i<3;i++) |
mov ebx,edx |