Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. INTERP_Z equ 1
  3.  
  4. macro DRAW_INIT
  5. {
  6. if TGL_FEATURE_RENDER_BITS eq 24
  7.         mov ecx,[p2]
  8.         mov eax,[ecx+offs_zbup_r]
  9.         shr eax,8
  10.         mov [colorR],al ;colorR=p2.r>>8
  11.         mov eax,[ecx+offs_zbup_g]
  12.         shr eax,8
  13.         mov [colorG],al ;colorG=p2.g>>8
  14.         mov eax,[ecx+offs_zbup_b]
  15.         shr eax,8
  16.         mov [colorB],al ;colorB=p2.b>>8
  17. ;else
  18. ;  color=RGB_TO_PIXEL(p2->r,p2->g,p2->b);
  19. end if
  20. }
  21.  
  22. macro PUT_PIXEL _a
  23. {
  24. local .end_0
  25.         mov eax,[z]
  26.         shr eax, ZB_POINT_Z_FRAC_BITS
  27.         mov [zz],eax
  28.         mov ebx,[pz]
  29.         cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
  30.         jl .end_0
  31.                 ;edi = pp
  32.                 mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
  33. if TGL_FEATURE_RENDER_BITS eq 24
  34.                 mov cl,[colorR]
  35.                 mov ch,[colorG]
  36.                 mov word[edi+3*_a],cx
  37.                 mov cl,[colorB]
  38.                 mov byte[edi+3*_a +2],cl
  39. ;else
  40. ;      pp[_a]=color;
  41. end if
  42.         .end_0:
  43.         mov eax,[dzdx]
  44.         add [z],eax
  45. }
  46.  
  47. align 4
  48. proc ZB_fillTriangleFlat, zb:dword, p0:dword, p1:dword, p2:dword
  49. locals
  50. if TGL_FEATURE_RENDER_BITS eq 24
  51.         colorR db ?
  52.         colorG db ?
  53.         colorB db ? ;unsigned char
  54. else
  55.         color dd ? ;int
  56. end if
  57. include 'ztriangle.inc'
  58.  
  59. ;
  60. ; Smooth filled triangle.
  61. ; The code below is very tricky :)
  62. ;
  63.  
  64. INTERP_Z equ 1
  65. INTERP_RGB equ 1
  66.  
  67. macro DRAW_INIT
  68. {
  69. if TGL_FEATURE_RENDER_BITS eq 16
  70. ;  _drgbdx=((drdx / (1<<6)) << 22) & 0xFFC00000;
  71. ;  _drgbdx|=(dgdx / (1<<5)) & 0x000007FF;
  72. ;  _drgbdx|=((dbdx / (1<<7)) << 12) & 0x001FF000;
  73. end if
  74. }
  75.  
  76. macro PUT_PIXEL _a
  77. {
  78. local .end_0
  79.         mov eax,[z]
  80.         shr eax,ZB_POINT_Z_FRAC_BITS
  81.         mov [zz],eax
  82.         mov ebx,[pz]
  83.         cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
  84.         jl .end_0
  85.                 ;edi = pp
  86.                 mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
  87. if TGL_FEATURE_RENDER_BITS eq 24
  88.                 mov eax,[or1]
  89.                 mov cl,ah
  90.                 mov eax,[og1]
  91.                 mov ch,ah
  92.                 mov word[edi+3*_a],cx
  93.                 mov eax,[ob1]
  94.                 mov byte[edi+3*_a +2],ah
  95. end if
  96. if TGL_FEATURE_RENDER_BITS eq 16
  97. ;      tmp=rgb & 0xF81F07E0;
  98. ;      pp[_a]=tmp | (tmp >> 16);
  99. ;else
  100. ;      pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);
  101. end if
  102.         .end_0:
  103.         mov eax,[dzdx]
  104.         add [z],eax
  105. if TGL_FEATURE_RENDER_BITS eq 16
  106. ;    rgb=(rgb+drgbdx) & ( ~ 0x00200800);
  107. end if
  108. if TGL_FEATURE_RENDER_BITS <> 16
  109.         mov eax,[dgdx]
  110.         add [og1],eax
  111.         mov eax,[drdx]
  112.         add [or1],eax
  113.         mov eax,[dbdx]
  114.         add [ob1],eax
  115. end if
  116. }
  117.  
  118. ;;;DRAW_LINE_M equ 1
  119.  
  120. macro DRAW_LINE code
  121. {
  122. local .cycle_0
  123. local .cycle_1
  124. if TGL_FEATURE_RENDER_BITS eq 16
  125. if code eq 0
  126.         pz dd ? ;uint*
  127.         tmp dd ? ;uint
  128.         z dd ? ;uint
  129.         zz dd ? ;uint
  130.         rgb dd ? ;uint
  131.         drgbdx dd ? ;uint
  132.         n dd ? ;int
  133. end if
  134. if code eq 1
  135.         mov eax,[x2]
  136.         shr eax,16
  137.         sub eax,[x1]
  138.         mov [n],eax ;n = (x2 >> 16) - x1
  139. ;  pp=pp1+x1;
  140. ;  pz=pz1+x1;
  141. ;  z=z1;
  142. ;  rgb=(r1 << 16) & 0xFFC00000;
  143. ;  rgb|=(g1 >> 5) & 0x000007FF;
  144. ;  rgb|=(b1 << 5) & 0x001FF000;
  145. ;  drgbdx=_drgbdx;
  146. align 4
  147.         .cycle_0: ;while (n>=3)
  148.         cmp dword[n],3
  149.         jl .cycle_1
  150.                 PUT_PIXEL 0
  151.                 PUT_PIXEL 1
  152.                 PUT_PIXEL 2
  153.                 PUT_PIXEL 3
  154.                 add dword[pz],8
  155.                 add edi,4
  156.                 sub [n],4
  157.         jmp .cycle_0
  158.         .cycle_1: ;while (n>=0)
  159.         cmp dword[n],0
  160.         jl .cycle_1_end
  161.                 PUT_PIXEL 0
  162.                 add dword[pz],2
  163.                 inc edi
  164.                 dec dword[n]
  165.                 jmp .cycle_1
  166.         .cycle_1_end:
  167. end if
  168. end if
  169. }
  170.  
  171. align 4
  172. proc ZB_fillTriangleSmooth, zb:dword, p0:dword, p1:dword, p2:dword
  173. locals
  174. if TGL_FEATURE_RENDER_BITS eq 16
  175.         _drgbdx dd ? ;int
  176. end if
  177. include 'ztriangle.inc'
  178.  
  179. align 4
  180. proc ZB_setTexture uses eax ebx, zb:dword, texture:dword
  181.         mov eax,[zb]
  182.         mov ebx,[texture]
  183.         mov dword[eax+offs_zbuf_current_texture],ebx
  184.         ret
  185. endp
  186.  
  187. INTERP_Z equ 1
  188. INTERP_ST equ 1
  189.  
  190. macro DRAW_INIT
  191. {
  192.         mov eax,[zb]
  193.         mov eax,[eax+offs_zbuf_current_texture]
  194.         mov [texture],eax
  195. }
  196.  
  197. macro PUT_PIXEL _a
  198. {
  199. local .end_0
  200.         mov eax,[z]
  201.         shr eax,ZB_POINT_Z_FRAC_BITS
  202.         mov [zz],eax
  203.         mov ebx,[pz]
  204.         cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
  205.         jl .end_0
  206. ;       pz[_a]=zz;
  207. if TGL_FEATURE_RENDER_BITS eq 24
  208. ;   unsigned char *ptr;
  209. ;       ptr = texture + (((t & 0x3FC00000) | s) >> 14) * 3;
  210. ;       pp[3 * _a]= ptr[0];
  211. ;       pp[3 * _a + 1]= ptr[1];
  212. ;       pp[3 * _a + 2]= ptr[2];
  213. else
  214. ;       pp[_a]=texture[((t & 0x3FC00000) | s) >> 14];
  215. end if
  216.         .end_0:
  217.         mov eax,[dzdx]
  218.         add [z],eax
  219.         mov eax,[dsdx]
  220.         add [s],eax
  221.         mov eax,[dtdx]
  222.         add [t],eax
  223. }
  224.  
  225. align 4
  226. proc ZB_fillTriangleMapping, zb:dword, p0:dword, p1:dword, p2:dword
  227. locals
  228.         texture dd ? ;PIXEL*
  229. include 'ztriangle.inc'
  230.  
  231. ;
  232. ; Texture mapping with perspective correction.
  233. ; We use the gradient method to make less divisions.
  234. ; TODO: pipeline the division
  235. ;
  236. if 1
  237.  
  238. INTERP_Z equ 1
  239. INTERP_STZ equ 1
  240.  
  241. NB_INTERP equ 8
  242.  
  243. macro DRAW_INIT
  244. {
  245.         mov eax,[zb]
  246.         mov eax,[eax+offs_zbuf_current_texture]
  247.         mov [texture],eax
  248.         fild dword[dzdx]
  249.         fstp dword[fdzdx]
  250. ;  fndzdx=NB_INTERP * fdzdx;
  251. ;  ndszdx=NB_INTERP * dszdx;
  252. ;  ndtzdx=NB_INTERP * dtzdx;
  253. }
  254.  
  255. macro PUT_PIXEL _a
  256. {
  257. local .end_0
  258.         mov eax,[z]
  259.         shr eax,ZB_POINT_Z_FRAC_BITS
  260.         mov [zz],eax
  261.         mov ebx,[pz]
  262.         cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
  263.         jl .end_0
  264. ;       pz[_a]=zz;
  265. if TGL_FEATURE_RENDER_BITS eq 24
  266. ;   unsigned char *ptr;
  267. ;       ptr = texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> 14) * 3;
  268. ;       pp[3 * _a]= ptr[0];
  269. ;       pp[3 * _a + 1]= ptr[1];
  270. ;       pp[3 * _a + 2]= ptr[2];
  271. else
  272. ;       pp[_a]=*(PIXEL *)((char *)texture+
  273. ;           (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));
  274. end if
  275.         .end_0:
  276.         mov eax,[dzdx]
  277.         add [z],eax
  278.         mov eax,[dsdx]
  279.         add [s],eax
  280.         mov eax,[dtdx]
  281.         add [t],eax
  282. }
  283.  
  284. DRAW_LINE_M equ 1
  285.  
  286. macro DRAW_LINE code
  287. {
  288. if TGL_FEATURE_RENDER_BITS eq 24
  289. if code eq 0
  290.         pz dd ? ;uint *
  291.         s dd ? ;uint
  292.         t dd ? ;uint
  293.         z dd ? ;uint
  294.         zz dd ? ;uint
  295.         n1 dd ? ;int - длинна горизонтальной линии в пикселях
  296.         dsdx dd ? ;int
  297.         dtdx dd ? ;int
  298.         s_z dd ? ;float
  299.         t_z dd ? ;float
  300.         fz dd ? ;float
  301.         zinv dd ? ;float
  302. end if
  303. if code eq 1
  304. ;  n1=(x2>>16)-x1;
  305. ;  fz=(float)z1;
  306. ;  zinv=1.0 / fz;
  307. ;  pp=(pp1 + x1 * PSZB);
  308. ;  pz=pz1+x1;
  309. ;  z=z1;
  310. ;  sz=sz1;
  311. ;  tz=tz1;
  312. ;  while (n1>=(NB_INTERP-1)) {
  313. ;    {
  314. ;      float ss,tt;
  315. ;      ss=(sz * zinv);
  316. ;      tt=(tz * zinv);
  317. ;      s=(int) ss;
  318. ;      t=(int) tt;
  319. ;      dsdx= (int)( (dszdx - ss*fdzdx)*zinv );
  320. ;      dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );
  321. ;      fz+=fndzdx;
  322. ;      zinv=1.0 / fz;
  323. ;    }
  324. ;    PUT_PIXEL(0);
  325. ;    PUT_PIXEL(1);
  326. ;    PUT_PIXEL(2);
  327. ;    PUT_PIXEL(3);
  328. ;    PUT_PIXEL(4);
  329. ;    PUT_PIXEL(5);
  330. ;    PUT_PIXEL(6);
  331. ;    PUT_PIXEL(7);
  332. ;    pz+=NB_INTERP;
  333. ;    pp=(pp + NB_INTERP * PSZB);
  334. ;    n1-=NB_INTERP;
  335. ;    sz+=ndszdx;
  336. ;    tz+=ndtzdx;
  337. ;  }
  338. ;    {
  339. ;      float ss,tt;
  340. ;      ss=(sz * zinv);
  341. ;      tt=(tz * zinv);
  342. ;      s=(int) ss;
  343. ;      t=(int) tt;
  344. ;      dsdx= (int)( (dszdx - ss*fdzdx)*zinv );
  345. ;      dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );
  346. ;    }
  347. ;  while (n1>=0) {
  348. ;;;             PUT_PIXEL 0
  349. ;    pz+=1;
  350. ;    pp=(PIXEL *)((char *)pp + PSZB);
  351.                 dec dword[n1]
  352. ;  }
  353. end if
  354. end if
  355. }
  356.  
  357. align 4
  358. proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
  359. locals
  360.         texture dd ? ;PIXEL *
  361.         fdzdx dd ? ;float
  362.         fndzdx dd ? ;float
  363.         ndszdx dd ? ;float
  364.         ndtzdx dd ? ;float
  365. include 'ztriangle.inc'
  366.  
  367. end if
  368.  
  369. if 0
  370.  
  371. ; slow but exact version (only there for reference, incorrect for 24
  372. ; bits)
  373.  
  374. INTERP_Z equ 1
  375. INTERP_STZ equ 1
  376.  
  377. macro DRAW_INIT
  378. {
  379.         mov eax,[zb]
  380.         mov eax,[eax+offs_zbuf_current_texture]
  381.         mov [texture],eax
  382. }
  383.  
  384. macro PUT_PIXEL _a
  385. {
  386. local .end_0
  387. ;   int s,t;
  388.         mov eax,[z]
  389.         shr eax,ZB_POINT_Z_FRAC_BITS
  390.         mov [zz],eax
  391.         mov ebx,[pz]
  392.         cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
  393.         jl .end_0
  394. ;       pz[_a]=zz;
  395.                 fild dword[z]
  396.                 fld dword[s_z]
  397.                 fdiv st0,st1
  398.                 ;fistp dword[...s...] ;s = (int) (s_z / (float) z)
  399. ;       t= (int) (t_z / (float) z);
  400. ;       pp[_a]=texture[((t & 0x3FC00000) | s) >> 14];
  401.         .end_0:
  402.         mov eax,[dzdx]
  403.         add [z],eax
  404.         fld dword[dszdx]
  405.         fadd dword[s_z]
  406.         fstp dword[s_z]
  407.         fld dword,[dtzdx]
  408.         fadd dword[t_z]
  409.         fstp dword[t_z]
  410. }
  411.  
  412. align 4
  413. proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
  414. locals
  415.         texture dd ? ;PIXEL*
  416. include 'ztriangle.inc'
  417.  
  418. end if
  419.