From 57ca8f2bd18525d80ed6ad5d3f72e57901162d55 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 7 Oct 2021 11:19:44 +0300 Subject: [PATCH] Always delay texture creation until it is allocated This allows greateer flexibility with setting a resource manager. --- source/backends/opengl/texture1d_backend.cpp | 3 +++ source/backends/opengl/texture2d_backend.cpp | 3 +++ source/backends/opengl/texture2dmultisample_backend.cpp | 3 +++ source/backends/opengl/texture3d_backend.cpp | 3 +++ source/backends/opengl/texture_backend.cpp | 5 +---- source/backends/opengl/texture_backend.h | 2 +- source/backends/opengl/texturecube_backend.cpp | 3 +++ source/core/texture.cpp | 6 +----- source/core/texture2d.cpp | 4 ---- 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/source/backends/opengl/texture1d_backend.cpp b/source/backends/opengl/texture1d_backend.cpp index e44ceb4e..bd754fde 100644 --- a/source/backends/opengl/texture1d_backend.cpp +++ b/source/backends/opengl/texture1d_backend.cpp @@ -19,6 +19,9 @@ void OpenGLTexture1D::allocate() unsigned width = static_cast(this)->width; unsigned levels = static_cast(this)->levels; + if(!id) + generate_id(); + GLenum gl_fmt = get_gl_pixelformat(storage_fmt); if(ARB_texture_storage) { diff --git a/source/backends/opengl/texture2d_backend.cpp b/source/backends/opengl/texture2d_backend.cpp index 71a998dc..725b6038 100644 --- a/source/backends/opengl/texture2d_backend.cpp +++ b/source/backends/opengl/texture2d_backend.cpp @@ -41,6 +41,9 @@ void OpenGLTexture2D::allocate() unsigned height = static_cast(this)->height; unsigned levels = static_cast(this)->levels; + if(!id) + generate_id(); + GLenum gl_fmt = get_gl_pixelformat(storage_fmt); if(ARB_texture_storage) { diff --git a/source/backends/opengl/texture2dmultisample_backend.cpp b/source/backends/opengl/texture2dmultisample_backend.cpp index c4a4e423..71f9e138 100644 --- a/source/backends/opengl/texture2dmultisample_backend.cpp +++ b/source/backends/opengl/texture2dmultisample_backend.cpp @@ -19,6 +19,9 @@ void OpenGLTexture2DMultisample::allocate() unsigned height = static_cast(this)->height; unsigned samples = static_cast(this)->samples; + if(!id) + generate_id(); + GLenum gl_fmt = get_gl_pixelformat(storage_fmt); if(ARB_texture_storage_multisample) { diff --git a/source/backends/opengl/texture3d_backend.cpp b/source/backends/opengl/texture3d_backend.cpp index 6826993a..1197405e 100644 --- a/source/backends/opengl/texture3d_backend.cpp +++ b/source/backends/opengl/texture3d_backend.cpp @@ -26,6 +26,9 @@ void OpenGLTexture3D::allocate() unsigned depth = static_cast(this)->depth; unsigned levels = static_cast(this)->levels; + if(!id) + generate_id(); + GLenum gl_fmt = get_gl_pixelformat(storage_fmt); if(ARB_texture_storage) { diff --git a/source/backends/opengl/texture_backend.cpp b/source/backends/opengl/texture_backend.cpp index fe4679f6..f3586b0b 100644 --- a/source/backends/opengl/texture_backend.cpp +++ b/source/backends/opengl/texture_backend.cpp @@ -22,13 +22,10 @@ int OpenGLTexture::swizzle_orders[] = OpenGLTexture *OpenGLTexture::scratch_binding = 0; -OpenGLTexture::OpenGLTexture(unsigned t, bool create): +OpenGLTexture::OpenGLTexture(unsigned t): id(0), target(t) { - if(create) - generate_id(); - static bool alignment_init = false; if(!alignment_init) { diff --git a/source/backends/opengl/texture_backend.h b/source/backends/opengl/texture_backend.h index f272d3d8..8b6a734e 100644 --- a/source/backends/opengl/texture_backend.h +++ b/source/backends/opengl/texture_backend.h @@ -19,7 +19,7 @@ protected: static int swizzle_orders[]; static OpenGLTexture *scratch_binding; - OpenGLTexture(unsigned, bool); + OpenGLTexture(unsigned); ~OpenGLTexture(); void generate_id(); diff --git a/source/backends/opengl/texturecube_backend.cpp b/source/backends/opengl/texturecube_backend.cpp index b113f1bd..cc894589 100644 --- a/source/backends/opengl/texturecube_backend.cpp +++ b/source/backends/opengl/texturecube_backend.cpp @@ -31,6 +31,9 @@ void OpenGLTextureCube::allocate() unsigned size = static_cast(this)->size; unsigned levels = static_cast(this)->levels; + if(!id) + generate_id(); + GLenum gl_fmt = get_gl_pixelformat(storage_fmt); if(ARB_texture_storage) { diff --git a/source/core/texture.cpp b/source/core/texture.cpp index 85f5fb58..be825e7f 100644 --- a/source/core/texture.cpp +++ b/source/core/texture.cpp @@ -9,7 +9,7 @@ namespace Msp { namespace GL { Texture::Texture(unsigned t, ResourceManager *m): - TextureBackend(t, !m), + TextureBackend(t), format(NO_PIXELFORMAT), storage_fmt(format), swizzle(NO_SWIZZLE), @@ -122,11 +122,7 @@ void Texture::Loader::generate_mipmap(bool gm) void Texture::Loader::image_data(const string &data) { if(obj.manager) - { obj.set_manager(0); - if(!obj.id) - obj.generate_id(); - } Graphics::Image img; IO::Memory mem(data.data(), data.size()); diff --git a/source/core/texture2d.cpp b/source/core/texture2d.cpp index 04ad6ed8..8dc15b1c 100644 --- a/source/core/texture2d.cpp +++ b/source/core/texture2d.cpp @@ -113,11 +113,7 @@ void Texture2D::Loader::init() void Texture2D::Loader::raw_data(const string &data) { if(obj.manager) - { obj.set_manager(0); - if(!obj.id) - obj.generate_id(); - } obj.image(0, data.data()); } -- 2.45.2