diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2016-09-23 02:40:19 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2016-09-23 02:40:19 +0300 |
commit | 1dfb89d229304c302b8849756aa0ddd7e8d96488 (patch) | |
tree | db7a2ed403101788b2cb308538d73a99c95621d6 /intern/ghost | |
parent | 4a1feaa5558ed60388fd3be41db74fbc54f2ab08 (diff) | |
parent | 1b2b7cfa2007172e07d78324bb941d0160b59c42 (diff) |
Merge branch 'master' into blender2.8
Conflicts:
intern/ghost/intern/GHOST_ContextCGL.mm
intern/ghost/intern/GHOST_WindowCocoa.mm
source/blender/makesrna/intern/rna_main.c
Diffstat (limited to 'intern/ghost')
-rw-r--r-- | intern/ghost/intern/GHOST_ContextCGL.h | 2 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_ContextCGL.mm | 88 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.mm | 2 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWin32.cpp | 2 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_WindowCocoa.h | 4 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_WindowCocoa.mm | 5 |
6 files changed, 74 insertions, 29 deletions
diff --git a/intern/ghost/intern/GHOST_ContextCGL.h b/intern/ghost/intern/GHOST_ContextCGL.h index c2f1ce176ad..8186eaa759d 100644 --- a/intern/ghost/intern/GHOST_ContextCGL.h +++ b/intern/ghost/intern/GHOST_ContextCGL.h @@ -138,6 +138,8 @@ private: //static CGLEWContext *s_cglewContext; + const bool m_debug; + /** The first created OpenGL context (for sharing display lists) */ static NSOpenGLContext *s_sharedOpenGLContext; static int s_sharedCount; diff --git a/intern/ghost/intern/GHOST_ContextCGL.mm b/intern/ghost/intern/GHOST_ContextCGL.mm index 6a39d76e752..1ab0301f7b2 100644 --- a/intern/ghost/intern/GHOST_ContextCGL.mm +++ b/intern/ghost/intern/GHOST_ContextCGL.mm @@ -59,7 +59,8 @@ GHOST_ContextCGL::GHOST_ContextCGL( int contextResetNotificationStrategy) : GHOST_Context(stereoVisual, numOfAASamples), m_openGLView(openGLView), - m_openGLContext(nil) + m_openGLContext(nil), + m_debug(contextFlags) { assert(openGLView != nil); @@ -186,27 +187,27 @@ GHOST_TSuccess GHOST_ContextCGL::updateDrawingContext() static void makeAttribList( std::vector<NSOpenGLPixelFormatAttribute>& attribs, - bool coreProfile, bool stereoVisual, int numOfAASamples, bool needAlpha, - bool needStencil) + bool needStencil, + bool softwareGL) { + attribs.clear(); + attribs.push_back(NSOpenGLPFAOpenGLProfile); attribs.push_back(coreProfile ? NSOpenGLProfileVersion3_2Core : NSOpenGLProfileVersionLegacy); // Pixel Format Attributes for the windowed NSOpenGLContext attribs.push_back(NSOpenGLPFADoubleBuffer); - // Force software OpenGL, for debugging - /* XXX jwilkins: fixed this to work on Intel macs? useful feature for Windows and Linux too? - * Maybe a command line flag is better... */ - if (getenv("BLENDER_SOFTWAREGL")) { + if (softwareGL) { attribs.push_back(NSOpenGLPFARendererID); attribs.push_back(kCGLRendererGenericFloatID); } else { attribs.push_back(NSOpenGLPFAAccelerated); + attribs.push_back(NSOpenGLPFANoRecovery); } attribs.push_back(NSOpenGLPFAAllowOfflineRenderers); // for automatic GPU switching @@ -239,13 +240,21 @@ static void makeAttribList( attribs.push_back(NSOpenGLPFASamples); attribs.push_back((NSOpenGLPixelFormatAttribute) numOfAASamples); - - attribs.push_back(NSOpenGLPFANoRecovery); } attribs.push_back((NSOpenGLPixelFormatAttribute) 0); } +// TODO(merwin): make this available to all platforms +static void getVersion(int *major, int *minor) +{ +#if 1 // legacy GL + sscanf((const char*)glGetString(GL_VERSION), "%d.%d", major, minor); +#else // 3.0+ + glGetIntegerv(GL_MAJOR_VERSION, major); + glGetIntegerv(GL_MINOR_VERSION, minor); +#endif +} GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext() { @@ -268,9 +277,12 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext() static const bool needStencil = false; #endif - makeAttribList(attribs, m_coreProfile, m_stereoVisual, m_numOfAASamples, needAlpha, needStencil); - + static bool softwareGL = getenv("BLENDER_SOFTWAREGL"); // command-line argument would be better + GLint major = 0, minor = 0; NSOpenGLPixelFormat *pixelFormat; + // TODO: keep pixel format for subsequent windows/contexts instead of recreating each time + + makeAttribList(attribs, coreProfile, m_stereoVisual, m_numOfAASamples, needAlpha, needStencil, softwareGL); pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:&attribs[0]]; @@ -281,7 +293,7 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext() // (Now that I think about it, does WGL really require the code that it has for finding a lesser match?) attribs.clear(); - makeAttribList(attribs, m_coreProfile, m_stereoVisual, 0, needAlpha, needStencil); + makeAttribList(attribs, coreProfile, m_stereoVisual, 0, needAlpha, needStencil, softwareGL); pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:&attribs[0]]; } @@ -302,25 +314,47 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext() } } - [m_openGLView setPixelFormat:pixelFormat]; + m_openGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:s_sharedOpenGLContext]; + [pixelFormat release]; - m_openGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:s_sharedOpenGLContext]; // +1 refCount to pixelFormat + [m_openGLContext makeCurrentContext]; - if (m_openGLContext == nil) - goto error; + getVersion(&major, &minor); + if (m_debug) { + fprintf(stderr, "OpenGL version %d.%d%s\n", major, minor, softwareGL ? " (software)" : ""); + fprintf(stderr, "Renderer: %s\n", glGetString(GL_RENDERER)); + } - if (s_sharedCount == 0) - s_sharedOpenGLContext = m_openGLContext; - - [pixelFormat release]; // -1 refCount to pixelFormat - - s_sharedCount++; + if (major < 2 || (major == 2 && minor < 1)) { + // fall back to software renderer if GL < 2.1 + fprintf(stderr, "OpenGL 2.1 is not supported on your hardware, falling back to software"); + softwareGL = true; + + // discard hardware GL context + [NSOpenGLContext clearCurrentContext]; + [m_openGLContext release]; + + // create software GL context + makeAttribList(attribs, m_stereoVisual, m_numOfAASamples, needAlpha, needStencil, softwareGL); + pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:&attribs[0]]; + m_openGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:s_sharedOpenGLContext]; + [pixelFormat release]; + + [m_openGLContext makeCurrentContext]; + + getVersion(&major, &minor); + if (m_debug) { + fprintf(stderr, "OpenGL version %d.%d%s\n", major, minor, softwareGL ? " (software)" : ""); + fprintf(stderr, "Renderer: %s\n", glGetString(GL_RENDERER)); + } + } #ifdef GHOST_MULTITHREADED_OPENGL //Switch openGL to multhreaded mode CGLContextObj cglCtx = (CGLContextObj)[tmpOpenGLContext CGLContextObj]; if (CGLEnable(cglCtx, kCGLCEMPEngine) == kCGLNoError) - printf("\nSwitched openGL to multithreaded mode\n"); + if (m_debug) + fprintf(stderr, "\nSwitched OpenGL to multithreaded mode\n"); #endif #ifdef GHOST_WAIT_FOR_VSYNC @@ -331,10 +365,16 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext() } #endif + initContextGLEW(); + [m_openGLView setOpenGLContext:m_openGLContext]; [m_openGLContext setView:m_openGLView]; - initContextGLEW(); + if (s_sharedCount == 0) + s_sharedOpenGLContext = m_openGLContext; + + s_sharedCount++; + initClearGL(); [m_openGLContext flushBuffer]; diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index b0d5ab31ce3..f31cba498e5 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -562,7 +562,7 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow( // Add contentRect.origin.y to respect docksize bottom = bottom > contentRect.origin.y ? bottom + contentRect.origin.y : contentRect.origin.y; - window = new GHOST_WindowCocoa (this, title, left, bottom, width, height, state, type, ((glSettings.flags & GHOST_glStereoVisual) != 0), glSettings.numOfAASamples); + window = new GHOST_WindowCocoa(this, title, left, bottom, width, height, state, type, glSettings.flags & GHOST_glStereoVisual, glSettings.numOfAASamples, glSettings.flags & GHOST_glDebugContext); if (window->getValid()) { // Store the pointer to the window diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index f884b0fadb1..60e7815ccbb 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -41,7 +41,7 @@ #include <shlobj.h> #include <tlhelp32.h> -#include <Psapi.h> +#include <psapi.h> #include <windowsx.h> #include "utfconv.h" diff --git a/intern/ghost/intern/GHOST_WindowCocoa.h b/intern/ghost/intern/GHOST_WindowCocoa.h index 3ed88086184..b234291396b 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.h +++ b/intern/ghost/intern/GHOST_WindowCocoa.h @@ -74,7 +74,8 @@ public: GHOST_TWindowState state, GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone, const bool stereoVisual = false, - const GHOST_TUns16 numOfAASamples = 0 + const GHOST_TUns16 numOfAASamples = 0, + bool is_debug = false ); /** @@ -305,6 +306,7 @@ protected: bool m_lionStyleFullScreen; bool m_immediateDraw; + bool m_debug_context; // for debug messages during context setup }; #endif // __GHOST_WINDOWCOCOA_H__ diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm index 383734be3e6..b0feb11a6af 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.mm +++ b/intern/ghost/intern/GHOST_WindowCocoa.mm @@ -528,10 +528,11 @@ GHOST_WindowCocoa::GHOST_WindowCocoa( GHOST_TUns32 height, GHOST_TWindowState state, GHOST_TDrawingContextType type, - const bool stereoVisual, const GHOST_TUns16 numOfAASamples + const bool stereoVisual, const GHOST_TUns16 numOfAASamples, bool is_debug ) : GHOST_Window(width, height, state, stereoVisual, false, numOfAASamples), - m_customCursor(0) + m_customCursor(0), + m_debug_context(is_debug) { m_systemCocoa = systemCocoa; m_fullScreen = false; |