Skip to content

Commit

Permalink
Add support for WebGL2 buffer types in GetBufferParameter
Browse files Browse the repository at this point in the history
This makes the new buffer types introduced in WebGL2 usable by the
GetBufferParameter call.
  • Loading branch information
mmatyas committed Apr 28, 2020
1 parent c990964 commit 2810c8d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 62 deletions.
6 changes: 4 additions & 2 deletions components/script/dom/webgl2renderingcontext.rs
Expand Up @@ -867,8 +867,10 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}

/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
fn GetBufferParameter(&self, cx: JSContext, target: u32, parameter: u32) -> JSVal {
self.base.GetBufferParameter(cx, target, parameter)
fn GetBufferParameter(&self, _cx: JSContext, target: u32, parameter: u32) -> JSVal {
let buffer =
handle_potential_webgl_error!(self.base, self.bound_buffer(target), return NullValue());
self.base.get_buffer_param(buffer, parameter)
}

#[allow(unsafe_code)]
Expand Down
32 changes: 17 additions & 15 deletions components/script/dom/webglrenderingcontext.rs
Expand Up @@ -1873,6 +1873,20 @@ impl WebGLRenderingContext {
Ok(())
});
}

pub fn get_buffer_param(&self, buffer: Option<DomRoot<WebGLBuffer>>, parameter: u32) -> JSVal {
let buffer =
handle_potential_webgl_error!(self, buffer.ok_or(InvalidOperation), return NullValue());

match parameter {
constants::BUFFER_SIZE => Int32Value(buffer.capacity() as i32),
constants::BUFFER_USAGE => Int32Value(buffer.usage() as i32),
_ => {
self.webgl_error(InvalidEnum);
NullValue()
},
}
}
}

#[cfg(not(feature = "webgl_backtrace"))]
Expand Down Expand Up @@ -1934,21 +1948,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
fn GetBufferParameter(&self, _cx: SafeJSContext, target: u32, parameter: u32) -> JSVal {
let buffer = handle_potential_webgl_error!(
self,
self.bound_buffer(target)
.and_then(|buf| buf.ok_or(InvalidOperation)),
return NullValue()
);

match parameter {
constants::BUFFER_SIZE => Int32Value(buffer.capacity() as i32),
constants::BUFFER_USAGE => Int32Value(buffer.usage() as i32),
_ => {
self.webgl_error(InvalidEnum);
NullValue()
},
}
let buffer =
handle_potential_webgl_error!(self, self.bound_buffer(target), return NullValue());
self.get_buffer_param(buffer, parameter)
}

#[allow(unsafe_code)]
Expand Down
Expand Up @@ -6,27 +6,12 @@
[WebGL test #201: gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_R) should be 33071 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #10: gl.getBufferParameter(gl.COPY_WRITE_BUFFER, gl.BUFFER_USAGE) should be 35048 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #9: gl.getBufferParameter(gl.COPY_WRITE_BUFFER, gl.BUFFER_SIZE) should be 16 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #16: gl.getBufferParameter(gl.PIXEL_UNPACK_BUFFER, gl.BUFFER_USAGE) should be 35048 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #4: gl.getBufferParameter(gl.ELEMENT_ARRAY_BUFFER, gl.BUFFER_USAGE) should be 35048 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #203: gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_IMMUTABLE_LEVELS) should be 0 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #204: getTexParameter returned 1 instead of null for invalid parameter enum: 0x84fe]
expected: FAIL

[WebGL test #13: gl.getBufferParameter(gl.PIXEL_PACK_BUFFER, gl.BUFFER_USAGE) should be 35048 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #196: gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_FUNC) should be 515 (of type number). Was null (of type object).]
expected: FAIL

Expand All @@ -36,9 +21,6 @@
[WebGL test #199: gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MAX_LOD) should be 10 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #15: gl.getBufferParameter(gl.PIXEL_UNPACK_BUFFER, gl.BUFFER_SIZE) should be 16 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #202: gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_IMMUTABLE_FORMAT) should be false (of type boolean). Was null (of type object).]
expected: FAIL

Expand All @@ -48,9 +30,6 @@
[WebGL test #337: gl.getActiveUniformBlockName(program, 0) should be Transform. Was _uTransform.]
expected: FAIL

[WebGL test #22: gl.getBufferParameter(gl.UNIFORM_BUFFER, gl.BUFFER_USAGE) should be 35048 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #259: gl.getUniform(samplerForWebGL2Program, s2DArrayValLoc) should be 1. Was 0.]
expected: FAIL

Expand All @@ -66,30 +45,6 @@
[WebGL test #195: gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_BASE_LEVEL) should be 0 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #3: gl.getBufferParameter(gl.ELEMENT_ARRAY_BUFFER, gl.BUFFER_SIZE) should be 16 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #5: getBufferParameter did not generate INVALID_ENUM for invalid parameter enum: NO_ERROR]
expected: FAIL

[WebGL test #18: gl.getBufferParameter(gl.TRANSFORM_FEEDBACK_BUFFER, gl.BUFFER_SIZE) should be 16 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #19: gl.getBufferParameter(gl.TRANSFORM_FEEDBACK_BUFFER, gl.BUFFER_USAGE) should be 35048 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #21: gl.getBufferParameter(gl.UNIFORM_BUFFER, gl.BUFFER_SIZE) should be 16 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #7: gl.getBufferParameter(gl.COPY_READ_BUFFER, gl.BUFFER_USAGE) should be 35048 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #6: gl.getBufferParameter(gl.COPY_READ_BUFFER, gl.BUFFER_SIZE) should be 16 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #12: gl.getBufferParameter(gl.PIXEL_PACK_BUFFER, gl.BUFFER_SIZE) should be 16 (of type number). Was null (of type object).]
expected: FAIL

[WebGL test #197: gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_COMPARE_MODE) should be 34894 (of type number). Was null (of type object).]
expected: FAIL

Expand Down

0 comments on commit 2810c8d

Please sign in to comment.