From 65d448aad0e6c792b1adba1272efef73b31c4885 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 24 Oct 2025 18:33:36 -0700 Subject: Consolidate renderers --- include/gfx/llr/llr.h | 146 ----------------------------------- include/gfx/render/imm.h | 52 +++++++++++++ include/gfx/render/llr.h | 147 ++++++++++++++++++++++++++++++++++++ include/gfx/render/renderer.h | 29 +++++++ include/gfx/renderer.h | 29 ------- include/gfx/renderer/imm_renderer.h | 52 ------------- 6 files changed, 228 insertions(+), 227 deletions(-) delete mode 100644 include/gfx/llr/llr.h create mode 100644 include/gfx/render/imm.h create mode 100644 include/gfx/render/llr.h create mode 100644 include/gfx/render/renderer.h delete mode 100644 include/gfx/renderer.h delete mode 100644 include/gfx/renderer/imm_renderer.h (limited to 'include') diff --git a/include/gfx/llr/llr.h b/include/gfx/llr/llr.h deleted file mode 100644 index 6d78a50..0000000 --- a/include/gfx/llr/llr.h +++ /dev/null @@ -1,146 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include - -typedef struct Anima Anima; -typedef struct Geometry Geometry; -typedef struct Light Light; -typedef struct Material Material; -typedef struct Mesh Mesh; -typedef struct ShaderProgram ShaderProgram; -typedef struct Skeleton Skeleton; -typedef struct Texture Texture; - -typedef struct LLR LLR; - -// ----------------------------------------------------------------------------- -// Data structures. - -/// Light type. -typedef enum LightType { EnvironmentLightType } LightType; - -/// Describes an environment light. -typedef struct EnvironmentLightDesc { - const Texture* environment_map; -} EnvironmentLightDesc; - -/// Describes a light. -typedef struct LightDesc { - LightType type; - union { - EnvironmentLightDesc environment; - } light; -} LightDesc; - -/// Describes a material. -/// -/// TODO: It doesn't hold the shader program anymore...It's in the Mesh. -/// A material holds a shader program and a set of shader-specific uniform -/// variables. Two materials can share the same shader, but shader parameters -/// generally give two materials a different appearance. -typedef struct MaterialDesc { - ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL]; - int num_uniforms; -} MaterialDesc; - -/// Describes a mesh. -typedef struct MeshDesc { - const Geometry* geometry; - const Material* material; - ShaderProgram* shader; -} MeshDesc; - -/// Create a light. -Light* gfx_make_light(const LightDesc*); - -/// Destroy the light. -/// -/// The light is conveniently removed from the scene graph and its parent scene -/// node is destroyed. -void gfx_destroy_light(Light**); - -/// Create a material. -Material* gfx_make_material(const MaterialDesc*); - -/// Destroy the material. -/// -/// The caller must make sure that no Mesh points to the given Material. -/// For a safe purge of unused resources, see scene_purge(). -void gfx_destroy_material(Material**); - -/// Create a mesh. -Mesh* gfx_make_mesh(const MeshDesc*); - -/// Destroy the mesh. -/// -/// The caller must make sure that no SceneObject points to the given Mesh. -/// For a safe purge of unused resources, see scene_purge(). -void gfx_destroy_mesh(Mesh**); - -// ----------------------------------------------------------------------------- -// Low-level rendering. - -/// Set the shader to be used for subsequent draw calls. -/// The shader is not yet activated at this point. -void gfx_llr_set_shader(LLR*, ShaderProgram*); - -/// Push a light into the lights stack. -void gfx_llr_push_light(LLR*, Light*); - -/// Pop the last light from the lights stack. -void gfx_llr_pop_light(LLR*); - -/// Load a skeleton. -/// -/// If a skeleton is loaded, subsequent meshes are rendered with joint data -/// passed to the shader. This has a cost, so if subsequent meshes are not -/// animated, unload the skeleton prior to rendering them. -void gfx_llr_set_skeleton(LLR*, const Anima*, const Skeleton*); - -/// Clear the loaded skeleton. -void gfx_llr_clear_skeleton(LLR*); - -/// Set the material. -/// -/// The material need not be set explicitly when rendering a mesh -/// (gfx_llr_render_mesh). This is mostly useful when using the lower-level -/// function to render geometry (gfx_llr_render_geometry). -void gfx_llr_set_material(LLR*, const Material*); - -/// Set the camera. -void gfx_llr_set_camera(LLR*, const Camera*); - -/// Set the projection matrix. -void gfx_llr_set_projection_matrix(LLR* renderer, const mat4* projection); - -/// Set the aspect ratio. -void gfx_llr_set_aspect(LLR*, float aspect); - -/// Render the geometry. -void gfx_llr_render_geometry(LLR*, const Geometry*); - -/// Render the mesh. -void gfx_llr_render_mesh(LLR*, const Mesh*); - -// ----------------------------------------------------------------------------- -// Matrix stack manipulation. - -/// Load an identity model matrix. Clears the matrix stack. -void gfx_llr_load_identity(LLR* renderer); - -/// Push the given matrix to the matrix stack. -void gfx_llr_push_matrix(LLR* renderer, const mat4* matrix); - -/// Pop the top of the matrix stack. -void gfx_llr_pop_matrix(LLR* renderer); - -/// Push a translation matrix to the matrix stack. -void gfx_llr_translate(LLR* renderer, vec3 offset); - -/// Set the model matrix. Clears the matrix stack. -void gfx_llr_set_model_matrix(LLR*, const mat4*); diff --git a/include/gfx/render/imm.h b/include/gfx/render/imm.h new file mode 100644 index 0000000..62c071e --- /dev/null +++ b/include/gfx/render/imm.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include + +typedef struct Imm Imm; + +/// Prepare the graphics systems for immediate-mode rendering. +/// +/// Call this before issuing any immediate-mode rendering draws. +void gfx_imm_start(Imm*); + +/// End immediate mode rendering. +/// +/// Call this after issuing immediate-mode rendering draws and before swapping +/// buffers. +void gfx_imm_end(Imm*); + +/// Flush draw commands. +/// +/// This should be done when changing any state that may affect the rendering of +/// primitives; for example, LLR matrix stack changes. +void gfx_imm_flush(Imm*); + +/// Draw a set of triangles. +void gfx_imm_draw_triangles(Imm*, const vec3[], size_t num_triangles); + +/// Draw a triangle. +void gfx_imm_draw_triangle(Imm*, const vec3[3]); + +/// Draw a bounding box. +void gfx_imm_draw_aabb2(Imm*, aabb2); + +/// Draw a bounding box. +void gfx_imm_draw_aabb3(Imm*, aabb3); + +/// Draw a box. +/// +/// The vertices must be given in the following order: +/// +/// 7 ----- 6 +/// / /| +/// 3 ----- 2 | +/// | | | +/// | 4 ----- 5 +/// |/ |/ +/// 0 ----- 1 +void gfx_imm_draw_box3(Imm* renderer, const vec3 vertices[8]); + +/// Set the render colour. +void gfx_imm_set_colour(Imm*, vec4 colour); diff --git a/include/gfx/render/llr.h b/include/gfx/render/llr.h new file mode 100644 index 0000000..785f9cd --- /dev/null +++ b/include/gfx/render/llr.h @@ -0,0 +1,147 @@ +#pragma once + +#include +#include + +#include +#include +#include + +typedef struct Anima Anima; +typedef struct Geometry Geometry; +typedef struct Light Light; +typedef struct Material Material; +typedef struct Mesh Mesh; +typedef struct ShaderProgram ShaderProgram; +typedef struct Skeleton Skeleton; +typedef struct Texture Texture; + +typedef struct LLR LLR; + +// ----------------------------------------------------------------------------- +// Data structures. + +/// Light type. +typedef enum LightType { EnvironmentLightType } LightType; + +/// Describes an environment light. +typedef struct EnvironmentLightDesc { + const Texture* environment_map; +} EnvironmentLightDesc; + +/// Describes a light. +typedef struct LightDesc { + LightType type; + union { + EnvironmentLightDesc environment; + } light; +} LightDesc; + +/// Describes a material. +/// +/// TODO: It doesn't hold the shader program anymore...It's in the Mesh. +/// A material holds a shader program and a set of shader-specific uniform +/// variables. Two materials can share the same shader, but shader parameters +/// generally give two materials a different appearance. +typedef struct MaterialDesc { + ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL]; + int num_uniforms; +} MaterialDesc; + +/// Describes a mesh. +typedef struct MeshDesc { + const Geometry* geometry; + const Material* material; + ShaderProgram* shader; +} MeshDesc; + +/// Create a light. +Light* gfx_make_light(const LightDesc*); + +/// Destroy the light. +/// +/// TODO: Remove this comment. Inline node payload as described in node_impl.h +/// The light is conveniently removed from the scene graph and its parent scene +/// node is destroyed. +void gfx_destroy_light(Light**); + +/// Create a material. +Material* gfx_make_material(const MaterialDesc*); + +/// Destroy the material. +/// +/// The caller must make sure that no Mesh points to the given Material. +/// For a safe purge of unused resources, see scene_purge(). +void gfx_destroy_material(Material**); + +/// Create a mesh. +Mesh* gfx_make_mesh(const MeshDesc*); + +/// Destroy the mesh. +/// +/// The caller must make sure that no SceneObject points to the given Mesh. +/// For a safe purge of unused resources, see scene_purge(). +void gfx_destroy_mesh(Mesh**); + +// ----------------------------------------------------------------------------- +// Low-level rendering. + +/// Set the shader to be used for subsequent draw calls. +/// The shader is not yet activated at this point. +void gfx_llr_set_shader(LLR*, ShaderProgram*); + +/// Push a light into the lights stack. +void gfx_llr_push_light(LLR*, Light*); + +/// Pop the last light from the lights stack. +void gfx_llr_pop_light(LLR*); + +/// Load a skeleton. +/// +/// If a skeleton is loaded, subsequent meshes are rendered with joint data +/// passed to the shader. This has a cost, so if subsequent meshes are not +/// animated, unload the skeleton prior to rendering them. +void gfx_llr_set_skeleton(LLR*, const Anima*, const Skeleton*); + +/// Clear the loaded skeleton. +void gfx_llr_clear_skeleton(LLR*); + +/// Set the material. +/// +/// The material need not be set explicitly when rendering a mesh +/// (gfx_llr_render_mesh). This is mostly useful when using the lower-level +/// function to render geometry (gfx_llr_render_geometry). +void gfx_llr_set_material(LLR*, const Material*); + +/// Set the camera. +void gfx_llr_set_camera(LLR*, const Camera*); + +/// Set the projection matrix. +void gfx_llr_set_projection_matrix(LLR* renderer, const mat4* projection); + +/// Set the aspect ratio. +void gfx_llr_set_aspect(LLR*, float aspect); + +/// Render the geometry. +void gfx_llr_render_geometry(LLR*, const Geometry*); + +/// Render the mesh. +void gfx_llr_render_mesh(LLR*, const Mesh*); + +// ----------------------------------------------------------------------------- +// Matrix stack manipulation. + +/// Load an identity model matrix. Clears the matrix stack. +void gfx_llr_load_identity(LLR* renderer); + +/// Push the given matrix to the matrix stack. +void gfx_llr_push_matrix(LLR* renderer, const mat4* matrix); + +/// Pop the top of the matrix stack. +void gfx_llr_pop_matrix(LLR* renderer); + +/// Push a translation matrix to the matrix stack. +void gfx_llr_translate(LLR* renderer, vec3 offset); + +/// Set the model matrix. Clears the matrix stack. +void gfx_llr_set_model_matrix(LLR*, const mat4*); diff --git a/include/gfx/render/renderer.h b/include/gfx/render/renderer.h new file mode 100644 index 0000000..1da74eb --- /dev/null +++ b/include/gfx/render/renderer.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +typedef struct GfxCore GfxCore; +typedef struct Scene Scene; +typedef struct SceneCamera SceneCamera; + +typedef struct Renderer Renderer; + +typedef enum RenderSceneMode { + RenderDefault, + RenderDebug, + RenderNormals, + RenderNormalMappedNormals, + RenderTangents +} RenderSceneMode; + +typedef struct RenderSceneParams { + RenderSceneMode mode; + const Scene* scene; + const SceneCamera* camera; +} RenderSceneParams; + +/// Render the scene. +void gfx_render_scene(Renderer*, const RenderSceneParams*); + +/// Update the scene. +void gfx_update(Scene*, const SceneCamera*, R t); diff --git a/include/gfx/renderer.h b/include/gfx/renderer.h deleted file mode 100644 index 1da74eb..0000000 --- a/include/gfx/renderer.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -typedef struct GfxCore GfxCore; -typedef struct Scene Scene; -typedef struct SceneCamera SceneCamera; - -typedef struct Renderer Renderer; - -typedef enum RenderSceneMode { - RenderDefault, - RenderDebug, - RenderNormals, - RenderNormalMappedNormals, - RenderTangents -} RenderSceneMode; - -typedef struct RenderSceneParams { - RenderSceneMode mode; - const Scene* scene; - const SceneCamera* camera; -} RenderSceneParams; - -/// Render the scene. -void gfx_render_scene(Renderer*, const RenderSceneParams*); - -/// Update the scene. -void gfx_update(Scene*, const SceneCamera*, R t); diff --git a/include/gfx/renderer/imm_renderer.h b/include/gfx/renderer/imm_renderer.h deleted file mode 100644 index 62c071e..0000000 --- a/include/gfx/renderer/imm_renderer.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include -#include -#include - -typedef struct Imm Imm; - -/// Prepare the graphics systems for immediate-mode rendering. -/// -/// Call this before issuing any immediate-mode rendering draws. -void gfx_imm_start(Imm*); - -/// End immediate mode rendering. -/// -/// Call this after issuing immediate-mode rendering draws and before swapping -/// buffers. -void gfx_imm_end(Imm*); - -/// Flush draw commands. -/// -/// This should be done when changing any state that may affect the rendering of -/// primitives; for example, LLR matrix stack changes. -void gfx_imm_flush(Imm*); - -/// Draw a set of triangles. -void gfx_imm_draw_triangles(Imm*, const vec3[], size_t num_triangles); - -/// Draw a triangle. -void gfx_imm_draw_triangle(Imm*, const vec3[3]); - -/// Draw a bounding box. -void gfx_imm_draw_aabb2(Imm*, aabb2); - -/// Draw a bounding box. -void gfx_imm_draw_aabb3(Imm*, aabb3); - -/// Draw a box. -/// -/// The vertices must be given in the following order: -/// -/// 7 ----- 6 -/// / /| -/// 3 ----- 2 | -/// | | | -/// | 4 ----- 5 -/// |/ |/ -/// 0 ----- 1 -void gfx_imm_draw_box3(Imm* renderer, const vec3 vertices[8]); - -/// Set the render colour. -void gfx_imm_set_colour(Imm*, vec4 colour); -- cgit v1.2.3