-
Notifications
You must be signed in to change notification settings - Fork 4
/
BaseEffect.swift
39 lines (33 loc) · 1.31 KB
/
BaseEffect.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// BaseEffect.swift
// Triangle
//
// Created by Andrew K. on 6/24/14.
// Copyright (c) 2014 Andrew Kharchyshyn. All rights reserved.
//
import UIKit
import Metal
@objc class BaseEffect: NSObject
{
var device:MTLDevice
var renderPipelineState:MTLRenderPipelineState?
var pipeLineDescriptor:MTLRenderPipelineDescriptor
init(device:MTLDevice ,vertexShaderName: String, fragmentShaderName:String)
{
self.device = device
// Setup MTLRenderPipline descriptor object with vertex and fragment shader
pipeLineDescriptor = MTLRenderPipelineDescriptor();
var library = device.newDefaultLibrary();
pipeLineDescriptor.vertexFunction = library.newFunctionWithName(vertexShaderName);
pipeLineDescriptor.fragmentFunction = library.newFunctionWithName(fragmentShaderName);
pipeLineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.BGRA8Unorm;
// BaseEffectSfiftFixer.setup(pipeLineDescriptor)
super.init()
}
func compile() -> MTLRenderPipelineState?
{
// Compile the MTLRenderPipline object into immutable and cheap for use MTLRenderPipelineState
renderPipelineState = device.newRenderPipelineStateWithDescriptor(pipeLineDescriptor, error: nil);
return renderPipelineState
}
}