}
TexUnit &unit = TexUnit::get_unit(i);
- const Texture *cur = unit.get_texture();
+ const Texture *old = unit.get_texture();
if(unit.set_texture(this))
{
if(manager)
manager->resource_used(*this);
unit.bind();
- if(cur && cur->target!=target)
- glDisable(cur->target);
- if(!cur || cur->target!=target)
- glEnable(target);
+ if(unit.supports_legacy())
+ {
+ if(old && old->target!=target)
+ glDisable(old->target);
+ if(!old || old->target!=target)
+ glEnable(target);
+ }
glBindTexture(target, id);
if(dirty_params)
{
unit.bind();
glBindTexture(cur->target, 0);
- glDisable(cur->target);
+ if(unit.supports_legacy())
+ glDisable(cur->target);
}
}
#include <stdexcept>
#include <msp/gl/extensions/arb_multitexture.h>
#include <msp/gl/extensions/arb_vertex_shader.h>
+#include <msp/gl/extensions/msp_legacy_features.h>
#include "gl.h"
#include "misc.h"
#include "texunit.h"
TexUnit *TexUnit::cur_unit = 0;
TexUnit::TexUnit():
+ legacy(false),
texture(0)
{ }
return count;
}
+unsigned TexUnit::get_n_legacy_units()
+{
+ static int count = -1;
+ if(count<0)
+ {
+ if(MSP_legacy_features)
+ count = get_i(GL_MAX_TEXTURE_UNITS);
+ else
+ count = 0;
+ }
+ return count;
+}
+
TexUnit &TexUnit::get_unit(unsigned n)
{
if(n>0)
if(units.size()<=n)
{
unsigned i = units.size();
+ unsigned n_legacy = get_n_legacy_units();
units.resize(n+1, TexUnit());
for(; i<units.size(); ++i)
+ {
units[i].index = i;
+ units[i].legacy = (i<n_legacy);
+ }
}
return units[n];
{
private:
unsigned index;
+ bool legacy;
const Texture *texture;
static std::vector<TexUnit> units;
public:
unsigned get_index() const { return index; }
+ bool supports_legacy() const { return legacy; }
bool set_texture(const Texture *);
const Texture *get_texture() const { return texture; }
void bind();
static unsigned get_n_units();
+ static unsigned get_n_legacy_units();
static TexUnit &get_unit(unsigned);
static TexUnit ¤t();
static TexUnit *find_unit(const Texture *);