Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Simple Texture Load & Unload

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2012

    Simple Texture Load & Unload

    Okay so I am making a live wallpaper for android phone but up until now, I have never noticed this issue.

    Basically I am looking to see if my texture load & unload function is efficient or at least not horrible.

    Breakdown of what happens on run:

    -Wallpaper initialized.
    -Texture manager Loops through all textures and loads them using glBindTexture.
    -Wallpaper shows up running perfectly fine. Using 21mb of ram.
    -I have the background flip back and forth every few seconds, both backgrounds are already loaded.
    -I change background by doing this ---> paramGL10.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.textures[i]); ( I flip/ flop the integer between 0 and 1 for instance )
    -On phone lock unload textures
    -On phone resume, reload textures.

    My ram increasing slowly but steadily. I don't understand why, all of my openGL knowledge has been self taught trial and error so I probably am not using the most efficient way of doing this.
    Increases continuously I have seen it go as high as 81mb.

    Here is my code.

    Texture Manager Loading Textures on initial run, or after phone was resumed.

    Code :
    public static void loadTextures(GL10 paramGL10) {
          bindTextureIDs(paramGL10, "blank");
          bindTextureIDs(paramGL10, "grid");

    Code :
      public static void bindTextureIDs(GL10 paramGL10, String fileName) {
          int ID = textureIDs.size();
            textureIDs.put(fileName, ID);
            try {
            int resID = context.getResources().getIdentifier(fileName, "drawable", ApplicationPackageName);
            BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
            bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_4444;
            Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resID, bitmapOptions);
            paramGL10.glTexParameterf(GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST );
            paramGL10.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
            paramGL10.glTexParameterf(GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
            paramGL10.glTexParameterf(GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
            } catch(Exception e) { Log.v("TEST","Texture Data Corrupt, Re-download Package."); }

    Texture Manager unloading textures on lock.

    Code :
      public static boolean unload(GL10 paramGL10)
        try {
            Log.v("TEST", "TextureManager Unloading Textures");
            paramGL10.glDeleteTextures(MAX_TEXTURES, textures, 0);
            isLoaded = false;
        } catch (Exception e) {}
        return true;

    And my rendering code

    Code :
    public void render(GL10 paramGL10, TextureManager paramTextureManager, MeshManager paramMeshManager) {
                  int i = paramTextureManager.getTextureID(paramGL10, this.texName);
                  Mesh localMesh = paramMeshManager.getMeshByName(paramGL10, this.meshName);
                  paramGL10.glTranslatef(this.origin.x,this.origin.y, this.origin.z);
                  paramGL10.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.textures[i]);
                  if (this.color != null) 
                  paramGL10.glColor4f(this.color.x, this.color.y, this.color.z, this.color.a);
                  paramGL10.glScalef(this.scale.x, this.scale.y,this.scale.z);
                  paramGL10.glRotatef(this.angles.a, this.angles.x, this.angles.y, this.angles.z);

    Can anyone help me explain why this is leaking my memory, I figured if I locked my phone and unlocked it after the memory leaked a lot, the unload and reload should clear the GPU memory but it does not.

    I hope someone is able to help me see the error of my ways!


  2. #2
    Junior Member Newbie
    Join Date
    Feb 2012
    I have read online that I should avoid using glDeleteTextures, only call texImage2D on initialize and then use glBind to reference the texture. So I have removed the glDeleteTextures, only called texImage2D on the initialize ( in this case the preview screen )
    and using glBind as normal.

    This shows the livewallpaper in the preview window perfectly, as soon as I set the wallpaper, my entire window goes white and all textures seem to be lost. Now because I am not unloading and reloading textures it remains white ( as before this wouldnt happen, and if it did a simple lock phone and unlock would reload the textures )

    But if I upload the application while its set as my wallpaper, it works perfect. Unless I go back to the wallpaper chooser and select the live wallpaper from the menu. Then once again the textures are all white.

    Ugh what is the issue?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2012
    Alright more reading and it turns out many people are having issues with the pause and resume reloading textures. I re-enabled everything back to the memory leak state and have only called

    on initialize. Seems to solve the memory leak issue. But if my wallpaper is set and I reselect it from the live wallpaper screen. my memory footprint doubles. I am going to sleep and hopefully it will come to me overnight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts