pub struct SurfaceMeshRenderData {
pub vertex_buffer: Buffer,
pub index_buffer: Buffer,
pub normal_buffer: Buffer,
pub barycentric_buffer: Buffer,
pub color_buffer: Buffer,
pub edge_is_real_buffer: Buffer,
pub uniform_buffer: Buffer,
pub bind_group: BindGroup,
pub num_triangles: u32,
pub num_indices: u32,
pub shadow_bind_group: Option<BindGroup>,
pub shadow_model_buffer: Option<Buffer>,
}Expand description
GPU resources for rendering a surface mesh.
Fields§
§vertex_buffer: BufferPosition buffer (storage buffer, vec4 for alignment).
index_buffer: BufferIndex buffer (triangle indices).
normal_buffer: BufferNormal buffer (vertex normals, vec4 for alignment).
barycentric_buffer: BufferBarycentric coordinate buffer for wireframe rendering.
Each triangle vertex gets [1,0,0], [0,1,0], [0,0,1].
color_buffer: BufferColor buffer (per-vertex colors for quantities, vec4).
edge_is_real_buffer: BufferEdge is real buffer - marks which edges are real polygon edges vs triangulation internal.
uniform_buffer: BufferUniform buffer for mesh-specific settings.
bind_group: BindGroupBind group for this surface mesh.
num_triangles: u32Number of triangles.
num_indices: u32Number of indices (num_triangles * 3).
shadow_bind_group: Option<BindGroup>Shadow pass bind group (for rendering to shadow map).
shadow_model_buffer: Option<Buffer>Shadow model uniform buffer (contains only model matrix).
Implementations§
Source§impl SurfaceMeshRenderData
impl SurfaceMeshRenderData
Sourcepub fn new(
device: &Device,
bind_group_layout: &BindGroupLayout,
camera_buffer: &Buffer,
vertices: &[Vec3],
triangles: &[[u32; 3]],
vertex_normals: &[Vec3],
edge_is_real: &[Vec3],
) -> Self
pub fn new( device: &Device, bind_group_layout: &BindGroupLayout, camera_buffer: &Buffer, vertices: &[Vec3], triangles: &[[u32; 3]], vertex_normals: &[Vec3], edge_is_real: &[Vec3], ) -> Self
Creates new render data from mesh geometry.
§Arguments
device- The wgpu devicebind_group_layout- The bind group layout for surface meshescamera_buffer- The camera uniform buffervertices- Vertex positionstriangles- Triangle indices (each [u32; 3] is one triangle)vertex_normals- Per-vertex normalsedge_is_real- Per-triangle-vertex flags marking real polygon edges vs internal triangulation edges
Sourcepub fn update_uniforms(&self, queue: &Queue, uniforms: &MeshUniforms)
pub fn update_uniforms(&self, queue: &Queue, uniforms: &MeshUniforms)
Updates the mesh uniform buffer.
Sourcepub fn update_colors(
&self,
queue: &Queue,
colors: &[Vec4],
triangles: &[[u32; 3]],
)
pub fn update_colors( &self, queue: &Queue, colors: &[Vec4], triangles: &[[u32; 3]], )
Updates the per-vertex color buffer with per-original-vertex colors. This expands the colors to match the per-triangle-vertex buffer layout.
Sourcepub fn clear_colors(&self, queue: &Queue)
pub fn clear_colors(&self, queue: &Queue)
Clears the color buffer (sets all colors to zero, which means use surface_color).
Sourcepub fn init_shadow_resources(
&mut self,
device: &Device,
shadow_bind_group_layout: &BindGroupLayout,
light_buffer: &Buffer,
)
pub fn init_shadow_resources( &mut self, device: &Device, shadow_bind_group_layout: &BindGroupLayout, light_buffer: &Buffer, )
Initializes shadow rendering resources.
Creates the bind group and model buffer needed for the shadow pass. The shadow pass renders this mesh from the light’s perspective to create shadows on the ground plane.
Sourcepub fn has_shadow_resources(&self) -> bool
pub fn has_shadow_resources(&self) -> bool
Returns whether shadow resources have been initialized.
Sourcepub fn num_vertices(&self) -> u32
pub fn num_vertices(&self) -> u32
Returns the number of vertices for shadow pass rendering.
The shadow pass uses non-indexed drawing with storage buffers, so this returns the number of expanded triangle vertices.
Sourcepub fn update_shadow_model(&self, queue: &Queue, model_matrix: [[f32; 4]; 4])
pub fn update_shadow_model(&self, queue: &Queue, model_matrix: [[f32; 4]; 4])
Updates the shadow model uniform buffer with the current transform.
This should be called whenever the mesh’s transform changes to ensure shadows are rendered at the correct position.
Sourcepub fn uniform_buffer(&self) -> &Buffer
pub fn uniform_buffer(&self) -> &Buffer
Returns the uniform buffer.
Sourcepub fn position_buffer(&self) -> &Buffer
pub fn position_buffer(&self) -> &Buffer
Returns the position buffer.
Sourcepub fn normal_buffer(&self) -> &Buffer
pub fn normal_buffer(&self) -> &Buffer
Returns the normal buffer.
Sourcepub fn barycentric_buffer(&self) -> &Buffer
pub fn barycentric_buffer(&self) -> &Buffer
Returns the barycentric buffer.
Sourcepub fn color_buffer(&self) -> &Buffer
pub fn color_buffer(&self) -> &Buffer
Returns the color buffer.
Sourcepub fn edge_is_real_buffer(&self) -> &Buffer
pub fn edge_is_real_buffer(&self) -> &Buffer
Returns the edge is real buffer.
Sourcepub fn vertex_count(&self) -> u32
pub fn vertex_count(&self) -> u32
Returns the number of vertices (for non-indexed drawing).
Auto Trait Implementations§
impl Freeze for SurfaceMeshRenderData
impl !RefUnwindSafe for SurfaceMeshRenderData
impl Send for SurfaceMeshRenderData
impl Sync for SurfaceMeshRenderData
impl Unpin for SurfaceMeshRenderData
impl UnsafeUnpin for SurfaceMeshRenderData
impl !UnwindSafe for SurfaceMeshRenderData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more