简体   繁体   English

从OpenCL内核修改VBO数据

[英]Modify VBO data from OpenCL kernel

I want the output of my OpenCL program to be drawn directly on the screen, without being downloaded from the GPU to then be uploaded again. 我希望我的OpenCL程序的输出直接在屏幕上绘制,而不是从GPU下载然后再上传。 How would I put data into my vertex array from the kernel? 我如何将数据从内核放入顶点数组? I'm using glfw3 and glew together with the default OpenCL library by nVidia in c++. 我正在使用glfw3,并与nVidia在c ++中的默认OpenCL库一起使用。

This example may help: http://enja.org/2010/08/27/adventures-in-opencl-part-2-particles-with-opengl/ 该示例可能会有所帮助: http : //enja.org/2010/08/27/adventures-in-opencl-part-2-particles-with-opengl/

The key requirement is to set up the CL/GL shared context. 关键要求是设置CL / GL共享上下文。 Depending on your GL host, you need to set different properties to the CL context: 根据您的GL主机,您需要为CL上下文设置不同的属性:

Apple: 苹果:

 cl_context_properties props[] =
    {
        CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup,
        0
    };

Windows: 视窗:

cl_context_properties props[] =
        {
            CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
            CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
            CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(),
            0
        };

Other: 其他:

cl_context_properties props[] =
        {
            CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
            CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
            CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(),
            0
        };

Then, you create the context, and use the GL buffers (acquiring and releasing them each time): 然后,创建上下文,并使用GL缓冲区(每次都获取并释放它们):

context = cl::Context(CL_DEVICE_TYPE_GPU, props);
cl::BufferGL glbuffer(context, CL_MEM_READ_WRITE, myvbo, &err);

for (each frame){
     queue.enqueueAcquireGLObjects(&glbuffer);
     //use glbuffer as if it is a clbuffer
     queue.enqueueReleaseGLObjects(&glbuffer);
}

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

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