Browse Source

Platform: move eglErrorString() helper to separate header.

It will be useful also elsewhere.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
5cd544b06d
  1. 4
      src/Magnum/Platform/CMakeLists.txt
  2. 54
      src/Magnum/Platform/Implementation/Egl.cpp
  3. 36
      src/Magnum/Platform/Implementation/Egl.h
  4. 40
      src/Magnum/Platform/Implementation/EglContextHandler.cpp
  5. 2
      src/Magnum/Platform/Implementation/EglContextHandler.h

4
src/Magnum/Platform/CMakeLists.txt

@ -171,7 +171,9 @@ if(NEED_EGLCONTEXT)
if(NOT EGL_FOUND) 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.") message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*APPLICATION to OFF to skip building them.")
endif() 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 # X11 macros are a mess, disable warnings for C-style casts
set_target_properties(MagnumEglContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") set_target_properties(MagnumEglContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
endif() endif()

54
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š <mosra@centrum.cz>
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)";
}
}}}

36
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š <mosra@centrum.cz>
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/egl.h>
namespace Magnum { namespace Platform { namespace Implementation {
const char* eglErrorString(EGLint error);
}}}
#endif

40
src/Magnum/Platform/Implementation/EglContextHandler.cpp

@ -32,6 +32,8 @@
#include "Magnum/Context.h" #include "Magnum/Context.h"
#include "Magnum/Version.h" #include "Magnum/Version.h"
#include "Egl.h"
namespace Magnum { namespace Platform { namespace Implementation { namespace Magnum { namespace Platform { namespace Implementation {
EglContextHandler::~EglContextHandler() { EglContextHandler::~EglContextHandler() {
@ -44,7 +46,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) {
/* Initialize */ /* Initialize */
display = eglGetDisplay(nativeDisplay); display = eglGetDisplay(nativeDisplay);
if(!eglInitialize(display, nullptr, nullptr)) { if(!eglInitialize(display, nullptr, nullptr)) {
Error() << "Cannot initialize EGL:" << errorString(eglGetError()); Error() << "Cannot initialize EGL:" << Implementation::eglErrorString(eglGetError());
std::exit(1); std::exit(1);
} }
@ -54,7 +56,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) {
EGLenum api = EGL_OPENGL_ES_API; EGLenum api = EGL_OPENGL_ES_API;
#endif #endif
if(!eglBindAPI(api)) { if(!eglBindAPI(api)) {
Error() << "Cannot bind EGL API:" << errorString(eglGetError()); Error() << "Cannot bind EGL API:" << Implementation::eglErrorString(eglGetError());
std::exit(1); std::exit(1);
} }
@ -77,7 +79,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) {
}; };
EGLint configCount; EGLint configCount;
if(!eglChooseConfig(display, attribs, &config, 1, &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); std::exit(1);
} }
@ -89,7 +91,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) {
/* Get visual ID */ /* Get visual ID */
EGLint visualId; EGLint visualId;
if(!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &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); std::exit(1);
} }
@ -140,40 +142,16 @@ void EglContextHandler::createContext(const AbstractXApplication::Configuration&
} }
#endif #endif
if(!eglCreateContext(display, config, EGL_NO_CONTEXT, attributes)) { if(!(context = eglCreateContext(display, config, EGL_NO_CONTEXT, attributes))) {
Error() << "Cannot create EGL context:" << errorString(eglGetError()); Error() << "Cannot create EGL context:" << Implementation::eglErrorString(eglGetError());
std::exit(1); std::exit(1);
} }
if(!(surface = eglCreateWindowSurface(display, config, window, nullptr))) { 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); std::exit(1);
} }
/** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */ /** @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 {};
}
}}} }}}

2
src/Magnum/Platform/Implementation/EglContextHandler.h

@ -71,8 +71,6 @@ class EglContextHandler: public AbstractContextHandler<AbstractXApplication::Con
} }
private: private:
const char* errorString(EGLint error);
EGLDisplay display; EGLDisplay display;
EGLConfig config; EGLConfig config;
EGLSurface surface; EGLSurface surface;

Loading…
Cancel
Save