如何绘制现有的opengl颜色附件?

时间:2016-08-26 15:37:32

标签: c++ qt opengl-es

我正在使用QtOpenGL ES 3.0和v4l2视频设备。使用此功能......

GLuint QOpenGLFramebufferObject :: takeTexture(int colorAttachmentIndex)

我可以抓住GLuint,在我看来,我应该能够吸引它。我有一个V4L2缓冲区,它位于void *缓冲区中。我需要将此缓冲区放入渲染循环中的颜色附件中。我已经看到很多关于使用glTexImage2D()的普通API转换的参考资料。所以我有这个......

//.h

QOpenGLFramebufferObject * m_fbo;
GLuint                     m_fboColorAttachment;

//.cpp
//...init code... 

m_fbo = new QOpenGLFramebufferObject ( D1_WIDTH, D1_HEIGHT );
glBindFramebuffer ( GL_FRAMEBUFFER, m_fbo->handle () );  // read and write
m_fbo->addColorAttachment ( D1_WIDTH, D1_HEIGHT );

//...end init code...
//...render loop... 

glBindFramebuffer ( GL_FRAMEBUFFER, m_fbo->handle () );  // read and write
m_fboColorAttachment = m_fbo->takeTexture ();     
glBindTexture ( GL_TEXTURE_2D, m_fboColorAttachment );

glTexImage2D ( GL_TEXTURE_2D,               // Type of texture
               0,                           // Pyramid level ( for mip-mapping ) - 0 is 
                                            //the top level
               GL_RGBA,                     // Internal colour format to convert to
               m_nWidth,                    // Image width
               m_nHeight,                   // Image height
               0,                           // Border width in pixels ( can either be 1
                                            //or 0 )
               GL_RGB,   //GL_RGB565,       // Input image format ( i.e. GL_RGB, GL_RGBA, 
                                            //GL_BGR etc. )
               GL_UNSIGNED_SHORT_5_6_5,     // Image data type
               (char*) m_v4l2Device->pool->buffers[ nIndex ].mem );  // The actual image 
                                                                     //data itself

//check if OpenGL errors happened 

if ( ( enumError = glGetError () ) != GL_NO_ERROR )
{
    qDebug ( "OpenGL error: %d.", enumError );
}

我收到了错误消息。所以这是我的问题,我应该如何写GLuint from char* data?我的目标是不创建新缓冲区并将其作为每个渲染循环中的新颜色附件附加。如果已经有颜色附件texture2d created,我似乎应该能够反复填充我的新数据。

我见过人们创建新缓冲区并附加它然后渲染缓冲区和等等。但是,如果颜色为texture2d already exists,我不明白为什么需要这样做。我希望将其与v4l2 char buffer data一起重复使用。

干杯, 皮特

1 个答案:

答案 0 :(得分:0)

OpenGL ES不支持格式转换作为纹理上传的一部分。在glTexImage2D()调用中, internalformat 格式 / 类型需要兼容,基于表3.2。 ES 3.0规范中的3.3和3.3。

根据表3.3中的值,对于未标注的GL_RGBA 内部格式,唯一合法的格式GL_RGBA,并与类型相结合这是GL_UNSIGNED_BYTEGL_UNSIGNED_SHORT_4_4_4_4GL_UNSIGNED_SHORT_5_5_5_1之一。

对于您尝试使用的GL_RGB / GL_UNSIGNED_SHORT_5_6_5 格式 / 类型组合, internalformat 值需要GL_RGBGL_RGB565。我总是建议使用大小的 internalformat 值。仅支持未大小的值以与旧的OpenGL版本兼容。