1 #ifndef MSP_GL_RENDERER_H_
2 #define MSP_GL_RENDERER_H_
8 #include "pipelinestate.h"
9 #include "programdata.h"
30 Rendering supervisor. This is the primary interface for setting state and
31 issuing draw commands.
33 The Renderer class allows setting textures and uniform values by names (using
34 ProgramData for the latter). The names are resolved into binding points when
35 the resources are needed for a draw command.
37 A state stack is provided to help with state management in render graphs.
38 Renderables can save the state by pushing it on the stack before beginning
39 their work, and pop it afterwards to restore it without disturbing state set
46 RAII helper class for pushing state on the stack.
54 Push(Renderer &r): renderer(r) { renderer.push_state(); }
55 ~Push() { renderer.pop_state(); }
62 mutable int binding = -1;
63 const Texture *texture = 0;
64 const Sampler *sampler = 0;
68 struct BoundProgramData
70 const ProgramData *shdata;
71 mutable unsigned generation = 0;
73 BoundProgramData(const ProgramData *);
78 const Camera *camera = 0;
80 const Framebuffer *framebuffer = 0;
81 const Rect *viewport = 0;
82 const Rect *scissor = 0;
83 unsigned texture_count = 0;
84 const Program *shprog = 0;
85 unsigned shdata_count = 0;
86 const VertexSetup *vertex_setup = 0;
87 FaceWinding front_face = NON_MANIFOLD;
88 CullMode face_cull = NO_CULL;
89 const DepthTest *depth_test = 0;
90 const StencilTest *stencil_test = 0;
91 const Blend *blend = 0;
92 unsigned object_lod_bias = 0;
101 unsigned char changed = 0;
102 std::vector<State> state_stack;
104 std::vector<BoundTexture> texture_stack;
105 ProgramData standard_shdata;
106 std::vector<BoundProgramData> shdata_stack;
107 PipelineState pipeline_state;
114 /** Sets the camera to render from. The model matrix is reset to identity. */
115 void set_camera(const Camera &);
117 const Camera *get_camera() const { return state->camera; }
119 /** Replaces the Renderer's model matrix. */
120 void set_matrix(const Matrix &);
122 /** Applies a transform to the Renderer's model matrix. */
123 void transform(const Matrix &);
125 /** Returns the current model matrix. */
126 const Matrix &get_matrix() const { return state->model_matrix; }
128 void set_framebuffer(const Framebuffer *);
129 void set_viewport(const Rect *);
130 void set_scissor(const Rect *);
132 const Framebuffer *get_framebuffer() const { return state->framebuffer; }
134 void set_texture(Tag, const Texture *, const Sampler * = 0);
136 void flush_textures();
138 DEPRECATED void set_material(const Material *);
140 DEPRECATED void set_lighting(const Lighting *);
142 /** Sets the shader program to use. As a convenience, uniform values may be
143 specified at the same time. */
144 void set_shader_program(const Program *prog, const ProgramData *data = 0);
146 /** Adds uniform values, which will be available for shader programs. If
147 multiple ProgramData objects with the same uniforms are added, the one added
148 last will be used. */
149 void add_shader_data(const ProgramData &data);
151 DEPRECATED void flush_shader_data() { flush_shader_data_(); }
153 void flush_shader_data_();
156 void set_vertex_setup(const VertexSetup *);
157 void set_front_face(FaceWinding);
158 void set_face_cull(CullMode);
160 void set_depth_test(const DepthTest *);
161 void set_stencil_test(const StencilTest *);
162 void set_blend(const Blend *);
164 void set_object_lod_bias(unsigned);
165 unsigned get_object_lod_bias() const { return state->object_lod_bias; }
167 /** Saves the current state so it can be restored later. */
170 /** Restores a previously saved state. Must be matched with an earlier
174 /** Unbinds all objects and resets related state. There must be no unpopped
175 state in the stack. The Renderer remains valid and may be reused for
176 further rendering. */
179 void clear(const ClearValue *);
181 /** Draws a batch of primitives. A shader must be active. */
182 void draw(const Batch &);
184 /** Draws multiple instances of a batch of primitives. A shader must be active. */
185 void draw_instanced(const Batch &, unsigned);
187 /** Resolves multisample attachments from the active framebuffer into
189 void resolve_multisample(Framebuffer &target);
191 void begin_query(const QueryPool &, unsigned);
192 void end_query(const QueryPool &, unsigned);