From e40ebdc5c6b9b7444affff230ca354d8051aaaff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Wei=C3=9F?= Date: Fri, 26 Aug 2016 12:39:08 +0200 Subject: [PATCH] updated GL and AL --- .../java/com/jme3/audio/lwjgl/LwjglALC.java | 51 +++++++++---------- .../jme3/input/lwjgl/GlfwJoystickInput.java | 2 +- .../com/jme3/input/lwjgl/GlfwKeyInput.java | 24 ++++++++- .../com/jme3/input/lwjgl/GlfwMouseInput.java | 34 +++++++++++-- .../lwjgl/LwjglGLDebugOutputHandler.java | 10 ++++ .../com/jme3/system/lwjgl/LwjglWindow.java | 45 +++++++++++++--- 6 files changed, 125 insertions(+), 41 deletions(-) diff --git a/jme3-lwjgl3/src/main/java/com/jme3/audio/lwjgl/LwjglALC.java b/jme3-lwjgl3/src/main/java/com/jme3/audio/lwjgl/LwjglALC.java index c9812d7df..cd4e428c0 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/audio/lwjgl/LwjglALC.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/audio/lwjgl/LwjglALC.java @@ -31,52 +31,49 @@ */ package com.jme3.audio.lwjgl; -import com.jme3.audio.openal.ALC; +import java.nio.ByteBuffer; import java.nio.IntBuffer; +import org.lwjgl.openal.AL; +import org.lwjgl.openal.ALC; import org.lwjgl.openal.ALC10; -import org.lwjgl.openal.ALContext; -import org.lwjgl.openal.ALDevice; +import org.lwjgl.openal.ALCCapabilities; import org.lwjgl.openal.SOFTPauseDevice; -public class LwjglALC implements ALC { +public class LwjglALC implements com.jme3.audio.openal.ALC { - private ALDevice device; - private ALContext context; - - private long contextId; - private long deviceId; + private long device; + private long context; public void createALC() { - device = ALDevice.create(); - context = ALContext.create(device); - context.makeCurrent(); - - contextId = ALC10.alcGetCurrentContext(); - deviceId = ALC10.alcGetContextsDevice(contextId); + device = ALC10.alcOpenDevice((ByteBuffer) null); + ALCCapabilities deviceCaps = ALC.createCapabilities(device); + context = ALC10.alcCreateContext(device, (IntBuffer) null); + ALC10.alcMakeContextCurrent(context); + AL.createCapabilities(deviceCaps); } public void destroyALC() { - if (context != null) { - context.destroy(); - context = null; + if (context != 0) { + ALC10.alcDestroyContext(context); + context = 0; } - if (device != null) { - device.destroy(); - device = null; + if (device != 0) { + ALC10.alcCloseDevice(device); + device = 0; } } public boolean isCreated() { - return context != null; + return context != 0; } public String alcGetString(final int parameter) { - return ALC10.alcGetString(deviceId, parameter); + return ALC10.alcGetString(device, parameter); } public boolean alcIsExtensionPresent(final String extension) { - return ALC10.alcIsExtensionPresent(deviceId, extension); + return ALC10.alcIsExtensionPresent(device, extension); } public void alcGetInteger(final int param, final IntBuffer buffer, final int size) { @@ -86,15 +83,15 @@ public class LwjglALC implements ALC { if (buffer.limit() != size) { throw new AssertionError(); } - ALC10.alcGetIntegerv(deviceId, param, buffer); + ALC10.alcGetIntegerv(device, param, buffer); } public void alcDevicePauseSOFT() { - SOFTPauseDevice.alcDevicePauseSOFT(deviceId); + SOFTPauseDevice.alcDevicePauseSOFT(device); } public void alcDeviceResumeSOFT() { - SOFTPauseDevice.alcDeviceResumeSOFT(deviceId); + SOFTPauseDevice.alcDeviceResumeSOFT(device); } } diff --git a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java index b1063d6b9..764b38379 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java @@ -65,7 +65,7 @@ public class GlfwJoystickInput implements JoyInput { @Override public Joystick[] loadJoysticks(final InputManager inputManager) { for (int i = 0; i < GLFW_JOYSTICK_LAST; i++) { - if (glfwJoystickPresent(i) == GL11.GL_TRUE) { + if (glfwJoystickPresent(i)) { final String name = glfwGetJoystickName(i); final GlfwJoystick joystick = new GlfwJoystick(inputManager, this, i, name); joysticks.put(i, joystick); diff --git a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java index e0fa70b92..7e1eb29f9 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java @@ -87,6 +87,16 @@ public class GlfwKeyInput implements KeyInput { keyInputEvents.add(event); } + + @Override + public void close() { + super.close(); + } + + @Override + public void callback(long args) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } }); glfwSetCharCallback(context.getWindowHandle(), charCallback = new GLFWCharCallback() { @@ -106,6 +116,16 @@ public class GlfwKeyInput implements KeyInput { keyInputEvents.add(released); } + + @Override + public void close() { + super.close(); + } + + @Override + public void callback(long args) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } }); initialized = true; @@ -132,8 +152,8 @@ public class GlfwKeyInput implements KeyInput { return; } - keyCallback.release(); - charCallback.release(); + keyCallback.close(); + charCallback.close(); logger.fine("Keyboard destroyed."); } diff --git a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java index 17c91aa33..f9081f731 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java @@ -133,6 +133,16 @@ public class GlfwMouseInput implements MouseInput { public void invoke(long window, double xpos, double ypos) { onCursorPos(window, xpos, ypos); } + + @Override + public void close() { + super.close(); + } + + @Override + public void callback(long args) { + super.callback(args); + } }); glfwSetScrollCallback(context.getWindowHandle(), scrollCallback = new GLFWScrollCallback() { @@ -140,6 +150,15 @@ public class GlfwMouseInput implements MouseInput { public void invoke(final long window, final double xOffset, final double yOffset) { onWheelScroll(window, xOffset, yOffset * WHEEL_SCALE); } + @Override + public void close() { + super.close(); + } + + @Override + public void callback(long args) { + super.callback(args); + } }); glfwSetMouseButtonCallback(context.getWindowHandle(), mouseButtonCallback = new GLFWMouseButtonCallback() { @@ -147,6 +166,15 @@ public class GlfwMouseInput implements MouseInput { public void invoke(final long window, final int button, final int action, final int mods) { onMouseButton(window, button, action, mods); } + @Override + public void close() { + super.close(); + } + + @Override + public void callback(long args) { + super.callback(args); + } }); setCursorVisible(cursorVisible); @@ -177,9 +205,9 @@ public class GlfwMouseInput implements MouseInput { return; } - cursorPosCallback.release(); - scrollCallback.release(); - mouseButtonCallback.release(); + cursorPosCallback.close(); + scrollCallback.close(); + mouseButtonCallback.close(); for (long glfwCursor : jmeToGlfwCursorMap.values()) { glfwDestroyCursor(glfwCursor); diff --git a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglGLDebugOutputHandler.java b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglGLDebugOutputHandler.java index aa9c46511..d03f54962 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglGLDebugOutputHandler.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglGLDebugOutputHandler.java @@ -75,4 +75,14 @@ class LwjglGLDebugOutputHandler extends GLDebugMessageARBCallback { System.err.println(String.format(MESSAGE_FORMAT, id, sourceStr, typeStr, severityStr, message)); } + + @Override + public void close() { + super.close(); + } + + @Override + public void callback(long args) { + super.callback(args); + } } diff --git a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java index 6e351d8b2..d5e515410 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java @@ -132,9 +132,19 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable { final String message = GLFWErrorCallback.getDescription(description); listener.handleError(message, new Exception(message)); } + + @Override + public void close(){ + super.close(); + } + + @Override + public void callback(long args) { + super.callback(args); + } }); - if (glfwInit() != GLFW_TRUE) { + if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } @@ -161,7 +171,7 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable { glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, settings.isResizable() ? GLFW_TRUE : GLFW_FALSE); - glfwWindowHint(GLFW_DOUBLE_BUFFER, GLFW_TRUE); + //glfwWindowHint(GLFW_DOUBLE_BUFFER, GLFW_TRUE); glfwWindowHint(GLFW_DEPTH_BITS, settings.getDepthBits()); glfwWindowHint(GLFW_STENCIL_BITS, settings.getStencilBits()); glfwWindowHint(GLFW_SAMPLES, settings.getSamples()); @@ -206,12 +216,21 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable { settings.setResolution(width, height); listener.reshape(width, height); } + + @Override + public void close() { + super.close(); + } + + @Override + public void callback(long args) { + super.callback(args); + } }); glfwSetWindowFocusCallback(window, windowFocusCallback = new GLFWWindowFocusCallback() { @Override - public void invoke(final long window, final int focused) { - final boolean focus = (focused == GL_TRUE); + public void invoke(final long window, final boolean focus) { if (wasActive != focus) { if (!wasActive) { listener.gainFocus(); @@ -223,6 +242,16 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable { wasActive = !wasActive; } } + + @Override + public void close() { + super.close(); + } + + @Override + public void callback(long args) { + super.callback(args); + } }); // Center the window @@ -260,17 +289,17 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable { } if (errorCallback != null) { - errorCallback.release(); + errorCallback.close(); errorCallback = null; } if (windowSizeCallback != null) { - windowSizeCallback.release(); + windowSizeCallback.close(); windowSizeCallback = null; } if (windowFocusCallback != null) { - windowFocusCallback.release(); + windowFocusCallback.close(); windowFocusCallback = null; } @@ -460,7 +489,7 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable { break; } - if (glfwWindowShouldClose(window) == GL_TRUE) { + if (glfwWindowShouldClose(window)) { listener.requestClose(false); } }