ul_next/gpu_driver/glium/
either_texture.rs1use glium::{
2 framebuffer::ToColorAttachment,
3 texture::SrgbTexture2d,
4 uniforms::{AsUniformValue, Sampler, UniformValue},
5 Texture2d,
6};
7
8pub enum EitherSampler<'t> {
9 Regular2d(Sampler<'t, Texture2d>),
10 Srgb2d(Sampler<'t, SrgbTexture2d>),
11}
12
13impl AsUniformValue for EitherSampler<'_> {
14 #[inline]
15 fn as_uniform_value(&self) -> UniformValue {
16 match self {
17 EitherSampler::Regular2d(t) => t.as_uniform_value(),
18 EitherSampler::Srgb2d(t) => t.as_uniform_value(),
19 }
20 }
21}
22
23pub enum EitherTexture {
24 Regular2d(Texture2d),
25 Srgb2d(SrgbTexture2d),
26}
27
28impl EitherTexture {
29 pub fn width(&self) -> u32 {
30 match self {
31 EitherTexture::Regular2d(t) => t.width(),
32 EitherTexture::Srgb2d(t) => t.width(),
33 }
34 }
35
36 pub fn height(&self) -> u32 {
37 match self {
38 EitherTexture::Regular2d(t) => t.height(),
39 EitherTexture::Srgb2d(t) => t.height(),
40 }
41 }
42
43 pub fn sampled(&'_ self) -> EitherSampler<'_> {
44 match self {
45 EitherTexture::Regular2d(t) => EitherSampler::Regular2d(t.sampled()),
46 EitherTexture::Srgb2d(t) => EitherSampler::Srgb2d(t.sampled()),
47 }
48 }
49}
50
51impl<'t> ToColorAttachment<'t> for &'t EitherTexture {
52 fn to_color_attachment(self) -> glium::framebuffer::ColorAttachment<'t> {
53 match self {
54 EitherTexture::Regular2d(t) => t.to_color_attachment(),
55 EitherTexture::Srgb2d(t) => t.to_color_attachment(),
56 }
57 }
58}