---
name: "clCreateFromGLTexture"
section: "3clc"
platform: "linux"
package: "opencl-1.2-man-doc"
version: "1.0~svn33624-5.1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/clCreateFromGLTexture"
---

# clCreateFromGLTexture(3clc)

Creates an OpenCL image object, image array object, or image buffer object from an OpenGL texture object, texture array object, texture buffer object, or a single face of an OpenGL cubemap texture object.

## NAME

clCreateFromGLTexture - Creates an OpenCL image object, image array object, or image buffer object from an OpenGL texture object, texture array object, texture buffer object, or a single face of an OpenGL cubemap texture object.

##

**cl\_mem clCreateFromGLTexture(cl\_context** *context***, cl\_mem\_flags** *flags***, GLenum** *texture\_target***, GLint** *miplevel***, GLuint** *texture***, cl\_int \*** *errcode\_ret***);**

## PARAMETERS

 *context*

A valid OpenCL context created from an OpenGL context.

 *flags*

A bit-field that is used to specify usage information. Refer to the table for [**clCreateBuffer**(3clc)](/clCreateBuffer/3clc.md)for a description of *flags*. Only the values **CL\_MEM\_READ\_ONLY**, **CL\_MEM\_WRITE\_ONLY** and **CL\_MEM\_READ\_WRITE** can be used.

 *texture\_target*

*texture\_target* This value must be one of **GL\_TEXTURE\_1D**, **GL\_TEXTURE\_1D\_ARRAY**, **GL\_TEXTURE\_BUFFER**, **GL\_TEXTURE\_2D**, **GL\_TEXTURE\_2D\_ARRAY**, **GL\_TEXTURE\_3D**, **GL\_TEXTURE\_CUBE\_MAP\_POSITIVE\_X**, **GL\_TEXTURE\_CUBE\_MAP\_POSITIVE\_Y**, **GL\_TEXTURE\_CUBE\_MAP\_POSITIVE\_Z**, **GL\_TEXTURE\_CUBE\_MAP\_NEGATIVE\_X**, **GL\_TEXTURE\_CUBE\_MAP\_NEGATIVE\_Y**, **GL\_TEXTURE\_CUBE\_MAP\_NEGATIVE\_Z**, or **GL\_TEXTURE\_RECTANGLE**. This requires OpenGL 3.1. Alternatively, **GL\_TEXTURE\_RECTANGLE\_ARB** may be specified if the OpenGL extension GL\_ARB\_texture\_rectangle is supported. *texture\_target* is used only to define the image type of *texture*. No reference to a bound GL texture object is made or implied by this parameter.

 *miplevel*

The mipmap level to be used. If *texture\_target* is **GL\_TEXTURE\_BUFFER**, miplevel must be 0. Implementations may return **CL\_INVALID\_OPERATION** for miplevel values \> 0

 *texture*

The name of a GL 1D, 2D, 3D, 1D array, 2D array, cubemap, rectangle or buffer texture object. The texture object must be a complete texture as per OpenGL rules on texture completeness. The *texture* format and dimensions defined by OpenGL for the specified *miplevel* of the texture will be used to create the OpenCL image memory object. Only GL texture objects with an internal format that maps to appropriate image channel order and data type specified in tables 5.5 and 5.6 may be used to create the OpenCL image memory object.

 *errcode\_ret*

Returns an appropriate error code as described below. If *errcode\_ret* is NULL, no error code is returned.

## NOTES

If the state of a GL texture object is modified through the GL API (e.g. **glTexImage2D**, **glTexImage3D** or the values of the texture parameters **GL\_TEXTURE\_BASE\_LEVEL** or **GL\_TEXTURE\_MAX\_LEVEL** are modified) while there exists a corresponding CL image object, subsequent use of the CL image object will result in undefined behavior.

The [**clRetainMemObject**(3clc)](/clRetainMemObject/3clc.md) and [**clReleaseMemObject**(3clc)](/clReleaseMemObject/3clc.md) functions can be used to retain and release the image objects.

## ERRORS

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\_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 or if value specified in *texture\_target* is not one of the values specified in the description of *texture\_target*.

• CL\_INVALID\_MIP\_LEVEL if *miplevel* is less than the value of *levelbase* (for OpenGL implementations) or zero (for OpenGL ES implementations); or greater than the value of *q* (for both OpenGL and OpenGL ES). *levelbase* and *q* are defined for the texture in section 3.8.10 (Texture Completeness) of the OpenGL 2.1 specification and section 3.7.10 of the OpenGL ES 2.0.

• CL\_INVALID\_MIP\_LEVEL if *miplevel* is greater than zero and the OpenGL implementation does not support creating from non-zero mipmap levels.

• CL\_INVALID\_GL\_OBJECT if *texture* is not a GL texture object whose type matches *texture\_target*, if the specified *miplevel* of *texture* is not defined, or if the width or height of the specified *miplevel* is zero.

• CL\_INVALID\_IMAGE\_FORMAT\_DESCRIPTOR if the OpenGL texture internal format does not map to a supported OpenCL image format.

• CL\_INVALID\_OPERATION if texture is a GL texture object created with a border width value greater than zero.

• CL\_OUT\_OF\_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device.

• CL\_OUT\_OF\_HOST\_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.

## SPECIFICATION

**OpenCL Specification**\[1\]

## SEE ALSO

obsolete page replaced by clCreateFromGLTexture

[**cl\_khr\_gl\_sharing**(3clc)](/cl_khr_gl_sharing/3clc.md), [**clCreateBuffer**(3clc)](/clCreateBuffer/3clc.md), [**clCreateFromGLTexture**(3clc)](/clCreateFromGLTexture/3clc.md)

## AUTHORS

**The Khronos Group**

## COPYRIGHT

Copyright © 2007-2011 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.

## NOTES

- 1\.

  OpenCL Specification

  page 50, section 9.7.3 - CL Image Objects -\> GL Textures
