Skip to content

Commit c60c667

Browse files
committed
[update] spacing.
1 parent d401b8b commit c60c667

10 files changed

+99
-2
lines changed

docs/game_roadmap_and_prototype.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This document outlines current engine capabilities, the gaps to address for 2D/3
2424
Key modules: windowing/events (winit), GPU (wgpu), render context, runtime loop, and GLSL→SPIR‑V shader compilation (naga).
2525

2626
Frame flow:
27+
2728
```
2829
App Components --> ApplicationRuntime --> RenderContext --> wgpu (Device/Queue/Surface)
2930
| | | |
@@ -49,6 +50,7 @@ Currently supported commands: Begin/EndRenderPass, SetPipeline, SetViewports, Se
4950
## Targeted API Additions (sketches)
5051

5152
Bind groups and uniforms (value: larger, structured GPU data; portable across adapters; enables cameras/materials):
53+
5254
```rust
5355
// Layout with one uniform buffer at set(0) binding(0)
5456
let layout = BindGroupLayoutBuilder::new()
@@ -84,10 +86,12 @@ RC::Draw { vertices: 0..3 };
8486
```
8587

8688
Notes
89+
8790
- UBO vs push constants: UBOs scale to KBs and are supported widely; use for view/projection and per‑frame data.
8891
- Dynamic offsets (optional later) let you pack many small structs into one UBO.
8992

9093
Textures and samplers (value: sprites, materials, UI images; sRGB correctness):
94+
9195
```rust
9296
let tex = TextureBuilder::new_2d(TextureFormat::Rgba8UnormSrgb)
9397
.with_size(w, h)
@@ -109,6 +113,7 @@ let tex_group = BindGroupBuilder::new(&tex_layout)
109113
```
110114

111115
Index draw and instancing (value: reduce vertex duplication; batch many objects in one draw):
116+
112117
```rust
113118
RC::BindVertexBuffer { pipeline: pipe_id, buffer: 0 };
114119
RC::BindVertexBuffer { pipeline: pipe_id, buffer: 1 }; // instances
@@ -117,6 +122,7 @@ RC::DrawIndexed { indices: 0..index_count, base_vertex: 0, instances: 0..instanc
117122
```
118123

119124
Instance buffer attributes example
125+
120126
```rust
121127
// slot 1: per-instance mat3x2 (2D) packed as 3x vec2, plus tint color
122128
let instance_attrs = vec![
@@ -130,6 +136,7 @@ let instance_attrs = vec![
130136
```
131137

132138
Depth/MSAA (value: correct 3D visibility and improved edge quality):
139+
133140
```rust
134141
let pass = RenderPassBuilder::new()
135142
.with_clear_color(wgpu::Color::BLACK)
@@ -154,10 +161,12 @@ let pipe = RenderPipelineBuilder::new()
154161
```
155162

156163
Notes
164+
157165
- Use reversed‑Z (Greater) later for precision, but start with Less.
158166
- MSAA sample count must match between pass and pipeline.
159167

160168
Offscreen render targets (value: post‑processing, shadow maps, UI composition, picking):
169+
161170
```rust
162171
let offscreen = RenderTargetBuilder::new()
163172
.with_color(TextureFormat::Rgba8UnormSrgb, width, height)
@@ -189,6 +198,7 @@ RC::EndRenderPass;
189198
```
190199

191200
WGSL support (value: first‑class wgpu shader language, fewer translation pitfalls):
201+
192202
```rust
193203
let vs = VirtualShader::WgslSource { source: include_str!("shaders/quad.wgsl").into(), name: "quad".into(), entry_point: "vs_main".into() };
194204
let fs = VirtualShader::WgslSource { source: include_str!("shaders/quad.wgsl").into(), name: "quad".into(), entry_point: "fs_main".into() };
@@ -201,6 +211,7 @@ Shader hot‑reload (value: faster iteration; no rebuild): watch file timestamps
201211
Goals: sprite batching via instancing; atlas textures; ortho camera; input mapping; text HUD. Target 60 FPS with 10k sprites (mid‑range GPU).
202212

203213
Core draw:
214+
204215
```rust
205216
RC::BeginRenderPass { render_pass: pass_id, viewport };
206217
RC::SetPipeline { pipeline: pipe_id };
@@ -214,12 +225,14 @@ RC::EndRenderPass;
214225
```
215226

216227
Building instance data each frame (value: dynamic transforms with minimal overhead):
228+
217229
```rust
218230
// CPU side: update transforms and pack into a Vec<Instance>
219231
queue.write_buffer(instance_vbo.raw(), 0, bytemuck::cast_slice(&instances));
220232
```
221233

222234
Text rendering options (value: legible UI/HUD):
235+
223236
- Bitmap font atlas: simplest path; pack glyphs into the sprite pipeline.
224237
- glyphon/glyph_brush integration: high‑quality layout; more deps; implement later.
225238

@@ -230,6 +243,7 @@ Goals: depth test/write, indexed mesh, textured material, simple lighting; orbit
230243
Core draw mirrors 2D but with depth enabled and mesh buffers.
231244

232245
Camera helpers (value: reduce boilerplate and bugs):
246+
233247
```rust
234248
let proj = matrix::perspective_matrix(60f32.to_radians(), width as f32 / height as f32, 0.1, 100.0);
235249
let view = matrix::translation_matrix([0.0, 0.0, -5.0]); // or look_at helper later

docs/specs/depth-stencil-msaa.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tags: ["spec", "rendering", "depth", "stencil", "msaa"]
1818
# Depth/Stencil and Multi-Sample Rendering
1919

2020
Summary
21+
2122
- Add configurable depth testing/writes and multi-sample anti-aliasing (MSAA)
2223
to the high-level rendering API via builders, without exposing `wgpu` types.
2324
- Provide validation and predictable defaults to enable 3D scenes and
@@ -85,6 +86,7 @@ App Code
8586
- `RenderPipelineBuilder::with_stencil(StencilState) -> Self`
8687
- `RenderPipelineBuilder::with_multi_sample(u32) -> Self`
8788
- Example (engine types only)
89+
8890
```rust
8991
use lambda::render::render_pass::RenderPassBuilder;
9092
use lambda::render::pipeline::{RenderPipelineBuilder, CompareFunction};
@@ -113,6 +115,7 @@ App Code
113115
Some(&fragment_shader),
114116
);
115117
```
118+
116119
- Behavior
117120
- Defaults
118121
- If neither depth nor stencil is requested on the pass, the pass MUST NOT
@@ -178,6 +181,7 @@ App Code
178181
- `render-validation-device`: device/format capability advisories (MSAA sample support).
179182

180183
Always-on safeguards (release and debug)
184+
181185
- Clamp depth clear to `[0.0, 1.0]`.
182186
- Align pipeline `sample_count` to the pass `sample_count`.
183187
- Clamp invalid MSAA sample counts to `1`.
@@ -254,6 +258,7 @@ Always-on safeguards (release and debug)
254258
defaults (no depth, no multi-sampling) unless explicitly configured.
255259

256260
## Changelog
261+
257262
- 2025-12-15 (v0.5.0) — Update example code to use `render_context.gpu()` and add `surface_format`/`depth_format` parameters to `RenderPassBuilder` and `RenderPipelineBuilder`.
258263
- 2025-11-21 (v0.4.1) — Clarify depth attachment and clear behavior for
259264
stencil-only passes; align specification with engine behavior that preserves

docs/specs/indexed-draws-and-multiple-vertex-buffers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tags: ["spec", "rendering", "vertex-input", "indexed-draws"]
1818
# Indexed Draws and Multiple Vertex Buffers
1919

2020
## Table of Contents
21+
2122
- [Summary](#summary)
2223
- [Scope](#scope)
2324
- [Terminology](#terminology)

docs/specs/textures-and-samplers.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tags: ["spec", "rendering", "textures", "samplers", "wgpu"]
1818
# Textures and Samplers
1919

2020
Summary
21+
2122
- Introduces first-class 2D and 3D sampled textures and samplers with a
2223
builder-based application programming interface and platform abstraction.
2324
- Rationale: Texture sampling is foundational for images, sprites, materials,
@@ -305,6 +306,7 @@ Render pass: SetPipeline -> SetBindGroup -> Draw
305306
## Example Usage
306307

307308
Rust (2D high level)
309+
308310
```rust
309311
use lambda::render::texture::{TextureBuilder, SamplerBuilder, TextureFormat};
310312
use lambda::render::bind::{BindGroupLayoutBuilder, BindGroupBuilder, BindingVisibility};
@@ -338,6 +340,7 @@ RC::SetBindGroup { set: 0, group: group_id, dynamic_offsets: vec![] };
338340
```
339341

340342
WGSL snippet (2D)
343+
341344
```wgsl
342345
@group(0) @binding(1) var texture_color: texture_2d<f32>;
343346
@group(0) @binding(2) var sampler_color: sampler;
@@ -350,6 +353,7 @@ fn fs_main(in_uv: vec2<f32>) -> @location(0) vec4<f32> {
350353
```
351354

352355
Rust (3D high level)
356+
353357
```rust
354358
use lambda::render::texture::{TextureBuilder, TextureFormat};
355359
use lambda::render::bind::{BindGroupLayoutBuilder, BindGroupBuilder};
@@ -375,6 +379,7 @@ let group3d = BindGroupBuilder::new()
375379
```
376380

377381
WGSL snippet (3D)
382+
378383
```wgsl
379384
@group(0) @binding(1) var volume_tex: texture_3d<f32>;
380385
@group(0) @binding(2) var volume_samp: sampler;

docs/specs/uniform-buffers-and-bind-groups.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tags: ["spec", "rendering", "uniforms", "bind-groups", "wgpu"]
1818
# Uniform Buffers and Bind Groups
1919

2020
Summary
21+
2122
- Specifies uniform buffer objects (UBOs) and bind groups for the
2223
wgpu‑backed renderer, preserving builder/command patterns and the separation
2324
between platform and high‑level layers.
@@ -72,6 +73,7 @@ Summary
7273
platform layer.
7374

7475
Data flow (one-time setup → per-frame):
76+
7577
```
7678
BindGroupLayoutBuilder --> BindGroupLayout --+--> RenderPipelineBuilder (layouts)
7779
|
@@ -142,6 +144,7 @@ Per-frame commands: BeginRenderPass -> SetPipeline -> SetBindGroup -> Draw -> En
142144
## Example Usage
143145

144146
Rust (high level)
147+
145148
```rust
146149
use lambda::render::{
147150
bind::{BindGroupLayoutBuilder, BindGroupBuilder, BindingVisibility},
@@ -198,6 +201,7 @@ rc.render(cmds);
198201
```
199202

200203
WGSL snippet
204+
201205
```wgsl
202206
struct Globals { view_proj: mat4x4<f32>; };
203207
@group(0) @binding(0) var<uniform> globals: Globals;
@@ -209,12 +213,14 @@ fn vs_main(in_pos: vec3<f32>) -> @builtin(position) vec4<f32> {
209213
```
210214

211215
GLSL snippet (via naga -> SPIR-V)
216+
212217
```glsl
213218
layout(set = 0, binding = 0) uniform Globals { mat4 view_proj; } globals;
214219
void main() { gl_Position = globals.view_proj * vec4(in_pos, 1.0); }
215220
```
216221

217222
Dynamic offsets
223+
218224
```rust
219225
let dyn_layout = BindGroupLayoutBuilder::new()
220226
.with_uniform_dynamic(0, BindingVisibility::Vertex)
@@ -226,6 +232,7 @@ let stride = lambda::render::validation::align_up(size, align);
226232
let offsets = vec![0u32, stride as u32, (2*stride) as u32];
227233
RC::SetBindGroup { set: 0, group: dyn_group_id, dynamic_offsets: offsets };
228234
```
235+
229236
## Performance Considerations
230237

231238
- Prefer `Properties::DEVICE_LOCAL` for long‑lived uniform buffers that are
@@ -293,8 +300,6 @@ RC::SetBindGroup { set: 0, group: dyn_group_id, dynamic_offsets: offsets };
293300
groups continue to function. New pipelines MAY specify layouts via
294301
`with_layouts` without impacting prior behavior.
295302

296-
297-
298303
## Changelog
299304

300305
- 2025-12-15 (v0.5.0) — Update example code to use `rc.gpu()` and add `surface_format`/`depth_format` parameters to `RenderPipelineBuilder`.

docs/tutorials/indexed-draws-and-multiple-vertex-buffers.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ tags: ["tutorial", "graphics", "indexed-draws", "vertex-buffers", "rust", "wgpu"
1616
---
1717

1818
## Overview <a name="overview"></a>
19+
1920
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.
2021

2122
Reference implementation: `crates/lambda-rs/examples/indexed_multi_vertex_buffers.rs`.
2223

2324
## Table of Contents
25+
2426
- [Overview](#overview)
2527
- [Goals](#goals)
2628
- [Prerequisites](#prerequisites)
@@ -86,6 +88,7 @@ Render Pass → wgpu::RenderPass::{set_vertex_buffer, set_index_buffer, draw_ind
8688
## Implementation Steps <a name="implementation-steps"></a>
8789

8890
### Step 1 — Shaders and Vertex Types <a name="step-1"></a>
91+
8992
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.
9093

9194
```glsl
@@ -130,6 +133,7 @@ struct ColorVertex {
130133
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.
131134

132135
### Step 2 — Component State and Shader Construction <a name="step-2"></a>
136+
133137
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.
134138

135139
```rust
@@ -192,6 +196,7 @@ impl Default for IndexedMultiBufferExample {
192196
This `Default` implementation ensures that the component has valid shaders and initial dimensions before it attaches to the render context.
193197

194198
### Step 3 — Render Pass, Vertex Data, Buffers, and Pipeline <a name="step-3"></a>
199+
195200
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`.
196201

197202
```rust
@@ -328,6 +333,7 @@ fn on_attach(
328333
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.
329334

330335
### Step 4 — Resize Handling and Updates <a name="step-4"></a>
336+
331337
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.
332338

333339
```rust
@@ -368,6 +374,7 @@ fn on_update(
368374
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.
369375

370376
### Step 5 — Render Commands and Runtime Entry Point <a name="step-5"></a>
377+
371378
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.
372379

373380
```rust

docs/tutorials/instanced-quads.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tags: ["tutorial", "graphics", "instancing", "vertex-buffers", "rust", "wgpu"]
1616
---
1717

1818
## Overview <a name="overview"></a>
19+
1920
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.
2021

2122
Reference implementation: `crates/lambda-rs/examples/instanced_quads.rs`.
@@ -69,6 +70,7 @@ Render Pass
6970
## Implementation Steps <a name="implementation-steps"></a>
7071

7172
### Step 1 — Shaders and Attribute Layout <a name="step-1"></a>
73+
7274
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.
7375

7476
```glsl
@@ -101,6 +103,7 @@ void main() {
101103
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.
102104

103105
### Step 2 — Vertex and Instance Types and Component State <a name="step-2"></a>
106+
104107
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.
105108

106109
```rust
@@ -210,6 +213,7 @@ impl Default for InstancedQuadsExample {
210213
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`.
211214

212215
### Step 3 — Render Pass, Geometry, Instances, and Buffers <a name="step-3"></a>
216+
213217
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.
214218

215219
```rust
@@ -352,6 +356,7 @@ fn on_attach(
352356
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.
353357

354358
### Step 4 — Resize Handling and Updates <a name="step-4"></a>
359+
355360
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.
356361

357362
```rust
@@ -393,6 +398,7 @@ fn on_update(
393398
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.
394399

395400
### Step 5 — Render Commands and Runtime Entry Point <a name="step-5"></a>
401+
396402
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.
397403

398404
```rust

0 commit comments

Comments
 (0)