[英]Fasted way to many 2d textured squares (quads) in opengl 3+
For a 2d game I need to draw many textured quads each frame.对于 2d 游戏,我需要每帧绘制许多纹理四边形。 They do not share any vertexes and should should be considered to have a random location that change every frame.
它们不共享任何顶点,应被视为具有每帧都会改变的随机位置。 As I am using opengl 3+ I can no longer use quads (it has been removed).
当我使用 opengl 3+ 时,我不能再使用四边形(它已被删除)。 I could instead use 2 triangles to make each quad but this would create a large amount of redundant reused data being passed to the GPU each frame.
我可以改为使用 2 个三角形来制作每个四边形,但这会产生大量重复使用的冗余数据,每帧都传递给 GPU。 So I was wondering what would be the best way to achieve my goal?
所以我想知道实现我的目标的最佳方法是什么?
I could create a geometry shader and simply pass it the quads top left point as well as it's width, height and texture position.我可以创建一个几何着色器,然后简单地将四边形的左上角以及它的宽度、高度和纹理位置传递给它。 The shader could then create the 2 triangles.
然后着色器可以创建 2 个三角形。 However I think this would be quite slow?
但是我认为这会很慢?
You have two potential methods:您有两种可能的方法:
You probably should not use a geometry shader.您可能不应该使用几何着色器。 They typically aren't meant to be run every frame, although they certainly can be.
它们通常并不意味着每帧都运行,尽管它们当然可以。 You get some benefits, particularly very little memory bandwidth being used, but the hardware requirements are significantly higher and the APIs are much stricter.
您会获得一些好处,特别是使用的内存带宽非常少,但硬件要求明显更高,API 也更加严格。 If your data is coming from CPU calculation that can be optimized on there, you may also end up with better performance;
如果您的数据来自可以在那里优化的 CPU 计算,那么您最终也可能获得更好的性能; at best you'll have to either translate the calculations or download the data to video memory.
充其量您必须转换计算或将数据下载到视频内存。
You absolutely do not want to calculate two triangles from the geometry shader, unless you mean two per square.你绝对不想从几何着色器计算两个三角形,除非你的意思是每平方两个。 The main benefit of shaders is parallelism, so you'd want to run through as many squares as possible and draw those in large batches.
着色器的主要优点是并行性,因此您需要遍历尽可能多的方块并大批量绘制它们。 Batching will almost always give you a performance boost, and there are a variety of ways to do it.
批处理几乎总是会给您带来性能提升,并且有多种方法可以做到这一点。 Things like changing the transforms in the API are terribly slow and best avoided (probably not much of an issue if you're on 3.0+, but it used to be a huge one).
像更改 API 中的转换这样的事情非常缓慢,最好避免(如果您使用的是 3.0+,可能不是什么大问题,但它曾经是一个很大的问题)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.