Skip to content

Commit

Permalink
rename clear_screen to clear
Browse files Browse the repository at this point in the history
  • Loading branch information
boralg committed Aug 3, 2024
1 parent ef90694 commit ab2daaf
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
4 changes: 2 additions & 2 deletions examples/src/cube_camera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sursface::cgmath::{perspective, Deg, Matrix4, Point3, SquareMatrix, Vector3}
use sursface::display::Display;
use sursface::std::models::{cube, quad_uvs, VertexPositionNormalUv};
use sursface::std::{
clear_screen, create_render_pipeline, create_sampler_entry, create_shader, create_texture,
clear, create_render_pipeline, create_sampler_entry, create_shader, create_texture,
create_texture_layout_entry_from_image, create_uniforms, get_framebuffer,
};
use sursface::time::now_secs;
Expand Down Expand Up @@ -168,7 +168,7 @@ impl AppState for CubeState {

let (output, view) = get_framebuffer(&display.surface);
{
let mut rpass = clear_screen(&view, &mut encoder, clear_color);
let mut rpass = clear(&view, &mut encoder, clear_color);

let now = now_secs();
let elapsed = now - self.start_time;
Expand Down
4 changes: 2 additions & 2 deletions examples/src/hello_triangle/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sursface::app::AppState;
use sursface::display::Display;
use sursface::std::{clear_screen, create_render_pipeline, create_shader, get_framebuffer};
use sursface::std::{clear, create_render_pipeline, create_shader, get_framebuffer};
use sursface::wgpu::{self, Color, RenderPipeline};

fn main() {
Expand Down Expand Up @@ -52,7 +52,7 @@ impl AppState for TriangleState {

let (output, view) = get_framebuffer(&display.surface);
{
let mut rpass = clear_screen(&view, &mut encoder, clear_color);
let mut rpass = clear(&view, &mut encoder, clear_color);

rpass.set_pipeline(&self.render_pipeline);
rpass.draw(0..3, 0..1);
Expand Down
4 changes: 2 additions & 2 deletions examples/src/hello_window/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl AppState for EmptyState {
.texture
.create_view(&wgpu::TextureViewDescriptor::default());

clear_screen(
clear(
display,
&view,
wgpu::Color {
Expand All @@ -44,7 +44,7 @@ impl AppState for EmptyState {
}
}

fn clear_screen<'a>(display: &mut Display, view: &TextureView, color: sursface::wgpu::Color) {
fn clear<'a>(display: &mut Display, view: &TextureView, color: sursface::wgpu::Color) {
let mut encoder = display
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
Expand Down
4 changes: 2 additions & 2 deletions examples/src/mandelbrot/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sursface::cgmath::{Vector2, Zero};
use sursface::display::Display;
use sursface::std::models::{quad_no_normal, quad_uvs, VertexPositionUv};
use sursface::std::{
clear_screen, create_render_pipeline, create_shader, create_uniforms, get_framebuffer,
clear, create_render_pipeline, create_shader, create_uniforms, get_framebuffer,
};
use sursface::time::now_secs;
use sursface::wgpu::util::DeviceExt;
Expand Down Expand Up @@ -245,7 +245,7 @@ impl AppState for MandelbrotState {
let (output, view) = get_framebuffer(&display.surface);

{
let mut rpass = clear_screen(&view, &mut encoder, clear_color);
let mut rpass = clear(&view, &mut encoder, clear_color);

self.uniforms.cursor_pos = [
self.cursor_location.x / display.config.width as f32,
Expand Down
44 changes: 41 additions & 3 deletions sursface/src/std/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ pub fn get_framebuffer(surface: &Surface) -> (SurfaceTexture, TextureView) {
(output, view)
}

pub fn clear_screen<'a>(
framebuffer_view: &'a TextureView,
pub fn clear<'a>(
view: &'a TextureView,
encoder: &'a mut CommandEncoder,
color: Color,
) -> RenderPass<'a> {
let rpass_descriptor = wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: framebuffer_view,
view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(color),
Expand Down Expand Up @@ -148,6 +148,44 @@ pub fn create_texture_layout_entry_from_image(
(entry, texture_view)
}

pub fn create_render_texture(
device: &Device,
width: u32,
height: u32,
format: wgpu::TextureFormat,
binding_index: u32,
) -> (BindGroupLayoutEntry, TextureView) {
let texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("Render Texture"),
size: wgpu::Extent3d {
width,
height,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[],
});

let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default());

let layout_entry = wgpu::BindGroupLayoutEntry {
binding: binding_index,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Float { filterable: true },
view_dimension: wgpu::TextureViewDimension::D2,
multisampled: false,
},
count: None,
};

(layout_entry, texture_view)
}

pub fn create_sampler_entry(
device: &Device,
binding_index: u32,
Expand Down

0 comments on commit ab2daaf

Please sign in to comment.