82 initializeOpenGLFunctions();
83 m_blitProgram =
new QOpenGLShaderProgram();
84 m_blitProgram->addShaderFromSourceCode(QOpenGLShader::Vertex,
"attribute vec4 position;\n\
85 attribute vec4 texCoords;\n\
86 varying vec2 outTexCoords;\n\
87 void main()\n\
88 {\n\
89 gl_Position = position;\n\
90 outTexCoords = texCoords.xy;\n\
91 }");
92 m_blitProgram->addShaderFromSourceCode(QOpenGLShader::Fragment,
"varying highp vec2 outTexCoords;\n\
93 uniform sampler2D texture;\n\
94 void main()\n\
95 {\n\
96 gl_FragColor = texture2D(texture, outTexCoords);\n\
97 }");
103 qDebug() <<
"Shader Program link failed.";
111 glDisable(GL_DEPTH_TEST);
113 glDisable(GL_CULL_FACE);
114 glDisable(GL_SCISSOR_TEST);
115 glDepthMask(GL_FALSE);
116 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
121 static const GLfloat squareVertices[] = {
127 static const GLfloat inverseSquareVertices[] = {
133 static const GLfloat textureVertices[] = {
144 m_buffer.allocate(
sizeof(squareVertices) +
sizeof(inverseSquareVertices) +
sizeof(textureVertices));
145 m_buffer.write(m_squareVerticesOffset, squareVertices,
sizeof(squareVertices));
146 m_buffer.write(m_inverseSquareVerticesOffset, inverseSquareVertices,
sizeof(inverseSquareVertices));
147 m_buffer.write(m_textureVerticesOffset, textureVertices,
sizeof(textureVertices));
149 m_blitProgram->setAttributeBuffer(1, GL_FLOAT, m_textureVerticesOffset, 2);
151 m_textureWrap = m_context->context()->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat) ? GL_REPEAT : GL_CLAMP_TO_EDGE;
157 void blit(QWaylandEglWindow *window)
159 QOpenGLTextureCache *cache = QOpenGLTextureCache::cacheForContext(m_context->context());
161 QSize surfaceSize = window->surfaceSize();
162 qreal scale = window->scale() ;
163 glViewport(0, 0, surfaceSize.width() * scale, surfaceSize.height() * scale);
166 if (
auto *decoration = window->decoration()) {
167 m_blitProgram->setAttributeBuffer(0, GL_FLOAT, m_inverseSquareVerticesOffset, 2);
168 QImage decorationImage = decoration->contentImage();
169 cache->bindTexture(
m_context->context(), decorationImage);
170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
172 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_textureWrap);
173 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_textureWrap);
174 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
178 m_blitProgram->setAttributeBuffer(0, GL_FLOAT, m_squareVerticesOffset, 2);
179 glBindTexture(GL_TEXTURE_2D, window->contentTexture());
180 QRect r = window->contentsRect();
181 glViewport(r.x() * scale, r.y() * scale, r.width() * scale, r.height() * scale);
182 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);