Subversion Repositories Kolibri OS

Rev

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

  1. ; fill triangle profile
  2. ; #define PROFILE
  3.  
  4. CLIP_XMIN equ (1<<0)
  5. CLIP_XMAX equ (1<<1)
  6. CLIP_YMIN equ (1<<2)
  7. CLIP_YMAX equ (1<<3)
  8. CLIP_ZMIN equ (1<<4)
  9. CLIP_ZMAX equ (1<<5)
  10.  
  11. align 16
  12. proc gl_transform_to_viewport uses eax ebx ecx, context:dword,v:dword
  13.         mov eax,[context]
  14.         mov ebx,[v]
  15.  
  16.         ; coordinates
  17.         fld1
  18.         fdiv dword[ebx+GLVertex.pc+offs_W] ;st0 = 1/v.pc.W
  19.  
  20.         fld dword[ebx+GLVertex.pc+offs_X] ;st0 = v.pc.X
  21.         fmul st0,st1
  22.         fmul dword[eax+GLContext.viewport+offs_vpor_scale+offs_X]
  23.         fadd dword[eax+GLContext.viewport+offs_vpor_trans+offs_X]
  24.         fistp dword[ebx+GLVertex.zp] ;v.zp.x = st0, st0 = st1
  25.  
  26.         fld dword[ebx+GLVertex.pc+offs_Y] ;st0 = v.pc.Y
  27.         fmul st0,st1
  28.         fmul dword[eax+GLContext.viewport+offs_vpor_scale+offs_Y]
  29.         fadd dword[eax+GLContext.viewport+offs_vpor_trans+offs_Y]
  30.         fistp dword[ebx+GLVertex.zp+offs_zbup_y] ;v.zp.y = st0, st0 = st1
  31.  
  32.         fld dword[ebx+GLVertex.pc+offs_Z] ;st0 = v.pc.Z
  33.         fmulp
  34.         fmul dword[eax+GLContext.viewport+offs_vpor_scale+offs_Z]
  35.         fadd dword[eax+GLContext.viewport+offs_vpor_trans+offs_Z]
  36.         fistp dword[ebx+GLVertex.zp+offs_zbup_z] ;v.zp.z = st0, st0 = st1
  37.  
  38.         ; color
  39.         cmp dword[eax+GLContext.lighting_enabled],0 ;if (context.lighting_enabled)
  40.         je @f
  41.                 lea ecx,[ebx+GLVertex.zp+offs_zbup_b]
  42.                 push ecx
  43.                 add ecx,offs_zbup_g-offs_zbup_b
  44.                 push ecx
  45.                 add ecx,offs_zbup_r-offs_zbup_g
  46.                 push ecx
  47.                 stdcall RGBFtoRGBI, dword[ebx+GLVertex.color],dword[ebx+GLVertex.color+4],dword[ebx+GLVertex.color+8]
  48.                 jmp .end_if
  49. align 4
  50.         @@:
  51.                 ; no need to convert to integer if no lighting : take current color
  52.                 mov ecx,[eax+GLContext.longcurrent_color]
  53.                 mov dword[ebx+GLVertex.zp+offs_zbup_r],ecx
  54.                 mov ecx,[eax+GLContext.longcurrent_color+4]
  55.                 mov dword[ebx+GLVertex.zp+offs_zbup_g],ecx
  56.                 mov ecx,[eax+GLContext.longcurrent_color+8]
  57.                 mov dword[ebx+GLVertex.zp+offs_zbup_b],ecx
  58.         .end_if:
  59.  
  60.         ; texture
  61.         cmp dword[eax+GLContext.texture_2d_enabled],0
  62.         je @f
  63.                 mov eax,[eax+GLContext.current_texture] ;eax = &context.current_texture
  64.                 mov eax,[eax] ;eax = context.current_texture
  65.                 ;[eax+offs_text_images] = im = &context.current_texture.images[0]
  66.  
  67.                 fild dword[eax+offs_text_images+offs_imag_s_bound]
  68.                 fmul dword[ebx+GLVertex.tex_coord+offs_X]
  69.                 fistp dword[ebx+GLVertex.zp+offs_zbup_s]
  70.                 ;v.zp.s=(int)(v.tex_coord.X * im.s_bound)
  71.  
  72.                 fild dword[eax+offs_text_images+offs_imag_t_bound]
  73.                 fmul dword[ebx+GLVertex.tex_coord+offs_Y]
  74.                 fistp dword[ebx+GLVertex.zp+offs_zbup_t]
  75.                 ;v.zp.t=(int)(v.tex_coord.Y * im.t_bound)
  76.         @@:
  77.         ret
  78. endp
  79.  
  80. align 16
  81. proc gl_add_select1 uses eax ebx ecx, context:dword, z1:dword,z2:dword,z3:dword
  82.         mov eax,[z1]
  83.         mov ebx,eax
  84.         cmp [z2],eax
  85.         jge @f
  86.                 mov eax,[z2]
  87.         @@:
  88.         cmp [z3],eax
  89.         jge @f
  90.                 mov eax,[z3]
  91.         @@:
  92.         cmp [z2],ebx
  93.         jle @f
  94.                 mov ebx,[z2]
  95.         @@:
  96.         cmp [z3],ebx
  97.         jle @f
  98.                 mov ebx,[z3]
  99.         @@:
  100.         mov ecx,0xffffffff
  101.         sub ecx,ebx
  102.         push ecx
  103.         mov ecx,0xffffffff
  104.         sub ecx,eax
  105.         push ecx
  106.         stdcall gl_add_select, [context] ;,0xffffffff-eax,0xffffffff-ebx
  107.         ret
  108. endp
  109.  
  110. ; point
  111.  
  112. align 16
  113. proc gl_draw_point uses eax ebx, context:dword, p0:dword
  114.         mov ebx,[p0]
  115.         cmp dword[ebx+GLVertex.clip_code],0 ;if (p0.clip_code == 0)
  116.         jne @f
  117.         mov eax,[context]
  118.         cmp dword[eax+GLContext.render_mode],GL_SELECT
  119.         jne .els
  120.                 stdcall gl_add_select, eax,dword[ebx+GLVertex.zp+offs_zbup_z],dword[ebx+GLVertex.zp+offs_zbup_z] ;p0.zp.z,p0.zp.z
  121.                 jmp @f
  122. align 4
  123.         .els:
  124.                 add ebx,GLVertex.zp
  125.                 stdcall ZB_plot, dword[eax+GLContext.zb],ebx
  126.         @@:
  127.         ret
  128. endp
  129.  
  130. ; line
  131.  
  132. ;input:
  133. ;q - регистр с адресом вершины для интерполяции
  134. ;p0 - регистр с адресом 1-й вершины
  135. ;p1 - регистр с адресом 2-й вершины
  136. ;t - float
  137. macro interpolate q, p0, p1, t
  138. {
  139.         fld dword[t]
  140.  
  141.         ; интерполяция по координатам
  142.         fld dword[p1+GLVertex.pc]
  143.         fsub dword[p0+GLVertex.pc]
  144.         fmul st0,st1
  145.         fadd dword[p0+GLVertex.pc]
  146.         fstp dword[q+GLVertex.pc] ;q.pc.X = p0.pc.X + (p1.pc.X - p0.pc.X) * t
  147.  
  148.         fld dword[p1+GLVertex.pc+offs_Y]
  149.         fsub dword[p0+GLVertex.pc+offs_Y]
  150.         fmul st0,st1
  151.         fadd dword[p0+GLVertex.pc+offs_Y]
  152.         fstp dword[q+GLVertex.pc+offs_Y]
  153.  
  154.         fld dword[p1+GLVertex.pc+offs_Z]
  155.         fsub dword[p0+GLVertex.pc+offs_Z]
  156.         fmul st0,st1
  157.         fadd dword[p0+GLVertex.pc+offs_Z]
  158.         fstp dword[q+GLVertex.pc+offs_Z]
  159.  
  160.         fld dword[p1+GLVertex.pc+offs_W]
  161.         fsub dword[p0+GLVertex.pc+offs_W]
  162.         fmul st0,st1
  163.         fadd dword[p0+GLVertex.pc+offs_W]
  164.         fstp dword[q+GLVertex.pc+offs_W]
  165.  
  166.         ; интерполяция по цвету
  167.         fld dword[p1+GLVertex.color]
  168.         fsub dword[p0+GLVertex.color]
  169.         fmul st0,st1
  170.         fadd dword[p0+GLVertex.color]
  171.         fstp dword[q+GLVertex.color]
  172.  
  173.         fld dword[p1+GLVertex.color+4]
  174.         fsub dword[p0+GLVertex.color+4]
  175.         fmul st0,st1
  176.         fadd dword[p0+GLVertex.color+4]
  177.         fstp dword[q+GLVertex.color+4]
  178.  
  179.         fld dword[p1+GLVertex.color+8]
  180.         fsub dword[p0+GLVertex.color+8]
  181.         fmulp
  182.         fadd dword[p0+GLVertex.color+8]
  183.         fstp dword[q+GLVertex.color+8]
  184. }
  185.  
  186. ;
  187. ; Line Clipping
  188. ;
  189.  
  190. ; Line Clipping algorithm from 'Computer Graphics', Principles and
  191. ; Practice
  192. ; tmin,tmax -> &float
  193. align 16
  194. proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword
  195.         fld dword[denom]
  196.         ftst
  197.         fstsw ax
  198.         sahf
  199.         jbe .els_0 ;if (denom>0)
  200.                 fld dword[num]
  201.                 fxch st1
  202.                 fdivp ;t=num/denom
  203.                 mov ebx,[tmax]
  204.                 fcom dword[ebx]
  205.                 fstsw ax
  206.                 sahf
  207.                 ja .r0_f1 ;if (t>*tmax) return 0
  208.                 mov ebx,[tmin]
  209.                 fcom dword[ebx]
  210.                 fstsw ax
  211.                 sahf
  212.                 jbe .r1_f1 ;if (t>*tmin) *tmin=t
  213.                         fstp dword[ebx]
  214.                 jmp .r1
  215. align 4
  216.         .els_0: ;else if (denom<0)
  217.                 jae .els_1
  218.                 fld dword[num]
  219.                 fxch st1
  220.                 fdivp ;t=num/denom
  221.                 mov ebx,[tmin]
  222.                 fcom dword[ebx]
  223.                 fstsw ax
  224.                 sahf
  225.                 jb .r0_f1 ;if (t<*tmin) return 0
  226.                 mov ebx,[tmax]
  227.                 fcom dword[ebx]
  228.                 fstsw ax
  229.                 sahf
  230.                 jae .r1_f1
  231.                         fstp dword[ebx] ;if (t<*tmin) *tmax=t
  232.                 jmp .r1
  233. align 4
  234.         .els_1: ;else if (num>0)
  235.                 ffree st0 ;denom
  236.                 fincstp
  237.                 fld dword[num]
  238.                 ftst
  239.                 fstsw ax
  240.                 sahf
  241.                 ja .r0_f1 ;if (num>0) return 0
  242.                 jmp .r1_f1
  243. align 4
  244.         .r0_f1: ;return 0 & free st0
  245.                 ffree st0
  246.                 fincstp
  247.         .r0: ;return 0
  248.                 xor eax,eax
  249.                 jmp .end_f
  250. align 4
  251.         .r1_f1: ;return 1 & free st0
  252.                 ffree st0
  253.                 fincstp
  254.         .r1: ;return 1
  255.                 xor eax,eax
  256.                 inc eax
  257.         .end_f:
  258.         ret
  259. endp
  260.  
  261. align 16
  262. proc gl_draw_line, context:dword, p1:dword, p2:dword
  263. locals
  264.         d_x dd ?
  265.         d_y dd ?
  266.         d_z dd ?
  267.         d_w dd ?
  268.         x1 dd ?
  269.         y1 dd ?
  270.         z1 dd ?
  271.         w1 dd ?
  272.         q1 GLVertex ?
  273.         q2 GLVertex ?
  274.         tmin dd ? ;ebp-8
  275.         tmax dd ? ;ebp-4
  276. endl
  277. pushad
  278.         mov edx,[context]
  279.         mov edi,[p1]
  280.         mov esi,[p2]
  281.  
  282.         cmp dword[edi+GLVertex.clip_code],0
  283.         jne .els_i
  284.         cmp dword[esi+GLVertex.clip_code],0
  285.         jne .els_i
  286.                 ;if ( (p1.clip_code | p2.clip_code) == 0)
  287.                 cmp dword[edx+GLContext.render_mode],GL_SELECT ;if (context.render_mode == GL_SELECT)
  288.                 jne .els_1
  289.                         stdcall gl_add_select1, edx,dword[edi+GLVertex.zp+offs_zbup_z],\
  290.                                 dword[esi+GLVertex.zp+offs_zbup_z],dword[esi+GLVertex.zp+offs_zbup_z]
  291.                         jmp .end_f
  292. align 4
  293.                 .els_1:
  294.                         add edi,GLVertex.zp
  295.                         add esi,GLVertex.zp
  296.                         push esi
  297.                         push edi
  298.                         push dword[edx+GLContext.zb]
  299.                         cmp dword[edx+GLContext.depth_test],0
  300.                         je .els_2
  301.                                 ;if (context.depth_test)
  302.                                 call ZB_line_z ;, dword[edx+GLContext.zb],edi,esi
  303.                                 jmp .end_f
  304. align 4
  305.                         .els_2:
  306.                                 call ZB_line ;, dword[edx+GLContext.zb],edi,esi
  307.                                 jmp .end_f
  308. align 4
  309.         .els_i:
  310.                 ;else if ( (p1.clip_code & p2.clip_code) != 0 )
  311.                 mov eax,[edi+GLVertex.clip_code]
  312.                 and eax,[esi+GLVertex.clip_code]
  313.                 or eax,eax
  314.                 jnz .end_f
  315.         .els_0:
  316.  
  317.         fld dword[esi+GLVertex.pc+offs_X]
  318.         fsub dword[edi+GLVertex.pc+offs_X]
  319.         fstp dword[d_x] ;d_x = p2.pc.X - p1.pc.X
  320.         fld dword[esi+GLVertex.pc+offs_Y]
  321.         fsub dword[edi+GLVertex.pc+offs_Y]
  322.         fstp dword[d_y] ;d_y = p2.pc.Y - p1.pc.Y
  323.         fld dword[esi+GLVertex.pc+offs_Z]
  324.         fsub dword[edi+GLVertex.pc+offs_Z]
  325.         fstp dword[d_z] ;d_z = p2.pc.Z - p1.pc.Z
  326.         fld dword[esi+GLVertex.pc+offs_W]
  327.         fsub dword[edi+GLVertex.pc+offs_W]
  328.         fstp dword[d_w] ;d_w = p2.pc.W - p1.pc.W
  329.  
  330.         mov eax,[edi+GLVertex.pc+offs_X]
  331.         mov [x1],eax ;x1 = p1.pc.X
  332.         mov eax,[edi+GLVertex.pc+offs_Y]
  333.         mov [y1],eax ;y1 = p1.pc.Y
  334.         mov eax,[edi+GLVertex.pc+offs_Z]
  335.         mov [z1],eax ;z1 = p1.pc.Z
  336.         mov eax,[edi+GLVertex.pc+offs_W]
  337.         mov [w1],eax ;w1 = p1.pc.W
  338.  
  339.         mov dword[tmin],0.0
  340.         mov dword[tmax],1.0
  341.  
  342.         lea eax,[ebp-4]
  343.         push eax ;толкаем в стек адрес &tmax
  344.         sub eax,4
  345.         push eax ;толкаем в стек адрес &tmin
  346.         fld dword[x1]
  347.         fadd dword[w1]
  348.         fchs
  349.         fstp dword[esp-4]
  350.         fld dword[d_x]
  351.         fadd dword[d_w]
  352.         fstp dword[esp-8]
  353.         sub esp,8
  354.         call ClipLine1 ;d_x+d_w,-x1-w1,&tmin,&tmax
  355.         bt eax,0
  356.         jnc .end_f
  357.  
  358.         sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
  359.         fld dword[x1]
  360.         fsub dword[w1]
  361.         fstp dword[esp-4]
  362.         fld dword[d_w]
  363.         fsub dword[d_x]
  364.         fstp dword[esp-8]
  365.         sub esp,8
  366.         call ClipLine1 ;-d_x+d_w,x1-w1,&tmin,&tmax
  367.         bt eax,0
  368.         jnc .end_f
  369.  
  370.         sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
  371.         fld dword[y1]
  372.         fadd dword[w1]
  373.         fchs
  374.         fstp dword[esp-4]
  375.         fld dword[d_y]
  376.         fadd dword[d_w]
  377.         fstp dword[esp-8]
  378.         sub esp,8
  379.         call ClipLine1 ;d_y+d_w,-y1-w1,&tmin,&tmax
  380.         bt eax,0
  381.         jnc .end_f
  382.  
  383.         sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
  384.         fld dword[y1]
  385.         fsub dword[w1]
  386.         fstp dword[esp-4]
  387.         fld dword[d_w]
  388.         fsub dword[d_y]
  389.         fstp dword[esp-8]
  390.         sub esp,8
  391.         call ClipLine1 ;-d_y+d_w,y1-w1,&tmin,&tmax
  392.         bt eax,0
  393.         jnc .end_f
  394.  
  395.         sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
  396.         fld dword[z1]
  397.         fadd dword[w1]
  398.         fchs
  399.         fstp dword[esp-4]
  400.         fld dword[d_z]
  401.         fadd dword[d_w]
  402.         fstp dword[esp-8]
  403.         sub esp,8
  404.         call ClipLine1 ;d_z+d_w,-z1-w1,&tmin,&tmax
  405.         bt eax,0
  406.         jnc .end_f
  407.  
  408.         sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax
  409.         fld dword[z1]
  410.         fsub dword[w1]
  411.         fstp dword[esp-4]
  412.         fld dword[d_w]
  413.         fsub dword[d_z]
  414.         fstp dword[esp-8]
  415.         sub esp,8
  416.         call ClipLine1 ;-d_z+d_w,z1-w1,&tmin,&tmax
  417.         bt eax,0
  418.         jnc .end_f
  419.  
  420.         lea eax,[ebp-8-2*sizeof.GLVertex] ;eax = &q1
  421.         interpolate eax,edi,esi,tmin
  422.         stdcall gl_transform_to_viewport, edx,eax
  423.         add eax,sizeof.GLVertex ;eax = &q2
  424.         interpolate eax,edi,esi,tmax
  425.         stdcall gl_transform_to_viewport, edx,eax
  426.  
  427.         sub eax,sizeof.GLVertex ;eax = &q1
  428.         lea ebx,[eax+GLVertex.zp+offs_zbup_b]
  429.         push ebx
  430.         add ebx,offs_zbup_g-offs_zbup_b
  431.         push ebx
  432.         add ebx,offs_zbup_r-offs_zbup_g
  433.         push ebx
  434.         stdcall RGBFtoRGBI, dword[eax+GLVertex.color],dword[eax+GLVertex.color+4],dword[eax+GLVertex.color+8]
  435.  
  436.         add eax,sizeof.GLVertex ;eax = &q2
  437.         lea ebx,[eax+GLVertex.zp+offs_zbup_b]
  438.         push ebx
  439.         add ebx,offs_zbup_g-offs_zbup_b
  440.         push ebx
  441.         add ebx,offs_zbup_r-offs_zbup_g
  442.         push ebx
  443.         stdcall RGBFtoRGBI, dword[eax+GLVertex.color],dword[eax+GLVertex.color+4],dword[eax+GLVertex.color+8]
  444.  
  445.         add eax,GLVertex.zp ;eax = &q2.zp
  446.         push eax
  447.         sub eax,sizeof.GLVertex ;eax = &q1.zp
  448.         push eax
  449.         push dword[edx+GLContext.zb]
  450.         cmp dword[edx+GLContext.depth_test],0
  451.         je .els_3
  452.                 call ZB_line_z ;(context.zb,&q1.zp,&q2.zp)
  453.                 jmp .end_f
  454. align 4
  455.         .els_3:
  456.                 call ZB_line ;(context.zb,&q1.zp,&q2.zp)
  457.         .end_f:
  458. popad
  459.         ret
  460. endp
  461.  
  462. ; triangle
  463.  
  464. ;
  465. ; Clipping
  466. ;
  467.  
  468. ; We clip the segment [a,b] against the 6 planes of the normal volume.
  469. ; We compute the point 'c' of intersection and the value of the parameter 't'
  470. ; of the intersection if x=a+t(b-a).
  471. ;
  472. ; sign: 0 -> '-', 1 -> '+'
  473. macro clip_func sign,dir,dir1,dir2
  474. {
  475. locals
  476.         t dd ?
  477.         d_X dd ?
  478.         d_Y dd ?
  479.         d_Z dd ?
  480.         d_W dd ?
  481. endl
  482.         mov edx,[a]
  483.         mov ebx,[b]
  484.         mov ecx,[c]
  485.         fld dword[ebx+offs_X]
  486.         fsub dword[edx+offs_X]
  487.         fstp dword[d_X] ;d_X = (b.X - a.X)
  488.         fld dword[ebx+offs_Y]
  489.         fsub dword[edx+offs_Y]
  490.         fstp dword[d_Y] ;d_Y = (b.Y - a.Y)
  491.         fld dword[ebx+offs_Z]
  492.         fsub dword[edx+offs_Z]
  493.         fstp dword[d_Z] ;d_Z = (b.Z - a.Z)
  494.         fld dword[ebx+offs_W]
  495.         fsub dword[edx+offs_W]
  496.         fst dword[d_W] ;d_W = (b.W - a.W)
  497. if sign eq 0
  498.         fadd dword[d#dir]
  499. else
  500.         fsub dword[d#dir]
  501. end if
  502.  
  503.         ftst
  504.         fstsw ax
  505.         sahf
  506.         jne @f
  507.                 fldz
  508.                 fst dword[t] ;t=0
  509.                 jmp .e_zero
  510. align 4
  511.         @@: ;else
  512.                 fld dword[edx+offs#dir]
  513. if sign eq 0           
  514.                 fchs
  515. end if
  516.                 fsub dword[edx+offs_W]
  517.                 fdiv st0,st1
  518.                 fst dword[t] ;t = ( sign a.dir - a.W) / den
  519.         .e_zero:
  520.  
  521.         fmul dword[d#dir1] ;st0 = t * d.dir1
  522.         fadd dword[edx+offs#dir1]
  523.         fstp dword[ecx+offs#dir1] ;c.dir1 = a.dir1 + t * d.dir1
  524.  
  525.         ffree st0
  526.         fincstp
  527.  
  528.         fld dword[t]
  529.         fmul dword[d#dir2] ;st0 = t * d.dir2
  530.         fadd dword[edx+offs#dir2]
  531.         fstp dword[ecx+offs#dir2] ;c.dir2 = a.dir2 + t * d.dir2
  532.  
  533.         fld dword[t]
  534.         fmul dword[d_W]
  535.         fadd dword[edx+offs_W]
  536.         fst dword[ecx+offs_W] ;c.W = a.W + t * d_W
  537.  
  538. if sign eq 0           
  539.                 fchs
  540. end if
  541.         fstp dword[ecx+offs#dir] ;c.dir = sign c.W
  542.         mov eax,[t]
  543. }
  544.  
  545. align 16
  546. proc clip_xmin uses ebx ecx edx, c:dword, a:dword, b:dword
  547.         clip_func 0,_X,_Y,_Z
  548.         ret
  549. endp
  550.  
  551. align 16
  552. proc clip_xmax uses ebx ecx edx, c:dword, a:dword, b:dword
  553.         clip_func 1,_X,_Y,_Z
  554.         ret
  555. endp
  556.  
  557. align 16
  558. proc clip_ymin uses ebx ecx edx, c:dword, a:dword, b:dword
  559.         clip_func 0,_Y,_X,_Z
  560.         ret
  561. endp
  562.  
  563. align 16
  564. proc clip_ymax uses ebx ecx edx, c:dword, a:dword, b:dword
  565.         clip_func 1,_Y,_X,_Z
  566.         ret
  567. endp
  568.  
  569. align 16
  570. proc clip_zmin uses ebx ecx edx, c:dword, a:dword, b:dword
  571.         clip_func 0,_Z,_X,_Y
  572.         ret
  573. endp
  574.  
  575. align 16
  576. proc clip_zmax uses ebx ecx edx, c:dword, a:dword, b:dword
  577.         clip_func 1,_Z,_X,_Y
  578.         ret
  579. endp
  580.  
  581. align 4
  582. clip_proc dd clip_xmin,clip_xmax, clip_ymin,clip_ymax, clip_zmin,clip_zmax
  583.  
  584. ;input:
  585. ;edi - q
  586. align 16
  587. proc updateTmp uses eax ecx edx, context:dword, p0:dword, p1:dword, t:dword
  588.         mov edx,[context]
  589.         mov eax,[p0]
  590.         cmp dword[edx+GLContext.current_shade_model],GL_SMOOTH ;if (context.current_shade_model == GL_SMOOTH)
  591.         jne .els_0
  592.                 mov ecx,[p1]
  593.                 fld dword[ecx+GLVertex.color]
  594.                 fsub dword[eax+GLVertex.color]
  595.                 fmul dword[t]
  596.                 fadd dword[eax+GLVertex.color]
  597.                 fstp dword[edi+GLVertex.color] ;q.color.v[0]=p0.color.v[0] + (p1.color.v[0]-p0.color.v[0])*t
  598.                 fld dword[ecx+GLVertex.color+4]
  599.                 fsub dword[eax+GLVertex.color+4]
  600.                 fmul dword[t]
  601.                 fadd dword[eax+GLVertex.color+4]
  602.                 fstp dword[edi+GLVertex.color+4] ;q.color.v[1]=p0.color.v[1] + (p1.color.v[1]-p0.color.v[1])*t
  603.                 fld dword[ecx+GLVertex.color+8]
  604.                 fsub dword[eax+GLVertex.color+8]
  605.                 fmul dword[t]
  606.                 fadd dword[eax+GLVertex.color+8]
  607.                 fstp dword[edi+GLVertex.color+8] ;q.color.v[2]=p0.color.v[2] + (p1.color.v[2]-p0.color.v[2])*t
  608.                 jmp @f
  609. align 4
  610.         .els_0:
  611.                 mov ecx,[eax+GLVertex.color]
  612.                 mov [edi+GLVertex.color],ecx ;q.color.v[0]=p0.color.v[0]
  613.                 mov ecx,[eax+GLVertex.color+4]
  614.                 mov [edi+GLVertex.color+4],ecx ;q.color.v[1]=p0.color.v[1]
  615.                 mov ecx,[eax+GLVertex.color+8]
  616.                 mov [edi+GLVertex.color+8],ecx ;q.color.v[2]=p0.color.v[2]
  617.         @@:
  618.  
  619.         cmp dword[edx+GLContext.texture_2d_enabled],0 ;if (context.texture_2d_enabled)
  620.         je @f
  621.                 mov ecx,[p1]
  622.                 fld dword[ecx+GLVertex.tex_coord+offs_X]
  623.                 fsub dword[eax+GLVertex.tex_coord+offs_X]
  624.                 fmul dword[t]
  625.                 fadd dword[eax+GLVertex.tex_coord+offs_X]
  626.                 fstp dword[edi+GLVertex.tex_coord+offs_X] ;q.tex_coord.X=p0.tex_coord.X + (p1.tex_coord.X-p0.tex_coord.X)*t
  627.                 fld dword[ecx+GLVertex.tex_coord+offs_Y]
  628.                 fsub dword[eax+GLVertex.tex_coord+offs_Y]
  629.                 fmul dword[t]
  630.                 fadd dword[eax+GLVertex.tex_coord+offs_Y]
  631.                 fstp dword[edi+GLVertex.tex_coord+offs_Y] ;q.tex_coord.Y=p0.tex_coord.Y + (p1.tex_coord.Y-p0.tex_coord.Y)*t
  632.         @@:
  633.  
  634.         stdcall gl_clipcode, [edi+GLVertex.pc+offs_X],[edi+GLVertex.pc+offs_Y],\
  635.                 [edi+GLVertex.pc+offs_Z],[edi+GLVertex.pc+offs_W]
  636.         mov dword[edi+GLVertex.clip_code],eax
  637.         or eax,eax ;if (q.clip_code==0)
  638.         jnz @f
  639.                 stdcall gl_transform_to_viewport,[context],edi
  640.                 lea eax,[edi+GLVertex.zp+offs_zbup_b]
  641.                 push eax
  642.                 add eax,offs_zbup_g-offs_zbup_b
  643.                 push eax
  644.                 add eax,offs_zbup_r-offs_zbup_g
  645.                 push eax
  646.                 stdcall RGBFtoRGBI, dword[edi+GLVertex.color],dword[edi+GLVertex.color+4],dword[edi+GLVertex.color+8]
  647.         @@:
  648.         ret
  649. endp
  650.  
  651. align 16
  652. proc gl_draw_triangle, context:dword, p0:dword, p1:dword, p2:dword
  653. locals
  654.         cc rd 3
  655.         front dd ?
  656.         norm dd ? ;float
  657. endl
  658. pushad
  659.         mov ebx,[p0]
  660.         mov ecx,[p1]
  661.         mov edx,[p2]
  662.         mov edi,[ebx+GLVertex.clip_code]
  663.         mov dword[cc],edi
  664.         mov eax,[ecx+GLVertex.clip_code]
  665.         mov dword[cc+4],eax
  666.         or edi,eax
  667.         mov eax,[edx+GLVertex.clip_code]
  668.         mov dword[cc+8],eax
  669.         or edi,eax ;co = cc[0] | cc[1] | cc[2]
  670.  
  671.         ; we handle the non clipped case here to go faster
  672.         ;or edi,___ - было выше
  673.         jnz .els_0
  674.                 ;if (co==0)
  675.                 mov edi,dword[edx+GLVertex.zp+offs_zbup_x]
  676.                 sub edi,dword[ebx+GLVertex.zp+offs_zbup_x]
  677.                 mov dword[norm],edi ;p2.x-p0.x
  678.                 fild dword[norm]
  679.                 mov edi,dword[ecx+GLVertex.zp+offs_zbup_y]
  680.                 sub edi,dword[ebx+GLVertex.zp+offs_zbup_y]
  681.                 mov dword[norm],edi ;p1.y-p0.y
  682.                 fimul dword[norm]
  683.                 fchs
  684.                 mov edi,dword[ecx+GLVertex.zp+offs_zbup_x]
  685.                 sub edi,dword[ebx+GLVertex.zp+offs_zbup_x]
  686.                 mov dword[norm],edi ;p1.x-p0.x
  687.                 fild dword[norm]
  688.                 mov edi,dword[edx+GLVertex.zp+offs_zbup_y]
  689.                 sub edi,dword[ebx+GLVertex.zp+offs_zbup_y]
  690.                 mov dword[norm],edi ;p2.y-p0.y
  691.                 fimul dword[norm]
  692.                 faddp
  693.                 ;st0 = (p1.zp.x-p0.zp.x)*(p2.zp.y-p0.zp.y) - (p2.zp.x-p0.zp.x)*(p1.zp.y-p0.zp.y)
  694.  
  695.                 mov dword[front],0
  696.                 ftst
  697.                 fstsw ax
  698.                 ffree st0
  699.                 fincstp
  700.                 sahf
  701.                 je .end_f
  702.                 jae @f
  703.                         inc dword[front] ;front = norm < 0.0
  704.                 @@:
  705.                 mov edi,[context]
  706.                 mov eax,dword[edi+GLContext.current_front_face]
  707.                 xor dword[front],eax ;front ^= context.current_front_face
  708.  
  709.                 ; back face culling
  710.                 cmp dword[edi+GLContext.cull_face_enabled],0
  711.                 je .els_1
  712.                         ; most used case first
  713.                         cmp dword[edi+GLContext.current_cull_face],GL_BACK
  714.                         jne @f
  715.                                 cmp dword[front],0
  716.                                 je .end_f
  717.                                         stdcall dword[edi+GLContext.draw_triangle_front], edi,ebx,ecx,edx
  718.                                 jmp .end_f
  719. align 4
  720.                         @@:
  721.                         cmp dword[edi+GLContext.current_cull_face],GL_FRONT
  722.                         jne .end_f
  723.                                 cmp dword[front],0
  724.                                 jne .end_f
  725.                                         stdcall dword[edi+GLContext.draw_triangle_back], edi,ebx,ecx,edx
  726.                         jmp .end_f
  727. align 4
  728.                 .els_1:
  729.                         ; no culling
  730.                         cmp dword[front],0
  731.                         je @f
  732.                                 stdcall dword[edi+GLContext.draw_triangle_front], edi,ebx,ecx,edx
  733.                                 jmp .end_f
  734. align 4
  735.                         @@:
  736.                                 stdcall dword[edi+GLContext.draw_triangle_back], edi,ebx,ecx,edx
  737.                 jmp .end_f
  738. align 4
  739.         .els_0:
  740.                 ;eax = cc[2]
  741.                 and eax,[cc]
  742.                 and eax,[cc+4] ;eax = c_and = cc[0] & cc[1] & cc[2]
  743.                 or eax,eax ;if (c_and==0)
  744.                 jnz .end_f
  745.                         stdcall gl_draw_triangle_clip, [context],ebx,ecx,edx,0
  746.         .end_f:
  747. popad
  748.         ret
  749. endp
  750.  
  751. align 16
  752. proc gl_draw_triangle_clip, context:dword, p0:dword, p1:dword, p2:dword, clip_bit:dword
  753. locals
  754.         co dd ?
  755.         cc rd 3
  756.         edge_flag_tmp dd ?
  757.         clip_mask dd ?
  758.         q rd 3 ;GLVertex*
  759.         tmp1 GLVertex ?
  760.         tmp2 GLVertex ?
  761. endl
  762. pushad
  763.         mov ebx,[p0]
  764.         mov ecx,[p1]
  765.         mov edx,[p2]
  766.  
  767.         mov edi,[ebx+GLVertex.clip_code]
  768.         mov [cc],edi
  769.         mov eax,[ecx+GLVertex.clip_code]
  770.         mov [cc+4],eax
  771.         or edi,eax
  772.         mov eax,[edx+GLVertex.clip_code]
  773.         mov [cc+8],eax
  774.         or edi,eax
  775.         mov [co],edi ;co = cc[0] | cc[1] | cc[2]
  776.  
  777.         or edi,edi ;if (co == 0)
  778.         jnz .els_0
  779.                 stdcall gl_draw_triangle, [context],ebx,ecx,edx
  780.                 jmp .end_f
  781. align 4
  782.         .els_0:
  783.                 ;eax = cc[2]
  784.                 and eax,[cc]
  785.                 and eax,[cc+4] ;c_and = cc[0] & cc[1] & cc[2]
  786.  
  787.                 ; the triangle is completely outside
  788.                 or eax,eax ;if (c_and!=0) return
  789.                 jnz .end_f
  790.  
  791.                 ; find the next direction to clip
  792.                 .cycle_0: ;while (clip_bit < 6 && (co & (1 << clip_bit)) == 0)
  793.                 cmp dword[clip_bit],6
  794.                 jge .cycle_0_end
  795.                 xor eax,eax
  796.                 inc eax
  797.                 mov ecx,[clip_bit]
  798.                 shl eax,cl
  799.                 and eax,[co]
  800.                 or eax,eax
  801.                 jnz .cycle_0_end
  802.                         inc dword[clip_bit]
  803.                         jmp .cycle_0
  804. align 4
  805.                 .cycle_0_end:
  806.  
  807.         ; this test can be true only in case of rounding errors
  808.         cmp dword[clip_bit],6
  809. if 0
  810.         jne @f
  811. ;      printf("Error:\n");
  812. ;      printf("%f %f %f %f\n",p0->pc.X,p0->pc.Y,p0->pc.Z,p0->pc.W);
  813. ;      printf("%f %f %f %f\n",p1->pc.X,p1->pc.Y,p1->pc.Z,p1->pc.W);
  814. ;      printf("%f %f %f %f\n",p2->pc.X,p2->pc.Y,p2->pc.Z,p2->pc.W);
  815.                 jmp .end_f
  816.         @@:
  817. end if
  818. if 1
  819.         je .end_f
  820. end if
  821.  
  822.         xor eax,eax
  823.         inc eax
  824.         mov ecx,[clip_bit]
  825.         shl eax,cl
  826.         mov [clip_mask],eax ;1 << clip_bit
  827.         mov edi,[cc]
  828.         xor edi,[cc+4]
  829.         xor edi,[cc+8]
  830.         and eax,edi ;eax = co1 = (cc[0] ^ cc[1] ^ cc[2]) & clip_mask
  831.  
  832.         mov ecx,[p1] ;востанавливаем после shl ___,cl
  833.  
  834.         or eax,eax ;if (co1)
  835.         jz .els_1
  836.                 ; one point outside
  837.                 mov eax,[cc]
  838.                 and eax,[clip_mask]
  839.                 or eax,eax ;if (cc[0] & clip_mask)
  840.                 jz .els_2
  841.                         ;q[0]=p0 q[1]=p1 q[2]=p2
  842.                         mov [q],ebx
  843.                         mov [q+4],ecx
  844.                         mov [q+8],edx
  845.                         jmp .els_2_end
  846. align 4
  847.                 .els_2:
  848.                 mov eax,[cc+4]
  849.                 and eax,[clip_mask]
  850.                 or eax,eax ;else if (cc[1] & clip_mask)
  851.                 jz .els_3
  852.                         ;q[0]=p1 q[1]=p2 q[2]=p0
  853.                         mov [q],ecx
  854.                         mov [q+4],edx
  855.                         mov [q+8],ebx
  856.                         jmp .els_2_end
  857. align 4
  858.                 .els_3:
  859.                         ;q[0]=p2 q[1]=p0 q[2]=p1
  860.                         mov [q],edx
  861.                         mov [q+4],ebx
  862.                         mov [q+8],ecx
  863.                 .els_2_end:
  864.  
  865.                 mov ebx,[q]
  866.                 add ebx,GLVertex.pc
  867.                 mov ecx,[q+4]
  868.                 add ecx,GLVertex.pc
  869.                 mov edx,[q+8]
  870.                 add edx,GLVertex.pc
  871.  
  872.                 lea eax,[clip_proc]
  873.                 mov edi,[clip_bit]
  874.                 lea eax,[eax+4*edi]
  875.                 lea edi,[ebp-(2*sizeof.GLVertex)+GLVertex.pc]
  876.                 stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc)
  877.                 sub edi,GLVertex.pc
  878.  
  879.                 sub ebx,GLVertex.pc
  880.                 sub ecx,GLVertex.pc
  881.                 stdcall updateTmp,[context],ebx,ecx,eax ;(c,&tmp1,q[0],q[1],tt)
  882.                 add ebx,GLVertex.pc
  883.  
  884.                 lea eax,[clip_proc]
  885.                 mov edi,[clip_bit]
  886.                 lea eax,[eax+4*edi]
  887.                 lea edi,[ebp-sizeof.GLVertex+GLVertex.pc]
  888.                 stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc)
  889.                 sub edi,GLVertex.pc
  890.                 sub ebx,GLVertex.pc
  891.                 sub edx,GLVertex.pc
  892.                 stdcall updateTmp,[context],ebx,edx,eax ;(c,&tmp2,q[0],q[2],tt)
  893.  
  894.                 mov eax,[ebx+GLVertex.edge_flag]
  895.                 mov [tmp1.edge_flag],eax ;q[0].edge_flag
  896.                 mov eax,[edx+GLVertex.edge_flag]
  897.                 mov [edge_flag_tmp],eax ;q[2].edge_flag
  898.                 mov dword[edx+GLVertex.edge_flag],0 ;q[2].edge_flag=0
  899.                 mov eax,[clip_bit]
  900.                 inc eax
  901.                 push eax ;для вызова нижней функции
  902.                 lea edi,[ebp-2*sizeof.GLVertex]
  903.                 stdcall gl_draw_triangle_clip,[context],edi,ecx,edx,eax ;gl_draw_triangle_clip(c,&tmp1,q[1],q[2],clip_bit+1)
  904.  
  905.                 mov dword[tmp2.edge_flag],0
  906.                 mov dword[tmp1.edge_flag],0
  907.                 mov eax,[edge_flag_tmp]
  908.                 mov [edx+GLVertex.edge_flag],eax ;q[2].edge_flag=edge_flag_tmp
  909.                 push edx
  910.                 push edi
  911.                 add edi,sizeof.GLVertex ;edi = &tmp2
  912.                 stdcall gl_draw_triangle_clip,[context],edi ;gl_draw_triangle_clip(c,&tmp2,&tmp1,q[2],clip_bit+1)
  913.                 jmp .end_f
  914. align 4
  915.         .els_1:
  916.                 ; two points outside
  917.                 mov eax,[cc]
  918.                 and eax,[clip_mask]
  919.                 cmp eax,0 ;if (cc[0] & clip_mask)==0
  920.                 jne .els_4
  921.                         ;q[0]=p0 q[1]=p1 q[2]=p2
  922.                         mov [q],ebx
  923.                         mov [q+4],ecx
  924.                         mov [q+8],edx
  925.                         jmp .els_4_end
  926. align 4
  927.                 .els_4:
  928.                 mov eax,[cc+4]
  929.                 and eax,[clip_mask]
  930.                 cmp eax,0 ;else if (cc[1] & clip_mask)==0
  931.                 jne .els_5
  932.                         ;q[0]=p1 q[1]=p2 q[2]=p0
  933.                         mov [q],ecx
  934.                         mov [q+4],edx
  935.                         mov [q+8],ebx
  936.                         jmp .els_4_end
  937. align 4
  938.                 .els_5:
  939.                         ;q[0]=p2 q[1]=p0 q[2]=p1
  940.                         mov [q],edx
  941.                         mov [q+4],ebx
  942.                         mov [q+8],ecx
  943.                 .els_4_end:
  944.  
  945.                 mov ebx,[q]
  946.                 add ebx,GLVertex.pc
  947.                 mov ecx,[q+4]
  948.                 add ecx,GLVertex.pc
  949.                 mov edx,[q+8]
  950.                 add edx,GLVertex.pc
  951.  
  952.                 lea eax,[clip_proc]
  953.                 mov edi,[clip_bit]
  954.                 lea eax,[eax+4*edi]
  955.                 lea edi,[ebp-(2*sizeof.GLVertex)+GLVertex.pc]
  956.                 stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc)
  957.                 sub edi,GLVertex.pc
  958.                 stdcall updateTmp,[context],[q],[q+4],eax
  959.  
  960.                 lea eax,[clip_proc]
  961.                 mov edi,[clip_bit]
  962.                 lea eax,[eax+4*edi]
  963.                 lea edi,[ebp-sizeof.GLVertex+GLVertex.pc]
  964.                 stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc)
  965.                 sub edi,GLVertex.pc
  966.                 stdcall updateTmp,[context],[q],[q+8],eax
  967.  
  968.                 mov dword[tmp1.edge_flag],1
  969.                 mov eax,[edx+GLVertex.edge_flag-GLVertex.pc]
  970.                 mov dword[tmp2.edge_flag],eax ;tmp2.edge_flag = q[2].edge_flag
  971.                 mov eax,[clip_bit]
  972.                 inc eax
  973.                 push eax
  974.                 push edi
  975.                 sub edi,sizeof.GLVertex
  976.                 stdcall gl_draw_triangle_clip,[context],[q],edi ;gl_draw_triangle_clip(c,q[0],&tmp1,&tmp2,clip_bit+1)
  977.         .end_f:
  978. popad
  979.         ret
  980. endp
  981.  
  982. align 16
  983. proc gl_draw_triangle_select uses eax, context:dword, p0:dword,p1:dword,p2:dword
  984.         mov eax,[p2]
  985.         push dword[eax+GLVertex.zp+offs_Z]
  986.         mov eax,[p1]
  987.         push dword[eax+GLVertex.zp+offs_Z]
  988.         mov eax,[p0]
  989.         push dword[eax+GLVertex.zp+offs_Z]
  990.         stdcall gl_add_select1, [context] ;,p0.zp.z, p1.zp.z, p2.zp.z
  991.         ret
  992. endp
  993.  
  994. if PROFILE eq 1
  995.         count_triangles dd ?
  996.         count_triangles_textured dd ?
  997.         count_pixels dd ?
  998. end if
  999.  
  1000. align 16
  1001. proc gl_draw_triangle_fill, context:dword, p0:dword,p1:dword,p2:dword
  1002. pushad
  1003. if PROFILE eq 1
  1004. ;    int norm;
  1005. ;    assert(p0->zp.x >= 0 && p0->zp.x < c->zb->xsize);
  1006. ;    assert(p0->zp.y >= 0 && p0->zp.y < c->zb->ysize);
  1007. ;    assert(p1->zp.x >= 0 && p1->zp.x < c->zb->xsize);
  1008. ;    assert(p1->zp.y >= 0 && p1->zp.y < c->zb->ysize);
  1009. ;    assert(p2->zp.x >= 0 && p2->zp.x < c->zb->xsize);
  1010. ;    assert(p2->zp.y >= 0 && p2->zp.y < c->zb->ysize);
  1011.    
  1012. ;    norm=(p1->zp.x-p0->zp.x)*(p2->zp.y-p0->zp.y)-
  1013. ;      (p2->zp.x-p0->zp.x)*(p1->zp.y-p0->zp.y);
  1014. ;    count_pixels+=abs(norm)/2;
  1015.         inc dword[count_triangles]
  1016. end if
  1017.  
  1018.         mov ebx,[p1]
  1019.         add ebx,GLVertex.zp
  1020.         mov ecx,[p2]
  1021.         add ecx,GLVertex.zp
  1022.         mov edx,[context]
  1023.         cmp dword[edx+GLContext.texture_2d_enabled],0
  1024.         je .els_i
  1025.                 ;if (context.texture_2d_enabled)
  1026. if PROFILE eq 1
  1027.         inc dword[count_triangles_textured]
  1028. end if
  1029.                 mov eax,[edx+GLContext.current_texture]
  1030.                 mov eax,[eax] ;переход по указателю
  1031.                 ;так как offs_text_images+offs_imag_pixmap = 0 то context.current_texture.images[0].pixmap = [eax]
  1032.                 stdcall ZB_setTexture, [edx+GLContext.zb], [eax],\
  1033.                         [eax+offs_imag_s_bound],[eax+offs_imag_t_bound],[eax+offs_imag_xsize_log2]
  1034.                 mov eax,[p0]
  1035.                 add eax,GLVertex.zp
  1036.                 push ecx
  1037.                 push ebx
  1038.                 push eax
  1039.                 push dword[edx+GLContext.zb]
  1040.                 cmp dword[edx+GLContext.matrix_model_projection_no_w_transform],0
  1041.                 je @f
  1042.                         call ZB_fillTriangleMappingPerspective
  1043.                         jmp .end_f
  1044. align 4
  1045.                 @@:
  1046.                         call ZB_fillTriangleMapping
  1047.                 jmp .end_f
  1048. align 4
  1049.         .els_i:
  1050.                 mov eax,[p0]
  1051.                 add eax,GLVertex.zp
  1052.                 cmp dword[edx+GLContext.current_shade_model],GL_SMOOTH
  1053.                 jne .els
  1054.                         ;else if (context.current_shade_model == GL_SMOOTH)
  1055.                         stdcall ZB_fillTriangleSmooth, dword[edx+GLContext.zb],eax,ebx,ecx
  1056.                         jmp .end_f
  1057. align 4
  1058.                 .els:
  1059.                         stdcall ZB_fillTriangleFlat, dword[edx+GLContext.zb],eax,ebx,ecx
  1060.         .end_f:
  1061. popad
  1062.         ret
  1063. endp
  1064.  
  1065. ; Render a clipped triangle in line mode
  1066.  
  1067. align 16
  1068. proc gl_draw_triangle_line uses eax ebx ecx edx, context:dword, p0:dword,p1:dword,p2:dword
  1069.         mov edx,[context]
  1070.         cmp dword[edx+GLContext.depth_test],0
  1071.         je .els
  1072.                 lea ecx,[ZB_line_z]
  1073.                 jmp @f
  1074. align 4
  1075.         .els:
  1076.                 lea ecx,[ZB_line]
  1077.         @@:
  1078.  
  1079.         ;if (p0.edge_flag) ZB_line_z(context.zb,&p0.zp,&p1.zp)
  1080.         mov eax,[p0]
  1081.         cmp dword[eax+GLVertex.edge_flag],0
  1082.         je @f
  1083.                 lea ebx,[eax+GLVertex.zp]
  1084.                 mov eax,[p1]
  1085.                 add eax,GLVertex.zp
  1086.                 stdcall ecx,dword[edx+GLContext.zb],ebx,eax
  1087.         @@:
  1088.         ;if (p1.edge_flag) ZB_line_z(context.zb,&p1.zp,&p2.zp)
  1089.         mov eax,[p1]
  1090.         cmp dword[eax+GLVertex.edge_flag],0
  1091.         je @f
  1092.                 lea ebx,[eax+GLVertex.zp]
  1093.                 mov eax,[p2]
  1094.                 add eax,GLVertex.zp
  1095.                 stdcall ecx,dword[edx+GLContext.zb],ebx,eax
  1096.         @@:
  1097.         ;if (p2.edge_flag) ZB_line_z(context.zb,&p2.zp,&p0.zp);
  1098.         mov eax,[p2]
  1099.         cmp dword[eax+GLVertex.edge_flag],0
  1100.         je @f
  1101.                 lea ebx,[eax+GLVertex.zp]
  1102.                 mov eax,[p0]
  1103.                 add eax,GLVertex.zp
  1104.                 stdcall ecx,dword[edx+GLContext.zb],ebx,eax
  1105.         @@:
  1106.  
  1107.         ret
  1108. endp
  1109.  
  1110. ; Render a clipped triangle in point mode
  1111. align 16
  1112. proc gl_draw_triangle_point uses eax edx, context:dword, p0:dword,p1:dword,p2:dword
  1113.         mov edx,[context]
  1114.         mov eax,[p0]
  1115.         cmp dword[eax+GLVertex.edge_flag],0
  1116.         je @f
  1117.                 lea eax,[eax+GLVertex.zp]
  1118.                 stdcall ZB_plot,dword[edx+GLContext.zb],eax
  1119.         @@:
  1120.         mov eax,[p1]
  1121.         cmp dword[eax+GLVertex.edge_flag],0
  1122.         je @f
  1123.                 lea eax,[eax+GLVertex.zp]
  1124.                 stdcall ZB_plot,dword[edx+GLContext.zb],eax
  1125.         @@:
  1126.         mov eax,[p2]
  1127.         cmp dword[eax+GLVertex.edge_flag],0
  1128.         je @f
  1129.                 lea eax,[eax+GLVertex.zp]
  1130.                 stdcall ZB_plot,dword[edx+GLContext.zb],eax
  1131.         @@:
  1132.         ret
  1133. endp
  1134.  
  1135.  
  1136.  
  1137.  
  1138.