Skip to content

Commit e7322b9

Browse files
committed
[update] documentation across lambda-rs.
1 parent a31f1c8 commit e7322b9

File tree

13 files changed

+79
-40
lines changed

13 files changed

+79
-40
lines changed

crates/lambda-rs/src/events.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub enum WindowEvent {
1515
Resize { width: u32, height: u32 },
1616
}
1717

18-
/// Kernel events are generated by the kernel itself
18+
/// Runtime events are generated by the Runtimes themselves.
1919
#[derive(Debug, Clone)]
2020
pub enum RuntimeEvent {
2121
Initialized,
@@ -25,6 +25,8 @@ pub enum RuntimeEvent {
2525
/// Exports the winit virtual key codes to this namespace for convenience.
2626
pub use lambda_platform::winit::winit_exports::VirtualKeyCode as VirtualKey;
2727

28+
/// Keyboard events are generated in response to keyboard events coming from
29+
/// the windowing system.
2830
#[derive(Debug, Clone)]
2931
pub enum Key {
3032
Pressed {
@@ -41,6 +43,7 @@ pub enum Key {
4143
},
4244
}
4345

46+
/// Mouse buttons.
4447
#[derive(Debug, Clone)]
4548
pub enum Button {
4649
Left,
@@ -49,6 +52,8 @@ pub enum Button {
4952
Other(u16),
5053
}
5154

55+
/// Mouse events are generated in response to mouse events coming from the
56+
/// windowing system. The coordinates are in logical pixels.
5257
#[derive(Debug, Clone)]
5358
pub enum Mouse {
5459
Moved {

crates/lambda-rs/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Lambda is a simple, fast, and safe compute engine written in Rust.
2+
13
pub mod component;
24
pub mod components;
35
pub mod events;

crates/lambda-rs/src/render/buffer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Buffers for allocating memory on the GPU.
2+
13
mod internal {
24
// Placed these in an internal module to avoid a name collision with the
35
// high level Buffer & BufferBuilder types in the parent module.
@@ -22,6 +24,7 @@ use super::{
2224
RenderContext,
2325
};
2426

27+
/// Buffer for storing vertex data on the GPU.
2528
#[derive(Debug)]
2629
pub struct Buffer {
2730
buffer: Rc<internal::Buffer<super::internal::RenderBackend>>,

crates/lambda-rs/src/render/command.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Render command definitions for lambda runtimes.
2+
13
use std::ops::Range;
24

35
use lambda_platform::gfx::viewport::ViewPort as PlatformViewPort;
@@ -20,36 +22,35 @@ pub enum RenderCommand {
2022
start_at: u32,
2123
viewports: Vec<super::viewport::Viewport>,
2224
},
23-
SetPipeline {
24-
pipeline: super::ResourceId,
25-
},
25+
/// Sets the pipeline to use for the render context.
26+
SetPipeline { pipeline: super::ResourceId },
2627
/// Begins the render pass.
2728
BeginRenderPass {
2829
render_pass: super::ResourceId,
2930
viewport: super::viewport::Viewport,
3031
},
3132
/// Ends the render pass.
3233
EndRenderPass,
34+
35+
/// Sets the push constants for the render pipeline.
3336
PushConstants {
3437
pipeline: super::ResourceId,
3538
stage: super::pipeline::PipelineStage,
3639
offset: u32,
3740
bytes: Vec<u32>,
3841
},
42+
/// Binds a vertex buffer to the render pipeline.
3943
BindVertexBuffer {
4044
pipeline: super::ResourceId,
4145
buffer: u32,
4246
},
4347
/// Draws a graphical primitive.
44-
Draw {
45-
vertices: Range<u32>,
46-
},
48+
Draw { vertices: Range<u32> },
4749
}
4850

4951
impl RenderCommand {
5052
/// Converts the RenderCommand into a platform compatible render command.
51-
// TODO(vmarcella): implement this using Into<PlatformRenderCommand>
52-
pub fn into_platform_command(
53+
pub(super) fn into_platform_command(
5354
&self,
5455
render_context: &mut RenderContext,
5556
) -> PlatformRenderCommand {

crates/lambda-rs/src/render/mesh.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Mesh Implementation
2+
13
use lambda_platform::obj::load_textured_obj_from_file;
24

35
use super::{
@@ -7,7 +9,6 @@ use super::{
79
VertexElement,
810
},
911
ColorFormat,
10-
RenderContext,
1112
};
1213

1314
// ---------------------------------- Mesh ------------------------------------
@@ -20,10 +21,12 @@ pub struct Mesh {
2021
}
2122

2223
impl Mesh {
24+
/// Gets the vertices of the mesh.
2325
pub fn vertices(&self) -> &[Vertex] {
2426
&self.vertices
2527
}
2628

29+
/// Gets the attributes of the mesh.
2730
pub fn attributes(&self) -> &[VertexAttribute] {
2831
&self.attributes
2932
}
@@ -40,6 +43,7 @@ pub struct MeshBuilder {
4043
}
4144

4245
impl MeshBuilder {
46+
/// Creates a new mesh builder.
4347
pub fn new() -> Self {
4448
return Self {
4549
capacity: 0,
@@ -48,16 +52,29 @@ impl MeshBuilder {
4852
};
4953
}
5054

55+
/// Allocates memory for the given number of vertices and fills
56+
/// the mesh with empty vertices.
5157
pub fn with_capacity(&mut self, size: usize) -> &mut Self {
5258
self.capacity = size;
59+
self.vertices.resize(
60+
size,
61+
Vertex {
62+
position: [0.0, 0.0, 0.0],
63+
normal: [0.0, 0.0, 0.0],
64+
color: [0.0, 0.0, 0.0],
65+
},
66+
);
5367
return self;
5468
}
5569

70+
/// Adds a vertex to the mesh.
5671
pub fn with_vertex(&mut self, vertex: Vertex) -> &mut Self {
5772
self.vertices.push(vertex);
5873
return self;
5974
}
6075

76+
/// Specify the attributes of the mesh. This is used to map the vertex data to
77+
/// the input of the vertex shader.
6178
pub fn with_attributes(
6279
&mut self,
6380
attributes: Vec<VertexAttribute>,

crates/lambda-rs/src/render/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,23 @@ use self::{
3838
render_pass::RenderPass,
3939
};
4040

41+
/// A RenderContext is a localized rendering context that can be used to render
42+
/// to a window. It is localized to a single window at the moment.
4143
pub struct RenderContextBuilder {
4244
name: String,
4345
render_timeout: u64,
4446
}
4547

4648
impl RenderContextBuilder {
47-
/// Create a new localized RenderContext
49+
/// Create a new localized RenderContext with the given name.
4850
pub fn new(name: &str) -> Self {
4951
return Self {
5052
name: name.to_string(),
5153
render_timeout: 1_000_000_000,
5254
};
5355
}
5456

55-
/// The time rendering has to complete before timing out.
57+
/// The time rendering has to complete before a timeout occurs.
5658
pub fn with_render_timeout(mut self, render_timeout: u64) -> Self {
5759
self.render_timeout = render_timeout;
5860
return self;
@@ -69,7 +71,7 @@ impl RenderContextBuilder {
6971

7072
let mut instance = internal::InstanceBuilder::new()
7173
.build::<internal::RenderBackend>(name.as_str());
72-
let mut surface = Rc::new(
74+
let surface = Rc::new(
7375
internal::SurfaceBuilder::new().build(&instance, window.window_handle()),
7476
);
7577

@@ -90,10 +92,6 @@ impl RenderContextBuilder {
9092
let render_semaphore =
9193
internal::RenderSemaphoreBuilder::new().build(&mut gpu);
9294

93-
// Create the image extent and initial frame buffer attachment description
94-
// for rendering.
95-
let (width, height) = window.dimensions();
96-
9795
return RenderContext {
9896
name,
9997
instance,
@@ -305,10 +303,14 @@ impl RenderContext {
305303
}
306304
}
307305

306+
/// Get the render pass with the resource ID that was provided upon
307+
/// attachment.
308308
pub fn get_render_pass(&self, id: ResourceId) -> &RenderPass {
309309
return &self.render_passes[id];
310310
}
311311

312+
/// Get the render pipeline with the resource ID that was provided upon
313+
/// attachment.
312314
pub fn get_render_pipeline(&mut self, id: ResourceId) -> &RenderPipeline {
313315
return &self.render_pipelines[id];
314316
}

crates/lambda-rs/src/render/pipeline.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
use std::{
2-
borrow::Borrow,
3-
ops::Deref,
4-
rc::Rc,
5-
};
1+
//! Render pipeline builders and definitions for lambda runtimes and
2+
//! applications.
3+
use std::rc::Rc;
64

7-
use lambda_platform::gfx::{
8-
buffer::Buffer as InternalBuffer,
9-
shader::{
10-
ShaderModuleBuilder,
11-
ShaderModuleType,
12-
},
5+
use lambda_platform::gfx::shader::{
6+
ShaderModuleBuilder,
7+
ShaderModuleType,
138
};
149

1510
use super::{
@@ -69,6 +64,7 @@ pub struct RenderPipelineBuilder {
6964
}
7065

7166
impl RenderPipelineBuilder {
67+
/// Creates a new render pipeline builder.
7268
pub fn new() -> Self {
7369
return Self {
7470
push_constants: Vec::new(),
@@ -88,6 +84,8 @@ impl RenderPipelineBuilder {
8884
return self;
8985
}
9086

87+
/// Adds a push constant to the render pipeline at the given stage
88+
/// with the given size in bytes.
9189
pub fn with_push_constant(
9290
mut self,
9391
stage: PipelineStage,

crates/lambda-rs/src/render/render_pass.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Render pass builders and definitions for lambda runtimes and applications.
12
use std::rc::Rc;
23

34
use lambda_platform::gfx::render_pass;
@@ -38,6 +39,7 @@ impl RenderPass {
3839
pub struct RenderPassBuilder {}
3940

4041
impl RenderPassBuilder {
42+
/// Creates a new render pass builder.
4143
pub fn new() -> Self {
4244
return Self {};
4345
}

crates/lambda-rs/src/render/shader.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! A module for compiling shaders into SPIR-V binary.
2+
13
// Expose some lower level shader
24
pub use lambda_platform::shaderc::{
35
ShaderCompiler,
@@ -6,18 +8,6 @@ pub use lambda_platform::shaderc::{
68
VirtualShader,
79
};
810

9-
#[macro_export]
10-
macro_rules! vertex_shader {
11-
($source:ident) => {
12-
VirtualShader::Source {
13-
source: String::from($stringify!($source)),
14-
kind: ShaderKind::Vertex,
15-
name: String::from("vertex-shader"),
16-
entry_point: String::from("main"),
17-
}
18-
};
19-
}
20-
2111
pub struct ShaderBuilder {
2212
compiler: ShaderCompiler,
2313
}
@@ -41,12 +31,16 @@ impl ShaderBuilder {
4131
}
4232
}
4333

34+
/// A shader that has been compiled into SPIR-V binary. Contains the binary
35+
/// representation of the shader as well as the virtual shader that was used
36+
/// to compile it.
4437
pub struct Shader {
4538
binary: Vec<u32>,
4639
virtual_shader: VirtualShader,
4740
}
4841

4942
impl Shader {
43+
/// Returns a copy of the SPIR-V binary representation of the shader.
5044
pub fn as_binary(&self) -> Vec<u32> {
5145
return self.binary.clone();
5246
}

crates/lambda-rs/src/render/vertex.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
//! Vertex data structures.
2+
13
pub use lambda_platform::gfx::assembler::{
24
VertexAttribute,
35
VertexElement,
46
};
57

8+
/// Vertex data structure with position, normal, and color.
69
#[repr(C)]
710
#[derive(Clone, Copy, Debug)]
811
pub struct Vertex {
@@ -20,6 +23,7 @@ pub struct VertexBuilder {
2023
}
2124

2225
impl VertexBuilder {
26+
/// Creates a new vertex builder.
2327
pub fn new() -> Self {
2428
return Self {
2529
position: [0.0, 0.0, 0.0],
@@ -40,11 +44,13 @@ impl VertexBuilder {
4044
return self;
4145
}
4246

47+
/// Set the color of the vertex.
4348
pub fn with_color(&mut self, color: [f32; 3]) -> &mut Self {
4449
self.color = color;
4550
return self;
4651
}
4752

53+
/// Build the vertex.
4854
pub fn build(&self) -> Vertex {
4955
return Vertex {
5056
position: self.position,

0 commit comments

Comments
 (0)