OpenGL 着色器?

发布于 2024-09-25 14:54:36 字数 299 浏览 1 评论 0原文

我正在用 Java LJGWL (OpenGL) 编写一个游戏。我正在使用一个库来为我处理很多混乱的细节,但需要找到更快的方法来做到这一点。

基本上我想将屏幕上的每个像素设置为尽可能快地表示随机颜色。 “随机颜色”只是一个每 2-3 秒更新一次的数组 [][]。我尝试过绘制矩形和使用图像,对于我想做的事情来说,两者都非常慢。

我想我想学习如何编写GPU着色器?这是最快的方法吗? LJGWL 将 OpenGL api 公开给 java。有关于如何开始使用 OpenGL 着色器的基本教程吗?或者我应该动态创建某种纹理,然后抛出整个纹理,这样会更快吗?

I'm writing a game in Java, LJGWL (OpenGL). I'm using a library that handles a lot of messy details for me, but need to find a lot faster way to do this.

Basically I want to set every pixel on the screen to say a random color as fast a possible. The "random colors" is just an Array [][] that gets updated every 2-3 seconds. I've tried drawing rects and using images, both are pretty slow for what I want to do.

I think I want to learn how to write a GPU shader? That is the fastest way to do this? LJGWL exposes OpenGL api to java. Any basic tutorials on how to get started with OpenGL shaders? Or should I dynamically create a texture of some sort and then just throw up the entire texture, would that be faster?

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

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

发布评论

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

评论(4

暖树树初阳… 2024-10-02 14:54:36

如果您静态显示相同的图像,那么使用纹理或显示列表就足够了。但当你想经常更新它时,着色器确实是最好的选择。着色器代码在 GPU 上执行并修改 GRAM 中的数据,因此从 CPU 到 GPU 的传输不会出现瓶颈。下一个最好的东西可能是像素或帧缓冲区对象。缓冲区对象允许您通过 DMA 读/写 GRAM(无需通过 CPU),因此速度非常快。

我还没有编写任何着色器,所以我无法推荐任何好的资源。但是SongHo 的 OpenGL 页面是了解缓冲区对象的好地方。 (不过他的例子是用 C++ 编写的)

If it were the case that you were statically displaying the same image, than using a texture or display list would suffice. But as you want to frequently update it, shaders really are the best option. Shader code executes on the GPU and modifies data in GRAM, so you have no bottle neck transferring from CPU to GPU. The next best thing would probably be a Pixel or Frame Buffer Object. Buffer Objects let you read/write to GRAM via DMA (without having to go through the CPU) so they can be pretty fast.

I haven't written any shaders yet, so I can't recommend any good resources. But SongHo's OpenGL pages are a good place to learn about Buffer Objects. (His examples are in C++ though)

溺孤伤于心 2024-10-02 14:54:36

纹理是在屏幕上绘制内容最快的方法,将纹理映射到屏幕上的四边形绘制,它应该足够快。当需要重新上传纹理数据时,使用glTexSubimage2D来更新它。

无需使用着色器。

Textures are the fastest way to draw something on screen, draw a texture mapped quad into the screen, it should be fast enough. When you need to reupload the texture data, use glTexSubimage2D to update it.

No need to use shaders.

一紙繁鸢 2024-10-02 14:54:36

我还没有在 OpenGL 中使用着色器进行任何工作,但在多个场合给出相同的场景,我使用在屏幕顶部抛出的纹理来处理它,并且效果非常有效。

I've yet to do any work with shaders in OpenGL, but given the same scenario in multiple occasions, I handled it with a texture I threw up across the screen on top, and it worked quite effectively.

§对你不离不弃 2024-10-02 14:54:36

我不知道你是如何准确绘制像素的,但你达到的这个限制可能是因为你传输的数据量(效率低下?)。每 2-3 秒更新一次充满像素的屏幕应该不难。虽然着色器让你更接近显卡,但它们永远不会让低效的方法变得更快,所以......

为什么你的代码这么慢?

  1. 什么代码?您到底尝试了什么代码?你使用了什么纹理,渲染到......?
  2. 慢吗?有多慢?您预计速度有多快?
  3. 在视频 RAM 中获得 1920x1080(?) 像素的速度有多快,您的硬件、驱动程序、操作系统是什么?

我认为您需要编辑/重新发布,然后我们才能帮助您解决问题。仅仅因为它很慢,并不能保证着色器会快一点

I don't know how you are drawing your pixels exactly, but this limit you hit could be because of the amount of data you transfer (inefficiently?). Updating a screen full of pixels every 2-3 seconds shouldn't be hard at all. Although shaders bring you closer to the graphics card, they will never make inefficient methods fast, so...

Why is your code so slow?

  1. What code? What code exactly did you try? What texture did you use, render to, ...?
  2. Is it slow? How slow? How fast do you expect it to be?
  3. How quickly can one get 1920x1080(?) pixels in video ram, what's your hardware, drivers, OS?

I think you need to edit/repost before we can help you solve your problem. Just because it is slow, is no guarantee at all that shaders will even be one bit faster.

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