使用 OpenGL 调整图像大小
我想使用 OpenGL 调整图像大小。我更喜欢 Java,但 C++ 也可以。
我对整个事情真的很陌生,所以这是我所看到的文字过程:
- 将图像作为纹理加载到 OGL 中,
- 设置一些关于状态和状态的东西。过滤
- 将不同大小的纹理绘制到另一个纹理上
- 将纹理数据放入数组或其他内容
您认为使用 OpenGL 和 GPU 是否会比使用基于 CPU 的 BLIT 库更快?
谢谢!
I'd like to resize an image using OpenGL. I'd prefer it in Java, but C++ is OK, too.
I am really new to the whole thing so here's the process in words as I see it:
- load the image as a texture into OGL
- set some stuff, regarding state & filtering
- draw the texture in different size onto another texture
- get the texture data into an array or something
Do you think if it would be faster to use OpenGL and the GPU than using a CPU-based BLIT library?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以简单地使用硬件 blit 功能:
glBlitFramebuffer
,而不是将四边形渲染到目标 FBO 中。它的参数很简单,但需要仔细准备源和目标 FBO:glCheckFramebufferStatus
)glBindFramebuffer)
glDraw/ReadBuffers
)glBlitFramebuffer
,在参数中设置 GL_LINEAR 过滤器我敢打赌,它在 GPU 上会快得多,尤其是对于大图像。
Instead of rendering a quad into the destination FBO, you can simply use hardware blit functionality:
glBlitFramebuffer
. Its arguments are straight forward, but it requires a careful preparation of your source and destination FBO's:glCheckFramebufferStatus
)glBindFramebuffer
)glDraw/ReadBuffers
)glBlitFramebuffer
, setting GL_LINEAR filter in the argumentI bet it will be much faster on GPU, especially for large images.
视情况而定,如果图像很大,使用 OpenGL 可能会更快。但是,如果它只是执行调整大小过程,而 GPU 端没有更多处理,那么这是不值得的,因为很可能会比 CPU 慢。
但如果您需要调整图像大小,并且可以在 OpenGL 中实现进一步处理,那么这是一个值得考虑的想法。
Depends, if the images are big, it might be faster using OpenGL. But if it's just doing the resize process and no more processing on the GPU side, then it's not worth it as is very likely that is going to be slower than the CPU.
But if you need to resize the image, and you can implement further processing in OpenGL, then is a worthy idea.