+ state->scissor = s;
+}
+
+void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
+{
+ if(tex)
+ if(ResourceManager *res_mgr = tex->get_manager())
+ res_mgr->resource_used(*tex);
+
+ if(texture_stack.size()>state->texture_count)
+ {
+ BoundTexture &bt = texture_stack[state->texture_count];
+ if(bt.tag==tag && bt.texture==tex && bt.sampler==samp)
+ {
+ ++state->texture_count;
+ return;
+ }
+ else
+ flush_textures();
+ }
+
+ for(auto i=texture_stack.end(); i!=texture_stack.begin(); )
+ 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.texture = tex;
+ bound_tex.sampler = samp;
+ state->texture_count = texture_stack.size();
+}
+
+void Renderer::flush_textures()
+{
+ for(unsigned i=0; i<state->texture_count; ++i)
+ if(texture_stack[i].replaced>=static_cast<int>(state->texture_count))
+ texture_stack[i].replaced = -1;
+
+ texture_stack.erase(texture_stack.begin()+state->texture_count, texture_stack.end());