From e0dd69febc8f73b0e39e14d070ecf6b73bbe2d4f Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 14 Feb 2026 19:06:49 -0800 Subject: Use float colour. First step towards directional lighting --- include/swgfx.h | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/swgfx.h b/include/swgfx.h index 452847c..d527f02 100644 --- a/include/swgfx.h +++ b/include/swgfx.h @@ -30,8 +30,8 @@ typedef float R; typedef struct sgVec2i { int x, y; } sgVec2i; typedef struct sgVec2 { R x, y; } sgVec2; -typedef struct sgVec3 { R x, y, z; } sgVec3; -typedef struct sgVec4 { R x, y, z, w; } sgVec4; +typedef struct sgVec3 { union { struct { R r, g, b; }; struct { R x, y, z; }; }; } sgVec3; +typedef struct sgVec4 { union { struct { R r, g, b, a; }; struct { R x, y, z, w; }; }; } sgVec4; typedef sgVec3 sgNormal; @@ -50,14 +50,17 @@ typedef uint16_t sgIdx; typedef struct sgVertIdx { sgIdx pos, uv, normal; } sgVertIdx; typedef struct sgTriIdx { sgVertIdx v0, v1, v2; } sgTriIdx; -typedef struct sgBgra { uint8_t b, g, r, a; } sgBgra; -typedef struct sgRgba { uint8_t r, g, b, a; } sgRgba; -// TODO: Should we use real-valued colours? +typedef struct sgRgba { uint8_t r, g, b, a; } sgRgba; +typedef struct sgBgra { uint8_t b, g, r, a; } sgBgra; + +typedef sgVec3 sgColour3; +typedef sgVec4 sgColour4; typedef sgRgba sgPixel; // TODO: Expose a macro to control the desired surface format. typedef sgBgra sgScreenPixel; typedef uint16_t sgTextureId; +typedef sgRgba sgTexel; typedef enum sgTextureFilter { sgNearest, @@ -67,7 +70,7 @@ typedef enum sgTextureFilter { typedef struct sgImage { int width; int height; - sgPixel* pixels; + sgTexel* pixels; } sgImage; typedef struct swgfx swgfx; @@ -87,8 +90,8 @@ void sgDel(swgfx**); // TODO: Write client app first, then implement the functions below in the C file. -sgPixel* sgColourBuffer(swgfx*); -void sgPresent(swgfx*, sgVec2i dimensions, sgScreenPixel* screen); +sgColour4* sgColourBuffer(swgfx*); +void sgPresent(swgfx*, sgVec2i dimensions, sgScreenPixel* screen); void sgModelId (swgfx*); void sgModel (swgfx*, sgVec3 position, sgVec3 right, sgVec3 up, sgVec3 forward); @@ -101,7 +104,7 @@ void sgTextureRegister(swgfx*, sgTextureId, const sgImage*, sgTextureFilter); void sgTextureActivate(swgfx*, sgTextureId); void sgClear(swgfx*); -void sgPixels(swgfx*, size_t count, const sgVec2i* positions, sgPixel colour); +void sgPixels(swgfx*, size_t count, const sgVec2i* positions, sgColour4); void sgQuads (swgfx*, size_t count, const sgQuad*); void sgQuadsi(swgfx*, size_t count, const sgQuadi*); void sgTriangles2 (swgfx*, size_t count, const sgTri2*); @@ -112,13 +115,13 @@ void sgTrianglesIndexed(swgfx*, size_t numIndices, const sgIdx* indices, const s void sgTrianglesIndexedNonUniform(swgfx*, size_t numTris, const sgTriIdx* tris, const sgVec3* positions, const sgVec2* texcoords, const sgVec3* normals); void sgLighting(swgfx*); -void sgAmbient(swgfx*, sgVec3 ambient); -// TODO: Implement directional lights. +void sgAmbient (swgfx*, sgColour3); +void sgDirectional(swgfx*, sgColour3, sgVec3 direction); void sgDepth(swgfx*); void sgNormals(swgfx*); -void sgGamma (swgfx*, sgPixel*, int width, int height); -void sgGammaInv(swgfx*, sgPixel*, int width, int height); +void sgGamma (swgfx*, sgTexel*, int width, int height); +void sgGammaInv(swgfx*, sgColour4*, int width, int height); sgCounters sgGetCounters(const swgfx*); -- cgit v1.2.3