Revision: 58507
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58507
Author:   jwilkins
Date:     2013-07-22 17:58:54 +0000 (Mon, 22 Jul 2013)
Log Message:
-----------
Added EGL initialization code to GHOST_WindowWin32, but this is just temporary 
until I'm sure exactly how GHOST_Context will be implemented.

Modified Paths:
--------------
    branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowWin32.cpp
    branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowWin32.h
    branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowX11.cpp
    branches/soc-2013-viewport_fx/source/blender/blenfont/intern/blf_lang.c

Modified: 
branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowWin32.cpp
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowWin32.cpp     
2013-07-22 16:49:37 UTC (rev 58506)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowWin32.cpp     
2013-07-22 17:58:54 UTC (rev 58507)
@@ -29,7 +29,8 @@
  *  \ingroup GHOST
  */
 
-#include <string.h>
+#define _USE_MATH_DEFINES
+
 #include "GHOST_WindowWin32.h"
 #include "GHOST_SystemWin32.h"
 #include "GHOST_DropTargetWin32.h"
@@ -38,20 +39,27 @@
 
 // Need glew for some defines
 #include <GL/glew.h>
+
+#if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
 #include <GL/wglew.h>
+#endif
+
 #include <math.h>
+#include <string.h>
 
 // MSVC6 still doesn't define M_PI
 #ifndef M_PI
-#  define M_PI 3.1415926536
+#define M_PI 3.1415926536
 #endif
 
+const wchar_t *GHOST_WindowWin32::s_windowClassName = L"GHOST_WindowClass";
+const int GHOST_WindowWin32::s_maxTitleLength = 128;
+
+#if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
 // Some more multisample defines
 #define WGL_SAMPLE_BUFFERS_ARB  0x2041
 #define WGL_SAMPLES_ARB         0x2042
 
-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;
 
@@ -88,7 +96,25 @@
        0,                              /* reserved */
        0, 0, 0                         /* no layer, visible, damage masks */
 };
+#endif
 
+#if defined(WITH_GL_SYSTEM_EMBEDDED)
+static EGLint attribList[] = {
+       EGL_RED_SIZE,       8,
+       EGL_GREEN_SIZE,     8,
+       EGL_BLUE_SIZE,      8,
+       EGL_DEPTH_SIZE,     8,
+#ifdef GHOST_OPENGL_ALPHA
+       EGL_ALPHA_SIZE,     8,
+#else
+       EGL_ALPHA_SIZE,     0,
+#endif
+       //EGL_STENCIL_SIZE,   8,
+       //EGL_SAMPLE_BUFFERS  1,
+       EGL_NONE
+};
+#endif
+
 /* Intel videocards don't work fine with multiple contexts and
  * have to share the same context for all windows.
  * But if we just share context for all windows it could work incorrect
@@ -125,7 +151,9 @@
                     stereoVisual, false, numOfAASamples),
        m_system(system),
        m_hDC(0),
+#if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
        m_hGlRc(0),
+#endif
        m_hasMouseCaptured(false),
        m_hasGrabMouse(false),
        m_nPressedButtons(0),
@@ -268,9 +296,11 @@
                // Store the device context
                m_hDC = ::GetDC(m_hWnd);
 
+#if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
                if (!s_firstHDC) {
                        s_firstHDC = m_hDC;
                }
+#endif
 
                // Show the window
                int nCmdShow;
@@ -400,7 +430,7 @@
 #if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
        ::wglMakeCurrent(NULL, NULL);
 #elif defined(WITH_GL_SYSTEM_EMBEDDED)
-       GHOST_PRINT("GHOST_WindowWin32::~GHOST_WindowWin32 for 
WITH_GL_SYSTEM_EMBEDDED not implemented\n");
+       ::eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, 
EGL_NO_CONTEXT);
 #else
 #error
 #endif
@@ -408,10 +438,19 @@
        m_multisampleEnabled = GHOST_kFailure;
        m_multisample = 0;
        setDrawingContextType(GHOST_kDrawingContextTypeNone);
+
+#if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
        if (m_hDC && m_hDC != s_firstHDC) {
                ::ReleaseDC(m_hWnd, m_hDC);
                m_hDC = 0;
        }
+#else
+       if (m_hDC && m_hDC) {
+               ::ReleaseDC(m_hWnd, m_hDC);
+               m_hDC = 0;
+       }
+#endif
+
        if (m_hWnd) {
                if (m_dropTarget) {
                        // Disable DragDrop
@@ -650,8 +689,7 @@
 
        return ::SwapBuffers(hDC) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
 #elif defined(WITH_GL_SYSTEM_EMBEDDED)
-       GHOST_PRINT("GHOST_WindowWin32::swapBuffers for WITH_GL_SYSTEM_EMBEDDED 
not implemented\n");
-       return GHOST_kFailure;
+       return ::eglSwapBuffers(egl_display, egl_surface) ? GHOST_kSuccess : 
GHOST_kFailure;
 #else
 #error
 #endif
@@ -664,14 +702,18 @@
        if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
 #if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
                if (m_hDC && m_hGlRc) {
-                       success = ::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE ? 
GHOST_kSuccess : GHOST_kFailure;
+                       success = ::wglMakeCurrent(m_hDC, m_hGlRc) ? 
GHOST_kSuccess : GHOST_kFailure;
                }
                else {
                        success = GHOST_kFailure;
                }
 #elif defined(WITH_GL_SYSTEM_EMBEDDED)
-       success = GHOST_kFailure;
-       GHOST_PRINT("GHOST_WindowWin32::activateDrawingContext for 
WITH_GL_SYSTEM_EMBEDDED not implemented\n");
+               if (m_hDC) {
+                       success = ::eglMakeCurrent(egl_display, egl_surface, 
egl_surface, egl_context) ? GHOST_kSuccess : GHOST_kFailure;
+               }
+               else {
+                       success = GHOST_kFailure;
+               }
 #else
 #error
 #endif
@@ -679,6 +721,7 @@
        else {
                success = GHOST_kSuccess;
        }
+
        return success;
 }
 
@@ -761,6 +804,7 @@
 GHOST_TSuccess 
GHOST_WindowWin32::installDrawingContext(GHOST_TDrawingContextType type)
 {
        GHOST_TSuccess success;
+
        switch (type) {
                case GHOST_kDrawingContextTypeOpenGL:
 #if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
@@ -925,12 +969,62 @@
                }
                break;
 #elif defined(WITH_GL_SYSTEM_EMBEDDED)
-               GHOST_PRINT("GHOST_WindowWin32::installDrawingContext for 
WITH_GL_SYSTEM_EMBEDDED not implemented\n");
-               success = GHOST_kFailure;
-               break;
+               {
+                       EGLint major, minor;
+                       EGLint num_config;
+                       EGLConfig config;
+#if defined(WITH_GL_PROFILE_ES20)
+                       EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, 
EGL_NONE, EGL_NONE };
+#endif
+
+                       egl_display = 
::eglGetDisplay((EGLNativeDisplayType)m_hDC);
+
+                       if(egl_display == EGL_NO_DISPLAY) {
+                               success = GHOST_kFailure;
+                               break;
+                       }
+
+                       if(!::eglInitialize(egl_display, &major, &minor)) {
+                               success = GHOST_kFailure;
+                               break;
+                       }
+
+                       if(!::eglGetConfigs(egl_display, NULL, 0, &num_config)) 
{
+                               success = GHOST_kFailure;
+                               break;
+                       }
+
+                       if(!::eglChooseConfig(egl_display, attribList, &config, 
1, &num_config)) {
+                               success = GHOST_kFailure;
+                               break;
+                       }
+
+                       egl_surface = ::eglCreateWindowSurface(egl_display, 
config, (EGLNativeWindowType)m_hWnd, NULL);
+
+                       if (egl_surface == EGL_NO_SURFACE ) {
+                               success = GHOST_kFailure;
+                               break;
+                       }
+
+                       egl_context = ::eglCreateContext(egl_display, config, 
EGL_NO_CONTEXT, attribs);
+
+                       if (egl_context == EGL_NO_CONTEXT) {
+                               success = GHOST_kFailure;
+                               break;
+                       }
+
+                       if (!::eglMakeCurrent(egl_display, egl_surface, 
egl_surface, egl_context)) {
+                               success = GHOST_kFailure;
+                               break;
+                       }
+
+                       success = GHOST_kSuccess;
+                       break;
+               }
 #else
 #error
 #endif
+
                case GHOST_kDrawingContextTypeNone:
                        success = GHOST_kSuccess;
                        break;
@@ -938,6 +1032,7 @@
                default:
                        success = GHOST_kFailure;
        }
+
        return success;
 }
 
@@ -958,8 +1053,18 @@
                        }
                        break;
 #elif defined(WITH_GL_SYSTEM_EMBEDDED)
-                       GHOST_PRINT("GHOST_WindowWin32::removeDrawingContext 
for WITH_GL_SYSTEM_EMBEDDED not implemented\n");
-                       success = GHOST_kFailure;
+                       if (egl_context != NULL) {
+                               if (eglDestroyContext(egl_display, 
egl_context)) {
+                                       egl_context = NULL;
+                                       success = GHOST_kSuccess;
+                               }
+                               else {
+                                       success = GHOST_kFailure;
+                               }
+                       }
+                       else {
+                               success = GHOST_kFailure;
+                       }
                        break;
 #else
 #error
@@ -1319,6 +1424,8 @@
        return GHOST_kFailure;
 }
 
+#if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
+
 /* Ron Fosner's code for weighting pixel formats and forcing software.
  * See http://www.opengl.org/resources/faq/technical/weight.cpp */
 
@@ -1410,4 +1517,4 @@
        return iPixelFormat;
 }
 
-
+#endif

Modified: branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowWin32.h
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowWin32.h       
2013-07-22 16:49:37 UTC (rev 58506)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowWin32.h       
2013-07-22 17:58:54 UTC (rev 58507)
@@ -44,6 +44,9 @@
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
+#if defined(WITH_GL_SYSTEM_EMBEDDED) // XXX jwilkins: can remove this after 
implementing GHOST_Context
+#include <GL/eglew.h>
+#endif
 
 #include <wintab.h>
 #define PACKETDATA  (PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | 
PK_CURSOR)
@@ -345,12 +348,19 @@
        HWND m_hWnd;
        /** Device context handle. */
        HDC m_hDC;
+#if defined(WITH_GL_SYSTEM_DESKTOP) || defined(WITH_GL_SYSTEM_LEGACY)
        /** OpenGL rendering context. */
        HGLRC m_hGlRc;
        /** The first created OpenGL context (for sharing display lists) */
        static HGLRC s_firsthGLRc;
        /** The first created device context handle. */
        static HDC s_firstHDC;
+#endif
+#if defined(WITH_GL_SYSTEM_EMBEDDED)
+       EGLContext egl_context;
+       EGLSurface egl_surface;
+       EGLDisplay egl_display;
+#endif
        /** Flag for if window has captured the mouse */
        bool m_hasMouseCaptured;
        /** Flag if an operator grabs the mouse with 
WM_cursor_grab_enable/ungrab() 

Modified: branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowX11.cpp
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowX11.cpp       
2013-07-22 16:49:37 UTC (rev 58506)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_WindowX11.cpp       
2013-07-22 17:58:54 UTC (rev 58507)
@@ -1349,6 +1349,7 @@
 #ifndef GLEW_INC_EGL
        if (m_context != NULL) {
                glXDestroyContext(m_display, m_context);
+               m_context = NULL;
                success = GHOST_kSuccess;
        }
        else {

Modified: 
branches/soc-2013-viewport_fx/source/blender/blenfont/intern/blf_lang.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/blenfont/intern/blf_lang.c     
2013-07-22 16:49:37 UTC (rev 58506)
+++ branches/soc-2013-viewport_fx/source/blender/blenfont/intern/blf_lang.c     
2013-07-22 17:58:54 UTC (rev 58507)
@@ -66,7 +66,7 @@
                        MEM_freeN((void *)locales_menu[idx].description); /* 
Also frees locales's relevant value! */
                }
 
-               MEM_freeN(locales);
+               MEM_freeN((void*)locales);
                locales = NULL;
        }
        if (locales_menu) {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to