X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Frenderer.cpp;h=0c5bf77454ed25c32151f2a44ed189723234a192;hb=016f0f0dd51511f98d0bf398d99199d7dec1543c;hp=946f0100bbbf0a5467877e451343d643a0f13670;hpb=c89c1fb972fae2cb2f720cb3ec6cf8238ae8d2e1;p=libs%2Fgl.git diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 946f0100..0c5bf774 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -10,6 +10,7 @@ #include "renderable.h" #include "renderer.h" #include "resourcemanager.h" +#include "resources.h" #include "sampler.h" #include "texture.h" #include "vertexarray.h" @@ -20,7 +21,8 @@ using namespace std; namespace Msp { namespace GL { -Renderer::Renderer() +Renderer::Renderer(): + placeholder_texture(Resources::get_global().get("_placeholder.png")) { state_stack.reserve(16); shdata_stack.reserve(32); @@ -148,8 +150,12 @@ void Renderer::set_texture(Tag tag, const Texture *tex, int level, const Sampler State &state = get_state(); if(tex) + { if(ResourceManager *res_mgr = tex->get_manager()) res_mgr->resource_used(*tex); + if(!tex->is_loaded()) + tex = &placeholder_texture; + } if(texture_stack.size()>state.texture_count) { @@ -235,11 +241,7 @@ void Renderer::set_object_lod_bias(unsigned b) void Renderer::clear(const ClearValue *values) { - const State &state = get_state(); - - pipeline_state.set_framebuffer(state.framebuffer); - pipeline_state.set_viewport(state.viewport); - pipeline_state.set_scissor(state.scissor); + apply_framebuffer(); commands.use_pipeline(&pipeline_state); commands.clear(values); } @@ -247,7 +249,7 @@ void Renderer::clear(const ClearValue *values) void Renderer::draw(const Batch &batch) { apply_state(); - batch.refresh(); + batch.refresh(frame_index); pipeline_state.set_primitive_type(batch.get_type()); commands.use_pipeline(&pipeline_state); commands.draw(batch); @@ -256,7 +258,7 @@ void Renderer::draw(const Batch &batch) void Renderer::draw_instanced(const Batch &batch, unsigned count) { apply_state(); - batch.refresh(); + batch.refresh(frame_index); pipeline_state.set_primitive_type(batch.get_type()); commands.use_pipeline(&pipeline_state); commands.draw_instanced(batch, count); @@ -289,6 +291,16 @@ void Renderer::end_query(const QueryPool &pool, unsigned index) commands.end_query(pool, index); } +void Renderer::apply_framebuffer() +{ + const State &state = get_state(); + + pipeline_state.set_framebuffer(state.framebuffer); + static const Rect default_rect = Rect::max(); + pipeline_state.set_viewport(state.viewport ? *state.viewport : default_rect); + pipeline_state.set_scissor(state.scissor ? *state.scissor : default_rect); +} + void Renderer::apply_state() { const State &state = get_state(); @@ -296,9 +308,7 @@ void Renderer::apply_state() if(!state.shprog) throw invalid_operation("Renderer::apply_state"); - pipeline_state.set_framebuffer(state.framebuffer); - pipeline_state.set_viewport(state.viewport); - pipeline_state.set_scissor(state.scissor); + apply_framebuffer(); bool shprog_changed = (state.shprog!=pipeline_state.get_shader_program()); pipeline_state.set_shader_program(state.shprog); @@ -323,7 +333,7 @@ void Renderer::apply_state() shdata_stack.erase(shdata_stack.begin()+state.shdata_count, shdata_stack.end()); for(const BoundProgramData &d: shdata_stack) { - d.shdata->apply(*state.shprog, pipeline_state); + d.shdata->apply(*state.shprog, pipeline_state, frame_index); d.generation = d.shdata->get_generation(); } changed &= ~SHADER_DATA; @@ -332,9 +342,9 @@ void Renderer::apply_state() if(state.vertex_setup) { if(const VertexArray *array = state.vertex_setup->get_vertex_array()) - array->refresh(); + array->refresh(frame_index); if(const VertexArray *array = state.vertex_setup->get_instance_array()) - array->refresh(); + array->refresh(frame_index); } pipeline_state.set_vertex_setup(state.vertex_setup); @@ -353,9 +363,12 @@ void Renderer::apply_state() pipeline_state.set_texture(t.binding, t.texture, t.level, t.sampler); } - pipeline_state.set_depth_test(state.depth_test); - pipeline_state.set_stencil_test(state.stencil_test); - pipeline_state.set_blend(state.blend); + static const DepthTest default_depth_test; + pipeline_state.set_depth_test(state.depth_test ? *state.depth_test : default_depth_test); + static const StencilTest default_stencil_test; + pipeline_state.set_stencil_test(state.stencil_test ? *state.stencil_test : default_stencil_test); + static const Blend default_blend; + pipeline_state.set_blend(state.blend ? *state.blend : default_blend); }