mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-19 23:29:05 +00:00
Switches to interleaved vertex data.
This more closely relates to what I actually want to do.
This commit is contained in:
parent
5c836604c0
commit
7551782a25
@ -1010,7 +1010,7 @@
|
|||||||
4B228CD624D773CA0077EF25 /* CSScanTarget.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSScanTarget.h; sourceTree = "<group>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
4B228CDA24DA41880077EF25 /* ScanTarget.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; name = ScanTarget.metal; path = "Clock Signal/ScanTarget/ScanTarget.metal"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.metal; };
|
||||||
4B24095A1C45DF85004DA684 /* Stepper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Stepper.hpp; sourceTree = "<group>"; };
|
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>"; };
|
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; };
|
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_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_PARAMETER = YES;
|
GCC_WARN_UNUSED_PARAMETER = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||||
MTL_ENABLE_DEBUG_INFO = YES;
|
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
@ -5218,7 +5218,7 @@
|
|||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_PARAMETER = YES;
|
GCC_WARN_UNUSED_PARAMETER = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||||
|
@ -18,8 +18,7 @@
|
|||||||
// much of the inspiration, albeit that I'm proceeding via MKLView.
|
// much of the inspiration, albeit that I'm proceeding via MKLView.
|
||||||
id<MTLFunction> _vertexShader;
|
id<MTLFunction> _vertexShader;
|
||||||
id<MTLFunction> _fragmentShader;
|
id<MTLFunction> _fragmentShader;
|
||||||
id<MTLBuffer> _positionBuffer;
|
id<MTLBuffer> _verticesBuffer;
|
||||||
id<MTLBuffer> _colourBuffer;
|
|
||||||
id<MTLRenderPipelineState> _gouraudPipeline;
|
id<MTLRenderPipelineState> _gouraudPipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,18 +28,32 @@
|
|||||||
_commandQueue = [view.device newCommandQueue];
|
_commandQueue = [view.device newCommandQueue];
|
||||||
|
|
||||||
// Generate some static buffers. AS A TEST.
|
// Generate some static buffers. AS A TEST.
|
||||||
constexpr float positions[] = {
|
constexpr float vertices[] = {
|
||||||
0.0f, 0.5f, 0.0f, 1.0f,
|
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.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
0.0f, 1.0f, 0.0f, 1.0f,
|
||||||
|
|
||||||
0.5f, -0.5f, 0.0f, 1.0f,
|
0.5f, -0.5f, 0.0f, 1.0f,
|
||||||
|
0.0f, 0.0f, 1.0f, 1.0f,
|
||||||
};
|
};
|
||||||
constexpr float colours[] = {
|
_verticesBuffer = [view.device newBufferWithBytes:vertices length:sizeof(vertices) options:MTLResourceOptionCPUCacheModeDefault];
|
||||||
1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 0.0f, 1.0f,
|
MTLVertexDescriptor *vertexDescriptor = [[MTLVertexDescriptor alloc] init];
|
||||||
0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
};
|
// Position.
|
||||||
_positionBuffer = [view.device newBufferWithBytes:positions length:sizeof(positions) options:MTLResourceOptionCPUCacheModeDefault];
|
vertexDescriptor.attributes[0].bufferIndex = 0;
|
||||||
_colourBuffer = [view.device newBufferWithBytes:colours length:sizeof(colours) options:MTLResourceOptionCPUCacheModeDefault];
|
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.
|
// Generate TEST pipeline.
|
||||||
id<MTLLibrary> library = [view.device newDefaultLibrary];
|
id<MTLLibrary> library = [view.device newDefaultLibrary];
|
||||||
@ -48,6 +61,7 @@
|
|||||||
pipelineDescriptor.vertexFunction = [library newFunctionWithName:@"vertex_main"];
|
pipelineDescriptor.vertexFunction = [library newFunctionWithName:@"vertex_main"];
|
||||||
pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"fragment_main"];
|
pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"fragment_main"];
|
||||||
pipelineDescriptor.colorAttachments[0].pixelFormat = view.colorPixelFormat;
|
pipelineDescriptor.colorAttachments[0].pixelFormat = view.colorPixelFormat;
|
||||||
|
pipelineDescriptor.vertexDescriptor = vertexDescriptor;
|
||||||
_gouraudPipeline = [view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil];
|
_gouraudPipeline = [view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -78,8 +92,7 @@
|
|||||||
|
|
||||||
// Drawing. Just the test triangle, as described above.
|
// Drawing. Just the test triangle, as described above.
|
||||||
[encoder setRenderPipelineState:_gouraudPipeline];
|
[encoder setRenderPipelineState:_gouraudPipeline];
|
||||||
[encoder setVertexBuffer:_positionBuffer offset:0 atIndex:0];
|
[encoder setVertexBuffer:_verticesBuffer offset:0 atIndex:0];
|
||||||
[encoder setVertexBuffer:_colourBuffer offset:0 atIndex:1];
|
|
||||||
[encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:3 instanceCount:1];
|
[encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:3 instanceCount:1];
|
||||||
|
|
||||||
// Complete encoding.
|
// Complete encoding.
|
||||||
|
@ -9,20 +9,27 @@
|
|||||||
#include <metal_stdlib>
|
#include <metal_stdlib>
|
||||||
using namespace metal;
|
using namespace metal;
|
||||||
|
|
||||||
struct ColoredVertex {
|
// These two structs are the same, but defined separately as an artefact
|
||||||
float4 position [[position]];
|
// of my learning process, and the fact that they soon won't be.
|
||||||
float4 color;
|
|
||||||
|
struct InputVertex {
|
||||||
|
float4 position [[attribute(0)]];
|
||||||
|
float4 colour [[attribute(1)]];
|
||||||
};
|
};
|
||||||
|
|
||||||
vertex ColoredVertex vertex_main( constant float4 *position [[buffer(0)]],
|
struct ColouredVertex {
|
||||||
constant float4 *color [[buffer(1)]],
|
float4 position [[position]];
|
||||||
|
float4 colour;
|
||||||
|
};
|
||||||
|
|
||||||
|
vertex ColouredVertex vertex_main( device const InputVertex *vertices [[buffer(0)]],
|
||||||
uint vid [[vertex_id]]) {
|
uint vid [[vertex_id]]) {
|
||||||
ColoredVertex vert;
|
ColouredVertex output;
|
||||||
vert.position = position[vid];
|
output.position = vertices[vid].position;
|
||||||
vert.color = color[vid];
|
output.colour = vertices[vid].colour;
|
||||||
return vert;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment float4 fragment_main(ColoredVertex vert [[stage_in]]) {
|
fragment float4 fragment_main(ColouredVertex vert [[stage_in]]) {
|
||||||
return vert.color;
|
return vert.colour;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user