pub struct GBuffer {
pub layout: GBufferLayout,
pub viewport: Viewport,
pub fbo_handle: u64,
pub texture_states: Vec<TextureState>,
pub depth_texture_state: TextureState,
pub mrt_config: MrtConfig,
pub debug_view: GBufferDebugView,
pub stats: GBufferStats,
pub is_bound: bool,
pub generation: u32,
pub is_created: bool,
/* private fields */
}Expand description
The main G-Buffer object that manages all attachment textures and the framebuffer. This struct owns the GPU resource handles (as opaque u64 IDs) and provides bind/unbind/resize/clear operations.
Fields§
§layout: GBufferLayoutThe layout describing all attachments.
viewport: ViewportCurrent viewport dimensions.
fbo_handle: u64Framebuffer object handle.
texture_states: Vec<TextureState>Per-attachment texture states.
depth_texture_state: TextureStateDepth texture state.
mrt_config: MrtConfigMRT configuration derived from the layout.
debug_view: GBufferDebugViewDebug view state.
stats: GBufferStatsStatistics.
is_bound: boolWhether the G-Buffer is currently bound as the render target.
generation: u32Generation counter (incremented on resize).
is_created: boolWhether the G-Buffer resources have been created.
Implementations§
Source§impl GBuffer
impl GBuffer
Sourcepub fn with_layout(layout: GBufferLayout, viewport: Viewport) -> Self
pub fn with_layout(layout: GBufferLayout, viewport: Viewport) -> Self
Create a new G-Buffer with a custom layout.
Sourcepub fn create(&mut self) -> Result<(), GBufferError>
pub fn create(&mut self) -> Result<(), GBufferError>
Allocate GPU resources for the G-Buffer. In a real engine this would call OpenGL/Vulkan; here we simulate handle allocation.
Sourcepub fn bind(&mut self) -> Result<(), GBufferError>
pub fn bind(&mut self) -> Result<(), GBufferError>
Bind the G-Buffer as the current render target.
Sourcepub fn bind_for_reading(&self) -> Result<Vec<(u32, u64)>, GBufferError>
pub fn bind_for_reading(&self) -> Result<Vec<(u32, u64)>, GBufferError>
Bind all G-Buffer textures for reading in the lighting pass.
Sourcepub fn bind_attachment(
&self,
semantic: GBufferSemantic,
texture_unit: u32,
) -> Result<u64, GBufferError>
pub fn bind_attachment( &self, semantic: GBufferSemantic, texture_unit: u32, ) -> Result<u64, GBufferError>
Bind a single attachment for sampling.
Sourcepub fn resize(&mut self, width: u32, height: u32) -> Result<(), GBufferError>
pub fn resize(&mut self, width: u32, height: u32) -> Result<(), GBufferError>
Resize the G-Buffer to a new resolution. Recreates all textures.
Sourcepub fn clear_all(&mut self)
pub fn clear_all(&mut self)
Clear all G-Buffer attachments using their configured clear values.
Sourcepub fn clear_attachment(
&self,
semantic: GBufferSemantic,
) -> Result<(), GBufferError>
pub fn clear_attachment( &self, semantic: GBufferSemantic, ) -> Result<(), GBufferError>
Clear a specific attachment.
Sourcepub fn texture_handle(&self, semantic: GBufferSemantic) -> Option<u64>
pub fn texture_handle(&self, semantic: GBufferSemantic) -> Option<u64>
Get the texture handle for a specific attachment.
Sourcepub fn aspect_ratio(&self) -> f32
pub fn aspect_ratio(&self) -> f32
Get the aspect ratio.
Sourcepub fn stats(&self) -> &GBufferStats
pub fn stats(&self) -> &GBufferStats
Get a reference to the stats.
Sourcepub fn describe(&self) -> String
pub fn describe(&self) -> String
Get a human-readable description of the G-Buffer configuration.
Sourcepub fn needs_recreate(&self) -> bool
pub fn needs_recreate(&self) -> bool
Check if the G-Buffer needs to be recreated (e.g., after layout change).
Sourcepub fn fullscreen_quad_vertices() -> ([f32; 12], [f32; 8])
pub fn fullscreen_quad_vertices() -> ([f32; 12], [f32; 8])
Convenience: create a fullscreen quad vertex data for the lighting pass. Returns (positions, uvs) for two triangles covering NDC [-1, 1].
Sourcepub fn lighting_vertex_shader() -> &'static str
pub fn lighting_vertex_shader() -> &'static str
Generate the complete GLSL vertex shader for the fullscreen lighting quad.
Sourcepub fn lighting_fragment_preamble(&self) -> String
pub fn lighting_fragment_preamble(&self) -> String
Generate the lighting pass fragment shader preamble (sampler uniforms).