在 OpenGL ES 2.0 中渲染大量较小的对象

发布于 2024-11-28 10:27:57 字数 513 浏览 0 评论 0原文

向大家问好。

最近几天我一直在努力解决 OpenGL ES 2.0 和一个特殊问题。我正在寻求为 iPhone 实现几何战争克隆,以获取乐趣并学习这项技术。因此,我的 3D 编程背景相当不错,尽管主要集中在向量数学方面,而不是对图形 API 的绘制调用,因为过去几年我一直断断续续地使用 DirectX。然而,问题是我主要处理更大的网格,以多种方式加载、翻译和转换它们,现在我发现自己想要处理小网格,以及很多网格。

这些对象是三角形、矩形、六边形等,我希望能够单独修改它们(例如,使另一边呈波浪形或脉动)。当我使用多个大网格时,我为它们进行了单独的绘制调用,轻松附加着色器及其各自的参数,但在这种情况下,我想在一次调用中渲染所有内容,而我的知识却让我失败了。

所以,为了澄清我的问题。如何单独修改小网格(最好存储在一个顶点数组中)并使用 OpenGL ES 2.0 着色器一次性渲染它们?

尽管代码示例更受欢迎,但“简单”的解释足以让我开始。我想我在这里遗漏了一些微不足道的东西,非常感谢任何帮助。

预先感谢,

卡尔

Greetings each and all.

I've been struggling with OpenGL ES 2.0 and a particular problem for the last few days now. I'm looking to implement a Geometry Wars clone, for the iPhone, for fun and to learn this technology. So, my background in 3d programming is fairly good, although mainly concentrated around vector mathematics rather then draw calls towards the graphical API, as I've been working with DirectX on and off for the last couple of years. The problem, however, is that I've mainly been working with bigger meshes, loading, translating and transforming them in several ways and now I find myself in a position where I want to handle small meshes, and lots of them.

The objects are triangles, rectangles, hexagons etc. and I want the ability to modify them all separately (eg making the other edge wavy or pulsating). When I've worked with multiple big meshes I've made separate draw calls for them, easily attaching shaders and their respective parameters, but in this case I would like to render it all in one call and there's where my knowledge fails me.

So, to clearify my question. How are you to modify small meshes, preferably stored in one vertex array, individually and render them all at once using shaders with OpenGL ES 2.0?

Although code examples are more then welcome, a "simple" explanation would be enough to get me started. I assume I'm missing something trivial here and any help is greatly appreciated.

Thanks in advance,

Karl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2024-12-05 10:27:57

听起来像实例(和实例化数组) 可以解决您的问题,尽管它可能有点太先进了一般情况下都支持 iOS 或 ES。通过这种方式,您可以使用每个实例数据(例如特定的纹理索引或子纹理或着色器参数)渲染相同几何体的许多副本。但是,当然,您无法在一次绘制调用中使用完全不同的着色器渲染不同的对象。

否则,更简单(可能优化程度更低)的函数 glMultiDrawArrays/Elements 在一次调用中渲染多个完全不同的几何图形,但您无法分辨哪个三角形属于着色器中的哪个对象,我也怀疑它带来了很大的性能提升。

Sounds like Instancing (and instanced arrays) can be an answer to your problem, although it might be a bit too advanced for iOS or ES in general to be supported. This way you can render many copies of the same geometry with per instance data (like a specific texture index or sub-texture or shader parameters). But of course, you cannot render different objects with completely different shaders in one draw call.

Otherwise the much simpler (and maybe much less optimized) function glMultiDrawArrays/Elements renders multiple completely different geometries in one call, but you cannot tell which triangle belongs to which object in the shader and I also doubt that it gives that much of a performance boost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文