From fcbc7ad7baa068b904953a5ebcdd0d2363d62d31 Mon Sep 17 00:00:00 2001 From: Walter Litwinczyk Date: Fri, 26 Sep 2014 13:11:51 -0700 Subject: [PATCH] Bug 1073216 - WebGL add strong GLenum support for VAO/Buffer bindings, and texture min/mag/wrap types. r=jgilbert --- dom/canvas/WebGLBuffer.cpp | 2 +- dom/canvas/WebGLBuffer.h | 3 ++- dom/canvas/WebGLContext.h | 2 +- dom/canvas/WebGLContextDraw.cpp | 9 ++++----- dom/canvas/WebGLContextGL.cpp | 2 +- dom/canvas/WebGLStrongTypes.h | 31 +++++++++++++++++++++++++++++++ dom/canvas/WebGLTexture.h | 14 ++++++++------ dom/canvas/WebGLVertexArray.cpp | 2 +- dom/canvas/WebGLVertexArray.h | 5 ++--- 9 files changed, 51 insertions(+), 19 deletions(-) diff --git a/dom/canvas/WebGLBuffer.cpp b/dom/canvas/WebGLBuffer.cpp index 9ed81e9b755..f7c434ce980 100644 --- a/dom/canvas/WebGLBuffer.cpp +++ b/dom/canvas/WebGLBuffer.cpp @@ -13,7 +13,7 @@ using namespace mozilla; WebGLBuffer::WebGLBuffer(WebGLContext *context) - : WebGLBindableName() + : WebGLBindableName() , WebGLContextBoundObject(context) , mByteLength(0) { diff --git a/dom/canvas/WebGLBuffer.h b/dom/canvas/WebGLBuffer.h index 3373b8a767e..819dce1fb63 100644 --- a/dom/canvas/WebGLBuffer.h +++ b/dom/canvas/WebGLBuffer.h @@ -13,6 +13,7 @@ #include "WebGLBindableName.h" #include "WebGLObjectModel.h" #include "WebGLTypes.h" +#include "WebGLStrongTypes.h" namespace mozilla { @@ -20,7 +21,7 @@ class WebGLElementArrayCache; class WebGLBuffer MOZ_FINAL : public nsWrapperCache - , public WebGLBindableName + , public WebGLBindableName , public WebGLRefCountedObject , public LinkedListElement , public WebGLContextBoundObject diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h index 951dac8ae03..eb6fc5dad74 100644 --- a/dom/canvas/WebGLContext.h +++ b/dom/canvas/WebGLContext.h @@ -1272,7 +1272,7 @@ protected: GLuint mGLName; public: - FakeBlackTexture(gl::GLContext* gl, GLenum target, GLenum format); + FakeBlackTexture(gl::GLContext* gl, TexTarget target, GLenum format); ~FakeBlackTexture(); GLuint GLName() const { return mGLName; } }; diff --git a/dom/canvas/WebGLContextDraw.cpp b/dom/canvas/WebGLContextDraw.cpp index dc1fea8bed7..6535a089953 100644 --- a/dom/canvas/WebGLContextDraw.cpp +++ b/dom/canvas/WebGLContextDraw.cpp @@ -710,11 +710,10 @@ WebGLContext::UnbindFakeBlackTextures() gl->fActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture); } -WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, GLenum format) +WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, TexTarget target, GLenum format) : mGL(gl) , mGLName(0) { - MOZ_ASSERT(target == LOCAL_GL_TEXTURE_2D || target == LOCAL_GL_TEXTURE_CUBE_MAP); MOZ_ASSERT(format == LOCAL_GL_RGB || format == LOCAL_GL_RGBA); mGL->MakeCurrent(); @@ -724,7 +723,7 @@ WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, G : LOCAL_GL_TEXTURE_BINDING_CUBE_MAP, &formerBinding); gl->fGenTextures(1, &mGLName); - gl->fBindTexture(target, mGLName); + gl->fBindTexture(target.get(), mGLName); // we allocate our zeros on the heap, and we overallocate (16 bytes instead of 4) // to minimize the risk of running into a driver bug in texImage2D, as it is @@ -732,7 +731,7 @@ WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, G // that texImage2D expects. void* zeros = calloc(1, 16); if (target == LOCAL_GL_TEXTURE_2D) { - gl->fTexImage2D(target, 0, format, 1, 1, + gl->fTexImage2D(target.get(), 0, format, 1, 1, 0, format, LOCAL_GL_UNSIGNED_BYTE, zeros); } else { for (GLuint i = 0; i < 6; ++i) { @@ -742,7 +741,7 @@ WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, G } free(zeros); - gl->fBindTexture(target, formerBinding); + gl->fBindTexture(target.get(), formerBinding); } WebGLContext::FakeBlackTexture::~FakeBlackTexture() diff --git a/dom/canvas/WebGLContextGL.cpp b/dom/canvas/WebGLContextGL.cpp index f98cd6fcd03..cbd9ac54e9d 100644 --- a/dom/canvas/WebGLContextGL.cpp +++ b/dom/canvas/WebGLContextGL.cpp @@ -942,7 +942,7 @@ WebGLContext::GenerateMipmap(GLenum rawTarget) // note that the choice of GL_NEAREST_MIPMAP_NEAREST really matters. See Chromium bug 101105. gl->fTexParameteri(target.get(), LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_NEAREST_MIPMAP_NEAREST); gl->fGenerateMipmap(target.get()); - gl->fTexParameteri(target.get(), LOCAL_GL_TEXTURE_MIN_FILTER, tex->MinFilter()); + gl->fTexParameteri(target.get(), LOCAL_GL_TEXTURE_MIN_FILTER, tex->MinFilter().get()); } else { gl->fGenerateMipmap(target.get()); } diff --git a/dom/canvas/WebGLStrongTypes.h b/dom/canvas/WebGLStrongTypes.h index f7ff6fc37e9..445ca26e00e 100644 --- a/dom/canvas/WebGLStrongTypes.h +++ b/dom/canvas/WebGLStrongTypes.h @@ -252,6 +252,26 @@ STRONG_GLENUM_BEGIN(TexType) STRONG_GLENUM_VALUE(FLOAT_32_UNSIGNED_INT_24_8_REV), STRONG_GLENUM_END(TexType) +STRONG_GLENUM_BEGIN(TexMinFilter) + STRONG_GLENUM_VALUE(NEAREST), + STRONG_GLENUM_VALUE(LINEAR), + STRONG_GLENUM_VALUE(NEAREST_MIPMAP_NEAREST), + STRONG_GLENUM_VALUE(LINEAR_MIPMAP_NEAREST), + STRONG_GLENUM_VALUE(NEAREST_MIPMAP_LINEAR), + STRONG_GLENUM_VALUE(LINEAR_MIPMAP_LINEAR), +STRONG_GLENUM_END(TexMinFilter) + +STRONG_GLENUM_BEGIN(TexMagFilter) + STRONG_GLENUM_VALUE(NEAREST), + STRONG_GLENUM_VALUE(LINEAR), +STRONG_GLENUM_END(TexMagFilter) + +STRONG_GLENUM_BEGIN(TexWrap) + STRONG_GLENUM_VALUE(REPEAT), + STRONG_GLENUM_VALUE(CLAMP_TO_EDGE), + STRONG_GLENUM_VALUE(MIRRORED_REPEAT), +STRONG_GLENUM_END(TexWrap) + STRONG_GLENUM_BEGIN(TexFormat) STRONG_GLENUM_VALUE(NONE), STRONG_GLENUM_VALUE(DEPTH_COMPONENT), @@ -405,4 +425,15 @@ STRONG_GLENUM_BEGIN(RBParam) STRONG_GLENUM_VALUE(RENDERBUFFER_STENCIL_SIZE), STRONG_GLENUM_END(RBParam) +STRONG_GLENUM_BEGIN(VAOBinding) + STRONG_GLENUM_VALUE(NONE), + STRONG_GLENUM_VALUE(VERTEX_ARRAY_BINDING), +STRONG_GLENUM_END(VAOBinding) + +STRONG_GLENUM_BEGIN(BufferBinding) + STRONG_GLENUM_VALUE(NONE), + STRONG_GLENUM_VALUE(ARRAY_BUFFER), + STRONG_GLENUM_VALUE(ELEMENT_ARRAY_BUFFER), +STRONG_GLENUM_END(BufferBinding) + #endif diff --git a/dom/canvas/WebGLTexture.h b/dom/canvas/WebGLTexture.h index 88db44797a3..000c875dfd5 100644 --- a/dom/canvas/WebGLTexture.h +++ b/dom/canvas/WebGLTexture.h @@ -194,7 +194,9 @@ public: protected: - GLenum mMinFilter, mMagFilter, mWrapS, mWrapT; + TexMinFilter mMinFilter; + TexMagFilter mMagFilter; + TexWrap mWrapS, mWrapT; size_t mFacesCount, mMaxLevelWithCustomImages; nsTArray mImageInfos; @@ -227,23 +229,23 @@ public: GLsizei aWidth, GLsizei aHeight, TexInternalFormat aFormat, TexType aType, WebGLImageDataStatus aStatus); - void SetMinFilter(GLenum aMinFilter) { + void SetMinFilter(TexMinFilter aMinFilter) { mMinFilter = aMinFilter; SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown); } - void SetMagFilter(GLenum aMagFilter) { + void SetMagFilter(TexMagFilter aMagFilter) { mMagFilter = aMagFilter; SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown); } - void SetWrapS(GLenum aWrapS) { + void SetWrapS(TexWrap aWrapS) { mWrapS = aWrapS; SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown); } - void SetWrapT(GLenum aWrapT) { + void SetWrapT(TexWrap aWrapT) { mWrapT = aWrapT; SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown); } - GLenum MinFilter() const { return mMinFilter; } + TexMinFilter MinFilter() const { return mMinFilter; } bool DoesMinFilterRequireMipmap() const { return !(mMinFilter == LOCAL_GL_NEAREST || mMinFilter == LOCAL_GL_LINEAR); diff --git a/dom/canvas/WebGLVertexArray.cpp b/dom/canvas/WebGLVertexArray.cpp index 9b49ad7cb16..211dcbeb77d 100644 --- a/dom/canvas/WebGLVertexArray.cpp +++ b/dom/canvas/WebGLVertexArray.cpp @@ -20,7 +20,7 @@ WebGLVertexArray::WrapObject(JSContext *cx) { } WebGLVertexArray::WebGLVertexArray(WebGLContext* context) - : WebGLBindableName() + : WebGLBindableName() , WebGLContextBoundObject(context) { SetIsDOMBinding(); diff --git a/dom/canvas/WebGLVertexArray.h b/dom/canvas/WebGLVertexArray.h index 6d58c8dd068..5d242f1e095 100644 --- a/dom/canvas/WebGLVertexArray.h +++ b/dom/canvas/WebGLVertexArray.h @@ -10,6 +10,7 @@ #include "WebGLObjectModel.h" #include "WebGLBuffer.h" #include "WebGLVertexAttribData.h" +#include "WebGLStrongTypes.h" #include "nsWrapperCache.h" @@ -21,7 +22,7 @@ class WebGLVertexArrayFake; class WebGLVertexArray : public nsWrapperCache - , public WebGLBindableName + , public WebGLBindableName , public WebGLRefCountedObject , public LinkedListElement , public WebGLContextBoundObject @@ -41,8 +42,6 @@ public: virtual void GenVertexArray() = 0; virtual void BindVertexArrayImpl() = 0; - GLuint GLName() const { return mGLName; } - // ------------------------------------------------------------------------- // IMPLEMENT PARENT CLASSES