]> git.tdb.fi Git - libs/gl.git/blob - source/renderer.h
Drop Id tags and copyright notices from files
[libs/gl.git] / source / renderer.h
1 #ifndef MSP_GL_RENDERER_H_
2 #define MSP_GL_RENDERER_H_
3
4 #include <vector>
5 #include "matrix.h"
6
7 namespace Msp {
8 namespace GL {
9
10 class Batch;
11 class Buffer;
12 class Camera;
13 class Material;
14 class Program;
15 class ProgramData;
16 class Texture;
17 class Texturing;
18 class VertexArray;
19 class WindingTest;
20
21 /**
22 A class for supervising the rendering process.  While many Renderables (in
23 particular, Objects and Scenes) can by rendered without a Renderer, using one
24 will often be more efficient.  This is especially true for ObjectInstances.
25
26 The Renderer works by deferring GL state changes until something is actually
27 being drawn.  This avoids many unnecessary GL calls. */
28 class Renderer
29 {
30 public:
31         class Push
32         {
33         private:
34                 Renderer &renderer;
35
36         public:
37                 Push(Renderer &r): renderer(r) { renderer.push_state(); }
38                 ~Push() { renderer.pop_state(); }
39         };
40
41 private:
42         struct State
43         {
44                 const Texture *texture;
45                 const Texturing *texturing;
46                 const Material *material;
47                 const Program *shprog;
48                 std::vector<const ProgramData *> shdata;
49                 const WindingTest *winding_test;
50
51                 State();
52         };
53
54         class MtxStack: public MatrixStack
55         {
56         private:
57                 Renderer &renderer;
58
59         public:
60                 MtxStack(Renderer &);
61         private:        
62                 virtual void update();
63         };
64
65         MtxStack mtx_stack;
66         bool mtx_changed;
67         const Camera *camera;
68         std::list<State> state_stack;
69         State *state;
70         const VertexArray *vertex_array;
71         bool vertex_array_changed;
72         const Buffer *element_buffer;
73
74 public:
75         Renderer(const Camera *);
76         ~Renderer();
77
78         MatrixStack &matrix_stack() { return mtx_stack; }
79
80         const Camera *get_camera() const { return camera; }
81
82         void set_texture(const Texture *);
83         void set_texturing(const Texturing *);
84         void set_material(const Material *);
85         void set_shader(const Program *, const ProgramData *);
86         void add_shader_data(const ProgramData *);
87         void set_vertex_array(const VertexArray *);
88         void set_element_buffer(const Buffer *);
89         void set_winding_test(const WindingTest *);
90
91         void push_state();
92         void pop_state();
93
94         /** Prepares for temporarily bypassing the Renderer. */
95         void escape();
96
97         void draw(const Batch &);
98
99 private:
100         void apply_state();
101 };
102
103 } // namespace GL
104 } // namespace Msp
105
106 #endif