From dc3065a56f1febf3de3b3bbf0904cf8fdc7f7c50 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Tue, 10 Apr 2007 17:38:55 +0000
Subject: [PATCH] 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
---
 Makefile.in                      |  73 ++--
 build/bakefiles/files.bkl        |  21 +-
 build/msw/makefile.bcc           |   8 +
 build/msw/makefile.gcc           |   8 +
 build/msw/makefile.vc            |  12 +-
 build/msw/makefile.wat           |   8 +
 build/msw/wx_gl.dsp              |  12 +
 docs/latex/wx/glcanvas.tex       | 129 ++----
 include/wx/cocoa/glcanvas.h      |  95 ++---
 include/wx/glcanvas.h            | 150 +++++--
 include/wx/gtk/glcanvas.h        | 172 ++++----
 include/wx/gtk1/glcanvas.h       | 191 +++++----
 include/wx/mac/carbon/glcanvas.h | 174 ++++----
 include/wx/msw/glcanvas.h        | 161 ++++----
 include/wx/palmos/glcanvas.h     |   6 -
 include/wx/x11/glcanvas.h        | 119 ++----
 src/cocoa/glcanvas.mm            |  50 +--
 src/common/glcmn.cpp             | 108 +++++
 src/gtk/app.cpp                  |   5 +
 src/gtk/glcanvas.cpp             | 333 +++++++---------
 src/gtk1/glcanvas.cpp            | 442 ++++++++-------------
 src/mac/carbon/glcanvas.cpp      | 524 +++++++++++++------------
 src/msw/glcanvas.cpp             | 655 +++++++++++++++----------------
 src/palmos/glcanvas.cpp          |   7 -
 src/x11/glcanvas.cpp             | 329 ++++------------
 25 files changed, 1828 insertions(+), 1964 deletions(-)
 create mode 100644 src/common/glcmn.cpp

diff --git a/Makefile.in b/Makefile.in
index ffac1767f1..5781ec3a17 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1641,14 +1641,16 @@ GLDLL_CXXFLAGS = $(__gldll_PCH_INC) -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \
 	-DWXMAKINGDLL_GL $(PIC_FLAG) $(CPPFLAGS) $(CXXFLAGS)
 GLDLL_OBJECTS =  \
 	$(__gldll___win32rc) \
-	$(__OPENGL_SRC_OBJECTS)
+	gldll_glcmn.o \
+	$(__OPENGL_SRC_PLATFORM_OBJECTS)
 GLDLL_ODEP =  $(___pch_wxprec_gldll_wx_wxprec_h_gch___depname)
 GLLIB_CXXFLAGS = $(__gllib_PCH_INC) -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \
 	$(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) \
 	$(__INC_TIFF_p) $(__INC_JPEG_p) $(__INC_PNG_p) $(__INC_ZLIB_p) \
 	$(__INC_ODBC_p) $(__INC_REGEX_p) $(__INC_EXPAT_p) $(CPPFLAGS) $(CXXFLAGS)
 GLLIB_OBJECTS =  \
-	$(__OPENGL_SRC_OBJECTS_1)
+	gllib_glcmn.o \
+	$(__OPENGL_SRC_PLATFORM_OBJECTS_1)
 GLLIB_ODEP =  $(___pch_wxprec_gllib_wx_wxprec_h_gch___depname)
 SOUND_SDL_CXXFLAGS = -DWXUSINGDLL -DwxUSE_GUI=0 $(PIC_FLAG) $(CPPFLAGS) \
 	$(CXXFLAGS)
@@ -1764,15 +1766,15 @@ COND_USE_STC_1___wxscintilla___depname = \
 @COND_TOOLKIT_WINCE@NET_WINCE_SRC = src/msw/wince/net.cpp
 @COND_TOOLKIT_WINCE@NET_WINCE_HDR = wx/msw/wince/net.h
 @COND_TOOLKIT_MSW@MSW_HTML_HDR = wx/msw/helpbest.h
-@COND_TOOLKIT_COCOA@OPENGL_HDR = wx/cocoa/glcanvas.h
-@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@OPENGL_HDR = wx/gtk1/glcanvas.h
-@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@OPENGL_HDR = wx/gtk/glcanvas.h
-@COND_TOOLKIT_MAC@OPENGL_HDR = wx/mac/carbon/glcanvas.h
-@COND_TOOLKIT_MOTIF@OPENGL_HDR = wx/x11/glcanvas.h
-@COND_TOOLKIT_MSW@OPENGL_HDR = wx/msw/glcanvas.h
-@COND_TOOLKIT_PM@OPENGL_HDR = wx/os2/glcanvas.h
-@COND_TOOLKIT_WINCE@OPENGL_HDR = wx/msw/glcanvas.h
-@COND_TOOLKIT_X11@OPENGL_HDR = wx/x11/glcanvas.h
+@COND_TOOLKIT_COCOA@OPENGL_HDR_PLATFORM = wx/cocoa/glcanvas.h
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@OPENGL_HDR_PLATFORM = wx/gtk1/glcanvas.h
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@OPENGL_HDR_PLATFORM = wx/gtk/glcanvas.h
+@COND_TOOLKIT_MAC@OPENGL_HDR_PLATFORM = wx/mac/glcanvas.h \
+@COND_TOOLKIT_MAC@	wx/mac/carbon/glcanvas.h
+@COND_TOOLKIT_MOTIF@OPENGL_HDR_PLATFORM = wx/x11/glcanvas.h
+@COND_TOOLKIT_MSW@OPENGL_HDR_PLATFORM = wx/msw/glcanvas.h
+@COND_TOOLKIT_WINCE@OPENGL_HDR_PLATFORM = wx/msw/glcanvas.h
+@COND_TOOLKIT_X11@OPENGL_HDR_PLATFORM = wx/x11/glcanvas.h
 COND_TOOLKIT__BASE_MACOSX_HDR =  \
 	wx/unix/apptbase.h \
 	wx/unix/apptrait.h \
@@ -2288,7 +2290,6 @@ COND_TOOLKIT_MAC_GUI_HDR =  \
 	wx/mac/fontdlg.h \
 	wx/mac/frame.h \
 	wx/mac/gauge.h \
-	wx/mac/glcanvas.h \
 	wx/mac/gsockmac.h \
 	wx/mac/helpxxxx.h \
 	wx/mac/icon.h \
@@ -3120,7 +3121,6 @@ COND_USE_GUI_1_ALL_GUI_HEADERS =  \
 	wx/gdiobj.h \
 	wx/geometry.h \
 	wx/gifdecod.h \
-	wx/glcanvas.h \
 	wx/help.h \
 	wx/helpbase.h \
 	wx/helpwin.h \
@@ -3205,7 +3205,8 @@ COND_USE_GUI_1_ALL_GUI_HEADERS =  \
 	wx/wxhtml.h \
 	wx/htmllbox.h \
 	$(MSW_HTML_HDR) \
-	$(OPENGL_HDR) \
+	wx/glcanvas.h \
+	$(OPENGL_HDR_PLATFORM) \
 	wx/debugrpt.h \
 	wx/dbgrid.h \
 	wx/xrc/xh_all.h \
@@ -11284,15 +11285,17 @@ COND_USE_SOSYMLINKS_1___gldll___so_symlinks_uninst_cmd = rm -f \
 	$(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX)
 @COND_USE_SOSYMLINKS_1@__gldll___so_symlinks_uninst_cmd = $(COND_USE_SOSYMLINKS_1___gldll___so_symlinks_uninst_cmd)
 @COND_PLATFORM_WIN32_1@__gldll___win32rc = gldll_version_rc.o
-@COND_TOOLKIT_COCOA@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o
-@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o
-@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o
-@COND_TOOLKIT_MAC@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o
-@COND_TOOLKIT_MOTIF@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o
-@COND_TOOLKIT_MSW@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o
-@COND_TOOLKIT_PM@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o
-@COND_TOOLKIT_WINCE@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o
-@COND_TOOLKIT_X11@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o
+@COND_TOOLKIT_COCOA@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@__OPENGL_SRC_PLATFORM_OBJECTS \
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@	= gldll_glcanvas.o
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__OPENGL_SRC_PLATFORM_OBJECTS \
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@	= gldll_glcanvas.o
+@COND_TOOLKIT_MAC@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
+@COND_TOOLKIT_MOTIF@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
+@COND_TOOLKIT_MSW@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
+@COND_TOOLKIT_PM@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
+@COND_TOOLKIT_WINCE@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
+@COND_TOOLKIT_X11@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
 COND_MONOLITHIC_0___WXLIBGLDEP_CORE_p = \
 	-lwx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_core-$(WX_RELEASE)$(HOST_SUFFIX)
 @COND_MONOLITHIC_0@__WXLIBGLDEP_CORE_p = $(COND_MONOLITHIC_0___WXLIBGLDEP_CORE_p)
@@ -11314,17 +11317,17 @@ COND_SHARED_0_USE_GUI_1_USE_OPENGL_1___gllib___depname = \
 @COND_ICC_PCH_1@	.pch/wxprec_gllib/wx/wxprec.h.gch
 @COND_USE_PCH_1@___pch_wxprec_gllib_wx_wxprec_h_gch___depname \
 @COND_USE_PCH_1@	= .pch/wxprec_gllib/wx/wxprec.h.gch
-@COND_TOOLKIT_COCOA@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o
-@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@__OPENGL_SRC_OBJECTS_1 \
+@COND_TOOLKIT_COCOA@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@__OPENGL_SRC_PLATFORM_OBJECTS_1 \
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_@	= gllib_glcanvas.o
-@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__OPENGL_SRC_OBJECTS_1 \
+@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__OPENGL_SRC_PLATFORM_OBJECTS_1 \
 @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@	= gllib_glcanvas.o
-@COND_TOOLKIT_MAC@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o
-@COND_TOOLKIT_MOTIF@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o
-@COND_TOOLKIT_MSW@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o
-@COND_TOOLKIT_PM@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o
-@COND_TOOLKIT_WINCE@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o
-@COND_TOOLKIT_X11@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o
+@COND_TOOLKIT_MAC@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
+@COND_TOOLKIT_MOTIF@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
+@COND_TOOLKIT_MSW@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
+@COND_TOOLKIT_PM@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
+@COND_TOOLKIT_WINCE@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
+@COND_TOOLKIT_X11@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
 @COND_SHARED_1@____wxgl_namedll_DEP = $(__gldll___depname)
 @COND_SHARED_0@____wxgl_namelib_DEP = $(__gllib___depname)
 COND_WITH_PLUGIN_SDL_1___sound_sdl___depname = \
@@ -30008,6 +30011,9 @@ stclib_ScintillaWX.o: $(srcdir)/src/stc/ScintillaWX.cpp $(STCLIB_ODEP)
 gldll_version_rc.o: $(srcdir)/src/msw/version.rc $(GLDLL_ODEP)
 	$(WINDRES) -i$< -o$@    --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_62)  $(__EXCEPTIONS_DEFINE_p_61) $(__RTTI_DEFINE_p_61) $(__THREAD_DEFINE_p_61)   --define WXDLLNAME=$(WXDLLNAMEPREFIXGUI)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG) $(__RCDEFDIR_p) --include-dir $(top_srcdir)/include $(__INC_TIFF_p_61) $(__INC_JPEG_p_62) $(__INC_PNG_p_61) $(__INC_ZLIB_p_63) $(__INC_ODBC_p_61) $(__INC_REGEX_p_61) $(__INC_EXPAT_p_61) --define WXUSINGDLL --define WXMAKINGDLL_GL
 
+gldll_glcmn.o: $(srcdir)/src/common/glcmn.cpp $(GLDLL_ODEP)
+	$(CXXC) -c -o $@ $(GLDLL_CXXFLAGS) $(srcdir)/src/common/glcmn.cpp
+
 @COND_TOOLKIT_MAC@gldll_glcanvas.o: $(srcdir)/src/mac/carbon/glcanvas.cpp $(GLDLL_ODEP)
 @COND_TOOLKIT_MAC@	$(CXXC) -c -o $@ $(GLDLL_CXXFLAGS) $(srcdir)/src/mac/carbon/glcanvas.cpp
 
@@ -30035,6 +30041,9 @@ gldll_version_rc.o: $(srcdir)/src/msw/version.rc $(GLDLL_ODEP)
 @COND_TOOLKIT_PM@gldll_glcanvas.o: $(srcdir)/src/os2/glcanvas.cpp $(GLDLL_ODEP)
 @COND_TOOLKIT_PM@	$(CXXC) -c -o $@ $(GLDLL_CXXFLAGS) $(srcdir)/src/os2/glcanvas.cpp
 
+gllib_glcmn.o: $(srcdir)/src/common/glcmn.cpp $(GLLIB_ODEP)
+	$(CXXC) -c -o $@ $(GLLIB_CXXFLAGS) $(srcdir)/src/common/glcmn.cpp
+
 @COND_TOOLKIT_MAC@gllib_glcanvas.o: $(srcdir)/src/mac/carbon/glcanvas.cpp $(GLLIB_ODEP)
 @COND_TOOLKIT_MAC@	$(CXXC) -c -o $@ $(GLLIB_CXXFLAGS) $(srcdir)/src/mac/carbon/glcanvas.cpp
 
diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl
index 1f74cf0d2e..4e2ba30fbd 100644
--- a/build/bakefiles/files.bkl
+++ b/build/bakefiles/files.bkl
@@ -832,7 +832,6 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     wx/gdiobj.h
     wx/geometry.h
     wx/gifdecod.h
-    wx/glcanvas.h
     wx/help.h
     wx/helpbase.h
     wx/helpwin.h
@@ -2223,7 +2222,6 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     wx/mac/fontdlg.h
     wx/mac/frame.h
     wx/mac/gauge.h
-    wx/mac/glcanvas.h
     wx/mac/gsockmac.h
     wx/mac/helpxxxx.h
     wx/mac/icon.h
@@ -3104,7 +3102,8 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
 <!--                             OpenGL canvas                              -->
 <!-- ====================================================================== -->
 
-<set var="OPENGL_SRC" hints="files">
+<set var="OPENGL_SRC_PLATFORM" hints="files">
+    src/common/glcmn.cpp
     <if cond="TOOLKIT=='MAC'">src/mac/carbon/glcanvas.cpp</if>
     <if cond="TOOLKIT=='COCOA'">src/cocoa/glcanvas.mm</if>
     <if cond="TOOLKIT=='GTK' and TOOLKIT_VERSION=='2'">src/gtk/glcanvas.cpp</if>
@@ -3116,8 +3115,13 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     <if cond="TOOLKIT=='PM'">src/os2/glcanvas.cpp</if>
 </set>
 
-<set var="OPENGL_HDR" hints="files">
-    <if cond="TOOLKIT=='MAC'">wx/mac/carbon/glcanvas.h</if>
+<set var="OPENGL_SRC" hints="files">
+    src/common/glcmn.cpp
+    $(OPENGL_SRC_PLATFORM)
+</set>
+
+<set var="OPENGL_HDR_PLATFORM" hints="files">
+    <if cond="TOOLKIT=='MAC'">wx/mac/glcanvas.h wx/mac/carbon/glcanvas.h</if>
     <if cond="TOOLKIT=='COCOA'">wx/cocoa/glcanvas.h</if>
     <if cond="TOOLKIT=='GTK' and TOOLKIT_VERSION=='2'">wx/gtk/glcanvas.h</if>
     <if cond="TOOLKIT=='GTK' and TOOLKIT_VERSION==''">wx/gtk1/glcanvas.h</if>
@@ -3125,9 +3129,12 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
     <if cond="TOOLKIT=='WINCE'">wx/msw/glcanvas.h</if>
     <if cond="TOOLKIT=='MOTIF'">wx/x11/glcanvas.h</if>
     <if cond="TOOLKIT=='X11'">wx/x11/glcanvas.h</if>
-    <if cond="TOOLKIT=='PM'">wx/os2/glcanvas.h</if>
 </set>
 
+<set var="OPENGL_HDR" hints="files">
+    wx/glcanvas.h
+    $(OPENGL_HDR_PLATFORM)
+</set>
 
 
 <!-- ====================================================================== -->
@@ -3458,7 +3465,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
             $(GUI_CORE_HEADERS)
             $(ADVANCED_HDR) $(MEDIA_HDR) $(HTML_HDR)
             $(OPENGL_HDR) $(QA_HDR) $(DBGRID_HDR) $(XRC_HDR) $(AUI_HDR) $(RICHTEXT_HDR)
-	    $(STC_HDR)
+            $(STC_HDR)
         </if>
     </set>
 
diff --git a/build/msw/makefile.bcc b/build/msw/makefile.bcc
index 0ac11e1532..91a21ba27a 100644
--- a/build/msw/makefile.bcc
+++ b/build/msw/makefile.bcc
@@ -1281,6 +1281,7 @@ GLDLL_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
 	-H=$(OBJS)\wxprec_gldll.csm $(CPPFLAGS) $(CXXFLAGS)
 GLDLL_OBJECTS =  \
 	$(OBJS)\gldll_dummy.obj \
+	$(OBJS)\gldll_glcmn.obj \
 	$(OBJS)\gldll_glcanvas.obj
 GLLIB_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
 	$(__OPTIMIZEFLAG) $(__THREADSFLAG) -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
@@ -1292,6 +1293,7 @@ GLLIB_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
 	$(CXXFLAGS)
 GLLIB_OBJECTS =  \
 	$(OBJS)\gllib_dummy.obj \
+	$(OBJS)\gllib_glcmn.obj \
 	$(OBJS)\gllib_glcanvas.obj
 BUILD_CFG_FILE = $(SETUPHDIR)\build.cfg
 
@@ -13425,12 +13427,18 @@ $(OBJS)\gldll_dummy.obj: ..\..\src\common\dummy.cpp
 $(OBJS)\gldll_version.res: ..\..\src\msw\version.rc
 	brcc32 -32 -r -fo$@ -i$(BCCDIR)\include    -d__WXMSW__ $(__WXUNIV_DEFINE_p_62) $(__DEBUG_DEFINE_p_61) $(__EXCEPTIONS_DEFINE_p_61) $(__RTTI_DEFINE_p_61) $(__THREAD_DEFINE_p_61) $(__UNICODE_DEFINE_p_62) $(__MSLU_DEFINE_p_61) $(__GFXCTX_DEFINE_p_61) -i$(SETUPHDIR) -i..\..\include -dWXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_VERSION_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl_bcc$(VENDORTAG) -i..\..\src\tiff -i..\..\src\jpeg -i..\..\src\png -i..\..\src\zlib  -i..\..\src\regex -i..\..\src\expat\lib -dWXUSINGDLL -dWXMAKINGDLL_GL $**
 
+$(OBJS)\gldll_glcmn.obj: ..\..\src\common\glcmn.cpp
+	$(CXX) -q -c -P -o$@ $(GLDLL_CXXFLAGS) $**
+
 $(OBJS)\gldll_glcanvas.obj: ..\..\src\msw\glcanvas.cpp
 	$(CXX) -q -c -P -o$@ $(GLDLL_CXXFLAGS) $**
 
 $(OBJS)\gllib_dummy.obj: ..\..\src\common\dummy.cpp
 	$(CXX) -q -c -P -o$@ $(GLLIB_CXXFLAGS) -H $**
 
+$(OBJS)\gllib_glcmn.obj: ..\..\src\common\glcmn.cpp
+	$(CXX) -q -c -P -o$@ $(GLLIB_CXXFLAGS) $**
+
 $(OBJS)\gllib_glcanvas.obj: ..\..\src\msw\glcanvas.cpp
 	$(CXX) -q -c -P -o$@ $(GLLIB_CXXFLAGS) $**
 
diff --git a/build/msw/makefile.gcc b/build/msw/makefile.gcc
index d0a5857217..91a9f41eeb 100644
--- a/build/msw/makefile.gcc
+++ b/build/msw/makefile.gcc
@@ -1283,6 +1283,7 @@ GLDLL_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) $(GCCFLAGS) \
 GLDLL_OBJECTS =  \
 	$(OBJS)\gldll_dummy.o \
 	$(OBJS)\gldll_version_rc.o \
+	$(OBJS)\gldll_glcmn.o \
 	$(OBJS)\gldll_glcanvas.o
 GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) $(GCCFLAGS) \
 	-DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) \
@@ -1294,6 +1295,7 @@ GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) $(GCCFLAGS) \
 	$(CXXFLAGS)
 GLLIB_OBJECTS =  \
 	$(OBJS)\gllib_dummy.o \
+	$(OBJS)\gllib_glcmn.o \
 	$(OBJS)\gllib_glcanvas.o
 BUILD_CFG_FILE = $(SETUPHDIR)\build.cfg
 
@@ -13986,12 +13988,18 @@ $(OBJS)\gldll_dummy.o: ../../src/common/dummy.cpp
 $(OBJS)\gldll_version_rc.o: ../../src/msw/version.rc
 	windres --use-temp-file -i$< -o$@    --define __WXMSW__ $(__WXUNIV_DEFINE_p_62) $(__DEBUG_DEFINE_p_61) $(__EXCEPTIONS_DEFINE_p_61) $(__RTTI_DEFINE_p_61) $(__THREAD_DEFINE_p_61) $(__UNICODE_DEFINE_p_62) $(__MSLU_DEFINE_p_61) $(__GFXCTX_DEFINE_p_61) --include-dir $(SETUPHDIR) --include-dir ..\../include --define WXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_VERSION_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl_gcc$(VENDORTAG) --include-dir ..\../src/tiff --include-dir ..\../src/jpeg --include-dir ..\../src/png --include-dir ..\../src/zlib  --include-dir ..\../src/regex --include-dir ..\../src/expat/lib --define WXUSINGDLL --define WXMAKINGDLL_GL
 
+$(OBJS)\gldll_glcmn.o: ../../src/common/glcmn.cpp
+	$(CXX) -c -o $@ $(GLDLL_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\gldll_glcanvas.o: ../../src/msw/glcanvas.cpp
 	$(CXX) -c -o $@ $(GLDLL_CXXFLAGS) $(CPPDEPS) $<
 
 $(OBJS)\gllib_dummy.o: ../../src/common/dummy.cpp
 	$(CXX) -c -o $@ $(GLLIB_CXXFLAGS) $(CPPDEPS) $<
 
+$(OBJS)\gllib_glcmn.o: ../../src/common/glcmn.cpp
+	$(CXX) -c -o $@ $(GLLIB_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\gllib_glcanvas.o: ../../src/msw/glcanvas.cpp
 	$(CXX) -c -o $@ $(GLLIB_CXXFLAGS) $(CPPDEPS) $<
 
diff --git a/build/msw/makefile.vc b/build/msw/makefile.vc
index 823b4a85b6..251c03ef0a 100644
--- a/build/msw/makefile.vc
+++ b/build/msw/makefile.vc
@@ -1385,6 +1385,7 @@ GLDLL_CXXFLAGS = /M$(__RUNTIME_LIBS_505)$(__DEBUGRUNTIME) /DWIN32 \
 GLDLL_OBJECTS =  \
 	$(OBJS)\gldll_dummy.obj \
 	$(OBJS)\gldll_version.res \
+	$(OBJS)\gldll_glcmn.obj \
 	$(OBJS)\gldll_glcanvas.obj
 GLLIB_CXXFLAGS = /M$(__RUNTIME_LIBS_518)$(__DEBUGRUNTIME) /DWIN32 \
 	$(__DEBUGINFO) \
@@ -1398,6 +1399,7 @@ GLLIB_CXXFLAGS = /M$(__RUNTIME_LIBS_518)$(__DEBUGRUNTIME) /DWIN32 \
 	/Yu"wx/wxprec.h" /Fp"$(OBJS)\wxprec_gllib.pch" $(CPPFLAGS) $(CXXFLAGS)
 GLLIB_OBJECTS =  \
 	$(OBJS)\gllib_dummy.obj \
+	$(OBJS)\gllib_glcmn.obj \
 	$(OBJS)\gllib_glcanvas.obj
 BUILD_CFG_FILE = $(SETUPHDIR)\build.cfg
 
@@ -4503,7 +4505,7 @@ clean:
 	-if exist $(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl.lib del $(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl.lib
 	cd ..\..\samples
 	$(MAKE) -f makefile.vc $(MAKEARGS) clean
-	cd $(MAKEDIR)
+	cd "$(MAKEDIR)"
 
 setup_h: $(SETUPHDIR)\wx ..\..\include\wx\$(__SETUP_H_SUBDIR_FILENAMES)\setup.h $(SETUPHDIR)\wx\setup.h $(SETUPHDIR)\wx\msw\rcdefs.h
 
@@ -4856,7 +4858,7 @@ wxgl: $(____wxgl_namedll_DEP) $(____wxgl_namelib_DEP)
 sub_samples: 
 	cd ..\..\samples
 	$(MAKE) -f makefile.vc $(MAKEARGS) all
-	cd $(MAKEDIR)
+	cd "$(MAKEDIR)"
 
 $(LIBDIRNAME): 
 	if not exist $(LIBDIRNAME) mkdir $(LIBDIRNAME)
@@ -13777,12 +13779,18 @@ $(OBJS)\gldll_dummy.obj: ..\..\src\common\dummy.cpp
 $(OBJS)\gldll_version.res: ..\..\src\msw\version.rc
 	rc /fo$@  /d WIN32 $(____DEBUGRUNTIME_4) $(__NO_VC_CRTDBG_p_68)  /d __WXMSW__ $(__WXUNIV_DEFINE_p_62) $(__DEBUG_DEFINE_p_61) $(__EXCEPTIONS_DEFINE_p_61) $(__RTTI_DEFINE_p_61) $(__THREAD_DEFINE_p_61) $(__UNICODE_DEFINE_p_62) $(__MSLU_DEFINE_p_61) $(__GFXCTX_DEFINE_p_61) /i $(SETUPHDIR) /i ..\..\include /d WXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_VERSION_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl_vc$(VENDORTAG) /i ..\..\src\tiff /i ..\..\src\jpeg /i ..\..\src\png /i ..\..\src\zlib  /i ..\..\src\regex /i ..\..\src\expat\lib /d WXUSINGDLL /d WXMAKINGDLL_GL $**
 
+$(OBJS)\gldll_glcmn.obj: ..\..\src\common\glcmn.cpp
+	$(CXX) /c /nologo /TP /Fo$@ $(GLDLL_CXXFLAGS) $**
+
 $(OBJS)\gldll_glcanvas.obj: ..\..\src\msw\glcanvas.cpp
 	$(CXX) /c /nologo /TP /Fo$@ $(GLDLL_CXXFLAGS) $**
 
 $(OBJS)\gllib_dummy.obj: ..\..\src\common\dummy.cpp
 	$(CXX) /c /nologo /TP /Fo$@ $(GLLIB_CXXFLAGS) /Ycwx/wxprec.h $**
 
+$(OBJS)\gllib_glcmn.obj: ..\..\src\common\glcmn.cpp
+	$(CXX) /c /nologo /TP /Fo$@ $(GLLIB_CXXFLAGS) $**
+
 $(OBJS)\gllib_glcanvas.obj: ..\..\src\msw\glcanvas.cpp
 	$(CXX) /c /nologo /TP /Fo$@ $(GLLIB_CXXFLAGS) $**
 
diff --git a/build/msw/makefile.wat b/build/msw/makefile.wat
index 41b89c1b00..ee3b489cd4 100644
--- a/build/msw/makefile.wat
+++ b/build/msw/makefile.wat
@@ -4238,6 +4238,7 @@ GLDLL_CXXFLAGS = -bd $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
 	$(CXXFLAGS)
 GLDLL_OBJECTS =  &
 	$(OBJS)\gldll_dummy.obj &
+	$(OBJS)\gldll_glcmn.obj &
 	$(OBJS)\gldll_glcanvas.obj
 GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
 	$(__RUNTIME_LIBS) -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) &
@@ -4249,6 +4250,7 @@ GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
 	$(__EXCEPTIONSFLAG) $(CPPFLAGS) $(CXXFLAGS)
 GLLIB_OBJECTS =  &
 	$(OBJS)\gllib_dummy.obj &
+	$(OBJS)\gllib_glcmn.obj &
 	$(OBJS)\gllib_glcanvas.obj
 BUILD_CFG_FILE = $(SETUPHDIR)\build.cfg
 
@@ -14257,12 +14259,18 @@ $(OBJS)\gldll_dummy.obj :  .AUTODEPEND ..\..\src\common\dummy.cpp
 $(OBJS)\gldll_version.res :  .AUTODEPEND ..\..\src\msw\version.rc
 	wrc -q -ad -bt=nt -r -fo=$^@    -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) $(__UNICODE_DEFINE_p)  $(__GFXCTX_DEFINE_p) -i=$(SETUPHDIR) -i=..\..\include -dWXDLLNAME=wx$(PORTNAME)$(WXUNIVNAME)$(WX_VERSION_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl_wat$(VENDORTAG) -i=..\..\src\tiff -i=..\..\src\jpeg -i=..\..\src\png -i=..\..\src\zlib  -i=..\..\src\regex -i=..\..\src\expat\lib -dWXUSINGDLL -dWXMAKINGDLL_GL $<
 
+$(OBJS)\gldll_glcmn.obj :  .AUTODEPEND ..\..\src\common\glcmn.cpp
+	$(CXX) -bt=nt -zq -fo=$^@ $(GLDLL_CXXFLAGS) $<
+
 $(OBJS)\gldll_glcanvas.obj :  .AUTODEPEND ..\..\src\msw\glcanvas.cpp
 	$(CXX) -bt=nt -zq -fo=$^@ $(GLDLL_CXXFLAGS) $<
 
 $(OBJS)\gllib_dummy.obj :  .AUTODEPEND ..\..\src\common\dummy.cpp
 	$(CXX) -bt=nt -zq -fo=$^@ $(GLLIB_CXXFLAGS) $<
 
+$(OBJS)\gllib_glcmn.obj :  .AUTODEPEND ..\..\src\common\glcmn.cpp
+	$(CXX) -bt=nt -zq -fo=$^@ $(GLLIB_CXXFLAGS) $<
+
 $(OBJS)\gllib_glcanvas.obj :  .AUTODEPEND ..\..\src\msw\glcanvas.cpp
 	$(CXX) -bt=nt -zq -fo=$^@ $(GLLIB_CXXFLAGS) $<
 
diff --git a/build/msw/wx_gl.dsp b/build/msw/wx_gl.dsp
index 154243dfeb..15161316ef 100644
--- a/build/msw/wx_gl.dsp
+++ b/build/msw/wx_gl.dsp
@@ -456,6 +456,10 @@ SOURCE=..\..\src\common\dummy.cpp
 # ADD BASE CPP /Yc"wx/wxprec.h"
 # ADD CPP /Yc"wx/wxprec.h"
 # End Source File
+# Begin Source File
+
+SOURCE=..\..\src\common\glcmn.cpp
+# End Source File
 # End Group
 # Begin Group "MSW Sources"
 
@@ -977,6 +981,14 @@ InputPath=..\..\include\wx\msw\genrcdefs.h
 SOURCE=..\..\include\wx\msw\glcanvas.h
 # End Source File
 # End Group
+# Begin Group "Common Headers"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\include\wx\glcanvas.h
+# End Source File
+# End Group
 # End Target
 # End Project
 
diff --git a/docs/latex/wx/glcanvas.tex b/docs/latex/wx/glcanvas.tex
index 2f5311306f..0df49efa82 100644
--- a/docs/latex/wx/glcanvas.tex
+++ b/docs/latex/wx/glcanvas.tex
@@ -1,29 +1,34 @@
 \section{\class{wxGLCanvas}}\label{wxglcanvas}
 
-wxGLCanvas is a class for displaying OpenGL graphics.
-
-There are two ways to use this class:
-
-For the older (before wx 2.7.x) and simpler method, create a wxGLCanvas window using one of the three
-constructors that implicitly create a rendering context, call \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrent} 
-to direct normal OpenGL commands to the window, and then call \helpref{wxGLCanvas::SwapBuffers}{wxglcanvasswapbuffers} 
-to show the OpenGL buffer on the window.
-
-For the newer (wx 2.7.x+) method, create a wxGLCanvas window using the constructor that does \emph{not} create an implicit rendering context,
-create an explicit instance of a \helpref{wxGLContext}{wxglcontext} that is initialized with the wxGLCanvas yourself,
-then use either \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrentrc} with the instance of the \helpref{wxGLContext}{wxglcontext}
-or \helpref{wxGLContext::SetCurrent}{wxglcontextsetcurrent} with the instance of the \helpref{wxGLCanvas}{wxglcanvas}
-to bind the OpenGL state that is represented by the rendering context to the canvas, and then call
-\helpref{wxGLCanvas::SwapBuffers}{wxglcanvasswapbuffers} to swap the buffers of the OpenGL canvas and thus show your current output.
+wxGLCanvas is a class for displaying OpenGL graphics. It is always used in
+conjunction with \helpref{wxGLContext}{wxglcontext} as the context can only be
+be made current (i.e. active for the OpenGL commands) when it is associated to
+a wxGLCanvas.
+
+More precisely, you first need to create a wxGLCanvas window and then create an
+instance of a \helpref{wxGLContext}{wxglcontext} that is initialized with this
+wxGLCanvas and then later use either \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrentrc} 
+with the instance of the \helpref{wxGLContext}{wxglcontext} or 
+\helpref{wxGLContext::SetCurrent}{wxglcontextsetcurrent} with the instance of
+the \helpref{wxGLCanvas}{wxglcanvas} (which might be not the same as was used
+for the creation of the context) to bind the OpenGL state that is represented
+by the rendering context to the canvas, and then finally call 
+\helpref{wxGLCanvas::SwapBuffers}{wxglcanvasswapbuffers} to swap the buffers of
+the OpenGL canvas and thus show your current output.
+
+Notice that previous versions of wxWidgets used to implicitly create a
+wxGLContext inside wxGLCanvas itself. This is still supported in the current
+version but is deprecated now and will be removed in the future, please update
+your code to create the rendering contexts explicitly.
 
 To set up the attributes for the canvas (number of bits for the depth buffer,
 number of bits for the stencil buffer and so on) you should set up the correct values of
 the {\it attribList} parameter. The values that should be set up and their meanings will be described below.
 
-To switch on wxGLCanvas support on under Windows, edit setup.h and set
-{\tt wxUSE\_GLCANVAS} to $1$. You may also need to have to add
-{\tt opengl32.lib} to the list of libraries your program is linked with. On
-Unix, pass \verb=--with-opengl= to configure to compile using OpenGL or Mesa.
+Notice that OpenGL is not enabled by default. To switch it on, you need to edit
+setup.h under Windows and set {\tt wxUSE\_GLCANVAS} to $1$ (you may also need
+to have to add {\tt opengl32.lib} and {\tt glu32.lib} to the list of libraries
+your program is linked with). On Unix, pass \verb=--with-opengl= to configure.
 
 \wxheading{Derived from}
 
@@ -75,46 +80,19 @@ alpha channel, and accum buffer. Other implementations may support them.
 
 \membersection{wxGLCanvas::wxGLCanvas}\label{wxglcanvasconstr}
 
-\func{void}{wxGLCanvas}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id = -1},
- \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},
- \param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"},
- \param{int*}{ attribList = 0}, \param{const wxPalette\&}{ palette = wxNullPalette}}
-
-\func{void}{wxGLCanvas}{\param{wxWindow* }{parent}, \param{wxGLContext* }{sharedContext}, \param{wxWindowID}{ id = -1},
- \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},
- \param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"},
- \param{int*}{ attribList = 0}, \param{const wxPalette\&}{ palette = wxNullPalette}}
-
-\func{void}{wxGLCanvas}{\param{wxWindow* }{parent}, \param{wxGLCanvas* }{sharedCanvas}, \param{wxWindowID}{ id = -1},
- \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},
- \param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"},
- \param{int*}{ attribList = 0}, \param{const wxPalette\&}{ palette = wxNullPalette}}
-
 \func{void}{wxGLCanvas}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id = wxID\_ANY},
- \param{int*}{ attribList = 0},
+ \param{const int*}{ attribList = NULL},
  \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},
  \param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"},
  \param{const wxPalette\&}{ palette = wxNullPalette}}
 
-Constructors.
-The first three constructors implicitly create an instance of \helpref{wxGLContext}{wxglcontext}.
-The fourth constructur is identical to the first, except for the fact that it does \emph{not}
-create such an implicit rendering context, which means that you have to create an explicit instance
-of \helpref{wxGLContext}{wxglcontext} yourself (highly recommended for future compatibility with wxWidgets
-and the flexibility of your own program!).
+Creates a window with the given parameters. Notice that you need to create and
+use a \helpref{wxGLContext}{wxglcontext} to output to this window.
 
-Note that if you used one of the first three constructors, \helpref{wxGLCanvas::GetContext}{wxglcanvasgetcontext}
-returns the pointer to the implicitly created instance, and the \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrent}
-method \emph{without} the parameter should be used.
-If however you used the fourth constructor, \helpref{wxGLCanvas::GetContext}{wxglcanvasgetcontext} always returns NULL
-and the \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrentrc} method \emph{with} the parameter must be used!
+If \arg{attribList} is not specified, double buffered RGBA mode is used.
 
 \docparam{parent}{Pointer to a parent window.}
 
-\docparam{sharedContext}{Context to share object resources with.}
-
-%TODO document sharedCanvas meaning
-
 \docparam{id}{Window identifier. If -1, will automatically create an identifier.}
 
 \docparam{pos}{Window position. wxDefaultPosition is (-1, -1) which indicates that wxWidgets
@@ -127,64 +105,43 @@ generate a default size for the window. If no suitable size can be found, the wi
 
 \docparam{name}{Window name.}
 
-\docparam{attribList}{Array of int. With this parameter you can set the device context attributes associated to this window.
+\docparam{attribList}{Array of integers. With this parameter you can set the device context attributes associated to this window.
 This array is zero-terminated: it should be set up with constants described in the table above.
 If a constant should be followed by a value, put it in the next array position.
 For example, the WX\_GL\_DEPTH\_SIZE should be followed by the value that indicates the number of
 bits for the depth buffer, so:}
 
 \begin{verbatim}
-attribList[index]= WX_GL_DEPTH_SIZE;
-attribList[index+1]=32;
+attribList[index] = WX_GL_DEPTH_SIZE;
+attribList[index+1] = 32;
 and so on.
 \end{verbatim}
 
-\docparam{palette}{If the window has the palette, it should by pass this value.
-Note: palette and WX\_GL\_RGBA are mutually exclusive.}
-
-
-\membersection{wxGLCanvas::GetContext}\label{wxglcanvasgetcontext}
-
-\func{wxGLContext*}{GetContext}{\void}
-
-Obtains the context that is associated with this canvas if one was implicitly created (by use of one of the first three constructors).
-Always returns NULL if the canvas was constructed with the fourth constructor.
+\docparam{palette}{Palette for indexed colour (i.e. non WX\_GL\_RGBA) mode.
+Ignored under most platforms.}
 
 
 \membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrent}
 
-\func{void}{SetCurrent}{\void}
-
-If this canvas was created with one of the first three constructors,
-a call to this method makes the implicit rendering context of this canvas current with this canvas,
-so that subsequent OpenGL calls modify the OpenGL state of the implicit rendering context.
-
-If this canvas was created with the fourth constructor, this method should not be called
-(use the SetCurrent method below with the parameter instead)!
-
-Note that this function may only be called \emph{after} the window has been shown.
-
-
-\membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrentrc}
-
-\func{void}{SetCurrent}{ \param{const wxGLContext&}{ RC} }
+\func{void}{SetCurrent}{ \param{const wxGLContext&}{ context} }
 
-If this canvas was created with one of the first three constructors,
-this method should not be called (use the SetCurrent above without the parameter instead)!
+Makes the OpenGL state that is represented by the OpenGL rendering context
+\arg{context} current, i.e. it will be used by all subsequent OpenGL calls.
 
-If this canvas was created with the fourth constructor, a call to this method
-makes the OpenGL state that is represented by the OpenGL rendering context { \it RC } current with this canvas,
-and if { \it win } is an object of type wxGLCanvas, the statements { \it win.SetCurrent(RC); } and { \it RC.SetCurrent(win); } are equivalent,
-see \helpref{wxGLContext::SetCurrent}{wxglcontextsetcurrent}.
+This is equivalent to \helpref{wxGLContext::SetCurrent}{wxglcontextsetcurrent} 
+called with this window as parameter.
 
-Note that this function may only be called \emph{after} the window has been shown.
+Note that this function may only be called when the window is shown on screen,
+in particular it can't usually be called from the constructor as the window
+isn't yet shown at this moment.
 
 
 \membersection{wxGLCanvas::SetColour}\label{wxglcanvassetcolour}
 
 \func{void}{SetColour}{\param{const char*}{ colour}}
 
-Sets the current colour for this window, using the wxWidgets colour database to find a named colour.
+Sets the current colour for this window (using \texttt{glcolor3f()}), using the
+wxWidgets colour database to find a named colour.
 
 
 \membersection{wxGLCanvas::SwapBuffers}\label{wxglcanvasswapbuffers}
diff --git a/include/wx/cocoa/glcanvas.h b/include/wx/cocoa/glcanvas.h
index 18b8a5fd75..c36bf9f36d 100644
--- a/include/wx/cocoa/glcanvas.h
+++ b/include/wx/cocoa/glcanvas.h
@@ -20,84 +20,62 @@
 
 class WXDLLIMPEXP_GL wxGLCanvas;
 DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLContext);
-//DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLView);
+DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLView);
 
 // ========================================================================
 // wxGLContext
 // ========================================================================
-class WXDLLIMPEXP_GL wxGLContext: public wxObject
+
+class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
 {
 public:
-    wxGLContext(bool isRGB, wxGLCanvas *win, const wxPalette& palette = wxNullPalette);
-
-    wxGLContext( bool isRGB, wxGLCanvas *win,
-        const wxPalette& WXUNUSED(palette),
-        const wxGLContext *other /* for sharing display lists */ );
+    wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
 
     virtual ~wxGLContext();
 
+    virtual void SetCurrent(const wxGLCanvas& win) const;
 
-    void SetCurrent();
-
-    void SetColour(const wxChar *colour);
-
-    void SwapBuffers();
+    WX_NSOpenGLContext GetNSOpenGLContext() const
+        { return m_cocoaNSOpenGLContext; }
 
-
-    inline wxWindow* GetWindow() const
-    {   return m_window; }
-
-    inline WX_NSOpenGLContext GetNSOpenGLContext() const
-    {   return m_cocoaNSOpenGLContext; }
-
-public:
+private:
     WX_NSOpenGLContext m_cocoaNSOpenGLContext;
-    wxWindow*        m_window;
 };
 
-
-
 // ========================================================================
 // wxGLCanvas
 // ========================================================================
-class WXDLLIMPEXP_GL wxGLCanvas: public wxWindow// , protected wxCocoaNSOpenGLView
+
+class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasBase
+                             // , protected wxCocoaNSOpenGLView
 {
     DECLARE_DYNAMIC_CLASS(wxGLCanvas)
-    DECLARE_EVENT_TABLE()
 //    WX_DECLARE_COCOA_OWNER(NSOpenGLView,NSView,NSView)
 // ------------------------------------------------------------------------
 // initialization
 // ------------------------------------------------------------------------
 public:
-    wxGLCanvas()
-    :   m_glContext(NULL)
-    { }
-    wxGLCanvas(wxWindow *parent, wxWindowID winid = wxID_ANY,
-            const wxPoint& pos = wxDefaultPosition,
-            const wxSize& size = wxDefaultSize,
-            long style = 0, const wxString& name = wxGLCanvasName,
-            int *attribList = NULL, const wxPalette& palette = wxNullPalette);
-
     wxGLCanvas(wxWindow *parent,
-            const wxGLContext *shared = NULL,
-            wxWindowID winid = wxID_ANY,
-            const wxPoint& pos = wxDefaultPosition,
-            const wxSize& size = wxDefaultSize,
-            long style = 0, const wxString& name = wxGLCanvasName,
-            int *attribList = NULL, const wxPalette& palette = wxNullPalette);
+               wxWindowID id = wxID_ANY,
+               const int *attribList = NULL,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const wxPalette& palette = wxNullPalette)
+    {
+        Create(parent, id, pos, size, style, name, attribList, palette);
+    }
+
+    bool Create(wxWindow *parent,
+                wxWindowID id = wxID_ANY,
+                const wxPoint& pos = wxDefaultPosition,
+                const wxSize& size = wxDefaultSize,
+                long style = 0,
+                const wxString& name = wxGLCanvasName,
+                const int *attribList = NULL,
+                const wxPalette& palette = wxNullPalette);
 
-    wxGLCanvas(wxWindow *parent,
-            const wxGLCanvas *shared = NULL,
-            wxWindowID winid = wxID_ANY,
-            const wxPoint& pos = wxDefaultPosition,
-            const wxSize& size = wxDefaultSize,
-            long style = 0, const wxString& name = wxGLCanvasName,
-            int *attribList = NULL, const wxPalette& palette = wxNullPalette);
-
-    bool Create(wxWindow *parent, wxWindowID winid,
-            const wxPoint& pos = wxDefaultPosition,
-            const wxSize& size = wxDefaultSize,
-            long style = 0, const wxString& name = wxGLCanvasName);
     virtual ~wxGLCanvas();
 
 // ------------------------------------------------------------------------
@@ -110,16 +88,11 @@ protected:
 // Implementation
 // ------------------------------------------------------------------------
 public:
-    void SetCurrent();
-    void SwapBuffers();
+    virtual void SwapBuffers();
 
-    void OnSize(wxSizeEvent& event)
-    {}
-    inline wxGLContext* GetContext() const
-    {   return m_glContext; }
-protected:
-    wxGLContext *m_glContext;
-    wxPalette m_palette;
+
+    NSOpenGLView *GetNSOpenGLView() const
+        { return (NSOpenGLView *)m_cocoaNSView; }
 };
 
 #endif //ndef _WX_COCOA_GLCANVAS_H__
diff --git a/include/wx/glcanvas.h b/include/wx/glcanvas.h
index 4e3e4328b8..9e1c89ea8e 100644
--- a/include/wx/glcanvas.h
+++ b/include/wx/glcanvas.h
@@ -16,14 +16,20 @@
 
 #if wxUSE_GLCANVAS
 
-//---------------------------------------------------------------------------
-// Constants for attriblist
-//---------------------------------------------------------------------------
+#include "wx/app.h"
+#include "wx/palette.h"
+#include "wx/window.h"
 
-// The generic GL implementation doesn't support most of these options,
-// such as stereo, auxiliary buffers, alpha channel, and accum buffer.
-// Other implementations may actually support them.
+class WXDLLIMPEXP_GL wxGLCanvas;
+class WXDLLIMPEXP_GL wxGLContext;
+
+// ----------------------------------------------------------------------------
+// Constants for attributes list
+// ----------------------------------------------------------------------------
 
+// The generic OpenGL implementation doesn't support most of these options,
+// such as stereo, auxiliary buffers, alpha channel, and accumulator buffer.
+// Other implementations may actually support them.
 enum
 {
     WX_GL_RGBA=1,          /* use true color palette */
@@ -46,41 +52,139 @@ enum
 
 #define wxGLCanvasName _T("GLCanvas")
 
+// ----------------------------------------------------------------------------
+// wxGLContextBase: OpenGL rendering context
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_GL wxGLContextBase : public wxObject
+{
+public:
+    /*
+        The derived class should provide a ctor with this signature:
+
+        wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
+     */
+
+    // set this context as the current one
+    virtual void SetCurrent(const wxGLCanvas& win) const = 0;
+};
+
+// ----------------------------------------------------------------------------
+// wxGLCanvasBase: window which can be used for OpenGL rendering
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_GL wxGLCanvasBase : public wxWindow
+{
+public:
+    // default ctor doesn't initialize the window, use Create() later
+    wxGLCanvasBase()
+    {
+#if WXWIN_COMPATIBILITY_2_8
+        m_glContext = NULL;
+#endif
+    }
+
+    virtual ~wxGLCanvasBase();
+
+
+    /*
+       The derived class should provide a ctor with this signature:
+
+    wxGLCanvas(wxWindow *parent,
+               wxWindowID id = wxID_ANY,
+               int* attribList = 0,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const wxPalette& palette = wxNullPalette);
+     */
+
+    // operations
+    // ----------
+
+    // set the given context associated with this window as the current one
+    void SetCurrent(const wxGLContext& context) const;
+
+    // flush the back buffer (if we have it)
+    virtual void SwapBuffers() = 0;
+
+
+    // accessors
+    // ---------
+
+    const wxPalette *GetPalette() const { return &m_palette; }
+
+    // miscellaneous helper functions
+    // ------------------------------
+
+    // call glcolor() for the colour with the given name, return false if
+    // colour not found
+    bool SetColour(const wxChar *colour);
+
+
+
+    // deprecated methods using the implicit wxGLContext
+#if WXWIN_COMPATIBILITY_2_8
+    wxDEPRECATED( wxGLContext* GetContext() const );
+
+    wxDEPRECATED( void SetCurrent() );
+
+    wxDEPRECATED( void OnSize(wxSizeEvent& event) );
+#endif // WXWIN_COMPATIBILITY_2_8
+
+#ifdef __WXUNIVERSAL__
+    // resolve the conflict with wxWindowUniv::SetCurrent()
+    virtual bool SetCurrent(bool doit) { return wxWindow::SetCurrent(doit); };
+#endif
+
+protected:
+    // override this to implement SetColour() in GL_INDEX_MODE
+    // (currently only implemented in wxX11 and wxMotif ports)
+    virtual int GetColourIndex(const wxColour& WXUNUSED(col)) { return -1; }
+
+    // create default palette if we're not using RGBA mode
+    // (not supported in most ports)
+    virtual wxPalette CreateDefaultPalette() { return wxNullPalette; }
+
+
+    wxPalette m_palette;
+
+#if WXWIN_COMPATIBILITY_2_8
+    wxGLContext *m_glContext;
+#endif // WXWIN_COMPATIBILITY_2_8
+};
+
 #if defined(__WXMSW__)
-#include "wx/msw/glcanvas.h"
-#elif defined(__WXMOTIF__)
-#include "wx/x11/glcanvas.h"
+    #include "wx/msw/glcanvas.h"
+#elif defined(__WXMOTIF__) || defined(__WXX11__)
+    #include "wx/x11/glcanvas.h"
 #elif defined(__WXGTK20__)
-#include "wx/gtk/glcanvas.h"
+    #include "wx/gtk/glcanvas.h"
 #elif defined(__WXGTK__)
-#include "wx/gtk1/glcanvas.h"
-#elif defined(__WXX11__)
-#include "wx/x11/glcanvas.h"
+    #include "wx/gtk1/glcanvas.h"
 #elif defined(__WXMAC__)
-#include "wx/mac/glcanvas.h"
+    #include "wx/mac/glcanvas.h"
 #elif defined(__WXCOCOA__)
-#include "wx/cocoa/glcanvas.h"
+    #include "wx/cocoa/glcanvas.h"
 #else
-#error "wxGLCanvas not supported in this wxWidgets port"
+    #error "wxGLCanvas not supported in this wxWidgets port"
 #endif
 
-#include "wx/app.h"
 class WXDLLIMPEXP_GL wxGLApp : public wxApp
 {
 public:
     wxGLApp() : wxApp() { }
-    virtual ~wxGLApp();
 
     // use this in the constructor of the user-derived wxGLApp class to
     // determine if an OpenGL rendering context with these attributes
     // is available - returns true if so, false if not.
-    bool InitGLVisual(int *attribList);
+    bool InitGLVisual(const int *attribList);
 
 private:
     DECLARE_DYNAMIC_CLASS(wxGLApp)
 };
 
-#endif
-    // wxUSE_GLCANVAS
-#endif
-    // _WX_GLCANVAS_H_BASE_
+#endif // wxUSE_GLCANVAS
+
+#endif // _WX_GLCANVAS_H_BASE_
diff --git a/include/wx/gtk/glcanvas.h b/include/wx/gtk/glcanvas.h
index 3eb5964fd8..35ef0d4322 100644
--- a/include/wx/gtk/glcanvas.h
+++ b/include/wx/gtk/glcanvas.h
@@ -12,42 +12,29 @@
 #ifndef _WX_GLCANVAS_H_
 #define _WX_GLCANVAS_H_
 
-#include "wx/scrolwin.h"
-#include "wx/app.h"
-
-extern "C" {
-#include <GL/gl.h>
-#include <GL/glx.h>
-#include <GL/glu.h>
+extern "C"
+{
+    #include <GL/gl.h>
+    #include <GL/glx.h>
+    #include <GL/glu.h>
 }
 
-//---------------------------------------------------------------------------
-// classes
-//---------------------------------------------------------------------------
-
-class WXDLLEXPORT wxGLContext;
-class WXDLLEXPORT wxGLCanvas;
-
 //---------------------------------------------------------------------------
 // wxGLContext
 //---------------------------------------------------------------------------
 
 
-class WXDLLEXPORT wxGLContext: public wxObject
+class WXDLLEXPORT wxGLContext : public wxGLContextBase
 {
 public:
-    wxGLContext(wxWindow* win, const wxGLContext* other=NULL /* for sharing display lists */);
+    wxGLContext(wxWindow* win, const wxGLContext* other = NULL);
     virtual ~wxGLContext();
 
-public:
-    // The win wxGLCanvas needs not necessarily be the same as the wxGLCanvas with which this context was created!
-    void SetCurrent(const wxGLCanvas& win) const;
-
+    virtual void SetCurrent(const wxGLCanvas& win) const;
 
 private:
     GLXContext m_glContext;
 
-private:
     DECLARE_CLASS(wxGLContext)
 };
 
@@ -55,72 +42,89 @@ private:
 // wxGLCanvas
 //---------------------------------------------------------------------------
 
-class WXDLLEXPORT wxGLCanvas: public wxWindow
+class WXDLLEXPORT wxGLCanvas : public wxGLCanvasBase
 {
 public:
-    // This ctor is identical to the next, except for the fact that it
-    // doesn't create an implicit wxGLContext.
-    // The attribList parameter has been moved to avoid overload clashes.
-    wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
-        int *attribList = (int*) NULL,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxGLCanvasName,
-        const wxPalette& palette = wxNullPalette );
-
-   wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxGLCanvasName,
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
-
-   wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
-        wxWindowID id = -1,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxGLCanvasName,
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
-
-   wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared,
-        wxWindowID id = -1,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxGLCanvasName,
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
-
-   bool Create( wxWindow *parent,
-                const wxGLContext *shared = (wxGLContext*)NULL,
-                const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
-                wxWindowID id = -1,
+    wxGLCanvas(wxWindow *parent,
+               wxWindowID id = wxID_ANY,
+               const int *attribList = NULL,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const wxPalette& palette = wxNullPalette);
+
+    bool Create(wxWindow *parent,
+                wxWindowID id = wxID_ANY,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = 0,
                 const wxString& name = wxGLCanvasName,
-                int *attribList = (int*) NULL,
-                const wxPalette& palette = wxNullPalette );
+                const int *attribList = NULL,
+                const wxPalette& palette = wxNullPalette);
 
-   virtual ~wxGLCanvas();
+    virtual ~wxGLCanvas();
 
-   void SetCurrent(const wxGLContext& RC) const;
-   void SetCurrent();
-   void SetColour(const wxChar *colour);
-   void SwapBuffers();
 
-   void OnSize(wxSizeEvent& event);
+    // implement wxGLCanvasBase methods
+    // --------------------------------
 
-   void OnInternalIdle();
+    virtual void SwapBuffers();
 
-   inline wxGLContext* GetContext() const { return m_glContext; }
 
- // implementation
+    // GTK-specific helpers
+    // --------------------
+
+    // return GLX version: 13 means 1.3
+    static int GetGLXVersion();
+
+
+    // deprecated methods
+    // ------------------
+
+#if WXWIN_COMPATIBILITY_2_8
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               const wxGLContext *shared,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               const wxGLCanvas *shared,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    // called from "realized" callback to create the implicit context if needed
+    void GTKInitImplicitContext();
+#endif // WXWIN_COMPATIBILITY_2_8
+
+    // implementation from now on
+    void OnInternalIdle();
 
-    wxGLContext      *m_glContext,
-                     *m_sharedContext;
-    wxGLCanvas       *m_sharedContextOf;
-    const bool        m_createImplicitContext;
     void             *m_vi; // actually an XVisualInfo*
     GLXFBConfig      *m_fbc;
     bool              m_canFreeVi;
@@ -128,23 +132,23 @@ public:
     GtkWidget        *m_glWidget;
     bool              m_exposed;
 
+#if WXWIN_COMPATIBILITY_2_8
+    wxGLContext      *m_sharedContext;
+    wxGLCanvas       *m_sharedContextOf;
+    const bool        m_createImplicitContext;
+#endif // WXWIN_COMPATIBILITY_2_8
+
     // returns an XVisualInfo* based on desired GL attributes;
     // returns NULL if an appropriate visual is not found. The
     // caller is reponsible for using XFree() to deallocate
     // the returned structure.
-    static void* ChooseGLVisual(int *attribList);
-    static void* ChooseGLFBC(int *attribList);
-    static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList );
+    static void* ChooseGLVisual(const int *attribList);
+    static void* ChooseGLFBC(const int *attribList);
+    static void GetGLAttribListFromWX(const int *wx_attribList, int *gl_attribList );
 
-    static void QueryGLXVersion();
-    static int GetGLXVersion();
-    static int m_glxVersion;
-    
 private:
-    DECLARE_EVENT_TABLE()
     DECLARE_CLASS(wxGLCanvas)
 };
 
-#endif
-    // _WX_GLCANVAS_H_
+#endif // _WX_GLCANVAS_H_
 
diff --git a/include/wx/gtk1/glcanvas.h b/include/wx/gtk1/glcanvas.h
index 0ba6b3ef66..c93bbc5706 100644
--- a/include/wx/gtk1/glcanvas.h
+++ b/include/wx/gtk1/glcanvas.h
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        wx/gtk1/glcanvas.h
+// Name:        glcanvas.h
 // Purpose:     wxGLCanvas, for using OpenGL/Mesa with wxWidgets and GTK
 // Author:      Robert Roebling
 // Modified by:
@@ -12,148 +12,143 @@
 #ifndef _WX_GLCANVAS_H_
 #define _WX_GLCANVAS_H_
 
-#include "wx/scrolwin.h"
-#include "wx/app.h"
-
-extern "C" {
-#include <GL/gl.h>
-#include <GL/glx.h>
-#include <GL/glu.h>
+extern "C"
+{
+    #include <GL/gl.h>
+    #include <GL/glx.h>
+    #include <GL/glu.h>
 }
 
-//---------------------------------------------------------------------------
-// classes
-//---------------------------------------------------------------------------
-
-class WXDLLEXPORT wxGLContext;
-class WXDLLEXPORT wxGLCanvas;
-
 //---------------------------------------------------------------------------
 // wxGLContext
 //---------------------------------------------------------------------------
 
 
-class WXDLLEXPORT wxGLContext: public wxObject
+class WXDLLEXPORT wxGLContext : public wxGLContextBase
 {
 public:
-    wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette );
-    wxGLContext(
-               bool WXUNUSED(isRGB), wxWindow *win,
-               const wxPalette& WXUNUSED(palette),
-               const wxGLContext *other        /* for sharing display lists */
-    );
+    wxGLContext(wxWindow* win, const wxGLContext* other = NULL);
     virtual ~wxGLContext();
 
-    void SetCurrent();
-    void SetColour(const wxChar *colour);
-    void SwapBuffers();
-
-    void SetupPixelFormat();
-    void SetupPalette(const wxPalette& palette);
-    wxPalette CreateDefaultPalette();
-
-    inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; }
-    inline wxWindow* GetWindow() const { return m_window; }
-    inline GtkWidget* GetWidget() const { return m_widget; }
-    inline GLXContext GetContext() const { return m_glContext; }
-
-public:
-   GLXContext       m_glContext;
-
-   GtkWidget       *m_widget;
-   wxPalette        m_palette;
-   wxWindow*        m_window;
+    virtual void SetCurrent(const wxGLCanvas& win) const;
 
 private:
-  DECLARE_CLASS(wxGLContext)
+    GLXContext m_glContext;
+
+    DECLARE_CLASS(wxGLContext)
 };
 
 //---------------------------------------------------------------------------
 // wxGLCanvas
 //---------------------------------------------------------------------------
 
-class WXDLLEXPORT wxGLCanvas: public wxWindow
+class WXDLLEXPORT wxGLCanvas : public wxGLCanvasBase
 {
 public:
-   inline wxGLCanvas() {
-      m_glContext = (wxGLContext*) NULL;
-      m_sharedContext = (wxGLContext*) NULL;
-      m_glWidget = (GtkWidget*) NULL;
-      m_vi = (void*) NULL;
-      m_exposed = FALSE;
-   }
-   wxGLCanvas( wxWindow *parent, wxWindowID id = -1,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxGLCanvasName,
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
-   wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
-        wxWindowID id = -1,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxGLCanvasName,
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
-   wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared,
-        wxWindowID id = -1,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxGLCanvasName,
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
-
-   bool Create( wxWindow *parent,
-                const wxGLContext *shared = (wxGLContext*)NULL,
-                const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
-                wxWindowID id = -1,
+    wxGLCanvas(wxWindow *parent,
+               wxWindowID id = wxID_ANY,
+               const int *attribList = NULL,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const wxPalette& palette = wxNullPalette);
+
+    bool Create(wxWindow *parent,
+                wxWindowID id = wxID_ANY,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = 0,
                 const wxString& name = wxGLCanvasName,
-                int *attribList = (int*) NULL,
-                const wxPalette& palette = wxNullPalette );
+                const int *attribList = NULL,
+                const wxPalette& palette = wxNullPalette);
 
-   virtual ~wxGLCanvas();
+    virtual ~wxGLCanvas();
 
-   void SetCurrent();
-   void SetColour(const wxChar *colour);
-   void SwapBuffers();
 
-   void OnSize(wxSizeEvent& event);
+    // implement wxGLCanvasBase methods
+    // --------------------------------
 
-   void OnInternalIdle();
+    virtual void SwapBuffers();
 
-   inline wxGLContext* GetContext() const { return m_glContext; }
 
- // implementation
+    // GTK-specific helpers
+    // --------------------
+
+    // return GLX version: 13 means 1.3
+    static int GetGLXVersion();
+
+
+    // deprecated methods
+    // ------------------
+
+#if WXWIN_COMPATIBILITY_2_8
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               const wxGLContext *shared,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               const wxGLCanvas *shared,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    // called from "realized" callback to create the implicit context if needed
+    void GTKInitImplicitContext();
+#endif // WXWIN_COMPATIBILITY_2_8
+
+    // implementation from now on
+    virtual void OnInternalIdle();
+
 
-    wxGLContext      *m_glContext,
-                     *m_sharedContext;
-    wxGLCanvas       *m_sharedContextOf;
     void             *m_vi; // actually an XVisualInfo*
     GLXFBConfig      *m_fbc;
     bool              m_canFreeVi;
     bool              m_canFreeFBC;
     GtkWidget        *m_glWidget;
-    bool              m_exposed;
+
+#if WXWIN_COMPATIBILITY_2_8
+    wxGLContext      *m_sharedContext;
+    wxGLCanvas       *m_sharedContextOf;
+    const bool        m_createImplicitContext;
+#endif // WXWIN_COMPATIBILITY_2_8
 
     // returns an XVisualInfo* based on desired GL attributes;
     // returns NULL if an appropriate visual is not found. The
     // caller is reponsible for using XFree() to deallocate
     // the returned structure.
-    static void* ChooseGLVisual(int *attribList);
-    static void* ChooseGLFBC(int *attribList);
-    static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList );
+    static void* ChooseGLVisual(const int *attribList);
+    static void* ChooseGLFBC(const int *attribList);
+    static void GetGLAttribListFromWX(const int *wx_attribList, int *gl_attribList );
 
-    static void QueryGLXVersion();
-    static int GetGLXVersion();
-    static int m_glxVersion;
 private:
-    DECLARE_EVENT_TABLE()
     DECLARE_CLASS(wxGLCanvas)
 };
 
-#endif
-    // _WX_GLCANVAS_H_
+#endif // _WX_GLCANVAS_H_
 
diff --git a/include/wx/mac/carbon/glcanvas.h b/include/wx/mac/carbon/glcanvas.h
index bd80bfb7ff..00cf0e625a 100644
--- a/include/wx/mac/carbon/glcanvas.h
+++ b/include/wx/mac/carbon/glcanvas.h
@@ -12,14 +12,6 @@
 #ifndef _WX_GLCANVAS_H_
 #define _WX_GLCANVAS_H_
 
-#include "wx/defs.h"
-
-#if wxUSE_GLCANVAS
-
-#include "wx/palette.h"
-#include "wx/scrolwin.h"
-#include "wx/app.h"
-
 #ifdef __DARWIN__
 #  include <OpenGL/gl.h>
 #  include <AGL/agl.h>
@@ -28,79 +20,121 @@
 #  include <agl.h>
 #endif
 
-class WXDLLEXPORT wxGLCanvas;     /* forward reference */
-
-class WXDLLEXPORT wxGLContext: public wxObject
+class WXDLLEXPORT wxGLContext : public wxGLContextBase
 {
 public:
-   wxGLContext(AGLPixelFormat fmt, wxGLCanvas *win,
-               const wxPalette& WXUNUSED(palette),
-               const wxGLContext *other        /* for sharing display lists */
-    );
-   virtual ~wxGLContext();
+    wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
+    virtual ~wxGLContext();
 
-   void SetCurrent();
-   void Update();  // must be called after window drag/grows/zoom or clut change
-   void SetColour(const wxChar *colour);
-   void SwapBuffers();
+    virtual void SetCurrent(const wxGLCanvas& win) const;
 
+    // Mac-specific
+    AGLContext GetAGLContext() const { return m_aglContext; }
 
-   inline wxWindow* GetWindow() const { return m_window; }
-   inline AGLDrawable GetDrawable() const { return m_drawable; }
+private:
+    AGLContext m_aglContext;
 
-public:
-   AGLContext       m_glContext;
-   AGLDrawable      m_drawable;
-   wxWindow*        m_window;
+    DECLARE_NO_COPY_CLASS(wxGLContext)
 };
 
-class WXDLLEXPORT wxGLCanvas: public wxWindow
+class WXDLLEXPORT wxGLCanvas : public wxGLCanvasBase
 {
-   DECLARE_CLASS(wxGLCanvas)
- public:
-   wxGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize, long style = 0,
-        const wxString& name = wxT("GLCanvas") , int *attribList = 0, const wxPalette& palette = wxNullPalette);
-   wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
-        wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxT("GLCanvas"),
-          int *attribList = (int*) NULL, const wxPalette& palette = wxNullPalette );
-
-   wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID id = wxID_ANY,
-        const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
-        const wxString& name = wxT("GLCanvas"), int *attribList = 0, const wxPalette& palette = wxNullPalette );
-
-   virtual ~wxGLCanvas();
-
-   bool Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id,
-               const wxPoint& pos, const wxSize& size, long style, const wxString& name,
-           int *attribList, const wxPalette& palette);
-
-   void SetCurrent();
-   void SetColour(const wxChar *colour);
-   void SwapBuffers();
-   void UpdateContext();
-   void SetViewport();
-   virtual bool Show(bool show = true) ;
-
-   // Unlike some other platforms, this must get called if you override it.
-   // It sets the viewport correctly and update the context.
-   // You shouldn't call glViewport yourself either (use SetViewport if you must reset it.)
-   void OnSize(wxSizeEvent& event);
-
-   virtual void MacSuperChangedPosition() ;
-   virtual void MacTopLevelWindowChangedPosition() ;
-   virtual void         MacVisibilityChanged() ;
-
-   void MacUpdateView() ;
-
-   inline wxGLContext* GetContext() const { return m_glContext; }
+public:
+    wxGLCanvas(wxWindow *parent,
+               wxWindowID id = wxID_ANY,
+               const int *attribList = NULL,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const wxPalette& palette = wxNullPalette);
+
+    bool Create(wxWindow *parent,
+                wxWindowID id = wxID_ANY,
+                const wxPoint& pos = wxDefaultPosition,
+                const wxSize& size = wxDefaultSize,
+                long style = 0,
+                const wxString& name = wxGLCanvasName,
+                const int *attribList = NULL,
+                const wxPalette& palette = wxNullPalette);
+
+    virtual ~wxGLCanvas();
+
+    // implement wxGLCanvasBase methods
+    virtual void SwapBuffers();
+
+
+    // Mac-specific functions
+    // ----------------------
+
+    // return the pixel format used by this window
+    AGLPixelFormat GetAGLPixelFormat() const { return m_aglFormat; }
+
+    // update the view port of the current context to match this window
+    void SetViewport();
+
+
+    // deprecated methods
+    // ------------------
+
+#if WXWIN_COMPATIBILITY_2_8
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               const wxGLContext *shared,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               const wxGLCanvas *shared,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+#endif // WXWIN_COMPATIBILITY_2_8
+
+    // implementation-only from now on
+
+    // Unlike some other platforms, this must get called if you override it.
+    // It sets the viewport correctly and update the context.
+    // You shouldn't call glViewport yourself either (use SetViewport if you must reset it.)
+    void OnSize(wxSizeEvent& event);
+
+    virtual void MacSuperChangedPosition();
+    virtual void MacTopLevelWindowChangedPosition();
+    virtual void MacVisibilityChanged();
+
+    void MacUpdateView();
 
 protected:
-    wxGLContext*   m_glContext;
-    bool m_macCanvasIsShown ;
-DECLARE_EVENT_TABLE()
+    AGLPixelFormat m_aglFormat;
+
+    bool m_macCanvasIsShown,
+         m_needsUpdate;
+
+    DECLARE_EVENT_TABLE()
+    DECLARE_CLASS(wxGLCanvas)
 };
 
-#endif // wxUSE_GLCANVAS
 #endif // _WX_GLCANVAS_H_
diff --git a/include/wx/msw/glcanvas.h b/include/wx/msw/glcanvas.h
index 54530303af..83362b0167 100644
--- a/include/wx/msw/glcanvas.h
+++ b/include/wx/msw/glcanvas.h
@@ -13,22 +13,24 @@
 #define _WX_GLCANVAS_H_
 
 #include "wx/palette.h"
-#include "wx/scrolwin.h"
 
 #include "wx/msw/wrapwin.h"
 
 #include <GL/gl.h>
 
-class WXDLLIMPEXP_GL wxGLCanvas;     /* forward reference */
+// ----------------------------------------------------------------------------
+// wxGLContext: OpenGL rendering context
+// ----------------------------------------------------------------------------
 
-class WXDLLIMPEXP_GL wxGLContext: public wxObject
+class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
 {
 public:
-    wxGLContext(wxGLCanvas *win, const wxGLContext* other=NULL /* for sharing display lists */ );
+    wxGLContext(wxGLCanvas *win, const wxGLContext* other = NULL);
     virtual ~wxGLContext();
 
-    void SetCurrent(const wxGLCanvas& win) const;
-    inline HGLRC GetGLRC() const { return m_glContext; }
+    virtual void SetCurrent(const wxGLCanvas& win) const;
+
+    HGLRC GetGLRC() const { return m_glContext; }
 
 protected:
     HGLRC m_glContext;
@@ -37,92 +39,111 @@ private:
     DECLARE_CLASS(wxGLContext)
 };
 
-class WXDLLIMPEXP_GL wxGLCanvas: public wxWindow
+// ----------------------------------------------------------------------------
+// wxGLCanvas: OpenGL output window
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasBase
 {
 public:
-    // This ctor is identical to the next, except for the fact that it
-    // doesn't create an implicit wxGLContext.
-    // The attribList parameter has been moved to avoid overload clashes.
-    wxGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
-        int* attribList = 0,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize, long style = 0,
-        const wxString& name = wxGLCanvasName,
-        const wxPalette& palette = wxNullPalette);
-
-    wxGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize, long style = 0,
-        const wxString& name = wxGLCanvasName, int *attribList = 0,
-        const wxPalette& palette = wxNullPalette);
-
     wxGLCanvas(wxWindow *parent,
-        const wxGLContext *shared,
-        wxWindowID id = wxID_ANY,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0,
-        const wxString& name = wxGLCanvasName,
-        int *attribList = (int *) NULL,
-        const wxPalette& palette = wxNullPalette);
-
-    wxGLCanvas(wxWindow *parent,
-        const wxGLCanvas *shared,
-        wxWindowID id = wxID_ANY,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0,
-        const wxString& name = wxGLCanvasName,
-        int *attribList = 0,
-        const wxPalette& palette = wxNullPalette);
+               wxWindowID id = wxID_ANY,
+               const int *attribList = NULL,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const wxPalette& palette = wxNullPalette);
+
+    bool Create(wxWindow *parent,
+                wxWindowID id = wxID_ANY,
+                const wxPoint& pos = wxDefaultPosition,
+                const wxSize& size = wxDefaultSize,
+                long style = 0,
+                const wxString& name = wxGLCanvasName,
+                const int *attribList = NULL,
+                const wxPalette& palette = wxNullPalette);
 
     virtual ~wxGLCanvas();
 
-    // Replaces wxWindow::Create functionality, since
-    // we need to use a different window class
-    bool Create(wxWindow *parent, wxWindowID id,
-        const wxPoint& pos, const wxSize& size,
-        long style, const wxString& name);
-
-    void SetCurrent(const wxGLContext& RC) const;
-    void SetCurrent();
+    // implement wxGLCanvasBase methods
+    virtual void SwapBuffers();
 
-#ifdef __WXUNIVERSAL__
-    virtual bool SetCurrent(bool doit) { return wxWindow::SetCurrent(doit); };
-#endif
 
-    void SetColour(const wxChar *colour);
+    // MSW-specific helpers
+    // --------------------
 
-    void SwapBuffers();
+    // get the HDC used for OpenGL rendering
+    HDC GetHDC() const { return m_hDC; }
 
-    void OnSize(wxSizeEvent& event);
+    // try to find pixel format matching the given attributes list for the
+    // specified HDC, return 0 on error, otherwise pfd is filled in with the
+    // information from attribList if non-NULL
+    static int ChooseMatchingPixelFormat(HDC hdc, const int *attribList,
+                                         PIXELFORMATDESCRIPTOR *pfd = NULL);
 
+#if wxUSE_PALETTE
+    // palette stuff
+    bool SetupPalette(const wxPalette& palette);
+    virtual wxPalette CreateDefaultPalette();
     void OnQueryNewPalette(wxQueryNewPaletteEvent& event);
-
     void OnPaletteChanged(wxPaletteChangedEvent& event);
+#endif // wxUSE_PALETTE
 
-    inline wxGLContext* GetContext() const { return m_glContext; }
-
-    inline WXHDC GetHDC() const { return m_hDC; }
-
-    void SetupPixelFormat(int *attribList = (int *) NULL);
+    // deprecated methods using the implicit wxGLContext, associate the context
+    // explicitly with the window instead
+#if WXWIN_COMPATIBILITY_2_8
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               const wxGLContext *shared,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+
+    wxDEPRECATED(
+    wxGLCanvas(wxWindow *parent,
+               const wxGLCanvas *shared,
+               wxWindowID id = wxID_ANY,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const int *attribList = NULL,
+               const wxPalette& palette = wxNullPalette)
+    );
+#endif // WXWIN_COMPATIBILITY_2_8
 
-    void SetupPalette(const wxPalette& palette);
+protected:
+    // common part of all ctors
+    void Init();
 
-    wxPalette CreateDefaultPalette();
+    // set up the pixel format using the given attributes and palette
+    bool DoSetup(const int *attribList);
 
-    inline wxPalette* GetPalette() const { return (wxPalette *) &m_palette; }
 
-protected:
-    wxGLContext*   m_glContext;  // this is typedef-ed ptr, in fact
-    wxPalette      m_palette;
-    WXHDC          m_hDC;
+    // HDC for this window, we keep it all the time
+    HDC m_hDC;
 
 private:
     DECLARE_EVENT_TABLE()
     DECLARE_CLASS(wxGLCanvas)
 };
 
-#endif
-    // _WX_GLCANVAS_H_
+#endif // _WX_GLCANVAS_H_
 
diff --git a/include/wx/palmos/glcanvas.h b/include/wx/palmos/glcanvas.h
index f42a189868..4aa7df791d 100644
--- a/include/wx/palmos/glcanvas.h
+++ b/include/wx/palmos/glcanvas.h
@@ -114,13 +114,7 @@ public:
 
     void SetupPalette(const wxPalette& palette);
 
-    wxPalette CreateDefaultPalette();
-
-    inline wxPalette* GetPalette() const { return (wxPalette *) &m_palette; }
-
 protected:
-    wxGLContext*   m_glContext;  // this is typedef-ed ptr, in fact
-    wxPalette      m_palette;
     WXHDC          m_hDC;
 
     DECLARE_EVENT_TABLE()
diff --git a/include/wx/x11/glcanvas.h b/include/wx/x11/glcanvas.h
index 2ee71b678d..e06246e2f5 100644
--- a/include/wx/x11/glcanvas.h
+++ b/include/wx/x11/glcanvas.h
@@ -13,13 +13,7 @@
 #ifndef _WX_GLCANVAS_H_
 #define _WX_GLCANVAS_H_
 
-#include "wx/defs.h"
-
-#if wxUSE_GLCANVAS
-
 #include "wx/gdicmn.h"
-#include "wx/palette.h"
-#include "wx/scrolwin.h"
 
 #include <GL/glx.h>
 
@@ -27,111 +21,54 @@
 // classes
 //---------------------------------------------------------------------------
 
-
-class WXDLLEXPORT wxGLContext: public wxObject
+class WXDLLEXPORT wxGLContext : public wxGLContextBase
 {
 public:
-    wxGLContext( bool isRGB, wxWindow *win,
-        const wxPalette& palette = wxNullPalette );
-    wxGLContext( bool WXUNUSED(isRGB), wxWindow *win,
-        const wxPalette& WXUNUSED(palette),
-        const wxGLContext *other  /* for sharing display lists */
-        );
+    wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
     virtual ~wxGLContext();
 
-    void SetCurrent();
-    void SetColour(const wxChar *colour);
-    void SwapBuffers();
+    virtual void SetCurrent(const wxGLCanvas& win) const;
 
-    void SetupPixelFormat();
-    void SetupPalette(const wxPalette& palette);
-    wxPalette CreateDefaultPalette();
-
-    inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; }
-    inline wxWindow* GetWindow() const { return m_window; }
-    // inline GtkWidget* GetWidget() const { return m_widget; }
-    inline GLXContext GetContext() const { return m_glContext; }
-
-public:
+private:
     GLXContext       m_glContext;
 
-    // GtkWidget       *m_widget;
-    wxPalette        m_palette;
-    wxWindow*        m_window;
-
     DECLARE_CLASS(wxGLContext)
 };
 
 
-class WXDLLEXPORT wxGLCanvas: public wxScrolledWindow
+class WXDLLEXPORT wxGLCanvas : public wxGLCanvasBase
 {
 public:
-    inline wxGLCanvas() {
-        m_glContext = (wxGLContext*) NULL;
-        m_sharedContext = (wxGLContext*) NULL;
-        // m_glWidget = (GtkWidget*) NULL;
-        m_vi = (void*) NULL;
-        // m_exposed = FALSE;
-    }
-    wxGLCanvas( wxWindow *parent, wxWindowID id = wxID_ANY,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxT("GLCanvas"),
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
-    wxGLCanvas( wxWindow *parent, const wxGLContext *shared,
-        wxWindowID id = wxID_ANY,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxT("GLCanvas"),
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
-    wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared,
-        wxWindowID id = wxID_ANY,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxT("GLCanvas"),
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
-
-    bool Create( wxWindow *parent,
-        const wxGLContext *shared = (wxGLContext*)NULL,
-        const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
-        wxWindowID id = wxID_ANY,
-        const wxPoint& pos = wxDefaultPosition,
-        const wxSize& size = wxDefaultSize,
-        long style = 0, const wxString& name = wxT("GLCanvas"),
-        int *attribList = (int*) NULL,
-        const wxPalette& palette = wxNullPalette );
+    wxGLCanvas(wxWindow *parent,
+               wxWindowID id = wxID_ANY,
+               const int *attribList = NULL,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = 0,
+               const wxString& name = wxGLCanvasName,
+               const wxPalette& palette = wxNullPalette);
+
+    bool Create(wxWindow *parent,
+                wxWindowID id = wxID_ANY,
+                const wxPoint& pos = wxDefaultPosition,
+                const wxSize& size = wxDefaultSize,
+                long style = 0,
+                const wxString& name = wxGLCanvasName,
+                const int *attribList = NULL,
+                const wxPalette& palette = wxNullPalette);
 
     virtual ~wxGLCanvas();
 
-    void SetCurrent();
-    void SetColour(const wxChar *colour);
-    void SwapBuffers();
-
-    // void OnSize(wxSizeEvent& event);
-
-    // void OnInternalIdle();
+    virtual void SwapBuffers();
 
-    inline wxGLContext* GetContext() const { return m_glContext; }
 
     // implementation
+    void *m_vi;
 
-    wxGLContext      *m_glContext,
-        *m_sharedContext;
-    wxGLCanvas       *m_sharedContextOf;
-    void             *m_vi;
-    // GtkWidget        *m_glWidget;
-    // bool              m_exposed;
-
-    DECLARE_EVENT_TABLE()
-        DECLARE_CLASS(wxGLCanvas)
+protected:
+    virtual int GetColourIndex(const wxColour& col);
 
+    DECLARE_CLASS(wxGLCanvas)
 };
 
-#endif
-//  wxUSE_GLCANVAS
-
-#endif
-// _WX_GLCANVAS_H_
+#endif // _WX_GLCANVAS_H_
diff --git a/src/cocoa/glcanvas.mm b/src/cocoa/glcanvas.mm
index a41176c1c6..8e12a3ca92 100644
--- a/src/cocoa/glcanvas.mm
+++ b/src/cocoa/glcanvas.mm
@@ -23,42 +23,31 @@
 #import <AppKit/NSOpenGL.h>
 #import <AppKit/NSOpenGLView.h>
 
-IMPLEMENT_DYNAMIC_CLASS(wxGLCanvas, wxWindow)
-BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
-END_EVENT_TABLE()
-// WX_IMPLEMENT_COCOA_OWNER(wxGLCanvas,NSOpenGLView,NSView,NSView)
-
-wxGLCanvas::wxGLCanvas(wxWindow *parent,
-            wxWindowID winid, const wxPoint& pos, const wxSize& size,
-            long style, const wxString& name,
-            int *attribList, const wxPalette& palette)
+wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other)
 {
-    Create(parent,winid,pos,size,style,name);
+    // TODO
 }
 
-wxGLCanvas::wxGLCanvas(wxWindow *parent,
-            const wxGLContext *shared,
-            wxWindowID winid, const wxPoint& pos, const wxSize& size,
-            long style, const wxString& name,
-            int *attribList, const wxPalette& palette)
+wxGLContext::~wxGLContext()
 {
-    Create(parent,winid,pos,size,style,name);
 }
 
-wxGLCanvas::wxGLCanvas(wxWindow *parent,
-            const wxGLCanvas *shared,
-            wxWindowID winid, const wxPoint& pos, const wxSize& size,
-            long style, const wxString& name,
-            int *attribList, const wxPalette& palette)
+void wxGLContext::SetCurrent(const wxGLCanvas& win) const
 {
-    Create(parent,winid,pos,size,style,name);
+    [[win.GetNSOpenGLView() openGLContext] makeCurrentContext];
 }
 
-bool wxGLCanvas::Create(wxWindow *parent, wxWindowID winid,
-           const wxPoint& pos,
-           const wxSize& size,
-           long style,
-           const wxString& name)
+IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
+// WX_IMPLEMENT_COCOA_OWNER(wxGLCanvas,NSOpenGLView,NSView,NSView)
+
+bool wxGLCanvas::Create(wxWindow *parent,
+                        wxWindowID winid,
+                        const wxPoint& pos,
+                        const wxSize& size,
+                        long style,
+                        const wxString& name,
+                        const int *attribList,
+                        const wxPalette& palette)
 {
     wxAutoNSAutoreleasePool pool;
     if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
@@ -77,14 +66,9 @@ wxGLCanvas::~wxGLCanvas()
 {
 }
 
-void wxGLCanvas::SetCurrent()
-{
-    [[(NSOpenGLView*)m_cocoaNSView openGLContext] makeCurrentContext];
-}
-
 void wxGLCanvas::SwapBuffers()
 {
-    [[(NSOpenGLView*)m_cocoaNSView openGLContext] flushBuffer];
+    [[GetNSOpenGLView() openGLContext] flushBuffer];
 }
 
 #endif // wxUSE_GLCANVAS
diff --git a/src/common/glcmn.cpp b/src/common/glcmn.cpp
new file mode 100644
index 0000000000..ffcb45a603
--- /dev/null
+++ b/src/common/glcmn.cpp
@@ -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
+
diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp
index fa47355e8f..5cfde2e126 100644
--- a/src/gtk/app.cpp
+++ b/src/gtk/app.cpp
@@ -339,6 +339,11 @@ wxApp::~wxApp()
 {
     if (m_idleTag)
         g_source_remove( m_idleTag );
+
+    if (m_glFBCInfo)
+        XFree(m_glFBCInfo);
+    if (m_glVisualInfo)
+        XFree(m_glVisualInfo);
 }
 
 bool wxApp::OnInitGui()
diff --git a/src/gtk/glcanvas.cpp b/src/gtk/glcanvas.cpp
index 7ac91509dc..c7bdfbfd19 100644
--- a/src/gtk/glcanvas.cpp
+++ b/src/gtk/glcanvas.cpp
@@ -33,22 +33,26 @@ extern "C"
 #include "wx/gtk/win_gtk.h"
 #include "wx/gtk/private.h"
 
-// DLL options compatibility check:
-#include "wx/build.h"
-WX_CHECK_BUILD_OPTIONS("wxGL")
-
-
-//---------------------------------------------------------------------------
-// static variables
-//---------------------------------------------------------------------------
-int wxGLCanvas::m_glxVersion = 0;
-
 //---------------------------------------------------------------------------
 // global data
 //---------------------------------------------------------------------------
 
 XVisualInfo *g_vi = (XVisualInfo*) NULL;
 
+// ----------------------------------------------------------------------------
+// helper functions
+// ----------------------------------------------------------------------------
+
+// wrapper around glXMakeContextCurrent/glXMakeCurrent depending on GLX
+// version
+static void wxMakeContextCurrent(GLXDrawable drawable, GLXContext context)
+{
+    if (wxGLCanvas::GetGLXVersion() >= 13)
+        glXMakeContextCurrent( GDK_DISPLAY(), drawable, drawable, context);
+    else // GLX <= 1.2 doesn't have glXMakeContextCurrent()
+        glXMakeCurrent( GDK_DISPLAY(), drawable, context);
+}
+
 //---------------------------------------------------------------------------
 // wxGLContext
 //---------------------------------------------------------------------------
@@ -61,16 +65,14 @@ wxGLContext::wxGLContext(wxWindow* win, const wxGLContext* other)
 
     if (wxGLCanvas::GetGLXVersion() >= 13)
     {
-        // GLX >= 1.3
         GLXFBConfig *fbc = gc->m_fbc;
         wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
         m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE,
                                            other ? other->m_glContext : None,
                                            GL_TRUE );
     }
-    else
+    else // GLX <= 1.2
     {
-        // GLX <= 1.2
         XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
         wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
         m_glContext = glXCreateContext( GDK_DISPLAY(), vi,
@@ -78,66 +80,50 @@ wxGLContext::wxGLContext(wxWindow* win, const wxGLContext* other)
                                         GL_TRUE );
     }
 
-    if ( !m_glContext )
-    {
-        wxFAIL_MSG( _T("Couldn't create OpenGl context") );
-    }
+    wxASSERT_MSG( m_glContext, _T("Couldn't create OpenGl context") );
 }
 
 wxGLContext::~wxGLContext()
 {
-    if (!m_glContext) return;
+    if ( !m_glContext )
+        return;
 
-    if (m_glContext == glXGetCurrentContext())
-    {
-        if (wxGLCanvas::GetGLXVersion() >= 13)
-            // GLX >= 1.3
-            glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL);
-        else
-            // GLX <= 1.2
-            glXMakeCurrent( GDK_DISPLAY(), None, NULL);
-    }
+    if ( m_glContext == glXGetCurrentContext() )
+        wxMakeContextCurrent(None, NULL);
 
     glXDestroyContext( GDK_DISPLAY(), m_glContext );
 }
 
 void wxGLContext::SetCurrent(const wxGLCanvas& win) const
 {
-    if (m_glContext)
-    {
-        GdkWindow *window = GTK_PIZZA(win.m_wxwindow)->bin_window;
+    if ( !m_glContext )
+        return;
 
-        if (wxGLCanvas::GetGLXVersion() >= 13)
-            // GLX >= 1.3
-            glXMakeContextCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), GDK_WINDOW_XWINDOW(window), m_glContext );
-        else
-            // GLX <= 1.2
-            glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), m_glContext );
-    }
+    GdkWindow *window = GTK_PIZZA(win.m_wxwindow)->bin_window;
+    wxCHECK_RET( window, _T("window must be shown") );
+
+    wxMakeContextCurrent(GDK_WINDOW_XWINDOW(window), m_glContext);
 }
 
 
+#if WXWIN_COMPATIBILITY_2_8
+
 //-----------------------------------------------------------------------------
-// "realize" from m_wxwindow
+// "realize" from m_wxwindow: used to create m_glContext implicitly
 //-----------------------------------------------------------------------------
 
 extern "C" {
 static gint
 gtk_glwindow_realized_callback( GtkWidget *WXUNUSED(widget), wxGLCanvas *win )
 {
-    if (!win->m_glContext && win->m_createImplicitContext)
-    {
-        wxGLContext *share = win->m_sharedContext;
-        if ( !share && win->m_sharedContextOf )
-            share = win->m_sharedContextOf->GetContext();
-
-        win->m_glContext = new wxGLContext(win, share);
-    }
+    win->GTKInitImplicitContext();
 
     return FALSE;
 }
 }
 
+#endif // WXWIN_COMPATIBILITY_2_8
+
 //-----------------------------------------------------------------------------
 // "map" from m_wxwindow
 //-----------------------------------------------------------------------------
@@ -146,16 +132,12 @@ extern "C" {
 static gint
 gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win )
 {
-    // CF: Can the "if" line be removed, and the code unconditionally (always) be run?
-    if (win->m_glContext || !win->m_createImplicitContext)
-    {
-        wxPaintEvent event( win->GetId() );
-        event.SetEventObject( win );
-        win->GetEventHandler()->ProcessEvent( event );
+    wxPaintEvent event( win->GetId() );
+    event.SetEventObject( win );
+    win->GetEventHandler()->ProcessEvent( event );
 
-        win->m_exposed = false;
-        win->GetUpdateRegion().Clear();
-    }
+    win->m_exposed = false;
+    win->GetUpdateRegion().Clear();
 
     return FALSE;
 }
@@ -207,76 +189,83 @@ gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, w
 
 IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
 
-BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
-    EVT_SIZE(wxGLCanvas::OnSize)
-END_EVENT_TABLE()
-
-wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id,
-                        int *attribList,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        const wxPalette& palette )
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       wxWindowID id,
+                       const int *attribList,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const wxPalette& palette)
+#if WXWIN_COMPATIBILITY_2_8
     : m_createImplicitContext(false)
+#endif
 {
-    Create( parent, NULL, NULL, id, pos, size, style, name, attribList, palette );
+    Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
-wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        int *attribList,
-                        const wxPalette& palette )
+#if WXWIN_COMPATIBILITY_2_8
+
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
     : m_createImplicitContext(true)
 {
-    Create( parent, NULL, NULL, id, pos, size, style, name, attribList, palette );
+    Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
-wxGLCanvas::wxGLCanvas( wxWindow *parent,
-                        const wxGLContext *shared,
-                        wxWindowID id,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        int *attribList,
-                        const wxPalette& palette )
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       const wxGLContext *shared,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
     : m_createImplicitContext(true)
 {
-    Create( parent, shared, NULL, id, pos, size, style, name, attribList, palette );
+    m_sharedContext = wx_const_cast(wxGLContext *, shared);
+
+    Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
-wxGLCanvas::wxGLCanvas( wxWindow *parent,
-                        const wxGLCanvas *shared,
-                        wxWindowID id,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        int *attribList,
-                        const wxPalette& palette )
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       const wxGLCanvas *shared,
+                       wxWindowID id,
+                       const wxPoint& pos, const wxSize& size,
+                       long style, const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette )
     : m_createImplicitContext(true)
 {
-    Create( parent, NULL, shared, id, pos, size, style, name, attribList, palette );
+    m_sharedContextOf = wx_const_cast(wxGLCanvas *, shared);
+
+    Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
-bool wxGLCanvas::Create( wxWindow *parent,
-                         const wxGLContext *shared,
-                         const wxGLCanvas *shared_context_of,
-                         wxWindowID id,
-                         const wxPoint& pos, const wxSize& size,
-                         long style, const wxString& name,
-                         int *attribList,
-                         const wxPalette& palette)
-{
-    m_sharedContext = (wxGLContext*)shared;  // const_cast
-    m_sharedContextOf = (wxGLCanvas*)shared_context_of;  // const_cast
-    m_glContext = (wxGLContext*) NULL;
+#endif // WXWIN_COMPATIBILITY_2_8
 
+bool wxGLCanvas::Create(wxWindow *parent,
+                        wxWindowID id,
+                        const wxPoint& pos,
+                        const wxSize& size,
+                        long style,
+                        const wxString& name,
+                        const int *attribList,
+                        const wxPalette& palette)
+{
     m_exposed = false;
     m_noExpose = true;
     m_nativeSizeEvent = true;
     m_fbc = NULL;
     m_vi = NULL;
 
-    // to be sure the glx version is known
-    wxGLCanvas::QueryGLXVersion();
-
     if (wxGLCanvas::GetGLXVersion() >= 13)
     {
         // GLX >= 1.3 uses a GLXFBConfig
@@ -340,7 +329,7 @@ bool wxGLCanvas::Create( wxWindow *parent,
         gtk_widget_set_colormap( m_glWidget, colormap );
     }
     else
-#endif
+#endif // GTK+ >= 2.2
     {
         visual = gdkx_visual_get( vi->visualid );
         colormap = gdk_colormap_new( visual, TRUE );
@@ -353,7 +342,9 @@ bool wxGLCanvas::Create( wxWindow *parent,
 
     gtk_widget_set_double_buffered( m_glWidget, FALSE );
 
+#if WXWIN_COMPATIBILITY_2_8
     g_signal_connect(m_wxwindow, "realize",       G_CALLBACK(gtk_glwindow_realized_callback), this);
+#endif // WXWIN_COMPATIBILITY_2_8
     g_signal_connect(m_wxwindow, "map",           G_CALLBACK(gtk_glwindow_map_callback),      this);
     g_signal_connect(m_wxwindow, "expose_event",  G_CALLBACK(gtk_glwindow_expose_callback),   this);
     g_signal_connect(m_widget,   "size_allocate", G_CALLBACK(gtk_glcanvas_size_callback),     this);
@@ -363,11 +354,13 @@ bool wxGLCanvas::Create( wxWindow *parent,
         gtk_widget_pop_colormap();
     }
 
+#if WXWIN_COMPATIBILITY_2_8
     // if our parent window is already visible, we had been realized before we
     // connected to the "realize" signal and hence our m_glContext hasn't been
     // initialized yet and we have to do it now
     if (GTK_WIDGET_REALIZED(m_wxwindow))
         gtk_glwindow_realized_callback( m_wxwindow, this );
+#endif // WXWIN_COMPATIBILITY_2_8
 
     if (GTK_WIDGET_MAPPED(m_wxwindow))
         gtk_glwindow_map_callback( m_wxwindow, this );
@@ -384,41 +377,40 @@ wxGLCanvas::~wxGLCanvas()
     XVisualInfo *vi = (XVisualInfo *) m_vi;
     if (vi && m_canFreeVi)
         XFree( vi );
-
-    delete m_glContext;
 }
 
-void* wxGLCanvas::ChooseGLVisual(int *attribList)
+void* wxGLCanvas::ChooseGLVisual(const int *attribList)
 {
     int data[512];
     GetGLAttribListFromWX( attribList, data );
-    attribList = (int*) data;
 
     Display *dpy = GDK_DISPLAY();
 
-    return glXChooseVisual( dpy, DefaultScreen(dpy), attribList );
+    return glXChooseVisual( dpy, DefaultScreen(dpy), data );
 }
 
-void* wxGLCanvas::ChooseGLFBC(int *attribList)
+void* wxGLCanvas::ChooseGLFBC(const int *attribList)
 {
     int data[512];
     GetGLAttribListFromWX( attribList, data );
-    attribList = (int*) data;
 
     int returned;
     return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()),
-                              attribList, &returned );
+                              data, &returned );
 }
 
 
-void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
+void
+wxGLCanvas::GetGLAttribListFromWX(const int *wx_attribList, int *gl_attribList)
 {
-    if (!wx_attribList)
+    if ( !wx_attribList )
     {
         if (wxGLCanvas::GetGLXVersion() >= 13)
-        // leave GLX >= 1.3 choose the default attributes
+        {
+            // leave GLX >= 1.3 choose the default attributes
             gl_attribList[0] = 0;
-        else
+        }
+        else // GLX < 1.3
         {
             int i = 0;
             // default settings if attriblist = 0
@@ -432,7 +424,7 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
             gl_attribList[i++] = None;
         }
     }
-    else
+    else // have non-default attributes
     {
         int arg=0, p=0;
         while( (wx_attribList[arg]!=0) && (p<510) )
@@ -441,8 +433,10 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
             {
                 case WX_GL_RGBA:
                     if (wxGLCanvas::GetGLXVersion() <= 12)
+                    {
                         // for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm)
                         gl_attribList[p++] = GLX_RGBA;
+                    }
                     break;
                 case WX_GL_BUFFER_SIZE:
                     gl_attribList[p++] = GLX_BUFFER_SIZE;
@@ -453,13 +447,7 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
                     gl_attribList[p++] = wx_attribList[arg++];
                     break;
                 case WX_GL_DOUBLEBUFFER:
-                    if (wxGLCanvas::GetGLXVersion() <= 12)
-                        gl_attribList[p++] = GLX_DOUBLEBUFFER;
-                    else
-                        // for GLX >= 1.3, GLX_DOUBLEBUFFER format is different (1 <=> True)
-                        // it seems this flag is useless for some hardware opengl implementation.
-                        // but for Mesa 6.2.1, this flag is used so don't ignore it.
-                        gl_attribList[p++] = GLX_DOUBLEBUFFER;
+                    gl_attribList[p++] = GLX_DOUBLEBUFFER;
                     gl_attribList[p++] = 1;
                     break;
                 case WX_GL_STEREO:
@@ -518,64 +506,34 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
     }
 }
 
-void wxGLCanvas::QueryGLXVersion()
+/* static */
+int wxGLCanvas::GetGLXVersion()
 {
-    if (m_glxVersion == 0)
+    static int s_glxVersion = 0;
+    if ( s_glxVersion == 0 )
     {
         // check the GLX version
         int glxMajorVer, glxMinorVer;
         bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer);
         wxASSERT_MSG( ok, _T("GLX version not found") );
         if (!ok)
-            m_glxVersion = 10; // 1.0 by default
+            s_glxVersion = 10; // 1.0 by default
         else
-            m_glxVersion = glxMajorVer*10 + glxMinorVer;
+            s_glxVersion = glxMajorVer*10 + glxMinorVer;
     }
-}
 
-int wxGLCanvas::GetGLXVersion()
-{
-    wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") );
-    return m_glxVersion;
+    return s_glxVersion;
 }
 
-
 void wxGLCanvas::SwapBuffers()
 {
     GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window;
     glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( window ) );
 }
 
-void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
-{
-}
-
-void wxGLCanvas::SetCurrent(const wxGLContext& RC) const
-{
-    RC.SetCurrent(*this);
-}
-
-void wxGLCanvas::SetCurrent()
-{
-    if (m_glContext)
-        m_glContext->SetCurrent(*this);
-}
-
-void wxGLCanvas::SetColour( const wxChar *colour )
-{
-    wxColour col = wxTheColourDatabase->Find(colour);
-    if (col.Ok())
-    {
-        float r = (float)(col.Red()/256.0);
-        float g = (float)(col.Green()/256.0);
-        float b = (float)(col.Blue()/256.0);
-        glColor3f( r, g, b);
-    }
-}
-
 void wxGLCanvas::OnInternalIdle()
 {
-    if (/*m_glContext &&*/ m_exposed)
+    if (m_exposed)
     {
         wxPaintEvent event( GetId() );
         event.SetEventObject( this );
@@ -588,50 +546,49 @@ void wxGLCanvas::OnInternalIdle()
     wxWindow::OnInternalIdle();
 }
 
+#if WXWIN_COMPATIBILITY_2_8
+
+void wxGLCanvas::GTKInitImplicitContext()
+{
+    if ( !m_glContext && m_createImplicitContext )
+    {
+        wxGLContext *share = m_sharedContext;
+        if ( !share && m_sharedContextOf )
+            share = m_sharedContextOf->m_glContext;
+
+        m_glContext = new wxGLContext(this, share);
+    }
+}
 
+#endif // WXWIN_COMPATIBILITY_2_8
 
 //---------------------------------------------------------------------------
 // wxGLApp
 //---------------------------------------------------------------------------
 
-IMPLEMENT_CLASS(wxGLApp, wxApp)
-
-wxGLApp::~wxGLApp()
-{
-    if (m_glFBCInfo)
-        XFree(m_glFBCInfo);
-    if (m_glVisualInfo)
-        XFree(m_glVisualInfo);
-}
-
-bool wxGLApp::InitGLVisual(int *attribList)
+bool wxGLApp::InitGLVisual(const int *attribList)
 {
-    wxGLCanvas::QueryGLXVersion();
-
-    if (wxGLCanvas::GetGLXVersion() >= 13)
+    if ( wxGLCanvas::GetGLXVersion() >= 13 )
     {
-        // GLX >= 1.3
         if (m_glFBCInfo)
             XFree(m_glFBCInfo);
         m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList);
 
-        if (m_glFBCInfo)
-        {
-            if (m_glVisualInfo)
-                XFree(m_glVisualInfo);
-            m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
-        }
-        return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL);
+        if ( !m_glFBCInfo )
+            return false;
+
+        if (m_glVisualInfo)
+            XFree(m_glVisualInfo);
+        m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
     }
-    else
+    else // GLX <= 1.2
     {
-        // GLX <= 1.2
         if (m_glVisualInfo)
             XFree(m_glVisualInfo);
         m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList);
-        return m_glVisualInfo != NULL;
     }
+
+    return m_glVisualInfo != NULL;
 }
 
-#endif
-    // wxUSE_GLCANVAS
+#endif // wxUSE_GLCANVAS
diff --git a/src/gtk1/glcanvas.cpp b/src/gtk1/glcanvas.cpp
index 235c0de0d7..9179b7a0c2 100644
--- a/src/gtk1/glcanvas.cpp
+++ b/src/gtk1/glcanvas.cpp
@@ -31,22 +31,14 @@ extern "C"
 }
 
 #include "wx/gtk1/win_gtk.h"
-
-// DLL options compatibility check:
-#include "wx/build.h"
-WX_CHECK_BUILD_OPTIONS("wxGL")
-
-
-//---------------------------------------------------------------------------
-// static variables
-//---------------------------------------------------------------------------
-int wxGLCanvas::m_glxVersion = 0;
+#include "wx/gtk1/private.h"
 
 //---------------------------------------------------------------------------
 // global data
 //---------------------------------------------------------------------------
 
 XVisualInfo *g_vi = (XVisualInfo*) NULL;
+
 //-----------------------------------------------------------------------------
 // idle system
 //-----------------------------------------------------------------------------
@@ -54,60 +46,40 @@ XVisualInfo *g_vi = (XVisualInfo*) NULL;
 extern void wxapp_install_idle_handler();
 extern bool g_isIdle;
 
+// ----------------------------------------------------------------------------
+// helper functions
+// ----------------------------------------------------------------------------
+
+// wrapper around glXMakeContextCurrent/glXMakeCurrent depending on GLX
+// version
+static void wxMakeContextCurrent(GLXDrawable drawable, GLXContext context)
+{
+    if (wxGLCanvas::GetGLXVersion() >= 13)
+        glXMakeContextCurrent( GDK_DISPLAY(), drawable, drawable, context);
+    else // GLX <= 1.2 doesn't have glXMakeContextCurrent()
+        glXMakeCurrent( GDK_DISPLAY(), drawable, context);
+}
+
 //---------------------------------------------------------------------------
 // wxGLContext
 //---------------------------------------------------------------------------
 
 IMPLEMENT_CLASS(wxGLContext,wxObject)
 
-wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette& WXUNUSED(palette) )
-{
-    m_window = win;
-    m_widget = win->m_wxwindow;
-
-    wxGLCanvas *gc = (wxGLCanvas*) win;
-
-    if (wxGLCanvas::GetGLXVersion() >= 13)
-    {
-        // GLX >= 1.3
-        GLXFBConfig *fbc = gc->m_fbc;
-        wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
-        m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, None, GL_TRUE );
-    }
-    else
-    {
-        // GLX <= 1.2
-        XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
-        wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
-        m_glContext = glXCreateContext( GDK_DISPLAY(), vi, None, GL_TRUE );
-    }
-
-    wxCHECK_RET( m_glContext, _T("Couldn't create OpenGl context") );
-}
-
-wxGLContext::wxGLContext(
-               bool WXUNUSED(isRGB), wxWindow *win,
-               const wxPalette& WXUNUSED(palette),
-               const wxGLContext *other        /* for sharing display lists */
-)
+wxGLContext::wxGLContext(wxWindow* win, const wxGLContext* other)
 {
-    m_window = win;
-    m_widget = win->m_wxwindow;
-
     wxGLCanvas *gc = (wxGLCanvas*) win;
 
     if (wxGLCanvas::GetGLXVersion() >= 13)
     {
-        // GLX >= 1.3
         GLXFBConfig *fbc = gc->m_fbc;
         wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
         m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE,
                                            other ? other->m_glContext : None,
                                            GL_TRUE );
     }
-    else
+    else // GLX <= 1.2
     {
-        // GLX <= 1.2
         XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
         wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
         m_glContext = glXCreateContext( GDK_DISPLAY(), vi,
@@ -115,100 +87,50 @@ wxGLContext::wxGLContext(
                                         GL_TRUE );
     }
 
-    if ( !m_glContext )
-    {
-        wxFAIL_MSG( _T("Couldn't create OpenGl context") );
-    }
+    wxASSERT_MSG( m_glContext, _T("Couldn't create OpenGl context") );
 }
 
 wxGLContext::~wxGLContext()
 {
-    if (!m_glContext) return;
+    if ( !m_glContext )
+        return;
 
-    if (m_glContext == glXGetCurrentContext())
-    {
-        if (wxGLCanvas::GetGLXVersion() >= 13)
-            // GLX >= 1.3
-            glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL);
-        else
-            // GLX <= 1.2
-            glXMakeCurrent( GDK_DISPLAY(), None, NULL);
-    }
+    if ( m_glContext == glXGetCurrentContext() )
+        wxMakeContextCurrent(None, NULL);
 
     glXDestroyContext( GDK_DISPLAY(), m_glContext );
 }
 
-void wxGLContext::SwapBuffers()
-{
-    if (m_glContext)
-    {
-        GdkWindow *window = GTK_PIZZA(m_widget)->bin_window;
-        glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( window ) );
-    }
-}
-
-void wxGLContext::SetCurrent()
+void wxGLContext::SetCurrent(const wxGLCanvas& win) const
 {
-    if (m_glContext)
-    {
-        GdkWindow *window = GTK_PIZZA(m_widget)->bin_window;
-
-        if (wxGLCanvas::GetGLXVersion() >= 13)
-            // GLX >= 1.3
-            glXMakeContextCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window),
-                                   GDK_WINDOW_XWINDOW(window), m_glContext );
-        else
-            // GLX <= 1.2
-            glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), m_glContext );
-    }
-}
+    if ( !m_glContext )
+        return;
 
-void wxGLContext::SetColour(const wxChar *colour)
-{
-    wxColour col = wxTheColourDatabase->Find(colour);
-    if (col.Ok())
-    {
-        float r = (float)(col.Red()/256.0);
-        float g = (float)(col.Green()/256.0);
-        float b = (float)(col.Blue()/256.0);
-        glColor3f( r, g, b);
-    }
-}
+    GdkWindow *window = GTK_PIZZA(win.m_wxwindow)->bin_window;
+    wxCHECK_RET( window, _T("window must be shown") );
 
-void wxGLContext::SetupPixelFormat()
-{
+    wxMakeContextCurrent(GDK_WINDOW_XWINDOW(window), m_glContext);
 }
 
-void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) )
-{
-}
 
-wxPalette wxGLContext::CreateDefaultPalette()
-{
-    return wxNullPalette;
-}
+#if WXWIN_COMPATIBILITY_2_8
 
 //-----------------------------------------------------------------------------
-// "realize" from m_wxwindow
+// "realize" from m_wxwindow: used to create m_glContext implicitly
 //-----------------------------------------------------------------------------
 
 extern "C" {
 static gint
 gtk_glwindow_realized_callback( GtkWidget *WXUNUSED(widget), wxGLCanvas *win )
 {
-    if ( !win->m_glContext )
-    {
-        wxGLContext *share = win->m_sharedContext;
-        if ( !share && win->m_sharedContextOf )
-            share = win->m_sharedContextOf->GetContext();
-
-        win->m_glContext = new wxGLContext( TRUE, win, wxNullPalette, share );
-    }
+    win->GTKInitImplicitContext();
 
     return FALSE;
 }
 }
 
+#endif // WXWIN_COMPATIBILITY_2_8
+
 //-----------------------------------------------------------------------------
 // "map" from m_wxwindow
 //-----------------------------------------------------------------------------
@@ -217,15 +139,11 @@ extern "C" {
 static gint
 gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win )
 {
-    if (win->m_glContext/* && win->m_exposed*/)
-    {
-        wxPaintEvent event( win->GetId() );
-        event.SetEventObject( win );
-        win->GetEventHandler()->ProcessEvent( event );
+    wxPaintEvent event( win->GetId() );
+    event.SetEventObject( win );
+    win->GetEventHandler()->ProcessEvent( event );
 
-        win->m_exposed = false;
-        win->GetUpdateRegion().Clear();
-    }
+    win->GetUpdateRegion().Clear();
 
     return FALSE;
 }
@@ -242,8 +160,6 @@ gtk_glwindow_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_e
     if (g_isIdle)
         wxapp_install_idle_handler();
 
-    win->m_exposed = true;
-
     win->GetUpdateRegion().Union( gdk_event->area.x,
                                   gdk_event->area.y,
                                   gdk_event->area.width,
@@ -262,8 +178,6 @@ gtk_glwindow_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxG
     if (g_isIdle)
         wxapp_install_idle_handler();
 
-    win->m_exposed = true;
-
     win->GetUpdateRegion().Union( rect->x, rect->y,
                                   rect->width, rect->height );
 }
@@ -295,63 +209,82 @@ gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, w
 
 IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
 
-BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
-    EVT_SIZE(wxGLCanvas::OnSize)
-END_EVENT_TABLE()
-
-wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        int *attribList,
-                        const wxPalette& palette )
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       wxWindowID id,
+                       const int *attribList,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const wxPalette& palette)
+#if WXWIN_COMPATIBILITY_2_8
+    : m_createImplicitContext(false)
+#endif
 {
-    Create( parent, NULL, NULL, id, pos, size, style, name, attribList, palette );
+    Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
-wxGLCanvas::wxGLCanvas( wxWindow *parent,
-                        const wxGLContext *shared,
-                        wxWindowID id,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        int *attribList,
-                        const wxPalette& palette )
+#if WXWIN_COMPATIBILITY_2_8
+
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
+    : m_createImplicitContext(true)
 {
-    Create( parent, shared, NULL, id, pos, size, style, name, attribList, palette );
+    Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
-wxGLCanvas::wxGLCanvas( wxWindow *parent,
-                        const wxGLCanvas *shared,
-                        wxWindowID id,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        int *attribList,
-                        const wxPalette& palette )
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       const wxGLContext *shared,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
+    : m_createImplicitContext(true)
 {
-    Create( parent, NULL, shared, id, pos, size, style, name, attribList, palette );
+    m_sharedContext = wx_const_cast(wxGLContext *, shared);
+
+    Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
-bool wxGLCanvas::Create( wxWindow *parent,
-                         const wxGLContext *shared,
-                         const wxGLCanvas *shared_context_of,
-                         wxWindowID id,
-                         const wxPoint& pos, const wxSize& size,
-                         long style, const wxString& name,
-                         int *attribList,
-                         const wxPalette& palette)
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       const wxGLCanvas *shared,
+                       wxWindowID id,
+                       const wxPoint& pos, const wxSize& size,
+                       long style, const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette )
+    : m_createImplicitContext(true)
 {
-    m_sharedContext = (wxGLContext*)shared;  // const_cast
-    m_sharedContextOf = (wxGLCanvas*)shared_context_of;  // const_cast
-    m_glContext = (wxGLContext*) NULL;
+    m_sharedContextOf = wx_const_cast(wxGLCanvas *, shared);
+
+    Create(parent, id, pos, size, style, name, attribList, palette);
+}
 
-    m_exposed = false;
+#endif // WXWIN_COMPATIBILITY_2_8
+
+bool wxGLCanvas::Create(wxWindow *parent,
+                        wxWindowID id,
+                        const wxPoint& pos,
+                        const wxSize& size,
+                        long style,
+                        const wxString& name,
+                        const int *attribList,
+                        const wxPalette& palette)
+{
     m_noExpose = true;
     m_nativeSizeEvent = true;
     m_fbc = NULL;
     m_vi = NULL;
 
-    // to be sure the glx version is known
-    wxGLCanvas::QueryGLXVersion();
-
     if (wxGLCanvas::GetGLXVersion() >= 13)
     {
         // GLX >= 1.3 uses a GLXFBConfig
@@ -394,64 +327,45 @@ bool wxGLCanvas::Create( wxWindow *parent,
     GdkVisual *visual;
     GdkColormap *colormap;
 
-    // MR: This needs a fix for lower gtk+ versions too. Might need to rethink logic (FIXME)
-#if 0
-    if (!gtk_check_version(2,2,0))
-    {
-        wxWindow::Create( parent, id, pos, size, style, name );
-
-        m_glWidget = m_wxwindow;
+    visual = gdkx_visual_get( vi->visualid );
+    colormap = gdk_colormap_new( visual, TRUE );
 
-        GdkScreen *screen = gtk_widget_get_screen( m_glWidget );
-        colormap = gdk_screen_get_default_colormap(screen);
-        visual = gdk_colormap_get_visual(colormap);
+    gtk_widget_push_colormap( colormap );
+    gtk_widget_push_visual( visual );
 
-        if (GDK_VISUAL_XVISUAL(visual)->visualid != vi->visualid)
-        {
-            visual = gdk_x11_screen_lookup_visual( screen, vi->visualid );
-            colormap = gdk_colormap_new(visual, FALSE);
-        }
-
-        gtk_widget_set_colormap( m_glWidget, colormap );
-    }
-    else
-#endif
-    {
-        visual = gdkx_visual_get( vi->visualid );
-        colormap = gdk_colormap_new( visual, TRUE );
-
-        gtk_widget_push_colormap( colormap );
-        gtk_widget_push_visual( visual );
-
-        wxWindow::Create( parent, id, pos, size, style, name );
-        m_glWidget = m_wxwindow;
-    }
+    wxWindow::Create( parent, id, pos, size, style, name );
+    m_glWidget = m_wxwindow;
 
     gtk_pizza_set_clear( GTK_PIZZA(m_wxwindow), FALSE );
 
+#if WXWIN_COMPATIBILITY_2_8
     gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize",
-                            GTK_SIGNAL_FUNC(gtk_glwindow_realized_callback), (gpointer) this );
+                            GTK_SIGNAL_FUNC(gtk_glwindow_realized_callback), (gpointer) this);
+#endif // WXWIN_COMPATIBILITY_2_8
 
     gtk_signal_connect( GTK_OBJECT(m_wxwindow), "map",
-                            GTK_SIGNAL_FUNC(gtk_glwindow_map_callback), (gpointer) this );
+                            GTK_SIGNAL_FUNC(gtk_glwindow_map_callback), (gpointer) this);
 
     gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
-        GTK_SIGNAL_FUNC(gtk_glwindow_expose_callback), (gpointer)this );
+                            GTK_SIGNAL_FUNC(gtk_glwindow_expose_callback), (gpointer) this);
 
     gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw",
-        GTK_SIGNAL_FUNC(gtk_glwindow_draw_callback), (gpointer)this );
+                            GTK_SIGNAL_FUNC(gtk_glwindow_draw_callback), (gpointer) this);
 
     gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
-        GTK_SIGNAL_FUNC(gtk_glcanvas_size_callback), (gpointer)this );
+                            GTK_SIGNAL_FUNC(gtk_glcanvas_size_callback), (gpointer) this);
 
     gtk_widget_pop_visual();
+
     gtk_widget_pop_colormap();
 
+#if WXWIN_COMPATIBILITY_2_8
     // if our parent window is already visible, we had been realized before we
     // connected to the "realize" signal and hence our m_glContext hasn't been
     // initialized yet and we have to do it now
     if (GTK_WIDGET_REALIZED(m_wxwindow))
         gtk_glwindow_realized_callback( m_wxwindow, this );
+#endif // WXWIN_COMPATIBILITY_2_8
 
     if (GTK_WIDGET_MAPPED(m_wxwindow))
         gtk_glwindow_map_callback( m_wxwindow, this );
@@ -468,41 +382,40 @@ wxGLCanvas::~wxGLCanvas()
     XVisualInfo *vi = (XVisualInfo *) m_vi;
     if (vi && m_canFreeVi)
         XFree( vi );
-
-    delete m_glContext;
 }
 
-void* wxGLCanvas::ChooseGLVisual(int *attribList)
+void* wxGLCanvas::ChooseGLVisual(const int *attribList)
 {
     int data[512];
     GetGLAttribListFromWX( attribList, data );
-    attribList = (int*) data;
 
     Display *dpy = GDK_DISPLAY();
 
-    return glXChooseVisual( dpy, DefaultScreen(dpy), attribList );
+    return glXChooseVisual( dpy, DefaultScreen(dpy), data );
 }
 
-void* wxGLCanvas::ChooseGLFBC(int *attribList)
+void* wxGLCanvas::ChooseGLFBC(const int *attribList)
 {
     int data[512];
     GetGLAttribListFromWX( attribList, data );
-    attribList = (int*) data;
 
     int returned;
     return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()),
-                              attribList, &returned );
+                              data, &returned );
 }
 
 
-void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
+void
+wxGLCanvas::GetGLAttribListFromWX(const int *wx_attribList, int *gl_attribList)
 {
-    if (!wx_attribList)
+    if ( !wx_attribList )
     {
         if (wxGLCanvas::GetGLXVersion() >= 13)
-        // leave GLX >= 1.3 choose the default attributes
+        {
+            // leave GLX >= 1.3 choose the default attributes
             gl_attribList[0] = 0;
-        else
+        }
+        else // GLX < 1.3
         {
             int i = 0;
             // default settings if attriblist = 0
@@ -516,7 +429,7 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
             gl_attribList[i++] = None;
         }
     }
-    else
+    else // have non-default attributes
     {
         int arg=0, p=0;
         while( (wx_attribList[arg]!=0) && (p<510) )
@@ -525,8 +438,10 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
             {
                 case WX_GL_RGBA:
                     if (wxGLCanvas::GetGLXVersion() <= 12)
+                    {
                         // for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm)
                         gl_attribList[p++] = GLX_RGBA;
+                    }
                     break;
                 case WX_GL_BUFFER_SIZE:
                     gl_attribList[p++] = GLX_BUFFER_SIZE;
@@ -537,13 +452,7 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
                     gl_attribList[p++] = wx_attribList[arg++];
                     break;
                 case WX_GL_DOUBLEBUFFER:
-                    if (wxGLCanvas::GetGLXVersion() <= 12)
-                        gl_attribList[p++] = GLX_DOUBLEBUFFER;
-                    else
-                        // for GLX >= 1.3, GLX_DOUBLEBUFFER format is different (1 <=> True)
-                        // it seems this flag is useless for some hardware opengl implementation.
-                        // but for Mesa 6.2.1, this flag is used so don't ignore it.
-                        gl_attribList[p++] = GLX_DOUBLEBUFFER;
+                    gl_attribList[p++] = GLX_DOUBLEBUFFER;
                     gl_attribList[p++] = 1;
                     break;
                 case WX_GL_STEREO:
@@ -602,109 +511,88 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
     }
 }
 
-void wxGLCanvas::QueryGLXVersion()
+/* static */
+int wxGLCanvas::GetGLXVersion()
 {
-    if (m_glxVersion == 0)
+    static int s_glxVersion = 0;
+    if ( s_glxVersion == 0 )
     {
         // check the GLX version
         int glxMajorVer, glxMinorVer;
         bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer);
         wxASSERT_MSG( ok, _T("GLX version not found") );
         if (!ok)
-            m_glxVersion = 10; // 1.0 by default
+            s_glxVersion = 10; // 1.0 by default
         else
-            m_glxVersion = glxMajorVer*10 + glxMinorVer;
+            s_glxVersion = glxMajorVer*10 + glxMinorVer;
     }
-}
 
-int wxGLCanvas::GetGLXVersion()
-{
-    wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") );
-    return m_glxVersion;
+    return s_glxVersion;
 }
 
-
 void wxGLCanvas::SwapBuffers()
 {
-    if (m_glContext)
-        m_glContext->SwapBuffers();
-}
-
-void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
-{
-}
-
-void wxGLCanvas::SetCurrent()
-{
-    if (m_glContext)
-        m_glContext->SetCurrent();
-}
-
-void wxGLCanvas::SetColour( const wxChar *colour )
-{
-    if (m_glContext)
-        m_glContext->SetColour( colour );
+    GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window;
+    glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( window ) );
 }
 
 void wxGLCanvas::OnInternalIdle()
 {
-    if (m_glContext && m_exposed)
+    if (!m_updateRegion.IsEmpty())
     {
         wxPaintEvent event( GetId() );
         event.SetEventObject( this );
         GetEventHandler()->ProcessEvent( event );
 
-        m_exposed = false;
         GetUpdateRegion().Clear();
     }
 
     wxWindow::OnInternalIdle();
 }
 
+#if WXWIN_COMPATIBILITY_2_8
 
+void wxGLCanvas::GTKInitImplicitContext()
+{
+    if ( !m_glContext && m_createImplicitContext )
+    {
+        wxGLContext *share = m_sharedContext;
+        if ( !share && m_sharedContextOf )
+            share = m_sharedContextOf->m_glContext;
+
+        m_glContext = new wxGLContext(this, share);
+    }
+}
+
+#endif // WXWIN_COMPATIBILITY_2_8
 
 //---------------------------------------------------------------------------
 // wxGLApp
 //---------------------------------------------------------------------------
 
-IMPLEMENT_CLASS(wxGLApp, wxApp)
-
-wxGLApp::~wxGLApp()
-{
-    if (m_glFBCInfo)
-        XFree(m_glFBCInfo);
-    if (m_glVisualInfo)
-        XFree(m_glVisualInfo);
-}
-
-bool wxGLApp::InitGLVisual(int *attribList)
+bool wxGLApp::InitGLVisual(const int *attribList)
 {
-    wxGLCanvas::QueryGLXVersion();
-
-    if (wxGLCanvas::GetGLXVersion() >= 13)
+    if ( wxGLCanvas::GetGLXVersion() >= 13 )
     {
-        // GLX >= 1.3
         if (m_glFBCInfo)
             XFree(m_glFBCInfo);
         m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList);
 
-        if (m_glFBCInfo)
-        {
-            if (m_glVisualInfo)
-                XFree(m_glVisualInfo);
-            m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
-        }
-        return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL);
+        if ( !m_glFBCInfo )
+            return false;
+
+        if (m_glVisualInfo)
+            XFree(m_glVisualInfo);
+        m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
     }
-    else
+    else // GLX <= 1.2
     {
-        // GLX <= 1.2
         if (m_glVisualInfo)
             XFree(m_glVisualInfo);
         m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList);
-        return m_glVisualInfo != NULL;
     }
+
+    return m_glVisualInfo != NULL;
 }
 
-#endif
-    // wxUSE_GLCANVAS
+#endif // wxUSE_GLCANVAS
diff --git a/src/mac/carbon/glcanvas.cpp b/src/mac/carbon/glcanvas.cpp
index f1f70a4ecb..fb67a57594 100644
--- a/src/mac/carbon/glcanvas.cpp
+++ b/src/mac/carbon/glcanvas.cpp
@@ -1,4 +1,4 @@
-/////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
 // Name:        src/mac/carbon/glcanvas.cpp
 // Purpose:     wxGLCanvas, for using OpenGL with wxWidgets under Macintosh
 // Author:      Stefan Csomor
@@ -7,7 +7,15 @@
 // RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
 
 #include "wx/wxprec.h"
 
@@ -27,86 +35,69 @@
 
 #include "wx/mac/uma.h"
 
-// DLL options compatibility check:
-#include "wx/build.h"
-WX_CHECK_BUILD_OPTIONS("wxGL")
-
 #include "wx/mac/private.h"
 
-/*
-* GLContext implementation
-*/
+// ----------------------------------------------------------------------------
+// helper functions
+// ----------------------------------------------------------------------------
 
-wxGLContext::wxGLContext(
-                         AGLPixelFormat fmt, wxGLCanvas *win,
-                         const wxPalette& palette,
-                         const wxGLContext *other        /* for sharing display lists */
-                         )
+static void wxLogAGLError(const char *func)
 {
-    m_window = win;
+    const int err = aglGetError();
 
-    m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetTopLevelWindowRef()));
+    wxLogError(_("OpenGL function \"%s\" failed: %s (error %d)"),
+               func, aglErrorString(err), err);
+}
 
-    m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL);
-    wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") );
+// ============================================================================
+// implementation
+// ============================================================================
 
-    GLboolean b;
-    b = aglSetDrawable(m_glContext, m_drawable);
-    wxCHECK_RET( b, wxT("Couldn't bind OpenGl context") );
-    aglEnable(m_glContext , AGL_BUFFER_RECT ) ;
-    b = aglSetCurrentContext(m_glContext);
-    wxCHECK_RET( b, wxT("Couldn't activate OpenGl context") );
-}
+// ----------------------------------------------------------------------------
+// wxGLContext
+// ----------------------------------------------------------------------------
 
-wxGLContext::~wxGLContext()
+wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other)
 {
-    if (m_glContext)
-    {
-        aglSetCurrentContext(NULL);
-        aglDestroyContext(m_glContext);
-    }
+    m_aglContext = aglCreateContext(win->GetAGLPixelFormat(),
+                                    other ? other->m_aglContext : NULL);
+    if ( !m_aglContext )
+        wxLogAGLError("aglCreateContext");
+
+    return;
+    if ( !aglEnable(m_aglContext, AGL_BUFFER_RECT) )
+        wxLogAGLError("aglEnable(AGL_BUFFER_RECT)");
 }
 
-void wxGLContext::SwapBuffers()
+wxGLContext::~wxGLContext()
 {
-    if (m_glContext)
+    if ( m_aglContext )
     {
-        aglSwapBuffers(m_glContext);
+        // it's ok to pass the current context to this function
+        if ( !aglDestroyContext(m_aglContext) )
+            wxLogAGLError("aglDestroyContext");
     }
 }
 
-void wxGLContext::SetCurrent()
+void wxGLContext::SetCurrent(const wxGLCanvas& win) const
 {
-    if (m_glContext)
-    {
-        aglSetCurrentContext(m_glContext);
-    }
-}
+    if ( !m_aglContext )
+        return;
 
-void wxGLContext::Update()
-{
-    if (m_glContext)
-    {
-        aglUpdateContext(m_glContext);
-    }
-}
+    AGLDrawable drawable = (AGLDrawable)UMAGetWindowPort(
+                                MAC_WXHWND(win.MacGetTopLevelWindowRef()));
+    if ( !aglSetDrawable(m_aglContext, drawable) )
+        wxLogAGLError("aglSetDrawable");
 
-void wxGLContext::SetColour(const wxChar *colour)
-{
-    wxColour col = wxTheColourDatabase->Find(colour);
-    if (col.Ok())
-    {
-        float r = (float)(col.Red()/256.0);
-        float g = (float)(col.Green()/256.0);
-        float b = (float)(col.Blue()/256.0);
-        glColor3f( r, g, b);
-    }
-}
+    if ( !aglSetCurrentContext(m_aglContext) )
+        wxLogAGLError("aglSetCurrentContext");
 
+    wx_const_cast(wxGLCanvas&, win).SetViewport();
+}
 
-/*
-* wxGLCanvas implementation
-*/
+// ----------------------------------------------------------------------------
+// wxGLCanvas
+// ----------------------------------------------------------------------------
 
 IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
 
@@ -114,96 +105,173 @@ BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
     EVT_SIZE(wxGLCanvas::OnSize)
 END_EVENT_TABLE()
 
-wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id,
-                       const wxPoint& pos, const wxSize& size, long style, const wxString& name,
-                       int *attribList, const wxPalette& palette)
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       wxWindowID id,
+                       const int *attribList,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const wxPalette& palette)
 {
-    Create(parent, NULL, id, pos, size, style, name, attribList, palette);
+    Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
-wxGLCanvas::wxGLCanvas( wxWindow *parent,
-                       const wxGLContext *shared, wxWindowID id,
-                       const wxPoint& pos, const wxSize& size, long style, const wxString& name,
-                       int *attribList, const wxPalette& palette )
+#if WXWIN_COMPATIBILITY_2_8
+
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
 {
-    Create(parent, shared, id, pos, size, style, name, attribList, palette);
+    if ( Create(parent, id, pos, size, style, name, attribList, palette) )
+        m_glContext = new wxGLContext(this);
 }
 
-wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID id,
-                       const wxPoint& pos, const wxSize& size, long style, const wxString& name,
-                       int *attribList, const wxPalette& palette )
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       const wxGLContext *shared,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
 {
-    Create(parent, shared ? shared->GetContext() : NULL, id, pos, size, style, name, attribList, palette);
+    if ( Create(parent, id, pos, size, style, name, attribList, palette) )
+        m_glContext = new wxGLContext(this, shared);
 }
 
-wxGLCanvas::~wxGLCanvas()
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       const wxGLCanvas *shared,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
 {
-    if (m_glContext != NULL) {
-        delete m_glContext;
-        m_glContext = NULL;
-    }
+    if ( Create(parent, id, pos, size, style, name, attribList, palette) )
+        m_glContext = new wxGLContext(this, shared ? shared->m_glContext : NULL);
 }
 
+#endif // WXWIN_COMPATIBILITY_2_8
+
 static AGLPixelFormat ChoosePixelFormat(const int *attribList)
 {
     GLint data[512];
-    GLint defaultAttribs[] = { AGL_RGBA,
+    const GLint defaultAttribs[] =
+    {
+        AGL_RGBA,
         AGL_DOUBLEBUFFER,
-        AGL_MINIMUM_POLICY,
+        AGL_MINIMUM_POLICY, // never choose less than requested
         AGL_DEPTH_SIZE, 1,  // use largest available depth buffer
         AGL_RED_SIZE, 1,
         AGL_GREEN_SIZE, 1,
         AGL_BLUE_SIZE, 1,
         AGL_ALPHA_SIZE, 0,
-        AGL_NONE };
-    GLint *attribs;
-    if (!attribList)
+        AGL_NONE
+    };
+
+    const GLint *attribs;
+    if ( !attribList )
     {
         attribs = defaultAttribs;
     }
     else
     {
-        int arg=0, p=0;
-
+        unsigned p = 0;
         data[p++] = AGL_MINIMUM_POLICY; // make _SIZE tags behave more like GLX
-        while( (attribList[arg]!=0) && (p<512) )
+
+        for ( unsigned arg = 0; attribList[arg] !=0 && p < WXSIZEOF(data); )
         {
-            switch( attribList[arg++] )
+            switch ( attribList[arg++] )
             {
-            case WX_GL_RGBA: data[p++] = AGL_RGBA; break;
-            case WX_GL_BUFFER_SIZE:
-                data[p++]=AGL_BUFFER_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_LEVEL:
-                data[p++]=AGL_LEVEL; data[p++]=attribList[arg++]; break;
-            case WX_GL_DOUBLEBUFFER: data[p++] = AGL_DOUBLEBUFFER; break;
-            case WX_GL_STEREO: data[p++] = AGL_STEREO; break;
-            case WX_GL_AUX_BUFFERS:
-                data[p++]=AGL_AUX_BUFFERS; data[p++]=attribList[arg++]; break;
-            case WX_GL_MIN_RED:
-                data[p++]=AGL_RED_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_MIN_GREEN:
-                data[p++]=AGL_GREEN_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_MIN_BLUE:
-                data[p++]=AGL_BLUE_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_MIN_ALPHA:
-                data[p++]=AGL_ALPHA_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_DEPTH_SIZE:
-                data[p++]=AGL_DEPTH_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_STENCIL_SIZE:
-                data[p++]=AGL_STENCIL_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_MIN_ACCUM_RED:
-                data[p++]=AGL_ACCUM_RED_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_MIN_ACCUM_GREEN:
-                data[p++]=AGL_ACCUM_GREEN_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_MIN_ACCUM_BLUE:
-                data[p++]=AGL_ACCUM_BLUE_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_MIN_ACCUM_ALPHA:
-                data[p++]=AGL_ACCUM_ALPHA_SIZE; data[p++]=attribList[arg++]; break;
-            default:
-                break;
+                case WX_GL_RGBA:
+                    data[p++] = AGL_RGBA;
+                    break;
+
+                case WX_GL_BUFFER_SIZE:
+                    data[p++] = AGL_BUFFER_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_LEVEL:
+                    data[p++]=AGL_LEVEL;
+                    data[p++]=attribList[arg++];
+                    break;
+
+                case WX_GL_DOUBLEBUFFER:
+                    data[p++] = AGL_DOUBLEBUFFER;
+                    break;
+
+                case WX_GL_STEREO:
+                    data[p++] = AGL_STEREO;
+                    break;
+
+                case WX_GL_AUX_BUFFERS:
+                    data[p++] = AGL_AUX_BUFFERS;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_MIN_RED:
+                    data[p++] = AGL_RED_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_MIN_GREEN:
+                    data[p++] = AGL_GREEN_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_MIN_BLUE:
+                    data[p++] = AGL_BLUE_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_MIN_ALPHA:
+                    data[p++] = AGL_ALPHA_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_DEPTH_SIZE:
+                    data[p++] = AGL_DEPTH_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_STENCIL_SIZE:
+                    data[p++] = AGL_STENCIL_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_MIN_ACCUM_RED:
+                    data[p++] = AGL_ACCUM_RED_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_MIN_ACCUM_GREEN:
+                    data[p++] = AGL_ACCUM_GREEN_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_MIN_ACCUM_BLUE:
+                    data[p++] = AGL_ACCUM_BLUE_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
+
+                case WX_GL_MIN_ACCUM_ALPHA:
+                    data[p++] = AGL_ACCUM_ALPHA_SIZE;
+                    data[p++] = attribList[arg++];
+                    break;
             }
         }
-        data[p] = 0;
+
+        data[p] = AGL_NONE;
 
         attribs = data;
     }
@@ -211,186 +279,142 @@ static AGLPixelFormat ChoosePixelFormat(const int *attribList)
     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)
+bool wxGLCanvas::Create(wxWindow *parent,
+                        wxWindowID id,
+                        const wxPoint& pos,
+                        const wxSize& size,
+                        long style,
+                        const wxString& name,
+                        const int *attribList,
+                        const wxPalette& WXUNUSED(palette))
 {
-    m_macCanvasIsShown = false ;
-    m_glContext = 0 ;
-    wxWindow::Create( parent, id, pos, size, style, name );
+    m_needsUpdate = false;
+    m_macCanvasIsShown = false;
 
-    AGLPixelFormat fmt = ChoosePixelFormat(attribList);
-    wxCHECK_MSG( fmt, false, wxT("Couldn't create OpenGl pixel format") );
+    m_aglFormat = ChoosePixelFormat(attribList);
+    if ( !m_aglFormat )
+        return false;
 
-    m_glContext = new wxGLContext(fmt, this, palette, shared);
-    m_macCanvasIsShown = true ;
-    aglDestroyPixelFormat(fmt);
+    if ( !wxWindow::Create(parent, id, pos, size, style, name) )
+        return false;
+
+    m_macCanvasIsShown = true;
 
     return true;
 }
 
-void wxGLCanvas::SwapBuffers()
+wxGLCanvas::~wxGLCanvas()
 {
-    if (m_glContext)
-        m_glContext->SwapBuffers();
+    if ( m_aglFormat )
+        aglDestroyPixelFormat(m_aglFormat);
 }
 
-void wxGLCanvas::UpdateContext()
+void wxGLCanvas::SwapBuffers()
 {
-    if (m_glContext)
-        m_glContext->Update();
+    AGLContext context = aglGetCurrentContext();
+    wxCHECK_RET( context, _T("should have current context") );
+
+    aglSwapBuffers(context);
 }
 
 void wxGLCanvas::SetViewport()
 {
-    // viewport is initially set to entire port
-    // adjust glViewport to just this window
-    int x = 0 ;
-    int y = 0 ;
+    if ( !m_needsUpdate )
+        return;
 
-    wxWindow* iter = this ;
-    while( iter->GetParent() )
-    {
-        iter = iter->GetParent() ;
-    }
+    m_needsUpdate = false;
+
+    AGLContext context = aglGetCurrentContext();
+    if ( !context )
+        return;
+
+    // viewport is initially set to entire port, adjust it to just this window
+    int x = 0,
+        y = 0;
+    MacClientToRootWindow(&x , &y);
+
+    int width, height;
+    GetClientSize(&width, &height);
+
+    Rect bounds;
+    GetWindowPortBounds(MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds);
 
-    if ( iter && iter->IsTopLevel() )
-    {
-        MacClientToRootWindow( &x , &y ) ;
-        int width, height;
-        GetClientSize(& width, & height);
-        Rect bounds ;
 #if 0
-		// TODO in case we adopt point vs pixel coordinates, this will make the conversion
-        GetWindowPortBounds( MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds ) ;
-        HIRect hiRect = CGRectMake( x, y, width, height ) ;
-        HIRectConvert( &hiRect, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL) ;
-        HIRect hiBounds = CGRectMake( 0, 0, bounds.right - bounds.left , bounds.bottom - bounds.top ) ;
-        HIRectConvert( &hiBounds, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL) ;
-        GLint parms[4] ;
-        parms[0] = hiRect.origin.x ;
-        parms[1] = hiBounds.size.height - (hiRect.origin.y + hiRect.size.height) ;
-        parms[2] = hiRect.size.width ;
-        parms[3] = hiRect.size.height ;
+    // TODO in case we adopt point vs pixel coordinates, this will make the conversion
+    HIRect hiRect = CGRectMake( x, y, width, height );
+    HIRectConvert( &hiRect, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL);
+    HIRect hiBounds = CGRectMake( 0, 0, bounds.right - bounds.left , bounds.bottom - bounds.top );
+    HIRectConvert( &hiBounds, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL);
+    GLint parms[4];
+    parms[0] = hiRect.origin.x;
+    parms[1] = hiBounds.size.height - (hiRect.origin.y + hiRect.size.height);
+    parms[2] = hiRect.size.width;
+    parms[3] = hiRect.size.height;
 #else
-        GetWindowPortBounds( MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds ) ;
-        GLint parms[4] ;
-        parms[0] = x ;
-        parms[1] = bounds.bottom - bounds.top - ( y + height ) ;
-        parms[2] = width ;
-        parms[3] = height ;
+    GLint parms[4];
+    parms[0] = x;
+    parms[1] = bounds.bottom - bounds.top - ( y + height );
+    parms[2] = width;
+    parms[3] = height;
 #endif
-        if ( !m_macCanvasIsShown )
-            parms[0] += 20000 ;
-        aglSetInteger( m_glContext->m_glContext , AGL_BUFFER_RECT , parms ) ;
-   }
-}
 
-void wxGLCanvas::OnSize(wxSizeEvent& event)
-{
-    MacUpdateView() ;
-}
+    // move the buffer rect out of sight if we're hidden
+    if ( !m_macCanvasIsShown )
+        parms[0] += 20000;
 
-void wxGLCanvas::MacUpdateView()
-{
-    if (m_glContext)
+    if ( !aglSetInteger(context, AGL_BUFFER_RECT, parms) )
     {
-        UpdateContext();
-        m_glContext->SetCurrent();
-        SetViewport();
+        wxLogAGLError("aglSetInteger(AGL_BUFFER_RECT)");
     }
 }
 
-void wxGLCanvas::MacSuperChangedPosition()
-{
-    MacUpdateView() ;
-    wxWindow::MacSuperChangedPosition() ;
-}
-
-void wxGLCanvas::MacTopLevelWindowChangedPosition()
+void wxGLCanvas::OnSize(wxSizeEvent& event)
 {
-    MacUpdateView() ;
-    wxWindow::MacTopLevelWindowChangedPosition() ;
+    MacUpdateView();
+    event.Skip();
 }
 
-void wxGLCanvas::SetCurrent()
+void wxGLCanvas::MacUpdateView()
 {
-    if (m_glContext)
-    {
-        m_glContext->SetCurrent();
-    }
+    m_needsUpdate = true;
+    Refresh(false);
 }
 
-void wxGLCanvas::SetColour(const wxChar *colour)
+void wxGLCanvas::MacSuperChangedPosition()
 {
-    if (m_glContext)
-        m_glContext->SetColour(colour);
+    MacUpdateView();
+    wxWindow::MacSuperChangedPosition();
 }
 
-bool wxGLCanvas::Show(bool show)
+void wxGLCanvas::MacTopLevelWindowChangedPosition()
 {
-    if ( !wxWindow::Show( show ) )
-        return false ;
-/*
-    if ( !show )
-    {
-        if ( m_macCanvasIsShown )
-        {
-            m_macCanvasIsShown = false ;
-            SetViewport() ;
-        }
-    }
-    else
-    {
-        if ( m_peer->IsVisible()&& !m_macCanvasIsShown )
-        {
-            m_macCanvasIsShown = true ;
-            SetViewport() ;
-        }
-    }
-*/
-    return true ;
+    MacUpdateView();
+    wxWindow::MacTopLevelWindowChangedPosition();
 }
 
 void wxGLCanvas::MacVisibilityChanged()
 {
-    if ( !MacIsReallyShown() )
+    if ( MacIsReallyShown() != m_macCanvasIsShown )
     {
-        if ( m_macCanvasIsShown )
-        {
-            m_macCanvasIsShown = false ;
-            SetViewport() ;
-        }
+        m_macCanvasIsShown = !m_macCanvasIsShown;
+        MacUpdateView();
     }
-    else
-    {
-        if ( !m_macCanvasIsShown )
-        {
-            m_macCanvasIsShown = true ;
-            SetViewport() ;
-        }
-    }
-    wxWindowMac::MacVisibilityChanged() ;
+
+    wxWindowMac::MacVisibilityChanged();
 }
 
-//---------------------------------------------------------------------------
+// ----------------------------------------------------------------------------
 // wxGLApp
-//---------------------------------------------------------------------------
+// ----------------------------------------------------------------------------
 
-IMPLEMENT_CLASS(wxGLApp, wxApp)
-
-bool wxGLApp::InitGLVisual(int *attribList)
+bool wxGLApp::InitGLVisual(const int *attribList)
 {
     AGLPixelFormat fmt = ChoosePixelFormat(attribList);
-    if (fmt != NULL) {
-        aglDestroyPixelFormat(fmt);
-        return true;
-    } else
+    if ( !fmt )
         return false;
-}
 
-wxGLApp::~wxGLApp(void)
-{
+    aglDestroyPixelFormat(fmt);
+    return true;
 }
 
 #endif // wxUSE_GLCANVAS
diff --git a/src/msw/glcanvas.cpp b/src/msw/glcanvas.cpp
index 39e37c4f84..a95e48a54b 100644
--- a/src/msw/glcanvas.cpp
+++ b/src/msw/glcanvas.cpp
@@ -9,6 +9,14 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
 #include "wx/wxprec.h"
 
 #if defined(__BORLANDC__)
@@ -18,8 +26,6 @@
 #if wxUSE_GLCANVAS
 
 #ifndef WX_PRECOMP
-    #include "wx/frame.h"
-    #include "wx/settings.h"
     #include "wx/intl.h"
     #include "wx/log.h"
     #include "wx/app.h"
@@ -28,18 +34,22 @@
 
 #include "wx/msw/private.h"
 
-// DLL options compatibility check:
-#include "wx/build.h"
-WX_CHECK_BUILD_OPTIONS("wxGL")
-
 #include "wx/glcanvas.h"
 
-#if GL_EXT_vertex_array
+// from src/msw/window.cpp
+LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
+                                   WPARAM wParam, LPARAM lParam);
+
+#ifdef GL_EXT_vertex_array
     #define WXUNUSED_WITHOUT_GL_EXT_vertex_array(name) name
 #else
     #define WXUNUSED_WITHOUT_GL_EXT_vertex_array(name) WXUNUSED(name)
 #endif
 
+// ----------------------------------------------------------------------------
+// libraries
+// ----------------------------------------------------------------------------
+
 /*
   The following two compiler directives are specific to the Microsoft Visual
   C++ family of compilers
@@ -62,12 +72,16 @@ WX_CHECK_BUILD_OPTIONS("wxGL")
 #  pragma comment( lib, "glu32" )
 #endif
 
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
 
 static const wxChar *wxGLCanvasClassName = wxT("wxGLCanvasClass");
 static const wxChar *wxGLCanvasClassNameNoRedraw = wxT("wxGLCanvasClassNR");
 
-LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
-                                   WPARAM wParam, LPARAM lParam);
+// ============================================================================
+// implementation
+// ============================================================================
 
 // ----------------------------------------------------------------------------
 // wxGLModule is responsible for unregistering wxGLCanvasClass Windows class
@@ -100,29 +114,12 @@ bool wxGLModule::ms_registeredGLClasses = false;
 /* static */
 bool wxGLModule::RegisterClasses()
 {
-    if (ms_registeredGLClasses)
+    if ( ms_registeredGLClasses )
         return true;
 
     // We have to register a special window class because we need the CS_OWNDC
-    // style for GLCanvas.
-
-  /*
-  From Angel Popov <jumpo@bitex.com>
-
-  Here are two snips from a dicussion in the OpenGL Gamedev list that explains
-  how this problem can be fixed:
-
-  "There are 5 common DCs available in Win95. These are aquired when you call
-  GetDC or GetDCEx from a window that does _not_ have the OWNDC flag.
-  OWNDC flagged windows do not get their DC from the common DC pool, the issue
-  is they require 800 bytes each from the limited 64Kb local heap for GDI."
-
-  "The deal is, if you hold onto one of the 5 shared DC's too long (as GL apps
-  do), Win95 will actually "steal" it from you.  MakeCurrent fails,
-  apparently, because Windows re-assigns the HDC to a different window.  The
-  only way to prevent this, the only reliable means, is to set CS_OWNDC."
-  */
-
+    // style for GLCanvas: some OpenGL drivers are buggy and don't work with
+    // windows without this style
     WNDCLASS wndclass;
 
     // the fields which are common to all classes
@@ -179,140 +176,82 @@ void wxGLModule::UnregisterClasses()
     }
 }
 
-/*
- * GLContext implementation
- */
+// ----------------------------------------------------------------------------
+// wxGLContext
+// ----------------------------------------------------------------------------
 
 IMPLEMENT_CLASS(wxGLContext, wxObject)
 
-wxGLContext::wxGLContext(wxGLCanvas* win, const wxGLContext* other /* for sharing display lists */)
+wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext* other)
 {
-  m_glContext = wglCreateContext((HDC) win->GetHDC());
-  wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") );
+    m_glContext = wglCreateContext(win->GetHDC());
+    wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") );
 
-  if( other != 0 )
-    wglShareLists( other->m_glContext, m_glContext );
+    if ( other )
+    {
+        if ( !wglShareLists(other->m_glContext, m_glContext) )
+            wxLogLastError(_T("wglShareLists"));
+    }
 }
 
 wxGLContext::~wxGLContext()
 {
-    // If this context happens to be the current context, wglDeleteContext() makes it un-current first.
+    // note that it's ok to delete the context even if it's the current one
     wglDeleteContext(m_glContext);
 }
 
 void wxGLContext::SetCurrent(const wxGLCanvas& win) const
 {
-    wglMakeCurrent((HDC) win.GetHDC(), m_glContext);
+    if ( !wglMakeCurrent(win.GetHDC(), m_glContext) )
+    {
+        wxLogLastError(_T("wglMakeCurrent"));
+    }
 }
 
-
-/*
- * wxGLCanvas implementation
- */
+// ============================================================================
+// wxGLCanvas
+// ============================================================================
 
 IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
 
 BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
-    EVT_SIZE(wxGLCanvas::OnSize)
     EVT_PALETTE_CHANGED(wxGLCanvas::OnPaletteChanged)
     EVT_QUERY_NEW_PALETTE(wxGLCanvas::OnQueryNewPalette)
 END_EVENT_TABLE()
 
-wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id, int *attribList,
-    const wxPoint& pos, const wxSize& size, long style,
-    const wxString& name, const wxPalette& palette) : wxWindow()
-{
-    m_glContext = NULL;
-
-    if (Create(parent, id, pos, size, style, name))
-    {
-        SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
-    }
-
-    m_hDC = (WXHDC) ::GetDC((HWND) GetHWND());
-
-    SetupPixelFormat(attribList);
-    SetupPalette(palette);
-
-    // This ctor does *not* create an instance of wxGLContext,
-    // m_glContext intentionally remains NULL.
-}
-
-wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id,
-    const wxPoint& pos, const wxSize& size, long style, const wxString& name,
-    int *attribList, const wxPalette& palette) : wxWindow()
-{
-  m_glContext = (wxGLContext*) NULL;
-
-  bool ret = Create(parent, id, pos, size, style, name);
-
-  if ( ret )
-  {
-    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
-  }
-
-  m_hDC = (WXHDC) ::GetDC((HWND) GetHWND());
-
-  SetupPixelFormat(attribList);
-  SetupPalette(palette);
-
-  m_glContext = new wxGLContext(this);
-}
+// ----------------------------------------------------------------------------
+// wxGLCanvas construction
+// ----------------------------------------------------------------------------
 
-wxGLCanvas::wxGLCanvas( wxWindow *parent,
-              const wxGLContext *shared, wxWindowID id,
-              const wxPoint& pos, const wxSize& size, long style, const wxString& name,
-              int *attribList, const wxPalette& palette )
-  : wxWindow()
+void wxGLCanvas::Init()
 {
-  m_glContext = (wxGLContext*) NULL;
-
-  bool ret = Create(parent, id, pos, size, style, name);
-
-  if ( ret )
-  {
-    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
-  }
-
-  m_hDC = (WXHDC) ::GetDC((HWND) GetHWND());
-
-  SetupPixelFormat(attribList);
-  SetupPalette(palette);
-
-  m_glContext = new wxGLContext(this, shared);
+#if WXWIN_COMPATIBILITY_2_8
+    m_glContext = NULL;
+#endif
+    m_hDC = NULL;
 }
 
-// Not very useful for wxMSW, but this is to be wxGTK compliant
-
-wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID id,
-                        const wxPoint& pos, const wxSize& size, long style, const wxString& name,
-                        int *attribList, const wxPalette& palette ):
-  wxWindow()
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       wxWindowID id,
+                       const int *attribList,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const wxPalette& palette)
 {
-  m_glContext = (wxGLContext*) NULL;
-
-  bool ret = Create(parent, id, pos, size, style, name);
-
-  if ( ret )
-  {
-    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
-  }
-
-  m_hDC = (WXHDC) ::GetDC((HWND) GetHWND());
+    Init();
 
-  SetupPixelFormat(attribList);
-  SetupPalette(palette);
-
-  wxGLContext *sharedContext=0;
-  if (shared) sharedContext=shared->GetContext();
-  m_glContext = new wxGLContext(this, sharedContext);
+    (void)Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
 wxGLCanvas::~wxGLCanvas()
 {
-  delete m_glContext;
+#if WXWIN_COMPATIBILITY_2_8
+    delete m_glContext;
+#endif
 
-  ::ReleaseDC((HWND) GetHWND(), (HDC) m_hDC);
+    ::ReleaseDC(GetHwnd(), m_hDC);
 }
 
 // Replaces wxWindow::Create functionality, since we need to use a different
@@ -322,7 +261,9 @@ bool wxGLCanvas::Create(wxWindow *parent,
                         const wxPoint& pos,
                         const wxSize& size,
                         long style,
-                        const wxString& name)
+                        const wxString& name,
+                        const int *attribList,
+                        const wxPalette& palette)
 {
     wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") );
 
@@ -338,170 +279,246 @@ bool wxGLCanvas::Create(wxWindow *parent,
 
     parent->AddChild(this);
 
-    DWORD msflags = 0;
-
     /*
        A general rule with OpenGL and Win32 is that any window that will have a
        HGLRC built for it must have two flags:  WS_CLIPCHILDREN & WS_CLIPSIBLINGS.
        You can find references about this within the knowledge base and most OpenGL
        books that contain the wgl function descriptions.
      */
-
     WXDWORD exStyle = 0;
-    msflags |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
-    msflags |= MSWGetStyle(style, & exStyle) ;
+    DWORD msflags = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
+    msflags |= MSWGetStyle(style, &exStyle);
+
+    if ( !MSWCreate(wxGLCanvasClassName, NULL, pos, size, msflags, exStyle) )
+        return false;
 
-    return MSWCreate(wxGLCanvasClassName, NULL, pos, size, msflags, exStyle);
+    m_hDC = ::GetDC(GetHwnd());
+    if ( !m_hDC )
+        return false;
+
+    if ( !DoSetup(attribList) )
+        return false;
+
+#if wxUSE_PALETTE
+    if ( !SetupPalette(palette) )
+        return false;
+#else // !wxUSE_PALETTE
+    wxUnusedVar(palette);
+#endif // wxUSE_PALETTE/!wxUSE_PALETTE
+
+    return true;
+}
+
+// ----------------------------------------------------------------------------
+// operations
+// ----------------------------------------------------------------------------
+
+void wxGLCanvas::SwapBuffers()
+{
+    if ( !::SwapBuffers(m_hDC) )
+        wxLogLastError(_T("SwapBuffers"));
 }
 
-static void AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, int *attribList)
+// ----------------------------------------------------------------------------
+// pixel format stuff
+// ----------------------------------------------------------------------------
+
+static void
+AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, const int *attribList)
 {
-  if (attribList) {
+    if ( !attribList )
+        return;
+
     pfd.dwFlags &= ~PFD_DOUBLEBUFFER;
     pfd.iPixelType = PFD_TYPE_COLORINDEX;
     pfd.cColorBits = 0;
     int arg=0;
 
-    while( (attribList[arg]!=0) )
+    while ( attribList[arg] )
     {
-      switch( attribList[arg++] )
-      {
-        case WX_GL_RGBA:
-          pfd.iPixelType = PFD_TYPE_RGBA;
-          break;
-        case WX_GL_BUFFER_SIZE:
-          pfd.cColorBits = (BYTE)attribList[arg++];
-          break;
-        case WX_GL_LEVEL:
-          // this member looks like it may be obsolete
-          if (attribList[arg] > 0) {
-            pfd.iLayerType = (BYTE)PFD_OVERLAY_PLANE;
-          } else if (attribList[arg] < 0) {
-            pfd.iLayerType = (BYTE)PFD_UNDERLAY_PLANE;
-          } else {
-            pfd.iLayerType = (BYTE)PFD_MAIN_PLANE;
-          }
-          arg++;
-          break;
-        case WX_GL_DOUBLEBUFFER:
-          pfd.dwFlags |= PFD_DOUBLEBUFFER;
-          break;
-        case WX_GL_STEREO:
-          pfd.dwFlags |= PFD_STEREO;
-          break;
-        case WX_GL_AUX_BUFFERS:
-          pfd.cAuxBuffers = (BYTE)attribList[arg++];
-          break;
-        case WX_GL_MIN_RED:
-          pfd.cColorBits = (BYTE)(pfd.cColorBits + (pfd.cRedBits = (BYTE)attribList[arg++]));
-          break;
-        case WX_GL_MIN_GREEN:
-          pfd.cColorBits = (BYTE)(pfd.cColorBits + (pfd.cGreenBits = (BYTE)attribList[arg++]));
-          break;
-        case WX_GL_MIN_BLUE:
-          pfd.cColorBits = (BYTE)(pfd.cColorBits + (pfd.cBlueBits = (BYTE)attribList[arg++]));
-          break;
-        case WX_GL_MIN_ALPHA:
-          // doesn't count in cColorBits
-          pfd.cAlphaBits = (BYTE)attribList[arg++];
-          break;
-        case WX_GL_DEPTH_SIZE:
-          pfd.cDepthBits = (BYTE)attribList[arg++];
-          break;
-        case WX_GL_STENCIL_SIZE:
-          pfd.cStencilBits = (BYTE)attribList[arg++];
-          break;
-        case WX_GL_MIN_ACCUM_RED:
-          pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumRedBits = (BYTE)attribList[arg++]));
-          break;
-        case WX_GL_MIN_ACCUM_GREEN:
-          pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumGreenBits = (BYTE)attribList[arg++]));
-          break;
-        case WX_GL_MIN_ACCUM_BLUE:
-          pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumBlueBits = (BYTE)attribList[arg++]));
-          break;
-        case WX_GL_MIN_ACCUM_ALPHA:
-          pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumAlphaBits = (BYTE)attribList[arg++]));
-          break;
-        default:
-          break;
-      }
+        switch ( attribList[arg++] )
+        {
+            case WX_GL_RGBA:
+                pfd.iPixelType = PFD_TYPE_RGBA;
+                break;
+            case WX_GL_BUFFER_SIZE:
+                pfd.cColorBits = attribList[arg++];
+                break;
+            case WX_GL_LEVEL:
+                // this member looks like it may be obsolete
+                if ( attribList[arg] > 0 )
+                    pfd.iLayerType = PFD_OVERLAY_PLANE;
+                else if ( attribList[arg] < 0 )
+                    pfd.iLayerType = (BYTE)PFD_UNDERLAY_PLANE;
+                else
+                    pfd.iLayerType = PFD_MAIN_PLANE;
+                arg++;
+                break;
+            case WX_GL_DOUBLEBUFFER:
+                pfd.dwFlags |= PFD_DOUBLEBUFFER;
+                break;
+            case WX_GL_STEREO:
+                pfd.dwFlags |= PFD_STEREO;
+                break;
+            case WX_GL_AUX_BUFFERS:
+                pfd.cAuxBuffers = attribList[arg++];
+                break;
+            case WX_GL_MIN_RED:
+                pfd.cColorBits = (pfd.cColorBits +
+                        (pfd.cRedBits = attribList[arg++]));
+                break;
+            case WX_GL_MIN_GREEN:
+                pfd.cColorBits = (pfd.cColorBits +
+                        (pfd.cGreenBits = attribList[arg++]));
+                break;
+            case WX_GL_MIN_BLUE:
+                pfd.cColorBits = (pfd.cColorBits +
+                        (pfd.cBlueBits = attribList[arg++]));
+                break;
+            case WX_GL_MIN_ALPHA:
+                // doesn't count in cColorBits
+                pfd.cAlphaBits = attribList[arg++];
+                break;
+            case WX_GL_DEPTH_SIZE:
+                pfd.cDepthBits = attribList[arg++];
+                break;
+            case WX_GL_STENCIL_SIZE:
+                pfd.cStencilBits = attribList[arg++];
+                break;
+            case WX_GL_MIN_ACCUM_RED:
+                pfd.cAccumBits = (pfd.cAccumBits +
+                        (pfd.cAccumRedBits = attribList[arg++]));
+                break;
+            case WX_GL_MIN_ACCUM_GREEN:
+                pfd.cAccumBits = (pfd.cAccumBits +
+                        (pfd.cAccumGreenBits = attribList[arg++]));
+                break;
+            case WX_GL_MIN_ACCUM_BLUE:
+                pfd.cAccumBits = (pfd.cAccumBits +
+                        (pfd.cAccumBlueBits = attribList[arg++]));
+                break;
+            case WX_GL_MIN_ACCUM_ALPHA:
+                pfd.cAccumBits = (pfd.cAccumBits +
+                        (pfd.cAccumAlphaBits = attribList[arg++]));
+                break;
+        }
     }
-  }
 }
 
-void wxGLCanvas::SetupPixelFormat(int *attribList) // (HDC hDC)
+/* static */
+int
+wxGLCanvas::ChooseMatchingPixelFormat(HDC hdc,
+                                      const int *attribList,
+                                      PIXELFORMATDESCRIPTOR *ppfd)
 {
-  PIXELFORMATDESCRIPTOR pfd = {
-        sizeof(PIXELFORMATDESCRIPTOR),    /* size */
-        1,                /* version */
+    // default neutral pixel format
+    PIXELFORMATDESCRIPTOR pfd =
+    {
+        sizeof(PIXELFORMATDESCRIPTOR),  // size
+        1,                              // version
         PFD_SUPPORT_OPENGL |
         PFD_DRAW_TO_WINDOW |
-        PFD_DOUBLEBUFFER,        /* support double-buffering */
-        PFD_TYPE_RGBA,            /* color type */
-        16,                /* preferred color depth */
-        0, 0, 0, 0, 0, 0,        /* color bits (ignored) */
-        0,                /* no alpha buffer */
-        0,                /* alpha bits (ignored) */
-        0,                /* no accumulation buffer */
-        0, 0, 0, 0,            /* accum bits (ignored) */
-        16,                /* depth buffer */
-        0,                /* no stencil buffer */
-        0,                /* no auxiliary buffers */
-        PFD_MAIN_PLANE,            /* main layer */
-        0,                /* reserved */
-        0, 0, 0,            /* no layer, visible, damage masks */
+        PFD_DOUBLEBUFFER,               // support double-buffering
+        PFD_TYPE_RGBA,                  // color type
+        16,                             // preferred color depth
+        0, 0, 0, 0, 0, 0,               // color bits (ignored)
+        0,                              // no alpha buffer
+        0,                              // alpha bits (ignored)
+        0,                              // no accumulation buffer
+        0, 0, 0, 0,                     // accumulator bits (ignored)
+        16,                             // depth buffer
+        0,                              // no stencil buffer
+        0,                              // no auxiliary buffers
+        PFD_MAIN_PLANE,                 // main layer
+        0,                              // reserved
+        0, 0, 0,                        // no layer, visible, damage masks
     };
 
-  AdjustPFDForAttributes(pfd, attribList);
+    if ( !ppfd )
+        ppfd = &pfd;
+    else
+        *ppfd = pfd;
 
-  int pixelFormat = ChoosePixelFormat((HDC) m_hDC, &pfd);
-  if (pixelFormat == 0) {
-    wxLogLastError(_T("ChoosePixelFormat"));
-  }
-  else {
-    if ( !::SetPixelFormat((HDC) m_hDC, pixelFormat, &pfd) ) {
-      wxLogLastError(_T("SetPixelFormat"));
-    }
-  }
+    AdjustPFDForAttributes(*ppfd, attribList);
+
+    return ::ChoosePixelFormat(hdc, ppfd);
 }
 
-void wxGLCanvas::SetupPalette(const wxPalette& palette)
+bool wxGLCanvas::DoSetup(const int *attribList)
 {
-    int pixelFormat = GetPixelFormat((HDC) m_hDC);
     PIXELFORMATDESCRIPTOR pfd;
+    const int pixelFormat = ChooseMatchingPixelFormat(m_hDC, attribList, &pfd);
+    if ( !pixelFormat )
+    {
+        wxLogLastError(_T("ChoosePixelFormat"));
+        return false;
+    }
+
+    if ( !::SetPixelFormat(m_hDC, pixelFormat, &pfd) )
+    {
+        wxLogLastError(_T("SetPixelFormat"));
+        return false;
+    }
+
+    return true;
+}
+
+// ----------------------------------------------------------------------------
+// palette stuff
+// ----------------------------------------------------------------------------
 
-    DescribePixelFormat((HDC) m_hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+#if wxUSE_PALETTE
 
-    if (pfd.dwFlags & PFD_NEED_PALETTE)
+bool wxGLCanvas::SetupPalette(const wxPalette& palette)
+{
+    const int pixelFormat = ::GetPixelFormat(m_hDC);
+    if ( !pixelFormat )
     {
+        wxLogLastError(_T("GetPixelFormat"));
+        return false;
     }
-    else
+
+    PIXELFORMATDESCRIPTOR pfd;
+    if ( !::DescribePixelFormat(m_hDC, pixelFormat, sizeof(pfd), &pfd) )
     {
-      return;
+        wxLogLastError(_T("DescribePixelFormat"));
+        return false;
     }
 
+    if ( !(pfd.dwFlags & PFD_NEED_PALETTE) )
+        return true;
+
     m_palette = palette;
 
     if ( !m_palette.Ok() )
     {
         m_palette = CreateDefaultPalette();
+        if ( !m_palette.Ok() )
+            return false;
+    }
+
+    if ( !::SelectPalette(m_hDC, GetHpaletteOf(m_palette), FALSE) )
+    {
+        wxLogLastError(_T("SelectPalette"));
+        return false;
     }
 
-    if (m_palette.Ok())
+    if ( ::RealizePalette(m_hDC) == GDI_ERROR )
     {
-        ::SelectPalette((HDC) m_hDC, (HPALETTE) m_palette.GetHPALETTE(), FALSE);
-        ::RealizePalette((HDC) m_hDC);
+        wxLogLastError(_T("RealizePalette"));
+        return false;
     }
+
+    return true;
 }
 
 wxPalette wxGLCanvas::CreateDefaultPalette()
 {
     PIXELFORMATDESCRIPTOR pfd;
     int paletteSize;
-    int pixelFormat = GetPixelFormat((HDC) m_hDC);
+    int pixelFormat = GetPixelFormat(m_hDC);
 
-    DescribePixelFormat((HDC) m_hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+    DescribePixelFormat(m_hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
 
     paletteSize = 1 << pfd.cColorBits;
 
@@ -537,61 +554,13 @@ wxPalette wxGLCanvas::CreateDefaultPalette()
     return palette;
 }
 
-void wxGLCanvas::SwapBuffers()
-{
-    ::SwapBuffers((HDC) m_hDC);
-}
-
-void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
-{
-}
-
-void wxGLCanvas::SetCurrent(const wxGLContext& RC) const
-{
-    // although on MSW it works even if the window is still hidden, it doesn't
-    // under wxGTK and documentation mentions that SetCurrent() can only be
-    // called for a shown window, so check it
-    wxASSERT_MSG( GetParent()->IsShown(), _T("can't make hidden GL canvas current") );
-
-    RC.SetCurrent(*this);
-}
-
-void wxGLCanvas::SetCurrent()
-{
-  // although on MSW it works even if the window is still hidden, it doesn't
-  // under wxGTK and documentation mentions that SetCurrent() can only be
-  // called for a shown window, so check it
-  wxASSERT_MSG( GetParent()->IsShown(),
-                    _T("can't make hidden GL canvas current") );
-
-  if (m_glContext)
-  {
-    m_glContext->SetCurrent(*this);
-  }
-}
-
-void wxGLCanvas::SetColour(const wxChar *colour)
-{
-    wxColour col = wxTheColourDatabase->Find(colour);
-
-    if (col.Ok())
-    {
-        float r = (float)(col.Red()/256.0);
-        float g = (float)(col.Green()/256.0);
-        float b = (float)(col.Blue()/256.0);
-        glColor3f( r, g, b);
-    }
-}
-
-// TODO: Have to have this called by parent frame (?)
-// So we need wxFrame to call OnQueryNewPalette for all children...
 void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent& event)
 {
   /* realize palette if this is the current window */
   if ( GetPalette()->Ok() ) {
     ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE());
-    ::SelectPalette((HDC) GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
-    ::RealizePalette((HDC) GetHDC());
+    ::SelectPalette(GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
+    ::RealizePalette(GetHDC());
     Refresh();
     event.SetPaletteRealized(true);
   }
@@ -599,7 +568,6 @@ void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent& event)
     event.SetPaletteRealized(false);
 }
 
-// I think this doesn't have to be propagated to child windows.
 void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event)
 {
   /* realize palette if this is *not* the current window */
@@ -607,59 +575,84 @@ void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event)
        GetPalette()->Ok() && (this != event.GetChangedWindow()) )
   {
     ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE());
-    ::SelectPalette((HDC) GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
-    ::RealizePalette((HDC) GetHDC());
+    ::SelectPalette(GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
+    ::RealizePalette(GetHDC());
     Refresh();
   }
 }
 
+#endif // wxUSE_PALETTE
 
-//---------------------------------------------------------------------------
-// wxGLApp
-//---------------------------------------------------------------------------
-
-IMPLEMENT_CLASS(wxGLApp, wxApp)
+// ----------------------------------------------------------------------------
+// deprecated wxGLCanvas methods using implicit wxGLContext
+// ----------------------------------------------------------------------------
 
-bool wxGLApp::InitGLVisual(int *attribList)
+// deprecated constructors creating an implicit m_glContext
+#if WXWIN_COMPATIBILITY_2_8
+
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
 {
-  int pixelFormat;
-  PIXELFORMATDESCRIPTOR pfd = {
-        sizeof(PIXELFORMATDESCRIPTOR),    /* size */
-        1,                /* version */
-        PFD_SUPPORT_OPENGL |
-        PFD_DRAW_TO_WINDOW |
-        PFD_DOUBLEBUFFER,        /* support double-buffering */
-        PFD_TYPE_RGBA,            /* color type */
-        16,                /* preferred color depth */
-        0, 0, 0, 0, 0, 0,        /* color bits (ignored) */
-        0,                /* no alpha buffer */
-        0,                /* alpha bits (ignored) */
-        0,                /* no accumulation buffer */
-        0, 0, 0, 0,            /* accum bits (ignored) */
-        16,                /* depth buffer */
-        0,                /* no stencil buffer */
-        0,                /* no auxiliary buffers */
-        PFD_MAIN_PLANE,            /* main layer */
-        0,                /* reserved */
-        0, 0, 0,            /* no layer, visible, damage masks */
-    };
+    Init();
 
-  AdjustPFDForAttributes(pfd, attribList);
+    if ( Create(parent, id, pos, size, style, name, attribList, palette) )
+        m_glContext = new wxGLContext(this);
+}
 
-  // use DC for whole (root) screen, since no windows have yet been created
-  pixelFormat = ChoosePixelFormat(ScreenHDC(), &pfd);
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       const wxGLContext *shared,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
+{
+    Init();
 
-  if (pixelFormat == 0) {
-    wxLogError(_("Failed to initialize OpenGL"));
-    return false;
-  }
+    if ( Create(parent, id, pos, size, style, name, attribList, palette) )
+        m_glContext = new wxGLContext(this, shared);
+}
+
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       const wxGLCanvas *shared,
+                       wxWindowID id,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const int *attribList,
+                       const wxPalette& palette)
+{
+    Init();
 
-  return true;
+    if ( Create(parent, id, pos, size, style, name, attribList, palette) )
+        m_glContext = new wxGLContext(this, shared ? shared->m_glContext : NULL);
 }
 
-wxGLApp::~wxGLApp()
+#endif // WXWIN_COMPATIBILITY_2_8
+
+
+// ----------------------------------------------------------------------------
+// wxGLApp
+// ----------------------------------------------------------------------------
+
+bool wxGLApp::InitGLVisual(const int *attribList)
 {
+    if ( !wxGLCanvas::ChooseMatchingPixelFormat(ScreenHDC(), attribList) )
+    {
+        wxLogError(_("Failed to initialize OpenGL"));
+        return false;
+    }
+
+    return true;
 }
 
-#endif
-    // wxUSE_GLCANVAS
+#endif // wxUSE_GLCANVAS
diff --git a/src/palmos/glcanvas.cpp b/src/palmos/glcanvas.cpp
index 5b0492303c..b7c476ab77 100644
--- a/src/palmos/glcanvas.cpp
+++ b/src/palmos/glcanvas.cpp
@@ -135,13 +135,6 @@ void wxGLCanvas::SetupPalette(const wxPalette& palette)
 {
 }
 
-wxPalette wxGLCanvas::CreateDefaultPalette()
-{
-    wxPalette palette;
-
-    return palette;
-}
-
 void wxGLCanvas::SwapBuffers()
 {
 }
diff --git a/src/x11/glcanvas.cpp b/src/x11/glcanvas.cpp
index c6aa213acc..f3917ebdf3 100644
--- a/src/x11/glcanvas.cpp
+++ b/src/x11/glcanvas.cpp
@@ -1,14 +1,24 @@
-/////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
 // Name:        src/x11/glcanvas.cpp
 // Purpose:     wxGLCanvas, for using OpenGL with wxWidgets
 //              Uses the GLX extension.
 // Author:      Julian Smart and Wolfram Gloger
-// Modified by:
+// Modified by: Vadim Zeitlin to update to new API
 // Created:     1995, 1999
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart, Wolfram Gloger
 // Licence:     wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+// TODO: merge this with wxGTK version in some src/unix/glcanvasx11.cpp
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
 
 // for compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
@@ -36,83 +46,47 @@
 #endif
 #include "wx/x11/private.h"
 
-// DLL options compatibility check:
-#include "wx/build.h"
-WX_CHECK_BUILD_OPTIONS("wxGL")
+// ----------------------------------------------------------------------------
+// local functions
+// ----------------------------------------------------------------------------
 
-static inline WXWindow wxGetClientAreaWindow(wxWindow* win)
+static inline Window wxGetClientAreaWindow(const wxWindow* win)
 {
+    return (Window)win->
 #ifdef __WXMOTIF__
-    return win->GetClientXWindow();
+    GetClientXWindow();
 #else
-    return win->GetClientAreaWindow();
+    GetClientAreaWindow();
 #endif
 }
 
-#ifdef OLD_MESA
-// workaround for bug in Mesa's glx.c
-static int bitcount( unsigned long n )
-{
-    int bits;
-    for (bits=0; n>0;)
-    {
-        if(n & 1) bits++;
-        n = n >> 1;
-    }
-    return bits;
-}
-#endif
-
-/*
- * GLContext implementation
- */
-
-IMPLEMENT_CLASS(wxGLContext,wxObject)
+// ============================================================================
+// implementation
+// ============================================================================
 
-wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win,
-                          const wxPalette& WXUNUSED(palette) )
-{
-    m_window = win;
-    // m_widget = win->m_wxwindow;
-
-    wxGLCanvas *gc = (wxGLCanvas*) win;
-    XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
-
-    wxCHECK_RET( vi, wxT("invalid visual for OpenGL") );
+// ----------------------------------------------------------------------------
+// wxGLContext
+// ----------------------------------------------------------------------------
 
-    m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi,
-                                    None, GL_TRUE);
-
-    wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") );
-}
+IMPLEMENT_CLASS(wxGLContext, wxObject)
 
-wxGLContext::wxGLContext(
-               bool WXUNUSED(isRGB), wxWindow *win,
-               const wxPalette& WXUNUSED(palette),
-               const wxGLContext *other        /* for sharing display lists */
-)
+wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other)
 {
-    m_window = win;
-    // m_widget = win->m_wxwindow;
+    XVisualInfo *vi = (XVisualInfo *) win->m_vi;
+    wxASSERT_MSG( vi, wxT("invalid visual in wxGLCanvas") );
 
-    wxGLCanvas *gc = (wxGLCanvas*) win;
-    XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
+    m_glContext = glXCreateContext( (Display *)wxGetDisplay(),
+                                    vi,
+                                    other ? other->m_glContext : None,
+                                    GL_TRUE);
 
-    wxCHECK_RET( vi, wxT("invalid visual for OpenGL") );
-
-    if( other != 0 )
-        m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi,
-                                        other->m_glContext, GL_TRUE );
-    else
-        m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi,
-                                        None, GL_TRUE );
-
-    wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") );
+    wxASSERT_MSG( m_glContext, wxT("Couldn't create OpenGL context") );
 }
 
 wxGLContext::~wxGLContext()
 {
-    if (!m_glContext) return;
+    if (!m_glContext)
+        return;
 
     if (m_glContext == glXGetCurrentContext())
     {
@@ -122,150 +96,57 @@ wxGLContext::~wxGLContext()
     glXDestroyContext( (Display*) wxGetDisplay(), m_glContext );
 }
 
-void wxGLContext::SwapBuffers()
+void wxGLContext::SetCurrent(const wxGLCanvas& win) const
 {
     if (m_glContext)
     {
         Display* display = (Display*) wxGetDisplay();
-        glXSwapBuffers(display, (Window) wxGetClientAreaWindow(m_window));
+        glXMakeCurrent(display, wxGetClientAreaWindow(&win), m_glContext);
     }
 }
 
-void wxGLContext::SetCurrent()
-{
-    if (m_glContext)
-    {
-        Display* display = (Display*) wxGetDisplay();
-        glXMakeCurrent(display, (Window) wxGetClientAreaWindow(m_window),
-                       m_glContext );
-    }
-}
+// ----------------------------------------------------------------------------
+// wxGLCanvas
+// ----------------------------------------------------------------------------
 
-void wxGLContext::SetColour(const wxChar *colour)
-{
-    wxColour the_colour = wxTheColourDatabase->Find(colour);
-    if(the_colour.Ok())
-    {
-        GLboolean b;
-        glGetBooleanv(GL_RGBA_MODE, &b);
-        if(b)
-        {
-            glColor3ub(the_colour.Red(),
-                    the_colour.Green(),
-                    the_colour.Blue());
-        }
-        else
-        {
-#ifdef __WXMOTIF__
-            the_colour.AllocColour(m_window->GetXDisplay());
-#else
-            the_colour.CalcPixel(wxTheApp->GetMainColormap(wxGetDisplay()));
-#endif
-            GLint pix = (GLint)the_colour.GetPixel();
-            if(pix == -1)
-            {
-                wxLogError(wxT("wxGLCanvas: cannot allocate color\n"));
-                return;
-            }
-            glIndexi(pix);
-        }
-    }
-}
+IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
 
-void wxGLContext::SetupPixelFormat()
+wxGLCanvas::wxGLCanvas(wxWindow *parent,
+                       wxWindowID id,
+                       const int *attribList,
+                       const wxPoint& pos,
+                       const wxSize& size,
+                       long style,
+                       const wxString& name,
+                       const wxPalette& palette)
 {
+    Create(parent, id, pos, size, style, name, attribList, palette);
 }
 
-void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) )
-{
-}
-
-wxPalette wxGLContext::CreateDefaultPalette()
-{
-    return wxNullPalette;
-}
-
-
-
-
-/*
- * GLCanvas implementation
- */
-
-IMPLEMENT_CLASS(wxGLCanvas, wxScrolledWindow)
-
-BEGIN_EVENT_TABLE(wxGLCanvas, wxScrolledWindow)
-//    EVT_SIZE(wxGLCanvas::OnSize)
-END_EVENT_TABLE()
-
-
-wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        int *attribList,
-                        const wxPalette& palette )
-: wxScrolledWindow(parent, id, pos, size, style, name)
-{
-    Create( parent, NULL, NULL, id, pos, size, style, name, attribList, palette );
-}
-
-wxGLCanvas::wxGLCanvas( wxWindow *parent,
-                        const wxGLContext *shared,
-                        wxWindowID id,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        int *attribList,
-                        const wxPalette& palette )
-: wxScrolledWindow(parent, id, pos, size, style, name)
-{
-    Create( parent, shared, NULL, id, pos, size, style, name, attribList, palette );
-}
-
-wxGLCanvas::wxGLCanvas( wxWindow *parent,
-                        const wxGLCanvas *shared,
+bool wxGLCanvas::Create(wxWindow *parent,
                         wxWindowID id,
-                        const wxPoint& pos, const wxSize& size,
-                        long style, const wxString& name,
-                        int *attribList,
-                        const wxPalette& palette )
-: wxScrolledWindow(parent, id, pos, size, style, name)
+                        const wxPoint& pos,
+                        const wxSize& size,
+                        long style,
+                        const wxString& name,
+                        const int *attribList,
+                        const wxPalette& palette)
 {
-    Create( parent, NULL, shared, id, pos, size, style, name, attribList, palette );
-}
+    m_vi = NULL;
 
+    if ( !wxWindow::Create(parent, id, pos, size, style, name) )
+        return false;
 
-/*
-bool wxGLCanvas::Create(wxWindow *parent,
-  const wxGLContext *shared, const wxGLCanvas *shared_context_of,
-  wxWindowID id = -1, const wxPoint& pos,
-  const wxSize& size, long style,
-  const wxString& name, int *attribList, const wxPalette& palette):
-    wxScrolledWindow(parent, id, pos, size, style, name)
-*/
-
-bool wxGLCanvas::Create( wxWindow *parent,
-                         const wxGLContext *shared,
-                         const wxGLCanvas *shared_context_of,
-                         wxWindowID id,
-                         const wxPoint& pos, const wxSize& size,
-                         long style, const wxString& name,
-                         int *attribList,
-                         const wxPalette& palette)
-{
     XVisualInfo *vi, vi_templ;
     XWindowAttributes xwa;
     int val, n;
 
-    m_sharedContext = (wxGLContext*)shared;  // const_cast
-    m_sharedContextOf = (wxGLCanvas*)shared_context_of;  // const_cast
-    m_glContext = (wxGLContext*) NULL;
-
     Display* display = (Display*) wxGetDisplay();
 
     // Check for the presence of the GLX extension
     if(!glXQueryExtension(display, NULL, NULL))
     {
-        wxLogDebug(wxT("wxGLCanvas: GLX extension is missing\n"));
+        wxLogDebug(wxT("wxGLCanvas: GLX extension is missing"));
         return false;
     }
 
@@ -311,104 +192,56 @@ bool wxGLCanvas::Create( wxWindow *parent,
       }
       data[p] = 0;
 
-      attribList = (int*) data;
       // Get an appropriate visual
-      vi = glXChooseVisual(display, DefaultScreen(display), attribList);
+      vi = glXChooseVisual(display, DefaultScreen(display), data);
       if(!vi) return false;
 
       // Here we should make sure that vi is the same visual as the
       // one used by the xwindow drawable in wxCanvas.  However,
       // there is currently no mechanism for this in wx_canvs.cc.
-    } else {
+    }
+    else // default attributes
+    {
         // By default, we use the visual of xwindow
-        // NI: is this really senseful ? opengl in e.g. color index mode ?
-      XGetWindowAttributes(display, (Window)wxGetClientAreaWindow(this), &xwa);
+      XGetWindowAttributes(display, wxGetClientAreaWindow(this), &xwa);
       vi_templ.visualid = XVisualIDFromVisual(xwa.visual);
       vi = XGetVisualInfo(display, VisualIDMask, &vi_templ, &n);
       if(!vi) return false;
       glXGetConfig(display, vi, GLX_USE_GL, &val);
       if(!val) return false;
-      // Basically, this is it.  It should be possible to use vi
-      // in glXCreateContext() below.  But this fails with Mesa.
-      // I notified the Mesa author about it; there may be a fix.
-#ifdef OLD_MESA
-      // Construct an attribute list matching the visual
-      int a_list[32];
-      n = 0;
-      if(vi->c_class==TrueColor || vi->c_class==DirectColor) { // RGBA visual
-          a_list[n++] = GLX_RGBA;
-          a_list[n++] = GLX_RED_SIZE;
-          a_list[n++] = bitcount(vi->red_mask);
-          a_list[n++] = GLX_GREEN_SIZE;
-          a_list[n++] = bitcount(vi->green_mask);
-          a_list[n++] = GLX_BLUE_SIZE;
-          a_list[n++] = bitcount(vi->blue_mask);
-          glXGetConfig(display, vi, GLX_ALPHA_SIZE, &val);
-          a_list[n++] = GLX_ALPHA_SIZE;
-          a_list[n++] = val;
-      } else { // Color index visual
-          glXGetConfig(display, vi, GLX_BUFFER_SIZE, &val);
-          a_list[n++] = GLX_BUFFER_SIZE;
-          a_list[n++] = val;
-      }
-      a_list[n] = None;
-      // XFree(vi);
-      vi = glXChooseVisual(display, DefaultScreen(display), a_list);
-      if(!vi) return false;
-#endif /* OLD_MESA */
     }
 
     m_vi = vi;  // safe for later use
 
     wxCHECK_MSG( m_vi, false, wxT("required visual couldn't be found") );
 
-    // Create the GLX context and make it current
-
-    wxGLContext *share= m_sharedContext;
-    if (share==NULL && m_sharedContextOf)
-        share = m_sharedContextOf->GetContext();
-
-    m_glContext = new wxGLContext( TRUE, this, wxNullPalette, share );
-
-#ifndef OLD_MESA
-    // XFree(vi);
-#endif
-    SetCurrent();
-
     return true;
 }
 
-wxGLCanvas::~wxGLCanvas(void)
+wxGLCanvas::~wxGLCanvas()
 {
     XVisualInfo *vi = (XVisualInfo *) m_vi;
 
-    if (vi) XFree( vi );
-    if (m_glContext) delete m_glContext;
-
-    // Display* display = (Display*) GetXDisplay();
-    // if(glx_cx) glXDestroyContext(display, glx_cx);
+    if (vi)
+        XFree( vi );
 }
 
 void wxGLCanvas::SwapBuffers()
 {
-    if( m_glContext ) m_glContext->SwapBuffers();
-
-    // Display* display = (Display*) GetXDisplay();
-    // if(glx_cx) glXSwapBuffers(display, (Window) GetClientAreaWindow());
+    glXSwapBuffers((Display *)wxGetDisplay(), wxGetClientAreaWindow(this));
 }
 
-void wxGLCanvas::SetCurrent()
+int wxGLCanvas::GetColourIndex(const wxColour& col_)
 {
-    if( m_glContext ) m_glContext->SetCurrent();
+    wxColour& col = wx_const_cast(wxColour&, col_);
 
-    // Display* display = (Display*) GetXDisplay();
-    // if(glx_cx) glXMakeCurrent(display, (Window) GetClientAreaWindow(), glx_cx);
-}
+#ifdef __WXMOTIF__
+    col.AllocColour(GetXDisplay());
+#else
+    col.CalcPixel(wxTheApp->GetMainColormap(wxGetDisplay()));
+#endif
 
-void wxGLCanvas::SetColour(const wxChar *col)
-{
-    if( m_glContext ) m_glContext->SetColour(col);
+    return col.GetPixel();
 }
 
-#endif
-    // wxUSE_GLCANVAS
+#endif // wxUSE_GLCANVAS
-- 
2.50.0

