102 QByteArray vertexSource;
103 QByteArray fragmentSource;
105 const QByteArray attribute = core ?
"in" :
"attribute";
106 const QByteArray varying_in = core ? (gles ?
"in" :
"noperspective in") :
"varying";
107 const QByteArray varying_out = core ? (gles ?
"out" :
"noperspective out") :
"varying";
108 const QByteArray texture2D = core ?
"texture" :
"texture2D";
109 const QByteArray fragColor = core ?
"fragColor" :
"gl_FragColor";
113 QTextStream stream(&vertexSource);
117 stream <<
"#version 300 es\n\n";
119 stream <<
"precision highp float;\n";
120 }
else if (glsl_140) {
121 stream <<
"#version 140\n\n";
124 stream <<
"uniform mat4 modelViewProjectionMatrix;\n";
125 stream <<
"uniform mat4 textureMatrix;\n";
126 stream << attribute <<
" vec4 vertex;\n\n";
127 stream << varying_out <<
" vec4 varyingTexCoords;\n";
129 stream <<
"void main(void)\n";
131 stream <<
" varyingTexCoords = vec4(textureMatrix * vertex).stst;\n";
132 stream <<
" gl_Position = modelViewProjectionMatrix * vertex;\n";
138 QTextStream stream2(&fragmentSource);
142 stream2 <<
"#version 300 es\n\n";
144 stream2 <<
"precision highp float;\n";
145 }
else if (glsl_140) {
146 stream2 <<
"#version 140\n\n";
149 stream2 <<
"uniform mat4 colorMatrix;\n";
150 stream2 <<
"uniform sampler2D sampler;\n";
151 stream2 <<
"uniform float opacity;\n";
152 stream2 << varying_in <<
" vec4 varyingTexCoords;\n";
155 stream2 <<
"out vec4 fragColor;\n\n";
158 stream2 <<
"void main(void)\n";
160 stream2 <<
" vec4 tex = " << texture2D <<
"(sampler, varyingTexCoords.st);\n";
162 stream2 <<
" if (opacity >= 1.0) {\n";
163 stream2 <<
" " << fragColor <<
" = tex * colorMatrix;\n";
164 stream2 <<
" } else {\n";
165 stream2 <<
" " << fragColor <<
" = tex * (opacity * colorMatrix + (1.0 - opacity) * mat4(1.0));\n";
173 if (m_shader->isValid()) {
174 m_colorMatrixLocation = m_shader->uniformLocation(
"colorMatrix");
175 m_textureMatrixLocation = m_shader->uniformLocation(
"textureMatrix");
176 m_mvpMatrixLocation = m_shader->uniformLocation(
"modelViewProjectionMatrix");
177 m_opacityLocation = m_shader->uniformLocation(
"opacity");
179 QMatrix4x4 modelViewProjection;
181 modelViewProjection.ortho(0, screenSize.width(), screenSize.height(), 0, 0, 65535);
183 m_shader->setUniform(m_colorMatrixLocation, QMatrix4x4());
184 m_shader->setUniform(m_textureMatrixLocation, QMatrix4x4());
185 m_shader->setUniform(m_mvpMatrixLocation, modelViewProjection);
186 m_shader->setUniform(m_opacityLocation, (
float)1.0);