X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Frenderer.cpp;h=d86b78046eb24454f954155f687d0c2ec9c710c0;hb=5b652353d545a3190ea2d86ba82a87b2e3382a0d;hp=8de24adbbca8aee385a5ddab15941b50ee41b9e6;hpb=c5583e23cc7b064ac28f2b2b6993d1e5fa415d5b;p=libs%2Fgl.git diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 8de24adb..d86b7804 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -2,6 +2,7 @@ #include "buffer.h" #include "camera.h" #include "clipping.h" +#include "deviceinfo.h" #include "error.h" #include "lighting.h" #include "material.h" @@ -11,7 +12,6 @@ #include "renderer.h" #include "sampler.h" #include "texture.h" -#include "texturing.h" #include "texunit.h" #include "vertexarray.h" #include "vertexsetup.h" @@ -22,27 +22,13 @@ using namespace std; 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()); shdata_stack.reserve(32); state = &state_stack.back(); + add_shader_data(standard_shdata); } Renderer::~Renderer() @@ -53,7 +39,7 @@ Renderer::~Renderer() void Renderer::set_camera(const Camera &c) { state->camera = &c; - changed |= CAMERA_SHDATA; + add_shader_data(c.get_shader_data()); set_matrix(Matrix()); } @@ -70,16 +56,11 @@ void Renderer::transform(const Matrix &matrix) } 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; @@ -89,7 +70,7 @@ void Renderer::set_texture(Tag tag, int unit, const Texture *tex, const Sampler } for(vector::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; @@ -98,17 +79,11 @@ void Renderer::set_texture(Tag tag, int unit, const Texture *tex, const Sampler 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; itexture_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; iget_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) @@ -160,7 +116,8 @@ void Renderer::set_lighting(const Lighting *l) void Renderer::set_clipping(const Clipping *c) { state->clipping = c; - changed |= CLIPPING_SHDATA; + if(c) + add_shader_data(c->get_shader_data()); } void Renderer::set_shader_program(const Program *p, const ProgramData *d) @@ -225,16 +182,9 @@ void Renderer::pop_state() if(state_stack.size()==1) throw stack_underflow("Renderer::pop_state"); - const Camera *old_camera = state->camera; - const Clipping *old_clipping = state->clipping; state_stack.pop_back(); state = &state_stack.back(); changed |= MATRIX; - bool camera_changed = (state->camera!=old_camera); - if(camera_changed) - changed |= CAMERA_SHDATA; - if(state->clipping!=old_clipping) - changed |= CLIPPING_SHDATA; } void Renderer::end() @@ -243,8 +193,6 @@ void Renderer::end() throw invalid_operation("Renderer::end"); *state = State(); - if(default_camera) - set_camera(*default_camera); shdata_stack.clear(); excluded.clear(); @@ -304,7 +252,7 @@ void Renderer::apply_state() for(vector::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) @@ -329,25 +277,7 @@ void Renderer::apply_state() LinAl::SquareMatrix nm = state->model_matrix.block<3, 3>(0, 0); nm = transpose(invert(nm)); standard_shdata.uniform("world_obj_normal_matrix", nm); - changed = (changed&~MATRIX)|STANDARD_SHDATA; - } - - if(state->camera && ((changed&CAMERA_SHDATA) || shprog_changed)) - { - state->camera->get_shader_data().apply(); - changed &= ~CAMERA_SHDATA; - } - - if(state->clipping && ((changed&CLIPPING_SHDATA) || shprog_changed)) - { - state->clipping->get_shader_data().apply(); - changed &= ~CLIPPING_SHDATA; - } - - if((changed&STANDARD_SHDATA) || shprog_changed) - { - standard_shdata.apply(); - changed &= ~STANDARD_SHDATA; + changed &= ~MATRIX; } bool shdata_changed = changed&SHADER_DATA; @@ -401,7 +331,7 @@ Renderer::BoundProgramData::BoundProgramData(const ProgramData *d): Renderer::State::State(): camera(0), texture_count(0), - lowest_effect_texunit(TexUnit::get_n_units()), + lowest_effect_texunit(Limits::get_global().max_texture_bindings), clipping(0), shprog(0), shdata_count(0),