]> git.tdb.fi Git - libs/gl.git/commitdiff
Defer retrieval of default resources in Renderer until needed
authorMikko Rasa <tdb@tdb.fi>
Thu, 17 Aug 2023 11:53:22 +0000 (14:53 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 17 Aug 2023 11:53:22 +0000 (14:53 +0300)
This allows the Renderer to work when no resources are present. provided
that all resources are explicitly supplied.

source/render/renderer.cpp
source/render/renderer.h

index 0e3a770ad1de8826803eb7dfe24feba35800a013..362285453c17e1632a9d3b7943132d3918a5bc33 100644 (file)
@@ -24,9 +24,7 @@ namespace GL {
 const Tag Renderer::world_obj_matrix_tag("world_obj_matrix");
 const Tag Renderer::world_obj_normal_matrix_tag("world_obj_normal_matrix");
 
-Renderer::Renderer():
-       placeholder_texture(Resources::get_global().get<Texture>("_placeholder.png")),
-       default_sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp"))
+Renderer::Renderer()
 {
        state_stack.reserve(16);
        shdata_stack.reserve(32);
@@ -180,9 +178,17 @@ void Renderer::set_texture(Tag tag, const Texture *tex, int level, const Sampler
                if(ResourceManager *res_mgr = tex->get_manager())
                        res_mgr->resource_used(*tex);
                if(!tex->is_loaded())
-                       tex = &placeholder_texture;
+               {
+                       if(!placeholder_texture)
+                               placeholder_texture = &Resources::get_global().get<Texture>("_placeholder.png");
+                       tex = placeholder_texture;
+               }
                if(!samp)
-                       samp = &default_sampler;
+               {
+                       if(!default_sampler)
+                               default_sampler = &Resources::get_global().get<Sampler>("_linear_clamp.samp");
+                       samp = default_sampler;
+               }
        }
        else
                samp = 0;
index 3ba5e64d2cd4a532afb229c5a6472ab4b7c83f81..b8ab02443961fd12aa693102a21eb9a0d4f40c14 100644 (file)
@@ -129,8 +129,8 @@ private:
        std::vector<BoundProgramData> shdata_stack;
        std::vector<BoundResource<const Buffer *>> buffer_stack;
        std::vector<BoundResource<SampledTexture>> texture_stack;
-       const Texture &placeholder_texture;
-       const Sampler &default_sampler;
+       const Texture *placeholder_texture = 0;
+       const Sampler *default_sampler = 0;
        PipelineState *last_pipeline = 0;
        Commands commands;