Reducing memory usage
- 1 Reducing memory usage
- 1.1 Watch your content
- 1.2 Reduce texture memory usage
- 1.3 Reduce animation size
- 1.4 Reduce memory usage of objects
Reducing memory usage
Android devices are much more limited devices than the usual desktop PC is 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 . If you want all textures to be handle that way by default,  is your friend. Keep in mind that using this option increases 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  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 () 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.
Reduce the number of keyframes
Your animation might look good enough with less keyframes. Just give it a try.
Remove animation sequences
A MD2-file usually contains a large set of animation sequences that you might not need in your application. You can remove them by calling .
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) () do this for you or by calling compress() () on the mesh yourself.
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() () does this for you.
Reduce memory usage of objects
If you don't want to modify an object at runtime, you can strip it to save some memory by calling strip() ().
If an object is used multiple times at once in an application (like bullets, multiple enemies...), you shouldn't load them multiple times but create clones of existing objects. This can be done by either calling cloneObject () or by using an appropriate constructor of Object3D.
In addition to sharing meshes in the vm's memory, you can also enable this for the data on the GPU. shareCompiledData() () is your friend here. This can also be used to make one animation call animate dozens of instances.