SFML community forums

General => General discussions => Topic started by: Phynx on May 27, 2016, 09:47:11 pm

Title: The new sf::shader additions
Post by: Phynx on May 27, 2016, 09:47:11 pm
I just had to register and say thanks for the new features that was added to sf::shader, being able to set array uniforms is what I've needed for awhile.
was wondering about being able to set custom struct arrays, would that be possible now?

ex:

#define MAX_LIGHTS 32

struct Light{
vec3 position;
vec4 color;
};

uniform Light sceneLights[MAX_LIGHTS];
Title: Re: The new sf::shader additions
Post by: fallahn on May 28, 2016, 09:22:02 am
Aye the new interface is far more useful than the now deprecated one. As far as I can tell opengl itself doesn't provide a way to supply struct data unless you directly address its members like this (http://stackoverflow.com/questions/23591264/how-to-pass-uniform-array-of-struct-to-shader-via-c-code) or this (https://github.com/fallahn/xygine/blob/master/Example/src/ParticleDemoState.cpp#L126). If you prefer, and you can ensure an opengl > 3 context, I have found uniform buffers (https://www.opengl.org/wiki/Uniform_Buffer_Object) can work well (https://github.com/fallahn/xygine/blob/master/xygine/include/xygine/mesh/UniformBuffer.hpp#L39) with SFML.
Title: Re: The new sf::shader additions
Post by: Phynx on May 30, 2016, 05:39:55 pm
Thanks, I will need to look into those for sure since with any sfml build newer than the stable 2.3.2 I run into a stack overflow when loading textures in a thread