renderspu_cocoa_helper.m revision c9819fb7aaf7275898c2a4ad2f891245a4a13e67
cda73f64f20b8a0afc4909f5ea1f055ec7913856Toomas Soome * VirtualBox OpenGL Cocoa Window System Helper implementation
4b22b9337f359bfd063322244f5336cc7c6ffcfars * Copyright (C) 2009 Sun Microsystems, Inc.
4b22b9337f359bfd063322244f5336cc7c6ffcfars * This file is part of VirtualBox Open Source Edition (OSE), as
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * available from http://www.virtualbox.org. This file is free software;
4b22b9337f359bfd063322244f5336cc7c6ffcfars * you can redistribute it and/or modify it under the terms of the GNU
4b22b9337f359bfd063322244f5336cc7c6ffcfars * General Public License (GPL) as published by the Free Software
4b22b9337f359bfd063322244f5336cc7c6ffcfars * Foundation, in version 2 as it comes in the "COPYING" file of the
4b22b9337f359bfd063322244f5336cc7c6ffcfars * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
4b22b9337f359bfd063322244f5336cc7c6ffcfars * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
4b22b9337f359bfd063322244f5336cc7c6ffcfars * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
4b22b9337f359bfd063322244f5336cc7c6ffcfars * Clara, CA 95054 USA or visit http://www.sun.com if you need
4b22b9337f359bfd063322244f5336cc7c6ffcfars * additional information or have any questions.
4b22b9337f359bfd063322244f5336cc7c6ffcfars#include "chromium.h" /* For the visual bits of chromium */
4b22b9337f359bfd063322244f5336cc7c6ffcfars/* Debug macros */
4b22b9337f359bfd063322244f5336cc7c6ffcfars#define FBO 1 /* Disable this to see how the output is without the FBO in the middle of the processing chain. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars//#define SHOW_WINDOW_BACKGROUND 1 /* Define this to see the window background even if the window is clipped */
4b22b9337f359bfd063322244f5336cc7c6ffcfars//#define DEBUG_VERBOSE /* Define this could get some debug info about the messages flow. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars do {} while (0)
4b22b9337f359bfd063322244f5336cc7c6ffcfars do {} while (0)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case GL_INVALID_ENUM: errStr = RTStrDup("GL_INVALID_ENUM"); break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case GL_INVALID_VALUE: errStr = RTStrDup("GL_INVALID_VALUE"); break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case GL_INVALID_OPERATION: errStr = RTStrDup("GL_INVALID_OPERATION"); break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case GL_STACK_OVERFLOW: errStr = RTStrDup("GL_STACK_OVERFLOW"); break;
4b22b9337f359bfd063322244f5336cc7c6ffcfars case GL_STACK_UNDERFLOW: errStr = RTStrDup("GL_STACK_UNDERFLOW"); break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case GL_OUT_OF_MEMORY: errStr = RTStrDup("GL_OUT_OF_MEMORY"); break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case GL_TABLE_TOO_LARGE: errStr = RTStrDup("GL_TABLE_TOO_LARGE"); break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG(("%s:%d: glError %d (%s)\n", file, line, g, errStr));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome do {} while (0)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); \
4b22b9337f359bfd063322244f5336cc7c6ffcfars/* Custom OpenGL context class. This implementation doesn't allow to set a view
4b22b9337f359bfd063322244f5336cc7c6ffcfars * to the context, but save the view for later use. Also it saves a copy of the
4b22b9337f359bfd063322244f5336cc7c6ffcfars * pixel format used to create that context for later use. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars/* The custom view class. This is the main class of the cocoa OpenGL
4b22b9337f359bfd063322244f5336cc7c6ffcfars * implementation. It manages an frame buffer object for the rendering of the
4b22b9337f359bfd063322244f5336cc7c6ffcfars * guest applications. The guest applications render in this frame buffer which
4b22b9337f359bfd063322244f5336cc7c6ffcfars * is bind to an OpenGL texture. To display the guest content, an secondary
4b22b9337f359bfd063322244f5336cc7c6ffcfars * shared OpenGL context of the main OpenGL context is created. The secondary
4b22b9337f359bfd063322244f5336cc7c6ffcfars * context is marked as non opaque & the texture is displayed on an object
4b22b9337f359bfd063322244f5336cc7c6ffcfars * which is composed out of the several visible region rectangles. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* FBO handling */
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* The corresponding dock tile view of this OpenGL view & all helper
4b22b9337f359bfd063322244f5336cc7c6ffcfars * members. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* For clipping */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Position/Size tracking */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* This is necessary for clipping on the root window */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome- (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome- (void)setVisibleRegions:(GLint)cRects paRects:(GLint*)paRects;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome/* Helper view. This view is added as a sub view of the parent view to track
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * main window changes. Whenever the main window is changed (which happens on
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * fullscreen/seamless entry/exit) the overlay window is informed & can add
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * them self as a child window again. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome-(id)initWithOverlayWindow:(OverlayWindow*)pOverlayWindow;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome/* Custom window class. This is the overlay window which contains our custom
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * NSView. Its a direct child of the Qt Main window. It marks its background
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * transparent & non opaque to make clipping possible. It also disable mouse
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * events and handle frame change events of the parent view. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome- (id)initWithParentView:(NSView*)pParentView overlayView:(OverlayView*)pOverlayView;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome- (void)parentWindowFrameChanged:(NSNotification *)note;
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* We need a lock cause the thumb image could be accessed from the main
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * thread when someone is calling display on the dock tile & from the
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * OpenGL thread when the thumbnail is updated. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Create a buffer for our thumbnail image. Its in the size of this view. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_ThumbBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_ThumbImage = [[NSImage alloc] initWithSize:[m_ThumbBitmap size]];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [m_ThumbImage addRepresentation:m_ThumbBitmap];
4b22b9337f359bfd063322244f5336cc7c6ffcfars [[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7] set];
4b22b9337f359bfd063322244f5336cc7c6ffcfars [NSBezierPath fillRect:NSMakeRect(0, 0, frame.size.width, frame.size.height)];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [m_ThumbImage drawAtPoint:NSMakePoint(0, 0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome/********************************************************************************
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome* OverlayOpenGLContext class implementation
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome********************************************************************************/
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome-(id)initWithFormat:(NSOpenGLPixelFormat*)format shareContext:(NSOpenGLContext*)share
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome self = [super initWithFormat:format shareContext:share];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG(("Dealloc context %X\n", (uint)self));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [m_pPixelFormat getValues:&val forAttribute:NSOpenGLPFADoubleBuffer forVirtualScreen:0];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome return [super view];
4b22b9337f359bfd063322244f5336cc7c6ffcfars/********************************************************************************
4b22b9337f359bfd063322244f5336cc7c6ffcfars* OverlayHelperView class implementation
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome********************************************************************************/
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome-(id)initWithOverlayWindow:(OverlayWindow*)pOverlayWindow
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome/********************************************************************************
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome* OverlayWindow class implementation
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome********************************************************************************/
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome- (id)initWithParentView:(NSView*)pParentView overlayView:(OverlayView*)pOverlayView
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if(self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_pOverlayHelperView = [[OverlayHelperView alloc] initWithOverlayWindow:self];
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* Add the helper view as a child of the parent view to get notifications */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Make sure this window is transparent */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* For debugging */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [self setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7]];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [self setBackgroundColor:[NSColor clearColor]];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Disable mouse events for this window */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Initial set the position to the parents view top/left (Compiz fix). */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [m_pParentView convertPoint:NSZeroPoint toView:nil]]];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Set the overlay view as our content view */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Add ourself as a child to the parent views window. Note: this has to
4b22b9337f359bfd063322244f5336cc7c6ffcfars * be done last so that everything else is setup in
4b22b9337f359bfd063322244f5336cc7c6ffcfars * parentWindowChanged. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars [[NSNotificationCenter defaultCenter] removeObserver:self];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome- (void)parentWindowFrameChanged:(NSNotification*)pNote
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* Reposition this window with the help of the OverlayView. Perform the
4b22b9337f359bfd063322244f5336cc7c6ffcfars * call in the OpenGL thread. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars// [m_pOverlayView performSelector:@selector(reshape) onThread:m_Thread withObject:nil waitUntilDone:YES];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [[NSNotificationCenter defaultCenter] removeObserver:self];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Ask to get notifications when our parent window frame changes. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Add us self as child window */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [pWindow addChildWindow:self ordered:NSWindowAbove];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Reshape the overlay view after a short waiting time to let the main
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * window resize itself properly. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [m_pOverlayView performSelector:@selector(reshape) withObject:nil afterDelay:0.2];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [NSTimer scheduledTimerWithTimeInterval:0.2 target:m_pOverlayView selector:@selector(reshape) userInfo:nil repeats:NO];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome/********************************************************************************
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome* OverlayView class implementation
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome********************************************************************************/
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome- (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Make some reasonable defaults */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG(("Init view %X (%X)\n", (uint)self, (uint)mThread));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// NSGraphicsContext*pC = [NSGraphicsContext currentContext];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [[NSColor blueColor] set];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// NSBezierPath *p = [[NSBezierPath alloc] bezierPathWithOvalInRect:[self frame]];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [[NSColor greenColor] set];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [p stroke];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// if ([self lockFocusIfCanDraw])
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [self renderFBOToView];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [self unlockFocus];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Update the viewport for our OpenGL view */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Setup all matrices */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glOrtho(0, r.size.width, 0, r.size.height, -1, 1);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Clear background to transparent */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Getting the right screen coordinates of the parents frame is a little bit
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * complicated. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSPoint parentPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:NSMakePoint(parentFrame.origin.x, parentFrame.origin.y + parentFrame.size.height)]];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Calculate the new screen coordinates of the overlay window. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars NSPoint childPos = NSMakePoint(m_Pos.x, m_Pos.y + m_Size.height);
4b22b9337f359bfd063322244f5336cc7c6ffcfars childPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:childPos]];
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* Make a frame out of it. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars NSRect childFrame = NSMakeRect(childPos.x, childPos.y, m_Size.width, m_Size.height);
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* We have to make sure that the overlay window will not be displayed out
4b22b9337f359bfd063322244f5336cc7c6ffcfars * of the parent window. So intersect both frames & use the result as the new
4b22b9337f359bfd063322244f5336cc7c6ffcfars * frame for the window. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars NSRect newFrame = NSIntersectionRect(parentFrame, childFrame);
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* Later we have to correct the texture position in the case the window is
4b22b9337f359bfd063322244f5336cc7c6ffcfars * out of the parents window frame. So save the shift values for later use. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars m_RootShift.x = parentFrame.origin.x - childFrame.origin.x;
4b22b9337f359bfd063322244f5336cc7c6ffcfars m_RootShift.y = parentFrame.origin.y - childFrame.origin.y;
4b22b9337f359bfd063322244f5336cc7c6ffcfars// NSScrollView *pScrollView = [[[m_pParentView window] contentView] enclosingScrollView];
4b22b9337f359bfd063322244f5336cc7c6ffcfars// if (pScrollView)
4b22b9337f359bfd063322244f5336cc7c6ffcfars// NSRect scrollRect = [pScrollView documentVisibleRect];
4b22b9337f359bfd063322244f5336cc7c6ffcfars// NSRect scrollRect = [m_pParentView visibleRect];
4b22b9337f359bfd063322244f5336cc7c6ffcfars// printf ("sc rect: %d %d %d %d\n", (int) scrollRect.origin.x,(int) scrollRect.origin.y,(int) scrollRect.size.width,(int) scrollRect.size.height);
4b22b9337f359bfd063322244f5336cc7c6ffcfars// NSRect b = [[m_pParentView superview] bounds];
4b22b9337f359bfd063322244f5336cc7c6ffcfars// printf ("bound rect: %d %d %d %d\n", (int) b.origin.x,(int) b.origin.y,(int) b.size.width,(int) b.size.height);
4b22b9337f359bfd063322244f5336cc7c6ffcfars// newFrame.origin.x += scrollRect.origin.x;
4b22b9337f359bfd063322244f5336cc7c6ffcfars// newFrame.origin.y += scrollRect.origin.y;
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* Set the new frame. */
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* Inform the dock tile view as well */
4b22b9337f359bfd063322244f5336cc7c6ffcfars /* Make sure the context is updated according */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* If not previously setup generate IDs for FBO and its associated texture. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Make sure the framebuffer extension is supported */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Get the extension name string. It is a space-delimited list of the
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * OpenGL extensions that are supported by the current renderer. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome isFBO = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG(("Your system does not support framebuffer extension\n"));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Create FBO object */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* & the texture as well the depth/stencil render buffer */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG_1(("Create FBO %d %d\n", m_FBOId, m_FBOTexId));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glGenRenderbuffersEXT(1, &m_FBODepthStencilPackedId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Bind to FBO */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome GLfloat imageAspectRatio = m_FBOTexSize.width / m_FBOTexSize.height;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Sanity check against maximum OpenGL texture size. If bigger adjust to
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * maximum possible size while maintain the aspect ratio. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// maxTexSize = 150;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (m_FBOTexSize.width > maxTexSize || m_FBOTexSize.height > maxTexSize)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_FBOTexSize.height = maxTexSize / imageAspectRatio;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_FBOTexSize.width = maxTexSize * imageAspectRatio;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Initialize FBO Texture */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, filter);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, filter);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* The GPUs like the GL_BGRA / GL_UNSIGNED_INT_8_8_8_8_REV combination
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * others are also valid, but might incur a costly software translation. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome 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);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Now attach texture to the FBO as its color destination */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId, 0);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, m_FBOTexSize.width, m_FBOTexSize.height);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Make sure the FBO was created succesfully. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (GL_FRAMEBUFFER_COMPLETE_EXT != glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT))
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG(("Framebuffer Object creation or update failed!\n"));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Is there a dock tile preview enabled in the GUI? If so setup a
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * additional thumbnail view for the dock tile. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOThumbId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Initialize FBO Texture */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOThumbTexId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NICEST);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NICEST);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* The GPUs like the GL_BGRA / GL_UNSIGNED_INT_8_8_8_8_REV combination
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * others are also valid, but might incur a costly software translation. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, m_FBOTexSize.width * m_FBOThumbScaleX, m_FBOTexSize.height * m_FBOThumbScaleY, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Now attach texture to the FBO as its color destination */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_FBOThumbTexId, 0);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Make sure the FBO was created succesfully. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (GL_FRAMEBUFFER_COMPLETE_EXT != glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT))
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG(("Framebuffer Thumb Object creation or update failed!\n"));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_DockTileView = [[DockOverlayView alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Initialize with one big visual region over the full size */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_paClipRects = (GLint*)RTMemAlloc(sizeof(GLint) * 4);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glDeleteRenderbuffersEXT(1, &m_FBODepthStencilPackedId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG_1(("MakeCurrent called %X\n", self));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* We change the active view, so flush first */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// if ([NSOpenGLContext currentContext] != m_pGLCtx)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [m_pGLCtx update];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG_1(("SwapCurrent called %X\n", self));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &tmpFB);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Don't use flush buffers cause we are using FBOs here */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [m_pGLCtx flushBuffer];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &tmpFB);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &tmpFB);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Create a shared context out of the main context. Use the same pixel format. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:[(OverlayOpenGLContext*)m_pGLCtx openGLPixelFormat] shareContext:m_pGLCtx];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Set the new context as non opaque */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [m_pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Only swap on screen refresh */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// GLint swap = 1;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [m_pSharedGLCtx setValues:&swap forParameter:NSOpenGLCPSwapInterval];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Set this view as the drawable for the new context */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Only update after atleast 200 ms, cause glReadPixels is
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * heavy performance wise. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* todo: check this for optimization */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_STORAGE_HINT_APPLE,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Do other work processing here, using a double or triple buffer
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOThumbId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* We like to read from the primary color buffer */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Setup all matrices */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glViewport(0, 0, rr.size.width, rr.size.height);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glOrtho(0, rr.size.width, 0, rr.size.height, -1, 1);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glScalef(m_FBOThumbScaleX, m_FBOThumbScaleY, 1.0f);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Clear background to transparent */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome GLint y1 = (r.size.height - m_paClipRects[4*i+1]);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome GLint y2 = (r.size.height - m_paClipRects[4*i+3]);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Here the magic of reading the FBO content in our own buffer
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * happens. We have to lock this access, in the case the dock
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * is updated currently. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome glReadPixels(0, 0, rr.size.width, rr.size.height,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSDockTile *pDT = [[NSApplication sharedApplication] dockTile];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Send a display message to the dock tile in the main thread */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:NO];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Clear background to transparent */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Blit the content of the FBO to the screen. todo: check for
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * optimization with display lists. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome GLint y1 = r.size.height - m_paClipRects[4*i+1];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome GLint y2 = r.size.height - m_paClipRects[4*i+3];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome- (void)setVisibleRegions:(GLint)cRects paRects:(GLint*)paRects
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_paClipRects = (GLint*)RTMemAlloc(sizeof(GLint) * 4 * cRects);
4b22b9337f359bfd063322244f5336cc7c6ffcfars memcpy(m_paClipRects, paRects, sizeof(GLint) * 4 * cRects);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSView *contentView = [[[NSApplication sharedApplication] dockTile] contentView];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if ([contentView respondsToSelector:@selector(screenContent)])
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome screenContent = [contentView performSelector:@selector(screenContent)];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSRect dockFrame = [[self dockTileScreen] frame];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_FBOThumbScaleX = (float)dockFrame.size.width / parentFrame.size.width;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome m_FBOThumbScaleY = (float)dockFrame.size.height / parentFrame.size.height;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSRect 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));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// 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));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// 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));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// 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);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome/********************************************************************************
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome* OpenGL context management
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome********************************************************************************/
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid cocoaGLCtxCreate(NativeGLCtxRef *ppCtx, GLbitfield fVisParams)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Mark the end */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Choose a pixel format */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSOpenGLPixelFormat* pFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome *ppCtx = [[OverlayOpenGLContext alloc] initWithFormat:pFmt shareContext:nil];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Enable multi threaded OpenGL engine */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// CGLContextObj cglCtx = [*ppCtx CGLContextObj];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// CGLError err = CGLEnable(cglCtx, kCGLCEMPEngine);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// if (err != kCGLNoError)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// printf ("Couldn't enable MT OpenGL engine!\n");
4b22b9337f359bfd063322244f5336cc7c6ffcfars NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [pCtx release];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome/********************************************************************************
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome* View management
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome********************************************************************************/
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid cocoaViewCreate(NativeViewRef *ppView, NativeViewRef pParentView, GLbitfield fVisParams)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Create our worker view */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome OverlayView* pView = [[OverlayView alloc] initWithFrame:NSZeroRect thread:RTThreadSelf() parentView:pParentView];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* We need a real window as container for the view */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [[OverlayWindow alloc] initWithParentView:pParentView overlayView:pView];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Return the freshly created overlay view */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Hide the view early */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [[NSNotificationCenter defaultCenter] removeObserver:win];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// for (; b > 1; --b)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [win performSelector:@selector(release)]
cda73f64f20b8a0afc4909f5ea1f055ec7913856Toomas Soome [win performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
cda73f64f20b8a0afc4909f5ea1f055ec7913856Toomas Soome// [win release];
cda73f64f20b8a0afc4909f5ea1f055ec7913856Toomas Soome /* There seems to be a bug in the performSelector method which is called in
cda73f64f20b8a0afc4909f5ea1f055ec7913856Toomas Soome * parentWindowChanged above. The object is retained but not released. This
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * results in an unbalanced reference count, which is here manually
4b22b9337f359bfd063322244f5336cc7c6ffcfars * decremented. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// for (; a > 1; --a)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [pView performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// [pView release];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid cocoaViewShow(NativeViewRef pView, GLboolean fShowIt)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid cocoaViewSetPosition(NativeViewRef pView, NativeViewRef pParentView, int x, int y)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [(OverlayView*)pView setPos:NSMakePoint(x, y)];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid cocoaViewSetSize(NativeViewRef pView, int w, int h)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [(OverlayView*)pView setSize:NSMakeSize(w, h)];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid cocoaViewGetGeometry(NativeViewRef pView, int *pX, int *pY, int *pW, int *pH)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid cocoaViewMakeCurrentContext(NativeViewRef pView, NativeGLCtxRef pCtx)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid cocoaViewSetVisibleRegion(NativeViewRef pView, GLint cRects, GLint* paRects)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome [(OverlayView*)pView setVisibleRegions:cRects paRects:paRects];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome/********************************************************************************
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome* Additional OpenGL wrapper
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome********************************************************************************/
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// glFlush();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSOpenGLContext *pCtx = [NSOpenGLContext currentContext];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if ([pView respondsToSelector:@selector(flushFBO)])
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSOpenGLContext *pCtx = [NSOpenGLContext currentContext];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if ([pView respondsToSelector:@selector(finishFBO)])
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid cocoaBindFramebufferEXT(GLenum target, GLuint framebuffer)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome DEBUG_MSG_1(("glRenderspuBindFramebufferEXT called %d\n", framebuffer));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome NSOpenGLContext *pCtx = [NSOpenGLContext currentContext];