25#ifndef SFML_SHADER_HPP
26#define SFML_SHADER_HPP
31#include <SFML/Graphics/Export.hpp>
32#include <SFML/Graphics/Glsl.hpp>
33#include <SFML/Window/GlResource.hpp>
34#include <SFML/System/NonCopyable.hpp>
35#include <SFML/System/Vector2.hpp>
36#include <SFML/System/Vector3.hpp>
140 bool loadFromFile(
const std::string& vertexShaderFilename,
const std::string& fragmentShaderFilename);
162 bool loadFromFile(
const std::string& vertexShaderFilename,
const std::string& geometryShaderFilename,
const std::string& fragmentShaderFilename);
203 bool loadFromMemory(
const std::string& vertexShader,
const std::string& fragmentShader);
225 bool loadFromMemory(
const std::string& vertexShader,
const std::string& geometryShader,
const std::string& fragmentShader);
496 void setUniformArray(
const std::string& name,
const float* scalarArray, std::size_t length);
562 SFML_DEPRECATED
void setParameter(
const std::string& name,
float x,
float y);
570 SFML_DEPRECATED
void setParameter(
const std::string& name,
float x,
float y,
float z);
578 SFML_DEPRECATED
void setParameter(
const std::string& name,
float x,
float y,
float z,
float w);
709 bool compile(
const char* vertexShaderCode,
const char* geometryShaderCode,
const char* fragmentShaderCode);
718 void bindTextures()
const;
728 int getUniformLocation(
const std::string& name);
737 struct UniformBinder;
742 typedef std::map<int, const Texture*> TextureTable;
743 typedef std::map<std::string, int> UniformTable;
748 unsigned int m_shaderProgram;
749 int m_currentTexture;
750 TextureTable m_textures;
751 UniformTable m_uniforms;
Utility class for manipulating RGBA colors.
Base class for classes that require an OpenGL context.
Utility class that makes any derived class non-copyable.
Shader class (vertex, geometry and fragment)
bool loadFromFile(const std::string &filename, Type type)
Load the vertex, geometry or fragment shader from a file.
void setUniformArray(const std::string &name, const Glsl::Mat4 *matrixArray, std::size_t length)
Specify values for mat4[] array uniform.
static void bind(const Shader *shader)
Bind a shader for rendering.
Shader()
Default constructor.
bool loadFromFile(const std::string &vertexShaderFilename, const std::string &geometryShaderFilename, const std::string &fragmentShaderFilename)
Load the vertex, geometry and fragment shaders from files.
void setUniform(const std::string &name, const Glsl::Ivec2 &vector)
Specify value for ivec2 uniform.
bool loadFromStream(InputStream &stream, Type type)
Load the vertex, geometry or fragment shader from a custom stream.
void setUniform(const std::string &name, const Glsl::Ivec4 &vector)
Specify value for ivec4 uniform.
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.
static bool isGeometryAvailable()
Tell whether or not the system supports geometry shaders.
void setParameter(const std::string &name, float x)
Change a float parameter of the shader.
void setUniform(const std::string &name, const Glsl::Vec2 &vector)
Specify value for vec2 uniform.
void setUniformArray(const std::string &name, const Glsl::Mat3 *matrixArray, std::size_t length)
Specify values for mat3[] array uniform.
void setUniformArray(const std::string &name, const float *scalarArray, std::size_t length)
Specify values for float[] array uniform.
void setUniform(const std::string &name, const Texture &texture)
Specify a texture as sampler2D uniform.
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 Transform &transform)
Change a matrix parameter of the shader.
void setParameter(const std::string &name, const Vector3f &vector)
Change a 3-components vector parameter of the shader.
void setUniform(const std::string &name, const Glsl::Ivec3 &vector)
Specify value for ivec3 uniform.
bool loadFromStream(InputStream &vertexShaderStream, InputStream &geometryShaderStream, InputStream &fragmentShaderStream)
Load the vertex, geometry and fragment shaders from custom streams.
void setParameter(const std::string &name, const Color &color)
Change a color parameter of the shader.
void setUniformArray(const std::string &name, const Glsl::Vec4 *vectorArray, std::size_t length)
Specify values for vec4[] array uniform.
void setUniform(const std::string &name, const Glsl::Vec3 &vector)
Specify value for vec3 uniform.
void setUniform(const std::string &name, const Glsl::Bvec3 &vector)
Specify value for bvec3 uniform.
void setUniform(const std::string &name, CurrentTextureType)
Specify current texture as sampler2D uniform.
void setUniform(const std::string &name, const Glsl::Bvec2 &vector)
Specify value for bvec2 uniform.
void setUniformArray(const std::string &name, const Glsl::Vec2 *vectorArray, std::size_t length)
Specify values for vec2[] array uniform.
bool loadFromMemory(const std::string &vertexShader, const std::string &geometryShader, const std::string &fragmentShader)
Load the vertex, geometry and fragment shaders from source codes in memory.
void setParameter(const std::string &name, float x, float y)
Change a 2-components vector parameter of the shader.
void setUniform(const std::string &name, const Glsl::Vec4 &vector)
Specify value for vec4 uniform.
void setUniform(const std::string &name, float x)
Specify value for float uniform.
void setUniform(const std::string &name, const Glsl::Mat3 &matrix)
Specify value for mat3 matrix.
unsigned int getNativeHandle() const
Get the underlying OpenGL handle of the shader.
static CurrentTextureType CurrentTexture
Represents the texture of the object being drawn.
void setUniform(const std::string &name, const Glsl::Bvec4 &vector)
Specify value for bvec4 uniform.
bool loadFromMemory(const std::string &shader, Type type)
Load the vertex, geometry 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.
void setUniform(const std::string &name, const Glsl::Mat4 &matrix)
Specify value for mat4 matrix.
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 setUniform(const std::string &name, int x)
Specify value for int uniform.
void setUniformArray(const std::string &name, const Glsl::Vec3 *vectorArray, std::size_t length)
Specify values for vec3[] array uniform.
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.
void setUniform(const std::string &name, bool x)
Specify value for bool uniform.
@ Geometry
Geometry shader.
Image living on the graphics card that can be used for drawing.
Utility template class for manipulating 3-dimensional vectors.
implementation defined Mat4
4x4 float matrix (mat4 in GLSL)
implementation defined Ivec4
4D int vector (ivec4 in GLSL)
implementation defined Vec4
4D float vector (vec4 in GLSL)
implementation defined Bvec4
4D bool vector (bvec4 in GLSL)
implementation defined Mat3
3x3 float matrix (mat3 in GLSL)
Special type that can be passed to setUniform(), and that represents the texture of the object being ...