mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
webgl: texture: Make initialize only mark as initialized the current face
Also refactor a bit the code, and remove the unused `is_initialized` flag.
This commit is contained in:
parent
21e2f97cfa
commit
d152c7fe88
2 changed files with 31 additions and 15 deletions
|
@ -389,7 +389,8 @@ impl WebGLRenderingContext {
|
||||||
// TODO(emilio): Flip Y axis if necessary here
|
// TODO(emilio): Flip Y axis if necessary here
|
||||||
|
|
||||||
// TexImage2D depth is always equal to 1
|
// TexImage2D depth is always equal to 1
|
||||||
handle_potential_webgl_error!(self, texture.initialize(width as u32,
|
handle_potential_webgl_error!(self, texture.initialize(target,
|
||||||
|
width as u32,
|
||||||
height as u32, 1,
|
height as u32, 1,
|
||||||
internal_format,
|
internal_format,
|
||||||
level as u32));
|
level as u32));
|
||||||
|
|
|
@ -33,7 +33,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_initialized: Cell<bool>,
|
|
||||||
/// Stores information about mipmap levels and cubemap faces.
|
/// Stores information about mipmap levels and cubemap faces.
|
||||||
#[ignore_heap_size_of = "Arrays are cumbersome"]
|
#[ignore_heap_size_of = "Arrays are cumbersome"]
|
||||||
image_info_array: DOMRefCell<[ImageInfo; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>,
|
image_info_array: DOMRefCell<[ImageInfo; MAX_LEVEL_COUNT * MAX_FACE_COUNT]>,
|
||||||
|
@ -51,7 +50,6 @@ 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_initialized: Cell::new(false),
|
|
||||||
face_count: Cell::new(0),
|
face_count: Cell::new(0),
|
||||||
base_mipmap_level: 0,
|
base_mipmap_level: 0,
|
||||||
image_info_array: DOMRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]),
|
image_info_array: DOMRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]),
|
||||||
|
@ -105,7 +103,13 @@ impl WebGLTexture {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initialize(&self, width: u32, height: u32, depth: u32, internal_format: u32, level: u32) -> WebGLResult<()> {
|
pub fn initialize(&self,
|
||||||
|
target: u32,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
depth: u32,
|
||||||
|
internal_format: u32,
|
||||||
|
level: u32) -> WebGLResult<()> {
|
||||||
let image_info = ImageInfo {
|
let image_info = ImageInfo {
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
|
@ -113,10 +117,18 @@ impl WebGLTexture {
|
||||||
internal_format: Some(internal_format),
|
internal_format: Some(internal_format),
|
||||||
is_initialized: true,
|
is_initialized: true,
|
||||||
};
|
};
|
||||||
self.set_image_infos_at_level(level, image_info);
|
|
||||||
|
|
||||||
self.is_initialized.set(true);
|
let face = match target {
|
||||||
|
constants::TEXTURE_2D | constants::TEXTURE_CUBE_MAP_POSITIVE_X => 0,
|
||||||
|
constants::TEXTURE_CUBE_MAP_NEGATIVE_X => 1,
|
||||||
|
constants::TEXTURE_CUBE_MAP_POSITIVE_Y => 2,
|
||||||
|
constants::TEXTURE_CUBE_MAP_NEGATIVE_Y => 3,
|
||||||
|
constants::TEXTURE_CUBE_MAP_POSITIVE_Z => 4,
|
||||||
|
constants::TEXTURE_CUBE_MAP_NEGATIVE_Z => 5,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
self.set_image_infos_at_level_and_face(level, face, image_info);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,12 +142,12 @@ impl WebGLTexture {
|
||||||
};
|
};
|
||||||
|
|
||||||
let base_image_info = self.base_image_info().unwrap();
|
let base_image_info = self.base_image_info().unwrap();
|
||||||
|
|
||||||
if !base_image_info.is_initialized() {
|
if !base_image_info.is_initialized() {
|
||||||
return Err(WebGLError::InvalidOperation);
|
return Err(WebGLError::InvalidOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if target == constants::TEXTURE_CUBE_MAP && !self.is_cube_complete() {
|
let is_cubic = target == constants::TEXTURE_CUBE_MAP;
|
||||||
|
if is_cubic && !self.is_cube_complete() {
|
||||||
return Err(WebGLError::InvalidOperation);
|
return Err(WebGLError::InvalidOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,10 +239,6 @@ impl WebGLTexture {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_power_of_two(&self) -> bool {
|
|
||||||
self.image_info_at_face(0, 0).is_power_of_two()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn populate_mip_chain(&self, first_level: u32, last_level: u32) -> WebGLResult<()> {
|
pub fn populate_mip_chain(&self, first_level: u32, last_level: u32) -> WebGLResult<()> {
|
||||||
let base_image_info = self.image_info_at_face(0, first_level);
|
let base_image_info = self.image_info_at_face(0, first_level);
|
||||||
if !base_image_info.is_initialized() {
|
if !base_image_info.is_initialized() {
|
||||||
|
@ -266,6 +274,8 @@ impl WebGLTexture {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_cube_complete(&self) -> bool {
|
fn is_cube_complete(&self) -> bool {
|
||||||
|
debug_assert!(self.face_count.get() == 6);
|
||||||
|
|
||||||
let image_info = self.base_image_info().unwrap();
|
let image_info = self.base_image_info().unwrap();
|
||||||
if !image_info.is_defined() {
|
if !image_info.is_defined() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -298,11 +308,16 @@ impl WebGLTexture {
|
||||||
|
|
||||||
fn set_image_infos_at_level(&self, level: u32, image_info: ImageInfo) {
|
fn set_image_infos_at_level(&self, level: u32, image_info: ImageInfo) {
|
||||||
for face in 0..self.face_count.get() {
|
for face in 0..self.face_count.get() {
|
||||||
let pos = (level * self.face_count.get() as u32) + face as u32;
|
self.set_image_infos_at_level_and_face(level, face, image_info);
|
||||||
self.image_info_array.borrow_mut()[pos as usize] = image_info;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_image_infos_at_level_and_face(&self, level: u32, face: u8, image_info: ImageInfo) {
|
||||||
|
debug_assert!(face < self.face_count.get());
|
||||||
|
let pos = (level * self.face_count.get() as u32) + face as u32;
|
||||||
|
self.image_info_array.borrow_mut()[pos as usize] = image_info;
|
||||||
|
}
|
||||||
|
|
||||||
fn base_image_info(&self) -> Option<ImageInfo> {
|
fn base_image_info(&self) -> Option<ImageInfo> {
|
||||||
assert!((self.base_mipmap_level as usize) < MAX_LEVEL_COUNT);
|
assert!((self.base_mipmap_level as usize) < MAX_LEVEL_COUNT);
|
||||||
|
|
||||||
|
@ -345,7 +360,7 @@ impl ImageInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_defined(&self) -> bool {
|
fn is_defined(&self) -> bool {
|
||||||
!self.internal_format.is_none()
|
self.internal_format.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_max_mimap_levels(&self) -> u32 {
|
fn get_max_mimap_levels(&self) -> u32 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue