2013/12/16 vlag <valentin.soudier at gmail.com>
OMG, I would have never found it by myself ^^
You’re perfectly right, switching to a uniform sampler2DRect works just
fine \o/
So I documented a little about these rectangle sampler, and it seems that
they are prefered and optimized for post-processing effects (it gets much
easier for the programmer to work with non-normalized texture coordinates).
The main drawback is that some fetch sampler features are unavailable for a
rectangle sampler.Found on another forum :
Quote:
Rect samplers support CLAMP, CLAMP_TO_EDGE, CLAMP_TO_BORDER wrapping.
Fetch samplers return undefined results for border texels.Rect samplers support filtering, including min/mag crossover (even
though there is only one LOD, the switchover may change from nearest to
linear filtering.) Fetch samplers only support nearest filtering.Rect samplers support shadow comparison. Fetch samplers don’t.
These points are utterly unimportant with shader usage and 2D games. All
you want
to do is fetch each pixel, apply some custom effects onto it, and send it
to the screen.
Am I guaranteed that using sampler2DRect into shader sources will always
work with SDL and a OpenGL / ES2 context ?
No, and that will likely be a problem. Which texture target is bound
(normal, rectangle) is
in no way exposed by SDL, so ultimately, the best you can do is look at
SDL’s source
code and mimic the way it behaves. Currently, you could eg. check for the
rect texture
extension, and if that’s present assume that SDL will use it. But this
internal behavior
can change without notification and will then very likely break your
shaders without any
warning.
Quote:
Rectangular textures are more of an incompatibility than a feature in my
eyes.I’m still pretty new with modern display features. Why should rectangle
sampler be avoided ?
Because they’re a deprecated functionality. Originally, textures in opengl
could only have
dimensions that were a power of two (256, 512 …). To allow for
arbitrarily sized textures,
a separate extension with its own texture type was created (which also
carried a bunch
of subtle changes compared to normal textures): rectangle textures. But
eventually, someone
must have realized that this was a useless over complication, and finally
arbitrary dimensions
in regular textures were implemented (initially exposed as an extension as
well,
GL_ARB_texture_non_power_of_two, but later made part of Core in 2.0), and
ever since
rectangle textures have faded into darkness as a useless feature (they’re
not even present
in GLES2). I think the best SDL could do is just drop the rect texture code
path, and either
go with fittingly sized regular textures when npot support is present
(which should be 99%
of the cases), and fall back to their already existing code path that
rounds up the texture
dimensions to powers of two on old hardware. This would at least allow
consistent shader
usage without fear of unforeseen breakage.> Anyway, a big thanks to everybody !