X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Frenderer.cpp;h=b142da75448652c3135a9aa3b30e796aa374f8ac;hb=f19366d32cc29287a2730cfba90893e407754081;hp=5610f30a7e4a863c1afb11f043903e0e0314c6d8;hpb=f8bf444f26ce0bb392b96317ef3665be0af110aa;p=libs%2Fgl.git diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 5610f30a..b142da75 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -2,8 +2,8 @@ #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" @@ -29,7 +29,6 @@ Renderer::Renderer(): shdata_stack.reserve(32); state = &state_stack.back(); add_shader_data(standard_shdata); - commands.use_pipeline(pipeline_state); } Renderer::~Renderer() @@ -89,7 +88,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(); @@ -224,7 +223,7 @@ void Renderer::end() add_shader_data(standard_shdata); excluded.clear(); - PipelineState::clear(); + commands.use_pipeline(0); } void Renderer::exclude(const Renderable &renderable) @@ -243,21 +242,18 @@ 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); + 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); } @@ -265,10 +261,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"); @@ -279,7 +276,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() @@ -319,15 +327,15 @@ void Renderer::apply_state() 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); @@ -335,10 +343,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; }