0
\$\begingroup\$

I have a array texture of which I would like some of its sub-images have wrap modes of GL_REPEAT and others to be GL_CLAMP_TO_EDGE.

From my research, I haven't found a clear answer. It appears Sampler Objects may be what I'm looking for, however I'm unsure as to how to go about implementing this.

As current I have a sampler class which looks like this:

class TextureSampler {
public:
    unsigned int id;

    TextureSampler();
    TextureSampler(unsigned int wrapS, unsigned int wrapT, unsigned int filterMin, unsigned int filterMag);
    ~TextureSampler();

    void bind(unsigned int textureId);
    void unbind(unsigned int textureId);
};

As you can expect the constructor simply sets all the wrap and filter parameters.

I bind with this glBindSampler(textureId, id);. The textureId being that from glGenTextures() and the id from glGenSamplers().

Now when it comes to my implementation, I've created two samplers, one for repeating wrap mode and another for edge clamping. This is where things are a bit murky. I've got two samplers, one texture array... it doesn't seem possible to bind both samplers at the same time and yet how do I access both types in the fragment shader? Google has not been much help and I've read parts of the ARB_sampler_objects extension to see if it had useful information and it seemed to say ...

  1. Should sampler objects be made visible to the shading language. This is left for a future extension.

I am using GL 4.3, so this is extension is not built-in, however that quote leaves me wondering if I've approached this all wrong. What is the correct approach to this? Is this possible with a single texture array?

\$\endgroup\$
5
  • \$\begingroup\$ Can you tell us more about how you're using/applying this in your game? There may be other ways to achieve that end. \$\endgroup\$ – DMGregory Apr 5 at 11:51
  • \$\begingroup\$ @DMGregory, Sure, on some quads in my terrain I have textures that scroll and warp, whilst others stay static. \$\endgroup\$ – Nork Apr 6 at 3:31
  • \$\begingroup\$ Do you actually mean "texture array"? Or "array texture"? \$\endgroup\$ – tuket Apr 19 at 20:24
  • \$\begingroup\$ @tuket yes, you are correct, array texture is what I meant. Updated to correct question. Since asking this question I have a better idea of sampler object usage, however, if there is some trick to achieve what I'm looking for with only a single texture binding, I'm all ears. \$\endgroup\$ – Nork Apr 21 at 1:02
  • \$\begingroup\$ As far as I know, it's not possible to do what you want with "array texture"s. However, if you use an array of textures, you can have a sampler object for each one. A couple workarounds I can think of 1) Have one "array texture" with all the REPEAT textures, and another with all CLAMP textures. 2) Use REPEAT for the sampler, then do "clamp()" of the UV in the shader if needed. \$\endgroup\$ – tuket Apr 21 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.