Reputation: 9547
I have a (default vertex and) fragment shader that should resize textures and scale their color by a specific factor for brightness correction.
The result is rendered into an GL_UNSIGNED_INT_8_8_8_8 framebuffer.
#version 330
uniform sampler2D tex;
uniform vec2 screenSize;
uniform float scale;
layout(location = 0) out vec4 color;
void main()
{
vec2 coord = gl_FragCoord.xy / screenSize;
color = texture(tex, coord);
color *= scale;
color.a = 1;
}
When I bind a R32I texture to tex, the output from the texture
call in the red channel is always 0, despite non 0 data being in the texture.
I checked via apitrace that the correct texture is bound to tex
and it contains values that go up to about 200.
Normalizing this value should give an output of 9.3e-8
from texture()
,
while scale = 9.67e7
.
There are no error messages (besides performance warnings) neither from glGetError
nor from the debug callback.
What am I doing wrong? Is it forbidden to bind integer textures to (non integer) samplers?
Upvotes: 2
Views: 1198
Reputation: 22167
Since you are using an integer format, you will have to use an isampler2D
instead of your sampler.
So for samplers, floating-point samplers begin with "sampler". Signed integer samplers begin with "isampler", and unsigned integer samplers begin with "usampler". If you attempt to read from a sampler where the texture's Image Format doesn't match the sampler's basic format (usampler2D with a GL_R8I, or sampler1D with GL_R8UI, for example), all reads will produce undefined values.
(Source: www.opengl.org)
Upvotes: 5