public PixmapTextureData (Pixmap pixmap, Format format, boolean useMipMaps, boolean disposePixmap, boolean managed) { this.pixmap = pixmap; this.format = format == null ? pixmap.getFormat() : format; this.useMipMaps = useMipMaps; this.disposePixmap = disposePixmap; this.managed = managed; }
public PixmapTextureData (Pixmap pixmap, Format format, boolean useMipMaps, boolean disposePixmap, boolean managed) { this.pixmap = pixmap; this.format = format == null ? pixmap.getFormat() : format; this.useMipMaps = useMipMaps; this.disposePixmap = disposePixmap; this.managed = managed; }
public FileTextureData (FileHandle file, Pixmap preloadedPixmap, Format format, boolean useMipMaps) { this.file = file; this.pixmap = preloadedPixmap; this.format = format; this.useMipMaps = useMipMaps; if (pixmap != null) { width = pixmap.getWidth(); height = pixmap.getHeight(); if (format == null) this.format = pixmap.getFormat(); } }
public FileTextureData (FileHandle file, Pixmap preloadedPixmap, Format format, boolean useMipMaps) { this.file = file; this.pixmap = preloadedPixmap; this.format = format; this.useMipMaps = useMipMaps; if (pixmap != null) { width = pixmap.getWidth(); height = pixmap.getHeight(); if (format == null) this.format = pixmap.getFormat(); } }
@Override protected void processFile (Entry entry) throws Exception { System.out.println("Processing " + entry.inputFile); Pixmap pixmap = new Pixmap(new FileHandle(entry.inputFile)); if (pixmap.getFormat() != Format.RGB888 && pixmap.getFormat() != Format.RGB565) { System.out.println("Converting from " + pixmap.getFormat() + " to RGB888!"); Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Format.RGB888); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); pixmap = tmp; } ETC1.encodeImagePKM(pixmap).write(new FileHandle(entry.outputFile)); pixmap.dispose(); }
@Override protected void processFile (Entry entry) throws Exception { System.out.println("Processing " + entry.inputFile); Pixmap pixmap = new Pixmap(new FileHandle(entry.inputFile)); if (pixmap.getFormat() != Format.RGB888 && pixmap.getFormat() != Format.RGB565) { System.out.println("Converting from " + pixmap.getFormat() + " to RGB888!"); Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Format.RGB888); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); pixmap = tmp; } ETC1.encodeImagePKM(pixmap).write(new FileHandle(entry.outputFile)); pixmap.dispose(); }
@Override public void prepare () { if (isPrepared) throw new GdxRuntimeException("Already prepared"); if (pixmap == null) { if (file.extension().equals("cim")) pixmap = PixmapIO.readCIM(file); else pixmap = new Pixmap(file); width = pixmap.getWidth(); height = pixmap.getHeight(); if (format == null) format = pixmap.getFormat(); } isPrepared = true; }
@Override public void prepare () { if (isPrepared) throw new GdxRuntimeException("Already prepared"); if (pixmap == null) { if (file.extension().equals("cim")) pixmap = PixmapIO.readCIM(file); else pixmap = new Pixmap(file); width = pixmap.getWidth(); height = pixmap.getHeight(); if (format == null) format = pixmap.getFormat(); } isPrepared = true; }
public void set (final Pixmap map) { if (map.getWidth() != width || map.getHeight() != height) throw new GdxRuntimeException("Incorrect map size"); set(map.getPixels(), map.getFormat()); }
/** Creates the texture if it has not been created, else reuploads the entire page pixmap to the texture if the pixmap has * changed since this method was last called. * @return true if the texture was created or reuploaded. */ public boolean updateTexture (TextureFilter minFilter, TextureFilter magFilter, boolean useMipMaps) { if (texture != null) { if (!dirty) return false; texture.load(texture.getTextureData()); } else { texture = new Texture(new PixmapTextureData(image, image.getFormat(), useMipMaps, false, true)) { @Override public void dispose () { super.dispose(); image.dispose(); } }; texture.setFilter(minFilter, magFilter); } dirty = false; return true; } }
/** Creates the texture if it has not been created, else reuploads the entire page pixmap to the texture if the pixmap has * changed since this method was last called. * @return true if the texture was created or reuploaded. */ public boolean updateTexture (TextureFilter minFilter, TextureFilter magFilter, boolean useMipMaps) { if (texture != null) { if (!dirty) return false; texture.load(texture.getTextureData()); } else { texture = new Texture(new PixmapTextureData(image, image.getFormat(), useMipMaps, false, true)) { @Override public void dispose () { super.dispose(); image.dispose(); } }; texture.setFilter(minFilter, magFilter); } dirty = false; return true; } }
/** Encodes the image via the ETC1 compression scheme. Only {@link Format#RGB565} and {@link Format#RGB888} are supported. * @param pixmap the {@link Pixmap} * @return the {@link ETC1Data} */ public static ETC1Data encodeImage (Pixmap pixmap) { int pixelSize = getPixelSize(pixmap.getFormat()); ByteBuffer compressedData = encodeImage(pixmap.getPixels(), 0, pixmap.getWidth(), pixmap.getHeight(), pixelSize); BufferUtils.newUnsafeByteBuffer(compressedData); return new ETC1Data(pixmap.getWidth(), pixmap.getHeight(), compressedData, 0); }
/** Encodes the image via the ETC1 compression scheme. Only {@link Format#RGB565} and {@link Format#RGB888} are supported. Adds * a PKM header in front of the compressed image data. * @param pixmap the {@link Pixmap} * @return the {@link ETC1Data} */ public static ETC1Data encodeImagePKM (Pixmap pixmap) { int pixelSize = getPixelSize(pixmap.getFormat()); ByteBuffer compressedData = encodeImagePKM(pixmap.getPixels(), 0, pixmap.getWidth(), pixmap.getHeight(), pixelSize); BufferUtils.newUnsafeByteBuffer(compressedData); return new ETC1Data(pixmap.getWidth(), pixmap.getHeight(), compressedData, 16); }
/** Encodes the image via the ETC1 compression scheme. Only {@link Format#RGB565} and {@link Format#RGB888} are supported. * @param pixmap the {@link Pixmap} * @return the {@link ETC1Data} */ public static ETC1Data encodeImage (Pixmap pixmap) { int pixelSize = getPixelSize(pixmap.getFormat()); ByteBuffer compressedData = encodeImage(pixmap.getPixels(), 0, pixmap.getWidth(), pixmap.getHeight(), pixelSize); BufferUtils.newUnsafeByteBuffer(compressedData); return new ETC1Data(pixmap.getWidth(), pixmap.getHeight(), compressedData, 0); }
/** Encodes the image via the ETC1 compression scheme. Only {@link Format#RGB565} and {@link Format#RGB888} are supported. Adds * a PKM header in front of the compressed image data. * @param pixmap the {@link Pixmap} * @return the {@link ETC1Data} */ public static ETC1Data encodeImagePKM (Pixmap pixmap) { int pixelSize = getPixelSize(pixmap.getFormat()); ByteBuffer compressedData = encodeImagePKM(pixmap.getPixels(), 0, pixmap.getWidth(), pixmap.getHeight(), pixelSize); BufferUtils.newUnsafeByteBuffer(compressedData); return new ETC1Data(pixmap.getWidth(), pixmap.getHeight(), compressedData, 16); }
@Override public void consumeTextureArrayData () { for (int i = 0; i < textureDatas.length; i++) { if (textureDatas[i].getType() == TextureData.TextureDataType.Custom) { textureDatas[i].consumeCustomData(GL30.GL_TEXTURE_2D_ARRAY); } else { TextureData texData = textureDatas[i]; Pixmap pixmap = texData.consumePixmap(); boolean disposePixmap = texData.disposePixmap(); if (texData.getFormat() != pixmap.getFormat()) { Pixmap temp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), texData.getFormat()); temp.setBlending(Pixmap.Blending.None); temp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); if (texData.disposePixmap()) { pixmap.dispose(); } pixmap = temp; disposePixmap = true; } Gdx.gl30.glTexSubImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, pixmap.getWidth(), pixmap.getHeight(), 1, pixmap.getGLInternalFormat(), pixmap.getGLType(), pixmap.getPixels()); if (disposePixmap) pixmap.dispose(); } } }
@Override public void consumeTextureArrayData () { for (int i = 0; i < textureDatas.length; i++) { if (textureDatas[i].getType() == TextureData.TextureDataType.Custom) { textureDatas[i].consumeCustomData(GL30.GL_TEXTURE_2D_ARRAY); } else { TextureData texData = textureDatas[i]; Pixmap pixmap = texData.consumePixmap(); boolean disposePixmap = texData.disposePixmap(); if (texData.getFormat() != pixmap.getFormat()) { Pixmap temp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), texData.getFormat()); temp.setBlending(Pixmap.Blending.None); temp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); if (texData.disposePixmap()) { pixmap.dispose(); } pixmap = temp; disposePixmap = true; } Gdx.gl30.glTexSubImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, pixmap.getWidth(), pixmap.getHeight(), 1, pixmap.getGLInternalFormat(), pixmap.getGLType(), pixmap.getPixels()); if (disposePixmap) pixmap.dispose(); } } }
@Override public void consumeCubemapData () { for (int i = 0; i < data.length; i++) { if (data[i].getType() == TextureData.TextureDataType.Custom) { data[i].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i); } else { Pixmap pixmap = data[i].consumePixmap(); boolean disposePixmap = data[i].disposePixmap(); if (data[i].getFormat() != pixmap.getFormat()) { Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data[i].getFormat()); tmp.setBlending(Blending.None); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); if (data[i].disposePixmap()) pixmap.dispose(); pixmap = tmp; disposePixmap = true; } Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1); Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); if (disposePixmap) pixmap.dispose(); } } }
@Override public void consumeCubemapData () { for (int i = 0; i < data.length; i++) { if (data[i].getType() == TextureData.TextureDataType.Custom) { data[i].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i); } else { Pixmap pixmap = data[i].consumePixmap(); boolean disposePixmap = data[i].disposePixmap(); if (data[i].getFormat() != pixmap.getFormat()) { Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data[i].getFormat()); tmp.setBlending(Blending.None); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); if (data[i].disposePixmap()) pixmap.dispose(); pixmap = tmp; disposePixmap = true; } Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1); Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); if (disposePixmap) pixmap.dispose(); } } }
private static void generateMipMapCPU (int target, Pixmap pixmap, int textureWidth, int textureHeight) { Gdx.gl.glTexImage2D(target, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); if ((Gdx.gl20 == null) && textureWidth != textureHeight) throw new GdxRuntimeException("texture width and height must be square when using mipmapping."); int width = pixmap.getWidth() / 2; int height = pixmap.getHeight() / 2; int level = 1; while (width > 0 && height > 0) { Pixmap tmp = new Pixmap(width, height, pixmap.getFormat()); tmp.setBlending(Blending.None); tmp.drawPixmap(pixmap, 0, 0, pixmap.getWidth(), pixmap.getHeight(), 0, 0, width, height); if (level > 1) pixmap.dispose(); pixmap = tmp; Gdx.gl.glTexImage2D(target, level, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); width = pixmap.getWidth() / 2; height = pixmap.getHeight() / 2; level++; } } }