|
30 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31 | 31 | */
|
32 | 32 | package com.jme3.shader;
|
33 |
| - |
| 33 | +import com.jme3.math.*; |
| 34 | +import com.jme3.texture.*; |
| 35 | +import com.jme3.shader.BufferObject; |
34 | 36 | public enum VarType {
|
35 | 37 |
|
36 |
| - Float("float"), |
37 |
| - Vector2("vec2"), |
38 |
| - Vector3("vec3"), |
39 |
| - Vector4("vec4"), |
| 38 | + Float("float",float.class,Float.class), |
| 39 | + Vector2("vec2",Vector2f.class), |
| 40 | + Vector3("vec3",Vector3f.class), |
| 41 | + Vector4("vec4",Vector4f.class, ColorRGBA.class), |
40 | 42 |
|
41 |
| - IntArray(true,false,"int"), |
42 |
| - FloatArray(true,false,"float"), |
43 |
| - Vector2Array(true,false,"vec2"), |
44 |
| - Vector3Array(true,false,"vec3"), |
45 |
| - Vector4Array(true,false,"vec4"), |
| 43 | + IntArray(true,false,"int",int[].class,Integer[].class), |
| 44 | + FloatArray(true,false,"float",float[].class,Float[].class), |
| 45 | + Vector2Array(true,false,"vec2",Vector2f[].class), |
| 46 | + Vector3Array(true,false,"vec3",Vector3f[].class), |
| 47 | + Vector4Array(true,false,"vec4",Vector4f[].class), |
46 | 48 |
|
47 |
| - Boolean("bool"), |
| 49 | + Boolean("bool",Boolean.class,boolean.class), |
48 | 50 |
|
49 |
| - Matrix3(true,false,"mat3"), |
50 |
| - Matrix4(true,false,"mat4"), |
| 51 | + Matrix3(true,false,"mat3",Matrix3f.class), |
| 52 | + Matrix4(true,false,"mat4",Matrix4f.class), |
51 | 53 |
|
52 |
| - Matrix3Array(true,false,"mat3"), |
53 |
| - Matrix4Array(true,false,"mat4"), |
| 54 | + Matrix3Array(true,false,"mat3",Matrix3f[].class), |
| 55 | + Matrix4Array(true,false,"mat4",Matrix4f[].class), |
54 | 56 |
|
55 |
| - TextureBuffer(false,true,"sampler1D|sampler1DShadow"), |
56 |
| - Texture2D(false,true,"sampler2D|sampler2DShadow"), |
57 |
| - Texture3D(false,true,"sampler3D"), |
58 |
| - TextureArray(false,true,"sampler2DArray|sampler2DArrayShadow"), |
59 |
| - TextureCubeMap(false,true,"samplerCube"), |
60 |
| - Int("int"), |
61 |
| - BufferObject(false, false, "custom"); |
| 57 | + TextureBuffer(false,true,"sampler1D|sampler1DShadow"), |
| 58 | + Texture2D(false,true,"sampler2D|sampler2DShadow",Texture2D.class,Texture.class), |
| 59 | + Texture3D(false,true,"sampler3D",Texture3D.class,Texture.class), |
| 60 | + TextureArray(false,true,"sampler2DArray|sampler2DArrayShadow",TextureArray.class,Texture.class), |
| 61 | + TextureCubeMap(false,true,"samplerCube",TextureCubeMap.class,Texture.class), |
| 62 | + Int("int",int.class,Integer.class), |
| 63 | + BufferObject(false, false, "custom", BufferObject.class); |
| 64 | + |
62 | 65 |
|
63 | 66 | private boolean usesMultiData = false;
|
64 | 67 | private boolean textureType = false;
|
65 | 68 | final private String glslType;
|
66 |
| - |
| 69 | + private Class<?> javaTypes[]; |
67 | 70 |
|
68 |
| - VarType(String glslType){ |
| 71 | + VarType(String glslType,Class<?> ...javaTypes){ |
69 | 72 | this.glslType = glslType;
|
| 73 | + if (javaTypes != null) { |
| 74 | + this.javaTypes = javaTypes; |
| 75 | + } else { |
| 76 | + this.javaTypes = new Class<?>[0]; |
| 77 | + } |
| 78 | + |
70 | 79 | }
|
71 | 80 |
|
72 |
| - VarType(boolean multiData, boolean textureType,String glslType){ |
| 81 | + |
| 82 | + VarType(boolean multiData, boolean textureType, String glslType, Class<?>... javaTypes) { |
73 | 83 | usesMultiData = multiData;
|
74 | 84 | this.textureType = textureType;
|
75 | 85 | this.glslType = glslType;
|
| 86 | + if (javaTypes != null) { |
| 87 | + this.javaTypes = javaTypes; |
| 88 | + } else { |
| 89 | + this.javaTypes = new Class<?>[0]; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Check if the passed object is of a type mapped to this VarType |
| 95 | + * @param o Object to check |
| 96 | + * @return true if the object type is mapped to this VarType |
| 97 | + */ |
| 98 | + public boolean isOfType(Object o){ |
| 99 | + for(Class<?> c : javaTypes){ |
| 100 | + if(c.isAssignableFrom(o.getClass()))return true; |
| 101 | + } |
| 102 | + return false; |
| 103 | + } |
| 104 | + |
| 105 | + |
| 106 | + /** |
| 107 | + * Get the java types mapped to this VarType |
| 108 | + * @return an array of classes mapped to this VarType |
| 109 | + */ |
| 110 | + public Class<?>[] getJavaType(){ |
| 111 | + return javaTypes; |
76 | 112 | }
|
77 | 113 |
|
78 | 114 | public boolean isTextureType() {
|
|
0 commit comments