1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-23 20:59:58 +01:00

Improve make

This commit is contained in:
Miloslav Číž 2020-06-17 18:12:58 +02:00
parent ac87859b29
commit 54a63abe24
3 changed files with 36 additions and 19 deletions

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
PROGRAM=helloTerminal PROGRAM=test
clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -O3 -Wall -Wextra -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -O3 -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wno-unused-parameter -Wno-missing-field-initializers -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM
#clear; clear; clang -x c -g -pedantic -O3 -Wall -Wextra -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM #clear; clear; clang -x c -g -pedantic -O3 -Wall -Wextra -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM

View file

@ -1,4 +1,4 @@
/* /**
Some basic tests for small3dlib. Some basic tests for small3dlib.
author: Miloslav Ciz author: Miloslav Ciz
@ -6,6 +6,8 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <math.h>
#define S3L_PIXEL_FUNCTION pixelFunc #define S3L_PIXEL_FUNCTION pixelFunc
#define S3L_RESOLUTION_X 100 #define S3L_RESOLUTION_X 100
@ -81,7 +83,7 @@ int testTriangleRasterization(
return numErrors; return numErrors;
} }
int testRasterization() int testRasterization(void)
{ {
printf("\n=== TESTING RASTERIZATION ===\n"); printf("\n=== TESTING RASTERIZATION ===\n");
@ -337,7 +339,7 @@ int testRasterization()
return numErrors; return numErrors;
} }
static inline double abs(double a) static inline double absVal(double a)
{ {
return a >= 0.0 ? a : (-1 * a); return a >= 0.0 ? a : (-1 * a);
} }
@ -350,7 +352,7 @@ double vec3Len(S3L_Vec4 v)
((double) v.z) * ((double) v.z)); ((double) v.z) * ((double) v.z));
} }
int testGeneral() int testGeneral(void)
{ {
printf("\n=== TESTING GENERAL ===\n"); printf("\n=== TESTING GENERAL ===\n");
@ -362,9 +364,9 @@ int testGeneral()
uint32_t errors0 = 0; uint32_t errors0 = 0;
uint32_t errors1 = 0; uint32_t errors1 = 0;
for (S3L_Unit x = -1 * m; x < m; x += 3 * (abs(x) / 64 + 1)) for (S3L_Unit x = -1 * m; x < m; x += 3 * (absVal(x) / 64 + 1))
for (S3L_Unit y = -1 * m; y < m; y += 3 * (abs(y) / 32 + 1)) for (S3L_Unit y = -1 * m; y < m; y += 3 * (absVal(y) / 32 + 1))
for (S3L_Unit z = -1 * m; z < m; z += 5 * (abs(z) / 64 + 1)) for (S3L_Unit z = -1 * m; z < m; z += 5 * (absVal(z) / 64 + 1))
{ {
S3L_Vec4 v; S3L_Vec4 v;
@ -372,13 +374,13 @@ int testGeneral()
S3L_normalizeVec3Fast(&v); S3L_normalizeVec3Fast(&v);
double l0 = vec3Len(v); double l0 = vec3Len(v);
double e0 = abs(l0 - S3L_FRACTIONS_PER_UNIT); double e0 = absVal(l0 - S3L_FRACTIONS_PER_UNIT);
S3L_setVec4(&v,x,y,z,0); S3L_setVec4(&v,x,y,z,0);
S3L_normalizeVec3(&v); S3L_normalizeVec3(&v);
double l1 = vec3Len(v); double l1 = vec3Len(v);
double e1 = abs(l1 - S3L_FRACTIONS_PER_UNIT); double e1 = absVal(l1 - S3L_FRACTIONS_PER_UNIT);
if (e0 > tolerance) if (e0 > tolerance)
errors0++; errors0++;
@ -397,8 +399,19 @@ int testGeneral()
return errors1; return errors1;
} }
int main() int testRender(void)
{ {
printf("\n=== TESTING RENDER ===\n");
// TODO
return 0;
}
int main(void)
{
printf("testing small3dlib\n\n");
S3L_Mat4 m, m2; S3L_Mat4 m, m2;
S3L_Vec4 v; S3L_Vec4 v;
@ -420,8 +433,9 @@ int main()
uint32_t totalErrors = 0; uint32_t totalErrors = 0;
totalErrors += testRasterization();
totalErrors += testGeneral(); totalErrors += testGeneral();
totalErrors += testRasterization();
totalErrors += testRender();
printf("\n===== DONE =====\ntotal errors: %d\n",totalErrors); printf("\n===== DONE =====\ntotal errors: %d\n",totalErrors);

View file

@ -22,6 +22,9 @@
z-buffer (full or reduced, S3L_Z_BUFFER), sorted-drawing (S3L_SORT), or even z-buffer (full or reduced, S3L_Z_BUFFER), sorted-drawing (S3L_SORT), or even
none of these. See the description of the options in this file. none of these. See the description of the options in this file.
The rendering itself is done with S3L_drawScene, usually preceded by
S3L_newFrame (for clearing zBuffer etc.).
The library is meant to be used in not so huge programs that use single The library is meant to be used in not so huge programs that use single
translation unit and so includes both declarations and implementation at once. translation unit and so includes both declarations and implementation at once.
If you for some reason use multiple translation units (which include the If you for some reason use multiple translation units (which include the
@ -681,10 +684,10 @@ void S3L_drawTriangle(
/** This should be called before rendering each frame. The function clears /** This should be called before rendering each frame. The function clears
buffers and does potentially other things needed for the frame. */ buffers and does potentially other things needed for the frame. */
void S3L_newFrame(); void S3L_newFrame(void);
void S3L_zBufferClear(); void S3L_zBufferClear(void);
void S3L_stencilBufferClear(); void S3L_stencilBufferClear(void);
/** Writes a value (not necessarily depth! depends on the format of z-buffer) /** Writes a value (not necessarily depth! depends on the format of z-buffer)
to z-buffer (if enabled). Does NOT check boundaries! */ to z-buffer (if enabled). Does NOT check boundaries! */
@ -1803,7 +1806,7 @@ void S3L_mapProjectionPlaneToScreen(
(point.y * S3L_HALF_RESOLUTION_X) / S3L_FRACTIONS_PER_UNIT; (point.y * S3L_HALF_RESOLUTION_X) / S3L_FRACTIONS_PER_UNIT;
} }
void S3L_zBufferClear() void S3L_zBufferClear(void)
{ {
#if S3L_Z_BUFFER #if S3L_Z_BUFFER
for (uint32_t i = 0; i < S3L_RESOLUTION_X * S3L_RESOLUTION_Y; ++i) for (uint32_t i = 0; i < S3L_RESOLUTION_X * S3L_RESOLUTION_Y; ++i)
@ -1811,7 +1814,7 @@ void S3L_zBufferClear()
#endif #endif
} }
void S3L_stencilBufferClear() void S3L_stencilBufferClear(void)
{ {
#if S3L_STENCIL_BUFFER #if S3L_STENCIL_BUFFER
for (uint32_t i = 0; i < S3L_STENCIL_BUFFER_SIZE; ++i) for (uint32_t i = 0; i < S3L_STENCIL_BUFFER_SIZE; ++i)
@ -1819,7 +1822,7 @@ void S3L_stencilBufferClear()
#endif #endif
} }
void S3L_newFrame() void S3L_newFrame(void)
{ {
S3L_zBufferClear(); S3L_zBufferClear();
S3L_stencilBufferClear(); S3L_stencilBufferClear();