namespace GL {
Renderer::Renderer(const Camera *c):
- mtx_stack(*this),
changed(0),
matrices_loaded(false),
shdata_applied(0),
if(camera)
{
- mtx_stack.load(camera->get_matrix());
+ state->modelview_matrix = camera->get_view_matrix();
standard_shdata.uniform("projection_matrix", camera->get_projection_matrix());
}
else
{
- mtx_stack.load(MatrixStack::modelview().top());
+ state->modelview_matrix = MatrixStack::modelview().top();
standard_shdata.uniform("projection_matrix", MatrixStack::projection().top());
}
}
void Renderer::set_matrix(const Matrix &matrix)
{
- mtx_stack.load(matrix);
+ state->modelview_matrix = matrix;
+ changed |= MATRIX;
}
void Renderer::transform(const Matrix &matrix)
{
- mtx_stack *= matrix;
+ state->modelview_matrix *= matrix;
+ changed |= MATRIX;
}
void Renderer::set_texture(const Texture *t)
void Renderer::set_lighting(const Lighting *l)
{
state->lighting = l;
- state->lighting_matrix = mtx_stack.top();
+ state->lighting_matrix = state->modelview_matrix;
if(l)
{
- l->update_shader_data(standard_shdata, mtx_stack.top());
+ l->update_shader_data(standard_shdata, state->lighting_matrix);
changed |= STANDARD_SHDATA;
}
changed |= LEGACY_LIGHTING;
void Renderer::set_clipping(const Clipping *c)
{
state->clipping = c;
- state->clipping_matrix = mtx_stack.top();
+ state->clipping_matrix = state->modelview_matrix;
if(c)
- c->update_shader_data(standard_shdata, mtx_stack.top());
+ c->update_shader_data(standard_shdata, state->clipping_matrix);
changed |= LEGACY_CLIPPING;
}
{
state_stack.push_back(state_stack.back());
state = &state_stack.back();
- mtx_stack.push();
}
void Renderer::pop_state()
changed |= SHADER_DATA;
}
shdata_applied = min<unsigned>(shdata_applied, shdata_stack.size());
- mtx_stack.pop();
changed |= MATRIX;
if(state->lighting!=old_lighting)
{
{
if(changed&MODERN_MATRIX)
{
- const Matrix &m = mtx_stack.top();
- standard_shdata.uniform("eye_obj_matrix", mtx_stack.top());
- LinAl::SquareMatrix<float, 3> nm = m.block<3, 3>(0, 0);
+ standard_shdata.uniform("eye_obj_matrix", state->modelview_matrix);
+ LinAl::SquareMatrix<float, 3> nm = state->modelview_matrix.block<3, 3>(0, 0);
nm = transpose(invert(nm));
standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0));
changed = (changed&~MODERN_MATRIX)|STANDARD_SHDATA;
if(changed&LEGACY_MATRIX)
{
- MatrixStack::modelview() = mtx_stack.top();
+ MatrixStack::modelview() = state->modelview_matrix;
changed &= ~LEGACY_MATRIX;
}
}
reverse_winding(false)
{ }
-
-Renderer::MtxStack::MtxStack(Renderer &r):
- renderer(r)
-{ }
-
-void Renderer::MtxStack::update()
-{
- renderer.changed |= MATRIX;
-}
-
} // namespace GL
} // namespace Msp
private:
struct State
{
+ Matrix modelview_matrix;
const Texture *texture;
const Texturing *texturing;
unsigned lowest_effect_texunit;
State();
};
- class MtxStack: public MatrixStack
- {
- private:
- Renderer &renderer;
-
- public:
- MtxStack(Renderer &);
- private:
- virtual void update();
- };
-
enum ChangeMask
{
LEGACY_MATRIX = 1,
STANDARD_SHDATA = 64
};
- MtxStack mtx_stack;
unsigned char changed;
bool matrices_loaded;
unsigned shdata_applied;
times without an intervening end(). */
void begin(const Camera *);
- /** Deprecated as unsafe. Use set_matrix() or transform() instead. */
- MatrixStack &matrix_stack() { return mtx_stack; }
-
/** Replaces the Renderer's modelview matrix. */
void set_matrix(const Matrix &);
void transform(const Matrix &);
/** Returns the current modelview matrix. */
- const Matrix &get_matrix() const { return mtx_stack.top(); }
+ const Matrix &get_matrix() const { return state->modelview_matrix; }
const Camera *get_camera() const { return camera; }