Subversion Repositories Kolibri OS

Rev

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