gecko/dom/canvas/WebGLBindableName.h
Dan Glastonbury 729760f4fe Bug 1002281 - Change WebGLBindableName to make mGLName const. r=jgilbert
Split the two functions into two classes. WebGLRenderBuffer and
WebGLVertexArray are special cases.

--HG--
extra : source : 547e328ef878882bce8df3fc1b1e28926d910f1d
2014-11-17 12:21:04 +10:00

71 lines
1.6 KiB
C++

/* -*- 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:
WebGLBindableName(GLuint name)
: WebGLBindable<T>()
, mGLName(name)
{ }
GLuint GLName() const { return mGLName; }
protected:
const GLuint mGLName;
};
} // namespace mozilla
#endif // !WEBGLBINDABLENAME_H_