added wxGLCanvas::IsDisplaySupported() (patch 1879906)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51526 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-02-03 14:55:05 +00:00
parent a0bcd61bbc
commit 3f20f7d8a3
8 changed files with 66 additions and 7 deletions

View File

@@ -278,6 +278,7 @@ All (GUI):
- Made wxSizer::Fit() set the client size of the target window - Made wxSizer::Fit() set the client size of the target window
- Add support for wxDatePickerCtrl in wxGenericValidator (Herry Ayen Yang) - Add support for wxDatePickerCtrl in wxGenericValidator (Herry Ayen Yang)
- Added wxWindow::HasFocus(). - Added wxWindow::HasFocus().
- Added wxGLCanvas::IsDisplaySupported()
wxGTK: wxGTK:

View File

@@ -125,6 +125,17 @@ and so on.
Ignored under most platforms.} Ignored under most platforms.}
\membersection{wxGLCanvas::IsDisplaySupported}\label{wxglcanvasisdisplaysupported}
\func{static bool}{IsDisplaySupported}{ \param{const int *}{ attribList = \NULL} }
Determines if a canvas having the specified attributes is available.
\docparam{attribList}{See \arg{attribList} for \helpref{wxGLCanvas::wxGLCanvas}{wxglcanvasconstr}.}
Returns \true if attributes are supported.
\membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrent} \membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrent}
\func{bool}{SetCurrent}{ \param{const wxGLContext&}{ context} } \func{bool}{SetCurrent}{ \param{const wxGLContext&}{ context} }

View File

@@ -108,6 +108,9 @@ public:
// accessors // accessors
// --------- // ---------
// check if the given attributes are supported without creating a canvas
static bool IsDisplaySupported(const int *attribList);
const wxPalette *GetPalette() const { return &m_palette; } const wxPalette *GetPalette() const { return &m_palette; }
// miscellaneous helper functions // miscellaneous helper functions

View File

@@ -95,6 +95,13 @@ public:
// free the global GL visual, called by wxGLApp // free the global GL visual, called by wxGLApp
static void FreeDefaultVisualInfo(); static void FreeDefaultVisualInfo();
// initializes XVisualInfo (in any case) and, if supported, GLXFBConfig
//
// returns false if XVisualInfo couldn't be initialized, otherwise caller
// is responsible for freeing the pointers
static bool InitXVisualInfo(const int *attribList,
GLXFBConfig **pFBC, XVisualInfo **pXVisual);
private: private:
// fills in glattrs with attributes defined by wxattrs which must be // fills in glattrs with attributes defined by wxattrs which must be
// 0-terminated if it is non-NULL // 0-terminated if it is non-NULL
@@ -103,13 +110,6 @@ private:
// should be at least 16 to accommodate the default attributes // should be at least 16 to accommodate the default attributes
static bool ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n); static bool ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n);
// initializes XVisualInfo (in any case) and, if supported, GLXFBConfig
//
// returns false if XVisualInfo couldn't be initialized, otherwise caller
// is responsible for freeing the pointers
static bool InitXVisualInfo(const int *attribList,
GLXFBConfig **pFBC, XVisualInfo **pXVisual);
// this is only used if it's supported i.e. if GL >= 1.3 // this is only used if it's supported i.e. if GL >= 1.3
GLXFBConfig *m_fbc; GLXFBConfig *m_fbc;

View File

@@ -385,6 +385,11 @@ MyFrame::MyFrame()
SetClientSize(400, 400); SetClientSize(400, 400);
Show(); Show();
// test IsDisplaySupported() function:
static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
wxLogStatus("Double-buffered display %s supported",
wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
} }
void MyFrame::OnClose(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnClose(wxCommandEvent& WXUNUSED(event))

View File

@@ -312,6 +312,19 @@ wxGLCanvas::~wxGLCanvas()
aglDestroyPixelFormat(m_aglFormat); aglDestroyPixelFormat(m_aglFormat);
} }
/* static */
bool wxGLCanvasBase::IsDisplaySupported(const int *attribList)
{
AGLPixelFormat aglFormat = ChoosePixelFormat(attribList);
if ( !aglFormat )
return false;
aglDestroyPixelFormat(aglFormat);
return true;
}
bool wxGLCanvas::SwapBuffers() bool wxGLCanvas::SwapBuffers()
{ {
AGLContext context = aglGetCurrentContext(); AGLContext context = aglGetCurrentContext();

View File

@@ -450,6 +450,14 @@ wxGLCanvas::ChooseMatchingPixelFormat(HDC hdc,
return ::ChoosePixelFormat(hdc, ppfd); return ::ChoosePixelFormat(hdc, ppfd);
} }
/* static */
bool wxGLCanvasBase::IsDisplaySupported(const int *attribList)
{
// We need a device context to test the pixel format, so get one
// for the root window.
return wxGLCanvas::ChooseMatchingPixelFormat(ScreenHDC(), attribList) > 0;
}
bool wxGLCanvas::DoSetup(const int *attribList) bool wxGLCanvas::DoSetup(const int *attribList)
{ {
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;

View File

@@ -297,6 +297,24 @@ wxGLCanvasX11::InitXVisualInfo(const int *attribList,
return *pXVisual != NULL; return *pXVisual != NULL;
} }
/* static */
bool
wxGLCanvasBase::IsDisplaySupported(const int *attribList)
{
GLXFBConfig *fbc = NULL;
XVisualInfo *vi = NULL;
const bool
isSupported = wxGLCanvasX11::InitXVisualInfo(attribList, &fbc, &vi);
if ( fbc )
XFree(fbc);
if ( vi )
XFree(vi);
return isSupported;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// default visual management // default visual management
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------