]> git.tdb.fi Git - libs/gl.git/commitdiff
Use ARB_texture_storage for defining texture storage
authorMikko Rasa <tdb@tdb.fi>
Thu, 27 Oct 2016 22:52:13 +0000 (01:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 28 Oct 2016 11:28:12 +0000 (14:28 +0300)
extensions/arb_texture_storage.glext [new file with mode: 0644]
source/texture1d.cpp
source/texture2d.cpp
source/texture3d.cpp
source/texturecube.cpp

diff --git a/extensions/arb_texture_storage.glext b/extensions/arb_texture_storage.glext
new file mode 100644 (file)
index 0000000..c752633
--- /dev/null
@@ -0,0 +1 @@
+extension ARB_texture_storage
index 0dc85586cbc2e76c328077ca9b666b96c16873e9..44e49f51142fde02d41fa4da16b5119cb129d840 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)
@@ -49,7 +60,10 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
        unsigned w = get_level_size(level);
 
        BindRestore _bind(this);
-       glTexImage1D(target, level, ifmt, w, 0, fmt, type, data);
+       if(ARB_texture_storage)
+               sub_image(level, 0, w, fmt, type, data);
+       else
+               glTexImage1D(target, level, ifmt, w, 0, fmt, type, data);
 
        allocated |= 1<<level;
        if(gen_mipmap && level==0)
index 95f9f790507292797573931f9c241b6ae877be6e..4aad82d27ad9eeb71678e1b9b1d23386751c6ece 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/gl/extensions/arb_texture_storage.h>
 #include "bindable.h"
 #include "buffer.h"
 #include "error.h"
@@ -65,8 +66,18 @@ void Texture2D::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);
+               glTexStorage2D(target, n_levels, ifmt, width, height);
+               allocated |= (1<<n_levels)-1;
+       }
+       else
+       {
+               PixelFormat base_fmt = get_base_pixelformat(ifmt);
+               image(level, base_fmt, get_alloc_type(base_fmt), 0);
+       }
 }
 
 void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
@@ -79,7 +90,10 @@ void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void
        get_level_size(level, w, h);
 
        BindRestore _bind(this);
-       glTexImage2D(target, level, ifmt, w, h, 0, fmt, type, data);
+       if(ARB_texture_storage)
+               sub_image(level, 0, 0, w, h, fmt, type, data);
+       else
+               glTexImage2D(target, level, ifmt, w, h, 0, fmt, type, data);
 
        allocated |= 1<<level;
        if(gen_mipmap && level==0)
index 12fc856b8415d4e9cc18ac95c2a9c548a79cf79f..d04a17e1fbb38bf81c507f9798406f75ca3b2942 100644 (file)
@@ -1,4 +1,5 @@
 #include <cmath>
+#include <msp/gl/extensions/arb_texture_storage.h>
 #include <msp/gl/extensions/ext_texture3d.h>
 #include <msp/graphics/image.h>
 #include "bindable.h"
@@ -53,8 +54,18 @@ void Texture3D::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);
+               glTexStorage3D(target, n_levels, ifmt, width, height, depth);
+               allocated |= (1<<n_levels)-1;
+       }
+       else
+       {
+               PixelFormat base_fmt = get_base_pixelformat(ifmt);
+               image(level, base_fmt, get_alloc_type(base_fmt), 0);
+       }
 }
 
 void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
@@ -68,7 +79,10 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
        get_level_size(level, w, h, d);
 
        BindRestore _bind(this);
-       glTexImage3D(target, level, ifmt, width, height, depth, 0, fmt, type, data);
+       if(ARB_texture_storage)
+               sub_image(level, 0, 0, 0, w, h, d, fmt, type, data);
+       else
+               glTexImage3D(target, level, ifmt, width, height, depth, 0, fmt, type, data);
 
        allocated |= 1<<level;
        if(gen_mipmap && level==0)
index 65b1845eaf9ca5f1bb82f9886ada4ed0eed46472..54a008ca50930054ee6c99507c27c032f4ff4e6c 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/datafile/collection.h>
 #include <msp/gl/extensions/arb_texture_cube_map.h>
+#include <msp/gl/extensions/arb_texture_storage.h>
 #include <msp/io/memory.h>
 #include <msp/strings/format.h>
 #include "bindable.h"
@@ -51,10 +52,20 @@ void TextureCube::allocate(unsigned level)
        if(allocated&(1<<level))
                return;
 
-       PixelFormat base_fmt = get_base_pixelformat(ifmt);
-       DataType type = get_alloc_type(base_fmt);
-       for(unsigned i=0; i<6; ++i)
-               image(enumerate_faces(i), level, base_fmt, type, 0);
+       if(ARB_texture_storage)
+       {
+               BindRestore _bind(this);
+               unsigned n_levels = (is_mipmapped(min_filter) ? get_n_levels() : 1);
+               glTexStorage2D(target, n_levels, ifmt, size, size);
+               allocated |= (1<<n_levels)-1;
+       }
+       else
+       {
+               PixelFormat base_fmt = get_base_pixelformat(ifmt);
+               DataType type = get_alloc_type(base_fmt);
+               for(unsigned i=0; i<6; ++i)
+                       image(enumerate_faces(i), level, base_fmt, type, 0);
+       }
 }
 
 void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, DataType type, const void *data)
@@ -67,7 +78,10 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
                throw out_of_range("TextureCube::image");
 
        BindRestore _bind(this);
-       glTexImage2D(face, level, ifmt, s, s, 0, fmt, type, data);
+       if(ARB_texture_storage)
+               sub_image(face, level, 0, 0, s, s, fmt, type, data);
+       else
+               glTexImage2D(face, level, ifmt, s, s, 0, fmt, type, data);
 
        // XXX Allocation should be tracked per-face, but we'll run out of bits
        allocated |= 1<<level;