diff options
| author | onelin <oscar@nelin.dk> | 2025-11-29 22:04:52 +0000 |
|---|---|---|
| committer | onelin <oscar@nelin.dk> | 2025-12-18 21:14:16 +0000 |
| commit | 07116cd28845c3e589ab7e99f32d0ab96dd5cf4d (patch) | |
| tree | 0382594d2d58376daa527aaa131d81d8273834a5 /src/include | |
| parent | c2335eab1db200481c3e81664f27f9244579397c (diff) | |
TMP Rework rendering
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/daw/rendering.h | 74 | ||||
| -rw-r--r-- | src/include/daw/window.h | 3 |
2 files changed, 41 insertions, 36 deletions
diff --git a/src/include/daw/rendering.h b/src/include/daw/rendering.h index 590bcb6..a26310e 100644 --- a/src/include/daw/rendering.h +++ b/src/include/daw/rendering.h @@ -124,6 +124,7 @@ typedef struct { // The texture ID, glBindTextures(target, &this->texture) u32 texture; + u32 texture_len; // Number of buffers usize buffer_len; @@ -191,30 +192,6 @@ typedef struct { } Camera; -usize ShaderBufferDataType_size(u16 flags); - -ShaderBufferFlag ShaderBuffer_get_access_frequency(u64 flags); -ShaderBufferFlag ShaderBuffer_get_access_type(u64 flags); -ShaderBufferFlag ShaderBuffer_get_type(u64 flags); -ShaderBufferFlag ShaderBuffer_get_data_type(u64 flags); - -/* Conversion to GL types */ -u32 ShaderBuffer_get_gl_type(u64 flags); -u32 ShaderBuffer_get_gl_accesstype(u64 flags); -u32 ShaderBuffer_get_gl_datatype(u64 flags); - -/* Misc */ -void r_perspective(Camera *c, f32 fov, ivec2 windowsize); -void r_perspective_ortho(Camera *c, f32 sz, ivec2 windowsize); - -void r_set_camera(Camera* c); -void r_reset_camera(Camera* c, ivec2 windowsize); - -//void window_size_callback(GLFWwindow* window, i32 width, i32 height); - -// 3D positional coordinates and scale in last element of `pos` -void engine_draw_model(RenderObject* o, vec4 pos); - typedef struct { vec3 pos; f32 scale; @@ -231,11 +208,14 @@ typedef enum { // Buffer parameter: Frame buffer // Buffer parameter: Texture buffer +#define BUFFERPARAMETER_TEXTURE_GET_DIMENSION(bufferparam) (BUFFERPARAMETER_GET_PARAMETER(bufferparam) & 7) #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) >> 3 & 2) #define BUFFERPARAMETER_TEXTURE_FMT_RGBA8 (1 << 4) #define BUFFERPARAMETER_TEXTURE_FMT_SRGB8 (2 << 4) #define BUFFERPARAMETER_TEXTURE_FMT_SRGBA8 (3 << 4) @@ -263,7 +243,7 @@ typedef enum { typedef struct { i32 num_attached_buffers; - ivec4 dimensions; // All objects attached to a framebuffer (in OpenGL) must have same size + ivec3 dimensions; // All objects attached to a framebuffer (in OpenGL) must have same size } FramebufferParameters; // A render target takes a bunch of drawcalls, and renders it to a texture. @@ -273,22 +253,15 @@ typedef struct { // glFrameBuffer usize framebuffer_len; - // glTexture / glRenderBuffer / glBuffer / glWhatever - usize buffer_len; - u32 *framebuffer; - u32 *buffer; // Number of buffers attached to each of the framebuffers. Used to iteratively // get all buffers by summing the previous sizes to get the first buffer // associated with the current. FramebufferParameters *framebuffer_parameters; - // Stores per-buffer type, and type-specific parameters. - u32 *buffer_parameters; - - // One cam per framebuffer - Camera *cam; + // 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. @@ -301,8 +274,38 @@ typedef struct { //// called with the new dimensions of the texture. //// Set to NULL to skip changing the camera size/perspective. void (**camera_reset_callback)(Camera*,ivec2); + + // glTexture / glRenderBuffer / glBuffer / glWhatever + usize buffer_len; + u32 *buffer; + // Stores per-buffer type, and type-specific parameters. + u32 *buffer_parameters; } RenderTargets; +usize ShaderBufferDataType_size(u16 flags); + +ShaderBufferFlag ShaderBuffer_get_access_frequency(u64 flags); +ShaderBufferFlag ShaderBuffer_get_access_type(u64 flags); +ShaderBufferFlag ShaderBuffer_get_type(u64 flags); +ShaderBufferFlag ShaderBuffer_get_data_type(u64 flags); + +/* Conversion to GL types */ +u32 ShaderBuffer_get_gl_type(u64 flags); +u32 ShaderBuffer_get_gl_accesstype(u64 flags); +u32 ShaderBuffer_get_gl_datatype(u64 flags); + +/* Misc */ +void r_perspective(Camera *c, f32 fov, ivec2 windowsize); +void r_perspective_ortho(Camera *c, f32 sz, ivec2 windowsize); + +void r_set_camera(RenderTargets *restrict t, i32 framebuffer_idx, Camera *restrict c); +void r_reset_camera(Camera* c, ivec2 windowsize); + +//void window_size_callback(GLFWwindow* window, i32 width, i32 height); + +// 3D positional coordinates and scale in last element of `pos` +void r_draw_model(void *restrict context, RenderTargets *restrict t, u32 framebuffer_idx, RenderObject* o, vec4 pos); + void r_camera_reset_default(Camera* c, ivec2 windowsize); RenderObject RenderObject_new( @@ -328,8 +331,9 @@ Texture createTextureFromImageData(unsigned char* image_data, i32 width, i32 hei 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, ivec4* restrict texture_sizes, 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); void r_destroy_textures(void *restrict ctx, u32* textures, usize num_textures); +void r_attach_buffers(void *restrict ctx, u32 fbo, u32* buffers, u32* buffer_parameters, i32 num_buffers); void r_init_renderstack( usize num_fbuf, usize num_buf, diff --git a/src/include/daw/window.h b/src/include/daw/window.h index 44ea1fa..4e00774 100644 --- a/src/include/daw/window.h +++ b/src/include/daw/window.h @@ -99,9 +99,10 @@ Window* Window_new(const struct Platform *p, const char *restrict title, Window_ /* Rendering functions */ void render_begin(Window* w); -void render_present(Window* w); +void render_present(Window* w, RenderObject *restrict default_quad); void window_reset_drawing(void); void render(Window* w); +void draw_model(Window *restrict w, u32 framebuffer_idx, RenderObject* o, vec4 pos); void window_init_renderstack(Window *restrict w, usize num_fbuf, usize num_buf, |
