Subversion Repositories Kolibri OS

Rev

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