1 /***************************************************************************
2 * Copyright (C) 2010 PCSX4ALL Team *
3 * Copyright (C) 2010 Unai *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. *
19 ***************************************************************************/
21 #ifndef __GPU_UNAI_GPU_RASTER_POLYGON_H__
22 #define __GPU_UNAI_GPU_RASTER_POLYGON_H__
24 //senquack - NOTE: GPU Unai poly routines have been rewritten/adapted
25 // from DrHell routines to fix multiple issues. See README_senquack.txt
27 ///////////////////////////////////////////////////////////////////////////////
28 // Shared poly vertex buffer, able to handle 3 or 4-pt polys of any type.
29 ///////////////////////////////////////////////////////////////////////////////
32 s32 x, y; // Sign-extended 11-bit X,Y coords
34 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
35 struct { u8 pad[2], v, u; } tex; // Texture coords (if used)
37 struct { u8 u, v, pad[2]; } tex; // Texture coords (if used)
42 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
43 struct { u8 pad, b, g, r; } col; // 24-bit RGB color (if used)
45 struct { u8 r, g, b, pad; } col; // 24-bit RGB color (if used)
52 POLYATTR_TEXTURE = (1 << 0),
53 POLYATTR_GOURAUD = (1 << 1)
58 POLYTYPE_FT = (POLYATTR_TEXTURE),
59 POLYTYPE_G = (POLYATTR_GOURAUD),
60 POLYTYPE_GT = (POLYATTR_TEXTURE | POLYATTR_GOURAUD)
63 ///////////////////////////////////////////////////////////////////////////////
64 // polyInitVertexBuffer()
65 // Fills vbuf[] array with data from any type of poly draw-command packet.
66 ///////////////////////////////////////////////////////////////////////////////
67 static void polyInitVertexBuffer(PolyVertex *vbuf, const PtrUnion packet, PolyType ptype, u32 is_quad)
69 bool texturing = ptype & POLYATTR_TEXTURE;
70 bool gouraud = ptype & POLYATTR_GOURAUD;
72 int vert_stride = 1; // Stride of vertices in cmd packet, in 32-bit words
78 int num_verts = (is_quad) ? 4 : 3;
81 // X,Y coords, adjusted by draw offsets
82 s32 x_off = gpu_unai.DrawingOffset[0];
83 s32 y_off = gpu_unai.DrawingOffset[1];
85 for (int i=0; i < num_verts; ++i, ptr += vert_stride) {
86 u32 coords = le32_to_u32(*ptr);
87 vbuf[i].x = GPU_EXPANDSIGN((s16)coords) + x_off;
88 vbuf[i].y = GPU_EXPANDSIGN((s16)(coords >> 16)) + y_off;
91 // U,V texture coords (if applicable)
94 for (int i=0; i < num_verts; ++i, ptr += vert_stride)
95 vbuf[i].tex_word = le32_to_u32(*ptr);
98 // Colors (if applicable)
101 for (int i=0; i < num_verts; ++i, ptr += vert_stride)
102 vbuf[i].col_word = le32_to_u32(*ptr);
106 ///////////////////////////////////////////////////////////////////////////////
107 // Helper functions to determine which vertex in a 2 or 3 vertex array
108 // has the highest/lowest X/Y coordinate.
109 // Note: the comparison logic is such that, given a set of vertices with
110 // identical values for a given coordinate, a different index will be
111 // returned from vertIdxOfLeast..() than a call to vertIdxOfHighest..().
112 // This ensures that, during the vertex-ordering phase of rasterization,
113 // all three vertices remain unique.
114 ///////////////////////////////////////////////////////////////////////////////
117 static inline int vertIdxOfLeastXCoord2(const T *Tptr)
119 return (Tptr[0].x <= Tptr[1].x) ? 0 : 1;
123 static inline int vertIdxOfLeastXCoord3(const T *Tptr)
125 int least_of_v0_v1 = vertIdxOfLeastXCoord2(Tptr);
126 return (Tptr[least_of_v0_v1].x <= Tptr[2].x) ? least_of_v0_v1 : 2;
130 static inline int vertIdxOfLeastYCoord2(const T *Tptr)
132 return (Tptr[0].y <= Tptr[1].y) ? 0 : 1;
136 static inline int vertIdxOfLeastYCoord3(const T *Tptr)
138 int least_of_v0_v1 = vertIdxOfLeastYCoord2(Tptr);
139 return (Tptr[least_of_v0_v1].y <= Tptr[2].y) ? least_of_v0_v1 : 2;
143 static inline int vertIdxOfHighestXCoord2(const T *Tptr)
145 return (Tptr[1].x >= Tptr[0].x) ? 1 : 0;
149 static inline int vertIdxOfHighestXCoord3(const T *Tptr)
151 int highest_of_v0_v1 = vertIdxOfHighestXCoord2(Tptr);
152 return (Tptr[2].x >= Tptr[highest_of_v0_v1].x) ? 2 : highest_of_v0_v1;
156 static inline int vertIdxOfHighestYCoord2(const T *Tptr)
158 return (Tptr[1].y >= Tptr[0].y) ? 1 : 0;
162 static inline int vertIdxOfHighestYCoord3(const T *Tptr)
164 int highest_of_v0_v1 = vertIdxOfHighestYCoord2(Tptr);
165 return (Tptr[2].y >= Tptr[highest_of_v0_v1].y) ? 2 : highest_of_v0_v1;
168 ///////////////////////////////////////////////////////////////////////////////
170 // Determines if the specified triangle should be rendered. If so, it
171 // fills the given array of vertex pointers, vert_ptrs, in order of
172 // increasing Y coordinate values, as required by rasterization algorithm.
173 // Parameter 'tri_num' is 0 for first triangle (idx 0,1,2 of vbuf[]),
174 // or 1 for second triangle of a quad (idx 1,2,3 of vbuf[]).
175 // Returns true if triangle should be rendered, false if not.
176 ///////////////////////////////////////////////////////////////////////////////
177 static bool polyUseTriangle(const PolyVertex *vbuf, int tri_num, const PolyVertex **vert_ptrs)
179 // Using verts 0,1,2 or is this the 2nd pass of a quad (verts 1,2,3)?
180 const PolyVertex *tri_ptr = &vbuf[(tri_num == 0) ? 0 : 1];
182 // Get indices of highest/lowest X,Y coords within triangle
183 int idx_lowest_x = vertIdxOfLeastXCoord3(tri_ptr);
184 int idx_highest_x = vertIdxOfHighestXCoord3(tri_ptr);
185 int idx_lowest_y = vertIdxOfLeastYCoord3(tri_ptr);
186 int idx_highest_y = vertIdxOfHighestYCoord3(tri_ptr);
188 // Maximum absolute distance between any two X coordinates is 1023,
189 // and for Y coordinates is 511 (PS1 hardware limitation)
190 int lowest_x = tri_ptr[idx_lowest_x].x;
191 int highest_x = tri_ptr[idx_highest_x].x;
192 int lowest_y = tri_ptr[idx_lowest_y].y;
193 int highest_y = tri_ptr[idx_highest_y].y;
194 if ((highest_x - lowest_x) >= CHKMAX_X ||
195 (highest_y - lowest_y) >= CHKMAX_Y)
198 // Determine if triangle is completely outside clipping range
199 int xmin, xmax, ymin, ymax;
200 xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2];
201 ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3];
202 int clipped_lowest_x = Max2(xmin,lowest_x);
203 int clipped_lowest_y = Max2(ymin,lowest_y);
204 int clipped_highest_x = Min2(xmax,highest_x);
205 int clipped_highest_y = Min2(ymax,highest_y);
206 if (clipped_lowest_x >= clipped_highest_x ||
207 clipped_lowest_y >= clipped_highest_y)
210 // Order vertex ptrs by increasing y value (draw routines need this).
211 // The middle index is deduced by a binary math trick that depends
212 // on index range always being between 0..2
213 vert_ptrs[0] = tri_ptr + idx_lowest_y;
214 vert_ptrs[1] = tri_ptr + ((idx_lowest_y + idx_highest_y) ^ 3);
215 vert_ptrs[2] = tri_ptr + idx_highest_y;
219 ///////////////////////////////////////////////////////////////////////////////
220 // GPU internal polygon drawing functions
221 ///////////////////////////////////////////////////////////////////////////////
223 /*----------------------------------------------------------------------
224 gpuDrawPolyF - Flat-shaded, untextured poly
225 ----------------------------------------------------------------------*/
226 void gpuDrawPolyF(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad)
228 // Set up bgr555 color to be used across calls in inner driver
229 gpu_unai.PixelData = GPU_RGB16(le32_to_u32(packet.U4[0]));
232 polyInitVertexBuffer(vbuf, packet, POLYTYPE_F, is_quad);
234 int total_passes = is_quad ? 2 : 1;
238 const PolyVertex* vptrs[3];
239 if (polyUseTriangle(vbuf, cur_pass, vptrs) == false)
243 s32 x3, dx3, x4, dx4, dx;
244 s32 x0, x1, x2, y0, y1, y2;
246 x0 = vptrs[0]->x; y0 = vptrs[0]->y;
247 x1 = vptrs[1]->x; y1 = vptrs[1]->y;
248 x2 = vptrs[2]->x; y2 = vptrs[2]->y;
252 dx = (x2 - x1) * ya - (x2 - x0) * yb;
254 for (int loop0 = 2; loop0; loop0--) {
259 #ifdef GPU_UNAI_USE_FLOATMATH
260 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
261 dx3 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) * FloatInv(y2 - y0)) : 0;
262 dx4 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) * FloatInv(y1 - y0)) : 0;
264 dx3 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) / (float)(y2 - y0)) : 0;
265 dx4 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) / (float)(y1 - y0)) : 0;
267 #else // Integer Division:
268 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
269 dx3 = ((y2 - y0) != 0) ? xLoDivx((x2 - x0), (y2 - y0)) : 0;
270 dx4 = ((y1 - y0) != 0) ? xLoDivx((x1 - x0), (y1 - y0)) : 0;
272 dx3 = ((y2 - y0) != 0) ? GPU_FAST_DIV((x2 - x0) << FIXED_BITS, (y2 - y0)) : 0;
273 dx4 = ((y1 - y0) != 0) ? GPU_FAST_DIV((x1 - x0) << FIXED_BITS, (y1 - y0)) : 0;
277 #ifdef GPU_UNAI_USE_FLOATMATH
278 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
279 dx3 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) * FloatInv(y1 - y0)) : 0;
280 dx4 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) * FloatInv(y2 - y0)) : 0;
282 dx3 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) / (float)(y1 - y0)) : 0;
283 dx4 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) / (float)(y2 - y0)) : 0;
285 #else // Integer Division:
286 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
287 dx3 = ((y1 - y0) != 0) ? xLoDivx((x1 - x0), (y1 - y0)) : 0;
288 dx4 = ((y2 - y0) != 0) ? xLoDivx((x2 - x0), (y2 - y0)) : 0;
290 dx3 = ((y1 - y0) != 0) ? GPU_FAST_DIV((x1 - x0) << FIXED_BITS, (y1 - y0)) : 0;
291 dx4 = ((y2 - y0) != 0) ? GPU_FAST_DIV((x2 - x0) << FIXED_BITS, (y2 - y0)) : 0;
296 //senquack - break out of final loop if nothing to be drawn (1st loop
297 // must always be taken to setup dx3/dx4)
303 x3 = i2x(x0) + (dx3 * (y1 - y0));
305 #ifdef GPU_UNAI_USE_FLOATMATH
306 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
307 dx4 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) * FloatInv(y2 - y1)) : 0;
309 dx4 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) / (float)(y2 - y1)) : 0;
311 #else // Integer Division:
312 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
313 dx4 = ((y2 - y1) != 0) ? xLoDivx ((x2 - x1), (y2 - y1)) : 0;
315 dx4 = ((y2 - y1) != 0) ? GPU_FAST_DIV((x2 - x1) << FIXED_BITS, (y2 - y1)) : 0;
320 x4 = i2x(x0) + (dx4 * (y1 - y0));
321 #ifdef GPU_UNAI_USE_FLOATMATH
322 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
323 dx3 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) * FloatInv(y2 - y1)) : 0;
325 dx3 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) / (float)(y2 - y1)) : 0;
327 #else // Integer Division:
328 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
329 dx3 = ((y2 - y1) != 0) ? xLoDivx ((x2 - x1), (y2 - y1)) : 0;
331 dx3 = ((y2 - y1) != 0) ? GPU_FAST_DIV((x2 - x1) << FIXED_BITS, (y2 - y1)) : 0;
337 s32 xmin, xmax, ymin, ymax;
338 xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2];
339 ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3];
341 if ((ymin - ya) > 0) {
342 x3 += (dx3 * (ymin - ya));
343 x4 += (dx4 * (ymin - ya));
347 if (yb > ymax) yb = ymax;
353 le16_t* PixelBase = &gpu_unai.vram[FRAME_OFFSET(0, ya)];
354 int li=gpu_unai.ilace_mask;
355 int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0);
356 int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1);
358 for (; loop1; --loop1, ya++, PixelBase += FRAME_WIDTH,
359 x3 += dx3, x4 += dx4 )
362 if ((ya&pi)==pif) continue;
364 xa = FixedCeilToInt(x3); xb = FixedCeilToInt(x4);
365 if ((xmin - xa) > 0) xa = xmin;
366 if (xb > xmax) xb = xmax;
368 gpuPolySpanDriver(gpu_unai, PixelBase + xa, (xb - xa));
371 } while (++cur_pass < total_passes);
374 /*----------------------------------------------------------------------
375 gpuDrawPolyFT - Flat-shaded, textured poly
376 ----------------------------------------------------------------------*/
377 void gpuDrawPolyFT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad)
379 // r8/g8/b8 used if texture-blending & dithering is applied (24-bit light)
380 gpu_unai.r8 = packet.U1[0];
381 gpu_unai.g8 = packet.U1[1];
382 gpu_unai.b8 = packet.U1[2];
383 // r5/g5/b5 used if just texture-blending is applied (15-bit light)
384 gpu_unai.r5 = packet.U1[0] >> 3;
385 gpu_unai.g5 = packet.U1[1] >> 3;
386 gpu_unai.b5 = packet.U1[2] >> 3;
389 polyInitVertexBuffer(vbuf, packet, POLYTYPE_FT, is_quad);
391 int total_passes = is_quad ? 2 : 1;
395 const PolyVertex* vptrs[3];
396 if (polyUseTriangle(vbuf, cur_pass, vptrs) == false)
400 s32 x3, dx3, x4, dx4, dx;
401 s32 u3, du3, v3, dv3;
402 s32 x0, x1, x2, y0, y1, y2;
403 s32 u0, u1, u2, v0, v1, v2;
406 x0 = vptrs[0]->x; y0 = vptrs[0]->y;
407 u0 = vptrs[0]->tex.u; v0 = vptrs[0]->tex.v;
408 x1 = vptrs[1]->x; y1 = vptrs[1]->y;
409 u1 = vptrs[1]->tex.u; v1 = vptrs[1]->tex.v;
410 x2 = vptrs[2]->x; y2 = vptrs[2]->y;
411 u2 = vptrs[2]->tex.u; v2 = vptrs[2]->tex.v;
415 dx4 = (x2 - x1) * ya - (x2 - x0) * yb;
416 du4 = (u2 - u1) * ya - (u2 - u0) * yb;
417 dv4 = (v2 - v1) * ya - (v2 - v0) * yb;
425 #ifdef GPU_UNAI_USE_FLOATMATH
426 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
428 float finv = FloatInv(dx4);
429 du4 = (fixed)((du4 << FIXED_BITS) * finv);
430 dv4 = (fixed)((dv4 << FIXED_BITS) * finv);
437 du4 = (fixed)((du4 << FIXED_BITS) / fdiv);
438 dv4 = (fixed)((dv4 << FIXED_BITS) / fdiv);
443 #else // Integer Division:
444 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
448 du4 = xInvMulx(du4, iF, iS);
449 dv4 = xInvMulx(dv4, iF, iS);
455 du4 = GPU_FAST_DIV(du4 << FIXED_BITS, dx4);
456 dv4 = GPU_FAST_DIV(dv4 << FIXED_BITS, dx4);
462 // Set u,v increments for inner driver
463 gpu_unai.u_inc = du4;
464 gpu_unai.v_inc = dv4;
466 //senquack - TODO: why is it always going through 2 iterations when sometimes one would suffice here?
467 // (SAME ISSUE ELSEWHERE)
468 for (s32 loop0 = 2; loop0; loop0--) {
472 u3 = i2x(u0); v3 = i2x(v0);
474 #ifdef GPU_UNAI_USE_FLOATMATH
475 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
476 if ((y2 - y0) != 0) {
477 float finv = FloatInv(y2 - y0);
478 dx3 = (fixed)(((x2 - x0) << FIXED_BITS) * finv);
479 du3 = (fixed)(((u2 - u0) << FIXED_BITS) * finv);
480 dv3 = (fixed)(((v2 - v0) << FIXED_BITS) * finv);
484 dx4 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) * FloatInv(y1 - y0)) : 0;
486 if ((y2 - y0) != 0) {
487 float fdiv = y2 - y0;
488 dx3 = (fixed)(((x2 - x0) << FIXED_BITS) / fdiv);
489 du3 = (fixed)(((u2 - u0) << FIXED_BITS) / fdiv);
490 dv3 = (fixed)(((v2 - v0) << FIXED_BITS) / fdiv);
494 dx4 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) / (float)(y1 - y0)) : 0;
496 #else // Integer Division:
497 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
498 if ((y2 - y0) != 0) {
500 xInv((y2 - y0), iF, iS);
501 dx3 = xInvMulx((x2 - x0), iF, iS);
502 du3 = xInvMulx((u2 - u0), iF, iS);
503 dv3 = xInvMulx((v2 - v0), iF, iS);
507 dx4 = ((y1 - y0) != 0) ? xLoDivx((x1 - x0), (y1 - y0)) : 0;
509 if ((y2 - y0) != 0) {
510 dx3 = GPU_FAST_DIV((x2 - x0) << FIXED_BITS, (y2 - y0));
511 du3 = GPU_FAST_DIV((u2 - u0) << FIXED_BITS, (y2 - y0));
512 dv3 = GPU_FAST_DIV((v2 - v0) << FIXED_BITS, (y2 - y0));
516 dx4 = ((y1 - y0) != 0) ? GPU_FAST_DIV((x1 - x0) << FIXED_BITS, (y1 - y0)) : 0;
520 #ifdef GPU_UNAI_USE_FLOATMATH
521 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
522 if ((y1 - y0) != 0) {
523 float finv = FloatInv(y1 - y0);
524 dx3 = (fixed)(((x1 - x0) << FIXED_BITS) * finv);
525 du3 = (fixed)(((u1 - u0) << FIXED_BITS) * finv);
526 dv3 = (fixed)(((v1 - v0) << FIXED_BITS) * finv);
530 dx4 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) * FloatInv(y2 - y0)) : 0;
532 if ((y1 - y0) != 0) {
533 float fdiv = y1 - y0;
534 dx3 = (fixed)(((x1 - x0) << FIXED_BITS) / fdiv);
535 du3 = (fixed)(((u1 - u0) << FIXED_BITS) / fdiv);
536 dv3 = (fixed)(((v1 - v0) << FIXED_BITS) / fdiv);
540 dx4 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) / (float)(y2 - y0)) : 0;
542 #else // Integer Division:
543 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
544 if ((y1 - y0) != 0) {
546 xInv((y1 - y0), iF, iS);
547 dx3 = xInvMulx((x1 - x0), iF, iS);
548 du3 = xInvMulx((u1 - u0), iF, iS);
549 dv3 = xInvMulx((v1 - v0), iF, iS);
553 dx4 = ((y2 - y0) != 0) ? xLoDivx((x2 - x0), (y2 - y0)) : 0;
555 if ((y1 - y0) != 0) {
556 dx3 = GPU_FAST_DIV((x1 - x0) << FIXED_BITS, (y1 - y0));
557 du3 = GPU_FAST_DIV((u1 - u0) << FIXED_BITS, (y1 - y0));
558 dv3 = GPU_FAST_DIV((v1 - v0) << FIXED_BITS, (y1 - y0));
562 dx4 = ((y2 - y0) != 0) ? GPU_FAST_DIV((x2 - x0) << FIXED_BITS, (y2 - y0)) : 0;
567 //senquack - break out of final loop if nothing to be drawn (1st loop
568 // must always be taken to setup dx3/dx4)
578 if ((y1 - y0) != 0) {
579 x3 += (dx3 * (y1 - y0));
580 u3 += (du3 * (y1 - y0));
581 v3 += (dv3 * (y1 - y0));
583 #ifdef GPU_UNAI_USE_FLOATMATH
584 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
585 dx4 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) * FloatInv(y2 - y1)) : 0;
587 dx4 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) / (float)(y2 - y1)) : 0;
589 #else // Integer Division:
590 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
591 dx4 = ((y2 - y1) != 0) ? xLoDivx((x2 - x1), (y2 - y1)) : 0;
593 dx4 = ((y2 - y1) != 0) ? GPU_FAST_DIV((x2 - x1) << FIXED_BITS, (y2 - y1)) : 0;
598 x4 = i2x(x0) + (dx4 * (y1 - y0));
601 #ifdef GPU_UNAI_USE_FLOATMATH
602 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
603 if ((y2 - y1) != 0) {
604 float finv = FloatInv(y2 - y1);
605 dx3 = (fixed)(((x2 - x1) << FIXED_BITS) * finv);
606 du3 = (fixed)(((u2 - u1) << FIXED_BITS) * finv);
607 dv3 = (fixed)(((v2 - v1) << FIXED_BITS) * finv);
612 if ((y2 - y1) != 0) {
613 float fdiv = y2 - y1;
614 dx3 = (fixed)(((x2 - x1) << FIXED_BITS) / fdiv);
615 du3 = (fixed)(((u2 - u1) << FIXED_BITS) / fdiv);
616 dv3 = (fixed)(((v2 - v1) << FIXED_BITS) / fdiv);
621 #else // Integer Division:
622 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
623 if ((y2 - y1) != 0) {
625 xInv((y2 - y1), iF, iS);
626 dx3 = xInvMulx((x2 - x1), iF, iS);
627 du3 = xInvMulx((u2 - u1), iF, iS);
628 dv3 = xInvMulx((v2 - v1), iF, iS);
633 if ((y2 - y1) != 0) {
634 dx3 = GPU_FAST_DIV((x2 - x1) << FIXED_BITS, (y2 - y1));
635 du3 = GPU_FAST_DIV((u2 - u1) << FIXED_BITS, (y2 - y1));
636 dv3 = GPU_FAST_DIV((v2 - v1) << FIXED_BITS, (y2 - y1));
645 s32 xmin, xmax, ymin, ymax;
646 xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2];
647 ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3];
649 if ((ymin - ya) > 0) {
650 x3 += dx3 * (ymin - ya);
651 x4 += dx4 * (ymin - ya);
652 u3 += du3 * (ymin - ya);
653 v3 += dv3 * (ymin - ya);
657 if (yb > ymax) yb = ymax;
663 le16_t* PixelBase = &gpu_unai.vram[FRAME_OFFSET(0, ya)];
664 int li=gpu_unai.ilace_mask;
665 int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0);
666 int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1);
668 for (; loop1; --loop1, ++ya, PixelBase += FRAME_WIDTH,
669 x3 += dx3, x4 += dx4,
670 u3 += du3, v3 += dv3 )
673 if ((ya&pi)==pif) continue;
677 xa = FixedCeilToInt(x3); xb = FixedCeilToInt(x4);
680 fixed itmp = i2x(xa) - x3;
682 u4 += (du4 * itmp) >> FIXED_BITS;
683 v4 += (dv4 * itmp) >> FIXED_BITS;
689 if ((xmin - xa) > 0) {
690 u4 += du4 * (xmin - xa);
691 v4 += dv4 * (xmin - xa);
695 // Set u,v coords for inner driver
699 if (xb > xmax) xb = xmax;
701 gpuPolySpanDriver(gpu_unai, PixelBase + xa, (xb - xa));
704 } while (++cur_pass < total_passes);
707 /*----------------------------------------------------------------------
708 gpuDrawPolyG - Gouraud-shaded, untextured poly
709 ----------------------------------------------------------------------*/
710 void gpuDrawPolyG(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad)
713 polyInitVertexBuffer(vbuf, packet, POLYTYPE_G, is_quad);
715 int total_passes = is_quad ? 2 : 1;
719 const PolyVertex* vptrs[3];
720 if (polyUseTriangle(vbuf, cur_pass, vptrs) == false)
724 s32 x3, dx3, x4, dx4, dx;
725 s32 r3, dr3, g3, dg3, b3, db3;
726 s32 x0, x1, x2, y0, y1, y2;
727 s32 r0, r1, r2, g0, g1, g2, b0, b1, b2;
730 x0 = vptrs[0]->x; y0 = vptrs[0]->y;
731 r0 = vptrs[0]->col.r; g0 = vptrs[0]->col.g; b0 = vptrs[0]->col.b;
732 x1 = vptrs[1]->x; y1 = vptrs[1]->y;
733 r1 = vptrs[1]->col.r; g1 = vptrs[1]->col.g; b1 = vptrs[1]->col.b;
734 x2 = vptrs[2]->x; y2 = vptrs[2]->y;
735 r2 = vptrs[2]->col.r; g2 = vptrs[2]->col.g; b2 = vptrs[2]->col.b;
739 dx4 = (x2 - x1) * ya - (x2 - x0) * yb;
740 dr4 = (r2 - r1) * ya - (r2 - r0) * yb;
741 dg4 = (g2 - g1) * ya - (g2 - g0) * yb;
742 db4 = (b2 - b1) * ya - (b2 - b0) * yb;
751 #ifdef GPU_UNAI_USE_FLOATMATH
752 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
754 float finv = FloatInv(dx4);
755 dr4 = (fixed)((dr4 << FIXED_BITS) * finv);
756 dg4 = (fixed)((dg4 << FIXED_BITS) * finv);
757 db4 = (fixed)((db4 << FIXED_BITS) * finv);
764 dr4 = (fixed)((dr4 << FIXED_BITS) / fdiv);
765 dg4 = (fixed)((dg4 << FIXED_BITS) / fdiv);
766 db4 = (fixed)((db4 << FIXED_BITS) / fdiv);
771 #else // Integer Division:
772 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
776 dr4 = xInvMulx(dr4, iF, iS);
777 dg4 = xInvMulx(dg4, iF, iS);
778 db4 = xInvMulx(db4, iF, iS);
784 dr4 = GPU_FAST_DIV(dr4 << FIXED_BITS, dx4);
785 dg4 = GPU_FAST_DIV(dg4 << FIXED_BITS, dx4);
786 db4 = GPU_FAST_DIV(db4 << FIXED_BITS, dx4);
792 // Setup packed Gouraud increment for inner driver
793 gpu_unai.gInc = gpuPackGouraudColInc(dr4, dg4, db4);
795 for (s32 loop0 = 2; loop0; loop0--) {
804 #ifdef GPU_UNAI_USE_FLOATMATH
805 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
806 if ((y2 - y0) != 0) {
807 float finv = FloatInv(y2 - y0);
808 dx3 = (fixed)(((x2 - x0) << FIXED_BITS) * finv);
809 dr3 = (fixed)(((r2 - r0) << FIXED_BITS) * finv);
810 dg3 = (fixed)(((g2 - g0) << FIXED_BITS) * finv);
811 db3 = (fixed)(((b2 - b0) << FIXED_BITS) * finv);
813 dx3 = dr3 = dg3 = db3 = 0;
815 dx4 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) * FloatInv(y1 - y0)) : 0;
817 if ((y2 - y0) != 0) {
818 float fdiv = y2 - y0;
819 dx3 = (fixed)(((x2 - x0) << FIXED_BITS) / fdiv);
820 dr3 = (fixed)(((r2 - r0) << FIXED_BITS) / fdiv);
821 dg3 = (fixed)(((g2 - g0) << FIXED_BITS) / fdiv);
822 db3 = (fixed)(((b2 - b0) << FIXED_BITS) / fdiv);
824 dx3 = dr3 = dg3 = db3 = 0;
826 dx4 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) / (float)(y1 - y0)) : 0;
828 #else // Integer Division:
829 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
830 if ((y2 - y0) != 0) {
832 xInv((y2 - y0), iF, iS);
833 dx3 = xInvMulx((x2 - x0), iF, iS);
834 dr3 = xInvMulx((r2 - r0), iF, iS);
835 dg3 = xInvMulx((g2 - g0), iF, iS);
836 db3 = xInvMulx((b2 - b0), iF, iS);
838 dx3 = dr3 = dg3 = db3 = 0;
840 dx4 = ((y1 - y0) != 0) ? xLoDivx((x1 - x0), (y1 - y0)) : 0;
842 if ((y2 - y0) != 0) {
843 dx3 = GPU_FAST_DIV((x2 - x0) << FIXED_BITS, (y2 - y0));
844 dr3 = GPU_FAST_DIV((r2 - r0) << FIXED_BITS, (y2 - y0));
845 dg3 = GPU_FAST_DIV((g2 - g0) << FIXED_BITS, (y2 - y0));
846 db3 = GPU_FAST_DIV((b2 - b0) << FIXED_BITS, (y2 - y0));
848 dx3 = dr3 = dg3 = db3 = 0;
850 dx4 = ((y1 - y0) != 0) ? GPU_FAST_DIV((x1 - x0) << FIXED_BITS, (y1 - y0)) : 0;
854 #ifdef GPU_UNAI_USE_FLOATMATH
855 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
856 if ((y1 - y0) != 0) {
857 float finv = FloatInv(y1 - y0);
858 dx3 = (fixed)(((x1 - x0) << FIXED_BITS) * finv);
859 dr3 = (fixed)(((r1 - r0) << FIXED_BITS) * finv);
860 dg3 = (fixed)(((g1 - g0) << FIXED_BITS) * finv);
861 db3 = (fixed)(((b1 - b0) << FIXED_BITS) * finv);
863 dx3 = dr3 = dg3 = db3 = 0;
865 dx4 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) * FloatInv(y2 - y0)) : 0;
867 if ((y1 - y0) != 0) {
868 float fdiv = y1 - y0;
869 dx3 = (fixed)(((x1 - x0) << FIXED_BITS) / fdiv);
870 dr3 = (fixed)(((r1 - r0) << FIXED_BITS) / fdiv);
871 dg3 = (fixed)(((g1 - g0) << FIXED_BITS) / fdiv);
872 db3 = (fixed)(((b1 - b0) << FIXED_BITS) / fdiv);
874 dx3 = dr3 = dg3 = db3 = 0;
876 dx4 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) / (float)(y2 - y0)) : 0;
878 #else // Integer Division:
879 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
880 if ((y1 - y0) != 0) {
882 xInv((y1 - y0), iF, iS);
883 dx3 = xInvMulx((x1 - x0), iF, iS);
884 dr3 = xInvMulx((r1 - r0), iF, iS);
885 dg3 = xInvMulx((g1 - g0), iF, iS);
886 db3 = xInvMulx((b1 - b0), iF, iS);
888 dx3 = dr3 = dg3 = db3 = 0;
890 dx4 = ((y2 - y0) != 0) ? xLoDivx((x2 - x0), (y2 - y0)) : 0;
892 if ((y1 - y0) != 0) {
893 dx3 = GPU_FAST_DIV((x1 - x0) << FIXED_BITS, (y1 - y0));
894 dr3 = GPU_FAST_DIV((r1 - r0) << FIXED_BITS, (y1 - y0));
895 dg3 = GPU_FAST_DIV((g1 - g0) << FIXED_BITS, (y1 - y0));
896 db3 = GPU_FAST_DIV((b1 - b0) << FIXED_BITS, (y1 - y0));
898 dx3 = dr3 = dg3 = db3 = 0;
900 dx4 = ((y2 - y0) != 0) ? GPU_FAST_DIV((x2 - x0) << FIXED_BITS, (y2 - y0)) : 0;
905 //senquack - break out of final loop if nothing to be drawn (1st loop
906 // must always be taken to setup dx3/dx4)
912 x3 = i2x(x0); x4 = i2x(x1);
913 r3 = i2x(r0); g3 = i2x(g0); b3 = i2x(b0);
915 if ((y1 - y0) != 0) {
916 x3 += (dx3 * (y1 - y0));
917 r3 += (dr3 * (y1 - y0));
918 g3 += (dg3 * (y1 - y0));
919 b3 += (db3 * (y1 - y0));
922 #ifdef GPU_UNAI_USE_FLOATMATH
923 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
924 dx4 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) * FloatInv(y2 - y1)) : 0;
926 dx4 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) / (float)(y2 - y1)) : 0;
928 #else // Integer Division:
929 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
930 dx4 = ((y2 - y1) != 0) ? xLoDivx((x2 - x1), (y2 - y1)) : 0;
932 dx4 = ((y2 - y1) != 0) ? GPU_FAST_DIV((x2 - x1) << FIXED_BITS, (y2 - y1)) : 0;
937 x4 = i2x(x0) + (dx4 * (y1 - y0));
939 r3 = i2x(r1); g3 = i2x(g1); b3 = i2x(b1);
941 #ifdef GPU_UNAI_USE_FLOATMATH
942 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
943 if ((y2 - y1) != 0) {
944 float finv = FloatInv(y2 - y1);
945 dx3 = (fixed)(((x2 - x1) << FIXED_BITS) * finv);
946 dr3 = (fixed)(((r2 - r1) << FIXED_BITS) * finv);
947 dg3 = (fixed)(((g2 - g1) << FIXED_BITS) * finv);
948 db3 = (fixed)(((b2 - b1) << FIXED_BITS) * finv);
950 dx3 = dr3 = dg3 = db3 = 0;
953 if ((y2 - y1) != 0) {
954 float fdiv = y2 - y1;
955 dx3 = (fixed)(((x2 - x1) << FIXED_BITS) / fdiv);
956 dr3 = (fixed)(((r2 - r1) << FIXED_BITS) / fdiv);
957 dg3 = (fixed)(((g2 - g1) << FIXED_BITS) / fdiv);
958 db3 = (fixed)(((b2 - b1) << FIXED_BITS) / fdiv);
960 dx3 = dr3 = dg3 = db3 = 0;
963 #else // Integer Division:
964 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
965 if ((y2 - y1) != 0) {
967 xInv((y2 - y1), iF, iS);
968 dx3 = xInvMulx((x2 - x1), iF, iS);
969 dr3 = xInvMulx((r2 - r1), iF, iS);
970 dg3 = xInvMulx((g2 - g1), iF, iS);
971 db3 = xInvMulx((b2 - b1), iF, iS);
973 dx3 = dr3 = dg3 = db3 = 0;
976 if ((y2 - y1) != 0) {
977 dx3 = GPU_FAST_DIV((x2 - x1) << FIXED_BITS, (y2 - y1));
978 dr3 = GPU_FAST_DIV((r2 - r1) << FIXED_BITS, (y2 - y1));
979 dg3 = GPU_FAST_DIV((g2 - g1) << FIXED_BITS, (y2 - y1));
980 db3 = GPU_FAST_DIV((b2 - b1) << FIXED_BITS, (y2 - y1));
982 dx3 = dr3 = dg3 = db3 = 0;
989 s32 xmin, xmax, ymin, ymax;
990 xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2];
991 ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3];
993 if ((ymin - ya) > 0) {
994 x3 += (dx3 * (ymin - ya));
995 x4 += (dx4 * (ymin - ya));
996 r3 += (dr3 * (ymin - ya));
997 g3 += (dg3 * (ymin - ya));
998 b3 += (db3 * (ymin - ya));
1002 if (yb > ymax) yb = ymax;
1004 int loop1 = yb - ya;
1008 le16_t* PixelBase = &gpu_unai.vram[FRAME_OFFSET(0, ya)];
1009 int li=gpu_unai.ilace_mask;
1010 int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0);
1011 int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1);
1013 for (; loop1; --loop1, ++ya, PixelBase += FRAME_WIDTH,
1014 x3 += dx3, x4 += dx4,
1015 r3 += dr3, g3 += dg3, b3 += db3 )
1017 if (ya&li) continue;
1018 if ((ya&pi)==pif) continue;
1022 xa = FixedCeilToInt(x3);
1023 xb = FixedCeilToInt(x4);
1024 r4 = r3; g4 = g3; b4 = b3;
1026 fixed itmp = i2x(xa) - x3;
1028 r4 += (dr4 * itmp) >> FIXED_BITS;
1029 g4 += (dg4 * itmp) >> FIXED_BITS;
1030 b4 += (db4 * itmp) >> FIXED_BITS;
1037 if ((xmin - xa) > 0) {
1038 r4 += (dr4 * (xmin - xa));
1039 g4 += (dg4 * (xmin - xa));
1040 b4 += (db4 * (xmin - xa));
1044 // Setup packed Gouraud color for inner driver
1045 gpu_unai.gCol = gpuPackGouraudCol(r4, g4, b4);
1047 if (xb > xmax) xb = xmax;
1049 gpuPolySpanDriver(gpu_unai, PixelBase + xa, (xb - xa));
1052 } while (++cur_pass < total_passes);
1055 /*----------------------------------------------------------------------
1056 gpuDrawPolyGT - Gouraud-shaded, textured poly
1057 ----------------------------------------------------------------------*/
1058 void gpuDrawPolyGT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad)
1061 polyInitVertexBuffer(vbuf, packet, POLYTYPE_GT, is_quad);
1063 int total_passes = is_quad ? 2 : 1;
1067 const PolyVertex* vptrs[3];
1068 if (polyUseTriangle(vbuf, cur_pass, vptrs) == false)
1072 s32 x3, dx3, x4, dx4, dx;
1073 s32 u3, du3, v3, dv3;
1074 s32 r3, dr3, g3, dg3, b3, db3;
1075 s32 x0, x1, x2, y0, y1, y2;
1076 s32 u0, u1, u2, v0, v1, v2;
1077 s32 r0, r1, r2, g0, g1, g2, b0, b1, b2;
1081 x0 = vptrs[0]->x; y0 = vptrs[0]->y;
1082 u0 = vptrs[0]->tex.u; v0 = vptrs[0]->tex.v;
1083 r0 = vptrs[0]->col.r; g0 = vptrs[0]->col.g; b0 = vptrs[0]->col.b;
1084 x1 = vptrs[1]->x; y1 = vptrs[1]->y;
1085 u1 = vptrs[1]->tex.u; v1 = vptrs[1]->tex.v;
1086 r1 = vptrs[1]->col.r; g1 = vptrs[1]->col.g; b1 = vptrs[1]->col.b;
1087 x2 = vptrs[2]->x; y2 = vptrs[2]->y;
1088 u2 = vptrs[2]->tex.u; v2 = vptrs[2]->tex.v;
1089 r2 = vptrs[2]->col.r; g2 = vptrs[2]->col.g; b2 = vptrs[2]->col.b;
1093 dx4 = (x2 - x1) * ya - (x2 - x0) * yb;
1094 du4 = (u2 - u1) * ya - (u2 - u0) * yb;
1095 dv4 = (v2 - v1) * ya - (v2 - v0) * yb;
1096 dr4 = (r2 - r1) * ya - (r2 - r0) * yb;
1097 dg4 = (g2 - g1) * ya - (g2 - g0) * yb;
1098 db4 = (b2 - b1) * ya - (b2 - b0) * yb;
1109 #ifdef GPU_UNAI_USE_FLOATMATH
1110 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
1112 float finv = FloatInv(dx4);
1113 du4 = (fixed)((du4 << FIXED_BITS) * finv);
1114 dv4 = (fixed)((dv4 << FIXED_BITS) * finv);
1115 dr4 = (fixed)((dr4 << FIXED_BITS) * finv);
1116 dg4 = (fixed)((dg4 << FIXED_BITS) * finv);
1117 db4 = (fixed)((db4 << FIXED_BITS) * finv);
1119 du4 = dv4 = dr4 = dg4 = db4 = 0;
1124 du4 = (fixed)((du4 << FIXED_BITS) / fdiv);
1125 dv4 = (fixed)((dv4 << FIXED_BITS) / fdiv);
1126 dr4 = (fixed)((dr4 << FIXED_BITS) / fdiv);
1127 dg4 = (fixed)((dg4 << FIXED_BITS) / fdiv);
1128 db4 = (fixed)((db4 << FIXED_BITS) / fdiv);
1130 du4 = dv4 = dr4 = dg4 = db4 = 0;
1133 #else // Integer Division:
1134 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
1138 du4 = xInvMulx(du4, iF, iS);
1139 dv4 = xInvMulx(dv4, iF, iS);
1140 dr4 = xInvMulx(dr4, iF, iS);
1141 dg4 = xInvMulx(dg4, iF, iS);
1142 db4 = xInvMulx(db4, iF, iS);
1144 du4 = dv4 = dr4 = dg4 = db4 = 0;
1148 du4 = GPU_FAST_DIV(du4 << FIXED_BITS, dx4);
1149 dv4 = GPU_FAST_DIV(dv4 << FIXED_BITS, dx4);
1150 dr4 = GPU_FAST_DIV(dr4 << FIXED_BITS, dx4);
1151 dg4 = GPU_FAST_DIV(dg4 << FIXED_BITS, dx4);
1152 db4 = GPU_FAST_DIV(db4 << FIXED_BITS, dx4);
1154 du4 = dv4 = dr4 = dg4 = db4 = 0;
1158 // Set u,v increments and packed Gouraud increment for inner driver
1159 gpu_unai.u_inc = du4;
1160 gpu_unai.v_inc = dv4;
1161 gpu_unai.gInc = gpuPackGouraudColInc(dr4, dg4, db4);
1163 for (s32 loop0 = 2; loop0; loop0--) {
1167 u3 = i2x(u0); v3 = i2x(v0);
1168 r3 = i2x(r0); g3 = i2x(g0); b3 = i2x(b0);
1170 #ifdef GPU_UNAI_USE_FLOATMATH
1171 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
1172 if ((y2 - y0) != 0) {
1173 float finv = FloatInv(y2 - y0);
1174 dx3 = (fixed)(((x2 - x0) << FIXED_BITS) * finv);
1175 du3 = (fixed)(((u2 - u0) << FIXED_BITS) * finv);
1176 dv3 = (fixed)(((v2 - v0) << FIXED_BITS) * finv);
1177 dr3 = (fixed)(((r2 - r0) << FIXED_BITS) * finv);
1178 dg3 = (fixed)(((g2 - g0) << FIXED_BITS) * finv);
1179 db3 = (fixed)(((b2 - b0) << FIXED_BITS) * finv);
1181 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1183 dx4 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) * FloatInv(y1 - y0)) : 0;
1185 if ((y2 - y0) != 0) {
1186 float fdiv = y2 - y0;
1187 dx3 = (fixed)(((x2 - x0) << FIXED_BITS) / fdiv);
1188 du3 = (fixed)(((u2 - u0) << FIXED_BITS) / fdiv);
1189 dv3 = (fixed)(((v2 - v0) << FIXED_BITS) / fdiv);
1190 dr3 = (fixed)(((r2 - r0) << FIXED_BITS) / fdiv);
1191 dg3 = (fixed)(((g2 - g0) << FIXED_BITS) / fdiv);
1192 db3 = (fixed)(((b2 - b0) << FIXED_BITS) / fdiv);
1194 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1196 dx4 = ((y1 - y0) != 0) ? (fixed)(((x1 - x0) << FIXED_BITS) / (float)(y1 - y0)) : 0;
1198 #else // Integer Division:
1199 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
1200 if ((y2 - y0) != 0) {
1202 xInv((y2 - y0), iF, iS);
1203 dx3 = xInvMulx((x2 - x0), iF, iS);
1204 du3 = xInvMulx((u2 - u0), iF, iS);
1205 dv3 = xInvMulx((v2 - v0), iF, iS);
1206 dr3 = xInvMulx((r2 - r0), iF, iS);
1207 dg3 = xInvMulx((g2 - g0), iF, iS);
1208 db3 = xInvMulx((b2 - b0), iF, iS);
1210 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1212 dx4 = ((y1 - y0) != 0) ? xLoDivx((x1 - x0), (y1 - y0)) : 0;
1214 if ((y2 - y0) != 0) {
1215 dx3 = GPU_FAST_DIV((x2 - x0) << FIXED_BITS, (y2 - y0));
1216 du3 = GPU_FAST_DIV((u2 - u0) << FIXED_BITS, (y2 - y0));
1217 dv3 = GPU_FAST_DIV((v2 - v0) << FIXED_BITS, (y2 - y0));
1218 dr3 = GPU_FAST_DIV((r2 - r0) << FIXED_BITS, (y2 - y0));
1219 dg3 = GPU_FAST_DIV((g2 - g0) << FIXED_BITS, (y2 - y0));
1220 db3 = GPU_FAST_DIV((b2 - b0) << FIXED_BITS, (y2 - y0));
1222 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1224 dx4 = ((y1 - y0) != 0) ? GPU_FAST_DIV((x1 - x0) << FIXED_BITS, (y1 - y0)) : 0;
1228 #ifdef GPU_UNAI_USE_FLOATMATH
1229 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
1230 if ((y1 - y0) != 0) {
1231 float finv = FloatInv(y1 - y0);
1232 dx3 = (fixed)(((x1 - x0) << FIXED_BITS) * finv);
1233 du3 = (fixed)(((u1 - u0) << FIXED_BITS) * finv);
1234 dv3 = (fixed)(((v1 - v0) << FIXED_BITS) * finv);
1235 dr3 = (fixed)(((r1 - r0) << FIXED_BITS) * finv);
1236 dg3 = (fixed)(((g1 - g0) << FIXED_BITS) * finv);
1237 db3 = (fixed)(((b1 - b0) << FIXED_BITS) * finv);
1239 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1241 dx4 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) * FloatInv(y2 - y0)) : 0;
1243 if ((y1 - y0) != 0) {
1244 float fdiv = y1 - y0;
1245 dx3 = (fixed)(((x1 - x0) << FIXED_BITS) / fdiv);
1246 du3 = (fixed)(((u1 - u0) << FIXED_BITS) / fdiv);
1247 dv3 = (fixed)(((v1 - v0) << FIXED_BITS) / fdiv);
1248 dr3 = (fixed)(((r1 - r0) << FIXED_BITS) / fdiv);
1249 dg3 = (fixed)(((g1 - g0) << FIXED_BITS) / fdiv);
1250 db3 = (fixed)(((b1 - b0) << FIXED_BITS) / fdiv);
1252 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1254 dx4 = ((y2 - y0) != 0) ? (fixed)(((x2 - x0) << FIXED_BITS) / float(y2 - y0)) : 0;
1256 #else // Integer Division:
1257 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
1258 if ((y1 - y0) != 0) {
1260 xInv((y1 - y0), iF, iS);
1261 dx3 = xInvMulx((x1 - x0), iF, iS);
1262 du3 = xInvMulx((u1 - u0), iF, iS);
1263 dv3 = xInvMulx((v1 - v0), iF, iS);
1264 dr3 = xInvMulx((r1 - r0), iF, iS);
1265 dg3 = xInvMulx((g1 - g0), iF, iS);
1266 db3 = xInvMulx((b1 - b0), iF, iS);
1268 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1270 dx4 = ((y2 - y0) != 0) ? xLoDivx((x2 - x0), (y2 - y0)) : 0;
1272 if ((y1 - y0) != 0) {
1273 dx3 = GPU_FAST_DIV((x1 - x0) << FIXED_BITS, (y1 - y0));
1274 du3 = GPU_FAST_DIV((u1 - u0) << FIXED_BITS, (y1 - y0));
1275 dv3 = GPU_FAST_DIV((v1 - v0) << FIXED_BITS, (y1 - y0));
1276 dr3 = GPU_FAST_DIV((r1 - r0) << FIXED_BITS, (y1 - y0));
1277 dg3 = GPU_FAST_DIV((g1 - g0) << FIXED_BITS, (y1 - y0));
1278 db3 = GPU_FAST_DIV((b1 - b0) << FIXED_BITS, (y1 - y0));
1280 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1282 dx4 = ((y2 - y0) != 0) ? GPU_FAST_DIV((x2 - x0) << FIXED_BITS, (y2 - y0)) : 0;
1287 //senquack - break out of final loop if nothing to be drawn (1st loop
1288 // must always be taken to setup dx3/dx4)
1289 if (y1 == y2) break;
1294 x3 = i2x(x0); x4 = i2x(x1);
1295 u3 = i2x(u0); v3 = i2x(v0);
1296 r3 = i2x(r0); g3 = i2x(g0); b3 = i2x(b0);
1298 if ((y1 - y0) != 0) {
1299 x3 += (dx3 * (y1 - y0));
1300 u3 += (du3 * (y1 - y0));
1301 v3 += (dv3 * (y1 - y0));
1302 r3 += (dr3 * (y1 - y0));
1303 g3 += (dg3 * (y1 - y0));
1304 b3 += (db3 * (y1 - y0));
1307 #ifdef GPU_UNAI_USE_FLOATMATH
1308 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
1309 dx4 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) * FloatInv(y2 - y1)) : 0;
1311 dx4 = ((y2 - y1) != 0) ? (fixed)(((x2 - x1) << FIXED_BITS) / (float)(y2 - y1)) : 0;
1313 #else // Integer Division:
1314 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
1315 dx4 = ((y2 - y1) != 0) ? xLoDivx((x2 - x1), (y2 - y1)) : 0;
1317 dx4 = ((y2 - y1) != 0) ? GPU_FAST_DIV((x2 - x1) << FIXED_BITS, (y2 - y1)) : 0;
1322 x4 = i2x(x0) + (dx4 * (y1 - y0));
1324 u3 = i2x(u1); v3 = i2x(v1);
1325 r3 = i2x(r1); g3 = i2x(g1); b3 = i2x(b1);
1326 #ifdef GPU_UNAI_USE_FLOATMATH
1327 #ifdef GPU_UNAI_USE_FLOAT_DIV_MULTINV
1328 if ((y2 - y1) != 0) {
1329 float finv = FloatInv(y2 - y1);
1330 dx3 = (fixed)(((x2 - x1) << FIXED_BITS) * finv);
1331 du3 = (fixed)(((u2 - u1) << FIXED_BITS) * finv);
1332 dv3 = (fixed)(((v2 - v1) << FIXED_BITS) * finv);
1333 dr3 = (fixed)(((r2 - r1) << FIXED_BITS) * finv);
1334 dg3 = (fixed)(((g2 - g1) << FIXED_BITS) * finv);
1335 db3 = (fixed)(((b2 - b1) << FIXED_BITS) * finv);
1337 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1340 if ((y2 - y1) != 0) {
1341 float fdiv = y2 - y1;
1342 dx3 = (fixed)(((x2 - x1) << FIXED_BITS) / fdiv);
1343 du3 = (fixed)(((u2 - u1) << FIXED_BITS) / fdiv);
1344 dv3 = (fixed)(((v2 - v1) << FIXED_BITS) / fdiv);
1345 dr3 = (fixed)(((r2 - r1) << FIXED_BITS) / fdiv);
1346 dg3 = (fixed)(((g2 - g1) << FIXED_BITS) / fdiv);
1347 db3 = (fixed)(((b2 - b1) << FIXED_BITS) / fdiv);
1349 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1352 #else // Integer Division:
1353 #ifdef GPU_UNAI_USE_INT_DIV_MULTINV
1354 if ((y2 - y1) != 0) {
1356 xInv((y2 - y1), iF, iS);
1357 dx3 = xInvMulx((x2 - x1), iF, iS);
1358 du3 = xInvMulx((u2 - u1), iF, iS);
1359 dv3 = xInvMulx((v2 - v1), iF, iS);
1360 dr3 = xInvMulx((r2 - r1), iF, iS);
1361 dg3 = xInvMulx((g2 - g1), iF, iS);
1362 db3 = xInvMulx((b2 - b1), iF, iS);
1364 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1367 if ((y2 - y1) != 0) {
1368 dx3 = GPU_FAST_DIV((x2 - x1) << FIXED_BITS, (y2 - y1));
1369 du3 = GPU_FAST_DIV((u2 - u1) << FIXED_BITS, (y2 - y1));
1370 dv3 = GPU_FAST_DIV((v2 - v1) << FIXED_BITS, (y2 - y1));
1371 dr3 = GPU_FAST_DIV((r2 - r1) << FIXED_BITS, (y2 - y1));
1372 dg3 = GPU_FAST_DIV((g2 - g1) << FIXED_BITS, (y2 - y1));
1373 db3 = GPU_FAST_DIV((b2 - b1) << FIXED_BITS, (y2 - y1));
1375 dx3 = du3 = dv3 = dr3 = dg3 = db3 = 0;
1382 s32 xmin, xmax, ymin, ymax;
1383 xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2];
1384 ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3];
1386 if ((ymin - ya) > 0) {
1387 x3 += (dx3 * (ymin - ya));
1388 x4 += (dx4 * (ymin - ya));
1389 u3 += (du3 * (ymin - ya));
1390 v3 += (dv3 * (ymin - ya));
1391 r3 += (dr3 * (ymin - ya));
1392 g3 += (dg3 * (ymin - ya));
1393 b3 += (db3 * (ymin - ya));
1397 if (yb > ymax) yb = ymax;
1399 int loop1 = yb - ya;
1403 le16_t* PixelBase = &gpu_unai.vram[FRAME_OFFSET(0, ya)];
1404 int li=gpu_unai.ilace_mask;
1405 int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0);
1406 int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1);
1408 for (; loop1; --loop1, ++ya, PixelBase += FRAME_WIDTH,
1409 x3 += dx3, x4 += dx4,
1410 u3 += du3, v3 += dv3,
1411 r3 += dr3, g3 += dg3, b3 += db3 )
1413 if (ya&li) continue;
1414 if ((ya&pi)==pif) continue;
1419 xa = FixedCeilToInt(x3);
1420 xb = FixedCeilToInt(x4);
1422 r4 = r3; g4 = g3; b4 = b3;
1424 fixed itmp = i2x(xa) - x3;
1426 u4 += (du4 * itmp) >> FIXED_BITS;
1427 v4 += (dv4 * itmp) >> FIXED_BITS;
1428 r4 += (dr4 * itmp) >> FIXED_BITS;
1429 g4 += (dg4 * itmp) >> FIXED_BITS;
1430 b4 += (db4 * itmp) >> FIXED_BITS;
1439 if ((xmin - xa) > 0) {
1440 u4 += du4 * (xmin - xa);
1441 v4 += dv4 * (xmin - xa);
1442 r4 += dr4 * (xmin - xa);
1443 g4 += dg4 * (xmin - xa);
1444 b4 += db4 * (xmin - xa);
1448 // Set packed Gouraud color and u,v coords for inner driver
1451 gpu_unai.gCol = gpuPackGouraudCol(r4, g4, b4);
1453 if (xb > xmax) xb = xmax;
1455 gpuPolySpanDriver(gpu_unai, PixelBase + xa, (xb - xa));
1458 } while (++cur_pass < total_passes);
1461 #endif /* __GPU_UNAI_GPU_RASTER_POLYGON_H__ */