imageSize = image.getMipMapSizes()[mipLevel]; } else { imageSize = width * height * image.getFormat().getBitsPerPixel() / 8;
log.log(Level.FINE, "img format {0}", imgFormat.toString()); int bytePerPixel = imgFormat.getBitsPerPixel() / 8; int byteBuffersSize = computeBuffersSize(numberOfMipmapLevels, pixelWidth, pixelHeight, bytePerPixel, pixelDepth); log.log(Level.FINE, "data size {0}", byteBuffersSize);
private static GLImageFormat getSrgbFormat(Format fmt){ switch (fmt){ case RGB8 : return sRGB_RGB8; case RGBA8 : return sRGB_RGBA8; case BGR8 : return sRGB_BGR8; case ABGR8 : return sRGB_ABGR8; case Luminance8 : return sRGB_Luminance8; case Luminance8Alpha8 : return sRGB_LuminanceAlpha8; case DXT1 : return sRGB_DXT1; case DXT1A : return sRGB_DXT1A; case DXT3 : return sRGB_DXT3; case DXT5 : return sRGB_DXT5; default : Logger.getLogger(TextureUtil.class.getName()).log(Level.WARNING, "Format {0} has no sRGB equivalent, using linear format.", fmt.toString()); return formatToGL[fmt.ordinal()]; } }
if (img.getFormat().isDepthFormat()) { img.setMultiSamples(Math.min(limits.get(Limits.DepthTextureSamples), imageSamples)); } else { if (img.getFormat().isDepthFormat() && !caps.contains(Caps.DepthTexture)) { throw new RendererException("Depth textures are not supported by the video hardware");
if (img.getFormat().isDepthFormat()) { img.setMultiSamples(Math.min(maxDepthTexSamples, imageSamples)); } else {
log.log(Level.FINE, "img format {0}", imgFormat.toString()); int bytePerPixel = imgFormat.getBitsPerPixel() / 8; int byteBuffersSize = computeBuffersSize(numberOfMipmapLevels, pixelWidth, pixelHeight, bytePerPixel, pixelDepth); log.log(Level.FINE, "data size {0}", byteBuffersSize);
return getSrgbFormat(fmt); return formatToGL[fmt.ordinal()];
return getSrgbFormat(fmt); } else { return formatToGL[fmt.ordinal()];
if (!depthFmt.isDepthFormat()){ return false; }else{ if (colorFmt.isDepthFormat()) return false; if (colorFmt.isCompressed()) return false; return false; default: if (colorFmt.isFloatingPont()) return caps.contains(Caps.FloatColorBuffer);
if (depthBuf != null){ Format depthFmt = depthBuf.getFormat(); if (!depthFmt.isDepthFormat()){ return false; }else{
if (jmeFormat.isCompressed()) { throw new UnsupportedOperationException("Updating compressed images is not supported"); } else if (jmeFormat.isDepthFormat()) { throw new UnsupportedOperationException("Updating depth images is not supported");
/** * Reads a grayscale image with mipmaps from the InputStream * @param flip Flip the loaded image by Y axis * @param totalSize Total size of the image in bytes including the mipmaps * @return A ByteBuffer containing the grayscale image data with mips. * @throws java.io.IOException If an error occured while reading from InputStream */ public ByteBuffer readGrayscale2D(boolean flip, int totalSize) throws IOException { ByteBuffer buffer = BufferUtils.createByteBuffer(totalSize); if (bpp == 8) { logger.finest("Source image format: R8"); } assert bpp == pixelFormat.getBitsPerPixel(); int mipWidth = width; int mipHeight = height; for (int mip = 0; mip < mipMapCount; mip++) { byte[] data = new byte[sizes[mip]]; in.readFully(data); if (flip) { data = flipData(data, mipWidth * bpp / 8, mipHeight); } buffer.put(data); mipWidth = Math.max(mipWidth / 2, 1); mipHeight = Math.max(mipHeight / 2, 1); } return buffer; }
/** * Inits the mip maps of a cube map witht he given number of mip maps * @param nbMipMaps the number of mip maps to initialize */ public void initMipMaps(int nbMipMaps) { int maxMipMap = (int) (Math.log(image.getWidth()) / Math.log(2) + 1); if (nbMipMaps > maxMipMap) { throw new IllegalArgumentException("Max mip map number for a " + image.getWidth() + "x" + image.getHeight() + " cube map is " + maxMipMap); } sizes = new int[nbMipMaps]; int totalSize = 0; for (int i = 0; i < nbMipMaps; i++) { int size = (int) pow(2, maxMipMap - 1 - i); sizes[i] = size * size * image.getFormat().getBitsPerPixel() / 8; totalSize += sizes[i]; } image.setMipMapSizes(sizes); image.getData().clear(); for (int i = 0; i < 6; i++) { image.addData(BufferUtils.createByteBuffer(totalSize)); } mipMapRaster = new MipMapImageRaster(image, 0); } }
@Override public void render(final RenderManager renderManager) { if (jobs.isEmpty()) { return; } final SnapshotJob job = jobs.get(0); for (int i = 0; i < 6; i++) { viewports[i].clearScenes(); viewports[i].attachScene(job.scene); renderManager.renderViewPort(viewports[i], 0.16f); buffers[i] = BufferUtils.createByteBuffer(size * size * imageFormat.getBitsPerPixel() / 8); renderManager.getRenderer().readFrameBufferWithFormat(framebuffers[i], buffers[i], imageFormat); images[i] = new Image(imageFormat, size, size, buffers[i], ColorSpace.Linear); MipMapGenerator.generateMipMaps(images[i]); } final TextureCubeMap map = EnvMapUtils.makeCubeMap(images[0], images[1], images[2], images[3], images[4], images[5], imageFormat); debugEnv = map; job.callback.done(map); map.getImage().dispose(); jobs.remove(0); }
public static void flipImage(Image img, int index){ if (img.getFormat().isCompressed()) throw new UnsupportedOperationException("Flipping compressed " + "images is unsupported."); int w = img.getWidth(); int h = img.getHeight(); int halfH = h / 2; // bytes per pixel int bpp = img.getFormat().getBitsPerPixel() / 8; int scanline = w * bpp; ByteBuffer data = img.getData(index); ByteBuffer temp = BufferUtils.createByteBuffer(scanline); data.rewind(); for (int y = 0; y < halfH; y++){ int oppY = h - y - 1; // read in scanline data.position(y * scanline); data.limit(data.position() + scanline); temp.rewind(); temp.put(data); } }
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)); }
public static void flipImage(Image img, int index){ if (img.getFormat().isCompressed()) throw new UnsupportedOperationException("Flipping compressed " + "images is unsupported."); int w = img.getWidth(); int h = img.getHeight(); int halfH = h / 2; // bytes per pixel int bpp = img.getFormat().getBitsPerPixel() / 8; int scanline = w * bpp; ByteBuffer data = img.getData(index); ByteBuffer temp = BufferUtils.createByteBuffer(scanline); data.rewind(); for (int y = 0; y < halfH; y++){ int oppY = h - y - 1; // read in scanline data.position(y * scanline); data.limit(data.position() + scanline); temp.rewind(); temp.put(data); } }
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)); }
/** * Computes the sizes of each mipmap level in bytes, and stores it in sizes_[]. */ private void loadSizes() { int mipWidth = width; int mipHeight = height; sizes = new int[mipMapCount]; int outBpp = pixelFormat.getBitsPerPixel(); for (int i = 0; i < mipMapCount; i++) { int size; if (compressed) { size = ((mipWidth + 3) / 4) * ((mipHeight + 3) / 4) * outBpp * 2; } else { size = mipWidth * mipHeight * outBpp / 8; } sizes[i] = ((size + 3) / 4) * 4; mipWidth = Math.max(mipWidth / 2, 1); mipHeight = Math.max(mipHeight / 2, 1); } }