@@ -90,14 +90,20 @@ public class FrameBuffer extends NativeObject {
9090 * buffer that will be rendered to. <code>RenderBuffer</code>s
9191 * are attached to an attachment slot on a <code>FrameBuffer</code>.
9292 */
93- public class RenderBuffer {
93+ public static class RenderBuffer {
9494
9595 Texture tex ;
9696 Image .Format format ;
9797 int id = -1 ;
9898 int slot = SLOT_UNDEF ;
9999 int face = -1 ;
100100 int layer = -1 ;
101+ int level = 0 ;
102+
103+
104+ public int getLevel () {
105+ return this .level ;
106+ }
101107
102108 /**
103109 * @return The image format of the render buffer.
@@ -167,6 +173,108 @@ public int getLayer() {
167173 }
168174 }
169175
176+
177+ public static class FrameBufferTextureTarget extends RenderBuffer {
178+ private FrameBufferTextureTarget (){}
179+ void setTexture (Texture tx ){
180+ this .tex =tx ;
181+ this .format =tx .getImage ().getFormat ();
182+ }
183+
184+ void setFormat (Format f ){
185+ this .format =f ;
186+ }
187+
188+ public FrameBufferTextureTarget layer (int i ){
189+ this .layer =i ;
190+ return this ;
191+ }
192+
193+ public FrameBufferTextureTarget level (int i ){
194+ this .level =i ;
195+ return this ;
196+ }
197+
198+ public FrameBufferTextureTarget face (TextureCubeMap .Face f ){
199+ return face (f .ordinal ());
200+ }
201+
202+ public FrameBufferTextureTarget face (int f ){
203+ this .face =f ;
204+ return this ;
205+ }
206+
207+ }
208+
209+ public static class FrameBufferBufferTarget extends RenderBuffer {
210+ private FrameBufferBufferTarget (){}
211+ void setFormat (Format f ){
212+ this .format =f ;
213+ }
214+ }
215+
216+ public static class FrameBufferTarget {
217+ public static FrameBufferTextureTarget newTarget (Texture tx ){
218+ FrameBufferTextureTarget t =new FrameBufferTextureTarget ();
219+ t .setTexture (tx );
220+ return t ;
221+ }
222+
223+ public static FrameBufferBufferTarget newTarget (Format format ){
224+ FrameBufferBufferTarget t =new FrameBufferBufferTarget ();
225+ t .setFormat (format );
226+ return t ;
227+ }
228+ }
229+
230+
231+ public void addColorTarget (FrameBufferBufferTarget colorBuf ){
232+ colorBuf .slot =colorBufs .size ();
233+ colorBufs .add (colorBuf );
234+ }
235+
236+ public void addColorTarget (FrameBufferTextureTarget colorBuf ){
237+ // checkSetTexture(colorBuf.getTexture(), false); // TODO: this won't work for levels.
238+ colorBuf .slot =colorBufs .size ();
239+ colorBufs .add (colorBuf );
240+ }
241+
242+ public void setDepthTarget (FrameBufferBufferTarget depthBuf ){
243+ if (!depthBuf .getFormat ().isDepthFormat ())
244+ throw new IllegalArgumentException ("Depth buffer format must be depth." );
245+ this .depthBuf = depthBuf ;
246+ this .depthBuf .slot = this .depthBuf .getFormat ().isDepthStencilFormat () ? SLOT_DEPTH_STENCIL : SLOT_DEPTH ;
247+ }
248+
249+ public void setDepthTarget (FrameBufferTextureTarget depthBuf ){
250+ checkSetTexture (depthBuf .getTexture (), true );
251+ this .depthBuf = depthBuf ;
252+ this .depthBuf .slot = depthBuf .getTexture ().getImage ().getFormat ().isDepthStencilFormat () ? SLOT_DEPTH_STENCIL : SLOT_DEPTH ;
253+ }
254+
255+ public int getNumColorTargets (){
256+ return colorBufs .size ();
257+ }
258+
259+ public RenderBuffer getColorTarget (int index ){
260+ return colorBufs .get (index );
261+ }
262+
263+ public RenderBuffer getColorTarget () {
264+ if (colorBufs .isEmpty ())
265+ return null ;
266+ if (colorBufIndex <0 || colorBufIndex >=colorBufs .size ()) {
267+ return colorBufs .get (0 );
268+ }
269+ return colorBufs .get (colorBufIndex );
270+ }
271+
272+ public RenderBuffer getDepthTarget () {
273+ return depthBuf ;
274+ }
275+
276+
277+
170278 /**
171279 * <p>
172280 * Creates a new FrameBuffer with the given width, height, and number
@@ -213,7 +321,9 @@ protected FrameBuffer(FrameBuffer src) {
213321 *
214322 * @param format The format to use for the depth buffer.
215323 * @throws IllegalArgumentException If <code>format</code> is not a depth format.
324+ * @deprecated Use setDepthTarget
216325 */
326+ @ Deprecated
217327 public void setDepthBuffer (Image .Format format ) {
218328 if (id != -1 ) {
219329 throw new UnsupportedOperationException ("FrameBuffer already initialized." );
@@ -233,7 +343,9 @@ public void setDepthBuffer(Image.Format format) {
233343 *
234344 * @param format The format to use for the color buffer.
235345 * @throws IllegalArgumentException If <code>format</code> is not a color format.
346+ * @deprecated Use addColorTarget
236347 */
348+ @ Deprecated
237349 public void setColorBuffer (Image .Format format ) {
238350 if (id != -1 ) {
239351 throw new UnsupportedOperationException ("FrameBuffer already initialized." );
@@ -337,7 +449,9 @@ public int getTargetIndex() {
337449 * only target.
338450 *
339451 * @param tex The color texture to set.
452+ * @deprecated Use addColorTarget
340453 */
454+ @ Deprecated
341455 public void setColorTexture (Texture2D tex ) {
342456 clearColorTargets ();
343457 addColorTexture (tex );
@@ -350,7 +464,9 @@ public void setColorTexture(Texture2D tex) {
350464 * only target.
351465 *
352466 * @param tex The color texture array to set.
467+ * @deprecated Use addColorTarget
353468 */
469+ @ Deprecated
354470 public void setColorTexture (TextureArray tex , int layer ) {
355471 clearColorTargets ();
356472 addColorTexture (tex , layer );
@@ -364,7 +480,9 @@ public void setColorTexture(TextureArray tex, int layer) {
364480 *
365481 * @param tex The cube-map texture to set.
366482 * @param face The face of the cube-map to render to.
483+ * @deprecated Use addColorTarget
367484 */
485+ @ Deprecated
368486 public void setColorTexture (TextureCubeMap tex , TextureCubeMap .Face face ) {
369487 clearColorTargets ();
370488 addColorTexture (tex , face );
@@ -386,7 +504,9 @@ public void clearColorTargets() {
386504 *
387505 * @param format the format of the color buffer
388506 * @see #addColorTexture(com.jme3.texture.Texture2D)
507+ * @deprecated Use addColorTarget
389508 */
509+ @ Deprecated
390510 public void addColorBuffer (Image .Format format ) {
391511 if (id != -1 ) {
392512 throw new UnsupportedOperationException ("FrameBuffer already initialized." );
@@ -412,7 +532,9 @@ public void addColorBuffer(Image.Format format) {
412532 *
413533 * @param tex The texture to add.
414534 * @see #addColorBuffer(com.jme3.texture.Image.Format)
535+ * @deprecated Use addColorTarget
415536 */
537+ @ Deprecated
416538 public void addColorTexture (Texture2D tex ) {
417539 if (id != -1 ) {
418540 throw new UnsupportedOperationException ("FrameBuffer already initialized." );
@@ -437,7 +559,9 @@ public void addColorTexture(Texture2D tex) {
437559 * is rendered to by the shader.
438560 *
439561 * @param tex The texture array to add.
562+ * @deprecated Use addColorTarget
440563 */
564+ @ Deprecated
441565 public void addColorTexture (TextureArray tex , int layer ) {
442566 if (id != -1 ) {
443567 throw new UnsupportedOperationException ("FrameBuffer already initialized." );
@@ -464,7 +588,9 @@ public void addColorTexture(TextureArray tex, int layer) {
464588 *
465589 * @param tex The cube-map texture to add.
466590 * @param face The face of the cube-map to render to.
591+ * @deprecated Use addColorTarget
467592 */
593+ @ Deprecated
468594 public void addColorTexture (TextureCubeMap tex , TextureCubeMap .Face face ) {
469595 if (id != -1 ) {
470596 throw new UnsupportedOperationException ("FrameBuffer already initialized." );
@@ -486,7 +612,9 @@ public void addColorTexture(TextureCubeMap tex, TextureCubeMap.Face face) {
486612 * Set the depth texture to use for this framebuffer.
487613 *
488614 * @param tex The color texture to set.
615+ * @deprecated Use setDepthTarget
489616 */
617+ @ Deprecated
490618 public void setDepthTexture (Texture2D tex ) {
491619 if (id != -1 ) {
492620 throw new UnsupportedOperationException ("FrameBuffer already initialized." );
@@ -501,6 +629,13 @@ public void setDepthTexture(Texture2D tex) {
501629 depthBuf .format = img .getFormat ();
502630 }
503631
632+ /**
633+ *
634+ * @param tex
635+ * @param layer
636+ * @deprecated Use setDepthTarget
637+ */
638+ @ Deprecated
504639 public void setDepthTexture (TextureArray tex , int layer ) {
505640 if (id != -1 ) {
506641 throw new UnsupportedOperationException ("FrameBuffer already initialized." );
@@ -518,15 +653,19 @@ public void setDepthTexture(TextureArray tex, int layer) {
518653
519654 /**
520655 * @return The number of color buffers attached to this texture.
656+ * @deprecated Use getNumColorTargets
521657 */
658+ @ Deprecated
522659 public int getNumColorBuffers () {
523660 return colorBufs .size ();
524661 }
525662
526663 /**
527664 * @param index
528665 * @return The color buffer at the given index.
666+ * @deprecated Use getColorTarget(int)
529667 */
668+ @ Deprecated
530669 public RenderBuffer getColorBuffer (int index ) {
531670 return colorBufs .get (index );
532671 }
@@ -535,7 +674,9 @@ public RenderBuffer getColorBuffer(int index) {
535674 * @return The color buffer with the index set by {@link #setTargetIndex(int)}, or null
536675 * if no color buffers are attached.
537676 * If MRT is disabled, the first color buffer is returned.
677+ * @deprecated Use getColorTarget()
538678 */
679+ @ Deprecated
539680 public RenderBuffer getColorBuffer () {
540681 if (colorBufs .isEmpty ()) {
541682 return null ;
@@ -549,7 +690,9 @@ public RenderBuffer getColorBuffer() {
549690 /**
550691 * @return The depth buffer attached to this FrameBuffer, or null
551692 * if no depth buffer is attached
693+ * @deprecated Use getDepthTarget()
552694 */
695+ @ Deprecated
553696 public RenderBuffer getDepthBuffer () {
554697 return depthBuf ;
555698 }
0 commit comments