Skip to content

Commit

Permalink
Auto merge of #14924 - ioctaptceb:webgl-blendFunc-tests, r=jdm
Browse files Browse the repository at this point in the history
Webgl blend func tests

<!-- Please describe your changes on the following line: -->
Add a function that validates the conditions for [Constant Color Blend](https://www.khronos.org/registry/webgl/specs/latest/1.0/#CONSTANT_COLOR_BLEND) in the WebGL specs. ./mach run -r tests/wpt/web-platform-tests/webgl/conformance-1.0.3/conformance/misc/webgl-specific.html

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14924)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Jan 11, 2017
2 parents f6940f6 + f3d6550 commit 783829e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 48 deletions.
33 changes: 33 additions & 0 deletions components/script/dom/webglrenderingcontext.rs
Expand Up @@ -103,6 +103,15 @@ macro_rules! object_binding_to_js_or_null {
};
}

fn has_invalid_blend_constants(arg1: u32, arg2: u32) -> bool {
match (arg1, arg2) {
(constants::CONSTANT_COLOR, constants::CONSTANT_ALPHA) => true,
(constants::ONE_MINUS_CONSTANT_COLOR, constants::ONE_MINUS_CONSTANT_ALPHA) => true,
(constants::ONE_MINUS_CONSTANT_COLOR, constants::CONSTANT_ALPHA) => true,
(constants::CONSTANT_COLOR, constants::ONE_MINUS_CONSTANT_ALPHA) => true,
(_, _) => false
}
}
/// Set of bitflags for texture unpacking (texImage2d, etc...)
bitflags! {
#[derive(HeapSizeOf, JSTraceable)]
Expand Down Expand Up @@ -808,13 +817,37 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn BlendFunc(&self, src_factor: u32, dest_factor: u32) {
// From the WebGL 1.0 spec, 6.13: Viewport Depth Range:
//
// A call to blendFunc will generate an INVALID_OPERATION error if one of the two
// factors is set to CONSTANT_COLOR or ONE_MINUS_CONSTANT_COLOR and the other to
// CONSTANT_ALPHA or ONE_MINUS_CONSTANT_ALPHA.
if has_invalid_blend_constants(src_factor, dest_factor) {
return self.webgl_error(InvalidOperation);
}
if has_invalid_blend_constants(dest_factor, src_factor) {
return self.webgl_error(InvalidOperation);
}

self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::BlendFunc(src_factor, dest_factor)))
.unwrap();
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn BlendFuncSeparate(&self, src_rgb: u32, dest_rgb: u32, src_alpha: u32, dest_alpha: u32) {
// From the WebGL 1.0 spec, 6.13: Viewport Depth Range:
//
// A call to blendFuncSeparate will generate an INVALID_OPERATION error if srcRGB is
// set to CONSTANT_COLOR or ONE_MINUS_CONSTANT_COLOR and dstRGB is set to
// CONSTANT_ALPHA or ONE_MINUS_CONSTANT_ALPHA or vice versa.
if has_invalid_blend_constants(src_rgb, dest_rgb) {
return self.webgl_error(InvalidOperation);
}
if has_invalid_blend_constants(dest_rgb, src_rgb) {
return self.webgl_error(InvalidOperation);
}

self.ipc_renderer.send(
CanvasMsg::WebGL(WebGLCommand::BlendFuncSeparate(src_rgb, dest_rgb, src_alpha, dest_alpha))).unwrap();
}
Expand Down
@@ -1,53 +1,5 @@
[webgl-specific.html]
type: testharness
[WebGL test #1: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFunc(gl.CONSTANT_COLOR, gl.CONSTANT_ALPHA)]
expected: FAIL

[WebGL test #2: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFunc(gl.ONE_MINUS_CONSTANT_COLOR, gl.CONSTANT_ALPHA)]
expected: FAIL

[WebGL test #3: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFunc(gl.CONSTANT_COLOR, gl.ONE_MINUS_CONSTANT_ALPHA)]
expected: FAIL

[WebGL test #4: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFunc(gl.ONE_MINUS_CONSTANT_COLOR, gl.ONE_MINUS_CONSTANT_ALPHA)]
expected: FAIL

[WebGL test #5: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFunc(gl.CONSTANT_ALPHA, gl.CONSTANT_COLOR)]
expected: FAIL

[WebGL test #6: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFunc(gl.CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_COLOR)]
expected: FAIL

[WebGL test #7: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFunc(gl.ONE_MINUS_CONSTANT_ALPHA, gl.CONSTANT_COLOR)]
expected: FAIL

[WebGL test #8: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFunc(gl.ONE_MINUS_CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_COLOR)]
expected: FAIL

[WebGL test #9: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFuncSeparate(gl.CONSTANT_COLOR, gl.CONSTANT_ALPHA, gl.ONE, gl.ZERO)]
expected: FAIL

[WebGL test #10: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFuncSeparate(gl.ONE_MINUS_CONSTANT_COLOR, gl.CONSTANT_ALPHA, gl.ONE, gl.ZERO)]
expected: FAIL

[WebGL test #11: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFuncSeparate(gl.CONSTANT_COLOR, gl.ONE_MINUS_CONSTANT_ALPHA, gl.ONE, gl.ZERO)]
expected: FAIL

[WebGL test #12: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFuncSeparate(gl.ONE_MINUS_CONSTANT_COLOR, gl.ONE_MINUS_CONSTANT_ALPHA, gl.ONE, gl.ZERO)]
expected: FAIL

[WebGL test #13: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFuncSeparate(gl.CONSTANT_ALPHA, gl.CONSTANT_COLOR, gl.ONE, gl.ZERO)]
expected: FAIL

[WebGL test #14: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFuncSeparate(gl.CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_COLOR, gl.ONE, gl.ZERO)]
expected: FAIL

[WebGL test #15: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFuncSeparate(gl.ONE_MINUS_CONSTANT_ALPHA, gl.CONSTANT_COLOR, gl.ONE, gl.ZERO)]
expected: FAIL

[WebGL test #16: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.blendFuncSeparate(gl.ONE_MINUS_CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_COLOR, gl.ONE, gl.ZERO)]
expected: FAIL

[WebGL test #21: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.drawArrays(gl.TRIANGLES, 0, 0)]
expected: FAIL

Expand Down

0 comments on commit 783829e

Please sign in to comment.