7 #include "programdata.h"
10 #include "texturing.h"
11 #include "vertexarray.h"
12 #include "windingtest.h"
19 Renderer::Renderer(const Camera *c):
24 state(&state_stack.back()),
26 vertex_array_changed(false),
29 MatrixStack::modelview().push();
32 MatrixStack::projection().push();
34 mtx_stack.load(camera->get_matrix());
37 mtx_stack.load(MatrixStack::modelview().top());
43 MatrixStack::projection().pop();
44 MatrixStack::modelview().pop();
47 Texture::unbind_from(0);
50 Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
51 WindingTest::unbind();
54 void Renderer::set_texture(const Texture *t)
60 void Renderer::set_texturing(const Texturing *t)
66 void Renderer::set_material(const Material *m)
71 void Renderer::set_shader_program(const Program *p, const ProgramData *d)
76 shdata_changed = true;
79 void Renderer::add_shader_data(const ProgramData &d)
81 state->shdata.push_back(&d);
82 shdata_changed = true;
85 void Renderer::set_vertex_array(const VertexArray *a)
87 vertex_array_changed = (a!=vertex_array);
91 void Renderer::set_element_buffer(const Buffer *b)
96 void Renderer::set_winding_test(const WindingTest *w)
98 state->winding_test = w;
101 void Renderer::push_state()
103 state_stack.push_back(state_stack.back());
104 state = &state_stack.back();
108 void Renderer::pop_state()
110 if(state_stack.size()==1)
111 throw stack_underflow("Renderer::pop_state");
113 state_stack.pop_back();
114 state = &state_stack.back();
117 shdata_changed = true;
120 void Renderer::escape()
123 Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
126 void Renderer::draw(const Batch &batch)
129 throw invalid_operation("Renderer::draw");
133 // Until VertexArray acquires VAO support and becomes Bindable
134 if(vertex_array_changed)
136 vertex_array->apply();
137 vertex_array_changed = false;
141 element_buffer->bind_to(ELEMENT_ARRAY_BUFFER);
143 Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
148 void Renderer::apply_state()
150 // We let the objects themselves figure out if the binding has changed
153 state->texturing->bind();
158 state->texture->bind_to(0);
160 Texture::unbind_from(0);
164 state->material->bind();
170 state->shprog->bind();
173 for(vector<const ProgramData *>::const_iterator i=state->shdata.begin(); i!=state->shdata.end(); ++i)
175 shdata_changed = false;
181 if(state->winding_test)
182 state->winding_test->bind();
184 WindingTest::unbind();
188 MatrixStack::modelview() = mtx_stack.top();
194 Renderer::State::State():
203 Renderer::MtxStack::MtxStack(Renderer &r):
207 void Renderer::MtxStack::update()
209 renderer.mtx_changed = true;