mirror of
https://github.com/Luigi30/FruitMachine-Swift.git
synced 2024-11-23 02:33:00 +00:00
OpenGL
This commit is contained in:
parent
a98bea0f34
commit
521e5a1636
@ -13,10 +13,10 @@
|
||||
2A5BC51C1F29A2EB008C03BE /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A5BC51B1F29A2EB008C03BE /* QuartzCore.framework */; };
|
||||
2A5BC51E1F29A4C3008C03BE /* AppleIBitmapDisplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */; };
|
||||
2A60851E1F2AFAE900E05B64 /* PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A60851D1F2AFAE900E05B64 /* PIA.swift */; };
|
||||
2A6D3BF21F2E6222001CBEFB /* AppleGLDisplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6D3BF11F2E6222001CBEFB /* AppleGLDisplay.swift */; };
|
||||
2AA8B5F81F2A8889002B350F /* AppleI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5F71F2A8889002B350F /* AppleI.swift */; };
|
||||
2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */; };
|
||||
2AA8B5FE1F2A942C002B350F /* PIAOverrides.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FD1F2A942C002B350F /* PIAOverrides.swift */; };
|
||||
2AB815E71F2DA25E000BCE7D /* AppleIMetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB815E61F2DA25E000BCE7D /* AppleIMetalView.swift */; };
|
||||
2AD458CE1F205EB700F05121 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD458CD1F205EB700F05121 /* AppDelegate.swift */; };
|
||||
2AD458D01F205EB700F05121 /* DebuggerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD458CF1F205EB700F05121 /* DebuggerViewController.swift */; };
|
||||
2AD458D21F205EB700F05121 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2AD458D11F205EB700F05121 /* Assets.xcassets */; };
|
||||
@ -43,10 +43,10 @@
|
||||
2A5BC51B1F29A2EB008C03BE /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
|
||||
2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleIBitmapDisplay.swift; sourceTree = "<group>"; };
|
||||
2A60851D1F2AFAE900E05B64 /* PIA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIA.swift; sourceTree = "<group>"; };
|
||||
2A6D3BF11F2E6222001CBEFB /* AppleGLDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleGLDisplay.swift; sourceTree = "<group>"; };
|
||||
2AA8B5F71F2A8889002B350F /* AppleI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleI.swift; sourceTree = "<group>"; };
|
||||
2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Terminal.swift; sourceTree = "<group>"; };
|
||||
2AA8B5FD1F2A942C002B350F /* PIAOverrides.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAOverrides.swift; sourceTree = "<group>"; };
|
||||
2AB815E61F2DA25E000BCE7D /* AppleIMetalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleIMetalView.swift; sourceTree = "<group>"; };
|
||||
2AD458CA1F205EB700F05121 /* FruitMachine.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FruitMachine.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2AD458CD1F205EB700F05121 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
2AD458CF1F205EB700F05121 /* DebuggerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebuggerViewController.swift; sourceTree = "<group>"; };
|
||||
@ -96,8 +96,8 @@
|
||||
2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */,
|
||||
2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */,
|
||||
2AA8B5F71F2A8889002B350F /* AppleI.swift */,
|
||||
2AB815E61F2DA25E000BCE7D /* AppleIMetalView.swift */,
|
||||
2A60851D1F2AFAE900E05B64 /* PIA.swift */,
|
||||
2A6D3BF11F2E6222001CBEFB /* AppleGLDisplay.swift */,
|
||||
);
|
||||
path = AppleI;
|
||||
sourceTree = "<group>";
|
||||
@ -278,7 +278,6 @@
|
||||
2AE42E431F28665300C4900E /* CharacterGenerator.swift in Sources */,
|
||||
2AE42E0C1F28522D00C4900E /* MemoryOverride.swift in Sources */,
|
||||
2A22EBFB1F21A7A700A36A61 /* IntegerExtensions.swift in Sources */,
|
||||
2AB815E71F2DA25E000BCE7D /* AppleIMetalView.swift in Sources */,
|
||||
2AD6D5841F26E6BF008F3CF5 /* DebuggerCommands.swift in Sources */,
|
||||
2AE5BA041F23DE4400FAA343 /* Disassembly.swift in Sources */,
|
||||
2AE42E3A1F28628300C4900E /* MainViewController.swift in Sources */,
|
||||
@ -288,6 +287,7 @@
|
||||
2AE5BA061F2469EB00FAA343 /* AddressConversions.swift in Sources */,
|
||||
2AE42E0A1F28521E00C4900E /* WriteOverride.swift in Sources */,
|
||||
2A5BC5191F29A28D008C03BE /* AppleScreenView.swift in Sources */,
|
||||
2A6D3BF21F2E6222001CBEFB /* AppleGLDisplay.swift in Sources */,
|
||||
2AD458E11F2064CB00F05121 /* MemoryInterface.swift in Sources */,
|
||||
2AA8B5F81F2A8889002B350F /* AppleI.swift in Sources */,
|
||||
2AD458DF1F205F4500F05121 /* CPU.swift in Sources */,
|
||||
|
83
FruitMachine/AppleI/AppleGLDisplay.swift
Normal file
83
FruitMachine/AppleI/AppleGLDisplay.swift
Normal file
@ -0,0 +1,83 @@
|
||||
//
|
||||
// AppleGLDisplay.swift
|
||||
// FruitMachine
|
||||
//
|
||||
// Created by Christopher Rohl on 7/30/17.
|
||||
// Copyright © 2017 Christopher Rohl. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import OpenGL
|
||||
import GLKit
|
||||
|
||||
class AppleGLDisplay: NSOpenGLView {
|
||||
|
||||
var displayLink: CVDisplayLink?
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
|
||||
// Drawing code here.
|
||||
renderFrame()
|
||||
|
||||
}
|
||||
|
||||
func doSetup() {
|
||||
let attr = [
|
||||
NSOpenGLPixelFormatAttribute(NSOpenGLPFAOpenGLProfile),
|
||||
NSOpenGLPixelFormatAttribute(NSOpenGLProfileVersion3_2Core),
|
||||
NSOpenGLPixelFormatAttribute(NSOpenGLPFAColorSize), 24,
|
||||
NSOpenGLPixelFormatAttribute(NSOpenGLPFAAlphaSize), 8,
|
||||
NSOpenGLPixelFormatAttribute(NSOpenGLPFADoubleBuffer),
|
||||
NSOpenGLPixelFormatAttribute(NSOpenGLPFADepthSize), 32,
|
||||
0
|
||||
]
|
||||
|
||||
self.pixelFormat = NSOpenGLPixelFormat(attributes: attr)
|
||||
self.openGLContext = NSOpenGLContext(format: pixelFormat!, share: nil)
|
||||
}
|
||||
|
||||
override func prepareOpenGL() {
|
||||
|
||||
func displayLinkOutputCallback(displayLink: CVDisplayLink, _ now: UnsafePointer<CVTimeStamp>, _ outputTime: UnsafePointer<CVTimeStamp>, _ flagsIn: CVOptionFlags, _ flagsOut: UnsafeMutablePointer<CVOptionFlags>, _ displayLinkContext: UnsafeMutableRawPointer?) -> CVReturn {
|
||||
unsafeBitCast(displayLinkContext, to: AppleGLDisplay.self).renderFrame()
|
||||
return kCVReturnSuccess
|
||||
}
|
||||
|
||||
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink)
|
||||
CVDisplayLinkSetOutputCallback(displayLink!, displayLinkOutputCallback, UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()))
|
||||
CVDisplayLinkStart(displayLink!)
|
||||
}
|
||||
|
||||
func renderFrame() {
|
||||
CGLLockContext((self.openGLContext?.cglContextObj!)!)
|
||||
CGLSetCurrentContext((self.openGLContext?.cglContextObj!)!)
|
||||
|
||||
// Draw something...
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GLbitfield(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
|
||||
|
||||
let vertices = [GLfloat]([-1, -1, 0,
|
||||
-1, 1, 0,
|
||||
1, 1, 0,
|
||||
1, -1, 0])
|
||||
|
||||
let indices = [GLubyte]([0, 1, 2,
|
||||
0, 2, 3])
|
||||
|
||||
glEnableVertexAttribArray(0)
|
||||
|
||||
let ptr = UnsafePointer<GLfloat>(vertices)
|
||||
glVertexAttribPointer(0, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(MemoryLayout<GLfloat>.size), ptr)
|
||||
|
||||
glDrawElements(GLenum(GL_TRIANGLES), 6, GLenum(GL_UNSIGNED_BYTE), indices)
|
||||
|
||||
CGLFlushDrawable((self.openGLContext?.cglContextObj!)!)
|
||||
CGLUnlockContext((self.openGLContext?.cglContextObj!)!)
|
||||
}
|
||||
|
||||
deinit {
|
||||
CVDisplayLinkStop(displayLink!)
|
||||
}
|
||||
|
||||
}
|
@ -25,7 +25,9 @@ class AppleI: NSObject {
|
||||
let emulatorViewDelegate = AppleIBitmapDisplay()
|
||||
let emulatorView = AppleScreenView(frame: NSMakeRect(0, 0, 640, 384))
|
||||
let emuScreenLayer = CALayer()
|
||||
let emuMetalLayer = CAMetalLayer()
|
||||
|
||||
//OpenGL
|
||||
let emuGLView = AppleGLDisplay()
|
||||
|
||||
static let CPU_FREQUENCY = 1000000
|
||||
static let FRAMES_PER_SECOND = 60
|
||||
@ -43,6 +45,9 @@ class AppleI: NSObject {
|
||||
emuScreenLayer.setNeedsDisplay()
|
||||
emulatorView.layer?.addSublayer(emuScreenLayer)
|
||||
|
||||
//GL
|
||||
emuGLView.frame = emulatorView.bounds
|
||||
|
||||
installOverrides()
|
||||
|
||||
for (cellNum, character) in terminal.characters.enumerated() {
|
||||
@ -78,5 +83,8 @@ class AppleI: NSObject {
|
||||
|
||||
emulatorView.setNeedsDisplay(emulatorView.frame)
|
||||
emulatorView.display()
|
||||
|
||||
//emuGLView.setNeedsDisplay(emuGLView.frame)
|
||||
//emuGLView.display()
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
//
|
||||
// AppleIMetalView.swift
|
||||
// FruitMachine
|
||||
//
|
||||
// Created by Christopher Rohl on 7/30/17.
|
||||
// Copyright © 2017 Christopher Rohl. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import Metal
|
||||
import MetalKit
|
||||
|
||||
class AppleIMetalView: MTKView {
|
||||
var commandQueue: MTLCommandQueue?
|
||||
var renderPipelineState: MTLRenderPipelineState?
|
||||
var depthStencilState: MTLDepthStencilState?
|
||||
|
||||
required init(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
|
||||
// Device
|
||||
device = MTLCreateSystemDefaultDevice()
|
||||
}
|
||||
}
|
@ -8,7 +8,8 @@
|
||||
|
||||
import Cocoa
|
||||
import CoreGraphics
|
||||
import MetalKit
|
||||
import OpenGL
|
||||
import GLKit
|
||||
|
||||
class MainViewController: NSViewController {
|
||||
|
||||
@ -28,6 +29,9 @@ class MainViewController: NSViewController {
|
||||
// Do view setup here.
|
||||
self.view.addSubview(computer.emulatorView)
|
||||
|
||||
//computer.emuGLView.doSetup()
|
||||
//self.view.addSubview(computer.emuGLView)
|
||||
|
||||
self.frameTimer = Timer.scheduledTimer(timeInterval: 1/60, target: self, selector: #selector(runEmulation), userInfo: nil, repeats: true)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user