Subversion Repositories Kolibri OS

Rev

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