ifmt(RGB),
min_filter(NEAREST_MIPMAP_LINEAR),
mag_filter(LINEAR),
+ mipmap_levels(0),
max_anisotropy(1.0f),
wrap_s(REPEAT),
wrap_t(REPEAT),
glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle_orders+swizzle*4);
}
}
+ if(mask&MIPMAP_LEVELS)
+ set_parameter_i(GL_TEXTURE_MAX_LEVEL, (mipmap_levels ? mipmap_levels-1 : 1000));
}
void Texture::set_parameter_i(GLenum param, int value) const
set_mag_filter(f==NEAREST ? NEAREST : LINEAR);
}
+void Texture::set_mipmap_levels(unsigned l)
+{
+ mipmap_levels = l;
+ update_parameter(MIPMAP_LEVELS);
+}
+
void Texture::set_max_anisotropy(float a)
{
if(a<1.0f)
image(img, srgb);
}
-void Texture::bind_to(unsigned i) const
+void Texture::bind_to(unsigned i, bool legacy) const
{
if(!id)
{
}
}
+ legacy = (legacy && is_legacy_target(target));
+
TexUnit &unit = TexUnit::get_unit(i);
const Texture *old = unit.get_texture();
- if(unit.set_texture(this))
+ bool old_legacy = unit.get_texture_legacy();
+ if(unit.set_texture(this, legacy))
{
if(manager)
manager->resource_used(*this);
- unit.bind();
- if(unit.supports_legacy())
+ if(ARB_direct_state_access && !old_legacy && (!unit.supports_legacy() || !legacy))
+ glBindTextureUnit(i, id);
+ else
{
- if(old && old->target!=target)
- glDisable(old->target);
- if(!old || old->target!=target)
- glEnable(target);
+ unit.bind();
+ if(unit.supports_legacy())
+ {
+ if(old && old->target!=target && old_legacy)
+ glDisable(old->target);
+ if((!old || old->target!=target) && legacy)
+ glEnable(target);
+ }
+ glBindTexture(target, id);
}
- glBindTexture(target, id);
if(dirty_params)
{
{
TexUnit &unit = TexUnit::get_unit(i);
const Texture *cur = unit.get_texture();
+ bool legacy = unit.get_texture_legacy();
if(unit.set_texture(0))
{
- unit.bind();
- glBindTexture(cur->target, 0);
- if(unit.supports_legacy())
- glDisable(cur->target);
+ if(ARB_direct_state_access && !legacy)
+ glBindTextureUnit(i, 0);
+ else
+ {
+ unit.bind();
+ glBindTexture(cur->target, 0);
+ if(unit.supports_legacy() && legacy)
+ glDisable(cur->target);
+ }
}
}
+bool Texture::is_legacy_target(GLenum target)
+{
+ return target<GL_TEXTURE_1D_ARRAY;
+}
+
Texture::Loader::Loader(Texture &t):
DataFile::CollectionObjectLoader<Texture>(t, 0)
add("mag_filter", &Loader::mag_filter);
add("max_anisotropy", &Loader::max_anisotropy);
add("min_filter", &Loader::min_filter);
+ add("mipmap_levels", &Loader::mipmap_levels);
add("wrap", &Loader::wrap);
add("wrap_r", &Loader::wrap_r);
add("wrap_s", &Loader::wrap_s);
obj.set_min_filter(f);
}
+void Texture::Loader::mipmap_levels(unsigned l)
+{
+ obj.set_mipmap_levels(l);
+}
+
void Texture::Loader::wrap(TextureWrap w)
{
obj.set_wrap(w);