three_d/core/texture/
depth_texture2d_multisample.rs1use crate::core::texture::*;
2
3pub struct DepthTexture2DMultisample {
4 context: Context,
5 id: crate::context::Renderbuffer,
6 width: u32,
7 height: u32,
8 number_of_samples: u32,
9}
10
11impl DepthTexture2DMultisample {
12 pub fn new<T: DepthTextureDataType>(
13 context: &Context,
14 width: u32,
15 height: u32,
16 number_of_samples: u32,
17 ) -> Self {
18 let id = unsafe {
19 context
20 .create_renderbuffer()
21 .expect("Failed creating render buffer")
22 };
23 let texture = Self {
24 context: context.clone(),
25 id,
26 width,
27 height,
28 number_of_samples,
29 };
30 texture.bind();
31 unsafe {
33 context.renderbuffer_storage_multisample(
34 crate::context::RENDERBUFFER,
35 number_of_samples as i32,
36 T::internal_format(),
37 width as i32,
38 height as i32,
39 );
40 }
41 texture
42 }
43
44 pub fn width(&self) -> u32 {
46 self.width
47 }
48
49 pub fn height(&self) -> u32 {
51 self.height
52 }
53
54 pub fn number_of_samples(&self) -> u32 {
56 self.number_of_samples
57 }
58
59 pub(in crate::core) fn bind_as_depth_target(&self) {
60 unsafe {
61 self.context.framebuffer_renderbuffer(
62 crate::context::FRAMEBUFFER,
63 crate::context::DEPTH_ATTACHMENT,
64 crate::context::RENDERBUFFER,
65 Some(self.id),
66 );
67 }
68 }
69
70 pub(in crate::core) fn bind(&self) {
71 unsafe {
72 self.context
73 .bind_renderbuffer(crate::context::RENDERBUFFER, Some(self.id));
74 }
75 }
76}
77
78impl Drop for DepthTexture2DMultisample {
79 fn drop(&mut self) {
80 unsafe {
81 self.context.delete_renderbuffer(self.id);
82 }
83 }
84}