Copying the frame buffer to implement scrolling is not appropriate of OpenGL applications. Just translate the coordinate system and redraw everything visible in the scrolled area.
As for why, reading a buffer is the slowest operation you could possibly perform. First, all pending rendering must finish so that the read data is current. That means that the CPU thread must wait doing nothing until the gnu finished rendering. Then the render buffer contents must be copied over the slow bus back to main memory. While the copy takes place, the gpu sits idle because it can't render into a buffer that is being read.
Then you just copy all that data back over a slow bus... The "copy on scroll" semantics of quartz 2D are not the way to implement OpenGL drawing. It is faster in quartz because the render buffer is never read. Quartz drawns into an open gl texture stored in maimemory and only ever draws the textured. The "copy on scroll" is copying the texture memory that is already inmainmemory - not reading it back from the card.
Sent from my iPad
On Aug 29, 2010, at 6:52 AM, Chris Carson <email@hidden> wrote:
> Hi all,
>
> I'm working on making a 2D scroller in OpenGL (really in a Cocoa NSOpenGLView subclass). It works, but the CPU usage on my Macbook shoots up to 50% and other user interface elements become a lot less snappy.
>
> To initialize I do:
>
> glShadeModel(GL_FLAT);
> glDisable(GL_DEPTH_TEST);
> glDisable(GL_LINE_SMOOTH);
> glDisable(GL_BLEND);
>
> Then when drawing (called 24 times per second) I do:
>
> glMatrixMode(GL_MODELVIEW);
> glLoadIdentity();
>
> // Scroll
> glReadBuffer(GL_FRONT);
> glDrawBuffer(GL_BACK);
> glRasterPos2d(-1.0, -1.0+dy);
> glCopyPixels(0, 0, rect.size.width, rect.size.height, GL_COLOR);
>
> // Draw new line
> glBegin(GL_QUAD_STRIP);
> glVertex2d(-1.0, -1.0+dy);
> glVertex2d(-1.0, -1.0);
> for (n = 0, x = -1.0 + dx; n < ([data length]/sizeof(double)); n++, x += dx) {
> glColor3d(datadata[n], datadata[n], datadata[n]);
> glVertex2d(x, -1.0+dy);
> glVertex2d(x, -1.0);
> }
> glEnd();
>
> // Copy back buffer to front
> [[self openGLContext] flushBuffer];
>
>
> If I take out the four lines of code under the // Scroll comment, everything is fine. Any ideas why this would be so slow? Scrolling a webpage in Safari is about the same thing, and that is much smoother and less CPU intensive, even though its probably not OpenGL. What's the matter?
>
> As a side question, is it possible to draw the quad strip in integer coordinates? Seems that glCopyPixels() must use integer coordinates whereas everything else is using floating-point coordinates between -1.0 and 1.0.
>
> Thanks,
> Chris
>
>
>
> _______________________________________________
> 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
_______________________________________________
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