diff options
| author | 3gg <3gg@shellblade.net> | 2025-11-02 18:18:56 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-11-02 18:18:56 -0800 |
| commit | 0dc3a9df980630b671bbc5df69503c2e72dcf004 (patch) | |
| tree | 1b46c45ecf8842f8aa3d24c542f28719452f8a46 /include | |
| parent | 3e559ab467857e49941d08b91873ceaa6d1f9d8d (diff) | |
Consolidate scene data structures
Diffstat (limited to 'include')
| -rw-r--r-- | include/gfx/core.h | 3 | ||||
| -rw-r--r-- | include/gfx/render/llr.h | 79 | ||||
| -rw-r--r-- | include/gfx/scene.h | 101 |
3 files changed, 97 insertions, 86 deletions
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*); | |||
| 482 | /// gfx_activate_shader_program(). | 482 | /// gfx_activate_shader_program(). |
| 483 | void gfx_apply_uniforms(const ShaderProgram*); | 483 | void gfx_apply_uniforms(const ShaderProgram*); |
| 484 | 484 | ||
| 485 | /// Set the uniform. | ||
| 486 | void gfx_set_uniform(ShaderProgram* prog, const ShaderUniform* uniform); | ||
| 487 | |||
| 485 | /// Set the int uniform. | 488 | /// Set the int uniform. |
| 486 | /// Has no effect if the shader does not contain the given uniform. | 489 | /// Has no effect if the shader does not contain the given uniform. |
| 487 | void gfx_set_int_uniform(ShaderProgram*, const char* name, int value); | 490 | 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 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include <gfx/core.h> | 3 | #include <math/fwd.h> |
| 4 | #include <gfx/sizes.h> | ||
| 5 | |||
| 6 | #include <math/camera.h> | ||
| 7 | #include <math/mat4.h> | ||
| 8 | #include <math/vec3.h> | 4 | #include <math/vec3.h> |
| 9 | 5 | ||
| 10 | typedef struct Anima Anima; | 6 | typedef struct Anima Anima; |
| 7 | typedef struct Camera Camera; | ||
| 11 | typedef struct Geometry Geometry; | 8 | typedef struct Geometry Geometry; |
| 12 | typedef struct Light Light; | 9 | typedef struct Light Light; |
| 13 | typedef struct Material Material; | 10 | typedef struct Material Material; |
| @@ -18,78 +15,6 @@ typedef struct Texture Texture; | |||
| 18 | 15 | ||
| 19 | typedef struct LLR LLR; | 16 | typedef struct LLR LLR; |
| 20 | 17 | ||
| 21 | // TODO: Move data structures to scene.h? | ||
| 22 | // ----------------------------------------------------------------------------- | ||
| 23 | // Data structures. | ||
| 24 | // ----------------------------------------------------------------------------- | ||
| 25 | |||
| 26 | /// Light type. | ||
| 27 | typedef enum LightType { EnvironmentLightType } LightType; | ||
| 28 | |||
| 29 | /// Describes an environment light. | ||
| 30 | typedef struct EnvironmentLightDesc { | ||
| 31 | const Texture* environment_map; | ||
| 32 | } EnvironmentLightDesc; | ||
| 33 | |||
| 34 | /// Describes a light. | ||
| 35 | typedef struct LightDesc { | ||
| 36 | LightType type; | ||
| 37 | union { | ||
| 38 | EnvironmentLightDesc environment; | ||
| 39 | } light; | ||
| 40 | } LightDesc; | ||
| 41 | |||
| 42 | /// Alpha mode. | ||
| 43 | typedef enum AlphaMode { Opaque = 0, Mask = 1, Blend = 2 } AlphaMode; | ||
| 44 | |||
| 45 | /// Describes a material. | ||
| 46 | /// | ||
| 47 | /// TODO: It doesn't hold the shader program anymore...It's in the Mesh. | ||
| 48 | /// A material holds a shader program and a set of shader-specific uniform | ||
| 49 | /// variables. Two materials can share the same shader, but shader parameters | ||
| 50 | /// generally give two materials a different appearance. | ||
| 51 | typedef struct MaterialDesc { | ||
| 52 | AlphaMode alpha_mode; | ||
| 53 | float alpha_cutoff; | ||
| 54 | int num_uniforms; | ||
| 55 | ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL]; | ||
| 56 | } MaterialDesc; | ||
| 57 | |||
| 58 | /// Describes a mesh. | ||
| 59 | typedef struct MeshDesc { | ||
| 60 | const Geometry* geometry; | ||
| 61 | const Material* material; | ||
| 62 | ShaderProgram* shader; | ||
| 63 | } MeshDesc; | ||
| 64 | |||
| 65 | /// Create a light. | ||
| 66 | Light* gfx_make_light(const LightDesc*); | ||
| 67 | |||
| 68 | /// Destroy the light. | ||
| 69 | /// | ||
| 70 | /// TODO: Remove this comment. Inline node payload as described in node_impl.h | ||
| 71 | /// The light is conveniently removed from the scene graph and its parent scene | ||
| 72 | /// node is destroyed. | ||
| 73 | void gfx_destroy_light(Light**); | ||
| 74 | |||
| 75 | /// Create a material. | ||
| 76 | Material* gfx_make_material(const MaterialDesc*); | ||
| 77 | |||
| 78 | /// Destroy the material. | ||
| 79 | /// | ||
| 80 | /// The caller must make sure that no Mesh points to the given Material. | ||
| 81 | /// For a safe purge of unused resources, see scene_purge(). | ||
| 82 | void gfx_destroy_material(Material**); | ||
| 83 | |||
| 84 | /// Create a mesh. | ||
| 85 | Mesh* gfx_make_mesh(const MeshDesc*); | ||
| 86 | |||
| 87 | /// Destroy the mesh. | ||
| 88 | /// | ||
| 89 | /// The caller must make sure that no SceneObject points to the given Mesh. | ||
| 90 | /// For a safe purge of unused resources, see scene_purge(). | ||
| 91 | void gfx_destroy_mesh(Mesh**); | ||
| 92 | |||
| 93 | // ----------------------------------------------------------------------------- | 18 | // ----------------------------------------------------------------------------- |
| 94 | // Low-level rendering. | 19 | // Low-level rendering. |
| 95 | // ----------------------------------------------------------------------------- | 20 | // ----------------------------------------------------------------------------- |
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 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include <gfx/scene.h> | 3 | #include <gfx/core.h> |
| 4 | #include <gfx/sizes.h> | 4 | #include <gfx/sizes.h> |
| 5 | 5 | ||
| 6 | #include <math/aabb3.h> | 6 | #include <math/aabb3.h> |
| 7 | #include <math/fwd.h> | 7 | #include <math/fwd.h> |
| 8 | #include <math/mat4.h> | 8 | #include <math/mat4.h> |
| 9 | 9 | ||
| 10 | typedef struct Anima Anima; | 10 | typedef struct Anima Anima; |
| 11 | typedef struct Camera Camera; | 11 | typedef struct Camera Camera; |
| 12 | typedef struct Light Light; | 12 | typedef struct Light Light; |
| 13 | typedef struct Mesh Mesh; | 13 | typedef struct Material Material; |
| 14 | typedef struct Model Model; | 14 | typedef struct Mesh Mesh; |
| 15 | typedef struct Scene Scene; | 15 | typedef struct Model Model; |
| 16 | typedef struct Scene Scene; | ||
| 16 | /// A node in the scene graph. | 17 | /// A node in the scene graph. |
| 17 | /// | 18 | /// |
| 18 | /// Scene nodes take ownership of the object they are associated with (Camera, | 19 | /// Scene nodes take ownership of the object they are associated with (Camera, |
| @@ -20,6 +21,46 @@ typedef struct Scene Scene; | |||
| 20 | typedef struct SceneNode SceneNode; | 21 | typedef struct SceneNode SceneNode; |
| 21 | typedef struct SceneObject SceneObject; | 22 | typedef struct SceneObject SceneObject; |
| 22 | typedef struct Skeleton Skeleton; | 23 | typedef struct Skeleton Skeleton; |
| 24 | typedef struct Texture Texture; | ||
| 25 | |||
| 26 | /// Light type. | ||
| 27 | typedef enum LightType { EnvironmentLightType } LightType; | ||
| 28 | |||
| 29 | /// Describes an environment light. | ||
| 30 | typedef struct EnvironmentLightDesc { | ||
| 31 | const Texture* environment_map; | ||
| 32 | } EnvironmentLightDesc; | ||
| 33 | |||
| 34 | /// Describes a light. | ||
| 35 | typedef struct LightDesc { | ||
| 36 | LightType type; | ||
| 37 | union { | ||
| 38 | EnvironmentLightDesc environment; | ||
| 39 | } light; | ||
| 40 | } LightDesc; | ||
| 41 | |||
| 42 | /// Alpha mode. | ||
| 43 | typedef enum AlphaMode { Opaque = 0, Mask = 1, Blend = 2 } AlphaMode; | ||
| 44 | |||
| 45 | /// Describes a material. | ||
| 46 | /// | ||
| 47 | /// TODO: It doesn't hold the shader program anymore...It's in the Mesh. | ||
| 48 | /// A material holds a shader program and a set of shader-specific uniform | ||
| 49 | /// variables. Two materials can share the same shader, but shader parameters | ||
| 50 | /// generally give two materials a different appearance. | ||
| 51 | typedef struct MaterialDesc { | ||
| 52 | AlphaMode alpha_mode; | ||
| 53 | float alpha_cutoff; | ||
| 54 | int num_uniforms; | ||
| 55 | ShaderUniform uniforms[GFX_MAX_UNIFORMS_PER_MATERIAL]; | ||
| 56 | } MaterialDesc; | ||
| 57 | |||
| 58 | /// Describes a mesh. | ||
| 59 | typedef struct MeshDesc { | ||
| 60 | const Geometry* geometry; | ||
| 61 | const Material* material; | ||
| 62 | ShaderProgram* shader; | ||
| 63 | } MeshDesc; | ||
| 23 | 64 | ||
| 24 | typedef struct ObjectDesc { | 65 | typedef struct ObjectDesc { |
| 25 | size_t num_meshes; | 66 | size_t num_meshes; |
| @@ -44,9 +85,51 @@ typedef enum NodeType { | |||
| 44 | Camera* gfx_make_camera(void); | 85 | Camera* gfx_make_camera(void); |
| 45 | 86 | ||
| 46 | /// Destroy the camera. | 87 | /// Destroy the camera. |
| 88 | /// | ||
| 89 | /// The caller must make sure that no Node owns the given Camera. | ||
| 90 | /// For a safe purge of unused resources, see scene_purge(). | ||
| 47 | void gfx_destroy_camera(Camera**); | 91 | void gfx_destroy_camera(Camera**); |
| 48 | 92 | ||
| 49 | // ----------------------------------------------------------------------------- | 93 | // ----------------------------------------------------------------------------- |
| 94 | // Light. | ||
| 95 | // ----------------------------------------------------------------------------- | ||
| 96 | |||
| 97 | /// Create a light. | ||
| 98 | Light* gfx_make_light(const LightDesc*); | ||
| 99 | |||
| 100 | /// Destroy the light. | ||
| 101 | /// | ||
| 102 | /// The caller must make sure that no Node owns the given Light. | ||
| 103 | /// For a safe purge of unused resources, see scene_purge(). | ||
| 104 | void gfx_destroy_light(Light**); | ||
| 105 | |||
| 106 | // ----------------------------------------------------------------------------- | ||
| 107 | // Material. | ||
| 108 | // ----------------------------------------------------------------------------- | ||
| 109 | |||
| 110 | /// Create a material. | ||
| 111 | Material* gfx_make_material(const MaterialDesc*); | ||
| 112 | |||
| 113 | /// Destroy the material. | ||
| 114 | /// | ||
| 115 | /// The caller must make sure that no Mesh points to the given Material. | ||
| 116 | /// For a safe purge of unused resources, see scene_purge(). | ||
| 117 | void gfx_destroy_material(Material**); | ||
| 118 | |||
| 119 | // ----------------------------------------------------------------------------- | ||
| 120 | // Mesh. | ||
| 121 | // ----------------------------------------------------------------------------- | ||
| 122 | |||
| 123 | /// Create a mesh. | ||
| 124 | Mesh* gfx_make_mesh(const MeshDesc*); | ||
| 125 | |||
| 126 | /// Destroy the mesh. | ||
| 127 | /// | ||
| 128 | /// The caller must make sure that no SceneObject points to the given Mesh. | ||
| 129 | /// For a safe purge of unused resources, see scene_purge(). | ||
| 130 | void gfx_destroy_mesh(Mesh**); | ||
| 131 | |||
| 132 | // ----------------------------------------------------------------------------- | ||
| 50 | // Model. | 133 | // Model. |
| 51 | // ----------------------------------------------------------------------------- | 134 | // ----------------------------------------------------------------------------- |
| 52 | 135 | ||
| @@ -66,8 +149,8 @@ SceneObject* gfx_make_object(const ObjectDesc*); | |||
| 66 | 149 | ||
| 67 | /// Destroy the object. | 150 | /// Destroy the object. |
| 68 | /// | 151 | /// |
| 69 | /// The object is conveniently removed from the scene graph and its parent scene | 152 | /// The caller must make sure that no Node owns the given SceneObject. |
| 70 | /// node is destroyed. | 153 | /// For a safe purge of unused resources, see scene_purge(). |
| 71 | void gfx_destroy_object(SceneObject**); | 154 | void gfx_destroy_object(SceneObject**); |
| 72 | 155 | ||
| 73 | /// Set the object's skeleton. | 156 | /// Set the object's skeleton. |
