1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-24 21:09:57 +01:00

Fix nner loop bu

This commit is contained in:
Miloslav Číž 2019-06-02 23:13:49 +02:00
parent 668bb0a44c
commit cc2e1f08ef
2 changed files with 37 additions and 29 deletions

View file

@ -1519,7 +1519,7 @@ void S3L_drawTriangle(
} }
#if S3L_PERSPECTIVE_CORRECTION == 1 #if S3L_PERSPECTIVE_CORRECTION == 1
S3L_ScreenCoord i = lXClipped - lX - 1; /* helper var to save one S3L_ScreenCoord i = lXClipped - lX; /* helper var to save one
substraction in the inner substraction in the inner
loop */ loop */
#endif #endif
@ -1528,14 +1528,11 @@ void S3L_drawTriangle(
for (S3L_ScreenCoord x = lXClipped; x < rXClipped; ++x) for (S3L_ScreenCoord x = lXClipped; x < rXClipped; ++x)
{ {
#if S3L_PERSPECTIVE_CORRECTION == 1 int8_t testsPassed = 1;
++i; /* Has to be done here, because the following tests can skip the
the rest of the loop. */
#endif
#if S3L_STENCIL_BUFFER #if S3L_STENCIL_BUFFER
if (!S3L_stencilTest(x,p.y)) if (!S3L_stencilTest(x,p.y))
continue; testsPassed = 0;
#endif #endif
p.x = x; p.x = x;
@ -1551,36 +1548,47 @@ void S3L_drawTriangle(
#if S3L_Z_BUFFER #if S3L_Z_BUFFER
if (!S3L_zTest(p.x,p.y,p.depth)) if (!S3L_zTest(p.x,p.y,p.depth))
continue; testsPassed = 0;
#endif #endif
if (testsPassed)
{
#if !S3L_FLAT
#if S3L_PERSPECTIVE_CORRECTION == 1
*barycentric0 =
(
S3L_interpolateFrom0(rOverZ,i,rowLength)
* p.depth
) / S3L_FRACTIONS_PER_UNIT;
*barycentric1 =
(
(lOverZ - S3L_interpolateFrom0(lOverZ,i,rowLength))
* p.depth
) / S3L_FRACTIONS_PER_UNIT;
#else
*barycentric0 = S3L_getFastLerpValue(b0FLS);
*barycentric1 = S3L_getFastLerpValue(b1FLS);
#endif
*barycentric2 =
S3L_FRACTIONS_PER_UNIT - *barycentric0 - *barycentric1;
#endif
S3L_PIXEL_FUNCTION(&p);
}
#if !S3L_FLAT #if !S3L_FLAT
#if S3L_PERSPECTIVE_CORRECTION == 1 #if S3L_PERSPECTIVE_CORRECTION == 1
*barycentric0 = i++;
(
S3L_interpolateFrom0(rOverZ,i,rowLength)
* p.depth
) / S3L_FRACTIONS_PER_UNIT;
*barycentric1 =
(
(lOverZ - S3L_interpolateFrom0(lOverZ,i,rowLength))
* p.depth
) / S3L_FRACTIONS_PER_UNIT;
#else #else
*barycentric0 = S3L_getFastLerpValue(b0FLS); S3L_stepFastLerp(b0FLS);
*barycentric1 = S3L_getFastLerpValue(b1FLS); S3L_stepFastLerp(b1FLS);
S3L_stepFastLerp(b0FLS);
S3L_stepFastLerp(b1FLS);
#endif #endif
*barycentric2 = S3L_FRACTIONS_PER_UNIT - *barycentric0 - *barycentric1;
#endif #endif
S3L_PIXEL_FUNCTION(&p); } // inner loop
} } // y clipping
} // y clipping
S3L_stepFastLerp(lSideFLS); S3L_stepFastLerp(lSideFLS);
S3L_stepFastLerp(rSideFLS); S3L_stepFastLerp(rSideFLS);

View file

@ -12,7 +12,7 @@
#define S3L_FLAT 0 #define S3L_FLAT 0
#define S3L_STRICT_NEAR_CULLING 0 #define S3L_STRICT_NEAR_CULLING 0
#define S3L_PERSPECTIVE_CORRECTION 1 #define S3L_PERSPECTIVE_CORRECTION 0
#define S3L_SORT 0 #define S3L_SORT 0
#define S3L_Z_BUFFER 1 #define S3L_Z_BUFFER 1