]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture1d.cpp
Rearrange texture bind calls to keep them closer to where they're needed
[libs/gl.git] / source / texture1d.cpp
index 0dc85586cbc2e76c328077ca9b666b96c16873e9..ed7d8f6e2b877fd4f660d71dbdc72874ef3de34b 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/gl/extensions/arb_texture_storage.h>
 #include <msp/gl/extensions/msp_texture1d.h>
 #include "bindable.h"
 #include "error.h"
@@ -37,8 +38,18 @@ void Texture1D::allocate(unsigned level)
        if(allocated&(1<<level))
                return;
 
-       PixelFormat base_fmt = get_base_pixelformat(ifmt);
-       image(level, base_fmt, get_alloc_type(base_fmt), 0);
+       if(ARB_texture_storage)
+       {
+               BindRestore _bind(this);
+               unsigned n_levels = (is_mipmapped(min_filter) ? get_n_levels() : 1);
+               glTexStorage1D(target, n_levels, ifmt, width);
+               allocated |= (1<<n_levels)-1;
+       }
+       else
+       {
+               PixelFormat base_fmt = get_base_pixelformat(ifmt);
+               image(level, base_fmt, get_alloc_type(base_fmt), 0);
+       }
 }
 
 void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
@@ -48,6 +59,9 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
 
        unsigned w = get_level_size(level);
 
+       if(ARB_texture_storage)
+               return sub_image(level, 0, w, fmt, type, data);
+
        BindRestore _bind(this);
        glTexImage1D(target, level, ifmt, w, 0, fmt, type, data);
 
@@ -64,10 +78,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);
        allocate(level);
 
-       BindRestore _bind(this);
        glTexSubImage1D(target, level, x, wd, fmt, type, data);
+
+       if(gen_mipmap && level==0)
+               auto_generate_mipmap();
 }
 
 void Texture1D::image(const Graphics::Image &img, bool srgb)