]> git.saurik.com Git - wxWidgets.git/blame - src/common/glcmn.cpp
Fix wxDocManager::GetLastDirectory() when there is no history.
[wxWidgets.git] / src / common / glcmn.cpp
CommitLineData
dc3065a5
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/glcmn.cpp
3// Purpose: wxGLCanvasBase implementation
4// Author: Vadim Zeitlin
5// Created: 2007-04-09
6// RCS-ID: $Id$
7// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// for compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#if wxUSE_GLCANVAS
27
28#ifndef WX_PRECOMP
29 #include "wx/log.h"
30#endif // WX_PRECOMP
31
32#include "wx/glcanvas.h"
33
34// DLL options compatibility check:
35#include "wx/build.h"
36WX_CHECK_BUILD_OPTIONS("wxGL")
37
38IMPLEMENT_CLASS(wxGLApp, wxApp)
39
40// ============================================================================
41// implementation
42// ============================================================================
43
15b239c0
VZ
44wxGLCanvasBase::wxGLCanvasBase()
45{
46#if WXWIN_COMPATIBILITY_2_8
47 m_glContext = NULL;
48#endif
49
50 // we always paint background entirely ourselves so prevent wx from erasing
51 // it to avoid flicker
52 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
53}
54
5ec69e96 55bool wxGLCanvasBase::SetCurrent(const wxGLContext& context) const
dc3065a5
VZ
56{
57 // although on MSW it works even if the window is still hidden, it doesn't
58 // work in other ports (notably X11-based ones) and documentation mentions
59 // that SetCurrent() can only be called for a shown window, so check for it
9a83f860 60 wxASSERT_MSG( IsShownOnScreen(), wxT("can't make hidden GL canvas current") );
dc3065a5 61
5c33522f 62 return context.SetCurrent(*static_cast<const wxGLCanvas *>(this));
dc3065a5
VZ
63}
64
03647350 65#ifndef wxHAS_OPENGL_ES
35f1f4f7 66bool wxGLCanvasBase::SetColour(const wxString& colour)
dc3065a5
VZ
67{
68 wxColour col = wxTheColourDatabase->Find(colour);
69 if ( !col.Ok() )
70 return false;
71
72 GLboolean isRGBA;
73 glGetBooleanv(GL_RGBA_MODE, &isRGBA);
74 if ( isRGBA )
75 {
76 glColor3f(col.Red() / 256., col.Green() / 256., col.Blue() / 256.);
77 }
78 else // indexed colour
79 {
80 GLint pix = GetColourIndex(col);
81 if ( pix == -1 )
82 {
83 wxLogError(_("Failed to allocate colour for OpenGL"));
84 return false;
85 }
86
87 glIndexi(pix);
88 }
89
90 return true;
91}
04ce16a8 92#endif
dc3065a5
VZ
93
94wxGLCanvasBase::~wxGLCanvasBase()
95{
96#if WXWIN_COMPATIBILITY_2_8
97 delete m_glContext;
98#endif // WXWIN_COMPATIBILITY_2_8
99}
100
101#if WXWIN_COMPATIBILITY_2_8
102
103wxGLContext *wxGLCanvasBase::GetContext() const
104{
105 return m_glContext;
106}
107
108void wxGLCanvasBase::SetCurrent()
109{
110 if ( m_glContext )
111 SetCurrent(*m_glContext);
112}
113
114void wxGLCanvasBase::OnSize(wxSizeEvent& WXUNUSED(event))
115{
116}
117
118#endif // WXWIN_COMPATIBILITY_2_8
119
c39d2e0a
VZ
120/* static */
121bool wxGLCanvasBase::IsExtensionInList(const char *list, const char *extension)
122{
442e842e
VZ
123 if ( !list )
124 return false;
125
c39d2e0a
VZ
126 for ( const char *p = list; *p; p++ )
127 {
128 // advance up to the next possible match
129 p = wxStrstr(p, extension);
130 if ( !p )
131 break;
132
133 // check that the extension appears at the beginning/ending of the list
134 // or is preceded/followed by a space to avoid mistakenly finding
135 // "glExtension" in a list containing some "glFunkyglExtension"
136 if ( (p == list || p[-1] == ' ') )
137 {
138 char c = p[strlen(extension)];
139 if ( c == '\0' || c == ' ' )
140 return true;
141 }
142 }
143
144 return false;
145}
146
dc3065a5
VZ
147#endif // wxUSE_GLCANVAS
148