CGL - How to get back buffer base address?

Twilight
Unregistered
 
Post: #1
Hi all,

I've setup a double buffered fullscreen CGLContext (kCGLPFADoubleBuffer flag) and use CGLFlushDrawable( contextObj ); to switch between the front and back buffer. OpenGL drawing works perfectly...

For some special pixel manipulation I need to know the base address of the back buffer. I'm able to get the front buffer base address with CGDisplayBaseAddress( kCGDirectMainDisplay ) but how can I get the base address of the back buffer?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You can't. It's in VRAM, you don't know the layout of the memory, and you don't know what OpenGL is doing to it. You shouldn't use CGDisplayBaseAddress either, for the same reasons. CGDisplayAddressForPosition is probably safe if you don't have an OpenGL context up...

You have several possibilities open to you; which you choose depends on your performance and hardware requirements, and the precise "pixel manipulation" you need to do.

Best case is, render to a PBuffer, then use ARB_fragment_program to do your pixel swizzling on the way to the back buffer. Requires a GeForce FX or a Radeon 9600 or better.

Next best is to render to a PBuffer, then use CopyTexSubImage2D from the PBuffer into an APPLE_texture_range client storage texture. That'll get you a DMA from the PBuffer into RAM, which is fast and asynchronous. You can then (later, give the DMA time to finish) use GetTexImage2D to flush the DMA, do your pixel swizzling on the CPU, use TexSubImage2D to update the texture back to the card (another DMA), then blit to the backbuffer. You'll end up 1-2 frames behind, but you should get good performance. Requires Mac OS X 10.3.4 or so, and probably a better-than-rage128 card. There's a discussion about precisely how to do all this in the mac-opengl mailing list archives.

If EXT_pixel_buffer_object is ever supported on the Mac, that'll provide a much nicer path than that Smile

Worst is to use ReadPixels to get the framebuffer image back to memory, do your pixel swizzling there, then return it to GL using DrawPixels or texturing. ReadPixels is slow and synchronous. You won't be a frame behind, but your framerate will be pitiful. Requires: nothing.
Quote this message in a reply
Twilight
Unregistered
 
Post: #3
Thank for the info! Too bad that its not possible

ARB_fragment_program is out of question due to its limited support...maybe an option in a year or so Smile

The PBuffer thing sounds good, only 10.3.4 is a minus but I'll check the mail-lists and test it. I wonder if its faster than render to a hidden window....

EXT_pixel_buffer_object would be great - but well.....maybe next time Smile
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Yeah, it doesn't really matter where you render to originally, though I'd recommend a second context so that you can benefit most from the asynchronicity available. Hidden window should be about as fast as a PBuffer, I just said "PBuffer" 'cos you said "CGL" Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGLES video play back prathap 0 1,176 May 9, 2014 03:45 AM
Last Post: prathap
  OpenGL ES2 matrix setup (humbly crawling back) Fenris 2 6,604 Aug 31, 2011 06:47 AM
Last Post: Fenris
  The tabbing on a word playing back the recorded voice itcreate 0 2,475 Jun 25, 2010 02:06 PM
Last Post: itcreate
  Alternate Back face culling Sohta 6 4,668 Aug 6, 2004 06:10 PM
Last Post: Sohta
  2D to 3D and back (Ortho and Perspective) Phate 5 5,416 Nov 30, 2003 10:56 AM
Last Post: AnotherJake