From 3db2b6fe574ce7d2e0b49720f0453b824a4d8312 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 5 Jan 2023 17:17:39 -0800 Subject: Move skyquad node setup to util. --- gltfview/src/game.c | 62 ++++++++++------------------------------------------- 1 file changed, 11 insertions(+), 51 deletions(-) (limited to 'gltfview') diff --git a/gltfview/src/game.c b/gltfview/src/game.c index bd474d6..54e498b 100644 --- a/gltfview/src/game.c +++ b/gltfview/src/game.c @@ -55,7 +55,7 @@ static ShaderProgram* load_shader( return shader; } -/// Loads the skyquad texture. +/// Load the skyquad texture. static Texture* load_environment_map(RenderBackend* render_backend) { return gfx_load_texture( render_backend, @@ -75,60 +75,20 @@ static Texture* load_environment_map(RenderBackend* render_backend) { }); } -/// Creates an object to render the skyquad in the background. -static SceneNode* make_skyquad_object_node( - Game* game, const Texture* environment_map) { +/// Load the skyquad and return the environment light node. +static SceneNode* load_skyquad(Game* game) { assert(game); - SceneObject* skyquad_object = - gfx_make_skyquad(game->gfx, game->scene, environment_map); - if (!skyquad_object) { - return 0; - } - SceneNode* skyquad_node = gfx_make_object_node(skyquad_object); - if (!skyquad_node) { - return 0; - } - gfx_set_node_parent(skyquad_node, gfx_get_scene_root(game->scene)); - return skyquad_node; -} - -/// Creates an environment light. -static SceneNode* make_environment_light( - Game* game, const Texture* environment_light) { - assert(game); - - Light* light = gfx_make_light(&(LightDesc){ - .type = EnvironmentLightType, - .light = (EnvironmentLightDesc){.environment_map = environment_light}}); - if (!light) { - return 0; - } - SceneNode* light_node = gfx_make_light_node(light); - if (!light_node) { - return 0; - } - gfx_set_node_parent(light_node, gfx_get_scene_root(game->scene)); - return light_node; -} - -/// Loads the skyquad and returns the SceneNode with the environment light. -static bool load_skyquad(Game* game, SceneNode** node) { - assert(game); - assert(node); - Texture* environment_map = load_environment_map(game->render_backend); if (!environment_map) { - return false; + return 0; } - make_skyquad_object_node(game, environment_map); - *node = make_environment_light(game, environment_map); - - return true; + return gfx_setup_skyquad( + game->gfx, gfx_get_scene_root(game->scene), environment_map); } -/// Loads the 3D scene. +/// Load the 3D scene. static bool load_scene( Game* game, const char* scene_filepath, const char* view_mode) { assert(game); @@ -143,8 +103,8 @@ static bool load_scene( // Damaged helmet. spatial3_set_position(&camera->spatial, vec3_make(0, 0, 2)); - SceneNode* sky_node = 0; - if (!load_skyquad(game, &sky_node) || !sky_node) { + SceneNode* sky_light_node = load_skyquad(game); + if (!sky_light_node) { return false; } @@ -155,7 +115,7 @@ static bool load_scene( // } if (!gfx_load_scene( - game->gfx, sky_node, + game->gfx, sky_light_node, &(LoadSceneCmd){ .origin = SceneFromFile, .filepath = scene_filepath})) { return false; @@ -164,7 +124,7 @@ static bool load_scene( return true; } -/// Loads a scene for debugging textures. +/// Load a scene for debugging textures. static bool load_texture_debugger_scene(Game* game) { assert(game); -- cgit v1.2.3