Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "GTKGLContext.h"
00009
00010 #include <gtk/gtk.h>
00011 #include <gdk/gdk.h>
00012 #include <gdk/gdkx.h>
00013
00014 CGTKGLContext::CGTKGLContext(CGTKGLContext *shared_context)
00015 : initialized(false), xdisplay(NULL)
00016 {
00017 if (glXQueryExtension(GDK_DISPLAY(), NULL, NULL) == FALSE)
00018 {
00019 printf("CGTKGLContext: no OpenGL support.\n");
00020 return;
00021 }
00022
00023 xdisplay = GDK_DISPLAY();
00024
00025 int attrlist[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, None};
00026
00027 XVisualInfo *vi = glXChooseVisual(xdisplay, DefaultScreen(xdisplay), attrlist);
00028 if (!vi)
00029 {
00030 printf("CGTKGLContext: couldn't find suitable VisualInfo for the GL context. (%d)\n", (size_t) xdisplay);
00031 return;
00032 }
00033
00034 if (shared_context)
00035 glxcontext = glXCreateContext(xdisplay, vi, shared_context->glxcontext, True);
00036 else
00037 glxcontext = glXCreateContext(xdisplay, vi, 0, True);
00038
00039 if (glxcontext == NULL)
00040 {
00041 printf("CGTKGLContext: creation of GL context failed.\n");
00042 XFree(vi);
00043 return;
00044 }
00045
00046 visual = gdkx_visual_get(vi->visualid);
00047 XFree(vi);
00048
00049 initialized = true;
00050 }
00051
00052 CGTKGLContext::~CGTKGLContext()
00053 {
00054 if (!initialized)
00055 return;
00056
00057 if (glxcontext == glXGetCurrentContext())
00058 glXMakeCurrent(xdisplay, None, NULL);
00059
00060 glXDestroyContext(xdisplay, glxcontext);
00061 }
00062
00063 bool CGTKGLContext::IsInitialized()
00064 {
00065 return initialized;
00066 }
00067
00068 void CGTKGLContext::MakeCurrent(GdkDrawable *drawable)
00069 {
00070 if (!initialized)
00071 return;
00072
00073 if (drawable)
00074 {
00075 if (glXMakeCurrent(xdisplay, GDK_WINDOW_XWINDOW(drawable), glxcontext) == False)
00076 {
00077 printf("GTKGLContext: make current failed\n");
00078 }
00079 }
00080 }
00081
00082 void CGTKGLContext::SwapBuffers(GdkDrawable *drawable)
00083 {
00084 if (!initialized)
00085 return;
00086
00087 glXSwapBuffers(GDK_WINDOW_XDISPLAY(drawable), GDK_WINDOW_XWINDOW(drawable));
00088 }
00089
00090 void CGTKGLContext::DoneCurrent()
00091 {
00092 if (!initialized)
00093 return;
00094
00095 glXMakeCurrent(xdisplay, None, NULL);
00096 }
00097
asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:57