[Interest] Using drawPixmap from an EGL buffer
Christophe Chapuis
chris.chapuis at gmail.com
Thu May 9 16:08:06 CEST 2013
Hello,
I have a problem regarding a GL texture that seems to never be actually
released.
Here are the details of the problem: I am creating an image in an EGL
buffer, that I would like to draw on a Qt widget using OpenGL textures to
avoid buffer duplication.
So first I create a QPixmap, and I bind it to GL_TEXTURE_2D.
Then I create an EGLImageKHR using eglCreateImageKHR, associated to my EGL
buffer, and I associate that EGLImageKHR to GL_TEXTURE_2D using
glEGLImageTargetTexture2DOES.
The next call is what is seems to cause the problem: I draw the QPixmap on
the widget using QPainter::drawPixmap. This painter here is a simple
QPainter, associated to the QGL2PaintEngineEx engine. It will delegate the
work to QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap &
pixmap, const QRectF & src).
In a simplified way, the code would look like this:
------------- snip ----------
QGLContext* gc = (QGLContext*) QGLContext::currentContext();
QPixmap *pixmap = new QPixmap(buffer->width, buffer->height);
unsigned int textureId = gc->bindTexture(*pixmap, GL_TEXTURE_2D, GL_BGRA,
QGLContext::PremultipliedAlphaBindOption);
EGLClientBuffer clientBuffer = (EGLClientBuffer) buffer;
EGLint attrs[] = {
EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
EGL_NONE,
};
EGLDisplay currentDisplay = eglGetCurrentDisplay();
EGLImageKHR image = eglCreateImageKHR(currentDisplay, EGL_NO_CONTEXT,
EGL_NATIVE_BUFFER_ANDROID, clientBuffer, attrs);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES) image);
painter->drawPixmap(m_visibleBounds.x(), m_visibleBounds.y(), *pixmap, 0,
0, m_visibleBounds.width(), m_visibleBounds.height());
eglDestroyImageKHR(currentDisplay, image);
gc->deleteTexture(textureId);
delete pixmap;
------------- snip ----------
This code draws actually the buffer in the Qt widget alright, but then it
seems that I can't reuse my EGL buffer, as there is still some binding
between GL_TEXTURE_2D and the buffer.
Note that if I call gc->deleteTexture(textureId) before calling drawPixmap,
I don't get the problem (but of course the buffer is not drawn on the
widget).
When investigating a bit further, I found out that the Qt GL engine uses
some texture caching. Could it be the cause of my problem ? Or would you
suggest another way, maybe cleaner, to draw the EGL buffer on a Qt widget ?
Thanks in advance.
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130509/6fa932ad/attachment.html>
More information about the Interest
mailing list