From: Mikko Rasa Date: Sun, 2 Jan 2022 11:15:01 +0000 (+0200) Subject: Use a placeholder texture when a texture has not been loaded yet X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b4941cd1f0b0b5d9cebc978379b4936a5070ca92;p=libs%2Fgl.git Use a placeholder texture when a texture has not been loaded yet --- diff --git a/Build b/Build index b46c5ad4..16e9537c 100644 --- 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 index 00000000..e1d35445 Binary files /dev/null and b/builtin_data/_placeholder.png differ diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index d3124f0d..4beb2da7 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -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("_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) { diff --git a/source/render/renderer.h b/source/render/renderer.h index fe13a882..f08ea0b2 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -108,6 +108,7 @@ private: ProgramData standard_shdata; std::vector shdata_stack; std::vector texture_stack; + const Texture &placeholder_texture; Commands commands; public: