Home | History | Annotate | Download | only in attributes
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *   http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  ******************************************************************************/
     16 
     17 package com.badlogic.gdx.graphics.g3d.attributes;
     18 
     19 import com.badlogic.gdx.graphics.Color;
     20 import com.badlogic.gdx.graphics.g3d.Attribute;
     21 import com.badlogic.gdx.utils.GdxRuntimeException;
     22 
     23 public class ColorAttribute extends Attribute {
     24 	public final static String DiffuseAlias = "diffuseColor";
     25 	public final static long Diffuse = register(DiffuseAlias);
     26 	public final static String SpecularAlias = "specularColor";
     27 	public final static long Specular = register(SpecularAlias);
     28 	public final static String AmbientAlias = "ambientColor";
     29 	public static final long Ambient = register(AmbientAlias);
     30 	public final static String EmissiveAlias = "emissiveColor";
     31 	public static final long Emissive = register(EmissiveAlias);
     32 	public final static String ReflectionAlias = "reflectionColor";
     33 	public static final long Reflection = register(ReflectionAlias);
     34 	public final static String AmbientLightAlias = "ambientLightColor";
     35 	public static final long AmbientLight = register(AmbientLightAlias);
     36 	public final static String FogAlias = "fogColor";
     37 	public static final long Fog = register(FogAlias);
     38 
     39 	protected static long Mask = Ambient | Diffuse | Specular | Emissive | Reflection | AmbientLight | Fog;
     40 
     41 	public final static boolean is (final long mask) {
     42 		return (mask & Mask) != 0;
     43 	}
     44 
     45 	public final static ColorAttribute createAmbient (final Color color) {
     46 		return new ColorAttribute(Ambient, color);
     47 	}
     48 
     49 	public final static ColorAttribute createAmbient (float r, float g, float b, float a) {
     50 		return new ColorAttribute(Ambient, r, g, b, a);
     51 	}
     52 
     53 	public final static ColorAttribute createDiffuse (final Color color) {
     54 		return new ColorAttribute(Diffuse, color);
     55 	}
     56 
     57 	public final static ColorAttribute createDiffuse (float r, float g, float b, float a) {
     58 		return new ColorAttribute(Diffuse, r, g, b, a);
     59 	}
     60 
     61 	public final static ColorAttribute createSpecular (final Color color) {
     62 		return new ColorAttribute(Specular, color);
     63 	}
     64 
     65 	public final static ColorAttribute createSpecular (float r, float g, float b, float a) {
     66 		return new ColorAttribute(Specular, r, g, b, a);
     67 	}
     68 
     69 	public final static ColorAttribute createReflection (final Color color) {
     70 		return new ColorAttribute(Reflection, color);
     71 	}
     72 
     73 	public final static ColorAttribute createReflection (float r, float g, float b, float a) {
     74 		return new ColorAttribute(Reflection, r, g, b, a);
     75 	}
     76 
     77 	public final Color color = new Color();
     78 
     79 	public ColorAttribute (final long type) {
     80 		super(type);
     81 		if (!is(type)) throw new GdxRuntimeException("Invalid type specified");
     82 	}
     83 
     84 	public ColorAttribute (final long type, final Color color) {
     85 		this(type);
     86 		if (color != null) this.color.set(color);
     87 	}
     88 
     89 	public ColorAttribute (final long type, float r, float g, float b, float a) {
     90 		this(type);
     91 		this.color.set(r, g, b, a);
     92 	}
     93 
     94 	public ColorAttribute (final ColorAttribute copyFrom) {
     95 		this(copyFrom.type, copyFrom.color);
     96 	}
     97 
     98 	@Override
     99 	public Attribute copy () {
    100 		return new ColorAttribute(this);
    101 	}
    102 
    103 	@Override
    104 	public int hashCode () {
    105 		int result = super.hashCode();
    106 		result = 953 * result + color.toIntBits();
    107 		return result;
    108 	}
    109 
    110 	@Override
    111 	public int compareTo (Attribute o) {
    112 		if (type != o.type) return (int)(type - o.type);
    113 		return ((ColorAttribute)o).color.toIntBits() - color.toIntBits();
    114 	}
    115 }
    116