--- /dev/null
+extension ARB_texture_storage
+#include <msp/gl/extensions/arb_texture_storage.h>
#include <msp/gl/extensions/msp_texture1d.h>
#include "bindable.h"
#include "error.h"
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)
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)
+#include <msp/gl/extensions/arb_texture_storage.h>
#include "bindable.h"
#include "buffer.h"
#include "error.h"
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)
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)
#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"
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)
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)
#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"
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)
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;