Bumping manifests a=b2g-bump
[gecko.git] / dom / canvas / WebGLBindableName.h
blobd92616fb292eef876ee9f85bfc8db685fd3c408e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WEBGLBINDABLENAME_H_
7 #define WEBGLBINDABLENAME_H_
9 #include "WebGLTypes.h"
11 #include "GLDefs.h"
12 #include "mozilla/TypeTraits.h"
13 #include "mozilla/Assertions.h"
15 namespace mozilla {
17 /** Represents a binding to a GL binding point
19 template<typename T>
20 class WebGLBindable
22 public:
23 WebGLBindable() : mTarget(LOCAL_GL_NONE) { }
24 bool HasEverBeenBound() const { return mTarget != LOCAL_GL_NONE; }
26 void BindTo(T target) {
27 MOZ_ASSERT(target != LOCAL_GL_NONE, "Can't bind to GL_NONE.");
28 MOZ_ASSERT(!HasEverBeenBound() || mTarget == target, "Rebinding is illegal.");
30 bool targetChanged = (target != mTarget);
31 mTarget = target;
32 if (targetChanged)
33 OnTargetChanged();
36 T Target() const {
37 MOZ_ASSERT(HasEverBeenBound());
38 return mTarget;
41 protected:
42 //! Called after mTarget has been changed by BindTo(target).
43 virtual void OnTargetChanged() {}
45 T mTarget;
49 /** Represents a GL name that can be bound to a target.
51 template<typename T>
52 class WebGLBindableName
53 : public WebGLBindable<T>
55 public:
57 explicit WebGLBindableName(GLuint aName)
58 : WebGLBindable<T>()
59 , mGLName(aName)
60 { }
61 GLuint GLName() const { return mGLName; }
63 protected:
64 const GLuint mGLName;
68 } // namespace mozilla
70 #endif // !WEBGLBINDABLENAME_H_