Browse Source

Platform: unified and cleaned up context creation.

Added missing tryCreateContext() implementations. Error messages are
printed only by tryCreateContext(), createContext() is only a thin
wrapper which exits the application if tryCreateContext() fails and
doesn't print any additional information on the output.

Hopefully I didn't break anything :-)
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
77677ff48d
  1. 11
      src/Platform/AbstractXApplication.cpp
  2. 3
      src/Platform/AbstractXApplication.h
  3. 9
      src/Platform/GlutApplication.cpp
  4. 10
      src/Platform/NaClApplication.cpp
  5. 10
      src/Platform/Sdl2Application.cpp
  6. 25
      src/Platform/WindowlessGlxApplication.cpp
  7. 3
      src/Platform/WindowlessGlxApplication.h
  8. 10
      src/Platform/WindowlessNaClApplication.cpp

11
src/Platform/AbstractXApplication.cpp

@ -51,7 +51,11 @@ AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandle
AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&, std::nullptr_t): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {}
void AbstractXApplication::createContext(const Configuration& configuration) {
CORRADE_ASSERT(!c, "AbstractXApplication::createContext(): context already created", );
if(!tryCreateContext(configuration)) std::exit(1);
}
bool AbstractXApplication::tryCreateContext(const Configuration& configuration) {
CORRADE_ASSERT(!c, "AbstractXApplication::tryCreateContext(): context already created", );
viewportSize = configuration.size();
@ -67,8 +71,8 @@ void AbstractXApplication::createContext(const Configuration& configuration) {
visTemplate.visualid = visualId;
visInfo = XGetVisualInfo(display, VisualIDMask, &visTemplate, &visualCount);
if(!visInfo) {
Error() << "Cannot get X visual";
std::exit(1);
Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): cannot get X visual";
return false;
}
/* Create X Window */
@ -97,6 +101,7 @@ void AbstractXApplication::createContext(const Configuration& configuration) {
contextHandler->makeCurrent();
c = new Context;
return true;
}
AbstractXApplication::~AbstractXApplication() {

3
src/Platform/AbstractXApplication.h

@ -90,6 +90,9 @@ class AbstractXApplication {
/** @copydoc Sdl2Application::createContext() */
void createContext(const Configuration& configuration);
/** @copydoc Sdl2Application::tryCreateContext() */
bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */
/** @copydoc Sdl2Application::viewportEvent() */

9
src/Platform/GlutApplication.cpp

@ -60,10 +60,7 @@ void GlutApplication::initialize(int& argc, char** argv) {
}
void GlutApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) {
Error() << "Platform::GlutApplication::createContext(): cannot create context";
std::exit(1);
}
if(!tryCreateContext(configuration)) std::exit(1);
}
bool GlutApplication::tryCreateContext(const Configuration& configuration) {
@ -76,8 +73,10 @@ bool GlutApplication::tryCreateContext(const Configuration& configuration) {
glutInitDisplayMode(flags);
glutInitWindowSize(configuration.size().x(), configuration.size().y());
if(!glutCreateWindow(configuration.title().data()))
if(!glutCreateWindow(configuration.title().data())) {
Error() << "Platform::GlutApplication::tryCreateContext(): cannot create context";
return false;
}
glutReshapeFunc(staticViewportEvent);
glutSpecialFunc(staticKeyEvent);
glutMouseFunc(staticMouseEvent);

10
src/Platform/NaClApplication.cpp

@ -69,10 +69,7 @@ NaClApplication::NaClApplication(const Arguments& arguments, std::nullptr_t): In
}
void NaClApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) {
Error() << "Platform::NaClApplication::createContext(): cannot create context";
std::exit(1);
}
if(!tryCreateContext(configuration)) std::exit(1);
}
bool NaClApplication::tryCreateContext(const Configuration& configuration) {
@ -93,13 +90,16 @@ bool NaClApplication::tryCreateContext(const Configuration& configuration) {
graphics = new pp::Graphics3D(this, attributes);
if(graphics->is_null()) {
Error() << "Platform::NaClApplication::tryCreateContext(): cannot create context";
delete graphics;
graphics = nullptr;
return false;
}
if(!BindGraphics(*graphics)) {
Error() << "Platform::NaClApplication::tryCreateContext(): cannot bind graphics";
std::exit(1);
delete graphics;
graphics = nullptr;
return false;
}
fullscreen = new pp::Fullscreen(this);

10
src/Platform/Sdl2Application.cpp

@ -89,10 +89,7 @@ void Sdl2Application::initialize() {
}
void Sdl2Application::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) {
Error() << "Platform::Sdl2Application::createContext(): cannot create context:" << SDL_GetError();
std::exit(1);
}
if(!tryCreateContext(configuration)) std::exit(1);
}
bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
@ -115,10 +112,13 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
if(!(window = SDL_CreateWindow(configuration.title().data(),
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
configuration.size().x(), configuration.size().y(),
SDL_WINDOW_OPENGL|flags)))
SDL_WINDOW_OPENGL|flags))) {
Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create window:" << SDL_GetError();
return false;
}
if(!(context = SDL_GL_CreateContext(window))) {
Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create context:" << SDL_GetError();
SDL_DestroyWindow(window);
window = nullptr;
return false;

25
src/Platform/WindowlessGlxApplication.cpp

@ -47,8 +47,12 @@ WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&): c(nullptr)
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, std::nullptr_t): c(nullptr) {}
void WindowlessGlxApplication::createContext(const Configuration&) {
CORRADE_ASSERT(!c, "WindowlessGlxApplication::createContext(): context already created", );
void WindowlessGlxApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) std::exit(1);
}
bool WindowlessGlxApplication::tryCreateContext(const Configuration&) {
CORRADE_ASSERT(!c, "Platform::WindowlessGlxApplication::tryCreateContext(): context already created", );
display = XOpenDisplay(nullptr);
@ -56,8 +60,8 @@ void WindowlessGlxApplication::createContext(const Configuration&) {
int major, minor;
glXQueryVersion(display, &major, &minor);
if(major == 1 && minor < 4) {
Error() << "WindowlessGlxApplication: GLX version 1.4 or greater is required.";
std::exit(1);
Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): GLX version 1.4 or greater is required";
return false;
}
/* Choose config */
@ -65,8 +69,8 @@ void WindowlessGlxApplication::createContext(const Configuration&) {
static const int fbAttributes[] = { None };
GLXFBConfig* configs = glXChooseFBConfig(display, DefaultScreen(display), fbAttributes, &configCount);
if(!configCount) {
Error() << "WindowlessGlxApplication: no supported framebuffer configuration found.";
std::exit(1);
Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): no supported framebuffer configuration found";
return false;
}
GLint contextAttributes[] = {
@ -82,8 +86,8 @@ void WindowlessGlxApplication::createContext(const Configuration&) {
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
context = glXCreateContextAttribsARB(display, configs[0], nullptr, True, contextAttributes);
if(!context) {
Error() << "WindowlessGlxApplication: cannot create context.";
std::exit(1);
Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): cannot create context";
return false;
}
/* Create pbuffer */
@ -98,11 +102,12 @@ void WindowlessGlxApplication::createContext(const Configuration&) {
/* Set OpenGL context as current */
if(!glXMakeContextCurrent(display, pbuffer, pbuffer, context)) {
Error() << "WindowlessGlxApplication: cannot make context current";
std::exit(1);
Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): cannot make context current";
return false;
}
c = new Context;
return true;
}
WindowlessGlxApplication::~WindowlessGlxApplication() {

3
src/Platform/WindowlessGlxApplication.h

@ -109,6 +109,9 @@ class WindowlessGlxApplication {
/** @copydoc Sdl2Application::createContext() */
void createContext(const Configuration& configuration);
/** @copydoc Sdl2Application::tryCreateContext() */
bool tryCreateContext(const Configuration& configuration);
private:
Display* display;
GLXContext context;

10
src/Platform/WindowlessNaClApplication.cpp

@ -68,10 +68,7 @@ WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments,
}
void WindowlessNaClApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) {
Error() << "Platform::WindowlessNaClApplication::createContext(): cannot create context";
std::exit(1);
}
if(!tryCreateContext(configuration)) std::exit(1);
}
bool WindowlessNaClApplication::tryCreateContext(const Configuration&) {
@ -88,13 +85,16 @@ bool WindowlessNaClApplication::tryCreateContext(const Configuration&) {
graphics = new pp::Graphics3D(this, attributes);
if(graphics->is_null()) {
Error() << "Platform::WindowlessNaClApplication::tryCreateContext(): cannot create context";
delete graphics;
graphics = nullptr;
return false;
}
if(!BindGraphics(*graphics)) {
Error() << "Platform::WindowlessNaClApplication::tryCreateContext(): cannot bind graphics";
std::exit(1);
delete graphics;
graphics = nullptr;
return false;
}
glSetCurrentContextPPAPI(graphics->pp_resource());

Loading…
Cancel
Save