X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glws_glx.cpp;h=67a88290b7988804bb0f3c4c16c30fc083d6451a;hb=9bde72eb176831d6d4b185ec7880ec35e61147f8;hp=be0a82beb8e2c9d65715b9a757719378a703762e;hpb=0b210a5f07344b85d9d04348daa9078db622eb6a;p=apitrace diff --git a/glws_glx.cpp b/glws_glx.cpp index be0a82b..67a8829 100644 --- a/glws_glx.cpp +++ b/glws_glx.cpp @@ -30,34 +30,34 @@ namespace glws { -class XlibVisual : public Visual +class GlxVisual : public Visual { public: XVisualInfo *visinfo; - XlibVisual(XVisualInfo *vi) : + GlxVisual(XVisualInfo *vi) : visinfo(vi) {} - ~XlibVisual() { + ~GlxVisual() { XFree(visinfo); } }; -class XlibDrawable : public Drawable +class GlxDrawable : public Drawable { public: Display *display; Window window; - XlibDrawable(const Visual *vis, Display *dpy, Window win) : + GlxDrawable(const Visual *vis, Display *dpy, Window win) : Drawable(vis), display(dpy), window(win) {} - ~XlibDrawable() { + ~GlxDrawable() { XDestroyWindow(display, window); } @@ -73,40 +73,37 @@ public: }; -class XlibContext : public Context +class GlxContext : public Context { public: Display *display; GLXContext context; - XlibContext(const Visual *vis, Display *dpy, GLXContext ctx) : + GlxContext(const Visual *vis, Display *dpy, GLXContext ctx) : Context(vis), display(dpy), context(ctx) {} - ~XlibContext() { + ~GlxContext() { glXDestroyContext(display, context); } }; -class XlibWindowSystem : public WindowSystem +class GlxWindowSystem : public WindowSystem { private: Display *display; int screen; public: - Drawable *currentDrawable; - Context *currentContext; - - XlibWindowSystem() { - display = XOpenDisplay(NULL); - screen = DefaultScreen(display); + GlxWindowSystem() { + display = XOpenDisplay(NULL); + screen = DefaultScreen(display); } - ~XlibWindowSystem() { + ~GlxWindowSystem() { XCloseDisplay(display); } @@ -118,6 +115,7 @@ public: GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 1, + GLX_STENCIL_SIZE, 1, None }; @@ -128,6 +126,7 @@ public: GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 1, + GLX_STENCIL_SIZE, 1, None }; @@ -135,13 +134,13 @@ public: visinfo = glXChooseVisual(display, screen, doubleBuffer ? double_attribs : single_attribs); - return new XlibVisual(visinfo); + return new GlxVisual(visinfo); } Drawable * createDrawable(const Visual *visual) { - XVisualInfo *visinfo = dynamic_cast(visual)->visinfo; + XVisualInfo *visinfo = dynamic_cast(visual)->visinfo; Window root = RootWindow(display, screen); @@ -182,50 +181,44 @@ public: XMapWindow(display, window); - return new XlibDrawable(visual, display, window); + return new GlxDrawable(visual, display, window); } Context * createContext(const Visual *visual) { - XVisualInfo *visinfo = dynamic_cast(visual)->visinfo; + XVisualInfo *visinfo = dynamic_cast(visual)->visinfo; GLXContext context = glXCreateContext(display, visinfo, NULL, True); - return new XlibContext(visual, display, context); + return new GlxContext(visual, display, context); } bool makeCurrent(Drawable *drawable, Context *context) { - Window win = drawable ? dynamic_cast(drawable)->window : NULL; - GLXContext ctx = context ? dynamic_cast(context)->context : NULL; - - bool ret = glXMakeCurrent(display, win, ctx); - - if (drawable && context && ret) { - currentDrawable = drawable; - currentContext = context; + if (!drawable || !context) { + return glXMakeCurrent(display, None, NULL); } else { - currentDrawable = NULL; - currentContext = NULL; - } + GlxDrawable *glxDrawable = dynamic_cast(drawable); + GlxContext *glxContext = dynamic_cast(context); - return ret; + return glXMakeCurrent(display, glxDrawable->window, glxContext->context); + } } bool processEvents(void) { - while (XPending(display) > 0) { - XEvent event; - XNextEvent(display, &event); - // TODO - } - return true; + while (XPending(display) > 0) { + XEvent event; + XNextEvent(display, &event); + // TODO + } + return true; } }; WindowSystem *createNativeWindowSystem(void) { - return new XlibWindowSystem(); + return new GlxWindowSystem(); }