Skip to content

Commit

Permalink
Implement WebGL GetRenderbufferParameter
Browse files Browse the repository at this point in the history
This needed a bump of gleam to version 0.4.33
  • Loading branch information
fnune committed Apr 24, 2018
1 parent 05fe8fa commit 58760d9
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 129 deletions.
13 changes: 13 additions & 0 deletions components/canvas/webgl_thread.rs
Expand Up @@ -754,6 +754,8 @@ impl WebGLImpl {
Self::active_uniform(ctx.gl(), program_id, index, chan),
WebGLCommand::GetAttribLocation(program_id, name, chan) =>
Self::attrib_location(ctx.gl(), program_id, name, chan),
WebGLCommand::GetRenderbufferParameter(target, pname, chan) =>
Self::get_renderbuffer_parameter(ctx.gl(), target, pname, chan),
WebGLCommand::GetFramebufferAttachmentParameter(target, attachment, pname, chan) =>
Self::get_framebuffer_attachment_parameter(ctx.gl(), target, attachment, pname, chan),
WebGLCommand::GetVertexAttrib(index, pname, chan) =>
Expand Down Expand Up @@ -1188,6 +1190,17 @@ impl WebGLImpl {
chan.send(parameter).unwrap();
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.7
fn get_renderbuffer_parameter(
gl: &gl::Gl,
target: u32,
pname: u32,
chan: WebGLSender<i32>
) {
let parameter = gl.get_renderbuffer_parameter_iv(target, pname);
chan.send(parameter).unwrap();
}

fn uniform_location(gl: &gl::Gl,
program_id: WebGLProgramId,
name: String,
Expand Down
2 changes: 2 additions & 0 deletions components/canvas_traits/webgl.rs
Expand Up @@ -220,6 +220,7 @@ pub enum WebGLCommand {
GetShaderInfoLog(WebGLShaderId, WebGLSender<String>),
GetProgramInfoLog(WebGLProgramId, WebGLSender<String>),
GetFramebufferAttachmentParameter(u32, u32, u32, WebGLSender<i32>),
GetRenderbufferParameter(u32, u32, WebGLSender<i32>),
PolygonOffset(f32, f32),
RenderbufferStorage(u32, u32, i32, i32),
ReadPixels(i32, i32, i32, i32, u32, u32, WebGLSender<ByteBuf>),
Expand Down Expand Up @@ -494,6 +495,7 @@ impl fmt::Debug for WebGLCommand {
GetVertexAttrib(..) => "GetVertexAttrib",
GetVertexAttribOffset(..) => "GetVertexAttribOffset",
GetFramebufferAttachmentParameter(..) => "GetFramebufferAttachmentParameter",
GetRenderbufferParameter(..) => "GetRenderbufferParameter",
PolygonOffset(..) => "PolygonOffset",
ReadPixels(..) => "ReadPixels",
RenderbufferStorage(..) => "RenderbufferStorage",
Expand Down
11 changes: 11 additions & 0 deletions components/script/dom/webgl2renderingcontext.rs
Expand Up @@ -159,6 +159,17 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
self.base.GetFramebufferAttachmentParameter(cx, target, attachment, pname)
}

#[allow(unsafe_code)]
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.7
unsafe fn GetRenderbufferParameter(
&self,
cx: *mut JSContext,
target: u32,
pname: u32
) -> JSVal {
self.base.GetRenderbufferParameter(cx, target, pname)
}

/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn ActiveTexture(&self, texture: u32) {
self.base.ActiveTexture(texture)
Expand Down
39 changes: 39 additions & 0 deletions components/script/dom/webglrenderingcontext.rs
Expand Up @@ -2348,6 +2348,45 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
Int32Value(receiver.recv().unwrap())
}

#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.7
unsafe fn GetRenderbufferParameter(
&self,
_cx: *mut JSContext,
target: u32,
pname: u32
) -> JSVal {
let target_matches = target == constants::RENDERBUFFER;

let pname_matches = match pname {
constants::RENDERBUFFER_WIDTH |
constants::RENDERBUFFER_HEIGHT |
constants::RENDERBUFFER_INTERNAL_FORMAT |
constants::RENDERBUFFER_RED_SIZE |
constants::RENDERBUFFER_GREEN_SIZE |
constants::RENDERBUFFER_BLUE_SIZE |
constants::RENDERBUFFER_ALPHA_SIZE |
constants::RENDERBUFFER_DEPTH_SIZE |
constants::RENDERBUFFER_STENCIL_SIZE => true,
_ => false,
};

if !target_matches || !pname_matches {
self.webgl_error(InvalidEnum);
return NullValue();
}

if self.bound_renderbuffer.get().is_none() {
self.webgl_error(InvalidOperation);
return NullValue();
}

let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetRenderbufferParameter(target, pname, sender));

Int32Value(receiver.recv().unwrap())
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetProgramInfoLog(&self, program: &WebGLProgram) -> Option<DOMString> {
match program.get_info_log() {
Expand Down
3 changes: 1 addition & 2 deletions components/script/dom/webidls/WebGLRenderingContext.webidl
Expand Up @@ -571,8 +571,7 @@ interface WebGLRenderingContextBase
GLenum pname);
any getProgramParameter(WebGLProgram program, GLenum pname);
DOMString? getProgramInfoLog(WebGLProgram program);
// FIXME: https://github.com/servo/servo/issues/20514
// any getRenderbufferParameter(GLenum target, GLenum pname);
any getRenderbufferParameter(GLenum target, GLenum pname);
any getShaderParameter(WebGLShader shader, GLenum pname);
WebGLShaderPrecisionFormat? getShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
DOMString? getShaderInfoLog(WebGLShader shader);
Expand Down
@@ -1,10 +1,7 @@
[methods.html]
[WebGL test #0: Property either does not exist or is not a function: getRenderbufferParameter]
[WebGL test #0: Property either does not exist or is not a function: getUniform]
expected: FAIL

[WebGL test #1: Property either does not exist or is not a function: getUniform]
expected: FAIL

[WebGL test #2: Property either does not exist or is not a function: isContextLost]
[WebGL test #1: Property either does not exist or is not a function: isContextLost]
expected: FAIL

This file was deleted.

0 comments on commit 58760d9

Please sign in to comment.