X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Frenderer.cpp;h=d3124f0da334c7439e630266db0eef7c8c4654cf;hb=3d60c98715b1a93ae3c7b007c18557e0c2c99fc7;hp=999ff1a22e32bc3bfa6e72d84a88936f6187661d;hpb=175153f224916b92d02a325aac5628956cda8daf;p=libs%2Fgl.git diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 999ff1a2..d3124f0d 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -27,18 +27,19 @@ Renderer::Renderer() texture_stack.reserve(32); } -Renderer::~Renderer() -{ -} - void Renderer::begin() { if(current_state) throw invalid_operation("Renderer::begin"); - state_stack.push_back(State()); + ++frame_index; + state_stack.emplace_back(); current_state = &state_stack.back(); + + RendererBackend::begin(); + add_shader_data(standard_shdata); + commands.begin_frame(frame_index); } void Renderer::end() @@ -46,12 +47,12 @@ void Renderer::end() if(!current_state || state_stack.size()>1) throw invalid_operation("Renderer::end"); + RendererBackend::end(); + current_state = 0; state_stack.clear(); texture_stack.clear(); shdata_stack.clear(); - - commands.use_pipeline(0); } void Renderer::push_state() @@ -138,6 +139,11 @@ void Renderer::add_shader_data(const ProgramData &d) } void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp) +{ + set_texture(tag, tex, -1, samp); +} + +void Renderer::set_texture(Tag tag, const Texture *tex, int level, const Sampler *samp) { State &state = get_state(); @@ -164,11 +170,12 @@ void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp) break; } - texture_stack.push_back(BoundTexture()); + texture_stack.emplace_back(); BoundTexture &bound_tex = texture_stack.back(); bound_tex.tag = tag; bound_tex.texture = tex; bound_tex.sampler = samp; + bound_tex.level = level; state.texture_count = texture_stack.size(); } @@ -240,7 +247,8 @@ 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); } @@ -248,7 +256,8 @@ 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); } @@ -314,7 +323,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; @@ -323,9 +332,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); @@ -341,7 +350,7 @@ void Renderer::apply_state() if(t.binding<0 || shprog_changed) t.binding = state.shprog->get_uniform_binding(t.tag); if(t.binding>=0) - pipeline_state.set_texture(t.binding, t.texture, t.sampler); + pipeline_state.set_texture(t.binding, t.texture, t.level, t.sampler); } pipeline_state.set_depth_test(state.depth_test);