goud_engine/libs/graphics/backend/render_backend/mod.rs
1//! `RenderBackend` trait definition, composed from focused sub-traits.
2//!
3//! Each sub-trait covers a specific area of GPU operations:
4//! - [`FrameOps`] -- frame lifecycle (begin/end)
5//! - [`ClearOps`] -- clear color and buffer clearing
6//! - [`StateOps`] -- viewport, depth, blending, culling state
7//! - [`BufferOps`] -- GPU buffer create/update/destroy/bind
8//! - [`TextureOps`] -- GPU texture create/update/destroy/bind
9//! - [`ShaderOps`] -- shader compile/link/destroy/bind and uniforms
10//! - [`DrawOps`] -- vertex attribute setup and draw calls
11//!
12//! The composed [`RenderBackend`] supertrait requires all sub-traits
13//! plus `Send + Sync`, providing the full rendering API contract.
14
15mod buffer_ops;
16mod clear_ops;
17mod draw_ops;
18mod frame_ops;
19mod shader_ops;
20mod state_ops;
21mod texture_ops;
22
23pub use buffer_ops::BufferOps;
24pub use clear_ops::ClearOps;
25pub use draw_ops::DrawOps;
26pub use frame_ops::FrameOps;
27pub use shader_ops::ShaderOps;
28pub use state_ops::StateOps;
29pub use texture_ops::TextureOps;
30
31use super::capabilities::{BackendCapabilities, BackendInfo};
32
33/// Main render backend trait abstracting graphics operations.
34///
35/// This trait provides a platform-agnostic interface for rendering operations,
36/// allowing the engine to support multiple graphics APIs without changing
37/// higher-level rendering code.
38///
39/// Composed from focused sub-traits:
40/// [`FrameOps`], [`ClearOps`], [`StateOps`], [`BufferOps`],
41/// [`TextureOps`], [`ShaderOps`], [`DrawOps`].
42///
43/// # Safety
44///
45/// Implementations must ensure:
46/// - All GPU handles remain valid for their lifetime
47/// - Operations on destroyed handles return errors gracefully
48/// - Thread safety is maintained per API requirements
49///
50/// # Object Safety
51///
52/// This trait is intentionally NOT object-safe to allow for:
53/// - Associated types for handle wrappers
54/// - Generic methods for efficient implementations
55/// - Zero-cost abstractions where possible
56pub trait RenderBackend:
57 FrameOps + ClearOps + StateOps + BufferOps + TextureOps + ShaderOps + DrawOps + Send + Sync
58{
59 /// Returns information about this backend implementation.
60 fn info(&self) -> &BackendInfo;
61
62 /// Returns the capabilities of this backend.
63 fn capabilities(&self) -> &BackendCapabilities {
64 &self.info().capabilities
65 }
66}