2024-09-08 15:03:43 +10:00
|
|
|
use crate::texture::InputTexture;
|
|
|
|
use librashader_common::{FilterMode, GetSize, Size, WrapMode};
|
2022-11-30 17:38:05 +11:00
|
|
|
|
2023-01-13 19:19:58 +11:00
|
|
|
/// A handle to an OpenGL texture with format and size information.
|
|
|
|
///
|
|
|
|
/// Generally for use as shader resource inputs.
|
2022-11-21 18:56:03 +11:00
|
|
|
#[derive(Default, Debug, Copy, Clone)]
|
2022-11-30 16:39:42 +11:00
|
|
|
pub struct GLImage {
|
2023-01-13 19:19:58 +11:00
|
|
|
/// A GLuint to the texture.
|
2024-02-06 10:39:01 +11:00
|
|
|
pub handle: Option<glow::Texture>,
|
2023-01-13 19:19:58 +11:00
|
|
|
/// The format of the texture.
|
2024-02-06 10:39:01 +11:00
|
|
|
pub format: u32,
|
2023-01-13 19:19:58 +11:00
|
|
|
/// The size of the texture.
|
2022-11-21 19:01:26 +11:00
|
|
|
pub size: Size<u32>,
|
2022-11-21 18:56:03 +11:00
|
|
|
}
|
2024-08-02 14:25:54 +10:00
|
|
|
|
2024-09-08 15:03:43 +10:00
|
|
|
impl GLImage {
|
|
|
|
pub(crate) fn as_texture(&self, filter: FilterMode, wrap_mode: WrapMode) -> InputTexture {
|
|
|
|
InputTexture {
|
|
|
|
image: *self,
|
|
|
|
filter,
|
|
|
|
mip_filter: filter,
|
|
|
|
wrap_mode,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-02 14:25:54 +10:00
|
|
|
impl GetSize<u32> for GLImage {
|
|
|
|
type Error = std::convert::Infallible;
|
|
|
|
|
|
|
|
fn size(&self) -> Result<Size<u32>, Self::Error> {
|
|
|
|
Ok(self.size)
|
|
|
|
}
|
|
|
|
}
|
2024-09-08 15:03:43 +10:00
|
|
|
|
|
|
|
impl GetSize<u32> for &GLImage {
|
|
|
|
type Error = std::convert::Infallible;
|
|
|
|
|
|
|
|
fn size(&self) -> Result<Size<u32>, Self::Error> {
|
|
|
|
Ok(self.size)
|
|
|
|
}
|
|
|
|
}
|