diff options
author | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-12 12:47:07 +1000 |
---|---|---|
committer | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-12 12:47:07 +1000 |
commit | f74cf52946f4e569a26bc81105537b40be95c2c7 (patch) | |
tree | 1d000367350d0e28eb7cfbc800286a0ed30a4e6c /src/new_render | |
parent | fedba7ff68924ff50022405fc9103a5acf7013fe (diff) |
wip: big makeover
Diffstat (limited to 'src/new_render')
-rw-r--r-- | src/new_render/pbr.h | 2 | ||||
-rw-r--r-- | src/new_render/render.c | 41 | ||||
-rw-r--r-- | src/new_render/render.h | 40 | ||||
-rw-r--r-- | src/new_render/render_types.h | 21 | ||||
-rw-r--r-- | src/new_render/shadows.h | 4 | ||||
-rw-r--r-- | src/new_render/skybox.h | 26 |
6 files changed, 109 insertions, 25 deletions
diff --git a/src/new_render/pbr.h b/src/new_render/pbr.h index dd29301..7573563 100644 --- a/src/new_render/pbr.h +++ b/src/new_render/pbr.h @@ -44,6 +44,8 @@ typedef struct PBR_Textures { // --- Internal +typedef struct MaterialMap MaterialMap; +typedef struct RenderEnt RenderEnt; GPU_Renderpass* PBR_RPassCreate(); GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass); diff --git a/src/new_render/render.c b/src/new_render/render.c index 455b730..f5547d5 100644 --- a/src/new_render/render.c +++ b/src/new_render/render.c @@ -4,34 +4,31 @@ #include "render.h" #include "maths_types.h" -#include "shadow.h" - -struct RendererConfig { - char window_name[256]; - u32 scr_width, scr_height; - Vec3 clear_colour; -}; +#include "pbr.h" +#include "ral_common.h" +#include "render_scene.h" +#include "shadows.h" struct Renderer { struct GLFWwindow* window; - RendererConfig config; - GPU_Device device; - GPU_Swapchain swapchain; - GPU_Renderpass* default_renderpass; - bool frame_aborted; - RenderScene scene; - PBR_Storage pbr; - Shadow_Storage shadows; - Terrain_Storage terrain; - Text_Storage text; - ResourcePools* resource_pools; + RendererConfig config; + GPU_Device device; + GPU_Swapchain swapchain; + GPU_Renderpass* default_renderpass; + bool frame_aborted; + RenderScene scene; + PBR_Storage* pbr; + Shadow_Storage* shadows; + // Terrain_Storage terrain; + // Text_Storage text; + struct ResourcePools* resource_pools; }; bool Renderer_Init(RendererConfig config, Renderer* renderer) { - // set the RAL backend up + // set the RAL backend up - // create our renderpasses - Shadow_Init(&renderer->shadows); + // create our renderpasses + Shadow_Init(renderer->shadows); - return true; + return true; } diff --git a/src/new_render/render.h b/src/new_render/render.h index 93b2366..7c6a4a5 100644 --- a/src/new_render/render.h +++ b/src/new_render/render.h @@ -4,9 +4,47 @@ #pragma once #include "defines.h" +#include "maths_types.h" +#include "ral_types.h" +#include "render_types.h" typedef struct Renderer Renderer; -typedef struct RendererConfig RendererConfig; +typedef struct RendererConfig { + char window_name[256]; + u32 scr_width, scr_height; + Vec3 clear_colour; +} RendererConfig; + +typedef struct RenderCtx { + Mat4 view; + Mat4 projection; +} RenderCtx; + +// --- Lifecycle PUB bool Renderer_Init(RendererConfig config, Renderer* renderer); PUB void Renderer_Shutdown(Renderer* renderer); + +// NOTE: All of these functions grab the Renderer instance off the global Core +PUB void Render_FrameBegin(Renderer* renderer); +PUB void Render_FrameEnd(Renderer* renderer); +PUB void Render_FrameDraw(Renderer* renderer); + +// --- Resources + +PUB TextureHandle TextureUpload(); +PUB ModelHandle ModelLoad(const char* name, const char* filepath); + +// --- Rendering Data + +PUB Mesh Mesh_Create(Geometry* geometry, bool free_on_upload); +PUB void Mesh_Delete(Mesh* mesh); + +// --- Drawing + +// NOTE: These functions use the globally bound camera in RenderScene +PUB void DrawMesh(Mesh* mesh, Material* material, Mat4 model); + +/** @brief the renderer does some internal bookkeeping for terrain so we use the terrain + stored on the Renderer rather than accept it as a parameter */ +PUB void Render_DrawTerrain(); diff --git a/src/new_render/render_types.h b/src/new_render/render_types.h index 63c472e..384a18f 100644 --- a/src/new_render/render_types.h +++ b/src/new_render/render_types.h @@ -7,6 +7,11 @@ #include "defines.h" #include "ral.h" #include "maths.h" +#include "ral_types.h" + +// --- Handles +CORE_DEFINE_HANDLE(ModelHandle); +#define ABSENT_MODEL_HANDLE 999999999 typedef struct Geometry { VertexFormat format; @@ -27,6 +32,11 @@ typedef struct Mesh { bool is_uploaded; // has the data been uploaded to the GPU } Mesh; +typedef struct TextureData { + TextureDesc description; + void* image_data; +} TextureData; + // --- Supported materials typedef enum MaterialKind { MAT_BLINN_PHONG, @@ -46,6 +56,8 @@ typedef struct Model { // materials } Model; +// TODO: function to create a model from a single mesh (like when using primitives) + // --- Lights typedef struct PointLight { Vec3 position; @@ -61,3 +73,12 @@ typedef struct DirectionalLight { Vec3 diffuse; Vec3 specular; } DirectionalLight; + +// --- + +// A renderable 'thing' +typedef struct RenderEnt { + ModelHandle model; + Mat4 affine; + bool casts_shadows; +} RenderEnt; diff --git a/src/new_render/shadows.h b/src/new_render/shadows.h index fd1c45d..82ded5c 100644 --- a/src/new_render/shadows.h +++ b/src/new_render/shadows.h @@ -5,11 +5,11 @@ #pragma once #include "defines.h" -#include "ral/ral_types.h" +#include "ral.h" +#include "render_types.h" typedef struct Shadow_Storage Shadow_Storage; -typedef struct RenderEnt RenderEnt; typedef struct Camera Camera; typedef struct Mat4 Mat4; diff --git a/src/new_render/skybox.h b/src/new_render/skybox.h index 10ec4f9..9bdc2ec 100644 --- a/src/new_render/skybox.h +++ b/src/new_render/skybox.h @@ -3,4 +3,30 @@ */ #pragma once +#include "backend_opengl.h" #include "defines.h" +#include "ral_types.h" + +typedef struct CubeMapData { + void* top_image_data; + void* bottom_image_data; + void* left_image_data; + void* right_image_data; + void* front_image_data; + void* back_image_data; + u32 width, height, num_channels; +} CubeMapData; + +PUB void CubeMapData_Load(const char** face_paths, int n); // should always pass n = 6 for now +PUB void CubeMapData_Free(CubeMapData* cubemap); // Frees all the image data for a cubemap +PUB TextureHandle CubeMapData_Upload(CubeMapData* cubemap); + +typedef struct Skybox { + BufferHandle vertex_buffer; + TextureHandle texture; + GPU_Pipeline* pipeline; // "shader" +} Skybox; + +PUB Skybox Skybox_Create(const char** face_paths, int n); // should always pass n = 6 for now + +PUB void Skybox_Draw(Skybox* skybox); |