Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![],
index_buffer,
};

let shader = ctx
Expand Down
3 changes: 1 addition & 2 deletions examples/instancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![geometry_vertex_buffer, positions_vertex_buffer],
index_buffer: index_buffer,
images: vec![],
index_buffer,
};

let shader = ctx
Expand Down
11 changes: 6 additions & 5 deletions examples/msaa_render_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct Stage {
offscreen_pipeline: Pipeline,
offscreen_bind: Bindings,
offscreen_pass: RenderPass,
color_resolve_img: TextureId,
rx: f32,
ry: f32,
ctx: Box<dyn RenderingBackend>,
Expand Down Expand Up @@ -104,9 +105,8 @@ impl Stage {
);

let offscreen_bind = Bindings {
vertex_buffers: vec![vertex_buffer.clone()],
index_buffer: index_buffer.clone(),
images: vec![],
vertex_buffers: vec![vertex_buffer],
index_buffer,
};

let display_bind = {
Expand All @@ -130,8 +130,7 @@ impl Stage {
);
Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![color_resolve_img],
index_buffer,
}
};

Expand Down Expand Up @@ -195,6 +194,7 @@ impl Stage {
offscreen_pipeline,
offscreen_bind,
offscreen_pass,
color_resolve_img,
rx: 0.,
ry: 0.,
ctx,
Expand Down Expand Up @@ -240,6 +240,7 @@ impl EventHandler for Stage {
.begin_default_pass(PassAction::clear_color(0.0, 0., 0.45, 1.));
self.ctx.apply_pipeline(&self.display_pipeline);
self.ctx.apply_bindings(&self.display_bind);
self.ctx.apply_image(&self.color_resolve_img);
self.ctx.apply_uniforms(UniformsSource::table(&vs_params));
self.ctx.draw(0, 6, 1);
self.ctx.end_render_pass();
Expand Down
11 changes: 6 additions & 5 deletions examples/offscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct Stage {
offscreen_pipeline: Pipeline,
offscreen_bind: Bindings,
offscreen_pass: RenderPass,
color_img: TextureId,
rx: f32,
ry: f32,
ctx: Box<dyn RenderingBackend>,
Expand Down Expand Up @@ -89,15 +90,13 @@ impl Stage {
);

let offscreen_bind = Bindings {
vertex_buffers: vec![vertex_buffer.clone()],
index_buffer: index_buffer.clone(),
images: vec![],
vertex_buffers: vec![vertex_buffer],
index_buffer,
};

let display_bind = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![color_img],
index_buffer,
};

let source = match ctx.info().backend {
Expand Down Expand Up @@ -160,6 +159,7 @@ impl Stage {
offscreen_pipeline,
offscreen_bind,
offscreen_pass,
color_img,
rx: 0.,
ry: 0.,
ctx,
Expand Down Expand Up @@ -205,6 +205,7 @@ impl EventHandler for Stage {
.begin_default_pass(PassAction::clear_color(0.0, 0., 0.45, 1.));
self.ctx.apply_pipeline(&self.display_pipeline);
self.ctx.apply_bindings(&self.display_bind);
self.ctx.apply_image(&self.color_img);
self.ctx.apply_uniforms(UniformsSource::table(&vs_params));
self.ctx.draw(0, 36, 1);
self.ctx.end_render_pass();
Expand Down
13 changes: 7 additions & 6 deletions examples/post_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct Stage {
offscreen_pipeline: Pipeline,
offscreen_bind: Bindings,
offscreen_pass: RenderPass,
color_img: TextureId,
rx: f32,
ry: f32,

Expand Down Expand Up @@ -90,9 +91,8 @@ impl Stage {
);

let offscreen_bind = Bindings {
vertex_buffers: vec![vertex_buffer.clone()],
index_buffer: index_buffer.clone(),
images: vec![],
vertex_buffers: vec![vertex_buffer],
index_buffer,
};

#[rustfmt::skip]
Expand Down Expand Up @@ -120,8 +120,7 @@ impl Stage {

let post_processing_bind = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![color_img],
index_buffer,
};

let default_shader = ctx
Expand Down Expand Up @@ -180,6 +179,7 @@ impl Stage {
offscreen_pipeline,
offscreen_bind,
offscreen_pass,
color_img,
rx: 0.,
ry: 0.,
ctx,
Expand Down Expand Up @@ -208,7 +208,7 @@ impl EventHandler for Stage {

self.ctx.delete_render_pass(self.offscreen_pass);
self.offscreen_pass = offscreen_pass;
self.post_processing_bind.images[0] = color_img;
self.color_img = color_img;
}

fn draw(&mut self) {
Expand Down Expand Up @@ -247,6 +247,7 @@ impl EventHandler for Stage {
self.ctx.begin_default_pass(PassAction::Nothing);
self.ctx.apply_pipeline(&self.post_processing_pipeline);
self.ctx.apply_bindings(&self.post_processing_bind);
self.ctx.apply_image(&self.color_img);
self.ctx
.apply_uniforms(UniformsSource::table(&post_processing_shader::Uniforms {
resolution: glam::vec2(w, h),
Expand Down
6 changes: 4 additions & 2 deletions examples/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Stage {

pipeline: Pipeline,
bindings: Bindings,
texture: TextureId,
}

impl Stage {
Expand Down Expand Up @@ -53,8 +54,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![texture],
index_buffer,
};

let shader = ctx
Expand Down Expand Up @@ -85,6 +85,7 @@ impl Stage {
Stage {
pipeline,
bindings,
texture,
ctx,
}
}
Expand All @@ -100,6 +101,7 @@ impl EventHandler for Stage {

self.ctx.apply_pipeline(&self.pipeline);
self.ctx.apply_bindings(&self.bindings);
self.ctx.apply_image(&self.texture);
for i in 0..10 {
let t = t + i as f64 * 0.3;

Expand Down
3 changes: 1 addition & 2 deletions examples/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![],
index_buffer,
};

let shader = ctx
Expand Down
3 changes: 1 addition & 2 deletions examples/triangle_color4b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![],
index_buffer,
};

let shader = ctx
Expand Down
25 changes: 9 additions & 16 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ impl Default for PipelineParams {
}
}

/// Geometry bindings
/// Geometry buffers bindings
#[derive(Clone, Debug)]
pub struct Bindings {
/// Vertex buffers. Data contained in the buffer must match layout
Expand All @@ -781,9 +781,6 @@ pub struct Bindings {
/// from a vertex buffer, with each subsequent 3 indices forming a
/// triangle.
pub index_buffer: BufferId,
/// Textures to be used with when drawing the geometry in the fragment
/// shader.
pub images: Vec<TextureId>,
}

#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down Expand Up @@ -1322,19 +1319,15 @@ pub trait RenderingBackend {
/// Should be applied after begin_pass.
fn apply_scissor_rect(&mut self, x: i32, y: i32, w: i32, h: i32);

fn apply_bindings_from_slice(
&mut self,
vertex_buffers: &[BufferId],
index_buffer: BufferId,
textures: &[TextureId],
);

fn apply_bindings_from_slice(&mut self, vertex_buffers: &[BufferId], index_buffer: BufferId);
fn apply_bindings(&mut self, bindings: &Bindings) {
self.apply_bindings_from_slice(
&bindings.vertex_buffers,
bindings.index_buffer,
&bindings.images,
);
self.apply_bindings_from_slice(&bindings.vertex_buffers, bindings.index_buffer);
}

fn apply_images(&mut self, images: &[TextureId]);
/// Same as [RenderingBackend::apply_images], but applies only one image
fn apply_image(&mut self, image: &TextureId) {
self.apply_images(std::slice::from_ref(image));
}

fn apply_uniforms(&mut self, uniforms: UniformsSource) {
Expand Down
51 changes: 24 additions & 27 deletions src/graphics/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,33 +1435,7 @@ impl RenderingBackend for GlContext {
}
}

fn apply_bindings_from_slice(
&mut self,
vertex_buffers: &[BufferId],
index_buffer: BufferId,
textures: &[TextureId],
) {
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
let shader = &self.shaders[pip.shader.0];

for (n, shader_image) in shader.images.iter().enumerate() {
let bindings_image = textures
.get(n)
.unwrap_or_else(|| panic!("Image count in bindings and shader did not match!"));
if let Some(gl_loc) = shader_image.gl_loc {
let texture = self.textures.get(*bindings_image);
let raw = match texture.raw {
TextureOrRenderbuffer::Texture(id) => id,
TextureOrRenderbuffer::Renderbuffer(id) => id,
};
unsafe {
self.cache
.bind_texture(n, texture.params.kind.into(), raw);
glUniform1i(gl_loc, n as i32);
}
}
}

fn apply_bindings_from_slice(&mut self, vertex_buffers: &[BufferId], index_buffer: BufferId) {
self.cache.bind_buffer(
GL_ELEMENT_ARRAY_BUFFER,
self.buffers[index_buffer.0].gl_buf,
Expand Down Expand Up @@ -1535,6 +1509,29 @@ impl RenderingBackend for GlContext {
}
}

fn apply_images(&mut self, images: &[TextureId]) {
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
let shader = &self.shaders[pip.shader.0];

for (n, shader_image) in shader.images.iter().enumerate() {
let Some(bindings_image) = images.get(n) else {
panic!("Image count in bindings and shader did not match!");
};

if let Some(gl_loc) = shader_image.gl_loc {
let texture = self.textures.get(*bindings_image);
let raw = match texture.raw {
TextureOrRenderbuffer::Texture(id) => id,
TextureOrRenderbuffer::Renderbuffer(id) => id,
};
unsafe {
self.cache.bind_texture(n, texture.params.kind.into(), raw);
glUniform1i(gl_loc, n as i32);
}
}
}
}

fn apply_uniforms_from_bytes(&mut self, uniform_ptr: *const u8, size: usize) {
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
let shader = &self.shaders[pip.shader.0];
Expand Down
18 changes: 10 additions & 8 deletions src/graphics/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,16 @@
unsafe {
let view = crate::window::apple_view();
assert!(!view.is_null());
let device: ObjcId = msg_send![view, device];

Check warning on line 289 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 289 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 289 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`
assert!(!device.is_null());
let command_queue: ObjcId = msg_send![device, newCommandQueue];

Check warning on line 291 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 291 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 291 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`

if false {
let capture_manager = msg_send_![class![MTLCaptureManager], sharedCaptureManager];

Check warning on line 294 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 294 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 294 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 294 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 294 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 294 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`
assert!(!capture_manager.is_null());

let MTLCaptureDestinationGPUTraceDocument = 2u64;
if !msg_send![

Check warning on line 298 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 298 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 298 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`
capture_manager,
supportsDestination: MTLCaptureDestinationGPUTraceDocument
] {
Expand All @@ -314,9 +314,9 @@
}

let capture_descriptor =
msg_send_![msg_send_![class![MTLCaptureDescriptor], alloc], init];

Check warning on line 317 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 317 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 317 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 317 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 317 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 317 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 317 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 317 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 317 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`
msg_send_![capture_descriptor, setCaptureObject: device];

Check warning on line 318 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 318 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 318 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`
msg_send_![

Check warning on line 319 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 319 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

unexpected `cfg` condition value: `cargo-clippy`

Check warning on line 319 in src/graphics/metal.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition value: `cargo-clippy`
capture_descriptor,
setDestination: MTLCaptureDestinationGPUTraceDocument
];
Expand Down Expand Up @@ -1057,12 +1057,7 @@
}
}

fn apply_bindings_from_slice(
&mut self,
vertex_buffers: &[BufferId],
index_buffer: BufferId,
textures: &[TextureId],
) {
fn apply_bindings_from_slice(&mut self, vertex_buffers: &[BufferId], index_buffer: BufferId) {
assert!(
self.render_encoder.is_some(),
"apply_bindings before begin_pass"
Expand All @@ -1078,13 +1073,20 @@
atIndex:(index + 1) as u64];
buffer.next_value = buffer.value + 1;
}

let index_buffer = &mut self.buffers[index_buffer.0];
self.index_buffer = Some(index_buffer.raw[index_buffer.value]);
index_buffer.next_value = index_buffer.value + 1;
}
}

fn apply_images(&mut self, images: &[TextureId]) {
unsafe {
let render_encoder = self.render_encoder.unwrap();

let img_count = textures.len();
let img_count = images.len();
if img_count > 0 {
for (n, img) in textures.iter().enumerate() {
for (n, img) in images.iter().enumerate() {
let Texture {
sampler, texture, ..
} = self.textures.get(*img);
Expand Down
Loading