mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-19 06:51:09 +00:00
- add the X11 OpenGL init code, even though it is useless until someone repairs mono's winforms implementation
This commit is contained in:
parent
ebba32e7ba
commit
3b2d50cce0
4 changed files with 487 additions and 5 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "Precomp.h"
|
||||
#include "OpenGLContext.h"
|
||||
#include <CommCtrl.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
|
@ -238,34 +239,398 @@ HGLRC OpenGLCreationHelper::CreateContext(HDC hdc, int major_version, int minor_
|
|||
|
||||
#else
|
||||
|
||||
OpenGLContext::OpenGLContext(void* window)
|
||||
#include <cstdio>
|
||||
|
||||
#define GL_USE_DLOPEN // Using dlopen for linux by default
|
||||
|
||||
#ifdef GL_USE_DLOPEN
|
||||
#define GL_OPENGL_LIBRARY "libGL.so.1"
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#ifdef GL_USE_DLOPEN
|
||||
#define GL_LOAD_GLFUNC(x) dlsym(opengl_lib_handle, # x)
|
||||
#else
|
||||
#define GL_LOAD_GLFUNC(x) &x
|
||||
#endif
|
||||
|
||||
OpenGLContext::OpenGLContext(void* display, void* window) : disp((::Display*)display), window((::Window)window)
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateContext();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
// to do: maybe provide a way to query what the creation error was
|
||||
}
|
||||
}
|
||||
|
||||
OpenGLContext::~OpenGLContext()
|
||||
{
|
||||
if (opengl_visual_info)
|
||||
{
|
||||
XFree(opengl_visual_info);
|
||||
opengl_visual_info = nullptr;
|
||||
}
|
||||
|
||||
if (opengl_context)
|
||||
{
|
||||
if (glx.glXGetCurrentContext() == opengl_context)
|
||||
OpenGL::set_active(nullptr);
|
||||
|
||||
if (disp)
|
||||
glx.glXDestroyContext(disp, opengl_context);
|
||||
|
||||
opengl_context = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLContext::Begin()
|
||||
{
|
||||
refcount++;
|
||||
if (refcount == 1)
|
||||
glx.glXMakeCurrent(disp, window, opengl_context);
|
||||
}
|
||||
|
||||
void OpenGLContext::End()
|
||||
{
|
||||
refcount--;
|
||||
if (refcount == 0)
|
||||
glx.glXMakeCurrent(0, 0, opengl_context);
|
||||
}
|
||||
|
||||
void OpenGLContext::SwapBuffers()
|
||||
{
|
||||
Begin();
|
||||
glx.glXSwapBuffers(disp, window);
|
||||
End();
|
||||
}
|
||||
|
||||
int OpenGLContext::GetWidth() const
|
||||
{
|
||||
return 0;
|
||||
::Window root_window;
|
||||
int x, y;
|
||||
unsigned int width, height, border_width, border_height, depth;
|
||||
Status result = XGetGeometry(disp, window, &root_window, &x, &y, &width, &height, &border_width, &border_height, &depth);
|
||||
return (result != 0) ? width: 0;
|
||||
}
|
||||
|
||||
int OpenGLContext::GetHeight() const
|
||||
{
|
||||
::Window root_window;
|
||||
int x, y;
|
||||
unsigned int width, height, border_width, border_height, depth;
|
||||
Status result = XGetGeometry(disp, window, &root_window, &x, &y, &width, &height, &border_width, &border_height, &depth);
|
||||
return (result != 0) ? height : 0;
|
||||
}
|
||||
|
||||
ProcAddress* OpenGLContext::get_proc_address(const char *function_name) const
|
||||
{
|
||||
if (glx.glXGetProcAddressARB)
|
||||
return glx.glXGetProcAddressARB((GLubyte*)function_name);
|
||||
else if (glx.glXGetProcAddress)
|
||||
return glx.glXGetProcAddress((GLubyte*)function_name);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void OpenGLContext::CreateContext()
|
||||
{
|
||||
#ifdef GL_USE_DLOPEN
|
||||
opengl_lib_handle = dlopen(GL_OPENGL_LIBRARY, RTLD_NOW | RTLD_GLOBAL);
|
||||
if (!opengl_lib_handle)
|
||||
throw std::runtime_error(std::string("Cannot open opengl library: ") + GL_OPENGL_LIBRARY);
|
||||
#endif
|
||||
|
||||
glx.glXChooseVisual = (GL_GLXFunctions::ptr_glXChooseVisual) GL_LOAD_GLFUNC(glXChooseVisual);
|
||||
glx.glXCopyContext = (GL_GLXFunctions::ptr_glXCopyContext) GL_LOAD_GLFUNC(glXCopyContext);
|
||||
glx.glXCreateContext = (GL_GLXFunctions::ptr_glXCreateContext) GL_LOAD_GLFUNC(glXCreateContext);
|
||||
glx.glXCreateGLXPixmap = (GL_GLXFunctions::ptr_glXCreateGLXPixmap) GL_LOAD_GLFUNC(glXCreateGLXPixmap);
|
||||
glx.glXDestroyContext = (GL_GLXFunctions::ptr_glXDestroyContext) GL_LOAD_GLFUNC(glXDestroyContext);
|
||||
glx.glXDestroyGLXPixmap = (GL_GLXFunctions::ptr_glXDestroyGLXPixmap) GL_LOAD_GLFUNC(glXDestroyGLXPixmap);
|
||||
glx.glXGetConfig = (GL_GLXFunctions::ptr_glXGetConfig) GL_LOAD_GLFUNC(glXGetConfig);
|
||||
glx.glXGetCurrentContext = (GL_GLXFunctions::ptr_glXGetCurrentContext) GL_LOAD_GLFUNC(glXGetCurrentContext);
|
||||
glx.glXGetCurrentDrawable = (GL_GLXFunctions::ptr_glXGetCurrentDrawable) GL_LOAD_GLFUNC(glXGetCurrentDrawable);
|
||||
glx.glXIsDirect = (GL_GLXFunctions::ptr_glXIsDirect) GL_LOAD_GLFUNC(glXIsDirect);
|
||||
glx.glXMakeCurrent = (GL_GLXFunctions::ptr_glXMakeCurrent) GL_LOAD_GLFUNC(glXMakeCurrent);
|
||||
glx.glXQueryExtension = (GL_GLXFunctions::ptr_glXQueryExtension) GL_LOAD_GLFUNC(glXQueryExtension);
|
||||
glx.glXQueryVersion = (GL_GLXFunctions::ptr_glXQueryVersion) GL_LOAD_GLFUNC(glXQueryVersion);
|
||||
glx.glXSwapBuffers = (GL_GLXFunctions::ptr_glXSwapBuffers) GL_LOAD_GLFUNC(glXSwapBuffers);
|
||||
glx.glXUseXFont = (GL_GLXFunctions::ptr_glXUseXFont) GL_LOAD_GLFUNC(glXUseXFont);
|
||||
glx.glXWaitGL = (GL_GLXFunctions::ptr_glXWaitGL) GL_LOAD_GLFUNC(glXWaitGL);
|
||||
glx.glXWaitX = (GL_GLXFunctions::ptr_glXWaitX) GL_LOAD_GLFUNC(glXWaitX);
|
||||
glx.glXGetClientString = (GL_GLXFunctions::ptr_glXGetClientString) GL_LOAD_GLFUNC(glXGetClientString);
|
||||
glx.glXQueryServerString = (GL_GLXFunctions::ptr_glXQueryServerString) GL_LOAD_GLFUNC(glXQueryServerString);
|
||||
glx.glXQueryExtensionsString = (GL_GLXFunctions::ptr_glXQueryExtensionsString) GL_LOAD_GLFUNC(glXQueryExtensionsString);
|
||||
glx.glXGetCurrentDisplay = (GL_GLXFunctions::ptr_glXGetCurrentDisplay) GL_LOAD_GLFUNC(glXGetCurrentDisplay);
|
||||
glx.glXChooseFBConfig = (GL_GLXFunctions::ptr_glXChooseFBConfig) GL_LOAD_GLFUNC(glXChooseFBConfig);
|
||||
glx.glXCreateNewContext = (GL_GLXFunctions::ptr_glXCreateNewContext) GL_LOAD_GLFUNC(glXCreateNewContext);
|
||||
glx.glXCreatePbuffer = (GL_GLXFunctions::ptr_glXCreatePbuffer) GL_LOAD_GLFUNC(glXCreatePbuffer);
|
||||
glx.glXCreatePixmap = (GL_GLXFunctions::ptr_glXCreatePixmap) GL_LOAD_GLFUNC(glXCreatePixmap);
|
||||
glx.glXCreateWindow = (GL_GLXFunctions::ptr_glXCreateWindow) GL_LOAD_GLFUNC(glXCreateWindow);
|
||||
glx.glXDestroyPbuffer = (GL_GLXFunctions::ptr_glXDestroyPbuffer) GL_LOAD_GLFUNC(glXDestroyPbuffer);
|
||||
glx.glXDestroyPixmap = (GL_GLXFunctions::ptr_glXDestroyPixmap) GL_LOAD_GLFUNC(glXDestroyPixmap);
|
||||
glx.glXDestroyWindow = (GL_GLXFunctions::ptr_glXDestroyWindow) GL_LOAD_GLFUNC(glXDestroyWindow);
|
||||
glx.glXGetCurrentReadDrawable = (GL_GLXFunctions::ptr_glXGetCurrentReadDrawable) GL_LOAD_GLFUNC(glXGetCurrentReadDrawable);
|
||||
glx.glXGetFBConfigAttrib = (GL_GLXFunctions::ptr_glXGetFBConfigAttrib) GL_LOAD_GLFUNC(glXGetFBConfigAttrib);
|
||||
glx.glXGetFBConfigs = (GL_GLXFunctions::ptr_glXGetFBConfigs) GL_LOAD_GLFUNC(glXGetFBConfigs);
|
||||
glx.glXGetSelectedEvent = (GL_GLXFunctions::ptr_glXGetSelectedEvent) GL_LOAD_GLFUNC(glXGetSelectedEvent);
|
||||
glx.glXGetVisualFromFBConfig = (GL_GLXFunctions::ptr_glXGetVisualFromFBConfig) GL_LOAD_GLFUNC(glXGetVisualFromFBConfig);
|
||||
glx.glXMakeContextCurrent = (GL_GLXFunctions::ptr_glXMakeContextCurrent) GL_LOAD_GLFUNC(glXMakeContextCurrent);
|
||||
glx.glXQueryContext = (GL_GLXFunctions::ptr_glXQueryContext) GL_LOAD_GLFUNC(glXQueryContext);
|
||||
glx.glXQueryDrawable = (GL_GLXFunctions::ptr_glXQueryDrawable) GL_LOAD_GLFUNC(glXQueryDrawable);
|
||||
glx.glXSelectEvent = (GL_GLXFunctions::ptr_glXSelectEvent) GL_LOAD_GLFUNC(glXSelectEvent);
|
||||
|
||||
glx.glXGetProcAddressARB = (GL_GLXFunctions::ptr_glXGetProcAddressARB) GL_LOAD_GLFUNC(glXGetProcAddressARB);
|
||||
glx.glXGetProcAddress = (GL_GLXFunctions::ptr_glXGetProcAddress) GL_LOAD_GLFUNC(glXGetProcAddress);
|
||||
|
||||
if ((glx.glXDestroyContext == nullptr) ||
|
||||
(glx.glXMakeCurrent == nullptr) ||
|
||||
(glx.glXGetCurrentContext == nullptr) ||
|
||||
(glx.glXChooseVisual == nullptr) ||
|
||||
(glx.glXIsDirect == nullptr) ||
|
||||
(glx.glXGetConfig == nullptr) ||
|
||||
(glx.glXQueryExtensionsString == nullptr) ||
|
||||
(glx.glXQueryVersion == nullptr) ||
|
||||
(glx.glXGetVisualFromFBConfig == nullptr) ||
|
||||
(glx.glXCreateNewContext == nullptr) ||
|
||||
(glx.glXCreateContext == nullptr))
|
||||
{
|
||||
throw std::runtime_error("Cannot obtain required OpenGL GLX functions");
|
||||
}
|
||||
|
||||
if ((glx.glXGetProcAddressARB == nullptr) && (glx.glXGetProcAddress == nullptr))
|
||||
{
|
||||
throw std::runtime_error("Cannot obtain required OpenGL GLX functions");
|
||||
}
|
||||
|
||||
// FBConfigs were added in GLX version 1.3.
|
||||
int glx_major, glx_minor;
|
||||
if (!glx.glXQueryVersion(disp, &glx_major, &glx_minor) || ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1))
|
||||
throw std::runtime_error("GLX 1.3 or better is required");
|
||||
|
||||
create_glx_1_3(disp);
|
||||
|
||||
//if (!glx.glXIsDirect(disp, opengl_context))
|
||||
// printf("No hardware acceleration available. I hope you got a really fast machine.\n");
|
||||
}
|
||||
|
||||
void OpenGLContext::create_glx_1_3(::Display* disp)
|
||||
{
|
||||
if (glx.glXChooseFBConfig == nullptr)
|
||||
throw std::runtime_error("Cannot find the glXChooseFBConfig function");
|
||||
|
||||
// Setup OpenGL:
|
||||
int gl_attribs_single[] =
|
||||
{
|
||||
GLX_X_RENDERABLE, True,
|
||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
GLX_STENCIL_SIZE, 8,
|
||||
GLX_BUFFER_SIZE, 24,
|
||||
None
|
||||
};
|
||||
|
||||
std::vector<int> gl_attribs;
|
||||
gl_attribs.reserve(64);
|
||||
|
||||
gl_attribs.push_back(GLX_X_RENDERABLE);
|
||||
gl_attribs.push_back(True);
|
||||
gl_attribs.push_back(GLX_DRAWABLE_TYPE);
|
||||
gl_attribs.push_back(GLX_WINDOW_BIT);
|
||||
gl_attribs.push_back(GLX_RENDER_TYPE);
|
||||
gl_attribs.push_back(GLX_RGBA_BIT);
|
||||
gl_attribs.push_back(GLX_X_VISUAL_TYPE);
|
||||
gl_attribs.push_back(GLX_TRUE_COLOR);
|
||||
gl_attribs.push_back(GLX_RED_SIZE);
|
||||
gl_attribs.push_back(8);
|
||||
gl_attribs.push_back(GLX_GREEN_SIZE);
|
||||
gl_attribs.push_back(8);
|
||||
gl_attribs.push_back(GLX_BLUE_SIZE);
|
||||
gl_attribs.push_back(8);
|
||||
gl_attribs.push_back(GLX_ALPHA_SIZE);
|
||||
gl_attribs.push_back(8);
|
||||
gl_attribs.push_back(GLX_DEPTH_SIZE);
|
||||
gl_attribs.push_back(24);
|
||||
gl_attribs.push_back(GLX_STENCIL_SIZE);
|
||||
gl_attribs.push_back(8);
|
||||
gl_attribs.push_back(GLX_DOUBLEBUFFER);
|
||||
gl_attribs.push_back(True);
|
||||
gl_attribs.push_back(GLX_STEREO);
|
||||
gl_attribs.push_back(False);
|
||||
gl_attribs.push_back(None);
|
||||
|
||||
// get an appropriate visual
|
||||
int fb_count;
|
||||
GLXFBConfig* fbc = glx.glXChooseFBConfig(disp, DefaultScreen(disp), &gl_attribs[0], &fb_count);
|
||||
if (!fbc)
|
||||
{
|
||||
printf("Requested visual not supported by your OpenGL implementation. Falling back on singlebuffered Visual!\n");
|
||||
fbc = glx.glXChooseFBConfig(disp, DefaultScreen(disp), gl_attribs_single, &fb_count);
|
||||
if (!fbc)
|
||||
throw std::runtime_error(" glxChooseFBConfig failed");
|
||||
fbconfig = fbc[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!glx.glXGetFBConfigAttrib)
|
||||
throw std::runtime_error("Cannot find function glXGetFBConfigAttrib");
|
||||
|
||||
int required_samples = 1; // desc.multisampling();
|
||||
int desired_config = 0;
|
||||
int max_sample_buffers = 0;
|
||||
int max_samples = 0;
|
||||
// Find the best fitting multisampling option
|
||||
for (int i = 0; i < fb_count; i++)
|
||||
{
|
||||
int samp_buf, samples;
|
||||
glx.glXGetFBConfigAttrib(disp, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
|
||||
glx.glXGetFBConfigAttrib(disp, fbc[i], GLX_SAMPLES, &samples);
|
||||
|
||||
// Samples are most important, because they are variable
|
||||
if (max_samples < required_samples)
|
||||
{
|
||||
if (samples > max_samples)
|
||||
{
|
||||
max_samples = samples;
|
||||
desired_config = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Use the maximum sample buffer
|
||||
if (max_samples == samples) // Only check if the sample is valid
|
||||
{
|
||||
if (max_sample_buffers < samp_buf)
|
||||
{
|
||||
max_sample_buffers = samp_buf;
|
||||
desired_config = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
fbconfig = fbc[desired_config];
|
||||
}
|
||||
|
||||
XFree(fbc);
|
||||
|
||||
if (opengl_visual_info) XFree(opengl_visual_info);
|
||||
opengl_visual_info = glx.glXGetVisualFromFBConfig(disp, fbconfig);
|
||||
if (opengl_visual_info == nullptr)
|
||||
{
|
||||
throw std::runtime_error("glXGetVisualFromFBConfig failed");
|
||||
}
|
||||
|
||||
// create a GLX context
|
||||
opengl_context = create_context_glx_1_3(nullptr);
|
||||
}
|
||||
|
||||
bool OpenGLContext::is_glx_extension_supported(const char* ext_name)
|
||||
{
|
||||
const char* ext_string = glx.glXQueryExtensionsString(disp, opengl_visual_info->screen);
|
||||
if (ext_string)
|
||||
{
|
||||
const char* start;
|
||||
const char* where, * terminator;
|
||||
|
||||
// Extension names should not have spaces.
|
||||
where = strchr(ext_name, ' ');
|
||||
if (where || *ext_name == '\0')
|
||||
return false;
|
||||
|
||||
int ext_len = strlen(ext_name);
|
||||
|
||||
// It takes a bit of care to be fool-proof about parsing the OpenGL extensions string. Don't be fooled by sub-strings, etc.
|
||||
for (start = ext_string; ; )
|
||||
{
|
||||
where = strstr(start, ext_name);
|
||||
|
||||
if (!where)
|
||||
break;
|
||||
|
||||
terminator = where + ext_len;
|
||||
|
||||
if (where == start || *(where - 1) == ' ')
|
||||
if (*terminator == ' ' || *terminator == '\0')
|
||||
return true;
|
||||
|
||||
start = terminator;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool cl_ctxErrorOccurred = false;
|
||||
static int cl_ctxErrorHandler(::Display* dpy, XErrorEvent* ev)
|
||||
{
|
||||
cl_ctxErrorOccurred = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLXContext OpenGLContext::create_context_glx_1_3(GLXContext shared_context)
|
||||
{
|
||||
GLXContext context;
|
||||
|
||||
context = glx.glXCreateNewContext(disp, fbconfig, GLX_RGBA_TYPE, shared_context, True);
|
||||
if (context == nullptr)
|
||||
throw std::runtime_error("glXCreateContext failed");
|
||||
|
||||
ptr_glXCreateContextAttribs glXCreateContextAttribs = nullptr;
|
||||
|
||||
if (is_glx_extension_supported("GLX_ARB_create_context"))
|
||||
{
|
||||
if (glx.glXGetProcAddressARB)
|
||||
glXCreateContextAttribs = (ptr_glXCreateContextAttribs)glx.glXGetProcAddressARB((GLubyte*) "glXCreateContextAttribsARB");
|
||||
if (glx.glXGetProcAddress)
|
||||
glXCreateContextAttribs = (ptr_glXCreateContextAttribs)glx.glXGetProcAddress((GLubyte*) "glXCreateContextAttribsARB");
|
||||
}
|
||||
|
||||
if (glXCreateContextAttribs)
|
||||
{
|
||||
// Install an X error handler so the application won't exit if GL 3.0 context allocation fails.
|
||||
//
|
||||
// Note this error handler is global. All display connections in all threads
|
||||
// of a process use the same error handler, so be sure to guard against other
|
||||
// threads issuing X commands while this code is running.
|
||||
int (*oldHandler)(::Display*, XErrorEvent*) = XSetErrorHandler(&cl_ctxErrorHandler);
|
||||
|
||||
std::vector<int> int_attributes;
|
||||
|
||||
int_attributes.push_back(0x2091); // GLX_CONTEXT_MAJOR_VERSION_ARB
|
||||
int_attributes.push_back(major_version);
|
||||
int_attributes.push_back(0x2092); // GLX_CONTEXT_MINOR_VERSION_ARB
|
||||
int_attributes.push_back(minor_version);
|
||||
|
||||
int_attributes.push_back(0x2094); // GLX_CONTEXT_FLAGS_ARB
|
||||
int_attributes.push_back(0x2); // GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
|
||||
|
||||
int_attributes.push_back(0x9126); // GLX_CONTEXT_PROFILE_MASK_ARB
|
||||
int_attributes.push_back(0x1); // GLX_CONTEXT_CORE_PROFILE_BIT_ARB
|
||||
|
||||
int_attributes.push_back(None);
|
||||
|
||||
cl_ctxErrorOccurred = false;
|
||||
|
||||
GLXContext context_gl3 = glXCreateContextAttribs(disp, fbconfig, shared_context, True, &int_attributes[0]);
|
||||
|
||||
if (cl_ctxErrorOccurred)
|
||||
{
|
||||
if (context_gl3)
|
||||
{
|
||||
glx.glXDestroyContext(disp, context_gl3);
|
||||
context_gl3 = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Restore the original error handler
|
||||
XSetErrorHandler(oldHandler);
|
||||
|
||||
if (context_gl3)
|
||||
{
|
||||
glx.glXDestroyContext(disp, context);
|
||||
context = context_gl3;
|
||||
}
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -48,10 +48,103 @@ private:
|
|||
|
||||
#else
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
typedef GLXContext(*ptr_glXCreateContextAttribs)(::Display* dpy, GLXFBConfig config, GLXContext share_list, Bool direct, const int* attrib_list);
|
||||
|
||||
class GL_GLXFunctions
|
||||
{
|
||||
public:
|
||||
typedef XVisualInfo* (GLFUNC* ptr_glXChooseVisual)(::Display* dpy, int screen, int* attrib_list);
|
||||
typedef void (GLFUNC* ptr_glXCopyContext)(::Display* dpy, GLXContext src, GLXContext dst, unsigned long mask);
|
||||
typedef GLXContext(GLFUNC* ptr_glXCreateContext)(::Display* dpy, XVisualInfo* vis, GLXContext share_list, Bool direct);
|
||||
typedef GLXPixmap(GLFUNC* ptr_glXCreateGLXPixmap)(::Display* dpy, XVisualInfo* vis, Pixmap pixmap);
|
||||
typedef void (GLFUNC* ptr_glXDestroyContext)(::Display* dpy, GLXContext ctx);
|
||||
typedef void (GLFUNC* ptr_glXDestroyGLXPixmap)(::Display* dpy, GLXPixmap pix);
|
||||
typedef int (GLFUNC* ptr_glXGetConfig)(::Display* dpy, XVisualInfo* vis, int attrib, int* value);
|
||||
typedef GLXContext(GLFUNC* ptr_glXGetCurrentContext)(void);
|
||||
typedef GLXDrawable(GLFUNC* ptr_glXGetCurrentDrawable)(void);
|
||||
typedef Bool(GLFUNC* ptr_glXIsDirect)(::Display* dpy, GLXContext ctx);
|
||||
typedef Bool(GLFUNC* ptr_glXMakeCurrent)(::Display* dpy, GLXDrawable drawable, GLXContext ctx);
|
||||
typedef Bool(GLFUNC* ptr_glXQueryExtension)(::Display* dpy, int* error_base, int* event_base);
|
||||
typedef Bool(GLFUNC* ptr_glXQueryVersion)(::Display* dpy, int* major, int* minor);
|
||||
typedef void (GLFUNC* ptr_glXSwapBuffers)(::Display* dpy, GLXDrawable drawable);
|
||||
typedef void (GLFUNC* ptr_glXUseXFont)(Font font, int first, int count, int list_base);
|
||||
typedef void (GLFUNC* ptr_glXWaitGL)(void);
|
||||
typedef void (GLFUNC* ptr_glXWaitX)(void);
|
||||
typedef const char* (GLFUNC* ptr_glXGetClientString)(::Display* dpy, int name);
|
||||
typedef const char* (GLFUNC* ptr_glXQueryServerString)(::Display* dpy, int screen, int name);
|
||||
typedef const char* (GLFUNC* ptr_glXQueryExtensionsString)(::Display* dpy, int screen);
|
||||
typedef ::Display* (GLFUNC* ptr_glXGetCurrentDisplay)(void);
|
||||
typedef GLXFBConfig* (GLFUNC* ptr_glXChooseFBConfig)(::Display* dpy, int screen, const int* attrib_list, int* nelements);
|
||||
typedef GLXContext(GLFUNC* ptr_glXCreateNewContext)(::Display* dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
|
||||
typedef GLXPbuffer(GLFUNC* ptr_glXCreatePbuffer)(::Display* dpy, GLXFBConfig config, const int* attrib_list);
|
||||
typedef GLXPixmap(GLFUNC* ptr_glXCreatePixmap)(::Display* dpy, GLXFBConfig config, Pixmap pixmap, const int* attrib_list);
|
||||
typedef GLXWindow(GLFUNC* ptr_glXCreateWindow)(::Display* dpy, GLXFBConfig config, Window win, const int* attrib_list);
|
||||
typedef void (GLFUNC* ptr_glXDestroyPbuffer)(::Display* dpy, GLXPbuffer pbuf);
|
||||
typedef void (GLFUNC* ptr_glXDestroyPixmap)(::Display* dpy, GLXPixmap pixmap);
|
||||
typedef void (GLFUNC* ptr_glXDestroyWindow)(::Display* dpy, GLXWindow win);
|
||||
typedef GLXDrawable(GLFUNC* ptr_glXGetCurrentReadDrawable)(void);
|
||||
typedef int (GLFUNC* ptr_glXGetFBConfigAttrib)(::Display* dpy, GLXFBConfig config, int attribute, int* value);
|
||||
typedef GLXFBConfig* (GLFUNC* ptr_glXGetFBConfigs)(::Display* dpy, int screen, int* nelements);
|
||||
typedef void (GLFUNC* ptr_glXGetSelectedEvent)(::Display* dpy, GLXDrawable draw, unsigned long* event_mask);
|
||||
typedef XVisualInfo* (GLFUNC* ptr_glXGetVisualFromFBConfig)(::Display* dpy, GLXFBConfig config);
|
||||
typedef Bool(GLFUNC* ptr_glXMakeContextCurrent)(::Display* display, GLXDrawable draw, GLXDrawable read, GLXContext ctx);
|
||||
typedef int (GLFUNC* ptr_glXQueryContext)(::Display* dpy, GLXContext ctx, int attribute, int* value);
|
||||
typedef void (GLFUNC* ptr_glXQueryDrawable)(::Display* dpy, GLXDrawable draw, int attribute, unsigned int* value);
|
||||
typedef void (GLFUNC* ptr_glXSelectEvent)(::Display* dpy, GLXDrawable draw, unsigned long event_mask);
|
||||
|
||||
typedef __GLXextFuncPtr(GLFUNC* ptr_glXGetProcAddress) (const GLubyte*);
|
||||
typedef void (*(GLFUNC* ptr_glXGetProcAddressARB)(const GLubyte* procName))(void);
|
||||
|
||||
public:
|
||||
ptr_glXChooseVisual glXChooseVisual;
|
||||
ptr_glXCopyContext glXCopyContext;
|
||||
ptr_glXCreateContext glXCreateContext;
|
||||
ptr_glXCreateGLXPixmap glXCreateGLXPixmap;
|
||||
ptr_glXDestroyContext glXDestroyContext;
|
||||
ptr_glXDestroyGLXPixmap glXDestroyGLXPixmap;
|
||||
ptr_glXGetConfig glXGetConfig;
|
||||
ptr_glXGetCurrentContext glXGetCurrentContext;
|
||||
ptr_glXGetCurrentDrawable glXGetCurrentDrawable;
|
||||
ptr_glXIsDirect glXIsDirect;
|
||||
ptr_glXMakeCurrent glXMakeCurrent;
|
||||
ptr_glXQueryExtension glXQueryExtension;
|
||||
ptr_glXQueryVersion glXQueryVersion;
|
||||
ptr_glXSwapBuffers glXSwapBuffers;
|
||||
ptr_glXUseXFont glXUseXFont;
|
||||
ptr_glXWaitGL glXWaitGL;
|
||||
ptr_glXWaitX glXWaitX;
|
||||
ptr_glXGetClientString glXGetClientString;
|
||||
ptr_glXQueryServerString glXQueryServerString;
|
||||
ptr_glXQueryExtensionsString glXQueryExtensionsString;
|
||||
ptr_glXGetCurrentDisplay glXGetCurrentDisplay;
|
||||
ptr_glXChooseFBConfig glXChooseFBConfig;
|
||||
ptr_glXCreateNewContext glXCreateNewContext;
|
||||
ptr_glXCreatePbuffer glXCreatePbuffer;
|
||||
ptr_glXCreatePixmap glXCreatePixmap;
|
||||
ptr_glXCreateWindow glXCreateWindow;
|
||||
ptr_glXDestroyPbuffer glXDestroyPbuffer;
|
||||
ptr_glXDestroyPixmap glXDestroyPixmap;
|
||||
ptr_glXDestroyWindow glXDestroyWindow;
|
||||
ptr_glXGetCurrentReadDrawable glXGetCurrentReadDrawable;
|
||||
ptr_glXGetFBConfigAttrib glXGetFBConfigAttrib;
|
||||
ptr_glXGetFBConfigs glXGetFBConfigs;
|
||||
ptr_glXGetSelectedEvent glXGetSelectedEvent;
|
||||
ptr_glXGetVisualFromFBConfig glXGetVisualFromFBConfig;
|
||||
ptr_glXMakeContextCurrent glXMakeContextCurrent;
|
||||
ptr_glXQueryContext glXQueryContext;
|
||||
ptr_glXQueryDrawable glXQueryDrawable;
|
||||
ptr_glXSelectEvent glXSelectEvent;
|
||||
ptr_glXGetProcAddress glXGetProcAddress;
|
||||
ptr_glXGetProcAddressARB glXGetProcAddressARB;
|
||||
};
|
||||
|
||||
class OpenGLContext
|
||||
{
|
||||
public:
|
||||
OpenGLContext(void* window);
|
||||
OpenGLContext(void* display, void* window);
|
||||
~OpenGLContext();
|
||||
|
||||
void Begin();
|
||||
|
@ -61,10 +154,26 @@ public:
|
|||
int GetWidth() const;
|
||||
int GetHeight() const;
|
||||
|
||||
explicit operator bool() const { return context != 0; }
|
||||
explicit operator bool() const { return opengl_context != 0; }
|
||||
|
||||
private:
|
||||
void* context = nullptr;
|
||||
void CreateContext();
|
||||
|
||||
::Display* disp = nullptr;
|
||||
::Window window = 0;
|
||||
GLXContext opengl_context = 0;
|
||||
|
||||
XVisualInfo* opengl_visual_info = nullptr;
|
||||
GLXFBConfig fbconfig;
|
||||
|
||||
GL_GLXFunctions glx;
|
||||
|
||||
ProcAddress* get_proc_address(const char *function_name) const;
|
||||
|
||||
GLXContext create_context_glx_1_3(GLXContext shared_context);
|
||||
void create_glx_1_3(::Display* disp);
|
||||
|
||||
int refcount = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,7 +7,11 @@
|
|||
#include "ShaderManager.h"
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef WIN32
|
||||
RenderDevice::RenderDevice(void* hwnd) : Context(hwnd)
|
||||
#else
|
||||
RenderDevice::RenderDevice(void* disp, void* window) : Context(disp, window)
|
||||
#endif
|
||||
{
|
||||
memset(mUniforms, 0, sizeof(mUniforms));
|
||||
|
||||
|
|
|
@ -74,7 +74,11 @@ enum class UniformName : int
|
|||
class RenderDevice
|
||||
{
|
||||
public:
|
||||
#ifdef WIN32
|
||||
RenderDevice(void* hwnd);
|
||||
#else
|
||||
RenderDevice(void* disp, void* window);
|
||||
#endif
|
||||
~RenderDevice();
|
||||
|
||||
void SetShader(ShaderName name);
|
||||
|
|
Loading…
Reference in a new issue