From bd2af428570c0a05177b8fb715660fa9e78fd720 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 1 Oct 2004 14:23:59 +0000 Subject: [PATCH] wxCocoa: Added (mostly) stubs for wxGLCanvas and friends. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29594 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- Makefile.in | 9 +++ build/bakefiles/files.bkl | 2 + include/wx/cocoa/glcanvas.h | 123 ++++++++++++++++++++++++++++++++++++ include/wx/glcanvas.h | 2 + src/cocoa/glcanvas.mm | 82 ++++++++++++++++++++++++ 5 files changed, 218 insertions(+) create mode 100644 include/wx/cocoa/glcanvas.h create mode 100644 src/cocoa/glcanvas.mm diff --git a/Makefile.in b/Makefile.in index c35b3d54ca..f38310d0c2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1162,6 +1162,7 @@ COND_WXUSE_EXPAT_BUILTIN___wxexpat___depname = \ @COND_TOOLKIT_WINCE@BASE_WINCE_HDR = wx/msw/wince/time.h @COND_TOOLKIT_WINCE@NET_WINCE_SRC = src/msw/wince/net.cpp @COND_TOOLKIT_WINCE@NET_WINCE_HDR = wx/msw/wince/net.h +@COND_TOOLKIT_COCOA@OPENGL_HDR = wx/cocoa/glcanvas.h @COND_TOOLKIT_GTK@OPENGL_HDR = wx/gtk/glcanvas.h @COND_TOOLKIT_MAC@OPENGL_HDR = wx/mac/carbon/glcanvas.h @COND_TOOLKIT_MOTIF@OPENGL_HDR = wx/x11/glcanvas.h @@ -6393,6 +6394,7 @@ COND_USE_SOSYMLINKS_1___gldll___so_symlinks_inst_cmd = rm -f \ $(DLLPREFIX)$(WXDLLNAMEPREFIXGUI)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl$(WXCOMPILER)$(VENDORTAG)$(WXDLLVERSIONTAG)$(dll___targetsuf2) \ $(LIBPREFIX)wx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl-$(WX_RELEASE)$(HOST_SUFFIX).$(DLLIMP_SUFFIX) @COND_USE_SOSYMLINKS_1@__gldll___so_symlinks_inst_cmd = $(COND_USE_SOSYMLINKS_1___gldll___so_symlinks_inst_cmd) +@COND_TOOLKIT_COCOA@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_GTK@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_MAC@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @COND_TOOLKIT_MOTIF@__OPENGL_SRC_OBJECTS = gldll_glcanvas.o @@ -6417,6 +6419,7 @@ COND_SHARED_0_USE_GUI_1_USE_OPENGL_1___gllib___depname = \ @COND_GCC_PCH_1@__gllib_PCH_INC = -I.pch/wxprec_gllib @COND_GCC_PCH_1@___pch_wxprec_gllib_wx_wxprec_h_gch___depname \ @COND_GCC_PCH_1@ = .pch/wxprec_gllib/wx/wxprec.h.gch +@COND_TOOLKIT_COCOA@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @COND_TOOLKIT_GTK@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @COND_TOOLKIT_MAC@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @COND_TOOLKIT_MOTIF@__OPENGL_SRC_OBJECTS_1 = gllib_glcanvas.o @@ -20865,6 +20868,9 @@ xrclib_xmlrsall.o: $(srcdir)/src/xrc/xmlrsall.cpp $(XRCLIB_ODEP) @COND_TOOLKIT_MAC@gldll_glcanvas.o: $(srcdir)/src/mac/carbon/glcanvas.cpp $(GLDLL_ODEP) @COND_TOOLKIT_MAC@ $(CXXC) -c -o $@ $(GLDLL_CXXFLAGS) $< +@COND_TOOLKIT_COCOA@gldll_glcanvas.o: $(srcdir)/src/cocoa/glcanvas.mm $(GLDLL_ODEP) +@COND_TOOLKIT_COCOA@ $(CXXC) -c -o $@ $(GLDLL_CXXFLAGS) $< + @COND_TOOLKIT_GTK@gldll_glcanvas.o: $(srcdir)/src/gtk/glcanvas.cpp $(GLDLL_ODEP) @COND_TOOLKIT_GTK@ $(CXXC) -c -o $@ $(GLDLL_CXXFLAGS) $< @@ -20886,6 +20892,9 @@ xrclib_xmlrsall.o: $(srcdir)/src/xrc/xmlrsall.cpp $(XRCLIB_ODEP) @COND_TOOLKIT_MAC@gllib_glcanvas.o: $(srcdir)/src/mac/carbon/glcanvas.cpp $(GLLIB_ODEP) @COND_TOOLKIT_MAC@ $(CXXC) -c -o $@ $(GLLIB_CXXFLAGS) $< +@COND_TOOLKIT_COCOA@gllib_glcanvas.o: $(srcdir)/src/cocoa/glcanvas.mm $(GLLIB_ODEP) +@COND_TOOLKIT_COCOA@ $(CXXC) -c -o $@ $(GLLIB_CXXFLAGS) $< + @COND_TOOLKIT_GTK@gllib_glcanvas.o: $(srcdir)/src/gtk/glcanvas.cpp $(GLLIB_ODEP) @COND_TOOLKIT_GTK@ $(CXXC) -c -o $@ $(GLLIB_CXXFLAGS) $< diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 57d1290536..32b334e3bd 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2406,6 +2406,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/mac/carbon/glcanvas.cpp + src/cocoa/glcanvas.mm src/gtk/glcanvas.cpp src/msw/glcanvas.cpp src/msw/glcanvas.cpp @@ -2416,6 +2417,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/mac/carbon/glcanvas.h + wx/cocoa/glcanvas.h wx/gtk/glcanvas.h wx/msw/glcanvas.h wx/msw/glcanvas.h diff --git a/include/wx/cocoa/glcanvas.h b/include/wx/cocoa/glcanvas.h new file mode 100644 index 0000000000..49f6a52595 --- /dev/null +++ b/include/wx/cocoa/glcanvas.h @@ -0,0 +1,123 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/cocoa/glcanvas.h +// Purpose: wxGLCanvas class +// Author: David Elliott +// Modified by: +// Created: 2004/09/29 +// RCS-ID: $Id$ +// Copyright: (c) 2004 David Elliott +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_COCOA_GLCANVAS_H__ +#define _WX_COCOA_GLCANVAS_H__ + +// #include "wx/cocoa/NSOpenGLView.h" +// Include gl.h from the OpenGL framework +#include + +class WXDLLIMPEXP_GL wxGLCanvas; +DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLContext); +//DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLView); + +// ======================================================================== +// wxGLContext +// ======================================================================== +class WXDLLIMPEXP_GL wxGLContext: public wxObject +{ +public: + wxGLContext(bool isRGB, wxGLCanvas *win, const wxPalette& palette = wxNullPalette); + + wxGLContext( bool isRGB, wxGLCanvas *win, + const wxPalette& WXUNUSED(palette), + const wxGLContext *other /* for sharing display lists */ ); + + ~wxGLContext(); + + + void SetCurrent(); + + void SetColour(const wxChar *colour); + + void SwapBuffers(); + + + inline wxWindow* GetWindow() const + { return m_window; } + + inline WX_NSOpenGLContext GetNSOpenGLContext() const + { return m_cocoaNSOpenGLContext; } + +public: + WX_NSOpenGLContext m_cocoaNSOpenGLContext; + wxWindow* m_window; +}; + + + +// ======================================================================== +// wxGLCanvas +// ======================================================================== +class WXDLLIMPEXP_GL wxGLCanvas: public wxWindow// , protected wxCocoaNSOpenGLView +{ + DECLARE_DYNAMIC_CLASS(wxGLCanvas) + DECLARE_EVENT_TABLE() +// WX_DECLARE_COCOA_OWNER(NSOpenGLView,NSView,NSView) +// ------------------------------------------------------------------------ +// initialization +// ------------------------------------------------------------------------ +public: + wxGLCanvas() + : m_glContext(NULL) + { } + wxGLCanvas(wxWindow *parent, wxWindowID winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, const wxString& name = wxGLCanvasName, + int *attribList = NULL, const wxPalette& palette = wxNullPalette); + + wxGLCanvas(wxWindow *parent, + const wxGLContext *shared = NULL, + wxWindowID winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, const wxString& name = wxGLCanvasName, + int *attribList = NULL, const wxPalette& palette = wxNullPalette); + + wxGLCanvas(wxWindow *parent, + const wxGLCanvas *shared = NULL, + wxWindowID winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, const wxString& name = wxGLCanvasName, + int *attribList = NULL, const wxPalette& palette = wxNullPalette); + + bool Create(wxWindow *parent, wxWindowID winid, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, const wxString& name = wxGLCanvasName); + virtual ~wxGLCanvas(); + +// ------------------------------------------------------------------------ +// Cocoa callbacks +// ------------------------------------------------------------------------ +protected: + // NSOpenGLView cannot be enabled/disabled + virtual void CocoaSetEnabled(bool enable) { } +// ------------------------------------------------------------------------ +// Implementation +// ------------------------------------------------------------------------ +public: + void SetCurrent(); + void SwapBuffers(); + + void OnSize(wxSizeEvent& event) + {} + inline wxGLContext* GetContext() const + { return m_glContext; } +protected: + wxGLContext *m_glContext; + wxPalette m_palette; +}; + +#endif //ndef _WX_COCOA_GLCANVAS_H__ diff --git a/include/wx/glcanvas.h b/include/wx/glcanvas.h index 2ba47b60db..815633ff7c 100644 --- a/include/wx/glcanvas.h +++ b/include/wx/glcanvas.h @@ -17,6 +17,8 @@ #include "wx/x11/glcanvas.h" #elif defined(__WXMAC__) #include "wx/mac/glcanvas.h" +#elif defined(__WXCOCOA__) +#include "wx/cocoa/glcanvas.h" #elif defined(__WXPM__) #include "wx/os2/glcanvas.h" #endif diff --git a/src/cocoa/glcanvas.mm b/src/cocoa/glcanvas.mm new file mode 100644 index 0000000000..ebb3a16cd6 --- /dev/null +++ b/src/cocoa/glcanvas.mm @@ -0,0 +1,82 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: cocoa/glcanvas.mm +// Purpose: wxGLContext, wxGLCanvas +// Author: David Elliott +// Modified by: +// Created: 2004/09/29 +// RCS-ID: $Id$ +// Copyright: (c) 2004 David Elliott +// Licence: wxWidgets licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#if wxUSE_GLCANVAS + +#ifndef WX_PRECOMP + #include "wx/app.h" +#endif //WX_PRECOMP +#include "wx/glcanvas.h" + +#include "wx/cocoa/autorelease.h" + +#import +#import + +IMPLEMENT_DYNAMIC_CLASS(wxGLCanvas, wxWindow) +BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow) +END_EVENT_TABLE() +// WX_IMPLEMENT_COCOA_OWNER(wxGLCanvas,NSOpenGLView,NSView,NSView) + +wxGLCanvas::wxGLCanvas(wxWindow *parent, + 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; + if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name)) + return false; + SetNSView([[NSOpenGLView alloc] initWithFrame: MakeDefaultNSRect(size) + pixelFormat:[NSOpenGLView defaultPixelFormat]]); + [m_cocoaNSView release]; + if(m_parent) + m_parent->CocoaAddChild(this); + SetInitialFrameRect(pos,size); + + return true; +} + +wxGLCanvas::~wxGLCanvas() +{ +} + +void wxGLCanvas::SetCurrent() +{ + [[(NSOpenGLView*)m_cocoaNSView openGLContext] makeCurrentContext]; +} + +void wxGLCanvas::SwapBuffers() +{ + [[(NSOpenGLView*)m_cocoaNSView openGLContext] flushBuffer]; +} + +#endif // wxUSE_GLCANVAS -- 2.45.2