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...

Qt Code:
  1. .h
  2. QOpenGLFramebufferObject* m_fbo;
  3. GLuint m_fboColorAttachment;
  4.  
  5. .cpp
  6. ...init code...
  7. m_fbo = new QOpenGLFramebufferObject ( D1_WIDTH, D1_HEIGHT );
  8. glBindFramebuffer ( GL_FRAMEBUFFER, m_fbo->handle () ); // read and write
  9. m_fbo->addColorAttachment ( D1_WIDTH, D1_HEIGHT );
  10. ...end init code...
  11. ...render loop...
  12. m_fboColorAttachment = m_fbo->takeTexture ();
  13. glBindTexture ( GL_TEXTURE_2D, m_fboColorAttachment );
  14.  
  15. glTexImage2D ( GL_TEXTURE_2D, // Type of texture
  16. 0, // Pyramid level ( for mip-mapping ) - 0 is the top level
  17. GL_RGBA, // Internal colour format to convert to
  18. m_nWidth, // Image width
  19. m_nHeight, // Image height
  20. 0, // Border width in pixels ( can either be 1 or 0 )
  21. GL_RGB, //GL_RGB565, // Input image format ( i.e. GL_RGB, GL_RGBA, GL_BGR etc. )
  22. GL_UNSIGNED_SHORT_5_6_5, // Image data type
  23. (char*) m_v4l2Device->pool->buffers[ nIndex ].mem ); // The actual image data itself
  24.  
  25. //check if OpenGL errors happened
  26. if ( ( enumError = glGetError () ) != GL_NO_ERROR )
  27. {
  28. qDebug ( "OpenGL error: %d.", enumError );
  29. }
To copy to clipboard, switch view to plain text mode 

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