From 946266e823c07025f115b5e4f5523b496dcb393e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 30 Sep 2014 00:07:20 +0300 Subject: [PATCH] Better handling of unloaded textures Since it's no longer guaranteed that calling ResourceManager::resource_used will result in Resource::load being called, it's better to avoid the binding logic entirely in the unloaded case. In particular, parameters must not be updated until the GL texture object has been created. Generating an ID for the texture has been delayed to the last phase of loading to further differentiate the loaded and unloaded states. --- source/texture.cpp | 11 +++++++++++ source/texture2d.cpp | 7 +++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/source/texture.cpp b/source/texture.cpp index 0fa65ead..cf08ac63 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -181,6 +181,17 @@ void Texture::set_compare_func(Predicate f) void Texture::bind_to(unsigned i) const { + if(!id) + { + if(manager) + manager->resource_used(*this); + if(!id) + { + unbind_from(i); + return; + } + } + TexUnit &unit = TexUnit::get_unit(i); const Texture *cur = unit.get_texture(); if(unit.set_texture(this)) diff --git a/source/texture2d.cpp b/source/texture2d.cpp index e237e504..2ea713eb 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -207,10 +207,7 @@ Texture2D::AsyncLoader::AsyncLoader(Texture2D &t, IO::Seekable &i): pixel_buffer(PIXEL_UNPACK_BUFFER), mapped_address(0), phase(0) -{ - if(!texture.id) - glGenTextures(1, &texture.id); -} +{ } bool Texture2D::AsyncLoader::needs_sync() const { @@ -245,6 +242,8 @@ bool Texture2D::AsyncLoader::process() return false; } + if(!texture.id) + glGenTextures(1, &texture.id); texture.image(image, false, true); } -- 2.43.0