summaryrefslogtreecommitdiff
path: root/engine/src/rendering.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-08-27 21:52:30 +0200
committerHampusM <hampus@hampusmat.com>2026-08-27 21:52:30 +0200
commite406e3401b4c2e47c3652e43e88359c5885f52c2 (patch)
tree362c3c2224c14551b251c9a02fe97be14d284af6 /engine/src/rendering.rs
parenta0096c1cf0e06ac32730c78cc18898d74b2f6408 (diff)
feat(engine): validate texture update pixel data format & type in gl rendering backend
Diffstat (limited to 'engine/src/rendering.rs')
-rw-r--r--engine/src/rendering.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/engine/src/rendering.rs b/engine/src/rendering.rs
index 7a46b29..5219d0a 100644
--- a/engine/src/rendering.rs
+++ b/engine/src/rendering.rs
@@ -19,6 +19,7 @@ use crate::ecs::system::initializable::Initializable;
use crate::ecs::system::observer::Observe;
use crate::ecs::system::Into;
use crate::ecs::{declare_entity, pair, Component, Query, Sole};
+use crate::image::{ColorType as ImageColorType, Image};
use crate::mesh::Mesh;
use crate::rendering::blending::Config as BlendingConfig;
use crate::rendering::object::{Id as ObjectId, Store as ObjectStore};
@@ -556,35 +557,35 @@ struct ActiveDrawProperties
pub draw_properties: DrawProperties,
}
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum RgbTextureDataType
{
UnsignedByte,
}
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum RgbaTextureDataType
{
UnsignedByte,
}
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum SrgbTextureDataType
{
UnsignedByte,
}
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum SrgbaTextureDataType
{
UnsignedByte,
}
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum TexturePixelDataFormat
{
@@ -593,3 +594,27 @@ pub enum TexturePixelDataFormat
Srgb(SrgbTextureDataType),
Srgba(SrgbaTextureDataType),
}
+
+impl TexturePixelDataFormat
+{
+ pub fn for_image(image: &Image) -> Option<Self>
+ {
+ let is_srgb = image.color_space_is_srgb();
+
+ match image.color_type() {
+ ImageColorType::Rgb8 if is_srgb => Some(TexturePixelDataFormat::Srgb(
+ SrgbTextureDataType::UnsignedByte,
+ )),
+ ImageColorType::Rgb8 => Some(TexturePixelDataFormat::Rgb(
+ RgbTextureDataType::UnsignedByte,
+ )),
+ ImageColorType::Rgba8 if is_srgb => Some(TexturePixelDataFormat::Srgba(
+ SrgbaTextureDataType::UnsignedByte,
+ )),
+ ImageColorType::Rgba8 => Some(TexturePixelDataFormat::Rgba(
+ RgbaTextureDataType::UnsignedByte,
+ )),
+ _ => None,
+ }
+ }
+}