summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-05-01 00:14:58 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-05-01 00:14:58 (GMT)
commit815eb1c4793ffc9d11ec160996350610deb4db7d (patch)
treefe24c022bc2411023f873da882e4fc1b599471c2 /demos
parent446085a8b3f22d7e2735b62b4511907e7aaba82a (diff)
parent96e13b0411ed3f4ef8753edafc41503fc9aceb0f (diff)
downloadQt-815eb1c4793ffc9d11ec160996350610deb4db7d.zip
Qt-815eb1c4793ffc9d11ec160996350610deb4db7d.tar.gz
Qt-815eb1c4793ffc9d11ec160996350610deb4db7d.tar.bz2
Merge branch 'shaderprograms' of git@scm.dev.nokia.troll.no:qt/rweathers-shaderprograms into shader-api
Conflicts: src/gui/math3d/math3d.pri src/gui/math3d/qgenericmatrix.cpp src/gui/math3d/qgenericmatrix.h src/gui/math3d/qmatrix4x4.cpp src/gui/math3d/qmatrix4x4.h src/gui/math3d/qquaternion.cpp src/gui/math3d/qquaternion.h src/gui/math3d/qvector2d.cpp src/gui/math3d/qvector2d.h src/gui/math3d/qvector3d.cpp src/gui/math3d/qvector3d.h src/gui/math3d/qvector4d.cpp src/gui/math3d/qvector4d.h src/opengl/opengl.pro tests/auto/math3d/math3d.pro tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp tests/auto/math3d/qquaternion/tst_qquaternion.cpp tests/auto/math3d/qvectornd/tst_qvectornd.cpp tests/auto/math3d/shared/math3dincludes.h
Diffstat (limited to 'demos')
-rw-r--r--demos/boxes/boxes.pro2
-rw-r--r--demos/boxes/glextensions.cpp37
-rw-r--r--demos/boxes/glextensions.h85
-rw-r--r--demos/boxes/glshaders.cpp266
-rw-r--r--demos/boxes/glshaders.h108
-rw-r--r--demos/boxes/scene.cpp102
-rw-r--r--demos/boxes/scene.h11
7 files changed, 61 insertions, 550 deletions
diff --git a/demos/boxes/boxes.pro b/demos/boxes/boxes.pro
index 6c1a331..a7b19a3 100644
--- a/demos/boxes/boxes.pro
+++ b/demos/boxes/boxes.pro
@@ -11,7 +11,6 @@ INCLUDEPATH += .
HEADERS += 3rdparty/fbm.h \
glbuffers.h \
glextensions.h \
- glshaders.h \
gltrianglemesh.h \
qtbox.h \
roundedbox.h \
@@ -21,7 +20,6 @@ HEADERS += 3rdparty/fbm.h \
SOURCES += 3rdparty/fbm.c \
glbuffers.cpp \
glextensions.cpp \
- glshaders.cpp \
main.cpp \
qtbox.cpp \
roundedbox.cpp \
diff --git a/demos/boxes/glextensions.cpp b/demos/boxes/glextensions.cpp
index 59256a8..5f168b6 100644
--- a/demos/boxes/glextensions.cpp
+++ b/demos/boxes/glextensions.cpp
@@ -47,23 +47,6 @@ bool GLExtensionFunctions::resolve(const QGLContext *context)
{
bool ok = true;
- RESOLVE_GL_FUNC(CreateShaderObjectARB)
- RESOLVE_GL_FUNC(ShaderSourceARB)
- RESOLVE_GL_FUNC(CompileShaderARB)
- RESOLVE_GL_FUNC(GetObjectParameterivARB)
- RESOLVE_GL_FUNC(DeleteObjectARB)
- RESOLVE_GL_FUNC(GetInfoLogARB)
- RESOLVE_GL_FUNC(CreateProgramObjectARB)
- RESOLVE_GL_FUNC(AttachObjectARB)
- RESOLVE_GL_FUNC(DetachObjectARB)
- RESOLVE_GL_FUNC(LinkProgramARB)
- RESOLVE_GL_FUNC(UseProgramObjectARB)
- RESOLVE_GL_FUNC(GetUniformLocationARB)
- RESOLVE_GL_FUNC(Uniform1iARB)
- RESOLVE_GL_FUNC(Uniform1fARB)
- RESOLVE_GL_FUNC(Uniform4fARB)
- RESOLVE_GL_FUNC(UniformMatrix4fvARB)
-
RESOLVE_GL_FUNC(GenFramebuffersEXT)
RESOLVE_GL_FUNC(GenRenderbuffersEXT)
RESOLVE_GL_FUNC(BindRenderbufferEXT)
@@ -88,26 +71,6 @@ bool GLExtensionFunctions::resolve(const QGLContext *context)
return ok;
}
-bool GLExtensionFunctions::glslSupported() {
- return CreateShaderObjectARB
- && CreateShaderObjectARB
- && ShaderSourceARB
- && CompileShaderARB
- && GetObjectParameterivARB
- && DeleteObjectARB
- && GetInfoLogARB
- && CreateProgramObjectARB
- && AttachObjectARB
- && DetachObjectARB
- && LinkProgramARB
- && UseProgramObjectARB
- && GetUniformLocationARB
- && Uniform1iARB
- && Uniform1fARB
- && Uniform4fARB
- && UniformMatrix4fvARB;
-}
-
bool GLExtensionFunctions::fboSupported() {
return GenFramebuffersEXT
&& GenRenderbuffersEXT
diff --git a/demos/boxes/glextensions.h b/demos/boxes/glextensions.h
index 74617d6..4755532 100644
--- a/demos/boxes/glextensions.h
+++ b/demos/boxes/glextensions.h
@@ -47,23 +47,6 @@
/*
Functions resolved:
-glCreateShaderObjectARB
-glShaderSourceARB
-glCompileShaderARB
-glGetObjectParameterivARB
-glDeleteObjectARB
-glGetInfoLogARB
-glCreateProgramObjectARB
-glAttachObjectARB
-glDetachObjectARB
-glLinkProgramARB
-glUseProgramObjectARB
-glGetUniformLocationARB
-glUniform1iARB
-glUniform1fARB
-glUniform4fARB
-glUniformMatrix4fvARB
-
glGenFramebuffersEXT
glGenRenderbuffersEXT
glBindRenderbufferEXT
@@ -136,39 +119,6 @@ typedef ptrdiff_t GLsizeiptr;
#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
#endif
-#ifndef GL_ARB_vertex_shader
-#define GL_VERTEX_SHADER_ARB 0x8B31
-#endif
-
-#ifndef GL_ARB_fragment_shader
-#define GL_FRAGMENT_SHADER_ARB 0x8B30
-#endif
-
-#ifndef GL_ARB_shader_objects
-typedef char GLcharARB;
-typedef unsigned int GLhandleARB;
-#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81
-#define GL_OBJECT_LINK_STATUS_ARB 0x8B82
-#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84
-#endif
-
-typedef GLhandleARB (APIENTRY *_glCreateShaderObjectARB) (GLenum);
-typedef void (APIENTRY *_glShaderSourceARB) (GLhandleARB, GLuint, const GLcharARB**, GLint *);
-typedef void (APIENTRY *_glCompileShaderARB) (GLhandleARB);
-typedef void (APIENTRY *_glGetObjectParameterivARB) (GLhandleARB, GLenum, int *);
-typedef void (APIENTRY *_glDeleteObjectARB) (GLhandleARB);
-typedef void (APIENTRY *_glGetInfoLogARB) (GLhandleARB, GLsizei, GLsizei *, GLcharARB *);
-typedef GLhandleARB (APIENTRY *_glCreateProgramObjectARB) ();
-typedef void (APIENTRY *_glAttachObjectARB) (GLhandleARB, GLhandleARB);
-typedef void (APIENTRY *_glDetachObjectARB) (GLhandleARB, GLhandleARB);
-typedef void (APIENTRY *_glLinkProgramARB) (GLhandleARB);
-typedef void (APIENTRY *_glUseProgramObjectARB) (GLhandleARB);
-typedef GLint (APIENTRY *_glGetUniformLocationARB) (GLhandleARB, const GLcharARB *);
-typedef void (APIENTRY *_glUniform1iARB) (GLint, GLint);
-typedef void (APIENTRY *_glUniform1fARB) (GLint, GLfloat);
-typedef void (APIENTRY *_glUniform4fARB) (GLint, GLfloat, GLfloat, GLfloat, GLfloat);
-typedef void (APIENTRY *_glUniformMatrix4fvARB) (GLint, GLuint, GLboolean, const GLfloat *);
-
typedef void (APIENTRY *_glGenFramebuffersEXT) (GLsizei, GLuint *);
typedef void (APIENTRY *_glGenRenderbuffersEXT) (GLsizei, GLuint *);
typedef void (APIENTRY *_glBindRenderbufferEXT) (GLenum, GLuint);
@@ -194,27 +144,9 @@ struct GLExtensionFunctions
{
bool resolve(const QGLContext *context);
- bool glslSupported();
bool fboSupported();
bool openGL15Supported(); // the rest: multi-texture, 3D-texture, vertex buffer objects
- _glCreateShaderObjectARB CreateShaderObjectARB;
- _glShaderSourceARB ShaderSourceARB;
- _glCompileShaderARB CompileShaderARB;
- _glGetObjectParameterivARB GetObjectParameterivARB;
- _glDeleteObjectARB DeleteObjectARB;
- _glGetInfoLogARB GetInfoLogARB;
- _glCreateProgramObjectARB CreateProgramObjectARB;
- _glAttachObjectARB AttachObjectARB;
- _glDetachObjectARB DetachObjectARB;
- _glLinkProgramARB LinkProgramARB;
- _glUseProgramObjectARB UseProgramObjectARB;
- _glGetUniformLocationARB GetUniformLocationARB;
- _glUniform1iARB Uniform1iARB;
- _glUniform1fARB Uniform1fARB;
- _glUniform4fARB Uniform4fARB;
- _glUniformMatrix4fvARB UniformMatrix4fvARB;
-
_glGenFramebuffersEXT GenFramebuffersEXT;
_glGenRenderbuffersEXT GenRenderbuffersEXT;
_glBindRenderbufferEXT BindRenderbufferEXT;
@@ -243,23 +175,6 @@ inline GLExtensionFunctions &getGLExtensionFunctions()
return funcs;
}
-#define glCreateShaderObjectARB getGLExtensionFunctions().CreateShaderObjectARB
-#define glShaderSourceARB getGLExtensionFunctions().ShaderSourceARB
-#define glCompileShaderARB getGLExtensionFunctions().CompileShaderARB
-#define glGetObjectParameterivARB getGLExtensionFunctions().GetObjectParameterivARB
-#define glDeleteObjectARB getGLExtensionFunctions().DeleteObjectARB
-#define glGetInfoLogARB getGLExtensionFunctions().GetInfoLogARB
-#define glCreateProgramObjectARB getGLExtensionFunctions().CreateProgramObjectARB
-#define glAttachObjectARB getGLExtensionFunctions().AttachObjectARB
-#define glDetachObjectARB getGLExtensionFunctions().DetachObjectARB
-#define glLinkProgramARB getGLExtensionFunctions().LinkProgramARB
-#define glUseProgramObjectARB getGLExtensionFunctions().UseProgramObjectARB
-#define glGetUniformLocationARB getGLExtensionFunctions().GetUniformLocationARB
-#define glUniform1iARB getGLExtensionFunctions().Uniform1iARB
-#define glUniform1fARB getGLExtensionFunctions().Uniform1fARB
-#define glUniform4fARB getGLExtensionFunctions().Uniform4fARB
-#define glUniformMatrix4fvARB getGLExtensionFunctions().UniformMatrix4fvARB
-
#define glGenFramebuffersEXT getGLExtensionFunctions().GenFramebuffersEXT
#define glGenRenderbuffersEXT getGLExtensionFunctions().GenRenderbuffersEXT
#define glBindRenderbufferEXT getGLExtensionFunctions().BindRenderbufferEXT
diff --git a/demos/boxes/glshaders.cpp b/demos/boxes/glshaders.cpp
deleted file mode 100644
index b6999a8..0000000
--- a/demos/boxes/glshaders.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the demonstration applications 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 either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** 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.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glshaders.h"
-
-#define GLSHADERS_ASSERT_OPENGL(prefix, assertion, returnStatement) \
-if (m_failed || !(assertion)) { \
- if (!m_failed) qCritical(prefix ": The necessary OpenGL functions are not available."); \
- m_failed = true; \
- returnStatement; \
-}
-
-
-GLShader::GLShader(const char *data, int size, GLenum shaderType)
-: m_compileError(false), m_failed(false)
-{
- GLSHADERS_ASSERT_OPENGL("GLShader::GLShader",
- glCreateShaderObjectARB && glShaderSourceARB && glCompileShaderARB && glGetObjectParameterivARB, return)
-
- m_shader = glCreateShaderObjectARB(shaderType);
-
- GLint glSize = size;
- glShaderSourceARB(m_shader, 1, &data, &glSize);
- glCompileShaderARB(m_shader);
- int status;
- glGetObjectParameterivARB(m_shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
- m_compileError = (status != 1);
-}
-
-GLShader::GLShader(const QString& fileName, GLenum shaderType)
- : m_compileError(false), m_failed(false)
-{
- GLSHADERS_ASSERT_OPENGL("GLShader::GLShader",
- glCreateShaderObjectARB && glShaderSourceARB && glCompileShaderARB && glGetObjectParameterivARB, return)
-
- m_shader = glCreateShaderObjectARB(shaderType);
-
- QFile file(fileName);
- if (file.open(QIODevice::ReadOnly)) {
- QByteArray bytes = file.readAll();
- GLint size = file.size();
- const char *p = bytes.data();
- file.close();
- glShaderSourceARB(m_shader, 1, &p, &size);
- glCompileShaderARB(m_shader);
- int status;
- glGetObjectParameterivARB(m_shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
- m_compileError = (status != 1);
- } else {
- m_compileError = true;
- }
-}
-
-GLShader::~GLShader()
-{
- GLSHADERS_ASSERT_OPENGL("GLShader::~GLShader", glDeleteObjectARB, return)
-
- glDeleteObjectARB(m_shader);
-}
-
-QString GLShader::log()
-{
- GLSHADERS_ASSERT_OPENGL("GLShader::log", glGetObjectParameterivARB
- && glGetInfoLogARB, return QLatin1String("GLSL not supported."))
-
- int length;
- glGetObjectParameterivARB(m_shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
- char *log = new char[length + 1];
- GLsizei glLength = length;
- glGetInfoLogARB(m_shader, glLength, &glLength, log);
- log[glLength] = '\0';
- QString result(log);
- delete log;
- return result;
-}
-
-GLVertexShader::GLVertexShader(const char *data, int size) : GLShader(data, size, GL_VERTEX_SHADER_ARB)
-{
-}
-
-GLVertexShader::GLVertexShader(const QString& fileName) : GLShader(fileName, GL_VERTEX_SHADER_ARB)
-{
-}
-
-GLFragmentShader::GLFragmentShader(const char *data, int size) : GLShader(data, size, GL_FRAGMENT_SHADER_ARB)
-{
-}
-
-GLFragmentShader::GLFragmentShader(const QString& fileName) : GLShader(fileName, GL_FRAGMENT_SHADER_ARB)
-{
-}
-
-GLProgram::GLProgram() : m_linked(false), m_linkError(false), m_failed(false)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::GLProgram", glCreateProgramObjectARB, return)
-
- m_program = glCreateProgramObjectARB();
-}
-
-GLProgram::~GLProgram()
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::~GLProgram", glDeleteObjectARB, return)
-
- glDeleteObjectARB(m_program);
-}
-
-void GLProgram::attach(const GLShader &shader)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::attach", glAttachObjectARB, return)
-
- glAttachObjectARB(m_program, shader.m_shader);
- m_linked = m_linkError = false;
-}
-
-void GLProgram::detach(const GLShader &shader)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::detach", glDetachObjectARB, return)
-
- glDetachObjectARB(m_program, shader.m_shader);
- m_linked = m_linkError = false;
-}
-
-bool GLProgram::failed()
-{
- if (m_failed || m_linkError)
- return true;
-
- if (m_linked)
- return false;
-
- GLSHADERS_ASSERT_OPENGL("GLProgram::failed", glLinkProgramARB && glGetObjectParameterivARB, return true)
-
- glLinkProgramARB(m_program);
- int status;
- glGetObjectParameterivARB(m_program, GL_OBJECT_LINK_STATUS_ARB, &status);
- m_linkError = !(m_linked = (status == 1));
- return m_linkError;
-}
-
-QString GLProgram::log()
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::log", glGetObjectParameterivARB && glGetInfoLogARB,
- return QLatin1String("Failed."))
-
- int length;
- glGetObjectParameterivARB(m_program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
- char *log = new char[length + 1];
- GLsizei glLength = length;
- glGetInfoLogARB(m_program, glLength, &glLength, log);
- log[glLength] = '\0';
- QString result(log);
- delete log;
- return result;
-}
-
-void GLProgram::bind()
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::bind", glUseProgramObjectARB, return)
-
- if (!failed())
- glUseProgramObjectARB(m_program);
-}
-
-void GLProgram::unbind()
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::bind", glUseProgramObjectARB, return)
-
- glUseProgramObjectARB(0);
-}
-
-bool GLProgram::hasParameter(const QString& name)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::hasParameter", glGetUniformLocationARB, return false)
-
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- return -1 != glGetUniformLocationARB(m_program, asciiName.data());
- }
- return false;
-}
-
-void GLProgram::setInt(const QString& name, int value)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::setInt", glGetUniformLocationARB && glUniform1iARB, return)
-
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- int loc = glGetUniformLocationARB(m_program, asciiName.data());
- glUniform1iARB(loc, value);
- }
-}
-
-void GLProgram::setFloat(const QString& name, float value)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::setFloat", glGetUniformLocationARB && glUniform1fARB, return)
-
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- int loc = glGetUniformLocationARB(m_program, asciiName.data());
- glUniform1fARB(loc, value);
- }
-}
-
-void GLProgram::setColor(const QString& name, QRgb value)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::setColor", glGetUniformLocationARB && glUniform4fARB, return)
-
- //qDebug() << "Setting color" << name;
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- int loc = glGetUniformLocationARB(m_program, asciiName.data());
- //qDebug() << "Location of" << name << "is" << loc;
- QColor color(value);
- glUniform4fARB(loc, color.redF(), color.greenF(), color.blueF(), color.alphaF());
- }
-}
-
-void GLProgram::setMatrix(const QString& name, const gfx::Matrix4x4f &mat)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::setMatrix", glGetUniformLocationARB && glUniformMatrix4fvARB, return)
-
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- int loc = glGetUniformLocationARB(m_program, asciiName.data());
- //qDebug() << "Location of" << name << "is" << loc;
- glUniformMatrix4fvARB(loc, 1, GL_FALSE, mat.bits());
- }
-} \ No newline at end of file
diff --git a/demos/boxes/glshaders.h b/demos/boxes/glshaders.h
deleted file mode 100644
index 2b6209a..0000000
--- a/demos/boxes/glshaders.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the demonstration applications 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 either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** 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.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GLSHADERS_H
-#define GLSHADERS_H
-
-//#include <GL/glew.h>
-#include "glextensions.h"
-
-#include <QtGui>
-#include <QtOpenGL>
-
-#include "vector.h"
-
-class GLShader
-{
-public:
- friend class GLProgram;
- virtual ~GLShader();
- bool failed() const {return m_failed;}
- QString log();
-protected:
- GLShader(const char *data, int size, GLenum shaderType);
- GLShader(const QString& fileName, GLenum shaderType);
-
- GLhandleARB m_shader;
- bool m_compileError;
- bool m_failed;
-};
-
-class GLVertexShader : public GLShader
-{
-public:
- GLVertexShader(const char *data, int size);
- GLVertexShader(const QString& fileName);
-};
-
-class GLFragmentShader : public GLShader
-{
-public:
- GLFragmentShader(const char *data, int size);
- GLFragmentShader(const QString& fileName);
-};
-
-class GLProgram
-{
-public:
- GLProgram();
- ~GLProgram();
- void attach(const GLShader &shader);
- void detach(const GLShader &shader);
- void bind();
- void unbind();
- bool failed();
- QString log();
- bool hasParameter(const QString& name);
- // use program before setting values
- void setInt(const QString& name, int value);
- void setFloat(const QString& name, float value);
- void setColor(const QString& name, QRgb value);
- void setMatrix(const QString& name, const gfx::Matrix4x4f &mat);
- // TODO: add a bunch of set-functions for different types.
-private:
- GLhandleARB m_program;
- bool m_linked;
- bool m_linkError;
- bool m_failed;
-};
-
-#endif
diff --git a/demos/boxes/scene.cpp b/demos/boxes/scene.cpp
index 1040e17..e5aab75 100644
--- a/demos/boxes/scene.cpp
+++ b/demos/boxes/scene.cpp
@@ -531,11 +531,11 @@ Scene::~Scene()
if (texture) delete texture;
if (m_mainCubemap)
delete m_mainCubemap;
- foreach (GLProgram *program, m_programs)
+ foreach (QGLShaderProgram *program, m_programs)
if (program) delete program;
if (m_vertexShader)
delete m_vertexShader;
- foreach (GLFragmentShader *shader, m_fragmentShaders)
+ foreach (QGLShader *shader, m_fragmentShaders)
if (shader) delete shader;
foreach (GLRenderTargetCube *rt, m_cubemaps)
if (rt) delete rt;
@@ -549,16 +549,18 @@ void Scene::initGL()
{
m_box = new GLRoundedBox(0.25f, 1.0f, 10);
- m_vertexShader = new GLVertexShader(":/res/boxes/basic.vsh");
+ m_vertexShader = new QGLShader(":/res/boxes/basic.vsh", QGLShader::VertexShader);
QStringList list;
list << ":/res/boxes/cubemap_posx.jpg" << ":/res/boxes/cubemap_negx.jpg" << ":/res/boxes/cubemap_posy.jpg"
<< ":/res/boxes/cubemap_negy.jpg" << ":/res/boxes/cubemap_posz.jpg" << ":/res/boxes/cubemap_negz.jpg";
m_environment = new GLTextureCube(list, qMin(1024, m_maxTextureSize));
- m_environmentShader = new GLFragmentShader(environmentShaderText, strlen(environmentShaderText));
- m_environmentProgram = new GLProgram;
- m_environmentProgram->attach(*m_vertexShader);
- m_environmentProgram->attach(*m_environmentShader);
+ m_environmentShader = new QGLShader(QGLShader::FragmentShader);
+ m_environmentShader->setSourceCode(environmentShaderText);
+ m_environmentProgram = new QGLShaderProgram;
+ m_environmentProgram->addShader(m_vertexShader);
+ m_environmentProgram->addShader(m_environmentShader);
+ m_environmentProgram->link();
const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed
m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE);
@@ -610,19 +612,19 @@ void Scene::initGL()
filter = QStringList("*.fsh");
files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable);
foreach (QFileInfo file, files) {
- GLProgram *program = new GLProgram;
- GLFragmentShader* shader = new GLFragmentShader(file.absoluteFilePath());
+ QGLShaderProgram *program = new QGLShaderProgram;
+ QGLShader* shader = new QGLShader(file.absoluteFilePath(), QGLShader::FragmentShader);
// The program does not take ownership over the shaders, so store them in a vector so they can be deleted afterwards.
- program->attach(*m_vertexShader);
- program->attach(*shader);
- if (program->failed()) {
+ program->addShader(m_vertexShader);
+ program->addShader(shader);
+ if (!program->link()) {
qWarning("Failed to compile and link shader program");
qWarning("Vertex shader log:");
- qWarning() << m_vertexShader->log();
+ qWarning() << m_vertexShader->errors();
qWarning() << "Fragment shader log ( file =" << file.absoluteFilePath() << "):";
- qWarning() << shader->log();
+ qWarning() << shader->errors();
qWarning("Shader program log:");
- qWarning() << program->log();
+ qWarning() << program->errors();
delete shader;
delete program;
@@ -633,13 +635,13 @@ void Scene::initGL()
m_programs << program;
m_renderOptions->addShader(file.baseName());
- program->bind();
- m_cubemaps << (program->hasParameter("env") ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
- program->unbind();
+ program->enable();
+ m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
+ program->disable();
}
if (m_programs.size() == 0)
- m_programs << new GLProgram;
+ m_programs << new QGLShaderProgram;
m_renderOptions->emitParameterChanged();
}
@@ -674,12 +676,12 @@ void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
// Don't render the environment if the environment texture can't be set for the correct sampler.
if (glActiveTexture) {
m_environment->bind();
- m_environmentProgram->bind();
- m_environmentProgram->setInt("tex", 0);
- m_environmentProgram->setInt("env", 1);
- m_environmentProgram->setInt("noise", 2);
+ m_environmentProgram->enable();
+ m_environmentProgram->setUniformValue("tex", 0);
+ m_environmentProgram->setUniformValue("env", 1);
+ m_environmentProgram->setUniformValue("noise", 2);
m_box->draw();
- m_environmentProgram->unbind();
+ m_environmentProgram->disable();
m_environment->unbind();
}
@@ -707,14 +709,18 @@ void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
else
m_environment->bind();
}
- m_programs[i]->bind();
- m_programs[i]->setInt("tex", 0);
- m_programs[i]->setInt("env", 1);
- m_programs[i]->setInt("noise", 2);
- m_programs[i]->setMatrix("view", view);
- m_programs[i]->setMatrix("invView", invView);
+ m_programs[i]->enable();
+ m_programs[i]->setUniformValue("tex", 0);
+ m_programs[i]->setUniformValue("env", 1);
+ m_programs[i]->setUniformValue("noise", 2);
+ QMatrix4x4 mview;
+ QMatrix4x4 minvview;
+ memcpy(mview.data(), view.bits(), sizeof(float) * 16);
+ memcpy(minvview.data(), invView.bits(), sizeof(float) * 16);
+ m_programs[i]->setUniformValue("view", mview);
+ m_programs[i]->setUniformValue("invView", minvview);
m_box->draw();
- m_programs[i]->unbind();
+ m_programs[i]->disable();
if (glActiveTexture) {
if (m_dynamicCubemap && m_cubemaps[i])
@@ -737,14 +743,18 @@ void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
m_environment->bind();
}
- m_programs[m_currentShader]->bind();
- m_programs[m_currentShader]->setInt("tex", 0);
- m_programs[m_currentShader]->setInt("env", 1);
- m_programs[m_currentShader]->setInt("noise", 2);
- m_programs[m_currentShader]->setMatrix("view", view);
- m_programs[m_currentShader]->setMatrix("invView", invView);
+ m_programs[m_currentShader]->enable();
+ m_programs[m_currentShader]->setUniformValue("tex", 0);
+ m_programs[m_currentShader]->setUniformValue("env", 1);
+ m_programs[m_currentShader]->setUniformValue("noise", 2);
+ QMatrix4x4 mview;
+ QMatrix4x4 minvview;
+ memcpy(mview.data(), view.bits(), sizeof(float) * 16);
+ memcpy(minvview.data(), invView.bits(), sizeof(float) * 16);
+ m_programs[m_currentShader]->setUniformValue("view", mview);
+ m_programs[m_currentShader]->setUniformValue("invView", minvview);
m_box->draw();
- m_programs[m_currentShader]->unbind();
+ m_programs[m_currentShader]->disable();
if (glActiveTexture) {
if (m_dynamicCubemap)
@@ -1021,20 +1031,20 @@ void Scene::toggleDynamicCubemap(int state)
void Scene::setColorParameter(const QString &name, QRgb color)
{
// set the color in all programs
- foreach (GLProgram *program, m_programs) {
- program->bind();
- program->setColor(name, color);
- program->unbind();
+ foreach (QGLShaderProgram *program, m_programs) {
+ program->enable();
+ program->setUniformValue(program->uniformLocation(name), QColor(color));
+ program->disable();
}
}
void Scene::setFloatParameter(const QString &name, float value)
{
// set the color in all programs
- foreach (GLProgram *program, m_programs) {
- program->bind();
- program->setFloat(name, value);
- program->unbind();
+ foreach (QGLShaderProgram *program, m_programs) {
+ program->enable();
+ program->setUniformValue(program->uniformLocation(name), value);
+ program->disable();
}
}
diff --git a/demos/boxes/scene.h b/demos/boxes/scene.h
index 2db9317..c056739 100644
--- a/demos/boxes/scene.h
+++ b/demos/boxes/scene.h
@@ -53,7 +53,6 @@
#include "vector.h"
#include "trackball.h"
#include "glbuffers.h"
-#include "glshaders.h"
#include "qtbox.h"
#define PI 3.14159265358979
@@ -231,11 +230,11 @@ private:
GLTexture3D *m_noise;
GLRenderTargetCube *m_mainCubemap;
QVector<GLRenderTargetCube *> m_cubemaps;
- QVector<GLProgram *> m_programs;
- GLVertexShader *m_vertexShader;
- QVector<GLFragmentShader *> m_fragmentShaders;
- GLFragmentShader *m_environmentShader;
- GLProgram *m_environmentProgram;
+ QVector<QGLShaderProgram *> m_programs;
+ QGLShader *m_vertexShader;
+ QVector<QGLShader *> m_fragmentShaders;
+ QGLShader *m_environmentShader;
+ QGLShaderProgram *m_environmentProgram;
};