GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_shader.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #ifndef GLC_SHADER_H_
26 #define GLC_SHADER_H_
27 
28 #include "../glc_global.h"
29 #include <QGLShader>
30 #include <QGLShaderProgram>
31 #include <QStack>
32 #include <QFile>
33 #include <QMutex>
34 #include <QString>
35 #include <QMap>
36 
37 #include "../glc_config.h"
38 
41 
48 
50 {
52 
54 
55 public:
57  GLC_Shader();
58 
60  GLC_Shader(QFile&, QFile&);
61 
63  GLC_Shader(const GLC_Shader&);
64 
66  ~GLC_Shader();
68 
70 
72 
73 public:
75  inline GLuint id() const
76  {return m_ProgramShaderId;}
77 
79  inline bool isUsable() const
80  {return m_ProgramShader.isLinked();}
81 
83  bool canBeDeleted() const;
84 
86  inline QString name() const
87  {return m_Name;}
88 
90  inline QGLShaderProgram* programShaderHandle()
91  {return &m_ProgramShader;}
92 
94  inline int positionAttributeId() const
95  {return m_PositionAttributeId;}
96 
98  inline int textureAttributeId() const
99  {return m_TextcoordAttributeId;}
100 
102  inline int colorAttributeId() const
103  {return m_ColorAttributeId;}
104 
106  inline int normalAttributeId() const
107  {return m_NormalAttributeId;}
108 
110  static int shaderCount();
111 
113  static bool asShader(GLC_uint shadingGroupId);
114 
116 
117  static GLC_Shader* shaderHandle(GLC_uint shadingGroupId);
118 
120  static bool hasActiveShader();
121 
123 
124  static GLC_Shader* currentShaderHandle();
126 
128 
130 
131 public:
133  void setVertexAndFragmentShader(QFile&, QFile&);
134 
136  /* If this shader is usable replacing shader must be usable*/
137  void replaceShader(const GLC_Shader&);
138 
140  inline GLC_Shader& operator=(const GLC_Shader& shader)
141  {
142  replaceShader(shader);
143  return *this;
144  }
145 
147  inline void setName(const QString& name)
148  {m_Name= name;}
149 
151  inline int modelViewLocationId() const
152  {return m_ModelViewLocationId;}
153 
155  inline int mvpLocationId() const
156  {return m_MvpLocationId;}
157 
159  inline int invModelViewLocationId() const
160  {return m_InvModelViewLocationId;}
161 
163  inline int enableLightingId() const
164  {return m_EnableLightingId;}
165 
167  inline int lightsEnableStateId() const
168  {return m_LightsEnableStateId;}
169 
171  inline int lightPositionId(GLenum lightId) const
172  {return m_LightsPositionId.value(lightId);}
173 
175  inline int lightAmbientColorId(GLenum lightId) const
176  {return m_LightsAmbientColorId.value(lightId);}
177 
179  inline int lightDiffuseColorId(GLenum lightId) const
180  {return m_LightsDiffuseColorId.value(lightId);}
181 
183  inline int lightSpecularColorId(GLenum lightId) const
184  {return m_LightsSpecularColorId.value(lightId);}
185 
187  inline int lightSpotDirectionId(GLenum lightId) const
188  {return m_LightsSpotDirectionId.value(lightId);}
189 
191  inline int lightAttebuationFactorsId(GLenum lightId) const
192  {return m_LightsAttenuationFactorsId.value(lightId);}
193 
195  inline int lightSpotExponentId(GLenum lightId) const
196  {return m_LightsSpotExponentId.value(lightId);}
197 
199  inline int lightSpotCutoffId(GLenum lightId) const
200  {return m_LightsSpotCutoffAngleId.value(lightId);}
201 
203  inline int lightComputeDistanceAttenuationId(GLenum lightId) const
204  {return m_LightsComputeDistanceAttenuationId.value(lightId);}
205 
207 
209 
211 
212 public:
214 
215  void use();
216 
218 
219  static bool use(GLC_uint ShadingGroupId);
220 
222  static void unuse();
223 
225 
226  void createAndCompileProgrammShader();
227 
229  void deleteShader();
231 
233 // private services function
235 private:
237  void initLightsUniformId();
239 // private members
241 private:
243  static QStack<GLC_uint> m_ShadingGroupStack;
244 
247 
249  static QHash<GLC_uint, GLC_Shader*> m_ShaderProgramHash;
250 
252  QGLShader m_VertexShader;
253 
255  QGLShader m_FragmentShader;
256 
258  QGLShaderProgram m_ProgramShader;
259 
262 
264  QString m_Name;
265 
268 
271 
274 
277 
280 
283 
286 
289 
292 
294  QMap<GLenum, int> m_LightsPositionId;
295 
297  QMap<GLenum, int> m_LightsAmbientColorId;
298 
300  QMap<GLenum, int> m_LightsDiffuseColorId;
301 
303  QMap<GLenum, int> m_LightsSpecularColorId;
304 
306  QMap<GLenum, int> m_LightsSpotDirectionId;
307 
309  QMap<GLenum, int> m_LightsAttenuationFactorsId;
310 
312  QMap<GLenum, int> m_LightsSpotExponentId;
313 
315  QMap<GLenum, int> m_LightsSpotCutoffAngleId;
316 
319 
320 };
321 
322 #endif /*GLC_SHADER_H_*/

©2005-2013 Laurent Ribon