Skip to content

Commit

Permalink
[gles] Handle cubemap copies (#2725)
Browse files Browse the repository at this point in the history
  • Loading branch information
expenses authored Jun 5, 2022
1 parent 5bd0a6c commit a3b2418
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
dst: dst_raw,
dst_target,
copy,
dst_is_cubemap: dst.is_cubemap,
})
}
}
Expand Down
19 changes: 10 additions & 9 deletions wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl crate::Device<super::Api> for super::Device {
depth: 1,
};

let inner = if render_usage.contains(desc.usage)
let (inner, is_cubemap) = if render_usage.contains(desc.usage)
&& desc.dimension == wgt::TextureDimension::D2
&& desc.size.depth_or_array_layers == 1
{
Expand Down Expand Up @@ -559,10 +559,10 @@ impl crate::Device<super::Api> for super::Device {
}

gl.bind_renderbuffer(glow::RENDERBUFFER, None);
super::TextureInner::Renderbuffer { raw }
(super::TextureInner::Renderbuffer { raw }, false)
} else {
let raw = gl.create_texture().unwrap();
let (target, is_3d) = match desc.dimension {
let (target, is_3d, is_cubemap) = match desc.dimension {
wgt::TextureDimension::D1 | wgt::TextureDimension::D2 => {
if desc.size.depth_or_array_layers > 1 {
//HACK: detect a cube map
Expand All @@ -575,17 +575,17 @@ impl crate::Device<super::Api> for super::Device {
None
};
match cube_count {
None => (glow::TEXTURE_2D_ARRAY, true),
Some(1) => (glow::TEXTURE_CUBE_MAP, false),
Some(_) => (glow::TEXTURE_CUBE_MAP_ARRAY, true),
None => (glow::TEXTURE_2D_ARRAY, true, false),
Some(1) => (glow::TEXTURE_CUBE_MAP, false, true),
Some(_) => (glow::TEXTURE_CUBE_MAP_ARRAY, true, true),
}
} else {
(glow::TEXTURE_2D, false)
(glow::TEXTURE_2D, false, false)
}
}
wgt::TextureDimension::D3 => {
copy_size.depth = desc.size.depth_or_array_layers;
(glow::TEXTURE_3D, true)
(glow::TEXTURE_3D, true, false)
}
};

Expand Down Expand Up @@ -639,7 +639,7 @@ impl crate::Device<super::Api> for super::Device {
}

gl.bind_texture(target, None);
super::TextureInner::Texture { raw, target }
(super::TextureInner::Texture { raw, target }, is_cubemap)
};

Ok(super::Texture {
Expand All @@ -653,6 +653,7 @@ impl crate::Device<super::Api> for super::Device {
format: desc.format,
format_desc,
copy_size,
is_cubemap,
})
}
unsafe fn destroy_texture(&self, texture: super::Texture) {
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ impl crate::Surface<super::Api> for Surface {
height: sc.extent.height,
depth: 1,
},
is_cubemap: false,
};
Ok(Some(crate::AcquiredSurfaceTexture {
texture,
Expand Down
3 changes: 3 additions & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ pub struct Texture {
#[allow(unused)]
format_desc: TextureFormatDesc,
copy_size: crate::CopyExtent,
is_cubemap: bool,
}

impl Texture {
Expand All @@ -281,6 +282,7 @@ impl Texture {
height: 0,
depth: 0,
},
is_cubemap: false,
}
}
}
Expand Down Expand Up @@ -616,6 +618,7 @@ enum Command {
dst: glow::Texture,
dst_target: BindTarget,
copy: crate::TextureCopy,
dst_is_cubemap: bool,
},
CopyBufferToTexture {
src: Buffer,
Expand Down
15 changes: 13 additions & 2 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ impl super::Queue {
src_target,
dst,
dst_target,
dst_is_cubemap,
ref copy,
} => {
//TODO: handle 3D copies
//TODO: handle cubemap copies
gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(self.copy_fbo));
if is_layered_target(src_target) {
//TODO: handle GLES without framebuffer_texture_3d
Expand All @@ -333,7 +333,18 @@ impl super::Queue {
}

gl.bind_texture(dst_target, Some(dst));
if is_layered_target(dst_target) {
if dst_is_cubemap {
gl.copy_tex_sub_image_2d(
CUBEMAP_FACES[copy.dst_base.array_layer as usize],
copy.dst_base.mip_level as i32,
copy.dst_base.origin.x as i32,
copy.dst_base.origin.y as i32,
copy.src_base.origin.x as i32,
copy.src_base.origin.y as i32,
copy.size.width as i32,
copy.size.height as i32,
);
} else if is_layered_target(dst_target) {
gl.copy_tex_sub_image_3d(
dst_target,
copy.dst_base.mip_level as i32,
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ impl crate::Surface<super::Api> for Surface {
height: sc.extent.height,
depth: 1,
},
is_cubemap: false,
};
Ok(Some(crate::AcquiredSurfaceTexture {
texture,
Expand Down

0 comments on commit a3b2418

Please sign in to comment.