[Bf-blender-cvs] [0c05f6e] soc-2014-viewport_context: Made glew-mx more easily extendable by creating a MXContext struct to put additional data in. Renamed the mx functions to more closely match their analogs in other systems. mxCreateContext now also calls glewInit

Jason Wilkins noreply at git.blender.org
Thu Jul 31 12:14:53 CEST 2014


Commit: 0c05f6eee3ed98090b296cebb59e157b00e8788f
Author: Jason Wilkins
Date:   Thu Jul 31 03:50:26 2014 -0500
Branches: soc-2014-viewport_context
https://developer.blender.org/rB0c05f6eee3ed98090b296cebb59e157b00e8788f

Made glew-mx more easily extendable by creating a MXContext struct to put additional data in.
Renamed the mx functions to more closely match their analogs in other systems.
mxCreateContext now also calls glewInit

===================================================================

M	CMakeLists.txt
M	intern/cycles/util/util_view.cpp
M	intern/ghost/intern/GHOST_Context.cpp
M	intern/ghost/intern/GHOST_Context.h
M	intern/ghost/intern/GHOST_ContextEGL.cpp
M	intern/glew-mx/glew-mx.h
M	intern/glew-mx/intern/glew-mx.c

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ec08377..9ca52ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2223,6 +2223,8 @@ if(WITH_GLEW_MX)
 	list(APPEND GL_DEFINITIONS -DWITH_GLEW_MX)
 endif()
 
+list(APPEND BLENDER_GLEW_LIBRARIES bf_intern_glew_mx)
+
 if(WITH_SYSTEM_GLEW)
 	find_package(GLEW)
 
@@ -2286,10 +2288,6 @@ else()
 
 endif()
 
-if(WITH_GLEW_MX)
-	list(APPEND BLENDER_GLEW_LIBRARIES bf_intern_glew_mx)
-endif()
-
 if(NOT WITH_GLU)
 	list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
 endif()
diff --git a/intern/cycles/util/util_view.cpp b/intern/cycles/util/util_view.cpp
index 2ab2cfb..fe08389 100644
--- a/intern/cycles/util/util_view.cpp
+++ b/intern/cycles/util/util_view.cpp
@@ -248,8 +248,7 @@ void view_main_loop(const char *title, int width, int height,
 	glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
 	glutCreateWindow(title);
 
-	mxSetContext(mxCreateContext());
-	glewInit();
+	mxMakeCurrentContext(mxCreateContext());
 
 	view_reshape(width, height);
 
diff --git a/intern/ghost/intern/GHOST_Context.cpp b/intern/ghost/intern/GHOST_Context.cpp
index 8866198..1b0e8d7 100644
--- a/intern/ghost/intern/GHOST_Context.cpp
+++ b/intern/ghost/intern/GHOST_Context.cpp
@@ -42,85 +42,6 @@
 #include <cstring>
 
 
-static const char *get_glew_error_message_string(GLenum error)
-{
-	switch (error) {
-		case GLEW_OK: /* also GLEW_NO_ERROR */
-			return "OK";
-
-		case GLEW_ERROR_NO_GL_VERSION:
-			return "Unable to determine GL version.";
-
-		case GLEW_ERROR_GL_VERSION_10_ONLY:
-			return "OpenGL 1.1 or later is required.";
-
-		case GLEW_ERROR_GLX_VERSION_11_ONLY:
-			return "GLX 1.2 or later is required.";
-
-#ifdef WITH_GLEW_ES
-		case GLEW_ERROR_NOT_GLES_VERSION:
-			return "OpenGL ES is required.";
-
-		case GLEW_ERROR_GLES_VERSION:
-			return "A non-ES version of OpenGL is required.";
-
-		case GLEW_ERROR_NO_EGL_VERSION:
-			return "Unabled to determine EGL version.";
-
-		case GLEW_ERROR_EGL_VERSION_10_ONLY:
-			return "EGL 1.1 or later is required.";
-#endif
-
-		default:
-			return NULL;
-	}
-}
-
-
-static const char *get_glew_error_enum_string(GLenum error)
-{
-	switch (error) {
-		CASE_CODE_RETURN_STR(GLEW_OK) /* also GLEW_NO_ERROR */
-		CASE_CODE_RETURN_STR(GLEW_ERROR_NO_GL_VERSION)
-		CASE_CODE_RETURN_STR(GLEW_ERROR_GL_VERSION_10_ONLY)
-		CASE_CODE_RETURN_STR(GLEW_ERROR_GLX_VERSION_11_ONLY)
-#ifdef WITH_GLEW_ES
-		CASE_CODE_RETURN_STR(GLEW_ERROR_NOT_GLES_VERSION)
-		CASE_CODE_RETURN_STR(GLEW_ERROR_GLES_VERSION)
-		CASE_CODE_RETURN_STR(GLEW_ERROR_NO_EGL_VERSION)
-		CASE_CODE_RETURN_STR(GLEW_ERROR_EGL_VERSION_10_ONLY)
-#endif
-		default:
-			return NULL;
-	}
-}
-
-
-GLenum glew_chk(GLenum error, const char *file, int line, const char *text)
-{
-	if (error != GLEW_OK) {
-		const char *code = get_glew_error_enum_string(error);
-		const char *msg  = get_glew_error_message_string(error);
-
-#ifndef NDEBUG
-		fprintf(stderr,
-		        "%s(%d):[%s] -> GLEW Error (0x%04X): %s: %s\n",
-		        file, line, text, error,
-		        code ? code : "<no symbol>",
-		        msg  ? msg  : "<no message>");
-#else
-		fprintf(stderr,
-		        "GLEW Error (%04X): %s: %s\n",
-		        error,
-		        code ? code : "<no symbol>",
-		        msg  ? msg  : "<no message>");
-#endif
-	}
-
-	return error;
-}
-
-
 #ifdef _WIN32
 
 bool win32_chk(bool result, const char *file, int line, const char *text)
@@ -218,13 +139,11 @@ bool win32_chk(bool result, const char *file, int line, const char *text)
 
 void GHOST_Context::initContextGLEW()
 {
-	mxDestroyContext(m_glewContext); // no-op if m_glewContext is NULL
-
-	mxSetContext(mxCreateContext());
+	mxDestroyContext(m_mxContext); // no-op if m_mxContext is NULL
 
-	m_glewContext = mxGetContext();
+	mxMakeCurrentContext(mxCreateContext());
 
-	GLEW_CHK(glewInit());
+	m_mxContext = mxGetCurrentContext();
 }
 
 
diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index 37d2040..0dfea86 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -51,14 +51,14 @@ public:
 	GHOST_Context(bool stereoVisual, GHOST_TUns16 numOfAASamples)
 	    : m_stereoVisual(stereoVisual),
 	      m_numOfAASamples(numOfAASamples),
-	      m_glewContext(NULL)
+	      m_mxContext(NULL)
 	{}
 
 	/**
 	 * Destructor.
 	 */
 	virtual ~GHOST_Context() {
-		mxDestroyContext(m_glewContext);
+		mxDestroyContext(m_mxContext);
 	}
 
 	/**
@@ -129,7 +129,7 @@ protected:
 	void initContextGLEW();
 
 	inline void activateGLEW() const {
-		mxSetContext(m_glewContext);
+		mxMakeCurrentContext(m_mxContext);
 	}
 
 	bool m_stereoVisual;
@@ -139,7 +139,7 @@ protected:
 	static void initClearGL();
 
 private:
-	GLEWContext *m_glewContext;
+	MXContext *m_mxContext;
 
 #ifdef WITH_CXX_GUARDEDALLOC
 	MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_Context")
@@ -147,15 +147,6 @@ private:
 };
 
 
-GLenum glew_chk(GLenum error, const char *file, int line, const char *text);
-
-#ifndef NDEBUG
-#  define GLEW_CHK(x) glew_chk((x), __FILE__, __LINE__, #x)
-#else
-#  define GLEW_CHK(x) x
-#endif
-
-
 #ifdef _WIN32
 bool win32_chk(bool result, const char *file = NULL, int line = 0, const char *text = NULL);
 
@@ -166,6 +157,5 @@ bool win32_chk(bool result, const char *file = NULL, int line = 0, const char *t
 #  endif
 #endif  /* _WIN32 */
 
-#define CASE_CODE_RETURN_STR(code) case code: return #code;
 
 #endif // __GHOST_CONTEXT_H__
diff --git a/intern/ghost/intern/GHOST_ContextEGL.cpp b/intern/ghost/intern/GHOST_ContextEGL.cpp
index 8a4c33d..fd8f772 100644
--- a/intern/ghost/intern/GHOST_ContextEGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextEGL.cpp
@@ -47,6 +47,8 @@ EGLEWContext *eglewContext = NULL;
 #endif
 
 
+#define CASE_CODE_RETURN_STR(code) case code: return #code;
+
 static const char *get_egl_error_enum_string(EGLenum error)
 {
 	switch (error) {
diff --git a/intern/glew-mx/glew-mx.h b/intern/glew-mx/glew-mx.h
index fa96c1c..5a8ee5b 100644
--- a/intern/glew-mx/glew-mx.h
+++ b/intern/glew-mx/glew-mx.h
@@ -27,48 +27,87 @@
 
 /** \file glew-mx.h
  *  \ingroup glew-mx
- * GLEW Context Management
+ *
+ * Support for GLEW Multimple rendering conteXts (MX)
+ * Maintained as a Blender Library.
+ *
+ * Different rendering contexts may have different entry points
+ * to extension functions of the same name.  So it can cause
+ * problems if, for example, a second context uses a pointer to
+ * say, glActiveTextureARB, that was queried from the first context.
+ *
+ * GLEW has basic support for multiple contexts by enabling WITH_GLEW_MX,
+ * but it does not provide a full implementation.  This is because
+ * there are too many questions about thread safety and memory
+ * allocation that are up to the user of GLEW.
+ *
+ * This implementation is very basic and isn't thread safe.
+ * For a single context the overhead should be
+ * no more than using GLEW without WITH_GLEW_MX enabled.
  */
 
 #ifndef __GLEW_MX_H__
 #define __GLEW_MX_H__
 
 #ifdef WITH_GLEW_MX
-/* glew its self expects this */
-#define GLEW_MX 1
-
-#define glewGetContext() _mxContext
+/* glew itself expects this */
+#  define GLEW_MX 1
+#  define glewGetContext() (&(_mx_context->glew_context))
 #endif
 
 #include <GL/glew.h>
 
-#ifdef WITH_GLEW_MX
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-extern GLEWContext *_mxContext;
+/* MXContext is used instead of GLEWContext directly so that
+   extending what data is held by a context is easier.
+ */
+typedef struct MXContext {
+#ifdef WITH_GLEW_MX
+	GLEWContext glew_context;
+#endif
+
+	int reserved; /* structs need at least one member */
 
-GLEWContext *mxGetContext(void);
-void mxSetContext(GLEWContext *ctx);
-GLEWContext *mxCreateContext(void);
-void mxDestroyContext(GLEWContext *ctx);
+} MXContext;
 
-#ifdef __cplusplus
-}
-#endif
+extern MXContext *_mx_context;
 
-#else
 
-typedef struct GLEWContext GLEWContext;
+MXContext *mxCreateContext(void);
+
+
+#ifdef WITH_GLEW_MX
+
+MXContext *mxGetCurrentContext (void);
+void       mxMakeCurrentContext(MXContext *ctx);
+void       mxDestroyContext    (MXContext *ctx);
+
+#else
 
 /* don't use NULL here (mightn't be defined)*/
-#define mxGetContext()          ((GLEWContext *)0)
-#define mxSetContext(ctx)       ((void)ctx)
-#define mxCreateContext()       ((GLEWContext *)0)
-#define mxDestroyContext(ctx)   ((void)ctx)
+#define mxGetCurrentContext()     ((MXContext *)0)
+#define mxMakeCurrentContext(ctx) ((void)ctx)
+#define mxDestroyContext(ctx)     ((void)ctx)
 
 #endif  /* WITH_GLEW_MX */
 
+
+GLenum glew_chk(GLenum error, const char *file, int line, const char *text);
+
+#ifndef NDEBUG
+#  define GLEW_CHK(x) glew_chk((x), __FILE__, __LINE__, #x)
+#else
+#  define GLEW_CHK(x) glew_chk((x), NULL, 0, NULL)
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
 #endif  /* __GLEW_MX_H__ */
diff --git a/intern/glew-mx/intern/glew-mx.c b/intern/glew-mx/intern/glew-mx.c
index 1915a78..713e094 100644
--- a/intern/glew-mx/intern/glew-mx.c
+++ b/intern/glew-mx/intern/glew-mx.c
@@ -27,52 +27,108 @@
 
 /** \file glew-mx.c
  *  \ingroup glew-mx
- *
- * Support for GLEW Multimple rendering conteXts (MX)
- * Maintained as a Blender Library.
- *
- * Different rendering contexts may have different entry points
- * to extension functions of the same name.  So it can cause
- * problems if, for example, a second context uses a pointer to
- * say, glActiveTextureARB, that was queried from the first context.
- *
- * GLEW has basic support for multiple contexts by enabling WITH_GLEW_MX,
- * but it does not provide a full implementation.  This is because
- * there are too many questions about thread safety and memory
- * allocation that are up to the user of GLEW.
- *
- * This implementation is very basic and isn't thread safe.
- * For a single context the overhead should be
- * no more than using GLEW without WITH_GLEW_MX enabled.
  */
 
-#ifdef WITH_GLEW_MX
-
 #include "glew-mx.h"
 
+#include <stdio.h>
 #include <stdlib.h>
 
-GLEWContext *_mxContext = NULL;
 
-GLEWContext *mxGetContext(void)
+#define CASE_CODE_RETURN_STR(code) case code: return #code;
+
+static const char *get_glew_error_enum_string(GLenum error)
+{
+	switch (error) {
+		CASE_CODE_RETURN_STR(GLEW_OK) /* also GLEW_NO_ERROR */
+		CASE_CODE_RETURN_STR(GLEW_ERROR_NO_GL_VERSION)
+		CASE_CODE_RETURN_STR

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list