mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #20144 - mkollaro:gettexparameter, r=jdm
Add WebGL function glGetTexParameter <!-- Please describe your changes on the following line: --> Add WebGL function glGetTexParameter --- <!-- 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 - [x] These changes fix part of #10209 <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- 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/20144) <!-- Reviewable:end -->
This commit is contained in:
commit
f5037cf621
11 changed files with 156 additions and 264 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue