@Override public void clearTextureAtlas(final int atlasId) { initialData.rewind(); getTextureAtlas(atlasId).getImage().setData(initialData); }
image.setData(0, combinedData); image.setMipMapSizes(mipSizes);
public static void createData(Image image, boolean mipmaps){ int bpp = image.getFormat().getBitsPerPixel(); int w = image.getWidth(); int h = image.getHeight(); if (!mipmaps){ image.setData(BufferUtils.createByteBuffer(w*h*bpp/8)); return; } int expectedMipmaps = 1 + (int) Math.ceil(Math.log(Math.max(h, w)) / LOG2); int[] mipMapSizes = new int[expectedMipmaps]; int total = 0; for (int i = 0; i < mipMapSizes.length; i++){ int size = (w * h * bpp) / 8; total += size; mipMapSizes[i] = size; w /= 2; h /= 2; } image.setMipMapSizes(mipMapSizes); image.setData(BufferUtils.createByteBuffer(total)); }
image.setData(0, combinedData); image.setMipMapSizes(mipSizes); image.setFormat(format);
/** * This method scales the given texture to the given size. * * @param texture * the texture to be scaled * @param width * new width of the texture * @param height * new height of the texture */ private void scale(Texture2D texture, int width, int height) { // first determine if scaling is required boolean scaleRequired = texture.getImage().getWidth() != width || texture.getImage().getHeight() != height; if (scaleRequired) { Image image = texture.getImage(); BufferedImage sourceImage = ImageToAwt.convert(image, false, true, 0); int sourceWidth = sourceImage.getWidth(); int sourceHeight = sourceImage.getHeight(); BufferedImage targetImage = new BufferedImage(width, height, sourceImage.getType()); Graphics2D g = targetImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(sourceImage, 0, 0, width, height, 0, 0, sourceWidth, sourceHeight, null); g.dispose(); Image output = new ImageLoader().load(targetImage, false); image.setWidth(width); image.setHeight(height); image.setData(output.getData(0)); image.setFormat(output.getFormat()); } }
textureImage.setWidth(width); textureImage.setHeight(height); textureImage.setData(scratch); return textureImage;
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
private void updateTexture(Texture2D tex, ByteBuffer buf, int stride) { if (buf == null) { tex.setImage(emptyImage); return; } if (tex.getImage().getData(0).capacity() != buf.capacity()) { Image img = new Image(Format.Luminance8, stride, buf.capacity() / stride, buf, ColorSpace.Linear); tex.setImage(img); } else { tex.getImage().setData(buf); } }
public static void createData(Image image, boolean mipmaps){ int bpp = image.getFormat().getBitsPerPixel(); int w = image.getWidth(); int h = image.getHeight(); if (!mipmaps){ image.setData(BufferUtils.createByteBuffer(w*h*bpp/8)); return; } int expectedMipmaps = 1 + (int) Math.ceil(Math.log(Math.max(h, w)) / LOG2); int[] mipMapSizes = new int[expectedMipmaps]; int total = 0; for (int i = 0; i < mipMapSizes.length; i++){ int size = (w * h * bpp) / 8; total += size; mipMapSizes[i] = size; w /= 2; h /= 2; } image.setMipMapSizes(mipMapSizes); image.setData(BufferUtils.createByteBuffer(total)); }
image.setData(0, combinedData); image.setMipMapSizes(mipSizes);
public static void createData(Image image, boolean mipmaps){ int bpp = image.getFormat().getBitsPerPixel(); int w = image.getWidth(); int h = image.getHeight(); if (!mipmaps){ image.setData(BufferUtils.createByteBuffer(w*h*bpp/8)); return; } int expectedMipmaps = 1 + (int) Math.ceil(Math.log(Math.max(h, w)) / LOG2); int[] mipMapSizes = new int[expectedMipmaps]; int total = 0; for (int i = 0; i < mipMapSizes.length; i++){ int size = (w * h * bpp) / 8; total += size; mipMapSizes[i] = size; w /= 2; h /= 2; } image.setMipMapSizes(mipMapSizes); image.setData(BufferUtils.createByteBuffer(total)); }
image.setData(0, combinedData); image.setMipMapSizes(mipSizes); image.setFormat(format);
image.setData(0, combinedData); image.setMipMapSizes(mipSizes); image.setFormat(format);
textureImage.setWidth(width); textureImage.setHeight(height); textureImage.setData(scratch); return textureImage;
public Object postProcess(AssetKey key, Object obj) { TextureKey texKey = (TextureKey) key; Image img = (Image) obj; if (img == null) { return null; } Texture tex; if (texKey.isAsCube()) { if (texKey.isFlipY()) { // also flip -y and +y image in cubemap ByteBuffer pos_y = img.getData(2); img.setData(2, img.getData(3)); img.setData(3, pos_y); } tex = new TextureCubeMap(); } else if (texKey.isAsTexture3D()) { tex = new Texture3D(); } else { tex = new Texture2D(); } // enable mipmaps if image has them // or generate them if requested by user if (img.hasMipmaps() || texKey.isGenerateMips()) { tex.setMinFilter(Texture.MinFilter.Trilinear); } tex.setAnisotropicFilter(texKey.getAnisotropy()); tex.setName(texKey.getName()); tex.setImage(img); return tex; }
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
@Override public Object postProcess(Object asset) { Image img = (Image) asset; if (img == null) { return null; } Texture tex; if (isAsCube()) { if (isFlipY()) { // also flip -y and +y image in cubemap ByteBuffer pos_y = img.getData(2); img.setData(2, img.getData(3)); img.setData(3, pos_y); } tex = new TextureCubeMap(); } else if (isAsTexture3D()) { tex = new Texture3D(); } else { tex = new Texture2D(); } // enable mipmaps if image has them // or generate them if requested by user if (img.hasMipmaps() || isGenerateMips()) { tex.setMinFilter(Texture.MinFilter.Trilinear); } tex.setAnisotropicFilter(getAnisotropy()); tex.setName(getName()); tex.setImage(img); return tex; }