Subversion Repositories Kolibri OS

Rev

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