@Override public void prepare () { int width = -1; int height = -1; for (TextureData data : textureDatas) { data.prepare(); if (width == -1) { width = data.getWidth(); height = data.getHeight(); continue; } if (width != data.getWidth() || height != data.getHeight()) { throw new GdxRuntimeException("Error whilst preparing TextureArray: TextureArray Textures must have equal dimensions."); } } prepared = true; }
@Override public void loadAsync (AssetManager manager, String fileName, FileHandle file, TextureParameter parameter) { info.filename = fileName; if (parameter == null || parameter.textureData == null) { Format format = null; boolean genMipMaps = false; info.texture = null; if (parameter != null) { format = parameter.format; genMipMaps = parameter.genMipMaps; info.texture = parameter.texture; } info.data = TextureData.Factory.loadFromFile(file, format, genMipMaps); } else { info.data = parameter.textureData; info.texture = parameter.texture; } if (!info.data.isPrepared()) info.data.prepare(); }
@Override public Format getFormat () { return mips[0].getFormat(); }
if (!data.isPrepared()) data.prepare(); final TextureDataType type = data.getType(); if (type == TextureDataType.Custom) { data.consumeCustomData(target); return; Pixmap pixmap = data.consumePixmap(); boolean disposePixmap = data.disposePixmap(); if (data.getFormat() != pixmap.getFormat()) { Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data.getFormat()); tmp.setBlending(Blending.None); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); if (data.disposePixmap()) { pixmap.dispose(); if (data.useMipMaps()) { MipMapGenerator.generateMipMap(target, pixmap, pixmap.getWidth(), pixmap.getHeight()); } else {
@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(); } } }
ImageUtil.flipImageVertically(imageBuff[i]); { TextureData textureData = AWTTextureIO.newTextureData(gl3.getGLProfile(), textureBuffIm, mipmap); gl3.glBindTexture(GL3.GL_TEXTURE_2D, objects[Objects.texture.ordinal()]); { int[] alignment = new int[1]; gl3.glGetIntegerv(GL3.GL_UNPACK_ALIGNMENT, alignment, 0); // System.out.println("alignment[0] "+alignment[0]); // System.out.println("textureData.getAlignment() "+textureData.getAlignment()); if (alignment[0] != textureData.getAlignment()) { gl3.glPixelStorei(GL3.GL_UNPACK_ALIGNMENT, textureData.getAlignment()); } { gl3.glTexImage2D(GL3.GL_TEXTURE_2D, 0, textureData.getInternalFormat(), textureData.getWidth(), textureData.getHeight(), textureData.getBorder(), textureData.getPixelFormat(), textureData.getPixelType(), textureData.getBuffer()); } if (alignment[0] != textureData.getAlignment()) { gl3.glPixelStorei(GL3.GL_UNPACK_ALIGNMENT, alignment[0]); }
public void load (TextureData data) { if (this.data != null && data.isManaged() != this.data.isManaged()) throw new GdxRuntimeException("New data must have the same managed status as the old data"); this.data = data; if (!data.isPrepared()) data.prepare(); bind(); uploadImageData(GL20.GL_TEXTURE_2D, data); unsafeSetFilter(minFilter, magFilter, true); unsafeSetWrap(uWrap, vWrap, true); Gdx.gl.glBindTexture(glTarget, 0); }
/** * Calculates the average color of a texture region. * * @param region The texture region * @return The average color */ public static Color getAverageColorFor(TextureRegion region) { region.getTexture().getTextureData().prepare(); final Pixmap pixmap = region.getTexture().getTextureData().consumePixmap(); float total = region.getRegionHeight() * region.getRegionWidth(); float r = 0, g = 0, b = 0; for (int y = region.getRegionY(), yMax = region.getRegionY() + region.getRegionHeight(); y < yMax; y++) { for (int x = region.getRegionX(), xMax = region.getRegionX() + region.getRegionWidth(); x < xMax; x++) { int pixel = pixmap.getPixel(x, y); // Ignore certain alpha colors if (((pixel & 0x000000ff)) / 255f < 0.0625f) { total--; continue; } r += ((pixel & 0xff000000) >>> 24) / 255f; g += ((pixel & 0x00ff0000) >>> 16) / 255f; b += ((pixel & 0x0000ff00) >>> 8) / 255f; } } if (region.getTexture().getTextureData().disposePixmap()) { pixmap.dispose(); } return new Color(r / total, g / total, b / total, 1f); }
TextureData textureData = texture.getTextureData(); textureData.prepare(); Pixmap pixmap = textureData.consumePixmap();
.loadFromFile(textureFile, Pixmap.Format.RGBA8888, false); if (!textureData.isPrepared()) textureData.prepare(); } catch (Exception e) { reportListenerError(e); textureData.disposePixmap(); reportListenerError(null); return;
@Override public int getWidth () { int tmp, width = 0; if (data[CubemapSide.PositiveZ.index] != null && (tmp = data[CubemapSide.PositiveZ.index].getWidth()) > width) width = tmp; if (data[CubemapSide.NegativeZ.index] != null && (tmp = data[CubemapSide.NegativeZ.index].getWidth()) > width) width = tmp; if (data[CubemapSide.PositiveY.index] != null && (tmp = data[CubemapSide.PositiveY.index].getWidth()) > width) width = tmp; if (data[CubemapSide.NegativeY.index] != null && (tmp = data[CubemapSide.NegativeY.index].getWidth()) > width) width = tmp; return width; }
@Override public int getHeight () { return mips[0].getHeight(); }
BitmapFontData data = unicodeFont.bitmapFont.getData(); BitmapFont.Glyph g = data.getGlyph((char)glyph.getCodePoint()); Pixmap fontPixmap = unicodeFont.bitmapFont.getRegions().get(g.page).getTexture().getTextureData().consumePixmap();
textureData.prepare(); textureData.disposePixmap(); pixmap.dispose();
if (!data.isPrepared()) data.prepare(); final TextureDataType type = data.getType(); if (type == TextureDataType.Custom) { data.consumeCustomData(target); return; Pixmap pixmap = data.consumePixmap(); boolean disposePixmap = data.disposePixmap(); if (data.getFormat() != pixmap.getFormat()) { Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data.getFormat()); tmp.setBlending(Blending.None); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); if (data.disposePixmap()) { pixmap.dispose(); if (data.useMipMaps()) { MipMapGenerator.generateMipMap(target, pixmap, pixmap.getWidth(), pixmap.getHeight()); } else {
@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(); } } }
public void load (TextureData data) { if (this.data != null && data.isManaged() != this.data.isManaged()) throw new GdxRuntimeException("New data must have the same managed status as the old data"); this.data = data; if (!data.isPrepared()) data.prepare(); bind(); uploadImageData(GL20.GL_TEXTURE_2D, data); unsafeSetFilter(minFilter, magFilter, true); unsafeSetWrap(uWrap, vWrap, true); Gdx.gl.glBindTexture(glTarget, 0); }
@Override public int getWidth () { int tmp, width = 0; if (data[CubemapSide.PositiveZ.index] != null && (tmp = data[CubemapSide.PositiveZ.index].getWidth()) > width) width = tmp; if (data[CubemapSide.NegativeZ.index] != null && (tmp = data[CubemapSide.NegativeZ.index].getWidth()) > width) width = tmp; if (data[CubemapSide.PositiveY.index] != null && (tmp = data[CubemapSide.PositiveY.index].getWidth()) > width) width = tmp; if (data[CubemapSide.NegativeY.index] != null && (tmp = data[CubemapSide.NegativeY.index].getWidth()) > width) width = tmp; return width; }
@Override public int getHeight () { int tmp, height = 0; if (data[CubemapSide.PositiveZ.index] != null && (tmp = data[CubemapSide.PositiveZ.index].getHeight()) > height) height = tmp; if (data[CubemapSide.NegativeZ.index] != null && (tmp = data[CubemapSide.NegativeZ.index].getHeight()) > height) height = tmp; if (data[CubemapSide.PositiveX.index] != null && (tmp = data[CubemapSide.PositiveX.index].getHeight()) > height) height = tmp; if (data[CubemapSide.NegativeX.index] != null && (tmp = data[CubemapSide.NegativeX.index].getHeight()) > height) height = tmp; return height; }
BitmapFontData data = unicodeFont.bitmapFont.getData(); BitmapFont.Glyph g = data.getGlyph((char)glyph.getCodePoint()); Pixmap fontPixmap = unicodeFont.bitmapFont.getRegions().get(g.page).getTexture().getTextureData().consumePixmap();