Big wxGL classes refactoring/cleanup:

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


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

View File

@@ -1641,14 +1641,16 @@ GLDLL_CXXFLAGS = $(__gldll_PCH_INC) -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \
-DWXMAKINGDLL_GL $(PIC_FLAG) $(CPPFLAGS) $(CXXFLAGS) -DWXMAKINGDLL_GL $(PIC_FLAG) $(CPPFLAGS) $(CXXFLAGS)
GLDLL_OBJECTS = \ GLDLL_OBJECTS = \
$(__gldll___win32rc) \ $(__gldll___win32rc) \
$(__OPENGL_SRC_OBJECTS) gldll_glcmn.o \
$(__OPENGL_SRC_PLATFORM_OBJECTS)
GLDLL_ODEP = $(___pch_wxprec_gldll_wx_wxprec_h_gch___depname) GLDLL_ODEP = $(___pch_wxprec_gldll_wx_wxprec_h_gch___depname)
GLLIB_CXXFLAGS = $(__gllib_PCH_INC) -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \ GLLIB_CXXFLAGS = $(__gllib_PCH_INC) -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \
$(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) \ $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) \
$(__INC_TIFF_p) $(__INC_JPEG_p) $(__INC_PNG_p) $(__INC_ZLIB_p) \ $(__INC_TIFF_p) $(__INC_JPEG_p) $(__INC_PNG_p) $(__INC_ZLIB_p) \
$(__INC_ODBC_p) $(__INC_REGEX_p) $(__INC_EXPAT_p) $(CPPFLAGS) $(CXXFLAGS) $(__INC_ODBC_p) $(__INC_REGEX_p) $(__INC_EXPAT_p) $(CPPFLAGS) $(CXXFLAGS)
GLLIB_OBJECTS = \ GLLIB_OBJECTS = \
$(__OPENGL_SRC_OBJECTS_1) gllib_glcmn.o \
$(__OPENGL_SRC_PLATFORM_OBJECTS_1)
GLLIB_ODEP = $(___pch_wxprec_gllib_wx_wxprec_h_gch___depname) GLLIB_ODEP = $(___pch_wxprec_gllib_wx_wxprec_h_gch___depname)
SOUND_SDL_CXXFLAGS = -DWXUSINGDLL -DwxUSE_GUI=0 $(PIC_FLAG) $(CPPFLAGS) \ SOUND_SDL_CXXFLAGS = -DWXUSINGDLL -DwxUSE_GUI=0 $(PIC_FLAG) $(CPPFLAGS) \
$(CXXFLAGS) $(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_SRC = src/msw/wince/net.cpp
@COND_TOOLKIT_WINCE@NET_WINCE_HDR = wx/msw/wince/net.h @COND_TOOLKIT_WINCE@NET_WINCE_HDR = wx/msw/wince/net.h
@COND_TOOLKIT_MSW@MSW_HTML_HDR = wx/msw/helpbest.h @COND_TOOLKIT_MSW@MSW_HTML_HDR = wx/msw/helpbest.h
@COND_TOOLKIT_COCOA@OPENGL_HDR = wx/cocoa/glcanvas.h @COND_TOOLKIT_COCOA@OPENGL_HDR_PLATFORM = wx/cocoa/glcanvas.h
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@OPENGL_HDR = wx/gtk1/glcanvas.h @COND_TOOLKIT_GTK_TOOLKIT_VERSION_@OPENGL_HDR_PLATFORM = wx/gtk1/glcanvas.h
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@OPENGL_HDR = wx/gtk/glcanvas.h @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@OPENGL_HDR_PLATFORM = wx/gtk/glcanvas.h
@COND_TOOLKIT_MAC@OPENGL_HDR = wx/mac/carbon/glcanvas.h @COND_TOOLKIT_MAC@OPENGL_HDR_PLATFORM = wx/mac/glcanvas.h \
@COND_TOOLKIT_MOTIF@OPENGL_HDR = wx/x11/glcanvas.h @COND_TOOLKIT_MAC@ wx/mac/carbon/glcanvas.h
@COND_TOOLKIT_MSW@OPENGL_HDR = wx/msw/glcanvas.h @COND_TOOLKIT_MOTIF@OPENGL_HDR_PLATFORM = wx/x11/glcanvas.h
@COND_TOOLKIT_PM@OPENGL_HDR = wx/os2/glcanvas.h @COND_TOOLKIT_MSW@OPENGL_HDR_PLATFORM = wx/msw/glcanvas.h
@COND_TOOLKIT_WINCE@OPENGL_HDR = wx/msw/glcanvas.h @COND_TOOLKIT_WINCE@OPENGL_HDR_PLATFORM = wx/msw/glcanvas.h
@COND_TOOLKIT_X11@OPENGL_HDR = wx/x11/glcanvas.h @COND_TOOLKIT_X11@OPENGL_HDR_PLATFORM = wx/x11/glcanvas.h
COND_TOOLKIT__BASE_MACOSX_HDR = \ COND_TOOLKIT__BASE_MACOSX_HDR = \
wx/unix/apptbase.h \ wx/unix/apptbase.h \
wx/unix/apptrait.h \ wx/unix/apptrait.h \
@@ -2288,7 +2290,6 @@ COND_TOOLKIT_MAC_GUI_HDR = \
wx/mac/fontdlg.h \ wx/mac/fontdlg.h \
wx/mac/frame.h \ wx/mac/frame.h \
wx/mac/gauge.h \ wx/mac/gauge.h \
wx/mac/glcanvas.h \
wx/mac/gsockmac.h \ wx/mac/gsockmac.h \
wx/mac/helpxxxx.h \ wx/mac/helpxxxx.h \
wx/mac/icon.h \ wx/mac/icon.h \
@@ -3120,7 +3121,6 @@ COND_USE_GUI_1_ALL_GUI_HEADERS = \
wx/gdiobj.h \ wx/gdiobj.h \
wx/geometry.h \ wx/geometry.h \
wx/gifdecod.h \ wx/gifdecod.h \
wx/glcanvas.h \
wx/help.h \ wx/help.h \
wx/helpbase.h \ wx/helpbase.h \
wx/helpwin.h \ wx/helpwin.h \
@@ -3205,7 +3205,8 @@ COND_USE_GUI_1_ALL_GUI_HEADERS = \
wx/wxhtml.h \ wx/wxhtml.h \
wx/htmllbox.h \ wx/htmllbox.h \
$(MSW_HTML_HDR) \ $(MSW_HTML_HDR) \
$(OPENGL_HDR) \ wx/glcanvas.h \
$(OPENGL_HDR_PLATFORM) \
wx/debugrpt.h \ wx/debugrpt.h \
wx/dbgrid.h \ wx/dbgrid.h \
wx/xrc/xh_all.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) $(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_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_PLATFORM_WIN32_1@__gldll___win32rc = gldll_version_rc.o
@COND_TOOLKIT_COCOA@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_COCOA@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_GTK_TOOLKIT_VERSION_@__OPENGL_SRC_PLATFORM_OBJECTS \
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_GTK_TOOLKIT_VERSION_@ = gldll_glcanvas.o
@COND_TOOLKIT_MAC@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__OPENGL_SRC_PLATFORM_OBJECTS \
@COND_TOOLKIT_MOTIF@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@ = gldll_glcanvas.o
@COND_TOOLKIT_MSW@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_MAC@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
@COND_TOOLKIT_PM@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_MOTIF@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
@COND_TOOLKIT_WINCE@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_MSW@__OPENGL_SRC_PLATFORM_OBJECTS = gldll_glcanvas.o
@COND_TOOLKIT_X11@__OPENGL_SRC_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 = \ COND_MONOLITHIC_0___WXLIBGLDEP_CORE_p = \
-lwx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_core-$(WX_RELEASE)$(HOST_SUFFIX) -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) @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_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___depname \
@COND_USE_PCH_1@ = .pch/wxprec_gllib/wx/wxprec.h.gch @COND_USE_PCH_1@ = .pch/wxprec_gllib/wx/wxprec.h.gch
@COND_TOOLKIT_COCOA@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @COND_TOOLKIT_COCOA@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@__OPENGL_SRC_OBJECTS_1 \ @COND_TOOLKIT_GTK_TOOLKIT_VERSION_@__OPENGL_SRC_PLATFORM_OBJECTS_1 \
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_@ = gllib_glcanvas.o @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_GTK_TOOLKIT_VERSION_2@ = gllib_glcanvas.o
@COND_TOOLKIT_MAC@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @COND_TOOLKIT_MAC@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
@COND_TOOLKIT_MOTIF@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @COND_TOOLKIT_MOTIF@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
@COND_TOOLKIT_MSW@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @COND_TOOLKIT_MSW@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
@COND_TOOLKIT_PM@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @COND_TOOLKIT_PM@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
@COND_TOOLKIT_WINCE@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @COND_TOOLKIT_WINCE@__OPENGL_SRC_PLATFORM_OBJECTS_1 = gllib_glcanvas.o
@COND_TOOLKIT_X11@__OPENGL_SRC_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_1@____wxgl_namedll_DEP = $(__gldll___depname)
@COND_SHARED_0@____wxgl_namelib_DEP = $(__gllib___depname) @COND_SHARED_0@____wxgl_namelib_DEP = $(__gllib___depname)
COND_WITH_PLUGIN_SDL_1___sound_sdl___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) 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 $(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@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 @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@gldll_glcanvas.o: $(srcdir)/src/os2/glcanvas.cpp $(GLDLL_ODEP)
@COND_TOOLKIT_PM@ $(CXXC) -c -o $@ $(GLDLL_CXXFLAGS) $(srcdir)/src/os2/glcanvas.cpp @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@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 @COND_TOOLKIT_MAC@ $(CXXC) -c -o $@ $(GLLIB_CXXFLAGS) $(srcdir)/src/mac/carbon/glcanvas.cpp

View File

@@ -832,7 +832,6 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
wx/gdiobj.h wx/gdiobj.h
wx/geometry.h wx/geometry.h
wx/gifdecod.h wx/gifdecod.h
wx/glcanvas.h
wx/help.h wx/help.h
wx/helpbase.h wx/helpbase.h
wx/helpwin.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/fontdlg.h
wx/mac/frame.h wx/mac/frame.h
wx/mac/gauge.h wx/mac/gauge.h
wx/mac/glcanvas.h
wx/mac/gsockmac.h wx/mac/gsockmac.h
wx/mac/helpxxxx.h wx/mac/helpxxxx.h
wx/mac/icon.h wx/mac/icon.h
@@ -3104,7 +3102,8 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
<!-- OpenGL canvas --> <!-- 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=='MAC'">src/mac/carbon/glcanvas.cpp</if>
<if cond="TOOLKIT=='COCOA'">src/cocoa/glcanvas.mm</if> <if cond="TOOLKIT=='COCOA'">src/cocoa/glcanvas.mm</if>
<if cond="TOOLKIT=='GTK' and TOOLKIT_VERSION=='2'">src/gtk/glcanvas.cpp</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> <if cond="TOOLKIT=='PM'">src/os2/glcanvas.cpp</if>
</set> </set>
<set var="OPENGL_HDR" hints="files"> <set var="OPENGL_SRC" hints="files">
<if cond="TOOLKIT=='MAC'">wx/mac/carbon/glcanvas.h</if> 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=='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=='2'">wx/gtk/glcanvas.h</if>
<if cond="TOOLKIT=='GTK' and TOOLKIT_VERSION==''">wx/gtk1/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=='WINCE'">wx/msw/glcanvas.h</if>
<if cond="TOOLKIT=='MOTIF'">wx/x11/glcanvas.h</if> <if cond="TOOLKIT=='MOTIF'">wx/x11/glcanvas.h</if>
<if cond="TOOLKIT=='X11'">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>
<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) $(GUI_CORE_HEADERS)
$(ADVANCED_HDR) $(MEDIA_HDR) $(HTML_HDR) $(ADVANCED_HDR) $(MEDIA_HDR) $(HTML_HDR)
$(OPENGL_HDR) $(QA_HDR) $(DBGRID_HDR) $(XRC_HDR) $(AUI_HDR) $(RICHTEXT_HDR) $(OPENGL_HDR) $(QA_HDR) $(DBGRID_HDR) $(XRC_HDR) $(AUI_HDR) $(RICHTEXT_HDR)
$(STC_HDR) $(STC_HDR)
</if> </if>
</set> </set>

View File

@@ -1281,6 +1281,7 @@ GLDLL_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
-H=$(OBJS)\wxprec_gldll.csm $(CPPFLAGS) $(CXXFLAGS) -H=$(OBJS)\wxprec_gldll.csm $(CPPFLAGS) $(CXXFLAGS)
GLDLL_OBJECTS = \ GLDLL_OBJECTS = \
$(OBJS)\gldll_dummy.obj \ $(OBJS)\gldll_dummy.obj \
$(OBJS)\gldll_glcmn.obj \
$(OBJS)\gldll_glcanvas.obj $(OBJS)\gldll_glcanvas.obj
GLLIB_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \ GLLIB_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
$(__OPTIMIZEFLAG) $(__THREADSFLAG) -D__WXMSW__ $(__WXUNIV_DEFINE_p) \ $(__OPTIMIZEFLAG) $(__THREADSFLAG) -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
@@ -1292,6 +1293,7 @@ GLLIB_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
$(CXXFLAGS) $(CXXFLAGS)
GLLIB_OBJECTS = \ GLLIB_OBJECTS = \
$(OBJS)\gllib_dummy.obj \ $(OBJS)\gllib_dummy.obj \
$(OBJS)\gllib_glcmn.obj \
$(OBJS)\gllib_glcanvas.obj $(OBJS)\gllib_glcanvas.obj
BUILD_CFG_FILE = $(SETUPHDIR)\build.cfg 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 $(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 $** 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 $(OBJS)\gldll_glcanvas.obj: ..\..\src\msw\glcanvas.cpp
$(CXX) -q -c -P -o$@ $(GLDLL_CXXFLAGS) $** $(CXX) -q -c -P -o$@ $(GLDLL_CXXFLAGS) $**
$(OBJS)\gllib_dummy.obj: ..\..\src\common\dummy.cpp $(OBJS)\gllib_dummy.obj: ..\..\src\common\dummy.cpp
$(CXX) -q -c -P -o$@ $(GLLIB_CXXFLAGS) -H $** $(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 $(OBJS)\gllib_glcanvas.obj: ..\..\src\msw\glcanvas.cpp
$(CXX) -q -c -P -o$@ $(GLLIB_CXXFLAGS) $** $(CXX) -q -c -P -o$@ $(GLLIB_CXXFLAGS) $**

View File

@@ -1283,6 +1283,7 @@ GLDLL_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) $(GCCFLAGS) \
GLDLL_OBJECTS = \ GLDLL_OBJECTS = \
$(OBJS)\gldll_dummy.o \ $(OBJS)\gldll_dummy.o \
$(OBJS)\gldll_version_rc.o \ $(OBJS)\gldll_version_rc.o \
$(OBJS)\gldll_glcmn.o \
$(OBJS)\gldll_glcanvas.o $(OBJS)\gldll_glcanvas.o
GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) $(GCCFLAGS) \ GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) $(GCCFLAGS) \
-DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) \ -DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) \
@@ -1294,6 +1295,7 @@ GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) $(GCCFLAGS) \
$(CXXFLAGS) $(CXXFLAGS)
GLLIB_OBJECTS = \ GLLIB_OBJECTS = \
$(OBJS)\gllib_dummy.o \ $(OBJS)\gllib_dummy.o \
$(OBJS)\gllib_glcmn.o \
$(OBJS)\gllib_glcanvas.o $(OBJS)\gllib_glcanvas.o
BUILD_CFG_FILE = $(SETUPHDIR)\build.cfg 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 $(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 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 $(OBJS)\gldll_glcanvas.o: ../../src/msw/glcanvas.cpp
$(CXX) -c -o $@ $(GLDLL_CXXFLAGS) $(CPPDEPS) $< $(CXX) -c -o $@ $(GLDLL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\gllib_dummy.o: ../../src/common/dummy.cpp $(OBJS)\gllib_dummy.o: ../../src/common/dummy.cpp
$(CXX) -c -o $@ $(GLLIB_CXXFLAGS) $(CPPDEPS) $< $(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 $(OBJS)\gllib_glcanvas.o: ../../src/msw/glcanvas.cpp
$(CXX) -c -o $@ $(GLLIB_CXXFLAGS) $(CPPDEPS) $< $(CXX) -c -o $@ $(GLLIB_CXXFLAGS) $(CPPDEPS) $<

View File

@@ -1385,6 +1385,7 @@ GLDLL_CXXFLAGS = /M$(__RUNTIME_LIBS_505)$(__DEBUGRUNTIME) /DWIN32 \
GLDLL_OBJECTS = \ GLDLL_OBJECTS = \
$(OBJS)\gldll_dummy.obj \ $(OBJS)\gldll_dummy.obj \
$(OBJS)\gldll_version.res \ $(OBJS)\gldll_version.res \
$(OBJS)\gldll_glcmn.obj \
$(OBJS)\gldll_glcanvas.obj $(OBJS)\gldll_glcanvas.obj
GLLIB_CXXFLAGS = /M$(__RUNTIME_LIBS_518)$(__DEBUGRUNTIME) /DWIN32 \ GLLIB_CXXFLAGS = /M$(__RUNTIME_LIBS_518)$(__DEBUGRUNTIME) /DWIN32 \
$(__DEBUGINFO) \ $(__DEBUGINFO) \
@@ -1398,6 +1399,7 @@ GLLIB_CXXFLAGS = /M$(__RUNTIME_LIBS_518)$(__DEBUGRUNTIME) /DWIN32 \
/Yu"wx/wxprec.h" /Fp"$(OBJS)\wxprec_gllib.pch" $(CPPFLAGS) $(CXXFLAGS) /Yu"wx/wxprec.h" /Fp"$(OBJS)\wxprec_gllib.pch" $(CPPFLAGS) $(CXXFLAGS)
GLLIB_OBJECTS = \ GLLIB_OBJECTS = \
$(OBJS)\gllib_dummy.obj \ $(OBJS)\gllib_dummy.obj \
$(OBJS)\gllib_glcmn.obj \
$(OBJS)\gllib_glcanvas.obj $(OBJS)\gllib_glcanvas.obj
BUILD_CFG_FILE = $(SETUPHDIR)\build.cfg 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 -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 cd ..\..\samples
$(MAKE) -f makefile.vc $(MAKEARGS) clean $(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 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: sub_samples:
cd ..\..\samples cd ..\..\samples
$(MAKE) -f makefile.vc $(MAKEARGS) all $(MAKE) -f makefile.vc $(MAKEARGS) all
cd $(MAKEDIR) cd "$(MAKEDIR)"
$(LIBDIRNAME): $(LIBDIRNAME):
if not exist $(LIBDIRNAME) mkdir $(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 $(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 $** 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 $(OBJS)\gldll_glcanvas.obj: ..\..\src\msw\glcanvas.cpp
$(CXX) /c /nologo /TP /Fo$@ $(GLDLL_CXXFLAGS) $** $(CXX) /c /nologo /TP /Fo$@ $(GLDLL_CXXFLAGS) $**
$(OBJS)\gllib_dummy.obj: ..\..\src\common\dummy.cpp $(OBJS)\gllib_dummy.obj: ..\..\src\common\dummy.cpp
$(CXX) /c /nologo /TP /Fo$@ $(GLLIB_CXXFLAGS) /Ycwx/wxprec.h $** $(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 $(OBJS)\gllib_glcanvas.obj: ..\..\src\msw\glcanvas.cpp
$(CXX) /c /nologo /TP /Fo$@ $(GLLIB_CXXFLAGS) $** $(CXX) /c /nologo /TP /Fo$@ $(GLLIB_CXXFLAGS) $**

View File

@@ -4238,6 +4238,7 @@ GLDLL_CXXFLAGS = -bd $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
$(CXXFLAGS) $(CXXFLAGS)
GLDLL_OBJECTS = & GLDLL_OBJECTS = &
$(OBJS)\gldll_dummy.obj & $(OBJS)\gldll_dummy.obj &
$(OBJS)\gldll_glcmn.obj &
$(OBJS)\gldll_glcanvas.obj $(OBJS)\gldll_glcanvas.obj
GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) & GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
$(__RUNTIME_LIBS) -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) & $(__RUNTIME_LIBS) -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) &
@@ -4249,6 +4250,7 @@ GLLIB_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
$(__EXCEPTIONSFLAG) $(CPPFLAGS) $(CXXFLAGS) $(__EXCEPTIONSFLAG) $(CPPFLAGS) $(CXXFLAGS)
GLLIB_OBJECTS = & GLLIB_OBJECTS = &
$(OBJS)\gllib_dummy.obj & $(OBJS)\gllib_dummy.obj &
$(OBJS)\gllib_glcmn.obj &
$(OBJS)\gllib_glcanvas.obj $(OBJS)\gllib_glcanvas.obj
BUILD_CFG_FILE = $(SETUPHDIR)\build.cfg 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 $(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 $< 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 $(OBJS)\gldll_glcanvas.obj : .AUTODEPEND ..\..\src\msw\glcanvas.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(GLDLL_CXXFLAGS) $< $(CXX) -bt=nt -zq -fo=$^@ $(GLDLL_CXXFLAGS) $<
$(OBJS)\gllib_dummy.obj : .AUTODEPEND ..\..\src\common\dummy.cpp $(OBJS)\gllib_dummy.obj : .AUTODEPEND ..\..\src\common\dummy.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(GLLIB_CXXFLAGS) $< $(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 $(OBJS)\gllib_glcanvas.obj : .AUTODEPEND ..\..\src\msw\glcanvas.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(GLLIB_CXXFLAGS) $< $(CXX) -bt=nt -zq -fo=$^@ $(GLLIB_CXXFLAGS) $<

View File

@@ -456,6 +456,10 @@ SOURCE=..\..\src\common\dummy.cpp
# ADD BASE CPP /Yc"wx/wxprec.h" # ADD BASE CPP /Yc"wx/wxprec.h"
# ADD CPP /Yc"wx/wxprec.h" # ADD CPP /Yc"wx/wxprec.h"
# End Source File # End Source File
# Begin Source File
SOURCE=..\..\src\common\glcmn.cpp
# End Source File
# End Group # End Group
# Begin Group "MSW Sources" # Begin Group "MSW Sources"
@@ -977,6 +981,14 @@ InputPath=..\..\include\wx\msw\genrcdefs.h
SOURCE=..\..\include\wx\msw\glcanvas.h SOURCE=..\..\include\wx\msw\glcanvas.h
# End Source File # End Source File
# End Group # 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 Target
# End Project # End Project

View File

@@ -1,29 +1,34 @@
\section{\class{wxGLCanvas}}\label{wxglcanvas} \section{\class{wxGLCanvas}}\label{wxglcanvas}
wxGLCanvas is a class for displaying OpenGL graphics. 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.
There are two ways to use this class: 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.
For the older (before wx 2.7.x) and simpler method, create a wxGLCanvas window using one of the three Notice that previous versions of wxWidgets used to implicitly create a
constructors that implicitly create a rendering context, call \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrent} wxGLContext inside wxGLCanvas itself. This is still supported in the current
to direct normal OpenGL commands to the window, and then call \helpref{wxGLCanvas::SwapBuffers}{wxglcanvasswapbuffers} version but is deprecated now and will be removed in the future, please update
to show the OpenGL buffer on the window. your code to create the rendering contexts explicitly.
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.
To set up the attributes for the canvas (number of bits for the depth buffer, 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 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. 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 Notice that OpenGL is not enabled by default. To switch it on, you need to edit
{\tt wxUSE\_GLCANVAS} to $1$. You may also need to have to add setup.h under Windows and set {\tt wxUSE\_GLCANVAS} to $1$ (you may also need
{\tt opengl32.lib} to the list of libraries your program is linked with. On to have to add {\tt opengl32.lib} and {\tt glu32.lib} to the list of libraries
Unix, pass \verb=--with-opengl= to configure to compile using OpenGL or Mesa. your program is linked with). On Unix, pass \verb=--with-opengl= to configure.
\wxheading{Derived from} \wxheading{Derived from}
@@ -75,46 +80,19 @@ alpha channel, and accum buffer. Other implementations may support them.
\membersection{wxGLCanvas::wxGLCanvas}\label{wxglcanvasconstr} \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}, \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{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},
\param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"}, \param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"},
\param{const wxPalette\&}{ palette = wxNullPalette}} \param{const wxPalette\&}{ palette = wxNullPalette}}
Constructors. Creates a window with the given parameters. Notice that you need to create and
The first three constructors implicitly create an instance of \helpref{wxGLContext}{wxglcontext}. use a \helpref{wxGLContext}{wxglcontext} to output to this window.
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!).
Note that if you used one of the first three constructors, \helpref{wxGLCanvas::GetContext}{wxglcanvasgetcontext} If \arg{attribList} is not specified, double buffered RGBA mode is used.
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!
\docparam{parent}{Pointer to a parent window.} \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{id}{Window identifier. If -1, will automatically create an identifier.}
\docparam{pos}{Window position. wxDefaultPosition is (-1, -1) which indicates that wxWidgets \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{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. 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. 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 For example, the WX\_GL\_DEPTH\_SIZE should be followed by the value that indicates the number of
bits for the depth buffer, so:} bits for the depth buffer, so:}
\begin{verbatim} \begin{verbatim}
attribList[index]= WX_GL_DEPTH_SIZE; attribList[index] = WX_GL_DEPTH_SIZE;
attribList[index+1]=32; attribList[index+1] = 32;
and so on. and so on.
\end{verbatim} \end{verbatim}
\docparam{palette}{If the window has the palette, it should by pass this value. \docparam{palette}{Palette for indexed colour (i.e. non WX\_GL\_RGBA) mode.
Note: palette and WX\_GL\_RGBA are mutually exclusive.} Ignored under most platforms.}
\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.
\membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrent} \membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrent}
\func{void}{SetCurrent}{\void} \func{void}{SetCurrent}{ \param{const wxGLContext&}{ context} }
If this canvas was created with one of the first three constructors, Makes the OpenGL state that is represented by the OpenGL rendering context
a call to this method makes the implicit rendering context of this canvas current with this canvas, \arg{context} current, i.e. it will be used by all subsequent OpenGL calls.
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 This is equivalent to \helpref{wxGLContext::SetCurrent}{wxglcontextsetcurrent}
(use the SetCurrent method below with the parameter instead)! 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::SetCurrent}\label{wxglcanvassetcurrentrc}
\func{void}{SetCurrent}{ \param{const wxGLContext&}{ RC} }
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)!
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}.
Note that this function may only be called \emph{after} the window has been shown.
\membersection{wxGLCanvas::SetColour}\label{wxglcanvassetcolour} \membersection{wxGLCanvas::SetColour}\label{wxglcanvassetcolour}
\func{void}{SetColour}{\param{const char*}{ colour}} \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} \membersection{wxGLCanvas::SwapBuffers}\label{wxglcanvasswapbuffers}

View File

@@ -20,84 +20,62 @@
class WXDLLIMPEXP_GL wxGLCanvas; class WXDLLIMPEXP_GL wxGLCanvas;
DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLContext); DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLContext);
//DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLView); DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLView);
// ======================================================================== // ========================================================================
// wxGLContext // wxGLContext
// ======================================================================== // ========================================================================
class WXDLLIMPEXP_GL wxGLContext: public wxObject
class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
{ {
public: public:
wxGLContext(bool isRGB, wxGLCanvas *win, const wxPalette& palette = wxNullPalette); wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
wxGLContext( bool isRGB, wxGLCanvas *win,
const wxPalette& WXUNUSED(palette),
const wxGLContext *other /* for sharing display lists */ );
virtual ~wxGLContext(); virtual ~wxGLContext();
virtual void SetCurrent(const wxGLCanvas& win) const;
void SetCurrent(); WX_NSOpenGLContext GetNSOpenGLContext() const
{ return m_cocoaNSOpenGLContext; }
void SetColour(const wxChar *colour); private:
void SwapBuffers();
inline wxWindow* GetWindow() const
{ return m_window; }
inline WX_NSOpenGLContext GetNSOpenGLContext() const
{ return m_cocoaNSOpenGLContext; }
public:
WX_NSOpenGLContext m_cocoaNSOpenGLContext; WX_NSOpenGLContext m_cocoaNSOpenGLContext;
wxWindow* m_window;
}; };
// ======================================================================== // ========================================================================
// wxGLCanvas // wxGLCanvas
// ======================================================================== // ========================================================================
class WXDLLIMPEXP_GL wxGLCanvas: public wxWindow// , protected wxCocoaNSOpenGLView
class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasBase
// , protected wxCocoaNSOpenGLView
{ {
DECLARE_DYNAMIC_CLASS(wxGLCanvas) DECLARE_DYNAMIC_CLASS(wxGLCanvas)
DECLARE_EVENT_TABLE()
// WX_DECLARE_COCOA_OWNER(NSOpenGLView,NSView,NSView) // WX_DECLARE_COCOA_OWNER(NSOpenGLView,NSView,NSView)
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// initialization // initialization
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
public: 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, wxGLCanvas(wxWindow *parent,
const wxGLContext *shared = NULL, wxWindowID id = wxID_ANY,
wxWindowID winid = wxID_ANY, const int *attribList = NULL,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, const wxString& name = wxGLCanvasName, long style = 0,
int *attribList = NULL, const wxPalette& palette = wxNullPalette); const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette)
{
Create(parent, id, pos, size, style, name, attribList, palette);
}
wxGLCanvas(wxWindow *parent, bool Create(wxWindow *parent,
const wxGLCanvas *shared = NULL, wxWindowID id = wxID_ANY,
wxWindowID winid = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
const wxSize& size = wxDefaultSize, long style = 0,
long style = 0, const wxString& name = wxGLCanvasName, const wxString& name = wxGLCanvasName,
int *attribList = NULL, const wxPalette& palette = wxNullPalette); const 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(); virtual ~wxGLCanvas();
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -110,16 +88,11 @@ protected:
// Implementation // Implementation
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
public: public:
void SetCurrent(); virtual void SwapBuffers();
void SwapBuffers();
void OnSize(wxSizeEvent& event)
{} NSOpenGLView *GetNSOpenGLView() const
inline wxGLContext* GetContext() const { return (NSOpenGLView *)m_cocoaNSView; }
{ return m_glContext; }
protected:
wxGLContext *m_glContext;
wxPalette m_palette;
}; };
#endif //ndef _WX_COCOA_GLCANVAS_H__ #endif //ndef _WX_COCOA_GLCANVAS_H__

View File

@@ -16,14 +16,20 @@
#if wxUSE_GLCANVAS #if wxUSE_GLCANVAS
//--------------------------------------------------------------------------- #include "wx/app.h"
// Constants for attriblist #include "wx/palette.h"
//--------------------------------------------------------------------------- #include "wx/window.h"
// The generic GL implementation doesn't support most of these options, class WXDLLIMPEXP_GL wxGLCanvas;
// such as stereo, auxiliary buffers, alpha channel, and accum buffer. 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. // Other implementations may actually support them.
enum enum
{ {
WX_GL_RGBA=1, /* use true color palette */ WX_GL_RGBA=1, /* use true color palette */
@@ -46,41 +52,139 @@ enum
#define wxGLCanvasName _T("GLCanvas") #define wxGLCanvasName _T("GLCanvas")
#if defined(__WXMSW__) // ----------------------------------------------------------------------------
#include "wx/msw/glcanvas.h" // wxGLContextBase: OpenGL rendering context
#elif defined(__WXMOTIF__) // ----------------------------------------------------------------------------
#include "wx/x11/glcanvas.h"
#elif defined(__WXGTK20__) class WXDLLIMPEXP_GL wxGLContextBase : public wxObject
#include "wx/gtk/glcanvas.h" {
#elif defined(__WXGTK__) public:
#include "wx/gtk1/glcanvas.h" /*
#elif defined(__WXX11__) The derived class should provide a ctor with this signature:
#include "wx/x11/glcanvas.h"
#elif defined(__WXMAC__) wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
#include "wx/mac/glcanvas.h" */
#elif defined(__WXCOCOA__)
#include "wx/cocoa/glcanvas.h" // set this context as the current one
#else virtual void SetCurrent(const wxGLCanvas& win) const = 0;
#error "wxGLCanvas not supported in this wxWidgets port" };
// ----------------------------------------------------------------------------
// 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__) || defined(__WXX11__)
#include "wx/x11/glcanvas.h"
#elif defined(__WXGTK20__)
#include "wx/gtk/glcanvas.h"
#elif defined(__WXGTK__)
#include "wx/gtk1/glcanvas.h"
#elif defined(__WXMAC__)
#include "wx/mac/glcanvas.h"
#elif defined(__WXCOCOA__)
#include "wx/cocoa/glcanvas.h"
#else
#error "wxGLCanvas not supported in this wxWidgets port"
#endif #endif
#include "wx/app.h"
class WXDLLIMPEXP_GL wxGLApp : public wxApp class WXDLLIMPEXP_GL wxGLApp : public wxApp
{ {
public: public:
wxGLApp() : wxApp() { } wxGLApp() : wxApp() { }
virtual ~wxGLApp();
// use this in the constructor of the user-derived wxGLApp class to // use this in the constructor of the user-derived wxGLApp class to
// determine if an OpenGL rendering context with these attributes // determine if an OpenGL rendering context with these attributes
// is available - returns true if so, false if not. // is available - returns true if so, false if not.
bool InitGLVisual(int *attribList); bool InitGLVisual(const int *attribList);
private: private:
DECLARE_DYNAMIC_CLASS(wxGLApp) DECLARE_DYNAMIC_CLASS(wxGLApp)
}; };
#endif #endif // wxUSE_GLCANVAS
// wxUSE_GLCANVAS
#endif #endif // _WX_GLCANVAS_H_BASE_
// _WX_GLCANVAS_H_BASE_

View File

@@ -12,42 +12,29 @@
#ifndef _WX_GLCANVAS_H_ #ifndef _WX_GLCANVAS_H_
#define _WX_GLCANVAS_H_ #define _WX_GLCANVAS_H_
#include "wx/scrolwin.h" extern "C"
#include "wx/app.h" {
#include <GL/gl.h>
extern "C" { #include <GL/glx.h>
#include <GL/gl.h> #include <GL/glu.h>
#include <GL/glx.h>
#include <GL/glu.h>
} }
//---------------------------------------------------------------------------
// classes
//---------------------------------------------------------------------------
class WXDLLEXPORT wxGLContext;
class WXDLLEXPORT wxGLCanvas;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxGLContext // wxGLContext
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
class WXDLLEXPORT wxGLContext: public wxObject class WXDLLEXPORT wxGLContext : public wxGLContextBase
{ {
public: public:
wxGLContext(wxWindow* win, const wxGLContext* other=NULL /* for sharing display lists */); wxGLContext(wxWindow* win, const wxGLContext* other = NULL);
virtual ~wxGLContext(); virtual ~wxGLContext();
public: virtual void SetCurrent(const wxGLCanvas& win) const;
// The win wxGLCanvas needs not necessarily be the same as the wxGLCanvas with which this context was created!
void SetCurrent(const wxGLCanvas& win) const;
private: private:
GLXContext m_glContext; GLXContext m_glContext;
private:
DECLARE_CLASS(wxGLContext) DECLARE_CLASS(wxGLContext)
}; };
@@ -55,72 +42,89 @@ private:
// wxGLCanvas // wxGLCanvas
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
class WXDLLEXPORT wxGLCanvas: public wxWindow class WXDLLEXPORT wxGLCanvas : public wxGLCanvasBase
{ {
public: public:
// This ctor is identical to the next, except for the fact that it wxGLCanvas(wxWindow *parent,
// doesn't create an implicit wxGLContext. wxWindowID id = wxID_ANY,
// The attribList parameter has been moved to avoid overload clashes. const int *attribList = NULL,
wxGLCanvas( wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
int *attribList = (int*) NULL, const wxSize& size = wxDefaultSize,
const wxPoint& pos = wxDefaultPosition, long style = 0,
const wxSize& size = wxDefaultSize, const wxString& name = wxGLCanvasName,
long style = 0, const wxString& name = wxGLCanvasName, const wxPalette& palette = wxNullPalette);
const wxPalette& palette = wxNullPalette );
wxGLCanvas( wxWindow *parent, wxWindowID id = -1, bool Create(wxWindow *parent,
const wxPoint& pos = wxDefaultPosition, wxWindowID id = wxID_ANY,
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,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
const wxString& name = wxGLCanvasName, const wxString& name = wxGLCanvasName,
int *attribList = (int*) NULL, const int *attribList = NULL,
const wxPalette& palette = wxNullPalette ); 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* void *m_vi; // actually an XVisualInfo*
GLXFBConfig *m_fbc; GLXFBConfig *m_fbc;
bool m_canFreeVi; bool m_canFreeVi;
@@ -128,23 +132,23 @@ public:
GtkWidget *m_glWidget; GtkWidget *m_glWidget;
bool m_exposed; 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 an XVisualInfo* based on desired GL attributes;
// returns NULL if an appropriate visual is not found. The // returns NULL if an appropriate visual is not found. The
// caller is reponsible for using XFree() to deallocate // caller is reponsible for using XFree() to deallocate
// the returned structure. // the returned structure.
static void* ChooseGLVisual(int *attribList); static void* ChooseGLVisual(const int *attribList);
static void* ChooseGLFBC(int *attribList); static void* ChooseGLFBC(const int *attribList);
static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList ); static void GetGLAttribListFromWX(const int *wx_attribList, int *gl_attribList );
static void QueryGLXVersion();
static int GetGLXVersion();
static int m_glxVersion;
private: private:
DECLARE_EVENT_TABLE()
DECLARE_CLASS(wxGLCanvas) DECLARE_CLASS(wxGLCanvas)
}; };
#endif #endif // _WX_GLCANVAS_H_
// _WX_GLCANVAS_H_

View File

@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk1/glcanvas.h // Name: glcanvas.h
// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWidgets and GTK // Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWidgets and GTK
// Author: Robert Roebling // Author: Robert Roebling
// Modified by: // Modified by:
@@ -12,148 +12,143 @@
#ifndef _WX_GLCANVAS_H_ #ifndef _WX_GLCANVAS_H_
#define _WX_GLCANVAS_H_ #define _WX_GLCANVAS_H_
#include "wx/scrolwin.h" extern "C"
#include "wx/app.h" {
#include <GL/gl.h>
extern "C" { #include <GL/glx.h>
#include <GL/gl.h> #include <GL/glu.h>
#include <GL/glx.h>
#include <GL/glu.h>
} }
//---------------------------------------------------------------------------
// classes
//---------------------------------------------------------------------------
class WXDLLEXPORT wxGLContext;
class WXDLLEXPORT wxGLCanvas;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxGLContext // wxGLContext
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
class WXDLLEXPORT wxGLContext: public wxObject class WXDLLEXPORT wxGLContext : public wxGLContextBase
{ {
public: public:
wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette ); wxGLContext(wxWindow* win, const wxGLContext* other = NULL);
wxGLContext(
bool WXUNUSED(isRGB), wxWindow *win,
const wxPalette& WXUNUSED(palette),
const wxGLContext *other /* for sharing display lists */
);
virtual ~wxGLContext(); virtual ~wxGLContext();
void SetCurrent(); virtual void SetCurrent(const wxGLCanvas& win) const;
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;
private: private:
DECLARE_CLASS(wxGLContext) GLXContext m_glContext;
DECLARE_CLASS(wxGLContext)
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxGLCanvas // wxGLCanvas
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
class WXDLLEXPORT wxGLCanvas: public wxWindow class WXDLLEXPORT wxGLCanvas : public wxGLCanvasBase
{ {
public: public:
inline wxGLCanvas() { wxGLCanvas(wxWindow *parent,
m_glContext = (wxGLContext*) NULL; wxWindowID id = wxID_ANY,
m_sharedContext = (wxGLContext*) NULL; const int *attribList = NULL,
m_glWidget = (GtkWidget*) NULL; const wxPoint& pos = wxDefaultPosition,
m_vi = (void*) NULL; const wxSize& size = wxDefaultSize,
m_exposed = FALSE; long style = 0,
} const wxString& name = wxGLCanvasName,
wxGLCanvas( wxWindow *parent, wxWindowID id = -1, const wxPalette& palette = wxNullPalette);
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, bool Create(wxWindow *parent,
const wxGLContext *shared = (wxGLContext*)NULL, wxWindowID id = wxID_ANY,
const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL,
wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
const wxString& name = wxGLCanvasName, const wxString& name = wxGLCanvasName,
int *attribList = (int*) NULL, const int *attribList = NULL,
const wxPalette& palette = wxNullPalette ); 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* void *m_vi; // actually an XVisualInfo*
GLXFBConfig *m_fbc; GLXFBConfig *m_fbc;
bool m_canFreeVi; bool m_canFreeVi;
bool m_canFreeFBC; bool m_canFreeFBC;
GtkWidget *m_glWidget; 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 an XVisualInfo* based on desired GL attributes;
// returns NULL if an appropriate visual is not found. The // returns NULL if an appropriate visual is not found. The
// caller is reponsible for using XFree() to deallocate // caller is reponsible for using XFree() to deallocate
// the returned structure. // the returned structure.
static void* ChooseGLVisual(int *attribList); static void* ChooseGLVisual(const int *attribList);
static void* ChooseGLFBC(int *attribList); static void* ChooseGLFBC(const int *attribList);
static void GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList ); static void GetGLAttribListFromWX(const int *wx_attribList, int *gl_attribList );
static void QueryGLXVersion();
static int GetGLXVersion();
static int m_glxVersion;
private: private:
DECLARE_EVENT_TABLE()
DECLARE_CLASS(wxGLCanvas) DECLARE_CLASS(wxGLCanvas)
}; };
#endif #endif // _WX_GLCANVAS_H_
// _WX_GLCANVAS_H_

View File

@@ -12,14 +12,6 @@
#ifndef _WX_GLCANVAS_H_ #ifndef _WX_GLCANVAS_H_
#define _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__ #ifdef __DARWIN__
# include <OpenGL/gl.h> # include <OpenGL/gl.h>
# include <AGL/agl.h> # include <AGL/agl.h>
@@ -28,79 +20,121 @@
# include <agl.h> # include <agl.h>
#endif #endif
class WXDLLEXPORT wxGLCanvas; /* forward reference */ class WXDLLEXPORT wxGLContext : public wxGLContextBase
class WXDLLEXPORT wxGLContext: public wxObject
{ {
public: public:
wxGLContext(AGLPixelFormat fmt, wxGLCanvas *win, wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
const wxPalette& WXUNUSED(palette), virtual ~wxGLContext();
const wxGLContext *other /* for sharing display lists */
);
virtual ~wxGLContext();
void SetCurrent(); virtual void SetCurrent(const wxGLCanvas& win) const;
void Update(); // must be called after window drag/grows/zoom or clut change
void SetColour(const wxChar *colour);
void SwapBuffers();
// Mac-specific
AGLContext GetAGLContext() const { return m_aglContext; }
inline wxWindow* GetWindow() const { return m_window; } private:
inline AGLDrawable GetDrawable() const { return m_drawable; } AGLContext m_aglContext;
public: DECLARE_NO_COPY_CLASS(wxGLContext)
AGLContext m_glContext;
AGLDrawable m_drawable;
wxWindow* m_window;
}; };
class WXDLLEXPORT wxGLCanvas: public wxWindow class WXDLLEXPORT wxGLCanvas : public wxGLCanvasBase
{ {
DECLARE_CLASS(wxGLCanvas) public:
public: wxGLCanvas(wxWindow *parent,
wxGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, wxWindowID id = wxID_ANY,
const wxSize& size = wxDefaultSize, long style = 0, const int *attribList = NULL,
const wxString& name = wxT("GLCanvas") , int *attribList = 0, const wxPalette& palette = wxNullPalette); const wxPoint& pos = wxDefaultPosition,
wxGLCanvas( wxWindow *parent, const wxGLContext *shared, const wxSize& size = wxDefaultSize,
wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, long style = 0,
const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxT("GLCanvas"), const wxString& name = wxGLCanvasName,
int *attribList = (int*) NULL, const wxPalette& palette = wxNullPalette ); const wxPalette& palette = wxNullPalette);
wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID id = wxID_ANY, bool Create(wxWindow *parent,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, wxWindowID id = wxID_ANY,
const wxString& name = wxT("GLCanvas"), int *attribList = 0, const wxPalette& palette = wxNullPalette ); 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(); virtual ~wxGLCanvas();
bool Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id, // implement wxGLCanvasBase methods
const wxPoint& pos, const wxSize& size, long style, const wxString& name, virtual void SwapBuffers();
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. // Mac-specific functions
// 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() ; // return the pixel format used by this window
virtual void MacTopLevelWindowChangedPosition() ; AGLPixelFormat GetAGLPixelFormat() const { return m_aglFormat; }
virtual void MacVisibilityChanged() ;
void MacUpdateView() ; // update the view port of the current context to match this window
void SetViewport();
inline wxGLContext* GetContext() const { return m_glContext; }
// 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: protected:
wxGLContext* m_glContext; AGLPixelFormat m_aglFormat;
bool m_macCanvasIsShown ;
DECLARE_EVENT_TABLE() bool m_macCanvasIsShown,
m_needsUpdate;
DECLARE_EVENT_TABLE()
DECLARE_CLASS(wxGLCanvas)
}; };
#endif // wxUSE_GLCANVAS
#endif // _WX_GLCANVAS_H_ #endif // _WX_GLCANVAS_H_

View File

@@ -13,22 +13,24 @@
#define _WX_GLCANVAS_H_ #define _WX_GLCANVAS_H_
#include "wx/palette.h" #include "wx/palette.h"
#include "wx/scrolwin.h"
#include "wx/msw/wrapwin.h" #include "wx/msw/wrapwin.h"
#include <GL/gl.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: public:
wxGLContext(wxGLCanvas *win, const wxGLContext* other=NULL /* for sharing display lists */ ); wxGLContext(wxGLCanvas *win, const wxGLContext* other = NULL);
virtual ~wxGLContext(); virtual ~wxGLContext();
void SetCurrent(const wxGLCanvas& win) const; virtual void SetCurrent(const wxGLCanvas& win) const;
inline HGLRC GetGLRC() const { return m_glContext; }
HGLRC GetGLRC() const { return m_glContext; }
protected: protected:
HGLRC m_glContext; HGLRC m_glContext;
@@ -37,92 +39,111 @@ private:
DECLARE_CLASS(wxGLContext) DECLARE_CLASS(wxGLContext)
}; };
class WXDLLIMPEXP_GL wxGLCanvas: public wxWindow // ----------------------------------------------------------------------------
// wxGLCanvas: OpenGL output window
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasBase
{ {
public: 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, wxGLCanvas(wxWindow *parent,
const wxGLContext *shared, wxWindowID id = wxID_ANY,
wxWindowID id = wxID_ANY, const int *attribList = NULL,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
const wxString& name = wxGLCanvasName, const wxString& name = wxGLCanvasName,
int *attribList = (int *) NULL, const wxPalette& palette = wxNullPalette);
const wxPalette& palette = wxNullPalette);
wxGLCanvas(wxWindow *parent, bool Create(wxWindow *parent,
const wxGLCanvas *shared, wxWindowID id = wxID_ANY,
wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
const wxSize& size = wxDefaultSize, long style = 0,
long style = 0, const wxString& name = wxGLCanvasName,
const wxString& name = wxGLCanvasName, const int *attribList = NULL,
int *attribList = 0, const wxPalette& palette = wxNullPalette);
const wxPalette& palette = wxNullPalette);
virtual ~wxGLCanvas(); virtual ~wxGLCanvas();
// Replaces wxWindow::Create functionality, since // implement wxGLCanvasBase methods
// we need to use a different window class virtual void SwapBuffers();
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();
#ifdef __WXUNIVERSAL__ // MSW-specific helpers
virtual bool SetCurrent(bool doit) { return wxWindow::SetCurrent(doit); }; // --------------------
#endif
void SetColour(const wxChar *colour); // get the HDC used for OpenGL rendering
HDC GetHDC() const { return m_hDC; }
void SwapBuffers(); // 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
void OnSize(wxSizeEvent& event); // 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 OnQueryNewPalette(wxQueryNewPaletteEvent& event);
void OnPaletteChanged(wxPaletteChangedEvent& event); void OnPaletteChanged(wxPaletteChangedEvent& event);
#endif // wxUSE_PALETTE
inline wxGLContext* GetContext() const { return m_glContext; } // 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)
);
inline WXHDC GetHDC() const { return m_hDC; } 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)
);
void SetupPixelFormat(int *attribList = (int *) NULL); wxDEPRECATED(
wxGLCanvas(wxWindow *parent,
void SetupPalette(const wxPalette& palette); const wxGLCanvas *shared,
wxWindowID id = wxID_ANY,
wxPalette CreateDefaultPalette(); const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
inline wxPalette* GetPalette() const { return (wxPalette *) &m_palette; } long style = 0,
const wxString& name = wxGLCanvasName,
const int *attribList = NULL,
const wxPalette& palette = wxNullPalette)
);
#endif // WXWIN_COMPATIBILITY_2_8
protected: protected:
wxGLContext* m_glContext; // this is typedef-ed ptr, in fact // common part of all ctors
wxPalette m_palette; void Init();
WXHDC m_hDC;
// set up the pixel format using the given attributes and palette
bool DoSetup(const int *attribList);
// HDC for this window, we keep it all the time
HDC m_hDC;
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_CLASS(wxGLCanvas) DECLARE_CLASS(wxGLCanvas)
}; };
#endif #endif // _WX_GLCANVAS_H_
// _WX_GLCANVAS_H_

View File

@@ -114,13 +114,7 @@ public:
void SetupPalette(const wxPalette& palette); void SetupPalette(const wxPalette& palette);
wxPalette CreateDefaultPalette();
inline wxPalette* GetPalette() const { return (wxPalette *) &m_palette; }
protected: protected:
wxGLContext* m_glContext; // this is typedef-ed ptr, in fact
wxPalette m_palette;
WXHDC m_hDC; WXHDC m_hDC;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()

View File

@@ -13,13 +13,7 @@
#ifndef _WX_GLCANVAS_H_ #ifndef _WX_GLCANVAS_H_
#define _WX_GLCANVAS_H_ #define _WX_GLCANVAS_H_
#include "wx/defs.h"
#if wxUSE_GLCANVAS
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/palette.h"
#include "wx/scrolwin.h"
#include <GL/glx.h> #include <GL/glx.h>
@@ -27,111 +21,54 @@
// classes // classes
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
class WXDLLEXPORT wxGLContext : public wxGLContextBase
class WXDLLEXPORT wxGLContext: public wxObject
{ {
public: public:
wxGLContext( bool isRGB, wxWindow *win, wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
const wxPalette& palette = wxNullPalette );
wxGLContext( bool WXUNUSED(isRGB), wxWindow *win,
const wxPalette& WXUNUSED(palette),
const wxGLContext *other /* for sharing display lists */
);
virtual ~wxGLContext(); virtual ~wxGLContext();
void SetCurrent(); virtual void SetCurrent(const wxGLCanvas& win) const;
void SetColour(const wxChar *colour);
void SwapBuffers();
void SetupPixelFormat(); private:
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; GLXContext m_glContext;
// GtkWidget *m_widget;
wxPalette m_palette;
wxWindow* m_window;
DECLARE_CLASS(wxGLContext) DECLARE_CLASS(wxGLContext)
}; };
class WXDLLEXPORT wxGLCanvas: public wxScrolledWindow class WXDLLEXPORT wxGLCanvas : public wxGLCanvasBase
{ {
public: public:
inline wxGLCanvas() { wxGLCanvas(wxWindow *parent,
m_glContext = (wxGLContext*) NULL; wxWindowID id = wxID_ANY,
m_sharedContext = (wxGLContext*) NULL; const int *attribList = NULL,
// m_glWidget = (GtkWidget*) NULL; const wxPoint& pos = wxDefaultPosition,
m_vi = (void*) NULL; const wxSize& size = wxDefaultSize,
// m_exposed = FALSE; long style = 0,
} const wxString& name = wxGLCanvasName,
wxGLCanvas( wxWindow *parent, wxWindowID id = wxID_ANY, const wxPalette& palette = wxNullPalette);
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, bool Create(wxWindow *parent,
const wxGLContext *shared = (wxGLContext*)NULL, wxWindowID id = wxID_ANY,
const wxGLCanvas *shared_context_of = (wxGLCanvas*)NULL, const wxPoint& pos = wxDefaultPosition,
wxWindowID id = wxID_ANY, const wxSize& size = wxDefaultSize,
const wxPoint& pos = wxDefaultPosition, long style = 0,
const wxSize& size = wxDefaultSize, const wxString& name = wxGLCanvasName,
long style = 0, const wxString& name = wxT("GLCanvas"), const int *attribList = NULL,
int *attribList = (int*) NULL, const wxPalette& palette = wxNullPalette);
const wxPalette& palette = wxNullPalette );
virtual ~wxGLCanvas(); virtual ~wxGLCanvas();
void SetCurrent(); virtual void SwapBuffers();
void SetColour(const wxChar *colour);
void SwapBuffers();
// void OnSize(wxSizeEvent& event);
// void OnInternalIdle();
inline wxGLContext* GetContext() const { return m_glContext; }
// implementation // implementation
void *m_vi;
wxGLContext *m_glContext, protected:
*m_sharedContext; virtual int GetColourIndex(const wxColour& col);
wxGLCanvas *m_sharedContextOf;
void *m_vi;
// GtkWidget *m_glWidget;
// bool m_exposed;
DECLARE_EVENT_TABLE()
DECLARE_CLASS(wxGLCanvas)
DECLARE_CLASS(wxGLCanvas)
}; };
#endif #endif // _WX_GLCANVAS_H_
// wxUSE_GLCANVAS
#endif
// _WX_GLCANVAS_H_

View File

@@ -23,42 +23,31 @@
#import <AppKit/NSOpenGL.h> #import <AppKit/NSOpenGL.h>
#import <AppKit/NSOpenGLView.h> #import <AppKit/NSOpenGLView.h>
IMPLEMENT_DYNAMIC_CLASS(wxGLCanvas, wxWindow) wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other)
BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow) {
END_EVENT_TABLE() // TODO
}
wxGLContext::~wxGLContext()
{
}
void wxGLContext::SetCurrent(const wxGLCanvas& win) const
{
[[win.GetNSOpenGLView() openGLContext] makeCurrentContext];
}
IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
// WX_IMPLEMENT_COCOA_OWNER(wxGLCanvas,NSOpenGLView,NSView,NSView) // WX_IMPLEMENT_COCOA_OWNER(wxGLCanvas,NSOpenGLView,NSView,NSView)
wxGLCanvas::wxGLCanvas(wxWindow *parent, bool wxGLCanvas::Create(wxWindow *parent,
wxWindowID winid, const wxPoint& pos, const wxSize& size, wxWindowID winid,
long style, const wxString& name, const wxPoint& pos,
int *attribList, const wxPalette& palette) const wxSize& size,
{ long style,
Create(parent,winid,pos,size,style,name); const wxString& name,
} const int *attribList,
const wxPalette& palette)
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)
{
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)
{
Create(parent,winid,pos,size,style,name);
}
bool wxGLCanvas::Create(wxWindow *parent, wxWindowID winid,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{ {
wxAutoNSAutoreleasePool pool; wxAutoNSAutoreleasePool pool;
if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name)) 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() void wxGLCanvas::SwapBuffers()
{ {
[[(NSOpenGLView*)m_cocoaNSView openGLContext] flushBuffer]; [[GetNSOpenGLView() openGLContext] flushBuffer];
} }
#endif // wxUSE_GLCANVAS #endif // wxUSE_GLCANVAS

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

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

View File

@@ -339,6 +339,11 @@ wxApp::~wxApp()
{ {
if (m_idleTag) if (m_idleTag)
g_source_remove( m_idleTag ); g_source_remove( m_idleTag );
if (m_glFBCInfo)
XFree(m_glFBCInfo);
if (m_glVisualInfo)
XFree(m_glVisualInfo);
} }
bool wxApp::OnInitGui() bool wxApp::OnInitGui()

View File

@@ -33,22 +33,26 @@ extern "C"
#include "wx/gtk/win_gtk.h" #include "wx/gtk/win_gtk.h"
#include "wx/gtk/private.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 // global data
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
XVisualInfo *g_vi = (XVisualInfo*) NULL; 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 // wxGLContext
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -61,16 +65,14 @@ wxGLContext::wxGLContext(wxWindow* win, const wxGLContext* other)
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3
GLXFBConfig *fbc = gc->m_fbc; GLXFBConfig *fbc = gc->m_fbc;
wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") ); wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE,
other ? other->m_glContext : None, other ? other->m_glContext : None,
GL_TRUE ); GL_TRUE );
} }
else else // GLX <= 1.2
{ {
// GLX <= 1.2
XVisualInfo *vi = (XVisualInfo *) gc->m_vi; XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
wxCHECK_RET( vi, _T("invalid visual for OpenGl") ); wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
m_glContext = glXCreateContext( GDK_DISPLAY(), vi, m_glContext = glXCreateContext( GDK_DISPLAY(), vi,
@@ -78,66 +80,50 @@ wxGLContext::wxGLContext(wxWindow* win, const wxGLContext* other)
GL_TRUE ); GL_TRUE );
} }
if ( !m_glContext ) wxASSERT_MSG( m_glContext, _T("Couldn't create OpenGl context") );
{
wxFAIL_MSG( _T("Couldn't create OpenGl context") );
}
} }
wxGLContext::~wxGLContext() wxGLContext::~wxGLContext()
{ {
if (!m_glContext) return; if ( !m_glContext )
return;
if (m_glContext == glXGetCurrentContext()) if ( m_glContext == glXGetCurrentContext() )
{ wxMakeContextCurrent(None, NULL);
if (wxGLCanvas::GetGLXVersion() >= 13)
// GLX >= 1.3
glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL);
else
// GLX <= 1.2
glXMakeCurrent( GDK_DISPLAY(), None, NULL);
}
glXDestroyContext( GDK_DISPLAY(), m_glContext ); glXDestroyContext( GDK_DISPLAY(), m_glContext );
} }
void wxGLContext::SetCurrent(const wxGLCanvas& win) const void wxGLContext::SetCurrent(const wxGLCanvas& win) const
{ {
if (m_glContext) if ( !m_glContext )
{ return;
GdkWindow *window = GTK_PIZZA(win.m_wxwindow)->bin_window;
if (wxGLCanvas::GetGLXVersion() >= 13) GdkWindow *window = GTK_PIZZA(win.m_wxwindow)->bin_window;
// GLX >= 1.3 wxCHECK_RET( window, _T("window must be shown") );
glXMakeContextCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), GDK_WINDOW_XWINDOW(window), m_glContext );
else wxMakeContextCurrent(GDK_WINDOW_XWINDOW(window), m_glContext);
// GLX <= 1.2
glXMakeCurrent( GDK_DISPLAY(), 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" { extern "C" {
static gint static gint
gtk_glwindow_realized_callback( GtkWidget *WXUNUSED(widget), wxGLCanvas *win ) gtk_glwindow_realized_callback( GtkWidget *WXUNUSED(widget), wxGLCanvas *win )
{ {
if (!win->m_glContext && win->m_createImplicitContext) win->GTKInitImplicitContext();
{
wxGLContext *share = win->m_sharedContext;
if ( !share && win->m_sharedContextOf )
share = win->m_sharedContextOf->GetContext();
win->m_glContext = new wxGLContext(win, share);
}
return FALSE; return FALSE;
} }
} }
#endif // WXWIN_COMPATIBILITY_2_8
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "map" from m_wxwindow // "map" from m_wxwindow
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -146,16 +132,12 @@ extern "C" {
static gint static gint
gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win ) gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win )
{ {
// CF: Can the "if" line be removed, and the code unconditionally (always) be run? wxPaintEvent event( win->GetId() );
if (win->m_glContext || !win->m_createImplicitContext) event.SetEventObject( win );
{ win->GetEventHandler()->ProcessEvent( event );
wxPaintEvent event( win->GetId() );
event.SetEventObject( win );
win->GetEventHandler()->ProcessEvent( event );
win->m_exposed = false; win->m_exposed = false;
win->GetUpdateRegion().Clear(); win->GetUpdateRegion().Clear();
}
return FALSE; return FALSE;
} }
@@ -207,76 +189,83 @@ gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, w
IMPLEMENT_CLASS(wxGLCanvas, wxWindow) IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow) wxGLCanvas::wxGLCanvas(wxWindow *parent,
EVT_SIZE(wxGLCanvas::OnSize) wxWindowID id,
END_EVENT_TABLE() const int *attribList,
const wxPoint& pos,
wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id, const wxSize& size,
int *attribList, long style,
const wxPoint& pos, const wxSize& size, const wxString& name,
long style, const wxString& name, const wxPalette& palette)
const wxPalette& palette ) #if WXWIN_COMPATIBILITY_2_8
: m_createImplicitContext(false) : 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, #if WXWIN_COMPATIBILITY_2_8
const wxPoint& pos, const wxSize& size,
long style, const wxString& name, wxGLCanvas::wxGLCanvas(wxWindow *parent,
int *attribList, wxWindowID id,
const wxPalette& palette ) const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name,
const int *attribList,
const wxPalette& palette)
: m_createImplicitContext(true) : 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, wxGLCanvas::wxGLCanvas(wxWindow *parent,
const wxGLContext *shared, 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)
{
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,
const int *attribList,
const wxPalette& palette )
: m_createImplicitContext(true)
{
m_sharedContextOf = wx_const_cast(wxGLCanvas *, shared);
Create(parent, id, pos, size, style, name, attribList, palette);
}
#endif // WXWIN_COMPATIBILITY_2_8
bool wxGLCanvas::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos,
long style, const wxString& name, const wxSize& size,
int *attribList, long style,
const wxPalette& palette ) const wxString& name,
: m_createImplicitContext(true) const int *attribList,
const wxPalette& palette)
{ {
Create( parent, shared, NULL, 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 )
: m_createImplicitContext(true)
{
Create( parent, NULL, shared, 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;
m_exposed = false; m_exposed = false;
m_noExpose = true; m_noExpose = true;
m_nativeSizeEvent = true; m_nativeSizeEvent = true;
m_fbc = NULL; m_fbc = NULL;
m_vi = NULL; m_vi = NULL;
// to be sure the glx version is known
wxGLCanvas::QueryGLXVersion();
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 uses a GLXFBConfig // GLX >= 1.3 uses a GLXFBConfig
@@ -340,7 +329,7 @@ bool wxGLCanvas::Create( wxWindow *parent,
gtk_widget_set_colormap( m_glWidget, colormap ); gtk_widget_set_colormap( m_glWidget, colormap );
} }
else else
#endif #endif // GTK+ >= 2.2
{ {
visual = gdkx_visual_get( vi->visualid ); visual = gdkx_visual_get( vi->visualid );
colormap = gdk_colormap_new( visual, TRUE ); colormap = gdk_colormap_new( visual, TRUE );
@@ -353,7 +342,9 @@ bool wxGLCanvas::Create( wxWindow *parent,
gtk_widget_set_double_buffered( m_glWidget, FALSE ); 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); 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, "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_wxwindow, "expose_event", G_CALLBACK(gtk_glwindow_expose_callback), this);
g_signal_connect(m_widget, "size_allocate", G_CALLBACK(gtk_glcanvas_size_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(); gtk_widget_pop_colormap();
} }
#if WXWIN_COMPATIBILITY_2_8
// if our parent window is already visible, we had been realized before we // 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 // connected to the "realize" signal and hence our m_glContext hasn't been
// initialized yet and we have to do it now // initialized yet and we have to do it now
if (GTK_WIDGET_REALIZED(m_wxwindow)) if (GTK_WIDGET_REALIZED(m_wxwindow))
gtk_glwindow_realized_callback( m_wxwindow, this ); gtk_glwindow_realized_callback( m_wxwindow, this );
#endif // WXWIN_COMPATIBILITY_2_8
if (GTK_WIDGET_MAPPED(m_wxwindow)) if (GTK_WIDGET_MAPPED(m_wxwindow))
gtk_glwindow_map_callback( m_wxwindow, this ); gtk_glwindow_map_callback( m_wxwindow, this );
@@ -384,41 +377,40 @@ wxGLCanvas::~wxGLCanvas()
XVisualInfo *vi = (XVisualInfo *) m_vi; XVisualInfo *vi = (XVisualInfo *) m_vi;
if (vi && m_canFreeVi) if (vi && m_canFreeVi)
XFree( vi ); XFree( vi );
delete m_glContext;
} }
void* wxGLCanvas::ChooseGLVisual(int *attribList) void* wxGLCanvas::ChooseGLVisual(const int *attribList)
{ {
int data[512]; int data[512];
GetGLAttribListFromWX( attribList, data ); GetGLAttribListFromWX( attribList, data );
attribList = (int*) data;
Display *dpy = GDK_DISPLAY(); 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]; int data[512];
GetGLAttribListFromWX( attribList, data ); GetGLAttribListFromWX( attribList, data );
attribList = (int*) data;
int returned; int returned;
return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()), 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) if (wxGLCanvas::GetGLXVersion() >= 13)
// leave GLX >= 1.3 choose the default attributes {
// leave GLX >= 1.3 choose the default attributes
gl_attribList[0] = 0; gl_attribList[0] = 0;
else }
else // GLX < 1.3
{ {
int i = 0; int i = 0;
// default settings if attriblist = 0 // default settings if attriblist = 0
@@ -432,7 +424,7 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
gl_attribList[i++] = None; gl_attribList[i++] = None;
} }
} }
else else // have non-default attributes
{ {
int arg=0, p=0; int arg=0, p=0;
while( (wx_attribList[arg]!=0) && (p<510) ) while( (wx_attribList[arg]!=0) && (p<510) )
@@ -441,8 +433,10 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
{ {
case WX_GL_RGBA: case WX_GL_RGBA:
if (wxGLCanvas::GetGLXVersion() <= 12) if (wxGLCanvas::GetGLXVersion() <= 12)
{
// for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm) // for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm)
gl_attribList[p++] = GLX_RGBA; gl_attribList[p++] = GLX_RGBA;
}
break; break;
case WX_GL_BUFFER_SIZE: case WX_GL_BUFFER_SIZE:
gl_attribList[p++] = GLX_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++]; gl_attribList[p++] = wx_attribList[arg++];
break; break;
case WX_GL_DOUBLEBUFFER: case WX_GL_DOUBLEBUFFER:
if (wxGLCanvas::GetGLXVersion() <= 12) gl_attribList[p++] = GLX_DOUBLEBUFFER;
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++] = 1; gl_attribList[p++] = 1;
break; break;
case WX_GL_STEREO: 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 // check the GLX version
int glxMajorVer, glxMinorVer; int glxMajorVer, glxMinorVer;
bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer); bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer);
wxASSERT_MSG( ok, _T("GLX version not found") ); wxASSERT_MSG( ok, _T("GLX version not found") );
if (!ok) if (!ok)
m_glxVersion = 10; // 1.0 by default s_glxVersion = 10; // 1.0 by default
else else
m_glxVersion = glxMajorVer*10 + glxMinorVer; s_glxVersion = glxMajorVer*10 + glxMinorVer;
} }
}
int wxGLCanvas::GetGLXVersion() return s_glxVersion;
{
wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") );
return m_glxVersion;
} }
void wxGLCanvas::SwapBuffers() void wxGLCanvas::SwapBuffers()
{ {
GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window; GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window;
glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( 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() void wxGLCanvas::OnInternalIdle()
{ {
if (/*m_glContext &&*/ m_exposed) if (m_exposed)
{ {
wxPaintEvent event( GetId() ); wxPaintEvent event( GetId() );
event.SetEventObject( this ); event.SetEventObject( this );
@@ -588,50 +546,49 @@ void wxGLCanvas::OnInternalIdle()
wxWindow::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 // wxGLApp
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGLApp, wxApp) bool wxGLApp::InitGLVisual(const int *attribList)
wxGLApp::~wxGLApp()
{ {
if (m_glFBCInfo) if ( wxGLCanvas::GetGLXVersion() >= 13 )
XFree(m_glFBCInfo);
if (m_glVisualInfo)
XFree(m_glVisualInfo);
}
bool wxGLApp::InitGLVisual(int *attribList)
{
wxGLCanvas::QueryGLXVersion();
if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3
if (m_glFBCInfo) if (m_glFBCInfo)
XFree(m_glFBCInfo); XFree(m_glFBCInfo);
m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList); m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList);
if (m_glFBCInfo) if ( !m_glFBCInfo )
{ return false;
if (m_glVisualInfo)
XFree(m_glVisualInfo); if (m_glVisualInfo)
m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]); XFree(m_glVisualInfo);
} m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL);
} }
else else // GLX <= 1.2
{ {
// GLX <= 1.2
if (m_glVisualInfo) if (m_glVisualInfo)
XFree(m_glVisualInfo); XFree(m_glVisualInfo);
m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList); m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList);
return m_glVisualInfo != NULL;
} }
return m_glVisualInfo != NULL;
} }
#endif #endif // wxUSE_GLCANVAS
// wxUSE_GLCANVAS

View File

@@ -31,22 +31,14 @@ extern "C"
} }
#include "wx/gtk1/win_gtk.h" #include "wx/gtk1/win_gtk.h"
#include "wx/gtk1/private.h"
// DLL options compatibility check:
#include "wx/build.h"
WX_CHECK_BUILD_OPTIONS("wxGL")
//---------------------------------------------------------------------------
// static variables
//---------------------------------------------------------------------------
int wxGLCanvas::m_glxVersion = 0;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// global data // global data
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
XVisualInfo *g_vi = (XVisualInfo*) NULL; XVisualInfo *g_vi = (XVisualInfo*) NULL;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// idle system // idle system
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -54,60 +46,40 @@ XVisualInfo *g_vi = (XVisualInfo*) NULL;
extern void wxapp_install_idle_handler(); extern void wxapp_install_idle_handler();
extern bool g_isIdle; 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 // wxGLContext
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGLContext,wxObject) IMPLEMENT_CLASS(wxGLContext,wxObject)
wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette& WXUNUSED(palette) ) wxGLContext::wxGLContext(wxWindow* win, const wxGLContext* other)
{ {
m_window = win;
m_widget = win->m_wxwindow;
wxGLCanvas *gc = (wxGLCanvas*) win; wxGLCanvas *gc = (wxGLCanvas*) win;
if (wxGLCanvas::GetGLXVersion() >= 13) 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 */
)
{
m_window = win;
m_widget = win->m_wxwindow;
wxGLCanvas *gc = (wxGLCanvas*) win;
if (wxGLCanvas::GetGLXVersion() >= 13)
{
// GLX >= 1.3
GLXFBConfig *fbc = gc->m_fbc; GLXFBConfig *fbc = gc->m_fbc;
wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") ); wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") );
m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE,
other ? other->m_glContext : None, other ? other->m_glContext : None,
GL_TRUE ); GL_TRUE );
} }
else else // GLX <= 1.2
{ {
// GLX <= 1.2
XVisualInfo *vi = (XVisualInfo *) gc->m_vi; XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
wxCHECK_RET( vi, _T("invalid visual for OpenGl") ); wxCHECK_RET( vi, _T("invalid visual for OpenGl") );
m_glContext = glXCreateContext( GDK_DISPLAY(), vi, m_glContext = glXCreateContext( GDK_DISPLAY(), vi,
@@ -115,100 +87,50 @@ wxGLContext::wxGLContext(
GL_TRUE ); GL_TRUE );
} }
if ( !m_glContext ) wxASSERT_MSG( m_glContext, _T("Couldn't create OpenGl context") );
{
wxFAIL_MSG( _T("Couldn't create OpenGl context") );
}
} }
wxGLContext::~wxGLContext() wxGLContext::~wxGLContext()
{ {
if (!m_glContext) return; if ( !m_glContext )
return;
if (m_glContext == glXGetCurrentContext()) if ( m_glContext == glXGetCurrentContext() )
{ wxMakeContextCurrent(None, NULL);
if (wxGLCanvas::GetGLXVersion() >= 13)
// GLX >= 1.3
glXMakeContextCurrent( GDK_DISPLAY(), None, None, NULL);
else
// GLX <= 1.2
glXMakeCurrent( GDK_DISPLAY(), None, NULL);
}
glXDestroyContext( GDK_DISPLAY(), m_glContext ); glXDestroyContext( GDK_DISPLAY(), m_glContext );
} }
void wxGLContext::SwapBuffers() void wxGLContext::SetCurrent(const wxGLCanvas& win) const
{ {
if (m_glContext) if ( !m_glContext )
{ return;
GdkWindow *window = GTK_PIZZA(m_widget)->bin_window;
glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( window ) ); GdkWindow *window = GTK_PIZZA(win.m_wxwindow)->bin_window;
} wxCHECK_RET( window, _T("window must be shown") );
wxMakeContextCurrent(GDK_WINDOW_XWINDOW(window), m_glContext);
} }
void wxGLContext::SetCurrent()
{
if (m_glContext)
{
GdkWindow *window = GTK_PIZZA(m_widget)->bin_window;
if (wxGLCanvas::GetGLXVersion() >= 13) #if WXWIN_COMPATIBILITY_2_8
// 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 );
}
}
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);
}
}
void wxGLContext::SetupPixelFormat()
{
}
void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) )
{
}
wxPalette wxGLContext::CreateDefaultPalette()
{
return wxNullPalette;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "realize" from m_wxwindow // "realize" from m_wxwindow: used to create m_glContext implicitly
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern "C" { extern "C" {
static gint static gint
gtk_glwindow_realized_callback( GtkWidget *WXUNUSED(widget), wxGLCanvas *win ) gtk_glwindow_realized_callback( GtkWidget *WXUNUSED(widget), wxGLCanvas *win )
{ {
if ( !win->m_glContext ) win->GTKInitImplicitContext();
{
wxGLContext *share = win->m_sharedContext;
if ( !share && win->m_sharedContextOf )
share = win->m_sharedContextOf->GetContext();
win->m_glContext = new wxGLContext( TRUE, win, wxNullPalette, share );
}
return FALSE; return FALSE;
} }
} }
#endif // WXWIN_COMPATIBILITY_2_8
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "map" from m_wxwindow // "map" from m_wxwindow
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -217,15 +139,11 @@ extern "C" {
static gint static gint
gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win ) gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win )
{ {
if (win->m_glContext/* && win->m_exposed*/) wxPaintEvent event( win->GetId() );
{ event.SetEventObject( win );
wxPaintEvent event( win->GetId() ); win->GetEventHandler()->ProcessEvent( event );
event.SetEventObject( win );
win->GetEventHandler()->ProcessEvent( event );
win->m_exposed = false; win->GetUpdateRegion().Clear();
win->GetUpdateRegion().Clear();
}
return FALSE; return FALSE;
} }
@@ -242,8 +160,6 @@ gtk_glwindow_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_e
if (g_isIdle) if (g_isIdle)
wxapp_install_idle_handler(); wxapp_install_idle_handler();
win->m_exposed = true;
win->GetUpdateRegion().Union( gdk_event->area.x, win->GetUpdateRegion().Union( gdk_event->area.x,
gdk_event->area.y, gdk_event->area.y,
gdk_event->area.width, gdk_event->area.width,
@@ -262,8 +178,6 @@ gtk_glwindow_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxG
if (g_isIdle) if (g_isIdle)
wxapp_install_idle_handler(); wxapp_install_idle_handler();
win->m_exposed = true;
win->GetUpdateRegion().Union( rect->x, rect->y, win->GetUpdateRegion().Union( rect->x, rect->y,
rect->width, rect->height ); rect->width, rect->height );
} }
@@ -295,63 +209,82 @@ gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, w
IMPLEMENT_CLASS(wxGLCanvas, wxWindow) IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow) wxGLCanvas::wxGLCanvas(wxWindow *parent,
EVT_SIZE(wxGLCanvas::OnSize) wxWindowID id,
END_EVENT_TABLE() const int *attribList,
const wxPoint& pos,
wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id, const wxSize& size,
const wxPoint& pos, const wxSize& size, long style,
long style, const wxString& name, const wxString& name,
int *attribList, const wxPalette& palette)
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, #if WXWIN_COMPATIBILITY_2_8
const wxGLContext *shared,
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, 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,
const int *attribList,
const wxPalette& palette)
: m_createImplicitContext(true)
{
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,
const int *attribList,
const wxPalette& palette )
: m_createImplicitContext(true)
{
m_sharedContextOf = wx_const_cast(wxGLCanvas *, shared);
Create(parent, id, pos, size, style, name, attribList, palette);
}
#endif // WXWIN_COMPATIBILITY_2_8
bool wxGLCanvas::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos,
long style, const wxString& name, const wxSize& size,
int *attribList, long style,
const wxPalette& palette ) const wxString& name,
const int *attribList,
const wxPalette& palette)
{ {
Create( parent, shared, NULL, 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 )
{
Create( parent, NULL, shared, 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;
m_exposed = false;
m_noExpose = true; m_noExpose = true;
m_nativeSizeEvent = true; m_nativeSizeEvent = true;
m_fbc = NULL; m_fbc = NULL;
m_vi = NULL; m_vi = NULL;
// to be sure the glx version is known
wxGLCanvas::QueryGLXVersion();
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3 uses a GLXFBConfig // GLX >= 1.3 uses a GLXFBConfig
@@ -394,64 +327,45 @@ bool wxGLCanvas::Create( wxWindow *parent,
GdkVisual *visual; GdkVisual *visual;
GdkColormap *colormap; GdkColormap *colormap;
// MR: This needs a fix for lower gtk+ versions too. Might need to rethink logic (FIXME) visual = gdkx_visual_get( vi->visualid );
#if 0 colormap = gdk_colormap_new( visual, TRUE );
if (!gtk_check_version(2,2,0))
{
wxWindow::Create( parent, id, pos, size, style, name );
m_glWidget = m_wxwindow; gtk_widget_push_colormap( colormap );
gtk_widget_push_visual( visual );
GdkScreen *screen = gtk_widget_get_screen( m_glWidget ); wxWindow::Create( parent, id, pos, size, style, name );
colormap = gdk_screen_get_default_colormap(screen); m_glWidget = m_wxwindow;
visual = gdk_colormap_get_visual(colormap);
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;
}
gtk_pizza_set_clear( GTK_PIZZA(m_wxwindow), FALSE ); gtk_pizza_set_clear( GTK_PIZZA(m_wxwindow), FALSE );
#if WXWIN_COMPATIBILITY_2_8
gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize", 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_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_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_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_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_visual();
gtk_widget_pop_colormap(); gtk_widget_pop_colormap();
#if WXWIN_COMPATIBILITY_2_8
// if our parent window is already visible, we had been realized before we // 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 // connected to the "realize" signal and hence our m_glContext hasn't been
// initialized yet and we have to do it now // initialized yet and we have to do it now
if (GTK_WIDGET_REALIZED(m_wxwindow)) if (GTK_WIDGET_REALIZED(m_wxwindow))
gtk_glwindow_realized_callback( m_wxwindow, this ); gtk_glwindow_realized_callback( m_wxwindow, this );
#endif // WXWIN_COMPATIBILITY_2_8
if (GTK_WIDGET_MAPPED(m_wxwindow)) if (GTK_WIDGET_MAPPED(m_wxwindow))
gtk_glwindow_map_callback( m_wxwindow, this ); gtk_glwindow_map_callback( m_wxwindow, this );
@@ -468,41 +382,40 @@ wxGLCanvas::~wxGLCanvas()
XVisualInfo *vi = (XVisualInfo *) m_vi; XVisualInfo *vi = (XVisualInfo *) m_vi;
if (vi && m_canFreeVi) if (vi && m_canFreeVi)
XFree( vi ); XFree( vi );
delete m_glContext;
} }
void* wxGLCanvas::ChooseGLVisual(int *attribList) void* wxGLCanvas::ChooseGLVisual(const int *attribList)
{ {
int data[512]; int data[512];
GetGLAttribListFromWX( attribList, data ); GetGLAttribListFromWX( attribList, data );
attribList = (int*) data;
Display *dpy = GDK_DISPLAY(); 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]; int data[512];
GetGLAttribListFromWX( attribList, data ); GetGLAttribListFromWX( attribList, data );
attribList = (int*) data;
int returned; int returned;
return glXChooseFBConfig( GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()), 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) if (wxGLCanvas::GetGLXVersion() >= 13)
// leave GLX >= 1.3 choose the default attributes {
// leave GLX >= 1.3 choose the default attributes
gl_attribList[0] = 0; gl_attribList[0] = 0;
else }
else // GLX < 1.3
{ {
int i = 0; int i = 0;
// default settings if attriblist = 0 // default settings if attriblist = 0
@@ -516,7 +429,7 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
gl_attribList[i++] = None; gl_attribList[i++] = None;
} }
} }
else else // have non-default attributes
{ {
int arg=0, p=0; int arg=0, p=0;
while( (wx_attribList[arg]!=0) && (p<510) ) while( (wx_attribList[arg]!=0) && (p<510) )
@@ -525,8 +438,10 @@ void wxGLCanvas::GetGLAttribListFromWX(int *wx_attribList, int *gl_attribList )
{ {
case WX_GL_RGBA: case WX_GL_RGBA:
if (wxGLCanvas::GetGLXVersion() <= 12) if (wxGLCanvas::GetGLXVersion() <= 12)
{
// for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm) // for GLX >= 1.3, GLX_RGBA is useless (setting this flags will crash on most opengl implm)
gl_attribList[p++] = GLX_RGBA; gl_attribList[p++] = GLX_RGBA;
}
break; break;
case WX_GL_BUFFER_SIZE: case WX_GL_BUFFER_SIZE:
gl_attribList[p++] = GLX_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++]; gl_attribList[p++] = wx_attribList[arg++];
break; break;
case WX_GL_DOUBLEBUFFER: case WX_GL_DOUBLEBUFFER:
if (wxGLCanvas::GetGLXVersion() <= 12) gl_attribList[p++] = GLX_DOUBLEBUFFER;
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++] = 1; gl_attribList[p++] = 1;
break; break;
case WX_GL_STEREO: 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 // check the GLX version
int glxMajorVer, glxMinorVer; int glxMajorVer, glxMinorVer;
bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer); bool ok = glXQueryVersion(GDK_DISPLAY(), &glxMajorVer, &glxMinorVer);
wxASSERT_MSG( ok, _T("GLX version not found") ); wxASSERT_MSG( ok, _T("GLX version not found") );
if (!ok) if (!ok)
m_glxVersion = 10; // 1.0 by default s_glxVersion = 10; // 1.0 by default
else else
m_glxVersion = glxMajorVer*10 + glxMinorVer; s_glxVersion = glxMajorVer*10 + glxMinorVer;
} }
}
int wxGLCanvas::GetGLXVersion() return s_glxVersion;
{
wxASSERT_MSG( m_glxVersion>0, _T("GLX version has not been initialized with wxGLCanvas::QueryGLXVersion()") );
return m_glxVersion;
} }
void wxGLCanvas::SwapBuffers() void wxGLCanvas::SwapBuffers()
{ {
if (m_glContext) GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window;
m_glContext->SwapBuffers(); glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( window ) );
}
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 );
} }
void wxGLCanvas::OnInternalIdle() void wxGLCanvas::OnInternalIdle()
{ {
if (m_glContext && m_exposed) if (!m_updateRegion.IsEmpty())
{ {
wxPaintEvent event( GetId() ); wxPaintEvent event( GetId() );
event.SetEventObject( this ); event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event ); GetEventHandler()->ProcessEvent( event );
m_exposed = false;
GetUpdateRegion().Clear(); GetUpdateRegion().Clear();
} }
wxWindow::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 // wxGLApp
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGLApp, wxApp) bool wxGLApp::InitGLVisual(const int *attribList)
wxGLApp::~wxGLApp()
{ {
if (m_glFBCInfo) if ( wxGLCanvas::GetGLXVersion() >= 13 )
XFree(m_glFBCInfo);
if (m_glVisualInfo)
XFree(m_glVisualInfo);
}
bool wxGLApp::InitGLVisual(int *attribList)
{
wxGLCanvas::QueryGLXVersion();
if (wxGLCanvas::GetGLXVersion() >= 13)
{ {
// GLX >= 1.3
if (m_glFBCInfo) if (m_glFBCInfo)
XFree(m_glFBCInfo); XFree(m_glFBCInfo);
m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList); m_glFBCInfo = wxGLCanvas::ChooseGLFBC(attribList);
if (m_glFBCInfo) if ( !m_glFBCInfo )
{ return false;
if (m_glVisualInfo)
XFree(m_glVisualInfo); if (m_glVisualInfo)
m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]); XFree(m_glVisualInfo);
} m_glVisualInfo = glXGetVisualFromFBConfig(GDK_DISPLAY(), ((GLXFBConfig *)m_glFBCInfo)[0]);
return (m_glFBCInfo != NULL) && (m_glVisualInfo != NULL);
} }
else else // GLX <= 1.2
{ {
// GLX <= 1.2
if (m_glVisualInfo) if (m_glVisualInfo)
XFree(m_glVisualInfo); XFree(m_glVisualInfo);
m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList); m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList);
return m_glVisualInfo != NULL;
} }
return m_glVisualInfo != NULL;
} }
#endif #endif // wxUSE_GLCANVAS
// wxUSE_GLCANVAS

View File

@@ -1,4 +1,4 @@
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: src/mac/carbon/glcanvas.cpp // Name: src/mac/carbon/glcanvas.cpp
// Purpose: wxGLCanvas, for using OpenGL with wxWidgets under Macintosh // Purpose: wxGLCanvas, for using OpenGL with wxWidgets under Macintosh
// Author: Stefan Csomor // Author: Stefan Csomor
@@ -7,7 +7,15 @@
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Stefan Csomor // Copyright: (c) Stefan Csomor
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/wxprec.h" #include "wx/wxprec.h"
@@ -27,86 +35,69 @@
#include "wx/mac/uma.h" #include "wx/mac/uma.h"
// DLL options compatibility check:
#include "wx/build.h"
WX_CHECK_BUILD_OPTIONS("wxGL")
#include "wx/mac/private.h" #include "wx/mac/private.h"
/* // ----------------------------------------------------------------------------
* GLContext implementation // helper functions
*/ // ----------------------------------------------------------------------------
wxGLContext::wxGLContext( static void wxLogAGLError(const char *func)
AGLPixelFormat fmt, wxGLCanvas *win,
const wxPalette& palette,
const wxGLContext *other /* for sharing display lists */
)
{ {
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); // wxGLContext
wxCHECK_RET( b, wxT("Couldn't bind OpenGl context") ); // ----------------------------------------------------------------------------
aglEnable(m_glContext , AGL_BUFFER_RECT ) ;
b = aglSetCurrentContext(m_glContext); wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other)
wxCHECK_RET( b, wxT("Couldn't activate OpenGl context") ); {
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)");
} }
wxGLContext::~wxGLContext() wxGLContext::~wxGLContext()
{ {
if (m_glContext) if ( m_aglContext )
{ {
aglSetCurrentContext(NULL); // it's ok to pass the current context to this function
aglDestroyContext(m_glContext); if ( !aglDestroyContext(m_aglContext) )
wxLogAGLError("aglDestroyContext");
} }
} }
void wxGLContext::SwapBuffers() void wxGLContext::SetCurrent(const wxGLCanvas& win) const
{ {
if (m_glContext) if ( !m_aglContext )
{ return;
aglSwapBuffers(m_glContext);
} AGLDrawable drawable = (AGLDrawable)UMAGetWindowPort(
MAC_WXHWND(win.MacGetTopLevelWindowRef()));
if ( !aglSetDrawable(m_aglContext, drawable) )
wxLogAGLError("aglSetDrawable");
if ( !aglSetCurrentContext(m_aglContext) )
wxLogAGLError("aglSetCurrentContext");
wx_const_cast(wxGLCanvas&, win).SetViewport();
} }
void wxGLContext::SetCurrent() // ----------------------------------------------------------------------------
{ // wxGLCanvas
if (m_glContext) // ----------------------------------------------------------------------------
{
aglSetCurrentContext(m_glContext);
}
}
void wxGLContext::Update()
{
if (m_glContext)
{
aglUpdateContext(m_glContext);
}
}
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);
}
}
/*
* wxGLCanvas implementation
*/
IMPLEMENT_CLASS(wxGLCanvas, wxWindow) IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
@@ -114,96 +105,173 @@ BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
EVT_SIZE(wxGLCanvas::OnSize) EVT_SIZE(wxGLCanvas::OnSize)
END_EVENT_TABLE() END_EVENT_TABLE()
wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id, wxGLCanvas::wxGLCanvas(wxWindow *parent,
const wxPoint& pos, const wxSize& size, long style, const wxString& name, wxWindowID id,
int *attribList, const wxPalette& palette) 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, #if WXWIN_COMPATIBILITY_2_8
const wxGLContext *shared, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name, wxGLCanvas::wxGLCanvas(wxWindow *parent,
int *attribList, const wxPalette& palette ) 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, wxGLCanvas::wxGLCanvas(wxWindow *parent,
const wxPoint& pos, const wxSize& size, long style, const wxString& name, const wxGLContext *shared,
int *attribList, const wxPalette& palette ) 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) { if ( Create(parent, id, pos, size, style, name, attribList, palette) )
delete m_glContext; m_glContext = new wxGLContext(this, shared ? shared->m_glContext : NULL);
m_glContext = NULL;
}
} }
#endif // WXWIN_COMPATIBILITY_2_8
static AGLPixelFormat ChoosePixelFormat(const int *attribList) static AGLPixelFormat ChoosePixelFormat(const int *attribList)
{ {
GLint data[512]; GLint data[512];
GLint defaultAttribs[] = { AGL_RGBA, const GLint defaultAttribs[] =
{
AGL_RGBA,
AGL_DOUBLEBUFFER, AGL_DOUBLEBUFFER,
AGL_MINIMUM_POLICY, AGL_MINIMUM_POLICY, // never choose less than requested
AGL_DEPTH_SIZE, 1, // use largest available depth buffer AGL_DEPTH_SIZE, 1, // use largest available depth buffer
AGL_RED_SIZE, 1, AGL_RED_SIZE, 1,
AGL_GREEN_SIZE, 1, AGL_GREEN_SIZE, 1,
AGL_BLUE_SIZE, 1, AGL_BLUE_SIZE, 1,
AGL_ALPHA_SIZE, 0, AGL_ALPHA_SIZE, 0,
AGL_NONE }; AGL_NONE
GLint *attribs; };
if (!attribList)
const GLint *attribs;
if ( !attribList )
{ {
attribs = defaultAttribs; attribs = defaultAttribs;
} }
else else
{ {
int arg=0, p=0; unsigned p = 0;
data[p++] = AGL_MINIMUM_POLICY; // make _SIZE tags behave more like GLX 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_RGBA:
case WX_GL_BUFFER_SIZE: data[p++] = AGL_RGBA;
data[p++]=AGL_BUFFER_SIZE; data[p++]=attribList[arg++]; break; break;
case WX_GL_LEVEL:
data[p++]=AGL_LEVEL; data[p++]=attribList[arg++]; break; case WX_GL_BUFFER_SIZE:
case WX_GL_DOUBLEBUFFER: data[p++] = AGL_DOUBLEBUFFER; break; data[p++] = AGL_BUFFER_SIZE;
case WX_GL_STEREO: data[p++] = AGL_STEREO; break; data[p++] = attribList[arg++];
case WX_GL_AUX_BUFFERS: break;
data[p++]=AGL_AUX_BUFFERS; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_RED: case WX_GL_LEVEL:
data[p++]=AGL_RED_SIZE; data[p++]=attribList[arg++]; break; data[p++]=AGL_LEVEL;
case WX_GL_MIN_GREEN: data[p++]=attribList[arg++];
data[p++]=AGL_GREEN_SIZE; data[p++]=attribList[arg++]; break; break;
case WX_GL_MIN_BLUE:
data[p++]=AGL_BLUE_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_DOUBLEBUFFER:
case WX_GL_MIN_ALPHA: data[p++] = AGL_DOUBLEBUFFER;
data[p++]=AGL_ALPHA_SIZE; data[p++]=attribList[arg++]; break; break;
case WX_GL_DEPTH_SIZE:
data[p++]=AGL_DEPTH_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_STEREO:
case WX_GL_STENCIL_SIZE: data[p++] = AGL_STEREO;
data[p++]=AGL_STENCIL_SIZE; data[p++]=attribList[arg++]; break; break;
case WX_GL_MIN_ACCUM_RED:
data[p++]=AGL_ACCUM_RED_SIZE; data[p++]=attribList[arg++]; break; case WX_GL_AUX_BUFFERS:
case WX_GL_MIN_ACCUM_GREEN: data[p++] = AGL_AUX_BUFFERS;
data[p++]=AGL_ACCUM_GREEN_SIZE; data[p++]=attribList[arg++]; break; data[p++] = attribList[arg++];
case WX_GL_MIN_ACCUM_BLUE: break;
data[p++]=AGL_ACCUM_BLUE_SIZE; data[p++]=attribList[arg++]; break;
case WX_GL_MIN_ACCUM_ALPHA: case WX_GL_MIN_RED:
data[p++]=AGL_ACCUM_ALPHA_SIZE; data[p++]=attribList[arg++]; break; data[p++] = AGL_RED_SIZE;
default: data[p++] = attribList[arg++];
break; 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; attribs = data;
} }
@@ -211,186 +279,142 @@ static AGLPixelFormat ChoosePixelFormat(const int *attribList)
return aglChoosePixelFormat(NULL, 0, attribs); return aglChoosePixelFormat(NULL, 0, attribs);
} }
bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id, bool wxGLCanvas::Create(wxWindow *parent,
const wxPoint& pos, const wxSize& size, long style, const wxString& name, wxWindowID id,
int *attribList, const wxPalette& palette) const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name,
const int *attribList,
const wxPalette& WXUNUSED(palette))
{ {
m_macCanvasIsShown = false ; m_needsUpdate = false;
m_glContext = 0 ; m_macCanvasIsShown = false;
wxWindow::Create( parent, id, pos, size, style, name );
AGLPixelFormat fmt = ChoosePixelFormat(attribList); m_aglFormat = ChoosePixelFormat(attribList);
wxCHECK_MSG( fmt, false, wxT("Couldn't create OpenGl pixel format") ); if ( !m_aglFormat )
return false;
m_glContext = new wxGLContext(fmt, this, palette, shared); if ( !wxWindow::Create(parent, id, pos, size, style, name) )
m_macCanvasIsShown = true ; return false;
aglDestroyPixelFormat(fmt);
m_macCanvasIsShown = true;
return true; return true;
} }
void wxGLCanvas::SwapBuffers() wxGLCanvas::~wxGLCanvas()
{ {
if (m_glContext) if ( m_aglFormat )
m_glContext->SwapBuffers(); aglDestroyPixelFormat(m_aglFormat);
} }
void wxGLCanvas::UpdateContext() void wxGLCanvas::SwapBuffers()
{ {
if (m_glContext) AGLContext context = aglGetCurrentContext();
m_glContext->Update(); wxCHECK_RET( context, _T("should have current context") );
aglSwapBuffers(context);
} }
void wxGLCanvas::SetViewport() void wxGLCanvas::SetViewport()
{ {
// viewport is initially set to entire port if ( !m_needsUpdate )
// adjust glViewport to just this window return;
int x = 0 ;
int y = 0 ;
wxWindow* iter = this ; m_needsUpdate = false;
while( iter->GetParent() )
{ AGLContext context = aglGetCurrentContext();
iter = iter->GetParent() ; 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 #if 0
// TODO in case we adopt point vs pixel coordinates, this will make the conversion // 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 );
HIRect hiRect = CGRectMake( x, y, width, height ) ; HIRectConvert( &hiRect, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL);
HIRectConvert( &hiRect, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL) ; HIRect hiBounds = CGRectMake( 0, 0, bounds.right - bounds.left , bounds.bottom - bounds.top );
HIRect hiBounds = CGRectMake( 0, 0, bounds.right - bounds.left , bounds.bottom - bounds.top ) ; HIRectConvert( &hiBounds, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL);
HIRectConvert( &hiBounds, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL) ; GLint parms[4];
GLint parms[4] ; parms[0] = hiRect.origin.x;
parms[0] = hiRect.origin.x ; parms[1] = hiBounds.size.height - (hiRect.origin.y + hiRect.size.height);
parms[1] = hiBounds.size.height - (hiRect.origin.y + hiRect.size.height) ; parms[2] = hiRect.size.width;
parms[2] = hiRect.size.width ; parms[3] = hiRect.size.height;
parms[3] = hiRect.size.height ;
#else #else
GetWindowPortBounds( MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds ) ; GLint parms[4];
GLint parms[4] ; parms[0] = x;
parms[0] = x ; parms[1] = bounds.bottom - bounds.top - ( y + height );
parms[1] = bounds.bottom - bounds.top - ( y + height ) ; parms[2] = width;
parms[2] = width ; parms[3] = height;
parms[3] = height ;
#endif #endif
if ( !m_macCanvasIsShown )
parms[0] += 20000 ; // move the buffer rect out of sight if we're hidden
aglSetInteger( m_glContext->m_glContext , AGL_BUFFER_RECT , parms ) ; if ( !m_macCanvasIsShown )
} parms[0] += 20000;
if ( !aglSetInteger(context, AGL_BUFFER_RECT, parms) )
{
wxLogAGLError("aglSetInteger(AGL_BUFFER_RECT)");
}
} }
void wxGLCanvas::OnSize(wxSizeEvent& event) void wxGLCanvas::OnSize(wxSizeEvent& event)
{ {
MacUpdateView() ; MacUpdateView();
event.Skip();
} }
void wxGLCanvas::MacUpdateView() void wxGLCanvas::MacUpdateView()
{ {
if (m_glContext) m_needsUpdate = true;
{ Refresh(false);
UpdateContext();
m_glContext->SetCurrent();
SetViewport();
}
} }
void wxGLCanvas::MacSuperChangedPosition() void wxGLCanvas::MacSuperChangedPosition()
{ {
MacUpdateView() ; MacUpdateView();
wxWindow::MacSuperChangedPosition() ; wxWindow::MacSuperChangedPosition();
} }
void wxGLCanvas::MacTopLevelWindowChangedPosition() void wxGLCanvas::MacTopLevelWindowChangedPosition()
{ {
MacUpdateView() ; MacUpdateView();
wxWindow::MacTopLevelWindowChangedPosition() ; wxWindow::MacTopLevelWindowChangedPosition();
}
void wxGLCanvas::SetCurrent()
{
if (m_glContext)
{
m_glContext->SetCurrent();
}
}
void wxGLCanvas::SetColour(const wxChar *colour)
{
if (m_glContext)
m_glContext->SetColour(colour);
}
bool wxGLCanvas::Show(bool show)
{
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 ;
} }
void wxGLCanvas::MacVisibilityChanged() void wxGLCanvas::MacVisibilityChanged()
{ {
if ( !MacIsReallyShown() ) if ( MacIsReallyShown() != m_macCanvasIsShown )
{ {
if ( m_macCanvasIsShown ) m_macCanvasIsShown = !m_macCanvasIsShown;
{ MacUpdateView();
m_macCanvasIsShown = false ;
SetViewport() ;
}
} }
else
{ wxWindowMac::MacVisibilityChanged();
if ( !m_macCanvasIsShown )
{
m_macCanvasIsShown = true ;
SetViewport() ;
}
}
wxWindowMac::MacVisibilityChanged() ;
} }
//--------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGLApp // wxGLApp
//--------------------------------------------------------------------------- // ----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGLApp, wxApp) bool wxGLApp::InitGLVisual(const int *attribList)
bool wxGLApp::InitGLVisual(int *attribList)
{ {
AGLPixelFormat fmt = ChoosePixelFormat(attribList); AGLPixelFormat fmt = ChoosePixelFormat(attribList);
if (fmt != NULL) { if ( !fmt )
aglDestroyPixelFormat(fmt);
return true;
} else
return false; return false;
}
wxGLApp::~wxGLApp(void) aglDestroyPixelFormat(fmt);
{ return true;
} }
#endif // wxUSE_GLCANVAS #endif // wxUSE_GLCANVAS

View File

@@ -9,6 +9,14 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/wxprec.h" #include "wx/wxprec.h"
#if defined(__BORLANDC__) #if defined(__BORLANDC__)
@@ -18,8 +26,6 @@
#if wxUSE_GLCANVAS #if wxUSE_GLCANVAS
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/frame.h"
#include "wx/settings.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/app.h" #include "wx/app.h"
@@ -28,18 +34,22 @@
#include "wx/msw/private.h" #include "wx/msw/private.h"
// DLL options compatibility check:
#include "wx/build.h"
WX_CHECK_BUILD_OPTIONS("wxGL")
#include "wx/glcanvas.h" #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 #define WXUNUSED_WITHOUT_GL_EXT_vertex_array(name) name
#else #else
#define WXUNUSED_WITHOUT_GL_EXT_vertex_array(name) WXUNUSED(name) #define WXUNUSED_WITHOUT_GL_EXT_vertex_array(name) WXUNUSED(name)
#endif #endif
// ----------------------------------------------------------------------------
// libraries
// ----------------------------------------------------------------------------
/* /*
The following two compiler directives are specific to the Microsoft Visual The following two compiler directives are specific to the Microsoft Visual
C++ family of compilers C++ family of compilers
@@ -62,12 +72,16 @@ WX_CHECK_BUILD_OPTIONS("wxGL")
# pragma comment( lib, "glu32" ) # pragma comment( lib, "glu32" )
#endif #endif
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
static const wxChar *wxGLCanvasClassName = wxT("wxGLCanvasClass"); static const wxChar *wxGLCanvasClassName = wxT("wxGLCanvasClass");
static const wxChar *wxGLCanvasClassNameNoRedraw = wxT("wxGLCanvasClassNR"); 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 // wxGLModule is responsible for unregistering wxGLCanvasClass Windows class
@@ -100,29 +114,12 @@ bool wxGLModule::ms_registeredGLClasses = false;
/* static */ /* static */
bool wxGLModule::RegisterClasses() bool wxGLModule::RegisterClasses()
{ {
if (ms_registeredGLClasses) if ( ms_registeredGLClasses )
return true; return true;
// We have to register a special window class because we need the CS_OWNDC // We have to register a special window class because we need the CS_OWNDC
// style for GLCanvas. // style for GLCanvas: some OpenGL drivers are buggy and don't work with
// windows without this style
/*
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."
*/
WNDCLASS wndclass; WNDCLASS wndclass;
// the fields which are common to all classes // the fields which are common to all classes
@@ -179,140 +176,82 @@ void wxGLModule::UnregisterClasses()
} }
} }
/* // ----------------------------------------------------------------------------
* GLContext implementation // wxGLContext
*/ // ----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGLContext, wxObject) 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()); m_glContext = wglCreateContext(win->GetHDC());
wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") ); wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") );
if( other != 0 ) if ( other )
wglShareLists( other->m_glContext, m_glContext ); {
if ( !wglShareLists(other->m_glContext, m_glContext) )
wxLogLastError(_T("wglShareLists"));
}
} }
wxGLContext::~wxGLContext() 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); wglDeleteContext(m_glContext);
} }
void wxGLContext::SetCurrent(const wxGLCanvas& win) const void wxGLContext::SetCurrent(const wxGLCanvas& win) const
{ {
wglMakeCurrent((HDC) win.GetHDC(), m_glContext); if ( !wglMakeCurrent(win.GetHDC(), m_glContext) )
{
wxLogLastError(_T("wglMakeCurrent"));
}
} }
// ============================================================================
/* // wxGLCanvas
* wxGLCanvas implementation // ============================================================================
*/
IMPLEMENT_CLASS(wxGLCanvas, wxWindow) IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow) BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
EVT_SIZE(wxGLCanvas::OnSize)
EVT_PALETTE_CHANGED(wxGLCanvas::OnPaletteChanged) EVT_PALETTE_CHANGED(wxGLCanvas::OnPaletteChanged)
EVT_QUERY_NEW_PALETTE(wxGLCanvas::OnQueryNewPalette) EVT_QUERY_NEW_PALETTE(wxGLCanvas::OnQueryNewPalette)
END_EVENT_TABLE() END_EVENT_TABLE()
wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id, int *attribList, // ----------------------------------------------------------------------------
const wxPoint& pos, const wxSize& size, long style, // wxGLCanvas construction
const wxString& name, const wxPalette& palette) : wxWindow() // ----------------------------------------------------------------------------
void wxGLCanvas::Init()
{ {
#if WXWIN_COMPATIBILITY_2_8
m_glContext = NULL; m_glContext = NULL;
#endif
if (Create(parent, id, pos, size, style, name)) m_hDC = NULL;
{
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, wxGLCanvas::wxGLCanvas(wxWindow *parent,
const wxPoint& pos, const wxSize& size, long style, const wxString& name, wxWindowID id,
int *attribList, const wxPalette& palette) : wxWindow() const int *attribList,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name,
const wxPalette& palette)
{ {
m_glContext = (wxGLContext*) NULL; Init();
bool ret = Create(parent, id, pos, size, style, name); (void)Create(parent, id, pos, size, style, name, attribList, palette);
if ( ret )
{
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
}
m_hDC = (WXHDC) ::GetDC((HWND) GetHWND());
SetupPixelFormat(attribList);
SetupPalette(palette);
m_glContext = new wxGLContext(this);
}
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()
{
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);
}
// 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()
{
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);
wxGLContext *sharedContext=0;
if (shared) sharedContext=shared->GetContext();
m_glContext = new wxGLContext(this, sharedContext);
} }
wxGLCanvas::~wxGLCanvas() 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 // Replaces wxWindow::Create functionality, since we need to use a different
@@ -322,7 +261,9 @@ bool wxGLCanvas::Create(wxWindow *parent,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, 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") ); wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") );
@@ -338,170 +279,246 @@ bool wxGLCanvas::Create(wxWindow *parent,
parent->AddChild(this); parent->AddChild(this);
DWORD msflags = 0;
/* /*
A general rule with OpenGL and Win32 is that any window that will have a 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. 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 You can find references about this within the knowledge base and most OpenGL
books that contain the wgl function descriptions. books that contain the wgl function descriptions.
*/ */
WXDWORD exStyle = 0; WXDWORD exStyle = 0;
msflags |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; DWORD msflags = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
msflags |= MSWGetStyle(style, & exStyle) ; msflags |= MSWGetStyle(style, &exStyle);
return MSWCreate(wxGLCanvasClassName, NULL, pos, size, msflags, exStyle); if ( !MSWCreate(wxGLCanvasClassName, NULL, pos, size, msflags, exStyle) )
return false;
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;
} }
static void AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, int *attribList) // ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void wxGLCanvas::SwapBuffers()
{ {
if (attribList) { if ( !::SwapBuffers(m_hDC) )
wxLogLastError(_T("SwapBuffers"));
}
// ----------------------------------------------------------------------------
// pixel format stuff
// ----------------------------------------------------------------------------
static void
AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, const int *attribList)
{
if ( !attribList )
return;
pfd.dwFlags &= ~PFD_DOUBLEBUFFER; pfd.dwFlags &= ~PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_COLORINDEX; pfd.iPixelType = PFD_TYPE_COLORINDEX;
pfd.cColorBits = 0; pfd.cColorBits = 0;
int arg=0; int arg=0;
while( (attribList[arg]!=0) ) while ( attribList[arg] )
{ {
switch( attribList[arg++] ) switch ( attribList[arg++] )
{ {
case WX_GL_RGBA: case WX_GL_RGBA:
pfd.iPixelType = PFD_TYPE_RGBA; pfd.iPixelType = PFD_TYPE_RGBA;
break; break;
case WX_GL_BUFFER_SIZE: case WX_GL_BUFFER_SIZE:
pfd.cColorBits = (BYTE)attribList[arg++]; pfd.cColorBits = attribList[arg++];
break; break;
case WX_GL_LEVEL: case WX_GL_LEVEL:
// this member looks like it may be obsolete // this member looks like it may be obsolete
if (attribList[arg] > 0) { if ( attribList[arg] > 0 )
pfd.iLayerType = (BYTE)PFD_OVERLAY_PLANE; pfd.iLayerType = PFD_OVERLAY_PLANE;
} else if (attribList[arg] < 0) { else if ( attribList[arg] < 0 )
pfd.iLayerType = (BYTE)PFD_UNDERLAY_PLANE; pfd.iLayerType = (BYTE)PFD_UNDERLAY_PLANE;
} else { else
pfd.iLayerType = (BYTE)PFD_MAIN_PLANE; pfd.iLayerType = PFD_MAIN_PLANE;
} arg++;
arg++; break;
break; case WX_GL_DOUBLEBUFFER:
case WX_GL_DOUBLEBUFFER: pfd.dwFlags |= PFD_DOUBLEBUFFER;
pfd.dwFlags |= PFD_DOUBLEBUFFER; break;
break; case WX_GL_STEREO:
case WX_GL_STEREO: pfd.dwFlags |= PFD_STEREO;
pfd.dwFlags |= PFD_STEREO; break;
break; case WX_GL_AUX_BUFFERS:
case WX_GL_AUX_BUFFERS: pfd.cAuxBuffers = attribList[arg++];
pfd.cAuxBuffers = (BYTE)attribList[arg++]; break;
break; case WX_GL_MIN_RED:
case WX_GL_MIN_RED: pfd.cColorBits = (pfd.cColorBits +
pfd.cColorBits = (BYTE)(pfd.cColorBits + (pfd.cRedBits = (BYTE)attribList[arg++])); (pfd.cRedBits = attribList[arg++]));
break; break;
case WX_GL_MIN_GREEN: case WX_GL_MIN_GREEN:
pfd.cColorBits = (BYTE)(pfd.cColorBits + (pfd.cGreenBits = (BYTE)attribList[arg++])); pfd.cColorBits = (pfd.cColorBits +
break; (pfd.cGreenBits = attribList[arg++]));
case WX_GL_MIN_BLUE: break;
pfd.cColorBits = (BYTE)(pfd.cColorBits + (pfd.cBlueBits = (BYTE)attribList[arg++])); case WX_GL_MIN_BLUE:
break; pfd.cColorBits = (pfd.cColorBits +
case WX_GL_MIN_ALPHA: (pfd.cBlueBits = attribList[arg++]));
// doesn't count in cColorBits break;
pfd.cAlphaBits = (BYTE)attribList[arg++]; case WX_GL_MIN_ALPHA:
break; // doesn't count in cColorBits
case WX_GL_DEPTH_SIZE: pfd.cAlphaBits = attribList[arg++];
pfd.cDepthBits = (BYTE)attribList[arg++]; break;
break; case WX_GL_DEPTH_SIZE:
case WX_GL_STENCIL_SIZE: pfd.cDepthBits = attribList[arg++];
pfd.cStencilBits = (BYTE)attribList[arg++]; break;
break; case WX_GL_STENCIL_SIZE:
case WX_GL_MIN_ACCUM_RED: pfd.cStencilBits = attribList[arg++];
pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumRedBits = (BYTE)attribList[arg++])); break;
break; case WX_GL_MIN_ACCUM_RED:
case WX_GL_MIN_ACCUM_GREEN: pfd.cAccumBits = (pfd.cAccumBits +
pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumGreenBits = (BYTE)attribList[arg++])); (pfd.cAccumRedBits = attribList[arg++]));
break; break;
case WX_GL_MIN_ACCUM_BLUE: case WX_GL_MIN_ACCUM_GREEN:
pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumBlueBits = (BYTE)attribList[arg++])); pfd.cAccumBits = (pfd.cAccumBits +
break; (pfd.cAccumGreenBits = attribList[arg++]));
case WX_GL_MIN_ACCUM_ALPHA: break;
pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumAlphaBits = (BYTE)attribList[arg++])); case WX_GL_MIN_ACCUM_BLUE:
break; pfd.cAccumBits = (pfd.cAccumBits +
default: (pfd.cAccumBlueBits = attribList[arg++]));
break; 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 = { // default neutral pixel format
sizeof(PIXELFORMATDESCRIPTOR), /* size */ PIXELFORMATDESCRIPTOR pfd =
1, /* version */ {
sizeof(PIXELFORMATDESCRIPTOR), // size
1, // version
PFD_SUPPORT_OPENGL | PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER, /* support double-buffering */ PFD_DOUBLEBUFFER, // support double-buffering
PFD_TYPE_RGBA, /* color type */ PFD_TYPE_RGBA, // color type
16, /* preferred color depth */ 16, // preferred color depth
0, 0, 0, 0, 0, 0, /* color bits (ignored) */ 0, 0, 0, 0, 0, 0, // color bits (ignored)
0, /* no alpha buffer */ 0, // no alpha buffer
0, /* alpha bits (ignored) */ 0, // alpha bits (ignored)
0, /* no accumulation buffer */ 0, // no accumulation buffer
0, 0, 0, 0, /* accum bits (ignored) */ 0, 0, 0, 0, // accumulator bits (ignored)
16, /* depth buffer */ 16, // depth buffer
0, /* no stencil buffer */ 0, // no stencil buffer
0, /* no auxiliary buffers */ 0, // no auxiliary buffers
PFD_MAIN_PLANE, /* main layer */ PFD_MAIN_PLANE, // main layer
0, /* reserved */ 0, // reserved
0, 0, 0, /* no layer, visible, damage masks */ 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); AdjustPFDForAttributes(*ppfd, attribList);
if (pixelFormat == 0) {
wxLogLastError(_T("ChoosePixelFormat")); return ::ChoosePixelFormat(hdc, ppfd);
}
else {
if ( !::SetPixelFormat((HDC) m_hDC, pixelFormat, &pfd) ) {
wxLogLastError(_T("SetPixelFormat"));
}
}
} }
void wxGLCanvas::SetupPalette(const wxPalette& palette) bool wxGLCanvas::DoSetup(const int *attribList)
{ {
int pixelFormat = GetPixelFormat((HDC) m_hDC);
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;
const int pixelFormat = ChooseMatchingPixelFormat(m_hDC, attribList, &pfd);
DescribePixelFormat((HDC) m_hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); if ( !pixelFormat )
if (pfd.dwFlags & PFD_NEED_PALETTE)
{ {
wxLogLastError(_T("ChoosePixelFormat"));
return false;
} }
else
if ( !::SetPixelFormat(m_hDC, pixelFormat, &pfd) )
{ {
return; wxLogLastError(_T("SetPixelFormat"));
return false;
} }
return true;
}
// ----------------------------------------------------------------------------
// palette stuff
// ----------------------------------------------------------------------------
#if wxUSE_PALETTE
bool wxGLCanvas::SetupPalette(const wxPalette& palette)
{
const int pixelFormat = ::GetPixelFormat(m_hDC);
if ( !pixelFormat )
{
wxLogLastError(_T("GetPixelFormat"));
return false;
}
PIXELFORMATDESCRIPTOR pfd;
if ( !::DescribePixelFormat(m_hDC, pixelFormat, sizeof(pfd), &pfd) )
{
wxLogLastError(_T("DescribePixelFormat"));
return false;
}
if ( !(pfd.dwFlags & PFD_NEED_PALETTE) )
return true;
m_palette = palette; m_palette = palette;
if ( !m_palette.Ok() ) if ( !m_palette.Ok() )
{ {
m_palette = CreateDefaultPalette(); m_palette = CreateDefaultPalette();
if ( !m_palette.Ok() )
return false;
} }
if (m_palette.Ok()) if ( !::SelectPalette(m_hDC, GetHpaletteOf(m_palette), FALSE) )
{ {
::SelectPalette((HDC) m_hDC, (HPALETTE) m_palette.GetHPALETTE(), FALSE); wxLogLastError(_T("SelectPalette"));
::RealizePalette((HDC) m_hDC); return false;
} }
if ( ::RealizePalette(m_hDC) == GDI_ERROR )
{
wxLogLastError(_T("RealizePalette"));
return false;
}
return true;
} }
wxPalette wxGLCanvas::CreateDefaultPalette() wxPalette wxGLCanvas::CreateDefaultPalette()
{ {
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;
int paletteSize; 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; paletteSize = 1 << pfd.cColorBits;
@@ -537,61 +554,13 @@ wxPalette wxGLCanvas::CreateDefaultPalette()
return palette; 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) void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent& event)
{ {
/* realize palette if this is the current window */ /* realize palette if this is the current window */
if ( GetPalette()->Ok() ) { if ( GetPalette()->Ok() ) {
::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE()); ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE());
::SelectPalette((HDC) GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE); ::SelectPalette(GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
::RealizePalette((HDC) GetHDC()); ::RealizePalette(GetHDC());
Refresh(); Refresh();
event.SetPaletteRealized(true); event.SetPaletteRealized(true);
} }
@@ -599,7 +568,6 @@ void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent& event)
event.SetPaletteRealized(false); event.SetPaletteRealized(false);
} }
// I think this doesn't have to be propagated to child windows.
void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event) void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event)
{ {
/* realize palette if this is *not* the current window */ /* realize palette if this is *not* the current window */
@@ -607,59 +575,84 @@ void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event)
GetPalette()->Ok() && (this != event.GetChangedWindow()) ) GetPalette()->Ok() && (this != event.GetChangedWindow()) )
{ {
::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE()); ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE());
::SelectPalette((HDC) GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE); ::SelectPalette(GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
::RealizePalette((HDC) GetHDC()); ::RealizePalette(GetHDC());
Refresh(); Refresh();
} }
} }
#endif // wxUSE_PALETTE
//--------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// deprecated wxGLCanvas methods using implicit wxGLContext
// ----------------------------------------------------------------------------
// 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)
{
Init();
if ( Create(parent, id, pos, size, style, name, attribList, palette) )
m_glContext = new wxGLContext(this);
}
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 ( 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();
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
// ----------------------------------------------------------------------------
// wxGLApp // wxGLApp
//--------------------------------------------------------------------------- // ----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGLApp, wxApp) bool wxGLApp::InitGLVisual(const int *attribList)
bool wxGLApp::InitGLVisual(int *attribList)
{ {
int pixelFormat; if ( !wxGLCanvas::ChooseMatchingPixelFormat(ScreenHDC(), attribList) )
PIXELFORMATDESCRIPTOR pfd = { {
sizeof(PIXELFORMATDESCRIPTOR), /* size */ wxLogError(_("Failed to initialize OpenGL"));
1, /* version */ return false;
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 */
};
AdjustPFDForAttributes(pfd, attribList); return true;
// use DC for whole (root) screen, since no windows have yet been created
pixelFormat = ChoosePixelFormat(ScreenHDC(), &pfd);
if (pixelFormat == 0) {
wxLogError(_("Failed to initialize OpenGL"));
return false;
}
return true;
} }
wxGLApp::~wxGLApp() #endif // wxUSE_GLCANVAS
{
}
#endif
// wxUSE_GLCANVAS

View File

@@ -135,13 +135,6 @@ void wxGLCanvas::SetupPalette(const wxPalette& palette)
{ {
} }
wxPalette wxGLCanvas::CreateDefaultPalette()
{
wxPalette palette;
return palette;
}
void wxGLCanvas::SwapBuffers() void wxGLCanvas::SwapBuffers()
{ {
} }

View File

@@ -1,14 +1,24 @@
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: src/x11/glcanvas.cpp // Name: src/x11/glcanvas.cpp
// Purpose: wxGLCanvas, for using OpenGL with wxWidgets // Purpose: wxGLCanvas, for using OpenGL with wxWidgets
// Uses the GLX extension. // Uses the GLX extension.
// Author: Julian Smart and Wolfram Gloger // Author: Julian Smart and Wolfram Gloger
// Modified by: // Modified by: Vadim Zeitlin to update to new API
// Created: 1995, 1999 // Created: 1995, 1999
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart, Wolfram Gloger // Copyright: (c) Julian Smart, Wolfram Gloger
// Licence: wxWindows licence // 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". // for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
@@ -36,83 +46,47 @@
#endif #endif
#include "wx/x11/private.h" #include "wx/x11/private.h"
// DLL options compatibility check: // ----------------------------------------------------------------------------
#include "wx/build.h" // local functions
WX_CHECK_BUILD_OPTIONS("wxGL") // ----------------------------------------------------------------------------
static inline WXWindow wxGetClientAreaWindow(wxWindow* win) static inline Window wxGetClientAreaWindow(const wxWindow* win)
{ {
return (Window)win->
#ifdef __WXMOTIF__ #ifdef __WXMOTIF__
return win->GetClientXWindow(); GetClientXWindow();
#else #else
return win->GetClientAreaWindow(); GetClientAreaWindow();
#endif #endif
} }
#ifdef OLD_MESA // ============================================================================
// workaround for bug in Mesa's glx.c // implementation
static int bitcount( unsigned long n ) // ============================================================================
// ----------------------------------------------------------------------------
// wxGLContext
// ----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGLContext, wxObject)
wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other)
{ {
int bits; XVisualInfo *vi = (XVisualInfo *) win->m_vi;
for (bits=0; n>0;) wxASSERT_MSG( vi, wxT("invalid visual in wxGLCanvas") );
{
if(n & 1) bits++;
n = n >> 1;
}
return bits;
}
#endif
/* m_glContext = glXCreateContext( (Display *)wxGetDisplay(),
* GLContext implementation vi,
*/ other ? other->m_glContext : None,
GL_TRUE);
IMPLEMENT_CLASS(wxGLContext,wxObject) wxASSERT_MSG( m_glContext, wxT("Couldn't create OpenGL context") );
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") );
m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi,
None, GL_TRUE);
wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") );
}
wxGLContext::wxGLContext(
bool WXUNUSED(isRGB), wxWindow *win,
const wxPalette& WXUNUSED(palette),
const wxGLContext *other /* for sharing display lists */
)
{
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") );
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") );
} }
wxGLContext::~wxGLContext() wxGLContext::~wxGLContext()
{ {
if (!m_glContext) return; if (!m_glContext)
return;
if (m_glContext == glXGetCurrentContext()) if (m_glContext == glXGetCurrentContext())
{ {
@@ -122,150 +96,57 @@ wxGLContext::~wxGLContext()
glXDestroyContext( (Display*) wxGetDisplay(), m_glContext ); glXDestroyContext( (Display*) wxGetDisplay(), m_glContext );
} }
void wxGLContext::SwapBuffers() void wxGLContext::SetCurrent(const wxGLCanvas& win) const
{ {
if (m_glContext) if (m_glContext)
{ {
Display* display = (Display*) wxGetDisplay(); Display* display = (Display*) wxGetDisplay();
glXSwapBuffers(display, (Window) wxGetClientAreaWindow(m_window)); glXMakeCurrent(display, wxGetClientAreaWindow(&win), m_glContext);
} }
} }
void wxGLContext::SetCurrent() // ----------------------------------------------------------------------------
// wxGLCanvas
// ----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
wxGLCanvas::wxGLCanvas(wxWindow *parent,
wxWindowID id,
const int *attribList,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name,
const wxPalette& palette)
{ {
if (m_glContext) Create(parent, id, pos, size, style, name, attribList, palette);
{
Display* display = (Display*) wxGetDisplay();
glXMakeCurrent(display, (Window) wxGetClientAreaWindow(m_window),
m_glContext );
}
} }
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);
}
}
}
void wxGLContext::SetupPixelFormat()
{
}
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,
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, shared, id, pos, size, style, name, attribList, palette );
}
/*
bool wxGLCanvas::Create(wxWindow *parent, bool wxGLCanvas::Create(wxWindow *parent,
const wxGLContext *shared, const wxGLCanvas *shared_context_of, wxWindowID id,
wxWindowID id = -1, const wxPoint& pos, const wxPoint& pos,
const wxSize& size, long style, const wxSize& size,
const wxString& name, int *attribList, const wxPalette& palette): long style,
wxScrolledWindow(parent, id, pos, size, style, name) const wxString& name,
*/ const int *attribList,
const wxPalette& 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_vi = NULL;
if ( !wxWindow::Create(parent, id, pos, size, style, name) )
return false;
XVisualInfo *vi, vi_templ; XVisualInfo *vi, vi_templ;
XWindowAttributes xwa; XWindowAttributes xwa;
int val, n; 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(); Display* display = (Display*) wxGetDisplay();
// Check for the presence of the GLX extension // Check for the presence of the GLX extension
if(!glXQueryExtension(display, NULL, NULL)) if(!glXQueryExtension(display, NULL, NULL))
{ {
wxLogDebug(wxT("wxGLCanvas: GLX extension is missing\n")); wxLogDebug(wxT("wxGLCanvas: GLX extension is missing"));
return false; return false;
} }
@@ -311,104 +192,56 @@ bool wxGLCanvas::Create( wxWindow *parent,
} }
data[p] = 0; data[p] = 0;
attribList = (int*) data;
// Get an appropriate visual // Get an appropriate visual
vi = glXChooseVisual(display, DefaultScreen(display), attribList); vi = glXChooseVisual(display, DefaultScreen(display), data);
if(!vi) return false; if(!vi) return false;
// Here we should make sure that vi is the same visual as the // Here we should make sure that vi is the same visual as the
// one used by the xwindow drawable in wxCanvas. However, // one used by the xwindow drawable in wxCanvas. However,
// there is currently no mechanism for this in wx_canvs.cc. // there is currently no mechanism for this in wx_canvs.cc.
} else { }
else // default attributes
{
// By default, we use the visual of xwindow // By default, we use the visual of xwindow
// NI: is this really senseful ? opengl in e.g. color index mode ? XGetWindowAttributes(display, wxGetClientAreaWindow(this), &xwa);
XGetWindowAttributes(display, (Window)wxGetClientAreaWindow(this), &xwa);
vi_templ.visualid = XVisualIDFromVisual(xwa.visual); vi_templ.visualid = XVisualIDFromVisual(xwa.visual);
vi = XGetVisualInfo(display, VisualIDMask, &vi_templ, &n); vi = XGetVisualInfo(display, VisualIDMask, &vi_templ, &n);
if(!vi) return false; if(!vi) return false;
glXGetConfig(display, vi, GLX_USE_GL, &val); glXGetConfig(display, vi, GLX_USE_GL, &val);
if(!val) return false; 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 m_vi = vi; // safe for later use
wxCHECK_MSG( m_vi, false, wxT("required visual couldn't be found") ); 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; return true;
} }
wxGLCanvas::~wxGLCanvas(void) wxGLCanvas::~wxGLCanvas()
{ {
XVisualInfo *vi = (XVisualInfo *) m_vi; XVisualInfo *vi = (XVisualInfo *) m_vi;
if (vi) XFree( vi ); if (vi)
if (m_glContext) delete m_glContext; XFree( vi );
// Display* display = (Display*) GetXDisplay();
// if(glx_cx) glXDestroyContext(display, glx_cx);
} }
void wxGLCanvas::SwapBuffers() void wxGLCanvas::SwapBuffers()
{ {
if( m_glContext ) m_glContext->SwapBuffers(); glXSwapBuffers((Display *)wxGetDisplay(), wxGetClientAreaWindow(this));
// Display* display = (Display*) GetXDisplay();
// if(glx_cx) glXSwapBuffers(display, (Window) GetClientAreaWindow());
} }
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);
}
void wxGLCanvas::SetColour(const wxChar *col)
{
if( m_glContext ) m_glContext->SetColour(col);
}
#ifdef __WXMOTIF__
col.AllocColour(GetXDisplay());
#else
col.CalcPixel(wxTheApp->GetMainColormap(wxGetDisplay()));
#endif #endif
// wxUSE_GLCANVAS
return col.GetPixel();
}
#endif // wxUSE_GLCANVAS