summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@viroteck.net>2014-08-20 00:37:57 +0200
committerRobin Burchell <robin.burchell@viroteck.net>2014-08-20 12:12:04 +0200
commitf2219eb6b7148186df00966df30684fc0f3feba5 (patch)
tree6fa72b5e0fec51c6c33798686527a347eda9e037 /examples
parent269edf1de83242b2c60c393c82ade609200ef948 (diff)
Replace custom texture upload with QOpenGLTexture
Change-Id: Ibf6facdd1fba72c2f9741e49cf2c83f9b4136ffc Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/qwindow-compositor/qwindowcompositor.cpp39
-rw-r--r--examples/qwindow-compositor/qwindowcompositor.h3
-rw-r--r--examples/qwindow-compositor/textureblitter.cpp2
3 files changed, 22 insertions, 22 deletions
diff --git a/examples/qwindow-compositor/qwindowcompositor.cpp b/examples/qwindow-compositor/qwindowcompositor.cpp
index 71fa4f9f6..a17af929d 100644
--- a/examples/qwindow-compositor/qwindowcompositor.cpp
+++ b/examples/qwindow-compositor/qwindowcompositor.cpp
@@ -44,6 +44,7 @@
#include <QKeyEvent>
#include <QTouchEvent>
#include <QOpenGLFunctions>
+#include <QOpenGLTexture>
#include <QGuiApplication>
#include <QCursor>
#include <QPixmap>
@@ -57,25 +58,25 @@
QT_BEGIN_NAMESPACE
-static GLuint textureFromImage(const QImage &image)
-{
- GLuint texture = 0;
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- QImage tx = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tx.width(), tx.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tx.constBits());
- glBindTexture(GL_TEXTURE_2D, 0);
- return texture;
-}
-
class BufferAttacher : public QWaylandBufferAttacher
{
public:
+ BufferAttacher()
+ : QWaylandBufferAttacher()
+ , shmTex(0)
+ {
+ }
+
+ ~BufferAttacher()
+ {
+ delete shmTex;
+ }
+
void attach(const QWaylandBufferRef &ref) Q_DECL_OVERRIDE
{
if (bufferRef) {
- if (ownTexture)
- glDeleteTextures(1, &texture);
+ if (bufferRef.isShm())
+ delete shmTex;
else
bufferRef.destroyTexture();
}
@@ -84,11 +85,10 @@ public:
if (bufferRef) {
if (bufferRef.isShm()) {
- texture = textureFromImage(bufferRef.image());
- ownTexture = true;
+ shmTex = new QOpenGLTexture(bufferRef.image(), QOpenGLTexture::DontGenerateMipMaps);
+ texture = shmTex->textureId();
} else {
texture = bufferRef.createTexture();
- ownTexture = false;
}
}
}
@@ -100,9 +100,9 @@ public:
return bufferRef.image();
}
+ QOpenGLTexture *shmTex;
QWaylandBufferRef bufferRef;
GLuint texture;
- bool ownTexture;
};
QWindowCompositor::QWindowCompositor(QOpenGLWindow *window)
@@ -139,7 +139,6 @@ QWindowCompositor::QWindowCompositor(QOpenGLWindow *window)
QWindowCompositor::~QWindowCompositor()
{
- glDeleteTextures(1, &m_backgroundTexture);
delete m_textureBlitter;
}
@@ -314,11 +313,11 @@ void QWindowCompositor::render()
cleanupGraphicsResources();
if (!m_backgroundTexture)
- m_backgroundTexture = textureFromImage(m_backgroundImage);
+ m_backgroundTexture = new QOpenGLTexture(m_backgroundImage, QOpenGLTexture::DontGenerateMipMaps);
m_textureBlitter->bind();
// Draw the background image texture
- m_textureBlitter->drawTexture(m_backgroundTexture,
+ m_textureBlitter->drawTexture(m_backgroundTexture->textureId(),
QRect(QPoint(0, 0), m_backgroundImage.size()),
window()->size(),
0, false, true);
diff --git a/examples/qwindow-compositor/qwindowcompositor.h b/examples/qwindow-compositor/qwindowcompositor.h
index f075c151d..8b224e6b8 100644
--- a/examples/qwindow-compositor/qwindowcompositor.h
+++ b/examples/qwindow-compositor/qwindowcompositor.h
@@ -53,6 +53,7 @@
QT_BEGIN_NAMESPACE
class QWaylandSurfaceView;
+class QOpenGLTexture;
class QWindowCompositor : public QObject, public QWaylandCompositor
{
@@ -92,7 +93,7 @@ private:
QOpenGLWindow *m_window;
QImage m_backgroundImage;
- GLuint m_backgroundTexture;
+ QOpenGLTexture *m_backgroundTexture;
QList<QWaylandSurface *> m_surfaces;
TextureBlitter *m_textureBlitter;
GLuint m_surface_fbo;
diff --git a/examples/qwindow-compositor/textureblitter.cpp b/examples/qwindow-compositor/textureblitter.cpp
index d7d569e64..813fd8966 100644
--- a/examples/qwindow-compositor/textureblitter.cpp
+++ b/examples/qwindow-compositor/textureblitter.cpp
@@ -68,7 +68,7 @@ TextureBlitter::TextureBlitter()
//Enable transparent windows
glEnable(GL_BLEND);
- glBlendFunc (GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
m_shaderProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, textureVertexProgram);
m_shaderProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, textureFragmentProgram);