PDA

View Full Version : How do i draw to an existing opengl color attachment?



PeterVE
26th August 2016, 17:08
I am using QtOpenGL ES 3.0 with a v4l2 video device. Using this function...

GLuint QOpenGLFramebufferObject::takeTexture(int colorAttachmentIndex)

I can grab the GLuint and in my mind, I should be able to draw to it. I have a V4L2 buffer which is in a void* buffer. I need to place this buffer into the color attachment in my render loop. I have seen a lot of references on normal API transitions using glTexImage2D(). So I have this...


.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...
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 );
}

I am getting an error. So here is my question, how am I supposed to write to this GLuint from the char* data? My goal was to not create a new buffer and attach it as a new color attachment in each render loop. If there is already a color attachment texture2d created, it seems I should be able to fill it with my new data over and over.

I have seen people create new buffers and attach it and then a render buffer and blah. But I don't see why this is needed if a color texture2d already exists. I want to reuse it with my v4l2 char buffer data.

Thank you for reading this.

Cheers, Pete