glium/texture/
texture_import.rs

1use std::{error::Error, fmt};
2
3use crate::{gl, image_format::FormatNotSupportedError, memory_object::MemoryObjectCreationError};
4
5/// Describes a tiling mode used in texture storage by an external API
6pub enum ExternalTilingMode {
7    /// Corresponds to VK_IMAGE_TILING_OPTIMAL
8    Optimal,
9    /// Corresponds to VK_IMAGE_TILING_LINEAR
10    Linear
11}
12
13impl Into<crate::gl::types::GLenum> for ExternalTilingMode {
14    fn into(self) -> crate::gl::types::GLenum {
15        match self {
16            ExternalTilingMode::Optimal => gl::OPTIMAL_TILING_EXT,
17            ExternalTilingMode::Linear => gl::LINEAR_TILING_EXT,
18        }
19    }
20}
21
22/// Contains parameters needed to import a texture created in an external
23/// API into OpenGL. Must match with parameters used by external memory.
24pub struct ImportParameters {
25    /// Describes whether this memory was created as "dedicated" by the external API.
26    pub dedicated_memory: bool,
27    /// Size of the memory object in bytes.
28    pub size: u64,
29    /// Offset of the memory object in bytes.
30    pub offset: u64,
31    /// Tiling mode used in the memory object.
32    pub tiling: ExternalTilingMode,
33}
34
35
36/// Error that can happen when importing a texture.
37#[derive(Debug, Clone, Copy)]
38pub enum TextureImportError {
39    /// A specific format for the texture was not given.
40    FormatNotPresent,
41    /// An error ocurred during memory object creation
42    MemoryObjectCreation(MemoryObjectCreationError),
43    /// Texture format not supported by this OpenGL context
44    FormatNotSupported(FormatNotSupportedError),
45}
46
47impl fmt::Display for TextureImportError {
48    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
49        use self::TextureImportError::*;
50        match *self {
51            FormatNotPresent => write!(fmt, "A specific format for the texture was not given."),
52            MemoryObjectCreation(e) => e.fmt(fmt),
53            FormatNotSupported(e) => e.fmt(fmt),
54        }
55    }
56}
57
58impl From<MemoryObjectCreationError> for TextureImportError {
59    fn from(e: MemoryObjectCreationError) -> Self {
60        Self::MemoryObjectCreation(e)
61    }
62}
63
64impl Error for TextureImportError {}