diff --git a/jme3-core/src/main/java/com/jme3/post/Filter.java b/jme3-core/src/main/java/com/jme3/post/Filter.java index 658a71877f..028bd60310 100644 --- a/jme3-core/src/main/java/com/jme3/post/Filter.java +++ b/jme3-core/src/main/java/com/jme3/post/Filter.java @@ -43,6 +43,7 @@ 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 void init(Renderer renderer, int width, int height, Format textureFormat, 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)); } diff --git a/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java b/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java index db57d96f26..fa3af964f0 100644 --- a/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java +++ b/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java @@ -41,6 +41,7 @@ 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 @@ private void initFilter(Filter filter, ViewPort vp) { 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 void reshape(ViewPort vp, int w, int h) { 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()) { diff --git a/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java b/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java index 89bc821ab7..eed55e3dc0 100644 --- a/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java +++ b/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java @@ -58,6 +58,7 @@ 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 @@ private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize 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; 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 0d1010b28c..449f16d770 100644 --- a/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java +++ b/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java @@ -231,6 +231,21 @@ public static FrameBufferBufferTarget newTarget(Format format){ 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 void addColorTarget(FrameBufferTextureTarget colorBuf){ 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."); diff --git a/jme3-effects/src/main/java/com/jme3/water/SimpleWaterProcessor.java b/jme3-effects/src/main/java/com/jme3/water/SimpleWaterProcessor.java index 19d3924470..92bcb9bd12 100644 --- a/jme3-effects/src/main/java/com/jme3/water/SimpleWaterProcessor.java +++ b/jme3-effects/src/main/java/com/jme3/water/SimpleWaterProcessor.java @@ -42,6 +42,7 @@ 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 @@ protected void createPreViews() { // 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 @@ protected void createPreViews() { // 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()); diff --git a/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyToMesh.java b/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyToMesh.java index 5d20d8c81a..8155654249 100644 --- a/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyToMesh.java +++ b/jme3-examples/src/main/java/jme3test/niftygui/TestNiftyToMesh.java @@ -44,6 +44,7 @@ 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 void simpleInitApp() { 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); diff --git a/jme3-examples/src/main/java/jme3test/post/TestFBOPassthrough.java b/jme3-examples/src/main/java/jme3test/post/TestFBOPassthrough.java index 3f8bbd0667..72a4c875f5 100644 --- a/jme3-examples/src/main/java/jme3test/post/TestFBOPassthrough.java +++ b/jme3-examples/src/main/java/jme3test/post/TestFBOPassthrough.java @@ -42,6 +42,7 @@ 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 void simpleInitApp() { 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); diff --git a/jme3-examples/src/main/java/jme3test/post/TestPostFiltersCompositing.java b/jme3-examples/src/main/java/jme3test/post/TestPostFiltersCompositing.java index b26b8fd66a..eef79e3bbc 100644 --- a/jme3-examples/src/main/java/jme3test/post/TestPostFiltersCompositing.java +++ b/jme3-examples/src/main/java/jme3test/post/TestPostFiltersCompositing.java @@ -43,6 +43,8 @@ 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 void simpleInitApp() { //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 diff --git a/jme3-examples/src/main/java/jme3test/post/TestRenderToCubemap.java b/jme3-examples/src/main/java/jme3test/post/TestRenderToCubemap.java index 84f24ad9d1..da00ccecd5 100644 --- a/jme3-examples/src/main/java/jme3test/post/TestRenderToCubemap.java +++ b/jme3-examples/src/main/java/jme3test/post/TestRenderToCubemap.java @@ -47,6 +47,7 @@ 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 Texture setupOffscreenView(){ 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); diff --git a/jme3-examples/src/main/java/jme3test/post/TestRenderToMemory.java b/jme3-examples/src/main/java/jme3test/post/TestRenderToMemory.java index 0d992667e6..1cfa50b9a2 100644 --- a/jme3-examples/src/main/java/jme3test/post/TestRenderToMemory.java +++ b/jme3-examples/src/main/java/jme3test/post/TestRenderToMemory.java @@ -49,6 +49,7 @@ 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 void setupOffscreenView(){ //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); diff --git a/jme3-examples/src/main/java/jme3test/post/TestRenderToTexture.java b/jme3-examples/src/main/java/jme3test/post/TestRenderToTexture.java index 037c959d36..88de57274d 100644 --- a/jme3-examples/src/main/java/jme3test/post/TestRenderToTexture.java +++ b/jme3-examples/src/main/java/jme3test/post/TestRenderToTexture.java @@ -49,6 +49,7 @@ 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 Texture setupOffscreenView(){ 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); diff --git a/jme3-examples/src/main/java/jme3test/renderer/TestDepthStencil.java b/jme3-examples/src/main/java/jme3test/renderer/TestDepthStencil.java index 13d95e37d1..0f333ac661 100644 --- a/jme3-examples/src/main/java/jme3test/renderer/TestDepthStencil.java +++ b/jme3-examples/src/main/java/jme3test/renderer/TestDepthStencil.java @@ -48,6 +48,7 @@ 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 void simpleInitApp() { 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); diff --git a/jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowFilterVR.java b/jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowFilterVR.java index 66e9cc707b..3144a417e0 100644 --- a/jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowFilterVR.java +++ b/jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowFilterVR.java @@ -43,8 +43,6 @@ 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; diff --git a/jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowRendererVR.java b/jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowRendererVR.java index f88f1cc579..783a0a1d74 100644 --- a/jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowRendererVR.java +++ b/jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowRendererVR.java @@ -59,6 +59,7 @@ 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 @@ private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize 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;