PDA

View Full Version : How to use texelFetch()?



fred_em
01-18-2011, 09:00 AM
Hi,

I would like to create a texture buffer object containing a series of vec4 values.

In GLSL, should things be declared the following way?

// Fragment shader

#version 150 compatibility
#extension GL_EXT_gpu_shader4 : enable

uniform sampler1D tex;

void main(void)
{
vec4 myValue = texelFetch(tex, 0);
[...]
}

When trying to compile this shader, I get the following error:

error C1115: unable to find compatible overloaded function "texelFetch(sampler2D, int)"

I am confused as to which function I should use: texelFetch, texelFetch1D, texelFetchBuffer?
The data I am dealing with is 1-dimensional.

I'm using a Fermi card with the latest drivers.

Regards,
Fred

fred_em
01-18-2011, 09:28 AM
Oops, I forgot the last argument... texelFetch(sampler1D, int, int).

Surprisingly, I am still getting a compilation error on AMD/ATI hardware, either texelFetch is not recognized, or it is another mistake of mine.

Alfonse Reinheart
01-18-2011, 10:15 AM
A buffer texture is not a GL_TEXTURE_1D texture. It is a buffer texture. It has its own special texture type (GL_TEXTURE_BUFFER), so it also has its own sampler type (http://www.opengl.org/wiki/GLSL_Samplers) (samplerBuffer).

MalcolmB
02-08-2011, 01:32 PM
He was actually talking about the textlFetch() function, not texelFetchBuffer()

Alfonse Reinheart
02-08-2011, 02:00 PM
He was actually talking about the textlFetch() function, not texelFetchBuffer()

No such thing. OK, there is if you use EXT_gpu_shader4, but why would you want to do that?

In version 1.50 (and 1.40. And 1.30. Basically, the last two+ years), the texture functions no longer redundantly state what sampler they use. There is no "texelFetchBuffer" in core GLSL 1.50. There is only "texelFetch" which can take just about any sampler type.

fred_em
02-11-2011, 12:33 AM
He was actually talking about the textlFetch() function, not texelFetchBuffer()

No such thing. OK, there is if you use EXT_gpu_shader4, but why would you want to do that?

In version 1.50 (and 1.40. And 1.30. Basically, the last two+ years), the texture functions no longer redundantly state what sampler they use. There is no "texelFetchBuffer" in core GLSL 1.50. There is only "texelFetch" which can take just about any sampler type.
This was the bit that I was basically missing, that older GLSL with the proper extension enabled the use of texelFetchXXXX() while more recent versions only accept texelFetch().
Not in front of my development computer right now but I believe nvidia drivers still tolerate texelFetchXXXX function names while AMD drivers do not.

As this way the first time I was looking at this, this confused me. AMD's GLSL compiler has had and still has very serious bugs, so I sometimes question its behavior even when it is correct (and I know it sometimes sticks to the specs more than the nvidia compiler).

Alfonse Reinheart
02-11-2011, 01:02 AM
Not in front of my development computer right now but I believe nvidia drivers still tolerate texelFetchXXXX function names while AMD drivers do not.

Both of them do when you explicitly enable the extensions that define them. And neither of them should when you don't enable those extensions.