
SwapBuffers took long time (>16ms) to draw?
Posted Wednesday, 17 August, 2011 - 19:36 by siqiaochen inHello, All! I recently started to convert my GUI code into a GLControl. I placed an GLControl into my UserControl. Thing seems to be fine at the beginning. Then I found out that text scrolling part flickers occasionally.
My Scrolling Function is actually displaying a gui+ rendered text bitmap:
if (variableSprite[i].Modified) UpdateTexture(variableSprite[i], variableSprite[i].BMP); GL.BindTexture(TextureTarget.Texture2D, variableSprite[i].ID); GL.Begin(BeginMode.Quads); GL.TexCoord2(XOffset, YOffset); GL.Vertex2(QuickVariableList[i].DisplayRect.Left, QuickVariableList[i].DisplayRect.Top); GL.TexCoord2(w + XOffset, YOffset); GL.Vertex2(QuickVariableList[i].DisplayRect.Right, QuickVariableList[i].DisplayRect.Top); GL.TexCoord2(w + XOffset, h + YOffset); GL.Vertex2(QuickVariableList[i].DisplayRect.Right, QuickVariableList[i].DisplayRect.Bottom); GL.TexCoord2(XOffset, h + YOffset); GL.Vertex2(QuickVariableList[i].DisplayRect.Left, QuickVariableList[i].DisplayRect.Bottom); signLayout.QuickVariableList[i].nextFrame(); GL.End();
And My Render Function (In another thread):
private void glRefreshControl() { //throw new NotImplementedException(); Thread.Sleep(100); glControlBaseball.MakeCurrent(); Stopwatch watch = new Stopwatch(); long lag = 0; while (!close) { if (setView) SetupViewport(); if (loadingVariables) { LoadVariables(); } Render(); // code to do the drawings setView = false; if (close) // break the loop if the form is closed return; watch.Reset(); watch.Start(); // it could take 18 - 32 milliseconds to swap the buffer // if I open or close a window, it could take 100-300 milliseconds GraphicsContext.CurrentContext.SwapBuffers(); watch.Stop(); lag = watch.ElapsedMilliseconds; if (lag > 16) { System.Console.WriteLine("Lag: " + lag + "ms."); lag = 0; } } }
I also found out that my actions in other applications, like resizing, mouse moving and dragging, could cause the glcontrol to flicker. After a few tests I found out that the SwapBuffers() is the source of the problem. But I believe SwapBuffers should be very fast. Could I know what might cause this issue?
Thank you very much!


Comments
Re: SwapBuffers took long time (>16ms) to draw?
You aint missing GL.End() do ya?
Re: SwapBuffers took long time (>16ms) to draw?
hi, thank you for point this out. Yeah, I forgot to post the GL.End() ... I will add it back to the code. Sorry for this dumb mistake.
But in my original code, I have GL.End(). And the thing I drawn on screen was just a 200*50 rectangle with a 1000*100 32bit texture. I don't think it could be that slow... Have you ever noticed any performance change in GLControl when you played with background applications?
Thank you for your help!