spiralstorm/Pixelwave — pull request #33 by Bekenn (2011-11-22 21:05:14+00:00)
Title: Add new event: PXEvent_PostRender

Added a new event that is dispatched just before the call to presentRenederbuffer. This allows client code to draw its own independent OpenGL content on top of Pixelwave's visuals. Client code registers for the event in the same way as for EnterFrame:

```Objective-C
[self addEventListenerOfType: PXEvent_PostRender listener: PXListener(postRender:)];
```

The application should create its own EAGLContext using the sharegroup from the provided Pixelwave context; this allows the application's context to draw to the same framebuffer:

```Objective-C
GLuint framebuffer;
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint*)&destFramebuffer);

EAGLContext* pxContext = [EAGLContext currentContext]; // grab Pixelwave's context
privateContext = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPOpenGLES1 sharegroup: [pxContext sharegroup]];

// Bind to the same framebuffer as Pixelwave's context
[EAGLContext setCurrentContext: privateContext];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);

// Set up viewport and frustum
// ...

// Set the current context back to the Pixelwave context
[EAGLContext setCurrentContext: pxContext];
```

On receiving the PostRender event, the client must flush the command queue for the Pixelwave context before switching to its own context, and again before reinstating the Pixelwave context:

```Objective-C
- (void)postRender: (PXEvent*)event
{
EAGLContext* pxContext = [EAGLContext currentContext];
glFlush(); // NOT PXGLFlush
[EAGLContext setCurrentContext: privateContext];

// draw custom content; thanks to the sharegroup, all of the textures from Pixelwave's PXTextureData objects are available for use
// ...

// Reinstate the Pixelwave context
glFlush();
[EAGLContext setCurrentContext: pxContext];
}
```