Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Shader.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  *
21  * Part of this file comes from SFML, with the same license:
22  * Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23  */
24 #ifndef GF_SHADER_H
25 #define GF_SHADER_H
26 
27 #include <string>
28 #include <map>
29 
30 #include "Matrix.h"
31 #include "Path.h"
32 #include "Portability.h"
33 #include "StringRef.h"
34 #include "Texture.h"
35 #include "Vector.h"
36 
37 namespace gf {
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 inline namespace v1 {
40 #endif
41 
42  class InputStream;
43 
120  class GF_API Shader {
121  public:
125  enum Type {
128  };
129 
135  Shader();
136 
152  Shader(const Path& filename, Type type);
153 
170  Shader(const Path& vertexShaderFilename, const Path& fragmentShaderFilename);
171 
186  Shader(const char *shader, Type type);
187 
204  Shader(const char *vertexShader, const char *fragmentShader);
205 
220  Shader(InputStream& stream, Type type);
221 
237  Shader(InputStream& vertexShaderStream, InputStream& fragmentShaderStream);
238 
242  ~Shader();
243 
247  Shader(const Shader&) = delete;
248 
252  Shader& operator=(const Shader&) = delete;
253 
271  void setUniform(StringRef name, float val);
272 
279  void setUniform(StringRef name, int val);
280 
287  void setUniform(StringRef name, const Vector2f& vec);
288 
295  void setUniform(StringRef name, const Vector3f& vec);
296 
303  void setUniform(StringRef name, const Vector4f& vec);
304 
311  void setUniform(StringRef name, const Vector2i& vec);
312 
319  void setUniform(StringRef name, const Vector3i& vec);
320 
327  void setUniform(StringRef name, const Vector4i& vec);
328 
335  void setUniform(StringRef name, const Matrix3f& mat);
336 
343  void setUniform(StringRef name, const Matrix4f& mat);
344 
371  void setUniform(StringRef name, const BareTexture& tex);
372 
383  static void bind(const Shader *shader);
384 
385  private:
386  friend class RenderTarget;
387  int getUniformLocation(StringRef name);
388  int getAttributeLocation(StringRef name);
389 
390  struct Guard;
391 
392  private:
393  unsigned m_program;
394 
395  std::map<int, const BareTexture *> m_textures;
396  };
397 
398 #ifndef DOXYGEN_SHOULD_SKIP_THIS
399 }
400 #endif
401 }
402 
403 #endif // GF_SHADER_H
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:90
An OpenGL vertex and/or fragment shader.
Definition: Shader.h:120
The namespace for gf classes.
Definition: Action.h:35
An image that lives in the graphic memory that can be used for drawing.
Definition: Texture.h:75
Abstract class for custom file input streams.
Definition: Stream.h:55
boost::filesystem::path Path
A path in the filesystem.
Definition: Path.h:44
Type
Type of shaders.
Definition: Shader.h:125
A constant reference to a string and its size.
Definition: StringRef.h:41
Type for a fragment (or pixel) shader.
Definition: Shader.h:127
Type for a vertex shader.
Definition: Shader.h:126