From 0dc3a9df980630b671bbc5df69503c2e72dcf004 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sun, 2 Nov 2025 18:18:56 -0800 Subject: Consolidate scene data structures --- include/gfx/core.h | 3 ++ include/gfx/render/llr.h | 79 +----------------------------------- include/gfx/scene.h | 101 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 97 insertions(+), 86 deletions(-) (limited to 'include') diff --git a/include/gfx/core.h b/include/gfx/core.h index 25b8779..8f01081 100644 --- a/include/gfx/core.h +++ b/include/gfx/core.h @@ -482,6 +482,9 @@ void gfx_deactivate_shader_program(const ShaderProgram*); /// gfx_activate_shader_program(). void gfx_apply_uniforms(const ShaderProgram*); +/// Set the uniform. +void gfx_set_uniform(ShaderProgram* prog, const ShaderUniform* uniform); + /// Set the int uniform. /// Has no effect if the shader does not contain the given uniform. void gfx_set_int_uniform(ShaderProgram*, const char* name, int value); diff --git a/include/gfx/render/llr.h b/include/gfx/render/llr.h index b30b11e..6f635b6 100644 --- a/include/gfx/render/llr.h +++ b/include/gfx/render/llr.h @@ -1,13 +1,10 @@ #pragma once -#include -#include - -#include -#include +#include #include typedef struct Anima Anima; +typedef struct Camera Camera; typedef struct Geometry Geometry; typedef struct Light Light; typedef struct Material Material; @@ -18,78 +15,6 @@ typedef struct Texture Texture; typedef struct LLR LLR; -// TODO: Move data structures to scene.h? -// ----------------------------------------------------------------------------- -// 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; - -/// Alpha mode. -typedef enum AlphaMode { Opaque = 0, Mask = 1, Blend = 2 } AlphaMode; - -/// 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 { - AlphaMode alpha_mode; - float alpha_cutoff; - int num_uniforms; - ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL]; -} 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. // ----------------------------------------------------------------------------- diff --git a/include/gfx/scene.h b/include/gfx/scene.h index 9747da7..3aa6e0e 100644 --- a/include/gfx/scene.h +++ b/include/gfx/scene.h @@ -1,18 +1,19 @@ #pragma once -#include +#include #include #include #include #include -typedef struct Anima Anima; -typedef struct Camera Camera; -typedef struct Light Light; -typedef struct Mesh Mesh; -typedef struct Model Model; -typedef struct Scene Scene; +typedef struct Anima Anima; +typedef struct Camera Camera; +typedef struct Light Light; +typedef struct Material Material; +typedef struct Mesh Mesh; +typedef struct Model Model; +typedef struct Scene Scene; /// A node in the scene graph. /// /// Scene nodes take ownership of the object they are associated with (Camera, @@ -20,6 +21,46 @@ typedef struct Scene Scene; typedef struct SceneNode SceneNode; typedef struct SceneObject SceneObject; typedef struct Skeleton Skeleton; +typedef struct Texture Texture; + +/// 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; + +/// Alpha mode. +typedef enum AlphaMode { Opaque = 0, Mask = 1, Blend = 2 } AlphaMode; + +/// 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 { + AlphaMode alpha_mode; + float alpha_cutoff; + int num_uniforms; + ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL]; +} MaterialDesc; + +/// Describes a mesh. +typedef struct MeshDesc { + const Geometry* geometry; + const Material* material; + ShaderProgram* shader; +} MeshDesc; typedef struct ObjectDesc { size_t num_meshes; @@ -44,8 +85,50 @@ typedef enum NodeType { Camera* gfx_make_camera(void); /// Destroy the camera. +/// +/// The caller must make sure that no Node owns the given Camera. +/// For a safe purge of unused resources, see scene_purge(). void gfx_destroy_camera(Camera**); +// ----------------------------------------------------------------------------- +// Light. +// ----------------------------------------------------------------------------- + +/// Create a light. +Light* gfx_make_light(const LightDesc*); + +/// Destroy the light. +/// +/// The caller must make sure that no Node owns the given Light. +/// For a safe purge of unused resources, see scene_purge(). +void gfx_destroy_light(Light**); + +// ----------------------------------------------------------------------------- +// Material. +// ----------------------------------------------------------------------------- + +/// 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**); + +// ----------------------------------------------------------------------------- +// Mesh. +// ----------------------------------------------------------------------------- + +/// 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**); + // ----------------------------------------------------------------------------- // Model. // ----------------------------------------------------------------------------- @@ -66,8 +149,8 @@ SceneObject* gfx_make_object(const ObjectDesc*); /// Destroy the object. /// -/// The object is conveniently removed from the scene graph and its parent scene -/// node is destroyed. +/// The caller must make sure that no Node owns the given SceneObject. +/// For a safe purge of unused resources, see scene_purge(). void gfx_destroy_object(SceneObject**); /// Set the object's skeleton. -- cgit v1.2.3