root/OpenSceneGraph/trunk/include/osgViewer/api/Carbon/PixelBufferCarbon @ 7039

Revision 7039, 3.5 kB (checked in by robert, 7 years ago)

From Stephan Huber, "attached you'll find a first implementation of pbuffer-support for os x.

I used osgprerender --pbuffer to test the carbon-implementation, for now
it works :)
"

RevLine 
[7039]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
15
16#ifndef OSGVIEWER_PIXELBUFFERCARBON
17#define OSGVIEWER_PIXELBUFFERCARBON 1
18
19#ifdef __APPLE__
20
21#include <osg/GraphicsContext>
22#include <osgViewer/Export>
23
24#include <Carbon/Carbon.h>
25#include <AGL/agl.h>
26
27
28namespace osgViewer
29{
30
31class OSGVIEWER_EXPORT PixelBufferCarbon : public osg::GraphicsContext
32{
33    public:
34
35        PixelBufferCarbon(osg::GraphicsContext::Traits* traits):
36            _valid(false),
37                        _initialized(false),
38            _realized(false),
39                        _pixelformat(0),
40            _pbuffer(0),
41            _context(0)
42                {
43            _traits = traits;
44
45            init();
46           
47            if (valid())
48            {
49                setState( new osg::State );
50                getState()->setGraphicsContext(this);
51
52                if (_traits.valid() && _traits->sharedContext)
53                {
54                    getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
55                    incrementContextIDUsageCount( getState()->getContextID() );   
56                }
57                else
58                {
59                    getState()->setContextID( osg::GraphicsContext::createNewContextID() );
60                }
61
62            }
63        }
64   
65        virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const PixelBufferCarbon*>(object)!=0; }
66        virtual const char* libraryName() const { return "osgViewer"; }
67        virtual const char* className() const { return "PixelBufferCarbon"; }
68
69        virtual bool valid() const { return _valid; }
70
71        /** Realise the GraphicsContext.*/
72        virtual bool realizeImplementation();
73
74        /** Return true if the graphics context has been realised and is ready to use.*/
75        virtual bool isRealizedImplementation() const { return _realized; }
76
77        /** Close the graphics context.*/
78        virtual void closeImplementation();
79
80        /** Make this graphics context current.*/
81        virtual bool makeCurrentImplementation();
82
83        /** Make this graphics context current with specified read context implementation. */
84        virtual bool makeContextCurrentImplementation(osg::GraphicsContext* readContext);
85
86        /** Release the graphics context.*/
87        virtual bool releaseContextImplementation();
88
89        /** Bind the graphics context to associated texture implementation.*/
90        virtual void bindPBufferToTextureImplementation( GLenum buffer );
91
92        /** Swap the front and back buffers.*/
93        virtual void swapBuffersImplementation();
94               
95                static AGLPixelFormat createPixelFormat(osg::GraphicsContext::Traits* traits);
96               
97                AGLContext getAGLContext() { return _context; }
98
99    public:
100   
101
102    protected:
103               
104
105   
106        ~PixelBufferCarbon();
107   
108        void init();
109
110        bool            _valid;
111        bool            _initialized;
112        bool            _realized;
113               
114                AGLPixelFormat  _pixelformat;
115                AGLPbuffer              _pbuffer;
116                AGLContext              _context;
117       
118};
119
120}
121
122#endif
123
124#endif
Note: See TracBrowser for help on using the browser.