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
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.
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.
@ Fragment
Fragment (pixel) shader.
@ Geometry
Geometry shader.
Image living on the graphics card that can be used for drawing.
ImplementationDefined Mat3
3x3 float matrix (mat3 in GLSL)
Vector2< int > Ivec2
2D int vector (ivec2 in GLSL)
Vector3< float > Vec3
3D float vector (vec3 in GLSL)
ImplementationDefined Ivec4
4D int vector (ivec4 in GLSL)
Vector2< float > Vec2
2D float vector (vec2 in GLSL)
Vector2< bool > Bvec2
2D bool vector (bvec2 in GLSL)
Vector3< int > Ivec3
3D int vector (ivec3 in GLSL)
Vector3< bool > Bvec3
3D bool vector (bvec3 in GLSL)
ImplementationDefined Vec4
4D float vector (vec4 in GLSL)
ImplementationDefined Mat4
4x4 float matrix (mat4 in GLSL)
ImplementationDefined Bvec4
4D bool vector (bvec4 in GLSL)
Special type that can be passed to setUniform(), and that represents the texture of the object being ...