X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/83df96d63a52ebb08b9e32549dc255354b4a18d0..a83ea9c15a7ac7bbdc6686164cfcbbc21ae5031a:/src/x11/glcanvas.cpp diff --git a/src/x11/glcanvas.cpp b/src/x11/glcanvas.cpp index 776eb9746c..42f4b854d1 100644 --- a/src/x11/glcanvas.cpp +++ b/src/x11/glcanvas.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: glcanvas.cpp -// Purpose: wxGLCanvas, for using OpenGL with wxWindows 2.0 for Motif. +// Purpose: wxGLCanvas, for using OpenGL with wxWidgets // Uses the GLX extension. // Author: Julian Smart and Wolfram Gloger // Modified by: @@ -10,7 +10,7 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "glcanvas.h" #endif @@ -21,15 +21,29 @@ #include "wx/glcanvas.h" #include "wx/utils.h" #include "wx/app.h" +#include "wx/log.h" #ifdef __VMS # pragma message disable nosimpint #endif -#include +#include #ifdef __VMS # pragma message enable nosimpint #endif -#include "wx/motif/private.h" +#include "wx/x11/private.h" + +// DLL options compatibility check: +#include "wx/build.h" +WX_CHECK_BUILD_OPTIONS("wxGL") + +static inline WXWindow wxGetClientAreaWindow(wxWindow* win) +{ +#ifdef __WXMOTIF__ + return win->GetClientXWindow(); +#else + return win->GetClientAreaWindow(); +#endif +} #ifdef OLD_MESA // workaround for bug in Mesa's glx.c @@ -59,12 +73,12 @@ wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, wxGLCanvas *gc = (wxGLCanvas*) win; XVisualInfo *vi = (XVisualInfo *) gc->m_vi; - wxCHECK_RET( vi, "invalid visual for OpenGl" ); + wxCHECK_RET( vi, wxT("invalid visual for OpenGL") ); - m_glContext = glXCreateContext( (Display *)m_window->GetXDisplay(), vi, + m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi, None, GL_TRUE); - wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" ); + wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") ); } wxGLContext::wxGLContext( @@ -79,16 +93,16 @@ wxGLContext::wxGLContext( wxGLCanvas *gc = (wxGLCanvas*) win; XVisualInfo *vi = (XVisualInfo *) gc->m_vi; - wxCHECK_RET( vi, "invalid visual for OpenGl" ); + wxCHECK_RET( vi, wxT("invalid visual for OpenGL") ); if( other != 0 ) - m_glContext = glXCreateContext( (Display *)m_window->GetXDisplay(), vi, + m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi, other->m_glContext, GL_TRUE ); else - m_glContext = glXCreateContext( (Display *)m_window->GetXDisplay(), vi, + m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi, None, GL_TRUE ); - wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" ); + wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") ); } wxGLContext::~wxGLContext() @@ -97,18 +111,18 @@ wxGLContext::~wxGLContext() if (m_glContext == glXGetCurrentContext()) { - glXMakeCurrent( (Display*) m_window->GetXDisplay(), None, NULL); + glXMakeCurrent( (Display*) wxGetDisplay(), None, NULL); } - glXDestroyContext( (Display*) m_window->GetXDisplay(), m_glContext ); + glXDestroyContext( (Display*) wxGetDisplay(), m_glContext ); } void wxGLContext::SwapBuffers() { if (m_glContext) { - Display* display = (Display*) m_window->GetXDisplay(); - glXSwapBuffers(display, (Window) m_window->GetXWindow()); + Display* display = (Display*) wxGetDisplay(); + glXSwapBuffers(display, (Window) wxGetClientAreaWindow(m_window)); } } @@ -116,40 +130,40 @@ void wxGLContext::SetCurrent() { if (m_glContext) { - Display* display = (Display*) m_window->GetXDisplay(); - glXMakeCurrent(display, (Window) m_window->GetXWindow(), + Display* display = (Display*) wxGetDisplay(); + glXMakeCurrent(display, (Window) wxGetClientAreaWindow(m_window), m_glContext );; } } -void wxGLContext::SetColour(const char *colour) +void wxGLContext::SetColour(const wxChar *colour) { - wxColour *the_colour = wxTheColourDatabase->FindColour(colour); - if(the_colour) { - GLboolean b; - glGetBooleanv(GL_RGBA_MODE, &b); - if(b) { - glColor3ub(the_colour->Red(), - the_colour->Green(), - the_colour->Blue()); - } else { - GLint pix = (GLint)the_colour->m_pixel; - if(pix == -1) { - XColor exact_def; - exact_def.red = (unsigned short)the_colour->Red() << 8; - exact_def.green = (unsigned short)the_colour->Green() << 8; - exact_def.blue = (unsigned short)the_colour->Blue() << 8; - exact_def.flags = DoRed | DoGreen | DoBlue; - if(!XAllocColor((Display*) m_window->GetXDisplay(), - (Colormap) wxTheApp->GetMainColormap(m_window->GetXDisplay()), - &exact_def)) { - wxDebugMsg("wxGLCanvas: cannot allocate color\n"); - return; - } - pix = the_colour->m_pixel = exact_def.pixel; - } - glIndexi(pix); - } + wxColour the_colour = wxTheColourDatabase->Find(colour); + if(the_colour.Ok()) + { + GLboolean b; + glGetBooleanv(GL_RGBA_MODE, &b); + if(b) + { + glColor3ub(the_colour.Red(), + the_colour.Green(), + the_colour.Blue()); + } + else + { +#ifdef __WXMOTIF__ + the_colour.AllocColour(m_window->GetXDisplay()); +#else + the_colour.CalcPixel(wxTheApp->GetMainColormap(wxGetDisplay())); +#endif + GLint pix = (GLint)the_colour.GetPixel(); + if(pix == -1) + { + wxLogError(wxT("wxGLCanvas: cannot allocate color\n")); + return; + } + glIndexi(pix); + } } } @@ -241,12 +255,12 @@ bool wxGLCanvas::Create( wxWindow *parent, m_sharedContextOf = (wxGLCanvas*)shared_context_of; // const_cast m_glContext = (wxGLContext*) NULL; - Display* display = (Display*) GetXDisplay(); + Display* display = (Display*) wxGetDisplay(); // Check for the presence of the GLX extension if(!glXQueryExtension(display, NULL, NULL)) { - wxDebugMsg("wxGLCanvas: GLX extension is missing\n"); - return false; + wxLogDebug(wxT("wxGLCanvas: GLX extension is missing\n")); + return FALSE; } if(attribList) { @@ -294,7 +308,7 @@ bool wxGLCanvas::Create( wxWindow *parent, attribList = (int*) data; // Get an appropriate visual vi = glXChooseVisual(display, DefaultScreen(display), attribList); - if(!vi) return false; + if(!vi) return FALSE; // Here we should make sure that vi is the same visual as the // one used by the xwindow drawable in wxCanvas. However, @@ -302,12 +316,12 @@ bool wxGLCanvas::Create( wxWindow *parent, } else { // By default, we use the visual of xwindow // NI: is this really senseful ? opengl in e.g. color index mode ? - XGetWindowAttributes(display, (Window) GetXWindow(), &xwa); + XGetWindowAttributes(display, (Window)wxGetClientAreaWindow(this), &xwa); vi_templ.visualid = XVisualIDFromVisual(xwa.visual); vi = XGetVisualInfo(display, VisualIDMask, &vi_templ, &n); - if(!vi) return false; + if(!vi) return FALSE; glXGetConfig(display, vi, GLX_USE_GL, &val); - if(!val) return false; + if(!val) return FALSE; // Basically, this is it. It should be possible to use vi // in glXCreateContext() below. But this fails with Mesa. // I notified the Mesa author about it; there may be a fix. @@ -334,13 +348,13 @@ bool wxGLCanvas::Create( wxWindow *parent, a_list[n] = None; // XFree(vi); vi = glXChooseVisual(display, DefaultScreen(display), a_list); - if(!vi) return false; + if(!vi) return FALSE; #endif /* OLD_MESA */ } m_vi = vi; // safe for later use - wxCHECK_MSG( m_vi, FALSE, "required visual couldn't be found" ); + wxCHECK_MSG( m_vi, FALSE, wxT("required visual couldn't be found") ); // Create the GLX context and make it current @@ -355,7 +369,7 @@ bool wxGLCanvas::Create( wxWindow *parent, #endif SetCurrent(); - return true; + return TRUE; } wxGLCanvas::~wxGLCanvas(void) @@ -374,7 +388,7 @@ void wxGLCanvas::SwapBuffers() if( m_glContext ) m_glContext->SwapBuffers(); // Display* display = (Display*) GetXDisplay(); - // if(glx_cx) glXSwapBuffers(display, (Window) GetXWindow()); + // if(glx_cx) glXSwapBuffers(display, (Window) GetClientAreaWindow()); } void wxGLCanvas::SetCurrent() @@ -382,10 +396,10 @@ void wxGLCanvas::SetCurrent() if( m_glContext ) m_glContext->SetCurrent(); // Display* display = (Display*) GetXDisplay(); - // if(glx_cx) glXMakeCurrent(display, (Window) GetXWindow(), glx_cx); + // if(glx_cx) glXMakeCurrent(display, (Window) GetClientAreaWindow(), glx_cx); } -void wxGLCanvas::SetColour(const char *col) +void wxGLCanvas::SetColour(const wxChar *col) { if( m_glContext ) m_glContext->SetColour(col); }