Skip to content

Commit

Permalink
Fixed primitive types on Metal
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniPlays committed Jul 11, 2022
1 parent 921d60b commit 1091a5c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
Binary file modified .DS_Store
Binary file not shown.
17 changes: 13 additions & 4 deletions Hazard-Renderer/src/Backend/Metal/MetalPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@

namespace HazardRenderer::Metal
{
static MTL::PrimitiveType DrawTypeToMTLPrimitive(const DrawType& type) {

switch(type) {
case DrawType::Fill: return MTL::PrimitiveTypeTriangle;
case DrawType::Line: return MTL::PrimitiveTypeLine;
case DrawType::Point: return MTL::PrimitiveTypePoint;
}
return MTL::PrimitiveTypeTriangle;
}

MetalPipeline::MetalPipeline(PipelineSpecification* specs)
{
m_Specs = *specs;
std::string file = File::ReadFile("res/" + specs->ShaderPath);



NS::Error* error = nullptr;

Expand Down Expand Up @@ -62,7 +71,7 @@ namespace HazardRenderer::Metal
{
auto cmdBuffer = commandBuffer.As<MetalRenderCommandBuffer>();
MTL::RenderCommandEncoder* encoder = cmdBuffer->GetEncoder();
encoder->drawIndexedPrimitives(MTL::PrimitiveTypeTriangle, count, MTL::IndexTypeUInt32, cmdBuffer->GetBoundIndexBuffer(), 0, 1);
encoder->drawIndexedPrimitives(DrawTypeToMTLPrimitive(m_Specs.DrawType), count, MTL::IndexTypeUInt32, cmdBuffer->GetBoundIndexBuffer(), 0, 1);
}
void MetalPipeline::DrawArrays(Ref<RenderCommandBuffer> commandBuffer, uint32_t count)
{
Expand All @@ -73,7 +82,7 @@ namespace HazardRenderer::Metal

auto cmdBuffer = commandBuffer.As<MetalRenderCommandBuffer>();
MTL::RenderCommandEncoder* encoder = cmdBuffer->GetEncoder();
encoder->drawIndexedPrimitives(MTL::PrimitiveTypeTriangle, count, MTL::IndexTypeUInt32, cmdBuffer->GetBoundIndexBuffer(), 0, instanceCount);
encoder->drawIndexedPrimitives(DrawTypeToMTLPrimitive(m_Specs.DrawType), count, MTL::IndexTypeUInt32, cmdBuffer->GetBoundIndexBuffer(), 0, instanceCount);
}
}
#endif
1 change: 0 additions & 1 deletion Hazard-Renderer/src/Backend/Metal/MetalPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace HazardRenderer::Metal
private:
PipelineSpecification m_Specs;
Ref<Shader> m_Shader;
uint32_t m_DrawType, m_PolygonMode;

MTL::RenderPipelineState* m_Pipeline = nullptr;
};
Expand Down
Binary file modified HazardLauncher/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions HazardLauncher/res/QuadInstanced.metal
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct Camera

struct VertexOut {
float4 position [[position]];
float PointSize [[point_size]];
float4 color;
};

Expand All @@ -43,6 +44,8 @@ vertex VertexOut Vertex (
VertexOut out;
out.position = u_Camera.ViewProjection * transform * float4(input.a_Position, 1.0);
out.color = data.a_Color;

out.PointSize = 10.0;

return out;
}
Expand Down
2 changes: 1 addition & 1 deletion HazardLauncher/src/tests/Rendering/InstancingTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace InstancingTest {
spec.ShaderPath = "QuadInstanced.metal";
#endif

spec.DrawType = DrawType::Fill;
spec.DrawType = DrawType::Point;
spec.CullMode = CullMode::None;
spec.Usage = PipelineUsage::GraphicsBit;
spec.pTargetRenderPass = window->GetSwapchain()->GetRenderPass().Raw();
Expand Down

0 comments on commit 1091a5c

Please sign in to comment.