]> git.tdb.fi Git - libs/gl.git/blobdiff - source/renderer.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / renderer.cpp
diff --git a/source/renderer.cpp b/source/renderer.cpp
deleted file mode 100644 (file)
index c56216e..0000000
+++ /dev/null
@@ -1,268 +0,0 @@
-#include "batch.h"
-#include "buffer.h"
-#include "camera.h"
-#include "error.h"
-#include "lighting.h"
-#include "material.h"
-#include "program.h"
-#include "programdata.h"
-#include "renderable.h"
-#include "renderer.h"
-#include "texture.h"
-#include "texturing.h"
-#include "vertexarray.h"
-#include "windingtest.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GL {
-
-Renderer::Renderer(const Camera *c):
-       mtx_stack(*this),
-       mtx_changed(false),
-       camera(c),
-       state_stack(1),
-       lighting_changed(false),
-       vertex_array(0),
-       element_buffer(0)
-{
-       state_stack.reserve(16);
-       shdata_stack.reserve(32);
-       state = &state_stack.back();
-
-       MatrixStack::modelview().push();
-       if(camera)
-       {
-               MatrixStack::projection().push();
-               camera->apply();
-               mtx_stack.load(camera->get_matrix());
-       }
-       else
-               mtx_stack.load(MatrixStack::modelview().top());
-}
-
-Renderer::~Renderer()
-{
-       if(camera)
-               MatrixStack::projection().pop();
-       MatrixStack::modelview().pop();
-
-       Texturing::unbind();
-       Texture::unbind_from(0);
-       Material::unbind();
-       Lighting::unbind();
-       Program::unbind();
-       Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
-       WindingTest::unbind();
-}
-
-void Renderer::set_texture(const Texture *t)
-{
-       state->texture = t;
-       state->texturing = 0;
-}
-
-void Renderer::set_texturing(const Texturing *t)
-{
-       state->texturing = t;
-       state->texture = 0;
-}
-
-void Renderer::set_material(const Material *m)
-{
-       state->material = m;
-}
-
-void Renderer::set_lighting(const Lighting *l)
-{
-       state->lighting = l;
-       state->lighting_matrix = mtx_stack.top();
-       lighting_changed = true;
-}
-
-void Renderer::set_shader_program(const Program *p, const ProgramData *d)
-{
-       state->shprog = p;
-       if(p && d)
-               add_shader_data(*d);
-
-       /* Even if we have no new shdata, the existing ones need to be re-applied
-       to the new program */
-       shdata_changed = true;
-}
-
-void Renderer::add_shader_data(const ProgramData &d)
-{
-       shdata_stack.push_back(&d);
-       state->shdata_count = shdata_stack.size();
-       shdata_changed = true;
-}
-
-void Renderer::set_vertex_array(const VertexArray *a)
-{
-       vertex_array = a;
-}
-
-void Renderer::set_element_buffer(const Buffer *b)
-{
-       element_buffer = b;
-}
-
-void Renderer::set_winding_test(const WindingTest *w)
-{
-       state->winding_test = w;
-}
-
-void Renderer::set_reverse_winding(bool r)
-{
-       state->reverse_winding = r;
-}
-
-void Renderer::push_state()
-{
-       state_stack.push_back(state_stack.back());
-       state = &state_stack.back();
-       mtx_stack.push();
-}
-
-void Renderer::pop_state()
-{
-       if(state_stack.size()==1)
-               throw stack_underflow("Renderer::pop_state");
-
-       state_stack.pop_back();
-       state = &state_stack.back();
-       if(shdata_stack.size()>state->shdata_count)
-               shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end());
-       mtx_stack.pop();
-       mtx_changed = true;
-       shdata_changed = true;
-}
-
-void Renderer::escape()
-{
-       apply_state();
-       Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
-}
-
-void Renderer::exclude(const Renderable &renderable)
-{
-       excluded.insert(&renderable);
-}
-
-void Renderer::include(const Renderable &renderable)
-{
-       excluded.erase(&renderable);
-}
-
-void Renderer::render(const Renderable &renderable, const Tag &tag)
-{
-       if(!excluded.count(&renderable))
-               renderable.render(*this, tag);
-}
-
-void Renderer::draw(const Batch &batch)
-{
-       if(!vertex_array)
-               throw invalid_operation("Renderer::draw");
-
-       apply_state();
-
-       vertex_array->apply();
-
-       if(element_buffer)
-               element_buffer->bind_to(ELEMENT_ARRAY_BUFFER);
-       else
-               Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
-
-       batch.draw();
-}
-
-void Renderer::apply_state()
-{
-       /* We (mostly) let the objects themselves figure out if the binding has
-       changed */
-
-       if(state->texturing)
-               state->texturing->bind();
-       else
-       {
-               Texturing::unbind();
-               if(state->texture)
-                       state->texture->bind_to(0);
-               else
-                       Texture::unbind_from(0);
-       }
-
-       if(state->material)
-               state->material->bind();
-       else
-               Material::unbind();
-
-       if(lighting_changed)
-       {
-               if(state->lighting)
-               {
-                       MatrixStack::modelview() = state->lighting_matrix;
-                       state->lighting->bind();
-                       mtx_changed = true;
-                       lighting_changed = false;
-               }
-               else
-                       Lighting::unbind();
-       }
-
-       if(state->shprog)
-       {
-               state->shprog->bind();
-               if(shdata_changed)
-               {
-                       for(vector<const ProgramData *>::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i)
-                               (*i)->apply();
-                       shdata_changed = false;
-               }
-       }
-       else
-               Program::unbind();
-
-       if(state->winding_test)
-       {
-               if(state->reverse_winding)
-                       state->winding_test->get_reverse().bind();
-               else
-                       state->winding_test->bind();
-       }
-       else
-               WindingTest::unbind();
-
-       if(mtx_changed)
-       {
-               MatrixStack::modelview() = mtx_stack.top();
-               mtx_changed = false;
-       }
-}
-
-
-Renderer::State::State():
-       texture(0),
-       texturing(0),
-       material(0),
-       lighting(0),
-       shprog(0),
-       shdata_count(0),
-       winding_test(0)
-{ }
-
-
-Renderer::MtxStack::MtxStack(Renderer &r):
-       renderer(r)
-{ }
-
-void Renderer::MtxStack::update()
-{
-       renderer.mtx_changed = true;
-}
-
-} // namespace GL
-} // namespace Msp