webgl: Return TEXTURE_IMMUTABLE_FORMAT as a boolean; don't panic on macOS for TEXTURE_IMMUTABLE_LEVELS.

This commit is contained in:
Josh Matthews 2020-04-29 14:29:53 -04:00
parent 3876d6dbdd
commit 9ce84d94de
5 changed files with 47 additions and 6 deletions

View file

@ -1839,6 +1839,11 @@ impl WebGLImpl {
.send(gl.get_tex_parameter_iv(target, param as u32)) .send(gl.get_tex_parameter_iv(target, param as u32))
.unwrap(); .unwrap();
}, },
WebGLCommand::GetTexParameterBool(target, param, ref sender) => {
sender
.send(gl.get_tex_parameter_iv(target, param as u32) != 0)
.unwrap();
},
WebGLCommand::GetInternalFormatIntVec(target, internal_format, param, ref sender) => { WebGLCommand::GetInternalFormatIntVec(target, internal_format, param, ref sender) => {
match param { match param {
InternalFormatIntVec::Samples => { InternalFormatIntVec::Samples => {

View file

@ -449,6 +449,7 @@ pub enum WebGLCommand {
GetCurrentVertexAttrib(u32, WebGLSender<[f32; 4]>), GetCurrentVertexAttrib(u32, WebGLSender<[f32; 4]>),
GetTexParameterFloat(u32, TexParameterFloat, WebGLSender<f32>), GetTexParameterFloat(u32, TexParameterFloat, WebGLSender<f32>),
GetTexParameterInt(u32, TexParameterInt, WebGLSender<i32>), GetTexParameterInt(u32, TexParameterInt, WebGLSender<i32>),
GetTexParameterBool(u32, TexParameterBool, WebGLSender<bool>),
GetInternalFormatIntVec(u32, u32, InternalFormatIntVec, WebGLSender<Vec<i32>>), GetInternalFormatIntVec(u32, u32, InternalFormatIntVec, WebGLSender<Vec<i32>>),
TexParameteri(u32, u32, i32), TexParameteri(u32, u32, i32),
TexParameterf(u32, u32, f32), TexParameterf(u32, u32, f32),
@ -886,9 +887,11 @@ parameters! {
TextureMaxLevel = gl::TEXTURE_MAX_LEVEL, TextureMaxLevel = gl::TEXTURE_MAX_LEVEL,
TextureCompareFunc = gl::TEXTURE_COMPARE_FUNC, TextureCompareFunc = gl::TEXTURE_COMPARE_FUNC,
TextureCompareMode = gl::TEXTURE_COMPARE_MODE, TextureCompareMode = gl::TEXTURE_COMPARE_MODE,
TextureImmutableFormat = gl::TEXTURE_IMMUTABLE_FORMAT,
TextureImmutableLevels = gl::TEXTURE_IMMUTABLE_LEVELS, TextureImmutableLevels = gl::TEXTURE_IMMUTABLE_LEVELS,
}), }),
Bool(TexParameterBool {
TextureImmutableFormat = gl::TEXTURE_IMMUTABLE_FORMAT,
}),
} }
} }

View file

@ -0,0 +1 @@
joshmatthews@joshmatthews-fcmd6r.1071

View file

@ -2236,6 +2236,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
self.webgl_error(InvalidEnum); self.webgl_error(InvalidEnum);
return NullValue(); return NullValue();
} }
if let Some(value) = texture.maybe_get_tex_parameter(texparam) {
match value {
TexParameterValue::Float(v) => return DoubleValue(v as f64),
TexParameterValue::Int(v) => return Int32Value(v),
TexParameterValue::Bool(v) => return BooleanValue(v),
}
}
match texparam { match texparam {
TexParameter::Float(param) => { TexParameter::Float(param) => {
let (sender, receiver) = webgl_channel().unwrap(); let (sender, receiver) = webgl_channel().unwrap();
@ -2247,6 +2256,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
self.send_command(WebGLCommand::GetTexParameterInt(target, param, sender)); self.send_command(WebGLCommand::GetTexParameterInt(target, param, sender));
Int32Value(receiver.recv().unwrap()) Int32Value(receiver.recv().unwrap())
}, },
TexParameter::Bool(param) => {
let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetTexParameterBool(target, param, sender));
BooleanValue(receiver.recv().unwrap())
},
} }
} }

View file

@ -14,7 +14,10 @@ use crate::dom::webgl_validations::types::TexImageTarget;
use crate::dom::webglframebuffer::WebGLFramebuffer; use crate::dom::webglframebuffer::WebGLFramebuffer;
use crate::dom::webglobject::WebGLObject; use crate::dom::webglobject::WebGLObject;
use crate::dom::webglrenderingcontext::{Operation, WebGLRenderingContext}; use crate::dom::webglrenderingcontext::{Operation, WebGLRenderingContext};
use canvas_traits::webgl::{webgl_channel, TexDataType, TexFormat, WebGLResult, WebGLTextureId}; use canvas_traits::webgl::{
webgl_channel, TexDataType, TexFormat, TexParameter, TexParameterBool, TexParameterInt,
WebGLResult, WebGLTextureId,
};
use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError}; use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError};
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell; use std::cell::Cell;
@ -23,6 +26,7 @@ use std::cmp;
pub enum TexParameterValue { pub enum TexParameterValue {
Float(f32), Float(f32),
Int(i32), Int(i32),
Bool(bool),
} }
const MAX_LEVEL_COUNT: usize = 31; const MAX_LEVEL_COUNT: usize = 31;
@ -37,7 +41,6 @@ pub struct WebGLTexture {
/// The target to which this texture was bound the first time /// The target to which this texture was bound the first time
target: Cell<Option<u32>>, target: Cell<Option<u32>>,
is_deleted: Cell<bool>, is_deleted: Cell<bool>,
is_immutable: Cell<bool>,
/// Stores information about mipmap levels and cubemap faces. /// Stores information about mipmap levels and cubemap faces.
#[ignore_malloc_size_of = "Arrays are cumbersome"] #[ignore_malloc_size_of = "Arrays are cumbersome"]
image_info_array: DomRefCell<[Option<ImageInfo>; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>, image_info_array: DomRefCell<[Option<ImageInfo>; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>,
@ -51,6 +54,8 @@ pub struct WebGLTexture {
attached_to_dom: Cell<bool>, attached_to_dom: Cell<bool>,
/// Framebuffer that this texture is attached to. /// Framebuffer that this texture is attached to.
attached_framebuffer: MutNullableDom<WebGLFramebuffer>, attached_framebuffer: MutNullableDom<WebGLFramebuffer>,
/// Number of immutable levels.
immutable_levels: Cell<Option<u32>>,
} }
impl WebGLTexture { impl WebGLTexture {
@ -60,7 +65,7 @@ impl WebGLTexture {
id: id, id: id,
target: Cell::new(None), target: Cell::new(None),
is_deleted: Cell::new(false), is_deleted: Cell::new(false),
is_immutable: Cell::new(false), immutable_levels: Cell::new(None),
face_count: Cell::new(0), face_count: Cell::new(0),
base_mipmap_level: 0, base_mipmap_level: 0,
min_filter: Cell::new(constants::NEAREST_MIPMAP_LINEAR), min_filter: Cell::new(constants::NEAREST_MIPMAP_LINEAR),
@ -224,13 +229,25 @@ impl WebGLTexture {
} }
pub fn is_immutable(&self) -> bool { pub fn is_immutable(&self) -> bool {
self.is_immutable.get() self.immutable_levels.get().is_some()
} }
pub fn target(&self) -> Option<u32> { pub fn target(&self) -> Option<u32> {
self.target.get() self.target.get()
} }
pub fn maybe_get_tex_parameter(&self, param: TexParameter) -> Option<TexParameterValue> {
match param {
TexParameter::Int(TexParameterInt::TextureImmutableLevels) => Some(
TexParameterValue::Int(self.immutable_levels.get().unwrap_or(0) as i32),
),
TexParameter::Bool(TexParameterBool::TextureImmutableFormat) => {
Some(TexParameterValue::Bool(self.is_immutable()))
},
_ => None,
}
}
/// We have to follow the conversion rules for GLES 2.0. See: /// We have to follow the conversion rules for GLES 2.0. See:
/// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html /// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html
/// ///
@ -240,6 +257,7 @@ impl WebGLTexture {
let (int_value, float_value) = match value { let (int_value, float_value) = match value {
TexParameterValue::Int(int_value) => (int_value, int_value as f32), TexParameterValue::Int(int_value) => (int_value, int_value as f32),
TexParameterValue::Float(float_value) => (float_value as i32, float_value), TexParameterValue::Float(float_value) => (float_value as i32, float_value),
TexParameterValue::Bool(_) => unreachable!("no settable tex params should be booleans"),
}; };
let update_filter = |filter: &Cell<u32>| { let update_filter = |filter: &Cell<u32>| {
@ -465,7 +483,7 @@ impl WebGLTexture {
depth = cmp::max(1, depth / 2); depth = cmp::max(1, depth / 2);
} }
self.is_immutable.set(true); self.immutable_levels.set(Some(levels));
if let Some(fb) = self.attached_framebuffer.get() { if let Some(fb) = self.attached_framebuffer.get() {
fb.update_status(); fb.update_status();