Stellarium 0.12.3
StelGLSLShader.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2012 Ferdinand Majerech
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELGLSLSHADER_HPP_
21 #define _STELGLSLSHADER_HPP_
22 
23 #include "VecMath.hpp"
24 
146 {
147 public:
151  virtual ~StelGLSLShader(){};
152 
161  virtual bool addVertexShader(const QString& source) = 0;
162 
171  virtual bool addFragmentShader(const QString& source) = 0;
172 
184  virtual bool addVertexShader(const QString& name, const QString& source) = 0;
185 
187  virtual bool hasVertexShader(const QString& name) const = 0;
188 
194  virtual void enableVertexShader(const QString& name) = 0;
195 
201  virtual void disableVertexShader(const QString& name) = 0;
202 
212  virtual bool build() = 0;
213 
221  virtual void unlock() = 0;
222 
227  virtual QString log() const = 0;
228 
236  virtual void bind() = 0;
237 
244  virtual void release() = 0;
245 
274  template<class T>
275  void setUniformValue(const char* const name, T value)
276  {
277  // Calls a virtual function for every type (since we can't have virtual templates).
278  // Unsupported types are asserted out at runtime
279  // (with C++11, static assert should be used instead)
280  setUniformValue_(name, value);
281  }
282 
288  virtual void useUnprojectedPositionAttribute() = 0;
289 
290 protected:
294  template<class T>
295  void setUniformValue_(const char* const name, T value)
296  {
297  Q_UNUSED(name);
298  Q_UNUSED(value);
299  //TODO C++11: use static assert here (for a compile-time error)
300  Q_ASSERT_X(false, Q_FUNC_INFO,
301  "Unsupported uniform data type. "
302  "Supported types: bool, int, float, Vec2f, Vec3f, Vec4f, Mat4f");
303  }
304 
306  virtual void setUniformValue_(const char* const name, const bool value) = 0;
307 
309  virtual void setUniformValue_(const char* const name, const int value) = 0;
310 
312  virtual void setUniformValue_(const char* const name, const float value) = 0;
313 
315  virtual void setUniformValue_(const char* const name, const Vec2f value) = 0;
316 
318  virtual void setUniformValue_(const char* const name, const Vec3f& value) = 0;
319 
321  virtual void setUniformValue_(const char* const name, const Vec4f& value) = 0;
322 
324  virtual void setUniformValue_(const char* const name, const Mat4f& value) = 0;
325 };
326 
327 #endif // _STELGLSLSHADER_HPP_