three_d/core/texture/
depth_texture_cube_map.rs1use crate::core::texture::*;
2
3pub struct DepthTextureCubeMap {
7 context: Context,
8 id: crate::context::Texture,
9 width: u32,
10 height: u32,
11}
12
13impl DepthTextureCubeMap {
14 pub fn new<T: DepthTextureDataType>(
18 context: &Context,
19 width: u32,
20 height: u32,
21 wrap_s: Wrapping,
22 wrap_t: Wrapping,
23 wrap_r: Wrapping,
24 ) -> Self {
25 let id = generate(context);
26 let texture = Self {
27 context: context.clone(),
28 id,
29 width,
30 height,
31 };
32 texture.bind();
33 set_parameters(
34 context,
35 crate::context::TEXTURE_CUBE_MAP,
36 Interpolation::Nearest,
37 Interpolation::Nearest,
38 None,
39 wrap_s,
40 wrap_t,
41 Some(wrap_r),
42 );
43 unsafe {
44 context.tex_storage_2d(
45 crate::context::TEXTURE_CUBE_MAP,
46 1,
47 T::internal_format(),
48 width as i32,
49 height as i32,
50 );
51 }
52 texture
53 }
54
55 pub fn as_depth_target(&mut self, side: CubeMapSide) -> DepthTarget<'_> {
60 DepthTarget::new_texture_cube_map(&self.context, self, side)
61 }
62
63 pub fn width(&self) -> u32 {
65 self.width
66 }
67
68 pub fn height(&self) -> u32 {
70 self.height
71 }
72
73 pub(in crate::core) fn bind_as_depth_target(&self, side: CubeMapSide) {
74 unsafe {
75 self.context.framebuffer_texture_2d(
76 crate::context::DRAW_FRAMEBUFFER,
77 crate::context::DEPTH_ATTACHMENT,
78 side.to_const(),
79 Some(self.id),
80 0,
81 );
82 }
83 }
84
85 pub(in crate::core) fn bind(&self) {
86 unsafe {
87 self.context
88 .bind_texture(crate::context::TEXTURE_CUBE_MAP, Some(self.id));
89 }
90 }
91}
92
93impl Drop for DepthTextureCubeMap {
94 fn drop(&mut self) {
95 unsafe {
96 self.context.delete_texture(self.id);
97 }
98 }
99}