作为一名OpenGLES初学者,我对Rosywriter中的一些OpenGLES函数有以下问题。 RosyWriter是Apple官方示例代码。链接在这里: https://developer.apple.com/library/prerelease/ios/samplecode/RosyWriter/Introduction/Intro.html
在
RosyWriterOpenGLRenderer::copyRenderedPixelBuffer:(CVPixelBufferRef)pixelBuffer
作者调用 CVOpenGLESTextureCacheCreateTextureFromImage 生成两个 CVOpenGLESTexture ,srcTexture(来自输入 CVPixelBufferRef pixelBuffer)和dstTexture(来自输出 CVPixelBufferRef dstPixelBuffer,由 CVPixelBufferPool 生成。 然后,以下代码将内容从srcTexture复制到dstTexture。
// Set up our destination pixel buffer as the framebuffer's render target.
glActiveTexture( GL_TEXTURE0 );
glBindTexture( CVOpenGLESTextureGetTarget( dstTexture ), CVOpenGLESTextureGetName( dstTexture ) );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, CVOpenGLESTextureGetTarget( dstTexture ), CVOpenGLESTextureGetName( dstTexture ), 0 );
// Render our source pixel buffer.
glActiveTexture( GL_TEXTURE1 );
glBindTexture( CVOpenGLESTextureGetTarget( srcTexture ), CVOpenGLESTextureGetName( srcTexture ) );
glUniform1i( _frame, 1 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glVertexAttribPointer( ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices );
glEnableVertexAttribArray( ATTRIB_VERTEX );
glVertexAttribPointer( ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0, textureVertices );
glEnableVertexAttribArray( ATTRIB_TEXTUREPOSITON );
glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
glBindTexture( CVOpenGLESTextureGetTarget( srcTexture ), 0 );
glBindTexture( CVOpenGLESTextureGetTarget( dstTexture ), 0 );
// Make sure that outstanding GL commands which render to the destination pixel buffer have been submitted.
// AVAssetWriter, AVSampleBufferDisplayLayer, and GL will block until the rendering is complete when sourcing from this pixel buffer.
glFlush();
我的问题是 1. CVOpenGLESTexture 上的更改是否也适用于 CVPixelBufferRef ,通过调用 CVOpenGLESTextureCacheCreateTextureFromImage 来创建 CVOpenGLESTexture ?我认同;否则dstPixelBuffer如何获取内容?
glDrawArrays 是否将纹理内容绘制为 GL_FRAMEBUFFER ?如果是这样,OpenGLES如何知道?是因为dstTexture附加到 GL_FRAMEBUFFER (通过调用 glFramebufferTexture2D ), glDrawArrays 修改的 GL_FRAMEBUFFER 中的内容将会还影响dstTexture?
在我发布的代码末尾,作者调用
glBindTexture( CVOpenGLESTextureGetTarget( srcTexture ), 0 );
glBindTexture( CVOpenGLESTextureGetTarget( dstTexture ), 0 );
目的是什么?
非常感谢您在我的问题上花费宝贵的时间。如果任何概念或术语有误,请随时更正。