-
Notifications
You must be signed in to change notification settings - Fork 0
/
gl_object.hpp
112 lines (92 loc) · 3.15 KB
/
gl_object.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef GL_OBJECT_HPP
#define GL_OBJECT_HPP
#include "gl.hpp"
namespace plush {
/**
* Base class for objects that represent OpenGL objects.
*
* These objects are owners: when they are created, the appropriate GL object
* is created (or allocated, according to type), and when they are destroyed,
* the GL object is also destroyed (or its reference count decremented).
*/
class GLObject {
protected:
/**
* A numeric identifier of the OpenGL object.
*
* OpenGL standard specifies that 0 is always an invalid identifier.
*
* OpenGL standard is not always clear whether various types of GL objects
* have separate numeric namespaces so do not rely on the identifier being
* unique between various types of objects.
*/
GLuint m_id;
/**
* Default constructor. Initializes m_id to 0 (invalid).
*/
GLObject() : m_id(0) { }
/**
* Destructor. The GL object should be destroyed or its reference count
* decreased here.
*/
virtual ~GLObject();
public:
/**
* Copy constructor; deleted as its behavior would be hard to define
* (the underlying GL object typically is not simply copyable).
*/
GLObject(const GLObject &src) = delete;
/**
* Assignment operator; deleted as its behavior would be hard to define.
*/
GLObject &operator=(const GLObject &src) = delete;
/**
* Returns the numeric identifier of the underlying OpenGL object.
*
* @important Use this call with care. It bypasses encapsulation
* and the caller has responsibility to keep the OpenGL object
* in the state the wrapper expects it to be.
*/
GLuint id() { return m_id; }
};
/**
* A non-owning, copyable, passable-by-value reference to an OpenGL object.
*
* Multiple proxies can exist for the same OpenGL object, and can be copied
* and reassigned as any primitive value.
*
* Each proxy type has an appropriate non-proxy GLObject type.
*/
template <typename T>
class GLObjectProxy {
protected:
/**
* A numeric identifier of the underlying OpenGL type.
*/
GLuint m_id;
/**
* Constructor. Makes a proxy for the OpenGL object with the given
* identifier.
*/
GLObjectProxy(GLuint id) : m_id(id) { }
public:
/**
* Constructor. The proxy is initialized to an empty value.
*/
GLObjectProxy() : m_id(0) { }
/**
* Constructor. Makes a proxy for the specified GLObject.
*/
GLObjectProxy(T &src) : m_id(src.id()) { }
/**
* Destructor (empty).
*/
~GLObjectProxy() { }
/**
* Returns true if the proxy is null, i.e. does not refer to any
* OpenGL object (its m_id is 0).
*/
bool isNull() const { return (m_id == 0); }
};
} // namespace
#endif