Skip to content

Commit 0e5dd6d

Browse files
authored
Merge pull request #42 from lambda-sh/vmarcella/math-library
Improvements to rendering & event processing
2 parents 8f524f4 + 1079b57 commit 0e5dd6d

34 files changed

Lines changed: 2213 additions & 192 deletions

Cargo.lock

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/lambda-platform/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ gfx-hal = "=0.9.0"
1212
winit = "=0.27.5"
1313
shaderc = "=0.7"
1414
cfg-if = "=1.0.0"
15+
rand = "=0.8.5"
1516

1617
# GFX-RS backends
1718
gfx-backend-gl = { version="=0.9.0", optional = true }
@@ -33,6 +34,10 @@ gfx-with-metal=["dep:gfx-backend-metal"]
3334
gfx-with-dx11=["dep:gfx-backend-dx11"]
3435
gfx-with-dx12=["dep:gfx-backend-dx12"]
3536

37+
[profile.dev]
38+
crate-type = ["cdylib", "rlib"]
39+
incremental = true
40+
3641
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies.gfx-platform-backend]
3742
package = "gfx-backend-gl"
3843
version = "=0.9.0"

crates/lambda-platform/src/gfx/api.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ cfg_if::cfg_if! {
1414
pub use gfx_backend_dx12 as RenderingAPI;
1515
} else if #[cfg(feature = "detect-platform")] {
1616
pub use gfx_platform_backend as RenderingAPI;
17-
} else {
18-
}
17+
} else {}
1918
}

crates/lambda-platform/src/gfx/assembler.rs

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,81 @@
11
//! Primitive assembly for the graphics pipeline.
22
3-
use gfx_hal::pso;
3+
pub use gfx_hal::pso::Element as VertexElement;
4+
use gfx_hal::pso::{
5+
self,
6+
AttributeDesc,
7+
VertexBufferDesc,
8+
};
9+
10+
use super::{
11+
buffer::Buffer,
12+
surface::ColorFormat,
13+
};
14+
15+
/// Attributes for a vertex.
16+
#[derive(Debug, Clone)]
17+
pub struct VertexAttribute {
18+
pub location: u32,
19+
pub offset: u32,
20+
pub element: VertexElement<ColorFormat>,
21+
}
422

523
/// PrimitiveAssemblerBuilder for preparing PrimitiveAssemblers to use in the
624
/// lambda-platform Rendering pipeline.
7-
pub struct PrimitiveAssemblerBuilder {}
25+
pub struct PrimitiveAssemblerBuilder {
26+
buffer_descriptions: Vec<VertexBufferDesc>,
27+
attribute_descriptions: Vec<AttributeDesc>,
28+
}
829

930
impl PrimitiveAssemblerBuilder {
1031
pub fn new() -> Self {
11-
return Self {};
32+
return Self {
33+
buffer_descriptions: Vec::new(),
34+
attribute_descriptions: Vec::new(),
35+
};
1236
}
1337

1438
/// Build a primitive assembler given the lambda-platform vertex shader
15-
/// module.
39+
/// module. Buffers & attributes do not have to be tied to
1640
pub fn build<'shader, RenderBackend: gfx_hal::Backend>(
17-
self,
41+
&'shader mut self,
1842
vertex_shader: &'shader super::shader::ShaderModule<RenderBackend>,
43+
buffers: Option<&Vec<&Buffer<RenderBackend>>>,
44+
attributes: Option<&[VertexAttribute]>,
1945
) -> PrimitiveAssembler<'shader, RenderBackend> {
46+
let binding = self.buffer_descriptions.len() as u32;
47+
48+
match (buffers, attributes) {
49+
(Some(buffers), Some(attributes)) => {
50+
println!(
51+
"[DEBUG] Building primitive assembler with buffers and attributes"
52+
);
53+
self.buffer_descriptions = buffers
54+
.iter()
55+
.map(|buffer| VertexBufferDesc {
56+
binding,
57+
stride: buffer.stride() as u32,
58+
rate: pso::VertexInputRate::Vertex,
59+
})
60+
.collect();
61+
62+
self.attribute_descriptions = attributes
63+
.iter()
64+
.map(|attribute| {
65+
return AttributeDesc {
66+
location: attribute.location,
67+
binding,
68+
element: attribute.element,
69+
};
70+
})
71+
.collect();
72+
}
73+
_ => {}
74+
}
75+
2076
let primitive_assembler = pso::PrimitiveAssemblerDesc::Vertex {
21-
buffers: &[],
22-
attributes: &[],
77+
buffers: self.buffer_descriptions.as_slice(),
78+
attributes: self.attribute_descriptions.as_slice(),
2379
input_assembler: pso::InputAssemblerDesc::new(
2480
pso::Primitive::TriangleList,
2581
),
@@ -52,7 +108,7 @@ impl<'shader, RenderBackend: gfx_hal::Backend>
52108

53109
/// Internal functions for the primitive assembler. User applications most
54110
/// likely should not use these functions directly nor should they need to.
55-
pub mod internal {
111+
pub(crate) mod internal {
56112
#[inline]
57113
pub fn into_primitive_assembler<'shader, RenderBackend: gfx_hal::Backend>(
58114
primitive_assembler: super::PrimitiveAssembler<'shader, RenderBackend>,

0 commit comments

Comments
 (0)