Subversion Repositories Kolibri OS

Rev

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