cocoa: implement GL_GetDrawableSize for OpenGL ES

This commit is contained in:
Steven Noonan 2021-04-09 07:44:38 -07:00 committed by Steven Noonan
parent e8fbb02d16
commit 3d8a7e4c15
No known key found for this signature in database
GPG key ID: 408EEB508ED0CD4D
4 changed files with 32 additions and 1 deletions

View file

@ -39,6 +39,8 @@ extern int Cocoa_GLES_LoadLibrary(_THIS, const char *path);
extern SDL_GLContext Cocoa_GLES_CreateContext(_THIS, SDL_Window * window);
extern int Cocoa_GLES_SwapWindow(_THIS, SDL_Window * window);
extern int Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
extern void Cocoa_GLES_GetDrawableSize(_THIS, SDL_Window * window,
int * w, int * h);
extern void Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context);
extern int Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window);
extern SDL_EGLSurface Cocoa_GLES_GetEGLSurface(_THIS, SDL_Window * window);

View file

@ -114,8 +114,29 @@ Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
return SDL_EGL_MakeCurrent(_this, window ? ((__bridge SDL_WindowData *) window->driverdata).egl_surface : EGL_NO_SURFACE, context);
}}
void
Cocoa_GLES_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *)window->driverdata;
NSView *contentView = windata.nswindow.contentView;
CALayer *layer = [contentView layer];
int width = layer.bounds.size.width * layer.contentsScale;
int height = layer.bounds.size.height * layer.contentsScale;
if (w) {
*w = width;
}
if (h) {
*h = height;
}
}}
int
Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSView* v;
/* The current context is lost in here; save it and reset it. */
@ -145,7 +166,7 @@ Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
}
return Cocoa_GLES_MakeCurrent(_this, current_win, current_ctx);
}
}}
SDL_EGLSurface
Cocoa_GLES_GetEGLSurface(_THIS, SDL_Window * window)

View file

@ -150,6 +150,7 @@ Cocoa_CreateDevice(void)
device->GL_UnloadLibrary = Cocoa_GLES_UnloadLibrary;
device->GL_CreateContext = Cocoa_GLES_CreateContext;
device->GL_MakeCurrent = Cocoa_GLES_MakeCurrent;
device->GL_GetDrawableSize = Cocoa_GLES_GetDrawableSize;
device->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval;
device->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval;
device->GL_SwapWindow = Cocoa_GLES_SwapWindow;

View file

@ -1787,6 +1787,13 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
if ((window->flags & SDL_WINDOW_OPENGL) &&
_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
[contentView setWantsLayer:TRUE];
if (!(window->flags & SDL_WINDOW_ALLOW_HIGHDPI)) {
contentView.layer.contentsScale = 1;
} else {
if ([nswindow.screen respondsToSelector:@selector(backingScaleFactor)]) {
contentView.layer.contentsScale = nswindow.screen.backingScaleFactor;
}
}
}
#endif /* SDL_VIDEO_OPENGL_EGL */
#endif /* SDL_VIDEO_OPENGL_ES2 */