root/OpenSceneGraph/trunk/src/osgViewer/PixelBufferCocoa.mm @ 13036

Revision 13036, 3.9 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
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    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
30         
31    NSOpenGLPixelFormatAttribute attr[32];
32    int i = 0;
33   
34    attr[i++] = NSOpenGLPFADepthSize;
35    attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->depth);
36
37    if (_traits->doubleBuffer) {
38        attr[i++] = NSOpenGLPFADoubleBuffer;
39    }
40   
41    if (_traits->alpha) {
42        attr[i++] = NSOpenGLPFAAlphaSize;
43        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->alpha);
44    }
45
46    if (_traits->stencil) {
47        attr[i++] = NSOpenGLPFAStencilSize;
48        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->stencil);
49    }
50 
51
52    if (_traits->sampleBuffers) {
53        attr[i++] = NSOpenGLPFASampleBuffers;
54        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->sampleBuffers);
55        attr[i++] = NSOpenGLPFASamples;
56        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->samples);
57    }
58
59    attr[i++] = NSOpenGLPFAPixelBuffer; // for pbuffer usage
60    attr[i++] = NSOpenGLPFAAccelerated;
61    attr[i] = static_cast<NSOpenGLPixelFormatAttribute>(0);
62   
63    // create the context
64    NSOpenGLContext* sharedContext = NULL;
65   
66    GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext);
67    if (graphicsHandleCocoa)
68    {
69        sharedContext = graphicsHandleCocoa->getNSOpenGLContext();
70    }
71   
72   
73    NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ];
74    _context = [[NSOpenGLContext alloc] initWithFormat: pixelformat shareContext: sharedContext];
75    NSOpenGLPixelBuffer* pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget: _traits->target textureInternalFormat: _traits->format textureMaxMipMapLevel: _traits->level pixelsWide: _traits->width pixelsHigh: _traits->height];
76   
77    [_context setPixelBuffer: pbuffer cubeMapFace: _traits->face mipMapLevel:_traits->level currentVirtualScreen: nil];
78   
79    [pool release];
80   
81    _realized = (_context != nil);
82    return _realized;
83}
84
85
86void PixelBufferCocoa::closeImplementation()
87{
88    _realized = false;
89   
90   
91}
92
93
94
95/** Make this graphics context current.*/
96bool PixelBufferCocoa::makeCurrentImplementation()
97{
98    // OSG_INFO << "PixelBufferCocoa::makeCurrentImplementation" << std::endl;
99   
100    [_context makeCurrentContext];
101    return true;
102}
103
104
105/** Make this graphics context current with specified read context implementation. */
106bool PixelBufferCocoa::makeContextCurrentImplementation(osg::GraphicsContext* readContext)
107{
108    return makeCurrentImplementation();
109}
110
111/** Release the graphics context.*/
112bool PixelBufferCocoa::releaseContextImplementation()
113{
114    // OSG_INFO << "PixelBufferCocoa::releaseContextImplementation" << std::endl;
115   
116    [NSOpenGLContext clearCurrentContext];
117    return true;
118}
119
120/** Bind the graphics context to associated texture implementation.*/
121void PixelBufferCocoa::bindPBufferToTextureImplementation( GLenum buffer )
122{
123    std::cout << "PixelBufferCocoa :: bindPBufferToTextureImplementation not implemented yet " << std::endl;
124}
125
126/** Swap the front and back buffers.*/
127void PixelBufferCocoa::swapBuffersImplementation()
128{
129    OSG_INFO << "PixelBufferCocoa::swapBuffersImplementation" << std::endl;
130    [_context flushBuffer];
131}
132
133 PixelBufferCocoa::~PixelBufferCocoa()
134 {   
135    [_context release];
136 }
137
138
139
140
141}
Note: See TracBrowser for help on using the browser.