绘制具有不同纹理的多个对象 [英] Drawing multiple objects with different textures

查看:88
本文介绍了绘制具有不同纹理的多个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否正确理解,绘制多个在OpenGL中具有不同纹理的对象的典型方法是使用glBindTexture一次简单地绑定一个纹理并绘制使用该纹理的对象,然后绑定一个不同的纹理并一样吗?

Do I understand correctly that the typical way to draw multiple objects that each have a different texture in OpenGL is to simply bind one texture at a time using glBindTexture and draw the objects that use it, then bind a different texture and do the same?

换句话说,在任何特定时间只有一个纹理可以活动"以进行绘制,这是使用glBindTexture绑定的最后一个纹理.这是正确的吗?

In other words, only one texture can be "active" for drawing at any particular time, and that is the last texture that was bound using glBindTexture. Is this correct?

推荐答案

使用glBindTexture一次绑定一个纹理并绘制使用该纹理的对象,然后绑定不同的纹理并执行相同的操作?

bind one texture at a time using glBindTexture and draw the objects that use it, then bind a different texture and do the same?

换句话说,在任何特定时间只能绘制一个纹理以进行绘制

In other words, only one texture can be "active" for drawing at any particular time

这两个语句不是同一回事.

These two statements are not the same thing.

单个渲染操作在任何时候都只能使用单个 set 纹理.该集合由当前绑定到各种纹理图像单元的纹理定义.可通过GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS查询可用的纹理图像单元的数量.

A single rendering operation can only use a single set of textures at any time. This set is defined by the textures currently bound to the various texture image units. The number of texture image units available is queryable through GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS.

因此,对于一个渲染命令,多个纹理可以处于活动"状态.

So multiple textures can be "active" for a single rendering command.

但是,与绑定一堆纹理然后渲染多个对象(每个对象仅使用 some (或者您所用的一个))不是相同绑定的纹理.您可以做到这一点,但实际上并没有太大意义.

However, that's not the same thing as binding a bunch of textures and then rendering several objects, where each object only uses some (or one, in your case) of the bound textures. You could do that, but really, there's not much point.

GLSL采样器和纹理图像单元之间的关联是程序对象状态的一部分.它是您在采样器制服上设置的值.因此,为了执行您建议的操作,必须绑定一堆纹理,将统一设置为其中一个,进行渲染,然后将统一设置为下一个,进行渲染,等等.

The association between a GLSL sampler and a texture image unit is part of the program object state. It's the value you set on the sampler uniform. Therefore, in order to do what you suggest, you would have to bind a bunch of textures, set the uniform to one of them, render, then set the uniform to the next, render, etc.

您仍然要承担绑定这些纹理的所有费用.您仍然要承担更换制服的所有开销.确实,它的效率可能较低,因为常规方式(绑定,渲染,绑定,渲染)不涉及更改统一状态.

You are still incurring all of the cost of binding those textures. You're still incurring all of the overhead of changing uniforms. Indeed, it might be less efficient, since the normal way (bind, render, bind, render) doesn't involve changing uniform state.

再加上,这很奇怪.通常,您不应该动态更改统一采样器状态.您定义一个简单的约定(漫反射纹理来自单元0,镜面反射来自单元1,依此类推),并遵循该约定.任何GL 3.x级硬件都必须提供不少于48个纹理图像单元(每个阶段16个),所以这好像并不会用完.

Plus, it's just weird. Generally, you shouldn't be changing uniform sampler state dynamically. You define a simple convention (diffuse texture comes from unit 0, specular from unit 1, etc), and you stick to that convention. Any GL 3.x-class hardware is required to provide no less than 48 texture image units (16 per stage), so it's not like you're going to run out.

有些机制可以使您做的事情与您所说的完全不同.例如,可以利用阵列纹理,尽管这需要显式的着色器逻辑和支持.这几乎肯定比绑定一堆纹理"方法要快,因为您只绑定了一个.另外,您要更改的制服是常规数据制服,而不是采样器制服,这可能会更快.

There are mechanisms to do things not entirely unlike what you're talking about. For example, array textures can be leveraged, though this requires explicit shader logic and support. That would almost certainly be faster than the "bind a bunch of textures" method, since you're only binding one. Also, the uniform you'd be changing is a regular data uniform rather than a sampler uniform, which is likely to be faster.

通过数组纹理机制,您还可以利用实例化,假设您要使用参数略有不同.

With the array texture mechanism, you can also leverage instancing, assuming you're rendering the same object with slightly different parameters.

这篇关于绘制具有不同纹理的多个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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