aboutsummaryrefslogtreecommitdiff
path: root/engine/src/test/jme3test/texture/TestTextureArray.java
blob: 823fd78818672865ef9c67baad2025f51c3bdcbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package jme3test.texture;


import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Caps;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.texture.Image;
import com.jme3.texture.Texture;
import com.jme3.texture.TextureArray;
import com.jme3.util.BufferUtils;
import java.util.ArrayList;
import java.util.List;

public class TestTextureArray extends SimpleApplication
{

   @Override
   public void simpleInitApp()
   {
       Material mat = new Material(assetManager, "jme3test/texture/UnshadedArray.j3md");
       
       for (Caps caps : renderManager.getRenderer().getCaps()) {
           System.out.println(caps.name());
       }
       if(!renderManager.getRenderer().getCaps().contains(Caps.TextureArray)){
           throw new UnsupportedOperationException("Your hardware does not support TextureArray");
       }
       
       
       Texture tex1 = assetManager.loadTexture( "Textures/Terrain/Pond/Pond.jpg");
       Texture tex2 = assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
       List<Image> images = new ArrayList<Image>();
       images.add(tex1.getImage());
       images.add(tex2.getImage());
       TextureArray tex3 = new TextureArray(images);
       mat.setTexture("ColorMap", tex3);

       Mesh m = new Mesh();
       Vector3f[] vertices = new Vector3f[8];
       vertices[0] = new Vector3f(0, 0, 0);
       vertices[1] = new Vector3f(3, 0, 0);
       vertices[2] = new Vector3f(0, 3, 0);
       vertices[3] = new Vector3f(3, 3, 0);

       vertices[4] = new Vector3f(3, 0, 0);
       vertices[5] = new Vector3f(6, 0, 0);
       vertices[6] = new Vector3f(3, 3, 0);
       vertices[7] = new Vector3f(6, 3, 0);

       Vector3f[] texCoord = new Vector3f[8];
       texCoord[0] = new Vector3f(0, 0, 0);
       texCoord[1] = new Vector3f(1, 0, 0);
       texCoord[2] = new Vector3f(0, 1, 0);
       texCoord[3] = new Vector3f(1, 1, 0);

       texCoord[4] = new Vector3f(0, 0, 1);
       texCoord[5] = new Vector3f(1, 0, 1);
       texCoord[6] = new Vector3f(0, 1, 1);
       texCoord[7] = new Vector3f(1, 1, 1);

       int[] indexes = { 2, 0, 1, 1, 3, 2 , 6, 4, 5, 5, 7, 6};

       m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
       m.setBuffer(Type.TexCoord, 3, BufferUtils.createFloatBuffer(texCoord));
       m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));
       m.updateBound();

       Geometry geom = new Geometry("Mesh", m);
       geom.setMaterial(mat);
       rootNode.attachChild(geom);
   }

   /**
    * @param args
    */
   public static void main(String[] args)
   {
       TestTextureArray app = new TestTextureArray();
       app.start();
   }

}