Skip to content

Instantly share code, notes, and snippets.

@fkaa
Created July 27, 2015 18:51
Show Gist options
  • Save fkaa/964bd909d86100034c3f to your computer and use it in GitHub Desktop.
Save fkaa/964bd909d86100034c3f to your computer and use it in GitHub Desktop.
int frameTexture; // shared
// main thread
// probably need some synchronization between decoding a frame
// on the decoder thread and displaying it on the main
glBindTexture(GL_TEXTURE_2D, frameTexture);
glDrawEverythingForMe(GL_MAGICAL_ENUM, 0xDEADBEEF);
// decode thread
// get secondary context
makeCurrent();
// switching between two PBOs will make it double buffered,
// and consume 2x space
while ((data = decode(foo)) != null) {
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
byte *ptr = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, ...);
glBufferData(..., data);
glUnmapBuffer (GL_PIXEL_UNPACK_BUFFER);
glBindTexture(GL_TEXTURE_2D, frameTexture);
glTexSubImage2D (GL_TEXTURE_2D, ..., (void *) 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment