Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PrimitiveType::TriangleStrip #485

Closed
wants to merge 2 commits into from
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
6 changes: 4 additions & 2 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -662,6 +662,7 @@ impl Default for Equation {

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum PrimitiveType {
TriangleStrip,
Triangles,
Lines,
Points,
Expand All @@ -670,6 +671,7 @@ pub enum PrimitiveType {
impl From<PrimitiveType> 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,
Expand Down Expand Up @@ -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],
Expand Down
9 changes: 6 additions & 3 deletions src/graphics/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl From<VertexStep> for MTLVertexStepFunction {
impl From<PrimitiveType> 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,
Expand Down Expand Up @@ -232,7 +233,7 @@ struct PipelineInternal {
//layout: Vec<BufferLayout>,
//attributes: Vec<VertexAttributeInternal>,
_shader: ShaderId,
//params: PipelineParams,
params: PipelineParams,
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -1017,7 +1018,7 @@ impl RenderingBackend for MetalContext {
//layout: buffer_layout.to_vec(),
//attributes: vertex_layout,
_shader: shader,
//params,
params,
};

self.pipelines.push(pipeline);
Expand Down Expand Up @@ -1231,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
Expand Down
Loading