summaryrefslogtreecommitdiffstats
path: root/examples/opengl
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-11-05 00:25:12 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-11-05 06:46:05 (GMT)
commitb91f1a2f749586014e8b28c6766015ff6ba62ee7 (patch)
treeb7c4eebcd52754645f463b363a425ce163f643a9 /examples/opengl
parent23572588c4b0c759c14a6c1687e5bd86461e31e8 (diff)
downloadQt-b91f1a2f749586014e8b28c6766015ff6ba62ee7.zip
Qt-b91f1a2f749586014e8b28c6766015ff6ba62ee7.tar.gz
Qt-b91f1a2f749586014e8b28c6766015ff6ba62ee7.tar.bz2
Modify QGLShader and QGLShaderProgram in response to API review
Reviewed-by: Sarah Smith
Diffstat (limited to 'examples/opengl')
-rw-r--r--examples/opengl/hellogl_es2/glwidget.cpp30
-rw-r--r--examples/opengl/textures/glwidget.cpp12
2 files changed, 25 insertions, 17 deletions
diff --git a/examples/opengl/hellogl_es2/glwidget.cpp b/examples/opengl/hellogl_es2/glwidget.cpp
index a31c34a..08e887a 100644
--- a/examples/opengl/hellogl_es2/glwidget.cpp
+++ b/examples/opengl/hellogl_es2/glwidget.cpp
@@ -92,6 +92,8 @@ void GLWidget::showBubbles(bool bubbles)
void GLWidget::paintQtLogo()
{
+ program1.enableAttributeArray(normalAttr1);
+ program1.enableAttributeArray(vertexAttr1);
program1.setAttributeArray(vertexAttr1, vertices.constData());
program1.setAttributeArray(normalAttr1, normals.constData());
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
@@ -159,6 +161,10 @@ void GLWidget::paintTexturedCube()
program2.setUniformValue(textureUniform2, 0); // use texture unit 0
+ program2.enableAttributeArray(vertexAttr2);
+ program2.enableAttributeArray(normalAttr2);
+ program2.enableAttributeArray(texCoordAttr2);
+
glDrawArrays(GL_TRIANGLES, 0, 36);
program2.disableAttributeArray(vertexAttr2);
@@ -173,7 +179,7 @@ void GLWidget::initializeGL ()
glGenTextures(1, &m_uiTexture);
m_uiTexture = bindTexture(QImage(":/qt.png"));
- QGLShader *vshader1 = new QGLShader(QGLShader::VertexShader, this);
+ QGLShader *vshader1 = new QGLShader(QGLShader::Vertex, this);
const char *vsrc1 =
"attribute highp vec4 vertex;\n"
"attribute mediump vec3 normal;\n"
@@ -188,16 +194,16 @@ void GLWidget::initializeGL ()
" color = clamp(color, 0.0, 1.0);\n"
" gl_Position = matrix * vertex;\n"
"}\n";
- vshader1->compile(vsrc1);
+ vshader1->compileSourceCode(vsrc1);
- QGLShader *fshader1 = new QGLShader(QGLShader::FragmentShader, this);
+ QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);
const char *fsrc1 =
"varying mediump vec4 color;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = color;\n"
"}\n";
- fshader1->compile(fsrc1);
+ fshader1->compileSourceCode(fsrc1);
program1.addShader(vshader1);
program1.addShader(fshader1);
@@ -207,7 +213,7 @@ void GLWidget::initializeGL ()
normalAttr1 = program1.attributeLocation("normal");
matrixUniform1 = program1.uniformLocation("matrix");
- QGLShader *vshader2 = new QGLShader(QGLShader::VertexShader);
+ QGLShader *vshader2 = new QGLShader(QGLShader::Vertex);
const char *vsrc2 =
"attribute highp vec4 vertex;\n"
"attribute highp vec4 texCoord;\n"
@@ -222,9 +228,9 @@ void GLWidget::initializeGL ()
" gl_Position = matrix * vertex;\n"
" texc = texCoord;\n"
"}\n";
- vshader2->compile(vsrc2);
+ vshader2->compileSourceCode(vsrc2);
- QGLShader *fshader2 = new QGLShader(QGLShader::FragmentShader);
+ QGLShader *fshader2 = new QGLShader(QGLShader::Fragment);
const char *fsrc2 =
"varying highp vec4 texc;\n"
"uniform sampler2D tex;\n"
@@ -235,7 +241,7 @@ void GLWidget::initializeGL ()
" color = color * 0.2 + color * 0.8 * angle;\n"
" gl_FragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\n"
"}\n";
- fshader2->compile(fsrc2);
+ fshader2->compileSourceCode(fsrc2);
program2.addShader(vshader2);
program2.addShader(fshader2);
@@ -284,15 +290,15 @@ void GLWidget::paintGL()
modelview.translate(0.0f, -0.2f, 0.0f);
if (qtLogo) {
- program1.enable();
+ program1.bind();
program1.setUniformValue(matrixUniform1, modelview);
paintQtLogo();
- program1.disable();
+ program1.release();
} else {
- program2.enable();
+ program2.bind();
program1.setUniformValue(matrixUniform2, modelview);
paintTexturedCube();
- program2.disable();
+ program2.release();
}
glDisable(GL_DEPTH_TEST);
diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp
index 6efd31a..0f50e2d 100644
--- a/examples/opengl/textures/glwidget.cpp
+++ b/examples/opengl/textures/glwidget.cpp
@@ -99,7 +99,7 @@ void GLWidget::initializeGL()
#define PROGRAM_VERTEX_ATTRIBUTE 0
#define PROGRAM_TEXCOORD_ATTRIBUTE 1
- QGLShader *vshader = new QGLShader(QGLShader::VertexShader, this);
+ QGLShader *vshader = new QGLShader(QGLShader::Vertex, this);
const char *vsrc =
"attribute highp vec4 vertex;\n"
"attribute mediump vec4 texCoord;\n"
@@ -110,9 +110,9 @@ void GLWidget::initializeGL()
" gl_Position = matrix * vertex;\n"
" texc = texCoord;\n"
"}\n";
- vshader->compile(vsrc);
+ vshader->compileSourceCode(vsrc);
- QGLShader *fshader = new QGLShader(QGLShader::FragmentShader, this);
+ QGLShader *fshader = new QGLShader(QGLShader::Fragment, this);
const char *fsrc =
"uniform sampler2D texture;\n"
"varying mediump vec4 texc;\n"
@@ -120,7 +120,7 @@ void GLWidget::initializeGL()
"{\n"
" gl_FragColor = texture2D(texture, texc.st);\n"
"}\n";
- fshader->compile(fsrc);
+ fshader->compileSourceCode(fsrc);
program = new QGLShaderProgram(this);
program->addShader(vshader);
@@ -129,7 +129,7 @@ void GLWidget::initializeGL()
program->bindAttributeLocation("texCoord", PROGRAM_TEXCOORD_ATTRIBUTE);
program->link();
- program->enable();
+ program->bind();
program->setUniformValue("texture", 0);
#endif
@@ -163,6 +163,8 @@ void GLWidget::paintGL()
m.rotate(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
program->setUniformValue("matrix", m);
+ program->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
+ program->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
program->setAttributeArray
(PROGRAM_VERTEX_ATTRIBUTE, vertices.constData());
program->setAttributeArray