mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 16:06:19 +00:00
1ec408280e
Move the deprecated setWantsBestResolutionOpenGLSurface to GL-specific code while we're here. Signed-off-by: Elias Naur <mail@eliasnaur.com>
89 lines
2.3 KiB
Objective-C
89 lines
2.3 KiB
Objective-C
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
// +build darwin,!ios
|
|
|
|
@import AppKit;
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
#include <OpenGL/OpenGL.h>
|
|
#include <OpenGL/gl3.h>
|
|
#include "_cgo_export.h"
|
|
|
|
@interface GioGLContext : NSOpenGLContext
|
|
@end
|
|
|
|
@implementation GioGLContext
|
|
- (void) notifyUpdate:(NSNotification*)notification {
|
|
CGLLockContext([self CGLContextObj]);
|
|
[self update];
|
|
CGLUnlockContext([self CGLContextObj]);
|
|
}
|
|
- (void)dealloc {
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
}
|
|
@end
|
|
|
|
CFTypeRef gio_createGLContext(void) {
|
|
@autoreleasepool {
|
|
NSOpenGLPixelFormatAttribute attr[] = {
|
|
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
|
|
NSOpenGLPFAColorSize, 24,
|
|
NSOpenGLPFADepthSize, 16,
|
|
NSOpenGLPFAAccelerated,
|
|
// Opt-in to automatic GPU switching. CGL-only property.
|
|
kCGLPFASupportsAutomaticGraphicsSwitching,
|
|
NSOpenGLPFAAllowOfflineRenderers,
|
|
0
|
|
};
|
|
NSOpenGLPixelFormat *pixFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
|
|
|
GioGLContext *ctx = [[GioGLContext alloc] initWithFormat:pixFormat shareContext: nil];
|
|
return CFBridgingRetain(ctx);
|
|
}
|
|
}
|
|
|
|
void gio_setContextView(CFTypeRef ctxRef, CFTypeRef viewRef) {
|
|
GioGLContext *ctx = (__bridge GioGLContext *)ctxRef;
|
|
NSView *view = (__bridge NSView *)viewRef;
|
|
[view setWantsBestResolutionOpenGLSurface:YES];
|
|
[ctx setView:view];
|
|
[[NSNotificationCenter defaultCenter] addObserver:ctx
|
|
selector:@selector(notifyUpdate:)
|
|
name:NSViewGlobalFrameDidChangeNotification
|
|
object:view];
|
|
}
|
|
|
|
void gio_clearCurrentContext(void) {
|
|
@autoreleasepool {
|
|
[NSOpenGLContext clearCurrentContext];
|
|
}
|
|
}
|
|
|
|
void gio_makeCurrentContext(CFTypeRef ctxRef) {
|
|
@autoreleasepool {
|
|
NSOpenGLContext *ctx = (__bridge NSOpenGLContext *)ctxRef;
|
|
[ctx makeCurrentContext];
|
|
}
|
|
}
|
|
|
|
void gio_lockContext(CFTypeRef ctxRef) {
|
|
@autoreleasepool {
|
|
NSOpenGLContext *ctx = (__bridge NSOpenGLContext *)ctxRef;
|
|
CGLLockContext([ctx CGLContextObj]);
|
|
}
|
|
}
|
|
|
|
void gio_unlockContext(CFTypeRef ctxRef) {
|
|
@autoreleasepool {
|
|
NSOpenGLContext *ctx = (__bridge NSOpenGLContext *)ctxRef;
|
|
CGLUnlockContext([ctx CGLContextObj]);
|
|
}
|
|
}
|
|
|
|
void gio_prepareContext(void) {
|
|
// Bind a default VBA to emulate OpenGL ES 2.
|
|
GLuint defVBA;
|
|
glGenVertexArrays(1, &defVBA);
|
|
glBindVertexArray(defVBA);
|
|
}
|