summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authoronelin <oscar@nelin.dk>2025-12-17 12:48:22 +0000
committeronelin <oscar@nelin.dk>2025-12-18 21:14:22 +0000
commit261d33c72095a2abd98177f88ebb24fe205a042f (patch)
tree88ae2e79ec7db38e39c1b68701ca22626032130c /src/include
parent3a24982d1ed318b26e5ea191db63cedeb9e8d43f (diff)
Rework buffer parameters
Diffstat (limited to 'src/include')
-rw-r--r--src/include/daw/rendering.h78
1 files changed, 40 insertions, 38 deletions
diff --git a/src/include/daw/rendering.h b/src/include/daw/rendering.h
index 42881a7..530a8e0 100644
--- a/src/include/daw/rendering.h
+++ b/src/include/daw/rendering.h
@@ -199,46 +199,59 @@ typedef struct {
} RenderDrawCall;
typedef enum {
- BufferType_frame = 1,
- BufferType_texture = 2,
- BufferType_render = 3,
- BufferType_buffer = 4,
+ BufferType_frame = 0,
+ BufferType_texture = 1,
+ BufferType_render = 2,
+ BufferType_buffer = 3,
} BufferType;
+// Gives a mask of N bits, used in shifting
+#define MASK(N) ((1 << N) - 1)
+
/* Buffer set/get macros */
-// `buffer_definition` has the first 4 bits for the type,
-#define BUFFERPARAMETER_MASK_TYPE ((1 << 4) - 1)
-// next 16 bits for the type-specific parameters
-#define BUFFERPARAMETER_MASK_PARAMETER (((1 << 16) - 1) << 4)
+// `buffer_definition` uses the first 2 bits for the type,
+#define BUFFERPARAMETER_MASK_TYPE MASK(2)
+// next 14 bits for the type-specific parameters, offset by type mask-size
+#define BUFFERPARAMETER_MASK_PARAMETER (MASK(14) << 2)
#define BUFFERPARAMETER_GET_TYPE(bufferparam) \
(BufferType)(bufferparam & BUFFERPARAMETER_MASK_TYPE)
#define BUFFERPARAMETER_GET_PARAMETER(bufferparam) \
- ((bufferparam & BUFFERPARAMETER_MASK_PARAMETER) >> 4)
+ ((bufferparam & BUFFERPARAMETER_MASK_PARAMETER) >> 2)
// SET operations clear the masked bits that you're setting. Set multiple parameters by
// OR'ing them.
#define BUFFERPARAMETER_SET_TYPE(bufferparam, type) \
(BufferType)((bufferparam & ~BUFFERPARAMETER_MASK_TYPE) | type)
#define BUFFERPARAMETER_SET_PARAMETER(bufferparam, param) \
- ((bufferparam & ~BUFFERPARAMETER_MASK_PARAMETER) | ((param) << 4))
+ ((bufferparam & ~BUFFERPARAMETER_MASK_PARAMETER) | ((param) << 2))
+
+// Textures and RenderBuffers can have different formats internally. Some of
+// the available formats are available to both, some internal formats are only
+// available to either.
-// Textures and RenderBuffers can have different formats internally. These are
-// mutually exclusive and shared between texture and renderbuffer buffers.
+// The "color" formats are stored in the first 10 bits of the PARAMETER, the depth & stencil
+// formats are stored in the following 3 bits.
+// The last bit is currently unused.
//TODO: More formats
-#define BUFFERPARAMETER_FMT_RGBA8 ( 1 << 8)
-#define BUFFERPARAMETER_FMT_RGB8 ( 2 << 8)
-#define BUFFERPARAMETER_FMT_SRGB8 ( 3 << 8)
-#define BUFFERPARAMETER_FMT_SRGBA8 ( 4 << 8)
+#define BUFFERPARAMETER_FMT_COLOR_MASK MASK(10)
+
+#define BUFFERPARAMETER_FMT_RGBA8 (1)
+#define BUFFERPARAMETER_FMT_RGB8 (2)
+#define BUFFERPARAMETER_FMT_SRGB8 (3)
+#define BUFFERPARAMETER_FMT_SRGBA8 (4)
+
+// Depth & stencil format(s)
+#define BUFFERPARAMETER_FMT_DEPTH_STENCIL_MASK (MASK(3) << 10)
-#define BUFFERPARAMETER_FMT_DEPTH24_STENCIL8 ( 5 << 8)
-#define BUFFERPARAMETER_FMT_DEPTH16 ( 6 << 8)
-#define BUFFERPARAMETER_FMT_DEPTH24 ( 7 << 8)
-#define BUFFERPARAMETER_FMT_DEPTH32 ( 8 << 8)
-#define BUFFERPARAMETER_FMT_DEPTH32F ( 9 << 8)
-#define BUFFERPARAMETER_FMT_STENCIL8 (10 << 8)
+#define BUFFERPARAMETER_FMT_DEPTH24_STENCIL8 (1 << 10)
+#define BUFFERPARAMETER_FMT_DEPTH16 (2 << 10)
+#define BUFFERPARAMETER_FMT_DEPTH24 (3 << 10)
+#define BUFFERPARAMETER_FMT_DEPTH32 (4 << 10)
+#define BUFFERPARAMETER_FMT_DEPTH32F (5 << 10)
+#define BUFFERPARAMETER_FMT_STENCIL8 (6 << 10)
// "Easy default" values
#define BUFFERPARAMETER_FMT_DEPTH_STENCIL BUFFERPARAMETER_FMT_DEPTH24_STENCIL8
@@ -249,26 +262,15 @@ typedef enum {
// identical, and we differentiate between them anyways wrt. dimensions, depth,
// stencil, and depth+stencil.
-// Buffer parameter: Frame buffer
-// Buffer parameter: Texture buffer
-#define BUFFERPARAMETER_TEXTURE_GET_DIMENSION(bufferparam) (BUFFERPARAMETER_GET_PARAMETER(bufferparam) & ((1 << 4) - 1))
-#define BUFFERPARAMETER_TEXTURE_1D 1
-#define BUFFERPARAMETER_TEXTURE_2D 2
-#define BUFFERPARAMETER_TEXTURE_3D 3
-#define BUFFERPARAMETER_TEXTURE_4D 4
// TODO: Change `2` once we add support for more formats
-#define BUFFERPARAMETER_TEXTURE_GET_FORMAT(bufferparam) (BUFFERPARAMETER_GET_PARAMETER(bufferparam) & (((1 << 8) - 1) << 4))
+#define BUFFERPARAMETER_FMT_GET(bufferparam) (BUFFERPARAMETER_GET_PARAMETER(bufferparam) & (((1 << 8) - 1) << 2))
-// Buffer parameter: Buffer buffer
-// A buffer can be either a depth and/or stencil buffer. Custom buffers could be
-// implemented for this at some point.
-// It is important that the types here are bitwise non-overlapping.
-#define BUFFERPARAMETER_RENDERBUFFER_GET_TYPE(bufferparam) (BUFFERPARAMETER_GET_PARAMETER(bufferparam) & ((1 << 4) - 1))
-#define BUFFERPARAMETER_RENDERBUFFER_DEPTH 1
-#define BUFFERPARAMETER_RENDERBUFFER_STENCIL 2
+#define BUFFERPARAMETER_FMT_IS_COLOR(bufferparam) \
+ ((BUFFERPARAMETER_GET_PARAMETER(bufferparam) & BUFFERPARAMETER_FMT_COLOR_MASK) != 0)
-#define BUFFERPARAMETER_RENDERBUFFER_GET_FORMAT(bufferparam) (BUFFERPARAMETER_GET_PARAMETER(bufferparam) & (((1 << 8) - 1)) << 4)
+#define BUFFERPARAMETER_FMT_IS_DEPTH_OR_STENCIL(bufferparam) \
+ ((BUFFERPARAMETER_GET_PARAMETER(bufferparam) & BUFFERPARAMETER_FMT_DEPTH_STENCIL_MASK) != 0)
typedef struct {
i32 num_attached_buffers;