From 88f2dfdb53addbef316c623c567aec0d0241ffee Mon Sep 17 00:00:00 2001 From: rogerman Date: Wed, 27 Apr 2022 04:52:25 -0700 Subject: [PATCH] Cocoa Port: Fix a longstanding bug where OpenGL video blitter would fail to render to window correctly on Retina displays. --- desmume/src/frontend/cocoa/OGLDisplayOutput.cpp | 4 ++-- .../cocoa/userinterface/DisplayWindowController.mm | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/desmume/src/frontend/cocoa/OGLDisplayOutput.cpp b/desmume/src/frontend/cocoa/OGLDisplayOutput.cpp index a89eee30a..64835d0ce 100644 --- a/desmume/src/frontend/cocoa/OGLDisplayOutput.cpp +++ b/desmume/src/frontend/cocoa/OGLDisplayOutput.cpp @@ -6516,7 +6516,7 @@ void OGLHUDLayer::RenderOGL(bool isRenderingFlipped) if (this->_needUpdateViewport) { - glUniform2f(this->_uniformViewSize, this->_output->GetPresenterProperties().clientWidth, this->_output->GetPresenterProperties().clientHeight); + glUniform2f(this->_uniformViewSize, this->_output->GetViewportWidth(), this->_output->GetViewportHeight()); glUniform1i(this->_uniformRenderFlipped, (isRenderingFlipped) ? GL_TRUE : GL_FALSE); this->_needUpdateViewport = false; } @@ -6589,7 +6589,7 @@ void OGLHUDLayer::RenderOGL(bool isRenderingFlipped) glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); // Finally, draw each character inside the box. - const GLfloat textBoxScale = (GLfloat)HUD_TEXTBOX_BASE_SCALE * this->_output->GetHUDObjectScale() / this->_output->GetScaleFactor(); + const GLfloat textBoxScale = (GLfloat)HUD_TEXTBOX_BASE_SCALE * this->_output->GetHUDObjectScale(); if (textBoxScale >= (2.0/3.0)) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); diff --git a/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm b/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm index d85cc9988..7111269b0 100644 --- a/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm +++ b/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm @@ -2101,6 +2101,13 @@ static std::unordered_map _screenMap; // localLayer = macOGLCDV->GetCALayer(); +#if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) + if ([[self window] respondsToSelector:@selector(backingScaleFactor)] && [localLayer respondsToSelector:@selector(setContentsScale:)]) + { + [localLayer setContentsScale:[[self window] backingScaleFactor]]; + } +#endif + // For macOS 10.8 Mountain Lion and later, we can use the CAOpenGLLayer directly. But for // earlier versions of macOS, using the CALayer directly will cause too many strange issues, // so we'll just keep using the old-school NSOpenGLContext for these older macOS versions. @@ -2268,7 +2275,8 @@ static std::unordered_map _screenMap; // } else if ([localLayer isKindOfClass:[CAOpenGLLayer class]]) { - [localLayer setBounds:CGRectMake(0.0f, 0.0f, props.clientWidth, props.clientHeight)]; + const double scaleFactor = [[self cdsVideoOutput] clientDisplay3DView]->Get3DPresenter()->GetScaleFactor(); + [localLayer setBounds:CGRectMake(0.0f, 0.0f, props.clientWidth / scaleFactor, props.clientHeight / scaleFactor)]; } #ifdef ENABLE_APPLE_METAL else if ([localLayer isKindOfClass:[CAMetalLayer class]])