2

I tried:

#version 130

uniform sampler2D texID;
in vec2 texcoord;
out vec4 outcolor;

void main(void) {
    vec2 tcoord=texcoord.xy*768.0;
    ivec2 tst=ivec2(tcoord.x,tcoord.y);
    outcolor=texelFetch(texID,tcoord);
}

And got error on the line with the texelFetch:

unable to find compatible overloaded function "texelFetch(sampler2D, vec2)".

I didn't putted those parameters from my head here few sources:

  1. http://www.opengl.org/wiki/Sampler_(GLSL)#Direct_texel_fetches

  2. http://www.opengl.org/sdk/docs/manglsl/xhtml/texelFetch.xml

TheQuestion: Is there a way to use GL_TEXTURE_2D with texelFetch or just direct read pixels from texture when executing shader?

User is deleted
  • 157
  • 2
  • 11

2 Answers2

5

Check the 1.30 spec, page 89.

None of the five texelFetch() overloads take two arguments:

gvec4 texelFetch (gsampler1D sampler, int P, int lod) 
gvec4 texelFetch (gsampler2D sampler, ivec2 P, int lod) 
gvec4 texelFetch (gsampler3D sampler, ivec3 P, int lod) 
gvec4 texelFetch (gsampler1DArray sampler, ivec2 P, int lod) 
gvec4 texelFetch (gsampler2DArray sampler, ivec3 P, int lod) 

You need a third parameter.

genpfault
  • 51,148
  • 11
  • 85
  • 139
2
texelFetch(sampler1D(0),0,0);

This is not legal GLSL.

sampler1D is an opaque type. It does not have a value of any kind. Yes, I know you "set" a value with glUniform1i, but you're not really setting a value. sampler1D cannot be constructed. This is a list of everything you can do with a sampler type in GLSL:

  1. Declare it as a uniform variable at global scope.
  2. Declare it as an input function parameter.
  3. Pass a variable of sampler type to a function that takes that sampler type as an argument.

Note that "call a constructor" is not on that list. sampler1D(0) is not proper syntax. If you want to use a sampler, you need to declare it as a uniform and set the texture image unit from OpenGL source code. Or use the layout(binding=#) syntax, if you have GL 4.2 or ARB_shading_language_420pack.

The true is that I want it for performance.

Then you are wanting it for the wrong reasons. You use texelFetch when texelFetch most accurately describes what you are trying to do. It is not merely "unfiltered"; you can get that simply by setting the texture/sampler parameters properly. You should use it when you want access to a specific texel, without texture coordinate normalization and so forth.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982