From d26525421167487f424f568c9090b7a54e3481f4 Mon Sep 17 00:00:00 2001 From: Birh Burh Date: Wed, 18 Sep 2024 21:45:09 +0200 Subject: [PATCH 1/2] Added PrimitiveType::TriangleStrip --- src/graphics.rs | 6 ++++-- src/graphics/metal.rs | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/graphics.rs b/src/graphics.rs index 28f9e304..6144c1cd 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -392,7 +392,7 @@ pub struct TextureParams { /// On OpenGL, for a `sample_count > 1` render texture, render buffer object will /// be created instead of a regulat texture. /// - /// The only way to use + /// The only way to use pub sample_count: i32, } @@ -662,6 +662,7 @@ impl Default for Equation { #[derive(Debug, PartialEq, Clone, Copy)] pub enum PrimitiveType { + TriangleStrip, Triangles, Lines, Points, @@ -670,6 +671,7 @@ pub enum PrimitiveType { impl From for GLenum { fn from(primitive_type: PrimitiveType) -> Self { match primitive_type { + PrimitiveType::TriangleStrip => GL_TRIANGLE_STRIP, PrimitiveType::Triangles => GL_TRIANGLES, PrimitiveType::Lines => GL_LINES, PrimitiveType::Points => GL_POINTS, @@ -1203,7 +1205,7 @@ pub trait RenderingBackend { /// Same as "new_render_pass", but allows multiple color attachments. /// if `resolve_img` is set, MSAA-resolve operation will happen in `end_render_pass` /// this operation require `color_img` to have sample_count > 1,resolve_img have - /// sample_count == 1, and color_img.len() should be equal to resolve_img.len() + /// sample_count == 1, and color_img.len() should be equal to resolve_img.len() fn new_render_pass_mrt( &mut self, color_img: &[TextureId], diff --git a/src/graphics/metal.rs b/src/graphics/metal.rs index 69741be5..7d2b851b 100644 --- a/src/graphics/metal.rs +++ b/src/graphics/metal.rs @@ -148,6 +148,7 @@ impl From for MTLVertexStepFunction { impl From for MTLPrimitiveType { fn from(primitive_type: PrimitiveType) -> Self { match primitive_type { + PrimitiveType::TriangleStrip => MTLPrimitiveType::TriangleStrip, PrimitiveType::Triangles => MTLPrimitiveType::Triangle, PrimitiveType::Lines => MTLPrimitiveType::Line, PrimitiveType::Points => MTLPrimitiveType::Point, From b84e8824b80a8d6aaae7b2c81a83645e0f71c1f4 Mon Sep 17 00:00:00 2001 From: Birh Burh Date: Thu, 19 Sep 2024 15:26:37 +0200 Subject: [PATCH 2/2] Using primitive_type in metal also now --- src/graphics/metal.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/graphics/metal.rs b/src/graphics/metal.rs index 7d2b851b..f3657b6f 100644 --- a/src/graphics/metal.rs +++ b/src/graphics/metal.rs @@ -233,7 +233,7 @@ struct PipelineInternal { //layout: Vec, //attributes: Vec, _shader: ShaderId, - //params: PipelineParams, + params: PipelineParams, } #[derive(Clone, Copy)] @@ -1018,7 +1018,7 @@ impl RenderingBackend for MetalContext { //layout: buffer_layout.to_vec(), //attributes: vertex_layout, _shader: shader, - //params, + params, }; self.pipelines.push(pipeline); @@ -1232,10 +1232,12 @@ impl RenderingBackend for MetalContext { let render_encoder = self.render_encoder.unwrap(); assert!(self.index_buffer.is_some()); let index_buffer = self.index_buffer.unwrap(); + let pip = &self.pipelines[self.current_pipeline.unwrap().0]; + let primitive_type: MTLPrimitiveType = pip.params.primitive_type.into(); assert!(base_element == 0); // TODO: figure indexBufferOffset/baseVertex unsafe { - msg_send_![render_encoder, drawIndexedPrimitives:MTLPrimitiveType::Triangle + msg_send_![render_encoder, drawIndexedPrimitives:primitive_type indexCount:num_elements as u64 indexType:MTLIndexType::UInt16 indexBuffer:index_buffer