diff options
| author | 3gg <3gg@shellblade.net> | 2026-02-14 19:06:49 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2026-02-14 19:06:49 -0800 |
| commit | e0dd69febc8f73b0e39e14d070ecf6b73bbe2d4f (patch) | |
| tree | 51b438b9447b50cdbc6dd6c2ae2ce42a384acfe6 /include/swgfx.h | |
| parent | b0544549c551dfa0b52e7c685580f954861240ba (diff) | |
Use float colour. First step towards directional lighting
Diffstat (limited to 'include/swgfx.h')
| -rw-r--r-- | include/swgfx.h | 29 |
1 files changed, 16 insertions, 13 deletions
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; | |||
| 30 | 30 | ||
| 31 | typedef struct sgVec2i { int x, y; } sgVec2i; | 31 | typedef struct sgVec2i { int x, y; } sgVec2i; |
| 32 | typedef struct sgVec2 { R x, y; } sgVec2; | 32 | typedef struct sgVec2 { R x, y; } sgVec2; |
| 33 | typedef struct sgVec3 { R x, y, z; } sgVec3; | 33 | typedef struct sgVec3 { union { struct { R r, g, b; }; struct { R x, y, z; }; }; } sgVec3; |
| 34 | typedef struct sgVec4 { R x, y, z, w; } sgVec4; | 34 | typedef struct sgVec4 { union { struct { R r, g, b, a; }; struct { R x, y, z, w; }; }; } sgVec4; |
| 35 | 35 | ||
| 36 | typedef sgVec3 sgNormal; | 36 | typedef sgVec3 sgNormal; |
| 37 | 37 | ||
| @@ -50,14 +50,17 @@ typedef uint16_t sgIdx; | |||
| 50 | typedef struct sgVertIdx { sgIdx pos, uv, normal; } sgVertIdx; | 50 | typedef struct sgVertIdx { sgIdx pos, uv, normal; } sgVertIdx; |
| 51 | typedef struct sgTriIdx { sgVertIdx v0, v1, v2; } sgTriIdx; | 51 | typedef struct sgTriIdx { sgVertIdx v0, v1, v2; } sgTriIdx; |
| 52 | 52 | ||
| 53 | typedef struct sgBgra { uint8_t b, g, r, a; } sgBgra; | 53 | typedef struct sgRgba { uint8_t r, g, b, a; } sgRgba; |
| 54 | typedef struct sgRgba { uint8_t r, g, b, a; } sgRgba; | 54 | typedef struct sgBgra { uint8_t b, g, r, a; } sgBgra; |
| 55 | // TODO: Should we use real-valued colours? | 55 | |
| 56 | typedef sgVec3 sgColour3; | ||
| 57 | typedef sgVec4 sgColour4; | ||
| 56 | typedef sgRgba sgPixel; | 58 | typedef sgRgba sgPixel; |
| 57 | // TODO: Expose a macro to control the desired surface format. | 59 | // TODO: Expose a macro to control the desired surface format. |
| 58 | typedef sgBgra sgScreenPixel; | 60 | typedef sgBgra sgScreenPixel; |
| 59 | 61 | ||
| 60 | typedef uint16_t sgTextureId; | 62 | typedef uint16_t sgTextureId; |
| 63 | typedef sgRgba sgTexel; | ||
| 61 | 64 | ||
| 62 | typedef enum sgTextureFilter { | 65 | typedef enum sgTextureFilter { |
| 63 | sgNearest, | 66 | sgNearest, |
| @@ -67,7 +70,7 @@ typedef enum sgTextureFilter { | |||
| 67 | typedef struct sgImage { | 70 | typedef struct sgImage { |
| 68 | int width; | 71 | int width; |
| 69 | int height; | 72 | int height; |
| 70 | sgPixel* pixels; | 73 | sgTexel* pixels; |
| 71 | } sgImage; | 74 | } sgImage; |
| 72 | 75 | ||
| 73 | typedef struct swgfx swgfx; | 76 | typedef struct swgfx swgfx; |
| @@ -87,8 +90,8 @@ void sgDel(swgfx**); | |||
| 87 | 90 | ||
| 88 | // TODO: Write client app first, then implement the functions below in the C file. | 91 | // TODO: Write client app first, then implement the functions below in the C file. |
| 89 | 92 | ||
| 90 | sgPixel* sgColourBuffer(swgfx*); | 93 | sgColour4* sgColourBuffer(swgfx*); |
| 91 | void sgPresent(swgfx*, sgVec2i dimensions, sgScreenPixel* screen); | 94 | void sgPresent(swgfx*, sgVec2i dimensions, sgScreenPixel* screen); |
| 92 | 95 | ||
| 93 | void sgModelId (swgfx*); | 96 | void sgModelId (swgfx*); |
| 94 | void sgModel (swgfx*, sgVec3 position, sgVec3 right, sgVec3 up, sgVec3 forward); | 97 | void sgModel (swgfx*, sgVec3 position, sgVec3 right, sgVec3 up, sgVec3 forward); |
| @@ -101,7 +104,7 @@ void sgTextureRegister(swgfx*, sgTextureId, const sgImage*, sgTextureFilter); | |||
| 101 | void sgTextureActivate(swgfx*, sgTextureId); | 104 | void sgTextureActivate(swgfx*, sgTextureId); |
| 102 | 105 | ||
| 103 | void sgClear(swgfx*); | 106 | void sgClear(swgfx*); |
| 104 | void sgPixels(swgfx*, size_t count, const sgVec2i* positions, sgPixel colour); | 107 | void sgPixels(swgfx*, size_t count, const sgVec2i* positions, sgColour4); |
| 105 | void sgQuads (swgfx*, size_t count, const sgQuad*); | 108 | void sgQuads (swgfx*, size_t count, const sgQuad*); |
| 106 | void sgQuadsi(swgfx*, size_t count, const sgQuadi*); | 109 | void sgQuadsi(swgfx*, size_t count, const sgQuadi*); |
| 107 | void sgTriangles2 (swgfx*, size_t count, const sgTri2*); | 110 | void sgTriangles2 (swgfx*, size_t count, const sgTri2*); |
| @@ -112,13 +115,13 @@ void sgTrianglesIndexed(swgfx*, size_t numIndices, const sgIdx* indices, const s | |||
| 112 | void sgTrianglesIndexedNonUniform(swgfx*, size_t numTris, const sgTriIdx* tris, const sgVec3* positions, const sgVec2* texcoords, const sgVec3* normals); | 115 | void sgTrianglesIndexedNonUniform(swgfx*, size_t numTris, const sgTriIdx* tris, const sgVec3* positions, const sgVec2* texcoords, const sgVec3* normals); |
| 113 | 116 | ||
| 114 | void sgLighting(swgfx*); | 117 | void sgLighting(swgfx*); |
| 115 | void sgAmbient(swgfx*, sgVec3 ambient); | 118 | void sgAmbient (swgfx*, sgColour3); |
| 116 | // TODO: Implement directional lights. | 119 | void sgDirectional(swgfx*, sgColour3, sgVec3 direction); |
| 117 | 120 | ||
| 118 | void sgDepth(swgfx*); | 121 | void sgDepth(swgfx*); |
| 119 | void sgNormals(swgfx*); | 122 | void sgNormals(swgfx*); |
| 120 | 123 | ||
| 121 | void sgGamma (swgfx*, sgPixel*, int width, int height); | 124 | void sgGamma (swgfx*, sgTexel*, int width, int height); |
| 122 | void sgGammaInv(swgfx*, sgPixel*, int width, int height); | 125 | void sgGammaInv(swgfx*, sgColour4*, int width, int height); |
| 123 | 126 | ||
| 124 | sgCounters sgGetCounters(const swgfx*); | 127 | sgCounters sgGetCounters(const swgfx*); |
