From f2384c80637270df2be64284cecde2766caf1560 Mon Sep 17 00:00:00 2001 From: Toni Helenius Date: Wed, 10 Aug 2016 20:02:34 +0300 Subject: [PATCH 01/10] Added a cursor cache to avoid cursor disappearing and app crashing when too many cursors are created --- .../com/jme3/input/lwjgl/LwjglMouseInput.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/jme3-lwjgl/src/main/java/com/jme3/input/lwjgl/LwjglMouseInput.java b/jme3-lwjgl/src/main/java/com/jme3/input/lwjgl/LwjglMouseInput.java index a91aab36e..f3982fd25 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/input/lwjgl/LwjglMouseInput.java +++ b/jme3-lwjgl/src/main/java/com/jme3/input/lwjgl/LwjglMouseInput.java @@ -39,6 +39,8 @@ import com.jme3.input.event.MouseButtonEvent; import com.jme3.input.event.MouseMotionEvent; import com.jme3.system.lwjgl.LwjglAbstractDisplay; import com.jme3.system.lwjgl.LwjglTimer; +import java.util.HashMap; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.lwjgl.LWJGLException; @@ -57,6 +59,12 @@ public class LwjglMouseInput implements MouseInput { private boolean supportHardwareCursor = false; private boolean cursorVisible = true; + /** + * We need to cache the cursors + * (https://github.com/jMonkeyEngine/jmonkeyengine/issues/537) + */ + private Map cursorMap = new HashMap(); + private int curX, curY, curWheel; public LwjglMouseInput(LwjglAbstractDisplay context){ @@ -120,7 +128,7 @@ public class LwjglMouseInput implements MouseInput { } if (btn != -1){ MouseButtonEvent evt = new MouseButtonEvent(btn, - Mouse.getEventButtonState(), x, y); + Mouse.getEventButtonState(), x, y); evt.setTime(Mouse.getEventNanoseconds()); listener.onMouseButtonEvent(evt); } @@ -132,6 +140,13 @@ public class LwjglMouseInput implements MouseInput { return; Mouse.destroy(); + + // Destroy the cursor cache + for (Cursor cursor : cursorMap.values()) { + cursor.destroy(); + } + cursorMap.clear(); + logger.fine("Mouse destroyed."); } @@ -155,14 +170,20 @@ public class LwjglMouseInput implements MouseInput { try { Cursor newCursor = null; if (jmeCursor != null) { - newCursor = new Cursor( - jmeCursor.getWidth(), - jmeCursor.getHeight(), - jmeCursor.getXHotSpot(), - jmeCursor.getYHotSpot(), - jmeCursor.getNumImages(), - jmeCursor.getImagesData(), - jmeCursor.getImagesDelay()); + 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) { From 9665b985e4c8565b6131dff2d360c04cff0ec458 Mon Sep 17 00:00:00 2001 From: Nehon Date: Fri, 19 Aug 2016 10:54:17 +0200 Subject: [PATCH 02/10] Fixed wrong alpha handling in the pbr shader --- .../main/resources/Common/MatDefs/Light/PBRLighting.frag | 6 ++++-- .../main/resources/Common/MatDefs/Light/PBRLighting.vert | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag index 27ea29aa4..0bd396383 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag @@ -9,7 +9,9 @@ varying vec2 texCoord; varying vec2 texCoord2; #endif -varying vec4 Color; +#ifndef BASECOLORMAP + varying vec4 Color; +#endif uniform vec4 g_LightData[NB_LIGHTS]; @@ -122,7 +124,7 @@ void main(){ float Metallic = max(m_Metallic, 0.0); #endif - float alpha = Color.a * albedo.a; + float alpha = albedo.a; #ifdef DISCARD_ALPHA if(alpha < m_AlphaDiscardThreshold){ diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert index 77782456b..c5cb00075 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert @@ -13,7 +13,9 @@ varying vec2 texCoord; attribute vec2 inTexCoord2; #endif -varying vec4 Color; +#ifndef BASECOLORMAP + varying vec4 Color; +#endif attribute vec3 inPosition; attribute vec2 inTexCoord; @@ -59,7 +61,9 @@ void main(){ wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w); #endif - Color = m_BaseColor; + #ifndef BASECOLORMAP + Color = m_BaseColor; + #endif #ifdef VERTEX_COLOR Color *= inColor; From 0262b72258d1b9b1b2e490ce8b6ee07aeaa66f82 Mon Sep 17 00:00:00 2001 From: MeFisto94 Date: Sat, 20 Aug 2016 11:26:41 +0200 Subject: [PATCH 03/10] Using LegacyApplication in the iOS Harness just like it has been done for Android in 3c56afe --- jme3-ios/src/main/java/com/jme3/system/ios/IosHarness.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jme3-ios/src/main/java/com/jme3/system/ios/IosHarness.java b/jme3-ios/src/main/java/com/jme3/system/ios/IosHarness.java index f3b10196e..7a47d8ff9 100644 --- a/jme3-ios/src/main/java/com/jme3/system/ios/IosHarness.java +++ b/jme3-ios/src/main/java/com/jme3/system/ios/IosHarness.java @@ -31,7 +31,7 @@ */ package com.jme3.system.ios; -import com.jme3.app.Application; +import com.jme3.app.LegacyApplication; import com.jme3.system.JmeSystem; /** @@ -39,7 +39,7 @@ import com.jme3.system.JmeSystem; */ public abstract class IosHarness extends ObjcNativeObject { - protected Application app; + protected LegacyApplication app; public IosHarness(long appDelegate) { super(appDelegate); From bdd15b7f3e2ef053db0766a183341af2d40873fd Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Tue, 6 Sep 2016 17:12:43 +0430 Subject: [PATCH 04/10] fixed a typo --- jme3-core/src/main/java/com/jme3/util/clone/JmeCloneable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/util/clone/JmeCloneable.java b/jme3-core/src/main/java/com/jme3/util/clone/JmeCloneable.java index 6b278b222..13a9e0e71 100644 --- a/jme3-core/src/main/java/com/jme3/util/clone/JmeCloneable.java +++ b/jme3-core/src/main/java/com/jme3/util/clone/JmeCloneable.java @@ -49,7 +49,7 @@ package com.jme3.util.clone; * *

Cloning of a JmeCloneable object is done in two parts. First, * the standard Java clone() method is called to create a shallow clone - * of the object. Second, the cloner wil lcall the cloneFields() method + * of the object. Second, the cloner will call the cloneFields() method * to let the object deep clone any of its fields that should be cloned.

* *

This two part process is necessary to facilitate circular references. From 28281f796281dee9e30b6193c590a3fef2a6ed4d Mon Sep 17 00:00:00 2001 From: TehLeo Date: Sat, 10 Sep 2016 20:33:50 +0200 Subject: [PATCH 05/10] Fix for MTR Framebuffers The problem: Happens with two MTR framebuffers with same number of color attachements. If we set a frame buffer frame1, then later frame2. r.setFrameBuffer(frame1); r.setFrameBuffer(frame2); Frame2 buffer will not output to multiple targets. Only its first target will be rendered. This patch fixes that problem. --- .../com/jme3/renderer/opengl/GLRenderer.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index 1a8270435..a3b71b92a 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -1675,16 +1675,15 @@ public final class GLRenderer implements Renderer { + " by the video hardware!"); } - if (context.boundDrawBuf != MRT_OFF + fb.getNumColorBuffers()) { - intBuf16.clear(); - for (int i = 0; i < fb.getNumColorBuffers(); i++) { - intBuf16.put(GLFbo.GL_COLOR_ATTACHMENT0_EXT + i); - } - - intBuf16.flip(); - glext.glDrawBuffers(intBuf16); - context.boundDrawBuf = MRT_OFF + fb.getNumColorBuffers(); + intBuf16.clear(); + for (int i = 0; i < fb.getNumColorBuffers(); i++) { + intBuf16.put(GLFbo.GL_COLOR_ATTACHMENT0_EXT + i); } + + intBuf16.flip(); + glext.glDrawBuffers(intBuf16); + context.boundDrawBuf = MRT_OFF + fb.getNumColorBuffers(); + } else { RenderBuffer rb = fb.getColorBuffer(fb.getTargetIndex()); // select this draw buffer From 651c3cc29ea4330249b34978bf442d6e4557de50 Mon Sep 17 00:00:00 2001 From: javasabr Date: Sun, 11 Sep 2016 13:50:52 +0300 Subject: [PATCH 06/10] fixed missing Cloneable in the Triangle. --- jme3-core/src/main/java/com/jme3/math/Triangle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/math/Triangle.java b/jme3-core/src/main/java/com/jme3/math/Triangle.java index 4b98e77aa..527d6e7b4 100644 --- a/jme3-core/src/main/java/com/jme3/math/Triangle.java +++ b/jme3-core/src/main/java/com/jme3/math/Triangle.java @@ -44,7 +44,7 @@ import java.io.IOException; * @author Mark Powell * @author Joshua Slack */ -public class Triangle extends AbstractTriangle implements Savable, java.io.Serializable { +public class Triangle extends AbstractTriangle implements Savable, Cloneable, java.io.Serializable { static final long serialVersionUID = 1; From 86c2c7f3413dba4f4b9c20cee8f809aa2c6b1420 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Wed, 14 Sep 2016 19:11:14 -0400 Subject: [PATCH 07/10] minor cleanup in GLRenderer --- .../com/jme3/renderer/opengl/GLRenderer.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index a3b71b92a..2052f91d2 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -1648,15 +1648,13 @@ public final class GLRenderer implements Renderer { if (fb.getNumColorBuffers() == 0) { // make sure to select NONE as draw buf // no color buffer attached. - if (gl2 != null) { - if (context.boundDrawBuf != NONE) { - gl2.glDrawBuffer(GL.GL_NONE); - context.boundDrawBuf = NONE; - } - if (context.boundReadBuf != NONE) { - gl2.glReadBuffer(GL.GL_NONE); - context.boundReadBuf = NONE; - } + if (context.boundDrawBuf != NONE) { + gl2.glDrawBuffer(GL.GL_NONE); + context.boundDrawBuf = NONE; + } + if (context.boundReadBuf != NONE) { + gl2.glReadBuffer(GL.GL_NONE); + context.boundReadBuf = NONE; } } else { if (fb.getNumColorBuffers() > limits.get(Limits.FrameBufferAttachments)) { @@ -1687,11 +1685,9 @@ public final class GLRenderer implements Renderer { } else { RenderBuffer rb = fb.getColorBuffer(fb.getTargetIndex()); // select this draw buffer - if (gl2 != null) { - if (context.boundDrawBuf != rb.getSlot()) { - gl2.glDrawBuffer(GLFbo.GL_COLOR_ATTACHMENT0_EXT + rb.getSlot()); - context.boundDrawBuf = rb.getSlot(); - } + if (context.boundDrawBuf != rb.getSlot()) { + gl2.glDrawBuffer(GLFbo.GL_COLOR_ATTACHMENT0_EXT + rb.getSlot()); + context.boundDrawBuf = rb.getSlot(); } } } From 8937e93cce4692bd398af270d60c0bc84d5b0ad2 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Thu, 15 Sep 2016 09:41:04 +0430 Subject: [PATCH 08/10] Minor fix in javadoc for Camera.java class --- jme3-core/src/main/java/com/jme3/renderer/Camera.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/Camera.java b/jme3-core/src/main/java/com/jme3/renderer/Camera.java index 2d4a61a45..a51ae0687 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/Camera.java +++ b/jme3-core/src/main/java/com/jme3/renderer/Camera.java @@ -991,7 +991,7 @@ public class Camera implements Savable, Cloneable { * Returns the pseudo distance from the given position to the near * plane of the camera. This is used for render queue sorting. * @param pos The position to compute a distance to. - * @return Distance from the far plane to the point. + * @return Distance from the near plane to the point. */ public float distanceToNearPlane(Vector3f pos) { return worldPlane[NEAR_PLANE].pseudoDistance(pos); From 97cac351051f0dcb6d27060f7b781427c15750c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Wei=C3=9F?= Date: Fri, 16 Sep 2016 09:42:57 +0200 Subject: [PATCH 09/10] Fix for #502 --- .../java/com/jme3/texture/FrameBuffer.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java b/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java index a3f825d26..e5755c595 100644 --- a/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java +++ b/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java @@ -363,6 +363,30 @@ public class FrameBuffer extends NativeObject { colorBufs.clear(); } + /** + * Add a color buffer without a texture bound to it. + * If MRT is enabled, then each subsequently added texture or buffer can be + * rendered to through a shader that writes to the array gl_FragData. + * If MRT is not enabled, then the index set with {@link FrameBuffer#setTargetIndex(int) } + * is rendered to by the shader. + * + * @param format the format of the color buffer + * @see #addColorTexture(com.jme3.texture.Texture2D) + */ + public void addColorBuffer(Image.Format format){ + if (id != -1) + throw new UnsupportedOperationException("FrameBuffer already initialized."); + + if (format.isDepthFormat()) + throw new IllegalArgumentException("Color buffer format must be color/luminance."); + + RenderBuffer colorBuf = new RenderBuffer(); + colorBuf.slot = colorBufs.size(); + colorBuf.format = format; + + colorBufs.add(colorBuf); + } + /** * Add a color texture to use for this framebuffer. * If MRT is enabled, then each subsequently added texture can be @@ -371,6 +395,7 @@ public class FrameBuffer extends NativeObject { * is rendered to by the shader. * * @param tex The texture to add. + * @see #addColorBuffer(com.jme3.texture.Image.Format) */ public void addColorTexture(Texture2D tex) { if (id != -1) From f642e5651713b18fe06f4d611c8741652b93f19d Mon Sep 17 00:00:00 2001 From: Nehon Date: Sun, 18 Sep 2016 15:24:49 +0200 Subject: [PATCH 10/10] Clean up in the PBR j3md file to remove warnings --- .../Common/MatDefs/Light/PBRLighting.j3md | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md index 586e8f5e7..864ff9877 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md @@ -154,7 +154,6 @@ MaterialDef PBR Lighting { } Defines { - COLOR_MAP : ColorMap DISCARD_ALPHA : AlphaDiscardThreshold NUM_BONES : NumberOfBones INSTANCING : UseInstancing @@ -187,7 +186,7 @@ MaterialDef PBR Lighting { FILTER_MODE : FilterMode PCFEDGE : PCFEdge DISCARD_ALPHA : AlphaDiscardThreshold - COLOR_MAP : ColorMap + SHADOWMAP_SIZE : ShadowMapSize SHADOWMAP_SIZE : ShadowMapSize FADE : FadeInfo PSSM : Splits @@ -219,7 +218,6 @@ MaterialDef PBR Lighting { FILTER_MODE : FilterMode PCFEDGE : PCFEdge DISCARD_ALPHA : AlphaDiscardThreshold - COLOR_MAP : ColorMap SHADOWMAP_SIZE : ShadowMapSize FADE : FadeInfo PSSM : Splits @@ -249,29 +247,6 @@ MaterialDef PBR Lighting { } Defines { - DIFFUSEMAP_ALPHA : DiffuseMap - NUM_BONES : NumberOfBones - INSTANCING : UseInstancing - } - - } - - - Technique PreNormalPassDerivative { - - VertexShader GLSL100 : Common/MatDefs/MSSAO/normal.vert - FragmentShader GLSL100 : Common/MatDefs/MSSAO/normal.frag - - WorldParameters { - WorldViewProjectionMatrix - WorldViewMatrix - NormalMatrix - ViewProjectionMatrix - ViewMatrix - } - - Defines { - DIFFUSEMAP_ALPHA : DiffuseMap NUM_BONES : NumberOfBones INSTANCING : UseInstancing } @@ -292,12 +267,6 @@ MaterialDef PBR Lighting { Defines { VERTEX_COLOR : UseVertexColor - MATERIAL_COLORS : UseMaterialColors - V_TANGENT : VTangent - MINNAERT : Minnaert - WARDISO : WardIso - - DIFFUSEMAP : DiffuseMap NORMALMAP : NormalMap SPECULARMAP : SpecularMap PARALLAXMAP : ParallaxMap