diff options
Diffstat (limited to 'gltfview')
-rw-r--r-- | gltfview/src/game.c | 62 |
1 files changed, 11 insertions, 51 deletions
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( | |||
55 | return shader; | 55 | return shader; |
56 | } | 56 | } |
57 | 57 | ||
58 | /// Loads the skyquad texture. | 58 | /// Load the skyquad texture. |
59 | static Texture* load_environment_map(RenderBackend* render_backend) { | 59 | static Texture* load_environment_map(RenderBackend* render_backend) { |
60 | return gfx_load_texture( | 60 | return gfx_load_texture( |
61 | render_backend, | 61 | render_backend, |
@@ -75,60 +75,20 @@ static Texture* load_environment_map(RenderBackend* render_backend) { | |||
75 | }); | 75 | }); |
76 | } | 76 | } |
77 | 77 | ||
78 | /// Creates an object to render the skyquad in the background. | 78 | /// Load the skyquad and return the environment light node. |
79 | static SceneNode* make_skyquad_object_node( | 79 | static SceneNode* load_skyquad(Game* game) { |
80 | Game* game, const Texture* environment_map) { | ||
81 | assert(game); | 80 | assert(game); |
82 | 81 | ||
83 | SceneObject* skyquad_object = | ||
84 | gfx_make_skyquad(game->gfx, game->scene, environment_map); | ||
85 | if (!skyquad_object) { | ||
86 | return 0; | ||
87 | } | ||
88 | SceneNode* skyquad_node = gfx_make_object_node(skyquad_object); | ||
89 | if (!skyquad_node) { | ||
90 | return 0; | ||
91 | } | ||
92 | gfx_set_node_parent(skyquad_node, gfx_get_scene_root(game->scene)); | ||
93 | return skyquad_node; | ||
94 | } | ||
95 | |||
96 | /// Creates an environment light. | ||
97 | static SceneNode* make_environment_light( | ||
98 | Game* game, const Texture* environment_light) { | ||
99 | assert(game); | ||
100 | |||
101 | Light* light = gfx_make_light(&(LightDesc){ | ||
102 | .type = EnvironmentLightType, | ||
103 | .light = (EnvironmentLightDesc){.environment_map = environment_light}}); | ||
104 | if (!light) { | ||
105 | return 0; | ||
106 | } | ||
107 | SceneNode* light_node = gfx_make_light_node(light); | ||
108 | if (!light_node) { | ||
109 | return 0; | ||
110 | } | ||
111 | gfx_set_node_parent(light_node, gfx_get_scene_root(game->scene)); | ||
112 | return light_node; | ||
113 | } | ||
114 | |||
115 | /// Loads the skyquad and returns the SceneNode with the environment light. | ||
116 | static bool load_skyquad(Game* game, SceneNode** node) { | ||
117 | assert(game); | ||
118 | assert(node); | ||
119 | |||
120 | Texture* environment_map = load_environment_map(game->render_backend); | 82 | Texture* environment_map = load_environment_map(game->render_backend); |
121 | if (!environment_map) { | 83 | if (!environment_map) { |
122 | return false; | 84 | return 0; |
123 | } | 85 | } |
124 | 86 | ||
125 | make_skyquad_object_node(game, environment_map); | 87 | return gfx_setup_skyquad( |
126 | *node = make_environment_light(game, environment_map); | 88 | game->gfx, gfx_get_scene_root(game->scene), environment_map); |
127 | |||
128 | return true; | ||
129 | } | 89 | } |
130 | 90 | ||
131 | /// Loads the 3D scene. | 91 | /// Load the 3D scene. |
132 | static bool load_scene( | 92 | static bool load_scene( |
133 | Game* game, const char* scene_filepath, const char* view_mode) { | 93 | Game* game, const char* scene_filepath, const char* view_mode) { |
134 | assert(game); | 94 | assert(game); |
@@ -143,8 +103,8 @@ static bool load_scene( | |||
143 | // Damaged helmet. | 103 | // Damaged helmet. |
144 | spatial3_set_position(&camera->spatial, vec3_make(0, 0, 2)); | 104 | spatial3_set_position(&camera->spatial, vec3_make(0, 0, 2)); |
145 | 105 | ||
146 | SceneNode* sky_node = 0; | 106 | SceneNode* sky_light_node = load_skyquad(game); |
147 | if (!load_skyquad(game, &sky_node) || !sky_node) { | 107 | if (!sky_light_node) { |
148 | return false; | 108 | return false; |
149 | } | 109 | } |
150 | 110 | ||
@@ -155,7 +115,7 @@ static bool load_scene( | |||
155 | // } | 115 | // } |
156 | 116 | ||
157 | if (!gfx_load_scene( | 117 | if (!gfx_load_scene( |
158 | game->gfx, sky_node, | 118 | game->gfx, sky_light_node, |
159 | &(LoadSceneCmd){ | 119 | &(LoadSceneCmd){ |
160 | .origin = SceneFromFile, .filepath = scene_filepath})) { | 120 | .origin = SceneFromFile, .filepath = scene_filepath})) { |
161 | return false; | 121 | return false; |
@@ -164,7 +124,7 @@ static bool load_scene( | |||
164 | return true; | 124 | return true; |
165 | } | 125 | } |
166 | 126 | ||
167 | /// Loads a scene for debugging textures. | 127 | /// Load a scene for debugging textures. |
168 | static bool load_texture_debugger_scene(Game* game) { | 128 | static bool load_texture_debugger_scene(Game* game) { |
169 | assert(game); | 129 | assert(game); |
170 | 130 | ||