diff --git a/src/Magnum/Platform/CMakeLists.txt b/src/Magnum/Platform/CMakeLists.txt index 1afd6dc0e..a3686d64d 100644 --- a/src/Magnum/Platform/CMakeLists.txt +++ b/src/Magnum/Platform/CMakeLists.txt @@ -171,7 +171,9 @@ if(NEED_EGLCONTEXT) if(NOT EGL_FOUND) message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*APPLICATION to OFF to skip building them.") endif() - add_library(MagnumEglContextHandler OBJECT Implementation/EglContextHandler.cpp) + add_library(MagnumEglContextHandler OBJECT + Implementation/EglContextHandler.cpp + Implementation/Egl.cpp) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumEglContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") endif() diff --git a/src/Magnum/Platform/Implementation/Egl.cpp b/src/Magnum/Platform/Implementation/Egl.cpp new file mode 100644 index 000000000..35c5fdda1 --- /dev/null +++ b/src/Magnum/Platform/Implementation/Egl.cpp @@ -0,0 +1,54 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Egl.h" + +namespace Magnum { namespace Platform { namespace Implementation { + +const char* eglErrorString(const EGLint error) { + switch(error) { + #define _error(name) case name: return #name; + _error(EGL_SUCCESS) + _error(EGL_NOT_INITIALIZED) + _error(EGL_BAD_ACCESS) + _error(EGL_BAD_ALLOC) + _error(EGL_BAD_ATTRIBUTE) + _error(EGL_BAD_CONTEXT) + _error(EGL_BAD_CONFIG) + _error(EGL_BAD_CURRENT_SURFACE) + _error(EGL_BAD_DISPLAY) + _error(EGL_BAD_SURFACE) + _error(EGL_BAD_MATCH) + _error(EGL_BAD_PARAMETER) + _error(EGL_BAD_NATIVE_PIXMAP) + _error(EGL_BAD_NATIVE_WINDOW) + _error(EGL_CONTEXT_LOST) + #undef _error + } + + return "EGL_(invalid)"; +} + +}}} diff --git a/src/Magnum/Platform/Implementation/Egl.h b/src/Magnum/Platform/Implementation/Egl.h new file mode 100644 index 000000000..a84e4fe4c --- /dev/null +++ b/src/Magnum/Platform/Implementation/Egl.h @@ -0,0 +1,36 @@ +#ifndef Magnum_Platform_Implementation_Egl_h +#define Magnum_Platform_Implementation_Egl_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +namespace Magnum { namespace Platform { namespace Implementation { + +const char* eglErrorString(EGLint error); + +}}} + +#endif diff --git a/src/Magnum/Platform/Implementation/EglContextHandler.cpp b/src/Magnum/Platform/Implementation/EglContextHandler.cpp index 9661d1960..153dd7bad 100644 --- a/src/Magnum/Platform/Implementation/EglContextHandler.cpp +++ b/src/Magnum/Platform/Implementation/EglContextHandler.cpp @@ -32,6 +32,8 @@ #include "Magnum/Context.h" #include "Magnum/Version.h" +#include "Egl.h" + namespace Magnum { namespace Platform { namespace Implementation { EglContextHandler::~EglContextHandler() { @@ -44,7 +46,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { /* Initialize */ display = eglGetDisplay(nativeDisplay); if(!eglInitialize(display, nullptr, nullptr)) { - Error() << "Cannot initialize EGL:" << errorString(eglGetError()); + Error() << "Cannot initialize EGL:" << Implementation::eglErrorString(eglGetError()); std::exit(1); } @@ -54,7 +56,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { EGLenum api = EGL_OPENGL_ES_API; #endif if(!eglBindAPI(api)) { - Error() << "Cannot bind EGL API:" << errorString(eglGetError()); + Error() << "Cannot bind EGL API:" << Implementation::eglErrorString(eglGetError()); std::exit(1); } @@ -77,7 +79,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { }; EGLint configCount; if(!eglChooseConfig(display, attribs, &config, 1, &configCount)) { - Error() << "Cannot get EGL visual config:" << errorString(eglGetError()); + Error() << "Cannot get EGL visual config:" << Implementation::eglErrorString(eglGetError()); std::exit(1); } @@ -89,7 +91,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { /* Get visual ID */ EGLint visualId; if(!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &visualId)) { - Error() << "Cannot get native visual ID:" << errorString(eglGetError()); + Error() << "Cannot get native visual ID:" << Implementation::eglErrorString(eglGetError()); std::exit(1); } @@ -140,40 +142,16 @@ void EglContextHandler::createContext(const AbstractXApplication::Configuration& } #endif - if(!eglCreateContext(display, config, EGL_NO_CONTEXT, attributes)) { - Error() << "Cannot create EGL context:" << errorString(eglGetError()); + if(!(context = eglCreateContext(display, config, EGL_NO_CONTEXT, attributes))) { + Error() << "Cannot create EGL context:" << Implementation::eglErrorString(eglGetError()); std::exit(1); } if(!(surface = eglCreateWindowSurface(display, config, window, nullptr))) { - Error() << "Cannot create window surface:" << errorString(eglGetError()); + Error() << "Cannot create window surface:" << Implementation::eglErrorString(eglGetError()); std::exit(1); } /** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */ } -const char* EglContextHandler::errorString(EGLint error) { - switch(error) { - #define _error(name) case name: return #name; - _error(EGL_SUCCESS) - _error(EGL_NOT_INITIALIZED) - _error(EGL_BAD_ACCESS) - _error(EGL_BAD_ALLOC) - _error(EGL_BAD_ATTRIBUTE) - _error(EGL_BAD_CONTEXT) - _error(EGL_BAD_CONFIG) - _error(EGL_BAD_CURRENT_SURFACE) - _error(EGL_BAD_DISPLAY) - _error(EGL_BAD_SURFACE) - _error(EGL_BAD_MATCH) - _error(EGL_BAD_PARAMETER) - _error(EGL_BAD_NATIVE_PIXMAP) - _error(EGL_BAD_NATIVE_WINDOW) - _error(EGL_CONTEXT_LOST) - #undef _error - } - - return {}; -} - }}} diff --git a/src/Magnum/Platform/Implementation/EglContextHandler.h b/src/Magnum/Platform/Implementation/EglContextHandler.h index 2a4ff5ae5..9fba78fd9 100644 --- a/src/Magnum/Platform/Implementation/EglContextHandler.h +++ b/src/Magnum/Platform/Implementation/EglContextHandler.h @@ -71,8 +71,6 @@ class EglContextHandler: public AbstractContextHandler