在OpenGL中绑定纹理 [英] Binding textures in OpenGL

查看:130
本文介绍了在OpenGL中绑定纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在批量渲染我的场景,以尽量减少状态变化。
由于我的着色器通常需要多个纹理,因此我有几个纹理单元同时绑定在一起。其中一些纹理被用于多个批次,所以甚至可以保持绑定。



现在我的问题是,重新绑定所有纹理是否需要批量处理,即使其中一些可能已经被绑定?或者我应该检查哪些是绑定的,只绑定新的? glBindTexture有多昂贵?我使用着色器,将未使用的纹理绑定到着色器不会从其中取样的纹理单元很糟糕,还是应该解除绑定?

我是主要是问如何让它快,而不是如何。

编辑:如果我提供代码会有帮助吗?


<解决方案

解决方案答案很难,因为任何强大的GL实现都应该将已绑定的纹理绑定为优化的无操作。您应该尝试进行基准测试,以确定是否存在条件会有所作为。

这同样适用于纹理单元中未使用的纹理,因为GL实现确实知道哪些纹理单元最终被使用,它不应该影响性能(作为优化)以使用未使用的纹理单元。


So I'm rendering my scene in batches, to try and minimize state changes. Since my shaders usually need multiple textures, I have a few of them bound at the same time to different texture units. Some of these textures are used in multiple batches, so could even stay bound.

Now my question is, is it fine to just re-bind all of the textures that I need during a batch, even though some of them may already be bound? Or should I check which ones are bound, and only bind new ones? How expensive is glBindTexture? I'm using shaders, is it bad to have unused textures bound to texture units that the shader won't sample from, or should I unbind them?

I'm mostly asking "how to make it fast", not "how to".

EDIT: Would it help if I supplied code?

解决方案

The answer is difficult, because any strong GL implementation should make binding a already bound texture a no-op as an optimization. You should try benchmarking to see if putting a condition makes a difference or not.

The same applies to unused textures in texture units, since the GL implementation does know what texture units are finally used, it should not affect performance (as an optimization) to have unused texture units.

这篇关于在OpenGL中绑定纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆