Home | History | Annotate | Download | only in texture
      1 package com.jme3.texture;
      2 
      3 import java.util.List;
      4 import java.util.logging.Level;
      5 import java.util.logging.Logger;
      6 
      7 /**
      8  * This class implements a Texture array
      9  * warning, this feature is only supported on opengl 3.0 version.
     10  * To check if a hardware supports TextureArray check :
     11  * renderManager.getRenderer().getCaps().contains(Caps.TextureArray)
     12  * @author phate666
     13  */
     14 public class TextureArray extends Texture {
     15 
     16     private WrapMode wrapS = WrapMode.EdgeClamp;
     17     private WrapMode wrapT = WrapMode.EdgeClamp;
     18 
     19     /**
     20      * Construct a TextureArray
     21      * warning, this feature is only supported on opengl 3.0 version.
     22      * To check if a hardware supports TextureArray check :
     23      * renderManager.getRenderer().getCaps().contains(Caps.TextureArray)
     24      */
     25     public TextureArray() {
     26         super();
     27     }
     28 
     29     /**
     30      * Construct a TextureArray from the given list of images
     31      * warning, this feature is only supported on opengl 3.0 version.
     32      * To check if a hardware supports TextureArray check :
     33      * renderManager.getRenderer().getCaps().contains(Caps.TextureArray)
     34      * @param images
     35      */
     36     public TextureArray(List<Image> images) {
     37         super();
     38         int width = images.get(0).getWidth();
     39         int height = images.get(0).getHeight();
     40         Image arrayImage = new Image(images.get(0).getFormat(), width, height,
     41                 null);
     42 
     43         for (Image img : images) {
     44             if (img.getHeight() != height || img.getWidth() != width) {
     45                 Logger.getLogger(TextureArray.class.getName()).log(
     46                         Level.WARNING,
     47                         "all images must have the same width/height");
     48                 continue;
     49             }
     50             arrayImage.addData(img.getData(0));
     51         }
     52         setImage(arrayImage);
     53     }
     54 
     55     @Override
     56     public Texture createSimpleClone() {
     57         TextureArray clone = new TextureArray();
     58         createSimpleClone(clone);
     59         return clone;
     60     }
     61 
     62     @Override
     63     public Texture createSimpleClone(Texture rVal) {
     64         rVal.setWrap(WrapAxis.S, wrapS);
     65         rVal.setWrap(WrapAxis.T, wrapT);
     66         return super.createSimpleClone(rVal);
     67     }
     68 
     69     @Override
     70     public Type getType() {
     71         return Type.TwoDimensionalArray;
     72     }
     73 
     74     @Override
     75     public WrapMode getWrap(WrapAxis axis) {
     76         switch (axis) {
     77             case S:
     78                 return wrapS;
     79             case T:
     80                 return wrapT;
     81             default:
     82                 throw new IllegalArgumentException("invalid WrapAxis: " + axis);
     83         }
     84     }
     85 
     86     @Override
     87     public void setWrap(WrapAxis axis, WrapMode mode) {
     88         if (mode == null) {
     89             throw new IllegalArgumentException("mode can not be null.");
     90         } else if (axis == null) {
     91             throw new IllegalArgumentException("axis can not be null.");
     92         }
     93         switch (axis) {
     94             case S:
     95                 this.wrapS = mode;
     96                 break;
     97             case T:
     98                 this.wrapT = mode;
     99                 break;
    100             default:
    101                 throw new IllegalArgumentException("Not applicable for 2D textures");
    102         }
    103     }
    104 
    105     @Override
    106     public void setWrap(WrapMode mode) {
    107         if (mode == null) {
    108             throw new IllegalArgumentException("mode can not be null.");
    109         }
    110         this.wrapS = mode;
    111         this.wrapT = mode;
    112     }
    113 }