Creates an OpenCL buffer object from an OpenGL buffer object.

cl_mem clCreateFromGLBuffer ( cl_context context,
  cl_mem_flags flags,
  GLuint bufobj,
  cl_int * errcode_ret)



A valid OpenCL context created from an OpenGL context.


A bit-field that is used to specify usage information. Refer to the table at clCreateBuffer for a description of flags. Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE values specified in the table at clCreateBuffer can be used.


The name of a GL buffer object. The data store of the GL buffer object must have have been previously created by calling OpenGL function glBufferData, although its contents need not be initialized. The size of the data store will be used to determine the size of the CL buffer object.


Returns an appropriate error code as described below. If errcode_ret is NULL, no error code is returned.


The size of the GL buffer object data store at the time clCreateFromGLBuffer is called will be used as the size of buffer object returned by clCreateFromGLBuffer. If the state of a GL buffer object is modified through the GL API (e.g. glBufferData) while there exists a corresponding CL buffer object, subsequent use of the CL buffer object will result in undefined behavior.

The clRetainMemObject and clReleaseMemObject functions can be used to retain and release the buffer object.


Returns a valid non-zero OpenCL buffer object and errcode_ret is set to CL_SUCCESS if the buffer object is created successfully. Otherwise, it returns a NULL value with one of the following error values returned in errcode_ret:

  • CL_INVALID_CONTEXT if context is not a valid context or was not created from a GL context.
  • CL_INVALID_VALUE if values specified in flags are not valid.
  • CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is a GL buffer object but does not have an existing data store.
  • CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.


OpenCL Specification

Also see

clCreateBuffer, clReleaseMemObject, clRetainMemObject

Copyright © 2007-2009 The Khronos Group Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.