#include "renderer.h"
#include "sampler.h"
#include "texture.h"
-#include "texturing.h"
#include "texunit.h"
#include "vertexarray.h"
#include "vertexsetup.h"
namespace Msp {
namespace GL {
-Renderer::Renderer():
- default_camera(0)
-{
- init();
-}
-
-Renderer::Renderer(const Camera *c):
- default_camera(c)
-{
- init();
-
- if(c)
- set_camera(*c);
-}
-
-void Renderer::init()
+Renderer::Renderer()
{
state_stack.reserve(16);
state_stack.push_back(State());
}
void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
-{
- set_texture(tag, -1, tex, samp);
-}
-
-void Renderer::set_texture(Tag tag, int unit, const Texture *tex, const Sampler *samp)
{
if(texture_stack.size()>state->texture_count)
{
BoundTexture &bt = texture_stack[state->texture_count];
- if((!tag.id || bt.tag==tag) && (unit<0 || bt.unit==unit) && bt.texture==tex && bt.sampler==samp)
+ if(bt.tag==tag && bt.texture==tex && bt.sampler==samp)
{
++state->texture_count;
return;
}
for(vector<BoundTexture>::iterator i=texture_stack.end(); i!=texture_stack.begin(); )
- if((--i)->tag==tag && i->unit==unit)
+ if((--i)->tag==tag)
{
i->replaced = texture_stack.size();
break;
texture_stack.push_back(BoundTexture());
BoundTexture &bound_tex = texture_stack.back();
bound_tex.tag = tag;
- bound_tex.unit = unit;
bound_tex.texture = tex;
bound_tex.sampler = samp;
state->texture_count = texture_stack.size();
}
-void Renderer::set_texture(const Texture *t, const Sampler *s)
-{
- set_texture(Tag(), 0, t, s);
-}
-
void Renderer::flush_textures()
{
for(unsigned i=0; i<texture_stack.size(); ++i)
texture_stack.erase(texture_stack.begin()+state->texture_count, texture_stack.end());
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void Renderer::set_texturing(const Texturing *t)
-{
- if(t)
- {
- unsigned n_units = TexUnit::get_n_units();
- for(unsigned i=0; i<n_units; ++i)
- if(const Texture *tex = t->get_attached_texture(i))
- set_texture(Tag(), i, tex, t->get_attached_sampler(i));
- }
-}
-#pragma GCC diagnostic pop
-
-unsigned Renderer::allocate_effect_texunit()
-{
- return --state->lowest_effect_texunit;
-}
-
void Renderer::set_material(const Material *m)
{
if(m)
throw invalid_operation("Renderer::end");
*state = State();
- if(default_camera)
- set_camera(*default_camera);
shdata_stack.clear();
excluded.clear();
for(vector<BoundTexture>::const_iterator i=texture_stack.begin(); i!=texture_stack.end(); ++i)
{
- int unit = (i->tag.id ? state->shprog->get_uniform_binding(i->tag) : i->unit);
+ int unit = state->shprog->get_uniform_binding(i->tag);
if(unit>=0)
{
if(i->texture)