]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture1d.cpp
Use ARB_direct_state_access to avoid some bind calls
[libs/gl.git] / source / texture1d.cpp
index ed7d8f6e2b877fd4f660d71dbdc72874ef3de34b..32053e83fa9bd8ad9231720c79defa3474229415 100644 (file)
@@ -1,3 +1,5 @@
+#include <msp/core/raii.h>
+#include <msp/gl/extensions/arb_direct_state_access.h>
 #include <msp/gl/extensions/arb_texture_storage.h>
 #include <msp/gl/extensions/msp_texture1d.h>
 #include "bindable.h"
@@ -40,9 +42,14 @@ void Texture1D::allocate(unsigned level)
 
        if(ARB_texture_storage)
        {
-               BindRestore _bind(this);
                unsigned n_levels = (is_mipmapped(min_filter) ? get_n_levels() : 1);
-               glTexStorage1D(target, n_levels, ifmt, width);
+               if(ARB_direct_state_access)
+                       glTextureStorage1D(id, n_levels, ifmt, width);
+               else
+               {
+                       BindRestore _bind(this);
+                       glTexStorage1D(target, n_levels, ifmt, width);
+               }
                allocated |= (1<<n_levels)-1;
        }
        else
@@ -78,10 +85,13 @@ void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelFormat fmt, D
        if(width==0)
                throw invalid_operation("Texture3D::image");
 
-       BindRestore _bind(this);
+       Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
        allocate(level);
 
-       glTexSubImage1D(target, level, x, wd, fmt, type, data);
+       if(ARB_direct_state_access)
+               glTextureSubImage1D(id, level, x, wd, fmt, type, data);
+       else
+               glTexSubImage1D(target, level, x, wd, fmt, type, data);
 
        if(gen_mipmap && level==0)
                auto_generate_mipmap();