Subversion Repositories Kolibri OS

Rev

Rev 5175 | Rev 5218 | 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],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.                 stdcall gl_M4_IsId,edx+offs_cont_matrix_stack_ptr+8
  175.                 xor edx,1
  176.                 mov ebx,[context]
  177.                 mov dword[ebx+offs_cont_apply_texture_matrix],edx
  178.  
  179.                 mov edx,[context]
  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.  
  257.                 ; projection coordinates
  258.                 mov ebx,dword[eax+offs_cont_matrix_stack_ptr+4]
  259.                 mov edx,[v]
  260.                 finit
  261.                 fld dword[edx+offs_vert_ec+offs_X]
  262.                 fld dword[edx+offs_vert_ec+offs_Y]
  263.                 fld dword[edx+offs_vert_ec+offs_Z]
  264.  
  265.                 mov ecx,4
  266.                 .cycle_1:
  267.                         fld dword[ebx]     ;st0 = m[0]
  268.                         fmul st0,st3       ;st0 *= v.ec.X
  269.                         fld dword[ebx+4]   ;st0 = m[1]
  270.                         fmul st0,st3       ;st0 *= v.ec.Y
  271.                         fld dword[ebx+8]   ;st0 = m[2]
  272.                         fmul st0,st3       ;st0 *= v.ec.Z
  273.                         fadd dword[ebx+12] ;st0 += m[3]
  274.                         faddp              ;st0 += v.ec.Z * m[2]
  275.                         faddp              ;st0 += v.ec.Y * m[1]
  276.                         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]
  277.                         add ebx,16 ;следущая строка матрицы
  278.                         add edx,4  ;следущая координата вектора
  279.                 loop .cycle_1
  280.  
  281.                 mov ebx,eax
  282.                 add ebx,offs_cont_matrix_model_view_inv
  283.                 mov edi,eax
  284.                 add edi,offs_cont_current_normal
  285.                 mov edx,[v]
  286.                 finit
  287.                 fld dword[edi+offs_X]
  288.                 fld dword[edi+offs_Y]
  289.                 fld dword[edi+offs_Z]
  290.  
  291.                 mov ecx,3
  292.                 .cycle_2:
  293.                         fld dword[ebx]     ;st0 = m[0]
  294.                         fmul st0,st3       ;st0 *= n.X
  295.                         fld dword[ebx+4]   ;st0 = m[1]
  296.                         fmul st0,st3       ;st0 *= n.Y
  297.                         fld dword[ebx+8]   ;st0 = m[2]
  298.                         fmul st0,st3       ;st0 *= n.Z
  299.                         faddp              ;st0 += n.Z * m[2]
  300.                         faddp              ;st0 += n.Y * m[1]
  301.                         fstp dword[edx+offs_vert_normal] ;v.normal.X = n.X * m[0] + n.Y * m[1] + n.Z * m[2]
  302.                         add ebx,16 ;следущая строка матрицы
  303.                         add edx,4  ;следущая координата вектора
  304.                 loop .cycle_2
  305.  
  306.                 cmp dword[eax+offs_cont_normalize_enabled],0
  307.                 je .end_els
  308. ;stdcall gl_V3_Norm(&v->normal)
  309.                 jmp .end_els
  310.         .els_0:
  311.                 ; no eye coordinates needed, no normal
  312.                 ; NOTE: W = 1 is assumed
  313.                 mov ebx,eax
  314.                 add ebx,offs_cont_matrix_model_projection
  315.  
  316.                 finit
  317.                 fld dword[edx+offs_vert_coord+offs_X]
  318.                 fld dword[edx+offs_vert_coord+offs_Y]
  319.                 fld dword[edx+offs_vert_coord+offs_Z]
  320.  
  321.                 mov esi,edx
  322.                 add esi,offs_vert_pc
  323.  
  324.                 fld dword[ebx]     ;st0 = m[0]
  325.                 fmul st0,st3       ;st0 *= v.coord.X
  326.                 fld dword[ebx+4]   ;st0 = m[1]
  327.                 fmul st0,st3       ;st0 *= v.coord.Y
  328.                 fld dword[ebx+8]   ;st0 = m[2]
  329.                 fmul st0,st3       ;st0 *= v.coord.Z
  330.                 fadd dword[ebx+12] ;st0 += m[3]
  331.                 faddp              ;st0 += v.coord.Z * m[2]
  332.                 faddp              ;st0 += v.coord.Y * m[1]
  333.                 fstp dword[esi]    ;v.pc.X = v.coord.X * m[0] + v.coord.Y * m[1] + v.coord.Z * m[2] + m[3]
  334.  
  335.                 fld dword[ebx+16]  ;st0 = m[4]
  336.                 fmul st0,st3       ;st0 *= v.coord.X
  337.                 fld dword[ebx+20]  ;st0 = m[5]
  338.                 fmul st0,st3       ;st0 *= v.coord.Y
  339.                 fld dword[ebx+24]  ;st0 = m[6]
  340.                 fmul st0,st3       ;st0 *= v.coord.Z
  341.                 fadd dword[ebx+28] ;st0 += m[7]
  342.                 faddp              ;st0 += v.coord.Z * m[6]
  343.                 faddp              ;st0 += v.coord.Y * m[5]
  344.                 fstp dword[esi+4]  ;v.pc.X = v.coord.X * m[4] + v.coord.Y * m[5] + v.coord.Z * m[6] + m[7]
  345.  
  346.                 fld dword[ebx+32]  ;st0 = m[8]
  347.                 fmul st0,st3       ;st0 *= v.coord.X
  348.                 fld dword[ebx+36]  ;st0 = m[9]
  349.                 fmul st0,st3       ;st0 *= v.coord.Y
  350.                 fld dword[ebx+40]  ;st0 = m[10]
  351.                 fmul st0,st3       ;st0 *= v.coord.Z
  352.                 fadd dword[ebx+44] ;st0 += m[11]
  353.                 faddp              ;st0 += v.coord.Z * m[10]
  354.                 faddp              ;st0 += v.coord.Y * m[9]
  355.                 fstp dword[esi+8]  ;v.pc.X = v.coord.X * m[8] + v.coord.Y * m[9] + v.coord.Z * m[10] + m[11]
  356.  
  357.                 cmp dword[eax+offs_cont_matrix_model_projection_no_w_transform],0
  358.                 je .els_1
  359.                         ;if (context.matrix_model_projection_no_w_transform)
  360.                         mov ebx,dword[ebx+60] ;ebx = m[15]
  361.                         mov dword[esi+12],ebx ;v.pc.W = m[15]
  362.                         jmp .end_els
  363.                 .els_1:
  364.                         fld dword[ebx+48]  ;st0 = m[12]
  365.                         fmul st0,st3       ;st0 *= v.coord.X
  366.                         fld dword[ebx+52]  ;st0 = m[13]
  367.                         fmul st0,st3       ;st0 *= v.coord.Y
  368.                         fld dword[ebx+56]  ;st0 = m[14]
  369.                         fmul st0,st3       ;st0 *= v.coord.Z
  370.                         fadd dword[ebx+60] ;st0 += m[15]
  371.                         faddp              ;st0 += v.coord.Z * m[14]
  372.                         faddp              ;st0 += v.coord.Y * m[13]
  373.                         fstp dword[esi+12] ;v.pc.W = v.coord.X * m[12] + v.coord.Y * m[13] + v.coord.Z * m[14] + m[15]
  374.         .end_els:
  375.         ffree st0
  376.         fincstp
  377.         ffree st0
  378.         fincstp
  379.         ffree st0
  380.         fincstp
  381.  
  382. if DEBUG ;gl_vertex_transform
  383.         stdcall dbg_print,f_vt,txt_nl
  384.         mov edx,[v]
  385.         add edx,offs_vert_pc
  386.         stdcall gl_print_matrix,edx,1
  387. end if
  388.         mov edx,[v]
  389.         stdcall gl_clipcode, dword[edx+offs_vert_pc+offs_X], dword[edx+offs_vert_pc+offs_Y],\
  390.                 dword[edx+offs_vert_pc+offs_Z], dword[edx+offs_vert_pc+offs_W]
  391.         mov dword[edx+offs_vert_clip_code],eax
  392. popad
  393.         ret
  394. endp
  395.  
  396. align 4
  397. proc glopVertex, context:dword, p:dword
  398. locals
  399.         ;ebx = GLVertex * v
  400.         n dd ? ;ebp-4
  401. endl
  402. pushad
  403.         mov edx,[context]
  404.  
  405. ;    assert(c->in_begin != 0);
  406.  
  407.         mov ecx,[edx+offs_cont_vertex_n]
  408.         mov [n],ecx
  409.         inc dword[edx+offs_cont_vertex_cnt]
  410.  
  411.         ; quick fix to avoid crashes on large polygons
  412.         mov ecx,[edx+offs_cont_vertex_max]
  413.         cmp dword[n],ecx
  414.         jl @f
  415.                 shl dword[edx+offs_cont_vertex_max],1 ; just double size
  416.                 imul ecx,2*sizeof.GLVertex
  417.                 stdcall gl_malloc,ecx
  418.                 cmp eax,0
  419.                 jne .no_err
  420. ;gl_fatal_error("unable to allocate GLVertex array.\n");
  421.                 .no_err:
  422.                 mov edi,eax
  423.                 mov ebx,eax
  424.                 mov esi,[edx+offs_cont_vertex]
  425.                 mov ecx,[n]
  426.                 imul ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
  427.                 rep movsd
  428.                 stdcall gl_free,dword[edx+offs_cont_vertex]
  429.                 mov dword[edx+offs_cont_vertex],ebx
  430.         @@:
  431.         ; new vertex entry
  432.         mov ebx,[n]
  433.         imul ebx,sizeof.GLVertex
  434.         add ebx,[edx+offs_cont_vertex]
  435.         inc dword[n]
  436.  
  437.         mov esi,[p]
  438.         add esi,4
  439.         mov edi,ebx
  440.         add edi,offs_vert_coord ;edi = &v.coord
  441.         mov ecx,4
  442.         rep movsd
  443.  
  444.         stdcall gl_vertex_transform, edx, ebx
  445.  
  446.         ; color
  447.  
  448.         cmp dword[edx+offs_cont_lighting_enabled],0
  449.         je .els_0
  450.                 stdcall gl_shade_vertex, edx,ebx
  451.                 jmp @f
  452.         .els_0:
  453.                 mov eax,[edx+offs_cont_current_color]
  454.                 mov [ebx+offs_vert_color],eax
  455.                 mov eax,[edx+offs_cont_current_color+4]
  456.                 mov [ebx+offs_vert_color+4],eax
  457.                 mov eax,[edx+offs_cont_current_color+8]
  458.                 mov [ebx+offs_vert_color+8],eax
  459.         @@:
  460.  
  461.         ; tex coords
  462.         cmp dword[edx+offs_cont_texture_2d_enabled],0
  463.         je @f
  464.                 cmp dword[edx+offs_cont_apply_texture_matrix],0
  465.                 je .els_1
  466. ;           gl_M4_MulV4(&v->tex_coord, c->matrix_stack_ptr[2], &c->current_tex_coord);
  467.                         jmp @f
  468.                 .els_1:
  469.                         mov eax,[edx+offs_cont_current_tex_coord]
  470.                         mov [ebx+offs_vert_tex_coord],eax
  471.         @@:
  472.  
  473.         ; precompute the mapping to the viewport
  474.         cmp dword[ebx+offs_vert_clip_code],0
  475.         jne @f
  476.                 stdcall gl_transform_to_viewport, edx,ebx
  477.         @@:
  478.  
  479.         ; edge flag
  480.         mov eax,[edx+offs_cont_current_edge_flag]
  481.         mov dword[ebx+offs_vert_edge_flag],eax ;v.edge_flag = context.current_edge_flag
  482.  
  483.         cmp dword[edx+offs_cont_begin_type],GL_POINTS
  484.         jne @f
  485.                 stdcall gl_draw_point, edx, dword[edx+offs_cont_vertex] ;dword[edx+...] = &context.vertex[0]
  486.                 mov dword[n],0
  487.                 jmp .end_f
  488.         @@:
  489.         cmp dword[edx+offs_cont_begin_type],GL_LINES
  490.         jne @f
  491.                 cmp dword[n],2
  492.                 jne .end_f
  493.                         mov eax,[edx+offs_cont_vertex]
  494.                         push eax
  495.                         add eax,sizeof.GLVertex
  496.                         stdcall gl_draw_line, edx, eax
  497.                         xor eax,eax
  498.                         mov dword[n],eax
  499.                 jmp .end_f
  500.         @@:
  501.         cmp dword[edx+offs_cont_begin_type],GL_LINE_STRIP
  502.         je .li_loop
  503.         cmp dword[edx+offs_cont_begin_type],GL_LINE_LOOP
  504.         jne @f
  505.                 .li_loop:
  506.                 cmp dword[n],1
  507.                 jne .els_2
  508.                         mov esi,[edx+offs_cont_vertex]
  509.                         mov edi,esi
  510.                         add edi,2*sizeof.GLVertex
  511.                         mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
  512.                         rep movsd ;context.vertex[2] = context.vertex[0]
  513.                         jmp .end_f
  514.                 .els_2:
  515.                 cmp dword[n],2
  516.                 jne .end_f ;else if (n == 2)
  517.                         mov eax,[edx+offs_cont_vertex]
  518.                         push eax
  519.                         add eax,sizeof.GLVertex
  520.                         stdcall gl_draw_line, edx, eax
  521.                         mov edi,[edx+offs_cont_vertex]
  522.                         mov esi,edi
  523.                         add esi,sizeof.GLVertex
  524.                         mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
  525.                         rep movsd ;context.vertex[0] = context.vertex[1]
  526.                         mov dword[n],1
  527.                 jmp .end_f
  528.         @@:
  529.         cmp dword[edx+offs_cont_begin_type],GL_TRIANGLES
  530.         jne @f
  531.                 cmp dword[n],3
  532.                 jne .end_f
  533.                         mov eax,[edx+offs_cont_vertex]
  534.                         push eax
  535.                         add eax,sizeof.GLVertex
  536.                         push eax
  537.                         add eax,sizeof.GLVertex
  538.                         stdcall gl_draw_triangle, edx, eax
  539.                         xor eax,eax
  540.                         mov dword[n],eax
  541.                 jmp .end_f
  542.         @@:
  543.         cmp dword[edx+offs_cont_begin_type],GL_TRIANGLE_STRIP
  544.         jne @f
  545. ;       if (c->vertex_cnt >= 3) {
  546. ;           if (n == 3)
  547. ;               n = 0;
  548. ;            /* needed to respect triangle orientation */
  549. ;            switch(c->vertex_cnt & 1) {
  550. ;            case 0:
  551. ;               gl_draw_triangle(c,&c->vertex[2],&c->vertex[1],&c->vertex[0]);
  552. ;               break;
  553. ;            default:
  554. ;            case 1:
  555. ;               gl_draw_triangle(c,&c->vertex[0],&c->vertex[1],&c->vertex[2]);
  556. ;               break;
  557. ;            }
  558. ;       }
  559.                 jmp .end_f
  560.         @@:
  561.         cmp dword[edx+offs_cont_begin_type],GL_TRIANGLE_FAN
  562.         jne @f
  563.                 cmp dword[n],2
  564.                 jne .end_f
  565. ;           gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
  566. ;           c->vertex[1] = c->vertex[2];
  567.                         mov dword[n],2
  568.                 jmp .end_f
  569.         @@:
  570.         cmp dword[edx+offs_cont_begin_type],GL_QUADS
  571.         jne @f
  572.                 cmp dword[n],4
  573.                 jne .end_f
  574.                         mov eax,[edx+offs_cont_vertex]
  575.                         add eax,2*sizeof.GLVertex
  576.                         mov dword[eax+offs_vert_edge_flag],0 ;context.vertex[2].edge_flag = 0
  577.                         push eax
  578.                         sub eax,sizeof.GLVertex
  579.                         push eax
  580.                         sub eax,sizeof.GLVertex
  581.                         stdcall gl_draw_triangle, edx,eax ;v0,v1,v2
  582.                         mov dword[eax+offs_vert_edge_flag],0 ;context.vertex[0].edge_flag = 0
  583.                         add eax,2*sizeof.GLVertex
  584.                         mov dword[eax+offs_vert_edge_flag],1 ;context.vertex[2].edge_flag = 1
  585.                         add eax,sizeof.GLVertex
  586.                         push eax
  587.                         sub eax,sizeof.GLVertex
  588.                         push eax
  589.                         sub eax,2*sizeof.GLVertex
  590.                         stdcall gl_draw_triangle, edx,eax ;v0,v2,v3
  591.                         xor eax,eax
  592.                         mov dword[n],eax
  593.                 jmp .end_f
  594.         @@:
  595.         cmp dword[edx+offs_cont_begin_type],GL_QUAD_STRIP
  596.         jne @f
  597.                 cmp dword[n],2
  598.                 jne .end_f
  599. ;           gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]);
  600. ;           gl_draw_triangle(c, &c->vertex[1], &c->vertex[3], &c->vertex[2]);
  601. ;           for (i = 0; i < 2; i++)
  602. ;               c->vertex[i] = c->vertex[i + 2];
  603.                         mov dword[n],2
  604.                 jmp .end_f
  605.         @@:
  606.         cmp dword[edx+offs_cont_begin_type],GL_POLYGON
  607.         je .end_f
  608. ;    default:
  609. ;       gl_fatal_error("glBegin: type %x not handled\n", c->begin_type);
  610. ;    }
  611.         .end_f:
  612.  
  613.         mov ecx,[n]
  614.         mov [edx+offs_cont_vertex_n],ecx
  615. popad
  616.         ret
  617. endp
  618.  
  619. align 4
  620. proc glopEnd uses eax ebx ecx, context:dword, p:dword
  621.         mov eax,[context]
  622. ;    assert(c->in_begin == 1);
  623.  
  624.         cmp dword[eax+offs_cont_begin_type],GL_LINE_LOOP
  625.         jne .else_i
  626.                 cmp dword[eax+offs_cont_vertex_cnt],3
  627.                 jl .end_i
  628.                         mov ebx,[eax+offs_cont_vertex]
  629.                         push ebx
  630.                         add ebx,2*sizeof.GLVertex
  631.                         push ebx
  632.                         stdcall gl_draw_line, eax
  633.                 jmp .end_i
  634.         .else_i:
  635.         cmp dword[eax+offs_cont_begin_type],GL_POLYGON
  636.         jne .end_i
  637.                 mov ebx,dword[eax+offs_cont_vertex_cnt]
  638.                 @@: ;while (ebx >= 3)
  639.                 cmp ebx,3
  640.                 jl .end_i
  641.                         dec ebx
  642.                         mov ecx,ebx
  643.                         imul ecx,sizeof.GLVertex
  644.                         add ecx,[eax+offs_cont_vertex]
  645.                         push ecx ;ecx = &context.vertex[i]
  646.                         sub ecx,sizeof.GLVertex
  647.                         push ecx ;ecx = &context.vertex[i-1]
  648.                         stdcall gl_draw_triangle, eax,[eax+offs_cont_vertex]
  649.                 jmp @b
  650.         .end_i:
  651.         mov dword[eax+offs_cont_in_begin],0
  652.         ret
  653. endp
  654.