- To clip drawing textures, would I use a fragment shader as opposed to a vertex shader (and update the bounds using parameters?) then setting the alpha to 0 if the pixel lies outside of the bounds? My current understanding of shaders says yes but more or less I'd like some confirmation that I'm not too entirely crazy.Yes. There's even a GLSL function to discard a fragment, instead of hacking its alpha to 0.
- Are shaders faster/more ideal than using sf::Sprite and an sf::Texture to draw images each frame?Shaders don't create anything, they just change how geometry and/or pixels are rendered. So you still need to feed them with geometry (sf::Sprite) and texture (sf::Texture).
- What's the difference (internally) between drawing an sf::Sprite with a texture and just a set of polygons with a shader that draws a texture specified? Is there any advantage? If SFML isn't using a built-in shader to do this, how is SFML drawing a texture to the screen?See my answer above. Shaders work on the provided geometry and texture, they don't replace them.
- If shaders -are- faster, to draw an image with a shader (assuming the shader has been passed the appropriate texture as a parameter) would I just draw four points do the draw() method and then pass the shader as part of the render state?Same answer, again.
- Are `uniform` constants (variables) in shaders just the parameters set by SFML's setParameter() method, verbatim?Yes. But not verbatim: for example, sf::Color components are normalized. sf::Transform is passed as a 4x4 matrix.
- If so, what happens when I want to use a uniform constant that hasn't been set by the application? Is it undefined behavior?Probably. Or maybe it has a default value of 0, I don't know.
- Are parameters sticky - meaning, if I set a parameter one frame, and not the next, does the value from the first time I set the parameter "stick" (persist) throughout the rest of the frames until it is explicitely set again?Yes.
- Can/will shaders lock up the computer if something unexpected happens (like drivers do)?Nop. They will just produce weird results.
- For maximum compatibility (the application in question is not a game) should I target the lowest possible shader version?Probably. I think it's enough for most shaders -- unless you really want to implement crazy stuff.
...
There are other solutions for clipping but I don't think they are compatible with SFML.
...
1. Can sf::RenderWindow's applyShader function be used as a way to make post-effects. If the answer in no, the what's the purpose of it?It's not public, you don't have to care about this function. Post-effects are explained in the documentation of sf::Shader.
2. I tried using the 'sf::Texture::update(Window&)' method for applying post-effects as show here. Initially it works fine, but if the window is re-sized the 'top image' doesn't update and I get a still image with the game running under it. I believe this is because the texture size have to be the same size as the window-view size, yet I tried changing the size of the texture on run time and the problem persists. Does anyone know how can this be fixed?Please show a complete and minimal code that reproduces the problem (in a new thread).
Is my only option then the 'draw everything to a sf::RenderTexture' method?Not the only one, but definitely the best.
Can I assign vec4 with non normalized components to gl_FragColor? (it's for computation, not graphics)I don't know. Why don't you check directly? Or check in the GLSL specification?
Can I assign vec4 with non normalized components to gl_FragColor? (it's for computation, not graphics)