Subversion Repositories Kolibri OS

Rev

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