From 1650623133123f4f708c61af6446aaaff9ef11e8 Mon Sep 17 00:00:00 2001 From: Gilles Depeyrot Date: Thu, 4 Oct 2001 18:40:22 +0000 Subject: [PATCH] applied SourceForge patch #467884 (Paul Thiessen) addes wxGLApp for wxMac git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11836 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/glcanvas.cpp | 41 +++++++++++++++++++++++++++++-------- src/mac/glcanvas.cpp | 41 +++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/mac/carbon/glcanvas.cpp b/src/mac/carbon/glcanvas.cpp index 22a0603ad5..6c1459db38 100644 --- a/src/mac/carbon/glcanvas.cpp +++ b/src/mac/carbon/glcanvas.cpp @@ -145,13 +145,10 @@ wxGLCanvas::~wxGLCanvas() delete m_glContext; } -bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id, - const wxPoint& pos, const wxSize& size, long style, const wxString& name, - int *attribList, const wxPalette& palette) +static AGLPixelFormat ChoosePixelFormat(const int *attribList) { - m_macEraseOnRedraw = false ; GLint data[512]; - GLint defs[] = { AGL_RGBA, + GLint defaultAttribs[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_MINIMUM_POLICY, AGL_DEPTH_SIZE, 1, // use largest available depth buffer @@ -163,11 +160,11 @@ bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID GLint *attribs; if (!attribList) { - attribs = defs; + attribs = defaultAttribs; } else { - int data[512], arg=0, p=0; + int arg=0, p=0; data[p++] = AGL_MINIMUM_POLICY; // make _SIZE tags behave more like GLX while( (attribList[arg]!=0) && (p<512) ) @@ -209,11 +206,20 @@ bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID } data[p] = 0; - attribs = defs; + attribs = data; } + + return aglChoosePixelFormat(NULL, 0, attribs); +} + +bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id, + const wxPoint& pos, const wxSize& size, long style, const wxString& name, + int *attribList, const wxPalette& palette) +{ + m_macEraseOnRedraw = false ; wxScrolledWindow::Create( parent, id, pos, size, style, name ); - AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, attribs); + AGLPixelFormat fmt = ChoosePixelFormat(attribList); wxCHECK_MSG( fmt, false, wxT("Couldn't create OpenGl pixel format") ); m_glContext = new wxGLContext(fmt, this, palette, shared); @@ -285,4 +291,21 @@ void wxGLCanvas::SetColour(const char *colour) m_glContext->SetColour(colour); } + +//--------------------------------------------------------------------------- +// wxGLApp +//--------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxGLApp, wxApp) + +bool wxGLApp::InitGLVisual(int *attribList) +{ + AGLPixelFormat fmt = ChoosePixelFormat(attribList); + return (fmt != NULL); +} + +wxGLApp::~wxGLApp(void) +{ +} + #endif // wxUSE_GLCANVAS diff --git a/src/mac/glcanvas.cpp b/src/mac/glcanvas.cpp index 22a0603ad5..6c1459db38 100644 --- a/src/mac/glcanvas.cpp +++ b/src/mac/glcanvas.cpp @@ -145,13 +145,10 @@ wxGLCanvas::~wxGLCanvas() delete m_glContext; } -bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id, - const wxPoint& pos, const wxSize& size, long style, const wxString& name, - int *attribList, const wxPalette& palette) +static AGLPixelFormat ChoosePixelFormat(const int *attribList) { - m_macEraseOnRedraw = false ; GLint data[512]; - GLint defs[] = { AGL_RGBA, + GLint defaultAttribs[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_MINIMUM_POLICY, AGL_DEPTH_SIZE, 1, // use largest available depth buffer @@ -163,11 +160,11 @@ bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID GLint *attribs; if (!attribList) { - attribs = defs; + attribs = defaultAttribs; } else { - int data[512], arg=0, p=0; + int arg=0, p=0; data[p++] = AGL_MINIMUM_POLICY; // make _SIZE tags behave more like GLX while( (attribList[arg]!=0) && (p<512) ) @@ -209,11 +206,20 @@ bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID } data[p] = 0; - attribs = defs; + attribs = data; } + + return aglChoosePixelFormat(NULL, 0, attribs); +} + +bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id, + const wxPoint& pos, const wxSize& size, long style, const wxString& name, + int *attribList, const wxPalette& palette) +{ + m_macEraseOnRedraw = false ; wxScrolledWindow::Create( parent, id, pos, size, style, name ); - AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, attribs); + AGLPixelFormat fmt = ChoosePixelFormat(attribList); wxCHECK_MSG( fmt, false, wxT("Couldn't create OpenGl pixel format") ); m_glContext = new wxGLContext(fmt, this, palette, shared); @@ -285,4 +291,21 @@ void wxGLCanvas::SetColour(const char *colour) m_glContext->SetColour(colour); } + +//--------------------------------------------------------------------------- +// wxGLApp +//--------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxGLApp, wxApp) + +bool wxGLApp::InitGLVisual(int *attribList) +{ + AGLPixelFormat fmt = ChoosePixelFormat(attribList); + return (fmt != NULL); +} + +wxGLApp::~wxGLApp(void) +{ +} + #endif // wxUSE_GLCANVAS