glc_shader.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 *****************************************************************************/
00022 
00024 
00025 #ifndef GLC_SHADER_H_
00026 #define GLC_SHADER_H_
00027 
00028 #include "../glc_global.h"
00029 #include <QGLShader>
00030 #include <QGLShaderProgram>
00031 #include <QStack>
00032 #include <QFile>
00033 #include <QMutex>
00034 #include <QString>
00035 
00036 #include "../glc_config.h"
00037 
00040 
00047 
00048 class GLC_LIB_EXPORT GLC_Shader
00049 {
00051 
00053 
00054 public:
00056         GLC_Shader();
00057 
00059         GLC_Shader(QFile&, QFile&);
00060 
00062         GLC_Shader(const GLC_Shader&);
00063 
00065         ~GLC_Shader();
00067 
00069 
00071 
00072 public:
00074         inline GLuint id() const
00075         {return m_ProgramShaderId;}
00076 
00078         inline bool isUsable() const
00079         {return m_ProgramShader.isLinked();}
00080 
00082         bool canBeDeleted() const;
00083 
00085         inline QString name() const
00086         {return m_Name;}
00087 
00089         inline QGLShaderProgram* programShaderHandle()
00090         {return &m_ProgramShader;}
00091 
00093         static int shaderCount();
00094 
00096         static bool asShader(GLC_uint shadingGroupId);
00097 
00099 
00100         static GLC_Shader* shaderHandle(GLC_uint shadingGroupId);
00101 
00103         static bool hasActiveShader();
00104 
00106 
00107         static GLC_Shader* currentShaderHandle();
00109 
00111 
00113 
00114 public:
00116         void setVertexAndFragmentShader(QFile&, QFile&);
00117 
00119         /* If this shader is usable replacing shader must be usable*/
00120         void replaceShader(const GLC_Shader&);
00121 
00123         inline GLC_Shader& operator=(const GLC_Shader& shader)
00124         {
00125                 replaceShader(shader);
00126                 return *this;
00127         }
00128 
00130         inline void setName(const QString& name)
00131         {m_Name= name;}
00132 
00134 
00136 
00138 
00139 public:
00141 
00142         void use();
00143 
00145 
00146         static bool use(GLuint ShadingGroupId);
00147 
00149         static void unuse();
00150 
00152 
00153         void createAndCompileProgrammShader();
00154 
00156         void deleteShader();
00158 
00160 // private members
00162 private:
00164         static QStack<GLC_uint> m_ShadingGroupStack;
00165 
00167         static GLC_uint m_CurrentShadingGroupId;
00168 
00170         static QHash<GLC_uint, GLC_Shader*> m_ShaderProgramHash;
00171 
00173         QGLShader m_VertexShader;
00174 
00176         QGLShader m_FragmentShader;
00177 
00179         QGLShaderProgram m_ProgramShader;
00180 
00182         GLC_uint m_ProgramShaderId;
00183 
00185         QString m_Name;
00186 
00187 };
00188 
00189 #endif /*GLC_SHADER_H_*/

SourceForge.net Logo

©2005-2011 Laurent Ribon