1 #ifndef MSP_GL_RENDERER_H_
2 #define MSP_GL_RENDERER_H_
25 A class for supervising the rendering process. While many Renderables (in
26 particular, Objects and Scenes) can by rendered without a Renderer, using one
27 will often be more efficient. This is especially true for ObjectInstances.
29 The Renderer works by deferring GL state changes until something is actually
30 being drawn. This avoids many unnecessary GL calls if consecutive renderables
31 use the same resources.
33 A state stack is provided to help with state scoping. Typically a Renderable
34 will push the current state on entry, set whatever state it requires, render
35 itself, and pop the state when it's done. An RAII helper class is provided for
36 the push/pop operation.
47 Push(Renderer &r): renderer(r) { renderer.push_state(); }
48 ~Push() { renderer.pop_state(); }
55 const Renderable &renderable;
58 Exclude(Renderer &r, const Renderable &e): renderer(r), renderable(e) { renderer.exclude(renderable); }
59 ~Exclude() { renderer.include(renderable); }
65 const Texture *texture;
66 const Texturing *texturing;
67 const Material *material;
68 const Lighting *lighting;
69 Matrix lighting_matrix;
70 const Program *shprog;
71 unsigned shdata_count;
72 const WindingTest *winding_test;
78 class MtxStack: public MatrixStack
86 virtual void update();
92 std::vector<State> state_stack;
94 bool lighting_changed;
95 std::vector<const ProgramData *> shdata_stack;
97 const Buffer *element_buffer;
98 std::set<const Renderable *> excluded;
101 Renderer(const Camera *);
104 MatrixStack &matrix_stack() { return mtx_stack; }
106 const Camera *get_camera() const { return camera; }
108 void set_texture(const Texture *);
109 void set_texturing(const Texturing *);
110 void set_material(const Material *);
112 void set_lighting(const Lighting *);
114 /** Sets the shader program to use. An initial set of data can be set as
115 well, with the same semantics as add_shader_data. */
116 void set_shader_program(const Program *prog, const ProgramData *data = 0);
118 /** Adds another set of data to be use with shader programs. The data is
119 independent of any shader program changes and remains in effect until the
120 Renderer state is popped. */
121 void add_shader_data(const ProgramData &data);
123 void set_element_buffer(const Buffer *);
124 void set_winding_test(const WindingTest *);
125 void set_reverse_winding(bool);
127 /** Saves the current state so it can be restored later. */
130 /** Restores a previously saved state. Must be matched with an earlier
134 /** Prepares for temporarily bypassing the Renderer by synchronizing the
135 current state with GL. No additional call is necessary to resume using the
139 void exclude(const Renderable &);
140 void include(const Renderable &);
142 void render(const Renderable &, const Tag & = Tag());
143 void draw(const Batch &);