Skip to content

Commit ef6d02e

Browse files
committed
using deprecated FrameBuffer methods in jme3-core and jme3-desktop jMonkeyEngine#1657
Updating all references to setDepthTexture and setColorTexture from old system to the new system.
1 parent f600f23 commit ef6d02e

File tree

13 files changed

+113
-43
lines changed

13 files changed

+113
-43
lines changed

jme3-core/src/main/java/com/jme3/post/Filter.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import com.jme3.texture.Image.Format;
4444
import com.jme3.texture.Texture;
4545
import com.jme3.texture.Texture2D;
46+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
47+
4648
import java.io.IOException;
4749
import java.util.Collection;
4850
import java.util.Iterator;
@@ -110,22 +112,22 @@ public void init(Renderer renderer, int width, int height, Format textureFormat,
110112
if (numSamples > 1 && caps.contains(Caps.FrameBufferMultisample) && caps.contains(Caps.OpenGL31)) {
111113
renderFrameBuffer = new FrameBuffer(width, height, numSamples);
112114
renderedTexture = new Texture2D(width, height, numSamples, textureFormat);
113-
renderFrameBuffer.setDepthBuffer(depthBufferFormat);
115+
renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthBufferFormat));
114116
if (renderDepth) {
115117
depthTexture = new Texture2D(width, height, numSamples, depthBufferFormat);
116-
renderFrameBuffer.setDepthTexture(depthTexture);
118+
renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthTexture));
117119
}
118120
} else {
119121
renderFrameBuffer = new FrameBuffer(width, height, 1);
120122
renderedTexture = new Texture2D(width, height, textureFormat);
121-
renderFrameBuffer.setDepthBuffer(depthBufferFormat);
123+
renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthBufferFormat));
122124
if (renderDepth) {
123125
depthTexture = new Texture2D(width, height, depthBufferFormat);
124-
renderFrameBuffer.setDepthTexture(depthTexture);
126+
renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthTexture));
125127
}
126128
}
127129

128-
renderFrameBuffer.setColorTexture(renderedTexture);
130+
renderFrameBuffer.addColorTarget(FrameBufferTarget.newTarget(renderedTexture));
129131

130132

131133
}

jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import com.jme3.texture.Image.Format;
4242
import com.jme3.texture.Texture;
4343
import com.jme3.texture.Texture2D;
44+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
45+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
4446
import com.jme3.ui.Picture;
4547
import com.jme3.util.SafeArrayList;
4648
import java.io.IOException;
@@ -182,7 +184,8 @@ private void initFilter(Filter filter, ViewPort vp) {
182184
if (filter.isRequiresDepthTexture()) {
183185
if (!computeDepth && renderFrameBuffer != null) {
184186
depthTexture = new Texture2D(width, height, depthFormat);
185-
renderFrameBuffer.setDepthTexture(depthTexture);
187+
188+
renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthTexture));
186189
}
187190
computeDepth = true;
188191
filter.init(assetManager, renderManager, vp, width, height);
@@ -488,21 +491,21 @@ public void reshape(ViewPort vp, int w, int h) {
488491
if (caps.contains(Caps.OpenGL32)) {
489492
Texture2D msColor = new Texture2D(width, height, numSamples, fbFormat);
490493
Texture2D msDepth = new Texture2D(width, height, numSamples, depthFormat);
491-
renderFrameBufferMS.setDepthTexture(msDepth);
492-
renderFrameBufferMS.setColorTexture(msColor);
494+
renderFrameBufferMS.setDepthTarget(FrameBufferTarget.newTarget(msDepth));
495+
renderFrameBufferMS.addColorTarget(FrameBufferTarget.newTarget(msColor));
493496
filterTexture = msColor;
494497
depthTexture = msDepth;
495498
} else {
496-
renderFrameBufferMS.setDepthBuffer(depthFormat);
497-
renderFrameBufferMS.setColorBuffer(fbFormat);
499+
renderFrameBufferMS.setDepthTarget(FrameBufferTarget.newTarget(depthFormat));
500+
renderFrameBufferMS.addColorTarget(FrameBufferTarget.newTarget(fbFormat));
498501
}
499502
}
500503

501504
if (numSamples <= 1 || !caps.contains(Caps.OpenGL32)) {
502505
renderFrameBuffer = new FrameBuffer(width, height, 1);
503-
renderFrameBuffer.setDepthBuffer(depthFormat);
506+
renderFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthFormat));
504507
filterTexture = new Texture2D(width, height, fbFormat);
505-
renderFrameBuffer.setColorTexture(filterTexture);
508+
renderFrameBuffer.addColorTarget(FrameBufferTarget.newTarget(filterTexture));
506509
}
507510

508511
for (Filter filter : filters.getArray()) {

jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import com.jme3.texture.Texture.MinFilter;
5959
import com.jme3.texture.Texture.ShadowCompareMode;
6060
import com.jme3.texture.Texture2D;
61+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
6162
import com.jme3.ui.Picture;
6263
import com.jme3.util.clone.Cloner;
6364
import com.jme3.util.clone.JmeCloneable;
@@ -170,10 +171,10 @@ private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize
170171
shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
171172
shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
172173

173-
shadowFB[i].setDepthTexture(shadowMaps[i]);
174+
shadowFB[i].setDepthTarget(FrameBufferTarget.newTarget(shadowMaps[i]));
174175

175176
//DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
176-
shadowFB[i].setColorTexture(dummyTex);
177+
shadowFB[i].addColorTarget(FrameBufferTarget.newTarget(dummyTex));
177178
shadowMapStringCache[i] = "ShadowMap" + i;
178179
lightViewStringCache[i] = "LightViewProjectionMatrix" + i;
179180

jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java

+35
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,24 @@ public static FrameBufferBufferTarget newTarget(Format format){
231231
t.setFormat(format);
232232
return t;
233233
}
234+
235+
/**
236+
* Creates a frame buffer texture and sets the face position
237+
* by using the face parameter.
238+
* It uses {@link TextureCubeMap} ordinal number for the
239+
* face position.
240+
*
241+
* @param tx texture to add to the frame buffer
242+
* @param face face to add to the color buffer to
243+
* @return FrameBufferTexture Target
244+
*/
245+
public static FrameBufferTextureTarget newTarget(Texture tx, TextureCubeMap.Face face){
246+
FrameBufferTextureTarget t=new FrameBufferTextureTarget();
247+
t.face = face.ordinal();
248+
t.setTexture(tx);
249+
return t;
250+
}
251+
234252
}
235253

236254
/**
@@ -250,6 +268,23 @@ public void addColorTarget(FrameBufferTextureTarget colorBuf){
250268
colorBufs.add(colorBuf);
251269
}
252270

271+
272+
/**
273+
* Adds a texture to one of the color Buffers Array.
274+
* It uses {@link TextureCubeMap} ordinal number for the
275+
* position in the color buffer ArrayList.
276+
*
277+
* @param colorBuf texture to add to the color Buffer
278+
* @param face position to add to the color buffer
279+
*/
280+
public void addColorTarget(FrameBufferTextureTarget colorBuf, TextureCubeMap.Face face){
281+
// checkSetTexture(colorBuf.getTexture(), false); // TODO: this won't work for levels.
282+
colorBuf.slot=colorBufs.size();
283+
colorBuf.face = face.ordinal();
284+
colorBufs.add(colorBuf);
285+
}
286+
287+
253288
public void setDepthTarget(FrameBufferBufferTarget depthBuf){
254289
if (!depthBuf.getFormat().isDepthFormat())
255290
throw new IllegalArgumentException("Depth buffer format must be depth.");

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
import com.jme3.scene.Spatial;
4343
import com.jme3.scene.shape.Quad;
4444
import com.jme3.texture.*;
45+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
46+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
47+
import com.jme3.texture.FrameBuffer.FrameBufferTextureTarget;
4548
import com.jme3.texture.Image.Format;
4649
import com.jme3.texture.Texture.WrapMode;
4750
import com.jme3.ui.Picture;
@@ -282,8 +285,8 @@ protected void createPreViews() {
282285
// create offscreen framebuffer
283286
reflectionBuffer = new FrameBuffer(renderWidth, renderHeight, 1);
284287
//setup framebuffer to use texture
285-
reflectionBuffer.setDepthBuffer(Format.Depth);
286-
reflectionBuffer.setColorTexture(reflectionTexture);
288+
reflectionBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
289+
reflectionBuffer.addColorTarget(FrameBufferTarget.newTarget(reflectionTexture));
287290

288291
//set viewport to render to offscreen framebuffer
289292
reflectionView.setOutputFrameBuffer(reflectionBuffer);
@@ -298,9 +301,8 @@ protected void createPreViews() {
298301
// create offscreen framebuffer
299302
refractionBuffer = new FrameBuffer(renderWidth, renderHeight, 1);
300303
//setup framebuffer to use texture
301-
refractionBuffer.setDepthBuffer(Format.Depth);
302-
refractionBuffer.setColorTexture(refractionTexture);
303-
refractionBuffer.setDepthTexture(depthTexture);
304+
refractionBuffer.addColorTarget(FrameBufferTarget.newTarget(refractionTexture));
305+
refractionBuffer.setDepthTarget(FrameBufferTarget.newTarget(depthTexture));
304306
//set viewport to render to offscreen framebuffer
305307
refractionView.setOutputFrameBuffer(refractionBuffer);
306308
refractionView.addProcessor(new RefractionProcessor());

jme3-examples/src/main/java/jme3test/niftygui/TestNiftyToMesh.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
import com.jme3.texture.Texture.MagFilter;
4545
import com.jme3.texture.Texture.MinFilter;
4646
import com.jme3.texture.Texture2D;
47+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
48+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
49+
4750
import de.lessvoid.nifty.Nifty;
4851

4952
public class TestNiftyToMesh extends SimpleApplication{
@@ -67,13 +70,13 @@ public void simpleInitApp() {
6770

6871
Texture2D depthTex = new Texture2D(1024, 768, Format.Depth);
6972
FrameBuffer fb = new FrameBuffer(1024, 768, 1);
70-
fb.setDepthTexture(depthTex);
73+
fb.setDepthTarget(FrameBufferTarget.newTarget(depthTex));
7174

7275
Texture2D tex = new Texture2D(1024, 768, Format.RGBA8);
7376
tex.setMinFilter(MinFilter.Trilinear);
7477
tex.setMagFilter(MagFilter.Bilinear);
7578

76-
fb.setColorTexture(tex);
79+
fb.addColorTarget(FrameBufferTarget.newTarget(tex));
7780
niftyView.setClearFlags(true, true, true);
7881
niftyView.setOutputFrameBuffer(fb);
7982

jme3-examples/src/main/java/jme3test/post/TestFBOPassthrough.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@
4040
import com.jme3.scene.Node;
4141
import com.jme3.scene.shape.Sphere;
4242
import com.jme3.texture.FrameBuffer;
43+
import com.jme3.texture.Texture;
4344
import com.jme3.texture.Image.Format;
4445
import com.jme3.texture.Texture2D;
46+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
47+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
48+
import com.jme3.texture.FrameBuffer.FrameBufferTextureTarget;
4549
import com.jme3.ui.Picture;
4650

4751
/**
@@ -70,8 +74,8 @@ public void simpleInitApp() {
7074
fb = new FrameBuffer(w, h, 1);
7175

7276
Texture2D fbTex = new Texture2D(w, h, Format.RGBA8);
73-
fb.setDepthBuffer(Format.Depth);
74-
fb.setColorTexture(fbTex);
77+
fb.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
78+
fb.addColorTarget(FrameBufferTarget.newTarget(fbTex));
7579

7680
// setup framebuffer's scene
7781
Sphere sphMesh = new Sphere(20, 20, 1);

jme3-examples/src/main/java/jme3test/post/TestPostFiltersCompositing.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
import com.jme3.texture.FrameBuffer;
4444
import com.jme3.texture.Image;
4545
import com.jme3.texture.Texture2D;
46+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
47+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
48+
import com.jme3.texture.FrameBuffer.FrameBufferTextureTarget;
49+
import com.jme3.texture.Image.Format;
4650
import com.jme3.util.SkyFactory;
4751

4852
/**
@@ -78,8 +82,9 @@ public void simpleInitApp() {
7882
//creating a frame buffer for the mainviewport
7983
FrameBuffer mainVPFrameBuffer = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
8084
Texture2D mainVPTexture = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
81-
mainVPFrameBuffer.addColorTexture(mainVPTexture);
82-
mainVPFrameBuffer.setDepthBuffer(Image.Format.Depth);
85+
mainVPFrameBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
86+
mainVPFrameBuffer.addColorTarget(FrameBufferTarget.newTarget(mainVPTexture));
87+
8388
viewPort.setOutputFrameBuffer(mainVPFrameBuffer);
8489

8590
//creating the post processor for the gui viewport

jme3-examples/src/main/java/jme3test/post/TestRenderToCubemap.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
import com.jme3.texture.Image.Format;
4848
import com.jme3.texture.Texture;
4949
import com.jme3.texture.TextureCubeMap;
50+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
51+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
52+
import com.jme3.texture.FrameBuffer.FrameBufferTextureTarget;
5053
import com.jme3.util.SkyFactory;
5154
import com.jme3.util.SkyFactory.EnvMapType;
5255

@@ -86,15 +89,15 @@ public Texture setupOffscreenView(){
8689
offTex.setMagFilter(Texture.MagFilter.Bilinear);
8790

8891
//setup framebuffer to use texture
89-
offBuffer.setDepthBuffer(Format.Depth);
92+
offBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
9093
offBuffer.setMultiTarget(true);
91-
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeX);
92-
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveX);
93-
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeY);
94-
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveY);
95-
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeZ);
96-
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveZ);
97-
94+
offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.NegativeX));
95+
offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.PositiveX));
96+
offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.NegativeY));
97+
offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.PositiveY));
98+
offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.NegativeZ));
99+
offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex, TextureCubeMap.Face.PositiveZ));
100+
98101
//set viewport to render to offscreen framebuffer
99102
offView.setOutputFrameBuffer(offBuffer);
100103

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
import com.jme3.system.AppSettings;
5050
import com.jme3.system.JmeContext.Type;
5151
import com.jme3.texture.FrameBuffer;
52+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
53+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
54+
import com.jme3.texture.FrameBuffer.FrameBufferTextureTarget;
5255
import com.jme3.texture.Image.Format;
5356
import com.jme3.util.BufferUtils;
5457
import com.jme3.util.Screenshots;
@@ -192,9 +195,8 @@ public void setupOffscreenView(){
192195

193196
//setup framebuffer to use renderbuffer
194197
// this is faster for gpu -> cpu copies
195-
offBuffer.setDepthBuffer(Format.Depth);
196-
offBuffer.setColorBuffer(Format.RGBA8);
197-
// offBuffer.setColorTexture(offTex);
198+
offBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
199+
offBuffer.addColorTarget(FrameBufferTarget.newTarget(Format.RGBA8));
198200

199201
//set viewport to render to offscreen framebuffer
200202
offView.setOutputFrameBuffer(offBuffer);

jme3-examples/src/main/java/jme3test/post/TestRenderToTexture.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
import com.jme3.texture.Image.Format;
5050
import com.jme3.texture.Texture;
5151
import com.jme3.texture.Texture2D;
52+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
53+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
54+
import com.jme3.texture.FrameBuffer.FrameBufferTextureTarget;
5255

5356
/**
5457
* This test renders a scene to a texture, then displays the texture on a cube.
@@ -86,8 +89,9 @@ public Texture setupOffscreenView(){
8689
offTex.setMagFilter(Texture.MagFilter.Bilinear);
8790

8891
//setup framebuffer to use texture
89-
offBuffer.setDepthBuffer(Format.Depth);
90-
offBuffer.setColorTexture(offTex);
92+
offBuffer.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth));
93+
offBuffer.addColorTarget(FrameBufferTarget.newTarget(offTex));
94+
9195

9296
//set viewport to render to offscreen framebuffer
9397
offView.setOutputFrameBuffer(offBuffer);

jme3-examples/src/main/java/jme3test/renderer/TestDepthStencil.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
import com.jme3.texture.FrameBuffer;
4949
import com.jme3.texture.Image.Format;
5050
import com.jme3.texture.Texture2D;
51+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
52+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
53+
import com.jme3.texture.FrameBuffer.FrameBufferTextureTarget;
5154
import com.jme3.ui.Picture;
5255

5356
public class TestDepthStencil extends SimpleApplication {
@@ -71,8 +74,8 @@ public void simpleInitApp() {
7174
fb = new FrameBuffer(w, h, 1);
7275

7376
Texture2D fbTex = new Texture2D(w, h, Format.RGB8);
74-
fb.setDepthBuffer(Format.Depth24Stencil8);
75-
fb.setColorTexture(fbTex);
77+
fb.setDepthTarget(FrameBufferTarget.newTarget(Format.Depth24Stencil8));
78+
fb.addColorTarget(FrameBufferTarget.newTarget(fbTex));
7679

7780
// setup framebuffer's scene
7881
Sphere sphMesh = new Sphere(20, 20, 1);

jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowRendererVR.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
import com.jme3.texture.Texture.MinFilter;
6060
import com.jme3.texture.Texture.ShadowCompareMode;
6161
import com.jme3.texture.Texture2D;
62+
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
63+
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
64+
import com.jme3.texture.FrameBuffer.FrameBufferTextureTarget;
6265
import com.jme3.ui.Picture;
6366

6467
import java.io.IOException;
@@ -169,10 +172,10 @@ private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize
169172
shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
170173
shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
171174

172-
shadowFB[i].setDepthTexture(shadowMaps[i]);
173-
175+
shadowFB[i].setDepthTarget(FrameBufferTarget.newTarget(shadowMaps[i]));
176+
174177
//DO NOT COMMENT THIS (It prevents the OSX incomplete read buffer crash.)
175-
shadowFB[i].setColorTexture(dummyTex);
178+
shadowFB[i].addColorTarget(FrameBufferTarget.newTarget(dummyTex));
176179
shadowMapStringCache[i] = "ShadowMap" + i;
177180
lightViewStringCache[i] = "LightViewProjectionMatrix" + i;
178181

0 commit comments

Comments
 (0)