Subversion Repositories Kolibri OS

Rev

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