From: Andy Nichols Date: Wed, 31 Aug 2011 14:23:10 +0000 (+0200) Subject: Enables semi-transparent clients in QWindow Compositor X-Git-Tag: qt-v5.0.0-alpha1~223^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=da9bddc605089397917b89037ac7429dbb9f32c7;p=profile%2Fivi%2Fqtwayland.git Enables semi-transparent clients in QWindow Compositor --- diff --git a/examples/qwindow-compositor/qwindowcompositor.cpp b/examples/qwindow-compositor/qwindowcompositor.cpp index 3d59a30..1b0c002 100644 --- a/examples/qwindow-compositor/qwindowcompositor.cpp +++ b/examples/qwindow-compositor/qwindowcompositor.cpp @@ -7,6 +7,7 @@ QWindowCompositor::QWindowCompositor(QOpenGLWindow *window) m_backgroundImage = QImage(QLatin1String("background.jpg")); m_renderer = new SurfaceRenderer(m_window->context(), m_window); m_backgroundTexture = m_renderer->textureFromImage(m_backgroundImage); + render(); } @@ -72,17 +73,16 @@ void QWindowCompositor::render() m_window->makeCurrent(); //Draw the background Image texture - m_renderer->drawTexture(m_backgroundTexture, m_window->geometry()); + m_renderer->drawTexture(m_backgroundTexture, m_window->geometry(), 0); //Iterate all surfaces in m_surfaces //If type == WaylandSurface::Texture draw textureId at geometry foreach (WaylandSurface *surface, m_surfaces) { if (surface->type() == WaylandSurface::Texture) - m_renderer->drawTexture(surface->texture(), surface->geometry()); + m_renderer->drawTexture(surface->texture(), surface->geometry(), 1); //depth argument should be dynamic (focused should be top). else if (surface->type() == WaylandSurface::Shm) m_renderer->drawImage(surface->image(), surface->geometry()); } - frameFinished(); glFinish(); m_window->swapBuffers(); diff --git a/examples/qwindow-compositor/surfacerenderer.cpp b/examples/qwindow-compositor/surfacerenderer.cpp index 20499f7..10ed41e 100644 --- a/examples/qwindow-compositor/surfacerenderer.cpp +++ b/examples/qwindow-compositor/surfacerenderer.cpp @@ -8,12 +8,12 @@ SurfaceRenderer::SurfaceRenderer(QOpenGLContext *context, QWindow *surface) { const char *textureVertexProgram = "uniform highp mat4 matrix;\n" - "attribute highp vec2 vertexCoordEntry;\n" + "attribute highp vec3 vertexCoordEntry;\n" "attribute highp vec2 textureCoordEntry;\n" "varying highp vec2 textureCoord;\n" "void main() {\n" " textureCoord = textureCoordEntry;\n" - " gl_Position = matrix * vec4(vertexCoordEntry, 0, 1);\n" + " gl_Position = matrix * vec4(vertexCoordEntry, 1);\n" "}\n"; const char *textureFragmentProgram = @@ -25,6 +25,10 @@ SurfaceRenderer::SurfaceRenderer(QOpenGLContext *context, QWindow *surface) m_context->makeCurrent(m_surface); + //Enable transparent windows + glEnable(GL_BLEND); + glBlendFunc (GL_ONE,GL_ONE_MINUS_SRC_ALPHA); + //May need to manually set context here m_shaderProgram = new QGLShaderProgram(); @@ -46,6 +50,7 @@ void SurfaceRenderer::drawImage(const QImage &image, const QRect &geometry) void SurfaceRenderer::drawTexture(int textureId, const QRect &geometry, int depth) { + GLfloat zValue = depth / 1000.0f; //Set Texture and Vertex coordinates GLfloat textureCoordinates[] = { 0, 0, 1, 0, @@ -53,10 +58,10 @@ void SurfaceRenderer::drawTexture(int textureId, const QRect &geometry, int dept 0, 1 }; - GLfloat vertexCoordinates[] = { geometry.left(), geometry.top(), - geometry.right(), geometry.top(), - geometry.right(), geometry.bottom(), - geometry.left(), geometry.bottom() + GLfloat vertexCoordinates[] = { geometry.left(), geometry.top(), zValue, + geometry.right(), geometry.top(), zValue, + geometry.right(), geometry.bottom(), zValue, + geometry.left(), geometry.bottom(), zValue }; //Set matrix to transfrom geometry values into gl coordinate space. @@ -70,7 +75,7 @@ void SurfaceRenderer::drawTexture(int textureId, const QRect &geometry, int dept m_context->functions()->glEnableVertexAttribArray(m_vertexCoordEntry); m_context->functions()->glEnableVertexAttribArray(m_textureCoordEntry); - m_context->functions()->glVertexAttribPointer(m_vertexCoordEntry, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinates); + m_context->functions()->glVertexAttribPointer(m_vertexCoordEntry, 3, GL_FLOAT, GL_FALSE, 0, vertexCoordinates); m_context->functions()->glVertexAttribPointer(m_textureCoordEntry, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinates); m_shaderProgram->setUniformValue(m_matrixLocation, m_transformMatrix);