id(0),
target(t),
ifmt(RGB),
+ swizzle(NO_SWIZZLE),
auto_gen_mipmap(false),
- dirty_params(0),
default_sampler(*this)
{
if(m)
void Texture::set_internal_format(PixelFormat fmt)
{
- FormatSwizzle swiz = NO_SWIZZLE;
+ swizzle = NO_SWIZZLE;
if(ARB_texture_rg && ARB_texture_swizzle)
{
if(fmt==LUMINANCE)
{
fmt = RED;
- swiz = R_TO_LUMINANCE;
+ swizzle = R_TO_LUMINANCE;
}
else if(fmt==LUMINANCE_ALPHA)
{
fmt = RG;
- swiz = RG_TO_LUMINANCE_ALPHA;
+ swizzle = RG_TO_LUMINANCE_ALPHA;
}
}
require_pixelformat(fmt);
ifmt = fmt;
- swizzle = swiz;
- if(swizzle)
- update_parameter(FORMAT_SWIZZLE);
}
PixelFormat Texture::get_upload_format(PixelFormat fmt) const
return fmt;
}
-void Texture::update_parameter(int mask) const
+void Texture::apply_swizzle()
{
- if(!id)
- {
- dirty_params |= mask;
+ if(swizzle==NO_SWIZZLE)
return;
- }
- if(!ARB_direct_state_access && TexUnit::current().get_texture()!=this)
+ if(get_gl_api()==OPENGL_ES2)
{
- TexUnit *unit = TexUnit::find_unit(this);
- if(!unit)
- {
- dirty_params |= mask;
- return;
- }
-
- unit->bind();
+ set_parameter_i(GL_TEXTURE_SWIZZLE_R, swizzle_orders[swizzle*4]);
+ set_parameter_i(GL_TEXTURE_SWIZZLE_G, swizzle_orders[swizzle*4+1]);
+ set_parameter_i(GL_TEXTURE_SWIZZLE_B, swizzle_orders[swizzle*4+2]);
+ set_parameter_i(GL_TEXTURE_SWIZZLE_A, swizzle_orders[swizzle*4+3]);
}
-
- if(mask&FORMAT_SWIZZLE)
+ else
{
- if(get_gl_api()==OPENGL_ES2)
- {
- set_parameter_i(GL_TEXTURE_SWIZZLE_R, swizzle_orders[swizzle*4]);
- set_parameter_i(GL_TEXTURE_SWIZZLE_G, swizzle_orders[swizzle*4+1]);
- set_parameter_i(GL_TEXTURE_SWIZZLE_B, swizzle_orders[swizzle*4+2]);
- set_parameter_i(GL_TEXTURE_SWIZZLE_A, swizzle_orders[swizzle*4+3]);
- }
+ if(ARB_direct_state_access)
+ glTextureParameteriv(id, GL_TEXTURE_SWIZZLE_RGBA, swizzle_orders+swizzle*4);
else
- {
- if(ARB_direct_state_access)
- glTextureParameteriv(id, GL_TEXTURE_SWIZZLE_RGBA, swizzle_orders+swizzle*4);
- else
- glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle_orders+swizzle*4);
- }
+ glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle_orders+swizzle*4);
}
}
glTexParameteri(target, param, value);
}
-void Texture::set_parameter_f(GLenum param, float value) const
-{
- if(ARB_direct_state_access)
- glTextureParameterf(id, param, value);
- else
- glTexParameterf(target, param, value);
-}
-
void Texture::set_min_filter(TextureFilter f)
{
default_sampler.set_min_filter(f);
glBindTexture(target, id);
}
- if(dirty_params)
- {
- update_parameter(dirty_params);
- dirty_params = 0;
- }
-
default_sampler.bind_to(i);
}
}
PixelFormat ifmt;
FormatSwizzle swizzle;
bool auto_gen_mipmap;
- mutable int dirty_params;
Sampler default_sampler;
static int swizzle_orders[];
static DataType get_alloc_type(PixelFormat);
void set_internal_format(PixelFormat);
PixelFormat get_upload_format(PixelFormat) const;
+ void apply_swizzle();
+ void set_parameter_i(GLenum, int) const;
public:
Sampler &get_default_sampler() { return default_sampler; }
const Sampler &get_default_sampler() const { return default_sampler; }
-protected:
- void update_parameter(int) const;
- void set_parameter_i(GLenum, int) const;
- void set_parameter_f(GLenum, float) const;
-public:
DEPRECATED void set_min_filter(TextureFilter);
DEPRECATED void set_mag_filter(TextureFilter);
if(ARB_texture_storage)
{
+ Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
if(ARB_direct_state_access)
glTextureStorage1D(id, levels, ifmt, width);
else
- {
- BindRestore _bind(this);
glTexStorage1D(target, levels, ifmt, width);
- }
+ apply_swizzle();
allocated |= (1<<levels)-1;
}
else
BindRestore _bind(this);
if(!allocated)
+ {
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ apply_swizzle();
+ }
glTexImage1D(target, level, ifmt, w, 0, get_upload_format(fmt), type, data);
allocated |= 1<<level;
if(ARB_texture_storage)
{
+ Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
if(ARB_direct_state_access)
glTextureStorage2D(id, levels, ifmt, width, height);
else
- {
- BindRestore _bind(this);
glTexStorage2D(target, levels, ifmt, width, height);
- }
+ apply_swizzle();
allocated |= (1<<levels)-1;
}
else
BindRestore _bind(this);
if(!allocated)
+ {
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ apply_swizzle();
+ }
glTexImage2D(target, level, ifmt, w, h, 0, get_upload_format(fmt), type, data);
allocated |= 1<<level;
glDeleteTextures(1, &id);
id = 0;
allocated = 0;
- // TODO check which params actually need refreshing
- dirty_params = -1;
default_sampler.unload();
}
if(ARB_texture_storage)
{
+ Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
if(ARB_direct_state_access)
glTextureStorage3D(id, levels, ifmt, width, height, depth);
else
- {
- BindRestore _bind(this);
glTexStorage3D(target, levels, ifmt, width, height, depth);
- }
+ apply_swizzle();
allocated |= (1<<levels)-1;
}
else
BindRestore _bind(this);
if(!allocated)
+ {
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ apply_swizzle();
+ }
glTexImage3D(target, level, ifmt, width, height, depth, 0, get_upload_format(fmt), type, data);
allocated |= 1<<level;
{
BindRestore _bind(this);
glTexStorage2D(target, levels, ifmt, size, size);
+ apply_swizzle();
allocated |= (1<<levels)-1;
}
else
BindRestore _bind(this);
if(!allocated)
+ {
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+ apply_swizzle();
+ }
glTexImage2D(face, level, ifmt, s, s, 0, get_upload_format(fmt), type, data);
if(level==0)