I want to write an app that will take a still image and generate an animated kaleidoscope. I want to take a triangular subsection of the original image and flip it and rotate it multiple times to create the kaleidoscope image. On a timer I will shift and/or rotate the location of the source triangle and repeat the process. I want to use OpenGL so it is fast enough for smooth animation even for large screens.
My target platform is Macintoshes running Mac OS 10.5 or later.
Here is my thinking:
Set up a full-screen viewport with orthographic projection (I don’t need 3D or perspective for this app - I’m just flipping and rotating a triangular section of a source image into a kaleidoscope)
Create a pixel buffer object (PBO) and copy my source image into the PBO. (Scale it down to screen size if needed.)
Create a stencil buffer and set it up to limit drawing to the target triangle in my color buffer.
From what I’ve read, stencil buffers seem to limit drawing into a target color buffer. It would be helpful if there was an equivalent function to clip SOURCE pixels from my PBO into a triangular slice to be drawn into my kaleidoscope.
Failing that, I guess I would need to apply a transformation matrix so my source image lines up with the target for the current triangle to be drawn into the render buffer, and draw the PBO into the render buffer. I would then apply a transformation to the stencil buffer to move my triangle to it’s next location, apply the same transformation to the matrix I use for drawing the PBO into the render buffer, and draw the PBO into the render buffer again.
Once I was done assembling the kaleidoscope from it’s component triangles, I would swap buffers to display it to the screen, and start a (platform specific) timer for the next frame.
When the timer went off, I would shift/rotate the matrix used for drawing my PBO into my render buffer, and build another frame of the kaleidoscope.
Would drawing using a stencil buffer enable the hardware to only process pixels that land in the selected part of my stencil buffer, and avoid performing computations on pixels that are not selected in the stencil buffer? And does drawing from a PBO into the render buffer use the current transformation matrix so that I can shift/rotate the pixels from my source PBO image into my destination render buffer?
Another question I have, which might be more appropriate for the Mac-specific forums: Can I be sure that PBOs are available on all Macs running OS 10.5? I think the answer to this is yes, but I’d like to be sure. I would NOT want to have to check for PBO support at runtime and write two separate sets of code for machines with and without PBO support.
If the answer is no, is there a clean, fast way to do this without PBOs? I want to keep all the pixel data in the video hardware so I’m not waiting for transfers back and forth between main memory and video memory. PBOs seem like the way to go for this.
I’d like to be able to get 30 FPS at full screen size out of this, so I get buttery smooth animation of the kaleidoscope, even on lower-end Mac hardware. I don’t know if that’s a reasonable expectation or not. Assuming there is enough video memory for a full screen stencil buffer and a full-screen sized PBO, I would think that what I am planning is fairly low demand for even the built-in video hardware on low end Macs (at least those that are fast enough to run OS 10.5)
Thanks in advance for any help or suggestions you can offer.