Skip to content

Commit

Permalink
Rename silly variable names, remove unneeded ones
Browse files Browse the repository at this point in the history
  • Loading branch information
hakolao committed Sep 27, 2023
1 parent 4984bc9 commit a076e36
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
1 change: 0 additions & 1 deletion examples/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ impl GlassApp for LineApp {
for line in lines {
line_pipeline.draw(
&mut rpass,
[0.0; 4],
camera_projection([WIDTH as f32, HEIGHT as f32]).to_cols_array_2d(),
line,
);
Expand Down
8 changes: 3 additions & 5 deletions src/pipelines/line/line.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
struct PushConstants {
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
start: vec4<f32>,
end: vec4<f32>,
Expand All @@ -23,13 +22,12 @@ fn vs_main(
model: VertexInput,
) -> VertexOutput {
var out: VertexOutput;
var pos = vec4<f32>(0.0);
var world_position = vec4<f32>(0.0);
if (model.index == u32(0)) {
pos = pc.start;
world_position = pc.start;
} else {
pos = pc.end;
world_position = pc.end;
}
let world_position = pos + pc.view_pos;
out.clip_position = pc.view_proj * world_position;
out.color = pc.color;
return out;
Expand Down
14 changes: 3 additions & 11 deletions src/pipelines/line/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,13 @@ impl LinePipeline {
pipeline
}

pub fn draw<'r>(
&'r self,
rpass: &mut RenderPass<'r>,
view_pos: [f32; 4],
view_proj: [[f32; 4]; 4],
line: Line,
) {
pub fn draw<'r>(&'r self, rpass: &mut RenderPass<'r>, view_proj: [[f32; 4]; 4], line: Line) {
rpass.set_pipeline(&self.pipeline);
rpass.set_vertex_buffer(0, self.vertices.slice(..));
rpass.set_push_constants(
ShaderStages::VERTEX_FRAGMENT,
0,
bytemuck::cast_slice(&[LinePushConstants::new(view_pos, view_proj, line)]),
bytemuck::cast_slice(&[LinePushConstants::new(view_proj, line)]),
);
rpass.draw(0..2, 0..1);
}
Expand All @@ -97,17 +91,15 @@ impl LinePipeline {
#[repr(C)]
#[derive(Copy, Clone, Pod, Zeroable)]
pub struct LinePushConstants {
pub view_position: [f32; 4],
pub view_proj: [[f32; 4]; 4],
pub start: [f32; 4],
pub end: [f32; 4],
pub color: [f32; 4],
}

impl LinePushConstants {
pub fn new(view_pos: [f32; 4], view_proj: [[f32; 4]; 4], line: Line) -> LinePushConstants {
pub fn new(view_proj: [[f32; 4]; 4], line: Line) -> LinePushConstants {
LinePushConstants {
view_position: view_pos,
view_proj,
start: line.start.extend(1.0).to_array(),
end: line.end.extend(1.0).to_array(),
Expand Down
10 changes: 5 additions & 5 deletions src/pipelines/quad/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ impl QuadPipeline {
}

pub fn push_constants(
view_position: [f32; 4],
quad_pos: [f32; 4],
view_proj: [[f32; 4]; 4],
quad_size: [f32; 2],
aa_strength: f32,
) -> QuadPushConstants {
QuadPushConstants {
view_position,
quad_pos,
view_proj,
dims: quad_size,
aa_strength,
Expand Down Expand Up @@ -150,7 +150,7 @@ impl QuadPipeline {
&'r self,
rpass: &mut RenderPass<'r>,
bind_group: &'r BindGroup,
view_pos: [f32; 4],
quad_pos: [f32; 4],
view_proj: [[f32; 4]; 4],
quad_size: [f32; 2],
aa_strength: f32,
Expand All @@ -163,7 +163,7 @@ impl QuadPipeline {
ShaderStages::VERTEX_FRAGMENT,
0,
bytemuck::cast_slice(&[QuadPipeline::push_constants(
view_pos,
quad_pos,
view_proj,
quad_size,
aa_strength,
Expand All @@ -177,7 +177,7 @@ impl QuadPipeline {
#[repr(C)]
#[derive(Copy, Clone, Pod, Zeroable)]
pub struct QuadPushConstants {
pub view_position: [f32; 4],
pub quad_pos: [f32; 4],
pub view_proj: [[f32; 4]; 4],
pub dims: [f32; 2],
pub aa_strength: f32,
Expand Down
4 changes: 2 additions & 2 deletions src/pipelines/quad/quad.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct PushConstants {
view_pos: vec4<f32>,
quad_pos: vec4<f32>,
view_proj: mat4x4<f32>,
dims: vec2<f32>,
aa_strength: f32,
Expand Down Expand Up @@ -28,7 +28,7 @@ fn vs_main(
// Scale vertices
model.position +
// Offset by pos
pc.view_pos;
pc.quad_pos;
out.clip_position = pc.view_proj * world_position;
out.color = model.color;
return out;
Expand Down

0 comments on commit a076e36

Please sign in to comment.