渲染器效率

发布于 2024-10-03 04:25:57 字数 298 浏览 2 评论 0原文

好的,我有一个渲染器类,其中包含程序其余部分调用的各种特殊函数:

  • DrawBoxFilled
  • DrawText
  • DrawLine
  • 大约 30 个以上...

每个函数分别调用 glBegin/glEnd ,我知道这可能非常低效(其甚至已弃用)。所以无论如何,我正在计划完全重写渲染器,我需要知道设置函数的最有效方法,以便当有东西调用它时,它会立即绘制所有内容,或者它需要执行的任何其他操作高效运行。提前致谢 :)

Ok, I have a renderer class which has all kinds of special functions called by the rest of the program:

  • DrawBoxFilled
  • DrawText
  • DrawLine
  • About 30 more...

Each of these functions calls glBegin/glEnd separably, which I know can be very inefficiently(its even deprecated). So anyways, I am planning a total rewrite of the renderer and I need to know the most efficient ways to set up the functions so that when something calls it, it draws it all at once, or whatever else it needs to do so it will run most efficiently. Thanks in advance :)

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

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

发布评论

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

评论(2

似最初 2024-10-10 04:25:57

有效的渲染方法通常是使用 VBO(顶点缓冲区对象)来存储顶点数据,但只有在渲染(大部分)静态数据时,这才真正有意义。

如果不了解更多关于应用程序应该呈现的内容,就很难说应该如何构建它。但理想情况下,您永远不应该绘制单个基元,而应该绘制顶点缓冲区的内容(子集)。

The efficient way to render is generally to use VBO's (vertex buffer objects) to store your vertex data, but that is only really meaningful if you are rendering (mostly) static data.

Without knowing more about what your application is supposed to render, it's hard to say how you should structure it. But ideally, you should never draw individual primitives, but rather draw the contents (a subset) of a vertexbuffer.

在巴黎塔顶看东京樱花 2024-10-10 04:25:57

最有效的方法是根本不公开此类低级方法。相反,您想要做的是构建一个 场景图,它是一个包含整个场景的表示。您可以在“更新”方法中更新场景图,然后在“渲染”方法中一次性渲染整个场景。

另一种略有不同的方法是每帧重新构建整个场景图。这样做的优点是场景图一旦组成就不会改变。因此,您可以在另一个线程上调用“渲染”方法,同时“更新”方法正在遍历并构建下一个帧的场景。

如果没有完整的场景图,许多更高级的效果根本不可能实现。例如,您无法进行阴影贴图(这需要您从不同的角度多次渲染场景),您无法进行延迟渲染,它还会进行任何依赖于排序绘制顺序的操作(例如阿尔法混合)非常困难。

从您的方法名称来看,您似乎正在以 2D 方式工作,因此虽然阴影贴图可能在您的功能列表中排名不高,但 alpha 混合延迟渲染可能排名靠前。

The most efficient way is not to expose such low-level methods at all. Instead, what you want to do is build a scene graph, which is a data structure that contains a representation of the entire scene. You update the scene graph in your "update" method, then render the whole thing in one go in your "render" method.

Another, slightly different approach is to re-build the entire scene graph each frame. This has the advantage that once the scene graph is composed, it doesn't change. So you can call your "render" method on another thread while your "update" method is going through and constructing the scene for the next frame at the same time.

Many of the more advanced effects are simply not possible without a complete scene graph. You can't do shadow mapping, for instance (which requires you to render the scene multiple times from a different angle), you can't do deferred rendering, it also makes anything which relies on sorted draw order (e.g. alpha-blending) very difficult.

From your method names, it looks like you're working in 2D, so while shadow mapping is probably not high on your feature list, alpha-blending deferred rendering might be.

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