Suppose I am texturing with linear magnification and minification filters, and GL_REPEAT as the wrapping mode. That means that if a texture coordinate is near 0, I may be mixing in texels from the opposite side of the texture. Is there any trick or extension to prevent the interpolation from crossing over the edge?
Why would there be? That’s what you asked for. You wanted repeat wrapping, which means the texture should be looked at in every way as an infinite canvas of the same image repeating. You asked for linear filtering, which means that the four neighboring texels will be fetched to determine the texel’s color.
“Neighboring” gets defined based on the wrapping mode. Edge wrapping repeats the edge colors, border wrapping uses a solid border color, and repeat wrapping fetches texels from the other side of the texture.
Why wouldn’t you want this behavior? It’s the right answer.
It sounds like you want
GL_CLAMP_TO_EDGE. But that’s hard to reconcile with any mention of repeat.
Perhaps you should describe what behavior you’re trying to achieve here and why (e.g. what are you trying to use this texture lookup for?).
OK, let me try to explain why I want this. First, I would think that you’d get sharper transitions from one repeat of the texture to the next. (Think of it like a tiled floor; you don’t want an edge of a tile to blend in with the edge of the adjacent tile.) Second, I’m working in a situation where I don’t have a lot of control over how a texture is being applied or the texture coordinates of the geometry it’s being applied to, and I’d rather always use GL_REPEAT rather than sometimes GL_REPEAT and sometimes GL_CLAMP_TO_EDGE. But if it happens that a texture is being simply applied to a flat geometry with texture coordinates [0,1]x[0,1], then I see a little fuzziness along the edge due to wrapping.
In that case, update the texture to include:
- 100% of the “grout” (or join appearance) on 2 of the 4 edges (e.g. left and bottom), or
- 50% of the “grout” (or join appearance) on all 4 edges
GL_REPEAT that. That gives you full control of the join appearance.
Well… then fix that. The less control/knowledge there is between the rendering API and the data being provided to it, the less effective you’re going to be at producing the results you want. I can tell you how to solve this one issue, but so long as your code is designed to remain ignorant of what is going on, you’re likely to encounter many other issues that cannot be corrected so easily.
And what do you do when the source data, which you admit you have zero control over, wants proper repetition instead of just being bound to the [0, 1] range? After all, “sharper transitions from one repeat of the texture to the next” is not what people want when they use
GL_REPEAT. Indeed, seamless repetition is the whole point of having repeat wrapping in the hardware at all.
It seems to me that in solving one problem, you’ll just create another.
The correct solution is to force the user to tell you what they actually want, not to try to guess at it. You may not have control over the texture, but you (should) have the power to make those who do have that control tell you want they want. Give them the power to determine the wrapping mode.