Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebGL function glGetTexParameter #20144

Merged
merged 1 commit into from Mar 6, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -758,6 +758,8 @@ impl WebGLImpl {
Self::buffer_parameter(ctx.gl(), target, param_id, chan),
WebGLCommand::GetParameter(param_id, chan) =>
Self::parameter(ctx.gl(), param_id, chan),
WebGLCommand::GetTexParameter(target, pname, chan) =>
Self::get_tex_parameter(ctx.gl(), target, pname, chan),
WebGLCommand::GetProgramParameter(program_id, param_id, chan) =>
Self::program_parameter(ctx.gl(), program_id, param_id, chan),
WebGLCommand::GetShaderParameter(shader_id, param_id, chan) =>
@@ -1061,6 +1063,27 @@ impl WebGLImpl {
chan.send(result).unwrap();
}

fn get_tex_parameter(gl: &gl::Gl,
target: u32,
pname: u32,
chan: WebGLSender<WebGLResult<WebGLParameter>> ) {
let result = match pname {
gl::TEXTURE_MAG_FILTER |
gl::TEXTURE_MIN_FILTER |
gl::TEXTURE_WRAP_S |
gl::TEXTURE_WRAP_T => {
let parameter = gl.get_tex_parameter_iv(target, pname);
if parameter == 0 {
Ok(WebGLParameter::Invalid)
} else {
Ok(WebGLParameter::Int(parameter))
}
}
_ => Err(WebGLError::InvalidEnum)
};
chan.send(result).unwrap();
}

fn finish(gl: &gl::Gl, chan: WebGLSender<()>) {
gl.finish();
chan.send(()).unwrap();
@@ -207,6 +207,7 @@ pub enum WebGLCommand {
GetBufferParameter(u32, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetExtensions(WebGLSender<String>),
GetParameter(u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetTexParameter(u32, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetProgramParameter(WebGLProgramId, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetShaderParameter(WebGLShaderId, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetShaderPrecisionFormat(u32, u32, WebGLSender<WebGLResult<(i32, i32, i32)>>),
@@ -477,6 +478,7 @@ impl fmt::Debug for WebGLCommand {
GetBufferParameter(..) => "GetBufferParameter",
GetExtensions(..) => "GetExtensions",
GetParameter(..) => "GetParameter",
GetTexParameter(..) => "GetTexParameter",
GetProgramParameter(..) => "GetProgramParameter",
GetShaderParameter(..) => "GetShaderParameter",
GetShaderPrecisionFormat(..) => "GetShaderPrecisionFormat",
@@ -115,6 +115,12 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
self.base.GetParameter(cx, parameter)
}

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

/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn GetError(&self) -> u32 {
self.base.GetError()
@@ -1336,6 +1336,37 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
}

#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
unsafe fn GetTexParameter(&self, _cx: *mut JSContext, target: u32, pname: u32) -> JSVal {
let texture = match target {
constants::TEXTURE_2D |
constants::TEXTURE_CUBE_MAP => self.bound_texture(target),
_ => {
self.webgl_error(InvalidEnum);
return NullValue();
}
};
if texture.is_some() {
let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetTexParameter(target, pname, sender));
match handle_potential_webgl_error!(self, receiver.recv().unwrap(), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(_) => panic!("Texture parameter should not be bool"),
WebGLParameter::Float(_) => panic!("Texture parameter should not be float"),
WebGLParameter::FloatArray(_) => panic!("Texture parameter should not be float array"),
WebGLParameter::String(_) => panic!("Texture parameter should not be string"),
WebGLParameter::Invalid => {
self.webgl_error(InvalidEnum);
NullValue()
}
}
} else {
self.webgl_error(InvalidOperation);
NullValue()
}
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn GetError(&self) -> u32 {
let error_code = if let Some(error) = self.last_error.get() {
@@ -600,7 +600,7 @@ interface WebGLRenderingContextBase

DOMString? getShaderSource(WebGLShader? shader);

//any getTexParameter(GLenum target, GLenum pname);
any getTexParameter(GLenum target, GLenum pname);

//any getUniform(WebGLProgram? program, WebGLUniformLocation? location);

@@ -9,12 +9,9 @@
[WebGL test #2: Property either does not exist or is not a function: getRenderbufferParameter]
expected: FAIL

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

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

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

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,6 +1,6 @@
[tex-input-validation.html]
type: testharness
expected: ERROR
expected: CRASH
[WebGL test #3: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.