Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Covered OpenGL surface causes system sluggishness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Covered OpenGL surface causes system sluggishness



Hi,

I've been trying to track down the source of a rather strange problem in my OpenGL application. I have a window, containing an OpenGL surface, and I cover that window entirely with other windows, the system becomes rather "sluggish" (window dragging is glitchy, etc). At first I thought it was my application, but I've noticed the exact same symptoms in certain GL based games (StepMania, Quake 3 Arena) but not in others (UT2004 Demo, Halo Demo).

If I open GL Driver Monitor and watch the graph, "CPU Wait for Free OpenGL Command Buffer" spikes immediately to its maximum value, while "CPU Wait for OpenGL Swap to Complete" becomes very erratic, jumping constantly between its maximum and minimum values. I'm not sure what this means, and also if it means anything at all, but the graph is relatively smooth until I cover the surface and then there are massive spikes while the surface is covered. CPU Usage, via Activity Monitor _falls_ slightly during the period when the window is covered.

An image of the GL Driver Monitor showing the spikes is here: http:// adam.beariscoding.com/drvmon.png
Where the graph is smooth, the window and its surface are exposed, the spikes are where the surface is covered.


I first noticed this issue while trying to use thread_policy_set() to make my rendering thread have a time constraint policy. It would work fine until I covered the surface, which would immediately cause the entire window server to "freeze" (the mouse would still move, and iTunes was still playing in the background, so it wasn't a crash). Getting rid of the call to thread_policy_set() prevented the system from "freezing" but I then noticed the glitchy window dragging, etc. Thinking it was probably something to do with the threading, I moved my rendering loop into main() — nothing changed.

My setup code:
================
Rect r; SetRect( &r, 100, 100, 740, 580 );
CreateNewWindow( kDocumentWindowClass, kWindowStandardDocumentAttributes, &r, &this->testWindow );

ShowWindow( this->testWindow );

AGLPixelFormat pf;
GLint attrs[] = {
AGL_RGBA,
AGL_ACCELERATED,
AGL_DOUBLEBUFFER,
AGL_PIXEL_SIZE,
32,
AGL_DEPTH_SIZE,
32,
AGL_NONE,
};

pf = aglChoosePixelFormat( nil, nil, attrs );
this->testContext = aglCreateContext( pf, nil );
aglDestroyPixelFormat( pf );

aglSetDrawable( this->testContext, GetWindowPort(this->testWindow) );

data = (GLfloat*)malloc( sizeof(GLfloat) * 9 * 1000 );
for (int i=0; i<1000; i+=9) {
data[i] = 0.5f;
data[i+1] = 0.5f;
data[i+2] = 0.0f;

data[i+3] = 0.0f;
data[i+4] = -0.5f;
data[i+5] = 0.0f;

data[i+6] = -0.5f;
data[i+7] = 0.5f;
data[i+8] = 0.0f;
}
================



My rendering code:
================
double currentTime, updateIterations;

#ifdef __CARBON__
currentTime = GetCurrentEventTime(); //AudioConvertHostTimeToNanos ( AudioGetCurrentHostTime() ) / kNanosecondsPerSecond;
#elif _WIN32
#endif

updateIterations = (currentTime - this->lastFrameTime) + this- >cyclesLeftOver;

if (updateIterations > (kMaxCyclesPerFrame * kUpdateInterval)) {
updateIterations = (kMaxCyclesPerFrame * kUpdateInterval);
}

aglSetCurrentContext( this->testContext );

while (updateIterations > kUpdateInterval) {
updateIterations -= kUpdateInterval;
glRotatef( 5*kUpdateInterval, 0, 0, 1 );
}

glClear( GL_COLOR_BUFFER_BIT );

glColor3f( 1, 0, 0 );

glVertexPointer( 3, GL_FLOAT, 0, data );
glEnableClientState( GL_VERTEX_ARRAY );
glDrawArrays( GL_TRIANGLES, 0, 1000 );


	aglSwapBuffers( this->testContext );

	this->cyclesLeftOver = updateIterations;
	this->lastFrameTime = currentTime;
================

As you can see, fairly simple. The rendering function is called as fast as it can.

This is on 10.4.3 on an iBook G4 with a Mobility Radeon 9200. Testing this on my iBook G3 (Mobility Radeon 7500) running 10.3.9 the effects are worse: While the application is running, any window movement is glitchy as hell.

Please tell me I'm doing something wrong,
Adam Zegelin

-----
Adam Zegelin
BearIsCoding
http://www.beariscoding.com


_______________________________________________ Do not post admin requests to the list. They will be ignored. Mac-opengl mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.