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 Program *shprog;
69 unsigned shdata_count;
70 const WindingTest *winding_test;
75 class MtxStack: public MatrixStack
83 virtual void update();
89 std::vector<State> state_stack;
91 std::vector<const ProgramData *> shdata_stack;
93 const VertexArray *vertex_array;
94 const Buffer *element_buffer;
95 std::set<const Renderable *> excluded;
98 Renderer(const Camera *);
101 MatrixStack &matrix_stack() { return mtx_stack; }
103 const Camera *get_camera() const { return camera; }
105 void set_texture(const Texture *);
106 void set_texturing(const Texturing *);
107 void set_material(const Material *);
109 /** Sets the shader program to use. An initial set of data can be set as
110 well, with the same semantics as add_shader_data. */
111 void set_shader_program(const Program *prog, const ProgramData *data = 0);
113 /** Adds another set of data to be use with shader programs. The data is
114 independent of any shader program changes and remains in effect until the
115 Renderer state is popped. */
116 void add_shader_data(const ProgramData &data);
118 void set_vertex_array(const VertexArray *);
119 void set_element_buffer(const Buffer *);
120 void set_winding_test(const WindingTest *);
122 /** Saves the current state so it can be restored later. */
125 /** Restores a previously saved state. Must be matched with an earlier
129 /** Prepares for temporarily bypassing the Renderer by synchronizing the
130 current state with GL. No additional call is necessary to resume using the
134 void exclude(const Renderable &);
135 void include(const Renderable &);
137 void render(const Renderable &, const Tag & = Tag());
138 void draw(const Batch &);