[changed] JoglGraphicsBase doesn't average the delta time anymore.
logConfig(config);\r
updatePpi();\r
\r
- Mesh.invalidateAllMeshes();\r
- Texture.invalidateAllTextures();\r
- ShaderProgram.invalidateAllShaderPrograms();\r
- FrameBuffer.invalidateAllFrameBuffers();\r
+ Mesh.invalidateAllMeshes(app);\r
+ Texture.invalidateAllTextures(app);\r
+ ShaderProgram.invalidateAllShaderPrograms(app);\r
+ FrameBuffer.invalidateAllFrameBuffers(app);\r
+ \r
+ Gdx.app.log("AndroidGraphics", Mesh.getManagedStatus());\r
+ Gdx.app.log("AndroidGraphics", Texture.getManagedStatus());\r
+ Gdx.app.log("AndroidGraphics", ShaderProgram.getManagedStatus());\r
+ Gdx.app.log("AndroidGraphics", FrameBuffer.getManagedStatus());\r
\r
Display display = app.getWindowManager().getDefaultDisplay();\r
this.width = display.getWidth();\r
} \r
\r
public void clearManagedCaches() {\r
- Mesh.clearAllMeshes();\r
- Texture.clearAllTextures();\r
- ShaderProgram.clearAllShaderPrograms();\r
- FrameBuffer.clearAllFrameBuffers();\r
+ Mesh.clearAllMeshes(app);\r
+ Texture.clearAllTextures(app);\r
+ ShaderProgram.clearAllShaderPrograms(app);\r
+ FrameBuffer.clearAllFrameBuffers(app);\r
+ \r
+ Gdx.app.log("AndroidGraphics", Mesh.getManagedStatus());\r
+ Gdx.app.log("AndroidGraphics", Texture.getManagedStatus());\r
+ Gdx.app.log("AndroidGraphics", ShaderProgram.getManagedStatus());\r
+ Gdx.app.log("AndroidGraphics", FrameBuffer.getManagedStatus());\r
}\r
\r
public View getView() {\r
boolean useGL2;\r
long frameStart = System.nanoTime();\r
long lastFrameTime = System.nanoTime();\r
- float deltaTime = 0;\r
- WindowedMean mean = new WindowedMean(10);\r
+ float deltaTime = 0; \r
int fps;\r
int frames;\r
boolean paused = true;\r
void create () {\r
frameStart = System.nanoTime();\r
lastFrameTime = frameStart;\r
- deltaTime = 0;\r
- mean.clear();\r
+ deltaTime = 0; \r
animator = new JoglAnimator(canvas);\r
// animator.setRunAsFastAsPossible(true);\r
animator.start();\r
paused = false;\r
frameStart = System.nanoTime();\r
lastFrameTime = frameStart;\r
- deltaTime = 0;\r
- mean.clear();\r
+ deltaTime = 0; \r
animator = new JoglAnimator(canvas);\r
animator.setRunAsFastAsPossible(true);\r
animator.start();\r
\r
void updateTimes () {\r
deltaTime = (System.nanoTime() - lastFrameTime) / 1000000000.0f;\r
- lastFrameTime = System.nanoTime();\r
- mean.addValue(deltaTime);\r
+ lastFrameTime = System.nanoTime(); \r
\r
if (System.nanoTime() - frameStart > 1000000000) {\r
fps = frames;\r
}\r
\r
@Override public float getDeltaTime () {\r
- return mean.getMean() == 0 ? deltaTime : mean.getMean();\r
+ return deltaTime;\r
}\r
\r
@Override public int getFramesPerSecond () {\r
import java.nio.FloatBuffer;\r
import java.nio.ShortBuffer;\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
\r
+import com.badlogic.gdx.Application;\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.graphics.VertexAttributes.Usage;\r
import com.badlogic.gdx.graphics.glutils.IndexBufferObject;\r
}\r
\r
/** list of all meshes **/\r
- static final ArrayList<Mesh> meshes = new ArrayList<Mesh>();\r
+ static final Map<Application, List<Mesh>> meshes = new HashMap<Application, List<Mesh>>();\r
\r
/** used for benchmarking **/\r
public static boolean forceVBO = false;\r
isVertexArray = true;\r
}\r
\r
- meshes.add(this);\r
+ addManagedMesh(Gdx.app, this);\r
}\r
\r
/**\r
isVertexArray = true;\r
}\r
\r
- meshes.add(this);\r
+ addManagedMesh(Gdx.app, this);\r
}\r
\r
/**\r
indices = new IndexBufferObject(maxIndices);\r
isVertexArray = true;\r
}\r
-\r
- meshes.add(this);\r
+ addManagedMesh(Gdx.app, this); \r
}\r
\r
/**\r
* Frees all resources associated with this Mesh\r
*/\r
public void dispose () {\r
- meshes.remove(this);\r
+ if(meshes.get(Gdx.app) != null) meshes.get(Gdx.app).remove(this);\r
vertices.dispose();\r
indices.dispose();\r
}\r
return indices.getBuffer();\r
}\r
\r
+ private static void addManagedMesh(Application app, Mesh mesh) {\r
+ List<Mesh> managedResources = meshes.get(app);\r
+ if(managedResources == null) managedResources = new ArrayList<Mesh>();\r
+ managedResources.add(mesh);\r
+ meshes.put(app, managedResources);\r
+ }\r
+ \r
/**\r
* Invalidates all meshes so the next time they are rendered new VBO handles are generated.\r
+ * @param app \r
*/\r
- public static void invalidateAllMeshes () {\r
-\r
- for (int i = 0; i < meshes.size(); i++) {\r
- if (meshes.get(i).vertices instanceof VertexBufferObject) {\r
- ((VertexBufferObject)meshes.get(i).vertices).invalidate();\r
- meshes.get(i).indices.invalidate();\r
+ public static void invalidateAllMeshes (Application app) {\r
+ List<Mesh> meshesList = meshes.get(app);\r
+ if(meshesList == null) return;\r
+ for (int i = 0; i < meshesList.size(); i++) {\r
+ if (meshesList.get(i).vertices instanceof VertexBufferObject) {\r
+ ((VertexBufferObject)meshesList.get(i).vertices).invalidate();\r
+ meshesList.get(i).indices.invalidate();\r
}\r
}\r
}\r
/**\r
* Will clear the managed mesh cache. I wouldn't use this if i was you :)\r
*/\r
- public static void clearAllMeshes () {\r
- meshes.clear();\r
+ public static void clearAllMeshes (Application app) { \r
+ meshes.remove(app);\r
+ }\r
+ \r
+ public static String getManagedStatus() {\r
+ StringBuilder builder = new StringBuilder();\r
+ int i = 0;\r
+ builder.append("Managed meshes/app: { ");\r
+ for(Application app: meshes.keySet()) {\r
+ builder.append(meshes.get(app).size());\r
+ builder.append(" ");\r
+ }\r
+ builder.append("}");\r
+ return builder.toString();\r
}\r
}\r
******************************************************************************/\r
package com.badlogic.gdx.graphics;\r
\r
-import java.nio.ByteBuffer;\r
import java.nio.IntBuffer;\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
\r
+import com.badlogic.gdx.Application;\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.files.FileHandle;\r
import com.badlogic.gdx.graphics.Pixmap.Blending;\r
}\r
\r
final static IntBuffer buffer = BufferUtils.newIntBuffer(1);\r
- final static ArrayList<Texture> managedTextures = new ArrayList<Texture>(); \r
+ final static Map<Application, List<Texture>> managedTextures = new HashMap<Application, List<Texture>>(); \r
\r
int width;\r
int height; \r
if(mipmap)\r
minFilter = TextureFilter.MipMap;\r
setFilter(minFilter, magFilter);\r
- setWrap(uWrap, vWrap);\r
- managedTextures.add(this);\r
+ setWrap(uWrap, vWrap); \r
+ addManagedTexture(Gdx.app, this);\r
}\r
\r
/**\r
minFilter = TextureFilter.MipMap;\r
setFilter(minFilter, magFilter);\r
setWrap(uWrap, vWrap);\r
- managedTextures.add(this);\r
+ addManagedTexture(Gdx.app, this);\r
}\r
\r
/**\r
format = Format.RGBA8888; // FIXME, let TextureData return the format upon load.\r
this.width = textureData.getWidth();\r
this.height = textureData.getHeight();\r
- managedTextures.add(this);\r
+ addManagedTexture(Gdx.app, this);\r
}\r
\r
private void reload() {\r
public void dispose () {\r
buffer.put(0, glHandle);\r
Gdx.gl.glDeleteTextures(1, buffer);\r
- if(isManaged)\r
- managedTextures.remove(this);\r
+ if(isManaged) {\r
+ if(managedTextures.get(Gdx.app) != null) managedTextures.get(Gdx.app).remove(this);\r
+ }\r
}\r
\r
/**\r
return GL10.GL_LINEAR_MIPMAP_LINEAR;\r
}\r
\r
+ private static void addManagedTexture(Application app, Texture texture) {\r
+ List<Texture> managedTexureList = managedTextures.get(app);\r
+ if(managedTexureList == null) managedTexureList = new ArrayList<Texture>();\r
+ managedTexureList.add(texture);\r
+ managedTextures.put(app, managedTexureList);\r
+ }\r
+ \r
/**\r
* Clears all managed textures. This is an internal method. Do not use it!\r
*/\r
- public static void clearAllTextures () {\r
- managedTextures.clear();\r
+ public static void clearAllTextures (Application app) {\r
+ managedTextures.remove(app);\r
}\r
\r
/**\r
* Invalidate all managed textures. This is an internal method. Do not use it!\r
*/\r
- public static void invalidateAllTextures () {\r
- for (int i = 0; i < managedTextures.size(); i++) { \r
- Texture texture = managedTextures.get(i); \r
+ public static void invalidateAllTextures (Application app) {\r
+ List<Texture> managedTexureList = managedTextures.get(app);\r
+ if(managedTexureList == null) return;\r
+ for (int i = 0; i < managedTexureList.size(); i++) { \r
+ Texture texture = managedTexureList.get(i); \r
texture.reload(); \r
} \r
}\r
\r
+ public static String getManagedStatus() {\r
+ StringBuilder builder = new StringBuilder();\r
+ int i = 0;\r
+ builder.append("Managed textures/app: { ");\r
+ for(Application app: managedTextures.keySet()) {\r
+ builder.append(managedTextures.get(app).size());\r
+ builder.append(" ");\r
+ }\r
+ builder.append("}");\r
+ return builder.toString();\r
+ }\r
+ \r
/**\r
* @return the {@link Format} of the Texture. For {@link TextureData} based textures this will always be RGBA8888.\r
*/\r
import java.nio.ByteOrder;\r
import java.nio.IntBuffer;\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
\r
+import com.badlogic.gdx.Application;\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.graphics.GL20;\r
+import com.badlogic.gdx.graphics.Mesh;\r
import com.badlogic.gdx.graphics.Pixmap;\r
import com.badlogic.gdx.graphics.Texture;\r
import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
*/\r
public class FrameBuffer implements Disposable {\r
/** the frame buffers **/\r
- private final static ArrayList<FrameBuffer> buffers = new ArrayList<FrameBuffer>();\r
+ private final static Map<Application, List<FrameBuffer>> buffers = new HashMap<Application, List<FrameBuffer>>();\r
\r
/** the color buffer texture **/\r
private Texture colorTexture;\r
this.format = format;\r
build();\r
\r
- buffers.add(this);\r
+ addManagedFrameBuffer(Gdx.app, this);\r
}\r
\r
private void build () {\r
handle.flip();\r
gl.glDeleteFramebuffers(1, handle);\r
\r
- buffers.remove(this);\r
+ if(buffers.get(Gdx.app) != null) buffers.get(Gdx.app).remove(this);\r
}\r
\r
/**\r
Gdx.graphics.getGL20().glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);\r
}\r
\r
+ private void addManagedFrameBuffer (Application app, FrameBuffer frameBuffer) {\r
+ List<FrameBuffer> managedResources = buffers.get(app);\r
+ if(managedResources == null) managedResources = new ArrayList<FrameBuffer>();\r
+ managedResources.add(frameBuffer);\r
+ buffers.put(app, managedResources);\r
+ }\r
+ \r
/**\r
* Invalidates all frame buffers. This can be used when the OpenGL context is lost to rebuild all managed frame buffers. This\r
* assumes that the texture attached to this buffer has already been rebuild! Use with care.\r
*/\r
- public static void invalidateAllFrameBuffers () {\r
+ public static void invalidateAllFrameBuffers (Application app) {\r
if (Gdx.graphics.getGL20() == null) return;\r
\r
- for (int i = 0; i < buffers.size(); i++) {\r
- buffers.get(i).build();\r
+ List<FrameBuffer> bufferList = buffers.get(app);\r
+ if(bufferList == null) return; \r
+ for (int i = 0; i < bufferList.size(); i++) {\r
+ bufferList.get(i).build();\r
}\r
}\r
\r
- public static void clearAllFrameBuffers () {\r
- buffers.clear();\r
+ public static void clearAllFrameBuffers (Application app) {\r
+ buffers.remove(app);\r
+ }\r
+ \r
+ public static String getManagedStatus() {\r
+ StringBuilder builder = new StringBuilder();\r
+ int i = 0;\r
+ builder.append("Managed buffers/app: { ");\r
+ for(Application app: buffers.keySet()) {\r
+ builder.append(buffers.get(app).size());\r
+ builder.append(" ");\r
+ }\r
+ builder.append("}");\r
+ return builder.toString();\r
}\r
\r
/**\r
import java.nio.FloatBuffer;\r
import java.nio.IntBuffer;\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
\r
+import com.badlogic.gdx.Application;\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.graphics.GL20;\r
import com.badlogic.gdx.graphics.Mesh;\r
public static boolean pedantic = true;\r
\r
/** the list of currently available shaders **/\r
- private final static ArrayList<ShaderProgram> shaders = new ArrayList<ShaderProgram>();\r
+ private final static Map<Application, List<ShaderProgram>> shaders = new HashMap<Application, List<ShaderProgram>>();\r
\r
/** the log **/\r
private String log = "";\r
ByteBuffer buffer = ByteBuffer.allocateDirect(4 * 16);\r
buffer.order(ByteOrder.nativeOrder());\r
matrix = buffer.asFloatBuffer();\r
- shaders.add(this);\r
+ addManagedShader(Gdx.app, this);\r
}\r
\r
/**\r
gl.glDeleteShader(vertexShaderHandle);\r
gl.glDeleteShader(fragmentShaderHandle);\r
gl.glDeleteProgram(program);\r
- shaders.remove(this);\r
+ if(shaders.get(Gdx.app) != null) shaders.get(Gdx.app).remove(this);\r
}\r
\r
/**\r
}\r
}\r
\r
+ private void addManagedShader (Application app, ShaderProgram shaderProgram) {\r
+ List<ShaderProgram> managedResources = shaders.get(app);\r
+ if(managedResources == null) managedResources = new ArrayList<ShaderProgram>();\r
+ managedResources.add(shaderProgram);\r
+ shaders.put(app, managedResources);\r
+ }\r
+ \r
/**\r
* Invalidates all shaders so the next time they are used new handles are generated\r
+ * @param app \r
*/\r
- public static void invalidateAllShaderPrograms () {\r
+ public static void invalidateAllShaderPrograms (Application app) {\r
if (Gdx.graphics.getGL20() == null) return;\r
\r
- for (int i = 0; i < shaders.size(); i++) {\r
- shaders.get(i).invalidated = true;\r
- shaders.get(i).checkManaged();\r
+ List<ShaderProgram> shaderList = shaders.get(app);\r
+ if(shaderList == null) return;\r
+ \r
+ for (int i = 0; i < shaderList.size(); i++) {\r
+ shaderList.get(i).invalidated = true;\r
+ shaderList.get(i).checkManaged();\r
}\r
}\r
\r
- public static void clearAllShaderPrograms () {\r
- shaders.clear();\r
+ public static void clearAllShaderPrograms (Application app) {\r
+ shaders.remove(app);\r
+ }\r
+ \r
+ public static String getManagedStatus() {\r
+ StringBuilder builder = new StringBuilder();\r
+ int i = 0;\r
+ builder.append("Managed shaders/app: { ");\r
+ for(Application app: shaders.keySet()) {\r
+ builder.append(shaders.get(app).size());\r
+ builder.append(" ");\r
+ }\r
+ builder.append("}");\r
+ return builder.toString();\r
}\r
\r
/**\r
MeshShaderTest.class,\r
MeshTest.class, \r
//Mpg123Test.class,\r
- MultitouchTest.class,\r
+ MultitouchTest.class, \r
MusicTest.class,\r
MyFirstTriangle.class,\r
ObjTest.class,\r