]> git.tdb.fi Git - libs/gl.git/commitdiff
Always delay texture creation until it is allocated
authorMikko Rasa <tdb@tdb.fi>
Thu, 7 Oct 2021 08:19:44 +0000 (11:19 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 7 Oct 2021 12:43:22 +0000 (15:43 +0300)
This allows greateer flexibility with setting a resource manager.

source/backends/opengl/texture1d_backend.cpp
source/backends/opengl/texture2d_backend.cpp
source/backends/opengl/texture2dmultisample_backend.cpp
source/backends/opengl/texture3d_backend.cpp
source/backends/opengl/texture_backend.cpp
source/backends/opengl/texture_backend.h
source/backends/opengl/texturecube_backend.cpp
source/core/texture.cpp
source/core/texture2d.cpp

index e44ceb4e757d6efefc4b54414d396894d8a9f019..bd754fde1091eb42b67fe6787ed2713b421d0f09 100644 (file)
@@ -19,6 +19,9 @@ void OpenGLTexture1D::allocate()
        unsigned width = static_cast<const Texture1D *>(this)->width;
        unsigned levels = static_cast<const Texture1D *>(this)->levels;
 
+       if(!id)
+               generate_id();
+
        GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
        if(ARB_texture_storage)
        {
index 71a998dcd31187585fd266c1c5e4b19d1369917d..725b603893973f1a52c47ad35d8dd8c8e69bc771 100644 (file)
@@ -41,6 +41,9 @@ void OpenGLTexture2D::allocate()
        unsigned height = static_cast<const Texture2D *>(this)->height;
        unsigned levels = static_cast<const Texture2D *>(this)->levels;
 
+       if(!id)
+               generate_id();
+
        GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
        if(ARB_texture_storage)
        {
index c4a4e42380d227666790386c6b9e1697617a80f2..71f9e138abddee50a7c157c0ef7e33b0dfda7a3a 100644 (file)
@@ -19,6 +19,9 @@ void OpenGLTexture2DMultisample::allocate()
        unsigned height = static_cast<const Texture2DMultisample *>(this)->height;
        unsigned samples = static_cast<const Texture2DMultisample *>(this)->samples;
 
+       if(!id)
+               generate_id();
+
        GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
        if(ARB_texture_storage_multisample)
        {
index 6826993ae6d9c37c414d5e6ff5aa50f1c9b7ff09..1197405ee367ff192690437f37ccca89b677000f 100644 (file)
@@ -26,6 +26,9 @@ void OpenGLTexture3D::allocate()
        unsigned depth = static_cast<const Texture3D *>(this)->depth;
        unsigned levels = static_cast<const Texture3D *>(this)->levels;
 
+       if(!id)
+               generate_id();
+
        GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
        if(ARB_texture_storage)
        {
index fe4679f63d4fe0815a7b808a2f13f02d32a1d32b..f3586b0bad09a1518a0a9eb21534a3822fad4cdb 100644 (file)
@@ -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)
        {
index f272d3d87b22cdf0f2fff876b05b40dc6d493a03..8b6a734e4eaf9850ea2d45583acc7cb951645ef7 100644 (file)
@@ -19,7 +19,7 @@ protected:
        static int swizzle_orders[];
        static OpenGLTexture *scratch_binding;
 
-       OpenGLTexture(unsigned, bool);
+       OpenGLTexture(unsigned);
        ~OpenGLTexture();
 
        void generate_id();
index b113f1bd21ba1a13f01effd610d67df8e7e01624..cc8945896fea9bdaad6763e4eedda5af50df859c 100644 (file)
@@ -31,6 +31,9 @@ void OpenGLTextureCube::allocate()
        unsigned size = static_cast<const TextureCube *>(this)->size;
        unsigned levels = static_cast<const TextureCube *>(this)->levels;
 
+       if(!id)
+               generate_id();
+
        GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
        if(ARB_texture_storage)
        {
index 85f5fb5836ebdcdb56af17191343a9c2f21be9ea..be825e7ff231f118356897dcc6036365c178be32 100644 (file)
@@ -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());
index 04ad6ed8d25fe5f61ef7e7893a33d238fcf31df5..8dc15b1c38aaf3a6364c3eccf80249ef25d2f301 100644 (file)
@@ -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());
 }