Author Topic: How to use 2048 * 1024 texture on a sphere?  (Read 4601 times)

Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
How to use 2048 * 1024 texture on a sphere?
« on: September 21, 2011, 08:50:28 am »
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.


Code: [Select]
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~~
« Last Edit: September 21, 2011, 09:02:04 am by hisong »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #1 on: September 21, 2011, 09:00:52 am »
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

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #2 on: September 21, 2011, 09:53:30 am »
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.

Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #3 on: September 21, 2011, 10:05:22 am »
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?

Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #4 on: September 21, 2011, 10:20:16 am »
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.
« Last Edit: September 21, 2011, 10:22:02 am by hisong »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #5 on: September 21, 2011, 11:11:58 am »
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.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #6 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().

Code: [Select]
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]);

}


Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #7 on: September 21, 2011, 02:02:24 pm »
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().

Code: [Select]
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....
« Last Edit: September 21, 2011, 02:53:17 pm by hisong »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #8 on: September 21, 2011, 02:26:47 pm »
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.

Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #9 on: September 21, 2011, 02:51:47 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #10 on: September 21, 2011, 02:56:04 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.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #11 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.


Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #12 on: September 21, 2011, 03:26:07 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.
« Last Edit: September 21, 2011, 04:00:08 pm by hisong »

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #13 on: September 21, 2011, 03:53:14 pm »
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

« Last Edit: September 22, 2011, 10:48:02 am by K24A3 »

Offline hisong

  • byte
  • *
  • Posts: 16
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #14 on: September 21, 2011, 04:12:38 pm »
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.