Mailing Lists: Apple Mailing Lists

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

Efficient drawing OpenGL vs. CoreImage



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?

Best regards,
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
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.