diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h index 0d85ca6789..feff3e2710 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h @@ -55,8 +55,6 @@ #define GPU_STEREO_CAMERA_BUFFER #endif -#define GPU_BINDLESS_TEXTURES 0 - namespace gpu { namespace gl { class GLBackend : public Backend, public std::enable_shared_from_this { diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index 22b5ad87e0..c23a83eaf9 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -20,6 +20,7 @@ #define INCREMENTAL_TRANSFER 0 #define GPU_SSBO_TRANSFORM_OBJECT 1 +#define GPU_BINDLESS_TEXTURES 0 namespace gpu { namespace gl45 { @@ -92,20 +93,11 @@ public: private: mutable Bindless _bindless; #endif - class InvalidSampler : public Sampler { - public: - InvalidSampler() { - _desc._borderColor = vec4(-1.0f); - } - operator const Sampler&() const { - return *this; - } - }; + static Sampler getInvalidSampler(); - static const Sampler INVALID_SAMPLER; // This stores the texture handle (64 bits) in xy, the min mip available in z, and the sampler ID in w - mutable Sampler _cachedSampler{ INVALID_SAMPLER }; + mutable Sampler _cachedSampler{ getInvalidSampler() }; }; #if GPU_BINDLESS_TEXTURES diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 3791a9802b..5a5d701150 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -163,7 +163,18 @@ private: }; static GLSamplerCache SAMPLER_CACHE; -const Sampler GL45Texture::INVALID_SAMPLER = GL45Texture::InvalidSampler(); + + +Sampler GL45Texture::getInvalidSampler() { + static Sampler INVALID_SAMPLER; + static std::once_flag once; + std::call_once(once, [] { + Sampler::Desc invalidDesc; + invalidDesc._borderColor = vec4(-1.0f); + INVALID_SAMPLER = Sampler(invalidDesc); + }); + return INVALID_SAMPLER; +} GL45Texture::GL45Texture(const std::weak_ptr& backend, const Texture& texture) : GLTexture(backend, texture, allocate(texture)) { diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index 150ea7a488..08d077605d 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -185,7 +185,7 @@ void GL45ResourceTexture::promote() { glDeleteTextures(1, &oldId); // Update sampler - _cachedSampler = InvalidSampler(); + _cachedSampler = getInvalidSampler(); syncSampler(); // update the memory usage @@ -228,7 +228,7 @@ void GL45ResourceTexture::demote() { glDeleteTextures(1, &oldId); // Update sampler - _cachedSampler = InvalidSampler(); + _cachedSampler = getInvalidSampler(); syncSampler(); // update the memory usage diff --git a/libraries/gpu/src/gpu/TextureTable.cpp b/libraries/gpu/src/gpu/TextureTable.cpp index 40f3decc83..0c3a43808b 100644 --- a/libraries/gpu/src/gpu/TextureTable.cpp +++ b/libraries/gpu/src/gpu/TextureTable.cpp @@ -11,6 +11,9 @@ #include using namespace gpu; + +const size_t TextureTable::COUNT{ TEXTURE_TABLE_COUNT }; + TextureTable::TextureTable() { } TextureTable::TextureTable(const std::initializer_list& textures) { @@ -23,7 +26,7 @@ TextureTable::TextureTable(const std::initializer_list& textures } } -TextureTable::TextureTable(const std::array& textures) : _stamp(1), _textures(textures) { +TextureTable::TextureTable(const Array& textures) : _textures(textures) { } void TextureTable::setTexture(size_t index, const TexturePointer& texturePointer) { diff --git a/libraries/gpu/src/gpu/TextureTable.h b/libraries/gpu/src/gpu/TextureTable.h index 02b777bbd6..794b8535d0 100644 --- a/libraries/gpu/src/gpu/TextureTable.h +++ b/libraries/gpu/src/gpu/TextureTable.h @@ -12,15 +12,17 @@ #include +#define TEXTURE_TABLE_COUNT 8 + namespace gpu { class TextureTable { public: - static const size_t COUNT = 8; - using Array = std::array; + static const size_t COUNT; + using Array = std::array; TextureTable(); TextureTable(const std::initializer_list& textures); - TextureTable(const std::array& textures); + TextureTable(const Array& textures); // Only for gpu::Context const GPUObjectPointer gpuObject{}; @@ -34,7 +36,7 @@ public: private: mutable Mutex _mutex; Array _textures; - Stamp _stamp{ 0 }; + Stamp _stamp{ 1 }; }; }