changed(0),
matrices_loaded(false),
shdata_applied(0),
- camera(0),
state_stack(1)
{
state_stack.reserve(16);
reset_state();
excluded.clear();
- camera = c;
- if(camera)
- {
- state->modelview_matrix = camera->get_view_matrix();
- standard_shdata.uniform("projection_matrix", camera->get_projection_matrix());
- }
- else
- {
- state->modelview_matrix = MatrixStack::modelview().top();
- standard_shdata.uniform("projection_matrix", MatrixStack::projection().top());
- }
- changed |= MATRIX|STANDARD_SHDATA;
+ if(c)
+ set_camera(*c);
+}
+
+void Renderer::set_camera(const Camera &c)
+{
+ state->camera = &c;
+ standard_shdata.uniform("projection_matrix", state->camera->get_projection_matrix());
+ changed |= STANDARD_SHDATA|LEGACY_PROJECTION;
+ set_matrix(state->camera->get_view_matrix());
}
void Renderer::set_matrix(const Matrix &matrix)
if(state_stack.size()==1)
throw stack_underflow("Renderer::pop_state");
+ const Camera *old_camera = state->camera;
const Lighting *old_lighting = state->lighting;
const Clipping *old_clipping = state->clipping;
state_stack.pop_back();
}
shdata_applied = min<unsigned>(shdata_applied, shdata_stack.size());
changed |= MATRIX;
+ if(state->camera!=old_camera)
+ {
+ standard_shdata.uniform("projection_matrix", state->camera->get_projection_matrix());
+ changed |= STANDARD_SHDATA|LEGACY_PROJECTION;
+ }
if(state->lighting!=old_lighting)
{
if(state->lighting)
if(!matrices_loaded)
{
MatrixStack::modelview().push();
- if(camera)
- {
- MatrixStack::projection().push();
- camera->apply();
- }
+ MatrixStack::projection().push();
matrices_loaded = true;
}
+ if(changed&LEGACY_PROJECTION)
+ {
+ MatrixStack::projection() = state->camera->get_projection_matrix();
+ changed &= ~LEGACY_PROJECTION;
+ }
+
if(changed&LEGACY_MATRIX)
{
MatrixStack::modelview() = state->modelview_matrix;
Renderer::State::State():
+ camera(0),
texture(0),
texturing(0),
lowest_effect_texunit(TexUnit::get_n_units()),
private:
struct State
{
+ const Camera *camera;
Matrix modelview_matrix;
const Texture *texture;
const Texturing *texturing;
LEGACY_CLIPPING = 8,
SHADER_DATA = 16,
MATERIAL_SHDATA = 32,
- STANDARD_SHDATA = 64
+ STANDARD_SHDATA = 64,
+ LEGACY_PROJECTION = 128
};
unsigned char changed;
bool matrices_loaded;
unsigned shdata_applied;
- const Camera *camera;
std::vector<State> state_stack;
State *state;
ProgramData standard_shdata;
times without an intervening end(). */
void begin(const Camera *);
+ /** Sets the camera to render from. The modelview matrix is reset to the
+ camera's view matrix. */
+ void set_camera(const Camera &);
+
+ const Camera *get_camera() const { return state->camera; }
+
/** Replaces the Renderer's modelview matrix. */
void set_matrix(const Matrix &);
/** Returns the current modelview matrix. */
const Matrix &get_matrix() const { return state->modelview_matrix; }
- const Camera *get_camera() const { return camera; }
-
void set_texture(const Texture *);
void set_texturing(const Texturing *);
unsigned allocate_effect_texunit();