Subversion Repositories Kolibri OS

Rev

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

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