зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
88baefe614
Коммит
89a0a8b4f6
|
@ -14,20 +14,16 @@
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
/** Represents a GL name that can be bound to a target.
|
||||
/** Represents a binding to a GL binding point
|
||||
*/
|
||||
template<typename T>
|
||||
class WebGLBindableName
|
||||
class WebGLBindable
|
||||
{
|
||||
public:
|
||||
WebGLBindable() : mTarget(LOCAL_GL_NONE) { }
|
||||
bool HasEverBeenBound() const { return mTarget != LOCAL_GL_NONE; }
|
||||
|
||||
WebGLBindableName()
|
||||
: mGLName(0)
|
||||
, mTarget(LOCAL_GL_NONE)
|
||||
{ }
|
||||
|
||||
void BindTo(T target)
|
||||
{
|
||||
void BindTo(T target) {
|
||||
MOZ_ASSERT(target != LOCAL_GL_NONE, "Can't bind to GL_NONE.");
|
||||
MOZ_ASSERT(!HasEverBeenBound() || mTarget == target, "Rebinding is illegal.");
|
||||
|
||||
|
@ -37,22 +33,38 @@ public:
|
|||
OnTargetChanged();
|
||||
}
|
||||
|
||||
bool HasEverBeenBound() const { return mTarget != LOCAL_GL_NONE; }
|
||||
GLuint GLName() const { return mGLName; }
|
||||
T Target() const {
|
||||
MOZ_ASSERT(HasEverBeenBound());
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//! Called after mTarget has been changed by BindTo(target).
|
||||
virtual void OnTargetChanged() {}
|
||||
|
||||
GLuint mGLName;
|
||||
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_
|
||||
|
|
|
@ -12,13 +12,11 @@
|
|||
|
||||
using namespace mozilla;
|
||||
|
||||
WebGLBuffer::WebGLBuffer(WebGLContext *context)
|
||||
: WebGLBindableName<BufferBinding>()
|
||||
WebGLBuffer::WebGLBuffer(WebGLContext* context, GLuint buf)
|
||||
: WebGLBindableName<BufferBinding>(buf)
|
||||
, WebGLContextBoundObject(context)
|
||||
, mByteLength(0)
|
||||
{
|
||||
mContext->MakeContextCurrent();
|
||||
mContext->gl->fGenBuffers(1, &mGLName);
|
||||
mContext->mBuffers.insertBack(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class WebGLBuffer MOZ_FINAL
|
|||
, public WebGLContextBoundObject
|
||||
{
|
||||
public:
|
||||
explicit WebGLBuffer(WebGLContext* aContext);
|
||||
explicit WebGLBuffer(WebGLContext* context, GLuint buf);
|
||||
|
||||
void Delete();
|
||||
|
||||
|
|
|
@ -361,7 +361,11 @@ WebGLContext::CreateBuffer()
|
|||
if (IsContextLost())
|
||||
return nullptr;
|
||||
|
||||
nsRefPtr<WebGLBuffer> globj = new WebGLBuffer(this);
|
||||
GLuint buf = 0;
|
||||
MakeContextCurrent();
|
||||
gl->fGenBuffers(1, &buf);
|
||||
|
||||
nsRefPtr<WebGLBuffer> globj = new WebGLBuffer(this, buf);
|
||||
return globj.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -1372,7 +1372,12 @@ WebGLContext::CreateTexture()
|
|||
{
|
||||
if (IsContextLost())
|
||||
return nullptr;
|
||||
nsRefPtr<WebGLTexture> globj = new WebGLTexture(this);
|
||||
|
||||
GLuint tex = 0;
|
||||
MakeContextCurrent();
|
||||
gl->fGenTextures(1, &tex);
|
||||
|
||||
nsRefPtr<WebGLTexture> globj = new WebGLTexture(this, tex);
|
||||
return globj.forget();
|
||||
}
|
||||
|
||||
|
@ -3098,7 +3103,12 @@ WebGLContext::CreateFramebuffer()
|
|||
{
|
||||
if (IsContextLost())
|
||||
return nullptr;
|
||||
nsRefPtr<WebGLFramebuffer> globj = new WebGLFramebuffer(this);
|
||||
|
||||
GLuint fbo = 0;
|
||||
MakeContextCurrent();
|
||||
gl->fGenFramebuffers(1, &fbo);
|
||||
|
||||
nsRefPtr<WebGLFramebuffer> globj = new WebGLFramebuffer(this, fbo);
|
||||
return globj.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,16 +26,14 @@ WebGLFramebuffer::WrapObject(JSContext* cx)
|
|||
return dom::WebGLFramebufferBinding::Wrap(cx, this);
|
||||
}
|
||||
|
||||
WebGLFramebuffer::WebGLFramebuffer(WebGLContext* context)
|
||||
: WebGLBindableName<FBTarget>()
|
||||
WebGLFramebuffer::WebGLFramebuffer(WebGLContext* context, GLuint fbo)
|
||||
: WebGLBindableName<FBTarget>(fbo)
|
||||
, WebGLContextBoundObject(context)
|
||||
, mStatus(0)
|
||||
, mDepthAttachment(LOCAL_GL_DEPTH_ATTACHMENT)
|
||||
, mStencilAttachment(LOCAL_GL_STENCIL_ATTACHMENT)
|
||||
, mDepthStencilAttachment(LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
|
||||
{
|
||||
mContext->MakeContextCurrent();
|
||||
mContext->gl->fGenFramebuffers(1, &mGLName);
|
||||
mContext->mFramebuffers.insertBack(this);
|
||||
|
||||
mColorAttachments.SetLength(1);
|
||||
|
|
|
@ -34,7 +34,7 @@ class WebGLFramebuffer MOZ_FINAL
|
|||
public:
|
||||
MOZ_DECLARE_REFCOUNTED_TYPENAME(WebGLFramebuffer)
|
||||
|
||||
explicit WebGLFramebuffer(WebGLContext* context);
|
||||
explicit WebGLFramebuffer(WebGLContext* context, GLuint fbo);
|
||||
|
||||
struct Attachment
|
||||
{
|
||||
|
|
|
@ -42,8 +42,8 @@ WebGLRenderbuffer::WrapObject(JSContext *cx) {
|
|||
return dom::WebGLRenderbufferBinding::Wrap(cx, this);
|
||||
}
|
||||
|
||||
WebGLRenderbuffer::WebGLRenderbuffer(WebGLContext *context)
|
||||
: WebGLBindableName<RBTarget>()
|
||||
WebGLRenderbuffer::WebGLRenderbuffer(WebGLContext* context)
|
||||
: WebGLBindable<RBTarget>()
|
||||
, WebGLContextBoundObject(context)
|
||||
, mPrimaryRB(0)
|
||||
, mSecondaryRB(0)
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace mozilla {
|
|||
|
||||
class WebGLRenderbuffer MOZ_FINAL
|
||||
: public nsWrapperCache
|
||||
, public WebGLBindableName<RBTarget>
|
||||
, public WebGLBindable<RBTarget>
|
||||
, public WebGLRefCountedObject<WebGLRenderbuffer>
|
||||
, public LinkedListElement<WebGLRenderbuffer>
|
||||
, public WebGLRectangleObject
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
using namespace mozilla;
|
||||
|
||||
WebGLSampler::WebGLSampler(WebGLContext* context)
|
||||
: WebGLContextBoundObject(context)
|
||||
: WebGLBindableName<GLenum>(0),
|
||||
WebGLContextBoundObject(context)
|
||||
{
|
||||
MOZ_CRASH("Not Implemented.");
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
namespace mozilla {
|
||||
|
||||
class WebGLSampler MOZ_FINAL
|
||||
: public WebGLBindableName<GLenum>
|
||||
, public nsWrapperCache
|
||||
: public nsWrapperCache
|
||||
, public WebGLBindableName<GLenum>
|
||||
, public WebGLRefCountedObject<WebGLSampler>
|
||||
, public LinkedListElement<WebGLSampler>
|
||||
, public WebGLContextBoundObject
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
using namespace mozilla;
|
||||
|
||||
JSObject*
|
||||
WebGLTexture::WrapObject(JSContext *cx) {
|
||||
WebGLTexture::WrapObject(JSContext* cx) {
|
||||
return dom::WebGLTextureBinding::Wrap(cx, this);
|
||||
}
|
||||
|
||||
WebGLTexture::WebGLTexture(WebGLContext *context)
|
||||
: WebGLBindableName<TexTarget>()
|
||||
WebGLTexture::WebGLTexture(WebGLContext* context, GLuint tex)
|
||||
: WebGLBindableName<TexTarget>(tex)
|
||||
, WebGLContextBoundObject(context)
|
||||
, mMinFilter(LOCAL_GL_NEAREST_MIPMAP_LINEAR)
|
||||
, mMagFilter(LOCAL_GL_LINEAR)
|
||||
|
@ -38,8 +38,6 @@ WebGLTexture::WebGLTexture(WebGLContext *context)
|
|||
, mMaxMipmapLevel(1000)
|
||||
, mFakeBlackStatus(WebGLTextureFakeBlackStatus::IncompleteTexture)
|
||||
{
|
||||
mContext->MakeContextCurrent();
|
||||
mContext->gl->fGenTextures(1, &mGLName);
|
||||
mContext->mTextures.insertBack(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class WebGLTexture MOZ_FINAL
|
|||
, public WebGLFramebufferAttachable
|
||||
{
|
||||
public:
|
||||
explicit WebGLTexture(WebGLContext* aContext);
|
||||
explicit WebGLTexture(WebGLContext* aContext, GLuint tex);
|
||||
|
||||
void Delete();
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
using namespace mozilla;
|
||||
|
||||
WebGLTransformFeedback::WebGLTransformFeedback(WebGLContext* context)
|
||||
: WebGLContextBoundObject(context)
|
||||
: WebGLBindableName<GLenum>(0)
|
||||
, WebGLContextBoundObject(context)
|
||||
{
|
||||
MOZ_CRASH("Not Implemented.");
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
namespace mozilla {
|
||||
|
||||
class WebGLTransformFeedback MOZ_FINAL
|
||||
: public WebGLBindableName<GLenum>
|
||||
, public nsWrapperCache
|
||||
: public nsWrapperCache
|
||||
, public WebGLBindableName<GLenum>
|
||||
, public WebGLRefCountedObject<WebGLTransformFeedback>
|
||||
, public LinkedListElement<WebGLTransformFeedback>
|
||||
, public WebGLContextBoundObject
|
||||
|
|
|
@ -20,8 +20,9 @@ WebGLVertexArray::WrapObject(JSContext *cx) {
|
|||
}
|
||||
|
||||
WebGLVertexArray::WebGLVertexArray(WebGLContext* context)
|
||||
: WebGLBindableName<VAOBinding>()
|
||||
: WebGLBindable<VAOBinding>()
|
||||
, WebGLContextBoundObject(context)
|
||||
, mGLName(0)
|
||||
{
|
||||
context->mVertexArrays.insertBack(this);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class WebGLVertexArrayFake;
|
|||
|
||||
class WebGLVertexArray
|
||||
: public nsWrapperCache
|
||||
, public WebGLBindableName<VAOBinding>
|
||||
, public WebGLBindable<VAOBinding>
|
||||
, public WebGLRefCountedObject<WebGLVertexArray>
|
||||
, public LinkedListElement<WebGLVertexArray>
|
||||
, public WebGLContextBoundObject
|
||||
|
@ -61,6 +61,8 @@ public:
|
|||
// -------------------------------------------------------------------------
|
||||
// MEMBER FUNCTIONS
|
||||
|
||||
GLuint GLName() const { return mGLName; }
|
||||
|
||||
void EnsureAttrib(GLuint index);
|
||||
bool HasAttrib(GLuint index) {
|
||||
return index < mAttribs.Length();
|
||||
|
@ -82,6 +84,7 @@ protected:
|
|||
// -------------------------------------------------------------------------
|
||||
// MEMBERS
|
||||
|
||||
GLuint mGLName;
|
||||
nsTArray<WebGLVertexAttribData> mAttribs;
|
||||
WebGLRefPtr<WebGLBuffer> mElementArrayBuffer;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче