How to update OpenCL-OpenGL shared buffer data in OpenCL kernel?
<p>I am trying to populate the OpenCL-OpenGL shared buffer from OpenCL kernel. I have written a simple program to plot 3 points. The (x,y,z) values for the 3 vertices are populated in the kernel. But the points are not plotted as expected. I know that I am not accessing the shared buffer correctly. The code is as follows:</p>

<pre><code>cl_GLuint vbo;
struct vertex
{
  float x, y, z, w; // position

}pos[3];


void CreateVBO(){

   glGenBuffers(1,&amp;vbo);
   glBindBuffer(GL_ARRAY_BUFFER,vbo);
   glBufferData(GL_ARRAY_BUFFER,3*sizeof(vertex),pos,GL_DYNAMIC_DRAW);

}

void Display(void)
{

    glLoadIdentity();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPointSize(10.0);
    CreateVBO();
    glBindBuffer(GL_ARRAY_BUFFER,vbo);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(4, GL_FLOAT, 0, 0);
    glDrawArrays(GL_POINTS,0,3);
    glDisableClientState(GL_VERTEX_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER,0);  
    glutSwapBuffers();
}

void InitGL(int argc , char * argv[])
{
    glutInit(&amp;argc , argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("Draw Points");
    glewInit();   
    glutDisplayFunc(Display);
    glClearColor(0,0,0,1);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glEnable( GL_POINT_SMOOTH | GL_DEPTH_TEST );
}

//MAIN program  

global_item_size = local_item_size = 1
InitGL(argc,argv);

//set properties
cl_context_properties properties[] =
{
    CL_GL_CONTEXT_KHR,   (cl_context_properties)wglGetCurrentContext(),
    CL_WGL_HDC_KHR,      (cl_context_properties)wglGetCurrentDC(),
    CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], 
    0
};

/* Create OpenCL context */
context = clCreateContext(properties, 1, device_id, NULL, NULL, &amp;ret);

/* Create Command Queue */
cmd_queue = clCreateCommandQueue(context, device_id[0], 0, &amp;ret);

/* Create Kernel Program from the source */
program = clCreateProgramWithSource(context, 1, (const char **)&amp;source_str, (const size_t *)&amp;source_size, &amp;ret);

/* Build Kernel Program */
ret = clBuildProgram(program, 1, device_id, NULL, NULL, NULL);

/* Create OpenCL Kernel */ 
kernel = clCreateKernel(program, "drawPoints", &amp;ret);

/* create opencl buffer*/
vbo_cl = clCreateFromGLBuffer(context,CL_MEM_READ_WRITE,vbo,NULL);

/* Set OpenCL Kernel Parameters */
ret = clSetKernelArg(kernel, 0,sizeof(cl_mem), (void *)&amp;vbo_cl); //,

glFlush(); 
ret = clEnqueueAcquireGLObjects(cmd_queue, 1, &amp;vbo_cl, 0,0,0);

/* Execute OpenCL Kernel */
ret = clEnqueueNDRangeKernel(cmd_queue, kernel, 1, NULL,&amp;global_item_size, &amp;local_item_size, 0, NULL, &amp;event);

ret = clEnqueueReleaseGLObjects(cmd_queue, 1, &amp;vbo_cl, 0,0,0);
clFinish(cmd_queue);

Display();
glutMainLoop();




//KERNEL CODE (Nvidia 820M Geforce GPU )
__kernel void drawPoints(__global float4* buffer) 
{
buffer[0] = (float4)(0, 1, -1, 1.0f);
buffer[1] = (float4)(-1, -1, -1, 1.0f);
buffer[2] = (float4)(1, -1, -1, 1.0f);
}
</code></pre>

<p>I am using the NVIDIA Geforce 820M GPU. Currently the kernel does just the populating of buffer.I have tried initializing the <code>pos[3]</code> values in <code>CreateVBO()</code> function and then tried updating it in the kernel. In both cases, the program executes without any errors. A point is plotted at co-ordinate (0,0,0) which is not the expected result. Please let me know the correct way of modifying/updating the OpenGL buffer data from OpenCL kernel.</p>