This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathWebGLBindableName.h
70 lines (53 loc) · 1.62 KB
/
WebGLBindableName.h
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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef WEBGLBINDABLENAME_H_
#define WEBGLBINDABLENAME_H_
#include "WebGLTypes.h"
#include "GLDefs.h"
#include "mozilla/TypeTraits.h"
#include "mozilla/Assertions.h"
namespace mozilla {
/** Represents a binding to a GL binding point
*/
template<typename T>
class WebGLBindable
{
public:
WebGLBindable() : mTarget(LOCAL_GL_NONE) { }
bool HasEverBeenBound() const { return mTarget != LOCAL_GL_NONE; }
void BindTo(T target) {
MOZ_ASSERT(target != LOCAL_GL_NONE, "Can't bind to GL_NONE.");
MOZ_ASSERT(!HasEverBeenBound() || mTarget == target, "Rebinding is illegal.");
bool targetChanged = (target != mTarget);
mTarget = target;
if (targetChanged)
OnTargetChanged();
}
T Target() const {
MOZ_ASSERT(HasEverBeenBound());
return mTarget;
}
protected:
//! Called after mTarget has been changed by BindTo(target).
virtual void OnTargetChanged() {}
T mTarget;
};
/** Represents a GL name that can be bound to a target.
*/
template<typename T>
class WebGLBindableName
: public WebGLBindable<T>
{
public:
explicit WebGLBindableName(GLuint aName)
: WebGLBindable<T>()
, mGLName(aName)
{ }
GLuint GLName() const { return mGLName; }
protected:
const GLuint mGLName;
};
} // namespace mozilla
#endif // !WEBGLBINDABLENAME_H_