Documentation of SFML 2.3

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
Shader.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages 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 freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef SFML_SHADER_HPP
26 #define SFML_SHADER_HPP
27 
29 // Headers
31 #include <SFML/Graphics/Export.hpp>
32 #include <SFML/Graphics/Transform.hpp>
33 #include <SFML/Graphics/Color.hpp>
34 #include <SFML/Window/GlResource.hpp>
35 #include <SFML/System/NonCopyable.hpp>
36 #include <SFML/System/Vector2.hpp>
37 #include <SFML/System/Vector3.hpp>
38 #include <map>
39 #include <string>
40 
41 
42 namespace sf
43 {
44 class InputStream;
45 class Texture;
46 
51 class SFML_GRAPHICS_API Shader : GlResource, NonCopyable
52 {
53 public:
54 
59  enum Type
60  {
62  Fragment
63  };
64 
72  struct CurrentTextureType {};
73 
81 
82 public:
83 
90  Shader();
91 
96  ~Shader();
97 
117  bool loadFromFile(const std::string& filename, Type type);
118 
138  bool loadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename);
139 
158  bool loadFromMemory(const std::string& shader, Type type);
159 
179  bool loadFromMemory(const std::string& vertexShader, const std::string& fragmentShader);
180 
199  bool loadFromStream(InputStream& stream, Type type);
200 
220  bool loadFromStream(InputStream& vertexShaderStream, InputStream& fragmentShaderStream);
221 
241  void setParameter(const std::string& name, float x);
242 
263  void setParameter(const std::string& name, float x, float y);
264 
286  void setParameter(const std::string& name, float x, float y, float z);
287 
310  void setParameter(const std::string& name, float x, float y, float z, float w);
311 
331  void setParameter(const std::string& name, const Vector2f& vector);
332 
352  void setParameter(const std::string& name, const Vector3f& vector);
353 
379  void setParameter(const std::string& name, const Color& color);
380 
402  void setParameter(const std::string& name, const sf::Transform& transform);
403 
434  void setParameter(const std::string& name, const Texture& texture);
435 
457  void setParameter(const std::string& name, CurrentTextureType);
458 
469  unsigned int getNativeHandle() const;
470 
492  static void bind(const Shader* shader);
493 
507  static bool isAvailable();
508 
509 private:
510 
523  bool compile(const char* vertexShaderCode, const char* fragmentShaderCode);
524 
532  void bindTextures() const;
533 
542  int getParamLocation(const std::string& name);
543 
545  // Types
547  typedef std::map<int, const Texture*> TextureTable;
548  typedef std::map<std::string, int> ParamTable;
549 
551  // Member data
553  unsigned int m_shaderProgram;
554  int m_currentTexture;
555  TextureTable m_textures;
556  ParamTable m_params;
557 };
558 
559 } // namespace sf
560 
561 
562 #endif // SFML_SHADER_HPP
563 
564 
Special type that can be passed to setParameter, and that represents the texture of the object being ...
Definition: Shader.hpp:72
Utility class for manipulating RGBA colors.
Definition: Color.hpp:40
Abstract class for custom file input streams.
Definition: InputStream.hpp:41
Base class for classes that require an OpenGL context.
Definition: GlResource.hpp:40
Type
Types of shaders.
Definition: Shader.hpp:59
static CurrentTextureType CurrentTexture
Represents the texture of the object being drawn.
Definition: Shader.hpp:80
Define a 3x3 transform matrix.
Definition: Transform.hpp:42
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:47
Shader class (vertex and fragment)
Definition: Shader.hpp:51
Utility template class for manipulating 3-dimensional vectors.
Definition: Vector3.hpp:37
Utility class that makes any derived class non-copyable.
Definition: NonCopyable.hpp:41
Vertex shader.
Definition: Shader.hpp:61