[Visualization] Use OpenGL on legacy systems

On legacy OSes, and legacy GPUs, it should use OpenGL and not Metal,
otherwise there could be horrible performance, or even crashes.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-05-23 17:21:13 -07:00
parent c59d4d0215
commit 4b2cf22800
1 changed files with 20 additions and 2 deletions

View File

@ -7,6 +7,8 @@
#import "SpectrumView.h"
#import <Metal/Metal.h>
#import "analyzer.h"
#define LOWER_BOUND -80
@ -26,6 +28,7 @@ extern NSString *CogPlaybackDidStopNotficiation;
BOOL isListening;
BOOL bandsReset;
BOOL cameraControlEnabled;
BOOL isOpenGL;
NSColor *backgroundColor;
ddb_analyzer_t _analyzer;
@ -44,9 +47,20 @@ extern NSString *CogPlaybackDidStopNotficiation;
- (id)initWithFrame:(NSRect)frame {
NSDictionary *sceneOptions = @{
SCNPreferredRenderingAPIKey: @(SCNRenderingAPIMetal),
SCNPreferLowPowerDeviceKey: @(YES)
SCNPreferredRenderingAPIKey: @(SCNRenderingAPIOpenGLCore32)
};
isOpenGL = YES;
if(@available(macOS 10.15, *)) {
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
if([device supportsFamily:MTLGPUFamilyMac2]) {
sceneOptions = @{
SCNPreferredRenderingAPIKey: @(SCNRenderingAPIMetal),
SCNPreferredDeviceKey: device
};
isOpenGL = NO;
}
}
self = [super initWithFrame:frame options:sceneOptions];
if(self) {
@ -103,6 +117,8 @@ extern NSString *CogPlaybackDidStopNotficiation;
SCNMaterial *material = materials[0];
material.diffuse.contents = barColor;
material.emission.contents = barColor;
if(isOpenGL)
material.emission.intensity = 0;
}
{
@ -112,6 +128,8 @@ extern NSString *CogPlaybackDidStopNotficiation;
SCNMaterial *material = materials[0];
material.diffuse.contents = dotColor;
material.emission.contents = dotColor;
if(isOpenGL)
material.emission.intensity = 0;
}
}