initial commit
This commit is contained in:
parent
04968efaed
commit
959623e0e3
|
|
@ -35,6 +35,16 @@
|
|||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
297F43081DEA2E3400638FC8 /* Supporting files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
29D8782F1C84D2B0007B5F17 /* Main.storyboard */,
|
||||
29D878321C84D2B0007B5F17 /* Info.plist */,
|
||||
29D878291C84D2B0007B5F17 /* AppDelegate.swift */,
|
||||
);
|
||||
name = "Supporting files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29D8781D1C84D2B0007B5F17 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
@ -57,9 +67,7 @@
|
|||
29D878381C84D309007B5F17 /* MetalView.swift */,
|
||||
29B186251C84FF5800E9C0AA /* MathUtils.swift */,
|
||||
29D8783A1C84D335007B5F17 /* Shaders.metal */,
|
||||
29D8782F1C84D2B0007B5F17 /* Main.storyboard */,
|
||||
29D878321C84D2B0007B5F17 /* Info.plist */,
|
||||
29D878291C84D2B0007B5F17 /* AppDelegate.swift */,
|
||||
297F43081DEA2E3400638FC8 /* Supporting files */,
|
||||
);
|
||||
path = chapter07;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -91,7 +99,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
LastUpgradeCheck = 0810;
|
||||
ORGANIZATIONNAME = "Marius Horga";
|
||||
TargetAttributes = {
|
||||
29D878251C84D2B0007B5F17 = {
|
||||
|
|
@ -168,8 +176,10 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
|
|
@ -212,8 +222,10 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0800"
|
||||
LastUpgradeVersion = "0810"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -23,27 +23,27 @@ class MetalView: MTKView {
|
|||
|
||||
func createBuffers() {
|
||||
device = MTLCreateSystemDefaultDevice()!
|
||||
commandQueue = device!.newCommandQueue()
|
||||
commandQueue = device!.makeCommandQueue()
|
||||
let vertex_data = [Vertex(position: [-1.0, -1.0, 0.0, 1.0], color: [1, 0, 0, 1]),
|
||||
Vertex(position: [ 1.0, -1.0, 0.0, 1.0], color: [0, 1, 0, 1]),
|
||||
Vertex(position: [ 0.0, 1.0, 0.0, 1.0], color: [0, 0, 1, 1])
|
||||
]
|
||||
vertexBuffer = device!.newBuffer(withBytes: vertex_data, length: sizeof(Vertex.self) * 3, options:[])
|
||||
uniformBuffer = device!.newBuffer(withLength: sizeof(Float.self) * 16, options: [])
|
||||
vertexBuffer = device!.makeBuffer(bytes: vertex_data, length: MemoryLayout<Vertex>.size * 3, options:[])
|
||||
uniformBuffer = device!.makeBuffer(length: MemoryLayout<Float>.size * 16, options: [])
|
||||
let bufferPointer = uniformBuffer.contents()
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, sizeof(Float.self) * 16)
|
||||
memcpy(bufferPointer, Matrix().modelMatrix(Matrix()).m, MemoryLayout<Float>.size * 16)
|
||||
}
|
||||
|
||||
func registerShaders() {
|
||||
let library = device!.newDefaultLibrary()!
|
||||
let vertex_func = library.newFunction(withName: "vertex_func")
|
||||
let frag_func = library.newFunction(withName: "fragment_func")
|
||||
let vertex_func = library.makeFunction(name: "vertex_func")
|
||||
let frag_func = library.makeFunction(name: "fragment_func")
|
||||
let rpld = MTLRenderPipelineDescriptor()
|
||||
rpld.vertexFunction = vertex_func
|
||||
rpld.fragmentFunction = frag_func
|
||||
rpld.colorAttachments[0].pixelFormat = .bgra8Unorm
|
||||
do {
|
||||
try rps = device!.newRenderPipelineState(with: rpld)
|
||||
try rps = device!.makeRenderPipelineState(descriptor: rpld)
|
||||
} catch let error {
|
||||
self.print("\(error)")
|
||||
}
|
||||
|
|
@ -51,14 +51,14 @@ class MetalView: MTKView {
|
|||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
if let rpd = currentRenderPassDescriptor, drawable = currentDrawable {
|
||||
if let rpd = currentRenderPassDescriptor, let drawable = currentDrawable {
|
||||
rpd.colorAttachments[0].clearColor = MTLClearColorMake(0.5, 0.5, 0.5, 1.0)
|
||||
let commandBuffer = device!.newCommandQueue().commandBuffer()
|
||||
let commandEncoder = commandBuffer.renderCommandEncoder(with: rpd)
|
||||
let commandBuffer = device!.makeCommandQueue().makeCommandBuffer()
|
||||
let commandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: rpd)
|
||||
commandEncoder.setRenderPipelineState(rps!)
|
||||
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, at: 0)
|
||||
commandEncoder.setVertexBuffer(uniformBuffer, offset: 0, at: 1)
|
||||
commandEncoder.drawPrimitives(.triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
commandEncoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1)
|
||||
commandEncoder.endEncoding()
|
||||
commandBuffer.present(drawable)
|
||||
commandBuffer.commit()
|
||||
|
|
|
|||
Loading…
Reference in New Issue