Skip to content

Use best available GL API #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DeltaCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
9B6047D8283A4AAB00589F2E /* EAGLContext+BestAvailable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B6047D5283A496E00589F2E /* EAGLContext+BestAvailable.swift */; };
BF0B260B23E91745007BE38B /* Bundle+Resources.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0B260A23E91745007BE38B /* Bundle+Resources.swift */; };
BF0BC4FA225C138A000151C6 /* BitmapProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0BC4F9225C138A000151C6 /* BitmapProcessor.swift */; };
BF0BC4FD225C15E8000151C6 /* OpenGLESProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0BC4FC225C15E8000151C6 /* OpenGLESProcessor.swift */; };
Expand Down Expand Up @@ -97,6 +98,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
9B6047D5283A496E00589F2E /* EAGLContext+BestAvailable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EAGLContext+BestAvailable.swift"; sourceTree = "<group>"; };
BF0B260A23E91745007BE38B /* Bundle+Resources.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+Resources.swift"; sourceTree = "<group>"; };
BF0BC4F9225C138A000151C6 /* BitmapProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitmapProcessor.swift; sourceTree = "<group>"; };
BF0BC4FC225C15E8000151C6 /* OpenGLESProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenGLESProcessor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -371,6 +373,7 @@
BFA5FCF320D3804300A3C5AB /* UIApplication+AppExtension.swift */,
BFA5FCF420D3804400A3C5AB /* UIResponder+FirstResponder.swift */,
BF0B260A23E91745007BE38B /* Bundle+Resources.swift */,
9B6047D5283A496E00589F2E /* EAGLContext+BestAvailable.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -606,6 +609,7 @@
BFB8F0D41D186D6000D9CD05 /* Game.swift in Sources */,
BFEC24031D24CE7B00B3A6A9 /* RingBuffer.swift in Sources */,
BFBAE94520CC6E1A00E78FBC /* ExtensibleEnums.swift in Sources */,
9B6047D8283A4AAB00589F2E /* EAGLContext+BestAvailable.swift in Sources */,
BFEC23CD1D247E4A00B3A6A9 /* AudioRendering.swift in Sources */,
BF3273D51B86428200494CFC /* ExternalGameControllerManager.swift in Sources */,
BF78880D1C27F5AB0088084C /* UIImage+PDF.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion DeltaCore/Emulator Core/Video/OpenGLESProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OpenGLESProcessor: VideoProcessor
init(videoFormat: VideoFormat, context: EAGLContext)
{
self.videoFormat = videoFormat
self.context = EAGLContext(api: .openGLES2, sharegroup: context.sharegroup)!
self.context = EAGLContext.createUsingBestAvailableAPI(sharegroup: context.sharegroup)
}

deinit
Expand Down
2 changes: 1 addition & 1 deletion DeltaCore/Emulator Core/Video/VideoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class VideoManager: NSObject, VideoRendering
public init(videoFormat: VideoFormat)
{
self.videoFormat = videoFormat
self.context = EAGLContext(api: .openGLES2)!
self.context = EAGLContext.createUsingBestAvailableAPI()
self.ciContext = CIContext(eaglContext: self.context, options: [.workingColorSpace: NSNull()])

switch videoFormat.format
Expand Down
35 changes: 35 additions & 0 deletions DeltaCore/Extensions/EAGLContext+BestAvailable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// EAGLContext+BestAvailable.swift
// DeltaCore
//
// Created by David Chavez on 22.05.22.
// Copyright © 2022 Riley Testut. All rights reserved.
//

import GLKit

extension EAGLContext {
static func createUsingBestAvailableAPI(sharegroup: EAGLSharegroup? = nil) -> EAGLContext {
if let sharegroup = sharegroup {
var context = EAGLContext(api: .openGLES3, sharegroup: sharegroup)
if context == nil {
context = EAGLContext(api: .openGLES2, sharegroup: sharegroup)
if context == nil {
context = EAGLContext(api: .openGLES1, sharegroup: sharegroup)
}
}

return context!
}

var context = EAGLContext(api: .openGLES3)
if context == nil {
context = EAGLContext(api: .openGLES2)
if context == nil {
context = EAGLContext(api: .openGLES1)
}
}

return context!
}
}
6 changes: 3 additions & 3 deletions DeltaCore/UI/Game/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class GameView: UIView
// to self.glkView may crash if we've already rendered to a game view.
EAGLContext.setCurrent(nil)

self.glkView.context = EAGLContext(api: .openGLES2, sharegroup: newValue.sharegroup)!
self.glkView.context = EAGLContext.createUsingBestAvailableAPI(sharegroup: newValue.sharegroup)
self.context = self.makeContext()
}
}
Expand All @@ -103,7 +103,7 @@ public class GameView: UIView

public override init(frame: CGRect)
{
let eaglContext = EAGLContext(api: .openGLES2)!
let eaglContext = EAGLContext.createUsingBestAvailableAPI()
self.glkView = GLKView(frame: CGRect.zero, context: eaglContext)

super.init(frame: frame)
Expand All @@ -113,7 +113,7 @@ public class GameView: UIView

public required init?(coder aDecoder: NSCoder)
{
let eaglContext = EAGLContext(api: .openGLES2)!
let eaglContext = EAGLContext.createUsingBestAvailableAPI()
self.glkView = GLKView(frame: CGRect.zero, context: eaglContext)

super.init(coder: aDecoder)
Expand Down