diff options
Diffstat (limited to 'src/new_render')
-rw-r--r-- | src/new_render/draw.h | 13 | ||||
-rw-r--r-- | src/new_render/immdraw.h | 14 | ||||
-rw-r--r-- | src/new_render/pbr.h | 62 | ||||
-rw-r--r-- | src/new_render/render.c | 34 | ||||
-rw-r--r-- | src/new_render/render.h | 54 | ||||
-rw-r--r-- | src/new_render/render_scene.h | 20 | ||||
-rw-r--r-- | src/new_render/render_types.h | 86 | ||||
-rw-r--r-- | src/new_render/shadows.h | 29 | ||||
-rw-r--r-- | src/new_render/skybox.h | 32 |
9 files changed, 344 insertions, 0 deletions
diff --git a/src/new_render/draw.h b/src/new_render/draw.h new file mode 100644 index 0000000..58e104e --- /dev/null +++ b/src/new_render/draw.h @@ -0,0 +1,13 @@ +/** + * @file draw.h + * @brief + */ +#pragma once +#include "defines.h" +#include "maths_types.h" +#include "render_types.h" + +// --- Public APIs + +PUB void EncodeDrawModel(Handle model, Mat4 transform); +PUB void EncodeDrawMesh(Mesh* mesh, Material* material, Mat4 affine); diff --git a/src/new_render/immdraw.h b/src/new_render/immdraw.h new file mode 100644 index 0000000..c2c3a24 --- /dev/null +++ b/src/new_render/immdraw.h @@ -0,0 +1,14 @@ +/** + * @brief Immediate-mode drawing APIs + */ + +#pragma once +#include "defines.h" +#include "maths_types.h" + +// --- Public API + + +void Immdraw_Cuboid(Transform tf); +void Immdraw_Sphere(Transform tf, f32 size); +void Immdraw_TransformGizmo(Transform tf, f32 size); diff --git a/src/new_render/pbr.h b/src/new_render/pbr.h new file mode 100644 index 0000000..7573563 --- /dev/null +++ b/src/new_render/pbr.h @@ -0,0 +1,62 @@ +/** + * @file pbr.h + * @brief PBR render pass + */ + +#pragma once +#include "defines.h" +#include "camera.h" +#include "maths_types.h" +#include "ral/ral.h" +#include "ral/ral_common.h" + +// PBR; + +// --- Public API +typedef struct PBR_Storage PBR_Storage; // Stores all necessary data and handles + +PUB void PBR_Init(PBR_Storage* storage); + +// NOTE: For simplicity's sake we will render this pass directly to the default framebuffer +PUB void PBR_Run( + PBR_Storage* storage + // light data + // camera + // geometry + // materials +); + +typedef struct PBR_Params { + Vec3 albedo; + f32 metallic; + f32 roughness; + f32 ao; +} PBR_Params; + +typedef struct PBR_Textures { + TextureHandle albedo_map; + TextureHandle normal_map; + bool metal_roughness_combined; + TextureHandle metallic_map; + TextureHandle roughness_map; + TextureHandle ao_map; +} PBR_Textures; + +// --- Internal + +typedef struct MaterialMap MaterialMap; +typedef struct RenderEnt RenderEnt; + +GPU_Renderpass* PBR_RPassCreate(); +GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass); +void PBR_Execute( + PBR_Storage* storage, + Camera camera, + TextureHandle shadowmap_tex, + MaterialMap* materials, // map of String -> Material + RenderEnt* entities, + size_t entity_count + +); + +// Internally this will need to update material parameters diff --git a/src/new_render/render.c b/src/new_render/render.c new file mode 100644 index 0000000..f5547d5 --- /dev/null +++ b/src/new_render/render.c @@ -0,0 +1,34 @@ +/** + * @brief + */ + +#include "render.h" +#include "maths_types.h" +#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; + struct ResourcePools* resource_pools; +}; + +bool Renderer_Init(RendererConfig config, Renderer* renderer) { + // set the RAL backend up + + // create our renderpasses + Shadow_Init(renderer->shadows); + + return true; +} diff --git a/src/new_render/render.h b/src/new_render/render.h new file mode 100644 index 0000000..b0b5495 --- /dev/null +++ b/src/new_render/render.h @@ -0,0 +1,54 @@ +/** + * @brief + */ + +#pragma once +#include "defines.h" +#include "maths_types.h" +#include "ral_types.h" +#include "render_types.h" + +typedef struct Renderer Renderer; +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); + +/** @brief */ +PUB void Render_RenderEntities(RenderEnt* entities, size_t entity_count); + +// TODO: Render_FrameDraw(); - this will + +// --- 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_scene.h b/src/new_render/render_scene.h new file mode 100644 index 0000000..7591d8f --- /dev/null +++ b/src/new_render/render_scene.h @@ -0,0 +1,20 @@ +/** + * @file render_scene.h + * @brief + */ +#pragma once +#include "defines.h" +#include "render_types.h" +#include "camera.h" + +/** @brief Holds globally bound data for rendering a scene. Typically held by the renderer. + * Whenever you call draw functions you can think of this as an implicit parameter. */ +typedef struct RenderScene { + Camera camera; + PointLight light; +} RenderScene; + +// --- Public APIs + +PUB void SetCamera(Camera camera); +PUB void SetPointLight(PointLight light); diff --git a/src/new_render/render_types.h b/src/new_render/render_types.h new file mode 100644 index 0000000..b27bf2f --- /dev/null +++ b/src/new_render/render_types.h @@ -0,0 +1,86 @@ +/** + * @file render_types.h + * @brief +*/ + +#pragma once +#include "defines.h" +#include "maths_types.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; + Vertex_darray* vertices; + bool has_indices; + u32_darray* indices; +} Geometry; + +typedef struct u32_opt { + u32 value; + bool has_value; +} u32_opt; + +typedef struct Mesh { + BufferHandle vextex_buffer; + BufferHandle index_buffer; + Geometry* geometry; // NULL means it has been freed CPU-side + 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, + MAT_PBR, + MAT_PBR_PARAMS, // uses float values to represent a surface uniformly + MAT_COUNT +} MaterialKind; +static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)", + "Count (This should be an error)" }; + +typedef struct Material { + char name[64]; +} Material; + +typedef struct Model { + // meshes + // materials +} Model; + +// TODO: function to create a model from a single mesh (like when using primitives) + +// --- Lights +typedef struct PointLight { + Vec3 position; + f32 constant, linear, quadratic; + Vec3 ambient; + Vec3 diffuse; + Vec3 specular; +} PointLight; + +typedef struct DirectionalLight { + Vec3 direction; + Vec3 ambient; + Vec3 diffuse; + Vec3 specular; +} DirectionalLight; + +// --- + +// A renderable 'thing' +typedef struct RenderEnt { + ModelHandle model; + Mat4 affine; // In the future this should be updated by the transform graph + // Bbox_3D bounding_box; + bool casts_shadows; +} RenderEnt; diff --git a/src/new_render/shadows.h b/src/new_render/shadows.h new file mode 100644 index 0000000..82ded5c --- /dev/null +++ b/src/new_render/shadows.h @@ -0,0 +1,29 @@ +/** + * @brief Functions for adding shadows to scene rendering. +*/ + + +#pragma once +#include "defines.h" +#include "ral.h" +#include "render_types.h" + +typedef struct Shadow_Storage Shadow_Storage; + +typedef struct Camera Camera; +typedef struct Mat4 Mat4; + +// --- Public API +PUB void Shadow_Init(Shadow_Storage* storage); + +/** @brief Run shadow map generation for given entities, and store in a texture. + * @note Uses active directional light for now */ +PUB void Shadow_Run(Shadow_Storage* storage, RenderEnt* entities, size_t entity_count); + +/** @brief Get the shadow texture generated from shadowmap pass */ +PUB Handle Shadow_GetShadowMapTexture(Shadow_Storage* storage); + +// --- Internal +GPU_Renderpass* Shadow_RPassCreate(); // Creates the render pass +GPU_Pipeline* Shadow_PipelineCreate(GPU_Renderpass* rpass); // Creates the pipeline +void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform, RenderEnt* entites, size_t entity_count); diff --git a/src/new_render/skybox.h b/src/new_render/skybox.h new file mode 100644 index 0000000..9bdc2ec --- /dev/null +++ b/src/new_render/skybox.h @@ -0,0 +1,32 @@ +/** + * @brief + */ + +#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); |