JOCL/JOGL interporability

It seems the current JOCL/JOGL interporability is out of date with current JOGL releases.
My current JOGL 2.0 (build 29/11/2010) release does not have WindowsWGLContext class, glDrawable does not have getNativeWindow method. The Animator class has been changed to com.jogamp.opengl.util.Animator. Help me to run the example.

By the way nice work on JOCL and also the JOCL experimental struct is being useful in my real time ray tracer. Hope to jump start a path tracer in JOCL soon.:smiley:

Hello,

Thank you, I was not aware of these modifications. I’ll try to update the sample ASAP.

There mainly seem to be some renamings, e.g.
com.sun.opengl.impl.windows.wgl.WindowsWGLContext
is now
com.jogamp.opengl.impl.windows.wgl.WindowsWGLContext

Maybe future versions of JOGL will have a dedicated method for this, avoiding the 'instanceof’s and accessing the implementations details, but for now, it should work when the „initContextProperties“ is adjusted to do the same as the „setupContextProperties“ method in jocl/CLGLContext.java at master · mbien/jocl · GitHub :wink:

bye
Marco

Thank you marco. :smiley:

After knowing where the Animator class, WindowsWGLContext class was & some code modification

        GLDrawable glDrawable = glContext.getGLDrawable();
        NativeWindow nativeWindow = 
                    (NativeWindow) glDrawable.getNativeSurface(); //From glDrawable.getNativeWindow();


        if(glContext instanceof WindowsWGLContext)
        {
            WindowsWGLContext windowsContext = (WindowsWGLContext)glContext;
            long nativeContext = windowsContext.getHandle(); //From windowsContext.getHGLRC();
            long hdc = nativeWindow.getSurfaceHandle();
            contextProperties.addProperty(CL_GL_CONTEXT_KHR, nativeContext);
            contextProperties.addProperty(CL_WGL_HDC_KHR, hdc);
        }
        else
        {
            throw new RuntimeException("Unsupported GLContext: "+glContext);
        }```

The program was up and running. 

Thank you

The sample has been updated. I noticed that some other (minor) modifications had been necessary, since the GLProfile.get method may no longer be called from the EDT. But the most important thing is the new initContextProperties method, which now looks like this:

    /**
     * Initializes the given context properties so that they may be
     * used to create an OpenCL context for the given GL object.
     *  
     * @param contextProperties The context properties
     * @param gl The GL object
     */
    private void initContextProperties(cl_context_properties contextProperties, GL gl)
    {
        // Adapted from http://jogamp.org/jocl/www/
        
        GLContext glContext = gl.getContext();
        if(!glContext.isCurrent()) 
        {
            throw new IllegalArgumentException(
                "OpenGL context is not current. This method should be called " +
                "from the OpenGL rendering thread, when the context is current.");
        }

        long glContextHandle = glContext.getHandle();
        GLContextImpl glContextImpl = (GLContextImpl)glContext;
        GLDrawableImpl glDrawableImpl = glContextImpl.getDrawableImpl();
        NativeSurface nativeSurface = glDrawableImpl.getNativeSurface();

        if (glContext instanceof X11GLXContext)
        {
            long displayHandle = nativeSurface.getDisplayHandle();
            contextProperties.addProperty(CL_GL_CONTEXT_KHR, glContextHandle);
            contextProperties.addProperty(CL_GLX_DISPLAY_KHR, displayHandle);
        }
        else if (glContext instanceof WindowsWGLContext)
        {
            long surfaceHandle = nativeSurface.getSurfaceHandle();
            contextProperties.addProperty(CL_GL_CONTEXT_KHR, glContextHandle);
            contextProperties.addProperty(CL_WGL_HDC_KHR, surfaceHandle);
        }
        else if (glContext instanceof MacOSXCGLContext)
        {
            contextProperties.addProperty(CL_CGL_SHAREGROUP_KHR, glContextHandle);
        }
        else if (glContext instanceof EGLContext)
        {
            long displayHandle = nativeSurface.getDisplayHandle();
            contextProperties.addProperty(CL_GL_CONTEXT_KHR, glContextHandle);
            contextProperties.addProperty(CL_EGL_DISPLAY_KHR, displayHandle);
        }
        else
        {
            throw new RuntimeException("unsupported GLContext: " + glContext);
        }
    }

Hopefully it works on other platforms as well, I could only test it on Win32 for now…

BTW: Is your Raytracer open source?

BTW -Is your Raytracer open source?

Its not open source… just a personal project. If finished to the desired level that I want then definitely I will email you the code. Actually my goal is to create a simple path tracer like the SmallptGPU. Really fascinated on how fast it is.:slight_smile: