20#ifndef _TGX_SHADERS_H_
21#define _TGX_SHADERS_H_
36 return ((v < 0) ? 0 : ((v > maxv) ? maxv : v));
44 template<
typename color_t,
typename ZBUFFER_t>
45 void shader_test(
const int32_t& offset,
const int32_t& lx,
const int32_t& ly,
46 const int32_t& dx1,
const int32_t& dy1, int32_t O1,
const tgx::RasterizerVec4& fP1,
47 const int32_t& dx2,
const int32_t& dy2, int32_t O2,
const tgx::RasterizerVec4& fP2,
48 const int32_t& dx3,
const int32_t& dy3, int32_t O3,
const tgx::RasterizerVec4& fP3,
49 const tgx::RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
52 color_t* buf = data.im->data() + offset;
53 const int32_t stride = data.im->stride();
54 for (
int y = 0; y < ly; y++)
56 for (
int x = 0; x < lx; x++)
58 const int32_t o1 = O1 + dx1 * x + dy1 * y;
59 const int32_t o2 = O2 + dx2 * x + dy2 * y;
60 const int32_t o3 = O3 + dx3 * x + dy3 * y;
61 if ((o1 >= 0) && (o2 >= 0) && (o3 >= 0))
63 buf[x + stride * y].
blend256(col, 128);
73 template<
typename color_t,
typename ZBUFFER_t>
74 void shader_Flat(
const int32_t& offset,
const int32_t& lx,
const int32_t& ly,
75 const int32_t& dx1,
const int32_t& dy1, int32_t O1,
const RasterizerVec4& fP1,
76 const int32_t& dx2,
const int32_t& dy2, int32_t O2,
const RasterizerVec4& fP2,
77 const int32_t& dx3,
const int32_t& dy3, int32_t O3,
const RasterizerVec4& fP3,
78 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
80 color_t col = (color_t)data.facecolor;
81 color_t* buf = data.im->data() + offset;
82 const int32_t stride = data.im->stride();
84 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
86 while ((uintptr_t)(buf) < end)
92 bx = (-O1 + dx1 - 1u) / dx1;
99 const int32_t by = (-O2 + dy2 - 1u) / dy2;
103 const int32_t offs = by * stride;
107 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
114 if (dy3 <= 0)
return;
115 const int32_t by = (-O3 + dy3 - 1u) / dy3;
119 const int32_t offs = by * stride;
123 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
127 int32_t C2 = O2 + (dx2 * bx);
128 int32_t C3 = O3 + (dx3 * bx);
129 while ((bx < lx) && ((C2 | C3) >= 0))
150 template<
typename color_t,
typename ZBUFFER_t>
152 const int32_t& dx1,
const int32_t& dy1, int32_t O1,
const RasterizerVec4& fP1,
153 const int32_t& dx2,
const int32_t& dy2, int32_t O2,
const RasterizerVec4& fP2,
154 const int32_t& dx3,
const int32_t& dy3, int32_t O3,
const RasterizerVec4& fP3,
155 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
157 color_t* buf = data.im->data() + offset;
158 const int32_t stride = data.im->stride();
160 const color_t col1 = (color_t)fP1.color;
161 const color_t col2 = (color_t)fP2.color;
162 const color_t col3 = (color_t)fP3.color;
164 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
165 const int32_t pa = O1 + O2 + O3;
166 const int32_t E = ((pa == 0) ? 1 : 0);
167 const int32_t aera = pa + E;
168 const int shiftC = (aera > (1 << 22)) ? 10 : 0;
170 while ((uintptr_t)(buf) < end)
176 bx = (-O1 + dx1 - 1u) / dx1;
182 if (dy2 <= 0)
return;
183 const int32_t by = (-O2 + dy2 - 1u) / dy2;
187 const int32_t offs = by * stride;
191 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
198 if (dy3 <= 0)
return;
199 const int32_t by = (-O3 + dy3 - 1u) / dy3;
203 const int32_t offs = by * stride;
207 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
211 int32_t C2 = O2 + (dx2 * bx);
212 int32_t C3 = O3 + (dx3 * bx);
213 while ((bx < lx) && ((C2 | C3) >= 0))
233 template<
typename color_t,
typename ZBUFFER_t,
bool TEXTURE_BILINEAR,
bool TEXTURE_WRAP>
235 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
236 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
237 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
238 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
240 color_t* buf = data.im->data() + offset;
241 const int32_t stride = data.im->stride();
243 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
244 const int32_t pa = O1 + O2 + O3;
245 const int32_t E = ((pa == 0) ? 1 : 0);
246 const int32_t aera = pa + E;
249 const float invaera =
fast_inv((
float)aera);
250 const float fP1a = fP1.w * invaera;
251 const float fP2a = fP2.w * invaera;
252 const float fP3a = fP3.w * invaera;
254 const float dw = (dx1 * fP1a) + (dx2 * fP2a) + (dx3 * fP3a);
256 const RGBf& cf = (
RGBf)data.facecolor;
257 const int fPR = (
int)(256 * cf.
R);
258 const int fPG = (int)(256 * cf.
G);
259 const int fPB = (int)(256 * cf.
B);
266 const color_t* tex = data.tex->data();
267 const int32_t texsize_x = data.tex->width();
268 const int32_t texsize_y = data.tex->height();
269 const int32_t texsize_x_mm = texsize_x - 1;
270 const int32_t texsize_y_mm = texsize_y - 1;
271 const int32_t texstride = data.tex->stride();
284 const float dtx = ((T1.
x * dx1) + (T2.
x * dx2) + (T3.
x * dx3));
285 const float dty = ((T1.
y * dx1) + (T2.
y * dx2) + (T3.
y * dx3));
287 while ((uintptr_t)(buf) < end)
293 bx = (-O1 + dx1 - 1u) / dx1;
299 if (dy2 <= 0)
return;
300 const int32_t by = (-O2 + dy2 - 1u) / dy2;
304 const int32_t offs = by * stride;
308 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
315 if (dy3 <= 0)
return;
316 const int32_t by = (-O3 + dy3 - 1u) / dy3;
320 const int32_t offs = by * stride;
324 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
328 int32_t C1 = O1 + (dx1 * bx) + E;
329 int32_t C2 = O2 + (dx2 * bx);
330 int32_t C3 = O3 + (dx3 * bx);
331 float cw = ((C1 * fP1a) + (C2 * fP2a) + (C3 * fP3a));
333 float tx = ((T1.
x * C1) + (T2.
x * C2) + (T3.
x * C3));
334 float ty = ((T1.
y * C1) + (T2.
y * C2) + (T3.
y * C3));
336 while ((bx < lx) && ((C2 | C3) >= 0))
341 if (TEXTURE_BILINEAR)
343 const float xx = tx * icw;
344 const float yy = ty * icw;
347 const float ax = xx - ttx;
348 const float ay = yy - tty;
349 const int minx = (TEXTURE_WRAP ? (ttx & (texsize_x_mm)) :
shaderclip(ttx, texsize_x_mm));
350 const int maxx = (TEXTURE_WRAP ? ((ttx + 1) & (texsize_x_mm)) :
shaderclip(ttx + 1, texsize_x_mm));
351 const int miny = (TEXTURE_WRAP ? ((tty & (texsize_y_mm))*texstride) :
shaderclip(tty, texsize_y_mm) * texstride);
352 const int maxy = (TEXTURE_WRAP ? (((tty + 1) & (texsize_y_mm))*texstride) :
shaderclip(tty + 1, texsize_y_mm) * texstride);
357 const int ttx = (TEXTURE_WRAP ? ((int)((tx * icw))) & (texsize_x_mm) :
shaderclip((
int)(tx * icw), texsize_x_mm));
358 const int tty = (TEXTURE_WRAP ? ((int)((ty * icw))) & (texsize_y_mm) :
shaderclip((
int)(ty * icw), texsize_y_mm));
359 col = tex[ttx + (tty)*texstride];
362 col.mult256(fPR, fPG, fPB);
387 template<
typename color_t,
typename ZBUFFER_t,
bool TEXTURE_BILINEAR,
bool TEXTURE_WRAP>
389 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
390 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
391 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
392 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
395 color_t* buf = data.im->data() + offset;
396 const int32_t stride = data.im->stride();
398 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
399 const int32_t pa = O1 + O2 + O3;
400 const int32_t E = ((pa == 0) ? 1 : 0);
401 const int32_t aera = pa + E;
403 const float invaera =
fast_inv((
float)aera);
404 const float fP1a = fP1.w * invaera;
405 const float fP2a = fP2.w * invaera;
406 const float fP3a = fP3.w * invaera;
408 const float dw = (dx1 * fP1a) + (dx2 * fP2a) + (dx3 * fP3a);
413 const int fP1R = (
int)(256 * cf1.
R);
414 const int fP1G = (int)(256 * cf1.
G);
415 const int fP1B = (int)(256 * cf1.
B);
416 const int fP21R = (int)(256 * (cf2.R - cf1.
R));
417 const int fP21G = (int)(256 * (cf2.G - cf1.
G));
418 const int fP21B = (int)(256 * (cf2.B - cf1.
B));
419 const int fP31R = (int)(256 * (cf3.
R - cf1.
R));
420 const int fP31G = (int)(256 * (cf3.
G - cf1.
G));
421 const int fP31B = (int)(256 * (cf3.
B - cf1.
B));
428 const color_t* tex = data.tex->data();
429 const int32_t texsize_x = data.tex->width();
430 const int32_t texsize_y = data.tex->height();
431 const int32_t texsize_x_mm = texsize_x - 1;
432 const int32_t texsize_y_mm = texsize_y - 1;
433 const int32_t texstride = data.tex->stride();
447 const float dtx = ((T1.
x * dx1) + (T2.
x * dx2) + (T3.
x * dx3));
448 const float dty = ((T1.
y * dx1) + (T2.
y * dx2) + (T3.
y * dx3));
450 while ((uintptr_t)(buf) < end)
456 bx = (-O1 + dx1 - 1u) / dx1;
462 if (dy2 <= 0)
return;
463 const int32_t by = (-O2 + dy2 - 1u) / dy2;
467 const int32_t offs = by * stride;
471 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
478 if (dy3 <= 0)
return;
479 const int32_t by = (-O3 + dy3 - 1u) / dy3;
483 const int32_t offs = by * stride;
487 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
491 int32_t C1 = O1 + (dx1 * bx) + E;
492 int32_t C2 = O2 + (dx2 * bx);
493 int32_t C3 = O3 + (dx3 * bx);
494 float cw = ((C1 * fP1a) + (C2 * fP2a) + (C3 * fP3a));
496 float tx = ((T1.
x * C1) + (T2.
x * C2) + (T3.
x * C3));
497 float ty = ((T1.
y * C1) + (T2.
y * C2) + (T3.
y * C3));
499 while ((bx < lx) && ((C2 | C3) >= 0))
504 if (TEXTURE_BILINEAR)
506 const float xx = tx * icw;
507 const float yy = ty * icw;
510 const float ax = xx - ttx;
511 const float ay = yy - tty;
512 const int minx = (TEXTURE_WRAP ? (ttx & (texsize_x_mm)) :
shaderclip(ttx, texsize_x_mm));
513 const int maxx = (TEXTURE_WRAP ? ((ttx + 1) & (texsize_x_mm)) :
shaderclip(ttx + 1, texsize_x_mm));
514 const int miny = (TEXTURE_WRAP ? ((tty & (texsize_y_mm)) * texstride) :
shaderclip(tty, texsize_y_mm) * texstride);
515 const int maxy = (TEXTURE_WRAP ? (((tty + 1) & (texsize_y_mm)) * texstride) :
shaderclip(tty + 1, texsize_y_mm) * texstride);
520 const int ttx = (TEXTURE_WRAP ? ((int)((tx * icw))) & (texsize_x_mm) :
shaderclip((
int)(tx * icw), texsize_x_mm));
521 const int tty = (TEXTURE_WRAP ? ((int)((ty * icw))) & (texsize_y_mm) :
shaderclip((
int)(ty * icw), texsize_y_mm));
522 col = tex[ttx + (tty)*texstride];
525 const int r = fP1R + ((C2 * fP21R + C3 * fP31R) / aera);
526 const int g = fP1G + ((C2 * fP21G + C3 * fP31G) / aera);
527 const int b = fP1B + ((C2 * fP21B + C3 * fP31B) / aera);
529 col.mult256(r, g, b);
554 template<
typename color_t,
typename ZBUFFER_t>
556 const int32_t& dx1,
const int32_t& dy1, int32_t O1,
const RasterizerVec4& fP1,
557 const int32_t& dx2,
const int32_t& dy2, int32_t O2,
const RasterizerVec4& fP2,
558 const int32_t& dx3,
const int32_t& dy3, int32_t O3,
const RasterizerVec4& fP3,
559 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
561 const color_t col = (color_t)data.facecolor;
562 color_t* buf = data.im->data() + offset;
563 ZBUFFER_t * zbuf = data.zbuf + offset;
565 const int32_t stride = data.im->stride();
566 const int32_t zstride = data.im->lx();
568 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
569 const int32_t pa = O1 + O2 + O3;
570 const int32_t E = ((pa == 0) ? 1 : 0);
571 const int32_t aera = pa + E;
573 const float wa = data.wa;
574 const float wb = data.wb;
575 const float invaera =
fast_inv((
float)aera);
576 const float invaera_wa = invaera * wa;
577 const float fP1a = fP1.w * invaera_wa;
578 const float fP2a = fP2.w * invaera_wa;
579 const float fP3a = fP3.w * invaera_wa;
580 const float dw = (dx1 * fP1a) + (dx2 * fP2a) + (dx3 * fP3a);
582 while ((uintptr_t)(buf) < end)
588 bx = (-O1 + dx1 - 1u) / dx1;
594 if (dy2 <= 0)
return;
595 const int32_t by = (-O2 + dy2 - 1u) / dy2;
599 const int32_t offs = by * stride;
604 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
611 if (dy3 <= 0)
return;
612 const int32_t by = (-O3 + dy3 - 1u) / dy3;
616 const int32_t offs = by * stride;
621 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
625 const int32_t C1 = O1 + (dx1 * bx) + E;
626 int32_t C2 = O2 + (dx2 * bx);
627 int32_t C3 = O3 + (dx3 * bx);
628 float cw = ((C1 * fP1a) + (C2 * fP2a) + (C3 * fP3a)) + wb;
630 while ((bx < lx) && ((C2 | C3) >= 0))
632 ZBUFFER_t& W = zbuf[bx];
633 const ZBUFFER_t aa = (ZBUFFER_t)(cw);
658 template<
typename color_t,
typename ZBUFFER_t,
int shiftC>
660 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
661 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
662 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
663 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
665 color_t* buf = data.im->data() + offset;
666 ZBUFFER_t* zbuf = data.zbuf + offset;
669 const int32_t stride = data.im->stride();
670 const int32_t zstride = data.im->lx();
672 const color_t col1 = (color_t)fP1.color;
673 const color_t col2 = (color_t)fP2.color;
674 const color_t col3 = (color_t)fP3.color;
676 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
677 const int32_t pa = O1 + O2 + O3;
678 const int32_t E = ((pa == 0) ? 1 : 0);
679 const int32_t aera = pa + E;
680 const int32_t aeraShifted = aera >> shiftC;
682 const float wa = data.wa;
683 const float wb = data.wb;
684 const float invaera =
fast_inv((
float)aera);
685 const float invaera_wa = invaera * wa;
686 const float fP1a = fP1.w * invaera_wa;
687 const float fP2a = fP2.w * invaera_wa;
688 const float fP3a = fP3.w * invaera_wa;
689 const float dw = (dx1 * fP1a) + (dx2 * fP2a) + (dx3 * fP3a);
691 while ((uintptr_t)(buf) < end)
697 bx = (-O1 + dx1 - 1u) / dx1;
703 if (dy2 <= 0)
return;
704 const int32_t by = (-O2 + dy2 - 1u) / dy2;
708 const int32_t offs = by * stride;
713 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
720 if (dy3 <= 0)
return;
721 const int32_t by = (-O3 + dy3 - 1u) / dy3;
725 const int32_t offs = by * stride;
730 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
734 const int32_t C1 = O1 + (dx1 * bx) + E;
735 int32_t C2 = O2 + (dx2 * bx);
736 int32_t C3 = O3 + (dx3 * bx);
737 float cw = ((C1 * fP1a) + (C2 * fP2a) + (C3 * fP3a)) + wb;
739 while ((bx < lx) && ((C2 | C3) >= 0))
741 ZBUFFER_t& W = zbuf[bx];
742 const ZBUFFER_t aa = (ZBUFFER_t)(cw);
765 template<
typename color_t,
typename ZBUFFER_t>
767 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
768 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
769 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
770 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
773 if (O1 + O2 + O3 > (1 << 24))
775 shader_Gouraud_Zbuffer_sub<color_t, ZBUFFER_t, 10>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
779 shader_Gouraud_Zbuffer_sub<color_t, ZBUFFER_t, 0>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
788 template<
typename color_t,
typename ZBUFFER_t,
bool TEXTURE_BILINEAR,
bool TEXTURE_WRAP>
790 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
791 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
792 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
793 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
795 color_t* buf = data.im->data() + offset;
796 ZBUFFER_t* zbuf = data.zbuf + offset;
798 const float wa = data.wa;
799 const float wb = data.wb;
804 const int32_t stride = data.im->stride();
805 const int32_t zstride = data.im->lx();
807 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
808 const int32_t pa = O1 + O2 + O3;
809 const int32_t E = ((pa == 0) ? 1 : 0);
810 const int32_t aera = pa + E;
812 const float invaera =
fast_inv((
float)aera);
813 const float fP1a = fP1.w * invaera;
814 const float fP2a = fP2.w * invaera;
815 const float fP3a = fP3.w * invaera;
817 const float dw = (dx1 * fP1a) + (dx2 * fP2a) + (dx3 * fP3a);
819 const RGBf& cf = (
RGBf)data.facecolor;
820 const int fPR = (
int)(256 * cf.
R);
821 const int fPG = (int)(256 * cf.
G);
822 const int fPB = (int)(256 * cf.
B);
829 const color_t* tex = data.tex->data();
830 const int32_t texsize_x = data.tex->width();
831 const int32_t texsize_y = data.tex->height();
832 const int32_t texsize_x_mm = texsize_x - 1;
833 const int32_t texsize_y_mm = texsize_y - 1;
834 const int32_t texstride = data.tex->stride();
847 const float dtx = ((T1.
x * dx1) + (T2.
x * dx2) + (T3.
x * dx3));
848 const float dty = ((T1.
y * dx1) + (T2.
y * dx2) + (T3.
y * dx3));
850 while ((uintptr_t)(buf) < end)
856 bx = (-O1 + dx1 - 1u) / dx1;
862 if (dy2 <= 0)
return;
863 const int32_t by = (-O2 + dy2 - 1u) / dy2;
867 const int32_t offs = by * stride;
872 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
879 if (dy3 <= 0)
return;
880 const int32_t by = (-O3 + dy3 - 1u) / dy3;
884 const int32_t offs = by * stride;
889 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
893 int32_t C1 = O1 + (dx1 * bx) + E;
894 int32_t C2 = O2 + (dx2 * bx);
895 int32_t C3 = O3 + (dx3 * bx);
896 float cw = ((C1 * fP1a) + (C2 * fP2a) + (C3 * fP3a));
898 float tx = ((T1.
x * C1) + (T2.
x * C2) + (T3.
x * C3));
899 float ty = ((T1.
y * C1) + (T2.
y * C2) + (T3.
y * C3));
901 while ((bx < lx) && ((C2 | C3) >= 0))
903 ZBUFFER_t& W = zbuf[bx];
904 const ZBUFFER_t aa = (std::is_same<ZBUFFER_t, uint16_t>::value) ? ((ZBUFFER_t)(cw * wa + wb)) : ((ZBUFFER_t)cw);
910 if (TEXTURE_BILINEAR)
912 const float xx = tx * icw;
913 const float yy = ty * icw;
916 const float ax = xx - ttx;
917 const float ay = yy - tty;
918 const int minx = (TEXTURE_WRAP ? (ttx & (texsize_x_mm)) :
shaderclip(ttx, texsize_x_mm));
919 const int maxx = (TEXTURE_WRAP ? ((ttx + 1) & (texsize_x_mm)) :
shaderclip(ttx + 1, texsize_x_mm));
920 const int miny = (TEXTURE_WRAP ? ((tty & (texsize_y_mm)) * texstride) :
shaderclip(tty, texsize_y_mm) * texstride);
921 const int maxy = (TEXTURE_WRAP ? (((tty + 1) & (texsize_y_mm)) * texstride) :
shaderclip(tty + 1, texsize_y_mm) * texstride);
926 const int ttx = (TEXTURE_WRAP ? ((int)((tx * icw))) & (texsize_x_mm) :
shaderclip((
int)(tx * icw), texsize_x_mm));
927 const int tty = (TEXTURE_WRAP ? ((int)((ty * icw))) & (texsize_y_mm) :
shaderclip((
int)(ty * icw), texsize_y_mm));
928 col = tex[ttx + (tty)*texstride];
931 col.mult256(fPR, fPG, fPB);
958 template<
typename color_t,
typename ZBUFFER_t,
bool TEXTURE_BILINEAR,
bool TEXTURE_WRAP>
960 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
961 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
962 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
963 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
965 color_t* buf = data.im->data() + offset;
966 ZBUFFER_t* zbuf = data.zbuf + offset;
968 const float wa = data.wa;
969 const float wb = data.wb;
973 const int32_t stride = data.im->stride();
974 const int32_t zstride = data.im->lx();
976 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
977 const int32_t pa = O1 + O2 + O3;
978 const int32_t E = ((pa == 0) ? 1 : 0);
979 const int32_t aera = pa + E;
981 const float invaera =
fast_inv((
float)aera);
982 const float fP1a = fP1.w * invaera;
983 const float fP2a = fP2.w * invaera;
984 const float fP3a = fP3.w * invaera;
986 const float dw = (dx1 * fP1a) + (dx2 * fP2a) + (dx3 * fP3a);
991 const int fP1R = (
int)(256 * cf1.
R);
992 const int fP1G = (int)(256 * cf1.
G);
993 const int fP1B = (int)(256 * cf1.
B);
994 const int fP21R = (int)(256 * (cf2.R - cf1.
R));
995 const int fP21G = (int)(256 * (cf2.G - cf1.
G));
996 const int fP21B = (int)(256 * (cf2.B - cf1.
B));
997 const int fP31R = (int)(256 * (cf3.
R - cf1.
R));
998 const int fP31G = (int)(256 * (cf3.
G - cf1.
G));
999 const int fP31B = (int)(256 * (cf3.
B - cf1.
B));
1006 const color_t* tex = data.tex->data();
1007 const int32_t texsize_x = data.tex->width();
1008 const int32_t texsize_y = data.tex->height();
1009 const int32_t texsize_x_mm = texsize_x - 1;
1010 const int32_t texsize_y_mm = texsize_y - 1;
1011 const int32_t texstride = data.tex->stride();
1024 const float dtx = ((T1.
x * dx1) + (T2.
x * dx2) + (T3.
x * dx3));
1025 const float dty = ((T1.
y * dx1) + (T2.
y * dx2) + (T3.
y * dx3));
1027 while ((uintptr_t)(buf) < end)
1033 bx = (-O1 + dx1 - 1u) / dx1;
1039 if (dy2 <= 0)
return;
1040 const int32_t by = (-O2 + dy2 - 1u) / dy2;
1044 const int32_t offs = by * stride;
1049 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
1056 if (dy3 <= 0)
return;
1057 const int32_t by = (-O3 + dy3 - 1u) / dy3;
1061 const int32_t offs = by * stride;
1066 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
1069 int32_t C1 = O1 + (dx1 * bx) + E;
1070 int32_t C2 = O2 + (dx2 * bx);
1071 int32_t C3 = O3 + (dx3 * bx);
1072 float cw = ((C1 * fP1a) + (C2 * fP2a) + (C3 * fP3a));
1074 float tx = ((T1.
x * C1) + (T2.
x * C2) + (T3.
x * C3));
1075 float ty = ((T1.
y * C1) + (T2.
y * C2) + (T3.
y * C3));
1077 while ((bx < lx) && ((C2 | C3) >= 0))
1079 ZBUFFER_t& W = zbuf[bx];
1080 const ZBUFFER_t aa = (std::is_same<ZBUFFER_t, uint16_t>::value) ? ((ZBUFFER_t)(cw * wa + wb)) : ((ZBUFFER_t)cw);
1087 if (TEXTURE_BILINEAR)
1089 const float xx = tx * icw;
1090 const float yy = ty * icw;
1093 const float ax = xx - ttx;
1094 const float ay = yy - tty;
1095 const int minx = (TEXTURE_WRAP ? (ttx & (texsize_x_mm)) :
shaderclip(ttx, texsize_x_mm));
1096 const int maxx = (TEXTURE_WRAP ? ((ttx + 1) & (texsize_x_mm)) :
shaderclip(ttx + 1, texsize_x_mm));
1097 const int miny = (TEXTURE_WRAP ? ((tty & (texsize_y_mm)) * texstride) :
shaderclip(tty, texsize_y_mm) * texstride);
1098 const int maxy = (TEXTURE_WRAP ? (((tty + 1) & (texsize_y_mm)) * texstride) :
shaderclip(tty + 1, texsize_y_mm) * texstride);
1103 const int ttx = (TEXTURE_WRAP ? ((int)((tx * icw))) & (texsize_x_mm) :
shaderclip((
int)(tx * icw), texsize_x_mm));
1104 const int tty = (TEXTURE_WRAP ? ((int)((ty * icw))) & (texsize_y_mm) :
shaderclip((
int)(ty * icw), texsize_y_mm));
1105 col = tex[ttx + (tty)*texstride];
1108 const int r = fP1R + ((C2 * fP21R + C3 * fP31R) / aera);
1109 const int g = fP1G + ((C2 * fP21G + C3 * fP31G) / aera);
1110 const int b = fP1B + ((C2 * fP21B + C3 * fP31B) / aera);
1111 col.mult256(r, g, b);
1138 template<
typename color_t,
typename ZBUFFER_t,
bool TEXTURE_BILINEAR,
bool TEXTURE_WRAP>
1140 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
1141 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
1142 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
1143 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
1145 color_t* buf = data.im->data() + offset;
1146 const int32_t stride = data.im->stride();
1148 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
1149 const int32_t pa = O1 + O2 + O3;
1150 const int32_t E = ((pa == 0) ? 1 : 0);
1151 const int32_t aera = pa + E;
1153 const float invaera =
fast_inv((
float)aera);
1155 const RGBf& cf = (
RGBf)data.facecolor;
1156 const int fPR = (
int)(256 * cf.
R);
1157 const int fPG = (int)(256 * cf.
G);
1158 const int fPB = (int)(256 * cf.
B);
1165 const color_t* tex = data.tex->data();
1166 const int32_t texsize_x = data.tex->width();
1167 const int32_t texsize_y = data.tex->height();
1168 const int32_t texsize_x_mm = texsize_x - 1;
1169 const int32_t texsize_y_mm = texsize_y - 1;
1170 const int32_t texstride = data.tex->stride();
1183 const float dtx = ((T1.
x * dx1) + (T2.
x * dx2) + (T3.
x * dx3));
1184 const float dty = ((T1.
y * dx1) + (T2.
y * dx2) + (T3.
y * dx3));
1186 while ((uintptr_t)(buf) < end)
1192 bx = (-O1 + dx1 - 1u) / dx1;
1198 if (dy2 <= 0)
return;
1199 const int32_t by = (-O2 + dy2 - 1u) / dy2;
1203 const int32_t offs = by * stride;
1207 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
1214 if (dy3 <= 0)
return;
1215 const int32_t by = (-O3 + dy3 - 1u) / dy3;
1219 const int32_t offs = by * stride;
1223 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
1226 int32_t C1 = O1 + (dx1 * bx) + E;
1227 int32_t C2 = O2 + (dx2 * bx);
1228 int32_t C3 = O3 + (dx3 * bx);
1230 float tx = ((T1.
x * C1) + (T2.
x * C2) + (T3.
x * C3));
1231 float ty = ((T1.
y * C1) + (T2.
y * C2) + (T3.
y * C3));
1233 while ((bx < lx) && ((C2 | C3) >= 0))
1237 if (TEXTURE_BILINEAR)
1239 const float xx = tx;
1240 const float yy = ty;
1243 const float ax = xx - ttx;
1244 const float ay = yy - tty;
1245 const int minx = (TEXTURE_WRAP ? (ttx & (texsize_x_mm)) :
shaderclip(ttx, texsize_x_mm));
1246 const int maxx = (TEXTURE_WRAP ? ((ttx + 1) & (texsize_x_mm)) :
shaderclip(ttx + 1, texsize_x_mm));
1247 const int miny = (TEXTURE_WRAP ? ((tty & (texsize_y_mm)) * texstride) :
shaderclip(tty, texsize_y_mm) * texstride);
1248 const int maxy = (TEXTURE_WRAP ? (((tty + 1) & (texsize_y_mm)) * texstride) :
shaderclip(tty + 1, texsize_y_mm) * texstride);
1253 const int ttx = (TEXTURE_WRAP ? ((int)((tx))) & (texsize_x_mm) :
shaderclip((
int)(tx), texsize_x_mm));
1254 const int tty = (TEXTURE_WRAP ? ((int)((ty))) & (texsize_y_mm) :
shaderclip((
int)(ty), texsize_y_mm));
1255 col = tex[ttx + (tty)*texstride];
1258 col.mult256(fPR, fPG, fPB);
1282 template<
typename color_t,
typename ZBUFFER_t,
bool TEXTURE_BILINEAR,
bool TEXTURE_WRAP>
1284 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
1285 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
1286 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
1287 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
1289 color_t* buf = data.im->data() + offset;
1290 const int32_t stride = data.im->stride();
1292 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
1293 const int32_t pa = O1 + O2 + O3;
1294 const int32_t E = ((pa == 0) ? 1 : 0);
1295 const int32_t aera = pa + E;
1297 const float invaera =
fast_inv((
float)aera);
1302 const int fP1R = (
int)(256 * cf1.
R);
1303 const int fP1G = (int)(256 * cf1.
G);
1304 const int fP1B = (int)(256 * cf1.
B);
1305 const int fP21R = (int)(256 * (cf2.R - cf1.
R));
1306 const int fP21G = (int)(256 * (cf2.G - cf1.
G));
1307 const int fP21B = (int)(256 * (cf2.B - cf1.
B));
1308 const int fP31R = (int)(256 * (cf3.
R - cf1.
R));
1309 const int fP31G = (int)(256 * (cf3.
G - cf1.
G));
1310 const int fP31B = (int)(256 * (cf3.
B - cf1.
B));
1317 const color_t* tex = data.tex->data();
1318 const int32_t texsize_x = data.tex->width();
1319 const int32_t texsize_y = data.tex->height();
1320 const int32_t texsize_x_mm = texsize_x - 1;
1321 const int32_t texsize_y_mm = texsize_y - 1;
1322 const int32_t texstride = data.tex->stride();
1335 const float dtx = ((T1.
x * dx1) + (T2.
x * dx2) + (T3.
x * dx3));
1336 const float dty = ((T1.
y * dx1) + (T2.
y * dx2) + (T3.
y * dx3));
1338 while ((uintptr_t)(buf) < end)
1344 bx = (-O1 + dx1 - 1u) / dx1;
1350 if (dy2 <= 0)
return;
1351 const int32_t by = (-O2 + dy2 - 1u) / dy2;
1355 const int32_t offs = by * stride;
1359 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
1366 if (dy3 <= 0)
return;
1367 const int32_t by = (-O3 + dy3 - 1u) / dy3;
1371 const int32_t offs = by * stride;
1375 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
1379 int32_t C1 = O1 + (dx1 * bx) + E;
1380 int32_t C2 = O2 + (dx2 * bx);
1381 int32_t C3 = O3 + (dx3 * bx);
1383 float tx = ((T1.
x * C1) + (T2.
x * C2) + (T3.
x * C3));
1384 float ty = ((T1.
y * C1) + (T2.
y * C2) + (T3.
y * C3));
1386 while ((bx < lx) && ((C2 | C3) >= 0))
1390 if (TEXTURE_BILINEAR)
1392 const float xx = tx;
1393 const float yy = ty;
1396 const float ax = xx - ttx;
1397 const float ay = yy - tty;
1398 const int minx = (TEXTURE_WRAP ? (ttx & (texsize_x_mm)) :
shaderclip(ttx, texsize_x_mm));
1399 const int maxx = (TEXTURE_WRAP ? ((ttx + 1) & (texsize_x_mm)) :
shaderclip(ttx + 1, texsize_x_mm));
1400 const int miny = (TEXTURE_WRAP ? ((tty & (texsize_y_mm)) * texstride) :
shaderclip(tty, texsize_y_mm) * texstride);
1401 const int maxy = (TEXTURE_WRAP ? (((tty + 1) & (texsize_y_mm)) * texstride) :
shaderclip(tty + 1, texsize_y_mm) * texstride);
1406 const int ttx = (TEXTURE_WRAP ? ((int)((tx))) & (texsize_x_mm) :
shaderclip((
int)(tx), texsize_x_mm));
1407 const int tty = (TEXTURE_WRAP ? ((int)((ty))) & (texsize_y_mm) :
shaderclip((
int)(ty), texsize_y_mm));
1408 col = tex[ttx + (tty)*texstride];
1411 const int r = fP1R + ((C2 * fP21R + C3 * fP31R) / aera);
1412 const int g = fP1G + ((C2 * fP21G + C3 * fP31G) / aera);
1413 const int b = fP1B + ((C2 * fP21B + C3 * fP31B) / aera);
1414 col.mult256(r, g, b);
1438 template<
typename color_t,
typename ZBUFFER_t,
bool TEXTURE_BILINEAR,
bool TEXTURE_WRAP>
1440 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
1441 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
1442 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
1443 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
1445 color_t* buf = data.im->data() + offset;
1446 ZBUFFER_t* zbuf = data.zbuf + offset;
1448 const float wa = data.wa;
1449 const float wb = data.wb;
1453 const int32_t stride = data.im->stride();
1454 const int32_t zstride = data.im->lx();
1456 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
1457 const int32_t pa = O1 + O2 + O3;
1458 const int32_t E = ((pa == 0) ? 1 : 0);
1459 const int32_t aera = pa + E;
1461 const float invaera =
fast_inv((
float)aera);
1462 const float fP1a = fP1.w * invaera;
1463 const float fP2a = fP2.w * invaera;
1464 const float fP3a = fP3.w * invaera;
1466 const float dw = (dx1 * fP1a) + (dx2 * fP2a) + (dx3 * fP3a);
1468 const RGBf& cf = (
RGBf)data.facecolor;
1469 const int fPR = (
int)(256 * cf.
R);
1470 const int fPG = (int)(256 * cf.
G);
1471 const int fPB = (int)(256 * cf.
B);
1478 const color_t* tex = data.tex->data();
1479 const int32_t texsize_x = data.tex->width();
1480 const int32_t texsize_y = data.tex->height();
1481 const int32_t texsize_x_mm = texsize_x - 1;
1482 const int32_t texsize_y_mm = texsize_y - 1;
1483 const int32_t texstride = data.tex->stride();
1496 const float dtx = ((T1.
x * dx1) + (T2.
x * dx2) + (T3.
x * dx3));
1497 const float dty = ((T1.
y * dx1) + (T2.
y * dx2) + (T3.
y * dx3));
1499 while ((uintptr_t)(buf) < end)
1505 bx = (-O1 + dx1 - 1u) / dx1;
1511 if (dy2 <= 0)
return;
1512 const int32_t by = (-O2 + dy2 - 1u) / dy2;
1516 const int32_t offs = by * stride;
1521 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
1528 if (dy3 <= 0)
return;
1529 const int32_t by = (-O3 + dy3 - 1u) / dy3;
1533 const int32_t offs = by * stride;
1538 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
1542 int32_t C1 = O1 + (dx1 * bx) + E;
1543 int32_t C2 = O2 + (dx2 * bx);
1544 int32_t C3 = O3 + (dx3 * bx);
1545 float cw = ((C1 * fP1a) + (C2 * fP2a) + (C3 * fP3a));
1547 float tx = ((T1.
x * C1) + (T2.
x * C2) + (T3.
x * C3));
1548 float ty = ((T1.
y * C1) + (T2.
y * C2) + (T3.
y * C3));
1550 while ((bx < lx) && ((C2 | C3) >= 0))
1552 ZBUFFER_t& W = zbuf[bx];
1553 const ZBUFFER_t aa = (std::is_same<ZBUFFER_t, uint16_t>::value) ? ((ZBUFFER_t)(cw * wa + wb)) : ((ZBUFFER_t)cw);
1559 if (TEXTURE_BILINEAR)
1561 const float xx = tx;
1562 const float yy = ty;
1565 const float ax = xx - ttx;
1566 const float ay = yy - tty;
1567 const int minx = (TEXTURE_WRAP ? (ttx & (texsize_x_mm)) :
shaderclip(ttx, texsize_x_mm));
1568 const int maxx = (TEXTURE_WRAP ? ((ttx + 1) & (texsize_x_mm)) :
shaderclip(ttx + 1, texsize_x_mm));
1569 const int miny = (TEXTURE_WRAP ? ((tty & (texsize_y_mm)) * texstride) :
shaderclip(tty, texsize_y_mm) * texstride);
1570 const int maxy = (TEXTURE_WRAP ? (((tty + 1) & (texsize_y_mm)) * texstride) :
shaderclip(tty + 1, texsize_y_mm) * texstride);
1575 const int ttx = (TEXTURE_WRAP ? ((int)((tx))) & (texsize_x_mm) :
shaderclip((
int)(tx), texsize_x_mm));
1576 const int tty = (TEXTURE_WRAP ? ((int)((ty))) & (texsize_y_mm) :
shaderclip((
int)(ty), texsize_y_mm));
1577 col = tex[ttx + (tty)*texstride];
1580 col.mult256(fPR, fPG, fPB);
1607 template<
typename color_t,
typename ZBUFFER_t,
bool TEXTURE_BILINEAR,
bool TEXTURE_WRAP>
1609 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
1610 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
1611 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
1612 const RasterizerParams<color_t, color_t, ZBUFFER_t>& data)
1614 color_t* buf = data.im->data() + offset;
1615 ZBUFFER_t* zbuf = data.zbuf + offset;
1617 const float wa = data.wa;
1618 const float wb = data.wb;
1622 const int32_t stride = data.im->stride();
1623 const int32_t zstride = data.im->lx();
1625 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
1626 const int32_t pa = O1 + O2 + O3;
1627 const int32_t E = ((pa == 0) ? 1 : 0);
1628 const int32_t aera = pa + E;
1630 const float invaera =
fast_inv((
float)aera);
1631 const float fP1a = fP1.w * invaera;
1632 const float fP2a = fP2.w * invaera;
1633 const float fP3a = fP3.w * invaera;
1635 const float dw = (dx1 * fP1a) + (dx2 * fP2a) + (dx3 * fP3a);
1640 const int fP1R = (
int)(256 * cf1.
R);
1641 const int fP1G = (int)(256 * cf1.
G);
1642 const int fP1B = (int)(256 * cf1.
B);
1643 const int fP21R = (int)(256 * (cf2.R - cf1.
R));
1644 const int fP21G = (int)(256 * (cf2.G - cf1.
G));
1645 const int fP21B = (int)(256 * (cf2.B - cf1.
B));
1646 const int fP31R = (int)(256 * (cf3.
R - cf1.
R));
1647 const int fP31G = (int)(256 * (cf3.
G - cf1.
G));
1648 const int fP31B = (int)(256 * (cf3.
B - cf1.
B));
1655 const color_t* tex = data.tex->data();
1656 const int32_t texsize_x = data.tex->width();
1657 const int32_t texsize_y = data.tex->height();
1658 const int32_t texsize_x_mm = texsize_x - 1;
1659 const int32_t texsize_y_mm = texsize_y - 1;
1660 const int32_t texstride = data.tex->stride();
1673 const float dtx = ((T1.
x * dx1) + (T2.
x * dx2) + (T3.
x * dx3));
1674 const float dty = ((T1.
y * dx1) + (T2.
y * dx2) + (T3.
y * dx3));
1676 while ((uintptr_t)(buf) < end)
1682 bx = (-O1 + dx1 - 1u) / dx1;
1688 if (dy2 <= 0)
return;
1689 const int32_t by = (-O2 + dy2 - 1u) / dy2;
1693 const int32_t offs = by * stride;
1698 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
1705 if (dy3 <= 0)
return;
1706 const int32_t by = (-O3 + dy3 - 1u) / dy3;
1710 const int32_t offs = by * stride;
1715 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
1719 int32_t C1 = O1 + (dx1 * bx) + E;
1720 int32_t C2 = O2 + (dx2 * bx);
1721 int32_t C3 = O3 + (dx3 * bx);
1722 float cw = ((C1 * fP1a) + (C2 * fP2a) + (C3 * fP3a));
1724 float tx = ((T1.
x * C1) + (T2.
x * C2) + (T3.
x * C3));
1725 float ty = ((T1.
y * C1) + (T2.
y * C2) + (T3.
y * C3));
1727 while ((bx < lx) && ((C2 | C3) >= 0))
1729 ZBUFFER_t& W = zbuf[bx];
1730 const ZBUFFER_t aa = (std::is_same<ZBUFFER_t, uint16_t>::value) ? ((ZBUFFER_t)(cw * wa + wb)) : ((ZBUFFER_t)cw);
1736 if (TEXTURE_BILINEAR)
1738 const float xx = tx;
1739 const float yy = ty;
1742 const float ax = xx - ttx;
1743 const float ay = yy - tty;
1744 const int minx = (TEXTURE_WRAP ? (ttx & (texsize_x_mm)) :
shaderclip(ttx, texsize_x_mm));
1745 const int maxx = (TEXTURE_WRAP ? ((ttx + 1) & (texsize_x_mm)) :
shaderclip(ttx + 1, texsize_x_mm));
1746 const int miny = (TEXTURE_WRAP ? ((tty & (texsize_y_mm)) * texstride) :
shaderclip(tty, texsize_y_mm) * texstride);
1747 const int maxy = (TEXTURE_WRAP ? (((tty + 1) & (texsize_y_mm)) * texstride) :
shaderclip(tty + 1, texsize_y_mm) * texstride);
1752 const int ttx = (TEXTURE_WRAP ? ((int)((tx))) & (texsize_x_mm) :
shaderclip((
int)(tx), texsize_x_mm));
1753 const int tty = (TEXTURE_WRAP ? ((int)((ty))) & (texsize_y_mm) :
shaderclip((
int)(ty), texsize_y_mm));
1754 col = tex[ttx + (tty)*texstride];
1757 const int r = fP1R + ((C2 * fP21R + C3 * fP31R) / aera);
1758 const int g = fP1G + ((C2 * fP21G + C3 * fP31G) / aera);
1759 const int b = fP1B + ((C2 * fP21B + C3 * fP31B) / aera);
1761 col.mult256(r, g, b);
1790 template<
int SHADER_FLAGS_ENABLED,
typename color_t,
typename ZBUFFER_t>
void shader_select(
const int32_t& offset,
const int32_t& lx,
const int32_t& ly,
1791 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
1792 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
1793 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
1794 const RasterizerParams<color_t, color_t, ZBUFFER_t> & data)
1796 int raster_type = data.shader_type;
1797 if (TGX_SHADER_HAS_ZBUFFER(SHADER_FLAGS_ENABLED) && (TGX_SHADER_HAS_ZBUFFER(raster_type)))
1799 if (TGX_SHADER_HAS_ORTHO(SHADER_FLAGS_ENABLED) && (TGX_SHADER_HAS_ORTHO(raster_type)))
1801 if (TGX_SHADER_HAS_TEXTURE(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE(raster_type))
1803 if (TGX_SHADER_HAS_GOURAUD(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_GOURAUD(raster_type))
1805 if (TGX_SHADER_HAS_TEXTURE_BILINEAR(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_BILINEAR(raster_type))
1807 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1808 shader_Gouraud_Texture_Zbuffer_Ortho<color_t,ZBUFFER_t, true,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1809 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1810 shader_Gouraud_Texture_Zbuffer_Ortho<color_t, ZBUFFER_t, true, true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1812 else if (TGX_SHADER_HAS_TEXTURE_NEAREST(SHADER_FLAGS_ENABLED))
1814 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1815 shader_Gouraud_Texture_Zbuffer_Ortho<color_t, ZBUFFER_t, false,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1816 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1817 shader_Gouraud_Texture_Zbuffer_Ortho<color_t, ZBUFFER_t, false,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1820 else if (TGX_SHADER_HAS_FLAT(SHADER_FLAGS_ENABLED))
1822 if (TGX_SHADER_HAS_TEXTURE_BILINEAR(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_BILINEAR(raster_type))
1824 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1825 shader_Flat_Texture_Zbuffer_Ortho<color_t, ZBUFFER_t, true,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1826 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1827 shader_Flat_Texture_Zbuffer_Ortho<color_t, ZBUFFER_t, true,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1829 else if (TGX_SHADER_HAS_TEXTURE_NEAREST(SHADER_FLAGS_ENABLED))
1831 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1832 shader_Flat_Texture_Zbuffer_Ortho<color_t, ZBUFFER_t, false,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1833 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1834 shader_Flat_Texture_Zbuffer_Ortho<color_t, ZBUFFER_t, false,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1838 else if (TGX_SHADER_HAS_NOTEXTURE(SHADER_FLAGS_ENABLED))
1840 if (TGX_SHADER_HAS_GOURAUD(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_GOURAUD(raster_type))
1841 shader_Gouraud_Zbuffer<color_t, ZBUFFER_t>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1842 else if (TGX_SHADER_HAS_FLAT(SHADER_FLAGS_ENABLED))
1843 shader_Flat_Zbuffer<color_t, ZBUFFER_t>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1846 else if (TGX_SHADER_HAS_PERSPECTIVE(SHADER_FLAGS_ENABLED))
1848 if (TGX_SHADER_HAS_TEXTURE(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE(raster_type))
1850 if (TGX_SHADER_HAS_GOURAUD(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_GOURAUD(raster_type))
1852 if (TGX_SHADER_HAS_TEXTURE_BILINEAR(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_BILINEAR(raster_type))
1854 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1855 shader_Gouraud_Texture_Zbuffer<color_t, ZBUFFER_t, true,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1856 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1857 shader_Gouraud_Texture_Zbuffer<color_t, ZBUFFER_t, true, true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1859 else if (TGX_SHADER_HAS_TEXTURE_NEAREST(SHADER_FLAGS_ENABLED))
1861 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1862 shader_Gouraud_Texture_Zbuffer<color_t, ZBUFFER_t, false,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1863 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1864 shader_Gouraud_Texture_Zbuffer<color_t, ZBUFFER_t, false,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1867 else if (TGX_SHADER_HAS_FLAT(SHADER_FLAGS_ENABLED))
1869 if (TGX_SHADER_HAS_TEXTURE_BILINEAR(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_BILINEAR(raster_type))
1871 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1872 shader_Flat_Texture_Zbuffer<color_t, ZBUFFER_t, true,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1873 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1874 shader_Flat_Texture_Zbuffer<color_t, ZBUFFER_t, true,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1876 else if (TGX_SHADER_HAS_TEXTURE_NEAREST(SHADER_FLAGS_ENABLED))
1878 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1879 shader_Flat_Texture_Zbuffer<color_t, ZBUFFER_t, false,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1880 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1881 shader_Flat_Texture_Zbuffer<color_t, ZBUFFER_t, false,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1885 else if (TGX_SHADER_HAS_NOTEXTURE(SHADER_FLAGS_ENABLED))
1887 if (TGX_SHADER_HAS_GOURAUD(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_GOURAUD(raster_type))
1888 shader_Gouraud_Zbuffer<color_t, ZBUFFER_t>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1889 else if (TGX_SHADER_HAS_FLAT(SHADER_FLAGS_ENABLED))
1890 shader_Flat_Zbuffer<color_t, ZBUFFER_t>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1894 else if (TGX_SHADER_HAS_NOZBUFFER(SHADER_FLAGS_ENABLED))
1896 if (TGX_SHADER_HAS_ORTHO(SHADER_FLAGS_ENABLED) && (TGX_SHADER_HAS_ORTHO(raster_type)))
1898 if (TGX_SHADER_HAS_TEXTURE(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE(raster_type))
1900 if (TGX_SHADER_HAS_GOURAUD(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_GOURAUD(raster_type))
1902 if (TGX_SHADER_HAS_TEXTURE_BILINEAR(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_BILINEAR(raster_type))
1904 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1905 shader_Gouraud_Texture_Ortho<color_t, ZBUFFER_t, true,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1906 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1907 shader_Gouraud_Texture_Ortho<color_t, ZBUFFER_t, true,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1909 else if (TGX_SHADER_HAS_TEXTURE_NEAREST(SHADER_FLAGS_ENABLED))
1911 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1912 shader_Gouraud_Texture_Ortho<color_t, ZBUFFER_t, false,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1913 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1914 shader_Gouraud_Texture_Ortho<color_t, ZBUFFER_t, false,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1917 else if (TGX_SHADER_HAS_FLAT(SHADER_FLAGS_ENABLED))
1919 if (TGX_SHADER_HAS_TEXTURE_BILINEAR(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_BILINEAR(raster_type))
1921 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1922 shader_Flat_Texture_Ortho<color_t, ZBUFFER_t, true,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1923 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1924 shader_Flat_Texture_Ortho<color_t, ZBUFFER_t, true,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1926 else if (TGX_SHADER_HAS_TEXTURE_NEAREST(SHADER_FLAGS_ENABLED))
1928 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1929 shader_Flat_Texture_Ortho<color_t, ZBUFFER_t, false,false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1930 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1931 shader_Flat_Texture_Ortho<color_t, ZBUFFER_t, false,true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1935 else if (TGX_SHADER_HAS_NOTEXTURE(SHADER_FLAGS_ENABLED))
1937 if (TGX_SHADER_HAS_GOURAUD(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_GOURAUD(raster_type))
1938 shader_Gouraud<color_t, ZBUFFER_t>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1939 else if (TGX_SHADER_HAS_FLAT(SHADER_FLAGS_ENABLED))
1940 shader_Flat<color_t, ZBUFFER_t>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1943 else if (TGX_SHADER_HAS_PERSPECTIVE(SHADER_FLAGS_ENABLED))
1945 if (TGX_SHADER_HAS_TEXTURE(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE(raster_type))
1947 if (TGX_SHADER_HAS_GOURAUD(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_GOURAUD(raster_type))
1949 if (TGX_SHADER_HAS_TEXTURE_BILINEAR(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_BILINEAR(raster_type))
1951 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1952 shader_Gouraud_Texture<color_t, ZBUFFER_t, true, false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1953 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1954 shader_Gouraud_Texture<color_t, ZBUFFER_t, true, true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1956 else if (TGX_SHADER_HAS_TEXTURE_NEAREST(SHADER_FLAGS_ENABLED))
1958 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1959 shader_Gouraud_Texture<color_t, ZBUFFER_t, false, false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1960 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1961 shader_Gouraud_Texture<color_t, ZBUFFER_t, false, true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1964 else if (TGX_SHADER_HAS_FLAT(SHADER_FLAGS_ENABLED))
1966 if (TGX_SHADER_HAS_TEXTURE_BILINEAR(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_BILINEAR(raster_type))
1968 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1969 shader_Flat_Texture<color_t, ZBUFFER_t, true, false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1970 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1971 shader_Flat_Texture<color_t, ZBUFFER_t, true, true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1973 else if (TGX_SHADER_HAS_TEXTURE_NEAREST(SHADER_FLAGS_ENABLED))
1975 if (TGX_SHADER_HAS_TEXTURE_CLAMP(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_TEXTURE_CLAMP(raster_type))
1976 shader_Flat_Texture<color_t, ZBUFFER_t, false, false>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1977 else if (TGX_SHADER_HAS_TEXTURE_WRAP_POW2(SHADER_FLAGS_ENABLED))
1978 shader_Flat_Texture<color_t, ZBUFFER_t, false, true>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1982 else if (TGX_SHADER_HAS_NOTEXTURE(SHADER_FLAGS_ENABLED))
1984 if (TGX_SHADER_HAS_GOURAUD(SHADER_FLAGS_ENABLED) && TGX_SHADER_HAS_GOURAUD(raster_type))
1985 shader_Gouraud<color_t, ZBUFFER_t>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
1986 else if (TGX_SHADER_HAS_FLAT(SHADER_FLAGS_ENABLED))
1987 shader_Flat<color_t, ZBUFFER_t>(offset, lx, ly, dx1, dy1, O1, fP1, dx2, dy2, O2, fP2, dx3, dy3, O3, fP3, data);
2000 template<
bool USE_BLENDING,
typename color_t_im>
2002 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
2003 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
2004 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
2005 const RasterizerParams<color_t_im, color_t_im, float> & data)
2007 color_t_im * buf = data.im->data() + offset;
2008 const int32_t stride = data.im->stride();
2011 const RGB32 col1 =
RGB64(fP1.color.R, fP1.color.G, fP1.color.B, fP1.A);
2012 const RGB32 col2 =
RGB64(fP2.color.R, fP2.color.G, fP2.color.B, fP2.A);
2013 const RGB32 col3 =
RGB64(fP3.color.R, fP3.color.G, fP3.color.B, fP3.A);
2015 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
2016 const int32_t pa = O1 + O2 + O3;
2017 const int32_t E = ((pa == 0) ? 1 : 0);
2018 const int32_t aera = pa + E;
2019 const int shiftC = (aera > (1 << 22)) ? 10 : 0;
2021 while ((uintptr_t)(buf) < end)
2027 bx = (-O1 + dx1 - 1u) / dx1;
2033 if (dy2 <= 0)
return;
2034 const int32_t by = (-O2 + dy2 - 1u) / dy2;
2038 const int32_t offs = by * stride;
2042 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
2049 if (dy3 <= 0)
return;
2050 const int32_t by = (-O3 + dy3 - 1u) / dy3;
2054 const int32_t offs = by * stride;
2058 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
2062 int32_t C2 = O2 + (dx2 * bx);
2063 int32_t C3 = O3 + (dx3 * bx);
2064 while ((bx < lx) && ((C2 | C3) >= 0))
2070 buf[bx] = color_t_im(c);
2093 template<
bool USE_BLENDING,
bool USE_MASKING,
bool USE_GRADIENT,
typename color_t_im,
typename color_t_tex>
2095 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
2096 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
2097 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
2098 const RasterizerParams<color_t_im, color_t_tex, float> & data)
2101 color_t_im * buf = data.im->data() + offset;
2102 const int32_t stride = data.im->stride();
2104 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
2105 const int32_t pa = O1 + O2 + O3;
2106 const int32_t E = ((pa == 0) ? 1 : 0);
2107 const int32_t aera = pa + E;
2109 const float invaera =
fast_inv((
float)aera);
2111 const color_t_tex mask_color = data.mask_color;
2122 const color_t_tex * tex = data.tex->data();
2123 const int32_t texsize_x = data.tex->width();
2124 const int32_t texsize_y = data.tex->height();
2125 const int32_t texsize_x_mm = data.tex->width() - 1;
2126 const int32_t texsize_y_mm = data.tex->height() - 1;
2127 const int32_t texstride = data.tex->stride();
2140 const float dtx = ((T1.x * dx1) + (T2.x * dx2) + (T3.x * dx3));
2141 const float dty = ((T1.y * dx1) + (T2.y * dx2) + (T3.y * dx3));
2143 while ((uintptr_t)(buf) < end)
2149 bx = (-O1 + dx1 - 1u) / dx1;
2155 if (dy2 <= 0)
return;
2156 const int32_t by = (-O2 + dy2 - 1u) / dy2;
2160 const int32_t offs = by * stride;
2164 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
2171 if (dy3 <= 0)
return;
2172 const int32_t by = (-O3 + dy3 - 1u) / dy3;
2176 const int32_t offs = by * stride;
2180 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
2184 int32_t C1 = O1 + (dx1 * bx) + E;
2185 int32_t C2 = O2 + (dx2 * bx);
2186 int32_t C3 = O3 + (dx3 * bx);
2188 float tx = ((T1.x * C1) + (T2.x * C2) + (T3.x * C3)) - 0.5f;
2189 float ty = ((T1.y * C1) + (T2.y * C2) + (T3.y * C3)) - 0.5f;
2191 while ((bx < lx) && ((C2 | C3) >= 0))
2193 const float xx = tx;
2194 const float yy = ty;
2197 const float ax = xx - ttx;
2198 const float ay = yy - tty;
2200 const int minx =
shaderclip(ttx, texsize_x_mm);
2201 const int maxx =
shaderclip(ttx + 1, texsize_x_mm);
2202 const int miny =
shaderclip(tty, texsize_y_mm) * texstride;
2203 const int maxy =
shaderclip(tty + 1, texsize_y_mm) * texstride;
2207 auto col00 = tex[minx + miny];
2210 auto col10 = tex[maxx + miny];
2213 auto col01 = tex[minx + maxy];
2216 auto col11 = tex[maxx + maxy];
2225 const int sC1 = aera - C3 - C2;
2226 const float m = 256.0f / aera;
2227 const int r = (int)((sC1 * cf1.
R + sC2 * cf2.R + sC3 * cf3.
R) * m);
2228 const int g = (int)((sC1 * cf1.
G + sC2 * cf2.G + sC3 * cf3.
G) * m);
2229 const int b = (int)((sC1 * cf1.
B + sC2 * cf2.B + sC3 * cf3.
B) * m);
2230 const int a = (int)((sC1 * fP1.A + sC2 * fP2.A + sC3 * fP3.A) * m);
2237 buf[bx] = color_t_im(c);
2241 buf[bx] = color_t_im(col);
2246 color_t_tex col =
interpolateColorsBilinear(tex[minx + miny], tex[maxx + miny], tex[minx + maxy], tex[maxx + maxy], ax, ay);
2251 const int sC1 = aera - C3 - C2;
2252 const float m = 256.0f / aera;
2253 const int r = (int)((sC1 * cf1.
R + sC2 * cf2.R + sC3 * cf3.
R) * m);
2254 const int g = (int)((sC1 * cf1.
G + sC2 * cf2.G + sC3 * cf3.
G) * m);
2255 const int b = (int)((sC1 * cf1.
B + sC2 * cf2.B + sC3 * cf3.
B) * m);
2256 const int a = (int)((sC1 * fP1.A + sC2 * fP2.A + sC3 * fP3.A) * m);
2257 col.mult256(r, g, b, a);
2261 color_t_tex c = color_t_tex(buf[bx]);
2262 c.blend(col, data.opacity);
2263 buf[bx] = color_t_im(c);
2267 buf[bx] = color_t_im(col);
2293 template<
typename BLEND_OP,
typename color_t_im,
typename color_t_tex>
2295 const int32_t dx1,
const int32_t dy1, int32_t O1,
const RasterizerVec4& fP1,
2296 const int32_t dx2,
const int32_t dy2, int32_t O2,
const RasterizerVec4& fP2,
2297 const int32_t dx3,
const int32_t dy3, int32_t O3,
const RasterizerVec4& fP3,
2298 const RasterizerParams<color_t_im, color_t_tex, float, BLEND_OP> & data)
2301 color_t_im * buf = data.im->data() + offset;
2302 const int32_t stride = data.im->stride();
2304 const uintptr_t end = (uintptr_t)(buf + (ly * stride));
2305 const int32_t pa = O1 + O2 + O3;
2306 const int32_t E = ((pa == 0) ? 1 : 0);
2307 const int32_t aera = pa + E;
2309 const float invaera =
fast_inv((
float)aera);
2317 const color_t_tex * tex = data.tex->data();
2318 const int32_t texsize_x = data.tex->width();
2319 const int32_t texsize_y = data.tex->height();
2320 const int32_t texsize_x_mm = data.tex->width() - 1;
2321 const int32_t texsize_y_mm = data.tex->height() - 1;
2322 const int32_t texstride = data.tex->stride();
2335 const float dtx = ((T1.
x * dx1) + (T2.
x * dx2) + (T3.
x * dx3));
2336 const float dty = ((T1.
y * dx1) + (T2.
y * dx2) + (T3.
y * dx3));
2338 while ((uintptr_t)(buf) < end)
2344 bx = (-O1 + dx1 - 1u) / dx1;
2350 if (dy2 <= 0)
return;
2351 const int32_t by = (-O2 + dy2 - 1u) / dy2;
2355 const int32_t offs = by * stride;
2359 const int32_t bx2 = (-O2 + dx2 - 1u) / dx2;
2366 if (dy3 <= 0)
return;
2367 const int32_t by = (-O3 + dy3 - 1u) / dy3;
2371 const int32_t offs = by * stride;
2375 const int32_t bx3 = (-O3 + dx3 - 1u) / dx3;
2379 int32_t C1 = O1 + (dx1 * bx) + E;
2380 int32_t C2 = O2 + (dx2 * bx);
2381 int32_t C3 = O3 + (dx3 * bx);
2383 float tx = ((T1.
x * C1) + (T2.
x * C2) + (T3.
x * C3)) - 0.5f;
2384 float ty = ((T1.
y * C1) + (T2.
y * C2) + (T3.
y * C3)) - 0.5f;
2386 while ((bx < lx) && ((C2 | C3) >= 0))
2388 const float xx = tx;
2389 const float yy = ty;
2392 const float ax = xx - ttx;
2393 const float ay = yy - tty;
2395 const int minx =
shaderclip(ttx, texsize_x_mm);
2396 const int maxx =
shaderclip(ttx + 1, texsize_x_mm);
2397 const int miny =
shaderclip(tty, texsize_y_mm) * texstride;
2398 const int maxy =
shaderclip(tty + 1, texsize_y_mm) * texstride;
2400 color_t_tex col =
interpolateColorsBilinear(tex[minx + miny], tex[maxx + miny], tex[minx + maxy], tex[maxx + maxy], ax, ay);
2402 buf[bx] = (color_t_im)((*data.p_blend_op)(col, buf[bx]));
const RGB32 RGB32_Red
Color red in RGB32 format.
RGB565 interpolateColorsBilinear(const RGB565 &C00, const RGB565 &C10, const RGB565 &C01, const RGB565 &C11, const float ax, const float ay)
Bilinear interpolation between 4 colors.
Definition: Color.h:621
RGB565 interpolateColorsTriangle(const RGB565 &col1, int32_t C1, const RGB565 &col2, int32_t C2, const RGB565 &col3, const int32_t totC)
Interpolate between 3 colors.
Definition: Color.h:591
TGX_INLINE int32_t lfloorf(float x)
Compute (int32_t)floorf(x).
Definition: Misc.h:374
TGX_INLINE T max(const T &a, const T &b)
Don't know why but much faster than fmaxf() for floats.
Definition: Misc.h:136
TGX_INLINE float fast_inv(float x)
Fast (approximate) computation of 1/x.
Definition: Misc.h:180
Triangle shader parameters.
void shader_test(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t &dx1, const int32_t &dy1, int32_t O1, const tgx::RasterizerVec4 &fP1, const int32_t &dx2, const int32_t &dy2, int32_t O2, const tgx::RasterizerVec4 &fP2, const int32_t &dx3, const int32_t &dy3, int32_t O3, const tgx::RasterizerVec4 &fP3, const tgx::RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
For test purposes...
Definition: Shaders.h:45
void shader_select(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
META-Shader THAT DISPATCH TO THE CORRECT Shader ABOVE (IF ENABLED).
Definition: Shaders.h:1790
void shader_Gouraud_Texture(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
TEXTURE + GOURAUD SHADING (NO ZBUFFER)
Definition: Shaders.h:388
void shader_2D_texture(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t_im, color_t_tex, float > &data)
2D shader (texture)
Definition: Shaders.h:2094
void shader_Flat(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t &dx1, const int32_t &dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t &dx2, const int32_t &dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t &dx3, const int32_t &dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
FLAT SHADING (NO ZBUFFER)
Definition: Shaders.h:74
void shader_Flat_Texture(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
TEXTURE + FLAT SHADING (NO ZBUFFER)
Definition: Shaders.h:234
void shader_Gouraud(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t &dx1, const int32_t &dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t &dx2, const int32_t &dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t &dx3, const int32_t &dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
GOURAUD SHADING (NO Z BUFFER)
Definition: Shaders.h:151
void shader_Flat_Texture_Zbuffer_Ortho(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
ZBUFFER + TEXTURE + FLAT SHADING + ORTHOGRAPHIC.
Definition: Shaders.h:1439
void shader_Gouraud_Texture_Ortho(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
TEXTURE + GOURAUD SHADING (NO ZBUFFER) + ORTHOGRAPHIC.
Definition: Shaders.h:1283
void shader_Flat_Texture_Zbuffer(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
ZBUFFER + TEXTURE + FLAT SHADING.
Definition: Shaders.h:789
void shader_Flat_Texture_Ortho(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
TEXTURE + FLAT SHADING (NO ZBUFFER) + ORTHOGRAPHIC.
Definition: Shaders.h:1139
void shader_Gouraud_Texture_Zbuffer_Ortho(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
ZBUFFER + TEXTURE + GOURAUD SHADING + ORTHOGRAPHIC.
Definition: Shaders.h:1608
void shader_Gouraud_Zbuffer(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
ZBUFFER + GOURAUD SHADING.
Definition: Shaders.h:766
void shader_2D_gradient(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t_im, color_t_im, float > &data)
2D shader (gradient)
Definition: Shaders.h:2001
TGX_INLINE int shaderclip(int v, int maxv)
for texture clamping
Definition: Shaders.h:34
void shader_Flat_Zbuffer(const int32_t offset, const int32_t &lx, const int32_t &ly, const int32_t &dx1, const int32_t &dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t &dx2, const int32_t &dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t &dx3, const int32_t &dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
ZBUFFER + FLAT SHADING.
Definition: Shaders.h:555
void shader_Gouraud_Zbuffer_sub(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
ZBUFFER + GOURAUD SHADING (sub-procedure, templated on shiftC)
Definition: Shaders.h:659
void shader_Gouraud_Texture_Zbuffer(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t, color_t, ZBUFFER_t > &data)
ZBUFFER + TEXTURE + GOURAUD SHADING.
Definition: Shaders.h:959
void shader_2D_texture_blend_op(const int32_t &offset, const int32_t &lx, const int32_t &ly, const int32_t dx1, const int32_t dy1, int32_t O1, const RasterizerVec4 &fP1, const int32_t dx2, const int32_t dy2, int32_t O2, const RasterizerVec4 &fP2, const int32_t dx3, const int32_t dy3, int32_t O3, const RasterizerVec4 &fP3, const RasterizerParams< color_t_im, color_t_tex, float, BLEND_OP > &data)
2D shader (texture with custom blending operator)
Definition: Shaders.h:2294
Color in R8/G8/B8/A8 format.
Definition: Color.h:1176
void mult256(int mr, int mg, int mb)
Multiply each color component by a given factor m/256 with m in [0,256] except the A component.
Definition: Color.h:1590
void blend256(const RGB32 &fg_col, uint32_t alpha)
alpha-blend fg_col over this one with a given opacity in the range 0.0f (fully transparent) to 1....
Definition: Color.h:1561
void blend(const RGB32 &fg_col, float alpha)
alpha-blend fg_col over this one with a given opacity in the range 0.0f (fully transparent) to 1....
Definition: Color.h:1546
float opacity() const
Return the opacity (alpha channel value) of this color in the range [0,1] (0=fully transparent,...
Definition: Color.h:1629
float opacity() const
Dummy function for compatibility with color types having an alpha channel.
Definition: Color.h:565
Color in R16/G16/B16/A16 format.
Definition: Color.h:1791
Color in R,G,B float format.
Definition: Color.h:2407
float R
Red channel.
Definition: Color.h:2420
float B
Blue channel.
Definition: Color.h:2422
float G
Green channel.
Definition: Color.h:2421
T x
'x' coordinate (first dimension)
Definition: Vec2.h:72
T y
'y' coordinate (second dimension)
Definition: Vec2.h:73