Deinit the opengl context before exiting.
This commit is contained in:
parent
2d59aca05d
commit
dfb72ae1b5
|
@ -28,25 +28,43 @@ static bool glx_beginOpenGL(void) { return 1; }
|
||||||
static void glx_endOpenGL(void) { }
|
static void glx_endOpenGL(void) { }
|
||||||
static bool glx_init(void) { return true; }
|
static bool glx_init(void) { return true; }
|
||||||
|
|
||||||
|
static GLXContext ctx;
|
||||||
|
static GLXPbuffer pbuf;
|
||||||
|
|
||||||
|
void deinit_glx_3Demu(void)
|
||||||
|
{
|
||||||
|
Display *dpy = glXGetCurrentDisplay();
|
||||||
|
|
||||||
|
if (dpy)
|
||||||
|
{
|
||||||
|
glXDestroyPbuffer(dpy, pbuf);
|
||||||
|
glXDestroyContext(dpy, ctx);
|
||||||
|
|
||||||
|
XCloseDisplay(dpy);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int init_glx_3Demu(void)
|
int init_glx_3Demu(void)
|
||||||
{
|
{
|
||||||
Display *dpy = XOpenDisplay(NULL);
|
Display *dpy = XOpenDisplay(NULL);
|
||||||
XVisualInfo *vis;
|
XVisualInfo *vis;
|
||||||
GLXContext ctx;
|
|
||||||
GLXFBConfig *cfg;
|
GLXFBConfig *cfg;
|
||||||
GLXPbuffer pbuf;
|
|
||||||
int maj, min;
|
int maj, min;
|
||||||
|
|
||||||
if (!dpy)
|
if (!dpy)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
// Check if GLX is present
|
// Check if GLX is present
|
||||||
if (!glXQueryVersion(dpy, &maj, &min))
|
if (!glXQueryVersion(dpy, &maj, &min))
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
// We need GLX 1.3 at least
|
// We need GLX 1.3 at least
|
||||||
if (maj < 1 || (maj == 1 && min < 3))
|
if (maj < 1 || (maj == 1 && min < 3))
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
const int vis_attr[] = {
|
const int vis_attr[] = {
|
||||||
GLX_RGBA,
|
GLX_RGBA,
|
||||||
|
@ -62,7 +80,7 @@ int init_glx_3Demu(void)
|
||||||
vis = glXChooseVisual(dpy, DefaultScreen(dpy), (int *)&vis_attr);
|
vis = glXChooseVisual(dpy, DefaultScreen(dpy), (int *)&vis_attr);
|
||||||
|
|
||||||
if (!vis)
|
if (!vis)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
const int fb_attr[] = {
|
const int fb_attr[] = {
|
||||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||||||
|
@ -82,7 +100,7 @@ int init_glx_3Demu(void)
|
||||||
cfg = glXChooseFBConfig(dpy, DefaultScreen(dpy), (int *)&fb_attr, &configs);
|
cfg = glXChooseFBConfig(dpy, DefaultScreen(dpy), (int *)&fb_attr, &configs);
|
||||||
|
|
||||||
if (!cfg)
|
if (!cfg)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
const int pbuf_attr[] = {
|
const int pbuf_attr[] = {
|
||||||
GLX_PBUFFER_WIDTH, 256,
|
GLX_PBUFFER_WIDTH, 256,
|
||||||
|
@ -98,10 +116,10 @@ int init_glx_3Demu(void)
|
||||||
ctx = glXCreateContext(dpy, vis, NULL, true);
|
ctx = glXCreateContext(dpy, vis, NULL, true);
|
||||||
|
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
if (!glXMakeContextCurrent(dpy, pbuf, pbuf, ctx))
|
if (!glXMakeContextCurrent(dpy, pbuf, pbuf, ctx))
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
printf("OGL/GLX Renderer has finished the initialization.\n");
|
printf("OGL/GLX Renderer has finished the initialization.\n");
|
||||||
|
|
||||||
|
@ -109,7 +127,7 @@ int init_glx_3Demu(void)
|
||||||
oglrender_beginOpenGL = glx_beginOpenGL;
|
oglrender_beginOpenGL = glx_beginOpenGL;
|
||||||
oglrender_endOpenGL = glx_endOpenGL;
|
oglrender_endOpenGL = glx_endOpenGL;
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAVE_GLX
|
#endif // HAVE_GLX
|
||||||
|
|
|
@ -19,5 +19,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_GL_GLX
|
#ifdef HAVE_GL_GLX
|
||||||
int init_glx_3Demu(void);
|
int init_glx_3Demu(void);
|
||||||
|
void deinit_glx_3Demu(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,18 +28,41 @@ static bool osmesa_beginOpenGL(void) { return 1; }
|
||||||
static void osmesa_endOpenGL(void) { }
|
static void osmesa_endOpenGL(void) { }
|
||||||
static bool osmesa_init(void) { return true; }
|
static bool osmesa_init(void) { return true; }
|
||||||
|
|
||||||
int init_osmesa_3Demu(void) {
|
static void * buffer = NULL;
|
||||||
void * buffer;
|
static OSMesaContext ctx;
|
||||||
OSMesaContext ctx;
|
|
||||||
|
|
||||||
ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
|
void deinit_osmesa_3Demu (void)
|
||||||
buffer = malloc(256 * 192 * 4);
|
{
|
||||||
OSMesaMakeCurrent(ctx, buffer, GL_UNSIGNED_BYTE, 256, 192);
|
free(buffer);
|
||||||
|
OSMesaDestroyContext(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
oglrender_init = osmesa_init;
|
int init_osmesa_3Demu(void)
|
||||||
oglrender_beginOpenGL = osmesa_beginOpenGL;
|
{
|
||||||
oglrender_endOpenGL = osmesa_endOpenGL;
|
if (!ctx)
|
||||||
|
{
|
||||||
|
printf("OSMesaCreateContext failed!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
buffer = malloc(256 * 192 * 4);
|
||||||
|
if (!buffer)
|
||||||
|
{
|
||||||
|
printf("Could not allocate enough memory!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!OSMesaMakeCurrent(ctx, buffer, GL_UNSIGNED_BYTE, 256, 192))
|
||||||
|
{
|
||||||
|
printf("OSMesaMakeCurrent failed!\n");
|
||||||
|
free(buffer);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
oglrender_init = osmesa_init;
|
||||||
|
oglrender_beginOpenGL = osmesa_beginOpenGL;
|
||||||
|
oglrender_endOpenGL = osmesa_endOpenGL;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,5 +19,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_LIBOSMESA
|
#ifdef HAVE_LIBOSMESA
|
||||||
int init_osmesa_3Demu( void);
|
int init_osmesa_3Demu(void);
|
||||||
|
void deinit_osmesa_3Demu(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue