简体   繁体   English

使用OpenGL调整图像大小

[英]Resizing an image using OpenGL

I'd like to resize an image using OpenGL. 我想使用OpenGL调整图像大小。 I'd prefer it in Java, but C++ is OK, too. 我更喜欢Java,但C ++也没问题。

I am really new to the whole thing so here's the process in words as I see it: 我对整个事情都很陌生,所以这就是我所看到的文字过程:

  1. load the image as a texture into OGL 将图像作为纹理加载到OGL中
  2. set some stuff, regarding state & filtering 设置一些关于状态和过滤的东西
  3. draw the texture in different size onto another texture 将不同大小的纹理绘制到另一个纹理上
  4. 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? 您认为使用OpenGL和GPU比使用基于CPU的BLIT库更快吗?

Thanks! 谢谢!

Instead of rendering a quad into the destination FBO, you can simply use hardware blit functionality: glBlitFramebuffer . 您可以简单地使用硬件blit功能: glBlitFramebuffer ,而不是将四元组渲染到目标FBO中。 Its arguments are straight forward, but it requires a careful preparation of your source and destination FBO's: 它的论点是直截了当的,但它需要仔细准备你的源和目标FBO:

  • ensure FBO's are complete ( glCheckFramebufferStatus ) 确保FBO完整( glCheckFramebufferStatus
  • set read FBO target and write FBO target independently ( glBindFramebuffer ) 设置读取FBO目标并独立写入FBO目标( glBindFramebuffer
  • set draw buffers and read buffers ( glDraw/ReadBuffers ) 设置绘制缓冲区和读缓冲区( glDraw/ReadBuffers
  • call glBlitFramebuffer , setting GL_LINEAR filter in the argument 调用glBlitFramebuffer ,在参数中设置GL_LINEAR过滤器

I bet it will be much faster on GPU, especially for large images. 我敢打赌它在GPU上要快得多,特别是对于大型图像。

Depends, if the images are big, it might be faster using OpenGL. 取决于,如果图像很大,使用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. 但是,如果它只是在调整大小进程而在GPU端没有更多的处理,那么它不值得,因为它很可能比CPU慢。

But if you need to resize the image, and you can implement further processing in OpenGL, then is a worthy idea. 但是如果你需要调整图像大小,并且可以在OpenGL中实现进一步处理,那么这是一个值得的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM