Subversion Repositories Kolibri OS

Rev

Rev 5208 | Rev 6111 | 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 ecx,[og1]
  86.                 mov eax,[or1]
  87.                 mov cl,ah
  88.                 mov word[edi+3*_a],cx
  89.                 mov eax,[ob1]
  90.                 mov byte[edi+3*_a +2],ah
  91. end if
  92. if TGL_FEATURE_RENDER_BITS eq 16
  93. ;      tmp=rgb & 0xF81F07E0;
  94. ;      pp[_a]=tmp | (tmp >> 16);
  95. ;else
  96. ;      pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);
  97. end if
  98.         .end_0:
  99.         mov eax,[dzdx]
  100.         add [z],eax
  101. if TGL_FEATURE_RENDER_BITS eq 16
  102. ;    rgb=(rgb+drgbdx) & ( ~ 0x00200800);
  103. end if
  104. if TGL_FEATURE_RENDER_BITS <> 16
  105.         mov eax,[dgdx]
  106.         add [og1],eax
  107.         mov eax,[drdx]
  108.         add [or1],eax
  109.         mov eax,[dbdx]
  110.         add [ob1],eax
  111. end if
  112. }
  113.  
  114. ;;;DRAW_LINE_M equ 1
  115.  
  116. macro DRAW_LINE code
  117. {
  118. local .cycle_0
  119. local .cycle_1
  120. if TGL_FEATURE_RENDER_BITS eq 16
  121. if code eq 0
  122.         pz dd ? ;uint*
  123.         tmp dd ? ;uint
  124.         z dd ? ;uint
  125.         zz dd ? ;uint
  126.         rgb dd ? ;uint
  127.         drgbdx dd ? ;uint
  128.         n dd ? ;int
  129. end if
  130. if code eq 1
  131.         mov eax,[x2]
  132.         sar eax,16
  133.         sub eax,[x1]
  134.         mov [n],eax ;n = (x2 >> 16) - x1
  135. ;  pp=pp1+x1;
  136. ;  pz=pz1+x1;
  137. ;  z=z1;
  138. ;  rgb=(r1 << 16) & 0xFFC00000;
  139. ;  rgb|=(g1 >> 5) & 0x000007FF;
  140. ;  rgb|=(b1 << 5) & 0x001FF000;
  141. ;  drgbdx=_drgbdx;
  142. align 4
  143.         .cycle_0: ;while (n>=3)
  144.         cmp dword[n],3
  145.         jl .cycle_1
  146.                 PUT_PIXEL 0
  147.                 PUT_PIXEL 1
  148.                 PUT_PIXEL 2
  149.                 PUT_PIXEL 3
  150.                 add dword[pz],8
  151.                 add edi,4
  152.                 sub [n],4
  153.         jmp .cycle_0
  154.         .cycle_1: ;while (n>=0)
  155.         cmp dword[n],0
  156.         jl .cycle_1_end
  157.                 PUT_PIXEL 0
  158.                 add dword[pz],2
  159.                 inc edi
  160.                 dec dword[n]
  161.                 jmp .cycle_1
  162.         .cycle_1_end:
  163. end if
  164. end if
  165. }
  166.  
  167. align 4
  168. proc ZB_fillTriangleSmooth, zb:dword, p0:dword, p1:dword, p2:dword
  169. locals
  170. if TGL_FEATURE_RENDER_BITS eq 16
  171.         _drgbdx dd ? ;int
  172. end if
  173. include 'ztriangle.inc'
  174.  
  175. align 4
  176. proc ZB_setTexture uses eax ebx, zb:dword, texture:dword
  177.         mov eax,[zb]
  178.         mov ebx,[texture]
  179.         mov dword[eax+offs_zbuf_current_texture],ebx
  180.         ret
  181. endp
  182.  
  183. INTERP_Z equ 1
  184. INTERP_ST equ 1
  185.  
  186. macro DRAW_INIT
  187. {
  188.         mov eax,[zb]
  189.         mov eax,[eax+offs_zbuf_current_texture]
  190.         mov [texture],eax
  191. }
  192.  
  193. macro PUT_PIXEL _a
  194. {
  195. local .end_0
  196.         mov eax,[z]
  197.         shr eax,ZB_POINT_Z_FRAC_BITS
  198.         mov [zz],eax
  199.         mov ebx,[pz]
  200.         cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
  201.         jl .end_0
  202.                 ;edi = pp
  203.                 mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
  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.                 ;edi = pp
  262.                 mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
  263. if TGL_FEATURE_RENDER_BITS eq 24
  264. ;   unsigned char *ptr;
  265. ;       ptr = texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> 14) * 3;
  266. ;       pp[3 * _a]= ptr[0];
  267. ;       pp[3 * _a + 1]= ptr[1];
  268. ;       pp[3 * _a + 2]= ptr[2];
  269. else
  270. ;       pp[_a]=*(PIXEL *)((char *)texture+
  271. ;           (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));
  272. end if
  273.         .end_0:
  274.         mov eax,[dzdx]
  275.         add [z],eax
  276.         mov eax,[dsdx]
  277.         add [s],eax
  278.         mov eax,[dtdx]
  279.         add [t],eax
  280. }
  281.  
  282. DRAW_LINE_M equ 1
  283.  
  284. macro DRAW_LINE code
  285. {
  286. if TGL_FEATURE_RENDER_BITS eq 24
  287. if code eq 0
  288.         pz dd ? ;uint *
  289.         s dd ? ;uint
  290.         t dd ? ;uint
  291.         z dd ? ;uint
  292.         zz dd ? ;uint
  293.         n1 dd ? ;int - длинна горизонтальной линии в пикселях
  294.         dsdx dd ? ;int
  295.         dtdx dd ? ;int
  296.         s_z dd ? ;float
  297.         t_z dd ? ;float
  298.         fz dd ? ;float
  299.         zinv dd ? ;float
  300. end if
  301. if code eq 1
  302. ;  n1=(x2>>16)-x1;
  303. ;  fz=(float)z1;
  304. ;  zinv=1.0 / fz;
  305. ;  pp=(pp1 + x1 * PSZB);
  306. ;  pz=pz1+x1;
  307. ;  z=z1;
  308. ;  sz=sz1;
  309. ;  tz=tz1;
  310. ;  while (n1>=(NB_INTERP-1)) {
  311. ;    {
  312. ;      float ss,tt;
  313. ;      ss=(sz * zinv);
  314. ;      tt=(tz * zinv);
  315. ;      s=(int) ss;
  316. ;      t=(int) tt;
  317. ;      dsdx= (int)( (dszdx - ss*fdzdx)*zinv );
  318. ;      dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );
  319. ;      fz+=fndzdx;
  320. ;      zinv=1.0 / fz;
  321. ;    }
  322. ;    PUT_PIXEL(0);
  323. ;    PUT_PIXEL(1);
  324. ;    PUT_PIXEL(2);
  325. ;    PUT_PIXEL(3);
  326. ;    PUT_PIXEL(4);
  327. ;    PUT_PIXEL(5);
  328. ;    PUT_PIXEL(6);
  329. ;    PUT_PIXEL(7);
  330. ;    pz+=NB_INTERP;
  331. ;    pp=(pp + NB_INTERP * PSZB);
  332. ;    n1-=NB_INTERP;
  333. ;    sz+=ndszdx;
  334. ;    tz+=ndtzdx;
  335. ;  }
  336. ;    {
  337. ;      float ss,tt;
  338. ;      ss=(sz * zinv);
  339. ;      tt=(tz * zinv);
  340. ;      s=(int) ss;
  341. ;      t=(int) tt;
  342. ;      dsdx= (int)( (dszdx - ss*fdzdx)*zinv );
  343. ;      dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );
  344. ;    }
  345. ;  while (n1>=0) {
  346. ;;;             PUT_PIXEL 0
  347. ;    pz+=1;
  348. ;    pp=(PIXEL *)((char *)pp + PSZB);
  349.                 dec dword[n1]
  350. ;  }
  351. end if
  352. end if
  353. }
  354.  
  355. align 4
  356. proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
  357. locals
  358.         texture dd ? ;PIXEL *
  359.         fdzdx dd ? ;float
  360.         fndzdx dd ? ;float
  361.         ndszdx dd ? ;float
  362.         ndtzdx dd ? ;float
  363. include 'ztriangle.inc'
  364.  
  365. end if
  366.  
  367. if 0
  368.  
  369. ; slow but exact version (only there for reference, incorrect for 24
  370. ; bits)
  371.  
  372. INTERP_Z equ 1
  373. INTERP_STZ equ 1
  374.  
  375. macro DRAW_INIT
  376. {
  377.         mov eax,[zb]
  378.         mov eax,[eax+offs_zbuf_current_texture]
  379.         mov [texture],eax
  380. }
  381.  
  382. macro PUT_PIXEL _a
  383. {
  384. local .end_0
  385. ;   int s,t;
  386.         mov eax,[z]
  387.         shr eax,ZB_POINT_Z_FRAC_BITS
  388.         mov [zz],eax
  389.         mov ebx,[pz]
  390.         cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a])
  391.         jl .end_0
  392.                 ;edi = pp
  393.                 mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение
  394.                 fild dword[z]
  395.                 fld dword[s_z]
  396.                 fdiv st0,st1
  397.                 ;fistp dword[...s...] ;s = (int) (s_z / (float) z)
  398. ;       t= (int) (t_z / (float) z);
  399. ;       pp[_a]=texture[((t & 0x3FC00000) | s) >> 14];
  400.         .end_0:
  401.         mov eax,[dzdx]
  402.         add [z],eax
  403.         fld dword[dszdx]
  404.         fadd dword[s_z]
  405.         fstp dword[s_z]
  406.         fld dword,[dtzdx]
  407.         fadd dword[t_z]
  408.         fstp dword[t_z]
  409. }
  410.  
  411. align 4
  412. proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
  413. locals
  414.         texture dd ? ;PIXEL*
  415. include 'ztriangle.inc'
  416.  
  417. end if
  418.