Why do this yourself, when QC has core image blend modes to do all of this for 
you? Make a CVOpenGLTextureRef or more ideally, publish an image output from 
your source comps and then use a 3rd comp to do arbitrary mixing. Caveat: all 
the QCRenderers should be on the same thread if you use an image output / 
QCImage due to API contractual obligations.

Otherwise, with a texture attachment from various FBO's, assuming the 
CGLContext objects are shared, you should be able to call a GL Flush on both 
threads (to ensure the FBO's are in sync, and then pass the GLuint texture ID 
to a thread that does the compositing. Syncing may be problematic, and 
honestly, im not 100% up to speed on the nuances. For sanity, get it working in 
a single thread 1st.

Additionally "Blend" means a lot of different things. Do you want a simple 
source over? Do you want  Porter / Duff blend modes? Do you want a mixer amount 
to animate between a and b channels?

You can just draw two quads, one on top of the other, and use basic OpenGL 
blend mode blending to do alpha blending.

glEnable(GL_BLEND)
glColor4f(1.0, 1.0, 1.0, 1.0);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

// bind texture channel a
// draw quad one

glColor4f(1.0, 1.0, 1.0, mix_amount);

//bind texture channel b
// draw quad 2

You can get more fancy and use GLSL shaders and bind both textures at once via 
multitexturing, and render to a quad however you want.

On Apr 15, 2012, at 5:17 AM, Nisar Ahmed wrote:

> Dear list,
> 
> How do I blend 2 textures rendered by 2 different compositions, these 
> compositions are rendered in separate FBOs in separate threads.
> 
> I have initialized FBO in the following code
> 
> #import <OpenGL/CGLMacro.h>
> int createFBO(GLuint* fbo, GLuint* color, GLuint* depth, uint32_t width, 
> uint32_t height, CGLContextObj cgl_ctx)
> {
>     // texture / color attachment
>     glGenTextures(1, color);
>     glEnable(GL_TEXTURE_2D);
>     glBindTexture(GL_TEXTURE_2D, *color);
>   
>     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
>     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
>     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
>     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, 
> GL_UNSIGNED_BYTE, NULL);
>     glBindTexture(GL_TEXTURE_2D, 0);
>     
>     /*
>     // depth buffer
>     glGenRenderbuffersEXT(1, depth);
>     glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, *depth);
>     glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, 
> height);
>     glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
>     */
>     // FBO and connect attachments
>     glGenFramebuffersEXT(1, fbo);
>     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, *fbo);
>     glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0, 
> GL_TEXTURE_2D, *color, 0);
>     //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT, 
> GL_RENDERBUFFER_EXT, *depth);
>     // Draw black so we have output if the renderer isn't loaded
>     glClearColor(0.0, 0.0, 0.0, 0.0);
>     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>     
>     glViewport(0, 0, width,  height);
>     
>     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
>     
>     GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
>     if(status != GL_FRAMEBUFFER_COMPLETE)
>     {
>         //NSLog(@"Simple Client: OpenGL error %04X", status);
>         glDeleteTextures(1, color);
>         glDeleteFramebuffersEXT(1, fbo);
>         glDeleteRenderbuffersEXT(1, depth);
>         *color = 0;
>         *fbo = 0;
>         *depth = 0;
>         return 0;
>     }
>     return 1;
> }
> The compositions are rendered in this FBO and the textures returned are 
> rendered in a separate rendering loop
> In my rendering loop I am enabling
> 
>     glEnable(GL_DEPTH_TEST);
>     glEnable(GL_BLEND);
>     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
> 
> before binding and rendering each texture into a quad.
> 
> Tanks
> NIsar
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Quartzcomposer-dev mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/quartzcomposer-dev/doktorp%40mac.com
> 
> This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to