From afd7ba59f1fd9f14c4b7cd85aba764ef6066d64e Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 15 Sep 2009 16:28:19 +1000 Subject: qdoc: Shift snippets in QGLShaderProgram out into doc/src/snippets --- .../snippets/code/src_opengl_qglshaderprogram.cpp | 92 ++++++++++++++++++++++ src/opengl/qglshaderprogram.cpp | 52 +----------- 2 files changed, 95 insertions(+), 49 deletions(-) create mode 100644 doc/src/snippets/code/src_opengl_qglshaderprogram.cpp diff --git a/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp b/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp new file mode 100644 index 0000000..2997297 --- /dev/null +++ b/doc/src/snippets/code/src_opengl_qglshaderprogram.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +QGLShader shader(QGLShader::VertexShader); +shader.compile(code); + +QGLShaderProgram program(context); +program.addShader(shader); +program.link(); + +program.enable(); +//! [0] + +//! [1] +program.addShader(QGLShader::VertexShader, + "attribute highp vec4 vertex;\n" + "attribute mediump mat4 matrix;\n" + "void main(void)\n" + "{\n" + " gl_Position = matrix * vertex;\n" + "}"); +program.addShader(QGLShader::FragmentShader, + "uniform mediump vec4 color;\n" + "void main(void)\n" + "{\n" + " gl_FragColor = color;\n" + "}"); +program.link(); +program.enable(); + +int vertexLocation = program.attributeLocation("vertex"); +int matrixLocation = program.attributeLocation("matrix"); +int colorLocation = program.uniformLocation("color"); +//! [1] + +//! [2] +static GLfloat const triangleVertices[] = { + 60.0f, 10.0f, 0.0f, + 110.0f, 110.0f, 0.0f, + 10.0f, 110.0f, 0.0f +}; + +QColor color(0, 255, 0, 255); + +QMatrix4x4 pmvMatrix; +pmvMatrix.ortho(rect()); + +program.setAttributeArray(vertexLocation, triangleVertices, 3); +program.setUniformValue(matrixLocation, pmvMatrix); +program.setUniformValue(colorLocation, color); + +glDrawArrays(GL_TRIANGLES, 0, 3); +//! [2] diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp index 0b7fe87..ebcd723 100644 --- a/src/opengl/qglshaderprogram.cpp +++ b/src/opengl/qglshaderprogram.cpp @@ -70,16 +70,7 @@ QT_BEGIN_NAMESPACE program is activated in the current QGLContext by calling QGLShaderProgram::enable(): - \code - QGLShader shader(QGLShader::VertexShader); - shader.compile(code); - - QGLShaderProgram program(context); - program.addShader(shader); - program.link(); - - program.enable(); - \endcode + \snippet doc/src/snippets/code/src_opengl_qglshaderprogram.cpp 0 \section1 Writing portable shaders @@ -107,49 +98,12 @@ QT_BEGIN_NAMESPACE \section1 Simple shader example - \code - program.addShader(QGLShader::VertexShader, - "attribute highp vec4 vertex;\n" - "attribute mediump mat4 matrix;\n" - "void main(void)\n" - "{\n" - " gl_Position = matrix * vertex;\n" - "}"); - program.addShader(QGLShader::FragmentShader, - "uniform mediump vec4 color;\n" - "void main(void)\n" - "{\n" - " gl_FragColor = color;\n" - "}"); - program.link(); - program.enable(); - - int vertexLocation = program.attributeLocation("vertex"); - int matrixLocation = program.attributeLocation("matrix"); - int colorLocation = program.uniformLocation("color"); - \endcode + \snippet doc/src/snippets/code/src_opengl_qglshaderprogram.cpp 1 With the above shader program active, we can draw a green triangle as follows: - \code - static GLfloat const triangleVertices[] = { - 60.0f, 10.0f, 0.0f, - 110.0f, 110.0f, 0.0f, - 10.0f, 110.0f, 0.0f - }; - - QColor color(0, 255, 0, 255); - - QMatrix4x4 pmvMatrix; - pmvMatrix.ortho(rect()); - - program.setAttributeArray(vertexLocation, triangleVertices, 3); - program.setUniformValue(matrixLocation, pmvMatrix); - program.setUniformValue(colorLocation, color); - - glDrawArrays(GL_TRIANGLES, 0, 3); - \endcode + \snippet doc/src/snippets/code/src_opengl_qglshaderprogram.cpp 2 \section1 Partial shaders -- cgit v0.12