C Specification
To create an OpenCL buffer object from an OpenGL buffer object, call the function
// Provided by cl_khr_gl_sharing
cl_mem clCreateFromGLBuffer(
cl_context context,
cl_mem_flags flags,
cl_GLuint bufobj,
cl_int* errcode_ret);
clCreateFromGLBuffer is provided by the cl_khr_gl_sharing extension.
|
Parameters
-
context is a valid OpenCL context created from an OpenGL context.
-
flags is a bit-field that is used to specify usage information. Refer to the Memory Flags table for a description of flags. Only the
CL_MEM_,READ_ ONLY CL_MEM_andWRITE_ ONLY CL_MEM_flags specified in that table can be used.READ_ WRITE -
bufobj is the name of an OpenGL buffer object. The data store of the OpenGL buffer object must have been previously created by calling
glBufferData, although its contents need not be initialized. The size of the data store will be used to determine the size of the OpenCL buffer object. -
errcode_ret will return an appropriate error code as described below. If errcode_ret is
NULL, no error code is returned.
Description
The size of the OpenGL 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 an OpenGL buffer object is modified through the OpenGL API
(e.g. glBufferData) while there exists a corresponding OpenCL buffer
object, subsequent use of the OpenCL buffer object will result in undefined
behavior.
The clRetainMemObject and clReleaseMemObject functions can be used to retain and release the buffer object.
The OpenCL buffer object created using clCreateFromGLBuffer can also be used to create an OpenCL 1D image buffer object.
| Refer to the Lifetime of Shared OpenCL/OpenGL Memory Objects and Acquiring, Releasing, and Synchronizing Access to Shared OpenCL/OpenGL Memory Objects sections for more information. |
clCreateFromGLBuffer 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_if context is not a valid context or was not created from an OpenGL context.CONTEXT -
CL_INVALID_if values specified in flags are not valid.VALUE -
CL_INVALID_if bufobj is not an OpenGL buffer object or is a OpenGL buffer object but does not have an existing data store or the size of the buffer is 0.GL_ OBJECT -
CL_OUT_if there is a failure to allocate resources required by the OpenCL implementation on the device.OF_ RESOURCES -
CL_OUT_if there is a failure to allocate resources required by the OpenCL implementation on the host.OF_ HOST_ MEMORY
Document Notes
For more information, see the OpenCL Specification
This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.