0

I need to create an OpenGL texture of type GL_TEXTURE_RECTANGLE_EXT, so that I can use

outputImageProviderFromTextureWithPixelFormat:pixelsWide:pixelsHigh:name:flipped:releaseCallback:releaseContext:colorSpace:shouldColorMatch

, but I can't figure out how to convert my CVImageBufferRef to an OpenGL texture. I'm sure I'm just no looking for the right thing. How can I convert an CVImageBufferRef to an OpenGL texture?

When I try:

   CVImageBufferRef imageBuffer = CVBufferRetain(mCurrentImageBuffer);

    GLuint                  texture = CVOpenGLTextureGetName(imageBuffer);


    id provider= [context outputImageProviderFromTextureWithPixelFormat:QCPlugInPixelFormatARGB8
                                                             pixelsWide:CVPixelBufferGetWidth(imageBuffer)
                                                             pixelsHigh:CVPixelBufferGetHeight(imageBuffer)
                                                                   name:texture
                                                                flipped:NO
                                                        releaseCallback:_TextureReleaseCallback
                                                         releaseContext:NULL
                                                             colorSpace:CVImageBufferGetColorSpace(imageBuffer)
                                                       shouldColorMatch:YES];

It tells me that 'name' cannot be null. I think that's because my imageBuffer is a pixel buffer, and not an OpenGL Texture. How can I create a OpenGL texture from my pixel buffer ?

Adam
  • 913
  • 1
  • 9
  • 26

1 Answers1

1

There might be some special fast-path in the CoreVideo framework, but you could always get the raw backing data and supply it to glTexImage2D. Here's an answered question which covers getting the raw data.

Edit:

Digging a little more, it seems you might be able to simply use the OpenGL texture already associated with your CVImageBufferRef by using CVOpenGLTextureGetTarget and CVOpenGLTextureGetName. These operate on CVOpenGLTextureRef types, which is typedef'd to CVImageBufferRef.

Community
  • 1
  • 1
James
  • 2,373
  • 18
  • 16
  • I tried using CVOpenGLTextureGetName(imageBuffer),and it seems to return null. I got '2011-11-20 12:23:52.607 Quartz Composer[18612:407] *** EXCEPTION IGNORED: -[CaptureWithDevice outputImageProviderFromTextureWithPixelFormat:pixelsWide:pixelsHigh:name:flipped:releaseCallback:releaseContext:colorSpace:shouldColorMatch:]: Argument "name" cannot be null' when I ran it.. – Adam Nov 20 '11 at 18:28
  • After reading the other thread you mentioned, I think the reason it's returning null is because my imageBuffer isn't an OpenGL buffer. So, still, I need to convert from a pixel buffer an open GL texture. – Adam Nov 20 '11 at 18:37
  • Ah, I see. You could try the raw-data route, then. Unfortunately, I have't done a lot of work with CoreVideo. – James Nov 20 '11 at 18:44