Merge remote-tracking branch 'origin/master' into experimental

experimental
Kirill Vainer 9 years ago
commit 3bb01d6963
  1. 2
      jme3-bullet-native/src/native/cpp/jmeClasses.cpp
  2. 1
      jme3-bullet-native/src/native/cpp/jmeClasses.h
  3. 24
      jme3-bullet-native/src/native/cpp/jmePhysicsSpace.cpp
  4. 15
      jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java
  5. 21
      jme3-core/src/main/java/com/jme3/app/LegacyApplication.java
  6. 10
      jme3-core/src/main/java/com/jme3/app/SimpleApplication.java
  7. 16
      jme3-core/src/main/java/com/jme3/light/Light.java
  8. 1
      jme3-core/src/main/java/com/jme3/renderer/opengl/GL3.java
  9. 6
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLDebugDesktop.java
  10. 8
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
  11. 7
      jme3-core/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java
  12. 2
      jme3-core/src/main/java/com/jme3/shader/VarType.java
  13. 56
      jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java
  14. 3
      jme3-core/src/main/java/com/jme3/util/clone/Cloner.java
  15. 1
      jme3-core/src/plugins/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java
  16. 10
      jme3-jbullet/src/main/java/com/jme3/bullet/PhysicsSpace.java
  17. 5
      jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglGL.java
  18. 5
      jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL.java
  19. 4
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java
  20. 3
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java
  21. 2
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglOffscreenBuffer.java
  22. 44
      jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java
  23. 6
      jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java
  24. 5
      jme3-lwjgl3/src/main/java/com/jme3/renderer/lwjgl/LwjglGL.java

@ -40,6 +40,7 @@ jclass jmeClasses::PhysicsSpace;
jmethodID jmeClasses::PhysicsSpace_preTick; jmethodID jmeClasses::PhysicsSpace_preTick;
jmethodID jmeClasses::PhysicsSpace_postTick; jmethodID jmeClasses::PhysicsSpace_postTick;
jmethodID jmeClasses::PhysicsSpace_addCollisionEvent; jmethodID jmeClasses::PhysicsSpace_addCollisionEvent;
jmethodID jmeClasses::PhysicsSpace_notifyCollisionGroupListeners;
jclass jmeClasses::PhysicsGhostObject; jclass jmeClasses::PhysicsGhostObject;
jmethodID jmeClasses::PhysicsGhostObject_addOverlappingObject; jmethodID jmeClasses::PhysicsGhostObject_addOverlappingObject;
@ -137,6 +138,7 @@ void jmeClasses::initJavaClasses(JNIEnv* env) {
PhysicsSpace_preTick = env->GetMethodID(PhysicsSpace, "preTick_native", "(F)V"); PhysicsSpace_preTick = env->GetMethodID(PhysicsSpace, "preTick_native", "(F)V");
PhysicsSpace_postTick = env->GetMethodID(PhysicsSpace, "postTick_native", "(F)V"); PhysicsSpace_postTick = env->GetMethodID(PhysicsSpace, "postTick_native", "(F)V");
PhysicsSpace_addCollisionEvent = env->GetMethodID(PhysicsSpace, "addCollisionEvent_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;Lcom/jme3/bullet/collision/PhysicsCollisionObject;J)V"); PhysicsSpace_addCollisionEvent = env->GetMethodID(PhysicsSpace, "addCollisionEvent_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;Lcom/jme3/bullet/collision/PhysicsCollisionObject;J)V");
PhysicsSpace_notifyCollisionGroupListeners = env->GetMethodID(PhysicsSpace, "notifyCollisionGroupListeners_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;Lcom/jme3/bullet/collision/PhysicsCollisionObject;)Z");
if (env->ExceptionCheck()) { if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred()); env->Throw(env->ExceptionOccurred());
return; return;

@ -46,6 +46,7 @@ public:
static jmethodID PhysicsSpace_addCollisionEvent; static jmethodID PhysicsSpace_addCollisionEvent;
static jclass PhysicsGhostObject; static jclass PhysicsGhostObject;
static jmethodID PhysicsGhostObject_addOverlappingObject; static jmethodID PhysicsGhostObject_addOverlappingObject;
static jmethodID PhysicsSpace_notifyCollisionGroupListeners;
static jclass Vector3f; static jclass Vector3f;
static jmethodID Vector3f_set; static jmethodID Vector3f_set;

@ -187,8 +187,28 @@ void jmePhysicsSpace::createPhysicsSpace(jfloat minX, jfloat minY, jfloat minZ,
jmeUserPointer *up0 = (jmeUserPointer*) co0 -> getUserPointer(); jmeUserPointer *up0 = (jmeUserPointer*) co0 -> getUserPointer();
jmeUserPointer *up1 = (jmeUserPointer*) co1 -> getUserPointer(); jmeUserPointer *up1 = (jmeUserPointer*) co1 -> getUserPointer();
if (up0 != NULL && up1 != NULL) { if (up0 != NULL && up1 != NULL) {
collides = (up0->group & up1->groups) != 0; collides = (up0->group & up1->groups) != 0 || (up1->group & up0->groups) != 0;
collides = collides && (up1->group & up0->groups);
if(collides){
jmePhysicsSpace *dynamicsWorld = (jmePhysicsSpace *)up0->space;
JNIEnv* env = dynamicsWorld->getEnv();
jobject javaPhysicsSpace = env->NewLocalRef(dynamicsWorld->getJavaPhysicsSpace());
jobject javaCollisionObject0 = env->NewLocalRef(up0->javaCollisionObject);
jobject javaCollisionObject1 = env->NewLocalRef(up1->javaCollisionObject);
jboolean notifyResult = env->CallBooleanMethod(javaPhysicsSpace, jmeClasses::PhysicsSpace_notifyCollisionGroupListeners, javaCollisionObject0, javaCollisionObject1);
env->DeleteLocalRef(javaPhysicsSpace);
env->DeleteLocalRef(javaCollisionObject0);
env->DeleteLocalRef(javaCollisionObject1);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return collides;
}
collides = (bool) notifyResult;
}
//add some additional logic here that modified 'collides' //add some additional logic here that modified 'collides'
return collides; return collides;

@ -336,6 +336,21 @@ public class PhysicsSpace {
collisionEvents.add(eventFactory.getEvent(PhysicsCollisionEvent.TYPE_PROCESSED, node, node1, manifoldPointObjectId)); collisionEvents.add(eventFactory.getEvent(PhysicsCollisionEvent.TYPE_PROCESSED, node, node1, manifoldPointObjectId));
} }
private boolean notifyCollisionGroupListeners_native(PhysicsCollisionObject node, PhysicsCollisionObject node1){
PhysicsCollisionGroupListener listener = collisionGroupListeners.get(node.getCollisionGroup());
PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(node1.getCollisionGroup());
boolean result = true;
if(listener != null){
result = listener.collide(node, node1);
}
if(listener1 != null && node.getCollisionGroup() != node1.getCollisionGroup()){
result = listener1.collide(node, node1) && result;
}
return result;
}
/** /**
* updates the physics space * updates the physics space
* *

@ -31,6 +31,7 @@
*/ */
package com.jme3.app; package com.jme3.app;
import com.jme3.app.state.AppState;
import com.jme3.app.state.AppStateManager; import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
import com.jme3.audio.AudioContext; import com.jme3.audio.AudioContext;
@ -100,8 +101,24 @@ public class LegacyApplication implements Application, SystemListener {
/** /**
* Create a new instance of <code>LegacyApplication</code>. * Create a new instance of <code>LegacyApplication</code>.
*/ */
public LegacyApplication(){ public LegacyApplication() {
this((AppState[])null);
}
/**
* Create a new instance of <code>LegacyApplication</code>, preinitialized
* with the specified set of app states.
*/
public LegacyApplication( AppState... initialStates ) {
initStateManager(); initStateManager();
if (initialStates != null) {
for (AppState a : initialStates) {
if (a != null) {
stateManager.attach(a);
}
}
}
} }
/** /**
@ -523,8 +540,10 @@ public class LegacyApplication implements Application, SystemListener {
* Internal use only. * Internal use only.
*/ */
public void reshape(int w, int h){ public void reshape(int w, int h){
if (renderManager != null) {
renderManager.notifyReshape(w, h); renderManager.notifyReshape(w, h);
} }
}
/** /**
* Restarts the context, applying any changed settings. * Restarts the context, applying any changed settings.

@ -100,15 +100,7 @@ public abstract class SimpleApplication extends LegacyApplication {
} }
public SimpleApplication( AppState... initialStates ) { public SimpleApplication( AppState... initialStates ) {
super(); super(initialStates);
if (initialStates != null) {
for (AppState a : initialStates) {
if (a != null) {
stateManager.attach(a);
}
}
}
} }
@Override @Override

@ -184,6 +184,22 @@ public abstract class Light implements Savable, Cloneable {
this.enabled = enabled; this.enabled = enabled;
} }
public boolean isFrustumCheckNeeded() {
return frustumCheckNeeded;
}
public void setFrustumCheckNeeded(boolean frustumCheckNeeded) {
this.frustumCheckNeeded = frustumCheckNeeded;
}
public boolean isIntersectsFrustum() {
return intersectsFrustum;
}
public void setIntersectsFrustum(boolean intersectsFrustum) {
this.intersectsFrustum = intersectsFrustum;
}
/** /**
* Determines if the light intersects with the given bounding box. * Determines if the light intersects with the given bounding box.
* <p> * <p>

@ -58,6 +58,7 @@ public interface GL3 extends GL2 {
public void glBindFragDataLocation(int param1, int param2, String param3); /// GL3+ public void glBindFragDataLocation(int param1, int param2, String param3); /// GL3+
public void glBindVertexArray(int param1); /// GL3+ public void glBindVertexArray(int param1); /// GL3+
public void glDeleteVertexArrays(IntBuffer arrays); /// GL3+ public void glDeleteVertexArrays(IntBuffer arrays); /// GL3+
public void glFramebufferTextureLayer(int param1, int param2, int param3, int param4, int param5); /// GL3+
public void glGenVertexArrays(IntBuffer param1); /// GL3+ public void glGenVertexArrays(IntBuffer param1); /// GL3+
public String glGetString(int param1, int param2); /// GL3+ public String glGetString(int param1, int param2); /// GL3+
} }

@ -94,4 +94,10 @@ public class GLDebugDesktop extends GLDebugES implements GL2, GL3, GL4 {
gl4.glPatchParameter(count); gl4.glPatchParameter(count);
checkError(); checkError();
} }
@Override
public void glFramebufferTextureLayer(int param1, int param2, int param3, int param4, int param5) {
gl3.glFramebufferTextureLayer(param1, param2, param3, param4, param5);
checkError();
}
} }

@ -1461,11 +1461,19 @@ public final class GLRenderer implements Renderer {
setupTextureParams(0, tex); setupTextureParams(0, tex);
} }
if (rb.getLayer() < 0){
glfbo.glFramebufferTexture2DEXT(GLFbo.GL_FRAMEBUFFER_EXT, glfbo.glFramebufferTexture2DEXT(GLFbo.GL_FRAMEBUFFER_EXT,
convertAttachmentSlot(rb.getSlot()), convertAttachmentSlot(rb.getSlot()),
convertTextureType(tex.getType(), image.getMultiSamples(), rb.getFace()), convertTextureType(tex.getType(), image.getMultiSamples(), rb.getFace()),
image.getId(), image.getId(),
0); 0);
} else {
gl3.glFramebufferTextureLayer(GLFbo.GL_FRAMEBUFFER_EXT,
convertAttachmentSlot(rb.getSlot()),
image.getId(),
0,
rb.getLayer());
}
} }
public void updateFrameBufferAttachment(FrameBuffer fb, RenderBuffer rb) { public void updateFrameBufferAttachment(FrameBuffer fb, RenderBuffer rb) {

@ -258,7 +258,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
} }
for (ShaderNodeVariable var : shaderNode.getDefinition().getOutputs()) { for (ShaderNodeVariable var : shaderNode.getDefinition().getOutputs()) {
ShaderNodeVariable v = new ShaderNodeVariable(var.getType(), shaderNode.getName(), var.getName()); ShaderNodeVariable v = new ShaderNodeVariable(var.getType(), shaderNode.getName(), var.getName(), var.getMultiplicity());
if (!declaredInputs.contains(shaderNode.getName() + "_" + var.getName())) { if (!declaredInputs.contains(shaderNode.getName() + "_" + var.getName())) {
if (!isVarying(info, v)) { if (!isVarying(info, v)) {
declareVariable(source, v); declareVariable(source, v);
@ -397,6 +397,11 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
source.append(mapping.getLeftVariable().getNameSpace()); source.append(mapping.getLeftVariable().getNameSpace());
source.append("_"); source.append("_");
source.append(mapping.getLeftVariable().getName()); source.append(mapping.getLeftVariable().getName());
if (mapping.getLeftVariable().getMultiplicity() != null){
source.append("[");
source.append(mapping.getLeftVariable().getMultiplicity());
source.append("]");
}
//left swizzle, the variable can't be declared and assigned on the same line. //left swizzle, the variable can't be declared and assigned on the same line.
if (mapping.getLeftSwizzling().length() > 0) { if (mapping.getLeftSwizzling().length() > 0) {

@ -55,7 +55,7 @@ public enum VarType {
TextureBuffer(false,true,"sampler1D|sampler1DShadow"), TextureBuffer(false,true,"sampler1D|sampler1DShadow"),
Texture2D(false,true,"sampler2D|sampler2DShadow"), Texture2D(false,true,"sampler2D|sampler2DShadow"),
Texture3D(false,true,"sampler3D"), Texture3D(false,true,"sampler3D"),
TextureArray(false,true,"sampler2DArray"), TextureArray(false,true,"sampler2DArray|sampler2DArrayShadow"),
TextureCubeMap(false,true,"samplerCube"), TextureCubeMap(false,true,"samplerCube"),
Int("int"); Int("int");

@ -97,6 +97,7 @@ public class FrameBuffer extends NativeObject {
int id = -1; int id = -1;
int slot = SLOT_UNDEF; int slot = SLOT_UNDEF;
int face = -1; int face = -1;
int layer = -1;
/** /**
* @return The image format of the render buffer. * @return The image format of the render buffer.
@ -160,6 +161,10 @@ public class FrameBuffer extends NativeObject {
return "BufferTarget[format=" + format + "]"; return "BufferTarget[format=" + format + "]";
} }
} }
public int getLayer() {
return this.layer;
}
} }
/** /**
@ -324,6 +329,19 @@ public class FrameBuffer extends NativeObject {
addColorTexture(tex); addColorTexture(tex);
} }
/**
* Set the color texture array to use for this framebuffer.
* This automatically clears all existing textures added previously
* with {@link FrameBuffer#addColorTexture } and adds this texture as the
* only target.
*
* @param tex The color texture array to set.
*/
public void setColorTexture(TextureArray tex, int layer){
clearColorTargets();
addColorTexture(tex, layer);
}
/** /**
* Set the color texture to use for this framebuffer. * Set the color texture to use for this framebuffer.
* This automatically clears all existing textures added previously * This automatically clears all existing textures added previously
@ -369,6 +387,31 @@ public class FrameBuffer extends NativeObject {
colorBufs.add(colorBuf); colorBufs.add(colorBuf);
} }
/**
* Add a color texture array to use for this framebuffer.
* If MRT is enabled, then each subsequently added texture can be
* rendered to through a shader that writes to the array <code>gl_FragData</code>.
* If MRT is not enabled, then the index set with {@link FrameBuffer#setTargetIndex(int) }
* is rendered to by the shader.
*
* @param tex The texture array to add.
*/
public void addColorTexture(TextureArray tex, int layer) {
if (id != -1)
throw new UnsupportedOperationException("FrameBuffer already initialized.");
Image img = tex.getImage();
checkSetTexture(tex, false);
RenderBuffer colorBuf = new RenderBuffer();
colorBuf.slot = colorBufs.size();
colorBuf.tex = tex;
colorBuf.format = img.getFormat();
colorBuf.layer = layer;
colorBufs.add(colorBuf);
}
/** /**
* Add a color texture to use for this framebuffer. * Add a color texture to use for this framebuffer.
* If MRT is enabled, then each subsequently added texture can be * If MRT is enabled, then each subsequently added texture can be
@ -412,6 +455,19 @@ public class FrameBuffer extends NativeObject {
depthBuf.tex = tex; depthBuf.tex = tex;
depthBuf.format = img.getFormat(); depthBuf.format = img.getFormat();
} }
public void setDepthTexture(TextureArray tex, int layer){
if (id != -1)
throw new UnsupportedOperationException("FrameBuffer already initialized.");
Image img = tex.getImage();
checkSetTexture(tex, true);
depthBuf = new RenderBuffer();
depthBuf.slot = img.getFormat().isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH;
depthBuf.tex = tex;
depthBuf.format = img.getFormat();
depthBuf.layer = layer;
}
/** /**
* @return The number of color buffers attached to this texture. * @return The number of color buffers attached to this texture.

@ -354,6 +354,9 @@ public class Cloner {
* clone() and objects without necessarily knowing their real type.</p> * clone() and objects without necessarily knowing their real type.</p>
*/ */
public <T> T javaClone( T object ) throws CloneNotSupportedException { public <T> T javaClone( T object ) throws CloneNotSupportedException {
if( object == null ) {
return null;
}
Method m = methodCache.get(object.getClass()); Method m = methodCache.get(object.getClass());
if( m == null ) { if( m == null ) {
try { try {

@ -753,6 +753,7 @@ public class ShaderNodeLoaderDelegate {
} }
right.setNameSpace(node.getName()); right.setNameSpace(node.getName());
right.setType(var.getType()); right.setType(var.getType());
right.setMultiplicity(var.getMultiplicity());
mapping.setRightVariable(right); mapping.setRightVariable(right);
storeVaryings(node, mapping.getRightVariable()); storeVaryings(node, mapping.getRightVariable());

@ -237,12 +237,12 @@ public class PhysicsSpace {
|| (collisionObject1.getCollideWithGroups() & collisionObject.getCollisionGroup()) > 0) { || (collisionObject1.getCollideWithGroups() & collisionObject.getCollisionGroup()) > 0) {
PhysicsCollisionGroupListener listener = collisionGroupListeners.get(collisionObject.getCollisionGroup()); PhysicsCollisionGroupListener listener = collisionGroupListeners.get(collisionObject.getCollisionGroup());
PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(collisionObject1.getCollisionGroup()); PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(collisionObject1.getCollisionGroup());
if (listener != null) { if(listener != null){
return listener.collide(collisionObject, collisionObject1); collides = listener.collide(collisionObject, collisionObject1);
} else if (listener1 != null) { }
return listener1.collide(collisionObject, collisionObject1); if(listener1 != null && collisionObject.getCollisionGroup() != collisionObject1.getCollisionGroup()){
collides = listener1.collide(collisionObject, collisionObject1) && collides;
} }
return true;
} else { } else {
return false; return false;
} }

@ -600,4 +600,9 @@ public class JoglGL implements GL, GL2, GL3, GL4 {
checkLimit(arrays); checkLimit(arrays);
GLContext.getCurrentGL().getGL2ES3().glDeleteVertexArrays(arrays.limit(), arrays); GLContext.getCurrentGL().getGL2ES3().glDeleteVertexArrays(arrays.limit(), arrays);
} }
@Override
public void glFramebufferTextureLayer(int param1, int param2, int param3, int param4, int param5) {
GLContext.getCurrentGL().getGL3().glFramebufferTextureLayer(param1, param2, param3, param4, param5);
}
} }

@ -457,4 +457,9 @@ public final class LwjglGL implements GL, GL2, GL3, GL4 {
checkLimit(arrays); checkLimit(arrays);
ARBVertexArrayObject.glDeleteVertexArrays(arrays); ARBVertexArrayObject.glDeleteVertexArrays(arrays);
} }
@Override
public void glFramebufferTextureLayer(int param1, int param2, int param3, int param4, int param5) {
GL30.glFramebufferTextureLayer(param1, param2, param3, param4, param5);
}
} }

@ -301,7 +301,7 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
// crashes on bad drivers // crashes on bad drivers
if (pbufferFormat == null){ if (pbufferFormat == null){
pbufferFormat = new PixelFormat(settings.getBitsPerPixel(), pbufferFormat = new PixelFormat(settings.getBitsPerPixel(),
0, settings.getAlphaBits(),
settings.getDepthBits(), settings.getDepthBits(),
settings.getStencilBits(), settings.getStencilBits(),
0, // samples 0, // samples
@ -315,7 +315,7 @@ public class LwjglCanvas extends LwjglAbstractDisplay implements JmeCanvasContex
if (canvasFormat == null){ if (canvasFormat == null){
int samples = getNumSamplesToUse(); int samples = getNumSamplesToUse();
canvasFormat = new PixelFormat(settings.getBitsPerPixel(), canvasFormat = new PixelFormat(settings.getBitsPerPixel(),
0, settings.getAlphaBits(),
settings.getDepthBits(), settings.getDepthBits(),
settings.getStencilBits(), settings.getStencilBits(),
samples, samples,

@ -84,7 +84,7 @@ public class LwjglDisplay extends LwjglAbstractDisplay {
int samples = getNumSamplesToUse(); int samples = getNumSamplesToUse();
PixelFormat pf = new PixelFormat(settings.getBitsPerPixel(), PixelFormat pf = new PixelFormat(settings.getBitsPerPixel(),
0, settings.getAlphaBits(),
settings.getDepthBits(), settings.getDepthBits(),
settings.getStencilBits(), settings.getStencilBits(),
samples, samples,
@ -99,6 +99,7 @@ public class LwjglDisplay extends LwjglAbstractDisplay {
boolean pixelFormatChanged = false; boolean pixelFormatChanged = false;
if (created.get() && (pixelFormat.getBitsPerPixel() != pf.getBitsPerPixel() if (created.get() && (pixelFormat.getBitsPerPixel() != pf.getBitsPerPixel()
||pixelFormat.getAlphaBits() != pf.getAlphaBits()
||pixelFormat.getDepthBits() != pf.getDepthBits() ||pixelFormat.getDepthBits() != pf.getDepthBits()
||pixelFormat.getStencilBits() != pf.getStencilBits() ||pixelFormat.getStencilBits() != pf.getStencilBits()
||pixelFormat.getSamples() != pf.getSamples())){ ||pixelFormat.getSamples() != pf.getSamples())){

@ -62,7 +62,7 @@ public class LwjglOffscreenBuffer extends LwjglContext implements Runnable {
int samples = getNumSamplesToUse(); int samples = getNumSamplesToUse();
pixelFormat = new PixelFormat(settings.getBitsPerPixel(), pixelFormat = new PixelFormat(settings.getBitsPerPixel(),
0, settings.getAlphaBits(),
settings.getDepthBits(), settings.getDepthBits(),
settings.getStencilBits(), settings.getStencilBits(),
samples); samples);

@ -36,13 +36,21 @@ import com.jme3.input.KeyInput;
import com.jme3.input.RawInputListener; import com.jme3.input.RawInputListener;
import com.jme3.input.event.KeyInputEvent; import com.jme3.input.event.KeyInputEvent;
import com.jme3.system.lwjgl.LwjglWindow; import com.jme3.system.lwjgl.LwjglWindow;
import org.lwjgl.glfw.GLFWCharCallback;
import org.lwjgl.glfw.GLFWKeyCallback; import org.lwjgl.glfw.GLFWKeyCallback;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import java.util.logging.Logger; import java.util.logging.Logger;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.GLFW_KEY_LAST;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE;
import static org.lwjgl.glfw.GLFW.GLFW_PRESS;
import static org.lwjgl.glfw.GLFW.GLFW_REPEAT;
import static org.lwjgl.glfw.GLFW.glfwGetTime;
import static org.lwjgl.glfw.GLFW.glfwSetCharCallback;
import static org.lwjgl.glfw.GLFW.glfwSetKeyCallback;
public class GlfwKeyInput implements KeyInput { public class GlfwKeyInput implements KeyInput {
@ -52,6 +60,7 @@ public class GlfwKeyInput implements KeyInput {
private RawInputListener listener; private RawInputListener listener;
private boolean initialized; private boolean initialized;
private GLFWKeyCallback keyCallback; private GLFWKeyCallback keyCallback;
private GLFWCharCallback charCallback;
private Queue<KeyInputEvent> keyInputEvents = new LinkedList<KeyInputEvent>(); private Queue<KeyInputEvent> keyInputEvents = new LinkedList<KeyInputEvent>();
public GlfwKeyInput(LwjglWindow context) { public GlfwKeyInput(LwjglWindow context) {
@ -66,14 +75,38 @@ public class GlfwKeyInput implements KeyInput {
glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() { glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() {
@Override @Override
public void invoke(long window, int key, int scancode, int action, int mods) { public void invoke(long window, int key, int scancode, int action, int mods) {
if (key < 0 || key > GLFW_KEY_LAST) {
return;
}
int jmeKey = GlfwKeyMap.toJmeKeyCode(key); int jmeKey = GlfwKeyMap.toJmeKeyCode(key);
final KeyInputEvent evt = new KeyInputEvent(jmeKey, (char) key, GLFW_PRESS == action, GLFW_REPEAT == action);
evt.setTime(getInputTimeNanos()); final KeyInputEvent event = new KeyInputEvent(jmeKey, '\0', GLFW_PRESS == action, GLFW_REPEAT == action);
keyInputEvents.add(evt); event.setTime(getInputTimeNanos());
keyInputEvents.add(event);
} }
}); });
glfwSetInputMode(context.getWindowHandle(), GLFW_STICKY_KEYS, 1); glfwSetCharCallback(context.getWindowHandle(), charCallback = new GLFWCharCallback() {
@Override
public void invoke(long window, int codepoint) {
final char keyChar = (char) codepoint;
final KeyInputEvent pressed = new KeyInputEvent(KeyInput.KEY_UNKNOWN, keyChar, true, false);
pressed.setTime(getInputTimeNanos());
keyInputEvents.add(pressed);
final KeyInputEvent released = new KeyInputEvent(KeyInput.KEY_UNKNOWN, keyChar, false, false);
released.setTime(getInputTimeNanos());
keyInputEvents.add(released);
}
});
initialized = true; initialized = true;
logger.fine("Keyboard created."); logger.fine("Keyboard created.");
@ -100,6 +133,7 @@ public class GlfwKeyInput implements KeyInput {
} }
keyCallback.release(); keyCallback.release();
charCallback.release();
logger.fine("Keyboard destroyed."); logger.fine("Keyboard destroyed.");
} }

@ -67,6 +67,8 @@ public class GlfwMouseInput implements MouseInput {
private static final Logger logger = Logger.getLogger(GlfwMouseInput.class.getName()); private static final Logger logger = Logger.getLogger(GlfwMouseInput.class.getName());
private static final int WHEEL_SCALE = 120;
private LwjglWindow context; private LwjglWindow context;
private RawInputListener listener; private RawInputListener listener;
private boolean cursorVisible = true; private boolean cursorVisible = true;
@ -136,7 +138,7 @@ public class GlfwMouseInput implements MouseInput {
glfwSetScrollCallback(context.getWindowHandle(), scrollCallback = new GLFWScrollCallback() { glfwSetScrollCallback(context.getWindowHandle(), scrollCallback = new GLFWScrollCallback() {
@Override @Override
public void invoke(final long window, final double xOffset, final double yOffset) { public void invoke(final long window, final double xOffset, final double yOffset) {
onWheelScroll(window, xOffset, yOffset); onWheelScroll(window, xOffset, yOffset * WHEEL_SCALE);
} }
}); });
@ -213,7 +215,7 @@ public class GlfwMouseInput implements MouseInput {
// TODO: currently animated cursors are not supported // TODO: currently animated cursors are not supported
IntBuffer imageData = jmeCursor.getImagesData(); IntBuffer imageData = jmeCursor.getImagesData();
ByteBuffer buf = BufferUtils.createByteBuffer(imageData.capacity()); ByteBuffer buf = BufferUtils.createByteBuffer(imageData.capacity() * 4);
buf.asIntBuffer().put(imageData); buf.asIntBuffer().put(imageData);
glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf); glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf);

@ -486,4 +486,9 @@ public class LwjglGL implements GL, GL2, GL3, GL4 {
checkLimit(arrays); checkLimit(arrays);
ARBVertexArrayObject.glDeleteVertexArrays(arrays); ARBVertexArrayObject.glDeleteVertexArrays(arrays);
} }
@Override
public void glFramebufferTextureLayer(int param1, int param2, int param3, int param4, int param5) {
GL30.glFramebufferTextureLayer(param1, param2, param3, param4, param5);
}
} }

Loading…
Cancel
Save