]> git.tdb.fi Git - libs/gl.git/commitdiff
Use a placeholder texture when a texture has not been loaded yet
authorMikko Rasa <tdb@tdb.fi>
Sun, 2 Jan 2022 11:15:01 +0000 (13:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 2 Jan 2022 11:15:01 +0000 (13:15 +0200)
Build
builtin_data/_placeholder.png [new file with mode: 0644]
source/render/renderer.cpp
source/render/renderer.h

diff --git a/Build b/Build
index b46c5ad4c40d8c80c9dbc315af4be6abd40f02d0..16e9537c0ce5d7cd5d0f2d488bb90ea3aeae10e6 100644 (file)
--- a/Build
+++ b/Build
@@ -44,6 +44,7 @@ package "mspgl"
                in_suffix ".glsl";
                in_suffix ".samp";
                in_suffix ".mesh";
+               in_suffix ".png";
                out_suffix ".cpp";
                command "mspdatatool";
                arguments "-i" "-n" "Msp::GL";
diff --git a/builtin_data/_placeholder.png b/builtin_data/_placeholder.png
new file mode 100644 (file)
index 0000000..e1d3544
Binary files /dev/null and b/builtin_data/_placeholder.png differ
index d3124f0da334c7439e630266db0eef7c8c4654cf..4beb2da7eca300d13450806b65d2eb503cd71f8e 100644 (file)
@@ -10,6 +10,7 @@
 #include "renderable.h"
 #include "renderer.h"
 #include "resourcemanager.h"
+#include "resources.h"
 #include "sampler.h"
 #include "texture.h"
 #include "vertexarray.h"
@@ -20,7 +21,8 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Renderer::Renderer()
+Renderer::Renderer():
+       placeholder_texture(Resources::get_global().get<Texture>("_placeholder.png"))
 {
        state_stack.reserve(16);
        shdata_stack.reserve(32);
@@ -148,8 +150,12 @@ void Renderer::set_texture(Tag tag, const Texture *tex, int level, const Sampler
        State &state = get_state();
 
        if(tex)
+       {
                if(ResourceManager *res_mgr = tex->get_manager())
                        res_mgr->resource_used(*tex);
+               if(!tex->is_loaded())
+                       tex = &placeholder_texture;
+       }
 
        if(texture_stack.size()>state.texture_count)
        {
index fe13a882430f5407b4175d1aa481f776df86d009..f08ea0b2d5bfa305c0ab1af8aeacf980e5ef79b1 100644 (file)
@@ -108,6 +108,7 @@ private:
        ProgramData standard_shdata;
        std::vector<BoundProgramData> shdata_stack;
        std::vector<BoundTexture> texture_stack;
+       const Texture &placeholder_texture;
        Commands commands;
 
 public: