Search in sources :

Example 21 with LWJGLException

use of org.lwjgl.LWJGLException in project jmonkeyengine by jMonkeyEngine.

the class LwjglCanvas method makePbufferAvailable.

/**
     * Makes sure the pbuffer is available and ready for use
     */
protected void makePbufferAvailable() throws LWJGLException {
    if (pbuffer != null && pbuffer.isBufferLost()) {
        logger.log(Level.WARNING, "PBuffer was lost!");
        pbuffer.destroy();
        pbuffer = null;
    }
    if (pbuffer == null) {
        pbuffer = new Pbuffer(1, 1, acquirePixelFormat(true), null);
        pbuffer.makeCurrent();
        logger.log(Level.FINE, "OGL: Pbuffer has been created");
        // Any created objects are no longer valid
        if (!runningFirstTime) {
            renderer.resetGLObjects();
        }
    }
    pbuffer.makeCurrent();
    if (!pbuffer.isCurrent()) {
        throw new LWJGLException("Pbuffer cannot be made current");
    }
}
Also used : Pbuffer(org.lwjgl.opengl.Pbuffer) LWJGLException(org.lwjgl.LWJGLException)

Example 22 with LWJGLException

use of org.lwjgl.LWJGLException in project jmonkeyengine by jMonkeyEngine.

the class LwjglContext method initOpenCL.

@SuppressWarnings("unchecked")
protected void initOpenCL() {
    logger.info("Initialize OpenCL wiht LWJGL2");
    try {
        CL.create();
    } catch (LWJGLException ex) {
        logger.log(Level.SEVERE, "Unable to initialize OpenCL", ex);
        return;
    }
    //load platforms and devices
    StringBuilder platformInfos = new StringBuilder();
    ArrayList<LwjglPlatform> platforms = new ArrayList<>();
    for (CLPlatform p : CLPlatform.getPlatforms()) {
        platforms.add(new LwjglPlatform(p));
    }
    platformInfos.append("Available OpenCL platforms:");
    for (int i = 0; i < platforms.size(); ++i) {
        LwjglPlatform platform = platforms.get(i);
        platformInfos.append("\n * Platform ").append(i + 1);
        platformInfos.append("\n *   Name: ").append(platform.getName());
        platformInfos.append("\n *   Vendor: ").append(platform.getVendor());
        platformInfos.append("\n *   Version: ").append(platform.getVersion());
        platformInfos.append("\n *   Profile: ").append(platform.getProfile());
        platformInfos.append("\n *   Supports interop: ").append(platform.hasOpenGLInterop());
        List<LwjglDevice> devices = platform.getDevices();
        platformInfos.append("\n *   Available devices:");
        for (int j = 0; j < devices.size(); ++j) {
            LwjglDevice device = devices.get(j);
            platformInfos.append("\n *    * Device ").append(j + 1);
            platformInfos.append("\n *    *   Name: ").append(device.getName());
            platformInfos.append("\n *    *   Vendor: ").append(device.getVendor());
            platformInfos.append("\n *    *   Version: ").append(device.getVersion());
            platformInfos.append("\n *    *   Profile: ").append(device.getProfile());
            platformInfos.append("\n *    *   Compiler version: ").append(device.getCompilerVersion());
            platformInfos.append("\n *    *   Device type: ").append(device.getDeviceType());
            platformInfos.append("\n *    *   Compute units: ").append(device.getComputeUnits());
            platformInfos.append("\n *    *   Work group size: ").append(device.getMaxiumWorkItemsPerGroup());
            platformInfos.append("\n *    *   Global memory: ").append(device.getGlobalMemorySize()).append("B");
            platformInfos.append("\n *    *   Local memory: ").append(device.getLocalMemorySize()).append("B");
            platformInfos.append("\n *    *   Constant memory: ").append(device.getMaximumConstantBufferSize()).append("B");
            platformInfos.append("\n *    *   Supports double: ").append(device.hasDouble());
            platformInfos.append("\n *    *   Supports half floats: ").append(device.hasHalfFloat());
            platformInfos.append("\n *    *   Supports writable 3d images: ").append(device.hasWritableImage3D());
            platformInfos.append("\n *    *   Supports interop: ").append(device.hasOpenGLInterop());
        }
    }
    logger.info(platformInfos.toString());
    //choose devices
    PlatformChooser chooser = null;
    if (settings.getOpenCLPlatformChooser() != null) {
        try {
            chooser = (PlatformChooser) Class.forName(settings.getOpenCLPlatformChooser()).newInstance();
        } catch (Exception ex) {
            logger.log(Level.WARNING, "unable to instantiate custom PlatformChooser", ex);
        }
    }
    if (chooser == null) {
        chooser = new DefaultPlatformChooser();
    }
    List<? extends Device> choosenDevices = chooser.chooseDevices(platforms);
    List<CLDevice> devices = new ArrayList<>(choosenDevices.size());
    LwjglPlatform platform = null;
    for (Device d : choosenDevices) {
        if (!(d instanceof LwjglDevice)) {
            logger.log(Level.SEVERE, "attempt to return a custom Device implementation from PlatformChooser: {0}", d);
            return;
        }
        LwjglDevice ld = (LwjglDevice) d;
        if (platform == null) {
            platform = ld.getPlatform();
        } else if (platform != ld.getPlatform()) {
            logger.severe("attempt to use devices from different platforms");
            return;
        }
        devices.add(ld.getDevice());
    }
    if (devices.isEmpty()) {
        logger.warning("no devices specified, no OpenCL context created");
        return;
    }
    clPlatform = platform;
    logger.log(Level.INFO, "chosen platform: {0}", platform.getName());
    logger.log(Level.INFO, "chosen devices: {0}", choosenDevices);
    //create context
    try {
        CLContext c = CLContext.create(platform.getPlatform(), devices, null, Display.getDrawable(), null);
        clContext = new com.jme3.opencl.lwjgl.LwjglContext(c, (List<LwjglDevice>) choosenDevices);
    } catch (LWJGLException ex) {
        logger.log(Level.SEVERE, "Unable to create OpenCL context", ex);
        return;
    }
    logger.info("OpenCL context created");
}
Also used : LwjglDevice(com.jme3.opencl.lwjgl.LwjglDevice) Device(com.jme3.opencl.Device) ArrayList(java.util.ArrayList) DefaultPlatformChooser(com.jme3.opencl.DefaultPlatformChooser) PlatformChooser(com.jme3.opencl.PlatformChooser) LWJGLException(org.lwjgl.LWJGLException) RendererException(com.jme3.renderer.RendererException) LwjglDevice(com.jme3.opencl.lwjgl.LwjglDevice) LwjglPlatform(com.jme3.opencl.lwjgl.LwjglPlatform) ArrayList(java.util.ArrayList) List(java.util.List) LWJGLException(org.lwjgl.LWJGLException) DefaultPlatformChooser(com.jme3.opencl.DefaultPlatformChooser)

Example 23 with LWJGLException

use of org.lwjgl.LWJGLException in project jmonkeyengine by jMonkeyEngine.

the class LwjglMouseInput method setNativeCursor.

public void setNativeCursor(JmeCursor jmeCursor) {
    try {
        Cursor newCursor = null;
        if (jmeCursor != null) {
            newCursor = cursorMap.get(jmeCursor);
            if (newCursor == null) {
                newCursor = new Cursor(jmeCursor.getWidth(), jmeCursor.getHeight(), jmeCursor.getXHotSpot(), jmeCursor.getYHotSpot(), jmeCursor.getNumImages(), jmeCursor.getImagesData(), jmeCursor.getImagesDelay());
                // Add to cache
                cursorMap.put(jmeCursor, newCursor);
            }
        }
        Mouse.setNativeCursor(newCursor);
    } catch (LWJGLException ex) {
        Logger.getLogger(LwjglMouseInput.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : JmeCursor(com.jme3.cursors.plugins.JmeCursor) Cursor(org.lwjgl.input.Cursor) LWJGLException(org.lwjgl.LWJGLException)

Example 24 with LWJGLException

use of org.lwjgl.LWJGLException in project malmo by Microsoft.

the class VideoHook method resizeIfNeeded.

/**
     * Resizes the window and the Minecraft rendering if necessary. Set renderWidth and renderHeight first.
     */
private void resizeIfNeeded() {
    // resize the window if we need to
    int oldRenderWidth = Display.getWidth();
    int oldRenderHeight = Display.getHeight();
    if (this.renderWidth == oldRenderWidth && this.renderHeight == oldRenderHeight)
        return;
    try {
        Display.setDisplayMode(new DisplayMode(this.renderWidth, this.renderHeight));
        System.out.println("Resized the window");
    } catch (LWJGLException e) {
        System.out.println("Failed to resize the window!");
        e.printStackTrace();
    }
    forceResize(this.renderWidth, this.renderHeight);
}
Also used : DisplayMode(org.lwjgl.opengl.DisplayMode) LWJGLException(org.lwjgl.LWJGLException)

Example 25 with LWJGLException

use of org.lwjgl.LWJGLException in project MinecraftForge by MinecraftForge.

the class SplashProgress method resume.

/**
     * @deprecated not a stable API, will break, don't use this yet
     */
@Deprecated
public static void resume() {
    if (!enabled)
        return;
    checkThreadState();
    pause = false;
    try {
        Display.getDrawable().releaseContext();
        d.makeCurrent();
    } catch (LWJGLException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    lock.unlock();
}
Also used : EnhancedRuntimeException(net.minecraftforge.fml.common.EnhancedRuntimeException) LWJGLException(org.lwjgl.LWJGLException)

Aggregations

LWJGLException (org.lwjgl.LWJGLException)43 ByteBuffer (java.nio.ByteBuffer)6 Pbuffer (org.lwjgl.opengl.Pbuffer)4 EnhancedRuntimeException (net.minecraftforge.fml.common.EnhancedRuntimeException)3 DisplayMode (org.lwjgl.opengl.DisplayMode)3 PixelFormat (org.lwjgl.opengl.PixelFormat)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 Method (java.lang.reflect.Method)2 FloatBuffer (java.nio.FloatBuffer)2 IntBuffer (java.nio.IntBuffer)2 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2 GLCanvas (org.eclipse.swt.opengl.GLCanvas)2 GLData (org.eclipse.swt.opengl.GLData)2 Sphere (org.lwjgl.util.glu.Sphere)2 LifecycleListener (com.badlogic.gdx.LifecycleListener)1 LwjglApplication (com.badlogic.gdx.backends.lwjgl.LwjglApplication)1 LwjglApplicationConfiguration (com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration)1 JmeCursor (com.jme3.cursors.plugins.JmeCursor)1 DefaultPlatformChooser (com.jme3.opencl.DefaultPlatformChooser)1