Search code examples
qtopengl-esgpuhardware-accelerationpbo

Storing RGBA32 pixels directly into an OpenGL ES texture


I'm using a library which provides me frames I have to blit to the screen. I allocate a buffer, and this library writes directly into this buffer. When I'm required, I have to blit a specified part of this buffer to the screen. I'm rendering using Qt with the OpenGL/ES paint engine.

Question is: what is the fastest way to blit to the screen? I'm currently loading the buffer in a QImage using the constructor that accepts a pointer to data. This should avoid any copy. Then, I use the drawImage() method of the QPainter to blit to the screen the correct area. I guess this method loads a copy of the area to the GPU memory and then blits to the screen using an OpenGL texture.

Would it be possible to avoid this copy to speed up the process? Would it be possible for instance to draw directly in a OpenGL texture so that I don't have to transfer to the GPU? I read of pixel buffer objects. Might that be a solution? May I use for this purpose a QGLFramebufferObject?


Solution

  • Ultimately you have to write to the GPU, all you can do is minimise the number of unnecessary copies and any in-CPU conversions from say RGBA to BGRA.

    I would start with QImage and QPainter and see if the graphics speed is the limiting step before starting to optimise.

    Take a look at this link.

    Note that a lot of general OpenGL advice does NOT apply to opengl-ES, it's best to think of ES as a totally separate concept to OpenGL.