Results 1 to 2 of 2

Thread: OpenCL/GL Interop Setup Problem

  1. #1
    Join Date
    Oct 2013

    OpenCL/GL Interop Setup Problem

    I'd like to use OpenGL for rendering on my graphics card, i.e. I'm looking for some way to write to the framebuffer.
    From what I've found, the way to go is using a shared CL/GL buffer or texture. If there is an easier way, please tell me.

    I fail to set up the CL/GL connection and the problem seems to revolve around the clGetExtensionFunctionAddressForPlatform() function.

    My development environment:
    Code :
    Windows7 64-bit
    MS VisualStudio 2012
    AMD APP SDK 2.8.1 (OpenGL 1.2)
    Graphics card: Radeon HD 5770 (Juniper)
    cl_khr_gl_sharing extension supported

    When I try to call the function pointer that clGetExtensionFunctionAddressForPlatform() returns I get the following error:
    "Unhandled exception at 0x51EC8B55 in main.exe: 0xC0000005: Access violation reading location 0x51EC8B55."
    But the debugger indicates that 0x51EC8B55 points somewhere into the "OpenCL.dll"

    I'm not really sure what to make of this, I'm not too experienced with C.

    Here is a reduced runnable version of my code that reproduces the error.
    Code :
    #include "stdafx.h"
    #include <CL/cl.h>
    #include <CL/cl_gl.h>
    int main(int argc, char** argv) 
    	cl_platform_id cl_platform;
    	clGetPlatformIDs(1, &cl_platform, NULL);
    	cl_device_id devices[32];
    	size_t sharing_devices_count;
    	clGetGLContextInfoKHR_fn *functionPtr = (clGetGLContextInfoKHR_fn*)clGetExtensionFunctionAddressForPlatform(cl_platform, "clGetGLContextInfoKHR");	
    	(*functionPtr)(NULL, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,32*sizeof(cl_device_id), devices, &sharing_devices_count);

    I hope you can help me.

    Regards, janismac

  2. #2
    Join Date
    Oct 2013
    I solved it on my own.

    Turns out clGetExtensionFunctionAddressForPlatform() and clGetGLContextInfoKHR() arent actually necessary to setup the interop.

    The following code snippet does the job. It has to be run AFTER OpenGL initialization.

    Code :
    cl_context_properties properties[] = 
    		CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), // WGL Context 
    		CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),  // WGL HDC
    		CL_CONTEXT_PLATFORM, (cl_context_properties)my_cl_platform,  // OpenCL platform
    	my_cl_context = clCreateContext (properties, 1, &my_cl_device, NULL, NULL, &cl_err);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean