Subversion Repositories Kolibri OS

Rev

Rev 5175 | 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],eax ;colorR=p2.r>>8
  11.         mov eax,[ecx+offs_zbup_g]
  12.         shr eax,8
  13.         mov [colorG],eax ;colorG=p2.g>>8
  14.         mov eax,[ecx+offs_zbup_b]
  15.         shr eax,8
  16.         mov [colorB],eax ;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. ;    zz=z >> ZB_POINT_Z_FRAC_BITS;
  25. ;    if (zz >= pz[_a]) {
  26. if TGL_FEATURE_RENDER_BITS eq 24
  27. ;      pp[3 * _a]=colorR;
  28. ;      pp[3 * _a + 1]=colorG;
  29. ;      pp[3 * _a + 2]=colorB;
  30. ;      pz[_a]=zz;
  31. else
  32. ;      pp[_a]=color;
  33. ;      pz[_a]=zz;
  34. end if
  35. ;    }
  36. ;    z+=dzdx;
  37. }
  38.  
  39. align 4
  40. proc ZB_fillTriangleFlat, zb:dword, p0:dword, p1:dword, p2:dword
  41. locals
  42. if TGL_FEATURE_RENDER_BITS eq 24
  43.         colorR db ?
  44.         colorG db ?
  45.         colorB db ? ;unsigned char
  46. else
  47.         color dd ? ;int
  48. end if
  49. include 'ztriangle.inc'
  50.         ret
  51. endp
  52.  
  53. ;
  54. ; Smooth filled triangle.
  55. ; The code below is very tricky :)
  56. ;
  57.  
  58. INTERP_Z equ 1
  59. INTERP_RGB equ 1
  60.  
  61. macro DRAW_INIT
  62. {
  63. if TGL_FEATURE_RENDER_BITS eq 16
  64. ;  _drgbdx=((drdx / (1<<6)) << 22) & 0xFFC00000;
  65. ;  _drgbdx|=(dgdx / (1<<5)) & 0x000007FF;
  66. ;  _drgbdx|=((dbdx / (1<<7)) << 12) & 0x001FF000;
  67. end if
  68. }
  69.  
  70. macro PUT_PIXEL _a
  71. {
  72. ;    zz=z >> ZB_POINT_Z_FRAC_BITS;
  73. if TGL_FEATURE_RENDER_BITS eq 24
  74. ;    if (zz >= pz[_a]) {
  75. ;      pp[3 * _a]=or1 >> 8;
  76. ;      pp[3 * _a + 1]=og1 >> 8;
  77. ;      pp[3 * _a + 2]=ob1 >> 8;
  78. ;      pz[_a]=zz;
  79. ;    }
  80. ;    z+=dzdx;
  81. ;    og1+=dgdx;
  82. ;    or1+=drdx;
  83. ;    ob1+=dbdx;
  84. elseif TGL_FEATURE_RENDER_BITS eq 16
  85. ;    if (zz >= pz[_a]) {
  86. ;      tmp=rgb & 0xF81F07E0;
  87. ;      pp[_a]=tmp | (tmp >> 16);
  88. ;      pz[_a]=zz;
  89. ;    }
  90. ;    z+=dzdx;
  91. ;    rgb=(rgb+drgbdx) & ( ~ 0x00200800);
  92. else
  93. ;    if (zz >= pz[_a]) {
  94. ;      pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);
  95. ;      pz[_a]=zz;
  96. ;    }
  97. ;    z+=dzdx;
  98. ;    og1+=dgdx;
  99. ;    or1+=drdx;
  100. ;    ob1+=dbdx;
  101. end if
  102. }
  103.  
  104. macro DRAW_LINE
  105. {
  106. if TGL_FEATURE_RENDER_BITS eq 16
  107. ;  register unsigned short *pz;
  108. ;  register PIXEL *pp;
  109. ;  register unsigned int tmp,z,zz,rgb,drgbdx;
  110. ;  register int n;
  111. ;  n=(x2 >> 16) - x1;
  112. ;  pp=pp1+x1;
  113. ;  pz=pz1+x1;
  114. ;  z=z1;
  115. ;  rgb=(r1 << 16) & 0xFFC00000;
  116. ;  rgb|=(g1 >> 5) & 0x000007FF;
  117. ;  rgb|=(b1 << 5) & 0x001FF000;
  118. ;  drgbdx=_drgbdx;
  119. ;  while (n>=3) {
  120. ;    PUT_PIXEL(0);
  121. ;    PUT_PIXEL(1);
  122. ;    PUT_PIXEL(2);
  123. ;    PUT_PIXEL(3);
  124. ;    pz+=4;
  125. ;    pp+=4;
  126. ;    n-=4;
  127. ;  }
  128. ;  while (n>=0) {
  129. ;    PUT_PIXEL(0);
  130. ;    pz+=1;
  131. ;    pp+=1;
  132. ;    n-=1;
  133. ;  }
  134. end if
  135. if TGL_FEATURE_RENDER_BITS eq 24
  136. ;  register unsigned short *pz;
  137. ;  register PIXEL *pp;
  138. ;  register unsigned int s,t,z,zz;
  139. ;  register int n,dsdx,dtdx;
  140. ;  float sz,tz,fz,zinv;
  141. ;  n=(x2>>16)-x1;
  142. ;  fz=(float)z1;
  143. ;  zinv=1.0 / fz;
  144. ;  pp=(pp1 + x1 * PSZB);
  145. ;  pz=pz1+x1;
  146. ;  z=z1;
  147. ;  sz=sz1;
  148. ;  tz=tz1;
  149. ;  while (n>=(NB_INTERP-1)) {
  150. ;    {
  151. ;      float ss,tt;
  152. ;      ss=(sz * zinv);
  153. ;      tt=(tz * zinv);
  154. ;      s=(int) ss;
  155. ;      t=(int) tt;
  156. ;      dsdx= (int)( (dszdx - ss*fdzdx)*zinv );
  157. ;      dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );
  158. ;      fz+=fndzdx;
  159. ;      zinv=1.0 / fz;
  160. ;    }
  161. ;    PUT_PIXEL(0);
  162. ;    PUT_PIXEL(1);
  163. ;    PUT_PIXEL(2);
  164. ;    PUT_PIXEL(3);
  165. ;    PUT_PIXEL(4);
  166. ;    PUT_PIXEL(5);
  167. ;    PUT_PIXEL(6);
  168. ;    PUT_PIXEL(7);
  169. ;    pz+=NB_INTERP;
  170. ;    pp=(pp + NB_INTERP * PSZB);
  171. ;    n-=NB_INTERP;
  172. ;    sz+=ndszdx;
  173. ;    tz+=ndtzdx;
  174. ;  }
  175. ;    {
  176. ;      float ss,tt;
  177. ;      ss=(sz * zinv);
  178. ;      tt=(tz * zinv);
  179. ;      s=(int) ss;
  180. ;      t=(int) tt;
  181. ;      dsdx= (int)( (dszdx - ss*fdzdx)*zinv );
  182. ;      dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );
  183. ;    }
  184. ;  while (n>=0) {
  185. ;    PUT_PIXEL(0);
  186. ;    pz+=1;
  187. ;    pp=(PIXEL *)((char *)pp + PSZB);
  188. ;    n-=1;
  189. ;  }
  190. end if
  191. }
  192.  
  193. align 4
  194. proc ZB_fillTriangleSmooth, zb:dword, p0:dword, p1:dword, p2:dword
  195. locals
  196. if TGL_FEATURE_RENDER_BITS eq 16
  197.         _drgbdx dd ? ;int
  198. end if
  199. include 'ztriangle.inc'
  200.         ret
  201. endp
  202.  
  203. align 4
  204. proc ZB_setTexture uses eax ebx, zb:dword, texture:dword
  205.         mov eax,[zb]
  206.         mov ebx,[texture]
  207.         mov dword[eax+offs_zbuf_current_texture],ebx
  208.         ret
  209. endp
  210.  
  211. INTERP_Z equ 1
  212. INTERP_ST equ 1
  213.  
  214. macro DRAW_INIT
  215. {
  216. ;  texture=zb->current_texture;
  217. }
  218.  
  219. macro PUT_PIXEL _a
  220. {
  221. ;   zz=z >> ZB_POINT_Z_FRAC_BITS;
  222. if TGL_FEATURE_RENDER_BITS eq 24
  223. ;   unsigned char *ptr;
  224. ;     if (zz >= pz[_a]) {
  225. ;       ptr = texture + (((t & 0x3FC00000) | s) >> 14) * 3;
  226. ;       pp[3 * _a]= ptr[0];
  227. ;       pp[3 * _a + 1]= ptr[1];
  228. ;       pp[3 * _a + 2]= ptr[2];
  229. ;       pz[_a]=zz;
  230. ;    }
  231. else
  232. ;     if (zz >= pz[_a]) {
  233. ;       pp[_a]=texture[((t & 0x3FC00000) | s) >> 14];
  234. ;       pz[_a]=zz;
  235. ;    }
  236. end if
  237. ;    z+=dzdx;
  238. ;    s+=dsdx;
  239. ;    t+=dtdx;
  240. }
  241.  
  242. align 4
  243. proc ZB_fillTriangleMapping, zb:dword, p0:dword, p1:dword, p2:dword
  244. locals
  245.         texture dd ? ;PIXEL*
  246. include 'ztriangle.inc'
  247.         ret
  248. endp
  249.  
  250. ;
  251. ; Texture mapping with perspective correction.
  252. ; We use the gradient method to make less divisions.
  253. ; TODO: pipeline the division
  254. ;
  255. if 1
  256.  
  257. INTERP_Z equ 1
  258. INTERP_STZ equ 1
  259.  
  260. NB_INTERP equ 8
  261.  
  262. macro DRAW_INIT
  263. {
  264. ;  texture=zb->current_texture;
  265. ;  fdzdx=(float)dzdx;
  266. ;  fndzdx=NB_INTERP * fdzdx;
  267. ;  ndszdx=NB_INTERP * dszdx;
  268. ;  ndtzdx=NB_INTERP * dtzdx;
  269. }
  270.  
  271. macro PUT_PIXEL _a
  272. {
  273. ;   zz=z >> ZB_POINT_Z_FRAC_BITS;
  274. if TGL_FEATURE_RENDER_BITS eq 24
  275. ;   unsigned char *ptr;
  276. ;     if (zz >= pz[_a]) {
  277. ;       ptr = texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> 14) * 3;
  278. ;       pp[3 * _a]= ptr[0];
  279. ;       pp[3 * _a + 1]= ptr[1];
  280. ;       pp[3 * _a + 2]= ptr[2];
  281. ;       pz[_a]=zz;
  282. ;    }
  283. else
  284. ;     if (zz >= pz[_a]) {
  285. ;       pp[_a]=*(PIXEL *)((char *)texture+
  286. ;               (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));
  287. ;       pz[_a]=zz;
  288. ;    }
  289. end if
  290. ;    z+=dzdx;
  291. ;    s+=dsdx;
  292. ;    t+=dtdx;
  293. }
  294.  
  295. align 4
  296. proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
  297. locals
  298. ;    PIXEL *texture;
  299. ;    float fdzdx,fndzdx,ndszdx,ndtzdx;
  300. include 'ztriangle.inc'
  301.         ret
  302. endp
  303.  
  304. end if
  305.  
  306. if 0
  307.  
  308. ; slow but exact version (only there for reference, incorrect for 24
  309. ; bits)
  310.  
  311. INTERP_Z equ 1
  312. INTERP_STZ equ 1
  313.  
  314. macro DRAW_INIT
  315. {
  316. ;  texture=zb->current_texture;
  317. }
  318.  
  319. macro PUT_PIXEL _a
  320. {
  321. ;   float zinv;
  322. ;   int s,t;
  323. ;   zz=z >> ZB_POINT_Z_FRAC_BITS;
  324. ;     if (zz >= pz[_a]) {
  325. ;       zinv= 1.0 / (float) z;
  326. ;       s= (int) (sz * zinv);
  327. ;       t= (int) (tz * zinv);
  328. ;       pp[_a]=texture[((t & 0x3FC00000) | s) >> 14];
  329. ;       pz[_a]=zz;
  330. ;    }
  331. ;    z+=dzdx;
  332. ;    sz+=dszdx;
  333. ;    tz+=dtzdx;
  334. }
  335.  
  336. align 4
  337. proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword
  338. locals
  339.         texture dd ? ;PIXEL*
  340. include 'ztriangle.inc'
  341.         ret
  342. endp
  343.  
  344. end if
  345.