Last active
December 23, 2016 01:18
-
-
Save iche033/c43103f739d981af847e8ed6d790baf6 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 Thu Dec 22 17:18:10 2016 -0800 | |
@@ -86,7 +86,7 @@ | |
mWindowDelegate = nil; | |
} | |
} | |
- | |
+ | |
void OSXCocoaWindow::create(const String& name, unsigned int width, unsigned int height, | |
bool fullScreen, const NameValuePairList *miscParams) | |
{ | |
@@ -128,17 +128,17 @@ | |
int depth = 32; | |
NameValuePairList::const_iterator opt; | |
mIsFullScreen = fullScreen; | |
- | |
+ | |
if(miscParams) | |
{ | |
opt = miscParams->find("title"); | |
if(opt != miscParams->end()) | |
windowTitle = [NSString stringWithCString:opt->second.c_str() encoding:NSUTF8StringEncoding]; | |
- | |
+ | |
opt = miscParams->find("left"); | |
if(opt != miscParams->end()) | |
winx = StringConverter::parseUnsignedInt(opt->second); | |
- | |
+ | |
opt = miscParams->find("top"); | |
if(opt != miscParams->end()) | |
winy = (int)NSHeight([[NSScreen mainScreen] frame]) - StringConverter::parseUnsignedInt(opt->second) - height; | |
@@ -150,11 +150,11 @@ | |
opt = miscParams->find("depthBuffer"); | |
if(opt != miscParams->end()) | |
hasDepthBuffer = StringConverter::parseBool(opt->second); | |
- | |
+ | |
opt = miscParams->find("FSAA"); | |
if(opt != miscParams->end()) | |
fsaa_samples = StringConverter::parseUnsignedInt(opt->second); | |
- | |
+ | |
opt = miscParams->find("gamma"); | |
if(opt != miscParams->end()) | |
mHwGamma = StringConverter::parseBool(opt->second); | |
@@ -176,7 +176,7 @@ | |
{ | |
NSOpenGLPixelFormatAttribute attribs[30]; | |
int i = 0; | |
- | |
+ | |
// Specify the display ID to associate the GL context with (main display for now) | |
// Useful if there is ambiguity | |
attribs[i++] = NSOpenGLPFAScreenMask; | |
@@ -186,7 +186,7 @@ | |
// This makes the View-based context a compatible with the fullscreen context, enabling us to use | |
// the "shareContext" feature to share textures, display lists, and other OpenGL objects between the two. | |
attribs[i++] = NSOpenGLPFANoRecovery; | |
- | |
+ | |
attribs[i++] = NSOpenGLPFAAccelerated; | |
attribs[i++] = NSOpenGLPFADoubleBuffer; | |
@@ -195,23 +195,23 @@ | |
attribs[i++] = NSOpenGLPFAAlphaSize; | |
attribs[i++] = (NSOpenGLPixelFormatAttribute) 8; | |
- | |
+ | |
attribs[i++] = NSOpenGLPFAStencilSize; | |
attribs[i++] = (NSOpenGLPixelFormatAttribute) 8; | |
attribs[i++] = NSOpenGLPFADepthSize; | |
attribs[i++] = (NSOpenGLPixelFormatAttribute) (hasDepthBuffer? 16 : 0); | |
- | |
+ | |
if(fsaa_samples > 0) | |
{ | |
attribs[i++] = NSOpenGLPFAMultisample; | |
attribs[i++] = NSOpenGLPFASampleBuffers; | |
attribs[i++] = (NSOpenGLPixelFormatAttribute) 1; | |
- | |
+ | |
attribs[i++] = NSOpenGLPFASamples; | |
attribs[i++] = (NSOpenGLPixelFormatAttribute) fsaa_samples; | |
} | |
- | |
+ | |
attribs[i++] = (NSOpenGLPixelFormatAttribute) 0; | |
mGLPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs]; | |
@@ -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; | |
@@ -265,7 +265,7 @@ | |
mUseNSView = true; | |
// If the macAPICocoaUseNSView parameter was set, use the winhandler as pointer to an NSView | |
// Otherwise we assume the user created the interface with Interface Builder and instantiated an OgreView. | |
- | |
+ | |
if(mUseNSView) { | |
LogManager::getSingleton().logMessage("Mac Cocoa Window: Rendering on an external plain NSView*"); | |
NSView *nsview = (NSView*)StringConverter::parseUnsignedLong(opt->second); | |
@@ -275,10 +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]; | |
@@ -290,8 +290,8 @@ | |
// 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; | |
+ // 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]; | |
@@ -313,13 +313,13 @@ | |
#endif | |
// Enable GL multithreading | |
- CGLEnable((CGLContextObj)[mGLContext CGLContextObj], kCGLCEMPEngine); | |
+ // CGLEnable((CGLContextObj)[mGLContext CGLContextObj], kCGLCEMPEngine); | |
// Fix garbage screen | |
glViewport(0, 0, mWidth, mHeight); | |
glClearColor(0, 0, 0, 1); | |
glClear(GL_COLOR_BUFFER_BIT); | |
- | |
+ | |
[mGLContext update]; | |
[mGLContext flushBuffer]; | |
@@ -329,7 +329,8 @@ | |
StringStream ss; | |
ss << "Cocoa: Window created " << mWidth << " x " << mHeight | |
- << " with backing store size " << mContext->mBackingWidth << " x " << mContext->mBackingHeight | |
+ // << " 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()); | |
} | |
@@ -359,25 +360,49 @@ | |
if(!mIsFullScreen) | |
{ | |
// Unregister and destroy OGRE GLContext | |
+ | |
+ StringStream sss; | |
+ sss << " ========================== mContext release "; | |
+ LogManager::getSingleton().logMessage(sss.str()); | |
+ | |
OGRE_DELETE mContext; | |
- | |
+ | |
if(!mIsExternal) | |
{ | |
+ StringStream ssss; | |
+ ssss << "WindowEventUtilities remove "; | |
+ LogManager::getSingleton().logMessage(ssss.str()); | |
+ | |
// Remove the window from the Window listener | |
WindowEventUtilities::_removeRenderWindow(this); | |
} | |
if(mGLContext) | |
{ | |
+ StringStream ss; | |
+ ss << "glcontext release "; | |
+ LogManager::getSingleton().logMessage(ss.str()); | |
+ | |
[mGLContext release]; | |
mGLContext = nil; | |
+ | |
+ ss << " done "; | |
+ LogManager::getSingleton().logMessage(ss.str()); | |
} | |
if(mWindow) | |
{ | |
+ StringStream aa; | |
+ aa << "close window "; | |
+ LogManager::getSingleton().logMessage(aa.str()); | |
+ | |
if(!mIsExternal) | |
[mWindow performClose:nil]; | |
+ aa << " done "; | |
+ LogManager::getSingleton().logMessage(aa.str()); | |
+ | |
+ | |
if(mGLPixelFormat) | |
{ | |
[mGLPixelFormat release]; | |
@@ -386,7 +411,7 @@ | |
} | |
} | |
- | |
+ | |
mActive = false; | |
mClosed = true; | |
} | |
@@ -417,16 +442,16 @@ | |
{ | |
mVSync = vsync; | |
mContext->setCurrent(); | |
- | |
+ | |
GLint vsyncInterval = mVSync ? 1 : 0; | |
[mGLContext setValues:&vsyncInterval forParameter:NSOpenGLCPSwapInterval]; | |
mContext->endCurrent(); | |
- | |
+ | |
if(mGLContext != [NSOpenGLContext currentContext]) | |
[mGLContext makeCurrentContext]; | |
} | |
- | |
+ | |
bool OSXCocoaWindow::isVSyncEnabled() const | |
{ | |
return mVSync; | |
@@ -442,22 +467,22 @@ | |
"Invalid box.", | |
"CocoaWindow::copyContentsToMemory" ); | |
} | |
- | |
+ | |
if (buffer == FB_AUTO) | |
{ | |
buffer = mIsFullScreen? FB_FRONT : FB_BACK; | |
} | |
- | |
+ | |
GLenum format = GLPixelUtil::getGLOriginFormat(dst.format); | |
GLenum type = GLPixelUtil::getGLOriginDataType(dst.format); | |
- | |
+ | |
if ((format == GL_NONE) || (type == 0)) | |
{ | |
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, | |
"Unsupported format.", | |
"CocoaWindow::copyContentsToMemory" ); | |
} | |
- | |
+ | |
if(dst.getWidth() != dst.rowPitch) | |
{ | |
glPixelStorei(GL_PACK_ROW_LENGTH, static_cast<GLint>(dst.rowPitch)); | |
@@ -467,15 +492,15 @@ | |
// Standard alignment of 4 is not right | |
glPixelStorei(GL_PACK_ALIGNMENT, 1); | |
} | |
- | |
+ | |
glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK); | |
glReadPixels((GLint)0, (GLint)(mHeight - dst.getHeight()), | |
(GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(), | |
format, type, dst.getTopLeftFrontPixelPtr()); | |
- | |
+ | |
glPixelStorei(GL_PACK_ALIGNMENT, 4); | |
glPixelStorei(GL_PACK_ROW_LENGTH, 0); | |
- | |
+ | |
PixelUtil::bulkPixelVerticalFlip(dst); | |
} | |
@@ -499,7 +524,7 @@ | |
{ | |
if(!mWindow) | |
return; | |
- | |
+ | |
if(mIsFullScreen) | |
return; | |
@@ -513,20 +538,22 @@ | |
if(mIsExternal) | |
{ | |
NSRect viewFrame = [mView frame]; | |
- viewFrame.size.width = width; | |
- viewFrame.size.height = height; | |
+ viewFrame.size.width = mWidth; | |
+ viewFrame.size.height = mHeight; | |
NSRect windowFrame = [[mView window] frame]; | |
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]; | |
- bufferRect[0] = mLeft; // 0 = left edge | |
- bufferRect[1] = mTop; // 0 = bottom edge | |
- bufferRect[2] = mWidth; // width of buffer rect | |
- bufferRect[3] = mHeight; // height of buffer rect | |
+ bufferRect[0] = mLeft; // 0 = left edge | |
+ bufferRect[1] = mTop; // 0 = bottom edge | |
+ bufferRect[2] = mWidth; // width of buffer rect | |
+ bufferRect[3] = mHeight; // height of buffer rect | |
CGLContextObj ctx = (CGLContextObj)[mGLContext CGLContextObj]; | |
CGLSetParameter(ctx, kCGLCPSwapRectangle, bufferRect); | |
} | |
@@ -551,22 +578,28 @@ | |
NSRect screenFrame = [[NSScreen mainScreen] visibleFrame]; | |
GLint bufferRect[4]; | |
- bufferRect[0] = viewFrame.origin.x; // 0 = left edge | |
- 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] = viewFrame.origin.x; // 0 = left edge | |
+ 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; | |
+ mLeft = viewFrame.origin.x; | |
mTop = screenFrame.size.height - viewFrame.size.height; | |
mWindowOrigin = NSMakePoint(mLeft, mTop); | |
} | |
- | |
- for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) | |
- { | |
- (*it).second->_updateDimensions(); | |
+ | |
+ for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) | |
+ { | |
+ (*it).second->_updateDimensions(); | |
} | |
} | |
@@ -575,7 +608,7 @@ | |
// Ensure the context is current | |
[mGLContext flushBuffer]; | |
} | |
- | |
+ | |
void OSXCocoaWindow::windowMovedOrResized() | |
{ | |
NSRect winFrame = [mWindow frame]; | |
@@ -586,6 +619,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) | |
@@ -606,36 +644,36 @@ | |
[mGLContext flushBuffer]; | |
CGLUnlockContext((CGLContextObj)[mGLContext CGLContextObj]); | |
} | |
- | |
+ | |
//-------------------------------------------------------------------------------------------------// | |
void OSXCocoaWindow::getCustomAttribute( const String& name, void* pData ) | |
{ | |
- if( name == "GLCONTEXT" ) | |
+ if( name == "GLCONTEXT" ) | |
{ | |
*static_cast<OSXContext**>(pData) = mContext; | |
return; | |
- } | |
- else if( name == "WINDOW" ) | |
+ } | |
+ else if( name == "WINDOW" ) | |
{ | |
*(void**)(pData) = mWindow; | |
return; | |
- } | |
- else if( name == "VIEW" ) | |
+ } | |
+ else if( name == "VIEW" ) | |
{ | |
*(void**)(pData) = mView; | |
return; | |
} | |
- else if( name == "NSOPENGLCONTEXT" ) | |
+ else if( name == "NSOPENGLCONTEXT" ) | |
{ | |
*(void**)(pData) = mGLContext; | |
return; | |
} | |
- else if( name == "NSOPENGLPIXELFORMAT" ) | |
+ else if( name == "NSOPENGLPIXELFORMAT" ) | |
{ | |
*(void**)(pData) = mGLPixelFormat; | |
return; | |
} | |
- | |
+ | |
} | |
void OSXCocoaWindow::createNewWindow(unsigned int width, unsigned int height, String title) | |
@@ -687,10 +725,10 @@ | |
mView = viewRef; | |
GLint bufferRect[4]; | |
- bufferRect[0] = viewBounds.origin.x; // 0 = left edge | |
- bufferRect[1] = viewBounds.origin.y; // 0 = bottom edge | |
- bufferRect[2] = viewBounds.size.width; // width of buffer rect | |
- bufferRect[3] = viewBounds.size.height; // height of buffer rect | |
+ bufferRect[0] = viewBounds.origin.x; // 0 = left edge | |
+ bufferRect[1] = viewBounds.origin.y; // 0 = bottom edge | |
+ bufferRect[2] = viewBounds.size.width; // width of buffer rect | |
+ bufferRect[3] = viewBounds.size.height; // height of buffer rect | |
CGLContextObj ctx = (CGLContextObj)[mGLContext CGLContextObj]; | |
CGLSetParameter(ctx, kCGLCPSwapRectangle, bufferRect); | |
@@ -753,9 +791,9 @@ | |
// If you do this last, there is a moment before the rendering window pops-up | |
[mGLContext makeCurrentContext]; | |
} | |
- | |
+ | |
[mGLContext update]; | |
- | |
+ | |
// Even though OgreCocoaView doesn't accept first responder, it will get passed onto the next in the chain | |
[mWindow makeFirstResponder:mView]; | |
[NSApp activateIgnoringOtherApps:YES]; | |
@@ -764,6 +802,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