@@ -31,22 +31,61 @@ impl DepthFormat {
3131 }
3232}
3333
34- #[ derive( Debug , Clone , Copy ) ]
35- /// Supported color texture formats for sampling.
34+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
35+ /// Supported color texture formats for sampling and render targets .
3636pub enum TextureFormat {
37+ /// 8-bit RGBA, linear (non-sRGB).
3738 Rgba8Unorm ,
39+ /// 8-bit RGBA, sRGB encoded.
3840 Rgba8UnormSrgb ,
41+ /// 8-bit BGRA, linear (non-sRGB). Common swapchain format.
42+ Bgra8Unorm ,
43+ /// 8-bit BGRA, sRGB encoded. Common swapchain format.
44+ Bgra8UnormSrgb ,
3945}
4046
4147impl TextureFormat {
42- fn to_platform ( self ) -> platform:: TextureFormat {
48+ pub ( crate ) fn to_platform ( self ) -> platform:: TextureFormat {
4349 return match self {
4450 TextureFormat :: Rgba8Unorm => platform:: TextureFormat :: RGBA8_UNORM ,
4551 TextureFormat :: Rgba8UnormSrgb => {
4652 platform:: TextureFormat :: RGBA8_UNORM_SRGB
4753 }
54+ TextureFormat :: Bgra8Unorm => platform:: TextureFormat :: BGRA8_UNORM ,
55+ TextureFormat :: Bgra8UnormSrgb => {
56+ platform:: TextureFormat :: BGRA8_UNORM_SRGB
57+ }
4858 } ;
4959 }
60+
61+ pub ( crate ) fn from_platform ( fmt : platform:: TextureFormat ) -> Option < Self > {
62+ if fmt == platform:: TextureFormat :: RGBA8_UNORM {
63+ return Some ( TextureFormat :: Rgba8Unorm ) ;
64+ }
65+ if fmt == platform:: TextureFormat :: RGBA8_UNORM_SRGB {
66+ return Some ( TextureFormat :: Rgba8UnormSrgb ) ;
67+ }
68+ if fmt == platform:: TextureFormat :: BGRA8_UNORM {
69+ return Some ( TextureFormat :: Bgra8Unorm ) ;
70+ }
71+ if fmt == platform:: TextureFormat :: BGRA8_UNORM_SRGB {
72+ return Some ( TextureFormat :: Bgra8UnormSrgb ) ;
73+ }
74+ return None ;
75+ }
76+
77+ /// Whether this format is sRGB encoded.
78+ pub fn is_srgb ( self ) -> bool {
79+ return matches ! (
80+ self ,
81+ TextureFormat :: Rgba8UnormSrgb | TextureFormat :: Bgra8UnormSrgb
82+ ) ;
83+ }
84+
85+ /// Number of bytes per pixel for this format.
86+ pub fn bytes_per_pixel ( self ) -> u32 {
87+ return 4 ;
88+ }
5089}
5190
5291#[ derive( Debug , Clone , Copy ) ]
@@ -98,6 +137,59 @@ impl AddressMode {
98137 } ;
99138 }
100139}
140+
141+ /// Texture usage flags.
142+ ///
143+ /// Use bitwise-OR to combine flags when creating textures with multiple usages.
144+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
145+ pub struct TextureUsages ( platform:: TextureUsages ) ;
146+
147+ impl TextureUsages {
148+ /// Texture can be used as a render attachment (color or depth/stencil).
149+ pub const RENDER_ATTACHMENT : TextureUsages =
150+ TextureUsages ( platform:: TextureUsages :: RENDER_ATTACHMENT ) ;
151+ /// Texture can be bound for sampling in shaders.
152+ pub const TEXTURE_BINDING : TextureUsages =
153+ TextureUsages ( platform:: TextureUsages :: TEXTURE_BINDING ) ;
154+ /// Texture can be used as the destination of a copy operation.
155+ pub const COPY_DST : TextureUsages =
156+ TextureUsages ( platform:: TextureUsages :: COPY_DST ) ;
157+ /// Texture can be used as the source of a copy operation.
158+ pub const COPY_SRC : TextureUsages =
159+ TextureUsages ( platform:: TextureUsages :: COPY_SRC ) ;
160+
161+ /// Create an empty flags set.
162+ pub const fn empty ( ) -> Self {
163+ return TextureUsages ( platform:: TextureUsages :: empty ( ) ) ;
164+ }
165+
166+ pub ( crate ) fn to_platform ( self ) -> platform:: TextureUsages {
167+ return self . 0 ;
168+ }
169+
170+ pub ( crate ) fn from_platform ( usage : platform:: TextureUsages ) -> Self {
171+ return TextureUsages ( usage) ;
172+ }
173+
174+ /// Check whether this flags set contains another set.
175+ pub fn contains ( self , other : TextureUsages ) -> bool {
176+ return self . 0 . contains ( other. 0 ) ;
177+ }
178+ }
179+
180+ impl std:: ops:: BitOr for TextureUsages {
181+ type Output = TextureUsages ;
182+
183+ fn bitor ( self , rhs : TextureUsages ) -> TextureUsages {
184+ return TextureUsages ( self . 0 | rhs. 0 ) ;
185+ }
186+ }
187+
188+ impl std:: ops:: BitOrAssign for TextureUsages {
189+ fn bitor_assign ( & mut self , rhs : TextureUsages ) {
190+ self . 0 |= rhs. 0 ;
191+ }
192+ }
101193#[ derive( Debug , Clone ) ]
102194/// High‑level texture wrapper that owns a platform texture.
103195pub struct Texture {
0 commit comments