简体   繁体   English

OpenGL:使用不同的参数重用相同的纹理

[英]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? 我想避免创建一个额外的缓冲区,并且每次我需要将它用于其他东西时基本上创建纹理的副本,所以我想知道是否有更好的方法?

This is what sampler objects are for (available in core since version 3.3, or using ARB_sampler_objects ). 这就是采样器对象的用途(自3.3版以来在核心中可用,或使用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: 来自ARB_sampler_objects扩展规范的引用:

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. 在未扩展的OpenGL纹理中,被认为是图像数据集(mip-chains,数组,立方体图面集等)和采样状态(采样模式,mip映射状态,坐标包装和钳位规则等)相结合成一个对象。 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. 此外,如果应用程序希望以多种方式从纹理中进行采样(例如,使用和不使用mip-mapping),则必须修改纹理的状态或创建两个纹理,每个纹理都具有相同图像数据的副本。 This can introduce runtime and memory costs to the application. 这可能会给应用程序带来运行时和内存成本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM