Bug 1325500 (flattened) - Fix DrawRangeElements impl and require size=4 for packed int types. - r=daoshengmu a=lizzard
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 22 Dec 2016 15:59:45 -0800
changeset 374305 dd2a8702cb8f0aab3e51e24150518dff610e4f2c
parent 374304 fc51c91558dc824ba2d5fea2db9a4a3bce4491bc
child 374306 2d2153ad43c9ee058b21eeec125720fd30b54ffe
push id35
push userfmarier@mozilla.com
push dateThu, 09 Feb 2017 06:52:49 +0000
reviewersdaoshengmu, lizzard
bugs1325500
milestone52.0a2
Bug 1325500 (flattened) - Fix DrawRangeElements impl and require size=4 for packed int types. - r=daoshengmu a=lizzard MozReview-Commit-ID: B3YpgZn48Nl
dom/canvas/WebGL2Context.h
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextDraw.cpp
dom/canvas/WebGLContextValidate.cpp
--- a/dom/canvas/WebGL2Context.h
+++ b/dom/canvas/WebGL2Context.h
@@ -271,17 +271,26 @@ public:
     void VertexAttribDivisor(GLuint index, GLuint divisor);
     void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount);
     void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei instanceCount);
     */
 
     void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
                            GLenum type, WebGLintptr byteOffset)
     {
-        DrawElements(mode, count, type, byteOffset);
+        const char funcName[] = "drawRangeElements";
+        if (IsContextLost())
+            return;
+
+        if (end < start) {
+            ErrorInvalidValue("%s: end must be >= start.", funcName);
+            return;
+        }
+
+        DrawElements(mode, count, type, byteOffset, funcName);
     }
 
     // ------------------------------------------------------------------------
     // Multiple Render Targets - WebGL2ContextMRTs.cpp
     /* Implemented in WebGLContext
     void DrawBuffers(const dom::Sequence<GLenum>& buffers);
     */
 
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -1254,17 +1254,17 @@ protected:
 // Vertices Feature (WebGLContextVertices.cpp)
     GLenum mPrimRestartTypeBytes;
 
 public:
     void DrawArrays(GLenum mode, GLint first, GLsizei count);
     void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count,
                              GLsizei primcount);
     void DrawElements(GLenum mode, GLsizei count, GLenum type,
-                      WebGLintptr byteOffset);
+                      WebGLintptr byteOffset, const char* funcName = nullptr);
     void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type,
                                WebGLintptr byteOffset, GLsizei primcount);
 
     void EnableVertexAttribArray(GLuint index);
     void DisableVertexAttribArray(GLuint index);
 
     JS::Value GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
                               ErrorResult& rv);
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -691,19 +691,22 @@ WebGLContext::DrawElements_check(const c
                         funcName, WebGLContext::EnumName(type));
     }
 
     return true;
 }
 
 void
 WebGLContext::DrawElements(GLenum mode, GLsizei vertCount, GLenum type,
-                           WebGLintptr byteOffset)
+                           WebGLintptr byteOffset, const char* funcName)
 {
-    const char funcName[] = "drawElements";
+    if (!funcName) {
+        funcName = "drawElements";
+    }
+
     if (IsContextLost())
         return;
 
     MakeContextCurrent();
 
     bool error = false;
     ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
     if (error)
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -357,16 +357,26 @@ WebGLContext::ValidateAttribPointer(bool
     MOZ_ASSERT(IsPowerOfTwo(requiredAlignment));
     GLsizei requiredAlignmentMask = requiredAlignment - 1;
 
     if (size < 1 || size > 4) {
         ErrorInvalidValue("%s: invalid element size", info);
         return false;
     }
 
+    switch (type) {
+    case LOCAL_GL_INT_2_10_10_10_REV:
+    case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
+        if (size != 4) {
+            ErrorInvalidOperation("%s: size must be 4 for this type.", info);
+            return false;
+        }
+        break;
+    }
+
     // see WebGL spec section 6.6 "Vertex Attribute Data Stride"
     if (stride < 0 || stride > 255) {
         ErrorInvalidValue("%s: negative or too large stride", info);
         return false;
     }
 
     if (byteOffset < 0) {
         ErrorInvalidValue("%s: negative offset", info);