import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
import com.badlogic.gdx.graphics.g2d.BitmapFont;\r
import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
+import com.badlogic.gdx.graphics.g3d.Environment;\r
import com.badlogic.gdx.graphics.g3d.ModelBatch;\r
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;\r
-import com.badlogic.gdx.graphics.g3d.environment.Environment;\r
import com.badlogic.gdx.math.Matrix3;\r
import com.badlogic.gdx.math.Matrix4;\r
import com.badlogic.gdx.math.Vector3;\r
-package com.badlogic.gdx.graphics.g3d.environment;
+package com.badlogic.gdx.graphics.g3d;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Cubemap;
-import com.badlogic.gdx.graphics.g3d.Attributes;
+import com.badlogic.gdx.graphics.g3d.environment.BaseLight;
+import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
+import com.badlogic.gdx.graphics.g3d.environment.PointLight;
+import com.badlogic.gdx.graphics.g3d.environment.ShadowMap;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
public class Environment extends Attributes {
/** @deprecated Experimental, likely to change, do not use! */
public ShadowMap shadowMap;
- public Cubemap environmentCubemap;
public final Array<DirectionalLight> directionalLights = new Array<DirectionalLight>();
public final Array<PointLight> pointLights = new Array<PointLight>();
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Camera;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;
import com.badlogic.gdx.graphics.g3d.utils.DefaultRenderableSorter;
import com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.model.Node;
import com.badlogic.gdx.graphics.g3d.utils.ShaderProvider;
import com.badlogic.gdx.math.Matrix4;
--- /dev/null
+package com.badlogic.gdx.graphics.g3d.attributes;
+
+import com.badlogic.gdx.graphics.Cubemap;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g3d.Attribute;
+import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor;
+import com.badlogic.gdx.utils.GdxRuntimeException;
+
+public class CubemapAttribute extends Attribute {
+ public final static String EnvironmentMapAlias = "environmentMapTexture";
+ public final static long EnvironmentMap = register(EnvironmentMapAlias);
+
+ // FIXME add more types!
+ // FIXME add scaling + offset?
+ // FIXME add filter settings? MipMap needs to be obeyed during loading :/
+
+ protected static long Mask = EnvironmentMap;
+
+ public final static boolean is(final long mask) {
+ return (mask & Mask) != 0;
+ }
+
+ public final TextureDescriptor<Cubemap> textureDescription;
+
+ public CubemapAttribute(final long type) {
+ super(type);
+ if (!is(type))
+ throw new GdxRuntimeException("Invalid type specified");
+ textureDescription = new TextureDescriptor<Cubemap>();
+ }
+
+ public <T extends Cubemap> CubemapAttribute(final long type, final TextureDescriptor<T> textureDescription) {
+ this(type);
+ this.textureDescription.set(textureDescription);
+ }
+
+ public CubemapAttribute(final long type, final Cubemap texture) {
+ this(type);
+ textureDescription.texture = texture;
+ }
+
+ public CubemapAttribute(final CubemapAttribute copyFrom) {
+ this(copyFrom.type, copyFrom.textureDescription);
+ }
+
+ @Override
+ public Attribute copy () {
+ return new CubemapAttribute(this);
+ }
+
+ @Override
+ protected boolean equals (Attribute other) {
+ return ((CubemapAttribute)other).textureDescription.equals(textureDescription);
+ }
+}
package com.badlogic.gdx.graphics.g3d.attributes;
+import com.badlogic.gdx.graphics.GLTexture;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g3d.Attribute;
import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor;
return new TextureAttribute(Specular, texture);
}
- public final TextureDescriptor textureDescription;
+ public final TextureDescriptor<Texture> textureDescription;
- public TextureAttribute(final long type, final TextureDescriptor textureDescription) {
+ public TextureAttribute(final long type) {
super(type);
if (!is(type))
throw new GdxRuntimeException("Invalid type specified");
- this.textureDescription = textureDescription; // FIXME Add TextureDescriptor#copy or #addRef ?
+ textureDescription = new TextureDescriptor<Texture>();
}
- public TextureAttribute(final long type) {
- this(type, new TextureDescriptor());
+ public <T extends Texture> TextureAttribute(final long type, final TextureDescriptor<T> textureDescription) {
+ this(type);
+ this.textureDescription.set(textureDescription);
}
public TextureAttribute(final long type, final Texture texture) {
- this(type, new TextureDescriptor(texture));
+ this(type);
+ textureDescription.texture = texture;
}
public TextureAttribute(final TextureAttribute copyFrom) {
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Attribute;
import com.badlogic.gdx.graphics.g3d.Attributes;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.Shader;
import com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
+import com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.IntAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
import com.badlogic.gdx.graphics.g3d.environment.AmbientCubemap;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.environment.PointLight;
import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
public final static Setter environmentCubemap = new Setter() {
@Override public boolean isGlobal (BaseShader shader, int inputID) { return false; }
@Override public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) {
- if (renderable.environment != null && renderable.environment.environmentCubemap != null) {
- final int unit = shader.context.textureBinder.bind(renderable.environment.environmentCubemap);
- shader.set(inputID, unit);
+ if (combinedAttributes.has(CubemapAttribute.EnvironmentMap)) {
+ shader.set(inputID, shader.context.textureBinder.bind(((CubemapAttribute)combinedAttributes.get(CubemapAttribute.EnvironmentMap)).textureDescription));
}
}
};
public DefaultShader(final Renderable renderable, final Config config, final ShaderProgram shaderProgram) {
this.program = shaderProgram;
this.lighting = renderable.environment != null;
- this.environmentCubemap = lighting && renderable.environment.environmentCubemap != null;
+ this.environmentCubemap = renderable.material.has(CubemapAttribute.EnvironmentMap) || (
+ lighting && renderable.environment.has(CubemapAttribute.EnvironmentMap));
this.shadowMap = lighting && renderable.environment.shadowMap != null;
this.fog = lighting && renderable.environment.has(ColorAttribute.Fog);
this.renderable = renderable;
}
if (renderable.environment.shadowMap != null)
prefix += "#define shadowMapFlag\n";
- if (renderable.environment.environmentCubemap != null)
+ if (renderable.material.has(CubemapAttribute.EnvironmentMap) || renderable.environment.has(CubemapAttribute.EnvironmentMap))
prefix += "#define environmentCubemapFlag\n";
}
}
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g3d.Attribute;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.Shader;
import com.badlogic.gdx.graphics.g3d.attributes.IntAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.environment.PointLight;
import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
-public class TextureDescriptor {
- public GLTexture texture = null;
+public class TextureDescriptor<T extends GLTexture> {
+ public T texture = null;
public Texture.TextureFilter minFilter;
public Texture.TextureFilter magFilter;
public Texture.TextureWrap uWrap;
public Texture.TextureWrap vWrap;
// TODO add other values, see http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml
- public TextureDescriptor(final Texture texture, final Texture.TextureFilter minFilter, final Texture.TextureFilter magFilter, final Texture.TextureWrap uWrap, final Texture.TextureWrap vWrap) {
+ public TextureDescriptor(final T texture, final Texture.TextureFilter minFilter, final Texture.TextureFilter magFilter, final Texture.TextureWrap uWrap, final Texture.TextureWrap vWrap) {
set(texture, minFilter, magFilter, uWrap, vWrap);
}
- public TextureDescriptor(final Texture texture) {
+ public TextureDescriptor(final T texture) {
this(texture, null, null, null, null);
}
public TextureDescriptor() {
}
- public void set(final GLTexture texture, final Texture.TextureFilter minFilter, final Texture.TextureFilter magFilter, final Texture.TextureWrap uWrap, final Texture.TextureWrap vWrap) {
+ public void set(final T texture, final Texture.TextureFilter minFilter, final Texture.TextureFilter magFilter, final Texture.TextureWrap uWrap, final Texture.TextureWrap vWrap) {
this.texture = texture;
this.minFilter = minFilter;
this.magFilter = magFilter;
this.vWrap = vWrap;
}
- public void set(final TextureDescriptor other) {
+ public <V extends T> void set(final TextureDescriptor<V> other) {
texture = other.texture;
minFilter = other.minFilter;
magFilter = other.magFilter;
if (obj == null) return false;
if (obj == this) return true;
if (!(obj instanceof TextureDescriptor)) return false;
- final TextureDescriptor other = (TextureDescriptor)obj;
+ final TextureDescriptor<?> other = (TextureDescriptor<?>)obj;
return other.texture == texture && other.minFilter == minFilter && other.magFilter == magFilter &&
other.uWrap == uWrap && other.vWrap == vWrap;
}
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.environment.PointLight;
import com.badlogic.gdx.graphics.g3d.loader.ObjLoader;
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Matrix4;
package com.badlogic.gdx.tests.bullet;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.WindowedMean;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.model.Animation;
import com.badlogic.gdx.graphics.g3d.model.MeshPart;
import com.badlogic.gdx.graphics.g3d.model.Node;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.PerspectiveCamera;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.IntAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.model.Node;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.tests.utils.GdxTest;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL10;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.environment.PointLight;
import com.badlogic.gdx.graphics.g3d.model.Animation;
import com.badlogic.gdx.graphics.g3d.model.NodeAnimation;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Cubemap;
import com.badlogic.gdx.graphics.Cubemap.CubemapSide;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.Shader;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
+import com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.environment.PointLight;
import com.badlogic.gdx.graphics.g3d.model.Animation;
import com.badlogic.gdx.graphics.g3d.shaders.BaseShader;
cubemap = null;
}
if (name.equals("<none>")) {
- if (lights.environmentCubemap != null) {
- lights.environmentCubemap = null;
+ if (lights.has(CubemapAttribute.EnvironmentMap)) {
+ lights.remove(CubemapAttribute.EnvironmentMap);
shaderProvider.clear();
}
}
root.child(name+"_PZ.png"), root.child(name+"_NZ.png"),
false); // FIXME mipmapping on desktop
cubemap.load(CubemapSide.NegativeX, root.child(name+"_NX.png"));
- if (lights.environmentCubemap == null)
+ if (!lights.has(CubemapAttribute.EnvironmentMap))
shaderProvider.clear();
- lights.environmentCubemap = cubemap;
+ lights.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
}
}
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Attribute;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.Shader;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.shaders.BaseShader;
import com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
-import com.badlogic.gdx.graphics.g3d.environment.Environment;
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;
import com.badlogic.gdx.graphics.g3d.shaders.GLES10Shader;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;