summaryrefslogtreecommitdiff
path: root/include/swgfx.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/swgfx.h')
-rw-r--r--include/swgfx.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/swgfx.h b/include/swgfx.h
new file mode 100644
index 0000000..b6dc769
--- /dev/null
+++ b/include/swgfx.h
@@ -0,0 +1,68 @@
1/*
2Software rendering library.
3
4Cooridnate systems:
5- Pixel coordinates (i,j) refer to the center of the pixel.
6 Thus, real-valued coordinates (x,y) with no fractional part point at the pixel center.
7- Viewport origin is the top-left corner of the screen.
8 The viewport axes extend down and to the right.
9
10Multi-threading:
11- Internal resources (swgfx context) are externally synchronized.
12- External resources (colour buffer) are internally synchronized.
13*/
14#pragma once
15
16#include <stddef.h>
17#include <stdint.h>
18
19typedef float R;
20
21typedef struct sgVec2i { int x, y; } sgVec2i;
22typedef struct sgVec2 { R x, y; } sgVec2;
23typedef struct sgVec3 { R x, y, z; } sgVec3;
24typedef struct sgVec4 { R x, y, z, w; } sgVec4;
25
26typedef sgVec3 sgNormal;
27
28typedef struct sgQuadi { sgVec2i p0, p1; } sgQuadi;
29typedef struct sgQuad { sgVec2 p0, p1; } sgQuad;
30typedef struct sgTri2 { sgVec2 p0, p1, p2; } sgTri2;
31typedef struct sgTri3 { sgVec3 p0, p1, p2; } sgTri3;
32
33// TODO: Should we use real-valued colours?
34typedef struct sgPixel { uint8_t r, g, b, a; } sgPixel;
35
36typedef struct swgfx swgfx;
37
38swgfx* sgNew();
39void sgDel(swgfx**);
40
41// TODO: Write client app first, then implement the functions below in the C file.
42
43void sgColourBuffer(swgfx*, sgVec2i dimensions, sgPixel* buffer);
44void sgPresent (swgfx*, sgVec2i dimensions, sgPixel* screen);
45
46void sgCam (swgfx*, sgVec3 position, sgVec3 forward);
47void sgOrtho (swgfx*, R left, R right, R top, R bottom, R near, R far);
48void sgPerspective(swgfx*, R fovy, R aspect, R near, R far);
49void sgViewport (swgfx*, int x0, int y0, int width, int height);
50
51void sgClear(swgfx*);
52void sgPixels(swgfx*, size_t count, const sgVec2i* positions, sgPixel colour);
53void sgQuads (swgfx*, size_t count, const sgQuad*);
54void sgQuadsi(swgfx*, size_t count, const sgQuadi*);
55void sgTriangles2 (swgfx*, size_t count, const sgTri2*);
56void sgTriangleStrip2(swgfx*, size_t count, const sgVec2*);
57void sgTriangles (swgfx*, size_t count, const sgTri3*, const sgNormal*);
58void sgTriangleStrip (swgfx*, size_t count, const sgVec3*, const sgNormal*);
59
60void sgCheck(swgfx*);
61
62// Memory
63#define SG_ALIGN 64
64#define SG_ALIGN_PTR(P) ((uintptr_t)(P) & (~(SG_ALIGN-1)))
65#define SG_ALIGN_ALLOC(COUNT, TYPE) (TYPE*)sgAlloc(1, COUNT * sizeof(TYPE))
66#define SG_FREE(PP) sgFree((void**)PP)
67void* sgAlloc(size_t count, size_t size);
68void sgFree(void**);