[squeak-dev] Re: OpenCL and OpenGL interop

Josh Gargus josh at schwa.ca
Mon Jun 7 19:08:16 UTC 2010


On Jun 7, 2010, at 11:39 AM, askoh wrote:

> 
> The following code is from Nvidia example oclSimpleGL_vc9.sln
> Can we create the following code in Squeak without creating primitives?
> 

Ah, I see what you're getting at.  The answer is "yes and no".  As I said before, in order to have OpenCL/OpenGL compatibility, you need to create an OpenCL context that refers to the OpenGL context that it wishes to share with (see Section 9.11 of the OpenCL specification: "Creating CL context from a GL context or share group").  The hitch is that we don't have easy access to the OpenGL context created by Croquet-OpenGL (a new B3DAcceleratorPlugin primitive is required).

Once you have obtained the OpenGL context handle and used it to create a new OpenCL context, you can directly transcribe the code below into Squeak using only FFI calls.

Cheers,
Josh




> Thanks,
> Aik-Siong Koh
> 
> void createVBO(GLuint* vbo)
> {
>    // create VBO
>    unsigned int size = mesh_width * mesh_height * 4 * sizeof(float);
>    if(!bQATest)
>    {
>        // create buffer object
>        glGenBuffers(1, vbo);
>        glBindBuffer(GL_ARRAY_BUFFER, *vbo);
> 
>        // initialize buffer object
>        glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);
> 
>        #ifdef GL_INTEROP
>            // create OpenCL buffer from GL VBO
>            vbo_cl = clCreateFromGLBuffer(cxGPUContext, CL_MEM_WRITE_ONLY,
> *vbo, NULL);
>        #else
>            // create standard OpenCL mem buffer
>            vbo_cl = clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, size,
> NULL, &ciErrNum);
>        #endif
>        shrCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);
>    }
>    else 
>    {
>        // create standard OpenCL mem buffer
>        vbo_cl = clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, size, NULL,
> &ciErrNum);
>        shrCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);
>    }
> }
> 
> -- 
> View this message in context: http://forum.world.st/OpenCL-and-OpenGL-interop-tp2246017p2246383.html
> Sent from the Squeak - Dev mailing list archive at Nabble.com.
> 




More information about the Squeak-dev mailing list