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