diff options
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/daw/rendering.h | 107 | ||||
| -rw-r--r-- | src/include/daw/window.h | 20 |
2 files changed, 118 insertions, 9 deletions
diff --git a/src/include/daw/rendering.h b/src/include/daw/rendering.h index 9c4b647..17d3728 100644 --- a/src/include/daw/rendering.h +++ b/src/include/daw/rendering.h @@ -204,15 +204,16 @@ u32 ShaderBuffer_get_gl_accesstype(u64 flags); u32 ShaderBuffer_get_gl_datatype(u64 flags); /* Misc */ -void r_perspective(f32 fov, Camera *c); -void r_perspective_ortho(f32 sz, Camera *c); +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); +void r_reset_camera(Camera* c, ivec2 windowsize); //void window_size_callback(GLFWwindow* window, i32 width, i32 height); -void engine_draw_model(RenderObject* o, vec3 pos); +// 3D positional coordinates and scale in last element of `pos` +void engine_draw_model(RenderObject* o, vec4 pos); typedef struct { vec3 pos; @@ -220,7 +221,89 @@ typedef struct { RenderObject* model; } RenderDrawCall; -// TODO make all the shader buffers a list +typedef enum { + BufferType_frame = 1, + BufferType_texture = 2, + BufferType_render = 3, + BufferType_buffer = 4, + +} BufferType; + +// Buffer parameter: Frame buffer +// Buffer parameter: Texture buffer +#define BUFFERPARAMETER_TEXTURE_1D 1 +#define BUFFERPARAMETER_TEXTURE_2D 2 +#define BUFFERPARAMETER_TEXTURE_3D 3 +#define BUFFERPARAMETER_TEXTURE_4D 4 + +#define BUFFERPARAMETER_TEXTURE_FMT_RGBA8 (1 << 4) +#define BUFFERPARAMETER_TEXTURE_FMT_SRGB8 (2 << 4) +#define BUFFERPARAMETER_TEXTURE_FMT_SRGBA8 (3 << 4) + +//TODO: texture formats + +// Buffer parameter: Buffer buffer +#define BUFFERPARAMETER_BUFFER_DEPTH 1 +#define BUFFERPARAMETER_BUFFER_STENCIL 2 + +// `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) + +#define BUFFERPARAMETER_GET_TYPE(bufferparam) \ + (BufferType)(bufferparam & BUFFERPARAMETER_MASK_TYPE) +#define BUFFERPARAMETER_GET_PARAMETER(bufferparam) \ + ((bufferparam & BUFFERPARAMETER_MASK_TYPE) >> 4) + +#define BUFFERPARAMETER_SET_TYPE(bufferparam, type) \ + (BufferType)((bufferparam & ~BUFFERPARAMETER_MASK_TYPE) | type) +#define BUFFERPARAMETER_SET_PARAMETER(bufferparam, param) \ + ((bufferparam & ~BUFFERPARAMETER_MASK_PARAMETER) | (param << 4)) + +typedef struct { + i32 num_attached_buffers; + ivec4 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. +// 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. +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; + + //// 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); + + //// 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); +} RenderTargets; + +void r_camera_reset_default(Camera* c, ivec2 windowsize); RenderObject RenderObject_new( Shader* shader, @@ -242,6 +325,20 @@ ShaderType guess_shadertype_from_filename(const char *restrict fname); Texture createTextureFromImageData(unsigned char* image_data, i32 width, i32 height, u8 components); +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_destroy_textures(void *restrict ctx, u32* textures, usize num_textures); + +void r_init_renderstack( + usize num_fbuf, usize num_buf, + FramebufferParameters *restrict fb_params, + u32 *restrict buffer_params + ); + +//static void r_create_renderbuffers(GladGLContext* restrict ctx, u32* restrict renderbuffer_array, u32* restrict renderbuffer_types, ivec2* restrict renderbuffer_sizes, usize num_targets); + + #ifdef __cplusplus } #endif diff --git a/src/include/daw/window.h b/src/include/daw/window.h index f445860..44ea1fa 100644 --- a/src/include/daw/window.h +++ b/src/include/daw/window.h @@ -12,6 +12,10 @@ extern "C" { #include <daw/rendering.h> +#define DAW_WINDOW_VSYNC (1 << 0) +#define DAW_WINDOW_FULLSCREEN (1 << 1) +#define DAW_WINDOW_RESIZEABLE (1 << 2) + typedef enum { WINDOW_FRAMEWORK_NONE = 0, WINDOW_FRAMEWORK_GLFW, @@ -39,11 +43,13 @@ typedef struct { usize bindings_sz; usize bindings_len; i_ctx** bindings; -} Window; -#define DAW_WINDOW_VSYNC (1 << 0) -#define DAW_WINDOW_FULLSCREEN (1 << 1) -#define DAW_WINDOW_RESIZEABLE (1 << 2) + /* The first element in the stack is the one presented to the screen. This is + * usually used for post-processing effects and can depend on previous + * RenderTextures. Use cases vary from shadowmapping, secondary in-game + * cameras, and UI. */ + RenderTargets *render_targets; +} Window; // Whether or not it is clever to force API consistency using a struct like this // can be debated, at the time of writing it seemed like a smart idea. @@ -97,6 +103,12 @@ void render_present(Window* w); void window_reset_drawing(void); void render(Window* w); +void window_init_renderstack(Window *restrict w, + usize num_fbuf, usize num_buf, + FramebufferParameters *restrict fb_params, + u32 *restrict buffer_params + ); + void get_mousepos(double *x, double *y); void window_get_size(ivec2* dst); |
