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

Move WebGL validation #20369

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

Always

Just for now

Next

Simplify GetTexParameter

  • Loading branch information
gootorov committed Mar 20, 2018
commit 431e3ddf8dfb68e2c5449f2f7cf49aa83be289a8
@@ -1066,21 +1066,8 @@ impl WebGLImpl {
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 {

This comment has been minimized.

@gootorov

gootorov Mar 20, 2018

Author Contributor

Note: I didn't find in the spec that it shouldn't be 0. Can we double check that?

This comment has been minimized.

@emilio

emilio Mar 20, 2018

Member

Can you file a separate issue for this? Let's keep this PR for the refactor I'd say, that makes it more straight-forward to land :)

This comment has been minimized.

@gootorov

gootorov Mar 20, 2018

Author Contributor

Sure!

Ok(WebGLParameter::Invalid)
} else {
Ok(WebGLParameter::Int(parameter))
}
}
_ => Err(WebGLError::InvalidEnum)
};
chan: WebGLSender<i32> ) {
let result = gl.get_tex_parameter_iv(target, pname);
chan.send(result).unwrap();
}

@@ -207,7 +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>>),
GetTexParameter(u32, u32, WebGLSender<i32>),
GetProgramParameter(WebGLProgramId, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetShaderParameter(WebGLShaderId, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetShaderPrecisionFormat(u32, u32, WebGLSender<WebGLResult<(i32, i32, i32)>>),
@@ -1342,31 +1342,39 @@ 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 {
let target_matches = match target {
constants::TEXTURE_2D |
constants::TEXTURE_CUBE_MAP => self.bound_texture(target),
constants::TEXTURE_CUBE_MAP => true,
_ => false,
};

let pname_matches = match pname {
constants::TEXTURE_MAG_FILTER |
constants::TEXTURE_MIN_FILTER |
constants::TEXTURE_WRAP_S |
constants::TEXTURE_WRAP_T => true,
_ => false,
};

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

if self.bound_texture(target).is_none() {
self.webgl_error(InvalidOperation);
return NullValue();
}

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

match receiver.recv().unwrap() {
value if value != 0 => Int32Value(value),
_ => {
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()
}
NullValue()
}
} else {
self.webgl_error(InvalidOperation);
NullValue()
}
}

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