Skip to content

Commit c015425

Browse files
committed
[fix] formatting for 3D demo.
1 parent 2aa4982 commit c015425

1 file changed

Lines changed: 33 additions & 8 deletions

File tree

lambda/examples/push_constants.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use lambda::{
44
render::{
55
buffer::BufferBuilder,
66
command::RenderCommand,
7-
mesh::MeshBuilder,
7+
mesh::{
8+
Mesh,
9+
MeshBuilder,
10+
},
811
pipeline::RenderPipelineBuilder,
912
render_pass::RenderPassBuilder,
1013
shader::{
@@ -39,6 +42,8 @@ use lambda_platform::{
3942
},
4043
};
4144

45+
// ------------------------------ SHADER SOURCE --------------------------------
46+
4247
const VERTEX_SHADER_SOURCE: &str = r#"
4348
#version 450
4449
@@ -60,20 +65,28 @@ void main() {
6065
6166
"#;
6267

68+
const FRAGMENT_SHADER_SOURCE: &str = r#"
69+
#version 450
70+
71+
layout (location = 0) in vec3 frag_color;
72+
73+
layout (location = 0) out vec4 fragment_color;
74+
75+
void main() {
76+
fragment_color = vec4(frag_color, 1.0);
77+
}
78+
79+
"#;
80+
81+
// ------------------------------ PUSH CONSTANTS -------------------------------
82+
6383
#[repr(C)]
6484
#[derive(Debug, Clone, Copy)]
6585
pub struct PushConstant {
6686
data: [f32; 4],
6787
render_matrix: [[f32; 4]; 4],
6888
}
6989

70-
pub struct PushConstantsExample {
71-
frame_number: u64,
72-
shader: Shader,
73-
render_pipeline: Option<ResourceId>,
74-
render_pass: Option<ResourceId>,
75-
}
76-
7790
pub fn push_constants_to_bytes(push_constants: &PushConstant) -> &[u32] {
7891
let bytes = unsafe {
7992
let size_in_bytes = std::mem::size_of::<PushConstant>();
@@ -85,6 +98,16 @@ pub fn push_constants_to_bytes(push_constants: &PushConstant) -> &[u32] {
8598
return bytes;
8699
}
87100

101+
// --------------------------------- COMPONENT ---------------------------------
102+
103+
pub struct PushConstantsExample {
104+
frame_number: u64,
105+
shader: Shader,
106+
mesh: Option<Mesh>,
107+
render_pipeline: Option<ResourceId>,
108+
render_pass: Option<ResourceId>,
109+
}
110+
88111
impl Component for PushConstantsExample {
89112
fn on_attach(
90113
&mut self,
@@ -149,6 +172,7 @@ impl Component for PushConstantsExample {
149172

150173
self.render_pass = Some(render_context.attach_render_pass(render_pass));
151174
self.render_pipeline = Some(render_context.attach_pipeline(pipeline));
175+
self.mesh = Some(mesh);
152176
}
153177

154178
fn on_detach(
@@ -246,6 +270,7 @@ impl Default for PushConstantsExample {
246270
return Self {
247271
frame_number: 0,
248272
shader,
273+
mesh: None,
249274
render_pipeline: None,
250275
render_pass: None,
251276
};

0 commit comments

Comments
 (0)