Ver Fonte

Merge branch 'master' of https://github.com/jMonkeyEngine/jmonkeyengine

# By Nehon (2) and others
# Via GitHub (7) and Nehon (1)
* 'master' of https://github.com/jMonkeyEngine/jmonkeyengine:
  Clean up in the PBR j3md file to remove warnings
  Fix for #502
  Minor fix in javadoc for Camera.java class
  minor cleanup in GLRenderer
  fixed missing Cloneable in the Triangle.
  Fix for MTR Framebuffers
  fixed a typo
  Using LegacyApplication in the iOS Harness just like it has been done for Android in 3c56afe
  Fixed wrong alpha handling in the pbr shader
  Added a cursor cache to avoid cursor disappearing and app crashing when too many cursors are created
Rémy Bouquet há 9 anos atrás
pai
commit
c50b4dbeaa

+ 1 - 1
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;
 

+ 1 - 1
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);

+ 18 - 23
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)) {
@@ -1675,24 +1673,21 @@ 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
-                    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();
                     }
                 }
             }

+ 25 - 0
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 <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 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)

+ 1 - 1
jme3-core/src/main/java/com/jme3/util/clone/JmeCloneable.java

@@ -49,7 +49,7 @@ package com.jme3.util.clone;
  *
  *  <p>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.</p>
  *
  *  <p>This two part process is necessary to facilitate circular references.

+ 4 - 2
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){

+ 1 - 32
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

+ 6 - 2
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;

+ 2 - 2
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);

+ 30 - 9
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<JmeCursor, Cursor> cursorMap = new HashMap<JmeCursor, Cursor>();
+
     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) {