1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.graphics.glutils; 18 19 import com.badlogic.gdx.graphics.Pixmap; 20 import com.badlogic.gdx.graphics.Pixmap.Format; 21 import com.badlogic.gdx.graphics.TextureData; 22 import com.badlogic.gdx.utils.GdxRuntimeException; 23 24 public class PixmapTextureData implements TextureData { 25 final Pixmap pixmap; 26 final Format format; 27 final boolean useMipMaps; 28 final boolean disposePixmap; 29 final boolean managed; 30 31 public PixmapTextureData (Pixmap pixmap, Format format, boolean useMipMaps, boolean disposePixmap) { 32 this(pixmap, format, useMipMaps, disposePixmap, false); 33 } 34 35 public PixmapTextureData (Pixmap pixmap, Format format, boolean useMipMaps, boolean disposePixmap, boolean managed) { 36 this.pixmap = pixmap; 37 this.format = format == null ? pixmap.getFormat() : format; 38 this.useMipMaps = useMipMaps; 39 this.disposePixmap = disposePixmap; 40 this.managed = managed; 41 } 42 43 @Override 44 public boolean disposePixmap () { 45 return disposePixmap; 46 } 47 48 @Override 49 public Pixmap consumePixmap () { 50 return pixmap; 51 } 52 53 @Override 54 public int getWidth () { 55 return pixmap.getWidth(); 56 } 57 58 @Override 59 public int getHeight () { 60 return pixmap.getHeight(); 61 } 62 63 @Override 64 public Format getFormat () { 65 return format; 66 } 67 68 @Override 69 public boolean useMipMaps () { 70 return useMipMaps; 71 } 72 73 @Override 74 public boolean isManaged () { 75 return managed; 76 } 77 78 @Override 79 public TextureDataType getType () { 80 return TextureDataType.Pixmap; 81 } 82 83 @Override 84 public void consumeCustomData (int target) { 85 throw new GdxRuntimeException("This TextureData implementation does not upload data itself"); 86 } 87 88 @Override 89 public boolean isPrepared () { 90 return true; 91 } 92 93 @Override 94 public void prepare () { 95 throw new GdxRuntimeException("prepare() must not be called on a PixmapTextureData instance as it is already prepared."); 96 } 97 } 98