diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 302b21d38..1bf433bff 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -1010,7 +1010,7 @@ 4B228CD624D773CA0077EF25 /* CSScanTarget.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSScanTarget.h; sourceTree = ""; }; 4B228CD724DA12C50077EF25 /* CSScanTargetView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSScanTargetView.h; sourceTree = ""; }; 4B228CD824DA12C60077EF25 /* CSScanTargetView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSScanTargetView.m; sourceTree = ""; }; - 4B228CDA24DA41880077EF25 /* ScanTarget.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; name = ScanTarget.metal; path = "Clock Signal/ScanTarget/ScanTarget.metal"; sourceTree = ""; }; + 4B228CDA24DA41880077EF25 /* ScanTarget.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; name = ScanTarget.metal; path = "Clock Signal/ScanTarget/ScanTarget.metal"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.metal; }; 4B24095A1C45DF85004DA684 /* Stepper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Stepper.hpp; sourceTree = ""; }; 4B2530F3244E6773007980BF /* fm.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = fm.json; sourceTree = ""; }; 4B2A332C1DB86821002876E3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/OricOptions.xib"; sourceTree = SOURCE_ROOT; }; @@ -5167,8 +5167,8 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; - MTL_ENABLE_DEBUG_INFO = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -5218,7 +5218,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/OSBindings/Mac/Clock Signal/ScanTarget/CSScanTarget.mm b/OSBindings/Mac/Clock Signal/ScanTarget/CSScanTarget.mm index d378305ff..a291ffb79 100644 --- a/OSBindings/Mac/Clock Signal/ScanTarget/CSScanTarget.mm +++ b/OSBindings/Mac/Clock Signal/ScanTarget/CSScanTarget.mm @@ -18,8 +18,7 @@ // much of the inspiration, albeit that I'm proceeding via MKLView. id _vertexShader; id _fragmentShader; - id _positionBuffer; - id _colourBuffer; + id _verticesBuffer; id _gouraudPipeline; } @@ -29,18 +28,32 @@ _commandQueue = [view.device newCommandQueue]; // Generate some static buffers. AS A TEST. - constexpr float positions[] = { - 0.0f, 0.5f, 0.0f, 1.0f, + constexpr float vertices[] = { + 0.0f, 0.5f, 0.0f, 1.0f, // Position. + 1.0f, 0.0f, 0.0f, 1.0f, // Colour. + -0.5f, -0.5f, 0.0f, 1.0f, + 0.0f, 1.0f, 0.0f, 1.0f, + 0.5f, -0.5f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, }; - constexpr float colours[] = { - 1.0f, 0.0f, 0.0f, 1.0f, - 0.0f, 1.0f, 0.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 1.0f, - }; - _positionBuffer = [view.device newBufferWithBytes:positions length:sizeof(positions) options:MTLResourceOptionCPUCacheModeDefault]; - _colourBuffer = [view.device newBufferWithBytes:colours length:sizeof(colours) options:MTLResourceOptionCPUCacheModeDefault]; + _verticesBuffer = [view.device newBufferWithBytes:vertices length:sizeof(vertices) options:MTLResourceOptionCPUCacheModeDefault]; + + MTLVertexDescriptor *vertexDescriptor = [[MTLVertexDescriptor alloc] init]; + + // Position. + vertexDescriptor.attributes[0].bufferIndex = 0; + vertexDescriptor.attributes[0].offset = 0; + vertexDescriptor.attributes[0].format = MTLVertexFormatFloat4; + + // Colour. + vertexDescriptor.attributes[1].bufferIndex = 0; + vertexDescriptor.attributes[1].offset = sizeof(float)*4; + vertexDescriptor.attributes[1].format = MTLVertexFormatFloat4; + + // Total vertex size. + vertexDescriptor.layouts[0].stride = sizeof(float) * 8; // Generate TEST pipeline. id library = [view.device newDefaultLibrary]; @@ -48,6 +61,7 @@ pipelineDescriptor.vertexFunction = [library newFunctionWithName:@"vertex_main"]; pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"fragment_main"]; pipelineDescriptor.colorAttachments[0].pixelFormat = view.colorPixelFormat; + pipelineDescriptor.vertexDescriptor = vertexDescriptor; _gouraudPipeline = [view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil]; } return self; @@ -78,8 +92,7 @@ // Drawing. Just the test triangle, as described above. [encoder setRenderPipelineState:_gouraudPipeline]; - [encoder setVertexBuffer:_positionBuffer offset:0 atIndex:0]; - [encoder setVertexBuffer:_colourBuffer offset:0 atIndex:1]; + [encoder setVertexBuffer:_verticesBuffer offset:0 atIndex:0]; [encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:3 instanceCount:1]; // Complete encoding. diff --git a/OSBindings/Mac/Clock Signal/ScanTarget/ScanTarget.metal b/OSBindings/Mac/Clock Signal/ScanTarget/ScanTarget.metal index 6e5e1bef3..8384aec14 100644 --- a/OSBindings/Mac/Clock Signal/ScanTarget/ScanTarget.metal +++ b/OSBindings/Mac/Clock Signal/ScanTarget/ScanTarget.metal @@ -9,20 +9,27 @@ #include using namespace metal; -struct ColoredVertex { - float4 position [[position]]; - float4 color; +// These two structs are the same, but defined separately as an artefact +// of my learning process, and the fact that they soon won't be. + +struct InputVertex { + float4 position [[attribute(0)]]; + float4 colour [[attribute(1)]]; }; -vertex ColoredVertex vertex_main( constant float4 *position [[buffer(0)]], - constant float4 *color [[buffer(1)]], +struct ColouredVertex { + float4 position [[position]]; + float4 colour; +}; + +vertex ColouredVertex vertex_main( device const InputVertex *vertices [[buffer(0)]], uint vid [[vertex_id]]) { - ColoredVertex vert; - vert.position = position[vid]; - vert.color = color[vid]; - return vert; + ColouredVertex output; + output.position = vertices[vid].position; + output.colour = vertices[vid].colour; + return output; } -fragment float4 fragment_main(ColoredVertex vert [[stage_in]]) { - return vert.color; +fragment float4 fragment_main(ColouredVertex vert [[stage_in]]) { + return vert.colour; }