renderspu_cocoa_helper.m revision 8842b172df03540da1eba3c422804d54f29c9fb6
/* $Id$ */
/** @file
* VirtualBox OpenGL Cocoa Window System Helper Implementation.
*/
/*
* Copyright (C) 2009-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "renderspu_cocoa_helper.h"
#import <Cocoa/Cocoa.h>
/** @page pg_opengl_cocoa OpenGL - Cocoa Window System Helper
*
* How this works:
* In general it is not so easy like on the other platforms, cause Cocoa
* doesn't support any clipping of already painted stuff. In Mac OS X there is
* the concept of translucent canvas's e.g. windows and there it is just
* painted what should be visible to the user. Unfortunately this isn't the
* concept of chromium. Therefor I reroute all OpenGL operation from the guest
* to a frame buffer object (FBO). This is a OpenGL extension, which is
* supported by all OS X versions we support (AFAIC tell). Of course the guest
* doesn't know that and we have to make sure that the OpenGL state always is
* Several functions below (like cocoaBindFramebufferEXT, cocoaGetIntegerv,
* ...) doing this. When a swap or finish is triggered by the guest, the
* content (which is already bound to an texture) is painted on the screen
* within a separate OpenGL context. This allows the usage of the same
* resources (texture ids, buffers ...) but at the same time having an
* different internal OpenGL state. Another advantage is that we can paint a
* thumbnail of the current output in a much more smaller (GPU accelerated
* scale) version on a third context and use glReadPixels to get the actual
* data. glReadPixels is a very slow operation, but as we just use a much more
* smaller image, we can handle it (anyway this is only done 5 times per
* second).
*
* Other things to know:
* - If the guest request double buffering, we have to make sure there are two
* buffers. We use the same FBO with 2 color attachments. Also glDrawBuffer
* the correct buffers. On swap our buffers are swapped and not the
* this is created.
* - If the size of the guest OpenGL window changes, all FBO's, textures, ...
* need to be recreated.
* - We need to track any changes to the parent window
* OverlayWindow, ... are there for.
* - The HGCM service runs on a other thread than the Main GUI. Keeps this
* always in mind (see e.g. performSelectorOnMainThread in renderFBOToView)
* - We make heavy use of late binding. We can not be sure that the GUI (or any
* other third party GUI), overwrite our NSOpenGLContext. So we always ask if
* this is our own one, before use. Really neat concept of Objective-C/Cocoa
* ;)
*/
/* Debug macros */
#define FBO 1 /* Disable this to see how the output is without the FBO in the middle of the processing chain. */
#if 0
# define SHOW_WINDOW_BACKGROUND 1 /* Define this to see the window background even if the window is clipped */
#else
do {} while (0)
#else
do {} while (0)
# define CHECK_GL_ERROR()\
do \
{ \
}while (0);
{
GLenum g = glGetError();
if (g != GL_NO_ERROR)
{
char *errStr;
switch (g)
{
}
}
}
#else
# define CHECK_GL_ERROR()\
do {} while (0)
do \
{ \
glPushMatrix(); \
glPushMatrix(); \
glMatrixMode(GL_COLOR); \
glPushMatrix(); \
glPushMatrix(); \
} \
while(0);
do \
{ \
glPopMatrix(); \
glMatrixMode(GL_COLOR); \
glPopMatrix(); \
glPopMatrix(); \
glPopMatrix(); \
glPopClientAttrib(); \
glPopAttrib(); \
} \
while(0);
/** Custom OpenGL context class.
*
* This implementation doesn't allow to set a view to the
* context, but save the view for later use. Also it saves a copy of the
* pixel format used to create that context for later use. */
@interface OverlayOpenGLContext: NSOpenGLContext
{
@private
}
@end
@class DockOverlayView;
/** The custom view class.
* This is the main class of the cocoa OpenGL implementation. It
* manages an frame buffer object for the rendering of the guest
* applications. The guest applications render in this frame buffer which
* is bind to an OpenGL texture. To display the guest content, an secondary
* shared OpenGL context of the main OpenGL context is created. The secondary
* context is marked as non opaque & the texture is displayed on an object
* which is composed out of the several visible region rectangles. */
@interface OverlayView: NSView
{
@private
/* FBO handling */
/** The corresponding dock tile view of this OpenGL view & all helper
* members. */
/* For clipping */
/** This is necessary for clipping on the root window */
}
- (NSOpenGLContext*)glCtx;
- (NSView*)parentView;
- (NSWindow*)overlayWin;
- (void)updateViewport;
- (void)reshape;
- (void)createFBO;
- (void)deleteFBO;
- (bool)isCurrentFBO;
- (void)updateFBO;
- (void)makeCurrentFBO;
- (void)swapFBO;
- (void)flushFBO;
- (void)finishFBO;
- (void)tryDraw;
- (void)renderFBOToView;
- (void)renderFBOToDockTile;
- (void)clearVisibleRegions;
- (NSView*)dockTileScreen;
- (void)reshapeDockTile;
@end
/** Helper view.
*
* This view is added as a sub view of the parent view to track
* main window changes. Whenever the main window is changed
* (which happens on fullscreen/seamless entry/exit) the overlay
* window is informed & can add them self as a child window
* again. */
@class OverlayWindow;
@interface OverlayHelperView: NSView
{
@private
}
@end
/** Custom window class.
*
* This is the overlay window which contains our custom NSView.
* Its a direct child of the Qt Main window. It marks its background
* transparent & non opaque to make clipping possible. It also disable mouse
* events and handle frame change events of the parent view. */
@interface OverlayWindow: NSWindow
{
@private
}
@end
@interface DockOverlayView: NSView
{
}
- (void)dealloc;
- (void)cleanup;
- (void)lock;
- (void)unlock;
- (NSImage*)thumbImage;
@end
{
if (self)
{
/* We need a lock cause the thumb image could be accessed from the main
* thread when someone is calling display on the dock tile & from the
* OpenGL thread when the thumbnail is updated. */
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)cleanup
{
if (m_ThumbImage != nil)
{
m_ThumbImage = nil;
}
if (m_ThumbBitmap != nil)
{
m_ThumbBitmap = nil;
}
}
- (void)lock
{
}
- (void)unlock
{
}
{
{
/* Create a buffer for our thumbnail image. Its in the size of this view. */
}
}
{
return YES;
}
{
#endif /* SHOW_WINDOW_BACKGROUND */
if (m_ThumbImage != nil)
[m_ThumbImage drawAtPoint:NSMakePoint(0, 0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
{
return m_ThumbBitmap;
}
- (NSImage*)thumbImage
{
return m_ThumbImage;
}
@end
/********************************************************************************
*
* OverlayOpenGLContext class implementation
*
********************************************************************************/
{
if (self)
return self;
}
- (void)dealloc
{
[super dealloc];
}
{
}
{
#else
}
{
return m_pView;
#else
return [super view];
}
-(void)clearDrawable
{
[super clearDrawable];
}
{
return m_pPixelFormat;
}
@end
/********************************************************************************
*
* OverlayHelperView class implementation
*
********************************************************************************/
{
return self;
}
-(void)viewDidMoveToWindow
{
}
@end
/********************************************************************************
*
* OverlayWindow class implementation
*
********************************************************************************/
{
if((self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]))
{
/* Add the helper view as a child of the parent view to get notifications */
/* Make sure this window is transparent */
/* For debugging */
#else
/* Disable mouse events for this window */
/* Set the overlay view as our content view */
/* Add ourself as a child to the parent views window. Note: this has to
* be done last so that everything else is setup in
* parentWindowChanged. */
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
{
/* Reposition this window with the help of the OverlayView. Perform the
* call in the OpenGL thread. */
/*
[m_pOverlayView performSelector:@selector(reshape) onThread:m_Thread withObject:nil waitUntilDone:YES];
*/
}
{
{
/* Ask to get notifications when our parent window frame changes. */
/* Add us self as child window */
/* Reshape the overlay view after a short waiting time to let the main
* window resize itself properly. */
/*
[m_pOverlayView performSelector:@selector(reshape) withObject:nil afterDelay:0.2];
[NSTimer scheduledTimerWithTimeInterval:0.2 target:m_pOverlayView selector:@selector(reshape) userInfo:nil repeats:NO];
*/
}
}
@end
/********************************************************************************
*
* OverlayView class implementation
*
********************************************************************************/
{
/* Make some reasonable defaults */
m_FBOId = 0;
m_FBOTexBackId = 0;
m_FBOTexFrontId = 0;
m_FBOThumbId = 0;
m_FBOThumbTexId = 0;
m_cClipRects = 0;
m_Pos = NSZeroPoint;
return self;
}
- (void)dealloc
{
if (m_pGLCtx)
{
}
if (m_pSharedGLCtx)
{
}
[super dealloc];
}
{
/* Do nothing */
}
{
}
- (NSOpenGLContext*)glCtx
{
return m_pGLCtx;
}
- (NSView*)parentView
{
return m_pParentView;
}
{
}
{
}
- (NSWindow*)overlayWin
{
return m_pOverlayWin;
}
{
}
{
return m_Pos;
}
{
if (m_FBOId)
{
DEBUG_MSG(("OVIW(%p): setSize: new size: %dx%d\n", (void*)self, (int)size.width, (int)size.height));
/* have to rebind GL_TEXTURE_RECTANGLE_ARB as m_FBOTexId could be changed in updateFBO call */
}
else
{
DEBUG_MSG(("OVIW(%p): setSize (no FBO): new size: %dx%d\n", (void*)self, (int)size.width, (int)size.height));
}
}
{
return m_Size;
}
- (void)updateViewport
{
NSRect r;
if (m_pSharedGLCtx)
{
/* Update the viewport for our OpenGL view */
/* Setup all matrices */
DEBUG_MSG_1(("OVIW(%p): frame[%i, %i, %i, %i]\n", (void*)self, (int)r.origin.x, (int)r.origin.x, (int)r.size.width, (int)r.size.height));
DEBUG_MSG_1(("OVIW(%p): m_Pos(%i,%i) m_Size(%i,%i)\n", (void*)self, (int)m_Pos.x, (int)m_Pos.y, (int)m_Size.width, (int)m_Size.height));
DEBUG_MSG_1(("OVIW(%p): m_RootShift(%i, %i)\n", (void*)self, (int)m_RootShift.x, (int)m_RootShift.y));
/* Clear background to transparent */
}
}
- (void)reshape
{
/* Getting the right screen coordinates of the parents frame is a little bit
* complicated. */
parentPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:NSMakePoint(parentFrame.origin.x, parentFrame.origin.y + parentFrame.size.height)]];
/* Calculate the new screen coordinates of the overlay window. */
childPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:childPos]];
/* Make a frame out of it. */
/* We have to make sure that the overlay window will not be displayed out
* of the parent window. So intersect both frames & use the result as the new
* frame for the window. */
/* Later we have to correct the texture position in the case the window is
* out of the parents window frame. So save the shift values for later use. */
else
m_RootShift.x = 0;
else
m_RootShift.y = 0;
/*
NSScrollView *pScrollView = [[[m_pParentView window] contentView] enclosingScrollView];
if (pScrollView)
{
NSRect scrollRect = [pScrollView documentVisibleRect];
NSRect scrollRect = [m_pParentView visibleRect];
printf ("sc rect: %d %d %d %d\n", (int) scrollRect.origin.x,(int) scrollRect.origin.y,(int) scrollRect.size.width,(int) scrollRect.size.height);
NSRect b = [[m_pParentView superview] bounds];
printf ("bound rect: %d %d %d %d\n", (int) b.origin.x,(int) b.origin.y,(int) b.size.width,(int) b.size.height);
newFrame.origin.x += scrollRect.origin.x;
newFrame.origin.y += scrollRect.origin.y;
}
*/
/* Set the new frame. */
/* Inform the dock tile view as well */
/* Make sure the context is updated according */
}
- (void)createFBO
{
/* If not previously setup generate IDs for FBO and its associated texture. */
if (!m_FBOId)
{
/* Make sure the framebuffer extension is supported */
/* Get the extension name string. It is a space-delimited list of the
* OpenGL extensions that are supported by the current renderer. */
if (!isFBO)
{
DEBUG_MSG(("Your system does not support the GL_EXT_framebuffer_object extension\n"));
}
if (!isFBO)
{
DEBUG_MSG(("Your system does not support the GL_EXT_framebuffer_blit extension\n"));
}
/* Create FBO object */
DEBUG_MSG(("OVIW(%p): gen numbers: FBOId=%d FBOTexBackId=%d FBOTexFrontId=%d\n", (void*)self, m_FBOId, m_FBOTexBackId, m_FBOTexFrontId));
}
/* Bind to FBO */
/*
glEnable(GL_TEXTURE_RECTANGLE_ARB);
*/
/* Sanity check against maximum OpenGL texture size. If bigger adjust to
* maximum possible size while maintain the aspect ratio. */
{
if (imageAspectRatio > 1)
{
}
else
{
}
}
DEBUG_MSG(("OVIW(%p): tex size is: %dx%d\n", (void*)self, (int)m_FBOTexSize.width, (int)m_FBOTexSize.height));
/* Initialize FBO Textures */
/* The GPUs like the GL_BGRA / GL_UNSIGNED_INT_8_8_8_8_REV combination
* others are also valid, but might incur a costly software translation. */
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, m_FBOTexSize.width, m_FBOTexSize.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, m_FBOTexSize.width, m_FBOTexSize.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
/* Now attach the textures to the FBO as its color destinations */
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, m_FBOAttBackId, GL_TEXTURE_RECTANGLE_ARB, m_FBOTexBackId, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, m_FBOAttFrontId, GL_TEXTURE_RECTANGLE_ARB, m_FBOTexFrontId, 0);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_FBOTexSize.width, m_FBOTexSize.height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId);
/* Bind the FBOs for reading and drawing. */
/* Explicitly clear the textures otherwise they would contain old memory stuff. */
/* Make sure the FBO was created successfully. */
// glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
/* Is there a dock tile preview enabled in the GUI? If so setup a
* additional thumbnail view for the dock tile. */
if (pDockScreen)
{
if (!m_FBOThumbId)
{
}
/* Initialize FBO Texture */
/* The GPUs like the GL_BGRA / GL_UNSIGNED_INT_8_8_8_8_REV combination
* others are also valid, but might incur a costly software translation. */
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, m_FBOTexSize.width * m_FBOThumbScaleX, m_FBOTexSize.height * m_FBOThumbScaleY, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
/* Now attach texture to the FBO as its color destination */
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_FBOThumbTexId, 0);
/* Make sure the FBO was created successfully. */
}
/* Initialize with one big visual region over the full size */
m_cClipRects = 1;
}
- (void)deleteFBO
{
if (m_pSharedGLCtx)
{
}
if (m_pGLCtx)
{
if (m_FBODepthStencilPackedId > 0)
{
}
if (m_FBOTexBackId > 0)
{
m_FBOTexBackId = 0;
}
if (m_FBOTexFrontId > 0)
{
m_FBOTexFrontId = 0;
}
if (m_FBOId > 0)
{
if ([self isCurrentFBO])
m_FBOId = 0;
}
}
if (m_DockTileView != nil)
{
}
}
- (void)updateFBO
{
if (m_pGLCtx)
{
}
}
- (void)makeCurrentFBO
{
if (m_pGLCtx)
{
{
/* We change the active view, so flush first */
glFlush();
}
/*
if ([NSOpenGLContext currentContext] != m_pGLCtx)
*/
{
/*
[m_pGLCtx update];
*/
}
}
}
- (bool)isCurrentFBO
{
#else
return false;
}
- (void)tryDraw
{
if ([self lockFocusIfCanDraw])
{
[self unlockFocus];
}
}
- (void)swapFBO
{
/* Don't use flush buffers cause we are using FBOs here! */
/* Before we swap make sure everything is done (This is really
* important. Don't remove.) */
glFlush();
/* Fetch the current used read and draw buffers. */
/* Do the swapping of our internal ids */
m_FBOTexBackId = sw;
m_FBOAttBackId = sw;
DEBUG_MSG_1(("read FBO: %d draw FBO: %d readId: %d drawId: %d\n", readFBOId, drawFBOId, readId, drawId));
/* We also have to swap the real ids on the current context. */
{
}
{
}
#else
}
- (void)flushFBO
{
glFlush();
/* If at any time OpenGl operations where done in the front buffer, we need
* to reflect this in the FBO as well. This is something which on real
* hardware happens and unfortunately some applications rely on it (grrr ... Compiz). */
if ( m_fFrontDrawing
&& [self isCurrentFBO])
{
/* Only reset if we aren't currently front. */
m_fFrontDrawing = false;
}
}
- (void)finishFBO
{
glFinish();
if ([self isCurrentFBO])
}
{
// DEBUG_MSG_1(("StateInfo requested: %d\n", pname));
switch(pname)
{
case GL_READ_FRAMEBUFFER_EXT:
case GL_DRAW_FRAMEBUFFER_EXT:
{
*params = 0;
break;
}
case GL_READ_BUFFER:
{
{
else
}
break;
}
case GL_DRAW_BUFFER:
{
{
else
}
break;
}
}
}
{
/*
if ([self isCurrentFBO])
*/
{
{
}
{
}
else
}
#else
}
{
/*
if ([self isCurrentFBO])
*/
{
{
m_fFrontDrawing = true;
}
{
}
else
{
}
}
#else
}
{
if (framebuffer != 0)
else
#else
}
- (void)renderFBOToView
{
GLint i = 0;
/* Fetch the current used read and draw buffers. */
if (!m_pSharedGLCtx)
{
/* Create a shared context out of the main context. Use the same pixel format. */
m_pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:[(OverlayOpenGLContext*)m_pGLCtx openGLPixelFormat] shareContext:m_pGLCtx];
/* Set the new context as non opaque */
/* Set this view as the drawable for the new context */
}
if (m_pSharedGLCtx)
{
DEBUG_MSG(("OVIW(%p): rF2V frame: [%i, %i, %i, %i]\n", (void*)self, (int)r.origin.x, (int)r.origin.y, (int)r.size.width, (int)r.size.height));
if (m_FBOTexFrontId > 0)
{
{
}
/* Render FBO content to the dock tile when necessary. */
#if 1 /* Set to 0 to see the docktile instead of the real output */
/* Clear background to transparent */
/* Blit the content of the FBO to the screen. */
for (i = 0; i < m_cClipRects; ++i)
{
}
/*
glFinish();
*/
/* Reset to previous buffer bindings. */
}
}
#else
}
- (void)renderFBOToDockTile
{
GLint i = 0;
if ( m_FBOThumbId
{
/* Only update after at least 200 ms, cause glReadPixels is
* heavy performance wise. */
{
#if 0
/* todo: check this for optimization */
glFlush();
/* Do other work processing here, using a double or triple buffer */
/* Clear background to transparent */
for (i = 0; i < m_cClipRects; ++i)
{
}
glFinish();
/* Here the magic of reading the FBO content in our own buffer
* happens. We have to lock this access, in the case the dock
* is updated currently. */
/* Send a display message to the dock tile in the main thread */
[[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:NO];
}
}
}
- (void)clearVisibleRegions
{
if(m_paClipRects)
{
}
m_cClipRects = 0;
}
{
if (cRects > 0)
{
int i =0;
for (i = 0; i < cRects; ++i)
DEBUG_MSG_1(("OVIW(%p): setVisibleRegions: %d - %d %d %d %d\n", (void*)self, i, paRects[i * 4], paRects[i * 4 + 1], paRects[i * 4 + 2], paRects[i * 4 + 3]));
}
else
}
- (NSView*)dockTileScreen
{
/* First try the new variant which checks if this window is within the
screen which is previewed in the dock. */
screenContent = [contentView performSelector:@selector(screenContentWithParentView:) withObject:(id)m_pParentView];
/* If it fails, fall back to the old variant (VBox...) */
return screenContent;
}
- (void)reshapeDockTile
{
{
newFrame = NSMakeRect((int)(m_Pos.x * m_FBOThumbScaleX), (int)(dockFrame.size.height - (m_Pos.y + m_Size.height - m_RootShift.y) * m_FBOThumbScaleY), (int)(m_Size.width * m_FBOThumbScaleX), (int)(m_Size.height * m_FBOThumbScaleY));
/*
NSRect newFrame = NSMakeRect ((int)roundf(m_Pos.x * m_FBOThumbScaleX), (int)roundf(dockFrame.size.height - (m_Pos.y + m_Size.height) * m_FBOThumbScaleY), (int)roundf(m_Size.width * m_FBOThumbScaleX), (int)roundf(m_Size.height * m_FBOThumbScaleY));
NSRect newFrame = NSMakeRect ((m_Pos.x * m_FBOThumbScaleX), (dockFrame.size.height - (m_Pos.y + m_Size.height) * m_FBOThumbScaleY), (m_Size.width * m_FBOThumbScaleX), (m_Size.height * m_FBOThumbScaleY));
printf ("%f %f %f %f - %f %f\n", newFrame.origin.x, newFrame.origin.y, newFrame.size.width, newFrame.size.height, m_Size.height, m_FBOThumbScaleY);
*/
}
}
@end
/********************************************************************************
*
* OpenGL context management
*
********************************************************************************/
void cocoaGLCtxCreate(NativeNSOpenGLContextRef *ppCtx, GLbitfield fVisParams, NativeNSOpenGLContextRef pSharedCtx)
{
{
};
int i = 4;
if (fVisParams & CR_ALPHA_BIT)
{
DEBUG_MSG(("CR_ALPHA_BIT requested\n"));
attribs[i++] = NSOpenGLPFAAlphaSize;
attribs[i++] = 8;
}
if (fVisParams & CR_DEPTH_BIT)
{
DEBUG_MSG(("CR_DEPTH_BIT requested\n"));
attribs[i++] = NSOpenGLPFADepthSize;
attribs[i++] = 24;
}
if (fVisParams & CR_STENCIL_BIT)
{
DEBUG_MSG(("CR_STENCIL_BIT requested\n"));
attribs[i++] = NSOpenGLPFAStencilSize;
attribs[i++] = 8;
}
if (fVisParams & CR_ACCUM_BIT)
{
DEBUG_MSG(("CR_ACCUM_BIT requested\n"));
attribs[i++] = NSOpenGLPFAAccumSize;
if (fVisParams & CR_ALPHA_BIT)
attribs[i++] = 32;
else
attribs[i++] = 24;
}
if (fVisParams & CR_MULTISAMPLE_BIT)
{
DEBUG_MSG(("CR_MULTISAMPLE_BIT requested\n"));
attribs[i++] = NSOpenGLPFASampleBuffers;
attribs[i++] = 1;
attribs[i++] = NSOpenGLPFASamples;
attribs[i++] = 4;
}
if (fVisParams & CR_DOUBLE_BIT)
{
DEBUG_MSG(("CR_DOUBLE_BIT requested\n"));
attribs[i++] = NSOpenGLPFADoubleBuffer;
}
if (fVisParams & CR_STEREO_BIT)
{
/* We don't support that.
DEBUG_MSG(("CR_STEREO_BIT requested\n"));
attribs[i++] = NSOpenGLPFAStereo;
*/
}
/* Mark the end */
attribs[i++] = 0;
/* Choose a pixel format */
if (pFmt)
{
/* Enable multi threaded OpenGL engine */
/*
CGLContextObj cglCtx = [*ppCtx CGLContextObj];
CGLError err = CGLEnable(cglCtx, kCGLCEMPEngine);
if (err != kCGLNoError)
printf ("Couldn't enable MT OpenGL engine!\n");
*/
}
}
{
/*
[pCtx release];
*/
}
/********************************************************************************
*
* View management
*
********************************************************************************/
{
/* Create our worker view */
OverlayView* pView = [[OverlayView alloc] initWithFrame:NSZeroRect thread:RTThreadSelf() parentView:pParentView];
if (pView)
{
/* We need a real window as container for the view */
/* Return the freshly created overlay view */
}
}
{
if (pOView)
{
/* Make sure the window is removed from any previous parent window. */
{
}
/* Set the new parent view */
/* Add the overlay window as a child to the new parent window */
if (pParentView != nil)
{
}
}
}
{
/* Hide the view early */
/*
a = [pWin retainCount];
for (; a > 1; --a)
[pWin performSelector:@selector(release)]
*/
/*
[pWin release];
*/
/* There seems to be a bug in the performSelector method which is called in
* parentWindowChanged above. The object is retained but not released. This
* results in an unbalanced reference count, which is here manually
* decremented. */
/*
a = [pView retainCount];
for (; a > 1; --a)
*/
/*
[pView release];
*/
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
/********************************************************************************
*
* Additional OpenGL wrapper
*
********************************************************************************/
{
if (pCtx)
{
if (pView)
{
}
}
}
{
if (pCtx)
{
if (pView)
{
}
}
}
{
if (pCtx)
{
if (pView)
{
}
}
}
void cocoaFlush(void)
{
DEBUG_MSG_1(("glFlush called\n"));
}
void cocoaFinish(void)
{
DEBUG_MSG_1(("glFinish called\n"));
}
{
}
{
else if (type == GL_STENCIL)
#else
}
{
// DEBUG_MSG_1(("getIntergerv called: %d\n", pname));
}
{
}
{
}