From 1f49d2fb73b855b8f429ffc06dc355a4c223cfe7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sat, 9 Apr 2011 16:14:14 +0100 Subject: [PATCH] Minor cleanup. --- glws_glx.cpp | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/glws_glx.cpp b/glws_glx.cpp index 3e25dc3..5a570e2 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,37 +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: - XlibWindowSystem() { + GlxWindowSystem() { display = XOpenDisplay(NULL); screen = DefaultScreen(display); } - ~XlibWindowSystem() { + ~GlxWindowSystem() { XCloseDisplay(display); } @@ -132,13 +132,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); @@ -179,24 +179,28 @@ 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; + if (!drawable || !context) { + return glXMakeCurrent(display, NULL, NULL); + } else { + GlxDrawable *glxDrawable = dynamic_cast(drawable); + GlxContext *glxContext = dynamic_cast(context); - return glXMakeCurrent(display, win, ctx); + return glXMakeCurrent(display, glxDrawable->window, glxContext->context); + } } bool @@ -212,7 +216,7 @@ public: WindowSystem *createNativeWindowSystem(void) { - return new XlibWindowSystem(); + return new GlxWindowSystem(); } -- 2.45.2