Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/examples/opengl/textures/glwidget.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the examples of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4343#include <QtOpenGL>
    4444
    45 #include <math.h>
    46 
    4745#include "glwidget.h"
    48 
    49 GLuint GLWidget::sharedObject = 0;
    50 int GLWidget::refCount = 0;
    5146
    5247GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget)
     
    5752    yRot = 0;
    5853    zRot = 0;
     54#ifdef QT_OPENGL_ES_2
     55    program = 0;
     56#endif
    5957}
    6058
    6159GLWidget::~GLWidget()
    6260{
    63     if (--refCount == 0) {
    64         makeCurrent();
    65         glDeleteLists(sharedObject, 1);
    66     }
    6761}
    6862
     
    9387void GLWidget::initializeGL()
    9488{
    95     if (!sharedObject)
    96         sharedObject = makeObject();
    97     ++refCount;
     89    makeObject();
    9890
    9991    glEnable(GL_DEPTH_TEST);
    10092    glEnable(GL_CULL_FACE);
     93#ifndef QT_OPENGL_ES_2
    10194    glEnable(GL_TEXTURE_2D);
     95#endif
     96
     97#ifdef QT_OPENGL_ES_2
     98
     99#define PROGRAM_VERTEX_ATTRIBUTE 0
     100#define PROGRAM_TEXCOORD_ATTRIBUTE 1
     101
     102    QGLShader *vshader = new QGLShader(QGLShader::Vertex, this);
     103    const char *vsrc =
     104        "attribute highp vec4 vertex;\n"
     105        "attribute mediump vec4 texCoord;\n"
     106        "varying mediump vec4 texc;\n"
     107        "uniform mediump mat4 matrix;\n"
     108        "void main(void)\n"
     109        "{\n"
     110        "    gl_Position = matrix * vertex;\n"
     111        "    texc = texCoord;\n"
     112        "}\n";
     113    vshader->compileSourceCode(vsrc);
     114
     115    QGLShader *fshader = new QGLShader(QGLShader::Fragment, this);
     116    const char *fsrc =
     117        "uniform sampler2D texture;\n"
     118        "varying mediump vec4 texc;\n"
     119        "void main(void)\n"
     120        "{\n"
     121        "    gl_FragColor = texture2D(texture, texc.st);\n"
     122        "}\n";
     123    fshader->compileSourceCode(fsrc);
     124
     125    program = new QGLShaderProgram(this);
     126    program->addShader(vshader);
     127    program->addShader(fshader);
     128    program->bindAttributeLocation("vertex", PROGRAM_VERTEX_ATTRIBUTE);
     129    program->bindAttributeLocation("texCoord", PROGRAM_TEXCOORD_ATTRIBUTE);
     130    program->link();
     131
     132    program->bind();
     133    program->setUniformValue("texture", 0);
     134
     135#endif
    102136}
    103137
     
    106140    qglClearColor(clearColor);
    107141    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     142
     143#if !defined(QT_OPENGL_ES_2)
     144
    108145    glLoadIdentity();
    109     glTranslated(0.0, 0.0, -10.0);
    110     glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
    111     glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
    112     glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
    113     glCallList(sharedObject);
     146    glTranslatef(0.0f, 0.0f, -10.0f);
     147    glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
     148    glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
     149    glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
     150
     151    glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
     152    glTexCoordPointer(2, GL_FLOAT, 0, texCoords.constData());
     153    glEnableClientState(GL_VERTEX_ARRAY);
     154    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     155
     156#else
     157
     158    QMatrix4x4 m;
     159    m.ortho(-0.5f, +0.5f, +0.5f, -0.5f, 4.0f, 15.0f);
     160    m.translate(0.0f, 0.0f, -10.0f);
     161    m.rotate(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
     162    m.rotate(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
     163    m.rotate(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
     164
     165    program->setUniformValue("matrix", m);
     166    program->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
     167    program->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
     168    program->setAttributeArray
     169        (PROGRAM_VERTEX_ATTRIBUTE, vertices.constData());
     170    program->setAttributeArray
     171        (PROGRAM_TEXCOORD_ATTRIBUTE, texCoords.constData());
     172
     173#endif
     174
     175    for (int i = 0; i < 6; ++i) {
     176        glBindTexture(GL_TEXTURE_2D, textures[i]);
     177        glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
     178    }
    114179}
    115180
     
    119184    glViewport((width - side) / 2, (height - side) / 2, side, side);
    120185
     186#if !defined(QT_OPENGL_ES_2)
    121187    glMatrixMode(GL_PROJECTION);
    122188    glLoadIdentity();
     189#ifndef QT_OPENGL_ES
    123190    glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
     191#else
     192    glOrthof(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
     193#endif
    124194    glMatrixMode(GL_MODELVIEW);
     195#endif
    125196}
    126197
     
    148219}
    149220
    150 GLuint GLWidget::makeObject()
     221void GLWidget::makeObject()
    151222{
    152223    static const int coords[6][4][3] = {
     
    159230    };
    160231
    161 
    162     GLuint textures[6];
    163     for (int j=0; j < 6; ++j)
    164         textures[j] = bindTexture(QPixmap(QString(":/images/side%1.png").arg(j + 1)),
    165                                   GL_TEXTURE_2D);
    166 
    167     GLuint list = glGenLists(1);
    168     glNewList(list, GL_COMPILE);
     232    for (int j=0; j < 6; ++j) {
     233        textures[j] = bindTexture
     234            (QPixmap(QString(":/images/side%1.png").arg(j + 1)), GL_TEXTURE_2D);
     235    }
     236
    169237    for (int i = 0; i < 6; ++i) {
    170         glBindTexture(GL_TEXTURE_2D, textures[i]);
    171         glBegin(GL_QUADS);
    172238        for (int j = 0; j < 4; ++j) {
    173             glTexCoord2d(j == 0 || j == 3, j == 0 || j == 1);
    174             glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1],
    175                        0.2 * coords[i][j][2]);
     239            texCoords.append
     240                (QVector2D(j == 0 || j == 3, j == 0 || j == 1));
     241            vertices.append
     242                (QVector3D(0.2 * coords[i][j][0], 0.2 * coords[i][j][1],
     243                           0.2 * coords[i][j][2]));
    176244        }
    177         glEnd();
    178     }
    179 
    180     glEndList();
    181     return list;
    182 }
     245    }
     246}
  • trunk/examples/opengl/textures/glwidget.h

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the examples of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4343#define GLWIDGET_H
    4444
     45#include <QtGui>
    4546#include <QGLWidget>
     47
     48class QGLShaderProgram;
    4649
    4750class GLWidget : public QGLWidget
     
    7073
    7174private:
    72     GLuint makeObject();
     75    void makeObject();
    7376
    7477    QColor clearColor;
     
    7780    int yRot;
    7881    int zRot;
    79 
    80     static GLuint sharedObject;
    81     static int refCount;
     82    GLuint textures[6];
     83    QVector<QVector3D> vertices;
     84    QVector<QVector2D> texCoords;
     85#ifdef QT_OPENGL_ES_2
     86    QGLShaderProgram *program;
     87#endif
    8288};
    8389
  • trunk/examples/opengl/textures/main.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the examples of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
  • trunk/examples/opengl/textures/textures.pro

    r2 r561  
    1212sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/textures
    1313INSTALLS += target sources
     14
     15symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
  • trunk/examples/opengl/textures/window.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the examples of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4949    QGridLayout *mainLayout = new QGridLayout;
    5050
    51     glWidgets[0][0] = 0;
    52 
    5351    for (int i = 0; i < NumRows; ++i) {
    5452        for (int j = 0; j < NumColumns; ++j) {
     
    5856                              255, 63);
    5957
    60             glWidgets[i][j] = new GLWidget(0, glWidgets[0][0]);
     58            glWidgets[i][j] = new GLWidget(0, 0);
    6159            glWidgets[i][j]->setClearColor(clearColor);
    6260            glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16);
  • trunk/examples/opengl/textures/window.h

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the examples of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
Note: See TracChangeset for help on using the changeset viewer.