How to use 2048 * 1024 texture on a sphere?

Started by hisong, September 21, 2011, 08:50:28 AM

Previous topic - Next topic

hisong

I was trying to use larger than 1024x1024 textures on a sphere I get from a 3ds file.

But an error of "Out of Memory" occurs during the the program is beginning to run.

And if I use the BitmapHelper to rescale the image to 1024*1024,  It works well.


Bitmap bitmap = BitmapHelper.rescale(BitmapFactory
.decodeFile("/sdcard/jpct/hd.jpg"), 1024, 1024);
// Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/jpct/hd.jpg");
Texture texture = new Texture(bitmap);
bitmap.recycle();

TextureManager.getInstance().addTexture("texture", texture);


Dose JPCT-AE not support the 2048*1024 or higher??

ps:I can use Opengl ES to load an image of 2048 * 1024 resolution. and of cause it work well and smoothly.

Thanks for help~~

EgonOlsen

Well...just do the math. 2048*1024 requires 8mb of memory for it's pixel data. Plus maybe ~4mb for the mipmaps. Plus you have to upload it to the gpu, which doubles memory usage. Combine that with a VM that has around 16-20mb available for all the data and you end up in an out of memory-situation. 2048*1024 is ridicilously high for a mobile device anyway IMHO. Why do you want to use such a large texture? Apart from all that, try to use square textures, because ES2.0 has problems with non-square textures on some devices.

The engine itself supports up to 8192*8192. There's just no hardware that could handle that ATM.

Edit: More info: http://www.jpct.net/wiki/index.php/Reducing_memory_usage

K24A3

Try to keep the textures at 512x512 to increase compatibility. If you set to minimum SDK to Android 2.2 then you can generally be safe using 1024x1024 textures. I wouldn't go higher than that unless you are specifically targeting Honeycomb tablets.

hisong

Thanks for replying so quickly. :)

I use such a large image so I can view  in a  360 degree panoramic scene more  clearly. 

And the image has a size of 200KB, I am confused that why it costs  8MB of memory? 

what I can do if I want to use such a big file with JPCT-AE instead of compressing the resolution?

hisong

#4
and what does the JPCT-AE base on ? 

If it is base on Opengl ES 1.0 or 1.1, I think it would  support  2048*1024 resolution file for I doing a test with Opengl ES1.0.

EgonOlsen

1.23 is based on 1.0/1.1. 1.24 (alpha) has additional support for 2.0. If you don't want to switch to 2.0 sometimes with this app, you won't run into problems.
   
8mb=2048*1024*4 (as written in the wiki: File size doesn't matter). You can try to save some memory by using the tips that i wrote in the wiki (link in the post above). If that doesn't help, it just won't work.

K24A3

Each type/model of Graphics Chip (GPU) has it's own maximum texture size, so you should check the size before creating large textures.

To query the texture size, call glGetIntegerv() in your main Activity's GLSurfaceView.Renderer class. You need a pointer to GL10 so you could place it in onSurfaceCreated().


public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Do nothing special.
int[] maxTextureSize = new int[1];
gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
Log.v("Log", "Max texture size = " + maxTextureSize[0]);

}


hisong

#7
Quote from: K24A3 on September 21, 2011, 11:22:05 AM
Each type/model of Graphics Chip (GPU) has it's own maximum texture size, so you should check the size before creating large textures.

To query the texture size, call glGetIntegerv() in your main Activity's GLSurfaceView.Renderer class. You need a pointer to GL10 so you could place it in onSurfaceCreated().


public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Do nothing special.
int[] maxTextureSize = new int[1];
gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
Log.v("Log", "Max texture size = " + maxTextureSize[0]);

}




I got a value 4096 from the maxTextureSize.  Dose it mean I can handle the texture with as larger as 4096*4096?
But now I can't load a texture with 2048*1024....

EgonOlsen

Because a 2048*4096 texture has 32mb without any mip maps...heeeeelllooo...we are on a limited, mobile device here. Please keep that in mind before going crazy on texture size.

hisong

Hehe,   I haven't gotten  crazy yet.  Thanks for your suggestions.

I was just confused why I could load the image with opengl es, but not with jpct-ae.

EgonOlsen

Quote from: hisong on September 21, 2011, 02:51:47 PM
I was just confused why I could load the image with opengl es...
You can't. The hardware says, that it can handle it...but that doesn't mean that the device provides enough resources to do it.

K24A3

What android device/phone are you using? (please don't say the Android Emulator :p)

Have a read of this article: http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/

I don't know how accurate that article is, but it mentions that you can get around the 24MB memory limit by using OpenGL textures, apparently textures are not limited to 24MB.

Also, what is your android:minSdkVersion value in the AndroidManifest.xml file? Increasing it to say "9" (gingerbread) may help relieve limitations.


hisong

#12
Quote from: K24A3 on September 21, 2011, 02:58:24 PM
What android device/phone are you using? (please don't say the Android Emulator :p)

Have a read of this article: http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/

I don't know how accurate that article is, but it mentions that you can get around the 24MB memory limit by using OpenGL textures, apparently textures are not limited to 24MB.

Also, what is your android:minSdkVersion value in the AndroidManifest.xml file? Increasing it to say "9" (gingerbread) may help relieve limitations.

Oh, My device is the Defy of Motorala.  Dose it not support the 24MB Memory limitation?

I got the value of 3502168 from the android.os.Debug.getNativeHeapAllocatedSize().

And I work with the eighth minSDKVersion.

K24A3

#13
you can check how much memory is being used by using the code from here:
http://www.jpct.net/forum2/index.php/topic,2287.msg16929.html#msg16929


hisong

I think that the problem  may be caused by the 3ds file(the segment or the radius are too large for I had set the segment of 32 and the radius of 20).

I will test it tomorrow.

Good night.