Skip to content

Commit

Permalink
All samples fixed for iOS8 - beta3
Browse files Browse the repository at this point in the history
  • Loading branch information
haawa799 committed Jul 10, 2014
1 parent f6d7dab commit ef4118a
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 80 deletions.
11 changes: 4 additions & 7 deletions 1. Colored Triangle/MetalTryOut-Objc/Nodes/Model.swift
Expand Up @@ -47,17 +47,14 @@ import QuartzCore
var commandEncoder:MTLRenderCommandEncoder = commandBuffer.renderCommandEncoderWithDescriptor(renderPassDesc)
commandEncoder.setRenderPipelineState(baseEffect.renderPipelineState)
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, atIndex: 0)
commandEncoder.drawPrimitives(MTLPrimitiveType.Triangle, vertexStart: 0, vertexCount: vertexCount);
commandEncoder.endEncoding();
commandEncoder.drawPrimitives(MTLPrimitiveType.Triangle, vertexStart: 0, vertexCount: vertexCount)
commandEncoder.endEncoding()

// After command in command buffer is encoded for GPU we provide drawable that will be invoked when this command buffer has been scheduled for execution
if let drawableAnyObject = drawable as? MTLDrawable
{
commandBuffer.presentDrawable(drawableAnyObject);
}
commandBuffer.presentDrawable(drawable)

// Commit commandBuffer to his commandQueue in which he will be executed after commands before him in queue
commandBuffer.commit();
commandBuffer.commit()

}

Expand Down
Expand Up @@ -24,7 +24,7 @@ import Metal
var library = device.newDefaultLibrary();
pipeLineDescriptor.vertexFunction = library.newFunctionWithName(vertexShaderName);
pipeLineDescriptor.fragmentFunction = library.newFunctionWithName(fragmentShaderName);
pipeLineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.FormatBGRA8Unorm;
pipeLineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.BGRA8Unorm;
// BaseEffectSfiftFixer.setup(pipeLineDescriptor)

super.init()
Expand Down
2 changes: 1 addition & 1 deletion 1. Colored Triangle/MetalTryOut-Objc/Shaders/Shaders.metal
Expand Up @@ -22,7 +22,7 @@ struct VertexOut
};


vertex VertexOut myVertexShader(const global Vertex* vertexArray [[buffer(0)]],
vertex VertexOut myVertexShader(const device Vertex* vertexArray [[buffer(0)]],
unsigned int vid [[vertex_id]])
{
VertexOut out;
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions 2. Cube + Transform/MetalTryOut-Objc/Nodes/Matrix4x4.swift
Expand Up @@ -10,7 +10,7 @@

let rows: Int = 4
let columns: Int = 4
var grid: Float[]
var grid: [Float]

init() {
grid = Array(count: rows * columns, repeatedValue: 0.0)
Expand All @@ -22,7 +22,7 @@

func transpose()
{
var tmp: Float[] = Array(count: rows * columns, repeatedValue: 0.0)
var tmp: [Float] = Array(count: rows * columns, repeatedValue: 0.0)
var i,j : Int
for i = 0; i < 4; i++
{
Expand All @@ -39,7 +39,7 @@

func multiplyMatrix(matrix: Matrix4x4)
{
var tmp: Float[] = Array(count: columns, repeatedValue: 0.0)
var tmp: [Float] = Array(count: columns, repeatedValue: 0.0)
for var j = 0; j < 4; j++
{
tmp[0] = grid[j]
Expand Down
5 changes: 1 addition & 4 deletions 2. Cube + Transform/MetalTryOut-Objc/Nodes/Model.swift
Expand Up @@ -71,10 +71,7 @@ import QuartzCore
commandEncoder.endEncoding();

// After command in command buffer is encoded for GPU we provide drawable that will be invoked when this command buffer has been scheduled for execution
if let drawableAnyObject = drawable as? MTLDrawable
{
commandBuffer.presentDrawable(drawableAnyObject);
}
commandBuffer.presentDrawable(drawable);

// Commit commandBuffer to his commandQueue in which he will be executed after commands before him in queue
commandBuffer.commit();
Expand Down
Expand Up @@ -25,7 +25,7 @@ import Metal
var library = device.newDefaultLibrary();
pipeLineDescriptor.vertexFunction = library.newFunctionWithName(vertexShaderName);
pipeLineDescriptor.fragmentFunction = library.newFunctionWithName(fragmentShaderName);
pipeLineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.FormatBGRA8Unorm;
pipeLineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.BGRA8Unorm;

super.init()
}
Expand Down
6 changes: 5 additions & 1 deletion 2. Cube + Transform/MetalTryOut-Objc/Shaders/Shaders.metal
Expand Up @@ -25,6 +25,10 @@ struct VertexOut
float4 color;
};

float4x4 mv_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix);
float4x4 proj_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix);


float4x4 mv_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix)
{
float4x4 matrix;
Expand All @@ -51,7 +55,7 @@ float4x4 proj_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix)
return matrix;
}

vertex VertexOut myVertexShader(const global Vertex* vertexArray [[buffer(0)]],
vertex VertexOut myVertexShader(const device Vertex* vertexArray [[buffer(0)]],
constant Uniforms& uniforms [[buffer(1)]],
unsigned int vid [[vertex_id]])
{
Expand Down
6 changes: 3 additions & 3 deletions 3. Texured cube/MetalTryOut-Objc/Nodes/Matrix4x4.swift
Expand Up @@ -10,7 +10,7 @@

let rows: Int = 4
let columns: Int = 4
var grid: Float[]
var grid: [Float]

init() {
grid = Array(count: rows * columns, repeatedValue: 0.0)
Expand All @@ -22,7 +22,7 @@

func transpose()
{
var tmp: Float[] = Array(count: rows * columns, repeatedValue: 0.0)
var tmp: [Float] = Array(count: rows * columns, repeatedValue: 0.0)
var i,j : Int
for i = 0; i < 4; i++
{
Expand All @@ -39,7 +39,7 @@

func multiplyMatrix(matrix: Matrix4x4)
{
var tmp: Float[] = Array(count: columns, repeatedValue: 0.0)
var tmp: [Float] = Array(count: columns, repeatedValue: 0.0)
for var j = 0; j < 4; j++
{
tmp[0] = grid[j]
Expand Down
5 changes: 1 addition & 4 deletions 3. Texured cube/MetalTryOut-Objc/Nodes/Model.swift
Expand Up @@ -91,10 +91,7 @@ import QuartzCore
commandEncoder.endEncoding();

// After command in command buffer is encoded for GPU we provide drawable that will be invoked when this command buffer has been scheduled for execution
if let drawableAnyObject = drawable as? MTLDrawable
{
commandBuffer.presentDrawable(drawableAnyObject);
}
commandBuffer.presentDrawable(drawable)

// Commit commandBuffer to his commandQueue in which he will be executed after commands before him in queue
commandBuffer.commit();
Expand Down
2 changes: 1 addition & 1 deletion 3. Texured cube/MetalTryOut-Objc/Shaders/BaseEffect.swift
Expand Up @@ -25,7 +25,7 @@ import Metal
var library = device.newDefaultLibrary();
pipeLineDescriptor.vertexFunction = library.newFunctionWithName(vertexShaderName);
pipeLineDescriptor.fragmentFunction = library.newFunctionWithName(fragmentShaderName);
pipeLineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.FormatBGRA8Unorm;
pipeLineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.BGRA8Unorm;

super.init()
}
Expand Down
5 changes: 4 additions & 1 deletion 3. Texured cube/MetalTryOut-Objc/Shaders/Shaders.metal
Expand Up @@ -27,6 +27,9 @@ struct VertexOut
float2 texCoord [[user(texturecoord)]];;
};

float4x4 mv_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix);
float4x4 proj_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix);

float4x4 mv_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix)
{
float4x4 matrix;
Expand All @@ -53,7 +56,7 @@ float4x4 proj_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix)
return matrix;
}

vertex VertexOut myVertexShader(const global Vertex* vertexArray [[buffer(0)]],
vertex VertexOut myVertexShader(const device Vertex* vertexArray [[buffer(0)]],
constant Uniforms& uniforms [[buffer(1)]],
unsigned int vid [[vertex_id]])
{
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions 4. Cube + Lighting/MetalTryOut-Objc/Nodes/Matrix4x4.swift
Expand Up @@ -10,7 +10,7 @@

let rows: Int = 4
let columns: Int = 4
var grid: Float[]
var grid: [Float]

init() {
grid = Array(count: rows * columns, repeatedValue: 0.0)
Expand All @@ -22,7 +22,7 @@

func transpose()
{
var tmp: Float[] = Array(count: rows * columns, repeatedValue: 0.0)
var tmp: [Float] = Array(count: rows * columns, repeatedValue: 0.0)
var i,j : Int
for i = 0; i < 4; i++
{
Expand All @@ -39,7 +39,7 @@

func multiplyMatrix(matrix: Matrix4x4)
{
var tmp: Float[] = Array(count: columns, repeatedValue: 0.0)
var tmp: [Float] = Array(count: columns, repeatedValue: 0.0)
for var j = 0; j < 4; j++
{
tmp[0] = grid[j]
Expand Down
5 changes: 1 addition & 4 deletions 4. Cube + Lighting/MetalTryOut-Objc/Nodes/Model.swift
Expand Up @@ -91,10 +91,7 @@ import QuartzCore
commandEncoder.endEncoding();

// After command in command buffer is encoded for GPU we provide drawable that will be invoked when this command buffer has been scheduled for execution
if let drawableAnyObject = drawable as? MTLDrawable
{
commandBuffer.presentDrawable(drawableAnyObject);
}
commandBuffer.presentDrawable(drawable)

// Commit commandBuffer to his commandQueue in which he will be executed after commands before him in queue
commandBuffer.commit();
Expand Down
4 changes: 2 additions & 2 deletions 4. Cube + Lighting/MetalTryOut-Objc/Shaders/BaseEffect.swift
Expand Up @@ -17,7 +17,7 @@ import Metal
var projectionMatrix:AnyObject = Matrix4()

var lightColor = MTLClearColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
var lightDirection: Float[] = [0.0,0.0,0.0]
var lightDirection: [Float] = [0.0,0.0,0.0]
var diffuseIntensity: Float = 1.0
var ambientIntensity: Float = 1.0
var specularIntensity: Float = 1.0
Expand All @@ -32,7 +32,7 @@ import Metal
var library = device.newDefaultLibrary();
pipeLineDescriptor.vertexFunction = library.newFunctionWithName(vertexShaderName);
pipeLineDescriptor.fragmentFunction = library.newFunctionWithName(fragmentShaderName);
pipeLineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.FormatBGRA8Unorm;
pipeLineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.BGRA8Unorm;

super.init()
}
Expand Down
5 changes: 4 additions & 1 deletion 4. Cube + Lighting/MetalTryOut-Objc/Shaders/Shaders.metal
Expand Up @@ -45,6 +45,9 @@ struct VertexOut
float shininess;
};

float4x4 mv_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix);
float4x4 proj_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix);

float4x4 mv_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix)
{
float4x4 matrix;
Expand All @@ -71,7 +74,7 @@ float4x4 proj_MatrixFromUniformBuffer(constant Uniforms& uniformMatrix)
return matrix;
}

vertex VertexOut myVertexShader(const global Vertex* vertexArray [[buffer(0)]],
vertex VertexOut myVertexShader(const device Vertex* vertexArray [[buffer(0)]],
constant Uniforms& uniforms [[buffer(1)]],
unsigned int vid [[vertex_id]])
{
Expand Down
Binary file not shown.
Expand Up @@ -171,21 +171,5 @@
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "MetalTryOut-Objc/Main/MetalView.swift"
timestampString = "426154089.859874"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "52"
endingLineNumber = "52"
landmarkName = "display()"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
14 changes: 7 additions & 7 deletions 5. Imported Model/MetalTryOut-Objc/Main/FrameBuffer.m
Expand Up @@ -85,12 +85,12 @@ - (void) setupRenderPassDescriptorForTexture:(id <MTLTexture>) texture
_renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];

// create a color attachment every frame since we have to recreate the texture every frame
MTLRenderPassAttachmentDescriptor *colorAttachment = [MTLRenderPassAttachmentDescriptor new];
MTLRenderPassColorAttachmentDescriptor *colorAttachment = [MTLRenderPassColorAttachmentDescriptor new];
colorAttachment.texture = texture;

// make sure to clear every frame for best performance
[colorAttachment setLoadAction:MTLLoadActionClear];
[colorAttachment setClearValue:MTLClearValueMakeColor(0.65f, 0.65f, 0.65f, 1.0f)];
colorAttachment.loadAction = MTLLoadActionClear;
colorAttachment.clearColor = MTLClearColorMake(0.65, 0.65, 0.65, 1.0);

// if sample count is greater than 1, render into using MSAA, then resolve into our color texture
if(_sampleCount > 1)
Expand Down Expand Up @@ -154,10 +154,10 @@ - (void) setupRenderPassDescriptorForTexture:(id <MTLTexture>) texture

_depthTex = [_device newTextureWithDescriptor: desc];

MTLRenderPassAttachmentDescriptor *depthAttachment = [MTLRenderPassAttachmentDescriptor new];
MTLRenderPassDepthAttachmentDescriptor *depthAttachment = [MTLRenderPassDepthAttachmentDescriptor new];
depthAttachment.texture = _depthTex;
[depthAttachment setLoadAction:MTLLoadActionClear];
[depthAttachment setClearValue:MTLClearValueMakeDepth(1.0)];
depthAttachment.clearDepth = 1.0;
[depthAttachment setStoreAction: MTLStoreActionDontCare];

_renderPassDescriptor.depthAttachment = depthAttachment;
Expand Down Expand Up @@ -185,10 +185,10 @@ - (void) setupRenderPassDescriptorForTexture:(id <MTLTexture>) texture

_stencilTex = [_device newTextureWithDescriptor: desc];

MTLRenderPassAttachmentDescriptor* stencilAttachment = [MTLRenderPassAttachmentDescriptor new];
MTLRenderPassStencilAttachmentDescriptor* stencilAttachment = [MTLRenderPassStencilAttachmentDescriptor new];
stencilAttachment.texture = _stencilTex;
[stencilAttachment setLoadAction:MTLLoadActionClear];
[stencilAttachment setClearValue:MTLClearValueMakeStencil(0)];
stencilAttachment.clearStencil = 0;
[stencilAttachment setStoreAction: MTLStoreActionDontCare];

_renderPassDescriptor.stencilAttachment = stencilAttachment;
Expand Down
2 changes: 1 addition & 1 deletion 5. Imported Model/MetalTryOut-Objc/Main/MetalView.swift
Expand Up @@ -102,7 +102,7 @@ import Metal
var device = MTLCreateSystemDefaultDevice()

_metalLayer.device = device
_metalLayer.pixelFormat = MTLPixelFormat.FormatBGRA8Unorm
_metalLayer.pixelFormat = MTLPixelFormat.BGRA8Unorm
_metalLayer.framebufferOnly = true

frameBuffer = FrameBuffer(metalView: self)
Expand Down
6 changes: 3 additions & 3 deletions 5. Imported Model/MetalTryOut-Objc/Nodes/Matrix4x4.swift
Expand Up @@ -10,7 +10,7 @@

let rows: Int = 4
let columns: Int = 4
var grid: Float[]
var grid: [Float]

init() {
grid = Array(count: rows * columns, repeatedValue: 0.0)
Expand All @@ -22,7 +22,7 @@

func transpose()
{
var tmp: Float[] = Array(count: rows * columns, repeatedValue: 0.0)
var tmp: [Float] = Array(count: rows * columns, repeatedValue: 0.0)
var i,j : Int
for i = 0; i < 4; i++
{
Expand All @@ -39,7 +39,7 @@

func multiplyMatrix(matrix: Matrix4x4)
{
var tmp: Float[] = Array(count: columns, repeatedValue: 0.0)
var tmp: [Float] = Array(count: columns, repeatedValue: 0.0)
for var j = 0; j < 4; j++
{
tmp[0] = grid[j]
Expand Down
15 changes: 7 additions & 8 deletions 5. Imported Model/MetalTryOut-Objc/Nodes/Node.swift
Expand Up @@ -86,19 +86,18 @@ import QuartzCore
func renderNode(node: Node, parentMatrix: AnyObject, projectionMatrix: AnyObject, renderPassDescriptor: MTLRenderPassDescriptor, commandBuffer: MTLCommandBuffer, encoder: MTLRenderCommandEncoder?) -> MTLRenderCommandEncoder
{
var commandEncoder:MTLRenderCommandEncoder

if encoder == nil
if let encoder = encoder
{
commandEncoder = commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor)
commandEncoder.setDepthStencilState(depthState)
commandEncoder.setRenderPipelineState(baseEffect.renderPipelineState)
commandEncoder.setFragmentSamplerState(samplerState, atIndex: 0)
commandEncoder.setCullMode(MTLCullMode.Front)
commandEncoder = encoder
}
else
{
commandEncoder = encoder!
commandEncoder = commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor)
}
commandEncoder.setDepthStencilState(depthState)
commandEncoder.setRenderPipelineState(baseEffect.renderPipelineState)
commandEncoder.setFragmentSamplerState(samplerState, atIndex: 0)
commandEncoder.setCullMode(MTLCullMode.Front)


commandEncoder.pushDebugGroup(node.name)
Expand Down
5 changes: 1 addition & 4 deletions 5. Imported Model/MetalTryOut-Objc/Nodes/Scene.swift
Expand Up @@ -53,10 +53,7 @@ class Scene: Node {
commandEncoder = renderNode(self, parentMatrix: parentModelViewMatrix, projectionMatrix: projectionMatrix, renderPassDescriptor: renderPathDescriptor, commandBuffer: commandBuffer, encoder: commandEncoder)
}

if let drawableAnyObject = metalView.frameBuffer.currentDrawable as? MTLDrawable
{
commandBuffer.presentDrawable(drawableAnyObject);
}
commandBuffer.presentDrawable(metalView.frameBuffer.currentDrawable)

commandEncoder?.endEncoding()

Expand Down

0 comments on commit ef4118a

Please sign in to comment.