Subversion Repositories Kolibri OS

Rev

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