Added new methods to set uniforms in sf::Shader

Implements a new design for the shader uniform API.
* Added Shader::setUniform() and Shader::setUniformArray() overloads for the following types:
  -> scalars: float, int, bool
  -> vectors: 2D, 3D, 4D
  -> matrices: 3x3, 4x4
  -> arrays of basic types
  -> samplers (sf::Texture)
  -> conversions for SFML types (sf::Transform, sf::Color)
* Added sf::Glsl namespace with GLSL-equivalent types
* Deprecated Shader::setParameter() overloads

Other related changes:
* Refactored sf::Shader internals to avoid code duplication
* Improved documentation
* Added SFML_DEPRECATED macro to Doxyfile
* Defined _SCL_SECURE_NO_WARNINGS to disable std::copy() warnings on MSVC
This commit is contained in:
Jan Haller 2015-10-12 07:54:21 +02:00
parent fcb05fb975
commit 9c5c750e60
10 changed files with 1272 additions and 321 deletions

View file

@ -31,14 +31,14 @@ public:
// Load the shader
if (!m_shader.loadFromFile("resources/pixelate.frag", sf::Shader::Fragment))
return false;
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
m_shader.setUniform("texture", sf::Shader::CurrentTexture);
return true;
}
void onUpdate(float, float x, float y)
{
m_shader.setParameter("pixel_threshold", (x + y) / 30);
m_shader.setUniform("pixel_threshold", (x + y) / 30);
}
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
@ -101,9 +101,9 @@ public:
void onUpdate(float time, float x, float y)
{
m_shader.setParameter("wave_phase", time);
m_shader.setParameter("wave_amplitude", x * 40, y * 40);
m_shader.setParameter("blur_radius", (x + y) * 0.008f);
m_shader.setUniform("wave_phase", time);
m_shader.setUniform("wave_amplitude", sf::Vector2f(x * 40, y * 40));
m_shader.setUniform("blur_radius", (x + y) * 0.008f);
}
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
@ -155,10 +155,10 @@ public:
void onUpdate(float time, float x, float y)
{
float radius = 200 + std::cos(time) * 150;
m_shader.setParameter("storm_position", x * 800, y * 600);
m_shader.setParameter("storm_inner_radius", radius / 3);
m_shader.setParameter("storm_total_radius", radius);
m_shader.setParameter("blink_alpha", 0.5f + std::cos(time * 3) * 0.25f);
m_shader.setUniform("storm_position", sf::Vector2f(x * 800, y * 600));
m_shader.setUniform("storm_inner_radius", radius / 3);
m_shader.setUniform("storm_total_radius", radius);
m_shader.setUniform("blink_alpha", 0.5f + std::cos(time * 3) * 0.25f);
}
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
@ -215,14 +215,14 @@ public:
// Load the shader
if (!m_shader.loadFromFile("resources/edge.frag", sf::Shader::Fragment))
return false;
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
m_shader.setUniform("texture", sf::Shader::CurrentTexture);
return true;
}
void onUpdate(float time, float x, float y)
{
m_shader.setParameter("edge_threshold", 1 - (x + y) / 2);
m_shader.setUniform("edge_threshold", 1 - (x + y) / 2);
// Update the position of the moving entities
for (std::size_t i = 0; i < m_entities.size(); ++i)