PDA

View Full Version : gl-cl interop and depth buffer



whites11
05-11-2010, 12:01 PM
Hi all.
i wrote some code that shares the color buffer between opengl and opencl and is able to read and write (from opencl) to this buffer(s). the code works well on linux.
i need now to access the depth buffer too.

the steps i'm following:


//init gl subsystem
...
glEnable(GL_DEPTH_TEST);
glEnable( GL_FRAMEBUFFER_EXT );

//glDeleteFramebuffersEXT(1, fboId);
glGenFramebuffersEXT(1, &fboId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);

//color buffer
glGenRenderbuffersEXT(1, &PS1_buffer_id);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, PS1_buffer_id);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, width, height);

//depth buffer
glGenRenderbuffersEXT(1, &PS1_depth_buffer_id);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, PS1_depth_buffer_id);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);

// attach a texture to FBO color attachement point
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, PS1_buffer_id);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, PS1_depth_buffer_id);

//framebuffer status is OK

//init openCL
cl_context_properties props[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
CL_CONTEXT_PLATFORM, (cl_context_properties)cpPlatform,
0};

cl_context ctx = clCreateContextFromType(props, CL_DEVICE_TYPE_GPU, NULL, NULL, &ciErrNum);
context = cl::Context(ctx);

cl::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
cl::Device device = devices[0];

std::string sources = ReadClFromFile("kernel_depth.cl");

cl::Program::Sources source(1, std::make_pair(sources.c_str(),sources.length()));
cl::Program program = cl::Program(context, source);
program.build(devices);

cl::CommandQueue queue = cl::CommandQueue(context, device, 0, &ciErrNum);

m_buffer = clCreateFromGLRenderbuffer(context(), CL_MEM_READ_ONLY, m_buffer_id, &ciErrNum);
m_depth_buffer = clCreateFromGLRenderbuffer(context(), CL_MEM_READ_ONLY, PS1_depth_buffer_id, &ciErrNum);


the first call to clCreateFromGLRenderbuffer works perfectly, while the second one fails with a CL_INVALID_VALUE
documentation (http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateFromGLRenderbuffer.html) says:

CL_INVALID_VALUE if values specified in flags are not valid.

any hint?

if you have any questions please ask.