Whitespace fixes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34994 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mart Raudsepp
2005-07-29 15:58:36 +00:00
parent 81f9c57504
commit b4d06fb78d
2 changed files with 428 additions and 360 deletions

View File

@@ -72,19 +72,19 @@ wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette&
wxGLCanvas *gc = (wxGLCanvas*) win; wxGLCanvas *gc = (wxGLCanvas*) win;
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 // GLX >= 1.3
GLXFBConfig *fbc = gc->m_fbc; GLXFBConfig *fbc = gc->m_fbc;
wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") ); wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, None, GL_TRUE ); m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, None, GL_TRUE );
} }
else else
{ {
// GLX <= 1.2 // GLX <= 1.2
XVisualInfo *vi = (XVisualInfo *) gc->m_vi; XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
wxCHECK_RET( vi, _T("invalid visual for OpenGl") ); wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
m_glContext = glXCreateContext( GDK_DISPLAY(), vi, None, GL_TRUE ); m_glContext = glXCreateContext( GDK_DISPLAY(), vi, None, GL_TRUE );
} }
wxCHECK_RET( m_glContext, _T("Couldn't create OpenGl context") ); wxCHECK_RET( m_glContext, _T("Couldn't create OpenGl context") );
} }
@@ -101,23 +101,23 @@ wxGLContext::wxGLContext(
wxGLCanvas *gc = (wxGLCanvas*) win; wxGLCanvas *gc = (wxGLCanvas*) win;
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 // GLX >= 1.3
GLXFBConfig *fbc = gc->m_fbc; GLXFBConfig *fbc = gc->m_fbc;
wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") ); wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE,
other ? other->m_glContext : None, other ? other->m_glContext : None,
GL_TRUE ); GL_TRUE );
} }
else else
{ {
// GLX <= 1.2 // GLX <= 1.2
XVisualInfo *vi = (XVisualInfo *) gc->m_vi; XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
wxCHECK_RET( vi, _T("invalid visual for OpenGl") ); wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
m_glContext = glXCreateContext( GDK_DISPLAY(), vi, m_glContext = glXCreateContext( GDK_DISPLAY(), vi,
other ? other->m_glContext : None, other ? other->m_glContext : None,
GL_TRUE ); GL_TRUE );
} }
if ( !m_glContext ) if ( !m_glContext )
{ {
@@ -131,12 +131,12 @@ wxGLContext::~wxGLContext()
if (m_glContext == glXGetCurrentContext()) if (m_glContext == glXGetCurrentContext())
{ {
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
// GLX >= 1.3 // GLX >= 1.3
glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL); glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL);
else else
// GLX <= 1.2 // GLX <= 1.2
glXMakeCurrent( GDK_DISPLAY(), None, NULL); glXMakeCurrent( GDK_DISPLAY(), None, NULL);
} }
glXDestroyContext( GDK_DISPLAY(), m_glContext ); glXDestroyContext( GDK_DISPLAY(), m_glContext );
@@ -157,12 +157,13 @@ void wxGLContext::SetCurrent()
{ {
GdkWindow *window = GTK_PIZZA(m_widget)->bin_window; GdkWindow *window = GTK_PIZZA(m_widget)->bin_window;
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
// GLX >= 1.3 // GLX >= 1.3
glXMakeContextCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), GDK_WINDOW_XWINDOW(window), m_glContext ); glXMakeContextCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window),
else GDK_WINDOW_XWINDOW(window), m_glContext );
// GLX <= 1.2 else
glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), m_glContext ); // GLX <= 1.2
glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), m_glContext );
} }
} }
@@ -358,39 +359,41 @@ bool wxGLCanvas::Create( wxWindow *parent,
wxGLCanvas::QueryGLXVersion(); wxGLCanvas::QueryGLXVersion();
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 uses a GLXFBConfig // GLX >= 1.3 uses a GLXFBConfig
GLXFBConfig * fbc = NULL; GLXFBConfig * fbc = NULL;
if (wxTheApp->m_glFBCInfo != NULL) if (wxTheApp->m_glFBCInfo != NULL)
{ {
fbc = (GLXFBConfig *) wxTheApp->m_glFBCInfo; fbc = (GLXFBConfig *) wxTheApp->m_glFBCInfo;
m_canFreeFBC = FALSE; // owned by wxTheApp - don't free upon destruction m_canFreeFBC = FALSE; // owned by wxTheApp - don't free upon destruction
} }
else else
{ {
fbc = (GLXFBConfig *) wxGLCanvas::ChooseGLFBC(attribList); fbc = (GLXFBConfig *) wxGLCanvas::ChooseGLFBC(attribList);
m_canFreeFBC = TRUE; m_canFreeFBC = TRUE;
} }
m_fbc = fbc; // save for later use m_fbc = fbc; // save for later use
wxCHECK_MSG( m_fbc, FALSE, _T("required FBConfig couldn't be found") ); wxCHECK_MSG( m_fbc, FALSE, _T("required FBConfig couldn't be found") );
} }
XVisualInfo *vi = NULL; XVisualInfo *vi = NULL;
if (wxTheApp->m_glVisualInfo != NULL) if (wxTheApp->m_glVisualInfo != NULL)
{ {
vi = (XVisualInfo *)wxTheApp->m_glVisualInfo; vi = (XVisualInfo *)wxTheApp->m_glVisualInfo;
m_canFreeVi = FALSE; // owned by wxTheApp - don't free upon destruction m_canFreeVi = FALSE; // owned by wxTheApp - don't free upon destruction
} }
else else
{ {
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
// GLX >= 1.3 // GLX >= 1.3
vi = glXGetVisualFromFBConfig(GDK_DISPLAY(), m_fbc[0]); vi = glXGetVisualFromFBConfig(GDK_DISPLAY(), m_fbc[0]);
else else
// GLX <= 1.2 // GLX <= 1.2
vi = (XVisualInfo *) ChooseGLVisual(attribList); vi = (XVisualInfo *) ChooseGLVisual(attribList);
m_canFreeVi = TRUE; m_canFreeVi = TRUE;
} }
m_vi = vi; // save for later use m_vi = vi; // save for later use
wxCHECK_MSG( m_vi, FALSE, _T("required visual couldn't be found") ); wxCHECK_MSG( m_vi, FALSE, _T("required visual couldn't be found") );
@@ -444,11 +447,13 @@ bool wxGLCanvas::Create( wxWindow *parent,
wxGLCanvas::~wxGLCanvas() wxGLCanvas::~wxGLCanvas()
{ {
GLXFBConfig * fbc = (GLXFBConfig *) m_fbc; GLXFBConfig * fbc = (GLXFBConfig *) m_fbc;
if (fbc && m_canFreeFBC) XFree( fbc ); if (fbc && m_canFreeFBC)
XFree( fbc );
XVisualInfo *vi = (XVisualInfo *) m_vi; XVisualInfo *vi = (XVisualInfo *) m_vi;
if (vi && m_canFreeVi) XFree( vi ); if (vi && m_canFreeVi)
XFree( vi );
delete m_glContext; delete m_glContext;
} }
@@ -456,122 +461,152 @@ wxGLCanvas::~wxGLCanvas()
void* wxGLCanvas::ChooseGLVisual(int *attribList) void* wxGLCanvas::ChooseGLVisual(int *attribList)
{ {
int data[512]; int data[512];
GetGLAttribListFromWX( attribList, data ); GetGLAttribListFromWX( attribList, data );
attribList = (int*) data; attribList = (int*) data;
Display *dpy = GDK_DISPLAY(); Display *dpy = GDK_DISPLAY();
return glXChooseVisual( dpy, DefaultScreen(dpy), attribList ); return glXChooseVisual( dpy, DefaultScreen(dpy), attribList );
} }
void* wxGLCanvas::ChooseGLFBC(int *attribList) void* wxGLCanvas::ChooseGLFBC(int *attribList)
{ {
int data[512]; int data[512];
GetGLAttribListFromWX( attribList, data ); GetGLAttribListFromWX( attribList, data );
attribList = (int*) data; attribList = (int*) data;
int returned; int returned;
return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()), return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()),
attribList, &returned ); attribList, &returned );
} }
void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList ) void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
{ {
if (!wx_attribList) if (!wx_attribList)
{ {
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
// leave GLX >= 1.3 choose the default attributes // leave GLX >= 1.3 choose the default attributes
gl_attribList[0] = 0; gl_attribList[0] = 0;
else else
{ {
int i = 0; int i = 0;
// default settings if attriblist = 0 // default settings if attriblist = 0
gl_attribList[i++] = GLX_RGBA; gl_attribList[i++] = GLX_RGBA;
gl_attribList[i++] = GLX_DOUBLEBUFFER; gl_attribList[i++] = GLX_DOUBLEBUFFER;
gl_attribList[i++] = GLX_DEPTH_SIZE; gl_attribList[i++] = 1; gl_attribList[i++] = GLX_DEPTH_SIZE; gl_attribList[i++] = 1;
gl_attribList[i++] = GLX_RED_SIZE; gl_attribList[i++] = 1; gl_attribList[i++] = GLX_RED_SIZE; gl_attribList[i++] = 1;
gl_attribList[i++] = GLX_GREEN_SIZE; gl_attribList[i++] = 1; gl_attribList[i++] = GLX_GREEN_SIZE; gl_attribList[i++] = 1;
gl_attribList[i++] = GLX_BLUE_SIZE; gl_attribList[i++] = 1; gl_attribList[i++] = GLX_BLUE_SIZE; gl_attribList[i++] = 1;
gl_attribList[i++] = GLX_ALPHA_SIZE; gl_attribList[i++] = 0; gl_attribList[i++] = GLX_ALPHA_SIZE; gl_attribList[i++] = 0;
gl_attribList[i++] = None; gl_attribList[i++] = None;
} }
} }
else else
{ {
int arg=0, p=0; int arg=0, p=0;
while( (wx_attribList[arg]!=0) && (p<510) ) while( (wx_attribList[arg]!=0) && (p<510) )
{
switch( wx_attribList[arg++] )
{ {
case WX_GL_RGBA: switch( wx_attribList[arg++] )
if (wxGLCanvas::GetGLXVersion() <= 12) {
// for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm) case WX_GL_RGBA:
gl_attribList[p++] = GLX_RGBA; if (wxGLCanvas::GetGLXVersion() <= 12)
break; // for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm)
case WX_GL_BUFFER_SIZE: gl_attribList[p++] = GLX_RGBA;
gl_attribList[p++]=GLX_BUFFER_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; break;
case WX_GL_LEVEL: case WX_GL_BUFFER_SIZE:
gl_attribList[p++]=GLX_LEVEL; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = GLX_BUFFER_SIZE;
case WX_GL_DOUBLEBUFFER: gl_attribList[p++] = wx_attribList[arg++];
if (wxGLCanvas::GetGLXVersion() <= 12) break;
gl_attribList[p++] = GLX_DOUBLEBUFFER; case WX_GL_LEVEL:
else gl_attribList[p++] = GLX_LEVEL;
// for GLX >= 1.3, GLX_DOUBLEBUFFER format is different (1 <=> True) gl_attribList[p++] = wx_attribList[arg++];
// it seems this flag is useless for some hardware opengl implementation. break;
// but for Mesa 6.2.1, this flag is used so don't ignore it. case WX_GL_DOUBLEBUFFER:
gl_attribList[p++] = GLX_DOUBLEBUFFER; gl_attribList[p++]=1; if (wxGLCanvas::GetGLXVersion() <= 12)
break; gl_attribList[p++] = GLX_DOUBLEBUFFER;
case WX_GL_STEREO: gl_attribList[p++] = GLX_STEREO; break; else
case WX_GL_AUX_BUFFERS: // for GLX >= 1.3, GLX_DOUBLEBUFFER format is different (1 <=> True)
gl_attribList[p++]=GLX_AUX_BUFFERS; gl_attribList[p++]=wx_attribList[arg++]; break; // it seems this flag is useless for some hardware opengl implementation.
case WX_GL_MIN_RED: // but for Mesa 6.2.1, this flag is used so don't ignore it.
gl_attribList[p++]=GLX_RED_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = GLX_DOUBLEBUFFER;
case WX_GL_MIN_GREEN: gl_attribList[p++] = 1;
gl_attribList[p++]=GLX_GREEN_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; break;
case WX_GL_MIN_BLUE: case WX_GL_STEREO:
gl_attribList[p++]=GLX_BLUE_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = GLX_STEREO;
case WX_GL_MIN_ALPHA: break;
gl_attribList[p++]=GLX_ALPHA_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; case WX_GL_AUX_BUFFERS:
case WX_GL_DEPTH_SIZE: gl_attribList[p++] = GLX_AUX_BUFFERS;
gl_attribList[p++]=GLX_DEPTH_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = wx_attribList[arg++];
case WX_GL_STENCIL_SIZE: break;
gl_attribList[p++]=GLX_STENCIL_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; case WX_GL_MIN_RED:
case WX_GL_MIN_ACCUM_RED: gl_attribList[p++] = GLX_RED_SIZE;
gl_attribList[p++]=GLX_ACCUM_RED_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = wx_attribList[arg++];
case WX_GL_MIN_ACCUM_GREEN: break;
gl_attribList[p++]=GLX_ACCUM_GREEN_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; case WX_GL_MIN_GREEN:
case WX_GL_MIN_ACCUM_BLUE: gl_attribList[p++] = GLX_GREEN_SIZE;
gl_attribList[p++]=GLX_ACCUM_BLUE_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = wx_attribList[arg++];
case WX_GL_MIN_ACCUM_ALPHA: break;
gl_attribList[p++]=GLX_ACCUM_ALPHA_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; case WX_GL_MIN_BLUE:
default: gl_attribList[p++] = GLX_BLUE_SIZE;
break; gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ALPHA:
gl_attribList[p++] = GLX_ALPHA_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_DEPTH_SIZE:
gl_attribList[p++] = GLX_DEPTH_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_STENCIL_SIZE:
gl_attribList[p++] = GLX_STENCIL_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ACCUM_RED:
gl_attribList[p++] = GLX_ACCUM_RED_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ACCUM_GREEN:
gl_attribList[p++] = GLX_ACCUM_GREEN_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ACCUM_BLUE:
gl_attribList[p++] = GLX_ACCUM_BLUE_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ACCUM_ALPHA:
gl_attribList[p++] = GLX_ACCUM_ALPHA_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
default:
break;
}
} }
}
gl_attribList[p] = 0; gl_attribList[p] = 0;
} }
} }
void wxGLCanvas::QueryGLXVersion() void wxGLCanvas::QueryGLXVersion()
{ {
if (m_glxVersion == 0) if (m_glxVersion == 0)
{ {
// check the GLX version // check the GLX version
int glxMajorVer, glxMinorVer; int glxMajorVer, glxMinorVer;
bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer); bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer);
wxASSERT_MSG( ok, _T("GLX version not found") ); wxASSERT_MSG( ok, _T("GLX version not found") );
if (!ok) if (!ok)
m_glxVersion = 10; // 1.0 by default m_glxVersion = 10; // 1.0 by default
else else
m_glxVersion = glxMajorVer*10 + glxMinorVer; m_glxVersion = glxMajorVer*10 + glxMinorVer;
} }
} }
int wxGLCanvas::GetGLXVersion() int wxGLCanvas::GetGLXVersion()
{ {
wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") ); wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") );
return m_glxVersion; return m_glxVersion;
} }
@@ -622,41 +657,40 @@ IMPLEMENT_CLASS(wxGLApp, wxApp)
wxGLApp::~wxGLApp() wxGLApp::~wxGLApp()
{ {
if (m_glFBCInfo) if (m_glFBCInfo)
XFree(m_glFBCInfo); XFree(m_glFBCInfo);
if (m_glVisualInfo) if (m_glVisualInfo)
XFree(m_glVisualInfo); XFree(m_glVisualInfo);
} }
bool wxGLApp::InitGLVisual(int *attribList) bool wxGLApp::InitGLVisual(int *attribList)
{ {
wxGLCanvas::QueryGLXVersion(); wxGLCanvas::QueryGLXVersion();
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 // GLX >= 1.3
if (m_glFBCInfo) if (m_glFBCInfo)
XFree(m_glFBCInfo); XFree(m_glFBCInfo);
m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList); m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList);
if (m_glFBCInfo) if (m_glFBCInfo)
{ {
if (m_glVisualInfo) if (m_glVisualInfo)
XFree(m_glVisualInfo); XFree(m_glVisualInfo);
m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]); m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
} }
return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL); return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL);
} }
else else
{ {
// GLX <= 1.2 // GLX <= 1.2
if (m_glVisualInfo) if (m_glVisualInfo)
XFree(m_glVisualInfo); XFree(m_glVisualInfo);
m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList); m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList);
return m_glVisualInfo != NULL; return m_glVisualInfo != NULL;
} }
} }
#endif #endif
// wxUSE_GLCANVAS // wxUSE_GLCANVAS

View File

@@ -72,19 +72,19 @@ wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette&
wxGLCanvas *gc = (wxGLCanvas*) win; wxGLCanvas *gc = (wxGLCanvas*) win;
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 // GLX >= 1.3
GLXFBConfig *fbc = gc->m_fbc; GLXFBConfig *fbc = gc->m_fbc;
wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") ); wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, None, GL_TRUE ); m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, None, GL_TRUE );
} }
else else
{ {
// GLX <= 1.2 // GLX <= 1.2
XVisualInfo *vi = (XVisualInfo *) gc->m_vi; XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
wxCHECK_RET( vi, _T("invalid visual for OpenGl") ); wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
m_glContext = glXCreateContext( GDK_DISPLAY(), vi, None, GL_TRUE ); m_glContext = glXCreateContext( GDK_DISPLAY(), vi, None, GL_TRUE );
} }
wxCHECK_RET( m_glContext, _T("Couldn't create OpenGl context") ); wxCHECK_RET( m_glContext, _T("Couldn't create OpenGl context") );
} }
@@ -101,23 +101,23 @@ wxGLContext::wxGLContext(
wxGLCanvas *gc = (wxGLCanvas*) win; wxGLCanvas *gc = (wxGLCanvas*) win;
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 // GLX >= 1.3
GLXFBConfig *fbc = gc->m_fbc; GLXFBConfig *fbc = gc->m_fbc;
wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") ); wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE,
other ? other->m_glContext : None, other ? other->m_glContext : None,
GL_TRUE ); GL_TRUE );
} }
else else
{ {
// GLX <= 1.2 // GLX <= 1.2
XVisualInfo *vi = (XVisualInfo *) gc->m_vi; XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
wxCHECK_RET( vi, _T("invalid visual for OpenGl") ); wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
m_glContext = glXCreateContext( GDK_DISPLAY(), vi, m_glContext = glXCreateContext( GDK_DISPLAY(), vi,
other ? other->m_glContext : None, other ? other->m_glContext : None,
GL_TRUE ); GL_TRUE );
} }
if ( !m_glContext ) if ( !m_glContext )
{ {
@@ -131,12 +131,12 @@ wxGLContext::~wxGLContext()
if (m_glContext == glXGetCurrentContext()) if (m_glContext == glXGetCurrentContext())
{ {
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
// GLX >= 1.3 // GLX >= 1.3
glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL); glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL);
else else
// GLX <= 1.2 // GLX <= 1.2
glXMakeCurrent( GDK_DISPLAY(), None, NULL); glXMakeCurrent( GDK_DISPLAY(), None, NULL);
} }
glXDestroyContext( GDK_DISPLAY(), m_glContext ); glXDestroyContext( GDK_DISPLAY(), m_glContext );
@@ -157,12 +157,13 @@ void wxGLContext::SetCurrent()
{ {
GdkWindow *window = GTK_PIZZA(m_widget)->bin_window; GdkWindow *window = GTK_PIZZA(m_widget)->bin_window;
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
// GLX >= 1.3 // GLX >= 1.3
glXMakeContextCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), GDK_WINDOW_XWINDOW(window), m_glContext ); glXMakeContextCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window),
else GDK_WINDOW_XWINDOW(window), m_glContext );
// GLX <= 1.2 else
glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), m_glContext ); // GLX <= 1.2
glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), m_glContext );
} }
} }
@@ -358,39 +359,41 @@ bool wxGLCanvas::Create( wxWindow *parent,
wxGLCanvas::QueryGLXVersion(); wxGLCanvas::QueryGLXVersion();
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 uses a GLXFBConfig // GLX >= 1.3 uses a GLXFBConfig
GLXFBConfig * fbc = NULL; GLXFBConfig * fbc = NULL;
if (wxTheApp->m_glFBCInfo != NULL) if (wxTheApp->m_glFBCInfo != NULL)
{ {
fbc = (GLXFBConfig *) wxTheApp->m_glFBCInfo; fbc = (GLXFBConfig *) wxTheApp->m_glFBCInfo;
m_canFreeFBC = FALSE; // owned by wxTheApp - don't free upon destruction m_canFreeFBC = FALSE; // owned by wxTheApp - don't free upon destruction
} }
else else
{ {
fbc = (GLXFBConfig *) wxGLCanvas::ChooseGLFBC(attribList); fbc = (GLXFBConfig *) wxGLCanvas::ChooseGLFBC(attribList);
m_canFreeFBC = TRUE; m_canFreeFBC = TRUE;
} }
m_fbc = fbc; // save for later use m_fbc = fbc; // save for later use
wxCHECK_MSG( m_fbc, FALSE, _T("required FBConfig couldn't be found") ); wxCHECK_MSG( m_fbc, FALSE, _T("required FBConfig couldn't be found") );
} }
XVisualInfo *vi = NULL; XVisualInfo *vi = NULL;
if (wxTheApp->m_glVisualInfo != NULL) if (wxTheApp->m_glVisualInfo != NULL)
{ {
vi = (XVisualInfo *)wxTheApp->m_glVisualInfo; vi = (XVisualInfo *)wxTheApp->m_glVisualInfo;
m_canFreeVi = FALSE; // owned by wxTheApp - don't free upon destruction m_canFreeVi = FALSE; // owned by wxTheApp - don't free upon destruction
} }
else else
{ {
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
// GLX >= 1.3 // GLX >= 1.3
vi = glXGetVisualFromFBConfig(GDK_DISPLAY(), m_fbc[0]); vi = glXGetVisualFromFBConfig(GDK_DISPLAY(), m_fbc[0]);
else else
// GLX <= 1.2 // GLX <= 1.2
vi = (XVisualInfo *) ChooseGLVisual(attribList); vi = (XVisualInfo *) ChooseGLVisual(attribList);
m_canFreeVi = TRUE; m_canFreeVi = TRUE;
} }
m_vi = vi; // save for later use m_vi = vi; // save for later use
wxCHECK_MSG( m_vi, FALSE, _T("required visual couldn't be found") ); wxCHECK_MSG( m_vi, FALSE, _T("required visual couldn't be found") );
@@ -444,11 +447,13 @@ bool wxGLCanvas::Create( wxWindow *parent,
wxGLCanvas::~wxGLCanvas() wxGLCanvas::~wxGLCanvas()
{ {
GLXFBConfig * fbc = (GLXFBConfig *) m_fbc; GLXFBConfig * fbc = (GLXFBConfig *) m_fbc;
if (fbc && m_canFreeFBC) XFree( fbc ); if (fbc && m_canFreeFBC)
XFree( fbc );
XVisualInfo *vi = (XVisualInfo *) m_vi; XVisualInfo *vi = (XVisualInfo *) m_vi;
if (vi && m_canFreeVi) XFree( vi ); if (vi && m_canFreeVi)
XFree( vi );
delete m_glContext; delete m_glContext;
} }
@@ -456,122 +461,152 @@ wxGLCanvas::~wxGLCanvas()
void* wxGLCanvas::ChooseGLVisual(int *attribList) void* wxGLCanvas::ChooseGLVisual(int *attribList)
{ {
int data[512]; int data[512];
GetGLAttribListFromWX( attribList, data ); GetGLAttribListFromWX( attribList, data );
attribList = (int*) data; attribList = (int*) data;
Display *dpy = GDK_DISPLAY(); Display *dpy = GDK_DISPLAY();
return glXChooseVisual( dpy, DefaultScreen(dpy), attribList ); return glXChooseVisual( dpy, DefaultScreen(dpy), attribList );
} }
void* wxGLCanvas::ChooseGLFBC(int *attribList) void* wxGLCanvas::ChooseGLFBC(int *attribList)
{ {
int data[512]; int data[512];
GetGLAttribListFromWX( attribList, data ); GetGLAttribListFromWX( attribList, data );
attribList = (int*) data; attribList = (int*) data;
int returned; int returned;
return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()), return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()),
attribList, &returned ); attribList, &returned );
} }
void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList ) void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
{ {
if (!wx_attribList) if (!wx_attribList)
{ {
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
// leave GLX >= 1.3 choose the default attributes // leave GLX >= 1.3 choose the default attributes
gl_attribList[0] = 0; gl_attribList[0] = 0;
else else
{ {
int i = 0; int i = 0;
// default settings if attriblist = 0 // default settings if attriblist = 0
gl_attribList[i++] = GLX_RGBA; gl_attribList[i++] = GLX_RGBA;
gl_attribList[i++] = GLX_DOUBLEBUFFER; gl_attribList[i++] = GLX_DOUBLEBUFFER;
gl_attribList[i++] = GLX_DEPTH_SIZE; gl_attribList[i++] = 1; gl_attribList[i++] = GLX_DEPTH_SIZE; gl_attribList[i++] = 1;
gl_attribList[i++] = GLX_RED_SIZE; gl_attribList[i++] = 1; gl_attribList[i++] = GLX_RED_SIZE; gl_attribList[i++] = 1;
gl_attribList[i++] = GLX_GREEN_SIZE; gl_attribList[i++] = 1; gl_attribList[i++] = GLX_GREEN_SIZE; gl_attribList[i++] = 1;
gl_attribList[i++] = GLX_BLUE_SIZE; gl_attribList[i++] = 1; gl_attribList[i++] = GLX_BLUE_SIZE; gl_attribList[i++] = 1;
gl_attribList[i++] = GLX_ALPHA_SIZE; gl_attribList[i++] = 0; gl_attribList[i++] = GLX_ALPHA_SIZE; gl_attribList[i++] = 0;
gl_attribList[i++] = None; gl_attribList[i++] = None;
} }
} }
else else
{ {
int arg=0, p=0; int arg=0, p=0;
while( (wx_attribList[arg]!=0) && (p<510) ) while( (wx_attribList[arg]!=0) && (p<510) )
{
switch( wx_attribList[arg++] )
{ {
case WX_GL_RGBA: switch( wx_attribList[arg++] )
if (wxGLCanvas::GetGLXVersion() <= 12) {
// for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm) case WX_GL_RGBA:
gl_attribList[p++] = GLX_RGBA; if (wxGLCanvas::GetGLXVersion() <= 12)
break; // for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm)
case WX_GL_BUFFER_SIZE: gl_attribList[p++] = GLX_RGBA;
gl_attribList[p++]=GLX_BUFFER_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; break;
case WX_GL_LEVEL: case WX_GL_BUFFER_SIZE:
gl_attribList[p++]=GLX_LEVEL; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = GLX_BUFFER_SIZE;
case WX_GL_DOUBLEBUFFER: gl_attribList[p++] = wx_attribList[arg++];
if (wxGLCanvas::GetGLXVersion() <= 12) break;
gl_attribList[p++] = GLX_DOUBLEBUFFER; case WX_GL_LEVEL:
else gl_attribList[p++] = GLX_LEVEL;
// for GLX >= 1.3, GLX_DOUBLEBUFFER format is different (1 <=> True) gl_attribList[p++] = wx_attribList[arg++];
// it seems this flag is useless for some hardware opengl implementation. break;
// but for Mesa 6.2.1, this flag is used so don't ignore it. case WX_GL_DOUBLEBUFFER:
gl_attribList[p++] = GLX_DOUBLEBUFFER; gl_attribList[p++]=1; if (wxGLCanvas::GetGLXVersion() <= 12)
break; gl_attribList[p++] = GLX_DOUBLEBUFFER;
case WX_GL_STEREO: gl_attribList[p++] = GLX_STEREO; break; else
case WX_GL_AUX_BUFFERS: // for GLX >= 1.3, GLX_DOUBLEBUFFER format is different (1 <=> True)
gl_attribList[p++]=GLX_AUX_BUFFERS; gl_attribList[p++]=wx_attribList[arg++]; break; // it seems this flag is useless for some hardware opengl implementation.
case WX_GL_MIN_RED: // but for Mesa 6.2.1, this flag is used so don't ignore it.
gl_attribList[p++]=GLX_RED_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = GLX_DOUBLEBUFFER;
case WX_GL_MIN_GREEN: gl_attribList[p++] = 1;
gl_attribList[p++]=GLX_GREEN_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; break;
case WX_GL_MIN_BLUE: case WX_GL_STEREO:
gl_attribList[p++]=GLX_BLUE_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = GLX_STEREO;
case WX_GL_MIN_ALPHA: break;
gl_attribList[p++]=GLX_ALPHA_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; case WX_GL_AUX_BUFFERS:
case WX_GL_DEPTH_SIZE: gl_attribList[p++] = GLX_AUX_BUFFERS;
gl_attribList[p++]=GLX_DEPTH_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = wx_attribList[arg++];
case WX_GL_STENCIL_SIZE: break;
gl_attribList[p++]=GLX_STENCIL_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; case WX_GL_MIN_RED:
case WX_GL_MIN_ACCUM_RED: gl_attribList[p++] = GLX_RED_SIZE;
gl_attribList[p++]=GLX_ACCUM_RED_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = wx_attribList[arg++];
case WX_GL_MIN_ACCUM_GREEN: break;
gl_attribList[p++]=GLX_ACCUM_GREEN_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; case WX_GL_MIN_GREEN:
case WX_GL_MIN_ACCUM_BLUE: gl_attribList[p++] = GLX_GREEN_SIZE;
gl_attribList[p++]=GLX_ACCUM_BLUE_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; gl_attribList[p++] = wx_attribList[arg++];
case WX_GL_MIN_ACCUM_ALPHA: break;
gl_attribList[p++]=GLX_ACCUM_ALPHA_SIZE; gl_attribList[p++]=wx_attribList[arg++]; break; case WX_GL_MIN_BLUE:
default: gl_attribList[p++] = GLX_BLUE_SIZE;
break; gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ALPHA:
gl_attribList[p++] = GLX_ALPHA_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_DEPTH_SIZE:
gl_attribList[p++] = GLX_DEPTH_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_STENCIL_SIZE:
gl_attribList[p++] = GLX_STENCIL_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ACCUM_RED:
gl_attribList[p++] = GLX_ACCUM_RED_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ACCUM_GREEN:
gl_attribList[p++] = GLX_ACCUM_GREEN_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ACCUM_BLUE:
gl_attribList[p++] = GLX_ACCUM_BLUE_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
case WX_GL_MIN_ACCUM_ALPHA:
gl_attribList[p++] = GLX_ACCUM_ALPHA_SIZE;
gl_attribList[p++] = wx_attribList[arg++];
break;
default:
break;
}
} }
}
gl_attribList[p] = 0; gl_attribList[p] = 0;
} }
} }
void wxGLCanvas::QueryGLXVersion() void wxGLCanvas::QueryGLXVersion()
{ {
if (m_glxVersion == 0) if (m_glxVersion == 0)
{ {
// check the GLX version // check the GLX version
int glxMajorVer, glxMinorVer; int glxMajorVer, glxMinorVer;
bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer); bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer);
wxASSERT_MSG( ok, _T("GLX version not found") ); wxASSERT_MSG( ok, _T("GLX version not found") );
if (!ok) if (!ok)
m_glxVersion = 10; // 1.0 by default m_glxVersion = 10; // 1.0 by default
else else
m_glxVersion = glxMajorVer*10 + glxMinorVer; m_glxVersion = glxMajorVer*10 + glxMinorVer;
} }
} }
int wxGLCanvas::GetGLXVersion() int wxGLCanvas::GetGLXVersion()
{ {
wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") ); wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") );
return m_glxVersion; return m_glxVersion;
} }
@@ -622,41 +657,40 @@ IMPLEMENT_CLASS(wxGLApp, wxApp)
wxGLApp::~wxGLApp() wxGLApp::~wxGLApp()
{ {
if (m_glFBCInfo) if (m_glFBCInfo)
XFree(m_glFBCInfo); XFree(m_glFBCInfo);
if (m_glVisualInfo) if (m_glVisualInfo)
XFree(m_glVisualInfo); XFree(m_glVisualInfo);
} }
bool wxGLApp::InitGLVisual(int *attribList) bool wxGLApp::InitGLVisual(int *attribList)
{ {
wxGLCanvas::QueryGLXVersion(); wxGLCanvas::QueryGLXVersion();
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 // GLX >= 1.3
if (m_glFBCInfo) if (m_glFBCInfo)
XFree(m_glFBCInfo); XFree(m_glFBCInfo);
m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList); m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList);
if (m_glFBCInfo) if (m_glFBCInfo)
{ {
if (m_glVisualInfo) if (m_glVisualInfo)
XFree(m_glVisualInfo); XFree(m_glVisualInfo);
m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]); m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
} }
return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL); return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL);
} }
else else
{ {
// GLX <= 1.2 // GLX <= 1.2
if (m_glVisualInfo) if (m_glVisualInfo)
XFree(m_glVisualInfo); XFree(m_glVisualInfo);
m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList); m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList);
return m_glVisualInfo != NULL; return m_glVisualInfo != NULL;
} }
} }
#endif #endif
// wxUSE_GLCANVAS // wxUSE_GLCANVAS