Bug 1073216 - WebGL add strong GLenum support for VAO/Buffer bindings, and texture min/mag/wrap types. r=jgilbert
authorWalter Litwinczyk <wlitwinczyk@mozilla.com>
Fri, 26 Sep 2014 13:11:51 -0700
changeset 207641 47e245533187c543c7c47beff52ad9e5afab01ac
parent 207640 99b68a13246b91d61c81dde4c7685e8bd19f6dab
child 207642 4578cddde9f7d96204d3d573e0a0bb69755f7b1b
push id27564
push userryanvm@gmail.com
push dateMon, 29 Sep 2014 18:57:04 +0000
treeherdermozilla-central@ce9a0b34225e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1073216
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1073216 - WebGL add strong GLenum support for VAO/Buffer bindings, and texture min/mag/wrap types. r=jgilbert
dom/canvas/WebGLBuffer.cpp
dom/canvas/WebGLBuffer.h
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextDraw.cpp
dom/canvas/WebGLContextGL.cpp
dom/canvas/WebGLStrongTypes.h
dom/canvas/WebGLTexture.h
dom/canvas/WebGLVertexArray.cpp
dom/canvas/WebGLVertexArray.h
--- a/dom/canvas/WebGLBuffer.cpp
+++ b/dom/canvas/WebGLBuffer.cpp
@@ -8,17 +8,17 @@
 #include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
 #include "WebGLElementArrayCache.h"
 
 using namespace mozilla;
 
 WebGLBuffer::WebGLBuffer(WebGLContext *context)
-    : WebGLBindableName<GLenum>()
+    : WebGLBindableName<BufferBinding>()
     , WebGLContextBoundObject(context)
     , mByteLength(0)
 {
     SetIsDOMBinding();
     mContext->MakeContextCurrent();
     mContext->gl->fGenBuffers(1, &mGLName);
     mContext->mBuffers.insertBack(this);
 }
--- a/dom/canvas/WebGLBuffer.h
+++ b/dom/canvas/WebGLBuffer.h
@@ -8,24 +8,25 @@
 
 #include "GLDefs.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsWrapperCache.h"
 #include "WebGLBindableName.h"
 #include "WebGLObjectModel.h"
 #include "WebGLTypes.h"
+#include "WebGLStrongTypes.h"
 
 namespace mozilla {
 
 class WebGLElementArrayCache;
 
 class WebGLBuffer MOZ_FINAL
     : public nsWrapperCache
-    , public WebGLBindableName<GLenum>
+    , public WebGLBindableName<BufferBinding>
     , public WebGLRefCountedObject<WebGLBuffer>
     , public LinkedListElement<WebGLBuffer>
     , public WebGLContextBoundObject
 {
 public:
     explicit WebGLBuffer(WebGLContext* aContext);
 
     void Delete();
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -1267,17 +1267,17 @@ protected:
     WebGLContextFakeBlackStatus mFakeBlackStatus;
 
     class FakeBlackTexture
     {
         gl::GLContext* mGL;
         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; }
     };
 
     UniquePtr<FakeBlackTexture> mBlackOpaqueTexture2D,
                                 mBlackOpaqueTextureCubeMap,
                                 mBlackTransparentTexture2D,
                                 mBlackTransparentTextureCubeMap;
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -705,49 +705,48 @@ WebGLContext::UnbindFakeBlackTextures()
             gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
             gl->fBindTexture(LOCAL_GL_TEXTURE_CUBE_MAP, mBoundCubeMapTextures[i]->GLName());
         }
     }
 
     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();
   GLuint formerBinding = 0;
   gl->GetUIntegerv(target == LOCAL_GL_TEXTURE_2D
                    ? LOCAL_GL_TEXTURE_BINDING_2D
                    : 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
   // a bit unusual maybe to create 1x1 textures, and the stack may not have the alignment
   // 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) {
           gl->fTexImage2D(LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format, 1, 1,
                           0, format, LOCAL_GL_UNSIGNED_BYTE, zeros);
       }
   }
   free(zeros);
 
-  gl->fBindTexture(target, formerBinding);
+  gl->fBindTexture(target.get(), formerBinding);
 }
 
 WebGLContext::FakeBlackTexture::~FakeBlackTexture()
 {
   if (mGL) {
       mGL->MakeCurrent();
       mGL->fDeleteTextures(1, &mGLName);
   }
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -937,17 +937,17 @@ WebGLContext::GenerateMipmap(GLenum rawT
     if (gl->WorkAroundDriverBugs()) {
         // bug 696495 - to work around failures in the texture-mips.html test on various drivers, we
         // set the minification filter before calling glGenerateMipmap. This should not carry a significant performance
         // overhead so we do it unconditionally.
         //
         // 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());
     }
 }
 
 already_AddRefed<WebGLActiveInfo>
 WebGLContext::GetActiveUniform(WebGLProgram *prog, uint32_t index)
 {
--- a/dom/canvas/WebGLStrongTypes.h
+++ b/dom/canvas/WebGLStrongTypes.h
@@ -247,16 +247,36 @@ STRONG_GLENUM_BEGIN(TexType)
     STRONG_GLENUM_VALUE(UNSIGNED_INT_2_10_10_10_REV),
     STRONG_GLENUM_VALUE(UNSIGNED_INT_24_8),
     STRONG_GLENUM_VALUE(UNSIGNED_INT_10F_11F_11F_REV),
     STRONG_GLENUM_VALUE(UNSIGNED_INT_5_9_9_9_REV),
     STRONG_GLENUM_VALUE(HALF_FLOAT_OES),
     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),
     STRONG_GLENUM_VALUE(RED),
     STRONG_GLENUM_VALUE(ALPHA),
     STRONG_GLENUM_VALUE(RGB),
     STRONG_GLENUM_VALUE(RGBA),
     STRONG_GLENUM_VALUE(LUMINANCE),
@@ -400,9 +420,20 @@ STRONG_GLENUM_BEGIN(RBParam)
     STRONG_GLENUM_VALUE(RENDERBUFFER_RED_SIZE),
     STRONG_GLENUM_VALUE(RENDERBUFFER_GREEN_SIZE),
     STRONG_GLENUM_VALUE(RENDERBUFFER_BLUE_SIZE),
     STRONG_GLENUM_VALUE(RENDERBUFFER_ALPHA_SIZE),
     STRONG_GLENUM_VALUE(RENDERBUFFER_DEPTH_SIZE),
     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
--- a/dom/canvas/WebGLTexture.h
+++ b/dom/canvas/WebGLTexture.h
@@ -189,17 +189,19 @@ public:
         }
         imageInfo.mImageDataStatus = newStatus;
     }
 
     void DoDeferredImageInitialization(TexImageTarget imageTarget, GLint level);
 
 protected:
 
-    GLenum mMinFilter, mMagFilter, mWrapS, mWrapT;
+    TexMinFilter mMinFilter;
+    TexMagFilter mMagFilter;
+    TexWrap mWrapS, mWrapT;
 
     size_t mFacesCount, mMaxLevelWithCustomImages;
     nsTArray<ImageInfo> mImageInfos;
 
     bool mHaveGeneratedMipmap;
     WebGLTextureFakeBlackStatus mFakeBlackStatus;
 
     void EnsureMaxLevelWithCustomImagesAtLeast(size_t aMaxLevelWithCustomImages) {
@@ -222,33 +224,33 @@ protected:
 public:
 
     void Bind(TexTarget aTexTarget);
 
     void SetImageInfo(TexImageTarget aTarget, GLint aLevel,
                       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);
     }
 
     void SetGeneratedMipmap();
 
     void SetCustomMipmap();
--- a/dom/canvas/WebGLVertexArray.cpp
+++ b/dom/canvas/WebGLVertexArray.cpp
@@ -15,17 +15,17 @@
 using namespace mozilla;
 
 JSObject*
 WebGLVertexArray::WrapObject(JSContext *cx) {
     return dom::WebGLVertexArrayBinding::Wrap(cx, this);
 }
 
 WebGLVertexArray::WebGLVertexArray(WebGLContext* context)
-    : WebGLBindableName<GLenum>()
+    : WebGLBindableName<VAOBinding>()
     , WebGLContextBoundObject(context)
 {
     SetIsDOMBinding();
     context->mVertexArrays.insertBack(this);
 }
 
 WebGLVertexArray*
 WebGLVertexArray::Create(WebGLContext* context)
--- a/dom/canvas/WebGLVertexArray.h
+++ b/dom/canvas/WebGLVertexArray.h
@@ -5,28 +5,29 @@
 
 #ifndef WEBGLVERTEXARRAY_H_
 #define WEBGLVERTEXARRAY_H_
 
 #include "WebGLBindableName.h"
 #include "WebGLObjectModel.h"
 #include "WebGLBuffer.h"
 #include "WebGLVertexAttribData.h"
+#include "WebGLStrongTypes.h"
 
 #include "nsWrapperCache.h"
 
 #include "mozilla/LinkedList.h"
 
 namespace mozilla {
 
 class WebGLVertexArrayFake;
 
 class WebGLVertexArray
     : public nsWrapperCache
-    , public WebGLBindableName<GLenum>
+    , public WebGLBindableName<VAOBinding>
     , public WebGLRefCountedObject<WebGLVertexArray>
     , public LinkedListElement<WebGLVertexArray>
     , public WebGLContextBoundObject
 {
 // -----------------------------------------------------------------------------
 // PUBLIC
 public:
     static WebGLVertexArray* Create(WebGLContext* context);
@@ -36,18 +37,16 @@ public:
            ever been bound */
         BindTo(LOCAL_GL_VERTEX_ARRAY_BINDING);
         BindVertexArrayImpl();
     };
 
     virtual void GenVertexArray() = 0;
     virtual void BindVertexArrayImpl() = 0;
 
-    GLuint GLName() const { return mGLName; }
-
     // -------------------------------------------------------------------------
     // IMPLEMENT PARENT CLASSES
 
     void Delete();
 
     virtual void DeleteImpl() = 0;
 
     WebGLContext* GetParentObject() const {