Last active
October 28, 2016 23:48
-
-
Save iche033/e0080a592c890cc9a4fce31f6863a5ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 108ab0bcc696 RenderSystems/GL/src/OSX/OgreOSXCocoaWindow.mm | |
--- a/RenderSystems/GL/src/OSX/OgreOSXCocoaWindow.mm Fri Jul 15 02:11:59 2016 +0200 | |
+++ b/RenderSystems/GL/src/OSX/OgreOSXCocoaWindow.mm Fri Oct 28 16:47:45 2016 -0700 | |
@@ -246,8 +246,8 @@ | |
mActive = true; | |
mClosed = false; | |
mName = [windowTitle cStringUsingEncoding:NSUTF8StringEncoding]; | |
- mWidth = width; | |
- mHeight = height; | |
+ mWidth = width * mContentScalingFactor; | |
+ mHeight = height * mContentScalingFactor; | |
mColourDepth = depth; | |
mFSAA = fsaa_samples; | |
@@ -275,11 +275,10 @@ | |
OgreView *view = (OgreView*)StringConverter::parseUnsignedLong(opt->second); | |
[view setOgreWindow:this]; | |
mView = view; | |
- | |
+ } | |
NSRect b = [mView bounds]; | |
- mWidth = (int)b.size.width; | |
- mHeight = (int)b.size.height; | |
- } | |
+ mWidth = (int)b.size.width * mContentScalingFactor; | |
+ mHeight = (int)b.size.height * mContentScalingFactor; | |
mWindow = [mView window]; | |
mIsExternal = true; | |
@@ -290,8 +289,6 @@ | |
// Create register the context with the rendersystem and associate it with this window | |
mContext = OGRE_NEW OSXCocoaContext(mGLContext, mGLPixelFormat); | |
- mContext->mBackingWidth = mWidth * mContentScalingFactor; | |
- mContext->mBackingHeight = mHeight * mContentScalingFactor; | |
// Create the window delegate instance to handle window resizing and other window events | |
mWindowDelegate = [[OSXCocoaWindowDelegate alloc] initWithNSWindow:mWindow ogreWindow:this]; | |
@@ -328,30 +325,21 @@ | |
[pool drain]; | |
StringStream ss; | |
+ ss << "[Cocoa Window with content scaling fix] \n"; | |
ss << "Cocoa: Window created " << mWidth << " x " << mHeight | |
- << " with backing store size " << mContext->mBackingWidth << " x " << mContext->mBackingHeight | |
+ << " with backing store size " << mWidth << " x " << mHeight | |
<< " using content scaling factor " << std::fixed << std::setprecision(1) << mContentScalingFactor; | |
LogManager::getSingleton().logMessage(ss.str()); | |
} | |
unsigned int OSXCocoaWindow::getWidth() const | |
{ | |
- NSRect winFrame; | |
- if(mContentScalingSupported && mContentScalingFactor > 1.0) | |
- winFrame = [mWindow convertRectToBacking:[mWindow contentRectForFrameRect:[mView frame]]]; | |
- else | |
- winFrame = [mView frame]; | |
- return (unsigned int) winFrame.size.width; | |
+ return mWidth; | |
} | |
unsigned int OSXCocoaWindow::getHeight() const | |
{ | |
- NSRect winFrame; | |
- if(mContentScalingSupported && mContentScalingFactor > 1.0) | |
- winFrame = [mWindow convertRectToBacking:[mWindow contentRectForFrameRect:[mView frame]]]; | |
- else | |
- winFrame = [mView frame]; | |
- return (unsigned int) winFrame.size.height; | |
+ return mHeight; | |
} | |
void OSXCocoaWindow::destroy(void) | |
@@ -503,13 +491,13 @@ | |
if(mIsFullScreen) | |
return; | |
+ mWidth = width * mContentScalingFactor; | |
+ mHeight = height * mContentScalingFactor; | |
+ | |
// Check if the window size really changed | |
if(mWidth == width && mHeight == height) | |
return; | |
- mWidth = width * mContentScalingFactor; | |
- mHeight = height * mContentScalingFactor; | |
- | |
if(mIsExternal) | |
{ | |
NSRect viewFrame = [mView frame]; | |
@@ -520,6 +508,8 @@ | |
mLeft = viewFrame.origin.x; | |
mTop = windowFrame.size.height - (viewFrame.origin.y + viewFrame.size.height); | |
+ mLeft = mLeft * mContentScalingFactor; | |
+ mTop = mTop * mContentScalingFactor; | |
mWindowOrigin = NSMakePoint(mLeft, mTop); | |
GLint bufferRect[4]; | |
@@ -555,12 +545,22 @@ | |
bufferRect[1] = windowFrame.size.height - (viewFrame.origin.y + viewFrame.size.height); // 0 = bottom edge | |
bufferRect[2] = viewFrame.size.width; // width of buffer rect | |
bufferRect[3] = viewFrame.size.height; // height of buffer rect | |
+ | |
+ bufferRect[0] = bufferRect[0] * mContentScalingFactor; | |
+ bufferRect[1] = bufferRect[1] * mContentScalingFactor; | |
+ bufferRect[2] = bufferRect[2] * mContentScalingFactor; | |
+ bufferRect[3] = bufferRect[3] * mContentScalingFactor; | |
+ | |
CGLContextObj ctx = (CGLContextObj)[mGLContext CGLContextObj]; | |
CGLSetParameter(ctx, kCGLCPSwapRectangle, bufferRect); | |
[mGLContext update]; | |
mLeft = viewFrame.origin.x; | |
mTop = screenFrame.size.height - viewFrame.size.height; | |
+ | |
+ mLeft = mLeft * mContentScalingFactor; | |
+ mTop = mTop * mContentScalingFactor; | |
+ | |
mWindowOrigin = NSMakePoint(mLeft, mTop); | |
} | |
@@ -586,6 +586,11 @@ | |
mLeft = (int)winFrame.origin.x; | |
mTop = screenFrame.size.height - winFrame.size.height; | |
+ mWidth = mWidth * mContentScalingFactor; | |
+ mHeight = mHeight * mContentScalingFactor; | |
+ mLeft = mLeft * mContentScalingFactor; | |
+ mTop = mTop * mContentScalingFactor; | |
+ | |
mWindowOrigin = NSMakePoint(mLeft, mTop); | |
for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) | |
@@ -739,7 +744,8 @@ | |
CGLSetParameter((CGLContextObj)[mGLContext CGLContextObj], kCGLCPSurfaceBackingSize, backingStoreDimensions); | |
CGLDisable((CGLContextObj)[mGLContext CGLContextObj], kCGLCESurfaceBackingSize); | |
- NSRect viewRect = NSMakeRect(mWindowOrigin.x, mWindowOrigin.y, mWidth, mHeight); | |
+ NSRect viewRect = NSMakeRect(mWindowOrigin.x, mWindowOrigin.y, | |
+ mWidth / mContentScalingFactor, mHeight / mContentScalingFactor); | |
[mWindow setFrame:viewRect display:YES]; | |
[mView setFrame:viewRect]; | |
[mWindow setStyleMask:NSResizableWindowMask|NSTitledWindowMask]; | |
@@ -764,6 +770,8 @@ | |
void OSXCocoaWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height) | |
{ | |
+ width = width * mContentScalingFactor; | |
+ height = height * mContentScalingFactor; | |
if (mIsFullScreen != fullScreen || width != mWidth || height != mHeight) | |
{ | |
// Set the full screen flag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment