siqiaochen's picture

SwapBuffers took long time (>16ms) to draw?

Hello, 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.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);

And My Render Function (In another thread):

    private void glRefreshControl()
            //throw new NotImplementedException();
            Stopwatch watch = new Stopwatch();
            long lag = 0;
            while (!close)
                if (setView)
                if (loadingVariables)
                Render();  // code to do the drawings
                setView = false;
                if (close)  // break the loop if the form is closed
                // it could take 18 - 32 milliseconds to swap the buffer
                // if I open or close a window, it could take 100-300 milliseconds
                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!


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Stupid_2D's picture

You aint missing GL.End() do ya?

siqiaochen's picture

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!