Hello All! I'm new to OpenCL-GL interop , while trying to use clCreateFromGLBuffer() , I encountered an error CL_INVALID_CONTEXT. However, I have already declared vbo buffer and filled the buffer data .
Here are some snippets ,and their success checkpoints:
void draw_cube(float r, float g, float b)
{
glGenBuffers(1, &vboId3);
glBindBuffer(GL_ARRAY_BUFFER, vboId3);
glBufferData(GL_ARRAY_BUFFER,sizeof(color), color, GL_STATIC_DRAW);
glGenBuffers(1, &vboId);
glBindBuffer(GL_ARRAY_BUFFER, vboId);
glBufferData(GL_ARRAY_BUFFER,72*sizeof(float), vertices, GL_STATIC_DRAW);
glGenBuffers(1, &vboId2);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId2);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,36*sizeof(GLubyte), indices, GL_STATIC_DRAW);
cl_mem cl_vbo_mem = clCreateFromGLBuffer(clGPUContext,CL_MEM_READ_WRITE, vboId,&errcode ); [ERROR ]
checkerr(errcode);
// glBindBuffer(GL_ARRAY_BUFFER, vboId3);
//glVertexPointer(3,GL_FLOAT, 0, 0);
glColorPointer(3, GL_FLOAT, 0,0);
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
printf("Pointers set\n");
printf("preparing to draw\n");
glDrawElements(GL_TRIANGLE_STRIP,36, GL_UNSIGNED_BYTE,0); [[[[[[CUBE SUCCESSFULLY DRAWN]]]]]
printf("drawn\n");
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void display()
{
...........
.....
draw_cube();
}
main()
{....;
.........;
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)platform, 0 }; [ [SUCCESS]]
checkerr(errcode);
clGPUContext = clCreateContext(props, 1, &device[0], NULL, NULL, &errcode); [ [SUCCESS]]
checkerr(errcode);
................
....................
glutDisplayFunc(display);
}
Solved! Go to Solution.
This may apply
From http://developer.amd.com/download/AM..._Developer.pdf
section 5.3
"For OpenGL interoperability with OpenCL, there currently is a requirement on when the
OpenCL context is created and when texture/buffer shared allocations can be made. To use
shared resources, the OpenGL application must create an OpenGL context and then an
OpenCL context. All resources (GL buffers and textures) created after creation of the OpenCL
context can be shared between OpenGL and OpenCL. If resources are allocated before the
OpenCL context creation, they cannot be shared between OpenGL and OpenCL."
This may apply
From http://developer.amd.com/download/AM..._Developer.pdf
section 5.3
"For OpenGL interoperability with OpenCL, there currently is a requirement on when the
OpenCL context is created and when texture/buffer shared allocations can be made. To use
shared resources, the OpenGL application must create an OpenGL context and then an
OpenCL context. All resources (GL buffers and textures) created after creation of the OpenCL
context can be shared between OpenGL and OpenCL. If resources are allocated before the
OpenCL context creation, they cannot be shared between OpenGL and OpenCL."