You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-2025-12-15 (v0.5.0) — Updateexamplecodetouse `render_context.gpu()` and add `surface_format`/`depth_format` parameters to `RenderPassBuilder` and `RenderPipelineBuilder`.
258
263
- 2025-11-21 (v0.4.1) — Clarify depth attachment and clear behavior for
This tutorial constructs a small scene rendered with indexed geometry and multiple vertex buffers. The example separates per-vertex positions from per-vertex colors and draws the result using the engine’s high-level buffer and command builders.
### Step 1 — Shaders and Vertex Types <aname="step-1"></a>
91
+
89
92
Step 1 defines the shader interface and vertex structures used by the example. The shaders consume positions and colors at locations `0` and `1`, and the vertex types store those attributes as three-component floating-point arrays.
90
93
91
94
```glsl
@@ -130,6 +133,7 @@ struct ColorVertex {
130
133
The shader `location` qualifiers match the vertex buffer layouts declared on the pipeline, and the `PositionVertex` and `ColorVertex` types mirror the `vec3` inputs as `[f32; 3]` arrays in Rust.
131
134
132
135
### Step 2 — Component State and Shader Construction <aname="step-2"></a>
136
+
133
137
Step 2 introduces the `IndexedMultiBufferExample` component and its `Default` implementation, which builds shader objects from the GLSL source and initializes render-resource fields and window dimensions.
134
138
135
139
```rust
@@ -192,6 +196,7 @@ impl Default for IndexedMultiBufferExample {
192
196
This `Default` implementation ensures that the component has valid shaders and initial dimensions before it attaches to the render context.
Step 3 implements `on_attach` to create the render pass, vertex and index data, GPU buffers, and the render pipeline, then attaches them to the `RenderContext`.
196
201
197
202
```rust
@@ -328,6 +333,7 @@ fn on_attach(
328
333
The pipeline uses the order of `with_buffer` calls to assign vertex buffer slots. The first buffer occupies slot `0` and provides attributes at location `0`, while the second buffer occupies slot `1` and provides attributes at location `1`. The component stores attached resource identifiers and the index count for use during rendering.
329
334
330
335
### Step 4 — Resize Handling and Updates <aname="step-4"></a>
336
+
331
337
Step 4 wires window resize events into the component and implements detach and update hooks. The resize handler keeps `width` and `height` in sync with the window so that the viewport matches the surface size.
332
338
333
339
```rust
@@ -368,6 +374,7 @@ fn on_update(
368
374
The resize path is the only dynamic input in this example. The update hook is a no-op that keeps the component interface aligned with other examples.
369
375
370
376
### Step 5 — Render Commands and Runtime Entry Point <aname="step-5"></a>
377
+
371
378
Step 5 records the render commands that bind the pipeline, vertex buffers, and index buffer, and then wires the component into the runtime as a windowed application.
This tutorial builds an instanced rendering example using the `lambda-rs` crate. The final application renders a grid of 2D quads that all share the same geometry but read per-instance offsets and colors from a second vertex buffer. The example demonstrates how to configure per-vertex and per-instance buffers, construct an instanced render pipeline, and issue draw commands with a multi-instance range.
### Step 1 — Shaders and Attribute Layout <aname="step-1"></a>
73
+
72
74
Step 1 defines the vertex and fragment shaders for instanced quads. The vertex shader consumes per-vertex positions and per-instance offsets and colors, and the fragment shader writes the interpolated color.
73
75
74
76
```glsl
@@ -101,6 +103,7 @@ void main() {
101
103
Attribute locations `0`, `1`, and `2` correspond to pipeline vertex attribute definitions for the per-vertex position and the per-instance offset and color. These locations will be matched by `VertexAttribute` entries when the render pipeline is constructed.
102
104
103
105
### Step 2 — Vertex and Instance Types and Component State <aname="step-2"></a>
106
+
104
107
Step 2 introduces the Rust vertex and instance structures and prepares the component state. The component stores compiled shaders and identifiers for the render pass, pipeline, and buffers.
105
108
106
109
```rust
@@ -210,6 +213,7 @@ impl Default for InstancedQuadsExample {
210
213
The `QuadVertex` and `InstanceData` structures mirror the GLSL inputs as arrays of `f32`, and the component tracks resource identifiers and counts that are populated during attachment. The `Default` implementation constructs shader objects from the GLSL source so that the component is ready to build a pipeline when it receives a `RenderContext`.
Step 3 implements the `on_attach` method for the component. This method creates the render pass, quad geometry, instance data, GPU buffers, and the render pipeline. It also records the number of indices and instances for use during rendering.
214
218
215
219
```rust
@@ -352,6 +356,7 @@ fn on_attach(
352
356
The first buffer created by `with_buffer` is treated as a per-vertex buffer in slot `0`, while `with_instance_buffer` registers the instance buffer in slot `1` with per-instance step mode. The `vertex_attributes` and `instance_attributes` vectors connect shader locations `0`, `1`, and `2` to their corresponding buffer slots and formats, and the component records index and instance counts for later draws. The effective byte offset of each attribute is computed as `attribute.offset + attribute.element.offset`. In this example `attribute.offset` is kept at `0` for all attributes, and the struct layout is expressed entirely through `VertexElement::offset` (for example, the `color` field in `InstanceData` starts 12 bytes after the `offset` field). More complex layouts MAY use a non-zero `attribute.offset` to reuse the same attribute description at different base positions within a vertex or instance element.
353
357
354
358
### Step 4 — Resize Handling and Updates <aname="step-4"></a>
359
+
355
360
Step 4 wires window resize events into the component and implements detach and update hooks. The resize handler keeps `width` and `height` in sync with the window so that the viewport matches the surface size.
356
361
357
362
```rust
@@ -393,6 +398,7 @@ fn on_update(
393
398
The component does not modify instance data over time, so `on_update` is a no-op. The resize path is the only dynamic input and ensures that the viewport used during rendering matches the current window size.
394
399
395
400
### Step 5 — Render Commands and Runtime Entry Point <aname="step-5"></a>
401
+
396
402
Step 5 records the render commands that bind the pipeline, vertex buffers, and index buffer, then wires the component into the `lambda-rs` runtime as a windowed application.
0 commit comments