在 Windows 中设置 OpenGL/Cuda 互操作
我正在编写一个 DLL,需要在 Cuda 3.2 中完成一些工作,在 OpenGL 中完成一些工作。 OpenGL将渲染一些我的Cuda代码需要读入和修改的灰度图像,然后作为纹理返回给OpenGL。我认为我需要创建公益组织来做到这一点。我以前做过一些基本的 OpenGL 东西,但从未使用过扩展,这就是我的问题所在 - 我已经搜索了 2 天,到目前为止还没有找到一个有效的示例,尽管我翻阅了一页又一页代码。我尝试过的示例都不起作用(我确信我的视频卡会支持它,因为是 GTX470)
一些具体问题:
1.我安装了nvidia opengl sdk。我应该使用 glew.h 和 wglew.h 来访问扩展吗?
2. 我的 DLL 没有任何 UI - 我需要创建隐藏窗口还是有更简单的方法来创建离屏渲染上下文?
3. 我可以使用GL_RED_8UI格式创建灰度PBO吗? cuda 和 gl 都会对此感到满意吗?我读了cuda编程手册中的opengl互操作部分,它说GL_RGBA_8UI只能由像素着色器使用,因为它是OpenGL 3.0功能,但我不知道这是否适用于1通道格式。 1 通道浮动也适用于我的目的。
4. 我认为这很容易做到——它真的需要数百行代码吗?
编辑:
我有代码来创建附加到 HBITMAP 的 OpenGL 上下文。我应该创建一个位图渲染上下文,然后尝试将 PBO 附加到它吗?或者渲染到 CPU 内存会减慢我的速度吗?创建一个隐形窗口并将 PBO 附加到其上是否更好?另外,我的 PBO 的像素格式必须与窗口/位图匹配吗?尺寸怎么样?
谢谢,
亚历克斯
I am writing a DLL that needs to do some work in Cuda 3.2 and some work in OpenGL. OpenGL will render some grayscale images that my Cuda code needs to read in and modify, and then give back to OpenGL as a texture. I believe I need to create PBOs to do that. I have done some basic OpenGL stuff before but never worked with extensions, and that's where my problem is - I've been searching for 2 days and so far haven't been able to find a working example, despite wading through pages and pages of code. None of the samples I've tried work (and I'm sure my vid card will support it, being a GTX470)
Some specific questions:
1. I installed the nvidia opengl sdk. Should I be using glew.h and wglew.h to access the extensions?
2. My DLL does not have any UI - do I need to create a hidden window or is there an easier way to create an off-screen rendering context?
3. Can I create a grayscale PBO by using GL_RED_8UI format? Will both cuda and gl be happy with that? I read the opengl interop section in the cuda programming manual and it said GL_RGBA_8UI was only usable by pixel shaders because it was an OpenGL 3.0 feature, but I didn't know if that applied to a 1-channel format. 1 channel float would also work for my purposes.
4. I thought this would be fairly easy to do - does it really require hundreds of lines of code?
Edit:
I have code to create an OpenGL context attached to a HBITMAP. Should I create a bitmap-rendering context and then try to attach a PBO to that? Or will that slow me down by also rendering to CPU memory? Is it better to create an invisible window and attach the PBO to that? Also, does the pixel format of my PBO have to match the window/bitmap? What about the dimensions?
Thanks,
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上有一个如何同时使用 OpenGL 和 CUDA 的示例。看看 SimpleGL 的例子。
There's actually an example of how to use OpenGL and CUDA together. Look at the SimpleGL example.
您可能想看一下这个示例:
https://github.com/nvpro-samples/gl_cuda_interop_pingpong_st< /a>
You may want to take a look at this example:
https://github.com/nvpro-samples/gl_cuda_interop_pingpong_st