CLCREATEFROMGLTEXTUR(3clc)
π NAME π
okay bestie, gather round, because this page is literally about clCreateFromGLTexture β and what it does is 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. yes it really said all of that. it's giving "we support every texture shape you could possibly have" energy β¨
cl_mem clCreateFromGLTexture(cl_context context, cl_mem_flags flags,
GLenum texture_target, GLint miplevel,
GLuint texture, cl_int * errcode_ret);
likeβ¦ she takes six things and hands you back a cl_mem. iconic. no cap. π«Ά
πΈ PARAMETERS πΈ
contextβ a valid OpenCL context that was created from an OpenGL context. it has to be that specific kind of context, bestie, no substitutes πflagsβ a bit-field for specifying usage information. go peek at the table inclCreateBuffer(3clc)for the full description of flags, but only these three are allowed here:CL_MEM_READ_ONLY,CL_MEM_WRITE_ONLY, andCL_MEM_READ_WRITE. that's the whole guest list, nobody else gets in πtexture_targetβ must be one of these, fr fr:GL_TEXTURE_1DGL_TEXTURE_1D_ARRAYGL_TEXTURE_BUFFERGL_TEXTURE_2DGL_TEXTURE_2D_ARRAYGL_TEXTURE_3DGL_TEXTURE_CUBE_MAP_POSITIVE_XGL_TEXTURE_CUBE_MAP_POSITIVE_YGL_TEXTURE_CUBE_MAP_POSITIVE_ZGL_TEXTURE_CUBE_MAP_NEGATIVE_XGL_TEXTURE_CUBE_MAP_NEGATIVE_YGL_TEXTURE_CUBE_MAP_NEGATIVE_ZGL_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. and listen β 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. so don't come in here thinking it's grabbing your bound texture, because it is Not π
miplevelβ the mipmap level to be used. iftexture_targetisGL_TEXTURE_BUFFER, thenmiplevelmust be 0. also, implementations may returnCL_INVALID_OPERATIONformiplevelvalues > 0. so likeβ¦ tread carefully β¨textureβ the name of a GL 1D, 2D, 3D, 1D array, 2D array, cubemap, rectangle or buffer texture object. this texture object must be a complete texture as per OpenGL rules on texture completeness β no half-finished textures allowed, she's got standards π. the texture format and dimensions that OpenGL defines for the specifiedmiplevelof the texture will be used to create the OpenCL image memory object. and 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. those tables are the vibe check, basically π¦errcode_retβ returns an appropriate error code as described below. iferrcode_retisNULL, no error code is returned. simple as that π
β οΈ NOTES β οΈ
okay this part is important so pay attention bestie π«Ά
if the state of a GL texture object gets modified through the GL API (like, say, 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, then subsequent use of the CL image object will result in undefined behavior. UNDEFINED. BEHAVIOR. do not test her, she will not be nice about it π
the clRetainMemObject(3clc) and clReleaseMemObject(3clc) functions can be used to retain and release the image objects. use them, they're right there, they're your friends π
π¨ ERRORS π¨
so here's the deal: she returns a valid non-zero OpenCL image object and errcode_ret is set to CL_SUCCESS if the image object is created successfully. slay. but otherwise? she returns a NULL value, and one of these error values comes back in errcode_ret:
CL_INVALID_CONTEXTifcontextis not a valid context or was not created from a GL context.CL_INVALID_VALUEif values specified inflagsare not valid, or if the value specified intexture_targetis not one of the values specified in the description oftexture_target.CL_INVALID_MIP_LEVELifmiplevelis less than the value oflevelbase(for OpenGL implementations) or zero (for OpenGL ES implementations); or greater than the value ofq(for both OpenGL and OpenGL ES).levelbaseandqare 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_LEVELifmiplevelis greater than zero and the OpenGL implementation does not support creating from non-zero mipmap levels.CL_INVALID_GL_OBJECTiftextureis not a GL texture object whose type matchestexture_target, if the specifiedmipleveloftextureis not defined, or if the width or height of the specifiedmiplevelis zero.CL_INVALID_IMAGE_FORMAT_DESCRIPTORif the OpenGL texture internal format does not map to a supported OpenCL image format.CL_INVALID_OPERATIONiftextureis a GL texture object created with a border width value greater than zero.CL_OUT_OF_RESOURCESif there is a failure to allocate resources required by the OpenCL implementation on the device.CL_OUT_OF_HOST_MEMORYif there is a failure to allocate resources required by the OpenCL implementation on the host.
note that CL_INVALID_MIP_LEVEL shows up twice up there β two completely different reasons, same name. she contains multitudes π
π SPECIFICATION π
OpenCL Specification[1] β yes, the whole thing, go read it, it's a whole mood π
π SEE ALSO π
obsolete page replaced by clCreateFromGLTexture
π AUTHORS π
The Khronos Group. legends only, honestly π
β 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 following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Materials.
π§ NOTES π§
- OpenCL Specification β page 50, section 9.7.3 - CL Image Objects -> GL Textures
and that's the whole page bestie π this one came from The Khronos Group, dated 01/14/2021, living in the 3clc section of the OpenCL Manual. go forth and make your textures, but likeβ¦ don't modify them mid-use, okay? i'm begging π«Άβ¨πΈ
π¦ where this page comes from
- ubuntu jammy: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- ubuntu noble: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms