Hi,
I’m trying to process textures that are rendered to using FBOs. The rendering part works fine, but when I try to use clCreateFromGLTexture2D it returns CL_INVALID_IMAGE_FORMAT_DESCRIPTOR. I assumed that maybe the texture’s internal format is wrong, but when I switched to GL_RGB the problem didn’t disappear.
I’m using kUbuntu 11.10 64bit with Catalyst 11.12 and APP SDK 2.6
here’s the code:
OpenCL initialization:
GLXContext the_glx_context = glXGetCurrentContext();
if ( the_glx_context == 0 )
{
std::cerr << "Error getting the current glX context.
";
objs::get()->conf.the_window.Close();
exit( 1 );
}
cl_int error = CL_SUCCESS;
if ( !clGetGLContextInfoKHR )
{
clGetGLContextInfoKHR = ( clGetGLContextInfoKHR_fn )clGetExtensionFunctionAddress( "clGetGLContextInfoKHR" );
if ( !clGetGLContextInfoKHR )
{
std::cerr << "Error getting clGetGLContextInfoKHR function ptr.
";
objs::get()->conf.the_window.Close();
exit( 1 );
}
}
cl_uint num_platfroms;
error = clGetPlatformIDs( 1, &the_platform, &num_platfroms );
objs::get()->get_opencl_error(error);
cl_context_properties the_context_properties[] =
{
CL_CONTEXT_PLATFORM,
( cl_context_properties )the_platform,
CL_GLX_DISPLAY_KHR,
( intptr_t )glXGetCurrentDisplay(),
CL_GL_CONTEXT_KHR,
( intptr_t )the_glx_context,
0
};
error = clGetGLContextInfoKHR( the_context_properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof( cl_device_id ), &the_device, 0 );
objs::get()->get_opencl_error(error);
the_context = clCreateContext( the_context_properties, 1, &the_device, 0, 0, &error );
objs::get()->get_opencl_error(error);
the_command_queue = clCreateCommandQueue( the_context, the_device, 0, &error );
objs::get()->get_opencl_error(error);
FBO initialization:
float w = objs::get()->conf.SCREEN_WIDTH;
float h = objs::get()->conf.SCREEN_HEIGHT;
fbo.create();
fbo.bind();
GLenum modes[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
glDrawBuffers( 2, modes );
albedo.create();
normals.create();
depth.create();
glActiveTexture( GL_TEXTURE5 );
albedo.bind();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB16F, w, h, 0, GL_RGBA, GL_FLOAT, 0 );
albedo.width = w;
albedo.height = h;
glActiveTexture( GL_TEXTURE6 );
normals.bind();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RG16F, w, h, 0, GL_RGBA, GL_FLOAT, 0 );
normals.width = w;
normals.height = h;
glActiveTexture( GL_TEXTURE7 );
depth.bind();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0 );
depth.width = w;
depth.height = h;
rbo.create();
rbo.bind();
rbo.set_storage_format( GL_DEPTH_COMPONENT, w, h );
rbo.width = w;
rbo.height = h;
rbo.attach_to_frame_buffer( GL_DEPTH_ATTACHMENT, &fbo );
glActiveTexture( GL_TEXTURE0 );
albedo.attach_to_frame_buffer( GL_COLOR_ATTACHMENT0, &fbo );
normals.attach_to_frame_buffer( GL_COLOR_ATTACHMENT1, &fbo );
depth.attach_to_frame_buffer( GL_DEPTH_ATTACHMENT, &fbo );
if ( fbo.check() == false )
{
std::cerr << "FBO not complete, DIE!
";
objs::get()->conf.the_window.Close();
exit( 1 );
}
fbo.unbind();
cl_int error;
albedo_cl = clCreateFromGLTexture2D(objs::get()->the_compute_context.the_context, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, albedo.data, &error);
objs::get()->get_opencl_error(error); //This throws CL_INVALID_IMAGE_FORMAT_DESCRIPTOR
normals_cl = clCreateFromGLTexture2D(objs::get()->the_compute_context.the_context, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, normals.data, &error);
objs::get()->get_opencl_error(error);
depth_cl = clCreateFromGLTexture2D(objs::get()->the_compute_context.the_context, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, depth.data, &error);
objs::get()->get_opencl_error(error);
any ideas what might went wrong?
Best regards,
Yours3!f