1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-21 20:39:57 +01:00
This commit is contained in:
Miloslav Číž 2019-06-11 12:03:19 +02:00
parent 6e6bdf0c77
commit 4c042bd5fa

View file

@ -145,8 +145,6 @@ BE REDEFINED, so rather don't do it (otherwise things may overflow etc.). */
#define S3L_FRACTIONS_PER_UNIT 512
#define S3L_UNIT_MINUS_ONE (S3L_FRACTIONS_PER_UNIT - 1)
typedef int16_t S3L_ScreenCoord;
typedef uint16_t S3L_Index;
@ -449,9 +447,10 @@ typedef struct
vertices. These serve to locate the pixel on a
triangle and interpolate values between it's
three points. Each one goes from 0 to
S3L_UNIT_MINUS_ONE (inclidung) and the sum of the
three coordinates will always be exactly
S3L_UNIT_MINUS_ONE. */
S3L_FRACTIONS_PER_UNIT (inclidung), but due to
rounding error may fall outside this range. The
sum of the three coordinates will always be
exactly S3L_FRACTIONS_PER_UNIT. */
S3L_Index triangleIndex; ///< Triangle index.
S3L_Index modelIndex;
S3L_Unit depth; ///< Depth (only if depth is turned on).
@ -1655,9 +1654,9 @@ void S3L_drawTriangle(
#if S3L_FLAT
p.depth = (tPointPP->z + lPointPP->z + rPointPP->z) / 3;
*barycentric0 = S3L_UNIT_MINUS_ONE / 3;
*barycentric1 = S3L_UNIT_MINUS_ONE / 3;
*barycentric2 = S3L_UNIT_MINUS_ONE - 2 * (S3L_UNIT_MINUS_ONE / 3);
*barycentric0 = S3L_FRACTIONS_PER_UNIT / 3;
*barycentric1 = S3L_FRACTIONS_PER_UNIT / 3;
*barycentric2 = S3L_FRACTIONS_PER_UNIT - 2 * (S3L_FRACTIONS_PER_UNIT / 3);
#endif
p.triangleSize[0] = rPointSx - lPointSx;
@ -1739,12 +1738,12 @@ void S3L_drawTriangle(
s##Dx = p2##PointSx - p1##PointSx;\
s##Dy = p2##PointSy - p1##PointSy;\
initDepthFLS(s,p1,p2)\
s##SideFLS.stepScaled = (S3L_UNIT_MINUS_ONE << S3L_FAST_LERP_QUALITY)\
s##SideFLS.stepScaled = (S3L_FRACTIONS_PER_UNIT << S3L_FAST_LERP_QUALITY)\
/ (s##Dy != 0 ? s##Dy : 1);\
s##SideFLS.valueScaled = 0;\
if (!down)\
{\
s##SideFLS.valueScaled = S3L_UNIT_MINUS_ONE << S3L_FAST_LERP_QUALITY;\
s##SideFLS.valueScaled = S3L_FRACTIONS_PER_UNIT << S3L_FAST_LERP_QUALITY;\
s##SideFLS.stepScaled *= -1;\
}\
s##Inc = s##Dx >= 0 ? 1 : -1;\
@ -1819,7 +1818,7 @@ void S3L_drawTriangle(
S3L_Unit *tmp = barycentric##b0;\
barycentric##b0 = barycentric##b1;\
barycentric##b1 = tmp;\
s0##SideFLS.valueScaled = (S3L_UNIT_MINUS_ONE\
s0##SideFLS.valueScaled = (S3L_FRACTIONS_PER_UNIT\
<< S3L_FAST_LERP_QUALITY) - s0##SideFLS.valueScaled;\
s0##SideFLS.stepScaled *= -1;\
manageSplitPerspective(s0,s1)
@ -1926,7 +1925,7 @@ void S3L_drawTriangle(
S3L_FastLerpState depthPC, b0PC, b1PC;
depthPC.valueScaled =
((S3L_UNIT_MINUS_ONE * S3L_FRACTIONS_PER_UNIT) /
((S3L_FRACTIONS_PER_UNIT * S3L_FRACTIONS_PER_UNIT) /
S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,i,rowLength)))
<< S3L_FAST_LERP_QUALITY;
@ -1957,7 +1956,7 @@ void S3L_drawTriangle(
#if S3L_COMPUTE_DEPTH
#if S3L_PERSPECTIVE_CORRECTION == 1
p.depth = (S3L_UNIT_MINUS_ONE * S3L_FRACTIONS_PER_UNIT) /
p.depth = (S3L_FRACTIONS_PER_UNIT * S3L_FRACTIONS_PER_UNIT) /
S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,i,rowLength));
#elif S3L_PERSPECTIVE_CORRECTION == 2
if (rowCount >= S3L_PC_APPROX_LENGTH)
@ -1968,7 +1967,7 @@ void S3L_drawTriangle(
S3L_Unit nextDepth =
(
(S3L_UNIT_MINUS_ONE * S3L_FRACTIONS_PER_UNIT) /
(S3L_FRACTIONS_PER_UNIT * S3L_FRACTIONS_PER_UNIT) /
S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,nextI,rowLength))
) << S3L_FAST_LERP_QUALITY;
@ -2032,7 +2031,7 @@ void S3L_drawTriangle(
#endif
*barycentric2 =
S3L_UNIT_MINUS_ONE - *barycentric0 - *barycentric1;
S3L_FRACTIONS_PER_UNIT - *barycentric0 - *barycentric1;
#endif
S3L_PIXEL_FUNCTION(&p);
}