Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL: Reusing the same texture with different parameters

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?

like image 803
Silverlan Avatar asked Oct 28 '13 12:10

Silverlan


1 Answers

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.

like image 114
Damon Avatar answered Sep 22 '22 12:09

Damon