109 initializeOpenGLFunctions();
110 m_blitProgram =
new QOpenGLShaderProgram();
111 m_blitProgram->addShaderFromSourceCode(QOpenGLShader::Vertex,
"attribute vec4 position;\n\
112 attribute vec4 texCoords;\n\
113 varying vec2 outTexCoords;\n\
114 void main()\n\
115 {\n\
116 gl_Position = position;\n\
117 outTexCoords = texCoords.xy;\n\
118 }");
119 m_blitProgram->addShaderFromSourceCode(QOpenGLShader::Fragment,
"varying highp vec2 outTexCoords;\n\
120 uniform sampler2D texture;\n\
121 void main()\n\
122 {\n\
123 gl_FragColor = texture2D(texture, outTexCoords);\n\
124 }");
130 qDebug() <<
"Shader Program link failed.";
138 glDisable(GL_DEPTH_TEST);
140 glDisable(GL_CULL_FACE);
141 glDisable(GL_SCISSOR_TEST);
142 glDepthMask(GL_FALSE);
143 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
148 static const GLfloat squareVertices[] = {
154 static const GLfloat inverseSquareVertices[] = {
160 static const GLfloat textureVertices[] = {
171 m_buffer.allocate(
sizeof(squareVertices) +
sizeof(inverseSquareVertices) +
sizeof(textureVertices));
172 m_buffer.write(m_squareVerticesOffset, squareVertices,
sizeof(squareVertices));
173 m_buffer.write(m_inverseSquareVerticesOffset, inverseSquareVertices,
sizeof(inverseSquareVertices));
174 m_buffer.write(m_textureVerticesOffset, textureVertices,
sizeof(textureVertices));
176 m_blitProgram->setAttributeBuffer(1, GL_FLOAT, m_textureVerticesOffset, 2);
178 m_textureWrap = m_context->context()->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat) ? GL_REPEAT : GL_CLAMP_TO_EDGE;
184 void blit(QWaylandEglWindow *window)
186 QOpenGLTextureCache *cache = QOpenGLTextureCache::cacheForContext(m_context->context());
188 QSize surfaceSize = window->surfaceSize();
189 qreal scale = window->scale() ;
190 glViewport(0, 0, surfaceSize.width() * scale, surfaceSize.height() * scale);
193 if (
auto *decoration = window->decoration()) {
194 m_blitProgram->setAttributeBuffer(0, GL_FLOAT, m_inverseSquareVerticesOffset, 2);
195 QImage decorationImage = decoration->contentImage();
196 cache->bindTexture(
m_context->context(), decorationImage);
197 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_textureWrap);
200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_textureWrap);
201 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
205 m_blitProgram->setAttributeBuffer(0, GL_FLOAT, m_squareVerticesOffset, 2);
206 glBindTexture(GL_TEXTURE_2D, window->contentTexture());
207 QRect r = window->contentsRect();
208 glViewport(r.x() * scale, r.y() * scale, r.width() * scale, r.height() * scale);
209 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);