use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class Image method read.
public void read(JmeImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this);
format = capsule.readEnum("format", Format.class, Format.RGBA8);
width = capsule.readInt("width", 0);
height = capsule.readInt("height", 0);
depth = capsule.readInt("depth", 0);
mipMapSizes = capsule.readIntArray("mipMapSizes", null);
multiSamples = capsule.readInt("multiSamples", 1);
data = (ArrayList<ByteBuffer>) capsule.readByteBufferArrayList("data", null);
colorSpace = capsule.readEnum("colorSpace", ColorSpace.class, null);
if (mipMapSizes != null) {
needGeneratedMips = false;
mipsWereGenerated = true;
}
}
use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class ImageTileLoader method getHeightMapAt.
/**
* Lets you specify the type of images that are being loaded. All images
* must be the same type.
* @param imageType eg. BufferedImage.TYPE_USHORT_GRAY
*/
/*public void setImageType(int imageType) {
this.imageType = imageType;
}*/
/**
* The ImageHeightmap that will parse the image type that you
* specify with setImageType().
* @param customImageHeightmap must extend AbstractHeightmap
*/
/*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
if (!(customImageHeightmap instanceof AbstractHeightMap)) {
throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
}
this.customImageHeightmap = customImageHeightmap;
}*/
private HeightMap getHeightMapAt(Vector3f location) {
// HEIGHTMAP image (for the terrain heightmap)
int x = (int) location.x;
int z = (int) location.z;
AbstractHeightMap heightmap = null;
//BufferedImage im = null;
String name = null;
try {
name = namer.getName(x, z);
logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
final Texture texture = assetManager.loadTexture(new TextureKey(name));
heightmap = new ImageBasedHeightMap(texture.getImage());
/*if (assetInfo != null){
InputStream in = assetInfo.openStream();
im = ImageIO.read(in);
} else {
im = new BufferedImage(patchSize, patchSize, imageType);
logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
}*/
// CREATE HEIGHTMAP
/*if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
heightmap = new Grayscale16BitHeightMap(im);
} else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
heightmap = new ImageBasedHeightMap(im);
} else if (customImageHeightmap != null && customImageHeightmap instanceof AbstractHeightMap) {
// If it gets here, it means you have specified a different image type, and you must
// then also supply a custom image heightmap class that can parse that image into
// a heightmap.
customImageHeightmap.setImage(im);
heightmap = (AbstractHeightMap) customImageHeightmap;
} else {
// error, no supported image format and no custom image heightmap specified
if (customImageHeightmap == null)
logger.log(Level.SEVERE, "Custom image type specified [{0}] but no customImageHeightmap declared! Use setCustomImageHeightmap()",imageType);
if (!(customImageHeightmap instanceof AbstractHeightMap))
logger.severe("customImageHeightmap must be an AbstractHeightMap!");
return null;
}*/
heightmap.setHeightScale(1);
heightmap.load();
//} catch (IOException e) {
// e.printStackTrace();
} catch (AssetNotFoundException e) {
logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name);
}
return heightmap;
}
use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class HDRRenderer method initialize.
public void initialize(RenderManager rm, ViewPort vp) {
if (!enabled)
return;
renderer = rm.getRenderer();
renderManager = rm;
viewPort = vp;
// loadInitial()
fsQuad = new Picture("HDR Fullscreen Quad");
Format lumFmt = Format.RGB8;
scene64FB = new FrameBuffer(64, 64, 1);
scene64 = new Texture2D(64, 64, lumFmt);
scene64FB.setColorTexture(scene64);
scene64.setMagFilter(fbMagFilter);
scene64.setMinFilter(fbMinFilter);
scene8FB = new FrameBuffer(8, 8, 1);
scene8 = new Texture2D(8, 8, lumFmt);
scene8FB.setColorTexture(scene8);
scene8.setMagFilter(fbMagFilter);
scene8.setMinFilter(fbMinFilter);
scene1FB[0] = new FrameBuffer(1, 1, 1);
scene1[0] = new Texture2D(1, 1, lumFmt);
scene1FB[0].setColorTexture(scene1[0]);
scene1FB[1] = new FrameBuffer(1, 1, 1);
scene1[1] = new Texture2D(1, 1, lumFmt);
scene1FB[1].setColorTexture(scene1[1]);
// prepare tonemap shader
tone = new Material(manager, "Common/MatDefs/Hdr/ToneMap.j3md");
tone.setFloat("A", 0.18f);
tone.setFloat("White", 100);
// load();
int w = vp.getCamera().getWidth();
int h = vp.getCamera().getHeight();
reshape(vp, w, h);
}
use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class TextureUtil method initialize.
public void initialize(EnumSet<Caps> caps) {
this.formats = GLImageFormats.getFormatsForCaps(caps);
if (logger.isLoggable(Level.FINE)) {
StringBuilder sb = new StringBuilder();
sb.append("Supported texture formats: \n");
for (int i = 0; i < Format.values().length; i++) {
Format format = Format.values()[i];
if (formats[0][i] != null) {
boolean srgb = formats[1][i] != null;
sb.append("\t").append(format.toString());
sb.append(" (Linear");
if (srgb)
sb.append("/sRGB");
sb.append(")\n");
}
}
logger.log(Level.FINE, sb.toString());
}
}
use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class PFMLoader method load.
private Image load(InputStream in, boolean needYFlip) throws IOException {
Format format = null;
String fmtStr = readString(in);
if (fmtStr.equals("PF")) {
format = Format.RGB32F;
} else if (fmtStr.equals("Pf")) {
format = Format.Luminance32F;
} else {
throw new IOException("File is not PFM format");
}
String sizeStr = readString(in);
int spaceIdx = sizeStr.indexOf(" ");
if (spaceIdx <= 0 || spaceIdx >= sizeStr.length() - 1)
throw new IOException("Invalid size syntax in PFM file");
int width = Integer.parseInt(sizeStr.substring(0, spaceIdx));
int height = Integer.parseInt(sizeStr.substring(spaceIdx + 1));
if (width <= 0 || height <= 0)
throw new IOException("Invalid size specified in PFM file");
String scaleStr = readString(in);
float scale = Float.parseFloat(scaleStr);
ByteOrder order = scale < 0 ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
boolean needEndienFlip = order != ByteOrder.nativeOrder();
// make sure all unneccessary stuff gets deleted from heap
// before allocating large amount of memory
System.gc();
int bytesPerPixel = format.getBitsPerPixel() / 8;
int scanLineBytes = bytesPerPixel * width;
ByteBuffer imageData = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
byte[] scanline = new byte[width * bytesPerPixel];
for (int y = height - 1; y >= 0; y--) {
if (!needYFlip)
imageData.position(scanLineBytes * y);
int read = 0;
int off = 0;
do {
read = in.read(scanline, off, scanline.length - off);
off += read;
} while (read > 0);
if (needEndienFlip) {
flipScanline(scanline);
}
imageData.put(scanline);
}
imageData.rewind();
return new Image(format, width, height, imageData, null, ColorSpace.Linear);
}
Aggregations