1
General discussions / Re: sf::Shader -- API to set uniforms
« on: April 25, 2014, 02:41:47 am »I still don't know...
I agree that SFML shouldn't try to solve the problems that other dedicated libraries probably already do much better. However for me creating a special sf::Shader::Matrix class seems more contrived than it has to be.
The pragmatist in me has me thinking:
Given that the user will be using e.g. Eigen to solve all their linear algebra needs, they will store some Eigen specific data in each of their objects that needs it.class SomeClassAnd now the user wants to send that matrix to the GL shader:
{
...
private:
Eigen::Matrix4d m_matrix;
}theShader.setParamater("theMatrix", sf::Shader::Matrix( ... grab data from Eigen matrix ... ));Wouldn't it be simpler to just allow directly passing the data array to the setParamater() method? In this case some other way of specifying the size of the data that is passed would be needed, and even with a templated sf::Shader::Matrix, the user would still be able to erroneously pass an array of a wrong size and not notice.
Because the user would use the LA library in their own data structures, sf::Shader::Matrix would only be used as part of the setParameter() API. I can't imagine anywhere where they would need to be returned, short of something coming from SFML itself and this also makes little sense in the case of uniforms (unless you want to add getParameter support as well).
I've kinda similar problem. I'm mostly using OpenGL and so I'm also using GLM rather than SFML types. Why? Because I need linear algebra (for 3D) and SFML doesn't provide that properly. Now due that, sometimes I've to convert between GLM and SFML types which isn't pleasant. Also sf::Shader doesn't support uniform blocks so I implemented it myself with direct OpenGL and there I can pass GLM types directly to glBufferData but I can't do that with SFML types.
So for SFML to be usable for everyone, it should define not classes as types, but struct types which have same layout which can be directly used by OpenGL and a lot of libraries already use same layout so they all can be used interchangeably with proper casts. I could pass same GLM types to SFML as I would do for OpenGL. Then similarly like GLM does, SFML could provide some helper Vector/Matrix classes which would operate and work with those types. So you could do like
// Using native SFML classes/types
sf::Matrix::Data matrix = sf::Shader::Matrix.data();
theShader.setParamater("theMatrix", matrix);
orsf::Matrix::Data matrix = sf::Shader::Matrix.data();
theShader.setParamater("theMatrix", matrix);
glm::mat4 matrix; // with GLM
theShader.setParamater("theMatrix", (sf::Matrix::Data)glm::value_ptr(matrix));
theShader.setParamater("theMatrix", (sf::Matrix::Data)glm::value_ptr(matrix));