Subversion Repositories Kolibri OS

Rev

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