-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.hpp
61 lines (54 loc) · 1.19 KB
/
scene.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef SCENE_HPP
#define SCENE_HPP
#include <vector>
#include <set>
#include "device.hpp"
class renderable;
class batch {
public:
virtual ~batch() {}
virtual void add(renderable*) = 0;
virtual void remove(renderable*) = 0;
virtual state_set* create_state_set() = 0;
virtual void remove_state_set(state_set* s) = 0;
virtual void update(float t) = 0;
virtual void present() = 0;
};
class renderable {
public:
void attach(batch* b)
{
b->add(this);
init_state_sets(b);
}
void detach(batch *b)
{
remove_state_sets(b);
b->remove(this);
}
virtual void update(float t);
protected:
virtual void init_state_sets(batch* b) = 0;
virtual void remove_state_sets(batch* b) = 0;
};
class sorted_batch : public batch {
public:
sorted_batch(device* dev);
void add(renderable*);
void remove(renderable*);
state_set* create_state_set();
void remove_state_set(state_set* s);
void update(float t);
void present();
private:
typedef std::vector<state_set*> state_set_list;
typedef std::set<renderable*> renderable_set;
device* device_;
state_set_list state_sets_;
renderable_set renderables_;
};
inline sorted_batch::sorted_batch(device* dev) :
device_(dev)
{
}
#endif