]> git.saurik.com Git - wxWidgets.git/blob - src/common/glcmn.cpp
Don't use hidden items for size calc (patch 1698314)
[wxWidgets.git] / src / common / glcmn.cpp
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"
36 WX_CHECK_BUILD_OPTIONS("wxGL")
37
38 IMPLEMENT_CLASS(wxGLApp, wxApp)
39
40 // ============================================================================
41 // implementation
42 // ============================================================================
43
44 void wxGLCanvasBase::SetCurrent(const wxGLContext& context) const
45 {
46 // although on MSW it works even if the window is still hidden, it doesn't
47 // work in other ports (notably X11-based ones) and documentation mentions
48 // that SetCurrent() can only be called for a shown window, so check for it
49 wxASSERT_MSG( IsShownOnScreen(), _T("can't make hidden GL canvas current") );
50
51 context.SetCurrent(*wx_static_cast(const wxGLCanvas *, this));
52 }
53
54 bool wxGLCanvasBase::SetColour(const wxChar *colour)
55 {
56 wxColour col = wxTheColourDatabase->Find(colour);
57 if ( !col.Ok() )
58 return false;
59
60 GLboolean isRGBA;
61 glGetBooleanv(GL_RGBA_MODE, &isRGBA);
62 if ( isRGBA )
63 {
64 glColor3f(col.Red() / 256., col.Green() / 256., col.Blue() / 256.);
65 }
66 else // indexed colour
67 {
68 GLint pix = GetColourIndex(col);
69 if ( pix == -1 )
70 {
71 wxLogError(_("Failed to allocate colour for OpenGL"));
72 return false;
73 }
74
75 glIndexi(pix);
76 }
77
78 return true;
79 }
80
81 wxGLCanvasBase::~wxGLCanvasBase()
82 {
83 #if WXWIN_COMPATIBILITY_2_8
84 delete m_glContext;
85 #endif // WXWIN_COMPATIBILITY_2_8
86 }
87
88 #if WXWIN_COMPATIBILITY_2_8
89
90 wxGLContext *wxGLCanvasBase::GetContext() const
91 {
92 return m_glContext;
93 }
94
95 void wxGLCanvasBase::SetCurrent()
96 {
97 if ( m_glContext )
98 SetCurrent(*m_glContext);
99 }
100
101 void wxGLCanvasBase::OnSize(wxSizeEvent& WXUNUSED(event))
102 {
103 }
104
105 #endif // WXWIN_COMPATIBILITY_2_8
106
107 #endif // wxUSE_GLCANVAS
108