OpenGL ES 2.0中许多具有不同纹理的对象 [英] Many objects with different textures in OpenGL ES 2.0

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

问题描述

我是OpenGL ES 2.0的新手,它具有可编程管线,并且正在移植应用程序,该应用程序可以渲染许多具有不同纹理的对象. 因此,这将需要为每个对象调用glDrawArrays并在调用之间更改纹理?还是有另一种方法可以通过一次glDrawArrays调用绘制具有不同纹理的多个对象?

I'm new to OpenGL ES 2.0 with it's programmable pipeline and I'm porting application that renders many objects all with different textures. So this will require calling glDrawArrays for each object and changing textures between calls? Or there's another way to draw multiple objects with different textures with single glDrawArrays call?

我之所以问是因为,我发现尝试使用glDrawArrays而不是使用'desktop'OpenGL的glBegin/glEnd时,对glDrawArrays的许多调用要慢得多.

I'm asking because I noticed that doing many calls to glDrawArrays is MUCH slower when tried to use them instead of glBegin/glEnd with 'desktop' OpenGL.

我正在渲染地图图块,因此所有纹理都是不同的,它们是动态加载的(不会花很多时间像加载一次一样处理它们),而且也很大(最大为512x512).

I'm rendering map tiles so ALL textures are different, they are dynamically loaded (can't spend much time processing them as if they were loaded once) and also quite large (up to 512x512).

推荐答案

不幸的是,没有简单的内置方法可以在单个批处理glDrawArrays调用中应用多个纹理.但是,有多种方法可以使它起作用.最常见的策略之一是称为纹理图集".基本上,该想法是将许多图像组合在一起成为一个较大的纹理,每个子图像都占据该纹理的一个已知子矩形.当将它们映射到图元时,将提供与要显示的图像相对应的子矩形的坐标.

Unfortunately, there is not a simple built-in way to apply multiple textures in a single batch glDrawArrays call. There are, however, ways to make it work. One of the most common strategies is known as a Texture Atlas. Basically, the idea is to combine many images together into one larger texture, with each sub-image occupying a known sub-rectangle of the texture. When you map those onto your primitives, you supply the coordinates of the sub-rectangle corresponding to the image you want to display.

纹理图集可在许多情况下使用,但设置起来可能比较复杂.如果您不必为每个对象都使用不同的纹理,那么首先要做的就是简单地将尽可能多的使用相同纹理的基元批处理在一起.

A texture atlas will work in a large number of cases, but can be comparatively complex to set up. If you don't have to do a different texture for every single object, the first thing to try would be to simply batch together as many primitives that use the same texturing as possible.

如果您不使用OpenGL ES,并且您的纹理都具有相同的大小,那么您可能还会考虑使用纹理阵列".

If you were not using OpenGL ES, you might also look into using Texture Arrays, if your textures are all of the same size.

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

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