2

Normally I would call glTexParameter when loading/initializing a texture. However, my current use case is that the same texture image may be used with many different parameter combinations (including GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_TEXTURE_BORDER_COLOR, etc).

Basically, I am mapping a texture to a mesh where it is clamped, and then mapping the same texture to different mesh where it is mirrored/repeated.

Is it better to call glTexParameter every frame before drawing each mesh/group (this is essentially supplying uniforms to my fragment shader), or should I load each texture multiple times for each different combination of parameters?

Keep in mind I may have a large number of textures each with several combinations of texture parameters.

I am using OpenGL 3.3 but am interested in any ideas.

JRS
  • 1,438
  • 2
  • 16
  • 26

2 Answers2

1

Looks like you should try Sampler Object feature (core from 3.3). It separates texture image from it's parameters. So you can use just one texture with multiple parameter sets.

From spec:

Sampler objects may be bound to texture
units to supplant the bound texture's sampling state. A single
sampler may be bound to more than one texture unit simultaneously,
allowing different textures to be accessed with a single set of
shared sampling parameters.

Also, by binding different sampler
objects to texture units to which the same texture has been bound,
the same texture image data may be sampled with different sampling
parameters.

Looks like it is exactly what you need but you should definitely test it on the OpenGL implementation you are targeting and compare with other approaches - this is the only way to answer to anything related to performance in OpenGL.

vbo
  • 13,583
  • 1
  • 25
  • 33
1

You are approaching this all wrong, in GL 3.3+ Sampler Objects allow you to separate all of the states you just mentioned from Texture Objects.

OpenGL 4.4 Core Profile Specification - Table 23.18. Textures (state per sampler object) - pp. 539

Sampler State

As long as you have a non-zero Sampler Object bound to a Texture Image Unit, then when it comes time to sample that texture the state will be taken from the Sampler Object instead of the bound Texture Object. Note that the only thing that differs between 3.3 and 4.4 in terms of sampler state is the addition of a Debug label.

This approach allows you to change the sampling parameters for a texture simply by binding a different sampler object to the texture image unit you sample it using. Furthermore, the sampler object interface uses a much nicer design that does not require you to bind a sampler in order to change its properties.

Community
  • 1
  • 1
Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
  • @JRS: No problem. Texture Objects still store all of these same states post-GL 3.3, Sampler Objects (if bound) simply allow you to override them without having to create multiple textures with the same image just to filter it differently. They took this idea a step farther in GL 4.3; you can share texture images and reinterpret the image data at the format level (e.g. 8-bit unsigned color -> 8-bit signed color) using [texture views](http://www.opengl.org/wiki/Texture_Storage#Texture_views). You probably do not need that functionality, but it exists ;) – Andon M. Coleman Jan 23 '14 at 00:12
  • It is not quite the same thing since it creates multiple texture objects, but it allows tremendous memory savings when you have two textures that use the same image just in a different way. Otherwise you have to create multiple texture objects and duplicate the data just because you needed to use the data in a different way. This was the same basic sort of benefit you got from separating texture data from sampler state in GL 3.3; no longer did you have to create duplicate texture objects with the same image just because you wanted to repeat it in one place in your shader and not another. – Andon M. Coleman Jan 23 '14 at 00:23