X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Frenderer.cpp;h=0c5bf77454ed25c32151f2a44ed189723234a192;hb=016f0f0dd51511f98d0bf398d99199d7dec1543c;hp=d3124f0da334c7439e630266db0eef7c8c4654cf;hpb=6d2e2a0bb28496a8c25b441009bdd2a1a1e72d81;p=libs%2Fgl.git diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index d3124f0d..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); } @@ -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); @@ -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); }