AnsweredAssumed Answered

CL_INVALID_CONTEXT error when using clCreateFromGLBuffer()

Question asked by bhawna.keswani on Jan 10, 2015
Latest reply on Jan 11, 2015 by moozoo

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);

}

Outcomes