diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index f42eeab4dbf3..529df5e9bbab 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -1233,6 +1233,17 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } } + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn DisableVertexAttribArray(&self, attrib_id: u32) { + if attrib_id > self.limits.max_vertex_attribs { + return self.webgl_error(InvalidValue); + } + + self.ipc_renderer + .send(CanvasMsg::WebGL(WebGLCommand::DisableVertexAttribArray(attrib_id))) + .unwrap() + } + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11 fn DrawArrays(&self, mode: u32, first: i32, count: i32) { match mode { @@ -1997,13 +2008,51 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { return self.webgl_error(InvalidValue); } - if let constants::FLOAT = data_type { - let msg = CanvasMsg::WebGL( - WebGLCommand::VertexAttribPointer2f(attrib_id, size, normalized, stride, offset as u32)); - self.ipc_renderer.send(msg).unwrap() - } else { - panic!("VertexAttribPointer: Data Type not supported") + // "If no WebGLBuffer is bound to the ARRAY_BUFFER target, + // an INVALID_OPERATION error will be generated." + if self.bound_buffer_array.get().is_none() { + return self.webgl_error(InvalidOperation); + } + + // From the WebGL spec, 6.11 "Vertex Attribute Data Stride": + // + // "The WebGL API supports vertex attribute data strides up + // to 255 bytes. A call to vertexAttribPointer will + // generate an INVALID_VALUE error if the value for the + // stride parameter exceeds 255." + if stride as u32 > 255 { + return self.webgl_error(InvalidValue); } + + // From the WebGL spec, 6.14 "Fixed point support": + // + // "The WebGL API does not support the GL_FIXED data type". + // + // Other than that, WebGL uses the valid vertex attrib types + // from GLES 2.0.25 spec, page 20. Additionally, we have to + // do type-specific stride mathcing from 6.4 "Buffer Offset + // and Stride Requirements": + // + // "The offset arguments to drawElements and + // vertexAttribPointer, and the stride argument to + // vertexAttribPointer, must be a multiple of the size of + // the data type passed to the call, or an + // INVALID_OPERATION error is generated." + let cpp = match data_type { + constants::BYTE | + constants::UNSIGNED_BYTE => 1, + constants::SHORT | + constants::UNSIGNED_SHORT => 2, + constants::FLOAT => 4, + _ => return self.webgl_error(InvalidEnum), + }; + if stride % cpp != 0 || offset % cpp as i64 != 0 { + return self.webgl_error(InvalidOperation); + } + + let msg = CanvasMsg::WebGL( + WebGLCommand::VertexAttribPointer(attrib_id, size, data_type, normalized, stride, offset as u32)); + self.ipc_renderer.send(msg).unwrap() } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.4 diff --git a/components/script/dom/webidls/WebGLRenderingContext.webidl b/components/script/dom/webidls/WebGLRenderingContext.webidl index e95ce00e5e54..65b06d360be5 100644 --- a/components/script/dom/webidls/WebGLRenderingContext.webidl +++ b/components/script/dom/webidls/WebGLRenderingContext.webidl @@ -552,7 +552,7 @@ interface WebGLRenderingContextBase void depthRange(GLclampf zNear, GLclampf zFar); void detachShader(WebGLProgram? program, WebGLShader? shader); void disable(GLenum cap); - //void disableVertexAttribArray(GLuint index); + void disableVertexAttribArray(GLuint index); void drawArrays(GLenum mode, GLint first, GLsizei count); void drawElements(GLenum mode, GLsizei count, GLenum type, GLintptr offset); diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-vertex-attrib-zero-issues.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-vertex-attrib-zero-issues.html.ini index 93580149f5ff..3a7a9f86d014 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-vertex-attrib-zero-issues.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-vertex-attrib-zero-issues.html.ini @@ -1,9 +1,32 @@ [gl-vertex-attrib-zero-issues.html] type: testharness - expected: ERROR - [WebGL test #3: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] + [WebGL test #5: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] expected: FAIL - [WebGL test #4: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] + [WebGL test #7: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] + expected: FAIL + + [WebGL test #11: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] + expected: FAIL + + [WebGL test #13: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] + expected: FAIL + + [WebGL test #17: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] + expected: FAIL + + [WebGL test #19: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] + expected: FAIL + + [WebGL test #23: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] + expected: FAIL + + [WebGL test #25: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] + expected: FAIL + + [WebGL test #29: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] + expected: FAIL + + [WebGL test #31: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] expected: FAIL diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-vertexattribpointer.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-vertexattribpointer.html.ini deleted file mode 100644 index b263af3b8a94..000000000000 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-vertexattribpointer.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[gl-vertexattribpointer.html] - type: testharness - expected: CRASH diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/buffers/index-validation-with-resized-buffer.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/buffers/index-validation-with-resized-buffer.html.ini deleted file mode 100644 index 9a2db0486a9a..000000000000 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/buffers/index-validation-with-resized-buffer.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[index-validation-with-resized-buffer.html] - type: testharness - expected: CRASH diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/buffers/index-validation.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/buffers/index-validation.html.ini index 6b265933f0ce..013171df3e31 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/buffers/index-validation.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/buffers/index-validation.html.ini @@ -1,9 +1,14 @@ [index-validation.html] type: testharness - expected: ERROR [WebGL test #0: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be 36053. Threw exception TypeError: gl.checkFramebufferStatus is not a function] expected: FAIL - [WebGL test #4: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] + [WebGL test #9: getError expected: INVALID_OPERATION. Was NO_ERROR : ] + expected: FAIL + + [WebGL test #12: getError expected: INVALID_OPERATION. Was NO_ERROR : ] + expected: FAIL + + [WebGL test #15: getError expected: INVALID_VALUE. Was NO_ERROR : ] expected: FAIL diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-long-names-test.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-long-names-test.html.ini index d5b7a13216ba..0faeb66a6a63 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-long-names-test.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-long-names-test.html.ini @@ -1,12 +1,8 @@ [gl-bind-attrib-location-long-names-test.html] type: testharness - expected: ERROR - [WebGL test #4: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] - expected: FAIL - [WebGL test #4: at (0, 0) expected: 0,255,0,255 was 255,255,255,255] expected: FAIL - [WebGL test #5: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] + [WebGL test #8: at (0, 0) expected: 255,0,0,255 was 255,255,255,255] expected: FAIL diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-test.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-test.html.ini index b618b447b954..bf2436c12efe 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-test.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/programs/gl-bind-attrib-location-test.html.ini @@ -1,12 +1,8 @@ [gl-bind-attrib-location-test.html] type: testharness - expected: ERROR - [WebGL test #6: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] + [WebGL test #13: at (20, 15) expected: 255,0,0,255 was 0,0,0,255] expected: FAIL [WebGL test #7: at (20, 15) expected: 0,255,0,255 was 0,0,0,255] expected: FAIL - [WebGL test #9: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] - expected: FAIL - diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/rendering/more-than-65536-indices.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/rendering/more-than-65536-indices.html.ini deleted file mode 100644 index e8902ddddc52..000000000000 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/rendering/more-than-65536-indices.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[more-than-65536-indices.html] - type: testharness - expected: CRASH