X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Frenderer.cpp;h=447ab4e35de83faaad278b5df44e8861c7ea5d18;hb=8544116298d7a1be176f52be48c9952529f5c446;hp=61eccb3b367ab4540e48bd40768c56beec966163;hpb=5f3e285643c87af749478bcf928aea04219698c6;p=libs%2Fgl.git diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 61eccb3b..447ab4e3 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -1,9 +1,8 @@ #include "batch.h" #include "buffer.h" #include "camera.h" -#include "clipping.h" -#include "deviceinfo.h" #include "error.h" +#include "framebuffer.h" #include "lighting.h" #include "material.h" #include "program.h" @@ -28,7 +27,6 @@ Renderer::Renderer() shdata_stack.reserve(32); state = &state_stack.back(); add_shader_data(standard_shdata); - commands.use_pipeline(pipeline_state); } Renderer::~Renderer() @@ -88,7 +86,7 @@ void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp) flush_textures(); } - for(vector::iterator i=texture_stack.end(); i!=texture_stack.begin(); ) + for(auto i=texture_stack.end(); i!=texture_stack.begin(); ) if((--i)->tag==tag) { i->replaced = texture_stack.size(); @@ -124,13 +122,6 @@ void Renderer::set_lighting(const Lighting *l) add_shader_data(l->get_shader_data()); } -void Renderer::set_clipping(const Clipping *c) -{ - state->clipping = c; - if(c) - add_shader_data(c->get_shader_data()); -} - void Renderer::set_shader_program(const Program *p, const ProgramData *d) { state->shprog = p; @@ -223,7 +214,7 @@ void Renderer::end() add_shader_data(standard_shdata); excluded.clear(); - PipelineState::clear(); + commands.use_pipeline(0); } void Renderer::exclude(const Renderable &renderable) @@ -242,21 +233,20 @@ void Renderer::render(const Renderable &renderable, Tag tag) renderable.render(*this, tag); } -void Renderer::clear() -{ - clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT|STENCIL_BUFFER_BIT); -} - -void Renderer::clear(BufferBits buffers) +void Renderer::clear(const ClearValue *values) { pipeline_state.set_framebuffer(state->framebuffer); - commands.clear(buffers); + pipeline_state.set_viewport(state->viewport); + pipeline_state.set_scissor(state->scissor); + commands.use_pipeline(&pipeline_state); + commands.clear(values); } void Renderer::draw(const Batch &batch) { apply_state(); batch.refresh(); + commands.use_pipeline(&pipeline_state); commands.draw(batch); } @@ -264,10 +254,11 @@ void Renderer::draw_instanced(const Batch &batch, unsigned count) { apply_state(); batch.refresh(); + commands.use_pipeline(&pipeline_state); commands.draw_instanced(batch, count); } -void Renderer::resolve_multisample(Framebuffer &target, BufferBits buffers) +void Renderer::resolve_multisample(Framebuffer &target) { if(!state->framebuffer) throw invalid_operation("Renderer::resolve_multisample"); @@ -278,7 +269,18 @@ void Renderer::resolve_multisample(Framebuffer &target, BufferBits buffers) throw incompatible_data("Renderer::resolve_multisample"); pipeline_state.set_framebuffer(state->framebuffer); - commands.resolve_multisample(target, buffers); + commands.use_pipeline(&pipeline_state); + commands.resolve_multisample(target); +} + +void Renderer::begin_query(const QueryPool &pool, unsigned index) +{ + commands.begin_query(pool, index); +} + +void Renderer::end_query(const QueryPool &pool, unsigned index) +{ + commands.end_query(pool, index); } void Renderer::apply_state() @@ -313,20 +315,19 @@ void Renderer::apply_state() pipeline_state.set_front_face(state->front_face); pipeline_state.set_face_cull(state->face_cull); - pipeline_state.set_enabled_clip_planes(state->clipping ? (1<clipping->get_n_planes())-1 : 0); if(state->texture_count::const_iterator i=texture_stack.begin(); i!=texture_stack.end(); ++i) + for(const BoundTexture &t: texture_stack) { - int unit = (i->tag.id ? state->shprog->get_uniform_binding(i->tag) : i->unit); + int unit = (t.tag.id ? state->shprog->get_uniform_binding(t.tag) : t.unit); if(unit>=0) - pipeline_state.set_texture(unit, i->texture, i->sampler); + pipeline_state.set_texture(unit, t.texture, t.sampler); } bool shdata_changed = changed&SHADER_DATA; - for(vector::const_iterator i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i) + for(auto i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i) shdata_changed = (i->shdata->get_generation()!=i->generation); bool extra_shdata = (shdata_stack.size()>state->shdata_count); @@ -334,10 +335,10 @@ void Renderer::apply_state() { if(extra_shdata) shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end()); - for(vector::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i) + for(const BoundProgramData &d: shdata_stack) { - i->shdata->apply(*state->shprog, pipeline_state); - i->generation = i->shdata->get_generation(); + d.shdata->apply(*state->shprog, pipeline_state); + d.generation = d.shdata->get_generation(); } changed &= ~SHADER_DATA; } @@ -348,36 +349,8 @@ void Renderer::apply_state() } -Renderer::BoundTexture::BoundTexture(): - unit(-1), - texture(0), - sampler(0), - replaced(-1) -{ } - - Renderer::BoundProgramData::BoundProgramData(const ProgramData *d): - shdata(d), - generation(0) -{ } - - -Renderer::State::State(): - camera(0), - framebuffer(0), - viewport(0), - scissor(0), - texture_count(0), - clipping(0), - shprog(0), - shdata_count(0), - vertex_setup(0), - front_face(NON_MANIFOLD), - face_cull(NO_CULL), - depth_test(0), - stencil_test(0), - blend(0), - object_lod_bias(0) + shdata(d) { } } // namespace GL