diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/wayland/minimal-cpp/compositor.cpp | 14 | ||||
-rw-r--r-- | examples/wayland/minimal-cpp/compositor.h | 5 | ||||
-rw-r--r-- | examples/wayland/minimal-cpp/window.cpp | 6 | ||||
-rw-r--r-- | examples/wayland/qwindow-compositor/compositor.cpp | 25 | ||||
-rw-r--r-- | examples/wayland/qwindow-compositor/compositor.h | 5 | ||||
-rw-r--r-- | examples/wayland/qwindow-compositor/window.cpp | 11 |
6 files changed, 22 insertions, 44 deletions
diff --git a/examples/wayland/minimal-cpp/compositor.cpp b/examples/wayland/minimal-cpp/compositor.cpp index ea685923..5e46895c 100644 --- a/examples/wayland/minimal-cpp/compositor.cpp +++ b/examples/wayland/minimal-cpp/compositor.cpp @@ -44,17 +44,9 @@ #include <QtWaylandCompositor/qwaylandoutput.h> #include <QOpenGLFunctions> -GLuint View::getTexture() { - if (advance()) { - QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions(); - if (m_texture) - functions->glDeleteTextures(1, &m_texture); - - functions->glGenTextures(1, &m_texture); - functions->glBindTexture(GL_TEXTURE_2D, m_texture); - functions->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - currentBuffer().bindToTexture(); - } +QOpenGLTexture *View::getTexture() { + if (advance()) + m_texture = currentBuffer().toOpenGLTexture(); return m_texture; } diff --git a/examples/wayland/minimal-cpp/compositor.h b/examples/wayland/minimal-cpp/compositor.h index fe379082..e44a8eb5 100644 --- a/examples/wayland/minimal-cpp/compositor.h +++ b/examples/wayland/minimal-cpp/compositor.h @@ -48,17 +48,18 @@ QT_BEGIN_NAMESPACE class Window; +class QOpenGLTexture; class View : public QWaylandView { Q_OBJECT public: View() : m_texture(0) {} - GLuint getTexture(); + QOpenGLTexture *getTexture(); bool isCursor() const; private: friend class Compositor; - GLuint m_texture; + QOpenGLTexture *m_texture; }; class Compositor : public QWaylandCompositor diff --git a/examples/wayland/minimal-cpp/window.cpp b/examples/wayland/minimal-cpp/window.cpp index 2d529cce..6ae89be4 100644 --- a/examples/wayland/minimal-cpp/window.cpp +++ b/examples/wayland/minimal-cpp/window.cpp @@ -44,6 +44,7 @@ #include <QPainter> #include <QMatrix4x4> #include <QOpenGLFunctions> +#include <QOpenGLTexture> Window::Window() : m_compositor(0) @@ -83,7 +84,10 @@ void Window::paintGL() Q_FOREACH (View *view, m_compositor->views()) { if (view->isCursor()) continue; - GLuint textureId = view->getTexture(); + auto texture = view->getTexture(); + if (!texture) + continue; + GLuint textureId = texture->textureId(); QWaylandSurface *surface = view->surface(); if (surface && surface->hasContent()) { QSize s = surface->size(); diff --git a/examples/wayland/qwindow-compositor/compositor.cpp b/examples/wayland/qwindow-compositor/compositor.cpp index e9231faf..a55bb3b7 100644 --- a/examples/wayland/qwindow-compositor/compositor.cpp +++ b/examples/wayland/qwindow-compositor/compositor.cpp @@ -65,32 +65,13 @@ View::View() , m_parentView(nullptr) {} -GLuint View::getTexture(GLenum *target) +QOpenGLTexture *View::getTexture() { - QWaylandBufferRef buf = currentBuffer(); - GLuint streamingTexture = buf.textureForPlane(0); - if (streamingTexture) - m_texture = streamingTexture; - - if (!buf.isSharedMemory() && buf.bufferFormatEgl() == QWaylandBufferRef::BufferFormatEgl_EXTERNAL_OES) - m_textureTarget = GL_TEXTURE_EXTERNAL_OES; - if (advance()) { - buf = currentBuffer(); - if (!m_texture) - glGenTextures(1, &m_texture); - - glBindTexture(m_textureTarget, m_texture); - if (buf.isSharedMemory()) - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - buf.bindToTexture(); + QWaylandBufferRef buf = currentBuffer(); + m_texture = buf.toOpenGLTexture(); } - buf.updateTexture(); - - if (target) - *target = m_textureTarget; - return m_texture; } diff --git a/examples/wayland/qwindow-compositor/compositor.h b/examples/wayland/qwindow-compositor/compositor.h index b7569082..bf52c8c7 100644 --- a/examples/wayland/qwindow-compositor/compositor.h +++ b/examples/wayland/qwindow-compositor/compositor.h @@ -53,13 +53,14 @@ QT_BEGIN_NAMESPACE class QWaylandWlShell; class QWaylandWlShellSurface; class QWaylandXdgShellV5; +class QOpenGLTexture; class View : public QWaylandView { Q_OBJECT public: View(); - GLuint getTexture(GLenum *target = 0); + QOpenGLTexture *getTexture(); QPointF position() const { return m_position; } void setPosition(const QPointF &pos) { m_position = pos; } bool isCursor() const; @@ -73,7 +74,7 @@ public: private: friend class Compositor; GLenum m_textureTarget; - GLuint m_texture; + QOpenGLTexture *m_texture; QPointF m_position; QWaylandWlShellSurface *m_wlShellSurface; QWaylandXdgSurfaceV5 *m_xdgSurface; diff --git a/examples/wayland/qwindow-compositor/window.cpp b/examples/wayland/qwindow-compositor/window.cpp index 617d79c0..371e0de8 100644 --- a/examples/wayland/qwindow-compositor/window.cpp +++ b/examples/wayland/qwindow-compositor/window.cpp @@ -120,12 +120,11 @@ void Window::paintGL() Q_FOREACH (View *view, m_compositor->views()) { if (view->isCursor()) continue; - GLenum target; - GLuint textureId = view->getTexture(&target); - if (!textureId || !target) + auto texture = view->getTexture(); + if (!texture) continue; - if (target != currentTarget) { - currentTarget = target; + if (texture->target() != currentTarget) { + currentTarget = texture->target(); m_textureBlitter.bind(currentTarget); } QWaylandSurface *surface = view->surface(); @@ -141,7 +140,7 @@ void Window::paintGL() ? QOpenGLTextureBlitter::OriginTopLeft : QOpenGLTextureBlitter::OriginBottomLeft; QMatrix4x4 targetTransform = QOpenGLTextureBlitter::targetTransform(surfaceGeometry, QRect(QPoint(), size())); - m_textureBlitter.blit(textureId, targetTransform, surfaceOrigin); + m_textureBlitter.blit(texture->textureId(), targetTransform, surfaceOrigin); } } } |