Subversion Repositories Kolibri OS

Rev

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

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