root/OpenSceneGraph/branches/osg-cocoa-dev/src/osgViewer/PixelBufferCocoa.mm @ 9836

Revision 9836, 4.1 kB (checked in by shuber, 5 years ago)

* fixed several issues with GraphicsWindowCocoa?, correct window-placement + resizing,
* first cut of PixelBufferCocoa?

  • Property svn:executable set to *
Line 
1/*
2 *  PixelBufferCocoa.cpp
3 *  OpenSceneGraph
4 *
5 *  Created by Stephan Huber on 27.06.08.
6 *  Copyright 2008 Stephan Maximilian Huber, digital mind. All rights reserved.
7 *
8 */
9
10#include <iostream>
11#include <osgViewer/api/Cocoa/PixelBufferCocoa>
12#include <osgViewer/api/Cocoa/GraphicsWindowCocoa>
13#include <Cocoa/Cocoa.h>
14
15namespace osgViewer {
16
17
18void PixelBufferCocoa::init()
19{
20        //std::cout << "PixelBufferCocoa :: init not implemented yet " << std::endl;
21       
22        _valid = _initialized = true;   
23       
24
25}
26
27bool PixelBufferCocoa::realizeImplementation()
28{
29        std::cout << "PixelBufferCocoa :: realizeImplementation not implemented yet " << std::endl;
30       
31    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
32         
33        NSOpenGLPixelFormatAttribute attr[32];
34    int i = 0;
35   
36    attr[i++] = NSOpenGLPFADepthSize;
37    attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->depth);
38
39    if (_traits->doubleBuffer) {
40        attr[i++] = NSOpenGLPFADoubleBuffer;
41    }
42   
43    if (_traits->alpha) {
44        attr[i++] = NSOpenGLPFAAlphaSize;
45        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->alpha);
46    }
47
48    if (_traits->stencil) {
49        attr[i++] = NSOpenGLPFAStencilSize;
50        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->stencil);
51    }
52 
53
54    if (_traits->sampleBuffers) {
55        attr[i++] = NSOpenGLPFASampleBuffers;
56        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->sampleBuffers);
57        attr[i++] = NSOpenGLPFASamples;
58        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->samples);
59    }
60
61    attr[i++] = NSOpenGLPFAPixelBuffer; // for pbuffer usage
62    attr[i++] = NSOpenGLPFAAccelerated;
63    attr[i] = static_cast<NSOpenGLPixelFormatAttribute>(0);
64   
65    // create the context
66    NSOpenGLContext* sharedContext = NULL;
67   
68    GraphicsWindowCocoa* graphicsWindowCocoa = dynamic_cast<GraphicsWindowCocoa*>(_traits->sharedContext);
69    if (graphicsWindowCocoa)
70    {
71        sharedContext = graphicsWindowCocoa->getContext();
72    }
73    else
74    {
75        PixelBufferCocoa* pixelbuffer = dynamic_cast<PixelBufferCocoa*>(_traits->sharedContext);
76        if (pixelbuffer) {
77            sharedContext = pixelbuffer->getContext();
78        }
79    }
80       
81        NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ];
82    _context = [[NSOpenGLContext alloc] initWithFormat: pixelformat shareContext: sharedContext];
83    NSOpenGLPixelBuffer* pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget: _traits->target textureInternalFormat: _traits->format textureMaxMipMapLevel: _traits->level pixelsWide: _traits->width pixelsHigh: _traits->height];
84   
85    [_context setPixelBuffer: pbuffer cubeMapFace: _traits->face mipMapLevel:_traits->level currentVirtualScreen: nil];
86   
87    [pool release];
88   
89    _realized = (_context != nil);
90    return _realized;
91}
92
93
94void PixelBufferCocoa::closeImplementation()
95{
96        _realized = false;
97   
98   
99}
100
101
102
103/** Make this graphics context current.*/
104bool PixelBufferCocoa::makeCurrentImplementation()
105{
106        // osg::notify(osg::INFO) << "PixelBufferCocoa::makeCurrentImplementation" << std::endl;
107   
108    [_context makeCurrentContext];
109        return true;
110}
111
112
113/** Make this graphics context current with specified read context implementation. */
114bool PixelBufferCocoa::makeContextCurrentImplementation(osg::GraphicsContext* readContext)
115{
116        return makeCurrentImplementation();
117}
118
119/** Release the graphics context.*/
120bool PixelBufferCocoa::releaseContextImplementation()
121{
122        // osg::notify(osg::INFO) << "PixelBufferCocoa::releaseContextImplementation" << std::endl;
123   
124    [NSOpenGLContext clearCurrentContext];
125    return true;
126}
127
128/** Bind the graphics context to associated texture implementation.*/
129void PixelBufferCocoa::bindPBufferToTextureImplementation( GLenum buffer )
130{
131        std::cout << "PixelBufferCocoa :: bindPBufferToTextureImplementation not implemented yet " << std::endl;
132}
133
134/** Swap the front and back buffers.*/
135void PixelBufferCocoa::swapBuffersImplementation()
136{
137        osg::notify(osg::INFO) << "PixelBufferCocoa::swapBuffersImplementation" << std::endl;
138    [_context flushBuffer];
139}
140
141 PixelBufferCocoa::~PixelBufferCocoa()
142 {     
143    [_context release];
144 }
145
146
147
148
149}
Note: See TracBrowser for help on using the browser.