Subversion Repositories Kolibri OS

Rev

Rev 5415 | 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.         gl_matrix_update eax,ebx
  120.         ret
  121. endp
  122.  
  123. align 4
  124. proc glopMultMatrix uses eax edi esi, context:dword, p:dword
  125. locals
  126.         m M4
  127. endl
  128.         mov esi,[p]
  129.         add esi,4
  130.         mov edi,ebp
  131.         sub edi,sizeof.M4
  132.         stdcall gl_M4_Transpose,edi,esi ;транспонируем входную матрицу в локальную матрицу m
  133.  
  134.         mov eax,[context]
  135.         mov esi,[eax+offs_cont_matrix_mode]
  136.         shl esi,2
  137.         add esi,eax
  138.         stdcall gl_M4_MulLeft,dword[esi+offs_cont_matrix_stack_ptr],edi
  139.  
  140.         gl_matrix_update eax,edi
  141.         ret
  142. endp
  143.  
  144. align 4
  145. proc glopPushMatrix uses eax ebx, context:dword, p:dword
  146.         mov eax,[context]
  147.         mov ebx,[eax+offs_cont_matrix_mode]
  148.  
  149. ;  assert( (c->matrix_stack_ptr[ebx] - c->matrix_stack[ebx] + 1 )
  150. ;          < c->matrix_stack_depth_max[ebx] );
  151.  
  152.         shl ebx,2
  153.         add ebx,eax
  154.         add ebx,offs_cont_matrix_stack_ptr
  155.         add dword[ebx],sizeof.M4
  156.         mov ebx,[ebx] ;ebx = ++context.matrix_stack_ptr[context.matrix_mode]
  157.  
  158.         sub ebx,sizeof.M4
  159.         push ebx
  160.         add ebx,sizeof.M4
  161.         stdcall gl_M4_Move, ebx
  162.  
  163.         gl_matrix_update eax,ebx
  164.         ret
  165. endp
  166.  
  167. align 4
  168. proc glopPopMatrix uses eax ebx, context:dword, p:dword
  169.         mov eax,[context]
  170.         mov ebx,[eax+offs_cont_matrix_mode]
  171.  
  172. ;  assert( c->matrix_stack_ptr[n] > c->matrix_stack[n] );
  173.  
  174.         shl ebx,2
  175.         add ebx,eax
  176.         sub dword[ebx+offs_cont_matrix_stack_ptr],sizeof.M4
  177.  
  178.         gl_matrix_update eax,ebx
  179.         ret
  180. endp
  181.  
  182. align 4
  183. proc glopRotate uses eax ebx ecx edx, context:dword, p:dword
  184. locals
  185.         u0 dd ?
  186.         u1 dd ?
  187.         u2 dd ?
  188.         angle dd ?
  189.         cost dd ?
  190.         sint dd ?
  191.         m M4
  192. endl
  193.  
  194.         mov eax,[context]
  195.         mov ebx,[p]
  196.         mov ecx,ebp
  197.         sub ecx,sizeof.M4 ;ecx=&m
  198.         finit
  199.         fldpi
  200.         fmul dword[ebx+4]
  201.         fdiv dword[an180f]
  202.         fst dword[angle] ;angle = p[1].f * M_PI / 180.0
  203.         ;st0 = angle
  204.  
  205.         ; simple case detection
  206.         xor edx,edx
  207.         fld dword[ebx+16]
  208.         ftst
  209.         fstsw ax
  210.         sahf
  211.         je @f
  212.                 inc edx
  213.         @@:
  214.         fstp dword[u2]
  215.         fld dword[ebx+12]
  216.         ftst
  217.         fstsw ax
  218.         sahf
  219.         je @f
  220.                 or edx,2
  221.         @@:
  222.         fstp dword[u1]
  223.         fld dword[ebx+8]
  224.         ftst
  225.         fstsw ax
  226.         sahf
  227.         je @f
  228.                 or edx,4
  229.         @@:
  230.         fstp dword[u0]
  231.  
  232.         ;st0 = angle
  233.         ;ebx = ((u0 != 0)<<2) | ((u1 != 0)<<1) | (u2 != 0)
  234.         or edx,edx
  235.         jz .end_f ;если нет поворотов выход из функции
  236.         cmp edx,4
  237.         jne @f
  238.                 fld dword[u0]
  239.                 ftst
  240.                 fstsw ax
  241.                 ffree st0
  242.                 fincstp
  243.                 sahf
  244.                 jae .u0ch
  245.                         fchs ;if (u0 < 0) angle *= -1
  246.                 .u0ch:
  247.                 push dword 0
  248.                 fstp dword[esp-4]
  249.                 sub esp,4
  250.                 stdcall gl_M4_Rotate, ecx
  251.                 jmp .end_sw
  252.         @@:
  253.         cmp edx,2
  254.         jne @f
  255.                 fld dword[u1]
  256.                 ftst
  257.                 fstsw ax
  258.                 ffree st0
  259.                 fincstp
  260.                 sahf
  261.                 jae .u1ch
  262.                         fchs ;if (u1 < 0) angle *= -1
  263.                 .u1ch:
  264.                 push dword 1
  265.                 fstp dword[esp-4]
  266.                 sub esp,4
  267.                 stdcall gl_M4_Rotate, ecx
  268.                 jmp .end_sw
  269.         @@:
  270.         cmp edx,1
  271.         jne @f
  272.                 fld dword[u2]
  273.                 ftst
  274.                 fstsw ax
  275.                 ffree st0
  276.                 fincstp
  277.                 sahf
  278.                 jae .u2ch
  279.                         fchs ;if (u2 < 0) angle *= -1
  280.                 .u2ch:
  281.                 push dword 2
  282.                 fstp dword[esp-4]
  283.                 sub esp,4
  284.                 stdcall gl_M4_Rotate, ecx
  285.                 jmp .end_sw
  286.         @@: ;default:
  287.  
  288.                 ; normalize vector
  289.                 fld dword[u0]
  290.                 fmul st0,st0
  291.                 fld dword[u1]
  292.                 fmul st0,st0
  293.                 faddp
  294.                 fld dword[u2]
  295.                 fmul st0,st0
  296.                 faddp
  297. ;               fst dword[len] ;len = u0*u0+u1*u1+u2*u2
  298.                 ftst
  299.                 fstsw ax
  300.                 sahf
  301.                 je .f2 ;if (len == 0.0f) return
  302.                 fsqrt
  303.                 fld1
  304.                 fxch
  305.                 fdivp ;len = 1.0f / sqrt(len)
  306. ;               fst dword[len]
  307.                 fld dword[u0]
  308.                 fmul st0,st1
  309.                 fstp dword[u0] ;u0 *= len
  310.                 fld dword[u1]
  311.                 fmul st0,st1
  312.                 fstp dword[u1] ;u1 *= len
  313.                 fld dword[u2]
  314.                 fmul st0,st1
  315.                 fstp dword[u2] ;u2 *= len
  316.                 ;st0 = len, st1 = angle
  317.                 ffree st0
  318.                 fincstp
  319.  
  320.                 ; store cos and sin values
  321.                 fcos
  322.                 fst dword[cost] ;cost=cos(angle)
  323.                 fld dword[angle]
  324.                 fsin
  325.                 fst dword[sint] ;sint=sin(angle)
  326.  
  327.                 ; fill in the values
  328.                 mov ebx,0.0
  329.                 mov [ecx+3*16   ],ebx ;m[3][0]
  330.                 mov [ecx+3*16 +4],ebx ;m[3][1]
  331.                 mov [ecx+3*16 +8],ebx ;m[3][2]
  332.                 mov [ecx+     12],ebx ;m[0][3]
  333.                 mov [ecx+  16+12],ebx ;m[1][3]
  334.                 mov [ecx+2*16+12],ebx ;m[2][3]
  335.                 mov ebx,1.0
  336.                 mov [ecx+3*16+12],ebx ;m[3][3]
  337.  
  338.                 ; do the math
  339.                 fld dword[u0]
  340.                 fmul st0,st0
  341.                 fld1
  342.                 fsub st0,st1
  343.                 fmul st0,st3 ;st0 = cost*(1-u0^2)
  344.                 faddp
  345.                 fstp dword[ecx] ;m[0][0] = u0*u0+cost*(1-u0*u0)
  346.  
  347.                 fld1
  348.                 fsub st0,st2 ;st0 = 1-cost
  349.  
  350.                 fld st0
  351.                 fmul dword[u0]
  352.                 fmul dword[u1]
  353.                 fld dword[u2]
  354.                 fmul st0,st3 ;st0 = u2*sint
  355.                 fchs
  356.                 faddp
  357.                 fstp dword[ecx+16] ;m[1][0] = u0*u1*(1-cost)-u2*sint
  358.  
  359.                 fld st0
  360.                 fmul dword[u0]
  361.                 fmul dword[u2]
  362.                 fld dword[u1]
  363.                 fmul st0,st3 ;st0 = u1*sint
  364.                 faddp
  365.                 fstp dword[ecx+32] ;m.m[2][0]=u[2]*u[0]*(1-cost)+u[1]*sint
  366.  
  367.                 fld st0
  368.                 fmul dword[u0]
  369.                 fmul dword[u1]
  370.                 fld dword[u2]
  371.                 fmul st0,st3 ;st0 = u2*sint
  372.                 faddp
  373.                 fstp dword[ecx+4] ;m.m[0][1]=u[0]*u[1]*(1-cost)+u[2]*sint
  374.  
  375.                 fld dword[u1]
  376.                 fmul st0,st0
  377.                 fld1
  378.                 fsub st0,st1
  379.                 fmul st0,st4 ;st0 = cost*(1-u1^2)
  380.                 faddp
  381.                 fstp dword[ecx+20] ;m.m[1][1]=u[1]*u[1]+cost*(1-u[1]*u[1])
  382.  
  383.                 fld st0
  384.                 fmul dword[u1]
  385.                 fmul dword[u2]
  386.                 fld dword[u0]
  387.                 fmul st0,st3 ;st0 = u0*sint
  388.                 fchs
  389.                 faddp
  390.                 fstp dword[ecx+36] ;m.m[2][1]=u[1]*u[2]*(1-cost)-u[0]*sint
  391.  
  392.                 fld st0
  393.                 fmul dword[u0]
  394.                 fmul dword[u2]
  395.                 fld dword[u1]
  396.                 fmul st0,st3 ;st0 = u1*sint
  397.                 fchs
  398.                 faddp
  399.                 fstp dword[ecx+8] ;m.m[0][2]=u[2]*u[0]*(1-cost)-u[1]*sint
  400.  
  401.                 fld st0
  402.                 fmul dword[u1]
  403.                 fmul dword[u2]
  404.                 fld dword[u0]
  405.                 fmul st0,st3 ;st0 = u0*sint
  406.                 faddp
  407.                 fstp dword[ecx+24] ;m.m[1][2]=u[1]*u[2]*(1-cost)+u[0]*sint
  408.  
  409.                 ffree st0 ;1-cost
  410.                 fincstp
  411.  
  412.                 fld dword[u2]
  413.                 fmul st0,st0
  414.                 fld1
  415.                 fsub st0,st1
  416.                 fmul st0,st3 ;st0 = cost*(1-u2^2)
  417.                 faddp
  418.                 fstp dword[ecx+40] ;m[2][2] = u2*u2+cost*(1-u2*u2)
  419.  
  420.                 ffree st0 ;sint
  421.   fincstp
  422.                 ffree st0 ;cost
  423.   fincstp
  424.         .end_sw:
  425.  
  426.         mov eax,[context]
  427.         mov ebx,[eax+offs_cont_matrix_mode]
  428.         shl ebx,2
  429.         add ebx,eax
  430.         stdcall gl_M4_MulLeft,dword[ebx+offs_cont_matrix_stack_ptr],ecx
  431.         gl_matrix_update eax,ebx
  432.         jmp .end_f
  433.         .f2:
  434.                 ffree st0 ;len
  435.                 fincstp
  436.                 ffree st0 ;angle
  437.                 fincstp
  438.         .end_f:
  439.         ret
  440. endp
  441.  
  442. align 4
  443. proc glopScale uses eax ebx ecx, context:dword, p:dword
  444.         mov ecx,[p]
  445.  
  446.         mov eax,[context]
  447.         mov ebx,[eax+offs_cont_matrix_mode]
  448.         shl ebx,2
  449.         add ebx,eax
  450.         mov ebx,[ebx+offs_cont_matrix_stack_ptr] ;ebx = &m[0]
  451.  
  452.         fld dword[ecx+ 4] ;x
  453.         fld dword[ecx+ 8] ;y
  454.         fld dword[ecx+12] ;z
  455.         mov ecx,4
  456.         @@:
  457.         fld dword[ebx]   ;m[0]
  458.         fmul st0,st3     ;m[0] * x
  459.         fstp dword[ebx]  ;m[0] *= x
  460.         fld dword[ebx+4] ;m[1]
  461.         fmul st0,st2     ;m[1] * y
  462.         fstp dword[ebx+4];m[1] *= y
  463.         fld dword[ebx+8] ;m[2]
  464.         fmul st0,st1     ;m[2] * z
  465.         fstp dword[ebx+8];m[2] *= z
  466.         add ebx,16
  467.         loop @b
  468.         ffree st0
  469.         fincstp
  470.         ffree st0
  471.         fincstp
  472.         ffree st0
  473.         fincstp
  474.  
  475.         gl_matrix_update eax,ebx
  476.         ret
  477. endp
  478.  
  479. align 4
  480. proc glopTranslate uses eax ebx ecx, context:dword, p:dword
  481.         mov ecx,[p]
  482.  
  483.         mov eax,[context]
  484.         mov ebx,[eax+offs_cont_matrix_mode]
  485.         shl ebx,2
  486.         add ebx,eax
  487.         mov ebx,[ebx+offs_cont_matrix_stack_ptr] ;ebx = &m[0]
  488.  
  489.         fld dword[ecx+ 4] ;x
  490.         fld dword[ecx+ 8] ;y
  491.         fld dword[ecx+12] ;z
  492.         mov ecx,4
  493.         @@:
  494.                 fld dword[ebx]   ;m[0]
  495.                 fmul st0,st3     ;m[0] * x
  496.                 fld dword[ebx+4] ;m[1]
  497.                 fmul st0,st3     ;m[1] * y
  498.                 faddp
  499.                 fld dword[ebx+8] ;m[2]
  500.                 fmul st0,st2     ;m[2] * z
  501.                 faddp
  502.                 fadd dword[ebx+12] ;m[3]
  503.                 fstp dword[ebx+12] ;m[3] = m[0] * x + m[1] * y + m[2] * z + m[3]
  504.                 add ebx,16
  505.         loop @b
  506.         ffree st0
  507.         fincstp
  508.         ffree st0
  509.         fincstp
  510.         ffree st0
  511.         fincstp
  512.  
  513.         gl_matrix_update eax,ebx
  514.         ret
  515. endp
  516.  
  517. align 4
  518. proc glopFrustum uses eax ebx ecx, context:dword, p:dword
  519. locals
  520.         x dd ?
  521.         y dd ?
  522.         A dd ?
  523.         B dd ?
  524.         C dd ?
  525.         D dd ?
  526.         m M4
  527. endl
  528.         mov eax,[context]
  529.         mov ebx,[p]
  530.  
  531.         fld dword[ebx+8]
  532.         fsub dword[ebx+4]  ;st0 = (right-left)
  533.         fld dword[ebx+20]  ;st0 = near
  534.         fadd st0,st0
  535.         fdiv st0,st1
  536.         fstp dword[x]      ;x = (2.0*near) / (right-left)
  537.         fld dword[ebx+16]
  538.         fsub dword[ebx+12] ;st0 = (top-bottom)
  539.         fld dword[ebx+20]  ;st0 = near
  540.         fadd st0,st0
  541.         fdiv st0,st1
  542.         fstp dword[y]      ;y = (2.0*near) / (top-bottom)
  543.         fld dword[ebx+8]
  544.         fadd dword[ebx+4]  ;st0 = (right+left)
  545.         fdiv st0,st2       ;st2 = (right-left)
  546.         fstp dword[A]      ;A = (right+left) / (right-left)
  547.         fld dword[ebx+16]
  548.         fadd dword[ebx+12] ;st0 = (top+bottom)
  549.         fdiv st0,st1       ;st1 = (top-bottom)
  550.         fstp dword[B]      ;B = (top+bottom) / (top-bottom)
  551.         fld dword[ebx+24]
  552.         fsub dword[ebx+20] ;st0 = (farp-near)
  553.         fld dword[ebx+24]
  554.         fadd dword[ebx+20]
  555.         fchs ;st0 = -(farp+near)
  556.         fdiv st0,st1
  557.         fstp dword[C]      ;C = -(farp+near) / (farp-near)
  558.         fld dword[ebx+24]
  559.         fmul dword[ebx+20] ;st0 = farp*near
  560.         fadd st0,st0
  561.         fchs               ;st0 = -(2.0*farp*near)
  562.         fdiv st0,st1
  563.         fstp dword[D]      ;D = -(2.0*farp*near) / (farp-near)
  564.         ffree st0
  565.         fincstp
  566.         ffree st0
  567.         fincstp
  568.         ffree st0
  569.         fincstp
  570.  
  571.         mov ecx,ebp
  572.         sub ecx,sizeof.M4
  573.  
  574.         mov ebx,[x]
  575.         mov dword[ecx],ebx
  576.         mov dword[ecx+4],0.0
  577.         mov ebx,[A]
  578.         mov dword[ecx+8],ebx
  579.         mov dword[ecx+12],0.0
  580.         mov dword[ecx+16],0.0
  581.         mov ebx,[y]
  582.         mov dword[ecx+20],ebx
  583.         mov ebx,[B]
  584.         mov dword[ecx+24],ebx
  585.         mov dword[ecx+28],0.0
  586.         mov dword[ecx+32],0.0
  587.         mov dword[ecx+36],0.0
  588.         mov ebx,[C]
  589.         mov dword[ecx+40],ebx
  590.         mov ebx,[D]
  591.         mov dword[ecx+44],ebx
  592.         mov dword[ecx+48],0.0
  593.         mov dword[ecx+52],0.0
  594.         mov dword[ecx+56],-1.0
  595.         mov dword[ecx+60],0.0
  596.  
  597.         mov ebx,[eax+offs_cont_matrix_mode]
  598.         shl ebx,2
  599.         add ebx,eax
  600.         stdcall gl_M4_MulLeft,dword[ebx+offs_cont_matrix_stack_ptr],ecx
  601.  
  602. if DEBUG ;glopFrustum
  603.         stdcall gl_print_matrix,ecx,4
  604.         stdcall gl_print_matrix,dword[ebx+offs_cont_matrix_stack_ptr],4
  605. end if
  606.         gl_matrix_update eax,ebx
  607.         ret
  608. endp
  609.  
  610.  
  611.