OSDN Git Service

added proper disposal of things, need to fix Model#dispose, attribuets may have dispo...
authorbadlogic <badlogicgames@gmail.com>
Sun, 24 Mar 2013 18:38:39 +0000 (19:38 +0100)
committerbadlogic <badlogicgames@gmail.com>
Sun, 24 Mar 2013 18:38:39 +0000 (19:38 +0100)
gdx/src/com/badlogic/gdx/graphics/g3d/Model.java
gdx/src/com/badlogic/gdx/graphics/g3d/ModelBatch.java
gdx/src/com/badlogic/gdx/graphics/g3d/Shader.java
gdx/src/com/badlogic/gdx/graphics/g3d/test/TestShader.java
gdx/src/com/badlogic/gdx/graphics/g3d/utils/DefaultShaderProvider.java
tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/NewModelTest.java

index 58226d9..5adb051 100644 (file)
@@ -30,6 +30,7 @@ import com.badlogic.gdx.graphics.g3d.utils.TextureProvider;
 import com.badlogic.gdx.graphics.g3d.utils.TextureProvider.FileTextureProvider;
 import com.badlogic.gdx.utils.Array;
 import com.badlogic.gdx.utils.BufferUtils;
+import com.badlogic.gdx.utils.Disposable;
 import com.badlogic.gdx.utils.ObjectMap;
 import com.badlogic.gdx.utils.Pool;
 
@@ -47,7 +48,7 @@ import com.badlogic.gdx.utils.Pool;
  * @author badlogic
  *
  */
-public class Model {
+public class Model implements Disposable {
        /** the meshes of the model **/
        public Array<Mesh> meshes = new Array<Mesh>();
        /** parts of meshes, used by nodes that have a graphical representation FIXME not sure if superfluous, stored in Nodes as well, could be useful to create bullet meshes **/
@@ -253,4 +254,14 @@ public class Model {
                        node.calculateTransforms(true);
                }
        }
+
+       @Override
+       public void dispose () {
+               for(Mesh mesh: meshes) {
+                       mesh.dispose();
+               }
+               for(NewMaterial material: materials) {
+                       // FIXME dispose textures! attribtue should probably be disposable, can decide whether it wants to get rid of resource or not
+               }
+       }
 }
\ No newline at end of file
index 643bc78..eaf8f14 100644 (file)
@@ -8,9 +8,10 @@ import com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder;
 import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
 import com.badlogic.gdx.math.Matrix4;
 import com.badlogic.gdx.utils.Array;
+import com.badlogic.gdx.utils.Disposable;
 import com.badlogic.gdx.utils.Pool;
 
-public class ModelBatch {
+public class ModelBatch implements Disposable {
        protected Camera camera;
        protected final Pool<Renderable> renderablesPool = new Pool<Renderable>() {
                @Override
@@ -98,4 +99,9 @@ public class ModelBatch {
                        reuseableRenderables.add(renderable);
                }
        }
+
+       @Override
+       public void dispose () {
+               shaderProvider.dispose();
+       }
 }
index b4b2bb0..5c4dd15 100644 (file)
@@ -2,8 +2,9 @@ package com.badlogic.gdx.graphics.g3d;
 
 import com.badlogic.gdx.graphics.Camera;
 import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
+import com.badlogic.gdx.utils.Disposable;
 
-public interface Shader {
+public interface Shader extends Disposable {
        int compareTo(Shader other); // TODO: probably better to add some weight value to sort on
        boolean canRender(Renderable instance);
        void begin(Camera camera, RenderContext context);
index babf76d..1b266c4 100644 (file)
@@ -227,4 +227,9 @@ public class TestShader implements Shader {
                        }
                }
        }
+
+       @Override
+       public void dispose () {
+               program.dispose();
+       }
 }
index 02ba015..8acfb00 100644 (file)
@@ -33,5 +33,8 @@ public class DefaultShaderProvider implements ShaderProvider {
 
        @Override
        public void dispose () {
+               for(Shader shader: shaders) {
+                       shader.dispose();
+               }
        }
 }
index 09a14d8..94af79e 100644 (file)
@@ -67,6 +67,12 @@ public class NewModelTest extends GdxTest {
                modelBatch.addModel(model, transform, lights);
                modelBatch.end();
        }
+       
+       @Override
+       public void dispose () {
+               model.dispose();
+               modelBatch.dispose();
+       }
 
        @Override
        public boolean touchDown (int x, int y, int pointer, int newParam) {