Skip to content
Permalink
Browse files

webgl: Add missing overload of bufferData().

I was writing this to fix the error in gl-enum-tests.html test (it now
gets farther along before it fails due to us missing
getTexParameter()), but it turned out that a lot of the conformance
tests were failing due to it.
  • Loading branch information
anholt committed Jan 5, 2017
1 parent af380c2 commit 4c656f1f6154978bf931016d8993acda93233065
@@ -991,6 +991,38 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
Ok(())
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
fn BufferData_(&self, target: u32, size: i64, usage: u32) -> Fallible<()> {
let bound_buffer = match target {
constants::ARRAY_BUFFER => self.bound_buffer_array.get(),
constants::ELEMENT_ARRAY_BUFFER => self.bound_buffer_element_array.get(),
_ => return Ok(self.webgl_error(InvalidEnum)),
};

let bound_buffer = match bound_buffer {
Some(bound_buffer) => bound_buffer,
None => return Ok(self.webgl_error(InvalidValue)),
};

if size < 0 {
return Ok(self.webgl_error(InvalidValue));
}

match usage {
constants::STREAM_DRAW |
constants::STATIC_DRAW |
constants::DYNAMIC_DRAW => (),
_ => return Ok(self.webgl_error(InvalidEnum)),
}

// FIXME: Allocating a buffer based on user-requested size is
// not great, but we don't have a fallible allocation to try.
let data = vec![0u8; size as usize];
handle_potential_webgl_error!(self, bound_buffer.buffer_data(target, &data, usage));

Ok(())
}

#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
unsafe fn BufferSubData(&self, _cx: *mut JSContext, target: u32, offset: i64, data: *mut JSObject) -> Fallible<()> {
@@ -489,14 +489,17 @@ interface WebGLRenderingContextBase
GLenum srcAlpha, GLenum dstAlpha);

// typedef (ArrayBuffer or ArrayBufferView) BufferDataSource;
//void bufferData(GLenum target, GLsizeiptr size, GLenum usage);
// FIXME(dmarcos) The function below is the original function in the webIdl:
// void bufferData(GLenum target, BufferDataSource? data, GLenum usage);
// The Code generator doesn't handle BufferDataSource so we're using 'object?'
// in the meantime, and marking the function as [Throws], so we can handle
// the type error from inside.
[Throws]
void bufferData(GLenum target, object? data, GLenum usage);
// FIXME: Codegen requires that this have [Throws] to match the other one.
[Throws]
void bufferData(GLenum target, GLsizeiptr size, GLenum usage);

//void bufferSubData(GLenum target, GLintptr offset, BufferDataSource? data);
[Throws]
void bufferSubData(GLenum target, GLintptr offset, object? data);

This file was deleted.

@@ -1,12 +1,5 @@
[buffer-data-array-buffer.html]
type: testharness
expected: ERROR
[WebGL test #3: getError expected: INVALID_OPERATION. Was INVALID_VALUE : ]
expected: FAIL

[WebGL test #5: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #3: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

This file was deleted.

@@ -9,42 +9,6 @@
[WebGL test #6: getError expected: INVALID_VALUE. Was NO_ERROR : after evaluating: context.clear(desktopGL['ACCUM_BUFFER_BIT'\] | context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT | context.STENCIL_BUFFER_BIT)]
expected: FAIL

[WebGL test #9: context.bufferData(context.ARRAY_BUFFER, 16, context.STREAM_DRAW) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #10: context.bufferData(context.ARRAY_BUFFER, 16, context.STATIC_DRAW) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #11: context.bufferData(context.ARRAY_BUFFER, 16, context.DYNAMIC_DRAW) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #12: context.bufferData(context.ARRAY_BUFFER, 16, desktopGL['STREAM_READ'\]) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #13: context.bufferData(context.ARRAY_BUFFER, 16, desktopGL['STREAM_COPY'\]) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #14: context.bufferData(context.ARRAY_BUFFER, 16, desktopGL['STATIC_READ'\]) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #15: context.bufferData(context.ARRAY_BUFFER, 16, desktopGL['STATIC_COPY'\]) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #16: context.bufferData(context.ARRAY_BUFFER, 16, desktopGL['DYNAMIC_READ'\]) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #17: context.bufferData(context.ARRAY_BUFFER, 16, desktopGL['DYNAMIC_COPY'\]) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #19: context.texImage2D(context.TEXTURE_2D, 0, context.RGBA, -16, -16, 0, context.RGBA, context.UNSIGNED_BYTE, null) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #20: context.texImage2D(context.TEXTURE_2D, 0, context.RGBA, 16, 16, 0, context.RGBA, context.UNSIGNED_BYTE, null) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #23: getError expected: NO_ERROR. Was INVALID_VALUE : after evaluating: context.texSubImage2D(context.TEXTURE_2D, 0, 0, 0, 2, 2, context.RGBA, context.UNSIGNED_BYTE, pixels)]
expected: FAIL

[WebGL test #44: context.getError() should be 1281. Was 0.]
expected: FAIL

@@ -1,23 +1,8 @@
[object-deletion-behaviour.html]
type: testharness
[WebGL test #9: gl.isShader(vertexShader) should be true. Threw exception TypeError: gl.isShader is not a function]
expected: FAIL

[WebGL test #11: gl.detachShader(program, vertexShader) threw exception TypeError: gl.detachShader is not a function]
expected: FAIL

[WebGL test #12: gl.isShader(vertexShader) should be false. Threw exception TypeError: gl.isShader is not a function]
expected: FAIL

[WebGL test #14: gl.isShader(fragmentShader) should be true. Threw exception TypeError: gl.isShader is not a function]
expected: FAIL

[WebGL test #17: gl.isProgram(program) should be true. Was false.]
expected: FAIL

[WebGL test #21: gl.isShader(fragmentShader) should be false. Threw exception TypeError: gl.isShader is not a function]
expected: FAIL

[WebGL test #30: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) should be [object WebGLTexture\]. Threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

@@ -30,15 +15,9 @@
[WebGL test #34: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

[WebGL test #35: gl.isTexture(tex) should be false. Threw exception TypeError: gl.isTexture is not a function]
expected: FAIL

[WebGL test #37: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.bindTexture(gl.TEXTURE_2D, tex)]
expected: FAIL

[WebGL test #43: gl.isTexture(texCubeMap) should be false. Threw exception TypeError: gl.isTexture is not a function]
expected: FAIL

[WebGL test #45: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCubeMap)]
expected: FAIL

@@ -51,54 +30,9 @@
[WebGL test #73: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

[WebGL test #74: gl.isRenderbuffer(rbo) should be false. Threw exception TypeError: gl.isRenderbuffer is not a function]
expected: FAIL

[WebGL test #86: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #51: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.bindTexture(gl.TEXTURE_2D, t)]
expected: FAIL

[WebGL test #113: gl.getParameter(gl.ARRAY_BUFFER_BINDING) should be null. Was [object WebGLBuffer\].]
expected: FAIL

[WebGL test #122: gl.getParameter(gl.ARRAY_BUFFER_BINDING) should be null. Was [object WebGLBuffer\].]
expected: FAIL

[WebGL test #130: gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING) should be null. Was [object WebGLBuffer\].]
expected: FAIL

[WebGL test #133: gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STATIC_DRAW) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #136: gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STATIC_DRAW) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #147: gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) should be [object WebGLBuffer\]. Was null.]
expected: FAIL

[WebGL test #148: gl.getVertexAttrib(2, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) should be [object WebGLBuffer\]. Was null.]
expected: FAIL

[WebGL test #149: gl.getVertexAttrib(3, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) should be [object WebGLBuffer\]. Was null.]
expected: FAIL

[WebGL test #150: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.deleteBuffer(b2);]
expected: FAIL

[WebGL test #151: gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) should be [object WebGLBuffer\]. Was null.]
expected: FAIL

[WebGL test #154: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.deleteBuffer(b1);]
expected: FAIL

[WebGL test #156: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)]
expected: FAIL

[WebGL test #161: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)]
expected: FAIL

[WebGL test #114: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) should be [object WebGLRenderbuffer\]. Threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

@@ -111,60 +45,9 @@
[WebGL test #119: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) should be 0. Threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

[WebGL test #120: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be 36053. Was 36061.]
expected: FAIL

[WebGL test #121: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) should be [object WebGLRenderbuffer\]. Threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

[WebGL test #145: gl.getParameter(gl.ARRAY_BUFFER_BINDING) should be null. Was [object WebGLBuffer\].]
expected: FAIL

[WebGL test #154: gl.getParameter(gl.ARRAY_BUFFER_BINDING) should be null. Was [object WebGLBuffer\].]
expected: FAIL

[WebGL test #162: gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING) should be null. Was [object WebGLBuffer\].]
expected: FAIL

[WebGL test #165: gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STATIC_DRAW) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #168: gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STATIC_DRAW) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #179: gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) should be [object WebGLBuffer\]. Was null.]
expected: FAIL

[WebGL test #180: gl.getVertexAttrib(2, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) should be [object WebGLBuffer\]. Was null.]
expected: FAIL

[WebGL test #181: gl.getVertexAttrib(3, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) should be [object WebGLBuffer\]. Was null.]
expected: FAIL

[WebGL test #182: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.deleteBuffer(b2);]
expected: FAIL

[WebGL test #183: gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) should be [object WebGLBuffer\]. Was null.]
expected: FAIL

[WebGL test #186: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.deleteBuffer(b1);]
expected: FAIL

[WebGL test #188: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)]
expected: FAIL

[WebGL test #193: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)]
expected: FAIL

[WebGL test #216: at (0, 0) expected: 255,0,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #224: at (16, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #227: at (0, 0) expected: 0,255,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #168: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) should be [object WebGLRenderbuffer\]. Threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

@@ -180,9 +63,6 @@
[WebGL test #198: gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) threw exception TypeError: gl.getFramebufferAttachmentParameter is not a function]
expected: FAIL

[WebGL test #199: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should not be 36053.]
expected: FAIL

[WebGL test #210: gl.getParameter(gl.ARRAY_BUFFER_BINDING) should be null. Was [object WebGLBuffer\].]
expected: FAIL

@@ -192,12 +72,6 @@
[WebGL test #227: gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING) should be null. Was [object WebGLBuffer\].]
expected: FAIL

[WebGL test #230: gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STATIC_DRAW) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #233: gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STATIC_DRAW) threw exception TypeError: Value is not an object.]
expected: FAIL

[WebGL test #244: gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) should be [object WebGLBuffer\]. Was null.]
expected: FAIL

@@ -219,24 +93,9 @@
[WebGL test #253: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)]
expected: FAIL

[WebGL test #281: at (0, 0) expected: 255,0,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #289: at (16, 0) expected: 0,255,0,255 was 0,0,0,0]
expected: FAIL

[WebGL test #292: at (0, 0) expected: 0,255,0,255 was 255,0,0,255]
expected: FAIL

[WebGL test #258: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)]
expected: FAIL

[WebGL test #278: at (16, 16) expected: 0,0,0,0 was 9,0,0,0]
expected: FAIL

[WebGL test #281: at (0, 0) expected: 255,0,0,255 was 0,0,0,255]
expected: FAIL

[WebGL test #289: at (16, 0) expected: 0,255,0,255 was 0,0,0,14]
[WebGL test #233: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STATIC_DRAW)]
expected: FAIL

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,6 +1,5 @@
[draw-elements-out-of-bounds.html]
type: testharness
expected: ERROR
[WebGL test #19: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_BYTE, 4)]
expected: FAIL

@@ -19,6 +18,3 @@
[WebGL test #34: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 30)]
expected: FAIL

[WebGL test #43: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

@@ -1,6 +1,6 @@
[point-size.html]
type: testharness
expected: ERROR
[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
[WebGL test #8: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

@@ -1,7 +1,7 @@
[gl-enum-tests.html]
type: testharness
expected: ERROR
[WebGL test #9: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
[WebGL test #18: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

[WebGL test #0: Unable to fetch WebGL rendering context for Canvas]

0 comments on commit 4c656f1

Please sign in to comment.
You can’t perform that action at this time.