From 261d33c72095a2abd98177f88ebb24fe205a042f Mon Sep 17 00:00:00 2001 From: onelin Date: Wed, 17 Dec 2025 13:48:22 +0100 Subject: Rework buffer parameters --- src/include/daw/rendering.h | 80 +++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 39 deletions(-) (limited to 'src/include') 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_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_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 (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; -- cgit v1.3