OpenGL: Reusing the same texture with different parameters
Asked Answered
L

1

7

In my program I have a texture which is used several times in different situations. In each situation I need to apply a certain set of parameters.

I want to avoid having to create an additional buffer and essentially creating a copy of the texture for every time I need to use it for something else, so I'd like to know if there's a better way?

Luigiluigino answered 28/10, 2013 at 12:0 Comment(0)
I
10

This is what sampler objects are for (available in core since version 3.3, or using ARB_sampler_objects). Sampler objects separate the texture image from its parameters, so you can use one texture with several parameter sets. That functionality was created with exactly your problem in mind.

Quote from ARB_sampler_objects extension spec:

In unextended OpenGL textures are considered to be sets of image data (mip-chains, arrays, cube-map face sets, etc.) and sampling state (sampling mode, mip-mapping state, coordinate wrapping and clamping rules, etc.) combined into a single object. It is typical for an application to use many textures with a limited set of sampling states that are the same between them. In order to use textures in this way, an application must generate and configure many texture names, adding overhead both to applications and to implementations. Furthermore, should an application wish to sample from a texture in more than one way (with and without mip-mapping, for example) it must either modify the state of the texture or create two textures, each with a copy of the same image data. This can introduce runtime and memory costs to the application.

Inquiry answered 28/10, 2013 at 12:28 Comment(1)
Also if you don't have sampler objects available you can change the texture parameter whenever you need to do so. Those are not one-time settings.Rubbish

© 2022 - 2024 — McMap. All rights reserved.