Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disposing a Texture in LibGdx

Tags:

libgdx

I am creating a single pixel with a specified color using a common method createSinglePixelTexture() as I have mentioned below.

Question: 1. Do I need to dispose "singlePixelPixmap" and texture "t" ? 2. If I need to dispose that where I can dispose it ?

singlePixelTexture = createSinglePixelTexture(0.129f, 0.129f, 0.129f, .7f);



private Texture createSinglePixelTexture(float r,float g,float b,float a) {
    Pixmap singlePixelPixmap; 
    singlePixelPixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    singlePixelPixmap.setColor(r, g, b, a);
    singlePixelPixmap.fill();
    PixmapTextureData textureData = new PixmapTextureData(singlePixelPixmap, Pixmap.Format.RGBA8888, false, false, true);
    Texture t = new Texture(textureData);
    t.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    return t; 
}
like image 445
iappmaker Avatar asked Nov 20 '25 06:11

iappmaker


1 Answers

  1. You don't need the intermediary PixmapTextureData; it's entirely optional.
  2. As soon as you create a Texture with a Pixmap, you can dispose the Pixmap. So you can insert the disposal of everything but the texture just before the return.
  3. Once you dispose a Texture, it cannot be drawn. Do not dispose t unless you are SURE you will never try to draw it again.
like image 135
Ryan Goldstein Avatar answered Nov 22 '25 04:11

Ryan Goldstein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!