Subversion Repositories Kolibri OS

Rev

Rev 5269 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. if DEBUG
  3. align 4
  4. proc gl_print_matrix uses eax ebx ecx edi, m:dword, rows:dword
  5.         mov ecx,[rows]
  6.         cmp ecx,1
  7.         jl .end_f
  8.         mov ebx,[m]
  9.         mov word[NumberSymbolsAD],3
  10.         finit
  11.         @@:
  12.                 lea edi,[buf_param]
  13.                 mov byte[edi],0
  14.  
  15.                 fld dword[ebx]
  16.                 fstp qword[Data_Double]
  17.                 call DoubleFloat_to_String
  18.                 stdcall str_cat, edi,Data_String
  19.  
  20.                 stdcall str_n_cat,edi,txt_zp_sp,2
  21.                 stdcall str_len,edi
  22.                 add edi,eax
  23.  
  24.                 fld dword[ebx+4]
  25.                 fstp qword[Data_Double]
  26.                 call DoubleFloat_to_String
  27.                 stdcall str_cat, edi,Data_String
  28.  
  29.                 stdcall str_n_cat,edi,txt_zp_sp,2
  30.                 stdcall str_len,edi
  31.                 add edi,eax
  32.  
  33.                 fld dword[ebx+8]
  34.                 fstp qword[Data_Double]
  35.                 call DoubleFloat_to_String
  36.                 stdcall str_cat, edi,Data_String
  37.  
  38.                 stdcall str_n_cat,edi,txt_zp_sp,2
  39.                 stdcall str_len,edi
  40.                 add edi,eax
  41.  
  42.                 fld dword[ebx+12]
  43.                 fstp qword[Data_Double]
  44.                 call DoubleFloat_to_String
  45.                 stdcall str_cat, edi,Data_String
  46.  
  47.                 stdcall str_n_cat,edi,txt_nl,2
  48.                 stdcall dbg_print,txt_sp,buf_param
  49.                
  50.                 add ebx,16
  51.         dec ecx
  52.         cmp ecx,0
  53.         jg @b
  54.         .end_f:
  55.         ret
  56. endp
  57. end if
  58.  
  59. macro gl_matrix_update context, reg
  60. {
  61.         local .end_0
  62.         xor reg,reg
  63.         cmp dword[context+offs_cont_matrix_mode],1
  64.         jg .end_0
  65.                 inc reg
  66.         .end_0:
  67.         mov dword[context+offs_cont_matrix_model_projection_updated],reg
  68. }
  69.  
  70. align 4
  71. proc glopMatrixMode uses eax ebx, context:dword, p:dword
  72.         mov eax,[context]
  73.         mov ebx,[p]
  74.  
  75.         cmp dword[ebx+4],GL_MODELVIEW ;cmp p[1],...
  76.         jne @f
  77.                 mov dword[eax+offs_cont_matrix_mode],0
  78.                 jmp .end_f
  79.         @@:
  80.         cmp dword[ebx+4],GL_PROJECTION
  81.         jne @f
  82.                 mov dword[eax+offs_cont_matrix_mode],1
  83.                 jmp .end_f
  84.         @@:
  85.         cmp dword[ebx+4],GL_TEXTURE
  86.         jne .def
  87.                 mov dword[eax+offs_cont_matrix_mode],2
  88.                 jmp .end_f
  89.         .def:
  90. ;assert(0);
  91.         .end_f:
  92.         ret
  93. endp
  94.  
  95. align 4
  96. proc glopLoadMatrix uses eax edi esi, context:dword, p:dword
  97.         mov eax,[context]
  98.         mov edi,[eax+offs_cont_matrix_mode]
  99.         shl edi,2
  100.         add edi,eax
  101.         mov edi,dword[edi+offs_cont_matrix_stack_ptr]
  102.  
  103.         mov esi,[p]
  104.         add esi,4
  105.         stdcall gl_M4_Transpose,edi,esi ;транспонируем входную матрицу в матрицу context.matrix_stack_ptr[context.matrix_mode]
  106.  
  107.         gl_matrix_update eax,edi
  108.         ret
  109. endp
  110.  
  111. align 4
  112. proc glopLoadIdentity uses eax ebx, context:dword, p:dword
  113.         mov eax,[context]
  114.         mov ebx,[eax+offs_cont_matrix_mode]
  115.         shl ebx,2
  116.         add ebx,eax
  117.  
  118.         stdcall gl_M4_Id,[ebx+offs_cont_matrix_stack_ptr]
  119. if DEBUG ;glopLoadIdentity
  120.         stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4
  121. end if
  122.         gl_matrix_update eax,ebx
  123.         ret
  124. endp
  125.  
  126. align 4
  127. proc glopMultMatrix uses eax edi esi, context:dword, p:dword
  128. locals
  129.         m M4
  130. endl
  131.         mov esi,[p]
  132.         add esi,4
  133.         mov edi,ebp
  134.         sub edi,sizeof.M4
  135.         stdcall gl_M4_Transpose,edi,esi ;транспонируем входную матрицу в локальную матрицу m
  136.  
  137.         mov eax,[context]
  138.         mov esi,[eax+offs_cont_matrix_mode]
  139.         shl esi,2
  140.         add esi,eax
  141.         stdcall gl_M4_MulLeft,dword[esi+offs_cont_matrix_stack_ptr],edi
  142.  
  143.         gl_matrix_update eax,edi
  144.         ret
  145. endp
  146.  
  147. align 4
  148. proc glopPushMatrix uses eax ebx, context:dword, p:dword
  149.         mov eax,[context]
  150.         mov ebx,[eax+offs_cont_matrix_mode]
  151.  
  152. ;  assert( (c->matrix_stack_ptr[ebx] - c->matrix_stack[ebx] + 1 )
  153. ;          < c->matrix_stack_depth_max[ebx] );
  154.  
  155.         shl ebx,2
  156.         add ebx,eax
  157.         add ebx,offs_cont_matrix_stack_ptr
  158.         add dword[ebx],sizeof.M4
  159.         mov ebx,[ebx] ;ebx = ++context.matrix_stack_ptr[context.matrix_mode]
  160.  
  161.         sub ebx,sizeof.M4
  162.         push ebx
  163.         add ebx,sizeof.M4
  164.         stdcall gl_M4_Move, ebx
  165.  
  166.         gl_matrix_update eax,ebx
  167.         ret
  168. endp
  169.  
  170. align 4
  171. proc glopPopMatrix uses eax ebx, context:dword, p:dword
  172.         mov eax,[context]
  173.         mov ebx,[eax+offs_cont_matrix_mode]
  174.  
  175. ;  assert( c->matrix_stack_ptr[n] > c->matrix_stack[n] );
  176.  
  177.         shl ebx,2
  178.         add ebx,eax
  179.         sub dword[ebx+offs_cont_matrix_stack_ptr],sizeof.M4
  180.  
  181.         gl_matrix_update eax,ebx
  182.         ret
  183. endp
  184.  
  185. align 4
  186. proc glopRotate uses eax ebx ecx, context:dword, p:dword
  187. locals
  188.         u0 dd ?
  189.         u1 dd ?
  190.         u2 dd ?
  191.         angle dd ?
  192.         cost dd ?
  193.         sint dd ?
  194.         m M4
  195. endl
  196.  
  197.         mov eax,[context]
  198.         mov ebx,[p]
  199.         mov ecx,ebp
  200.         sub ecx,sizeof.M4 ;ecx=&m
  201.         finit
  202.         fldpi
  203.         fmul dword[ebx+4]
  204.         fdiv dword[an180f]
  205.         fst dword[angle] ;angle = p[1].f * M_PI / 180.0
  206.         ;st0 = angle
  207.  
  208.         fldz
  209.         fild dword[ebx+8]
  210.         fstp dword[u0]
  211.         fild dword[ebx+12]
  212.         fstp dword[u1]
  213.         fild dword[ebx+16]
  214.         fst dword[u2]
  215.  
  216.         ; simple case detection
  217.         xor ebx,ebx
  218.         fcomp st1 ;u2 ... 0
  219.         fstsw ax
  220.         sahf
  221.         je @f
  222.                 inc ebx
  223.         @@:
  224.         fcom dword[u1] ;0 ... u1
  225.         fstsw ax
  226.         sahf
  227.         je @f
  228.                 or ebx,2
  229.         @@:
  230.         fcom dword[u0] ;0 ... u0
  231.         fstsw ax
  232.         sahf
  233.         je @f
  234.                 or ebx,4
  235.         @@:
  236.         ;st0 = 0, st1 = angle
  237.  
  238.         ;ebx = ((u0 != 0)<<2) | ((u1 != 0)<<1) | (u2 != 0)
  239.         cmp ebx,0
  240.         je .end_f ;если нет поворотов выход из функции
  241.         cmp ebx,4
  242.         jne @f
  243.                 fcomp dword[u0] ;0 ... u0
  244.                 fstsw ax
  245.                 sahf
  246.                 jae .u0ch
  247.                         fchs
  248.                         fstp dword[angle] ;if (u0 < 0) angle *= -1
  249.                 .u0ch:
  250.                 stdcall gl_M4_Rotate, ecx,[angle],0
  251.                 jmp .end_sw
  252.         @@:
  253.         cmp ebx,2
  254.         jne @f
  255.                 fcomp dword[u1] ;0 ... u1
  256.                 fstsw ax
  257.                 sahf
  258.                 jae .u1ch
  259.                         fchs
  260.                         fstp dword[angle] ;if (u1 < 0) angle *= -1
  261.                 .u1ch:
  262.                 stdcall gl_M4_Rotate, ecx,[angle],1
  263.                 jmp .end_sw
  264.         @@:
  265.         cmp ebx,1
  266.         jne @f
  267.                 fcomp dword[u2] ;0 ... u2
  268.                 fstsw ax
  269.                 sahf
  270.                 jae .u2ch
  271.                         fchs
  272.                         fstp dword[angle] ;if (u2 < 0) angle *= -1
  273.                 .u2ch:
  274.                 stdcall gl_M4_Rotate, ecx,[angle],2
  275.                 jmp .end_sw
  276.         @@: ;default:
  277. if DEBUG ;glopRotete
  278.                 stdcall dbg_print,txt_sp,m_1
  279. end if
  280.  
  281.                 ; normalize vector
  282.                 fld dword[u0]
  283.                 fmul st0,st0
  284.                 fld dword[u1]
  285.                 fmul st0,st0
  286.                 fld dword[u2]
  287.                 fmul st0,st0
  288.                 fadd st0,st1
  289.                 fadd st0,st2
  290. ;               fst dword[len] ;len = u0*u0+u1*u1+u2*u2
  291.                 fcom st1
  292.                 fstsw ax
  293.                 sahf
  294.                 je .end_f ;if (len == 0.0f) return
  295.                 fsqrt
  296.                 fld1
  297.                 fdiv st0,st1
  298. ;               fst dword[len] ;len = 1.0f / sqrt(len)
  299.                 fld dword[u0]
  300.                 fmul st0,st1
  301.                 fstp dword[u0] ;u0 *= len
  302.                 fld dword[u1]
  303.                 fmul st0,st1
  304.                 fstp dword[u1] ;u1 *= len
  305.                 fld dword[u2]
  306.                 fmul st0,st1
  307.                 fstp dword[u2] ;u2 *= len
  308.                 ;st0 = len, st1=..., st2=..., st3 = 0, st4 = angle
  309.  
  310.                 ; store cos and sin values
  311.                 finit
  312.                 fld dword[angle]
  313.                 fcos
  314.                 fst dword[cost] ;cost=cos(angle)
  315.                 fld dword[angle]
  316.                 fsin
  317.                 fst dword[sint] ;sint=sin(angle)
  318.  
  319.                 ; fill in the values
  320.                 mov ebx,0.0
  321.                 mov [ecx+3*16   ],ebx ;m[3][0]
  322.                 mov [ecx+3*16 +4],ebx ;m[3][1]
  323.                 mov [ecx+3*16 +8],ebx ;m[3][2]
  324.                 mov [ecx+     12],ebx ;m[0][3]
  325.                 mov [ecx+  16+12],ebx ;m[1][3]
  326.                 mov [ecx+2*16+12],ebx ;m[2][3]
  327.                 mov ebx,1.0
  328.                 mov [ecx+3*16+12],ebx ;m[3][3]
  329.  
  330.                 ; do the math
  331. ;      m.m[0][0]=u[0]*u[0]+cost*(1-u[0]*u[0]);
  332. ;      m.m[1][0]=u[0]*u[1]*(1-cost)-u[2]*sint;
  333. ;      m.m[2][0]=u[2]*u[0]*(1-cost)+u[1]*sint;
  334. ;      m.m[0][1]=u[0]*u[1]*(1-cost)+u[2]*sint;
  335. ;      m.m[1][1]=u[1]*u[1]+cost*(1-u[1]*u[1]);
  336. ;      m.m[2][1]=u[1]*u[2]*(1-cost)-u[0]*sint;
  337. ;      m.m[0][2]=u[2]*u[0]*(1-cost)-u[1]*sint;
  338. ;      m.m[1][2]=u[1]*u[2]*(1-cost)+u[0]*sint;
  339. ;      m.m[2][2]=u[2]*u[2]+cost*(1-u[2]*u[2]);
  340.         .end_sw:
  341.  
  342.         mov eax,[context]
  343.         mov ebx,[eax+offs_cont_matrix_mode]
  344.         shl ebx,2
  345.         add ebx,eax
  346.         stdcall gl_M4_MulLeft,dword[ebx+offs_cont_matrix_stack_ptr],ecx
  347. if DEBUG ;glopRotete
  348.                 stdcall gl_print_matrix,ecx,4
  349. end if
  350.         gl_matrix_update eax,ebx
  351.         .end_f:
  352.         ret
  353. endp
  354.  
  355. align 4
  356. proc glopScale uses eax ebx ecx, context:dword, p:dword
  357.         mov ecx,[p]
  358.  
  359.         mov eax,[context]
  360.         mov ebx,[eax+offs_cont_matrix_mode]
  361.         shl ebx,2
  362.         add ebx,eax
  363.         mov ebx,[ebx+offs_cont_matrix_stack_ptr] ;ebx = &m[0]
  364.  
  365.         fld dword[ecx+ 4] ;x
  366.         fld dword[ecx+ 8] ;y
  367.         fld dword[ecx+12] ;z
  368.         mov ecx,4
  369.         @@:
  370.         fld dword[ebx]   ;m[0]
  371.         fmul st0,st3     ;m[0] * x
  372.         fstp dword[ebx]  ;m[0] *= x
  373.         fld dword[ebx+4] ;m[1]
  374.         fmul st0,st2     ;m[1] * y
  375.         fstp dword[ebx+4];m[1] *= y
  376.         fld dword[ebx+8] ;m[2]
  377.         fmul st0,st1     ;m[2] * z
  378.         fstp dword[ebx+8];m[2] *= z
  379.         add ebx,16
  380.         loop @b
  381.  
  382. if DEBUG ;glopScale
  383.         mov ebx,[eax+offs_cont_matrix_mode]
  384.         shl ebx,2
  385.         add ebx,eax
  386.         stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4
  387. end if
  388.         gl_matrix_update eax,ebx
  389.         ret
  390. endp
  391.  
  392. align 4
  393. proc glopTranslate uses eax ebx ecx, context:dword, p:dword
  394.         mov ecx,[p]
  395.  
  396.         mov eax,[context]
  397.         mov ebx,[eax+offs_cont_matrix_mode]
  398.         shl ebx,2
  399.         add ebx,eax
  400.         mov ebx,[ebx+offs_cont_matrix_stack_ptr] ;ebx = &m[0]
  401.  
  402.         fld dword[ecx+ 4] ;x
  403.         fld dword[ecx+ 8] ;y
  404.         fld dword[ecx+12] ;z
  405.         mov ecx,4
  406.         @@:
  407.                 fld dword[ebx]   ;m[0]
  408.                 fmul st0,st3     ;m[0] * x
  409.                 fld dword[ebx+4] ;m[1]
  410.                 fmul st0,st3     ;m[1] * y
  411.                 fld dword[ebx+8] ;m[2]
  412.                 fmul st0,st3     ;m[2] * z
  413.                 fadd st0,st1
  414.                 fadd st0,st2
  415.                 fadd dword[ebx+12] ;m[3]
  416.                 fstp dword[ebx+12] ;m[3] = m[0] * x + m[1] * y + m[2] * z + m[3]
  417.                 ffree st0
  418.                 fincstp
  419.                 ffree st0
  420.                 fincstp
  421.                 add ebx,16
  422.         loop @b
  423.  
  424. if DEBUG ;glopTranslate
  425.         mov ebx,[eax+offs_cont_matrix_mode]
  426.         shl ebx,2
  427.         add ebx,eax
  428.         stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4
  429. end if
  430.         gl_matrix_update eax,ebx
  431.         ret
  432. endp
  433.  
  434. align 4
  435. proc glopFrustum uses eax ebx ecx, context:dword, p:dword
  436. locals
  437.         x dd ?
  438.         y dd ?
  439.         A dd ?
  440.         B dd ?
  441.         C dd ?
  442.         D dd ?
  443.         m M4
  444. endl
  445.         mov eax,[context]
  446.         mov ebx,[p]
  447.  
  448.         fld dword[ebx+8]
  449.         fsub dword[ebx+4]  ;st0 = (right-left)
  450.         fld dword[ebx+20]  ;st0 = near
  451.         fadd st0,st0
  452.         fdiv st0,st1
  453.         fstp dword[x]      ;x = (2.0*near) / (right-left)
  454.         fld dword[ebx+16]
  455.         fsub dword[ebx+12] ;st0 = (top-bottom)
  456.         fld dword[ebx+20]  ;st0 = near
  457.         fadd st0,st0
  458.         fdiv st0,st1
  459.         fstp dword[y]      ;y = (2.0*near) / (top-bottom)
  460.         fld dword[ebx+8]
  461.         fadd dword[ebx+4]  ;st0 = (right+left)
  462.         fdiv st0,st2       ;st2 = (right-left)
  463.         fstp dword[A]      ;A = (right+left) / (right-left)
  464.         fld dword[ebx+16]
  465.         fadd dword[ebx+12] ;st0 = (top+bottom)
  466.         fdiv st0,st1       ;st1 = (top-bottom)
  467.         fstp dword[B]      ;B = (top+bottom) / (top-bottom)
  468.         fld dword[ebx+24]
  469.         fsub dword[ebx+20] ;st0 = (farp-near)
  470.         fldz
  471.         fsub dword[ebx+24]
  472.         fsub dword[ebx+20] ;st0 = -(farp+near)
  473.         fdiv st0,st1
  474.         fstp dword[C]      ;C = -(farp+near) / (farp-near)
  475.         fld dword[ebx+24]
  476.         fmul dword[ebx+20] ;st0 = farp*near
  477.         fadd st0,st0
  478.         fchs               ;st0 = -(2.0*farp*near)
  479.         fdiv st0,st1
  480.         fstp dword[D]      ;D = -(2.0*farp*near) / (farp-near)
  481.  
  482.         mov ecx,ebp
  483.         sub ecx,sizeof.M4
  484.  
  485.         mov ebx,[x]
  486.         mov dword[ecx],ebx
  487.         mov dword[ecx+4],0.0
  488.         mov ebx,[A]
  489.         mov dword[ecx+8],ebx
  490.         mov dword[ecx+12],0.0
  491.         mov dword[ecx+16],0.0
  492.         mov ebx,[y]
  493.         mov dword[ecx+20],ebx
  494.         mov ebx,[B]
  495.         mov dword[ecx+24],ebx
  496.         mov dword[ecx+28],0.0
  497.         mov dword[ecx+32],0.0
  498.         mov dword[ecx+36],0.0
  499.         mov ebx,[C]
  500.         mov dword[ecx+40],ebx
  501.         mov ebx,[D]
  502.         mov dword[ecx+44],ebx
  503.         mov dword[ecx+48],0.0
  504.         mov dword[ecx+52],0.0
  505.         mov dword[ecx+56],-1.0
  506.         mov dword[ecx+60],0.0
  507.  
  508.         mov ebx,[eax+offs_cont_matrix_mode]
  509.         shl ebx,2
  510.         add ebx,eax
  511.         stdcall gl_M4_MulLeft,dword[ebx+offs_cont_matrix_stack_ptr],ecx
  512.  
  513. if DEBUG ;glopFrustum
  514.         stdcall gl_print_matrix,ecx,4
  515.         stdcall gl_print_matrix,dword[ebx+offs_cont_matrix_stack_ptr],4
  516. end if
  517.         gl_matrix_update eax,ebx
  518.         ret
  519. endp
  520.  
  521.  
  522.