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

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #15 on: September 21, 2011, 04:31:10 pm »
I was thinking it may be a 3DS issue, perhaps try texturing a bare sphere using primitives.getSphere.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #16 on: September 21, 2011, 05:00:10 pm »
To upload a texture, a copy into the VM's memory has to exists. Or otherwise, there's nothing to upload. By default, jPCT-AE keeps this copy for handling context changes. You can disable this behaviour, but you still need the memory before it will be uploaded. 2048*2048*4=16mb => crash. I don't really get how one can think that this should actually work on a VM with 16-24mb. And i don't the reason why it should. No game on the desktop is using this crazy resolution maybe except for shadow maps. So why on earth does anybody even think about using it on a mobile device...  ???

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #17 on: September 22, 2011, 08:42:59 am »
Is there a way to stream the texture into the GPU or perhaps use Texture compression?

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #18 on: September 22, 2011, 10:37:46 am »
I found a way to load huge textures, but only honeycomb (Android 3.x) is supported.

Honeycomb increases the memory size per application to 48MB using the standard heap (as opposed to 24MB and 32MB in previous Androids). But loading a 2048x2048 texture still crashed my app.

Here is the memory allocation (crashes when loading the large texture):
09-22 18:21:08.190: VERBOSE/Tosh(25398): debug.heap native: allocated 3.02MB of 3.04MB (0.01MB free)
09-22 18:21:08.190: VERBOSE/Tosh(25398): debug.memory: allocated: 22.00MB of 48.00MB (6.00MB free)

Then I made the following changes to increase the heap to Large:
In default.properties file, I changed the target to 'target=android-11'
In AndroidManifest.xml file, I added 'android:largeHeap="true"' to the Application tag.

Now that large 2048 texture loads with no problem.
09-22 18:23:14.980: VERBOSE/Tosh(25572): debug.heap native: allocated 3.02MB of 3.02MB (0.00MB free)
09-22 18:23:14.980: VERBOSE/Tosh(25572): debug.memory: allocated: 55.00MB of 256.00MB (22.00MB free)

256MB to play with! But your app won't be able to run on any phone, or at least until Icecream Sandwich phones come out (2012).

Here's the code to log the memory stats
Code: [Select]
public static void logHeap() {
        Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));
        Double available = new Double(Debug.getNativeHeapSize())/1048576.0;
        Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0;
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);

        Log.d("Log", "debug. =================================");
        Log.d("Log", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)");
        Log.d("Log", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");
    }


« Last Edit: September 22, 2011, 11:46:24 am by K24A3 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #19 on: September 23, 2011, 05:59:34 pm »
...So they finally realized that people might need some more memory...good to know.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to use 2048 * 1024 texture on a sphere?
« Reply #20 on: September 23, 2011, 06:48:12 pm »
hehe yeah I think we will see a big jump in memory capacity and performance soon.

The Tegra Wiki suggests that performance will be 10x faster with the Tegra 4 chip next year (compared to Tegra2), then 50x faster the following year, including support for OpenGL 4.0
http://en.wikipedia.org/wiki/Nvidia_Tegra#Tegra_3_.28Kal-El.29_series