Optimizing CGLFlushDrawable
I've been working on a simple 2D lighting/shadowing system in OpenGL and realized that I'm only getting 30fps. I have a Radeon 9700 which I figure is the problem, but just in case I ran the OpenGL Profiler and found that 98% of OpenGL's time and 78% of my apps time is spent on CGLFlushDrawable. What's the process for optimizing this? I only call SDL_GL_SwapBuffers() once per frame so that's not it. Would anything else be a problem? I do call glCopyTexImage2D once a frame if that hurts it. It looks like the glCopyTexImage2D takes about 75 usec whatever that adds up to. It looks like more than everything else so should I just not use that for my effect? Thanks.
Btw, here's the txt export of the profiler (not pretty, but it might help)
Btw, here's the txt export of the profiler (not pretty, but it might help)
Code:
GL Function;# of Calls;Total Time (µsec);Avg Time (µsec);% GL Time;% App Time
CGLFlushDrawable;962;27513873;28600.70;98.20;78.20
CGLGetVirtualScreen;1;0;0.00;0.00;0.00
CGLSetParameter;4;0;0.00;0.00;0.00
CGLSetSurface;1;0;0.00;0.00;0.00
glBegin;17,317;174498;10.08;0.62;0.50
glBindTexture;3,851;6198;1.61;0.02;0.02
glBlendFunc;1;1;1.03;0.00;0.00
glClear;3,850;134988;35.06;0.48;0.38
glClearColor;1,926;1463;0.76;0.01;0.00
glClearStencil;1;7;7.43;0.00;0.00
glColor4f;8,659;2914;0.34;0.01;0.01
glColorMask;3,849;1115;0.29;0.00;0.00
glCopyTexImage2D;962;69117;71.85;0.25;0.20
glDepthMask;3,849;744;0.19;0.00;0.00
glDisable;4,811;4189;0.87;0.01;0.01
glEnable;3,853;6777;1.76;0.02;0.02
glEnd;17,316;15103;0.87;0.05;0.04
glGenTextures;3;10;3.40;0.00;0.00
glGetFloatv;2;13;6.70;0.00;0.00
glGetIntegerv;26;10;0.42;0.00;0.00
glGetTexLevelParameteriv;2;318;159.07;0.00;0.00
glLoadIdentity;964;2621;2.72;0.01;0.01
glMatrixMode;2;1;0.81;0.00;0.00
glOrtho;1;2;2.55;0.00;0.00
glPixelStorei;18;7;0.44;0.00;0.00
glPointSize;962;2082;2.16;0.01;0.01
glPopMatrix;2,886;1377;0.48;0.00;0.00
glPushMatrix;2,886;4997;1.73;0.02;0.01
glScissor;1;361;361.23;0.00;0.00
glStencilFunc;3,849;1317;0.34;0.00;0.00
glStencilOp;3,849;1211;0.31;0.00;0.00
glTexCoord2f;11,544;696;0.06;0.00;0.00
glTexImage2D;24;51121;2130.07;0.18;0.15
glTexParameterf;2;1570;785.31;0.01;0.00
glTexParameteri;10;42;4.30;0.00;0.00
glTranslatef;2,886;1726;0.60;0.01;0.00
glVertex2f;28,860;7473;0.26;0.03;0.02
glVertex3f;61,587;9777;0.16;0.03;0.03
glViewport;2;14;7.19;0.00;0.00
Spending CPU time in CGLFlushDrawable usually means that you're not doing any real CPU work in your program... the 30fps sounds an awful lot like you're vsync'd on an LCD, and not quite making 60fps.
Don't use gl*TexImage* more often than you have to (in this case, probably once at program startup). They're slow. Use gl*TexSubImage* instead, which are much faster.
Of course, for the particular case of glCopyTex[Sub]Image2D, you should probably be looking into using an FBO instead.
Don't use gl*TexImage* more often than you have to (in this case, probably once at program startup). They're slow. Use gl*TexSubImage* instead, which are much faster.
Of course, for the particular case of glCopyTex[Sub]Image2D, you should probably be looking into using an FBO instead.
I do need to call the glCopyTexImage any time a light moves to regenerate the lightmap texture. I used some if statements and it helps. If a light moves around a lot, I lose frames, but when I turned off vsync I got up to 80-90 fps.
I'll look into the glCopyTexSubImage2D as well as FBOs.
I'll look into the glCopyTexSubImage2D as well as FBOs.
No, you don't need to call CopyTexImage unless the size or internal format of the texture changes. CopyTexSubImage is capable of changing all the pixels in the texture.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Optimizing rendering. | jorgemonti | 15 | 5,416 |
Apr 6, 2005 04:05 AM Last Post: jorgemonti |
|
| Optimizing for OpenGL on OS X | aaronsullivan | 3 | 3,102 |
Mar 22, 2005 02:36 PM Last Post: Puzzler183 |
|
| Optimizing Terrain Drawing? | Blake | 10 | 3,905 |
Jan 25, 2004 03:44 PM Last Post: Blake |
|
| optimizing dynamic geometry | arekkusu | 15 | 6,742 |
Nov 27, 2003 12:29 PM Last Post: OneSadCookie |
|
| optimizing OpenGL | ghettotek | 20 | 7,606 |
Feb 25, 2003 05:47 PM Last Post: henryj |
|

