From fd8083f61d82a4ad07b2408797773a792de17116 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 2 Sep 2010 10:38:26 -0400 Subject: [PATCH] Bug 592416 - Various WebGL fixes - r=vladimir --- content/canvas/src/WebGLContextGL.cpp | 52 +++++++++++++++---- content/canvas/test/webgl/failing_tests.txt | 3 -- .../more/functions/vertexAttribPointer.html | 1 - .../canvas/nsICanvasRenderingContextWebGL.idl | 3 +- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index d1a4f70cf4bb..58f1eaeec7bd 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -223,7 +223,7 @@ WebGLContext::BindFramebuffer(WebGLenum target, nsIWebGLFramebuffer *fbobj) WebGLFramebuffer *wfb; if (target != LOCAL_GL_FRAMEBUFFER) - return ErrorInvalidOperation("BindFramebuffer: target must be GL_FRAMEBUFFER"); + return ErrorInvalidEnum("BindFramebuffer: target must be GL_FRAMEBUFFER"); if (!GetConcreteObjectAndGLName("bindFramebuffer", fbobj, &wfb, &framebuffername, &isNull)) return NS_OK; @@ -1751,7 +1751,7 @@ WebGLContext::GetFramebufferAttachmentParameter(WebGLenum target, WebGLenum atta break; default: - return ErrorInvalidEnum("GetFramebufferAttachmentParameter: invalid parameter"); + return ErrorInvalidEnumInfo("GetFramebufferAttachmentParameter: pname", pname); } } else if (atype == LOCAL_GL_TEXTURE) { switch (pname) { @@ -1777,10 +1777,18 @@ WebGLContext::GetFramebufferAttachmentParameter(WebGLenum target, WebGLenum atta break; default: - return ErrorInvalidEnum("GetFramebufferAttachmentParameter: invalid parameter"); + return ErrorInvalidEnumInfo("GetFramebufferAttachmentParameter: pname", pname); } - } else { - NS_WARNING("Unknown framebuffer attachment type?"); + } else if (atype == LOCAL_GL_NONE) { + switch (pname) { + case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: + wrval->SetAsInt32(atype); + break; + + default: + return ErrorInvalidEnumInfo("GetFramebufferAttachmentParameter: pname", pname); + } + } else { // GL bug? should never happen return NS_ERROR_FAILURE; } @@ -3282,39 +3290,61 @@ WebGLContext::ShaderSource(nsIWebGLShader *sobj, const nsAString& source) NS_IMETHODIMP WebGLContext::VertexAttribPointer(WebGLuint index, WebGLint size, WebGLenum type, - WebGLboolean normalized, WebGLuint stride, - WebGLuint byteOffset) + WebGLboolean normalized, WebGLsizei stride, + WebGLsizeiptr byteOffset) { if (mBoundArrayBuffer == nsnull) return ErrorInvalidOperation("VertexAttribPointer: must have valid GL_ARRAY_BUFFER binding"); + WebGLsizei requiredAlignment = 1; switch (type) { case LOCAL_GL_BYTE: case LOCAL_GL_UNSIGNED_BYTE: + requiredAlignment = 1; + break; case LOCAL_GL_SHORT: case LOCAL_GL_UNSIGNED_SHORT: + requiredAlignment = 2; + break; // XXX case LOCAL_GL_FIXED: case LOCAL_GL_FLOAT: + requiredAlignment = 4; break; default: return ErrorInvalidEnumInfo("VertexAttribPointer: type", type); } + // requiredAlignment should always be a power of two. + WebGLsizei requiredAlignmentMask = requiredAlignment - 1; + if (index >= mAttribBuffers.Length()) return ErrorInvalidValue("VertexAttribPointer: index out of range - %d >= %d", index, mAttribBuffers.Length()); if (size < 1 || size > 4) return ErrorInvalidValue("VertexAttribPointer: invalid element size"); + if (stride < 0 || stride > 255) // see WebGL spec section 6.6 "Vertex Attribute Data Stride" + return ErrorInvalidValue("VertexAttribPointer: negative stride"); + + if (byteOffset < 0) + return ErrorInvalidValue("VertexAttribPointer: negative offset"); + + if (stride & requiredAlignmentMask) { + return ErrorInvalidValue("VertexAttribPointer: stride doesn't satisfy the alignment " + "requirement of given type"); + } + + if (byteOffset & requiredAlignmentMask) { + return ErrorInvalidValue("VertexAttribPointer: byteOffset doesn't satisfy the alignment " + "requirement of given type"); + + } + /* XXX make work with bufferSubData & heterogeneous types if (type != mBoundArrayBuffer->GLType()) return ErrorInvalidOperation("VertexAttribPointer: type must match bound VBO type: %d != %d", type, mBoundArrayBuffer->GLType()); */ - // XXX 0 stride? - //if (stride < (GLuint) size) - // return ErrorInvalidOperation("VertexAttribPointer: stride must be >= size!"); - WebGLVertexAttribData &vd = mAttribBuffers[index]; vd.buf = mBoundArrayBuffer; diff --git a/content/canvas/test/webgl/failing_tests.txt b/content/canvas/test/webgl/failing_tests.txt index 17803e7e0d53..2fa38a31484b 100644 --- a/content/canvas/test/webgl/failing_tests.txt +++ b/content/canvas/test/webgl/failing_tests.txt @@ -8,7 +8,6 @@ conformance/context-attributes-alpha-depth-stencil-antialias.html conformance/context-attributes.html conformance/context-type-test.html conformance/framebuffer-object-attachment.html -conformance/framebuffer-test.html conformance/get-active-test.html conformance/gl-bind-attrib-location-test.html conformance/gl-enum-tests.html @@ -58,7 +57,5 @@ more/functions/texSubImage2DHTMLBadArgs.html more/functions/uniformfBadArgs.html more/functions/uniformiBadArgs.html more/functions/uniformMatrixBadArgs.html -more/functions/vertexAttribPointer.html -more/functions/vertexAttribPointerBadArgs.html more/glsl/arrayOutOfBounds.html conformance/renderbuffer-initialization.html diff --git a/content/canvas/test/webgl/more/functions/vertexAttribPointer.html b/content/canvas/test/webgl/more/functions/vertexAttribPointer.html index 70658ab48813..1e9c448d4468 100644 --- a/content/canvas/test/webgl/more/functions/vertexAttribPointer.html +++ b/content/canvas/test/webgl/more/functions/vertexAttribPointer.html @@ -65,7 +65,6 @@ Tests.endUnit = function(gl, prog, v,n,t) { } Tests.testVertexAttribPointerVBO = function(gl, prog, v,n,t) { -console.log(v); var vbo = gl.createBuffer(); var vertsArr = new Float32Array(verts); gl.bindBuffer(gl.ARRAY_BUFFER, vbo); diff --git a/dom/interfaces/canvas/nsICanvasRenderingContextWebGL.idl b/dom/interfaces/canvas/nsICanvasRenderingContextWebGL.idl index 5fed505fd499..99f20a5b7033 100644 --- a/dom/interfaces/canvas/nsICanvasRenderingContextWebGL.idl +++ b/dom/interfaces/canvas/nsICanvasRenderingContextWebGL.idl @@ -49,6 +49,7 @@ typedef boolean WebGLboolean; typedef unsigned long WebGLbitfield; typedef long WebGLint; typedef long WebGLsizei; +typedef long WebGLsizeiptr; typedef unsigned long WebGLuint; typedef float WebGLfloat; typedef float WebGLclampf; @@ -830,7 +831,7 @@ interface nsICanvasRenderingContextWebGL : nsISupports [noscript] void vertexAttrib4fv_array(in WebGLuint indx, in WebGLArrayPtr values); // size is number of elements per attrib; offset, stride are in bytes - void vertexAttribPointer(in WebGLuint idx, in WebGLint size, in WebGLenum type, in WebGLboolean normalized, in WebGLuint stride, in WebGLuint offset); + void vertexAttribPointer(in WebGLuint idx, in WebGLint size, in WebGLenum type, in WebGLboolean normalized, in WebGLsizei stride, in WebGLsizeiptr offset); void viewport(in WebGLint x, in WebGLint y, in WebGLsizei width, in WebGLsizei height); };