Difference between revisions of "Reducing memory usage"

From JPCT
Jump to: navigation, search
(Created page with '=== Reducing memory usage === Android devices are much more limited devices than the usual desktop PC when it comes to memory. This page will explain some ways to reduce the mem…')
 
Line 2: Line 2:
  
 
Android devices are much more limited devices than the usual desktop PC when it comes to memory. This page will explain some ways to reduce the memory usage of a jPCT-AE powered application.
 
Android devices are much more limited devices than the usual desktop PC when it comes to memory. This page will explain some ways to reduce the memory usage of a jPCT-AE powered application.
 +
  
 
==== Watch your content ====
 
==== Watch your content ====
Line 28: Line 29:
  
 
This in an experimental feature which can be found in some alpha versions. Ignore it for now.
 
This in an experimental feature which can be found in some alpha versions. Ignore it for now.
 +
 +
 +
==== Reduce animation size ====
 +
 +
Keyframe animations are fast and simple to use, but require a lot of memory. However, there are some ways to reduce this.
 +
 +
===== Compress meshes =====
 +
 +
If you create your keyframe animation out of individual meshes (and not by loading a MD2 file), it can help a little to compress the mesh. You can either do this by letting cloneMesh(true) ([http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Mesh.html#cloneMesh(boolean)]) do this for you or by calling compress() ([http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Mesh.html#compress()]) on the mesh yourself.
 +
 +
===== Strip meshes =====
 +
 +
You can safely remove triangle information from a mesh if it's used for animations only. If it isn't, you should make a clone of it anyway, so actually, this applies in every case. A call to strip() ([http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Mesh.html#strip()]) does this for you.

Revision as of 10:37, 22 July 2011

Reducing memory usage

Android devices are much more limited devices than the usual desktop PC when it comes to memory. This page will explain some ways to reduce the memory usage of a jPCT-AE powered application.


Watch your content

Check your models and textures to make sure that they aren't overly complex. You might want to lower texture resolution of vertex/polygon count of your mesh to save memory. Keep in mind that for textures, the compressed size matters...not the size that the file has on disk. I.e. a 32bit 512*512 texture needs 512*512=262144*4=1048576 (1MB). A 256*256 texture of the same depth only uses one quarter of that. In addition, the texture is stored twice by default, one copy remains in main memory while one will be uploaded to the GPU (you can disable this behaviour at the cost of not being able to recover from a pause or stop event then without reloading everything from scratch).


Reduce texture memory usage

As said, smaller textures need less memory. If this still doesn't help, there are ways to reduce memory usage somewhat further.

Use 16bit textures instead of 32bit ones

It might be sufficient to use 16bit textures (at least for some textures) instead of 32bit ones. These textures use only half the memory on the GPU and might also help to increase performance. To make a single texture use 16bit (i.e. 4 bits per pixel), so can use [1]. If you want all textures to be handle that way by default, [2] is your friend. Keep in mind that using this option increaes color banding in the textures and it doesn't look good on all textures.

Compress the in-memory copy of the texture data

By default, jPCT-AE keeps a copy of the pixel data of a texture in main memory to handle pause/stop events, which destroy the gl content, i.e. all textures uploaded to the GPU. You can trade memory usage for upload performance by compressing this in-memory copy. Simple call [3] to enable this feature. Please note that this causes an little memory peak when uploading the compressed texture, because it has to be decompressed first.

Avoid mip-map generation on textures that don't need it

You should use mip-mapping ([4]) to improve image quality and avoid texture flickering. However, some textures just don't need it. For example uni-colored textures or textures used for blitting only. You can safely disable mip-mapping for these textures to save some memory.

Use texture ETC1-compression

This in an experimental feature which can be found in some alpha versions. Ignore it for now.


Reduce animation size

Keyframe animations are fast and simple to use, but require a lot of memory. However, there are some ways to reduce this.

Compress meshes

If you create your keyframe animation out of individual meshes (and not by loading a MD2 file), it can help a little to compress the mesh. You can either do this by letting cloneMesh(true) ([5]) do this for you or by calling compress() ([6]) on the mesh yourself.

Strip meshes

You can safely remove triangle information from a mesh if it's used for animations only. If it isn't, you should make a clone of it anyway, so actually, this applies in every case. A call to strip() ([7]) does this for you.