* TextureArray constructor ensures all images passed to it have the same format and dimensions, otherwise an IllegalArgumentException is thrown

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10562 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
ShA..Rd 12 years ago
parent 1f27804716
commit fbac631160
  1. 18
      engine/src/core/com/jme3/texture/TextureArray.java

@ -31,6 +31,7 @@
*/ */
package com.jme3.texture; package com.jme3.texture;
import com.jme3.texture.Image.Format;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -58,26 +59,27 @@ public class TextureArray extends Texture {
} }
/** /**
* Construct a TextureArray from the given list of images * Construct a TextureArray from the given list of images.
* warning, this feature is only supported on opengl 3.0 version.
* To check if a hardware supports TextureArray check : * To check if a hardware supports TextureArray check :
* renderManager.getRenderer().getCaps().contains(Caps.TextureArray) * renderManager.getRenderer().getCaps().contains(Caps.TextureArray)
* @param images * @param images
*/ */
public TextureArray(List<Image> images) { public TextureArray(List<Image> images) {
super(); super();
int width = images.get(0).getWidth(); int width = images.get(0).getWidth();
int height = images.get(0).getHeight(); int height = images.get(0).getHeight();
Image arrayImage = new Image(images.get(0).getFormat(), width, height, Format format = images.get(0).getFormat();
null); Image arrayImage = new Image(format, width, height, null);
for (Image img : images) { for (Image img : images) {
if (img.getHeight() != height || img.getWidth() != width) { if (img.getHeight() != height || img.getWidth() != width) {
Logger.getLogger(TextureArray.class.getName()).log( throw new IllegalArgumentException("Images in texture array must have same dimensions");
Level.WARNING,
"all images must have the same width/height");
continue;
} }
if (img.getFormat() != format) {
throw new IllegalArgumentException("Images in texture array must have same format");
}
arrayImage.addData(img.getData(0)); arrayImage.addData(img.getData(0));
} }
setImage(arrayImage); setImage(arrayImage);

Loading…
Cancel
Save