Loading...
Searching...
No Matches
Shader.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
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
38#include <map>
39#include <string>
40
41
42namespace sf
43{
44class InputStream;
45class Texture;
46
52{
53public :
54
59 enum Type
60 {
63 };
64
72
73public :
74
82
88
108 bool loadFromFile(const std::string& filename, Type type);
109
129 bool loadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename);
130
149 bool loadFromMemory(const std::string& shader, Type type);
150
170 bool loadFromMemory(const std::string& vertexShader, const std::string& fragmentShader);
171
190 bool loadFromStream(InputStream& stream, Type type);
191
211 bool loadFromStream(InputStream& vertexShaderStream, InputStream& fragmentShaderStream);
212
232 void setParameter(const std::string& name, float x);
233
254 void setParameter(const std::string& name, float x, float y);
255
277 void setParameter(const std::string& name, float x, float y, float z);
278
301 void setParameter(const std::string& name, float x, float y, float z, float w);
302
322 void setParameter(const std::string& name, const Vector2f& vector);
323
343 void setParameter(const std::string& name, const Vector3f& vector);
344
370 void setParameter(const std::string& name, const Color& color);
371
393 void setParameter(const std::string& name, const sf::Transform& transform);
394
425 void setParameter(const std::string& name, const Texture& texture);
426
448 void setParameter(const std::string& name, CurrentTextureType);
449
471 static void bind(const Shader* shader);
472
483 static bool isAvailable();
484
485private :
486
499 bool compile(const char* vertexShaderCode, const char* fragmentShaderCode);
500
508 void bindTextures() const;
509
518 int getParamLocation(const std::string& name);
519
521 // Types
523 typedef std::map<int, const Texture*> TextureTable;
524 typedef std::map<std::string, int> ParamTable;
525
527 // Member data
529 unsigned int m_shaderProgram;
530 int m_currentTexture;
531 TextureTable m_textures;
532 ParamTable m_params;
533};
534
535} // namespace sf
536
537
538#endif // SFML_SHADER_HPP
539
540
#define SFML_GRAPHICS_API
Utility class for manpulating RGBA colors.
Definition Color.hpp:41
GlResource()
Default constructor.
Abstract class for custom file input streams.
NonCopyable()
Default constructor.
bool loadFromFile(const std::string &filename, Type type)
Load either the vertex or fragment shader from a file.
static void bind(const Shader *shader)
Bind a shader for rendering.
Shader()
Default constructor.
bool loadFromStream(InputStream &stream, Type type)
Load either the vertex or fragment shader from a custom stream.
void setParameter(const std::string &name, const sf::Transform &transform)
Change a matrix parameter of the shader.
void setParameter(const std::string &name, const Vector2f &vector)
Change a 2-components vector parameter of the shader.
bool loadFromStream(InputStream &vertexShaderStream, InputStream &fragmentShaderStream)
Load both the vertex and fragment shaders from custom streams.
void setParameter(const std::string &name, float x)
Change a float parameter of the shader.
~Shader()
Destructor.
void setParameter(const std::string &name, float x, float y, float z)
Change a 3-components vector parameter of the shader.
void setParameter(const std::string &name, const Texture &texture)
Change a texture parameter of the shader.
void setParameter(const std::string &name, const Vector3f &vector)
Change a 3-components vector parameter of the shader.
void setParameter(const std::string &name, const Color &color)
Change a color parameter of the shader.
void setParameter(const std::string &name, float x, float y)
Change a 2-components vector parameter of the shader.
static CurrentTextureType CurrentTexture
Definition Shader.hpp:71
bool loadFromMemory(const std::string &shader, Type type)
Load either the vertex or fragment shader from a source code in memory.
bool loadFromFile(const std::string &vertexShaderFilename, const std::string &fragmentShaderFilename)
Load both the vertex and fragment shaders from files.
static bool isAvailable()
Tell whether or not the system supports shaders.
bool loadFromMemory(const std::string &vertexShader, const std::string &fragmentShader)
Load both the vertex and fragment shaders from source codes in memory.
void setParameter(const std::string &name, float x, float y, float z, float w)
Change a 4-components vector parameter of the shader.
void setParameter(const std::string &name, CurrentTextureType)
Change a texture parameter of the shader.
Type
Types of shaders.
Definition Shader.hpp:60
@ Vertex
Vertex shader.
Definition Shader.hpp:61
@ Fragment
Fragment (pixel) shader.
Definition Shader.hpp:62
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:48
Define a 3x3 transform matrix.
Definition Transform.hpp:43
Vector2< float > Vector2f
Definition Vector2.hpp:255
Vector3< float > Vector3f
Definition Vector3.hpp:256
Special type/value that can be passed to setParameter, and that represents the texture of the object ...
Definition Shader.hpp:70