I am using an API which only gives me the integer id of the texture object, and I need to pass that texture's data to AVAssetWriter to create the video.
I know how to create CVOpenGLESTexture object from pixel buffer (CVPixelBufferRef), but in my case I have to somehow copy the data of a texture of which only the id is available.
In other words, I need to copy an opengl texture to my pixelbuffer-based texture object. Is it possible? If yes then how?
In my sample code I have something like:
void encodeFrame(Gluint textureOb)
{
CVPixelBufferPoolCreatePixelBuffer (NULL, [assetWriterPixelBufferAdaptor pixelBufferPool], &pixelBuffer[0]);
CVOpenGLESTextureCacheCreateTextureFromImage (kCFAllocatorDefault, coreVideoTextureCache, pixelBuffer[0],
NULL, // texture attributes
GL_TEXTURE_2D,
GL_RGBA, // opengl format
(int)FRAME_WIDTH,
(int)FRAME_HEIGHT,
GL_BGRA, // native iOS format
GL_UNSIGNED_BYTE,
0,
&renderTexture[0]);
CVPixelBufferLockBaseAddress(pixelBuffer[pixelBuffernum], 0);
//Creation of textureOb is not under my control.
//All I have is the id of texture.
//Here I need the data of textureOb somehow be appended as a video frame.
//Either by copying the data to pixelBuffer or somehow pass the textureOb to the Adaptor.
[assetWriterPixelBufferAdaptor appendPixelBuffer:pixelBuffer[0] withPresentationTime:presentationTime];
}
Thanks for tips and answers.
P.S. glGetTexImage
isn't available on iOS.
Update:
@Dr. Larson, I can't set the texture ID for API. Actually I can't dictate 3rd party API to use my own created texture object.
After going through the answers what I understood is that I need to:
1- Attach pixelbuffer-associated texture object as color attachment to a texFBO. For each frame:
2- Bind the texture obtained from API
3- Bind texFBO and call drawElements
What am I doing wrong in this code?
P.S. I'm not familiar with shaders yet, so it is difficult for me to make use of them right now.
Update 2: With the help of Brad Larson's answer and using the correct shaders solved the problem. I had to use shaders which are an essential requirement of Opengl ES 2.0