Changeset 37332 in vbox for trunk/src/VBox/HostServices/SharedOpenGL/render
- Timestamp:
- Jun 6, 2011 4:41:41 PM (14 years ago)
- Location:
- trunk/src/VBox/HostServices/SharedOpenGL/render
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c
r33977 r37332 1077 1077 renderspu_SystemBindFramebufferEXT(target, framebuffer); 1078 1078 } 1079 1080 void renderspuCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) 1081 { 1082 renderspu_SystemCopyPixels(x, y, width, height, type); 1083 } 1084 1085 void renderspuGetIntegerv(GLenum pname, GLint * params) 1086 { 1087 renderspu_SystemGetIntegerv(pname, params); 1088 } 1089 1090 void renderspuDrawBuffer(GLenum mode) 1091 { 1092 renderspu_SystemDrawBuffer(mode); 1093 } 1094 1095 void renderspuReadBuffer(GLenum mode) 1096 { 1097 printf("read win id: %d\n", render_spu.window_id); 1098 renderspu_SystemReadBuffer(mode); 1099 } 1079 1100 # endif 1080 1101 #endif … … 1121 1142 FILLIN( "Finish", renderspuFinish ); 1122 1143 FILLIN( "BindFramebufferEXT", renderspuBindFramebufferEXT ); 1144 FILLIN( "CopyPixels", renderspuCopyPixels ); 1145 FILLIN( "GetIntegerv", renderspuGetIntegerv ); 1146 FILLIN( "ReadBuffer", renderspuReadBuffer ); 1147 FILLIN( "DrawBuffer", renderspuDrawBuffer ); 1123 1148 # endif 1124 1149 #endif -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.h
r33991 r37332 303 303 extern void renderspu_SystemFinish(); 304 304 extern void renderspu_SystemBindFramebufferEXT(GLenum target, GLuint framebuffer); 305 extern void renderspu_SystemCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); 306 extern void renderspu_SystemGetIntegerv(GLenum pname, GLint *params); 307 extern void renderspu_SystemReadBuffer(GLenum mode); 308 extern void renderspu_SystemDrawBuffer(GLenum mode); 305 309 # endif 306 310 #endif -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa.c
r33806 r37332 201 201 } 202 202 203 void renderspu_SystemCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) 204 { 205 cocoaCopyPixels(x, y, width, height, type); 206 } 207 208 void renderspu_SystemGetIntegerv(GLenum pname, GLint * params) 209 { 210 cocoaGetIntegerv(pname, params); 211 } 212 213 void renderspu_SystemReadBuffer(GLenum mode) 214 { 215 cocoaReadBuffer(mode); 216 } 217 218 void renderspu_SystemDrawBuffer(GLenum mode) 219 { 220 cocoaDrawBuffer(mode); 221 } 222 -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.h
r30126 r37332 49 49 void cocoaFinish(void); 50 50 void cocoaBindFramebufferEXT(GLenum target, GLuint framebuffer); 51 void cocoaCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); 52 void cocoaGetIntegerv(GLenum pname, GLint *params); 53 void cocoaReadBuffer(GLenum mode); 54 void cocoaDrawBuffer(GLenum mode); 51 55 52 56 RT_C_DECLS_END -
trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m
r36735 r37332 27 27 #include <iprt/time.h> 28 28 29 /* 30 * How this works: 31 * In general it is not so easy like on the other platforms, cause Cocoa 32 * doesn't support any clipping of already painted stuff. In Mac OS X there is 33 * the concept of translucent canvas's e.g. windows and there it is just 34 * painted what should be visible to the user. Unfortunately this isn't the 35 * concept of chromium. Therefor I reroute all OpenGL operation from the guest 36 * to a frame buffer object (FBO). This is a OpenGL extension, which is 37 * supported by all OS X versions we support (AFAIC tell). Of course the guest 38 * doesn't know that and we have to make sure that the OpenGL state always is 39 * in the right state to paint into the FBO and not to the front/back buffer. 40 * Several functions below (like cocoaBindFramebufferEXT, cocoaGetIntegerv, 41 * ...) doing this. When a swap or finish is triggered by the guest, the 42 * content (which is already bound to an texture) is painted on the screen 43 * within a separate OpenGL context. This allows the usage of the same 44 * resources (texture ids, buffers ...) but at the same time having an 45 * different internal OpenGL state. Another advantage is that we can paint a 46 * thumbnail of the current output in a much more smaller (GPU accelerated 47 * scale) version on a third context and use glReadPixels to get the actual 48 * data. glReadPixels is a very slow operation, but as we just use a much more 49 * smaller image, we can handle it (anyway this is only done 5 times per 50 * second). 51 * 52 * Other things to know: 53 * - If the guest request double buffering, we have to make sure there are two 54 * buffers. We use the same FBO with 2 color attachments. Also glDrawBuffer 55 * and glReadBuffer is intercepted to make sure it is painted/read to/from 56 * the correct buffers. On swap our buffers are swapped and not the 57 * front/back buffer. 58 * - If the guest request a depth/stencil buffer, a combined render buffer for 59 * this is created. 60 * - If the size of the guest OpenGL window changes, all FBO's, textures, ... 61 * need to be recreated. 62 * - We need to track any changes to the parent window 63 * (create/destroy/move/resize). The various classes like OverlayHelperView, 64 * OverlayWindow, ... are there for. 65 * - The HGCM service runs on a other thread than the Main GUI. Keeps this 66 * always in mind (see e.g. performSelectorOnMainThread in renderFBOToView) 67 * - We make heavy use of late binding. We can not be sure that the GUI (or any 68 * other third party GUI), overwrite our NSOpenGLContext. So we always ask if 69 * this is our own one, before use. Really neat concept of Objective-C/Cocoa 70 * ;) 71 */ 72 29 73 /* Debug macros */ 30 74 #define FBO 1 /* Disable this to see how the output is without the FBO in the middle of the processing chain. */ 31 75 //#define SHOW_WINDOW_BACKGROUND 1 /* Define this to see the window background even if the window is clipped */ 32 //#define DEBUG_VERBOSE /* Define this couldget some debug info about the messages flow. */76 //#define DEBUG_VERBOSE /* Define this to get some debug info about the messages flow. */ 33 77 34 78 #ifdef DEBUG_poetzsch … … 63 107 switch (g) 64 108 { 65 case GL_INVALID_ENUM: errStr = RTStrDup("GL_INVALID_ENUM"); break;66 case GL_INVALID_VALUE: errStr = RTStrDup("GL_INVALID_VALUE"); break;109 case GL_INVALID_ENUM: errStr = RTStrDup("GL_INVALID_ENUM"); break; 110 case GL_INVALID_VALUE: errStr = RTStrDup("GL_INVALID_VALUE"); break; 67 111 case GL_INVALID_OPERATION: errStr = RTStrDup("GL_INVALID_OPERATION"); break; 68 case GL_STACK_OVERFLOW: errStr = RTStrDup("GL_STACK_OVERFLOW"); break;69 case GL_STACK_UNDERFLOW: errStr = RTStrDup("GL_STACK_UNDERFLOW"); break;70 case GL_OUT_OF_MEMORY: errStr = RTStrDup("GL_OUT_OF_MEMORY"); break;71 case GL_TABLE_TOO_LARGE: errStr = RTStrDup("GL_TABLE_TOO_LARGE"); break;72 default: errStr = RTStrDup("UNKNOWN"); break;112 case GL_STACK_OVERFLOW: errStr = RTStrDup("GL_STACK_OVERFLOW"); break; 113 case GL_STACK_UNDERFLOW: errStr = RTStrDup("GL_STACK_UNDERFLOW"); break; 114 case GL_OUT_OF_MEMORY: errStr = RTStrDup("GL_OUT_OF_MEMORY"); break; 115 case GL_TABLE_TOO_LARGE: errStr = RTStrDup("GL_TABLE_TOO_LARGE"); break; 116 default: errStr = RTStrDup("UNKNOWN"); break; 73 117 } 74 118 DEBUG_MSG(("%s:%d: glError %d (%s)\n", file, line, g, errStr)); … … 144 188 RTTHREAD mThread; 145 189 190 #ifdef FBO 191 GLuint m_FBOId; 146 192 /* FBO handling */ 147 GLuint m_FBOId; 148 GLuint m_FBOTexId; 193 GLuint m_FBOTexBackId; 194 GLuint m_FBOTexFrontId; 195 GLuint m_FBOAttBackId; 196 GLuint m_FBOAttFrontId; 197 GLuint m_FBODepthStencilPackedId; 149 198 NSSize m_FBOTexSize; 150 GLuint m_FBODepthStencilPackedId; 199 200 bool m_fFrontDrawing; 201 #endif 151 202 152 203 /* The corresponding dock tile view of this OpenGL view & all helper 153 204 * members. */ 154 205 DockOverlayView *m_DockTileView; 206 155 207 GLuint m_FBOThumbId; 156 208 GLuint m_FBOThumbTexId; … … 189 241 - (void)deleteFBO; 190 242 243 - (bool)isCurrentFBO; 191 244 - (void)updateFBO; 192 245 - (void)makeCurrentFBO; 193 246 - (void)swapFBO; 194 247 - (void)flushFBO; 248 - (void)stateInfo:(GLenum)pname withParams:(GLint*)params; 195 249 - (void)finishFBO; 196 - (void)bindFBO; 250 - (void)bindFBO:(GLenum)target withFrameBuffer:(GLuint)framebuffer; 251 - (void)tryDraw; 197 252 - (void)renderFBOToView; 253 - (void)renderFBOToDockTile; 198 254 199 255 - (void)clearVisibleRegions; … … 317 373 isPlanar:NO 318 374 colorSpaceName:NSDeviceRGBColorSpace 375 bitmapFormat:NSAlphaFirstBitmapFormat 319 376 bytesPerRow:frame.size.width * 4 320 377 bitsPerPixel:8 * 4]; … … 332 389 - (void)drawRect:(NSRect)aRect 333 390 { 391 NSRect frame; 392 334 393 [self lock]; 335 394 #ifdef SHOW_WINDOW_BACKGROUND 336 395 [[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7] set]; 337 NSRectframe = [self frame];338 [NSBezierPath fillRect:NSMakeRect(0, 0, frame.size.width, frame.size.height)]; 396 frame = [self frame]; 397 [NSBezierPath fillRect:NSMakeRect(0, 0, frame.size.width, frame.size.height)]; 339 398 #endif /* SHOW_WINDOW_BACKGROUND */ 340 399 if (m_ThumbImage != nil) … … 370 429 m_pPixelFormat = format; 371 430 431 DEBUG_MSG(("OCTX(%p): init OverlayOpenGLContext\n", (void*)self)); 432 372 433 return self; 373 434 } 374 435 375 436 - (void)dealloc 376 437 { 377 DEBUG_MSG((" Dealloc context %X\n", (uint)self));438 DEBUG_MSG(("OCTX(%p): dealloc OverlayOpenGLContext\n", (void*)self)); 378 439 379 440 [m_pPixelFormat release]; … … 391 452 -(void)setView:(NSView*)view 392 453 { 454 DEBUG_MSG(("OCTX(%p): setView: new view: %p\n", (void*)self, (void*)view)); 455 393 456 #ifdef FBO 394 457 m_pView = view;; … … 409 472 -(void)clearDrawable 410 473 { 474 DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void*)self)); 475 411 476 m_pView = NULL;; 412 477 [super clearDrawable]; … … 418 483 } 419 484 420 @end ;485 @end 421 486 422 487 /******************************************************************************** … … 433 498 m_pOverlayWindow = pOverlayWindow; 434 499 500 DEBUG_MSG(("OHVW(%p): init OverlayHelperView\n", (void*)self)); 501 435 502 return self; 436 503 } … … 438 505 -(void)viewDidMoveToWindow 439 506 { 507 DEBUG_MSG(("OHVW(%p): viewDidMoveToWindow: new win: %p\n", (void*)self, (void*)[self window])); 508 440 509 [m_pOverlayWindow parentWindowChanged:[self window]]; 441 510 } … … 452 521 - (id)initWithParentView:(NSView*)pParentView overlayView:(OverlayView*)pOverlayView 453 522 { 454 if(self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]) 523 NSWindow *pParentWin = nil; 524 525 if((self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])) 455 526 { 456 527 m_pParentView = pParentView; … … 476 547 [self setIgnoresMouseEvents:YES]; 477 548 478 NSWindow *pParentWin = [m_pParentView window];549 pParentWin = [m_pParentView window]; 479 550 480 551 /* Initial set the position to the parents view top/left (Compiz fix). */ … … 488 559 /* Add ourself as a child to the parent views window. Note: this has to 489 560 * be done last so that everything else is setup in 490 * parentWindowChanged. */ 561 * parentWindowChanged. */ 491 562 [pParentWin addChildWindow:self ordered:NSWindowAbove]; 492 563 } 564 DEBUG_MSG(("OWIN(%p): init OverlayWindow\n", (void*)self)); 565 493 566 return self; 494 567 } … … 496 569 - (void)dealloc 497 570 { 498 DEBUG_MSG((" Dealloc window %X\n", (uint)self));571 DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void*)self)); 499 572 500 573 [[NSNotificationCenter defaultCenter] removeObserver:self]; … … 508 581 - (void)parentWindowFrameChanged:(NSNotification*)pNote 509 582 { 583 DEBUG_MSG(("OWIN(%p): parentWindowFrameChanged\n", (void*)self)); 584 510 585 /* Reposition this window with the help of the OverlayView. Perform the 511 586 * call in the OpenGL thread. */ 512 // [m_pOverlayView performSelector:@selector(reshape) onThread:m_Thread withObject:nil waitUntilDone:YES]; 513 DEBUG_MSG(("parentWindowFrameChanged\n")); 587 /* 588 [m_pOverlayView performSelector:@selector(reshape) onThread:m_Thread withObject:nil waitUntilDone:YES]; 589 */ 590 514 591 [m_pOverlayView reshape]; 515 592 } … … 517 594 - (void)parentWindowChanged:(NSWindow*)pWindow 518 595 { 596 DEBUG_MSG(("OWIN(%p): parentWindowChanged\n", (void*)self)); 597 519 598 [[NSNotificationCenter defaultCenter] removeObserver:self]; 520 DEBUG_MSG(("parentWindowChanged\n")); 599 521 600 if(pWindow != nil) 522 601 { … … 531 610 /* Reshape the overlay view after a short waiting time to let the main 532 611 * window resize itself properly. */ 533 // [m_pOverlayView performSelector:@selector(reshape) withObject:nil afterDelay:0.2]; 534 // [NSTimer scheduledTimerWithTimeInterval:0.2 target:m_pOverlayView selector:@selector(reshape) userInfo:nil repeats:NO]; 612 /* 613 [m_pOverlayView performSelector:@selector(reshape) withObject:nil afterDelay:0.2]; 614 [NSTimer scheduledTimerWithTimeInterval:0.2 target:m_pOverlayView selector:@selector(reshape) userInfo:nil repeats:NO]; 615 */ 535 616 [m_pOverlayView reshape]; 536 617 } … … 548 629 - (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView 549 630 { 550 m_pParentView = pParentView;631 m_pParentView = pParentView; 551 632 /* Make some reasonable defaults */ 552 m_pGLCtx = NULL; 553 m_pSharedGLCtx = NULL; 554 mThread = aThread; 555 m_FBOId = 0; 556 m_FBOTexId = 0; 557 m_FBOTexSize = NSZeroSize; 633 m_pGLCtx = nil; 634 m_pSharedGLCtx = nil; 635 mThread = aThread; 636 #ifdef FBO 637 m_FBOId = 0; 638 m_FBOTexBackId = 0; 639 m_FBOTexFrontId = 0; 640 m_FBOAttBackId = GL_COLOR_ATTACHMENT0_EXT; 641 m_FBOAttFrontId = GL_COLOR_ATTACHMENT1_EXT; 558 642 m_FBODepthStencilPackedId = 0; 559 m_FBOT humbId = 0;560 m_FBOThumbTexId = 0; 561 m_ cClipRects= 0;562 m_ paClipRects = NULL;563 m_ Pos = NSZeroPoint;564 m_ Size = NSZeroSize;565 m_ RootShift= NSZeroPoint;566 567 DEBUG_MSG(("Init view %X (%X)\n", (uint)self, (uint)mThread));568 643 m_FBOTexSize = NSZeroSize; 644 #endif 645 m_FBOThumbId = 0; 646 m_FBOThumbTexId = 0; 647 m_cClipRects = 0; 648 m_paClipRects = NULL; 649 m_Pos = NSZeroPoint; 650 m_Size = NSMakeSize(1, 1); 651 m_RootShift = NSZeroPoint; 652 569 653 self = [super initWithFrame:frame]; 570 654 655 DEBUG_MSG(("OVIW(%p): init OverlayView\n", (void*)self)); 656 571 657 return self; 572 658 } … … 574 660 - (void)dealloc 575 661 { 576 DEBUG_MSG((" Dealloc view %X\n", (uint)self));662 DEBUG_MSG(("OVIW(%p): dealloc OverlayView\n", (void*)self)); 577 663 578 664 [self deleteFBO]; … … 580 666 if (m_pGLCtx) 581 667 { 582 if ([m_pGLCtx view] == self) 668 if ([m_pGLCtx view] == self) 583 669 [m_pGLCtx clearDrawable]; 584 670 } 585 671 if (m_pSharedGLCtx) 586 672 { 587 if ([m_pSharedGLCtx view] == self) 673 if ([m_pSharedGLCtx view] == self) 588 674 [m_pSharedGLCtx clearDrawable]; 589 675 … … 598 684 - (void)drawRect:(NSRect)aRect 599 685 { 600 // NSGraphicsContext*pC = [NSGraphicsContext currentContext]; 601 // [[NSColor blueColor] set]; 602 // NSBezierPath *p = [[NSBezierPath alloc] bezierPathWithOvalInRect:[self frame]]; 603 // [p fill]; 604 // [[NSColor greenColor] set]; 605 // [p stroke]; 606 // if ([self lockFocusIfCanDraw]) 607 // { 608 // [self renderFBOToView]; 609 // [self unlockFocus]; 610 // } 686 /* Do nothing */ 611 687 } 612 688 613 689 - (void)setGLCtx:(NSOpenGLContext*)pCtx 614 690 { 691 DEBUG_MSG(("OVIW(%p): setGLCtx: new ctx: %p\n", (void*)self, (void*)pCtx)); 692 615 693 m_pGLCtx = pCtx; 616 694 } … … 626 704 } 627 705 628 - (void)setParentView: (NSView*)view 629 { 630 m_pParentView = view; 631 } 632 633 - (void)setOverlayWin: (NSWindow*)win 634 { 635 m_pOverlayWin = win; 706 - (void)setParentView:(NSView*)pView 707 { 708 DEBUG_MSG(("OVIW(%p): setParentView: new view: %p\n", (void*)self, (void*)pView)); 709 710 m_pParentView = pView; 711 } 712 713 - (void)setOverlayWin:(NSWindow*)pWin 714 { 715 DEBUG_MSG(("OVIW(%p): setOverlayWin: new win: %p\n", (void*)self, (void*)pWin)); 716 717 m_pOverlayWin = pWin; 636 718 } 637 719 … … 643 725 - (void)setPos:(NSPoint)pos 644 726 { 727 DEBUG_MSG(("OVIW(%p): setPos: new pos: %d, %d\n", (void*)self, (int)pos.x, (int)pos.y)); 728 645 729 m_Pos = pos; 730 646 731 [self reshape]; 647 732 } … … 655 740 { 656 741 m_Size = size; 657 658 if (!m_FBOId) 659 { 660 DEBUG_MSG(("Set size (no fbo) %p\n", self)); 661 [self reshape]; 662 [self updateFBO]; 663 } 664 else 665 { 666 DEBUG_MSG(("Set size FBO %p\n", self)); 742 743 #ifdef FBO 744 if (m_FBOId) 745 { 746 DEBUG_MSG(("OVIW(%p): setSize: new size: %dx%d\n", (void*)self, (int)size.width, (int)size.height)); 667 747 [self reshape]; 668 748 [self updateFBO]; … … 670 750 [self updateViewport]; 671 751 } 752 else 753 #endif 754 { 755 DEBUG_MSG(("OVIW(%p): setSize (no FBO): new size: %dx%d\n", (void*)self, (int)size.width, (int)size.height)); 756 [self reshape]; 757 [self updateFBO]; 758 } 672 759 } 673 760 … … 679 766 - (void)updateViewport 680 767 { 681 DEBUG_MSG(("updateViewport %p\n", self)); 768 NSRect r; 769 770 DEBUG_MSG(("OVIW(%p): updateViewport\n", (void*)self)); 771 772 #ifdef FBO 682 773 if (m_pSharedGLCtx) 683 774 { 684 775 /* Update the viewport for our OpenGL view */ 685 DEBUG_MSG((" MakeCurrent (shared) %X\n",m_pSharedGLCtx));776 DEBUG_MSG(("OVIW(%p): makeCurrent (shared) %p\n", (void*)self, (void*)m_pSharedGLCtx)); 686 777 [m_pSharedGLCtx makeCurrentContext]; 687 778 [m_pSharedGLCtx update]; 688 779 689 NSRectr = [self frame];780 r = [self frame]; 690 781 /* Setup all matrices */ 691 782 glMatrixMode(GL_PROJECTION); … … 693 784 glViewport(0, 0, r.size.width, r.size.height); 694 785 glOrtho(0, r.size.width, 0, r.size.height, -1, 1); 695 DEBUG_MSG_1((" frame[%i, %i, %i, %i]\n", (int)r.origin.x, (int)r.origin.x, (int)r.size.width, (int)r.size.height));696 DEBUG_MSG_1((" m_Pos(%i,%i) m_Size(%i,%i)\n", (int)m_Pos.x, (int)m_Pos.y, (int)m_Size.width, (int)m_Size.height));697 DEBUG_MSG_1((" m_RootShift(%i, %i)\n", (int)m_RootShift.x, (int)m_RootShift.y));786 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)); 787 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)); 788 DEBUG_MSG_1(("OVIW(%p): m_RootShift(%i, %i)\n", (void*)self, (int)m_RootShift.x, (int)m_RootShift.y)); 698 789 glMatrixMode(GL_TEXTURE); 699 790 glLoadIdentity(); 700 glTranslatef(0.0f, m_RootShift.y, 0.0f);701 791 glMatrixMode(GL_MODELVIEW); 702 792 glLoadIdentity(); 703 glTranslatef(-m_RootShift.x, 0.0f, 0.0f);704 793 705 794 /* Clear background to transparent */ 706 795 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 707 796 708 glEnable(GL_TEXTURE_RECTANGLE_ARB); 709 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId); 710 711 DEBUG_MSG(("MakeCurrent %X\n", m_pGLCtx)); 797 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 798 glReadBuffer(m_FBOAttFrontId); 799 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); 800 glDrawBuffer(GL_BACK); 801 802 DEBUG_MSG(("OVIW(%p): makeCurrent (non shared) %p\n", (void*)self, (void*)m_pGLCtx)); 712 803 [m_pGLCtx makeCurrentContext]; 713 804 } 805 #endif 714 806 } 715 807 716 808 - (void)reshape 717 809 { 718 DEBUG_MSG(("(%p)reshape %p\n", RTThreadSelf(), self)); 810 NSRect parentFrame = NSZeroRect; 811 NSPoint parentPos = NSZeroPoint; 812 NSPoint childPos = NSZeroPoint; 813 NSRect childFrame = NSZeroRect; 814 NSRect newFrame = NSZeroRect; 815 816 DEBUG_MSG(("OVIW(%p): reshape\n", (void*)self)); 817 719 818 /* Getting the right screen coordinates of the parents frame is a little bit 720 819 * complicated. */ 721 NSRectparentFrame = [m_pParentView frame];722 NSPointparentPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:NSMakePoint(parentFrame.origin.x, parentFrame.origin.y + parentFrame.size.height)]];820 parentFrame = [m_pParentView frame]; 821 parentPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:NSMakePoint(parentFrame.origin.x, parentFrame.origin.y + parentFrame.size.height)]]; 723 822 parentFrame.origin.x = parentPos.x; 724 823 parentFrame.origin.y = parentPos.y; 725 824 726 825 /* Calculate the new screen coordinates of the overlay window. */ 727 NSPointchildPos = NSMakePoint(m_Pos.x, m_Pos.y + m_Size.height);826 childPos = NSMakePoint(m_Pos.x, m_Pos.y + m_Size.height); 728 827 childPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:childPos]]; 729 828 730 829 /* Make a frame out of it. */ 731 NSRectchildFrame = NSMakeRect(childPos.x, childPos.y, m_Size.width, m_Size.height);830 childFrame = NSMakeRect(childPos.x, childPos.y, m_Size.width, m_Size.height); 732 831 733 832 /* We have to make sure that the overlay window will not be displayed out 734 833 * of the parent window. So intersect both frames & use the result as the new 735 834 * frame for the window. */ 736 NSRectnewFrame = NSIntersectionRect(parentFrame, childFrame);835 newFrame = NSIntersectionRect(parentFrame, childFrame); 737 836 738 837 /* Later we have to correct the texture position in the case the window is … … 747 846 m_RootShift.y = 0; 748 847 749 // NSScrollView *pScrollView = [[[m_pParentView window] contentView] enclosingScrollView]; 750 // if (pScrollView) 751 // { 752 // NSRect scrollRect = [pScrollView documentVisibleRect]; 753 // NSRect scrollRect = [m_pParentView visibleRect]; 754 // printf ("sc rect: %d %d %d %d\n", (int) scrollRect.origin.x,(int) scrollRect.origin.y,(int) scrollRect.size.width,(int) scrollRect.size.height); 755 // NSRect b = [[m_pParentView superview] bounds]; 756 // printf ("bound rect: %d %d %d %d\n", (int) b.origin.x,(int) b.origin.y,(int) b.size.width,(int) b.size.height); 757 // newFrame.origin.x += scrollRect.origin.x; 758 // newFrame.origin.y += scrollRect.origin.y; 759 // } 848 /* 849 NSScrollView *pScrollView = [[[m_pParentView window] contentView] enclosingScrollView]; 850 if (pScrollView) 851 { 852 NSRect scrollRect = [pScrollView documentVisibleRect]; 853 NSRect scrollRect = [m_pParentView visibleRect]; 854 printf ("sc rect: %d %d %d %d\n", (int) scrollRect.origin.x,(int) scrollRect.origin.y,(int) scrollRect.size.width,(int) scrollRect.size.height); 855 NSRect b = [[m_pParentView superview] bounds]; 856 printf ("bound rect: %d %d %d %d\n", (int) b.origin.x,(int) b.origin.y,(int) b.size.width,(int) b.size.height); 857 newFrame.origin.x += scrollRect.origin.x; 858 newFrame.origin.y += scrollRect.origin.y; 859 } 860 */ 760 861 761 862 /* Set the new frame. */ … … 771 872 - (void)createFBO 772 873 { 773 GLint oldTexId; 774 GLint oldFBId; 775 776 DEBUG_MSG(("createFBO %p\n", self)); 874 GLint oldTexId = 0; 875 GLint oldFBId = 0; 876 NSView *pDockScreen = nil; 877 GLint maxTexSize = 0; 878 GLfloat imageAspectRatio = 0; 879 GLint filter = GL_NEAREST; 880 777 881 [self deleteFBO]; 778 882 779 //GL_SAVE_STATE; 780 #if 0 781 CHECK_GL_ERROR(); 782 glPushAttrib(GL_ACCUM_BUFFER_BIT); 783 glPopAttrib(); 784 CHECK_GL_ERROR(); 785 #endif 883 #ifdef FBO 884 DEBUG_MSG(("OVIW(%p): createFBO\n", (void*)self)); 786 885 787 886 glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &oldTexId); … … 800 899 if (!isFBO) 801 900 { 802 DEBUG_MSG(("Your system does not support framebuffer extension\n")); 803 } 804 901 DEBUG_MSG(("Your system does not support the GL_EXT_framebuffer_object extension\n")); 902 } 903 isFBO = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_blit", strExt); 904 if (!isFBO) 905 { 906 DEBUG_MSG(("Your system does not support the GL_EXT_framebuffer_blit extension\n")); 907 } 908 805 909 /* Create FBO object */ 806 910 glGenFramebuffersEXT(1, &m_FBOId); 807 911 /* & the texture as well the depth/stencil render buffer */ 808 glGenTextures(1, &m_FBOTexId); 809 DEBUG_MSG(("Create FBO %d %d\n", m_FBOId, m_FBOTexId)); 912 glGenTextures(1, &m_FBOTexBackId); 913 glGenTextures(1, &m_FBOTexFrontId); 914 DEBUG_MSG(("OVIW(%p): gen numbers: FBOId=%d FBOTexBackId=%d FBOTexFrontId=%d\n", (void*)self, m_FBOId, m_FBOTexBackId, m_FBOTexFrontId)); 810 915 811 916 glGenRenderbuffersEXT(1, &m_FBODepthStencilPackedId); … … 816 921 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId); 817 922 818 /*glEnable(GL_TEXTURE_RECTANGLE_ARB);*/ 819 820 GLfloat imageAspectRatio = m_FBOTexSize.width / m_FBOTexSize.height; 923 /* 924 glEnable(GL_TEXTURE_RECTANGLE_ARB); 925 */ 926 927 imageAspectRatio = m_FBOTexSize.width / m_FBOTexSize.height; 821 928 822 929 /* Sanity check against maximum OpenGL texture size. If bigger adjust to 823 930 * maximum possible size while maintain the aspect ratio. */ 824 GLint maxTexSize;825 931 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize); 826 // maxTexSize = 150; 827 GLint filter = GL_NEAREST; 828 if (m_FBOTexSize.width > maxTexSize || m_FBOTexSize.height > maxTexSize) 932 if (m_FBOTexSize.width > maxTexSize || m_FBOTexSize.height > maxTexSize) 829 933 { 830 934 filter = GL_LINEAR; 831 935 if (imageAspectRatio > 1) 832 936 { 833 m_FBOTexSize.width = maxTexSize; 937 m_FBOTexSize.width = maxTexSize; 834 938 m_FBOTexSize.height = maxTexSize / imageAspectRatio; 835 939 } … … 837 941 { 838 942 m_FBOTexSize.width = maxTexSize * imageAspectRatio; 839 m_FBOTexSize.height = maxTexSize; 840 } 841 } 842 843 /* Initialize FBO Texture */ 844 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId); 845 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, filter); 846 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, filter); 847 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); 848 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); 849 943 m_FBOTexSize.height = maxTexSize; 944 } 945 } 946 947 DEBUG_MSG(("OVIW(%p): tex size is: %dx%d\n", (void*)self, (int)m_FBOTexSize.width, (int)m_FBOTexSize.height)); 948 949 /* Initialize FBO Textures */ 850 950 /* The GPUs like the GL_BGRA / GL_UNSIGNED_INT_8_8_8_8_REV combination 851 951 * others are also valid, but might incur a costly software translation. */ 952 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexBackId); 852 953 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); 853 DEBUG_MSG(("m_FBOTexSize(%i,%i)\n", (int)m_FBOTexSize.width, (int)m_FBOTexSize.height)); 854 855 /* Now attach texture to the FBO as its color destination */ 856 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId, 0); 954 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexFrontId); 955 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); 956 957 /* Now attach the textures to the FBO as its color destinations */ 958 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, m_FBOAttBackId, GL_TEXTURE_RECTANGLE_ARB, m_FBOTexBackId, 0); 959 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, m_FBOAttFrontId, GL_TEXTURE_RECTANGLE_ARB, m_FBOTexFrontId, 0); 857 960 858 961 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId); 859 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, m_FBOTexSize.width, m_FBOTexSize.height); 860 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId); 861 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId); 962 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_FBOTexSize.width, m_FBOTexSize.height); 963 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId); 964 965 /* Bind the FBOs for reading and drawing. */ 966 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 967 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId); 968 969 /* Explicitly clear the textures otherwise they would contain old memory stuff. */ 970 glDrawBuffer(m_FBOAttBackId); 971 glClear(GL_COLOR_BUFFER_BIT); 972 glDrawBuffer(m_FBOAttFrontId); 973 glClear(GL_COLOR_BUFFER_BIT); 974 975 /* Now initially reading/drawing to the back buffer. */ 976 glReadBuffer(m_FBOAttBackId); 977 glDrawBuffer(m_FBOAttBackId); 862 978 863 979 /* Make sure the FBO was created successfully. */ 864 980 if (GL_FRAMEBUFFER_COMPLETE_EXT != glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)) 865 DEBUG_MSG((" Framebuffer Object creation or update failed!\n"));981 DEBUG_MSG(("OVIW(%p): Framebuffer Object creation or update failed!\n", (void*)self)); 866 982 867 983 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, oldTexId); 868 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, oldFBId ? oldFBId:m_FBOId);984 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (GLuint)oldFBId ? (GLuint)oldFBId : m_FBOId); 869 985 870 986 /* Is there a dock tile preview enabled in the GUI? If so setup a 871 987 * additional thumbnail view for the dock tile. */ 872 NSView *dockScreen = [self dockTileScreen];873 if ( dockScreen)988 pDockScreen = [self dockTileScreen]; 989 if (pDockScreen) 874 990 { 875 991 if (!m_FBOThumbId) … … 886 1002 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); 887 1003 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); 888 1004 889 1005 /* The GPUs like the GL_BGRA / GL_UNSIGNED_INT_8_8_8_8_REV combination 890 1006 * others are also valid, but might incur a costly software translation. */ 891 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB A, m_FBOTexSize.width * m_FBOThumbScaleX, m_FBOTexSize.height * m_FBOThumbScaleY, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);1007 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); 892 1008 893 1009 /* Now attach texture to the FBO as its color destination */ … … 896 1012 /* Make sure the FBO was created successfully. */ 897 1013 if (GL_FRAMEBUFFER_COMPLETE_EXT != glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)) 898 DEBUG_MSG((" Framebuffer Thumb Object creation or update failed!\n"));1014 DEBUG_MSG(("OVIW(%p): Framebuffer \"Thumb\" Object creation or update failed!\n", (void*)self)); 899 1015 900 1016 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, oldTexId); 901 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, oldFBId ? oldFBId:m_FBOId);1017 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (GLuint)oldFBId ? (GLuint)oldFBId : m_FBOId); 902 1018 903 1019 m_DockTileView = [[DockOverlayView alloc] init]; 904 1020 [self reshapeDockTile]; 905 [ dockScreen addSubview:m_DockTileView];1021 [pDockScreen addSubview:m_DockTileView]; 906 1022 } 907 1023 … … 914 1030 m_paClipRects[2] = m_FBOTexSize.width; 915 1031 m_paClipRects[3] = m_FBOTexSize.height; 916 917 //GL_RESTORE_STATE; 1032 #endif 918 1033 } 919 1034 920 1035 - (void)deleteFBO 921 1036 { 922 DEBUG_MSG(("deleteFBO %p\n", self)); 1037 DEBUG_MSG(("OVIW(%p): deleteFBO\n", (void*)self)); 1038 923 1039 if (m_pSharedGLCtx) 924 1040 { 925 DEBUG_MSG((" MakeCurrent (shared) %X\n",m_pSharedGLCtx));1041 DEBUG_MSG(("OVIW(%p): makeCurrent (shared) %p\n", (void*)self, (void*)m_pSharedGLCtx)); 926 1042 [m_pSharedGLCtx makeCurrentContext]; 927 1043 [m_pSharedGLCtx update]; … … 933 1049 if (m_pGLCtx) 934 1050 { 935 DEBUG_MSG((" MakeCurrent %X\n",m_pGLCtx));1051 DEBUG_MSG(("OVIW(%p): makeCurrent (non shared) %p\n", (void*)self, (void*)m_pGLCtx)); 936 1052 [m_pGLCtx makeCurrentContext]; 937 1053 1054 #ifdef FBO 938 1055 if (m_FBODepthStencilPackedId > 0) 939 1056 { … … 941 1058 m_FBODepthStencilPackedId = 0; 942 1059 } 943 if (m_FBOTexId > 0) 944 { 945 glDeleteTextures(1, &m_FBOTexId); 946 m_FBOTexId = 0; 1060 if (m_FBOTexBackId > 0) 1061 { 1062 glDeleteTextures(1, &m_FBOTexBackId); 1063 m_FBOTexBackId = 0; 1064 } 1065 if (m_FBOTexFrontId > 0) 1066 { 1067 glDeleteTextures(1, &m_FBOTexFrontId); 1068 m_FBOTexFrontId = 0; 947 1069 } 948 1070 if (m_FBOId > 0) 949 1071 { 950 GLint tmpFB; 951 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &tmpFB); 952 953 if (tmpFB == m_FBOId) 954 { 1072 if ([self isCurrentFBO]) 955 1073 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 956 } 957 1074 958 1075 glDeleteFramebuffersEXT(1, &m_FBOId); 959 1076 m_FBOId = 0; 960 1077 } 1078 #endif 961 1079 } 962 1080 … … 971 1089 - (void)updateFBO 972 1090 { 973 DEBUG_MSG(("updateFBO %p\n", self)); 1091 DEBUG_MSG(("OVIW(%p): updateFBO\n", (void*)self)); 1092 974 1093 [self makeCurrentFBO]; 975 1094 976 1095 if (m_pGLCtx) 977 1096 { … … 987 1106 - (void)makeCurrentFBO 988 1107 { 989 DEBUG_MSG_1(("MakeCurrent called %X\n", self)); 990 991 #ifdef FBO 1108 DEBUG_MSG(("OVIW(%p): makeCurrentFBO\n", (void*)self)); 1109 1110 #ifdef FBO 1111 DEBUG_MSG(("OVIW(%p): FBOId=%d CTX=%p\n", (void*)self, m_FBOId, (void*)m_pGLCtx)); 992 1112 if([NSOpenGLContext currentContext] != 0) 993 1113 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId); … … 995 1115 if (m_pGLCtx) 996 1116 { 997 if ([m_pGLCtx view] != self) 1117 if ([m_pGLCtx view] != self) 998 1118 { 999 1119 /* We change the active view, so flush first */ … … 1003 1123 CHECK_GL_ERROR(); 1004 1124 } 1005 // if ([NSOpenGLContext currentContext] != m_pGLCtx) 1006 { 1007 DEBUG_MSG(("MakeCurrent %X\n", m_pGLCtx)); 1125 /* 1126 if ([NSOpenGLContext currentContext] != m_pGLCtx) 1127 */ 1128 { 1008 1129 [m_pGLCtx makeCurrentContext]; 1009 1130 CHECK_GL_ERROR(); 1010 // [m_pGLCtx update]; 1131 /* 1132 [m_pGLCtx update]; 1133 */ 1011 1134 } 1012 1135 } … … 1016 1139 } 1017 1140 1141 - (bool)isCurrentFBO 1142 { 1143 #ifdef FBO 1144 GLint curFBOId = 0; 1145 1146 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &curFBOId); 1147 DEBUG_MSG_1(("OVIW(%p): isCurrentFBO: curFBOId=%d FBOId=%d\n", (void*)self, curFBOId, m_FBOId)); 1148 return (GLuint)curFBOId == m_FBOId; 1149 #else 1150 return false; 1151 #endif 1152 } 1153 1154 - (void)tryDraw 1155 { 1156 if ([self lockFocusIfCanDraw]) 1157 { 1158 [self renderFBOToView]; 1159 [self unlockFocus]; 1160 } 1161 } 1162 1018 1163 - (void)swapFBO 1019 1164 { 1020 DEBUG_MSG_1(("SwapCurrent called %X\n", self)); 1021 1022 #ifdef FBO 1023 GLint tmpFB; 1024 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &tmpFB); 1025 DEBUG_MSG_1(("Swap GetINT %d\n", tmpFB)); 1026 /* Don't use flush buffers cause we are using FBOs here */ 1027 // [m_pGLCtx flushBuffer]; 1028 glFlush(); 1029 // glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1030 DEBUG_MSG_1(("swapFBO bound:%i, self:%i\n", tmpFB, m_FBOId)); 1031 if (tmpFB == m_FBOId) 1032 { 1033 if ([self lockFocusIfCanDraw]) 1034 { 1035 [self renderFBOToView]; 1036 [self unlockFocus]; 1037 } 1038 } 1039 // glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId); 1165 GLint sw = 0; 1166 GLint readId = 0; 1167 GLint drawId = 0; 1168 1169 DEBUG_MSG(("OVIW(%p): swapFBO\n", (void*)self)); 1170 1171 #ifdef FBO 1172 glBindFramebufferEXT(GL_FRAMEBUFFER_BINDING_EXT, m_FBOId); 1173 1174 /* Don't use flush buffers cause we are using FBOs here! */ 1175 1176 if ([self isCurrentFBO]) 1177 { 1178 /* Fetch the current used read and draw buffers. */ 1179 glGetIntegerv(GL_READ_BUFFER, &readId); 1180 glGetIntegerv(GL_DRAW_BUFFER, &drawId); 1181 1182 /* Do the swapping of our internal ids */ 1183 sw = m_FBOTexFrontId; 1184 m_FBOTexFrontId = m_FBOTexBackId; 1185 m_FBOTexBackId = sw; 1186 sw = m_FBOAttFrontId; 1187 m_FBOAttFrontId = m_FBOAttBackId; 1188 m_FBOAttBackId = sw; 1189 1190 /* We also have to swap the real ids on the current context. */ 1191 if ((GLuint)readId == m_FBOAttFrontId) 1192 { 1193 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1194 glReadBuffer(m_FBOAttBackId); 1195 } 1196 if ((GLuint)drawId == m_FBOAttFrontId) 1197 { 1198 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId); 1199 glDrawBuffer(m_FBOAttBackId); 1200 } 1201 1202 [self tryDraw]; 1203 } 1040 1204 #else 1041 1205 [m_pGLCtx flushBuffer]; … … 1045 1209 - (void)flushFBO 1046 1210 { 1047 GLint tmpFB; 1048 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &tmpFB); 1211 GLint drawId = 0; 1212 1213 DEBUG_MSG(("OVIW(%p): flushFBO\n", (void*)self)); 1214 1049 1215 glFlush(); 1050 // glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1051 DEBUG_MSG_1 (("Flush GetINT %d\n", tmpFB)); 1052 if (tmpFB == m_FBOId) 1053 { 1054 if ([self lockFocusIfCanDraw]) 1055 { 1056 [self renderFBOToView]; 1057 [self unlockFocus]; 1058 } 1059 } 1060 // glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId); 1216 #ifdef FBO 1217 /* If at any time OpenGl operations where done in the front buffer, we need 1218 * to reflect this in the FBO as well. This is something which on real 1219 * hardware happens and unfortunately some applications rely on it (grrr ... Compiz). */ 1220 if ( m_fFrontDrawing 1221 && [self isCurrentFBO]) 1222 { 1223 /* Only reset if we aren't currently front. */ 1224 glGetIntegerv(GL_DRAW_BUFFER, &drawId); 1225 if (drawId != m_FBOAttFrontId) 1226 m_fFrontDrawing = false; 1227 [self tryDraw]; 1228 } 1229 #endif 1061 1230 } 1062 1231 1063 1232 - (void)finishFBO 1064 1233 { 1065 GLint tmpFB;1066 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &tmpFB); 1234 DEBUG_MSG(("OVIW(%p): finishFBO\n", (void*)self)); 1235 1067 1236 glFinish(); 1068 // glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1069 DEBUG_MSG_1 (("Finish GetINT %d\n", tmpFB)); 1070 if (tmpFB == m_FBOId) 1071 { 1072 if ([self lockFocusIfCanDraw]) 1073 { 1074 [self renderFBOToView]; 1075 [self unlockFocus]; 1076 } 1077 } 1078 // glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId); 1079 } 1080 1081 - (void)bindFBO 1082 { 1083 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOId); 1237 #ifdef FBO 1238 if ([self isCurrentFBO]) 1239 [self tryDraw]; 1240 #endif 1241 } 1242 1243 - (void)stateInfo:(GLenum)pname withParams:(GLint*)params 1244 { 1245 DEBUG_MSG_1(("StateInfo requested: %d\n", pname)); 1246 1247 glGetIntegerv(pname, params); 1248 #ifdef FBO 1249 switch(pname) 1250 { 1251 case GL_FRAMEBUFFER_BINDING_EXT: 1252 case GL_READ_FRAMEBUFFER_BINDING: 1253 case GL_READ_FRAMEBUFFER_EXT: 1254 case GL_DRAW_FRAMEBUFFER_EXT: 1255 { 1256 // DEBUG_MSG_1(("StateInfo current Framebuffer: %d\n", *params)); 1257 if ((GLuint)*params == m_FBOId) 1258 *params = 0; 1259 break; 1260 } 1261 case GL_READ_BUFFER: 1262 case GL_DRAW_BUFFER: 1263 { 1264 // DEBUG_MSG_1(("StateInfo current read/draw buffer: %d\n", *params)); 1265 if ((GLuint)*params == m_FBOAttFrontId) 1266 *params = GL_FRONT; 1267 else 1268 if ((GLuint)*params == m_FBOAttBackId) 1269 *params = GL_BACK; 1270 break; 1271 } 1272 } 1273 #endif 1274 } 1275 1276 - (void)readBuffer:(GLenum)mode 1277 { 1278 #ifdef FBO 1279 /* 1280 if ([self isCurrentFBO]) 1281 */ 1282 { 1283 if (mode == GL_FRONT) 1284 glReadBuffer(m_FBOAttFrontId); 1285 else if (mode == GL_BACK) 1286 glReadBuffer(m_FBOAttBackId); 1287 else 1288 glReadBuffer(mode); 1289 } 1290 #else 1291 glReadBuffer(mode); 1292 #endif 1293 } 1294 1295 - (void)drawBuffer:(GLenum)mode 1296 { 1297 #ifdef FBO 1298 /* 1299 if ([self isCurrentFBO]) 1300 */ 1301 { 1302 if (mode == GL_FRONT) 1303 { 1304 DEBUG_MSG(("OVIW(%p): front\n", (void*)self)); 1305 glDrawBuffer(m_FBOAttFrontId); 1306 m_fFrontDrawing = true; 1307 } 1308 else if (mode == GL_BACK) 1309 { 1310 DEBUG_MSG(("OVIW(%p): back\n", (void*)self)); 1311 glDrawBuffer(m_FBOAttBackId); 1312 } 1313 else 1314 { 1315 DEBUG_MSG(("OVIW(%p): other\n", (void*)self)); 1316 glDrawBuffer(mode); 1317 } 1318 } 1319 #else 1320 glDrawBuffer(mode); 1321 #endif 1322 } 1323 1324 - (void)bindFBO:(GLenum)target withFrameBuffer:(GLuint)framebuffer 1325 { 1326 #ifdef FBO 1327 if (framebuffer != 0) 1328 glBindFramebufferEXT(target, framebuffer); 1329 else 1330 glBindFramebufferEXT(target, m_FBOId); 1331 #else 1332 glBindFramebufferEXT(target, framebuffer); 1333 #endif 1084 1334 } 1085 1335 1086 1336 - (void)renderFBOToView 1087 1337 { 1338 GLint opaque = 0; 1339 GLint i = 0; 1340 GLint oldReadFBOId = 0; 1341 GLint oldDrawFBOId = 0; 1342 GLint oldReadId = 0; 1343 GLint oldDrawId = 0; 1344 1345 DEBUG_MSG(("OVIW(%p): renderFBOToView\n", (void*)self)); 1346 1347 #ifdef FBO 1348 1349 /* Fetch the current used read and draw buffers. */ 1350 glGetIntegerv(GL_READ_FRAMEBUFFER_EXT, &oldReadFBOId); 1351 glGetIntegerv(GL_DRAW_FRAMEBUFFER_EXT, &oldDrawFBOId); 1352 glGetIntegerv(GL_READ_BUFFER, &oldReadId); 1353 glGetIntegerv(GL_DRAW_BUFFER, &oldDrawId); 1354 1088 1355 if (!m_pSharedGLCtx) 1089 1356 { … … 1092 1359 1093 1360 /* Set the new context as non opaque */ 1094 GLint opaque = 0; 1095 [m_pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; 1096 /* Only swap on screen refresh */ 1097 // GLint swap = 1; 1098 // [m_pSharedGLCtx setValues:&swap forParameter:NSOpenGLCPSwapInterval]; 1361 [m_pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; 1099 1362 /* Set this view as the drawable for the new context */ 1100 1363 [m_pSharedGLCtx setView: self]; … … 1105 1368 { 1106 1369 NSRect r = [self frame]; 1107 DEBUG_MSG _1(("rF2V frame[%i, %i, %i, %i]\n", (int)r.origin.x, (int)r.origin.y, (int)r.size.width, (int)r.size.height));1108 1109 if (m_FBOTex Id > 0)1370 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)); 1371 1372 if (m_FBOTexFrontId > 0) 1110 1373 { 1111 1374 if ([m_pSharedGLCtx view] != self) 1112 1375 { 1113 DEBUG_MSG((" renderFBOToView: not current view of shared ctx!"));1376 DEBUG_MSG(("OVIW(%p): not current view of shared ctx! Switching ...\n", (void*)self)); 1114 1377 [m_pSharedGLCtx setView: self]; 1115 1378 [self updateViewport]; 1116 1379 } 1117 1380 1118 //DEBUG_MSG(("MakeCurrent (shared) %X\n", m_pSharedGLCtx));1119 1381 [m_pSharedGLCtx makeCurrentContext]; 1120 1121 if (m_FBOThumbTexId > 0 && 1122 [m_DockTileView thumbBitmap] != nil) 1123 { 1124 /* Only update after at least 200 ms, cause glReadPixels is 1125 * heavy performance wise. */ 1126 uint64_t uiNewTime = RTTimeMilliTS(); 1127 if (uiNewTime - m_uiDockUpdateTime > 200) 1128 { 1129 m_uiDockUpdateTime = uiNewTime; 1130 #if 0 1131 /* todo: check this for optimization */ 1132 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName); 1133 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_STORAGE_HINT_APPLE, 1134 GL_STORAGE_SHARED_APPLE); 1135 glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); 1136 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, 1137 sizex, sizey, 0, GL_BGRA, 1138 GL_UNSIGNED_INT_8_8_8_8_REV, myImagePtr); 1139 glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 1140 0, 0, 0, 0, 0, image_width, image_height); 1141 glFlush(); 1142 // Do other work processing here, using a double or triple buffer 1143 glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA, 1144 GL_UNSIGNED_INT_8_8_8_8_REV, pixels); 1145 #endif 1146 1147 GL_SAVE_STATE; 1148 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBOThumbId); 1149 1150 /* We like to read from the primary color buffer */ 1151 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); 1152 1153 NSRect rr = [m_DockTileView frame]; 1154 1155 /* Setup all matrices */ 1156 glMatrixMode(GL_PROJECTION); 1157 glLoadIdentity(); 1158 glViewport(0, 0, rr.size.width, rr.size.height); 1159 glOrtho(0, rr.size.width, 0, rr.size.height, -1, 1); 1160 glScalef(m_FBOThumbScaleX, m_FBOThumbScaleY, 1.0f); 1161 glMatrixMode(GL_TEXTURE); 1162 glLoadIdentity(); 1163 glTranslatef(0.0f, m_RootShift.y, 0.0f); 1164 glMatrixMode(GL_MODELVIEW); 1165 glLoadIdentity(); 1166 1167 /* Clear background to transparent */ 1168 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 1169 glClear(GL_COLOR_BUFFER_BIT); 1170 1171 glEnable(GL_TEXTURE_RECTANGLE_ARB); 1172 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId); 1173 GLint i; 1174 for (i = 0; i < m_cClipRects; ++i) 1175 { 1176 GLint x1 = m_paClipRects[4*i]; 1177 GLint y1 = (r.size.height - m_paClipRects[4*i+1]); 1178 GLint x2 = m_paClipRects[4*i+2]; 1179 GLint y2 = (r.size.height - m_paClipRects[4*i+3]); 1180 glBegin(GL_QUADS); 1181 { 1182 glTexCoord2i(x1, y1); glVertex2i(x1, y1); 1183 glTexCoord2i(x1, y2); glVertex2i(x1, y2); 1184 glTexCoord2i(x2, y2); glVertex2i(x2, y2); 1185 glTexCoord2i(x2, y1); glVertex2i(x2, y1); 1186 } 1187 glEnd(); 1188 } 1189 glFinish(); 1190 1191 /* Here the magic of reading the FBO content in our own buffer 1192 * happens. We have to lock this access, in the case the dock 1193 * is updated currently. */ 1194 [m_DockTileView lock]; 1195 glReadPixels(0, 0, rr.size.width, rr.size.height, 1196 GL_RGBA, 1197 GL_UNSIGNED_BYTE, 1198 [[m_DockTileView thumbBitmap] bitmapData]); 1199 [m_DockTileView unlock]; 1200 1201 NSDockTile *pDT = [[NSApplication sharedApplication] dockTile]; 1202 1203 /* Send a display message to the dock tile in the main thread */ 1204 [[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:NO]; 1205 1206 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1207 GL_RESTORE_STATE; 1208 } 1209 } 1210 1382 1383 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1384 glReadBuffer(m_FBOAttFrontId); 1385 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); 1386 glDrawBuffer(GL_BACK); 1387 1388 /* Render FBO content to the dock tile when necessary. */ 1389 [self renderFBOToDockTile]; 1390 1391 #if 1 /* Set to 0 to see the docktile instead of the real output */ 1211 1392 /* Clear background to transparent */ 1212 1393 glClear(GL_COLOR_BUFFER_BIT); 1213 1394 1214 glEnable(GL_TEXTURE_RECTANGLE_ARB);1215 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId);1216 1217 1395 /* Blit the content of the FBO to the screen. todo: check for 1218 1396 * optimization with display lists. */ 1219 GLint i;1220 1397 for (i = 0; i < m_cClipRects; ++i) 1221 1398 { … … 1224 1401 GLint x2 = m_paClipRects[4*i+2]; 1225 1402 GLint y2 = r.size.height - m_paClipRects[4*i+3]; 1226 glBegin(GL_QUADS); 1227 { 1228 glTexCoord2i(x1, y1); glVertex2i(x1, y1); 1229 glTexCoord2i(x1, y2); glVertex2i(x1, y2); 1230 glTexCoord2i(x2, y2); glVertex2i(x2, y2); 1231 glTexCoord2i(x2, y1); glVertex2i(x2, y1); 1232 } 1233 glEnd(); 1403 glBlitFramebufferEXT(x1, y1 + m_RootShift.y, x2, y2 + m_RootShift.y, 1404 x1 - m_RootShift.x, y1, x2 - m_RootShift.x, y2, 1405 GL_COLOR_BUFFER_BIT, GL_NEAREST); 1406 } 1407 #endif 1408 // glFinish(); 1409 [m_pSharedGLCtx flushBuffer]; 1410 1411 [m_pGLCtx makeCurrentContext]; 1412 /* Reset to previous buffer bindings. */ 1413 if ( (GLuint)oldReadId == m_FBOAttBackId 1414 || (GLuint)oldReadId == m_FBOAttFrontId) 1415 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1416 glReadBuffer(oldReadId); 1417 if ( (GLuint)oldDrawId == m_FBOAttBackId 1418 || (GLuint)oldDrawId == m_FBOAttFrontId) 1419 // glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, oldDrawFBOId); 1420 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_FBOId); 1421 glDrawBuffer(oldDrawId); 1422 } 1423 } 1424 #endif 1425 } 1426 1427 - (void)renderFBOToDockTile 1428 { 1429 NSRect r = [self frame]; 1430 NSRect rr = NSZeroRect; 1431 GLint i = 0; 1432 NSDockTile *pDT = nil; 1433 1434 #ifdef FBO 1435 if ( m_FBOThumbId 1436 && m_FBOThumbTexId 1437 && [m_DockTileView thumbBitmap] != nil) 1438 { 1439 /* Only update after at least 200 ms, cause glReadPixels is 1440 * heavy performance wise. */ 1441 uint64_t uiNewTime = RTTimeMilliTS(); 1442 if (uiNewTime - m_uiDockUpdateTime > 200) 1443 { 1444 m_uiDockUpdateTime = uiNewTime; 1445 #if 0 1446 /* todo: check this for optimization */ 1447 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName); 1448 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_STORAGE_HINT_APPLE, 1449 GL_STORAGE_SHARED_APPLE); 1450 glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); 1451 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, 1452 sizex, sizey, 0, GL_BGRA, 1453 GL_UNSIGNED_INT_8_8_8_8_REV, myImagePtr); 1454 glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 1455 0, 0, 0, 0, 0, image_width, image_height); 1456 glFlush(); 1457 /* Do other work processing here, using a double or triple buffer */ 1458 glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA, 1459 GL_UNSIGNED_INT_8_8_8_8_REV, pixels); 1460 #endif 1461 /* Clear background to transparent */ 1462 glClear(GL_COLOR_BUFFER_BIT); 1463 1464 rr = [m_DockTileView frame]; 1465 1466 for (i = 0; i < m_cClipRects; ++i) 1467 { 1468 GLint x1 = m_paClipRects[4*i]; 1469 GLint y1 = r.size.height - m_paClipRects[4*i+1]; 1470 GLint x2 = m_paClipRects[4*i+2]; 1471 GLint y2 = r.size.height - m_paClipRects[4*i+3]; 1472 1473 glBlitFramebufferEXT(x1, y1 + m_RootShift.y, x2, y2 + m_RootShift.y, 1474 x1 * m_FBOThumbScaleX, y1 * m_FBOThumbScaleY, x2 * m_FBOThumbScaleX, y2 * m_FBOThumbScaleY, 1475 GL_COLOR_BUFFER_BIT, GL_NEAREST); 1234 1476 } 1235 1477 glFinish(); 1236 [m_pSharedGLCtx flushBuffer]; 1237 //DEBUG_MSG(("MakeCurrent %X\n", m_pGLCtx)); 1238 [m_pGLCtx makeCurrentContext]; 1239 } 1240 } 1478 1479 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); 1480 glReadBuffer(GL_BACK); 1481 /* Here the magic of reading the FBO content in our own buffer 1482 * happens. We have to lock this access, in the case the dock 1483 * is updated currently. */ 1484 [m_DockTileView lock]; 1485 glReadPixels(0, 0, rr.size.width, rr.size.height, 1486 GL_BGRA, 1487 GL_UNSIGNED_INT_8_8_8_8, 1488 [[m_DockTileView thumbBitmap] bitmapData]); 1489 [m_DockTileView unlock]; 1490 1491 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_FBOId); 1492 glReadBuffer(m_FBOAttFrontId); 1493 1494 pDT = [[NSApplication sharedApplication] dockTile]; 1495 1496 /* Send a display message to the dock tile in the main thread */ 1497 [[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:NO]; 1498 1499 } 1500 } 1501 #endif 1241 1502 } 1242 1503 … … 1253 1514 - (void)setVisibleRegions:(GLint)cRects paRects:(GLint*)paRects 1254 1515 { 1255 DEBUG_MSG_1((" New region received\n"));1516 DEBUG_MSG_1(("OVIW(%p): setVisibleRegions: cRects=%d\n", (void*)self, cRects)); 1256 1517 1257 1518 [self clearVisibleRegions]; 1258 1519 1259 if (cRects >0)1520 if (cRects > 0) 1260 1521 { 1261 1522 m_paClipRects = (GLint*)RTMemAlloc(sizeof(GLint) * 4 * cRects); … … 1281 1542 - (void)reshapeDockTile 1282 1543 { 1544 NSRect newFrame = NSZeroRect; 1545 1283 1546 NSView *pView = [self dockTileScreen]; 1284 1547 if (pView != nil) … … 1289 1552 m_FBOThumbScaleX = (float)dockFrame.size.width / parentFrame.size.width; 1290 1553 m_FBOThumbScaleY = (float)dockFrame.size.height / parentFrame.size.height; 1291 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)); 1292 // 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)); 1293 // 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)); 1294 // 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); 1554 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)); 1555 /* 1556 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)); 1557 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)); 1558 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); 1559 */ 1295 1560 [m_DockTileView setFrame: newFrame]; 1296 1561 } … … 1306 1571 void cocoaGLCtxCreate(NativeNSOpenGLContextRef *ppCtx, GLbitfield fVisParams) 1307 1572 { 1573 NSOpenGLPixelFormat *pFmt = nil; 1574 1308 1575 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1309 1576 1310 NSOpenGLPixelFormatAttribute attribs[24] = 1577 NSOpenGLPixelFormatAttribute attribs[24] = 1311 1578 { 1312 1579 NSOpenGLPFAWindow, … … 1314 1581 NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24 1315 1582 }; 1316 1583 1317 1584 int i = 4; 1585 1318 1586 if (fVisParams & CR_ALPHA_BIT) 1319 1587 { … … 1327 1595 attribs[i++] = NSOpenGLPFADepthSize; 1328 1596 attribs[i++] = 24; 1597 // attribs[i++] = 32; 1329 1598 } 1330 1599 if (fVisParams & CR_STENCIL_BIT) … … 1334 1603 attribs[i++] = 8; 1335 1604 } 1336 if (fVisParams & CR_ACCUM_BIT) 1605 if (fVisParams & CR_ACCUM_BIT) 1337 1606 { 1338 1607 DEBUG_MSG(("CR_ACCUM_BIT requested\n")); … … 1343 1612 attribs[i++] = 24; 1344 1613 } 1345 if (fVisParams & CR_MULTISAMPLE_BIT) 1614 if (fVisParams & CR_MULTISAMPLE_BIT) 1346 1615 { 1347 1616 DEBUG_MSG(("CR_MULTISAMPLE_BIT requested\n")); … … 1358 1627 if (fVisParams & CR_STEREO_BIT) 1359 1628 { 1360 DEBUG_MSG(("CR_DOUBLE_BIT requested\n")); 1629 /* We don't support that. 1630 DEBUG_MSG(("CR_STEREO_BIT requested\n")); 1361 1631 attribs[i++] = NSOpenGLPFAStereo; 1362 } 1363 1632 */ 1633 } 1634 1364 1635 /* Mark the end */ 1365 1636 attribs[i++] = 0; 1366 1637 1367 1638 /* Choose a pixel format */ 1368 NSOpenGLPixelFormat*pFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];1369 1639 pFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; 1640 1370 1641 if (pFmt) 1371 1642 { … … 1373 1644 1374 1645 /* Enable multi threaded OpenGL engine */ 1375 // CGLContextObj cglCtx = [*ppCtx CGLContextObj]; 1376 // CGLError err = CGLEnable(cglCtx, kCGLCEMPEngine); 1377 // if (err != kCGLNoError) 1378 // printf ("Couldn't enable MT OpenGL engine!\n"); 1379 1646 /* 1647 CGLContextObj cglCtx = [*ppCtx CGLContextObj]; 1648 CGLError err = CGLEnable(cglCtx, kCGLCEMPEngine); 1649 if (err != kCGLNoError) 1650 printf ("Couldn't enable MT OpenGL engine!\n"); 1651 */ 1652 1380 1653 DEBUG_MSG(("New context %X\n", (uint)*ppCtx)); 1381 1654 } … … 1446 1719 void cocoaViewDestroy(NativeNSViewRef pView) 1447 1720 { 1721 NSWindow *pWin = nil; 1722 1448 1723 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1449 1724 … … 1451 1726 [pView setHidden: YES]; 1452 1727 1453 NSWindow *win = [pView window]; 1454 [[NSNotificationCenter defaultCenter] removeObserver:win]; 1455 [win setContentView: nil]; 1456 [[win parentWindow] removeChildWindow: win]; 1457 int b = [win retainCount]; 1458 // for (; b > 1; --b) 1459 // [win performSelector:@selector(release)] 1460 [win performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:YES]; 1461 // [win release]; 1728 pWin = [pView window]; 1729 [[NSNotificationCenter defaultCenter] removeObserver:pWin]; 1730 [pWin setContentView: nil]; 1731 [[pWin parentWindow] removeChildWindow: pWin]; 1732 /* 1733 a = [pWin retainCount]; 1734 for (; a > 1; --a) 1735 [pWin performSelector:@selector(release)] 1736 */ 1737 [pWin performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:YES]; 1738 /* 1739 [pWin release]; 1740 */ 1462 1741 1463 1742 /* There seems to be a bug in the performSelector method which is called in … … 1465 1744 * results in an unbalanced reference count, which is here manually 1466 1745 * decremented. */ 1467 int a = [pView retainCount]; 1468 // for (; a > 1; --a) 1746 /* 1747 a = [pView retainCount]; 1748 for (; a > 1; --a) 1749 */ 1469 1750 [pView performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:YES]; 1470 // [pView release]; 1751 /* 1752 [pView release]; 1753 */ 1471 1754 1472 1755 [pPool release]; … … 1483 1766 1484 1767 void cocoaViewDisplay(NativeNSViewRef pView) 1485 { 1768 { 1486 1769 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1487 1770 1488 DEBUG_MSG_1(("cocoaViewDisplay %p\n", pView));1771 DEBUG_MSG_1(("cocoaViewDisplay %p\n", (void*)pView)); 1489 1772 [(OverlayView*)pView swapFBO]; 1490 1773 … … 1529 1812 1530 1813 DEBUG_MSG(("cocoaViewMakeCurrentContext(%p, %p)\n", (void*)pView, (void*)pCtx)); 1531 1814 1532 1815 [(OverlayView*)pView setGLCtx:pCtx]; 1533 1816 [(OverlayView*)pView makeCurrentFBO]; … … 1550 1833 * 1551 1834 ********************************************************************************/ 1552 void cocoaFlush(void) 1553 { 1554 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1555 1556 // glFlush(); 1557 // return; 1558 1559 DEBUG_MSG_1(("glFlush called\n")); 1560 1561 #ifdef FBO 1835 static void performSelectorOnView(SEL selector) 1836 { 1562 1837 NSOpenGLContext *pCtx = [NSOpenGLContext currentContext]; 1838 1563 1839 if (pCtx) 1564 1840 { … … 1566 1842 if (pView) 1567 1843 { 1568 if ([pView respondsToSelector:@selector(flushFBO)]) 1569 [pView performSelector:@selector(flushFBO)]; 1570 } 1571 } 1572 #else 1573 glFlush(); 1574 #endif 1575 1576 [pPool release]; 1577 } 1578 1579 void cocoaFinish(void) 1580 { 1581 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1582 1583 DEBUG_MSG_1(("glFinish called\n")); 1584 1585 #ifdef FBO 1844 if ([pView respondsToSelector:selector]) 1845 [pView performSelector:selector]; 1846 } 1847 } 1848 } 1849 1850 static void performSelectorOnViewOneArg(SEL selector, id arg1) 1851 { 1586 1852 NSOpenGLContext *pCtx = [NSOpenGLContext currentContext]; 1853 1587 1854 if (pCtx) 1588 1855 { … … 1590 1857 if (pView) 1591 1858 { 1592 if ([pView respondsToSelector:@selector(finishFBO)]) 1593 [pView performSelector:@selector(finishFBO)]; 1594 } 1595 } 1859 if ([pView respondsToSelector:selector]) 1860 [pView performSelector:selector withObject:arg1]; 1861 } 1862 } 1863 } 1864 1865 static void performSelectorOnViewTwoArgs(SEL selector, id arg1, id arg2) 1866 { 1867 NSOpenGLContext *pCtx = [NSOpenGLContext currentContext]; 1868 1869 if (pCtx) 1870 { 1871 NSView *pView = [pCtx view]; 1872 if (pView) 1873 { 1874 if ([pView respondsToSelector:selector]) 1875 [pView performSelector:selector withObject:arg1 withObject:arg2]; 1876 } 1877 } 1878 } 1879 1880 void cocoaFlush(void) 1881 { 1882 NSOpenGLContext *pCtx = nil; 1883 1884 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1885 1886 DEBUG_MSG_1(("glFlush called\n")); 1887 1888 performSelectorOnView(@selector(flushFBO)); 1889 1890 [pPool release]; 1891 } 1892 1893 void cocoaFinish(void) 1894 { 1895 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1896 1897 DEBUG_MSG_1(("glFinish called\n")); 1898 1899 performSelectorOnView(@selector(finishFBO)); 1900 1901 [pPool release]; 1902 } 1903 1904 void cocoaBindFramebufferEXT(GLenum target, GLuint framebuffer) 1905 { 1906 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1907 1908 DEBUG_MSG_1(("glBindFramebufferEXT called target: %d fb: %d\n", target, framebuffer)); 1909 1910 performSelectorOnViewTwoArgs(@selector(bindFBO:withFrameBuffer:), (id)target, (id)framebuffer); 1911 1912 [pPool release]; 1913 } 1914 1915 void cocoaCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) 1916 { 1917 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1918 1919 DEBUG_MSG_1(("glCopyPixels called: %d,%d-%dx%d type: %d\n", x, y, width, height, type)); 1920 1921 #ifdef FBO 1922 GLbitfield mask = GL_COLOR_BUFFER_BIT; 1923 if (type == GL_DEPTH) 1924 mask = GL_DEPTH_BUFFER_BIT; 1925 else if (type == GL_STENCIL) 1926 mask = GL_STENCIL_BUFFER_BIT; 1927 glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, mask, GL_NEAREST); 1596 1928 #else 1597 gl Finish();1929 glCopyPixels(x, y, width, height, type); 1598 1930 #endif 1599 1931 … … 1601 1933 } 1602 1934 1603 void cocoa BindFramebufferEXT(GLenum target, GLuint framebuffer)1935 void cocoaGetIntegerv(GLenum pname, GLint *params) 1604 1936 { 1605 1937 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1606 1938 1607 DEBUG_MSG(("glRenderspuBindFramebufferEXT called %d\n", framebuffer)); 1608 1609 #ifdef FBO 1610 if (framebuffer != 0) 1611 glBindFramebufferEXT(target, framebuffer); 1612 else 1613 { 1614 NSOpenGLContext *pCtx = [NSOpenGLContext currentContext]; 1615 if (pCtx) 1616 { 1617 NSView *pView = [pCtx view]; 1618 if (pView) 1619 { 1620 if ([pView respondsToSelector:@selector(bindFBO)]) 1621 [pView performSelector:@selector(bindFBO)]; 1622 } 1623 } 1624 } 1625 #else 1626 glBindFramebufferEXT(target, framebuffer); 1627 #endif 1939 DEBUG_MSG_1(("getIntergerv called: %d\n", pname)); 1940 1941 performSelectorOnViewTwoArgs(@selector(stateInfo:withParams:), (id)pname, (id)params); 1628 1942 1629 1943 [pPool release]; 1630 1944 } 1631 1945 1946 void cocoaReadBuffer(GLenum mode) 1947 { 1948 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1949 1950 DEBUG_MSG_1(("glReadBuffer called: %d\n", mode)); 1951 1952 performSelectorOnViewOneArg(@selector(readBuffer:), (id)mode); 1953 1954 [pPool release]; 1955 } 1956 1957 void cocoaDrawBuffer(GLenum mode) 1958 { 1959 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; 1960 1961 DEBUG_MSG_1(("glDrawBuffer called: %d\n", mode)); 1962 1963 performSelectorOnViewOneArg(@selector(drawBuffer:), (id)mode); 1964 1965 [pPool release]; 1966 } 1967
Note:
See TracChangeset
for help on using the changeset viewer.