Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: clCreateFromGLBuffer crash

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2018

    clCreateFromGLBuffer crash

    Hello every one,

    When I tried to use my vbo with opencl I get a crash when calling clCreateFromGLBuffer

    Below a small code that reproduce the issue:

    Code :
    sf::ContextSettings settings;
    settings.depthBits = 24;
    settings.stencilBits = 8;
    settings.antialiasingLevel = 2;
    sf::Window window(sf::VideoMode(2048, 1024), "GAME",
            sf::Style::Fullscreen, settings);
    cl_platform_id platform_id = NULL;
    cl_device_id device_id = NULL;
    cl_uint ret_num_devices;
    cl_uint ret_num_platforms;
    cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
    ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id,
    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_id, 0 };
    cl_context context = clCreateContext(props, 1, &device_id, NULL, NULL,
    GLuint vboID_m = 0;
    Creation of the vertex buffer object
    glGenBuffers(1, &vboID_m);
    glBindBuffer(GL_ARRAY_BUFFER, vboID_m);
        std::vector<float> tmp = { 0., 0., 0., 0., 0., 0., 0., 0., 0. };
        glBufferData(GL_ARRAY_BUFFER, (tmp.size()) * sizeof(float), 0,
        glBufferSubData(GL_ARRAY_BUFFER, 0, tmp.size() * sizeof(float),
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    cl_int status;
    clCreateFromGLBuffer(context, CL_MEM_READ_WRITE, vboID_m, &status);
    return 0;

    Thanks for your help!

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2013
    Try glFinish() instad of glFlush()

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2018
    Quote Originally Posted by Osbios View Post
    Try glFinish() instad of glFlush()
    Thanks for your reply, unfortunatly it doesn't do the trick

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2018
    When I check the value of ret_num_devices, I get 2. If I change the code to get the platform id for the second device, every things works fine. So I am wondering if the problem is : The opengl context is created for the second platform (my graphic card) and I was trying to access the gpu of my cpu (first platform).

    If this is true, Can you explain me how to retrieve the platform that correspond to the one used by opengl ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts