2014-05-07 07:11:18 +04:00
|
|
|
/* -*- 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"
|
|
|
|
|
2014-09-19 03:14:22 +04:00
|
|
|
#include "GLDefs.h"
|
|
|
|
#include "mozilla/TypeTraits.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
|
2014-05-07 07:11:18 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-11-17 05:21:04 +03:00
|
|
|
/** Represents a binding to a GL binding point
|
2014-05-07 07:11:18 +04:00
|
|
|
*/
|
2014-09-19 03:14:22 +04:00
|
|
|
template<typename T>
|
2014-11-17 05:21:04 +03:00
|
|
|
class WebGLBindable
|
2014-05-07 07:11:18 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-11-17 05:21:04 +03:00
|
|
|
WebGLBindable() : mTarget(LOCAL_GL_NONE) { }
|
|
|
|
bool HasEverBeenBound() const { return mTarget != LOCAL_GL_NONE; }
|
2014-05-07 07:11:18 +04:00
|
|
|
|
2014-11-17 05:21:04 +03:00
|
|
|
void BindTo(T target) {
|
2014-09-19 03:14:22 +04:00
|
|
|
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;
|
|
|
|
}
|
2014-05-07 07:11:18 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
//! Called after mTarget has been changed by BindTo(target).
|
|
|
|
virtual void OnTargetChanged() {}
|
|
|
|
|
2014-09-19 03:14:22 +04:00
|
|
|
T mTarget;
|
2014-05-07 07:11:18 +04:00
|
|
|
};
|
|
|
|
|
2014-11-17 05:21:04 +03:00
|
|
|
|
|
|
|
/** Represents a GL name that can be bound to a target.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class WebGLBindableName
|
|
|
|
: public WebGLBindable<T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-12-11 01:49:09 +03:00
|
|
|
explicit WebGLBindableName(GLuint aName)
|
2014-11-17 05:21:04 +03:00
|
|
|
: WebGLBindable<T>()
|
2014-12-11 01:49:09 +03:00
|
|
|
, mGLName(aName)
|
2014-11-17 05:21:04 +03:00
|
|
|
{ }
|
|
|
|
GLuint GLName() const { return mGLName; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const GLuint mGLName;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-05-07 07:11:18 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // !WEBGLBINDABLENAME_H_
|