From 1ec46bead3cf87971a2329f9ef4ddde5a0c48325 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 4 Jul 2025 10:27:06 -0700 Subject: Clarify doc --- include/gfx/core.h | 3 ++ include/gfx/llr/light.h | 30 +++++++++++ include/gfx/llr/llr.h | 117 +++++++++++++++++++++++++++++++++++++++++++ include/gfx/llr/material.h | 25 +++++++++ include/gfx/llr/mesh.h | 23 +++++++++ include/gfx/scene/light.h | 30 ----------- include/gfx/scene/material.h | 25 --------- include/gfx/scene/mesh.h | 23 --------- 8 files changed, 198 insertions(+), 78 deletions(-) create mode 100644 include/gfx/llr/light.h create mode 100644 include/gfx/llr/llr.h create mode 100644 include/gfx/llr/material.h create mode 100644 include/gfx/llr/mesh.h delete mode 100644 include/gfx/scene/light.h delete mode 100644 include/gfx/scene/material.h delete mode 100644 include/gfx/scene/mesh.h (limited to 'include') diff --git a/include/gfx/core.h b/include/gfx/core.h index 2a29003..0cf4465 100644 --- a/include/gfx/core.h +++ b/include/gfx/core.h @@ -474,6 +474,9 @@ void gfx_deactivate_shader_program(const ShaderProgram*); /// /// This function should be called after setting all of the uniform variables /// and prior to issuing a draw call. +/// +/// The given program must have been activated prior to this call with +/// gfx_activate_shader_program(). void gfx_apply_uniforms(const ShaderProgram*); /// Set the texture uniform. diff --git a/include/gfx/llr/light.h b/include/gfx/llr/light.h new file mode 100644 index 0000000..132e344 --- /dev/null +++ b/include/gfx/llr/light.h @@ -0,0 +1,30 @@ +#pragma once + +typedef struct Texture Texture; + +typedef struct Light Light; + +/// 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; + +/// 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**); diff --git a/include/gfx/llr/llr.h b/include/gfx/llr/llr.h new file mode 100644 index 0000000..49b7706 --- /dev/null +++ b/include/gfx/llr/llr.h @@ -0,0 +1,117 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +typedef struct Anima Anima; +typedef struct Light Light; +typedef struct Mesh Mesh; +typedef struct Skeleton Skeleton; + +typedef struct ImmRenderer ImmRenderer; + +/// Prepare the graphics systems for immediate-mode rendering. +/// +/// Call this before issuing any immediate-mode rendering draws. +void gfx_imm_start(ImmRenderer*); + +/// End immediate mode rendering. +/// +/// Call this after issuing immediate-mode rendering draws and before swapping +/// buffers. +void gfx_imm_end(ImmRenderer*); + +// ----------------------------------------------------------------------------- +// Immediate-mode rendering of scene elements. +// +// This renders models and meshes under lighting. It is up to the client to +// determine visibility, sort the calls optimally, etc. + +/// Push a light into the lights stack. +void gfx_imm_push_light(ImmRenderer*, Light*); + +/// Pop the last light from the lights stack. +void gfx_imm_pop_light(ImmRenderer*); + +/// 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_imm_set_skeleton(ImmRenderer*, const Anima*, const Skeleton*); + +/// Unload the loaded skeleton. +void gfx_imm_unset_skeleton(ImmRenderer*); + +/// Render the mesh. +void gfx_imm_render_mesh(ImmRenderer*, const Mesh*); + +// ----------------------------------------------------------------------------- +// Immediate-mode rendering of primitives. +// +// This is rather inefficient and should be reserved for debug rendering. It +// also does not support lighting; the primitives are rendered with a constant +// colour. + +/// Draw a set of triangles. +void gfx_imm_draw_triangles(ImmRenderer*, const vec3[], size_t num_triangles); + +/// Draw a triangle. +void gfx_imm_draw_triangle(ImmRenderer*, const vec3[3]); + +/// Draw a bounding box. +void gfx_imm_draw_aabb2(ImmRenderer*, aabb2); + +/// Draw a bounding box. +void gfx_imm_draw_aabb3(ImmRenderer*, 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(ImmRenderer* renderer, const vec3 vertices[8]); + +/// Set the render colour. +void gfx_imm_set_colour(ImmRenderer*, vec4 colour); + +// ----------------------------------------------------------------------------- +// Matrix stack manipulation. +// +// Common to both scene and and primitive rendering. + +/// Load an identity model matrix. Clears the matrix stack. +void gfx_imm_load_identity(ImmRenderer* renderer); + +/// Push the given matrix to the matrix stack. +void gfx_imm_push_matrix(ImmRenderer* renderer, const mat4* matrix); + +/// Pop the top of the matrix stack. +void gfx_imm_pop_matrix(ImmRenderer* renderer); + +/// Push a translation matrix to the matrix stack. +void gfx_imm_translate(ImmRenderer* renderer, vec3 offset); + +/// Set the model matrix. Clears the matrix stack. +void gfx_imm_set_model_matrix(ImmRenderer*, const mat4*); + +// ----------------------------------------------------------------------------- +// Camera +// +// Common to both scene and and primitive rendering. + +/// Set the camera. +void gfx_imm_set_camera(ImmRenderer*, const Camera*); + +/// Set the view-projection matrix. +// void gfx_imm_set_view_projection_matrix(ImmRenderer*, const mat4*); diff --git a/include/gfx/llr/material.h b/include/gfx/llr/material.h new file mode 100644 index 0000000..bca664e --- /dev/null +++ b/include/gfx/llr/material.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +typedef struct Material Material; + +/// Describes a material. +/// +/// 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; + +/// 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**); diff --git a/include/gfx/llr/mesh.h b/include/gfx/llr/mesh.h new file mode 100644 index 0000000..0d3b4d4 --- /dev/null +++ b/include/gfx/llr/mesh.h @@ -0,0 +1,23 @@ +#pragma once + +typedef struct Geometry Geometry; +typedef struct Material Material; +typedef struct ShaderProgram ShaderProgram; + +typedef struct Mesh Mesh; + +/// Describes a mesh. +typedef struct MeshDesc { + const Geometry* geometry; + const Material* material; + ShaderProgram* shader; +} MeshDesc; + +/// 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**); diff --git a/include/gfx/scene/light.h b/include/gfx/scene/light.h deleted file mode 100644 index 132e344..0000000 --- a/include/gfx/scene/light.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -typedef struct Texture Texture; - -typedef struct Light Light; - -/// 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; - -/// 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**); diff --git a/include/gfx/scene/material.h b/include/gfx/scene/material.h deleted file mode 100644 index bca664e..0000000 --- a/include/gfx/scene/material.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -typedef struct Material Material; - -/// Describes a material. -/// -/// 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; - -/// 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**); diff --git a/include/gfx/scene/mesh.h b/include/gfx/scene/mesh.h deleted file mode 100644 index 0d3b4d4..0000000 --- a/include/gfx/scene/mesh.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -typedef struct Geometry Geometry; -typedef struct Material Material; -typedef struct ShaderProgram ShaderProgram; - -typedef struct Mesh Mesh; - -/// Describes a mesh. -typedef struct MeshDesc { - const Geometry* geometry; - const Material* material; - ShaderProgram* shader; -} MeshDesc; - -/// 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**); -- cgit v1.2.3