[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58594] branches/soc-2013-viewport_fx: Implemented GHOST_ContextEGL.cpp (untested)
Jason Wilkins
Jason.A.Wilkins at gmail.com
Thu Jul 25 12:04:05 CEST 2013
Revision: 58594
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58594
Author: jwilkins
Date: 2013-07-25 10:04:05 +0000 (Thu, 25 Jul 2013)
Log Message:
-----------
Implemented GHOST_ContextEGL.cpp (untested)
Modified Paths:
--------------
branches/soc-2013-viewport_fx/extern/glew-es/include/GL/eglew.h
branches/soc-2013-viewport_fx/extern/glew-es/src/glew.c
branches/soc-2013-viewport_fx/intern/ghost/CMakeLists.txt
branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_Context.h
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_WindowWin32.cpp
Added Paths:
-----------
branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextNone.cpp
branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextNone.h
Modified: branches/soc-2013-viewport_fx/extern/glew-es/include/GL/eglew.h
===================================================================
--- branches/soc-2013-viewport_fx/extern/glew-es/include/GL/eglew.h 2013-07-25 08:36:35 UTC (rev 58593)
+++ branches/soc-2013-viewport_fx/extern/glew-es/include/GL/eglew.h 2013-07-25 10:04:05 UTC (rev 58594)
@@ -1366,7 +1366,7 @@
#define EGLEW_GET_VAR(x) (*(const GLboolean*)&x)
#define EGLEW_GET_FUN(x) x
-extern GLenum eglewContextInit (void); // XXX jwilkins: context handling not really written yet?
+extern GLenum eglewContextInit (EGLDisplay display); // XXX jwilkins: context handling not really written yet?
#define eglewInit eglewContextInit // XXX jwilkins: context handling not really written yet?
extern GLboolean eglewIsSupported (const char* name);
Modified: branches/soc-2013-viewport_fx/extern/glew-es/src/glew.c
===================================================================
--- branches/soc-2013-viewport_fx/extern/glew-es/src/glew.c 2013-07-25 08:36:35 UTC (rev 58593)
+++ branches/soc-2013-viewport_fx/extern/glew-es/src/glew.c 2013-07-25 10:04:05 UTC (rev 58594)
@@ -93,7 +93,7 @@
# define GLXEW_CONTEXT_ARG_DEF_LIST GLXEWContext* ctx
# endif
# endif /* _WIN32 */
-# define GLEW_CONTEXT_ARG_DEF_LIST GLEWContext* ctx
+# define GLEW_CONTEXT_ARG_DEF_LIST EGLDisplay display, GLEWContext* ctx
#else /* GLEW_MX */
# define GLEW_CONTEXT_ARG_DEF_INIT void
# define GLEW_CONTEXT_ARG_VAR_INIT
@@ -103,7 +103,7 @@
# define GLXEW_CONTEXT_ARG_DEF_INIT void
# define GLXEW_CONTEXT_ARG_DEF_LIST void
# define EGLEW_CONTEXT_ARG_DEF_INIT void
-# define EGLEW_CONTEXT_ARG_DEF_LIST void
+# define EGLEW_CONTEXT_ARG_DEF_LIST EGLDisplay display
#endif /* GLEW_MX */
#if defined(GLEW_USE_LIB_ES)
@@ -14353,7 +14353,7 @@
GLint major, minor;
const GLubyte* extStart;
const GLubyte* extEnd;
- s = (GLubyte*)eglQueryString(eglGetCurrentDisplay() , EGL_VERSION);
+ s = (GLubyte*)eglQueryString(display , EGL_VERSION);
dot = _glewStrCLen(s, '.');
if (dot == 0)
return GLEW_ERROR_NO_EGL_VERSION;
Modified: branches/soc-2013-viewport_fx/intern/ghost/CMakeLists.txt
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/CMakeLists.txt 2013-07-25 08:36:35 UTC (rev 58593)
+++ branches/soc-2013-viewport_fx/intern/ghost/CMakeLists.txt 2013-07-25 10:04:05 UTC (rev 58594)
@@ -39,6 +39,7 @@
intern/GHOST_C-api.cpp
intern/GHOST_CallbackEventConsumer.cpp
intern/GHOST_Context.cpp
+ intern/GHOST_ContextNone.cpp
intern/GHOST_DisplayManager.cpp
intern/GHOST_EventManager.cpp
intern/GHOST_ISystem.cpp
@@ -66,6 +67,7 @@
intern/GHOST_Buttons.h
intern/GHOST_CallbackEventConsumer.h
intern/GHOST_Context.h
+ intern/GHOST_ContextNone.h
intern/GHOST_Debug.h
intern/GHOST_DisplayManager.h
intern/GHOST_Event.h
Modified: branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_Context.h
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_Context.h 2013-07-25 08:36:35 UTC (rev 58593)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_Context.h 2013-07-25 10:04:05 UTC (rev 58594)
@@ -33,5 +33,46 @@
#ifndef __GHOST_CONTEXT_H__
#define __GHOST_CONTEXT_H__
+#include "GHOST_Types.h"
+
+
+class GHOST_Context
+{
+public:
+ /**
+ * Destructor.
+ */
+ virtual ~GHOST_Context()
+ {}
+
+ /**
+ * Swaps front and back buffers of a window.
+ * \return A boolean success indicator.
+ */
+ virtual GHOST_TSuccess swapBuffers() = 0;
+
+ /**
+ * Activates the drawing context of this window.
+ * \return A boolean success indicator.
+ */
+ virtual GHOST_TSuccess activateDrawingContext() = 0;
+
+ /**
+ * Tries to install a rendering context in this window.
+ * \param stereoVisual Stereo visual for quad buffered stereo.
+ * \param numOfAASamples Number of samples used for AA (zero if no AA)
+ * \return Indication as to whether installation has succeeded.
+ */
+ virtual GHOST_TSuccess installDrawingContext(bool stereoVisual = false, GHOST_TUns16 numOfAASamples = 0) = 0;
+
+ /**
+ * Removes the current drawing context.
+ * \return Indication as to whether removal has succeeded.
+ */
+ virtual GHOST_TSuccess removeDrawingContext() = 0;
+};
+
+
+
#endif // __GHOST_CONTEXT_H__
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-25 08:36:35 UTC (rev 58593)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextEGL.cpp 2013-07-25 10:04:05 UTC (rev 58594)
@@ -30,3 +30,312 @@
* Definition of GHOST_ContextEGL class.
*/
+#include "GHOST_ContextEGL.h"
+
+#include <cassert>
+#include <cstdio>
+#include <vector>
+
+
+
+static const char* get_egl_error_string(EGLenum error)
+{
+ switch(error) {
+ case EGL_SUCCESS:
+ return "The last function succeeded without error.";
+
+ case EGL_NOT_INITIALIZED:
+ return "EGL is not initialized, or could not be initialized, for the specified EGL display connection.";
+
+ case EGL_BAD_ACCESS:
+ return "EGL cannot access a requested resource (for example a context is bound in another thread).";
+
+ case EGL_BAD_ALLOC:
+ return "EGL failed to allocate resources for the requested operation.";
+
+ case EGL_BAD_ATTRIBUTE:
+ return "An unrecognized attribute or attribute value was passed in the attribute list.";
+
+ case EGL_BAD_CONTEXT:
+ return "An EGLContext argument does not name a valid EGL rendering context.";
+
+ case EGL_BAD_CONFIG:
+ return "An EGLConfig argument does not name a valid EGL frame buffer configuration.";
+
+ case EGL_BAD_CURRENT_SURFACE:
+ return "The current surface of the calling thread is a window, pixel buffer or pixmap that is no longer valid.";
+
+ case EGL_BAD_DISPLAY:
+ return "An EGLDisplay argument does not name a valid EGL display connection.";
+
+ case EGL_BAD_SURFACE:
+ return "An EGLSurface argument does not name a valid surface (window, pixel buffer or pixmap) configured for GL rendering.";
+
+ case EGL_BAD_MATCH:
+ return "Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface).";
+
+ case EGL_BAD_PARAMETER:
+ return "One or more argument values are invalid.";
+
+ case EGL_BAD_NATIVE_PIXMAP:
+ return "A NativePixmapType argument does not refer to a valid native pixmap.";
+
+ case EGL_BAD_NATIVE_WINDOW:
+ return "A NativeWindowType argument does not refer to a valid native window.";
+
+ case EGL_CONTEXT_LOST:
+ return "A power management event has occurred. The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering.";
+
+ default:
+ abort();
+ }
+}
+
+
+
+static inline bool egl_chk(bool result, const char* file, int line, const char* text)
+{
+ GLenum error;
+
+ for (;;) {
+ error = eglGetError();
+
+ if (error == EGL_SUCCESS)
+ break;
+
+ fprintf(stderr, "EGL Error: %s\n", get_egl_error_string(error));
+ fprintf(stderr, "%s(%d): %s\n", file, line, text);
+ }
+
+ return result;
+}
+
+
+
+#define EGL_CHK(x) egl_chk((x), __FILE__, __LINE__, #x)
+
+
+
+static inline void bindAPI(EGLenum api)
+{
+ if (EGLEW_VERSION_1_2)
+ EGL_CHK(eglBindAPI(api));
+}
+
+
+
+#if defined(WITH_ANGLE)
+HMODULE GHOST_ContextEGL::s_d3dcompiler = NULL;
+#endif
+
+
+
+bool GHOST_ContextEGL::s_eglewInitialized = false;
+
+
+
+EGLContext GHOST_ContextEGL::s_gl_sharedContext = NULL;
+EGLint GHOST_ContextEGL::s_gl_sharedCount = 0;
+
+EGLContext GHOST_ContextEGL::s_gles_sharedContext = NULL;
+EGLint GHOST_ContextEGL::s_gles_sharedCount = 0;
+
+EGLContext GHOST_ContextEGL::s_vg_sharedContext = NULL;
+EGLint GHOST_ContextEGL::s_vg_sharedCount = 0;
+
+
+
+template <typename T>
+T& choose_api(EGLenum api, T& a, T& b, T& c)
+{
+ switch(api) {
+ case EGL_OPENGL_API:
+ return a;
+ case EGL_OPENGL_ES_API:
+ return b;
+ case EGL_OPENVG_API:
+ return c;
+ default:
+ abort();
+ }
+}
+
+
+
+GHOST_ContextEGL::GHOST_ContextEGL(EGLenum api, EGLint egl_ContextClientVersion)
+ : m_display(EGL_NO_DISPLAY)
+ , m_surface(EGL_NO_SURFACE)
+ , m_context(EGL_NO_CONTEXT)
+ , m_api(api)
+ , m_egl_ContextClientVersion(egl_ContextClientVersion)
+ , 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))
+{ }
+
+
+GHOST_ContextEGL::~GHOST_ContextEGL()
+{
+ removeDrawingContext();
+
+ // Note: If multiple GHOST_ContextEGL are initialized with the same EGLNativeDisplayType then
+ // those other GHOST_ContextEGL will become invalid after this call to eglTerminate.
+ // See EGL 1.4 spec section 3.2
+ EGL_CHK(::eglTerminate(m_display));
+}
+
+
+
+GHOST_TSuccess GHOST_ContextEGL::swapBuffers()
+{
+ return EGL_CHK(eglSwapBuffers(m_display, m_surface)) ? GHOST_kSuccess : GHOST_kFailure;
+}
+
+
+
+GHOST_TSuccess GHOST_ContextEGL::activateDrawingContext()
+{
+ bindAPI(m_api);
+
+ return EGL_CHK(::eglMakeCurrent(m_display, m_surface, m_surface, m_context)) ? GHOST_kSuccess : GHOST_kFailure;
+}
+
+
+
+GHOST_TSuccess GHOST_ContextEGL::installDrawingContext(bool stereoVisual, GHOST_TUns16 numOfAASamples)
+{
+ if (stereoVisual)
+ return GHOST_kFailure;
+
+#if defined(WITH_ANGLE)
+ // d3dcompiler_XX.dll needs to be loaded before ANGLE will work
+ if (s_d3dcompiler == NULL) {
+ s_d3dcompiler = LoadLibrary(D3DCOMPILER);
+
+ if (s_d3dcompiler == NULL) {
+ printf("LoadLibrary(\"" D3DCOMPILER "\") failed!\n");
+ return GHOST_kFailure;
+ }
+ }
+#endif
+
+ m_display = ::eglGetDisplay(m_nativeDisplay);
+
+ if (EGL_CHK(m_display == EGL_NO_DISPLAY))
+ return GHOST_kFailure;
+
+ EGLint major, minor;
+
+ if (!EGL_CHK(::eglInitialize(m_display, &major, &minor)))
+ return GHOST_kFailure;
+
+ printf("EGL %d.%d\n", major, minor);
+
+ if (!s_eglewInitialized) {
+ if (eglewInit(m_display) == GLEW_OK) {
+ s_eglewInitialized = true;
+ }
+ else {
+ return GHOST_kFailure;
+ }
+ }
+
+ bindAPI(m_api);
+
+ std::vector<EGLint> attrib_list;
+ attrib_list.reserve(20);
+
+ attrib_list.push_back(EGL_RED_SIZE);
+ attrib_list.push_back(8);
+
+ attrib_list.push_back(EGL_GREEN_SIZE);
+ attrib_list.push_back(8);
+
+ attrib_list.push_back(EGL_BLUE_SIZE);
+ attrib_list.push_back(8);
+
+#ifdef GHOST_OPENGL_ALPHA
+ attrib_list.push_back(EGL_ALPHA_SIZE);
+ attrib_list.push_back(8);
+#endif
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list