summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-02-17 14:47:48 -0800
committer3gg <3gg@shellblade.net>2024-02-17 14:47:48 -0800
commit25cad97b0b265885d6abc56fefb3f6d58984bc0a (patch)
tree38d5bc633fd4e83b24bea8ae0bc74c6565628eff
parent6799f7bd263202d8697c5e27bf12f4e66e4c0ed1 (diff)
Fix constness of node.
-rw-r--r--gfx/include/gfx/scene/model.h4
-rw-r--r--gfx/include/gfx/scene/node.h26
-rw-r--r--gfx/src/renderer/renderer.c6
-rw-r--r--gfx/src/scene/model.c2
-rw-r--r--gfx/src/scene/node.c35
5 files changed, 48 insertions, 25 deletions
diff --git a/gfx/include/gfx/scene/model.h b/gfx/include/gfx/scene/model.h
index c55fc8c..42f85d4 100644
--- a/gfx/include/gfx/scene/model.h
+++ b/gfx/include/gfx/scene/model.h
@@ -9,6 +9,4 @@ Anima* gfx_get_model_anima(Model*);
9 9
10/// Return the model's root node. 10/// Return the model's root node.
11const SceneNode* gfx_get_model_root(const Model*); 11const SceneNode* gfx_get_model_root(const Model*);
12 12SceneNode* gfx_get_model_root_mut(Model*);
13/// Return the model's root node.
14SceneNode* gfx_get_model_root_mut(Model*);
diff --git a/gfx/include/gfx/scene/node.h b/gfx/include/gfx/scene/node.h
index 77db85c..a2c2836 100644
--- a/gfx/include/gfx/scene/node.h
+++ b/gfx/include/gfx/scene/node.h
@@ -80,50 +80,50 @@ void gfx_destroy_node(SceneNode**);
80// Getters. 80// Getters.
81// ----------------------------------------------------------------------------- 81// -----------------------------------------------------------------------------
82 82
83// TODO: Review constness of getters here.
84
85/// Get the node's type. 83/// Get the node's type.
86NodeType gfx_get_node_type(const SceneNode*); 84NodeType gfx_get_node_type(const SceneNode*);
87 85
88/// Get the node's anima. 86/// Get the node's anima.
89/// 87///
90/// The node must be of type AnimaNode. 88/// The node must be of type AnimaNode.
91Anima* gfx_get_node_anima(const SceneNode*); 89const Anima* gfx_get_node_anima(const SceneNode*);
90Anima* gfx_get_node_anima_mut(SceneNode*);
92 91
93/// Get the node's camera. 92/// Get the node's camera.
94/// 93///
95/// The node must be of type CameraNode. 94/// The node must be of type CameraNode.
96SceneCamera* gfx_get_node_camera(const SceneNode* node); 95const SceneCamera* gfx_get_node_camera(const SceneNode* node);
96SceneCamera* gfx_get_node_camera_mut(SceneNode* node);
97 97
98/// Get the node's light. 98/// Get the node's light.
99/// 99///
100/// The node must be of type LightNode. 100/// The node must be of type LightNode.
101Light* gfx_get_node_light(const SceneNode*); 101const Light* gfx_get_node_light(const SceneNode*);
102Light* gfx_get_node_light_mut(SceneNode*);
102 103
103/// Get the node's model. 104/// Get the node's model.
104/// 105///
105/// The node must be of type ModelNode. 106/// The node must be of type ModelNode.
106Model* gfx_get_node_model(const SceneNode*); 107const Model* gfx_get_node_model(const SceneNode*);
108Model* gfx_get_node_model_mut(SceneNode*);
107 109
108/// Get the node's scene object. 110/// Get the node's scene object.
109/// 111///
110/// The node must be of type ObjectNode. 112/// The node must be of type ObjectNode.
111SceneObject* gfx_get_node_object(const SceneNode*); 113const SceneObject* gfx_get_node_object(const SceneNode*);
114SceneObject* gfx_get_node_object_mut(SceneNode*);
112 115
113/// Get the node's parent. 116/// Get the node's parent.
114const SceneNode* gfx_get_node_parent(const SceneNode*); 117const SceneNode* gfx_get_node_parent(const SceneNode*);
118SceneNode* gfx_get_node_parent_mut(SceneNode*);
115 119
116/// Get the node's first child. 120/// Get the node's first child.
117const SceneNode* gfx_get_node_child(const SceneNode*); 121const SceneNode* gfx_get_node_child(const SceneNode*);
118 122SceneNode* gfx_get_node_child_mut(SceneNode*);
119/// Get the node's first child.
120SceneNode* gfx_get_node_child_mut(SceneNode*);
121 123
122/// Get the node's immediate sibling. 124/// Get the node's immediate sibling.
123const SceneNode* gfx_get_node_sibling(const SceneNode*); 125const SceneNode* gfx_get_node_sibling(const SceneNode*);
124 126SceneNode* gfx_get_node_sibling_mut(SceneNode*);
125/// Get the node's immediate sibling.
126SceneNode* gfx_get_node_sibling_mut(SceneNode*);
127 127
128/// Get the node's (local) transform. 128/// Get the node's (local) transform.
129mat4 gfx_get_node_transform(const SceneNode*); 129mat4 gfx_get_node_transform(const SceneNode*);
diff --git a/gfx/src/renderer/renderer.c b/gfx/src/renderer/renderer.c
index c72f719..dbfc62b 100644
--- a/gfx/src/renderer/renderer.c
+++ b/gfx/src/renderer/renderer.c
@@ -180,7 +180,7 @@ typedef struct RenderState {
180 const float fovy; 180 const float fovy;
181 const float aspect; 181 const float aspect;
182 Light* environment_light; 182 Light* environment_light;
183 Anima* anima; 183 const Anima* anima;
184 size_t num_joints; 184 size_t num_joints;
185 mat4 joint_matrices[GFX_MAX_NUM_JOINTS]; 185 mat4 joint_matrices[GFX_MAX_NUM_JOINTS];
186} RenderState; 186} RenderState;
@@ -373,10 +373,10 @@ static void update_rec(SceneNode* node, const SceneCamera* camera, R t) {
373 // TODO: Models do not need to be animated if they are not visible to the 373 // TODO: Models do not need to be animated if they are not visible to the
374 // camera. 374 // camera.
375 if (node_type == AnimaNode) { 375 if (node_type == AnimaNode) {
376 Anima* anima = gfx_get_node_anima(node); 376 Anima* anima = gfx_get_node_anima_mut(node);
377 gfx_update_animation(anima, (R)t); 377 gfx_update_animation(anima, (R)t);
378 } else if (node_type == ModelNode) { 378 } else if (node_type == ModelNode) {
379 Model* model = gfx_get_node_model(node); 379 Model* model = gfx_get_node_model_mut(node);
380 SceneNode* root = gfx_get_model_root_mut(model); 380 SceneNode* root = gfx_get_model_root_mut(model);
381 update_rec(root, camera, t); 381 update_rec(root, camera, t);
382 } 382 }
diff --git a/gfx/src/scene/model.c b/gfx/src/scene/model.c
index 507c478..cc41a9a 100644
--- a/gfx/src/scene/model.c
+++ b/gfx/src/scene/model.c
@@ -29,7 +29,7 @@ Anima* gfx_get_model_anima(Model* model) {
29 29
30 SceneNode* root = mem_get_node(model->root); 30 SceneNode* root = mem_get_node(model->root);
31 if (gfx_get_node_type(root) == AnimaNode) { 31 if (gfx_get_node_type(root) == AnimaNode) {
32 return gfx_get_node_anima(root); 32 return gfx_get_node_anima_mut(root);
33 } else { 33 } else {
34 return 0; 34 return 0;
35 } 35 }
diff --git a/gfx/src/scene/node.c b/gfx/src/scene/node.c
index 05f6428..67ce93c 100644
--- a/gfx/src/scene/node.c
+++ b/gfx/src/scene/node.c
@@ -209,23 +209,43 @@ NodeType gfx_get_node_type(const SceneNode* node) {
209 return mem_get_##field(node->field); \ 209 return mem_get_##field(node->field); \
210 } 210 }
211 211
212Anima* gfx_get_node_anima(const SceneNode* node) { 212const Anima* gfx_get_node_anima(const SceneNode* node) {
213 NODE_GET(node, anima, AnimaNode); 213 NODE_GET(node, anima, AnimaNode);
214} 214}
215 215
216SceneCamera* gfx_get_node_camera(const SceneNode* node) { 216Anima* gfx_get_node_anima_mut(SceneNode* node) {
217 NODE_GET(node, anima, AnimaNode);
218}
219
220const SceneCamera* gfx_get_node_camera(const SceneNode* node) {
221 NODE_GET(node, camera, CameraNode);
222}
223
224SceneCamera* gfx_get_node_camera_mut(SceneNode* node) {
217 NODE_GET(node, camera, CameraNode); 225 NODE_GET(node, camera, CameraNode);
218} 226}
219 227
220Light* gfx_get_node_light(const SceneNode* node) { 228const Light* gfx_get_node_light(const SceneNode* node) {
221 NODE_GET(node, light, LightNode); 229 NODE_GET(node, light, LightNode);
222} 230}
223 231
224Model* gfx_get_node_model(const SceneNode* node) { 232Light* gfx_get_node_light_mut(SceneNode* node) {
233 NODE_GET(node, light, LightNode);
234}
235
236const Model* gfx_get_node_model(const SceneNode* node) {
225 NODE_GET(node, model, ModelNode); 237 NODE_GET(node, model, ModelNode);
226} 238}
227 239
228SceneObject* gfx_get_node_object(const SceneNode* node) { 240Model* gfx_get_node_model_mut(SceneNode* node) {
241 NODE_GET(node, model, ModelNode);
242}
243
244const SceneObject* gfx_get_node_object(const SceneNode* node) {
245 NODE_GET(node, object, ObjectNode);
246}
247
248SceneObject* gfx_get_node_object_mut(SceneNode* node) {
229 NODE_GET(node, object, ObjectNode); 249 NODE_GET(node, object, ObjectNode);
230} 250}
231 251
@@ -234,6 +254,11 @@ const SceneNode* gfx_get_node_parent(const SceneNode* node) {
234 return mem_get_node(node->parent); 254 return mem_get_node(node->parent);
235} 255}
236 256
257SceneNode* gfx_get_node_parent_mut(SceneNode* node) {
258 assert(node);
259 return mem_get_node(node->parent);
260}
261
237const SceneNode* gfx_get_node_child(const SceneNode* node) { 262const SceneNode* gfx_get_node_child(const SceneNode* node) {
238 assert(node); 263 assert(node);
239 if (node->child.val) { 264 if (node->child.val) {