C Specification
To create an OpenCL 2D image object from an OpenGL renderbuffer object, call the function
// Provided by cl_khr_gl_sharing
cl_mem clCreateFromGLRenderbuffer(
cl_context context,
cl_mem_flags flags,
cl_GLuint renderbuffer,
cl_int* errcode_ret);
clCreateFromGLRenderbuffer 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 -
renderbuffer is the name of an OpenGL renderbuffer object. The renderbuffer storage must be specified before the image object can be created. The renderbuffer format and dimensions defined by OpenGL will be used to create the 2D image object. Only OpenGL renderbuffers with an internal format that maps to an appropriate Image Channel Order and Image Channel Data Type may be used to create the 2D image object.
-
errcode_ret will return an appropriate error code as described below. If errcode_ret is
NULL, no error code is returned.
Description
If the state of an OpenGL renderbuffer object is modified through the OpenGL
API (i.e. changes to the dimensions or format used to represent pixels of
the OpenGL renderbuffer using appropriate OpenGL API calls such as
glRenderbufferStorage) while there exists a corresponding OpenCL image
object, subsequent use of the OpenCL image object will result in undefined
behavior.
The clRetainMemObject and clReleaseMemObject functions can be used to retain and release the image objects.
The OpenGL Internal Formats and Corresponding OpenCL Internal Formats table describes the list of OpenGL renderbuffer internal formats and the Corresponding OpenCL Image Formats. If an OpenGL renderbuffer object with an internal format from the table is successfully created by OpenGL, then there is guaranteed to be a mapping to one of the corresponding OpenCL image format(s) in that table. Renderbuffer objects created with other OpenGL internal formats may (but are not guaranteed to) have a mapping to an OpenCL image format; if such mappings exist, they are guaranteed to preserve all color components, data types, and at least the number of bits/component actually allocated by OpenGL for that format.
| 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. |
clCreateFromGLRenderbuffer returns a valid non-zero OpenCL image object
and errcode_ret is set to CL_SUCCESS if the image 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 renderbuffer is not an OpenGL renderbuffer object, or if the width or height of renderbuffer is zero.GL_ OBJECT -
CL_INVALID_if the internal format of renderbuffer is not listed in the OpenGL Internal Formats and Corresponding OpenCL Internal Formats table.IMAGE_ FORMAT_ DESCRIPTOR -
CL_INVALID_if renderbuffer is a multi-sample OpenGL renderbuffer object.OPERATION -
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.