diff options
Diffstat (limited to 'src/rendering/include')
| -rw-r--r-- | src/rendering/include/engine/rendering/platform.h | 57 | ||||
| -rw-r--r-- | src/rendering/include/engine/rendering/platform_glfw.h | 32 | ||||
| -rw-r--r-- | src/rendering/include/engine/rendering/rendering.h | 288 | ||||
| -rw-r--r-- | src/rendering/include/engine/rendering/window.h | 53 |
4 files changed, 0 insertions, 430 deletions
diff --git a/src/rendering/include/engine/rendering/platform.h b/src/rendering/include/engine/rendering/platform.h deleted file mode 100644 index ea51c47..0000000 --- a/src/rendering/include/engine/rendering/platform.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef PLATFORM_H -#define PLATFORM_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <cglm/ivec2.h> - -#include <engine/core/types.h> -// TODO: We only need the window once all the garbage in Instance is cleaned up. -#include <engine/core/platform.h> -#include <engine/rendering/window.h> - -#define DAW_WINDOW_VSYNC (1 << 0) -#define DAW_WINDOW_FULLSCREEN (1 << 1) -#define DAW_WINDOW_RESIZEABLE (1 << 2) - -// 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. - -// Platform libraries must implement a struct Platform: -struct Platform { - /* Initialize a window for the given platform. The rendering backend should - * also be initialized here. - * Parameters: - * const char* title: window title. - * ivec2 windowsize: the size in pixels for the new window. - * const u32 flags: window flags, such as static size and fullscreen. - * The flags are platform agnostic and needs to be - * converted to the specific library - * Returns: - * A pointer to a struct Window, NULL on error. - */ - Window* (*window_init)(const char *restrict title, ivec2 windowsize, const u32 flags); - - /* Destroy, close, and free up resources related to the window and the - * platform library specific resources. - */ - void (*window_destroy)(Window *restrict w); - - /* Resize the given window. Resize callbacks are handled by the wrapper - * implementation. - */ - void (*window_resize)(Window *restrict window, int width, int height); - - /* Return true if the platform has ordered the window to exit. */ - bool (*window_should_close)(Window *restrict w); - - /* Poll events on the window from the operating system. */ - void (*window_poll)(void); -}; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/rendering/include/engine/rendering/platform_glfw.h b/src/rendering/include/engine/rendering/platform_glfw.h deleted file mode 100644 index 949968d..0000000 --- a/src/rendering/include/engine/rendering/platform_glfw.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef ENGINE_RENDERING_PLATFORM_GLFW_H -#define ENGINE_RENDERING_PLATFORM_GLFW_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <cglm/ivec2.h> - -#include <engine/core/types.h> -#include <engine/rendering/platform.h> -#include <engine/rendering/window.h> - -Window* window_init_glfw(const char *restrict windowtitle, ivec2 windowsize, const u32 flags); -void window_destroy_glfw(Window *restrict w); -void window_resize_glfw(Window *restrict window, int width, int height); -bool window_should_close_glfw(Window *restrict window); -void window_poll_glfw(void); - -const struct Platform Platform_GLFW = { - .window_init = window_init_glfw, - .window_destroy = window_destroy_glfw, - .window_resize = window_resize_glfw, - .window_should_close = window_should_close_glfw, - .window_poll = window_poll_glfw, -}; - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/src/rendering/include/engine/rendering/rendering.h b/src/rendering/include/engine/rendering/rendering.h deleted file mode 100644 index a996257..0000000 --- a/src/rendering/include/engine/rendering/rendering.h +++ /dev/null @@ -1,288 +0,0 @@ -#ifndef ENGINE_RENDERING_RENDERING_H -#define ENGINE_RENDERING_RENDERING_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <engine/core/types.h> -#include <engine/rendering/window.h> - -#include <cglm/ivec2.h> - -/* Definitions */ -#define RGBA(_r, _g, _b, _a) ((Engine_color){.r = _r, .g = _g, .b = _b, .a = _a}) -#define RGB(_r, _g, _b) RGBA(_r, _g, _b, 0xFF) - -/* Types */ -/* TODO: Cleanup these types. */ -typedef struct { - u8 r; - u8 g; - u8 b; - u8 a; -} Engine_color; - -typedef struct { - /* Maybe implement types, such as `atlas` (default), `standalone`, or - * something idk. */ - u32 id; - i32 width; - i32 height; -} Texture; - -typedef struct { - u32 texture_id; - ivec2 coord; -} Sprite; - -typedef enum { - Shader_Error, - - Shader_Program, - Shader_Vertex, - Shader_Tessellation, - Shader_Geometry, - Shader_Fragment, - Shader_Compute, -} ShaderType; - -typedef struct { - /* Shader proram */ - ShaderType type; - u32 program; -} Shader; - -typedef struct { - vec3 position; - vec3 size; - mat4 rotation; -} Transform; - -typedef enum { - ShaderBufferFlag_none = 0x00, - - // First 3 bytes describe the access frequency. - ShaderBuffer_AccessFrequency_stream = 0b0000000000001, // 1 - ShaderBuffer_AccessFrequency_static = 0b0000000000010, // 2 - ShaderBuffer_AccessFrequency_dynamic = 0b0000000000011, // 3 - - // Next 3 bytes describe the access type. - ShaderBuffer_AccessType_draw = 0b0000000001000, // 8 - ShaderBuffer_AccessType_read = 0b0000000010000, // 16 - ShaderBuffer_AccessType_copy = 0b0000000011000, // 24 - - // Next 3 bytes describe the buffer type - ShaderBuffer_Type_vertexData = 0b0000001000000, // 64 - ShaderBuffer_Type_vertexPosition = 0b0000010000000, // 128 - ShaderBuffer_Type_vertexIndex = 0b0000011000000, // 192 - - // Next 4 bytes are designated for the data type - ShaderBuffer_DataType_nil = 0b0001000000000, // 512 - - ShaderBuffer_DataType_f32 = 0b0010000000000, // 1024 - ShaderBuffer_DataType_f64 = 0b0011000000000, // 1536 - - ShaderBuffer_DataType_i8 = 0b0100000000000, // 2048 - ShaderBuffer_DataType_i16 = 0b0101000000000, // 2560 - ShaderBuffer_DataType_i32 = 0b0110000000000, // 3072 - ShaderBuffer_DataType_i64 = 0b0111000000000, // 3584 - - ShaderBuffer_DataType_u8 = 0b1000000000000, // 4096 - ShaderBuffer_DataType_u16 = 0b1001000000000, // 4608 - ShaderBuffer_DataType_u32 = 0b1010000000000, // 5120 - ShaderBuffer_DataType_u64 = 0b1011000000000, // 5632 -} ShaderBufferFlag; - -typedef struct { - // The backend ID, ie. glGenBuffer(numBufferObjects, &this->buffername) - u32 buffername; - // Array, access, and data, type. - u32 buffertype; - // Buffer size of `data`. To get the size of the actual data, size_elem * count - usize size; - // Number of elements - usize count; - // components per generic vertex attribute (ie, 3 for RGB, 2 for UV) - usize components; - // size of each element - usize size_elem; - // Pointer to the data - void* data; -} ShaderBuffer; - -// SHADERBUFFER_NEW is a constructor that takes the -// * type T, as one of f32, f64, i8, i16, i32, i64, u8, u16, u32, or u64. -// * COUNT, number of elements in the buffer -// * COMPONENTS, number of elements to be grouped together, ie. 3 for a vec3. -// * DATA, the buffer (it is pointed to automatically) -// * FLAGS, are low-level GL flags that hints the access frequency, the access -// type, and what buffer type it is, such as "data" or an index buffer. -#define SHADERBUFFER_NEW(T, COUNT, COMPONENTS, DATA, FLAGS) \ - (ShaderBuffer){ \ - .buffername = 0, \ - .buffertype = ShaderBuffer_DataType_##T | FLAGS, \ - .size = COUNT * sizeof(T), \ - .count = COUNT, \ - .components = COMPONENTS, \ - .size_elem = sizeof(T), \ - .data = DATA, \ - } - -typedef struct { - /* Shader proram */ - Shader shader; - /* Vertex Array Object */ - u32 vao; - - /* MVP (a uniform from the shader). - * This could also probably be generalized */ - i32 mvp; - - // The texture ID, glBindTextures(target, &this->texture) - u32 texture; - - // Number of buffers - usize buffer_len; - - // The vertex buffer is also just a buffer - ShaderBuffer* buffer; -} RenderObject; - -typedef struct { - // Index of the model in the RenderBatch models buffer - usize model_idx; - // The transformation of the model - Transform transform; -} BatchModelInstance; - -typedef struct { - // Size of models buffer - usize msize; - // number of models in the `models` buffer - usize mcount; - // Pointers to original models in this batch - RenderObject **models; - - // Size of instance buffer - usize inst_size; - // number of instances in the `instances` buffer - usize inst_count; - // Pointers to original models in this batch - BatchModelInstance *instances; - - // The rendered destination object - RenderObject renderobj; -} RenderBatch; - -typedef enum { - Camera_Perspective, - Camera_Orthogonal, -} CameraType; - -typedef struct { - /* Position of the camera in world-space. */ - vec3 pos; - - /* The viewing direction of the camera, relative to the camera. */ - vec3 dir; - - /* Perspective matrix. Initialize with r_perspective_ortho or r_perspective. */ - /* Alternatively, use `glm_perspective` or `glm_ortho`. */ - mat4 per; - - /* Used to re-calculate the perspective matrix when resizing the window */ - CameraType type; - /* Yes, could use a singular "f32 arg", but this is more extendable in the - * future. */ - union { - struct {f32 fov;} perspective; - struct {f32 sz;} orthogonal; - } parameters; - -} 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); - -/* Rendering functions */ -void render_begin(Window* w); -void render_present(Window* w); -void drawcall_reset(void); -void render(Window* w); - -/* Misc */ -void r_perspective(f32 fov, Camera *c); -void r_perspective_ortho(f32 sz, Camera *c); - -void r_set_camera(Camera* c); -void r_reset_camera(Camera* c); - -//void window_size_callback(GLFWwindow* window, i32 width, i32 height); - -void engine_draw_sprite(Sprite* s, ivec2* pos, f32 scale); -void engine_draw_sprite_ex(Sprite* s, ivec2* pos, f32 scale, - Engine_color colormod); -void engine_draw_model(RenderObject* o, vec3 pos); - -Sprite sprite_new(u64 tid, u8 coord); - -typedef enum { - RenderDrawCallType_Text, - RenderDrawCallType_Sprite, - RenderDrawCallType_Model, -} RenderDrawCallType; - -typedef struct { - RenderDrawCallType type; - union { - void* data; - struct { - Sprite* sprite; - i32 x; - i32 y; - f32 scale; - } sprite; - struct { - RenderObject* model; - vec3 pos; - f32 scale; - } model; - } data; -} RenderDrawCall; - -// TODO make all the shader buffers a list - -RenderObject RenderObject_new( - Shader* shader, - u32 texture, - ShaderBuffer *restrict buffers, usize num_buffers); - -int renderbatch_new(RenderBatch* renderbatch, usize count); -i32 renderbatch_add(RenderBatch* renderbatch, RenderObject* obj, Transform* t); -void renderbatch_transform(RenderBatch* renderbatch, usize obj_idx, Transform* t); -int renderbatch_refresh(RenderBatch* renderbatch); - -Shader compile_shader(const char* file_path, const ShaderType shader_type); -Shader compose_shader(Shader *shaders, usize shaders_len); -void shaders_delete(Shader* shader, usize shader_len); - -u32 ComposeShader(u32 *shaders, usize shaders_len); - -ShaderType guess_shadertype_from_filename(const char *restrict fname); - -Texture createTextureFromImageData(unsigned char* image_data, i32 width, i32 height, u8 components); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/rendering/include/engine/rendering/window.h b/src/rendering/include/engine/rendering/window.h deleted file mode 100644 index a964b38..0000000 --- a/src/rendering/include/engine/rendering/window.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef WINDOW_H -#define WINDOW_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <cglm/ivec2.h> - -#include <engine/core/types.h> -#include <engine/ctrl/input.h> - -#ifndef ENGINE_RENDERING_WINDOW_H_EXCLUDE_EXTERNS -extern u64 (*get_time)(void); -#endif - -typedef enum { - WINDOW_FRAMEWORK_NONE = 0, - WINDOW_FRAMEWORK_GLFW, -} Window_framework; - -typedef enum { - WINDOW_RENDERER_NONE = 0, - WINDOW_RENDERER_OPENGL, -} Window_renderer; - -typedef struct { - // Specifies the framwork & renderer combo used. - Window_framework framework; - Window_renderer renderer; - - // Window *buffer* size, in pixels. - ivec2 windowsize; - - // These are used differently depending on the framework / renderer combo. - // Subject to change to a union of backend-dependent structs - void* window; - void* context; - - /* The ctrl is probably the only sensible thing in this struct. */ - usize bindings_sz; - usize bindings_len; - i_ctx** bindings; -} Window; - -Window* Window_new(const char *restrict title, Window_framework framework, Window_renderer renderer, ivec2 size, u32 flags); - -void get_mousepos(double *x, double *y); - -#ifdef __cplusplus -} -#endif -#endif |
