]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor texture ID generation into a function
authorMikko Rasa <tdb@tdb.fi>
Sat, 17 Apr 2021 22:04:53 +0000 (01:04 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 17 Apr 2021 22:10:56 +0000 (01:10 +0300)
source/core/texture.cpp
source/core/texture.h
source/core/texture2d.cpp

index 3a4b1096f99cb2edee54137194f64cb3b805b808..3eb48b8b2eb426dafebd1791ab11d4fba09b4c63 100644 (file)
@@ -34,10 +34,8 @@ Texture::Texture(GLenum t, ResourceManager *m):
 {
        if(m)
                set_manager(m);
-       else if(ARB_direct_state_access)
-               glCreateTextures(target, 1, &id);
        else
-               glGenTextures(1, &id);
+               generate_id();
 }
 
 Texture::~Texture()
@@ -49,6 +47,16 @@ Texture::~Texture()
                glDeleteTextures(1, &id);
 }
 
+void Texture::generate_id()
+{
+       if(id)
+               throw invalid_operation("Texture::generate_id");
+       if(ARB_direct_state_access)
+               glCreateTextures(target, 1, &id);
+       else
+               glGenTextures(1, &id);
+}
+
 void Texture::set_format(PixelFormat fmt)
 {
        PixelComponents comp = get_components(fmt);
index c4e72031ebb174e372877dfd14972449e80d9178..bca0d409b105d9177ea7a108efc498e25c180769 100644 (file)
@@ -90,6 +90,7 @@ public:
        ~Texture();
 
 protected:
+       void generate_id();
        void set_format(PixelFormat);
        void apply_swizzle();
        void set_parameter_i(GLenum, int) const;
index d2addda70fc4d6e35de11e2df472bf98b89d9940..0f06790c06056f419f6f50766db8a4eb975793f3 100644 (file)
@@ -290,12 +290,7 @@ bool Texture2D::AsyncLoader::process()
                }
 
                if(!texture.id)
-               {
-                       if(ARB_direct_state_access)
-                               glCreateTextures(texture.target, 1, &texture.id);
-                       else
-                               glGenTextures(1, &texture.id);
-               }
+                       texture.generate_id();
                texture.image(image, 0, true);
        }