Big wxGL classes refactoring/cleanup:

1. Provide the same API, especially, but not limited to, wxGLCanvas and
   wxCLContext ctors (which were completely different in all ports)
2. Extracted common parts into wxGLCanvas/ContextBase classes
3. Deprecate the old API using implicitly created wxGLContext


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45388 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-04-10 17:38:55 +00:00
parent 1f602af615
commit dc3065a56f
25 changed files with 1860 additions and 1996 deletions

108
src/common/glcmn.cpp Normal file
View File

@@ -0,0 +1,108 @@
///////////////////////////////////////////////////////////////////////////////
// Name: src/common/glcmn.cpp
// Purpose: wxGLCanvasBase implementation
// Author: Vadim Zeitlin
// Created: 2007-04-09
// RCS-ID: $Id$
// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_GLCANVAS
#ifndef WX_PRECOMP
#include "wx/log.h"
#endif // WX_PRECOMP
#include "wx/glcanvas.h"
// DLL options compatibility check:
#include "wx/build.h"
WX_CHECK_BUILD_OPTIONS("wxGL")
IMPLEMENT_CLASS(wxGLApp, wxApp)
// ============================================================================
// implementation
// ============================================================================
void wxGLCanvasBase::SetCurrent(const wxGLContext& context) const
{
// although on MSW it works even if the window is still hidden, it doesn't
// work in other ports (notably X11-based ones) and documentation mentions
// that SetCurrent() can only be called for a shown window, so check for it
wxASSERT_MSG( IsShownOnScreen(), _T("can't make hidden GL canvas current") );
context.SetCurrent(*wx_static_cast(const wxGLCanvas *, this));
}
bool wxGLCanvasBase::SetColour(const wxChar *colour)
{
wxColour col = wxTheColourDatabase->Find(colour);
if ( !col.Ok() )
return false;
GLboolean isRGBA;
glGetBooleanv(GL_RGBA_MODE, &isRGBA);
if ( isRGBA )
{
glColor3f(col.Red() / 256., col.Green() / 256., col.Blue() / 256.);
}
else // indexed colour
{
GLint pix = GetColourIndex(col);
if ( pix == -1 )
{
wxLogError(_("Failed to allocate colour for OpenGL"));
return false;
}
glIndexi(pix);
}
return true;
}
wxGLCanvasBase::~wxGLCanvasBase()
{
#if WXWIN_COMPATIBILITY_2_8
delete m_glContext;
#endif // WXWIN_COMPATIBILITY_2_8
}
#if WXWIN_COMPATIBILITY_2_8
wxGLContext *wxGLCanvasBase::GetContext() const
{
return m_glContext;
}
void wxGLCanvasBase::SetCurrent()
{
if ( m_glContext )
SetCurrent(*m_glContext);
}
void wxGLCanvasBase::OnSize(wxSizeEvent& WXUNUSED(event))
{
}
#endif // WXWIN_COMPATIBILITY_2_8
#endif // wxUSE_GLCANVAS