Skip to content

Commit

Permalink
Implement gl.getParameter(gl.VIEWPORT)
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Mar 22, 2018
1 parent e9758e0 commit dc45347
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 27 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions components/canvas/webgl_thread.rs
Expand Up @@ -858,8 +858,12 @@ impl WebGLImpl {
ctx.gl().vertex_attrib_pointer_f32(attrib_id, size, normalized, stride, offset),
WebGLCommand::VertexAttribPointer(attrib_id, size, data_type, normalized, stride, offset) =>
ctx.gl().vertex_attrib_pointer(attrib_id, size, data_type, normalized, stride, offset),
WebGLCommand::Viewport(x, y, width, height) =>
ctx.gl().viewport(x, y, width, height),
WebGLCommand::GetViewport(sender) => {
sender.send(ctx.gl().get_viewport()).unwrap();
}
WebGLCommand::SetViewport(x, y, width, height) => {
ctx.gl().viewport(x, y, width, height);
}
WebGLCommand::TexImage2D(target, level, internal, width, height, format, data_type, data) =>
ctx.gl().tex_image_2d(target, level, internal, width, height,
/*border*/0, format, data_type, Some(&data)),
Expand Down Expand Up @@ -1053,8 +1057,7 @@ impl WebGLImpl {

// Int32Array
gl::MAX_VIEWPORT_DIMS |
gl::SCISSOR_BOX |
gl::VIEWPORT => Err(WebGLError::InvalidEnum),
gl::SCISSOR_BOX => Err(WebGLError::InvalidEnum),

// Invalid parameters
_ => Err(WebGLError::InvalidEnum)
Expand Down
6 changes: 4 additions & 2 deletions components/canvas_traits/webgl.rs
Expand Up @@ -259,7 +259,8 @@ pub enum WebGLCommand {
VertexAttrib(u32, f32, f32, f32, f32),
VertexAttribPointer(u32, i32, u32, bool, i32, u32),
VertexAttribPointer2f(u32, i32, bool, i32, u32),
Viewport(i32, i32, i32, i32),
GetViewport(WebGLSender<(i32, i32, i32, i32)>),
SetViewport(i32, i32, i32, i32),
TexImage2D(u32, i32, i32, i32, i32, u32, u32, Vec<u8>),
TexParameteri(u32, u32, i32),
TexParameterf(u32, u32, f32),
Expand Down Expand Up @@ -530,7 +531,8 @@ impl fmt::Debug for WebGLCommand {
VertexAttrib(..) => "VertexAttrib",
VertexAttribPointer2f(..) => "VertexAttribPointer2f",
VertexAttribPointer(..) => "VertexAttribPointer",
Viewport(..) => "Viewport",
GetViewport(..) => "GetViewport",
SetViewport(..) => "SetViewport",
TexImage2D(..) => "TexImage2D",
TexParameteri(..) => "TexParameteri",
TexParameterf(..) => "TexParameterf",
Expand Down
10 changes: 9 additions & 1 deletion components/script/dom/webglrenderingcontext.rs
Expand Up @@ -1304,6 +1304,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
return Int32Value(constants::UNSIGNED_BYTE as i32);
}
}
constants::VIEWPORT => {
let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetViewport(sender));
let (x, y, width, height) = receiver.recv().unwrap();
rooted!(in(cx) let mut rval = UndefinedValue());
[x, y, width, height].to_jsval(cx, rval.handle_mut());
return rval.get();
}
_ => {
if !self.extension_manager.is_get_parameter_name_enabled(parameter) {
self.webgl_error(WebGLError::InvalidEnum);
Expand Down Expand Up @@ -3144,7 +3152,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
return self.webgl_error(InvalidValue)
}

self.send_command(WebGLCommand::Viewport(x, y, width, height))
self.send_command(WebGLCommand::SetViewport(x, y, width, height))
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
Expand Down
@@ -1,6 +1,5 @@
[gl-get-calls.html]
type: testharness
expected: ERROR
[WebGL test #3: (context.getParameter(context.ALIASED_LINE_WIDTH_RANGE)[0\] <= 1) && (context.getParameter(context.ALIASED_LINE_WIDTH_RANGE)[0\] > 0) && (context.getParameter(context.ALIASED_LINE_WIDTH_RANGE)[1\] >= 1) should be true. Threw exception TypeError: context.getParameter(...) is null]
expected: FAIL

Expand Down Expand Up @@ -46,12 +45,93 @@
[WebGL test #43: context.getParameter(context.SCISSOR_BOX)[1\] should be 0. Threw exception TypeError: context.getParameter(...) is null]
expected: FAIL

[WebGL test #44: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
[WebGL test #44: context.getParameter(context.SCISSOR_BOX)[2\] should be 2. Threw exception TypeError: context.getParameter(...) is null]
expected: FAIL

[WebGL test #0: Unable to fetch WebGL rendering context for Canvas]
[WebGL test #45: context.getParameter(context.SCISSOR_BOX)[3\] should be 2. Threw exception TypeError: context.getParameter(...) is null]
expected: FAIL

[WebGL test #1: context does not exist]
[WebGL test #46: context.getParameter(context.SCISSOR_BOX) is not an instance of function Int32Array() {\n [native code\]\n}]
expected: FAIL

[WebGL test #47: context.getParameter(context.SCISSOR_TEST) should be false (of type boolean). Was null (of type object).]
expected: FAIL

[WebGL test #85: context.getParameter(context.UNPACK_FLIP_Y_WEBGL) should be false (of type boolean). Was null (of type object).]
expected: FAIL

[WebGL test #86: context.getParameter(context.UNPACK_PREMULTIPLY_ALPHA_WEBGL) should be false (of type boolean). Was null (of type object).]
expected: FAIL

[WebGL test #88: context.getParameter(context.VIEWPORT) is not an instance of Int32Array]
expected: FAIL

[WebGL test #91: context.getParameter(context.MAX_FRAGMENT_UNIFORM_VECTORS) should be >= 16. Was null (of type object).]
expected: FAIL

[WebGL test #95: context.getParameter(context.MAX_VARYING_VECTORS) should be >= 8. Was null (of type object).]
expected: FAIL

[WebGL test #98: context.getParameter(context.MAX_VERTEX_UNIFORM_VECTORS) should be >= 128. Was null (of type object).]
expected: FAIL

[WebGL test #99: context.getParameter(context.MAX_VIEWPORT_DIMS)[0\] >= window.screen.width should be true. Threw exception TypeError: context.getParameter(...) is null]
expected: FAIL

[WebGL test #100: context.getParameter(context.MAX_VIEWPORT_DIMS)[1\] >= window.screen.height should be true. Threw exception TypeError: context.getParameter(...) is null]
expected: FAIL

[WebGL test #101: context.getParameter(context.MAX_VIEWPORT_DIMS) is not an instance of Int32Array]
expected: FAIL

[WebGL test #173: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #182: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #191: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #200: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #209: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #218: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #227: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #236: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #245: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #254: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #263: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #272: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #281: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #290: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #299: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

[WebGL test #308: context.getVertexAttrib(ii, context.CURRENT_VERTEX_ATTRIB) is not an instance of Float32Array]
expected: FAIL

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

0 comments on commit dc45347

Please sign in to comment.