summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
aff68a1)
Also add a few argument validity checks to functions
{
if(width==0)
throw invalid_operation("Texture1D::image");
{
if(width==0)
throw invalid_operation("Texture1D::image");
+ if(level>=levels)
+ throw out_of_range("Texture1D::image");
unsigned w = get_level_size(level);
unsigned w = get_level_size(level);
void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
{
if(width==0)
void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
{
if(width==0)
- throw invalid_operation("Texture3D::image");
+ throw invalid_operation("Texture1D::sub_image");
+ if(level>=levels)
+ throw out_of_range("Texture1D::sub_image");
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
{
if(width==0 || height==0)
throw invalid_operation("Texture2D::image");
{
if(width==0 || height==0)
throw invalid_operation("Texture2D::image");
+ if(level>=levels)
+ throw out_of_range("Texture2D::image");
- unsigned w = width;
- unsigned h = height;
- get_level_size(level, w, h);
+ LinAl::Vector<unsigned, 2> size = get_level_size(level);
- return sub_image(level, 0, 0, w, h, data);
+ return sub_image(level, 0, 0, size.x, size.y, data);
PixelComponents comp = get_components(storage_fmt);
GLenum type = get_gl_type(get_component_type(storage_fmt));
PixelComponents comp = get_components(storage_fmt);
GLenum type = get_gl_type(get_component_type(storage_fmt));
- glTexImage2D(target, level, storage_fmt, w, h, 0, comp, type, data);
+ glTexImage2D(target, level, storage_fmt, size.x, size.y, 0, comp, type, data);
allocated |= 1<<level;
if(auto_gen_mipmap && level==0)
allocated |= 1<<level;
if(auto_gen_mipmap && level==0)
{
if(width==0 || height==0)
throw invalid_operation("Texture2D::sub_image");
{
if(width==0 || height==0)
throw invalid_operation("Texture2D::sub_image");
+ if(level>=levels)
+ throw out_of_range("Texture2D::sub_image");
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
-void Texture2D::get_level_size(unsigned level, unsigned &w, unsigned &h) const
+LinAl::Vector<unsigned, 2> Texture2D::get_level_size(unsigned level) const
- w >>= level;
- h >>= level;
+ unsigned w = width>>level;
+ unsigned h = height>>level;
if(!w && h)
w = 1;
else if(!h && w)
h = 1;
if(!w && h)
w = 1;
else if(!h && w)
h = 1;
+
+ return LinAl::Vector<unsigned, 2>(w, h);
}
Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *)
}
Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *)
#include <string>
#include <msp/graphics/image.h>
#include <string>
#include <msp/graphics/image.h>
+#include <msp/linal/vector.h>
#include "texture.h"
namespace Msp {
#include "texture.h"
namespace Msp {
private:
unsigned get_n_levels() const;
private:
unsigned get_n_levels() const;
- void get_level_size(unsigned, unsigned &, unsigned &) const;
+ LinAl::Vector<unsigned, 2> get_level_size(unsigned) const;
public:
virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
public:
virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
void Texture2DArray::layer_image(unsigned level, unsigned z, const void *data)
{
void Texture2DArray::layer_image(unsigned level, unsigned z, const void *data)
{
- unsigned w = get_width();
- unsigned h = get_height();
- unsigned d = get_depth();
- get_level_size(level, w, h, d);
+ if(level>=levels || z>=depth)
+ throw out_of_range("Texture2DArray::layer_image");
- sub_image(level, 0, 0, z, w, h, 1, data);
+ LinAl::Vector<unsigned, 3> size = get_level_size(level);
+ sub_image(level, 0, 0, z, size.x, size.y, 1, data);
}
void Texture2DArray::layer_image(unsigned level, unsigned z, PixelComponents comp, DataType type, const void *data)
}
void Texture2DArray::layer_image(unsigned level, unsigned z, PixelComponents comp, DataType type, const void *data)
{
if(width==0 || height==0 || depth==0)
throw invalid_operation("Texture3D::image");
{
if(width==0 || height==0 || depth==0)
throw invalid_operation("Texture3D::image");
+ if(level>=levels)
+ throw out_of_range("Texture3D::image");
- unsigned w = width;
- unsigned h = height;
- unsigned d = depth;
- get_level_size(level, w, h, d);
+ LinAl::Vector<unsigned, 3> size = get_level_size(level);
- return sub_image(level, 0, 0, 0, w, h, d, data);
+ return sub_image(level, 0, 0, 0, size.x, size.y, size.z, data);
PixelComponents comp = get_components(storage_fmt);
GLenum type = get_gl_type(get_component_type(storage_fmt));
PixelComponents comp = get_components(storage_fmt);
GLenum type = get_gl_type(get_component_type(storage_fmt));
- glTexImage3D(target, level, storage_fmt, width, height, depth, 0, comp, type, data);
+ glTexImage3D(target, level, storage_fmt, size.x, size.y, size.z, 0, comp, type, data);
allocated |= 1<<level;
if(auto_gen_mipmap && level==0)
allocated |= 1<<level;
if(auto_gen_mipmap && level==0)
void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data)
{
if(width==0 || height==0 || depth==0)
void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data)
{
if(width==0 || height==0 || depth==0)
- throw invalid_operation("Texture3D::image");
+ throw invalid_operation("Texture3D::sub_image");
+ if(level>=levels)
+ throw out_of_range("Texture3D::sub_image");
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
allocate(level);
-void Texture3D::get_level_size(unsigned level, unsigned &w, unsigned &h, unsigned &d) const
+LinAl::Vector<unsigned, 3> Texture3D::get_level_size(unsigned level) const
- w >>= level;
- h >>= level;
+ unsigned w = width>>level;
+ unsigned h = height>>level;
+ unsigned d = depth;
if(target!=GL_TEXTURE_2D_ARRAY)
d >>= level;
if(target!=GL_TEXTURE_2D_ARRAY)
d >>= level;
h = 1;
if(!d && (w || h))
d = 1;
h = 1;
if(!d && (w || h))
d = 1;
+
+ return LinAl::Vector<unsigned, 3>(w, h, d);
}
UInt64 Texture3D::get_data_size() const
}
UInt64 Texture3D::get_data_size() const
#define MSP_GL_TEXTURE3D_H_
#include <string>
#define MSP_GL_TEXTURE3D_H_
#include <string>
+#include <msp/linal/vector.h>
#include "texture.h"
namespace Msp {
#include "texture.h"
namespace Msp {
void storage_levels(PixelFormat, unsigned, unsigned, unsigned, unsigned);
};
void storage_levels(PixelFormat, unsigned, unsigned, unsigned, unsigned);
};
unsigned width;
unsigned height;
unsigned depth;
unsigned levels;
unsigned allocated;
unsigned width;
unsigned height;
unsigned depth;
unsigned levels;
unsigned allocated;
Texture3D(GLenum);
public:
Texture3D();
Texture3D(GLenum);
public:
Texture3D();
unsigned get_depth() const { return depth; }
protected:
unsigned get_n_levels() const;
unsigned get_depth() const { return depth; }
protected:
unsigned get_n_levels() const;
- void get_level_size(unsigned, unsigned &, unsigned &, unsigned &) const;
+ LinAl::Vector<unsigned, 3> get_level_size(unsigned) const;
public:
virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
public:
virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
{
if(size==0)
throw invalid_operation("TextureCube::image");
{
if(size==0)
throw invalid_operation("TextureCube::image");
+ if(level>=levels)
+ throw out_of_range("TextureCube::image");
unsigned s = get_level_size(level);
unsigned s = get_level_size(level);
- if(s==0)
- throw out_of_range("TextureCube::image");
if(ARB_texture_storage)
return sub_image(face, level, 0, 0, s, s, data);
if(ARB_texture_storage)
return sub_image(face, level, 0, 0, s, s, data);
{
if(size==0)
throw invalid_operation("TextureCube::sub_image");
{
if(size==0)
throw invalid_operation("TextureCube::sub_image");
+ if(level>=levels)
+ throw out_of_range("TextureCube::sub_image");
Conditional<BindRestore> _bind(!ARB_direct_state_acess, this);
allocate(level);
Conditional<BindRestore> _bind(!ARB_direct_state_acess, this);
allocate(level);