diff options
author | Omniscient <omniscient.oce@gmail.com> | 2024-07-11 18:03:34 +1000 |
---|---|---|
committer | Omniscient <omniscient.oce@gmail.com> | 2024-07-11 18:03:34 +1000 |
commit | 9f23f65ec631bcd08f200b3ef517da8acf8d6b17 (patch) | |
tree | bc0e9d9fc0c687b646ddcb5c44122bfc70b4cfed /src | |
parent | 65d74bdb26af833b5380046dec204f685f745cc1 (diff) |
new
Diffstat (limited to 'src')
-rw-r--r-- | src/new_render/draw.h | 13 | ||||
-rw-r--r-- | src/new_render/render.h | 0 | ||||
-rw-r--r-- | src/new_render/render_scene.h | 20 | ||||
-rw-r--r-- | src/new_render/render_types.h | 59 | ||||
-rw-r--r-- | src/systems/terrain.c | 32 | ||||
-rw-r--r-- | src/systems/terrain.h | 44 |
6 files changed, 133 insertions, 35 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/render.h b/src/new_render/render.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/new_render/render.h 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..13a45a4 --- /dev/null +++ b/src/new_render/render_types.h @@ -0,0 +1,59 @@ +/** + * @file render_types.h + * @brief +*/ + +#pragma once +#include "defines.h" +#include "ral.h" +#include "maths.h" + +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; + +// --- 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 Model { + // meshes + // materials +} Model; + +// --- 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; diff --git a/src/systems/terrain.c b/src/systems/terrain.c index 6342d66..a8e8b48 100644 --- a/src/systems/terrain.c +++ b/src/systems/terrain.c @@ -11,14 +11,28 @@ #include "terrain.h" #include "ral.h" -bool terrain_system_init(terrain_state* state) { - gpu_renderpass_desc rpass_desc = { - .default_framebuffer = true, - }; - struct graphics_pipeline_desc pipeline_desc = { +struct Terrain_Storage { + arena terrain_allocator; + heightmap* heightmap; // NULL = no heightmap + GPU_Renderpass* hmap_renderpass; + GPU_Pipeline* hmap_pipeline; +}; - }; +PUB bool Terrain_Init(Terrain_Storage* storage) { - state->hmap_renderpass = gpu_renderpass_create(&rpass_desc); - state->hmap_pipeline = gpu_graphics_pipeline_create(pipeline_desc); -}
\ No newline at end of file + return true; +} +PUB void Terrain_Shutdown(Terrain_Storage* storage); + + +/* bool terrain_system_init(terrain_state* state) { */ +/* gpu_renderpass_desc rpass_desc = { */ +/* .default_framebuffer = true, */ +/* }; */ +/* struct graphics_pipeline_desc pipeline_desc = { */ + +/* }; */ + +/* state->hmap_renderpass = gpu_renderpass_create(&rpass_desc); */ +/* state->hmap_pipeline = gpu_graphics_pipeline_create(pipeline_desc); */ +/* } */ diff --git a/src/systems/terrain.h b/src/systems/terrain.h index 888b6f4..a65ecec 100644 --- a/src/systems/terrain.h +++ b/src/systems/terrain.h @@ -1,14 +1,10 @@ /** * @file terrain.h - * @author your name (you@domain.com) * @brief - * @version 0.1 - * @date 2024-04-27 - * - * @copyright Copyright (c) 2024 - * */ +#pragma once + /* Future: - Chunked terrain @@ -22,37 +18,33 @@ Future: #include "render.h" #include "str.h" -typedef struct heightmap { +typedef struct Heightmap { str8 filepath; u32x2 size; void* image_data; bool is_uploaded; -} heightmap; +} Heightmap; + +typedef struct Terrain_Storage Terrain_Storage; + +// --- Public API +PUB bool Terrain_Init(Terrain_Storage* storage); +PUB void Terrain_Shutdown(Terrain_Storage* storage); +PUB void Terrain_Run(Terrain_Storage* storage); // NOTE: For now it renders directly to main framebuffer -typedef struct terrain_state { - arena terrain_allocator; - heightmap* heightmap; // NULL = no heightmap - gpu_renderpass* hmap_renderpass; - gpu_pipeline* hmap_pipeline; -} terrain_state; +PUB Heightmap Heightmap_FromImage(str8 filepath); +PUB Heightmap Heightmap_FromPerlin(/* TODO: perlin noise generation parameters */); -bool terrain_system_init(terrain_state* state); -void terrain_system_shutdown(terrain_state* state); -void terrain_system_render_hmap(renderer* rend, terrain_state* state); +// --- Internal -heightmap heightmap_from_image(str8 filepath); -heightmap heightmap_from_perlin(/* TODO: perlin noise generation parameters */); +// TODO: void terrain_system_render_hmap(renderer* rend, terrain_state* state); /** @brief Get the height (the Y component) for a vertex at a particular coordinate in the heightmap */ -f32 heightmap_height_at_xz(heightmap* hmap, f32 x, f32 z); +f32 Heightmap_HeightXZ(Heightmap* hmap, f32 x, f32 z); /** @brief Calculate the normal vector of a vertex at a particular coordinate in the heightmap */ -vec3 heightmap_normal_at_xz(heightmap* hmap, f32 x, f32 z); +Vec3 Heightmap_NormalXZ(Heightmap* hmap, f32 x, f32 z); /** @brief Generate the `geometry_data` for a heightmap ready to be uploaded to the GPU */ -geometry_data geo_heightmap(arena* a, heightmap heightmap); - -// somewhere there will be an easy way to add a heightmap - -// TODO: scene_add_heightmap +Geometry geo_heightmap(arena* a, Heightmap heightmap); |