39#include <unordered_map>
168 Shader(
const std::filesystem::path& vertexShaderFilename,
const std::filesystem::path& fragmentShaderFilename);
190 Shader(
const std::filesystem::path& vertexShaderFilename,
191 const std::filesystem::path& geometryShaderFilename,
192 const std::filesystem::path& fragmentShaderFilename);
233 Shader(std::string_view vertexShader, std::string_view fragmentShader);
255 Shader(std::string_view vertexShader, std::string_view geometryShader, std::string_view fragmentShader);
360 [[nodiscard]]
bool loadFromFile(
const std::filesystem::path& vertexShaderFilename,
361 const std::filesystem::path& fragmentShaderFilename);
383 [[nodiscard]]
bool loadFromFile(
const std::filesystem::path& vertexShaderFilename,
384 const std::filesystem::path& geometryShaderFilename,
385 const std::filesystem::path& fragmentShaderFilename);
426 [[nodiscard]]
bool loadFromMemory(std::string_view vertexShader, std::string_view fragmentShader);
449 std::string_view geometryShader,
450 std::string_view fragmentShader);
729 void setUniformArray(
const std::string& name,
const float* scalarArray, std::size_t length);
861 [[nodiscard]]
bool compile(std::string_view vertexShaderCode,
862 std::string_view geometryShaderCode,
863 std::string_view fragmentShaderCode);
872 void bindTextures()
const;
882 int getUniformLocation(
const std::string& name);
891 struct UniformBinder;
896 using TextureTable = std::unordered_map<int, const Texture*>;
897 using UniformTable = std::unordered_map<std::string, int>;
902 unsigned int m_shaderProgram{};
903 int m_currentTexture{-1};
904 TextureTable m_textures;
905 UniformTable m_uniforms;
#define SFML_GRAPHICS_API
Definition Export.hpp:42
GlResource()
Default constructor.
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 & operator=(Shader &&right) noexcept
Move assignment.
Shader(InputStream &stream, Type type)
Construct from a shader stream.
Shader(const std::filesystem::path &vertexShaderFilename, const std::filesystem::path &geometryShaderFilename, const std::filesystem::path &fragmentShaderFilename)
Construct from vertex, geometry and fragment shader files.
Shader(Shader &&source) noexcept
Move constructor.
bool loadFromStream(InputStream &stream, Type type)
Load the vertex, geometry or fragment shader from a custom stream.
bool loadFromFile(const std::filesystem::path &vertexShaderFilename, const std::filesystem::path &geometryShaderFilename, const std::filesystem::path &fragmentShaderFilename)
Load the vertex, geometry and fragment shaders from files.
void setUniform(const std::string &name, const Glsl::Ivec4 &vector)
Specify value for ivec4 uniform.
bool loadFromStream(InputStream &vertexShaderStream, InputStream &fragmentShaderStream)
Load both the vertex and fragment shaders from custom streams.
Shader & operator=(const Shader &)=delete
Deleted copy assignment.
static bool isGeometryAvailable()
Tell whether or not the system supports geometry shaders.
Shader(const std::filesystem::path &filename, Type type)
Construct from a shader file.
bool loadFromFile(const std::filesystem::path &filename, Type type)
Load the vertex, geometry or fragment shader from a file.
void setUniformArray(const std::string &name, const Glsl::Mat3 *matrixArray, std::size_t length)
Specify values for mat3[] array uniform.
void setUniform(const std::string &name, Glsl::Vec2 vector)
Specify value for vec2 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.
bool loadFromFile(const std::filesystem::path &vertexShaderFilename, const std::filesystem::path &fragmentShaderFilename)
Load both the vertex and fragment shaders from files.
void setUniform(const std::string &name, Glsl::Bvec2 vector)
Specify value for bvec2 uniform.
bool loadFromMemory(std::string_view vertexShader, std::string_view fragmentShader)
Load both the vertex and fragment shaders from source codes in memory.
Shader(InputStream &vertexShaderStream, InputStream &fragmentShaderStream)
Construct from vertex and fragment shader streams.
void setUniform(const std::string &name, const Glsl::Ivec3 &vector)
Specify value for ivec3 uniform.
void setUniform(const std::string &name, Glsl::Ivec2 vector)
Specify value for ivec2 uniform.
bool loadFromStream(InputStream &vertexShaderStream, InputStream &geometryShaderStream, InputStream &fragmentShaderStream)
Load the vertex, geometry and fragment shaders from custom streams.
Shader(const Shader &)=delete
Deleted copy constructor.
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 setUniformArray(const std::string &name, const Glsl::Vec2 *vectorArray, std::size_t length)
Specify values for vec2[] array uniform.
Shader()=default
Default constructor.
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.
Shader(std::string_view vertexShader, std::string_view fragmentShader)
Construct from vertex and fragment shaders in memory.
static CurrentTextureType CurrentTexture
Represents the texture of the object being drawn.
Definition Shader.hpp:85
void setUniform(const std::string &name, const Glsl::Bvec4 &vector)
Specify value for bvec4 uniform.
void setUniform(const std::string &name, const Glsl::Mat4 &matrix)
Specify value for mat4 matrix.
void setUniform(const std::string &name, const Texture &&texture)=delete
Disallow setting from a temporary texture.
static bool isAvailable()
Tell whether or not the system supports shaders.
bool loadFromMemory(std::string_view shader, Type type)
Load the vertex, geometry or fragment shader from a source code 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.
Shader(std::string_view vertexShader, std::string_view geometryShader, std::string_view fragmentShader)
Construct from vertex, geometry and fragment shaders in memory.
Shader(std::string_view shader, Type type)
Construct from shader in memory.
Shader(InputStream &vertexShaderStream, InputStream &geometryShaderStream, InputStream &fragmentShaderStream)
Construct from vertex, geometry and fragment shader streams.
void setUniform(const std::string &name, bool x)
Specify value for bool uniform.
Shader(const std::filesystem::path &vertexShaderFilename, const std::filesystem::path &fragmentShaderFilename)
Construct from vertex and fragment shader files.
bool loadFromMemory(std::string_view vertexShader, std::string_view geometryShader, std::string_view fragmentShader)
Load the vertex, geometry and fragment shaders from source codes in memory.
Type
Types of shaders.
Definition Shader.hpp:61
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:56
priv::Vector4< bool > Bvec4
Definition Glsl.hpp:184
priv::Vector4< int > Ivec4
Definition Glsl.hpp:183
Vector2< int > Ivec2
2D int vector (ivec2 in GLSL)
Definition Glsl.hpp:67
Vector3< float > Vec3
3D float vector (vec3 in GLSL)
Definition Glsl.hpp:79
priv::Matrix< 3, 3 > Mat3
Definition Glsl.hpp:185
Vector2< float > Vec2
2D float vector (vec2 in GLSL)
Definition Glsl.hpp:61
Vector2< bool > Bvec2
2D bool vector (bvec2 in GLSL)
Definition Glsl.hpp:73
Vector3< int > Ivec3
3D int vector (ivec3 in GLSL)
Definition Glsl.hpp:85
Vector3< bool > Bvec3
3D bool vector (bvec3 in GLSL)
Definition Glsl.hpp:91
priv::Vector4< float > Vec4
Definition Glsl.hpp:182
priv::Matrix< 4, 4 > Mat4
Definition Glsl.hpp:186
Definition BlendMode.hpp:34
Special type that can be passed to setUniform(), and that represents the texture of the object being ...
Definition Shader.hpp:75
Define a point with color and texture coordinates.
Definition Vertex.hpp:44