Subversion Repositories Kolibri OS

Rev

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