root/OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/GraphicsWindowCocoa @ 11289

Revision 11289, 7.0 kB (checked in by robert, 4 years ago)

From Stephan Huber, "attached you'll find a small enhancement for GraphicsWindowCocoa?. My
submision adds a getter for the pixel-format. I need this for some
custom software so I can integrate CoreVideo?-playback with osg.
"

  • Property svn:executable set to *
RevLine 
[9879]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14/* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both
15 * a guide to use of X11/GLX and copiying directly in the case of setBorder().
16 * These elements are license under OSGPL as above, with Copyright (C) 2001-2004  Don Burns.
17 */
18
19#ifndef OSGVIEWER_GRAPHICSWINDOWCOCOA
20#define OSGVIEWER_GRAPHICSWINDOWCOCOA 1
21
22#ifdef __APPLE__
23
24#ifdef __OBJC__
25@class GraphicsWindowCocoaWindow;
[10208]26@class GraphicsWindowCocoaGLView;
[9879]27@class NSOpenGLContext;
[11289]28@class NSOpenGLPixelFormat;
[9879]29@class NSWindow;
[10208]30@class NSView;
[9879]31#else
[10208]32class GraphicsWindowCocoaGLView;
[9879]33class GraphicsWindowCocoaWindow;
34class NSOpenGLContext;
[11289]35class NSOpenGLPixelFormat;
[9879]36class NSWindow;
[10208]37class NSView;
[9879]38#endif
39
40#include <osgViewer/GraphicsWindow>
[10887]41#include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
[9879]42
43// we may not include any cocoa-header here, because this will pollute the name-sapce and tend to compile-errors
44
45namespace osgViewer
46{
47
[10887]48class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleCocoa
[9879]49{
50    public:
[10208]51    class Implementation;
[9879]52
53        GraphicsWindowCocoa(osg::GraphicsContext::Traits* traits):
[10887]54            osgViewer::GraphicsWindow(),
55            osgViewer::GraphicsHandleCocoa(),
[9879]56            _valid(false),
57            _initialized(false),
58            _realized(false),
[10208]59            _closeRequested(false),
60            _checkForEvents(true),
[9879]61            _ownsWindow(true),
[10208]62            _currentCursor(RightArrowCursor),
[10887]63            _window(NULL)
[9879]64        {
65            _traits = traits;
66
67            init();
68           
69            if (valid())
70            {
71                setState( new osg::State );
72                getState()->setGraphicsContext(this);
73
74                if (_traits.valid() && _traits->sharedContext)
75                {
76                    getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
77                    incrementContextIDUsageCount( getState()->getContextID() );   
78                }
79                else
80                {
81                    getState()->setContextID( osg::GraphicsContext::createNewContextID() );
82                }
83            }
84        }
85   
86        virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowCocoa*>(object)!=0; }
87        virtual const char* libraryName() const { return "osgViewer"; }
88        virtual const char* className() const { return "GraphicsWindowCarbon"; }
89
90        virtual bool valid() const { return _valid; }
91
92        /** Realise the GraphicsContext.*/
93        virtual bool realizeImplementation();
94
95        /** Return true if the graphics context has been realised and is ready to use.*/
96        virtual bool isRealizedImplementation() const { return _realized; }
97
98        /** Close the graphics context.*/
99        virtual void closeImplementation();
100
101        /** Make this graphics context current.*/
102        virtual bool makeCurrentImplementation();
103       
104        /** Release the graphics context.*/
105        virtual bool releaseContextImplementation();
106
107        /** Swap the front and back buffers.*/
108        virtual void swapBuffersImplementation();
109       
110        /** Check to see if any events have been generated.*/
111        virtual void checkEvents();
112
113        /** Set Window decoration.*/
114        virtual bool setWindowDecorationImplementation(bool flag);
115
116        /** Get focus.*/
117        virtual void grabFocus();
118       
119        /** Get focus on if the pointer is in this window.*/
120        virtual void grabFocusIfPointerInWindow();
121       
122        bool requestClose() { bool b = _closeRequested; _closeRequested = true; return b; }
123       
124        virtual void resizedImplementation(int x, int y, int width, int height);
125       
126        virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
127       
128        virtual void setWindowName (const std::string & name);
129        virtual void useCursor(bool cursorOn);
130        virtual void setCursor(MouseCursor mouseCursor);
131               
132        /** WindowData is used to pass in the Cocoa window handle attached the GraphicsContext::Traits structure. */
133        class WindowData : public osg::Referenced
134        {
135            public:
[10208]136                enum Options { CreateOnlyView = 1, CheckForEvents = 2, PoseAsStandaloneApp = 4};
137                WindowData(unsigned int options)
138                :    _createOnlyView(options & CreateOnlyView),
139                    _checkForEvents(options & CheckForEvents),
140                    _poseAsStandaloneApp(options & PoseAsStandaloneApp),
141                    _view(NULL)
142                {
143                }
144                           
145                inline NSView* getCreatedNSView() { return _view; }
146                bool createOnlyView() const { return _createOnlyView; }
147                bool checkForEvents() const { return _checkForEvents; }
148                bool poseAsStandaloneApp() const { return _poseAsStandaloneApp; }
149           
150            protected:
151                inline void setCreatedNSView(NSView* view) { _view = view; }
152           
[9879]153            private:
[10208]154                bool         _createOnlyView, _checkForEvents, _poseAsStandaloneApp;
155                NSView*         _view;
[9879]156           
[10208]157            friend class GraphicsWindowCocoa;
158
[9879]159        };
160       
161        NSOpenGLContext* getContext() { return _context; }
162        GraphicsWindowCocoaWindow* getWindow() { return _window; }
[11289]163        NSOpenGLPixelFormat* getPixelFormat() { return _pixelformat; }
[9879]164               
165        void setVSync(bool f);
166       
[10208]167        /** adapts a resize / move of the window, coords in global screen space */
168        void adaptResize(int x, int y, int w, int h);
169       
[9879]170    protected:
171   
172        void init();
173       
174        void transformMouseXY(float& x, float& y);
175        void setupNSWindow(NSWindow* win);
176       
177       
178        virtual ~GraphicsWindowCocoa();
179
180
181        bool            _valid;
182        bool            _initialized;
183        bool            _realized;
184        bool            _useWindowDecoration;
185
[10208]186   
[9879]187         
188    private:       
189       
190       
[10456]191        bool                            _closeRequested, _checkForEvents,_ownsWindow;
192        MouseCursor                     _currentCursor;
193        GraphicsWindowCocoaWindow*      _window;
194        GraphicsWindowCocoaGLView*      _view;
195        NSOpenGLContext*                _context;
[11289]196        NSOpenGLPixelFormat*            _pixelformat;
[10456]197        bool                            _updateContext;
[9879]198};
199
200}
201
202#endif
203#endif
Note: See TracBrowser for help on using the browser.