OSDN Git Service

Rename TestShader to DefaultShader and move to .shaders package, move Light and add...
authorXoppa <contact@xoppa.nl>
Mon, 1 Apr 2013 22:00:07 +0000 (00:00 +0200)
committerXoppa <contact@xoppa.nl>
Mon, 1 Apr 2013 22:00:07 +0000 (00:00 +0200)
17 files changed:
demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/Renderer.java
gdx/src/com/badlogic/gdx/graphics/g3d/Light.java [new file with mode: 0644]
gdx/src/com/badlogic/gdx/graphics/g3d/ModelBatch.java
gdx/src/com/badlogic/gdx/graphics/g3d/Renderable.java
gdx/src/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.java [moved from gdx/src/com/badlogic/gdx/graphics/g3d/test/TestShader.java with 91% similarity]
gdx/src/com/badlogic/gdx/graphics/g3d/shaders/GLES10Shader.java [moved from gdx/src/com/badlogic/gdx/graphics/g3d/test/GLES10Shader.java with 98% similarity]
gdx/src/com/badlogic/gdx/graphics/g3d/shaders/default.fragment.glsl [moved from gdx/src/com/badlogic/gdx/graphics/g3d/test/test.fragment.glsl with 100% similarity]
gdx/src/com/badlogic/gdx/graphics/g3d/shaders/default.vertex.glsl [moved from gdx/src/com/badlogic/gdx/graphics/g3d/test/test.vertex.glsl with 100% similarity]
gdx/src/com/badlogic/gdx/graphics/g3d/test/Light.java [deleted file]
gdx/src/com/badlogic/gdx/graphics/g3d/utils/DefaultShaderProvider.java
tests/gdx-tests/src/com/badlogic/gdx/tests/CullTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/EdgeDetectionTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/BaseBulletTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/BaseWorld.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/BulletWorld.java
tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/BatchRenderTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/NewModelTest.java

index 8dfdd16..064f580 100644 (file)
@@ -30,7 +30,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
 import com.badlogic.gdx.graphics.g3d.ModelBatch;\r
 import com.badlogic.gdx.graphics.g3d.RenderableProvider;\r
-import com.badlogic.gdx.graphics.g3d.test.TestShader;\r
+import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;\r
 import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
 import com.badlogic.gdx.math.Matrix3;\r
 import com.badlogic.gdx.math.Matrix4;\r
@@ -78,7 +78,7 @@ public class Renderer {
                try {\r
                        spriteBatch = new SpriteBatch();\r
                        modelBatch = new ModelBatch();\r
-                       TestShader.ignoreUnimplemented = true;\r
+                       DefaultShader.ignoreUnimplemented = true;\r
 \r
                        backgroundTexture = new Texture(Gdx.files.internal("data/planet.jpg"), Format.RGB565, true);\r
                        backgroundTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);\r
diff --git a/gdx/src/com/badlogic/gdx/graphics/g3d/Light.java b/gdx/src/com/badlogic/gdx/graphics/g3d/Light.java
new file mode 100644 (file)
index 0000000..198f4e8
--- /dev/null
@@ -0,0 +1,72 @@
+package com.badlogic.gdx.graphics.g3d;
+
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.math.Vector3;
+
+public class Light {
+       public final Color color = new Color();
+       public Vector3 position;
+       public Vector3 direction;
+       public float angle = 0f;
+       public float power = 1f;
+       
+       /** Create a new directional light */
+       public Light(final Color color, final Vector3 direction) {
+               this.color.set(color);
+               this.direction = new Vector3(direction);
+       }
+       
+       /** Create a new directional light */
+       public Light(float r, float g, float b, float a, float x, float y, float z) {
+               this.color.set(r, g, b, a);
+               this.direction = new Vector3(x, y, z);
+       }
+       
+       /** Create a new point light */
+       public Light(final Color color, final Vector3 position, final float power) {
+               this(color.r, color.g, color.b, color.a, position.x, position.y, position.z, power);
+       }
+       
+       /** Create a new point light */
+       public Light(final float red, final float green, final float blue, final float alpha, 
+                                       final float x, final float y, final float z, final float power) {
+               color.set(red, green, blue, alpha);
+               this.position = new Vector3(x, y, z);
+               this.power = power;
+       }
+       
+       /** Create a new spot light */
+       public Light(final Color color, final Vector3 position, final Vector3 direction, final float angle, final float power) {
+               this.color.set(color);
+               this.position = new Vector3(position);
+               this.direction = new Vector3(direction);
+               this.angle = angle;
+               this.power = power;
+       }
+       
+       public boolean equals(Light other) {
+               if (other == null) return false;
+               if (other == this) return true;
+               return color.equals(other.color) && position.equals(other.position) && power == other.power;
+       }
+       
+       @Override
+       public boolean equals (Object arg0) {
+               if (arg0 == null) return false;
+               if (arg0 == this) return true;
+               if (!(arg0 instanceof Light)) return false;
+               return equals((Light)arg0);
+       }
+       
+       public boolean isPointLight() {
+               return position != null && direction == null;
+       }
+       
+       public boolean isDirectionalLight() {
+               return position == null && direction != null;
+       }
+       
+       public boolean isSpotLight() {
+               return position != null && direction != null;
+       }
+}
index c8ff7f3..748647a 100644 (file)
@@ -2,7 +2,6 @@ package com.badlogic.gdx.graphics.g3d;
 
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.Camera;
-import com.badlogic.gdx.graphics.g3d.test.Light;
 import com.badlogic.gdx.graphics.g3d.utils.DefaultRenderableSorter;
 import com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider;
 import com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder;
index 3eac87c..8141626 100644 (file)
@@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.GL20;
 import com.badlogic.gdx.graphics.Mesh;
 import com.badlogic.gdx.graphics.g3d.materials.Material;
 import com.badlogic.gdx.graphics.g3d.model.Node;
-import com.badlogic.gdx.graphics.g3d.test.Light;
 import com.badlogic.gdx.math.Matrix4;
 
 /**
@@ -1,9 +1,10 @@
-package com.badlogic.gdx.graphics.g3d.test;
+package com.badlogic.gdx.graphics.g3d.shaders;
 
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.Camera;
 import com.badlogic.gdx.graphics.GL10;
 import com.badlogic.gdx.graphics.Mesh;
+import com.badlogic.gdx.graphics.g3d.Light;
 import com.badlogic.gdx.graphics.g3d.Renderable;
 import com.badlogic.gdx.graphics.g3d.Shader;
 import com.badlogic.gdx.graphics.g3d.materials.BlendingAttribute;
@@ -16,7 +17,7 @@ import com.badlogic.gdx.math.Matrix3;
 import com.badlogic.gdx.math.Matrix4;
 import com.badlogic.gdx.utils.GdxRuntimeException;
 
-public class TestShader implements Shader {
+public class DefaultShader implements Shader {
        public final static String PROJECTION_TRANSFORM = "u_projTrans";
        public final static String MODEL_TRANSFORM = "u_modelTrans";
        public final static String NORMAL_TRANSFORM = "u_normalMatrix";
@@ -24,14 +25,14 @@ public class TestShader implements Shader {
        private static String defaultVertexShader = null;
        public final static String getDefaultVertexShader() {
                if (defaultVertexShader == null)
-                       defaultVertexShader = Gdx.files.classpath("com/badlogic/gdx/graphics/g3d/test/test.vertex.glsl").readString();
+                       defaultVertexShader = Gdx.files.classpath("com/badlogic/gdx/graphics/g3d/shaders/default.vertex.glsl").readString();
                return defaultVertexShader;
        }
        
        private static String defaultFragmentShader = null;
        public final static String getDefaultFragmentShader() {
                if (defaultFragmentShader == null)
-                       defaultFragmentShader = Gdx.files.classpath("com/badlogic/gdx/graphics/g3d/test/test.fragment.glsl").readString();
+                       defaultFragmentShader = Gdx.files.classpath("com/badlogic/gdx/graphics/g3d/shaders/default.fragment.glsl").readString();
                return defaultFragmentShader;
        }
 
@@ -54,19 +55,19 @@ public class TestShader implements Shader {
        protected RenderContext context;
        protected long mask;
        
-       public TestShader(final Material material, int maxLightsCount) {
+       public DefaultShader(final Material material, int maxLightsCount) {
                this(getDefaultVertexShader(), getDefaultFragmentShader(), material, maxLightsCount);
        }
        
-       public TestShader(final long mask, int maxLightsCount) {
+       public DefaultShader(final long mask, int maxLightsCount) {
                this(getDefaultVertexShader(), getDefaultFragmentShader(), mask, maxLightsCount);
        }
 
-       public TestShader(final String vertexShader, final String fragmentShader, final Material material, int maxLightsCount) {
+       public DefaultShader(final String vertexShader, final String fragmentShader, final Material material, int maxLightsCount) {
                this(vertexShader, fragmentShader, material.getMask(), maxLightsCount);
        }
        
-       public TestShader(final String vertexShader, final String fragmentShader, final long mask, int maxLightsCount) {
+       public DefaultShader(final String vertexShader, final String fragmentShader, final long mask, int maxLightsCount) {
                if (!Gdx.graphics.isGL20Available())
                        throw new GdxRuntimeException("This shader requires OpenGL ES 2.0");
                
@@ -120,10 +121,10 @@ public class TestShader implements Shader {
        
        @Override
        public boolean equals (Object obj) {
-               return (obj instanceof TestShader) ? equals((TestShader)obj) : false;
+               return (obj instanceof DefaultShader) ? equals((DefaultShader)obj) : false;
        }
        
-       public boolean equals (TestShader obj) {
+       public boolean equals (DefaultShader obj) {
                return (obj == this);
        }
 
@@ -1,4 +1,4 @@
-package com.badlogic.gdx.graphics.g3d.test;
+package com.badlogic.gdx.graphics.g3d.shaders;
 
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.Camera;
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Color;
 import com.badlogic.gdx.graphics.GL10;
 import com.badlogic.gdx.graphics.Mesh;
 import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g3d.Light;
 import com.badlogic.gdx.graphics.g3d.Renderable;
 import com.badlogic.gdx.graphics.g3d.Shader;
 import com.badlogic.gdx.graphics.g3d.materials.BlendingAttribute;
diff --git a/gdx/src/com/badlogic/gdx/graphics/g3d/test/Light.java b/gdx/src/com/badlogic/gdx/graphics/g3d/test/Light.java
deleted file mode 100644 (file)
index 780386d..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.badlogic.gdx.graphics.g3d.test;
-
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.math.Vector3;
-
-public class Light {
-       public final Color color = new Color();
-       public final Vector3 position = new Vector3();
-       public float power = 1f;
-       
-       public Light(final Color color, final Vector3 position, final float power) {
-               this(color.r, color.g, color.b, color.a, position.x, position.y, position.z, power);
-       }
-       
-       public Light(final float red, final float green, final float blue, final float alpha, 
-                                       final float x, final float y, final float z, final float power) {
-               color.set(red, green, blue, alpha);
-               position.set(x, y, z);
-               this.power = power;
-       }
-       
-       public boolean equals(Light other) {
-               if (other == null) return false;
-               if (other == this) return true;
-               return color.equals(other.color) && position.equals(other.position) && power == other.power;
-       }
-       
-       @Override
-       public boolean equals (Object arg0) {
-               if (arg0 == null) return false;
-               if (arg0 == this) return true;
-               if (!(arg0 instanceof Light)) return false;
-               return equals((Light)arg0);
-       }
-}
index c89577f..ab2477b 100644 (file)
@@ -4,8 +4,8 @@ import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.g3d.Renderable;
 import com.badlogic.gdx.graphics.g3d.Shader;
 import com.badlogic.gdx.graphics.g3d.materials.Material;
-import com.badlogic.gdx.graphics.g3d.test.GLES10Shader;
-import com.badlogic.gdx.graphics.g3d.test.TestShader;
+import com.badlogic.gdx.graphics.g3d.shaders.GLES10Shader;
+import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;
 import com.badlogic.gdx.utils.Array;
 
 public class DefaultShaderProvider extends BaseShaderProvider {
@@ -15,7 +15,7 @@ public class DefaultShaderProvider extends BaseShaderProvider {
        protected Shader createShader(final Renderable renderable) {
                Gdx.app.log("DefaultShaderProvider", "Creating new shader");
                if (Gdx.graphics.isGL20Available())
-                       return new TestShader(renderable.material, renderable.lights == null ? -1 : maxLightsCount);
+                       return new DefaultShader(renderable.material, renderable.lights == null ? -1 : maxLightsCount);
                return new GLES10Shader(maxLightsCount);
        }
 }
index 561a1ce..3cb5945 100644 (file)
@@ -37,7 +37,7 @@ import com.badlogic.gdx.graphics.g3d.ModelBatch;
 import com.badlogic.gdx.graphics.g3d.ModelInstance;\r
 import com.badlogic.gdx.graphics.g3d.materials.ColorAttribute;\r
 import com.badlogic.gdx.graphics.g3d.materials.Material;\r
-import com.badlogic.gdx.graphics.g3d.test.TestShader;\r
+import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;\r
 import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;\r
 import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
 import com.badlogic.gdx.math.Vector3;\r
index 50d80b4..b407f3c 100644 (file)
@@ -30,7 +30,7 @@ import com.badlogic.gdx.graphics.g3d.Model;
 import com.badlogic.gdx.graphics.g3d.ModelBatch;\r
 import com.badlogic.gdx.graphics.g3d.ModelInstance;\r
 import com.badlogic.gdx.graphics.g3d.loader.ObjLoader;\r
-import com.badlogic.gdx.graphics.g3d.test.TestShader;\r
+import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;\r
 import com.badlogic.gdx.graphics.glutils.FrameBuffer;\r
 import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
 import com.badlogic.gdx.math.Matrix4;\r
@@ -72,7 +72,7 @@ public class EdgeDetectionTest extends GdxTest {
                        Gdx.app.log("EdgeDetectionTest", "couldn't compile post-processing shader: " + batchShader.getLog());\r
                }\r
 \r
-               TestShader.ignoreUnimplemented = true;\r
+               DefaultShader.ignoreUnimplemented = true;\r
                ObjLoader objLoader = new ObjLoader();\r
                scene = objLoader.loadObj(Gdx.files.internal("data/scene.obj"));\r
                sceneInstance = new ModelInstance(scene);\r
index 919cfd1..76282f5 100644 (file)
@@ -26,6 +26,7 @@ import com.badlogic.gdx.graphics.PerspectiveCamera;
 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.Light;
 import com.badlogic.gdx.graphics.g3d.Model;
 import com.badlogic.gdx.graphics.g3d.ModelBatch;
 import com.badlogic.gdx.graphics.g3d.loader.ObjLoader;
@@ -37,8 +38,7 @@ import com.badlogic.gdx.graphics.g3d.model.data.ModelMesh;
 import com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart;
 import com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPartMaterial;
 import com.badlogic.gdx.graphics.g3d.model.data.ModelNode;
-import com.badlogic.gdx.graphics.g3d.test.Light;
-import com.badlogic.gdx.graphics.g3d.test.TestShader;
+import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;
 import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
 import com.badlogic.gdx.graphics.glutils.ShaderProgram;
 import com.badlogic.gdx.math.Quaternion;
@@ -91,7 +91,7 @@ public class BaseBulletTest extends BulletTest {
        public void create () {
                init();
                modelBatch = new ModelBatch();
-               TestShader.ignoreUnimplemented = true;
+               DefaultShader.ignoreUnimplemented = true;
                
                world = createWorld();
                world.performanceCounter = performanceCounter;
index 9d9b142..09bd796 100644 (file)
@@ -20,9 +20,9 @@ import com.badlogic.gdx.graphics.Camera;
 import com.badlogic.gdx.graphics.Color;
 import com.badlogic.gdx.graphics.GL10;
 import com.badlogic.gdx.graphics.Mesh;
+import com.badlogic.gdx.graphics.g3d.Light;
 import com.badlogic.gdx.graphics.g3d.Model;
 import com.badlogic.gdx.graphics.g3d.ModelBatch;
-import com.badlogic.gdx.graphics.g3d.test.Light;
 import com.badlogic.gdx.math.Matrix4;
 import com.badlogic.gdx.utils.Array;
 import com.badlogic.gdx.utils.Disposable;
index b679585..93248bb 100644 (file)
@@ -16,8 +16,8 @@
 package com.badlogic.gdx.tests.bullet;
 
 import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.g3d.Light;
 import com.badlogic.gdx.graphics.g3d.ModelBatch;
-import com.badlogic.gdx.graphics.g3d.test.Light;
 import com.badlogic.gdx.math.Matrix4;
 import com.badlogic.gdx.math.Vector3;
 import com.badlogic.gdx.math.WindowedMean;
index 5e4f20d..9ddb5ba 100644 (file)
@@ -6,13 +6,13 @@ import com.badlogic.gdx.graphics.GL10;
 import com.badlogic.gdx.graphics.GL20;
 import com.badlogic.gdx.graphics.PerspectiveCamera;
 import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g3d.Light;
 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.loader.JsonModelLoader;
 import com.badlogic.gdx.graphics.g3d.loader.ObjLoader;
-import com.badlogic.gdx.graphics.g3d.test.Light;
-import com.badlogic.gdx.graphics.g3d.test.TestShader;
+import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;
 import com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder;
 import com.badlogic.gdx.math.Matrix4;
 import com.badlogic.gdx.math.Vector3;
@@ -48,7 +48,7 @@ public class BatchRenderTest extends GdxTest {
        
        @Override
        public void create () {
-               TestShader.ignoreUnimplemented = true;
+               DefaultShader.ignoreUnimplemented = true;
                
                final JsonModelLoader loader = new JsonModelLoader();
 
index aebcfb7..3f4e8a4 100644 (file)
@@ -4,12 +4,12 @@ import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.Color;
 import com.badlogic.gdx.graphics.GL10;
 import com.badlogic.gdx.graphics.PerspectiveCamera;
+import com.badlogic.gdx.graphics.g3d.Light;
 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.loader.JsonModelLoader;
-import com.badlogic.gdx.graphics.g3d.test.Light;
-import com.badlogic.gdx.graphics.g3d.test.TestShader;
+import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;
 import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
 import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
 import com.badlogic.gdx.math.Matrix4;
@@ -38,7 +38,7 @@ public class NewModelTest extends GdxTest {
                model = new Model(loader.parseModel(Gdx.files.internal("data/g3d/cubes.g3dj")));
                instance = new ModelInstance(model);
                modelBatch = new ModelBatch();
-               TestShader.ignoreUnimplemented = true;
+               DefaultShader.ignoreUnimplemented = true;
                shapeRenderer = new ShapeRenderer();
                
                cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());