Hi forum, 

I think Graphics Context actually encapsulates information on the way in which 
scene objects are drawn and rendering states are applied. OSG uses the 
osg::GraphicsContext class to represent the abstract graphics context. 

In one of the functions that i am writing now, takes a osg::GraphicsContext 
class object as parameter and from this i need to derive a OS specific window 
handle and i am not sure how to do it. I did not find any example to it either. 

Right now i am doing it in the following manner and i think it is not correct. 


Code:


#ifdef _WIN32
#include <osgViewer/api/Win32/GraphicsHandleWin32>
#elif defined(__GNUC__)
#include <osgViewer/api/X11/GraphicsHandleX11>
#elif defined( __APPLE__)
#include <osgViewer/api/Carbon/GraphicsHandleCarbon>
#endif
..................................
..................................

bool Context::setupDeviceAndContext(osg::GraphicsContext &ctx)
{
...........................
#ifdef defined(_WIN32)
      osgViewer::GraphicsHandleWin32 *windowsContext = NULL;
#elif defined( __GNUC__)
      osgViewer::GraphicsHandleX11 *linuxContext = NULL;
#elif defined( __APPLE__ )
      osgViewer::GraphicsHandleCarbon *osxContext = NULL;
#endif

      //platform dependent casting for the OpenCL context creation
#ifdef defined(_WIN32)
      windowsContext = dynamic_cast<osgViewer::GraphicsHandleWin32*>(&ctx);

      if(NULL == windowsContext)
      {
     osg::notify(osg::FATAL) << "Win32 Graphics Context Casting is 
unsuccessful" << std::endl;
     return false;
      }
#elif defined(__GNUC__)
      linuxContext = dynamic_cast<osgViewer::GraphicsHandleX11*>(&ctx);

      if(NULL == linuxContext)
      {
     osg::notify(osg::FATAL) << "X11 Graphics Context Casting is unsuccessful" 
<< std::endl;
     return false;
      }
#elif defined(__APPLE__)
      osxContext = dynamic_cast<osgViewer::GraphicsHandleCarbon*>(&ctx);

      if(NULL == osxContext)
      {
     osg::notify(osg::FATAL) << "MACOSX Graphics Context Casting is 
unsuccessful. " << std::endl;
     return false;
      }
#endif
........................................................
}




.........
I need this OS specific Window Handle to create a context property for OpenCL 
device as follows:


Code:

     cl_context_properties contextProperties[] =
        {
#ifdef defined(_WIN32)
           CL_CONTEXT_PLATFORM, (cl_context_properties) _m_clPlatform,
           CL_GL_CONTEXT_KHR, (cl_context_properties) 
windowsContext->getWGLContext(),
           CL_WGL_HDC_KHR, (cl_context_properties) windowsContext->getHDC(),
#elif defined(__GNUC__)
           CL_CONTEXT_PLATFORM, (cl_context_properties) _m_clPlatform,
           CL_GL_CONTEXT_KHR, (cl_context_properties) 
linuxContext->getContext(),
           CL_GLX_DISPLAY_KHR, (cl_context_properties) 
linuxContext->getDisplay(),
#elif defined(__APPLE__)
           CGLContextObj glContext = CGLGetCurrentContext(); // get the current 
GL context
           CGLShareGroupObj shareGroup = CGLGetShareGroup(glContext); // share 
group

           CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
           (cl_context_properties) shareGroup,
#endif
           0
        };





You do not need to worry about the OpenCL stuff here. I just need to know how 
to derive OS specific window handles from osg::GraphicsContext ?

Is it the proper way to do it as i am doing right now ? I am having trouble in 
this manner because OpenCL context creation is giving me undefined behavior. 

If i  am correct , then i have to concentrate some where else in the code.

I really need your hint over this issue.
 

Cheers,
Sajjadul

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56407#56407





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to