Subversion Repositories Kolibri OS

Rev

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

  1. if DEBUG
  2. f_vt db ' gl_vertex_transform',0
  3. end if
  4.  
  5. align 16
  6. proc glopNormal uses ecx esi edi, context:dword, p:dword
  7.         mov esi,[p]
  8.         add esi,4
  9.         mov edi,[context]
  10.         add edi,GLContext.current_normal
  11.         mov ecx,3
  12.         rep movsd
  13.         mov dword[edi],0.0 ;context.current_normal.W = 0.0
  14.         ret
  15. endp
  16.  
  17. align 16
  18. proc glopTexCoord uses ecx esi edi, context:dword, p:dword
  19.         mov esi,[p]
  20.         add esi,4
  21.         mov edi,[context]
  22.         add edi,GLContext.current_tex_coord
  23.         mov ecx,4
  24.         rep movsd
  25.         ret
  26. endp
  27.  
  28. align 16
  29. proc glopEdgeFlag uses eax ebx, context:dword, p:dword
  30.         mov eax,[context]
  31.         mov ebx,[p]
  32.         mov ebx,[ebx+4] ;ebx = p[1]
  33.         mov dword[eax+GLContext.current_edge_flag],ebx
  34.         ret
  35. endp
  36.  
  37. align 16
  38. proc glopColor uses eax ecx esi edi, context:dword, p:dword
  39. locals
  40.         q rd 7
  41. endl
  42.         ;current_color[3] = p[1-4]
  43.         ;longcurrent_color[2] = p[5-7]
  44.         mov esi,[p]
  45.         add esi,4
  46.         mov edi,[context]
  47.         add edi,GLContext.current_color
  48.         mov ecx,7
  49.         rep movsd
  50.  
  51.         mov eax,[context]
  52.         cmp dword[eax+GLContext.color_material_enabled],0
  53.         je @f
  54.                 mov dword[q],OP_Material
  55.                 mov ecx,[eax+GLContext.current_color_material_mode]
  56.                 mov dword[q+4],ecx
  57.                 mov ecx,[eax+GLContext.current_color_material_type]
  58.                 mov dword[q+8],ecx
  59.                 mov esi,[p]
  60.                 add esi,4
  61.                 mov edi,ebp
  62.                 sub edi,16 ;edi = &q[3]
  63.                 mov ecx,4
  64.                 rep movsd
  65.                 ;mov edi,ebp
  66.                 sub edi,28 ;edi = &q
  67.                 stdcall glopMaterial, eax,edi
  68.         @@:
  69.         ret
  70. endp
  71.  
  72. align 16
  73. proc gl_eval_viewport uses eax, context:dword
  74. locals
  75.         zsize dd ? ;float
  76. endl
  77.         mov eax,[context]
  78.         add eax,GLContext.viewport ;eax = (GLViewport*) v
  79.  
  80.         mov dword[zsize],(1 shl (ZB_Z_BITS + ZB_POINT_Z_FRAC_BITS))
  81.         fild dword[zsize]
  82.         fstp dword[zsize]
  83.  
  84.         fld1
  85.         fld1
  86.         fadd st1,st0 ;st1 = 2.0
  87.         fdiv st0,st1 ;st0 = 0.5
  88.  
  89.         fild dword[eax+offs_vpor_xsize]
  90.         fsub st0,st1
  91.         fdiv st0,st2
  92.         fst dword[eax+offs_vpor_scale+offs_X]
  93.         fiadd dword[eax+offs_vpor_xmin]
  94.         fstp dword[eax+offs_vpor_trans+offs_X]
  95.  
  96.         fild dword[eax+offs_vpor_ysize]
  97.         fsub st0,st1
  98.         fdiv st0,st2
  99.         fchs
  100.         fst dword[eax+offs_vpor_scale+offs_Y]
  101.         fchs
  102.         fiadd dword[eax+offs_vpor_ymin]
  103.         fstp dword[eax+offs_vpor_trans+offs_Y]
  104.  
  105.         fld dword[zsize]
  106.         fsub st0,st1
  107.         fdiv st0,st2
  108.         fchs
  109.         fst dword[eax+offs_vpor_scale+offs_Z]
  110.         fchs
  111.         mov dword[zsize],(1 shl ZB_POINT_Z_FRAC_BITS) / 2
  112.         fiadd dword[zsize]
  113.         fstp dword[eax+offs_vpor_trans+offs_Z]
  114.         ret
  115. endp
  116.  
  117.  
  118. align 16
  119. proc glopBegin uses eax ebx ecx edx, context:dword, p:dword
  120. locals
  121.         tmp M4
  122. endl
  123. ;assert(context.in_begin == 0)
  124.  
  125.         mov edx,[context]
  126.         mov ebx,[p]
  127.         mov ebx,[ebx+4] ;ebx = p[1]
  128.         mov [edx+GLContext.begin_type],ebx
  129.         mov dword[edx+GLContext.in_begin],1
  130.         mov dword[edx+GLContext.vertex_n],0
  131.         mov dword[edx+GLContext.vertex_cnt],0
  132.  
  133.         bt dword[edx+GLContext.matrix_model_projection_updated],0
  134.         jnc .end_mmpu
  135.  
  136.         cmp dword[edx+GLContext.lighting_enabled],0 ;if(context.lighting_enabled)
  137.         jne .if_0
  138.         cmp dword[eax+GLContext.texture_2d_enabled],0
  139.         jne .if_0
  140.                 jmp @f
  141. align 4
  142.         .if_0:
  143. if DEBUG ;context.matrix_stack_ptr[0]
  144.         stdcall gl_print_matrix,dword[edx+GLContext.matrix_stack_ptr],4
  145. end if
  146.                 ; precompute inverse modelview
  147.                 mov ebx,ebp
  148.                 sub ebx,sizeof.M4
  149.                 stdcall gl_M4_Inv, ebx,dword[edx+GLContext.matrix_stack_ptr]
  150. if DEBUG ;tmp
  151.         stdcall dbg_print,txt_sp,txt_nl
  152.         stdcall gl_print_matrix,ebx,4
  153. end if
  154.                 push ebx
  155.                 mov ebx,edx
  156.                 add ebx,GLContext.matrix_model_view_inv
  157.                 stdcall gl_M4_Transpose, ebx
  158. if DEBUG ;context.matrix_model_view_inv
  159.         stdcall dbg_print,txt_sp,txt_nl
  160.         stdcall gl_print_matrix,ebx,4
  161. end if
  162.                 jmp .end_if_0
  163. align 4
  164.         @@:
  165.                 mov ecx,edx
  166.                 add ecx,GLContext.matrix_model_projection
  167.                 ; precompute projection matrix
  168.                 stdcall gl_M4_Mul, ecx,dword[edx+GLContext.matrix_stack_ptr+4],dword[edx+GLContext.matrix_stack_ptr]
  169.  
  170.                 ; test to accelerate computation
  171.                 mov dword[edx+GLContext.matrix_model_projection_no_w_transform],0
  172.                 fldz
  173.                 fld dword[ecx+12*4]
  174.                 fcomp st1
  175.                 fstsw ax
  176.                 sahf
  177.                 jne @f
  178.                 fld dword[ecx+13*4]
  179.                 fcomp st1
  180.                 fstsw ax
  181.                 sahf
  182.                 jne @f
  183.                 fld dword[ecx+14*4]
  184.                 fcomp st1
  185.                 fstsw ax
  186.                 sahf
  187.                 jne @f
  188.                         mov dword[edx+GLContext.matrix_model_projection_no_w_transform],1
  189.                 @@:
  190.                 ffree st0 ;0.0
  191.                 fincstp
  192.         .end_if_0:
  193.  
  194.                 ; test if the texture matrix is not Identity
  195.                 mov eax,edx
  196.                 add eax,GLContext.matrix_stack_ptr+8
  197.                 stdcall gl_M4_IsId,eax
  198.                 xor eax,1
  199.                 mov dword[edx+GLContext.apply_texture_matrix],eax
  200.  
  201.                 mov dword[edx+GLContext.matrix_model_projection_updated],0
  202.         .end_mmpu:
  203.  
  204.         ; viewport
  205.         cmp dword[edx+GLContext.viewport+offs_vpor_updated],0 ;if (context.viewport.updated)
  206.         je @f
  207.                 stdcall gl_eval_viewport,edx
  208.                 mov dword[edx+GLContext.viewport+offs_vpor_updated],0
  209.         @@:
  210.         ; triangle drawing functions
  211.         cmp dword[edx+GLContext.render_mode],GL_SELECT
  212.         jne @f
  213.                 mov dword[edx+GLContext.draw_triangle_front],gl_draw_triangle_select
  214.                 mov dword[edx+GLContext.draw_triangle_back],gl_draw_triangle_select
  215.                 jmp .end_if_2
  216. align 4
  217.         @@:
  218.  
  219.         cmp dword[edx+GLContext.polygon_mode_front],GL_POINT
  220.         jne @f
  221.                 mov dword[edx+GLContext.draw_triangle_front],gl_draw_triangle_point
  222.                 jmp .end_if_1
  223. align 4
  224.         @@:
  225.         cmp dword[edx+GLContext.polygon_mode_front],GL_LINE
  226.         jne @f
  227.                 mov dword[edx+GLContext.draw_triangle_front],gl_draw_triangle_line
  228.                 jmp .end_if_1
  229. align 4
  230.         @@: ;default:
  231.                 mov dword[edx+GLContext.draw_triangle_front],gl_draw_triangle_fill
  232.         .end_if_1:
  233.  
  234.         cmp dword[edx+GLContext.polygon_mode_back],GL_POINT
  235.         jne @f
  236.                 mov dword[edx+GLContext.draw_triangle_back],gl_draw_triangle_point
  237.                 jmp .end_if_2
  238. align 4
  239.         @@:
  240.         cmp dword[edx+GLContext.polygon_mode_back],GL_LINE
  241.         jne @f
  242.                 mov dword[edx+GLContext.draw_triangle_back],gl_draw_triangle_line
  243.                 jmp .end_if_2
  244. align 4
  245.         @@: ;default:
  246.             mov dword[edx+GLContext.draw_triangle_back],gl_draw_triangle_fill
  247.         .end_if_2:
  248.         ret
  249. endp
  250.  
  251. ; coords, tranformation , clip code and projection
  252. ; TODO : handle all cases
  253. align 16
  254. proc gl_vertex_transform, context:dword, v:dword
  255. pushad
  256.         mov eax,[context]
  257.         mov edx,[v]
  258.         cmp dword[eax+GLContext.lighting_enabled],0 ;if (context.lighting_enabled)
  259.         jne @f
  260.         cmp dword[eax+GLContext.texture_2d_enabled],0
  261.         jne @f
  262.                 jmp .els_0
  263. align 4
  264.         @@:
  265.                 ; eye coordinates needed for lighting
  266.                 mov ebx,dword[eax+GLContext.matrix_stack_ptr]
  267.                 finit
  268.                 fld dword[edx+offs_vert_coord+offs_X]
  269.                 fld dword[edx+offs_vert_coord+offs_Y]
  270.                 fld dword[edx+offs_vert_coord+offs_Z]
  271.  
  272.                 mov ecx,4
  273.                 .cycle_0:
  274.                         fld dword[ebx]     ;st0 = m[0]
  275.                         fmul st0,st3       ;st0 *= v.coord.X
  276.                         fld dword[ebx+4]   ;st0 = m[1]
  277.                         fmul st0,st3       ;st0 *= v.coord.Y
  278.                         faddp              ;st0 = v.coord.X * m[0] + v.coord.Y * m[1]
  279.                         fld dword[ebx+8]   ;st0 = m[2]
  280.                         fmul st0,st2       ;st0 *= v.coord.Z
  281.                         fadd dword[ebx+12] ;st0 += m[3]
  282.                         faddp              ;st0 = v.ec.X
  283.                         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]
  284.                         add ebx,16 ;следущая строка матрицы
  285.                         add edx,4  ;следущая координата вектора
  286.                 loop .cycle_0
  287.                 ffree st0
  288.                 fincstp
  289.                 ffree st0
  290.                 fincstp
  291.                 ffree st0
  292.                 fincstp
  293.  
  294.                 ; projection coordinates
  295.                 mov ebx,dword[eax+GLContext.matrix_stack_ptr+4]
  296.                 mov edx,[v]
  297.  
  298.                 fld dword[edx+offs_vert_ec+offs_X]
  299.                 fld dword[edx+offs_vert_ec+offs_Y]
  300.                 fld dword[edx+offs_vert_ec+offs_Z]
  301.                 fld dword[edx+offs_vert_ec+offs_W]
  302.  
  303.                 mov ecx,4
  304.                 .cycle_1:
  305.                         fld dword[ebx]     ;st0 = m[0]
  306.                         fmul st0,st4       ;st0 *= v.ec.X
  307.                         fld dword[ebx+4]   ;st0 = m[1]
  308.                         fmul st0,st4       ;st0 *= v.ec.Y
  309.                         faddp              ;st0 = v.ec.X * m[0] + v.ec.Y * m[1]
  310.                         fld dword[ebx+8]   ;st0 = m[2]
  311.                         fmul st0,st3       ;st0 *= v.ec.Z
  312.                         faddp              ;st0 = v.ec.X * m[0] + v.ec.Y * m[1] + v.ec.Z * m[2]
  313.                         fld dword[ebx+12]  ;st0 = m[3]
  314.                         fmul st0,st2       ;st0 *= v.ec.W
  315.                         faddp              ;st0 = v.pc.X
  316.                         fstp dword[edx+offs_vert_pc] ;v.pc.X = v.ec.X * m[0] + v.ec.Y * m[1] + v.ec.Z * m[2] + v.ec.W * m[3]
  317.                         add ebx,16 ;следущая строка матрицы
  318.                         add edx,4  ;следущая координата вектора
  319.                 loop .cycle_1
  320.                 ffree st0
  321.                 fincstp
  322.                 ffree st0
  323.                 fincstp
  324.                 ffree st0
  325.                 fincstp
  326.                 ffree st0
  327.                 fincstp
  328.  
  329.                 mov ebx,eax
  330.                 add ebx,GLContext.matrix_model_view_inv
  331.                 mov edi,eax
  332.                 add edi,GLContext.current_normal
  333.                 mov edx,[v]
  334.  
  335.                 fld dword[edi] ;edi = &n
  336.                 fld dword[edi+offs_Y]
  337.                 fld dword[edi+offs_Z]
  338.  
  339.                 add edx,offs_vert_normal
  340.  
  341.                 fld dword[ebx]   ;st0 = m[0]
  342.                 fmul st0,st3     ;st0 *= n.X
  343.                 fld dword[ebx+4] ;st0 = m[1]
  344.                 fmul st0,st3     ;st0 *= n.Y
  345.                 faddp            ;st0 = n.X * m[0] + n.Y * m[1]
  346.                 fld dword[ebx+8] ;st0 = m[2]
  347.                 fmul st0,st2     ;st0 *= n.Z
  348.                 faddp            ;st0 = v.normal.X
  349.                 fstp dword[edx]  ;v.normal.X = n.X * m[0] + n.Y * m[1] + n.Z * m[2]
  350.  
  351.                 fld dword[ebx+16];st0 = m[4]
  352.                 fmul st0,st3     ;st0 *= n.X
  353.                 fld dword[ebx+20];st0 = m[5]
  354.                 fmul st0,st3     ;st0 *= n.Y
  355.                 faddp            ;st0 = n.X * m[4] + n.Y * m[5]
  356.                 fld dword[ebx+24];st0 = m[6]
  357.                 fmul st0,st2     ;st0 *= n.Z
  358.                 faddp            ;st0 = v.normal.X
  359.                 fstp dword[edx+4];v.normal.X = n.X * m[4] + n.Y * m[5] + n.Z * m[6]
  360.  
  361.                 fld dword[ebx+32];st0 = m[8]
  362.                 fmul st0,st3     ;st0 *= n.X
  363.                 fld dword[ebx+36];st0 = m[9]
  364.                 fmul st0,st3     ;st0 *= n.Y
  365.                 faddp            ;st0 = n.X * m[8] + n.Y * m[9]
  366.                 fld dword[ebx+40];st0 = m[10]
  367.                 fmul st0,st2     ;st0 *= n.Z
  368.                 faddp            ;st0 = v.normal.X
  369.                 fstp dword[edx+8];v.normal.X = n.X * m[8] + n.Y * m[9] + n.Z * m[10]
  370.  
  371.                 cmp dword[eax+GLContext.normalize_enabled],0
  372.                 je .end_els
  373.                         stdcall gl_V3_Norm,edx
  374.                 jmp .end_els
  375. align 4
  376.         .els_0:
  377.                 ; no eye coordinates needed, no normal
  378.                 ; NOTE: W = 1 is assumed
  379.                 mov ebx,eax
  380.                 add ebx,GLContext.matrix_model_projection
  381.  
  382.                 finit
  383.                 fld dword[edx+offs_vert_coord+offs_X]
  384.                 fld dword[edx+offs_vert_coord+offs_Y]
  385.                 fld dword[edx+offs_vert_coord+offs_Z]
  386.  
  387.                 mov esi,edx
  388.                 add esi,offs_vert_pc
  389.  
  390.                 fld dword[ebx]     ;st0 = m[0]
  391.                 fmul st0,st3       ;st0 *= v.coord.X
  392.                 fld dword[ebx+4]   ;st0 = m[1]
  393.                 fmul st0,st3       ;st0 *= v.coord.Y
  394.                 faddp              ;st0 = v.coord.X * m[0] + v.coord.Y * m[1]
  395.                 fld dword[ebx+8]   ;st0 = m[2]
  396.                 fmul st0,st2       ;st0 *= v.coord.Z
  397.                 fadd dword[ebx+12] ;st0 += m[3]
  398.                 faddp              ;st0 = v.pc.X
  399.                 fstp dword[esi]    ;v.pc.X = v.coord.X * m[0] + v.coord.Y * m[1] + v.coord.Z * m[2] + m[3]
  400.  
  401.                 fld dword[ebx+16]  ;st0 = m[4]
  402.                 fmul st0,st3       ;st0 *= v.coord.X
  403.                 fld dword[ebx+20]  ;st0 = m[5]
  404.                 fmul st0,st3       ;st0 *= v.coord.Y
  405.                 faddp              ;st0 = v.coord.X * m[4] + v.coord.Y * m[5]
  406.                 fld dword[ebx+24]  ;st0 = m[6]
  407.                 fmul st0,st2       ;st0 *= v.coord.Z
  408.                 fadd dword[ebx+28] ;st0 += m[7]
  409.                 faddp              ;st0 = v.pc.Y
  410.                 fstp dword[esi+4]  ;v.pc.Y = v.coord.X * m[4] + v.coord.Y * m[5] + v.coord.Z * m[6] + m[7]
  411.  
  412.                 fld dword[ebx+32]  ;st0 = m[8]
  413.                 fmul st0,st3       ;st0 *= v.coord.X
  414.                 fld dword[ebx+36]  ;st0 = m[9]
  415.                 fmul st0,st3       ;st0 *= v.coord.Y
  416.                 faddp              ;st0 = v.coord.X * m[8] + v.coord.Y * m[9]
  417.                 fld dword[ebx+40]  ;st0 = m[10]
  418.                 fmul st0,st2       ;st0 *= v.coord.Z
  419.                 fadd dword[ebx+44] ;st0 += m[11]
  420.                 faddp              ;st0 = v.pc.Z
  421.                 fstp dword[esi+8]  ;v.pc.Z = v.coord.X * m[8] + v.coord.Y * m[9] + v.coord.Z * m[10] + m[11]
  422.  
  423.                 cmp dword[eax+GLContext.matrix_model_projection_no_w_transform],0
  424.                 je .els_1
  425.                         ;if (context.matrix_model_projection_no_w_transform)
  426.                         mov ebx,dword[ebx+60] ;ebx = m[15]
  427.                         mov dword[esi+12],ebx ;v.pc.W = m[15]
  428.                         jmp .end_els
  429. align 4
  430.                 .els_1:
  431.                         fld dword[ebx+48]  ;st0 = m[12]
  432.                         fmul st0,st3       ;st0 *= v.coord.X
  433.                         fld dword[ebx+52]  ;st0 = m[13]
  434.                         fmul st0,st3       ;st0 *= v.coord.Y
  435.                         faddp              ;st0 = v.coord.X * m[12] + v.coord.Y * m[13]
  436.                         fld dword[ebx+56]  ;st0 = m[14]
  437.                         fmul st0,st2       ;st0 *= v.coord.Z
  438.                         fadd dword[ebx+60] ;st0 += m[15]
  439.                         faddp              ;st0 = v.pc.W
  440.                         fstp dword[esi+12] ;v.pc.W = v.coord.X * m[12] + v.coord.Y * m[13] + v.coord.Z * m[14] + m[15]
  441.         .end_els:
  442.         ffree st0
  443.         fincstp
  444.         ffree st0
  445.         fincstp
  446.         ffree st0
  447.         fincstp
  448.  
  449. if DEBUG ;gl_vertex_transform
  450.         stdcall dbg_print,f_vt,txt_nl
  451.         mov edx,[v]
  452.         add edx,offs_vert_pc
  453.         stdcall gl_print_matrix,edx,1
  454. end if
  455.         mov edx,[v]
  456.         stdcall gl_clipcode, dword[edx+offs_vert_pc+offs_X], dword[edx+offs_vert_pc+offs_Y],\
  457.                 dword[edx+offs_vert_pc+offs_Z], dword[edx+offs_vert_pc+offs_W]
  458.         mov dword[edx+offs_vert_clip_code],eax
  459. popad
  460.         ret
  461. endp
  462.  
  463. align 16
  464. proc glopVertex, context:dword, p:dword
  465. locals
  466.         ;ebx = GLVertex * v
  467.         n dd ? ;ebp-4
  468. endl
  469. pushad
  470.         mov edx,[context]
  471.  
  472. ;    assert(c->in_begin != 0);
  473.  
  474.         mov ecx,[edx+GLContext.vertex_n]
  475.         mov [n],ecx
  476.         inc dword[edx+GLContext.vertex_cnt]
  477.  
  478.         ; quick fix to avoid crashes on large polygons
  479.         mov ecx,[edx+GLContext.vertex_max]
  480.         cmp dword[n],ecx
  481.         jl @f
  482.                 shl dword[edx+GLContext.vertex_max],1 ; just double size
  483.                 imul ecx,2*sizeof.GLVertex
  484.                 stdcall gl_malloc,ecx
  485.                 cmp eax,0
  486.                 jne .no_err
  487. ;gl_fatal_error("unable to allocate GLVertex array.\n");
  488.                 .no_err:
  489.                 mov edi,eax
  490.                 mov ebx,eax
  491.                 mov esi,[edx+GLContext.vertex]
  492.                 mov ecx,[n]
  493.                 imul ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
  494.                 rep movsd
  495.                 stdcall gl_free,dword[edx+GLContext.vertex]
  496.                 mov dword[edx+GLContext.vertex],ebx
  497.         @@:
  498.         ; new vertex entry
  499.         mov ebx,[n]
  500.         imul ebx,sizeof.GLVertex
  501.         add ebx,[edx+GLContext.vertex]
  502.         inc dword[n]
  503.  
  504.         mov esi,[p]
  505.         add esi,4
  506.         mov edi,ebx
  507.         add edi,offs_vert_coord ;edi = &v.coord
  508.         mov ecx,4
  509.         rep movsd
  510.  
  511.         stdcall gl_vertex_transform, edx, ebx
  512.  
  513.         ; color
  514.         cmp dword[edx+GLContext.lighting_enabled],0
  515.         je .els_0
  516.                 stdcall gl_shade_vertex, edx,ebx
  517.                 jmp @f
  518. align 4
  519.         .els_0:
  520.                 mov esi,edx
  521.                 add esi,GLContext.current_color
  522.                 mov edi,ebx
  523.                 add edi,offs_vert_color ;edi = &v.color
  524.                 mov ecx,4
  525.                 rep movsd
  526.         @@:
  527.  
  528.         ; tex coords
  529.         cmp dword[edx+GLContext.texture_2d_enabled],0
  530.         je @f
  531.                 cmp dword[edx+GLContext.apply_texture_matrix],0
  532.                 je .els_1
  533.                         mov eax,edx
  534.                         add eax,GLContext.current_tex_coord
  535.                         push eax ;&context.current_tex_coord
  536.                         mov eax,ebx
  537.                         add eax,offs_vert_tex_coord
  538.                         stdcall gl_M4_MulV4, eax, dword[edx+GLContext.matrix_stack_ptr+8]
  539.                         jmp @f
  540. align 4
  541.                 .els_1:
  542.                         mov esi,edx
  543.                         add esi,GLContext.current_tex_coord
  544.                         mov edi,ebx
  545.                         add edi,offs_vert_tex_coord
  546.                         mov ecx,4
  547.                         rep movsd
  548.         @@:
  549.  
  550.         ; precompute the mapping to the viewport
  551.         cmp dword[ebx+offs_vert_clip_code],0
  552.         jne @f
  553.                 stdcall gl_transform_to_viewport, edx,ebx
  554.         @@:
  555.  
  556.         ; edge flag
  557.         mov eax,[edx+GLContext.current_edge_flag]
  558.         mov dword[ebx+offs_vert_edge_flag],eax ;v.edge_flag = context.current_edge_flag
  559.  
  560.         cmp dword[edx+GLContext.begin_type],GL_POINTS
  561.         jne @f
  562.                 stdcall gl_draw_point, edx, dword[edx+GLContext.vertex] ;dword[edx+...] = &context.vertex[0]
  563.                 mov dword[n],0
  564.                 jmp .end_f
  565. align 4
  566.         @@:
  567.         cmp dword[edx+GLContext.begin_type],GL_LINES
  568.         jne @f
  569.                 cmp dword[n],2
  570.                 jne .end_f
  571.                         mov eax,[edx+GLContext.vertex]
  572.                         push eax
  573.                         add eax,sizeof.GLVertex
  574.                         stdcall gl_draw_line, edx, eax
  575.                         xor eax,eax
  576.                         mov dword[n],eax
  577.                 jmp .end_f
  578. align 4
  579.         @@:
  580.         cmp dword[edx+GLContext.begin_type],GL_LINE_STRIP
  581.         je .li_loop
  582.         cmp dword[edx+GLContext.begin_type],GL_LINE_LOOP
  583.         jne @f
  584.                 .li_loop:
  585.                 cmp dword[n],1
  586.                 jne .els_2
  587.                         mov esi,[edx+GLContext.vertex]
  588.                         mov edi,esi
  589.                         add edi,2*sizeof.GLVertex
  590.                         mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
  591.                         rep movsd ;context.vertex[2] = context.vertex[0]
  592.                         jmp .end_f
  593. align 4
  594.                 .els_2:
  595.                 cmp dword[n],2
  596.                 jne .end_f ;else if (n == 2)
  597.                         mov eax,[edx+GLContext.vertex]
  598.                         push eax
  599.                         mov edi,eax
  600.                         add eax,sizeof.GLVertex
  601.                         mov esi,eax
  602.                         stdcall gl_draw_line, edx, eax
  603.                         mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
  604.                         rep movsd ;context.vertex[0] = context.vertex[1]
  605.                         mov dword[n],1
  606.                 jmp .end_f
  607. align 4
  608.         @@:
  609.         cmp dword[edx+GLContext.begin_type],GL_TRIANGLES
  610.         jne @f
  611.                 cmp dword[n],3
  612.                 jne .end_f
  613.                         mov eax,[edx+GLContext.vertex]
  614.                         mov [esp-12],eax
  615.                         add eax,sizeof.GLVertex
  616.                         mov [esp-8],eax
  617.                         add eax,sizeof.GLVertex
  618.                         mov [esp-4],eax
  619.                         sub esp,12
  620.                         stdcall gl_draw_triangle, edx ;v0,v1,v2
  621.                         xor eax,eax
  622.                         mov dword[n],eax
  623.                 jmp .end_f
  624. align 4
  625.         @@:
  626.         cmp dword[edx+GLContext.begin_type],GL_TRIANGLE_STRIP
  627.         jne @f
  628.                 cmp dword[edx+GLContext.vertex_cnt],3 ;if (context.vertex_cnt >= 3)
  629.                 jl .end_f
  630.                         cmp dword[n],3
  631.                         jne .ts3
  632.                                 xor eax,eax
  633.                                 mov dword[n],eax
  634.                         .ts3:
  635.                         ; needed to respect triangle orientation
  636.                         mov eax,[edx+GLContext.vertex]
  637.                         bt dword[edx+GLContext.vertex_cnt],0
  638.                         jc .case_1
  639.                                 mov [esp-4],eax
  640.                                 add eax,sizeof.GLVertex
  641.                                 mov [esp-8],eax
  642.                                 add eax,sizeof.GLVertex
  643.                                 mov [esp-12],eax
  644.                                 sub esp,12
  645.                                 stdcall gl_draw_triangle, edx ;v2,v1,v0
  646.                                 jmp .end_f
  647. align 4
  648.                         .case_1:
  649.                                 mov [esp-12],eax
  650.                                 add eax,sizeof.GLVertex
  651.                                 mov [esp-8],eax
  652.                                 add eax,sizeof.GLVertex
  653.                                 mov [esp-4],eax
  654.                                 sub esp,12
  655.                                 stdcall gl_draw_triangle, edx ;v0,v1,v2
  656.                 jmp .end_f
  657. align 4
  658.         @@:
  659.         cmp dword[edx+GLContext.begin_type],GL_TRIANGLE_FAN
  660.         jne @f
  661.                 cmp dword[n],3
  662.                 jne .end_f
  663.                         mov eax,[edx+GLContext.vertex]
  664.                         mov [esp-12],eax
  665.                         add eax,sizeof.GLVertex
  666.                         mov [esp-8],eax
  667.                         mov edi,eax
  668.                         add eax,sizeof.GLVertex
  669.                         mov [esp-4],eax
  670.                         mov esi,eax
  671.                         sub esp,12
  672.                         stdcall gl_draw_triangle, edx ;v0,v1,v2
  673.                         mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
  674.                         rep movsd ;context.vertex[1] = context.vertex[2]
  675.                         mov dword[n],2
  676.                 jmp .end_f
  677. align 4
  678.         @@:
  679.         cmp dword[edx+GLContext.begin_type],GL_QUADS
  680.         jne @f
  681.                 cmp dword[n],4
  682.                 jne .end_f
  683.                         mov eax,[edx+GLContext.vertex]
  684.                         add eax,2*sizeof.GLVertex
  685.                         mov dword[eax+offs_vert_edge_flag],0 ;context.vertex[2].edge_flag = 0
  686.                         push eax
  687.                         sub eax,sizeof.GLVertex
  688.                         push eax
  689.                         sub eax,sizeof.GLVertex
  690.                         stdcall gl_draw_triangle, edx,eax ;v0,v1,v2
  691.                         mov dword[eax+offs_vert_edge_flag],0 ;context.vertex[0].edge_flag = 0
  692.                         add eax,2*sizeof.GLVertex
  693.                         mov dword[eax+offs_vert_edge_flag],1 ;context.vertex[2].edge_flag = 1
  694.                         add eax,sizeof.GLVertex
  695.                         push eax
  696.                         sub eax,sizeof.GLVertex
  697.                         push eax
  698.                         sub eax,2*sizeof.GLVertex
  699.                         stdcall gl_draw_triangle, edx,eax ;v0,v2,v3
  700.                         xor eax,eax
  701.                         mov dword[n],eax
  702.                 jmp .end_f
  703. align 4
  704.         @@:
  705.         cmp dword[edx+GLContext.begin_type],GL_QUAD_STRIP
  706.         jne @f
  707.                 cmp dword[n],4
  708.                 jne .end_f
  709.                         mov eax,[edx+GLContext.vertex]
  710.                         mov [esp-12],eax
  711.                         mov edi,eax
  712.                         add eax,sizeof.GLVertex
  713.                         mov [esp-8],eax
  714.                         add eax,sizeof.GLVertex
  715.                         mov [esp-4],eax
  716.                         mov esi,eax
  717.                         sub esp,12
  718.                         stdcall gl_draw_triangle, edx ;v0,v1,v2
  719.                         mov [esp-4],eax
  720.                         add eax,sizeof.GLVertex
  721.                         mov [esp-8],eax
  722.                         sub eax,2*sizeof.GLVertex
  723.                         mov [esp-12],eax
  724.                         sub esp,12
  725.                         stdcall gl_draw_triangle, edx ;v1,v3,v2
  726.                         mov ecx,(sizeof.GLVertex)/2 ;((...)/2) копируем 2 вершины
  727.                         rep movsd ;context.vertex[0] = context.vertex[2], context.vertex[1] = context.vertex[3]
  728.                         mov dword[n],2
  729.                 jmp .end_f
  730. align 4
  731.         @@:
  732.         cmp dword[edx+GLContext.begin_type],GL_POLYGON
  733.         je .end_f
  734. ;    default:
  735. ;       gl_fatal_error("glBegin: type %x not handled\n", c->begin_type);
  736. ;    }
  737.         .end_f:
  738.  
  739.         mov ecx,[n]
  740.         mov [edx+GLContext.vertex_n],ecx
  741. popad
  742.         ret
  743. endp
  744.  
  745. align 16
  746. proc glopEnd uses eax ebx ecx, context:dword, p:dword
  747.         mov eax,[context]
  748. ;    assert(c->in_begin == 1);
  749.  
  750.         cmp dword[eax+GLContext.begin_type],GL_LINE_LOOP
  751.         jne .else_i
  752.                 cmp dword[eax+GLContext.vertex_cnt],3
  753.                 jl .end_i
  754.                         mov ebx,[eax+GLContext.vertex]
  755.                         push ebx
  756.                         add ebx,2*sizeof.GLVertex
  757.                         push ebx
  758.                         stdcall gl_draw_line, eax
  759.                 jmp .end_i
  760. align 4
  761.         .else_i:
  762.         cmp dword[eax+GLContext.begin_type],GL_POLYGON
  763.         jne .end_i
  764.                 mov ebx,dword[eax+GLContext.vertex_cnt]
  765.                 @@: ;while (ebx >= 3)
  766.                 cmp ebx,3
  767.                 jl .end_i
  768.                         dec ebx
  769.                         mov ecx,ebx
  770.                         imul ecx,sizeof.GLVertex
  771.                         add ecx,[eax+GLContext.vertex]
  772.                         push ecx ;ecx = &context.vertex[i]
  773.                         sub ecx,sizeof.GLVertex
  774.                         push ecx ;ecx = &context.vertex[i-1]
  775.                         stdcall gl_draw_triangle, eax,[eax+GLContext.vertex]
  776.                 jmp @b
  777. align 4
  778.         .end_i:
  779.         mov dword[eax+GLContext.in_begin],0
  780.         ret
  781. endp
  782.