Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Efficient drawing OpenGL vs. CoreImage



Correct me if I am wrong but I am not sure a GeForce 5200 is hardware accelerated at all. From what I have read those a slower than the CPU when it comes to the pixel shader and use of the GPU on this configuration is disabled by default. Or is it some other variant of the 5200?

I have faced this dillema when writing my app. One of the filters (zooming, offseting and pixellating) has to be done in real time (on each draw). If run on an accelerated machine (like radeon 9600 or better) then it's very fast since everything happens in the GPU, but if I use my iBook then drawing openGL textures is much much faster (since you only set antialiasing to GL_NEAREST and you have your pixellation).

It all depends on the machine on which you're gonna run it in the end. If it's a mac book pro or an imac core duo then Core Image will be very fast.

If your mouse is notreactive this is probably all the rendering happens in the CPU. Look at the CPU usage when you run your app. If it all happened in the GPU then your mouse would be fine.

In my case I decided to go for both options: users with a non supported GPU will use OpenGL , others will use 100% Core Image.

Le 20 mai 06 à 20:27, Federico Tessmann a écrit :

Hi,

I am trying to draw an animation of two seperate dj turntables that
react to mouse events. The drawing should be as performant as
possible.
I also have to constantly update two textfields and 4 meetering views.
I tested two solutions, one with openGL and one with CoreImage.

OpenGL approach:

On initialization time we load 7 textures the following way:

image= [ NSImage imageNamed: @"Turntable_271x220.tif" ];
bitmap = [[NSBitmapImageRep alloc]initWithData: [image TIFFRepresentation]];

data = [bitmap bitmapData];
for (i = 0; i < TEXTURE_SIZE; i++) {
for (j = 0; j < TEXTURE_SIZE; j++) {
if(j<djTableSize.width && i < djTableSize.height){
djImage[i][j][0] = (GLubyte)data[[bitmap bytesPerRow]*i+j*[bitmap
samplesPerPixel]];
djImage[i][j][1] = (GLubyte)data[[bitmap bytesPerRow]*i+j*[bitmap
samplesPerPixel]+1];
djImage[i][j][2] = (GLubyte)data[[bitmap bytesPerRow]*i+j*[bitmap
samplesPerPixel]+2];
djImage[i][j][3] = (GLubyte)255;
}else{
djImage[i][j][0] = (GLubyte)255;
djImage[i][j][1] = (GLubyte)255;
djImage[i][j][2] = (GLubyte)255;
djImage[i][j][3] = (GLubyte)0;
}
}
}

glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);


	glGenTextures(1, &djTableTexture);
	glBindTexture(GL_TEXTURE_2D, djTableTexture);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXTURE_SIZE, TEXTURE_SIZE,
0, 	GL_RGBA, GL_UNSIGNED_BYTE, djImage);

For the animation task we use a timer with an interval of 0,02 seconds.
For drawing we bind each texture and then draw it.


	[[self openGLContext] makeCurrentContext];
	[self lockFocusIfCanDraw];
	glClearColor(0,0,0,1.0);
	glEnable (GL_BLEND);
   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_TEXTURE_2D);
	
	//I do the following for each textures
	___________________________________________
	glBindTexture(GL_TEXTURE_2D, djTableTexture);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glBegin(GL_TRIANGLE_STRIP);
		glTexCoord2f(0.0,1.0);	glVertex3f(oLinks.x, uRechts.y, 0);
		glTexCoord2f(0.0,0.0);	glVertex3f(oLinks.x, oLinks.y, 0);
		glTexCoord2f(1.0,1.0);	glVertex3f(uRechts.x, uRechts.y, 0);
		glTexCoord2f(1.0,0.0);	glVertex3f(uRechts.x, oLinks.y, 0);
	glEnd();
	___________________________________________

	glDisable(GL_TEXTURE_2D);
	glFlush();
	[self unlockFocus];

CoreImage approach:

We load the 7 images and then we draw each image.
Loading : 	Image   = [CIImage imageWithContentsOfURL: url];
Drawing: [cicontext drawImage: image atPoint:abdekPos fromRect:src];
We use here also a timer with the same interval as above.

In both solutions the turntable views are juddering. The machine I was
testing on is a g4 powerbook with 1.5 GHz and 1.25 GB RAM. I have an
GeForce FX Go5200 graphics card with 64 MB VRAM.

What is genarally the better solution regarding performance? Would it
help to thread the drawing? If threading is reasonable how can I
guaranty that the drawing in seperate threads is save?
Furthermore I made the observation that OpenGL reacts a lot better to
mouse events than CoreImage, is there a logic behind that?

Thanks a lot Federico
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden


.........................................................
Santiago (Jacques) Lema - link-u
http://www.link-u.com/
http://mobile.link-u.com/
http://jack.link-u.com/
http://www.chocoflop.com/
.........................................................


_______________________________________________ Do not post admin requests to the list. They will be ignored. Quartz-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden
References: 
 >Efficient drawing OpenGL vs. CoreImage (From: "Federico Tessmann" <email@hidden>)



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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.