diff --git a/src/graphics/render.nim b/src/graphics/render.nim index d580959..fbb0e5e 100644 --- a/src/graphics/render.nim +++ b/src/graphics/render.nim @@ -192,7 +192,24 @@ proc draw_all*(self: RenderManager) = continue scene.update_all_matrices() scene.update_lights() - # TODO: render probes required by cameras of enabled screens + # TODO: move this + var update_probe_ubo = false + for probe in scene.cubemap_probes: + let upd = case probe.update_strategy: + of UpdateNever: false + of UpdateOnFirstUse: + # TODO: detect when relevant objects are fully loaded + # and also when anything that affects it is visible and + # nearby + not probe.used + of UpdateAlways: true + if upd: + probe.render_cubemap(true) + probe.used = true + update_probe_ubo = true + if update_probe_ubo: + scene.cubemap_UBO.update() + # TODO: render shadows required by cameras of enabled screens for screen in self.engine.screens: if not screen.enabled: diff --git a/src/loaders/blend.nim b/src/loaders/blend.nim index c0cea54..67591a9 100644 --- a/src/loaders/blend.nim +++ b/src/loaders/blend.nim @@ -584,13 +584,18 @@ method loadScene*(self: BlendLoader, name: string="", scene: Scene=nil, callback if scn["id"]["name"].cstr == idname.cstring: let node = scn var scene = scene + let was_first_scene = self.engine.scenes.len == 0 if scene == nil: scene = self.engine.new_scene(name=name) self.loadSceneImpl(node, scene) callback(scene) + # TODO: when loading is async, move this stuff after loading has + # finished + if was_first_scene and not scene.enabled: + echo "Warning: Your scene is not enabled, use 'scene.enable_render()' or 'scene.enable_all()'" + scene.render_all_cubemaps(true) return assert false, &"Scene {name} not found" proc debug_dump*(self: BlendLoader) = - self.blend_file.debug_dump - + self.blend_file.debug_dump \ No newline at end of file diff --git a/src/objects/cubemap_probe.nim b/src/objects/cubemap_probe.nim index 340faee..1f0196f 100644 --- a/src/objects/cubemap_probe.nim +++ b/src/objects/cubemap_probe.nim @@ -96,6 +96,7 @@ proc newCubemapProbe*(engine: MyouEngine, name: string="camera", scene: Scene = parallax_distance else: influence_distance + self.update_strategy = UpdateOnFirstUse return self diff --git a/src/scene.nim b/src/scene.nim index b689804..92f0342 100644 --- a/src/scene.nim +++ b/src/scene.nim @@ -351,6 +351,17 @@ proc destroy*(self: Scene) = self.engine.scenes.del(self.name) return +proc enable_render*(self: Scene) = + self.enabled = true + +proc enable_physics*(self: Scene) = + if self.world != nil: + self.world.enabled = true + +proc enable_all*(self: Scene) = + self.enable_render() + self.enable_physics() + proc new_gameobject*(self: Scene, name: string): GameObject = return self.engine.new_gameobject(name=name, scene=self) @@ -528,10 +539,6 @@ proc get_lighting_code*(self: Scene): string = code.add staticOrDebugRead "shadows/simple_shadow.glsl" return code.join "\n" - -# template as_float_array(x: untyped): untyped = -# cast[array[sizeof(typeof(x)) div 4, float]](x) - proc update_lights*(self: Scene) = if self.lighting_UBOs.len == 0: return diff --git a/src/types.nim b/src/types.nim index e3bb9bf..1872e40 100644 --- a/src/types.nim +++ b/src/types.nim @@ -694,6 +694,11 @@ type # cubemap_probe.nim + ProbeUpdateStrategy* = enum + UpdateNever + UpdateOnFirstUse + UpdateAlways + ProbeInfluenceType* = enum SphereInfluence BoxInfluence @@ -715,6 +720,8 @@ type intensity*: float32 clipping_start*: float32 clipping_end*: float32 + update_strategy*: ProbeUpdateStrategy + used*: bool # NOTE: layout must match struct CubemapInfo in scene.nim CubemapProbeUniform* = object @@ -761,6 +768,8 @@ type parent_object*: GameObject World* = ref object of RootObj + enabled*: bool + DebugDraw* = ref object of RootObj Body* = ref object @@ -824,12 +833,15 @@ type BlendLoader* = ref object of Loader cached_materials*: Table[(FNode, string, bool), (string, seq[Varying], OrderedTable[string, string], OrderedTable[string, TexturePixels])] ## private resource*: LoadableResource - -template enqueue*(self: RenderManager, fun: proc()) = - if self.initialized: + +template enqueue*(renderer: RenderManager, fun: proc()) = + ## Run a proc after the renderer has been initialized. + ## + ## If it was already initialized, it runs it immediately. + if renderer.initialized: fun() else: - self.queue.add fun + renderer.queue.add fun when not defined(release): from sugar import dump