Просмотр исходного кода

using deprecated FrameBuffer methods in jme3-core and jme3-desktop #1657 (#1696)

* This is a very simple addition. It allows a person to set 3 variables in AppSettings. ‘CenterWindow’, ‘WindowXPosition’ and ‘WindowYPosition’ variables. This way these variable will be saved in the profile when the profile is saved, and be reloaded. I added ‘CenterWindow’ to be added with a ‘true’ value for the default value so it will run just like it did before.

But if you set ‘CenterWindow’ to ‘false’ then inside LwjglWindow.java (lwjgl3 code) it will look at these new values, it will determine to center the window or use the position values to place the window back at the location the user last moved it to.

Of course, these values are only updated if the “program” updates this value. So if you want to save screen position, you can save them on closing to and on restart put the window back into the same location.

* formatting and comments changes.

* jme3test.app.TestApplication hangs with LWJGL3 #1193
LWJGL3-JME library would block the current thread when executing LWJGL3.    Instead of calling run() that is blocking,  made it work like LWJGL2-JME library when they start it as a thread so run gets called. I commented out the run() function and replaced it with Thread.start().

* removing unwanted changes, since you can't do multiple pull requests at once.

* formatting issues.

* changed parameter naming to be more consistency with other items.

* jme3test.app.TestApplication hangs with LWJGL3 #1193

LWJGL3-JME projects was doing a call that is blocking the current thread.  I changed it to match how LWJGL2-JME project launches the Context Window.

* jme3test.app.TestApplication hangs with LWJGL3 #1193 (#3)

LWJGL3-JME projects was doing a call that is blocking the current thread.  I changed it to match how LWJGL2-JME project launches the Context Window.

* removing unwanted changes.

* AppSettings:  enhance the new javadoc

* AppSettings:  capitalize Window{X/Y}Position consistent w/other settings

* LwjglWindow:  convert tabs to spaces

* AppSettings:  re-arrange @see tags in javadoc

* using deprecated FrameBuffer methods in jme3-core and jme3-desktop #1657

Updating all references to setDepthTexture  and setColorTexture from old system to the new system.

* Removing unused imports.

* missed an unused import.

* FrameBuffer:  improve formatting of the added sourcecode

* tweak the whitespace

Co-authored-by: Stephen Gold <[email protected]>
bob0bob 3 лет назад
Родитель
Сommit
53d4704eae

+ 6 - 5
jme3-core/src/main/java/com/jme3/post/Filter.java

@@ -43,6 +43,7 @@ import com.jme3.texture.FrameBuffer;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Iterator;
@@ -110,22 +111,22 @@ public abstract class Filter implements Savable {
             if (numSamples > 1 && caps.contains(Caps.FrameBufferMultisample) && caps.contains(Caps.OpenGL31)) {
                 renderFrameBuffer = new FrameBuffer(width, height, numSamples);                
                 renderedTexture = new Texture2D(width, height, numSamples, textureFormat);
-                renderFrameBuffer.setDepthBuffer(depthBufferFormat);
+                renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthBufferFormat));
                 if (renderDepth) {
                     depthTexture = new Texture2D(width, height, numSamples, depthBufferFormat);
-                    renderFrameBuffer.setDepthTexture(depthTexture);
+                    renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthTexture));
                 }
             } else {
                 renderFrameBuffer = new FrameBuffer(width, height, 1);
                 renderedTexture = new Texture2D(width, height, textureFormat);
-                renderFrameBuffer.setDepthBuffer(depthBufferFormat);
+                renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthBufferFormat));
                 if (renderDepth) {
                     depthTexture = new Texture2D(width, height, depthBufferFormat);
-                    renderFrameBuffer.setDepthTexture(depthTexture);
+                    renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthTexture));
                 }
             }
 
-            renderFrameBuffer.setColorTexture(renderedTexture);
+            renderFrameBuffer.addColorTarget(FrameBufferTarget.newTarget(renderedTexture));
 
 
         }

+ 8 - 7
jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java

@@ -41,6 +41,7 @@ import com.jme3.texture.FrameBuffer;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.ui.Picture;
 import com.jme3.util.SafeArrayList;
 import java.io.IOException;
@@ -182,7 +183,7 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
         if (filter.isRequiresDepthTexture()) {
             if (!computeDepth && renderFrameBuffer != null) {
                 depthTexture = new Texture2D(width, height, depthFormat);
-                renderFrameBuffer.setDepthTexture(depthTexture);
+                renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthTexture));
             }
             computeDepth = true;
             filter.init(assetManager, renderManager, vp, width, height);
@@ -488,21 +489,21 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
             if (caps.contains(Caps.OpenGL32)) {
                 Texture2D msColor = new Texture2D(width, height, numSamples, fbFormat);
                 Texture2D msDepth = new Texture2D(width, height, numSamples, depthFormat);
-                renderFrameBufferMS.setDepthTexture(msDepth);
-                renderFrameBufferMS.setColorTexture(msColor);
+                renderFrameBufferMS.setDepthTarget(FrameBufferTarget.newTarget(msDepth));
+                renderFrameBufferMS.addColorTarget(FrameBufferTarget.newTarget(msColor));
                 filterTexture = msColor;
                 depthTexture = msDepth;
             } else {
-                renderFrameBufferMS.setDepthBuffer(depthFormat);
-                renderFrameBufferMS.setColorBuffer(fbFormat);
+                renderFrameBufferMS.setDepthTarget(FrameBufferTarget.newTarget(depthFormat));
+                renderFrameBufferMS.addColorTarget(FrameBufferTarget.newTarget(fbFormat));
             }
         }
 
         if (numSamples <= 1 || !caps.contains(Caps.OpenGL32)) {
             renderFrameBuffer = new FrameBuffer(width, height, 1);
-            renderFrameBuffer.setDepthBuffer(depthFormat);
+            renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthFormat));
             filterTexture = new Texture2D(width, height, fbFormat);
-            renderFrameBuffer.setColorTexture(filterTexture);
+            renderFrameBuffer.addColorTarget(FrameBufferTarget.newTarget(filterTexture));
         }
 
         for (Filter filter : filters.getArray()) {

+ 3 - 2
jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java

@@ -58,6 +58,7 @@ import com.jme3.texture.Texture.MagFilter;
 import com.jme3.texture.Texture.MinFilter;
 import com.jme3.texture.Texture.ShadowCompareMode;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.ui.Picture;
 import com.jme3.util.clone.Cloner;
 import com.jme3.util.clone.JmeCloneable;
@@ -170,10 +171,10 @@ public abstract class AbstractShadowRenderer implements SceneProcessor, Savable,
             shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
             shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
 
-            shadowFB[i].setDepthTexture(shadowMaps[i]);
+            shadowFB[i].setDepthTarget(FrameBufferTarget.newTarget(shadowMaps[i]));
 
             //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
-            shadowFB[i].setColorTexture(dummyTex);
+            shadowFB[i].addColorTarget(FrameBufferTarget.newTarget(dummyTex));
             shadowMapStringCache[i] = "ShadowMap" + i; 
             lightViewStringCache[i] = "LightViewProjectionMatrix" + i;
 

+ 29 - 0
jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java

@@ -231,6 +231,21 @@ public class FrameBuffer extends NativeObject {
             t.setFormat(format);
             return t;
         }
+
+        /**
+         * Creates a frame buffer texture and sets the face position by using the face parameter. It uses
+         * {@link TextureCubeMap} ordinal number for the face position.
+         *
+         * @param tx texture to add to the frame buffer
+         * @param face face to add to the color buffer to
+         * @return FrameBufferTexture Target
+         */
+        public static FrameBufferTextureTarget newTarget(Texture tx, TextureCubeMap.Face face) {
+            FrameBufferTextureTarget t = new FrameBufferTextureTarget();
+            t.face = face.ordinal();
+            t.setTexture(tx);
+            return t;
+        }
     }
 
     /**
@@ -250,6 +265,20 @@ public class FrameBuffer extends NativeObject {
         colorBufs.add(colorBuf);
     }
 
+    /**
+     * Adds a texture to one of the color Buffers Array. It uses {@link TextureCubeMap} ordinal number for the
+     * position in the color buffer ArrayList.
+     *
+     * @param colorBuf texture to add to the color Buffer
+     * @param face position to add to the color buffer
+     */
+    public void addColorTarget(FrameBufferTextureTarget colorBuf, TextureCubeMap.Face face) {
+        // checkSetTexture(colorBuf.getTexture(), false);  // TODO: this won't work for levels.
+        colorBuf.slot = colorBufs.size();
+        colorBuf.face = face.ordinal();
+        colorBufs.add(colorBuf);
+    }
+
     public void setDepthTarget(FrameBufferBufferTarget depthBuf){
         if (!depthBuf.getFormat().isDepthFormat())
             throw new IllegalArgumentException("Depth buffer format must be depth.");

+ 5 - 5
jme3-effects/src/main/java/com/jme3/water/SimpleWaterProcessor.java

@@ -42,6 +42,7 @@ import com.jme3.scene.Geometry;
 import com.jme3.scene.Spatial;
 import com.jme3.scene.shape.Quad;
 import com.jme3.texture.*;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture.WrapMode;
 import com.jme3.ui.Picture;
@@ -282,8 +283,8 @@ public class SimpleWaterProcessor implements SceneProcessor {
         // create offscreen framebuffer
         reflectionBuffer = new FrameBuffer(renderWidth, renderHeight, 1);
         //setup framebuffer to use texture
-        reflectionBuffer.setDepthBuffer(Format.Depth);
-        reflectionBuffer.setColorTexture(reflectionTexture);
+        reflectionBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
+        reflectionBuffer.addColorTarget(FrameBufferTarget.newTarget(reflectionTexture));
 
         //set viewport to render to offscreen framebuffer
         reflectionView.setOutputFrameBuffer(reflectionBuffer);
@@ -298,9 +299,8 @@ public class SimpleWaterProcessor implements SceneProcessor {
         // create offscreen framebuffer
         refractionBuffer = new FrameBuffer(renderWidth, renderHeight, 1);
         //setup framebuffer to use texture
-        refractionBuffer.setDepthBuffer(Format.Depth);
-        refractionBuffer.setColorTexture(refractionTexture);
-        refractionBuffer.setDepthTexture(depthTexture);
+        refractionBuffer.addColorTarget(FrameBufferTarget.newTarget(refractionTexture));
+        refractionBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthTexture));
         //set viewport to render to offscreen framebuffer
         refractionView.setOutputFrameBuffer(refractionBuffer);
         refractionView.addProcessor(new RefractionProcessor());

+ 3 - 2
jme3-examples/src/main/java/jme3test/niftygui/TestNiftyToMesh.java

@@ -44,6 +44,7 @@ import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture.MagFilter;
 import com.jme3.texture.Texture.MinFilter;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import de.lessvoid.nifty.Nifty;
 
 public class TestNiftyToMesh extends SimpleApplication{
@@ -67,13 +68,13 @@ public class TestNiftyToMesh extends SimpleApplication{
 
         Texture2D depthTex = new Texture2D(1024, 768, Format.Depth);
         FrameBuffer fb = new FrameBuffer(1024, 768, 1);
-        fb.setDepthTexture(depthTex);
+        fb.setDepthTarget(FrameBufferTarget.newTarget(depthTex));
 
         Texture2D tex = new Texture2D(1024, 768, Format.RGBA8);
         tex.setMinFilter(MinFilter.Trilinear);
         tex.setMagFilter(MagFilter.Bilinear);
 
-        fb.setColorTexture(tex);
+        fb.addColorTarget(FrameBufferTarget.newTarget(tex));
         niftyView.setClearFlags(true, true, true);
         niftyView.setOutputFrameBuffer(fb);
 

+ 3 - 2
jme3-examples/src/main/java/jme3test/post/TestFBOPassthrough.java

@@ -42,6 +42,7 @@ import com.jme3.scene.shape.Sphere;
 import com.jme3.texture.FrameBuffer;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.ui.Picture;
 
 /**
@@ -70,8 +71,8 @@ public class TestFBOPassthrough extends SimpleApplication {
         fb = new FrameBuffer(w, h, 1);
 
         Texture2D fbTex = new Texture2D(w, h, Format.RGBA8);
-        fb.setDepthBuffer(Format.Depth);
-        fb.setColorTexture(fbTex);
+        fb.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
+        fb.addColorTarget(FrameBufferTarget.newTarget(fbTex));
 
         // setup framebuffer's scene
         Sphere sphMesh = new Sphere(20, 20, 1);

+ 5 - 2
jme3-examples/src/main/java/jme3test/post/TestPostFiltersCompositing.java

@@ -43,6 +43,8 @@ import com.jme3.scene.Spatial;
 import com.jme3.texture.FrameBuffer;
 import com.jme3.texture.Image;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
+import com.jme3.texture.Image.Format;
 import com.jme3.util.SkyFactory;
 
 /**
@@ -78,8 +80,9 @@ public class TestPostFiltersCompositing extends SimpleApplication {
         //creating a frame buffer for the mainviewport
         FrameBuffer mainVPFrameBuffer = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
         Texture2D mainVPTexture = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
-        mainVPFrameBuffer.addColorTexture(mainVPTexture);
-        mainVPFrameBuffer.setDepthBuffer(Image.Format.Depth);
+        mainVPFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
+        mainVPFrameBuffer.addColorTarget(FrameBufferTarget.newTarget(mainVPTexture));
+
         viewPort.setOutputFrameBuffer(mainVPFrameBuffer);
 
         //creating the post processor for the gui viewport

+ 9 - 8
jme3-examples/src/main/java/jme3test/post/TestRenderToCubemap.java

@@ -47,6 +47,7 @@ import com.jme3.texture.FrameBuffer;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture;
 import com.jme3.texture.TextureCubeMap;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.util.SkyFactory;
 import com.jme3.util.SkyFactory.EnvMapType;
 
@@ -86,15 +87,15 @@ public class TestRenderToCubemap  extends SimpleApplication {
         offTex.setMagFilter(Texture.MagFilter.Bilinear);
  
         //setup framebuffer to use texture
-        offBuffer.setDepthBuffer(Format.Depth);
+        offBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
         offBuffer.setMultiTarget(true);
-        offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeX);
-        offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveX);
-        offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeY);
-        offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveY);
-        offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeZ);
-        offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveZ);
-        
+        offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.NegativeX));
+        offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.PositiveX));
+        offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.NegativeY));
+        offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.PositiveY));
+        offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.NegativeZ));
+        offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.PositiveZ));
+
         //set viewport to render to offscreen framebuffer
         offView.setOutputFrameBuffer(offBuffer);
  

+ 3 - 3
jme3-examples/src/main/java/jme3test/post/TestRenderToMemory.java

@@ -49,6 +49,7 @@ import com.jme3.scene.shape.Box;
 import com.jme3.system.AppSettings;
 import com.jme3.system.JmeContext.Type;
 import com.jme3.texture.FrameBuffer;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.texture.Image.Format;
 import com.jme3.util.BufferUtils;
 import com.jme3.util.Screenshots;
@@ -192,9 +193,8 @@ public class TestRenderToMemory extends SimpleApplication implements SceneProces
 
         //setup framebuffer to use renderbuffer
         // this is faster for gpu -> cpu copies
-        offBuffer.setDepthBuffer(Format.Depth);
-        offBuffer.setColorBuffer(Format.RGBA8);
-//        offBuffer.setColorTexture(offTex);
+        offBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
+        offBuffer.addColorTarget(FrameBufferTarget.newTarget(Format.RGBA8));
         
         //set viewport to render to offscreen framebuffer
         offView.setOutputFrameBuffer(offBuffer);

+ 4 - 3
jme3-examples/src/main/java/jme3test/post/TestRenderToTexture.java

@@ -49,6 +49,7 @@ import com.jme3.texture.FrameBuffer;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 
 /**
  * This test renders a scene to a texture, then displays the texture on a cube.
@@ -86,9 +87,9 @@ public class TestRenderToTexture extends SimpleApplication implements ActionList
         offTex.setMagFilter(Texture.MagFilter.Bilinear);
 
         //setup framebuffer to use texture
-        offBuffer.setDepthBuffer(Format.Depth);
-        offBuffer.setColorTexture(offTex);
-        
+        offBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
+        offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex));
+
         //set viewport to render to offscreen framebuffer
         offView.setOutputFrameBuffer(offBuffer);
 

+ 3 - 2
jme3-examples/src/main/java/jme3test/renderer/TestDepthStencil.java

@@ -48,6 +48,7 @@ import com.jme3.scene.shape.Sphere;
 import com.jme3.texture.FrameBuffer;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.ui.Picture;
 
 public class TestDepthStencil extends SimpleApplication {
@@ -71,8 +72,8 @@ public class TestDepthStencil extends SimpleApplication {
         fb = new FrameBuffer(w, h, 1);
 
         Texture2D fbTex = new Texture2D(w, h, Format.RGB8);
-        fb.setDepthBuffer(Format.Depth24Stencil8);
-        fb.setColorTexture(fbTex);
+        fb.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth24Stencil8));
+        fb.addColorTarget(FrameBufferTarget.newTarget(fbTex));
 
         // setup framebuffer's scene
         Sphere sphMesh = new Sphere(20, 20, 1);

+ 0 - 2
jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowFilterVR.java

@@ -43,8 +43,6 @@ import com.jme3.post.Filter;
 import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.ViewPort;
 import com.jme3.renderer.queue.RenderQueue;
-import com.jme3.shadow.CompareMode;
-import com.jme3.shadow.EdgeFilteringMode;
 import com.jme3.texture.FrameBuffer;
 
 import java.io.IOException;

+ 3 - 2
jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowRendererVR.java

@@ -59,6 +59,7 @@ import com.jme3.texture.Texture.MagFilter;
 import com.jme3.texture.Texture.MinFilter;
 import com.jme3.texture.Texture.ShadowCompareMode;
 import com.jme3.texture.Texture2D;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.ui.Picture;
 
 import java.io.IOException;
@@ -169,10 +170,10 @@ public abstract class AbstractShadowRendererVR implements SceneProcessor, Savabl
             shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
             shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
 
-            shadowFB[i].setDepthTexture(shadowMaps[i]);
+            shadowFB[i].setDepthTarget(FrameBufferTarget.newTarget(shadowMaps[i]));
 
             //DO NOT COMMENT THIS (It prevents the OSX incomplete read buffer crash.)
-            shadowFB[i].setColorTexture(dummyTex);
+            shadowFB[i].addColorTarget(FrameBufferTarget.newTarget(dummyTex));
             shadowMapStringCache[i] = "ShadowMap" + i; 
             lightViewStringCache[i] = "LightViewProjectionMatrix" + i;