Index: src/test/jme3test/texture/2dArraytexture.j3md
===================================================================
--- src/test/jme3test/texture/2dArraytexture.j3md (revision 0)
+++ src/test/jme3test/texture/2dArraytexture.j3md (revision 0)
@@ -0,0 +1,16 @@
+MaterialDef My MaterialDef {
+
+ MaterialParameters {
+ Texture3D Texture
+ }
+
+ Technique {
+ VertexShader GLSL100: jme3test/texture/2dArraytexture.vert
+ FragmentShader GLSL100: jme3test/texture/2dArraytexture.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+}
Index: src/test/jme3test/texture/2dArraytexture.vert
===================================================================
--- src/test/jme3test/texture/2dArraytexture.vert (revision 0)
+++ src/test/jme3test/texture/2dArraytexture.vert (revision 0)
@@ -0,0 +1,11 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+
+attribute vec3 inTexCoord;
+attribute vec3 inPosition;
+
+varying vec3 texCoord;
+
+void main(){
+ gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition,1.0);
+ texCoord=inTexCoord;
+}
No newline at end of file
Index: src/test/jme3test/texture/2dArraytexture.frag
===================================================================
--- src/test/jme3test/texture/2dArraytexture.frag (revision 0)
+++ src/test/jme3test/texture/2dArraytexture.frag (revision 0)
@@ -0,0 +1,7 @@
+uniform sampler2DArray m_Texture;
+
+varying vec3 texCoord;
+
+void main(){
+ gl_FragColor= texture2DArray(m_Texture,vec3(texCoord.xy,texCoord.z*10));
+}
No newline at end of file
Index: src/test/jme3test/texture/TestTexture2DArrayLoading.java
===================================================================
--- src/test/jme3test/texture/TestTexture2DArrayLoading.java (revision 0)
+++ src/test/jme3test/texture/TestTexture2DArrayLoading.java (revision 0)
@@ -0,0 +1,104 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package jme3test.texture;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.bounding.BoundingBox;
+import com.jme3.light.PointLight;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.Vector3f;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.VertexBuffer;
+import com.jme3.scene.VertexBuffer.Type;
+import com.jme3.scene.VertexBuffer.Usage;
+import com.jme3.scene.shape.Sphere;
+import com.jme3.texture.Image;
+import com.jme3.texture.Image.Format;
+import com.jme3.texture.Texture;
+import com.jme3.texture.Texture2DArray;
+import com.jme3.texture.Texture3D;
+import com.jme3.util.BufferUtils;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
+import java.util.ArrayList;
+
+public class TestTexture2DArrayLoading extends SimpleApplication {
+
+ public static void main(String[] args) {
+ TestTexture2DArrayLoading app = new TestTexture2DArrayLoading();
+ app.start();
+ }
+
+ @Override
+ public void simpleInitApp() {
+ //mouseInput.setCursorVisible(true);
+ flyCam.setMoveSpeed(10);
+ //creating a sphere
+ Sphere sphere = new Sphere(32, 32, 1);
+ //getting the boundingbox
+ sphere.updateBound();
+ BoundingBox bb = (BoundingBox) sphere.getBound();
+ Vector3f min = bb.getMin(null);
+ float[] ext = new float[]{bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2};
+ //we need to change the UV coordinates (the sphere is assumet to be inside the 3D image box)
+ sphere.clearBuffer(Type.TexCoord);
+ VertexBuffer vb = sphere.getBuffer(Type.Position);
+ FloatBuffer fb = (FloatBuffer) vb.getData();
+ float[] uvCoordinates = BufferUtils.getFloatArray(fb);
+ //now transform the coordinates so that they are in the range of <0; 1>
+ for (int i = 0; i < uvCoordinates.length; i += 3) {
+ uvCoordinates[i] = (uvCoordinates[i] - min.x) / ext[0];
+ uvCoordinates[i + 1] = (uvCoordinates[i + 1] - min.y) / ext[1];
+ uvCoordinates[i + 2] = (uvCoordinates[i + 2] - min.z) / ext[2];
+ }
+ //apply new texture coordinates
+ VertexBuffer uvCoordsBuffer = new VertexBuffer(Type.TexCoord);
+ uvCoordsBuffer.setupData(Usage.Static, 3, com.jme3.scene.VertexBuffer.Format.Float,
+ BufferUtils.createFloatBuffer(uvCoordinates));
+ sphere.setBuffer(uvCoordsBuffer);
+ //create geometry, and apply material and our 3D texture
+ Geometry g = new Geometry("sphere", sphere);
+ Material material = new Material(assetManager, "jme3test/texture/2dArraytexture.j3md");
+ try {
+ Texture texture = this.getTexture();
+ material.setTexture("Texture", texture);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ g.setMaterial(material);
+ rootNode.attachChild(g);
+ //add some light so that it is visible
+ PointLight light = new PointLight();
+ light.setColor(ColorRGBA.White);
+ light.setPosition(new Vector3f(5, 5, 5));
+ light.setRadius(20);
+ rootNode.addLight(light);
+ light = new PointLight();
+ light.setColor(ColorRGBA.White);
+ light.setPosition(new Vector3f(-5, -5, -5));
+ light.setRadius(20);
+ rootNode.addLight(light);
+ }
+
+ /**
+ * This method creates a RGB8 texture with the sizes of 10x10x10 pixels.
+ */
+ private Texture getTexture() throws IOException {
+ ArrayList<ByteBuffer> data = new ArrayList<ByteBuffer>(1);
+ ByteBuffer bb = BufferUtils.createByteBuffer(10 * 10 * 10 * 3);//all data must be inside one buffer
+ for (int i = 0; i < 10; ++i) {
+ for (int j = 0; j < 10 * 10; ++j) {
+ bb.put((byte) (255f*i/10f));
+ bb.put((byte) (255f*i/10f));
+ bb.put((byte) (255f));
+ }
+ }
+ bb.rewind();
+ data.add(bb);
+ return new Texture2DArray(new Image(Format.RGB8, 10, 10, 10, data));
+ }
+}
No newline at end of file
Index: src/core/com/jme3/texture/Texture2DArray.java
===================================================================
--- src/core/com/jme3/texture/Texture2DArray.java (revision 0)
+++ src/core/com/jme3/texture/Texture2DArray.java (revision 0)
@@ -0,0 +1,132 @@
+package com.jme3.texture;
+
+import java.io.IOException;
+
+import com.jme3.export.InputCapsule;
+import com.jme3.export.JmeExporter;
+import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
+import com.jme3.texture.Texture.MagFilter;
+import com.jme3.texture.Texture.MinFilter;
+import com.jme3.texture.Texture.Type;
+import com.jme3.texture.Texture.WrapAxis;
+import com.jme3.texture.Texture.WrapMode;
+
+public class Texture2DArray extends Texture {
+ private WrapMode wrapS = WrapMode.EdgeClamp;
+ private WrapMode wrapT = WrapMode.EdgeClamp;
+
+
+ public Texture2DArray(){
+ super();
+ }
+
+ public Texture2DArray(Image img) {
+ super();
+ setImage(img);
+ if (img.getFormat().isDepthFormat()) {
+ setMagFilter(MagFilter.Nearest);
+ setMinFilter(MinFilter.NearestNoMipMaps);
+ }
+ }
+
+ public Texture2DArray(int width, int height, int depth, Image.Format format) {
+ this(new Image(format, width, height, depth, null));
+ }
+
+ public Texture2DArray(int width, int height, int depth, int numSamples, Image.Format format) {
+ this(new Image(format, width, height, depth, null));
+ getImage().setMultiSamples(numSamples);
+ }
+
+ public void setWrap(WrapAxis axis, WrapMode mode) {
+ if (mode == null) {
+ throw new IllegalArgumentException("mode can not be null.");
+ } else if (axis == null) {
+ throw new IllegalArgumentException("axis can not be null.");
+ }
+ switch (axis) {
+ case S:
+ this.wrapS = mode;
+ break;
+ case T:
+ this.wrapT = mode;
+ break;
+ case R:
+ throw new RuntimeException("no third axis wrapmode supported");
+ }
+ }
+
+ public void setWrap(WrapMode mode) {
+ if (mode == null) {
+ throw new IllegalArgumentException("mode can not be null.");
+ }
+ this.wrapS = mode;
+ this.wrapT = mode;
+ }
+
+ public WrapMode getWrap(WrapAxis axis) {
+ switch (axis) {
+ case S:
+ return wrapS;
+ case T:
+ return wrapT;
+ case R:
+ throw new RuntimeException("no third axis wrapmode supported");
+ }
+ throw new IllegalArgumentException("invalid WrapAxis: " + axis);
+ }
+
+ @Override
+ public Type getType() {
+ return Type.TwoDimensionalArray;
+ }
+
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof Texture3D)) {
+ return false;
+ }
+ Texture2DArray that = (Texture2DArray) other;
+ if (this.getWrap(WrapAxis.S) != that.getWrap(WrapAxis.S)) {
+ return false;
+ }
+ if (this.getWrap(WrapAxis.T) != that.getWrap(WrapAxis.T)) {
+ return false;
+ }
+ return super.equals(other);
+ }
+
+ @Override
+ public Texture createSimpleClone() {
+ Texture2DArray clone = new Texture2DArray();
+ createSimpleClone(clone);
+ return clone;
+ }
+
+ @Override
+ public Texture createSimpleClone(Texture rVal) {
+ rVal.setWrap(WrapAxis.S, wrapS);
+ rVal.setWrap(WrapAxis.T, wrapT);
+ return super.createSimpleClone(rVal);
+ }
+
+
+ @Override
+ public void write(JmeExporter e) throws IOException {
+ super.write(e);
+ OutputCapsule capsule = e.getCapsule(this);
+ capsule.write(wrapS, "wrapS", WrapMode.EdgeClamp);
+ capsule.write(wrapT, "wrapT", WrapMode.EdgeClamp);
+ }
+
+ @Override
+ public void read(JmeImporter e) throws IOException {
+ super.read(e);
+ InputCapsule capsule = e.getCapsule(this);
+ wrapS = capsule.readEnum("wrapS", WrapMode.class, WrapMode.EdgeClamp);
+ wrapT = capsule.readEnum("wrapT", WrapMode.class, WrapMode.EdgeClamp);
+ }
+
+}
Index: src/core/com/jme3/asset/TextureKey.java
===================================================================
--- src/core/com/jme3/asset/TextureKey.java (revision 8391)
+++ src/core/com/jme3/asset/TextureKey.java (working copy)
@@ -39,6 +39,7 @@
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.Type;
import com.jme3.texture.Texture2D;
+import com.jme3.texture.Texture2DArray;
import com.jme3.texture.Texture3D;
import com.jme3.texture.TextureCubeMap;
import java.io.IOException;
@@ -52,6 +53,7 @@
private boolean asTexture3D;
private int anisotropy;
private Texture.Type textureTypeHint=Texture.Type.TwoDimensional;
+ private boolean asTextureArray;
public TextureKey(String name, boolean flipY) {
super(name);
@@ -104,6 +106,8 @@
tex = new TextureCubeMap();
} else if (isAsTexture3D()) {
tex = new Texture3D();
@@ -155,7 +159,15 @@
public void setAsTexture3D(boolean asTexture3D) {
this.asTexture3D = asTexture3D;
}
+
-
public boolean isAsTextureArray() {
-
return asTextureArray;
-
}
-
public void setAsTextureArray(boolean b) {
-
this.asTextureArray = b;
-
}
-
@Override
public boolean equals(Object other) {
if (!(other instanceof TextureKey)) {
@@ -191,4 +203,5 @@
asCube = ic.readBoolean("as_cubemap", false);
anisotropy = ic.readInt("anisotropy", 0);
}
-
}