Explorar o código

LwjglCanvas: initialize OpenCL for LWJGL2 (#1720)

* Fixing OpenCL context null issue with LwjglCanvas. It is important that for Swing applications and with this fix, OpenCL won't be available in "simpleInitApp" and everything needs to be initialized inside the "simpleUpdate" with a boolean variable.

* Adding description to javaDoc
AmiroooTheWalnut %!s(int64=3) %!d(string=hai) anos
pai
achega
0be4f6f7b1

+ 7 - 1
jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java

@@ -438,6 +438,9 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
      * This is called:
      * This is called:
      * 1) When the context thread starts
      * 1) When the context thread starts
      * 2) Any time the canvas becomes displayable again.
      * 2) Any time the canvas becomes displayable again.
+	 * In the first call of this method, OpenGL context is not ready yet. Therefore, OpenCL context cannot be created.
+	 * The second call of this method is done after "simpleInitApp" is called. Therefore, OpenCL won't be available in "simpleInitApp" if Canvas/Swing is used.
+	 * To use OpenCL with Canvas/Swing, you need to use OpenCL in the rendering loop "simpleUpdate" and check for "context.getOpenCLContext()!=null".
      */
      */
     @Override
     @Override
     protected void createContext(AppSettings settings) {
     protected void createContext(AppSettings settings) {
@@ -477,7 +480,10 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
                 }else{
                 }else{
                     Display.create(acquirePixelFormat(false));
                     Display.create(acquirePixelFormat(false));
                 }
                 }
-
+				if (settings.isOpenCLSupport()) {
+					initOpenCL();
+				}
+				
                 renderer.invalidateState();
                 renderer.invalidateState();
             }else{
             }else{
                 // First create the pbuffer, if it is needed.
                 // First create the pbuffer, if it is needed.