diff options
Diffstat (limited to 'intern/ghost/intern/GHOST_WindowWin32.cpp')
-rw-r--r-- | intern/ghost/intern/GHOST_WindowWin32.cpp | 497 |
1 files changed, 169 insertions, 328 deletions
diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp index 8e7e824186c..11ddc478d6c 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.cpp +++ b/intern/ghost/intern/GHOST_WindowWin32.cpp @@ -29,32 +29,34 @@ * \ingroup GHOST */ -#include <string.h> +#define _USE_MATH_DEFINES + #include "GHOST_WindowWin32.h" #include "GHOST_SystemWin32.h" #include "GHOST_DropTargetWin32.h" +#include "GHOST_ContextNone.h" #include "utfconv.h" #include "utf_winfunc.h" -// Need glew for some defines -#include <GL/glew.h> -#include <GL/wglew.h> -#include <math.h> +#if defined(WITH_GL_CONTEXT_DESKTOP) +#include "GHOST_ContextWGL.h" +#endif -// MSVC6 still doesn't define M_PI -#ifndef M_PI -# define M_PI 3.1415926536 +#if defined(WITH_GL_CONTEXT_EMBEDDED) +#include "GHOST_ContextEGL.h" #endif -// Some more multisample defines -#define WGL_SAMPLE_BUFFERS_ARB 0x2041 -#define WGL_SAMPLES_ARB 0x2042 +#include <math.h> +#include <string.h> +#include <assert.h> + + const wchar_t *GHOST_WindowWin32::s_windowClassName = L"GHOST_WindowClass"; const int GHOST_WindowWin32::s_maxTitleLength = 128; -HGLRC GHOST_WindowWin32::s_firsthGLRc = NULL; -HDC GHOST_WindowWin32::s_firstHDC = NULL; +<<<<<<< HEAD +======= static int WeightPixelFormat(PIXELFORMATDESCRIPTOR &pfd); static int EnumPixelFormats(HDC hdc); @@ -97,14 +99,9 @@ static PIXELFORMATDESCRIPTOR sPreferredFormat = { static int is_crappy_intel_card(void) { static short is_crappy = -1; +>>>>>>> master - if (is_crappy == -1) { - const char *vendor = (const char *)glGetString(GL_VENDOR); - is_crappy = (strstr(vendor, "Intel") != NULL); - } - return is_crappy; -} /* force NVidia Optimus to used dedicated graphics */ extern "C" { @@ -112,6 +109,34 @@ extern "C" { } GHOST_WindowWin32::GHOST_WindowWin32( +<<<<<<< HEAD + GHOST_SystemWin32 *system, + const STR_String& title, + GHOST_TInt32 left, + GHOST_TInt32 top, + GHOST_TUns32 width, + GHOST_TUns32 height, + GHOST_TWindowState state, + GHOST_TDrawingContextType type, + bool wantStereoVisual, + GHOST_TUns16 wantNumOfAASamples, + GHOST_TEmbedderWindowID parentwindowhwnd +) + : GHOST_Window(width, height, state, wantStereoVisual, false, wantNumOfAASamples), + m_inLiveResize(false), + m_system(system), + m_hDC(0), + m_hasMouseCaptured(false), + m_hasGrabMouse(false), + m_nPressedButtons(0), + m_customCursor(0), + m_wintab(NULL), + m_tabletData(NULL), + m_tablet(0), + m_maxPressure(0), + m_normal_state(GHOST_kWindowStateNormal), + m_parentWindowHwnd(parentwindowhwnd) +======= GHOST_SystemWin32 *system, const STR_String &title, GHOST_TInt32 left, @@ -152,6 +177,7 @@ GHOST_WindowWin32::GHOST_WindowWin32( m_stereo(stereoVisual), m_nextWindow(NULL), m_parentWindowHwnd(parentwindowhwnd) +>>>>>>> master { OSVERSIONINFOEX versionInfo; bool hasMinVersionForTaskbar = false; @@ -272,6 +298,7 @@ GHOST_WindowWin32::GHOST_WindowWin32( 0); // pointer to window-creation data free(title_16); } + if (m_hWnd) { // Register this window as a droptarget. Requires m_hWnd to be valid. // Note that OleInitialize(0) has to be called prior to this. Done in GHOST_SystemWin32. @@ -286,35 +313,37 @@ GHOST_WindowWin32::GHOST_WindowWin32( // Store the device context m_hDC = ::GetDC(m_hWnd); - if (!s_firstHDC) { - s_firstHDC = m_hDC; - } + GHOST_TSuccess success = setDrawingContextType(type); - // Show the window - int nCmdShow; - switch (state) { - case GHOST_kWindowStateMaximized: - nCmdShow = SW_SHOWMAXIMIZED; - break; - case GHOST_kWindowStateMinimized: - nCmdShow = SW_SHOWMINIMIZED; - break; - case GHOST_kWindowStateNormal: - default: - nCmdShow = SW_SHOWNORMAL; - break; - } - GHOST_TSuccess success; - success = setDrawingContextType(type); + if (success) { + // Show the window + int nCmdShow; + switch (state) { + case GHOST_kWindowStateMaximized: + nCmdShow = SW_SHOWMAXIMIZED; + break; + case GHOST_kWindowStateMinimized: + nCmdShow = SW_SHOWMINIMIZED; + break; + case GHOST_kWindowStateNormal: + default: + nCmdShow = SW_SHOWNORMAL; + break; + } +<<<<<<< HEAD +======= if (success) { +>>>>>>> master ::ShowWindow(m_hWnd, nCmdShow); + // Force an initial paint of the window ::UpdateWindow(m_hWnd); } else { //invalidate the window - m_hWnd = 0; + ::DestroyWindow(m_hWnd); + m_hWnd = NULL; } } @@ -415,6 +444,10 @@ GHOST_WindowWin32::~GHOST_WindowWin32() m_customCursor = NULL; } +<<<<<<< HEAD + if (m_hWnd != NULL && m_hDC != NULL && releaseNativeHandles()) + ::ReleaseDC(m_hWnd, m_hDC); +======= ::wglMakeCurrent(NULL, NULL); m_multisampleEnabled = GHOST_kFailure; m_multisample = 0; @@ -424,6 +457,7 @@ GHOST_WindowWin32::~GHOST_WindowWin32() ::ReleaseDC(m_hWnd, m_hDC); m_hDC = 0; } +>>>>>>> master if (m_hWnd) { if (m_dropTarget) { @@ -438,14 +472,9 @@ GHOST_WindowWin32::~GHOST_WindowWin32() } } -GHOST_Window *GHOST_WindowWin32::getNextWindow() -{ - return m_nextWindow; -} - bool GHOST_WindowWin32::getValid() const { - return m_hWnd != 0; + return GHOST_Window::getValid() && m_hWnd != 0 && m_hDC != 0; } HWND GHOST_WindowWin32::getHWND() const @@ -678,49 +707,6 @@ GHOST_TSuccess GHOST_WindowWin32::setOrder(GHOST_TWindowOrder order) } -GHOST_TSuccess GHOST_WindowWin32::swapBuffers() -{ - HDC hDC = m_hDC; - - if (is_crappy_intel_card()) - hDC = ::wglGetCurrentDC(); - - return ::SwapBuffers(hDC) == TRUE ? GHOST_kSuccess : GHOST_kFailure; -} - -GHOST_TSuccess GHOST_WindowWin32::setSwapInterval(int interval) -{ - if (!WGL_EXT_swap_control) - return GHOST_kFailure; - return wglSwapIntervalEXT(interval) == TRUE ? GHOST_kSuccess : GHOST_kFailure; -} - -int GHOST_WindowWin32::getSwapInterval() -{ - if (WGL_EXT_swap_control) - return wglGetSwapIntervalEXT(); - - return 0; -} - -GHOST_TSuccess GHOST_WindowWin32::activateDrawingContext() -{ - GHOST_TSuccess success; - if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) { - if (m_hDC && m_hGlRc) { - success = ::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE ? GHOST_kSuccess : GHOST_kFailure; - } - else { - success = GHOST_kFailure; - } - } - else { - success = GHOST_kSuccess; - } - return success; -} - - GHOST_TSuccess GHOST_WindowWin32::invalidate() { GHOST_TSuccess success; @@ -733,264 +719,116 @@ GHOST_TSuccess GHOST_WindowWin32::invalidate() return success; } -GHOST_TSuccess GHOST_WindowWin32::initMultisample(PIXELFORMATDESCRIPTOR pfd) + + +GHOST_Context* GHOST_WindowWin32::newDrawingContext(GHOST_TDrawingContextType type) { - int pixelFormat; - bool success = FALSE; - UINT numFormats; - HDC hDC = GetDC(getHWND()); - float fAttributes[] = {0, 0}; - UINT nMaxFormats = 1; - - // The attributes to look for - int iAttributes[] = { - WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, - WGL_SUPPORT_OPENGL_ARB, GL_TRUE, - WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, - WGL_COLOR_BITS_ARB, pfd.cColorBits, - WGL_DEPTH_BITS_ARB, pfd.cDepthBits, -#ifdef GHOST_OPENGL_ALPHA - WGL_ALPHA_BITS_ARB, pfd.cAlphaBits, + if (type == GHOST_kDrawingContextTypeOpenGL) { +#if defined(WITH_GL_CONTEXT_DESKTOP) + +#if defined(WITH_GL_PROFILE_CORE) + GHOST_Context* context = new GHOST_ContextWGL( + m_wantStereoVisual, + m_wantNumOfAASamples, + m_hWnd, + m_hDC, + WGL_CONTEXT_OPENGL_CORE_PROFILE_BIT, + 3, 2, + GHOST_OPENGL_WGL_CONTEXT_FLAGS, + GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY); +#elif defined(WITH_GL_PROFILE_ES20) + GHOST_Context* context = new GHOST_ContextWGL( + m_wantStereoVisual, + m_wantNumOfAASamples, + m_hWnd, + m_hDC, + WGL_CONTEXT_ES2_PROFILE_BIT_EXT, + 2, 0, + GHOST_OPENGL_WGL_CONTEXT_FLAGS, + GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY); +#elif defined(WITH_GL_PROFILE_COMPAT) + GHOST_Context* context = new GHOST_ContextWGL( + m_wantStereoVisual, + m_wantNumOfAASamples, + m_hWnd, + m_hDC, + 0, // profile bit + 0, 0, + GHOST_OPENGL_WGL_CONTEXT_FLAGS, + GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY); +#else +#error #endif - WGL_STENCIL_BITS_ARB, pfd.cStencilBits, - WGL_DOUBLE_BUFFER_ARB, GL_TRUE, - WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, - WGL_SAMPLES_ARB, m_multisample, - 0, 0 - }; - // Get the function - PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); +#elif defined(WITH_GL_CONTEXT_EMBEDDED) + +#if defined(WITH_GL_PROFILE_CORE) + GHOST_Context* context = new GHOST_ContextEGL( + m_wantStereoVisual, + m_wantNumOfAASamples, + m_hWnd, + m_hDC, + 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_hWnd, + m_hDC, + 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_hWnd, + m_hDC, + 0, // profile bit + 0, 0, + GHOST_OPENGL_EGL_CONTEXT_FLAGS, + GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY, + EGL_OPENGL_API); +#else +#error +#endif +<<<<<<< HEAD +#else +#error +#endif + if (context->initializeDrawingContext()) + return context; + else + delete context; +======= if (!wglChoosePixelFormatARB) { m_multisampleEnabled = GHOST_kFailure; return GHOST_kFailure; +>>>>>>> master } - // iAttributes[17] is the initial multisample. If not valid try to use the closest valid value under it. - while (iAttributes[17] > 0) { - // See if the format is valid - success = wglChoosePixelFormatARB(hDC, iAttributes, fAttributes, nMaxFormats, &pixelFormat, &numFormats); - GHOST_PRINTF("WGL_SAMPLES_ARB = %i --> success = %i, %i formats\n", iAttributes[17], success, numFormats); - - if (success && numFormats >= 1 && m_multisampleEnabled == GHOST_kFailure) { - GHOST_PRINTF("valid pixel format with %i multisamples\n", iAttributes[17]); - m_multisampleEnabled = GHOST_kSuccess; - m_msPixelFormat = pixelFormat; - } - iAttributes[17] -= 1; - success = GHOST_kFailure; - } - if (m_multisampleEnabled == GHOST_kSuccess) { - return GHOST_kSuccess; - } - GHOST_PRINT("no available pixel format\n"); - return GHOST_kFailure; + return NULL; } -GHOST_TSuccess GHOST_WindowWin32::installDrawingContext(GHOST_TDrawingContextType type) -{ - GHOST_TSuccess success; - switch (type) { - case GHOST_kDrawingContextTypeOpenGL: - { - // If this window has multisample enabled, use the supplied format - if (m_multisampleEnabled) - { - if (SetPixelFormat(m_hDC, m_msPixelFormat, &sPreferredFormat) == FALSE) - { - success = GHOST_kFailure; - break; - } - - // Create the context - m_hGlRc = ::wglCreateContext(m_hDC); - if (m_hGlRc) { - if (::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE) { - if (s_firsthGLRc) { - if (is_crappy_intel_card()) { - if (::wglMakeCurrent(NULL, NULL) == TRUE) { - ::wglDeleteContext(m_hGlRc); - m_hGlRc = s_firsthGLRc; - } - else { - ::wglDeleteContext(m_hGlRc); - m_hGlRc = NULL; - } - } - else { - ::wglCopyContext(s_firsthGLRc, m_hGlRc, GL_ALL_ATTRIB_BITS); - ::wglShareLists(s_firsthGLRc, m_hGlRc); - } - } - else { - s_firsthGLRc = m_hGlRc; - } - - if (m_hGlRc) { - success = ::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE ? GHOST_kSuccess : GHOST_kFailure; - } - else { - success = GHOST_kFailure; - } - } - else { - success = GHOST_kFailure; - } - } - else { - success = GHOST_kFailure; - } - - if (success == GHOST_kFailure) { - printf("Failed to get a context....\n"); - } - } - else { - if (m_stereoVisual) - sPreferredFormat.dwFlags |= PFD_STEREO; - - // Attempt to match device context pixel format to the preferred format - int iPixelFormat = EnumPixelFormats(m_hDC); - if (iPixelFormat == 0) { - success = GHOST_kFailure; - break; - } - if (::SetPixelFormat(m_hDC, iPixelFormat, &sPreferredFormat) == FALSE) { - success = GHOST_kFailure; - break; - } - // For debugging only: retrieve the pixel format chosen - PIXELFORMATDESCRIPTOR preferredFormat; - ::DescribePixelFormat(m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &preferredFormat); - - // Create the context - m_hGlRc = ::wglCreateContext(m_hDC); - if (m_hGlRc) { - if (::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE) { - if (s_firsthGLRc) { - if (is_crappy_intel_card()) { - if (::wglMakeCurrent(NULL, NULL) == TRUE) { - ::wglDeleteContext(m_hGlRc); - m_hGlRc = s_firsthGLRc; - } - else { - ::wglDeleteContext(m_hGlRc); - m_hGlRc = NULL; - } - } - else { - ::wglShareLists(s_firsthGLRc, m_hGlRc); - } - } - else { - s_firsthGLRc = m_hGlRc; - } - - if (m_hGlRc) { - success = ::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE ? GHOST_kSuccess : GHOST_kFailure; - } - else { - success = GHOST_kFailure; - } - } - else { - success = GHOST_kFailure; - } - } - else { - success = GHOST_kFailure; - } - - if (success == GHOST_kFailure) { - printf("Failed to get a context....\n"); - } - - // Attempt to enable multisample - if (m_multisample && WGL_ARB_multisample && !m_multisampleEnabled && !is_crappy_intel_card()) - { - success = initMultisample(preferredFormat); - - if (success) - { - - // Make sure we don't screw up the context - if (m_hGlRc == s_firsthGLRc) - s_firsthGLRc = NULL; - m_drawingContextType = GHOST_kDrawingContextTypeOpenGL; - removeDrawingContext(); - - // Create a new window - GHOST_TWindowState new_state = getState(); - - m_nextWindow = new GHOST_WindowWin32((GHOST_SystemWin32 *)GHOST_ISystem::getSystem(), - m_title, - m_left, - m_top, - m_width, - m_height, - new_state, - type, - m_stereo, - m_multisample, - m_parentWindowHwnd, - m_multisampleEnabled, - m_msPixelFormat); - - // Return failure so we can trash this window. - success = GHOST_kFailure; - break; - } - else { - m_multisampleEnabled = GHOST_kSuccess; - printf("Multisample failed to initialize\n"); - success = GHOST_kSuccess; - } - } - } - - } - break; - case GHOST_kDrawingContextTypeNone: - success = GHOST_kSuccess; - break; - - default: - success = GHOST_kFailure; - } - return success; -} - -GHOST_TSuccess GHOST_WindowWin32::removeDrawingContext() -{ - GHOST_TSuccess success; - switch (m_drawingContextType) { - case GHOST_kDrawingContextTypeOpenGL: - // we shouldn't remove the drawing context if it's the first OpenGL context - // If we do, we get corrupted drawing. See #19997 - if (m_hGlRc && m_hGlRc != s_firsthGLRc) { - success = ::wglDeleteContext(m_hGlRc) == TRUE ? GHOST_kSuccess : GHOST_kFailure; - m_hGlRc = 0; - } - else { - success = GHOST_kFailure; - } - break; - case GHOST_kDrawingContextTypeNone: - success = GHOST_kSuccess; - break; - default: - success = GHOST_kFailure; - } - return success; -} void GHOST_WindowWin32::lostMouseCapture() { if (m_hasMouseCaptured) { +<<<<<<< HEAD + m_hasGrabMouse = false; + m_nPressedButtons = 0; +======= m_hasGrabMouse = false; m_nPressedButtons = 0; +>>>>>>> master m_hasMouseCaptured = false; } } @@ -1334,6 +1172,8 @@ GHOST_TSuccess GHOST_WindowWin32::endProgressBar() return GHOST_kFailure; } +<<<<<<< HEAD +======= /* Ron Fosner's code for weighting pixel formats and forcing software. * See http://www.opengl.org/resources/faq/technical/weight.cpp */ @@ -1424,3 +1264,4 @@ static int EnumPixelFormats(HDC hdc) } return iPixelFormat; } +>>>>>>> master |