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

Update tests

This commit is contained in:
Miloslav Číž 2019-06-30 17:02:43 +02:00
parent f7ec996b60
commit 4d5902990c

View file

@ -1,6 +1,13 @@
/*
Some basic tests for small3dlib.
author: Miloslav Ciz
license: CC0 1.0
*/
#include <stdio.h>
#define S3L_PIXEL_FUNCTION pixelFunc
#include "s3l.h"
#include "../small3dlib.h"
#define TEST_BUFFER_W 16
#define TEST_BUFFER_H 16
@ -26,12 +33,17 @@ uint16_t testTriangleRasterization(
S3L_DrawConfig conf;
conf.backfaceCulling = S3L_BACKFACE_CULLING_NONE;
conf.mode = S3L_MODE_TRIANGLES;
conf.backfaceCulling = 0;
memset(testRaster,0,TEST_BUFFER_W * TEST_BUFFER_H);
S3L_drawTriangle(x0,y0,x1,y1,x2,y2,conf,0);
S3L_Vec4 p0, p1, p2;
S3L_setVec4(&p0,x0,y0,1000,0);
S3L_setVec4(&p1,x1,y1,1000,0);
S3L_setVec4(&p2,x2,y2,1000,0);
S3L_drawTriangle(p0,p1,p2,0,0);
printf(" 0123456789ABCDEF\n");
@ -224,11 +236,6 @@ uint16_t testRasterization()
printf("cover test (each pixel should be covered exactly once):\n\n");
S3L_DrawConfig conf;
conf.backfaceCulling = S3L_BACKFACE_CULLING_NONE;
conf.mode = S3L_MODE_TRIANGLES;
S3L_ScreenCoord coords[] =
{
0,0,
@ -254,36 +261,44 @@ uint16_t testRasterization()
memset(testRaster,0,TEST_BUFFER_W * TEST_BUFFER_H);
#define dt(i1,i2,i3) S3L_drawTriangle(coords[2*i1],coords[2*i1 + 1],coords[2*i2],coords[2*i2+1],coords[2*i3],coords[2*i3+1],conf,0)
dt(0,1,6); // 0
dt(1,2,5); // 1
dt(2,4,5); // 2
dt(2,3,4); // 3
dt(0,6,9); // 4
dt(1,10,6); // 5
dt(1,5,10); // 6
dt(5,4,8); // 7
dt(4,3,8); // 8
dt(9,6,10); // 9
dt(10,5,12); // 10
dt(5,7,12); // 11
dt(5,7,11); // 12
dt(5,8,11); // 13
dt(8,3,18); // 14
dt(9,10,13); // 15
dt(10,12,13); // 16
dt(12,7,11); // 17
dt(11,8,18); // 18
dt(9,13,17); // 19
dt(13,12,14); // 20
dt(12,11,14); // 21
dt(11,14,15); // 22
dt(15,11,18); // 23
dt(13,14,16); // 24
dt(14,15,16); // 25
dt(17,13,16); // 26
dt(16,15,18); // 27
dt(16,17,18); // 28
#define dt(i1,i2,i3)\
{\
S3L_Vec4 p0, p1, p2;\
S3L_setVec4(&p0,coords[2*i1],coords[2*i1 + 1],1000,0);\
S3L_setVec4(&p1,coords[2*i2],coords[2*i2+1],1000,0);\
S3L_setVec4(&p2,coords[2*i3],coords[2*i3+1],1000,0);\
S3L_drawTriangle(p0,p1,p2,0,0);\
}
dt(0,1,6) // 0
dt(1,2,5) // 1
dt(2,4,5) // 2
dt(2,3,4) // 3
dt(0,6,9) // 4
dt(1,10,6) // 5
dt(1,5,10) // 6
dt(5,4,8) // 7
dt(4,3,8) // 8
dt(9,6,10) // 9
dt(10,5,12) // 10
dt(5,7,12) // 11
dt(5,7,11) // 12
dt(5,8,11) // 13
dt(8,3,18) // 14
dt(9,10,13) // 15
dt(10,12,13) // 16
dt(12,7,11) // 17
dt(11,8,18) // 18
dt(9,13,17) // 19
dt(13,12,14) // 20
dt(12,11,14) // 21
dt(11,14,15) // 22
dt(15,11,18) // 23
dt(13,14,16) // 24
dt(14,15,16) // 25
dt(17,13,16) // 26
dt(16,15,18) // 27
dt(16,17,18) // 28
// extra empty triangles
dt(12,12,12);
@ -327,20 +342,20 @@ int main()
S3L_Vec4 v;
S3L_initMat4(&m);
S3L_writeMat4(m);
S3L_logMat4(m);
S3L_initVec4(&v);
S3L_writeVec4(v);
S3L_logVec4(v);
S3L_vec4Xmat4(&v,&m);
S3L_writeVec4(v);
S3L_logVec4(v);
S3L_makeTranslationMat(100,200,300,&m2);
S3L_writeMat4(m2);
S3L_logMat4(m2);
S3L_mat4Xmat4(&m,&m2);
S3L_writeMat4(m);
S3L_logMat4(m);
testRasterization();