changed */
bool legacy_bindings = (!state->shprog || state->shprog->uses_legacy_variables());
+ bool legacy_textures = !state->shprog;
if(state->texturing)
- state->texturing->bind();
+ state->texturing->bind(legacy_textures);
else
{
Texturing::unbind();
if(state->texture)
- state->texture->bind_to(0);
+ state->texture->bind_to(0, legacy_textures);
else
Texture::unbind_from(0);
}
image(img, srgb);
}
-void Texture::bind_to(unsigned i) const
+void Texture::bind_to(unsigned i, bool legacy) const
{
if(!id)
{
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);
- if(ARB_direct_state_access && !unit.supports_legacy())
+ if(ARB_direct_state_access && !old_legacy && (!unit.supports_legacy() || !legacy))
glBindTextureUnit(i, id);
else
{
unit.bind();
if(unit.supports_legacy())
{
- if(old && old->target!=target)
+ if(old && old->target!=target && old_legacy)
glDisable(old->target);
- if((!old || old->target!=target))
+ if((!old || old->target!=target) && legacy)
glEnable(target);
}
glBindTexture(target, id);
{
TexUnit &unit = TexUnit::get_unit(i);
const Texture *cur = unit.get_texture();
+ bool legacy = unit.get_texture_legacy();
if(unit.set_texture(0))
{
- if(ARB_direct_state_access && !unit.supports_legacy())
+ if(ARB_direct_state_access && !legacy)
glBindTextureUnit(i, 0);
else
{
unit.bind();
glBindTexture(cur->target, 0);
- if(unit.supports_legacy())
+ if(unit.supports_legacy() && legacy)
glDisable(cur->target);
}
}
GLenum get_target() const { return target; }
unsigned get_id() const { return id; }
- void bind() const { bind_to(0); }
- void bind_to(unsigned) const;
+ void bind(bool legacy = true) const { bind_to(0, legacy); }
+ void bind_to(unsigned, bool = true) const;
static const Texture *current(unsigned = 0);
static void unbind() { unbind_from(0); }
namespace Msp {
namespace GL {
+bool Texturing::legacy_used = true;
+
Texturing::~Texturing()
{
if(current()==this)
attachments[attch] = tex;
if(current()==this)
- bind_attachment(attch);
+ bind_attachment(attch, legacy_used);
}
const Texture *Texturing::get_attached_texture(unsigned i) const
return i<attachments.size() ? attachments[i] : 0;
}
-void Texturing::bind_attachment(unsigned i) const
+void Texturing::bind_attachment(unsigned i, bool legacy) const
{
if(const Texture *tex = attachments[i])
- tex->bind_to(i);
+ tex->bind_to(i, legacy);
else
Texture::unbind_from(i);
}
Texture::unbind_from(i);
}
-void Texturing::bind() const
+void Texturing::bind(bool legacy) const
{
const Texturing *old = current();
- if(set_current(this))
+ if(set_current(this) || legacy!=legacy_used)
{
+ legacy_used = legacy;
for(unsigned i=0; i<attachments.size(); ++i)
- bind_attachment(i);
+ bind_attachment(i, legacy);
if(old)
{
for(unsigned i=attachments.size(); i<old->attachments.size(); ++i)
private:
std::vector<const Texture *> attachments;
+ static bool legacy_used;
+
public:
~Texturing();
const Texture *get_attached_texture(unsigned) const;
private:
- void bind_attachment(unsigned) const;
+ void bind_attachment(unsigned, bool) const;
static void unbind_attachment(unsigned);
public:
- void bind() const;
+ void bind(bool = true) const;
static void unbind();
};
TexUnit::TexUnit():
legacy(false),
- texture(0)
+ texture(0),
+ tex_legacy(false)
{ }
-bool TexUnit::set_texture(const Texture *tex)
+bool TexUnit::set_texture(const Texture *tex, bool lgc)
{
- bool result = (tex!=texture);
+ lgc = (lgc && legacy && tex);
+ bool result = (tex!=texture || lgc!=tex_legacy);
texture = tex;
+ tex_legacy = lgc;
return result;
}
unsigned index;
bool legacy;
const Texture *texture;
+ bool tex_legacy;
static std::vector<TexUnit> units;
static TexUnit *cur_unit;
public:
unsigned get_index() const { return index; }
bool supports_legacy() const { return legacy; }
- bool set_texture(const Texture *);
+ bool set_texture(const Texture *, bool = true);
const Texture *get_texture() const { return texture; }
+ bool get_texture_legacy() const { return tex_legacy; }
void bind();
static unsigned get_n_units();