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  Version 2.0.0 Beta 1, packaged on April 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 *****************************************************************************/
00024 
00026 
00027 #ifndef GLC_SHADER_H_
00028 #define GLC_SHADER_H_
00029 
00030 #include "../glc_ext.h"
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_ProgramShader;}
00076 
00078         inline bool isUsable() const
00079         {return m_ProgramShader != 0;}
00080 
00082         bool canBeDeleted() const;
00083 
00085         inline QString name() const
00086         {return m_Name;}
00088 
00090 
00092 
00093 public:
00095         void setVertexAndFragmentShader(QFile&, QFile&);
00096 
00098         /* If this shader is usable replacing shader must be usable*/
00099         void replaceShader(const GLC_Shader&);
00100 
00102         inline GLC_Shader& operator=(const GLC_Shader& shader)
00103         {
00104                 replaceShader(shader);
00105                 return *this;
00106         }
00107 
00109         inline void setName(const QString& name)
00110         {m_Name= name;}
00111 
00113 
00115 
00117 
00118 public:
00120 
00121         void use();
00122 
00124 
00125         static void use(GLuint);
00126 
00128         static void unuse();
00129 
00131 
00132         void createAndCompileProgrammShader();
00133 
00135         void deleteShader();
00136 
00137 private:
00139         void createAndLinkVertexShader();
00140 
00142         void createAndLinkFragmentShader();
00144 
00146 
00148 
00149 
00150         void loadVertexShader();
00151 
00153         void loadFragmentShader();
00154 
00156         void setVertexShader(QFile&);
00157 
00159         void setFragmentShader(QFile&);
00160 
00162         QByteArray readShaderFile(QFile&);
00163 
00164 
00166 
00168 // private members
00170 private:
00172         static QStack<GLuint> m_ProgrammStack;
00173 
00175         static GLuint m_CurrentProgramm;
00176 
00178         static QMutex m_Mutex;
00179 
00181         QByteArray m_VertexByteArray;
00182 
00184         GLuint m_VertexShader;
00185 
00187         QByteArray m_FragmentByteArray;
00188 
00190         GLuint m_FragmentShader;
00191 
00193         GLuint m_ProgramShader;
00194 
00196         QString m_Name;
00197 
00198 };
00199 
00200 #endif /*GLC_SHADER_H_*/

SourceForge.net Logo

©2005 Laurent Ribon