mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.9 KiB
96 lines
2.9 KiB
|
14 years ago
|
/*
|
||
|
|
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
|
Magnum is free software: you can redistribute it and/or modify
|
||
|
|
it under the terms of the GNU Lesser General Public License version 3
|
||
|
|
only, as published by the Free Software Foundation.
|
||
|
|
|
||
|
|
Magnum is distributed in the hope that it will be useful,
|
||
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
|
GNU Lesser General Public License version 3 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
14 years ago
|
#include "GlxContextHandler.h"
|
||
|
14 years ago
|
|
||
|
|
#include <GL/glxext.h>
|
||
|
14 years ago
|
#include <Utility/Debug.h>
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#include "Context.h"
|
||
|
|
|
||
|
14 years ago
|
#define None 0L // redef Xlib nonsense
|
||
|
|
|
||
|
14 years ago
|
namespace Magnum { namespace Platform {
|
||
|
14 years ago
|
|
||
|
14 years ago
|
VisualID GlxContextHandler::getVisualId(Display* nativeDisplay) {
|
||
|
14 years ago
|
display = nativeDisplay;
|
||
|
|
|
||
|
|
/* Check version */
|
||
|
|
int major, minor;
|
||
|
|
glXQueryVersion(nativeDisplay, &major, &minor);
|
||
|
|
if(major == 1 && minor < 4) {
|
||
|
14 years ago
|
Error() << "GlxContextHandler: GLX version 1.4 or greater is required.";
|
||
|
14 years ago
|
exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Choose config */
|
||
|
|
int configCount = 0;
|
||
|
|
static const int attributes[] = {
|
||
|
|
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||
|
|
GLX_X_RENDERABLE, True,
|
||
|
|
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
||
|
|
GLX_DOUBLEBUFFER, True,
|
||
|
|
GLX_RED_SIZE, 8,
|
||
|
|
GLX_GREEN_SIZE, 8,
|
||
|
|
GLX_BLUE_SIZE, 8,
|
||
|
|
0
|
||
|
|
};
|
||
|
|
configs = glXChooseFBConfig(nativeDisplay, DefaultScreen(nativeDisplay), attributes, &configCount);
|
||
|
|
if(!configCount) {
|
||
|
14 years ago
|
Error() << "GlxContextHandler: no supported framebuffer configuration found.";
|
||
|
14 years ago
|
exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Get visual ID */
|
||
|
|
XVisualInfo* info = glXGetVisualFromFBConfig(display, configs[0]);
|
||
|
|
VisualID visualId = info->visualid;
|
||
|
|
XFree(info);
|
||
|
|
|
||
|
|
return visualId;
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
void GlxContextHandler::createContext(Window nativeWindow) {
|
||
|
14 years ago
|
window = nativeWindow;
|
||
|
|
|
||
|
|
GLint attributes[] = {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||
|
14 years ago
|
GLX_CONTEXT_MINOR_VERSION_ARB, 2,
|
||
|
14 years ago
|
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||
|
|
#else
|
||
|
|
GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
|
||
|
|
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
|
||
|
|
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,
|
||
|
|
#endif
|
||
|
|
0
|
||
|
|
};
|
||
|
|
|
||
|
|
/** @todo Use some extension wrangler for this, not GLEW, as it apparently needs context to create context, yo dawg wtf. */
|
||
|
|
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
|
||
|
|
context = glXCreateContextAttribsARB(display, configs[0], 0, True, attributes);
|
||
|
|
XFree(configs);
|
||
|
|
if(!context) {
|
||
|
14 years ago
|
Error() << "GlxContextHandler: cannot create context.";
|
||
|
14 years ago
|
exit(1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
GlxContextHandler::~GlxContextHandler() {
|
||
|
14 years ago
|
glXMakeCurrent(display, None, nullptr);
|
||
|
|
glXDestroyContext(display, context);
|
||
|
|
}
|
||
|
|
|
||
|
|
}}
|