简体   繁体   English

绘制许多纹理化的小队OpenGL ES 2.0

[英]Drawing many textured squads OpenGL ES 2.0

I'm programming an Android App where a grid is drawn, which you can move around and move in it's direction. 我正在编写一个绘制了网格的Android应用程序,您可以在网格的方向上移动。 The grid consists of about 2000 to 5000 quads, each with a different texture. 网格由大约2000到5000个四边形组成,每个四边形具有不同的纹理。 I defined 4 vertices and use an index buffer to draw each quad. 我定义了4个顶点,并使用索引缓冲区绘制了每个四边形。 Before drawing I position it using a model matrix. 在绘制之前,我使用模型矩阵对其进行定位。 As you can move in my scene I use view frustum culling, which increases the performance in some situations. 当您可以在场景中移动时,我会使用视锥台剔除,这在某些情况下会提高性能。 Unfortunately there might be the case where I will need to draw all of the quads, so I want to ask how I prevent slow drawing. 不幸的是,在某些情况下我可能需要绘制所有四边形,因此我想问一下如何防止缓慢绘制。

I can't use a texture atlas as all of the textures are pretty big (from 256x256 to 1024x1024). 我无法使用纹理图集,因为所有纹理都很大(从256x256到1024x1024)。 I think calling glDrawElements() for each squad is what makes me slow, but I don't know how I can change it. 我认为为每个小队调用glDrawElements()会让我变慢,但我不知道如何更改它。

Another idea I had would be to draw the scene to a texture and just bind this texture to a single quad to create an illusion of the scene being drawn. 我的另一个想法是将场景绘制为纹理,然后将该纹理绑定到单个四边形上,从而对正在绘制的场景产生幻觉。 As the user gets closer I could redraw it for better resolution. 随着用户的接近,我可以重新绘制它以获得更好的分辨率。 Could this work? 能行吗?

I look forward for any kind of help. 我期待任何帮助。

I can't use a texture atlas as all of the textures are pretty big (from 256x256 to 1024x1024). 我无法使用纹理图集,因为所有纹理都很大(从256x256到1024x1024)。

You can fit 64 256x256 textures into a 2048x2048 atlas, that's a huge amount, so you should definitely atlas. 您可以将64个256x256纹理贴合到2048x2048地图集中,这是一个巨大的数目,因此您绝对应该使用地图集。 Even getting 4 1024x1024 onto a 2048x2048 is worth doing, it can quarter your draw call count. 即使将4 1024x1024放到2048x2048上也是值得的,它可以使绘图调用数增加四分之一。

And as WLGfx says in the comments to your question, you should batch up any quads that use the same texture (with atlasing there will be a lot more of these). 就像WLGfx在对问题的评论中所说的那样,您应该对使用相同纹理的所有四边形进行批处理(加上图集,其中更多的四边形)。

I think this would be enough, but you still might have a pretty high drawcall count in your fully zoomed-out view. 我认为这足够了,但是在完全缩小的视图中,您仍然可能会有相当高的调用次数。 After implementing atlasing and batching, if performance here is still a problem, you could create a separate asset set of thumb-nail textures at, say, quarter resolution (so a 256x256 becomes 64x64). 实施图集和批处理后,如果仍然存在性能问题,则可以创建单独的缩略图纹理资产集,例如四分之一分辨率(因此256x256变为64x64)。 This thumbnail asset set would fit onto just a handful of 2048x2048 atlas sheets, and you could switch to it when zoomed out far enough. 此缩略图资产集仅适合少数2048x2048图集,并且您可以在缩小足够远时切换到该缩略图集。

Another idea I had would be to draw the scene to a texture and just bind this texture to a single quad to create an illusion of the scene being drawn. 我的另一个想法是将场景绘制为纹理,然后将该纹理绑定到单个四边形上,从而对正在绘制的场景产生幻觉。 As the user gets closer I could redraw it for better resolution. 随着用户的接近,我可以重新绘制它以获得更好的分辨率。 Could this work? 能行吗?

This could work, as long as your scene is very static, if the quads are moving/changing every frame, then it might not help. 只要您的场景非常静态,这就可以工作,如果四边形在移动/更改每一帧,那么它可能无济于事。 Also, there might be a noticeable framerate hitch when you have to do the full redraw. 另外,当您必须进行完全重绘时,可能会有明显的帧率故障。

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

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