1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-05 10:28:58 +00:00

Reduces vertex size, draws a quad.

This commit is contained in:
Thomas Harte 2020-08-05 21:33:25 -04:00
parent 7551782a25
commit 219923bd63
3 changed files with 21 additions and 19 deletions

View File

@ -1010,7 +1010,7 @@
4B228CD624D773CA0077EF25 /* CSScanTarget.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSScanTarget.h; sourceTree = "<group>"; };
4B228CD724DA12C50077EF25 /* CSScanTargetView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSScanTargetView.h; sourceTree = "<group>"; };
4B228CD824DA12C60077EF25 /* CSScanTargetView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSScanTargetView.m; sourceTree = "<group>"; };
4B228CDA24DA41880077EF25 /* ScanTarget.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; name = ScanTarget.metal; path = "Clock Signal/ScanTarget/ScanTarget.metal"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.metal; };
4B228CDA24DA41880077EF25 /* ScanTarget.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = ScanTarget.metal; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.metal; };
4B24095A1C45DF85004DA684 /* Stepper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Stepper.hpp; sourceTree = "<group>"; };
4B2530F3244E6773007980BF /* fm.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = fm.json; sourceTree = "<group>"; };
4B2A332C1DB86821002876E3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/OricOptions.xib"; sourceTree = SOURCE_ROOT; };
@ -2068,6 +2068,7 @@
4B228CD324D773B30077EF25 /* ScanTarget */ = {
isa = PBXGroup;
children = (
4B228CDA24DA41880077EF25 /* ScanTarget.metal */,
4B228CD424D773B30077EF25 /* CSScanTarget.mm */,
4B228CD624D773CA0077EF25 /* CSScanTarget.h */,
);
@ -3325,7 +3326,6 @@
4BB73E951B587A5100552FC2 = {
isa = PBXGroup;
children = (
4B228CDA24DA41880077EF25 /* ScanTarget.metal */,
4BC3C67A24C9230F0027BF76 /* BufferingScanTarget.cpp */,
4BC3C67B24C9230F0027BF76 /* BufferingScanTarget.hpp */,
4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */,

View File

@ -29,14 +29,17 @@
// Generate some static buffers. AS A TEST.
constexpr float vertices[] = {
0.0f, 0.5f, 0.0f, 1.0f, // Position.
1.0f, 0.0f, 0.0f, 1.0f, // Colour.
-0.9f, -0.9f, // Position.
1.0f, 0.0f, 0.0f, // Colour.
-0.5f, -0.5f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
-0.9f, 0.9f,
0.0f, 1.0f, 0.0f,
0.5f, -0.5f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.9f, -0.9f,
0.0f, 0.0f, 1.0f,
0.9f, 0.9f,
0.0f, 1.0f, 1.0f,
};
_verticesBuffer = [view.device newBufferWithBytes:vertices length:sizeof(vertices) options:MTLResourceOptionCPUCacheModeDefault];
@ -45,15 +48,15 @@
// Position.
vertexDescriptor.attributes[0].bufferIndex = 0;
vertexDescriptor.attributes[0].offset = 0;
vertexDescriptor.attributes[0].format = MTLVertexFormatFloat4;
vertexDescriptor.attributes[0].format = MTLVertexFormatFloat2;
// Colour.
vertexDescriptor.attributes[1].bufferIndex = 0;
vertexDescriptor.attributes[1].offset = sizeof(float)*4;
vertexDescriptor.attributes[1].format = MTLVertexFormatFloat4;
vertexDescriptor.attributes[1].offset = sizeof(float)*2;
vertexDescriptor.attributes[1].format = MTLVertexFormatFloat3;
// Total vertex size.
vertexDescriptor.layouts[0].stride = sizeof(float) * 8;
vertexDescriptor.layouts[0].stride = sizeof(float)*5;
// Generate TEST pipeline.
id<MTLLibrary> library = [view.device newDefaultLibrary];
@ -93,7 +96,7 @@
// Drawing. Just the test triangle, as described above.
[encoder setRenderPipelineState:_gouraudPipeline];
[encoder setVertexBuffer:_verticesBuffer offset:0 atIndex:0];
[encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:3 instanceCount:1];
[encoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4 instanceCount:1];
// Complete encoding.
[encoder endEncoding];

View File

@ -13,8 +13,8 @@ using namespace metal;
// of my learning process, and the fact that they soon won't be.
struct InputVertex {
float4 position [[attribute(0)]];
float4 colour [[attribute(1)]];
float2 position [[attribute(0)]];
float3 colour [[attribute(1)]];
};
struct ColouredVertex {
@ -22,11 +22,10 @@ struct ColouredVertex {
float4 colour;
};
vertex ColouredVertex vertex_main( device const InputVertex *vertices [[buffer(0)]],
uint vid [[vertex_id]]) {
vertex ColouredVertex vertex_main(InputVertex vert [[stage_in]]) {
ColouredVertex output;
output.position = vertices[vid].position;
output.colour = vertices[vid].colour;
output.position = float4(vert.position, 0.0, 1.0);
output.colour = float4(vert.colour, 1.0);
return output;
}