encapsulate context creation

Hello,

I need to use the opencl context and its associated command queues across several classes and therefore i am planning to encapsulate the opencl context creation into a single class and make a singleton instance of it. That instance will be used by several other class objects in the application.

Is my plan in the right direction ?

Is it necessary to use the clRetainContext() some where here ?

Thanks

Seems reasonable.

As long as your class that holds the context holds it until everyone is done, then you don’t need additional retain/release calls since the singleton class holds a reference count.

If you are using C++ might also investigate using the OpenCL C++ wrapper classes; they offer some convenience over the C API.