Subversion Repositories Kolibri OS

Rev

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