|
|
#1 |
|
OpenGL flickering on window resizing
This is really bothering me. I have an OpenGL window subclassed from NSOpenGLView and rendering via the display link. If I resize the window via the zoom button, the view flickers like crazy until the resize is complete (typically a white window when I'm filling the screen with black). All other reshapes seem to work as expected except for the zoom button. (FYI, It is double buffered).
If I force a redraw of the frame in the reshape, everything appears smooth, but that kills the performance of trying to resize the window. I also tried Apple's GLEssentials from the help docs, and saw this problem in there too. *EDIT* OK, resizing the window normally also has flickers too. Last edited by BehindTimes; Feb 5, 2013 at 01:32 AM. |
|
|
|
0
|
|
|
#2 | |
|
Quote:
I hope someone with more knowledge can answer you but this may be what you want to look in to. EDIT: Oops I noticed you said this happens when resizing. My suggestion may not be of much help.
__________________
Macbook Air 13inch Ultimate
Hexcore MacPro 3.33ghz - 24 gigs ram - ATI 5870 - Dual 27inch ACD's |
||
|
|
0
|
|
|
#3 | |
|
Quote:
https://www.youtube.com/watch?v=IK06sbIAGIQ 2 mins displaying the issue, and the last 30 seconds using Apple's own example which demonstrates the same issue. |
||
|
|
0
|
|
|
#4 |
|
I'm having the same issue with a double-buffered context. Weird.
|
|
|
|
0
|
|
|
#5 |
|
Are you drawing on the main thread? The sample code GLEssentials shows how to do things the *right* way and it was resizing smoothly for me.
No one can see what you are actually doing without you posting some code you are running and seeing the flickering.
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me |
|
|
|
0
|
|
|
#6 | |
|
Quote:
But, here's some simple code which is failing (minus functions which have nothing to do with the rendering): Code:
- (NSOpenGLPixelFormat *) createPixelFormat
{
NSOpenGLPixelFormatAttribute attr[] =
{
//NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFADepthSize, 16,
0
};
return [(NSOpenGLPixelFormat *)[NSOpenGLPixelFormat alloc]
initWithAttributes:attr];
}
- (id)initWithFrame:(NSRect)frame
{
NSOpenGLPixelFormat *pixelFormat;
pixelFormat = [self createPixelFormat];
self = [super initWithFrame:frame pixelFormat:pixelFormat];
if (self)
{
m_bRedraw = false;
}
return self;
}
- (BOOL) isOpaque
{
return YES;
}
- (BOOL) isFlipped
{
return YES;
}
CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
{
CVReturn result = [(__bridge OpenGLHelper*)displayLinkContext getFrameForTime:outputTime];
return result;
}
- (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime
{
@autoreleasepool
{
if ([self lockFocusIfCanDraw])
{
NSRect curFrame = [self frame];
[self drawFrame: curFrame];
[self unlockFocus];
}
}
return kCVReturnSuccess;
}
- (void) prepareOpenGL
{
[super prepareOpenGL];
// Synchronize buffer swaps with vertical refresh rate
GLint swapInt = 1;
[[self openGLContext] makeCurrentContext];
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
CGLLockContext([[self openGLContext] CGLContextObj]);
glEnable( GL_TEXTURE_2D );
glShadeModel( GL_SMOOTH );
glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
CGLUnlockContext([[self openGLContext] CGLContextObj]);
// Create a display link capable of being used with all active displays
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
// Set the renderer output callback function
CVDisplayLinkSetOutputCallback(displayLink, &MyDisplayLinkCallback, (__bridge void *)(self));
// Set the display link for the current renderer
CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat);
// Activate the display link
CVDisplayLinkStart(displayLink);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:NSApplicationWillTerminateNotification
object:nil];
}
- (void) SetResizeRedraw: (bool) redraw
{
m_bRedraw = redraw;
}
- (void) reshape
{
NSRect rect;
//[super reshape];
CGLLockContext([[self openGLContext] CGLContextObj]);
[[self openGLContext] makeCurrentContext];
[[self openGLContext] update];
rect = [self bounds];
glViewport(0, 0, rect.size.width, rect.size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, rect.size.width, rect.size.height, 0, 0, 100.0f);
CGLUnlockContext([[self openGLContext] CGLContextObj]);
//if (!CVDisplayLinkIsRunning(displayLink))
// Will work if this is uncommented, but kills performance
/*if(m_bRedraw)
{
[self drawFrame:[self frame]];
}*/
}
- (void)drawRect:(NSRect)dirtyRect
{
if (!CVDisplayLinkIsRunning(displayLink))
{
[self drawFrame:dirtyRect];
}
}
- (void) drawFrame:(NSRect)dirtyRect
{
CGLLockContext([[self openGLContext] CGLContextObj]);
[[self openGLContext] makeCurrentContext];
glClearColor(0, 0, 0, 255);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
CGLUnlockContext([[self openGLContext] CGLContextObj]);
}
|
||
|
|
0
|
|
|
#7 |
|
From the back of my head since it's been a while I used OpenGL, but in your code I see you explicitly call the frame-update yourself; the proper way however is to let the OpenGL-threading mechanism handle that, i.e. whenever you want the frame updated, put in code '[self setNeedsDisplay:YES];' (self being the instance of the class derived from a View-superclass).
This will indicate to graphics-thread scheduler that your display needs updating (duh!) and whenever the time is ready, it will do so, without flickering. The ADC-docs I'm sure, contain a more precise and clear formulation of this
|
|
|
|
0
|
|
|
#8 | |
|
Quote:
|
||
|
|
0
|
|
|
#9 |
|
Hi,
I tried following code in my reshape function : Code:
-(void)reshape
{
NSOpenGLContext *context = [self openGLContext];
[context makeCurrentContext];
// must lock GL context because display link is threaded
CGLLockContext([context CGLContextObj]);
//glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
[context flushBuffer];
CGLUnlockContext([context CGLContextObj]);
}
You must be calling another subroutine in your drawFrame method for your animation (assuming this because I did not found any subroutine for animation in the code) which you have not specified in the forum and the overhead must be because of that subroutine when you are calling drawFrame from within reshape method. Last edited by 840quadra; Feb 8, 2013 at 11:38 AM. Reason: Please use [Code] tags when sharing code in posts |
|
|
|
0
|
|
|
#10 | |
|
Quote:
|
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 02:03 AM.







Linear Mode
