OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1719 Discussions

Problem with OpenCL and OpenGL Interoperability

gyeresi_c_
Beginner
716 Views

Hi!
I'm following this example to create a project, which uses OpenCL and OpenGL. 
https://software.intel.com/en-us/articles/sharing-surfaces-between-opencl-and-opengl-43-on-intel-processor-graphics-using-implicit

I had to change a few things, but clCreateFromGLTexture function returns CL_INVALID_CONTEXT.

Creating context:

//get the GL rendering context
    HGLRC hGLRC = wglGetCurrentContext();
    //get the device context
    HDC hDC = wglGetCurrentDC();
    cl_context_properties properties[] =
    {
        CL_GL_CONTEXT_KHR, (cl_context_properties)hGLRC,
        CL_WGL_HDC_KHR, (cl_context_properties)hDC,
        CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[0],
        0
    };

    //create an OCL context using the context properties 
    cl_context context = clCreateContext(properties, numDevices, &devices[0], NULL, NULL, &status);
    checkStatus("clCreateContext", status);    //here status is cl_success

//create a texture object and assign data to it
    GLuint texture;
    glGenTextures(1, &texture);
    //bind the texture
    glBindTexture(GL_TEXTURE_2D, texture);
    //allocate storage for texture data
    glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 600, 600, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

    //specify data    
    glTexSubImage2D(GL_TEXTURE_2D,
        0, //mip map level, in this case we only have 1 level==0
        0, 0, //subregion offset
        300, 300, //width and height of subregion                        
        GL_RGBA, GL_UNSIGNED_BYTE,
        texture); //works! We specify initial data

    size_t global_dim[2];
    global_dim[0] = 300;
    global_dim[1] = 300;

    cl_mem sharedMemObject = clCreateFromGLTexture(context, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, texture, &status);

Can anybody help me with this? 

I'm using Intel Atom E3845 with the latest driver.

0 Kudos
2 Replies
Jeffrey_M_Intel1
Employee
716 Views

Were you able to get any other OpenCL samples running on this system?  https://software.intel.com/en-us/intel-opencl-support/code-samples

How about any OpenGL examples? 

Just want to make sure your environment is fully set up as a first step.  If those both work, will the original example code compile and run?  If not, what did you need to change?

 

 

0 Kudos
gyeresi_c_
Beginner
716 Views

Thank You for the reply!

I've already solved the problem. I had to create the OpenGL Texture before the properties array, because wglGetCurrentContext() couldn't return it, since it was created later.

0 Kudos
Reply