summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authoronelin <oscar@nelin.dk>2025-12-17 12:48:51 +0000
committeronelin <oscar@nelin.dk>2025-12-18 21:14:22 +0000
commit99d49b59e99cc94d18efd3ff0e33a25d7356bae9 (patch)
treed60fdcdf59c7f75307b6f57c3ac8734999425971 /src/include
parent261d33c72095a2abd98177f88ebb24fe205a042f (diff)
Add framebuffer resizing
Diffstat (limited to 'src/include')
-rw-r--r--src/include/daw/rendering.h55
1 files changed, 37 insertions, 18 deletions
diff --git a/src/include/daw/rendering.h b/src/include/daw/rendering.h
index 530a8e0..70b1566 100644
--- a/src/include/daw/rendering.h
+++ b/src/include/daw/rendering.h
@@ -264,26 +264,39 @@ typedef enum {
// TODO: Change `2` once we add support for more formats
-#define BUFFERPARAMETER_FMT_GET(bufferparam) (BUFFERPARAMETER_GET_PARAMETER(bufferparam) & (((1 << 8) - 1) << 2))
-
#define BUFFERPARAMETER_FMT_IS_COLOR(bufferparam) \
((BUFFERPARAMETER_GET_PARAMETER(bufferparam) & BUFFERPARAMETER_FMT_COLOR_MASK) != 0)
#define BUFFERPARAMETER_FMT_IS_DEPTH_OR_STENCIL(bufferparam) \
((BUFFERPARAMETER_GET_PARAMETER(bufferparam) & BUFFERPARAMETER_FMT_DEPTH_STENCIL_MASK) != 0)
+// The textures and renderbuffers must be contigous in the rendertargets
+// `buffer` and `buffer_parameters` members
typedef struct {
- i32 num_attached_buffers;
- ivec3 dimensions; // All objects attached to a framebuffer (in OpenGL) must have same size
+ // Number of attached textures
+ i8 num_textures;
+ // Number of attached renderbuffers
+ i8 num_renderbuffers;
+ // All objects attached to a framebuffer (at least in OpenGL) must have same
+ // size. Set the remainding dimensions to zero to indicate they're unused
+ // even though, mathematically speaking, they should be one.
+ ivec3 dimensions;
} FramebufferParameters;
-// A render target takes a bunch of drawcalls, and renders it to a texture.
+// A render target takes a bunch of drawcalls, and renders it to either a
+// texture or buffer.
// TODO: user runs "init" for their rendertarget(s) "stack", possibly using some
-// predefined macro "DEFAULT_RENDERTARGETS". Requires user to specify number of lights et. al.
+// predefined macro "DEFAULT_RENDERTARGETS". Requires user to specify number of
+// lights et. al.
+// The RenderTargets is technically two SOAs:
+// * framebuffers, holding the OpenGL "framebuffer name", buffer parameters,
+// camera, and resize callbacks,
+// * and "buffers" (generalized name for "textures" and "renderbuffers")
typedef struct {
- // glFrameBuffer
+ // Number of framebuffers.
usize framebuffer_len;
+ // OpenGL "names"
u32 *framebuffer;
// Number of buffers attached to each of the framebuffers. Used to iteratively
@@ -294,22 +307,25 @@ typedef struct {
// One cam per framebuffer, is usually a pointer to user-allocated camera
Camera **cam;
- //// Called when window is resized with new width and height. Set to NULL to
- //// skip changing texture_size. Comparable to glViewport.
- //// This function can be heavy due to it destroying and re-creating framebuffers.
- //// Which requires me to store the parameters that they we're created with.
- //void (**framebuffer_size_callback)(ivec2*,ivec2);
+ // Indirectly called when window is resized with new width and height. Set to
+ // NULL to skip changing framebuffer_size. Comparable to glViewport.
+ // This function can be heavy due to it destroying and re-creating buffers,
+ // textures and framebuffers.
+ void (**framebuffer_size_callback)(ivec3* dst,ivec2 src);
- //// Called when window is resized. Calls the respective texture_size_callback function at
- //// the same index if not null. The camera resize callback function is then
- //// called with the new dimensions of the texture.
- //// Set to NULL to skip changing the camera size/perspective.
- void (**camera_reset_callback)(Camera*,ivec2);
+ // Called when window is resized. Calls the respective framebuffer_size_callback function at
+ // the same index if not null. The camera resize callback function is then
+ // called with the new dimensions of the framebuffer if
+ // framebuffer_size_callback is not null, otherwise called with
+ // the new window size.
+ // Set to NULL to skip changing the camera size/perspective.
+ void (**camera_reset_callback)(Camera*,ivec2 src);
- // glTexture / glRenderBuffer / glBuffer / glWhatever.
+ // glTexture and glRenderBuffer
// Currently, each buffer must be either a texture or a (depth and/or stencil)
// buffer.
usize buffer_len;
+ // OpenGL buffer names
u32 *buffer;
// Stores per-buffer type, and type-specific parameters.
u32 *buffer_parameters;
@@ -362,6 +378,9 @@ ShaderType guess_shadertype_from_filename(const char *restrict fname);
Texture createTextureFromImageData(unsigned char* image_data, i32 width, i32 height, u8 components);
+// Creates and initializes buffers for the framebuffer
+void r_setup_framebuffer(void *restrict ctx, u32 framebuffer_id, FramebufferParameters param, u32 *restrict buffer_array, u32 *restrict buffer_parameters);
+
void r_create_framebuffers(void* restrict ctx, u32* restrict framebuffer_array, usize num_targets);
void r_destroy_framebuffers(void* restrict ctx, u32* restrict framebuffer_array, usize num_targets);
void r_create_textures(void *restrict ctx, u32* restrict texture_array, u32* restrict texture_types, ivec3* restrict texture_sizes, usize num_targets);