Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/ghost/intern/GHOST_WindowCocoa.mm')
-rw-r--r--intern/ghost/intern/GHOST_WindowCocoa.mm352
1 files changed, 117 insertions, 235 deletions
diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm
index f9b8899fbe5..8805dc93179 100644
--- a/intern/ghost/intern/GHOST_WindowCocoa.mm
+++ b/intern/ghost/intern/GHOST_WindowCocoa.mm
@@ -20,30 +20,33 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): Maarten Gribnau 05/2001
- Damien Plisson 10/2009
+ * Contributor(s): Maarten Gribnau 05/2001
+ * Damien Plisson 10/2009
+ * Jason Wilkins 02/2014
*
* ***** END GPL LICENSE BLOCK *****
*/
+#include "GHOST_WindowCocoa.h"
+#include "GHOST_SystemCocoa.h"
+#include "GHOST_ContextNone.h"
+#include "GHOST_Debug.h"
+
+#if defined(WITH_GL_EGL)
+# include "GHOST_ContextEGL.h"
+#else
+# include "GHOST_ContextCGL.h"
+#endif
+
#include <Cocoa/Cocoa.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED <= 1050
-//Use of the SetSystemUIMode function (64bit compatible)
-#include <Carbon/Carbon.h>
+ //Use of the SetSystemUIMode function (64bit compatible)
+# include <Carbon/Carbon.h>
#endif
-#include <OpenGL/gl.h>
-#include <OpenGL/CGLRenderers.h>
-/***** Multithreaded opengl code : uncomment for enabling
-#include <OpenGL/OpenGL.h>
-*/
-#include "GHOST_WindowCocoa.h"
-#include "GHOST_SystemCocoa.h"
-#include "GHOST_Debug.h"
-
#include <sys/sysctl.h>
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
@@ -535,8 +538,6 @@ enum {
@end
#endif
-NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;
-
GHOST_WindowCocoa::GHOST_WindowCocoa(
GHOST_SystemCocoa *systemCocoa,
const STR_String& title,
@@ -548,13 +549,9 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
GHOST_TDrawingContextType type,
const bool stereoVisual, const GHOST_TUns16 numOfAASamples
) :
- GHOST_Window(width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual, false, numOfAASamples),
+ GHOST_Window(width, height, state, stereoVisual, false, numOfAASamples),
m_customCursor(0)
{
- NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[40];
- NSOpenGLPixelFormat *pixelFormat = nil;
- int i;
-
m_systemCocoa = systemCocoa;
m_fullScreen = false;
m_immediateDraw = false;
@@ -586,104 +583,10 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
minSize.height = 240;
[m_window setContentMinSize:minSize];
- setTitle(title);
-
-
- // Pixel Format Attributes for the windowed NSOpenGLContext
- i=0;
- pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
-
- // Guarantees the back buffer contents to be valid after a call to NSOpenGLContext object's flushBuffer
- // needed for 'Draw Overlap' drawing method
- pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore;
-
- // Force software OpenGL, for debugging
- if (getenv("BLENDER_SOFTWAREGL")) {
- pixelFormatAttrsWindow[i++] = NSOpenGLPFARendererID;
- pixelFormatAttrsWindow[i++] = kCGLRendererAppleSWID;
- }
- else
- pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
-
- //pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,; // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
-
- pixelFormatAttrsWindow[i++] = NSOpenGLPFADepthSize;
- pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
-
- pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccumSize;
- pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
-
- if (stereoVisual) pixelFormatAttrsWindow[i++] = NSOpenGLPFAStereo;
-
- if (numOfAASamples > 0) {
- // Multisample anti-aliasing
- pixelFormatAttrsWindow[i++] = NSOpenGLPFAMultisample;
-
- pixelFormatAttrsWindow[i++] = NSOpenGLPFASampleBuffers;
- pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 1;
-
- pixelFormatAttrsWindow[i++] = NSOpenGLPFASamples;
- pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) numOfAASamples;
-
- pixelFormatAttrsWindow[i++] = NSOpenGLPFANoRecovery;
- }
-
- pixelFormatAttrsWindow[i] = (NSOpenGLPixelFormatAttribute) 0;
-
- pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
-
-
- //Fall back to no multisampling if Antialiasing init failed
- if (pixelFormat == nil) {
- i=0;
- pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
-
- // Guarantees the back buffer contents to be valid after a call to NSOpenGLContext object's flushBuffer
- // needed for 'Draw Overlap' drawing method
- pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore;
-
- // Force software OpenGL, for debugging
- if (getenv("BLENDER_SOFTWAREGL")) {
- pixelFormatAttrsWindow[i++] = NSOpenGLPFARendererID;
- pixelFormatAttrsWindow[i++] = kCGLRendererAppleSWID;
- }
- else
- pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
-
- //pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,; // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
-
- pixelFormatAttrsWindow[i++] = NSOpenGLPFADepthSize;
- pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
-
- pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccumSize;
- pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
-
- if (stereoVisual) pixelFormatAttrsWindow[i++] = NSOpenGLPFAStereo;
-
- pixelFormatAttrsWindow[i] = (NSOpenGLPixelFormatAttribute) 0;
-
- pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
-
- }
-
- if (numOfAASamples > 0) { //Set m_numOfAASamples to the actual value
- GLint gli;
- [pixelFormat getValues:&gli forAttribute:NSOpenGLPFASamples forVirtualScreen:0];
- if (m_numOfAASamples != (GHOST_TUns16)gli) {
- m_numOfAASamples = (GHOST_TUns16)gli;
- printf("GHOST_Window could be created with anti-aliasing of only %i samples\n",m_numOfAASamples);
- }
- }
-
//Creates the OpenGL View inside the window
- m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect
- pixelFormat:pixelFormat];
-
- [m_openGLView setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
+ m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect];
- [pixelFormat release];
-
- m_openGLContext = [m_openGLView openGLContext]; //This context will be replaced by the proper one just after
+ [m_openGLView setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
[m_window setContentView:m_openGLView];
[m_window setInitialFirstResponder:m_openGLView];
@@ -694,6 +597,7 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
updateDrawingContext();
activateDrawingContext();
+ // XXX jwilkins: This seems like it belongs in GHOST_ContextCGL, but probably not GHOST_ContextEGL
if (m_systemCocoa->m_nativePixel) {
if ([m_openGLView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
[m_openGLView setWantsBestResolutionOpenGLSurface:YES];
@@ -703,6 +607,8 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
}
}
+ setTitle(title);
+
m_tablet.Active = GHOST_kTabletModeNone;
CocoaWindowDelegate *windowDelegate = [[CocoaWindowDelegate alloc] init];
@@ -750,6 +656,8 @@ GHOST_WindowCocoa::~GHOST_WindowCocoa()
m_customCursor = nil;
}
+ releaseNativeHandles();
+
[m_openGLView release];
if (m_window) {
@@ -774,7 +682,7 @@ GHOST_WindowCocoa::~GHOST_WindowCocoa()
bool GHOST_WindowCocoa::getValid() const
{
- return (m_window != 0);
+ return GHOST_Window::getValid() && m_window != 0 && m_openGLView != 0;
}
void* GHOST_WindowCocoa::getOSWindow() const
@@ -962,7 +870,12 @@ GHOST_TWindowState GHOST_WindowCocoa::getState() const
if (masks & NSFullScreenWindowMask) {
// Lion style fullscreen
- state = GHOST_kWindowStateFullScreen;
+ if (!m_immediateDraw) {
+ state = GHOST_kWindowStateFullScreen;
+ }
+ else {
+ state = GHOST_kWindowStateNormal;
+ }
}
else
#endif
@@ -976,7 +889,12 @@ GHOST_TWindowState GHOST_WindowCocoa::getState() const
state = GHOST_kWindowStateMaximized;
}
else {
+ if (m_immediateDraw) {
+ state = GHOST_kWindowStateFullScreen;
+ }
+ else {
state = GHOST_kWindowStateNormal;
+ }
}
[pool drain];
return state;
@@ -1266,131 +1184,95 @@ GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
#pragma mark Drawing context
-/*#define WAIT_FOR_VSYNC 1*/
-
-GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()
-{
- if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
- if (m_openGLContext != nil) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [m_openGLContext flushBuffer];
- [pool drain];
- return GHOST_kSuccess;
- }
- }
- return GHOST_kFailure;
-}
-
-GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()
-{
- if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
- if (m_openGLContext != nil) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [m_openGLContext update];
- [pool drain];
- return GHOST_kSuccess;
- }
- }
- return GHOST_kFailure;
-}
+GHOST_Context *GHOST_WindowCocoa::newDrawingContext(GHOST_TDrawingContextType type)
+{
+ if (type == GHOST_kDrawingContextTypeOpenGL) {
+#if !defined(WITH_GL_EGL)
+
+#if defined(WITH_GL_PROFILE_CORE)
+ GHOST_Context *context = new GHOST_ContextCGL(
+ m_initStereoVisual,
+ m_initNumOfAASamples,
+ m_window,
+ m_openGLView,
+ CGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
+ 3, 2,
+ GHOST_OPENGL_CGL_CONTEXT_FLAGS,
+ GHOST_OPENGL_CGL_RESET_NOTIFICATION_STRATEGY);
+#elif defined(WITH_GL_PROFILE_ES20)
+ GHOST_Context *context = new GHOST_ContextCGL(
+ m_initStereoVisual,
+ m_initNumOfAASamples,
+ m_window,
+ m_openGLView,
+ CGL_CONTEXT_ES2_PROFILE_BIT_EXT,
+ 2, 0,
+ GHOST_OPENGL_CGL_CONTEXT_FLAGS,
+ GHOST_OPENGL_CGL_RESET_NOTIFICATION_STRATEGY);
+#elif defined(WITH_GL_PROFILE_COMPAT)
+ GHOST_Context *context = new GHOST_ContextCGL(
+ m_wantStereoVisual,
+ m_wantNumOfAASamples,
+ m_window,
+ m_openGLView,
+ 0, // profile bit
+ 0, 0,
+ GHOST_OPENGL_CGL_CONTEXT_FLAGS,
+ GHOST_OPENGL_CGL_RESET_NOTIFICATION_STRATEGY);
+#else
+# error
+#endif
-GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()
-{
- if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
- if (m_openGLContext != nil) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [m_openGLContext makeCurrentContext];
-
- // Disable AA by default
- if (m_numOfAASamples > 0) glDisable(GL_MULTISAMPLE_ARB);
- [pool drain];
- return GHOST_kSuccess;
- }
- }
- return GHOST_kFailure;
-}
+#else
+#if defined(WITH_GL_PROFILE_CORE)
+ GHOST_Context *context = new GHOST_ContextEGL(
+ m_wantStereoVisual,
+ m_wantNumOfAASamples,
+ m_window,
+ m_openGLView,
+ EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
+ 3, 2,
+ GHOST_OPENGL_EGL_CONTEXT_FLAGS,
+ GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
+ EGL_OPENGL_API);
+#elif defined(WITH_GL_PROFILE_ES20)
+ GHOST_Context *context = new GHOST_ContextEGL(
+ m_wantStereoVisual,
+ m_wantNumOfAASamples,
+ m_window,
+ m_openGLView,
+ 0, // profile bit
+ 2, 0,
+ GHOST_OPENGL_EGL_CONTEXT_FLAGS,
+ GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
+ EGL_OPENGL_ES_API);
+#elif defined(WITH_GL_PROFILE_COMPAT)
+ GHOST_Context *context = new GHOST_ContextEGL(
+ m_wantStereoVisual,
+ m_wantNumOfAASamples,
+ m_window,
+ m_openGLView,
+ 0, // profile bit
+ 0, 0,
+ GHOST_OPENGL_EGL_CONTEXT_FLAGS,
+ GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
+ EGL_OPENGL_API);
+#else
+# error
+#endif
-GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextType type)
-{
- GHOST_TSuccess success = GHOST_kFailure;
-
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- NSOpenGLPixelFormat *pixelFormat;
- NSOpenGLContext *tmpOpenGLContext;
-
- /***** Multithreaded opengl code : uncomment for enabling
- CGLContextObj cglCtx;
- */
-
- switch (type) {
- case GHOST_kDrawingContextTypeOpenGL:
- if (!getValid()) break;
-
- pixelFormat = [m_openGLView pixelFormat];
- tmpOpenGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
- shareContext:s_firstOpenGLcontext];
- if (tmpOpenGLContext == nil) {
- success = GHOST_kFailure;
- break;
- }
-
- //Switch openGL to multhreaded mode
- /******* Multithreaded opengl code : uncomment for enabling
- cglCtx = (CGLContextObj)[tmpOpenGLContext CGLContextObj];
- if (CGLEnable(cglCtx, kCGLCEMPEngine) == kCGLNoError)
- printf("\nSwitched openGL to multithreaded mode\n");
- */
-
- if (!s_firstOpenGLcontext) s_firstOpenGLcontext = tmpOpenGLContext;
-#ifdef WAIT_FOR_VSYNC
- {
- GLint swapInt = 1;
- /* wait for vsync, to avoid tearing artifacts */
- [tmpOpenGLContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
- }
#endif
- [m_openGLView setOpenGLContext:tmpOpenGLContext];
- [tmpOpenGLContext setView:m_openGLView];
-
- m_openGLContext = tmpOpenGLContext;
- break;
-
- case GHOST_kDrawingContextTypeNone:
- success = GHOST_kSuccess;
- break;
-
- default:
- break;
+ if (context->initializeDrawingContext())
+ return context;
+ else
+ delete context;
}
- [pool drain];
- return success;
-}
-
-GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()
-{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- switch (m_drawingContextType) {
- case GHOST_kDrawingContextTypeOpenGL:
- if (m_openGLContext) {
- [m_openGLView clearGLContext];
- if (s_firstOpenGLcontext == m_openGLContext) s_firstOpenGLcontext = nil;
- m_openGLContext = nil;
- }
- [pool drain];
- return GHOST_kSuccess;
- case GHOST_kDrawingContextTypeNone:
- [pool drain];
- return GHOST_kSuccess;
- break;
- default:
- [pool drain];
- return GHOST_kFailure;
- }
+ return NULL;
}
+#pragma mark invalidate
GHOST_TSuccess GHOST_WindowCocoa::invalidate()
{