是否可以让 OpenGL 在内存表面上绘图?
我开始学习 OpenGL,我想知道是否可以让它在我通过其他库获得的视频内存缓冲区上绘制?
I am starting to learn OpenGL and I was wondering if it is possible to have it draw on a video memory buffer that I've obtained through other libraries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了绘制到视频内存中,您可以使用 framebuffer 对象 绘制到 OpenGL 纹理或渲染缓冲区(VRAM屏幕外渲染区域),就像 Stefan 建议的那样。
当涉及到由另一个库创建的 VRAM 缓冲区时,这取决于您正在谈论的库。如果这个库也在底层使用了 OpenGL,那么您需要深入了解该库才能获取该“缓冲区”(无论是纹理,您可以使用 FBO 直接渲染到其中,还是 GL 缓冲区对象,您可以在其中读取渲染的内容)使用 PBO 的像素数据
如果此库使用其他 API 来连接 GPU,则有没有那么多 它使用 OpenCL 或 CUDA,这些 API 具有直接使用其内存缓冲区或图像作为 OpenGL 缓冲区或纹理的功能,然后您可以使用上述技术进行渲染。
如果 但至少 nVidia 有一个扩展来直接进行。使用 Direct3D 9 表面和纹理作为 OpenGL 缓冲区和纹理,但我对此没有任何经验,也不知道这是否得到广泛支持。
For drawing into video memory you can use framebuffer objects to draw into OpenGL textures or renderbuffers (VRAM areas for offscreen rendering), like Stefan suggested.
When it comes to a VRAM buffer created by another library, it depends what library you are talking about. If this library also uses OpenGL under the hood, you need some insight into the library to get that "buffer" (be it a texture, into which you can render directly using FBOs, or a GL buffer object, into which you can read rendered pixel data using PBOs.
If this library uses some other API to interface the GPU, there are not so many possibilities. If it uses OpenCL or CUDA, these APIs have functions to directly use their memory buffers or images as OpenGL buffers or textures, which you can then render into with the mentioned techniques.
If this library uses Direct3D under the hood, it gets a bit more difficult. But at least nVidia has an extension to directly use Direct3D 9 surfaces and textures as OpenGL buffers and textures, but I don't have any experience with this and neither do I know if this is widely supported.
你不能让 OpenGL 直接绘制到任意内存,原因之一是在大多数实现中 OpenGL 绘制发生在视频 RAM 中,而不是系统内存中。不过,您可以绘制到 OpenGL 离屏上下文,然后将结果读回到系统内存中的任何位置。在网络上搜索帧缓冲区对象 (FBO) 应该可以找到文档和教程。
如果您拥有的内存已经在 VRAM 中,例如通过硬件加速解码,那么如果它可用作 OpenGL 纹理,您可能可以直接绘制到它 - 那么您可以使用一些渲染到纹理技术,这将节省您的传输VRAM 中的数据和数据。
You cannot let OpenGL draw directly to arbitrary memory, one reason is that in most implementations OpenGL drawing happens in video RAM, not system memory. You can however draw to an OpenGL offscreen context and then read back the result to any place in system memory. A web search for framebuffer objects (FBOs) should point you to documentation and tutorials.
If the memory you have is already in VRAM, for example decoded by hardware acceleration, then you might be able to draw to it directly if it is available as an OpenGL texture - then you can use some render to texture techniques that will save you transferring data from and to VRAM.