[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58679] branches/soc-2013-viewport_fx/ intern/ghost/intern: Got GLEW_MX working with GHOST_ContextEGL

Jason Wilkins Jason.A.Wilkins at gmail.com
Sat Jul 27 22:59:45 CEST 2013


Revision: 58679
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58679
Author:   jwilkins
Date:     2013-07-27 20:59:45 +0000 (Sat, 27 Jul 2013)
Log Message:
-----------
Got GLEW_MX working with GHOST_ContextEGL

Modified Paths:
--------------
    branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextEGL.cpp
    branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextEGL.h
    branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.cpp

Modified: branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextEGL.cpp
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextEGL.cpp	2013-07-27 20:54:52 UTC (rev 58678)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextEGL.cpp	2013-07-27 20:59:45 UTC (rev 58679)
@@ -38,6 +38,10 @@
 
 
 
+EGLEWContext* eglewContext = NULL;
+
+
+
 static const char* get_egl_error_enum_string(EGLenum error)
 {
 	switch(error) {
@@ -187,7 +191,7 @@
 
 static inline void bindAPI(EGLenum api)
 {
-	if (EGLEW_VERSION_1_2)
+	if (eglewContext != NULL && EGLEW_VERSION_1_2)
 		EGL_CHK(eglBindAPI(api));
 }
 
@@ -209,6 +213,7 @@
 EGLint     GHOST_ContextEGL::s_vg_sharedCount     = 0;
 
 
+#pragma warning(disable : 4715)
 
 template <typename T>
 T& choose_api(EGLenum api, T& a, T& b, T& c)
@@ -242,6 +247,7 @@
 	, m_context(EGL_NO_CONTEXT)
 	, m_sharedContext(choose_api(api, s_gl_sharedContext, s_gles_sharedContext, s_vg_sharedContext))
 	, m_sharedCount  (choose_api(api, s_gl_sharedCount,   s_gles_sharedCount,   s_vg_sharedCount))
+	, m_eglewContext(NULL)
 {
 	assert(m_nativeWindow  != NULL);
 	assert(m_nativeDisplay != NULL);
@@ -251,6 +257,8 @@
 
 GHOST_ContextEGL::~GHOST_ContextEGL()
 {
+	eglewContext = m_eglewContext;
+
 	bindAPI(m_api);
 
 	if (m_context != EGL_NO_CONTEXT) {
@@ -273,6 +281,8 @@
 		EGL_CHK(::eglDestroySurface(m_display, m_surface));
 
 	EGL_CHK(::eglTerminate(m_display));
+
+	delete m_eglewContext;
 }
 
 
@@ -286,6 +296,10 @@
 
 GHOST_TSuccess GHOST_ContextEGL::activateDrawingContext()
 {
+	eglewContext = m_eglewContext;
+
+	activateGlew();
+
 	bindAPI(m_api);
 
 	return EGL_CHK(::eglMakeCurrent(m_display, m_surface, m_surface, m_context)) ? GHOST_kSuccess : GHOST_kFailure;
@@ -293,14 +307,20 @@
 
 
 
-static bool init_eglew()
+bool GHOST_ContextEGL::initEGlew()
 {
-	static bool eglewInitialized = false;
+	if (m_eglewContext == NULL) {
+		eglewContext = new EGLEWContext;
 
-	if (!eglewInitialized && eglewInit() == GLEW_OK)
-		eglewInitialized = true;
+		if (eglewInit() != GLEW_OK) {
+			delete eglewContext;
+			eglewContext = NULL;
+		}
 
-	return eglewInitialized;
+		m_eglewContext = eglewContext;
+	}
+
+	return m_eglewContext != NULL;
 }
 
 
@@ -349,9 +369,11 @@
 	if (!EGL_CHK(::eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)))
 		goto error;
 
-	if (!init_eglew())
+	if (!initEGlew())
 		fprintf(stderr, "EGLEW failed to initialize.\n");
 
+	eglewContext = m_eglewContext;
+
 	bindAPI(m_api);
 
 	attrib_list.reserve(20);

Modified: branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextEGL.h
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextEGL.h	2013-07-27 20:54:52 UTC (rev 58678)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextEGL.h	2013-07-27 20:59:45 UTC (rev 58679)
@@ -35,7 +35,9 @@
 
 #include "GHOST_Context.h"
 
+#define eglewGetContext() eglewContext
 #include <GL/eglew.h>
+extern "C" EGLEWContext* eglewContext;
 
 
 
@@ -86,6 +88,8 @@
 	virtual GHOST_TSuccess releaseNativeHandles();
 
 private:
+	bool GHOST_ContextEGL::initEGlew();
+
 	EGLNativeDisplayType m_nativeDisplay;
 	EGLNativeWindowType  m_nativeWindow;
 
@@ -99,6 +103,7 @@
 	EGLContext& m_sharedContext;
 	EGLint&     m_sharedCount;
 
+	EGLEWContext* m_eglewContext;
 
 	static EGLContext s_gl_sharedContext;
 	static EGLint     s_gl_sharedCount;

Modified: branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.cpp
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.cpp	2013-07-27 20:54:52 UTC (rev 58678)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.cpp	2013-07-27 20:59:45 UTC (rev 58679)
@@ -40,7 +40,7 @@
 
 
 
-extern "C" WGLEWContext* wglewContext = NULL;
+WGLEWContext* wglewContext = NULL;
 
 
 
@@ -141,8 +141,6 @@
 
 GHOST_ContextWGL::~GHOST_ContextWGL()
 {
-	wglewContext = m_wglewContext;
-
 	if (m_hGLRC != NULL) {
 		if (m_hGLRC == ::wglGetCurrentContext())
 			WIN32_CHK(::wglMakeCurrent(NULL, NULL));




More information about the Bf-blender-cvs mailing list