Take the 2-minute tour ×

EDIT: As suggested I changed the texture target to GL_TEXTURE_2D. So the initialisation looks like that now:

void initTexture( int width, int height )
    glGenTextures(1, &tex);
    glBindTexture(GL_TEXTURE_2D, tex);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width,
            height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL );
    glBindTexture(GL_TEXTURE_2D, 0);

Since it's a GL_TEXTURE_2D, mipmaps need to be defined. How should that be reflected on the initialisation of the OpenCL Image2D?

texMems.push_back(Image2DGL(clw->context, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, tex, &err));

I'm still getting a CL_INVALID_GL_OBJECT, though. So the question still is: How can I check for texture completeness at the point of the initialisation of the OpenCL Image2D?

Previous approach:

I'm decoding a video-file with avcodec. The result is an AVFrame. I can display the frames on a GL_TEXTURE_RECTANGLE_ARB.

This is an excerpt from my texture initialisation, following an initialisation of the gl (glew) context:

GLuint tex = 0;

void initTexture( int width, int height )
    glGenTextures(1, &tex);
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex);
    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB8, width,
            height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL );
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);

Now I want to assign tex to a Image2DGL for an interop between OpenCL and OpenGL. Im using an Nvidia Geforce 310M, Cuda Toolkit 4. OpenGL version is 3.3.0 and GLX version is 1.4.

texMems.push_back(Image2DGL(clw->context, CL_MEM_READ_WRITE, GL_TEXTURE_RECTANGLE_ARB, 0, tex, &err));

This gives back an:

clCreateFromGLBuffer: -60 (CL_INVALID_GL_OBJECT)

This is all happening before I'm starting the render loop. I can display the video frames on the texture just fineafter that. The texture target (GL_TEXTURE_RECTANGLE_ARB) is allowed for the OpenCL context, as the corresponding OpenGL extension is enabled (GL_ARB_texture_rectangle).

Now the error description in the OpenCL 1.1 spec states:


I'm using GL_TEXTURE_RECTANGLE_ARB, so there's not mipmapping (as I understand). However what I found was this statement in the Nvidia OpenCL implementation notes:

If the texture object specified in a call to clCreateFromGLTexture2D or clCreateFromGLTexture3D is incomplete as per OpenGL rules on texture completeness then the call will return CL_INVALID_GL_OBJECT in errcode_ret.

How can I validate the texture completeness at that state where I only initialize the texture without providing any actual texture content? Any ideas?

share|improve this question
Rectangle textures have been core functionality since GL 2.0, and any card that can run OpenCL has them in core. Please stop using the feature as an extension (the ARB suffix). That's not your problem, but it's still something that you shouldn't do. –  Nicol Bolas Jan 26 '12 at 15:46
I wonder why you use rectangle textures at all. Since OpenGL-2 regular textures may be of arbitrary size. –  datenwolf Jan 26 '12 at 15:49
Thanks for the comments, I used the rectangle texture type, because I ... copied off of an example. So I should be using GL_TEXTURE_2D instead? –  rdoubleui Jan 26 '12 at 16:46
How did you create your OpenCL context? Show us that code. –  James Jan 27 '12 at 23:21
The context has been created the os-specific way and seemed not to be the problem. I was able to find out the what the problem was this morning. –  rdoubleui Jan 28 '12 at 8:22
add comment

1 Answer

up vote 4 down vote accepted

I was able to resolve the issue that I couldn't create an Image2DGL. I was missing to specify a 4-channel internal format for the texture2D:

void initTexture( int width, int height )
    glGenTextures(1, &tex);
    glBindTexture(GL_TEXTURE_2D, tex);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL );
    glBindTexture(GL_TEXTURE_2D, 0);

By specifying GL_RGBA I was able to successfully create the Image2DGL (which is equivalent to clCreateFromGLTexture2D). It seems that this fulfilled the demand to have texture completeness.

share|improve this answer
thanks a lot for the discussion. All i am not able to understand is that why is that line needed glBindTexture(GL_TEXTURE_2D, 0); because once we already bind in 3rd line again why we need to do it. from your solution things are working for me ... will the OpenCL texture now generated will from that tex texture.. please do replay as earliest –  Megharaj Jun 16 '12 at 10:50
+1 Because it solved my problem too –  Victor Sand Apr 15 '13 at 18:45
add comment

Your Answer


