use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class TextureAtlas method convertImageToAwt.
private Image convertImageToAwt(Image source) {
//use awt dependent classes without actual dependency via reflection
try {
Class clazz = Class.forName("jme3tools.converters.ImageToAwt");
if (clazz == null) {
return null;
}
Image newImage = new Image(format, source.getWidth(), source.getHeight(), BufferUtils.createByteBuffer(source.getWidth() * source.getHeight() * 4), null, ColorSpace.Linear);
clazz.getMethod("convert", Image.class, Image.class).invoke(clazz.newInstance(), source, newImage);
return newImage;
} catch (InstantiationException ex) {
} catch (IllegalAccessException ex) {
} catch (IllegalArgumentException ex) {
} catch (InvocationTargetException ex) {
} catch (NoSuchMethodException ex) {
} catch (SecurityException ex) {
} catch (ClassNotFoundException ex) {
}
return null;
}
use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class TextureAtlas method getAtlasTexture.
/**
* Creates a new atlas texture for the given map name.
* @param mapName
* @return the atlas texture
*/
public Texture getAtlasTexture(String mapName) {
if (images == null) {
return null;
}
byte[] image = images.get(mapName);
if (image != null) {
//TODO check if color space shouldn't be sRGB
Texture2D tex = new Texture2D(new Image(format, atlasWidth, atlasHeight, BufferUtils.createByteBuffer(image), null, ColorSpace.Linear));
tex.setMagFilter(Texture.MagFilter.Bilinear);
tex.setMinFilter(Texture.MinFilter.BilinearNearestMipMap);
tex.setWrap(Texture.WrapMode.EdgeClamp);
return tex;
}
return null;
}
use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class TextureAtlas method drawImage.
private void drawImage(Image source, int x, int y, String mapName) {
if (images == null) {
images = new HashMap<String, byte[]>();
}
byte[] image = images.get(mapName);
//Texture Atlas should linearize the data if the source image isSRGB
if (image == null) {
image = new byte[atlasWidth * atlasHeight * 4];
images.put(mapName, image);
}
//TODO: all buffers?
ByteBuffer sourceData = source.getData(0);
int height = source.getHeight();
int width = source.getWidth();
Image newImage = null;
for (int yPos = 0; yPos < height; yPos++) {
for (int xPos = 0; xPos < width; xPos++) {
int i = ((xPos + x) + (yPos + y) * atlasWidth) * 4;
if (source.getFormat() == Format.ABGR8) {
int j = (xPos + yPos * width) * 4;
//a
image[i] = sourceData.get(j);
//b
image[i + 1] = sourceData.get(j + 1);
//g
image[i + 2] = sourceData.get(j + 2);
//r
image[i + 3] = sourceData.get(j + 3);
} else if (source.getFormat() == Format.BGR8) {
int j = (xPos + yPos * width) * 3;
//a
image[i] = 1;
//b
image[i + 1] = sourceData.get(j);
//g
image[i + 2] = sourceData.get(j + 1);
//r
image[i + 3] = sourceData.get(j + 2);
} else if (source.getFormat() == Format.RGB8) {
int j = (xPos + yPos * width) * 3;
//a
image[i] = 1;
//b
image[i + 1] = sourceData.get(j + 2);
//g
image[i + 2] = sourceData.get(j + 1);
//r
image[i + 3] = sourceData.get(j);
} else if (source.getFormat() == Format.RGBA8) {
int j = (xPos + yPos * width) * 4;
//a
image[i] = sourceData.get(j + 3);
//b
image[i + 1] = sourceData.get(j + 2);
//g
image[i + 2] = sourceData.get(j + 1);
//r
image[i + 3] = sourceData.get(j);
} else if (source.getFormat() == Format.Luminance8) {
int j = (xPos + yPos * width) * 1;
//a
image[i] = 1;
//b
image[i + 1] = sourceData.get(j);
//g
image[i + 2] = sourceData.get(j);
//r
image[i + 3] = sourceData.get(j);
} else if (source.getFormat() == Format.Luminance8Alpha8) {
int j = (xPos + yPos * width) * 2;
//a
image[i] = sourceData.get(j + 1);
//b
image[i + 1] = sourceData.get(j);
//g
image[i + 2] = sourceData.get(j);
//r
image[i + 3] = sourceData.get(j);
} else {
//ImageToAwt conversion
if (newImage == null) {
newImage = convertImageToAwt(source);
if (newImage != null) {
source = newImage;
sourceData = source.getData(0);
int j = (xPos + yPos * width) * 4;
//a
image[i] = sourceData.get(j);
//b
image[i + 1] = sourceData.get(j + 1);
//g
image[i + 2] = sourceData.get(j + 2);
//r
image[i + 3] = sourceData.get(j + 3);
} else {
throw new UnsupportedOperationException("Cannot draw or convert textures with format " + source.getFormat());
}
} else {
throw new UnsupportedOperationException("Cannot draw textures with format " + source.getFormat());
}
}
}
}
}
use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class OGLESContext method createView.
/**
* <code>createView</code> creates the GLSurfaceView that the renderer will
* draw to. <p> The result GLSurfaceView will receive input events and
* forward them to the Application. Any rendering will be done into the
* GLSurfaceView. Only one GLSurfaceView can be created at this time. The
* given configType specifies how to determine the display configuration.
*
* @return GLSurfaceView The newly created view
*/
public GLSurfaceView createView(Context context) {
// NOTE: We assume all ICS devices have OpenGL ES 2.0.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// below 4.0, check OpenGL ES 2.0 support.
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
if (info.reqGlEsVersion < 0x20000) {
throw new UnsupportedOperationException("OpenGL ES 2.0 is not supported on this device");
}
} else if (Build.VERSION.SDK_INT < 9) {
throw new UnsupportedOperationException("jME3 requires Android 2.3 or later");
}
// Start to set up the view
GLSurfaceView view = new GLSurfaceView(context);
logger.log(Level.INFO, "Android Build Version: {0}", Build.VERSION.SDK_INT);
if (androidInput == null) {
if (Build.VERSION.SDK_INT >= 14) {
androidInput = new AndroidInputHandler14();
} else if (Build.VERSION.SDK_INT >= 9) {
androidInput = new AndroidInputHandler();
}
}
androidInput.setView(view);
androidInput.loadSettings(settings);
// setEGLContextClientVersion must be set before calling setRenderer
// this means it cannot be set in AndroidConfigChooser (too late)
view.setEGLContextClientVersion(2);
view.setFocusableInTouchMode(true);
view.setFocusable(true);
// setFormat must be set before AndroidConfigChooser is called by the surfaceview.
// if setFormat is called after ConfigChooser is called, then execution
// stops at the setFormat call without a crash.
// We look at the user setting for alpha bits and set the surfaceview
// PixelFormat to either Opaque, Transparent, or Translucent.
// ConfigChooser will do it's best to honor the alpha requested by the user
// For best rendering performance, use Opaque (alpha bits = 0).
int curAlphaBits = settings.getAlphaBits();
logger.log(Level.FINE, "curAlphaBits: {0}", curAlphaBits);
if (curAlphaBits >= 8) {
logger.log(Level.FINE, "Pixel Format: TRANSLUCENT");
view.getHolder().setFormat(PixelFormat.TRANSLUCENT);
view.setZOrderOnTop(true);
} else if (curAlphaBits >= 1) {
logger.log(Level.FINE, "Pixel Format: TRANSPARENT");
view.getHolder().setFormat(PixelFormat.TRANSPARENT);
} else {
logger.log(Level.FINE, "Pixel Format: OPAQUE");
view.getHolder().setFormat(PixelFormat.OPAQUE);
}
AndroidConfigChooser configChooser = new AndroidConfigChooser(settings);
view.setEGLConfigChooser(configChooser);
view.setRenderer(this);
// reloading all the OpenGL objects.
if (Build.VERSION.SDK_INT >= 11) {
view.setPreserveEGLContextOnPause(true);
}
return view;
}
use of com.jme3.scene.VertexBuffer.Format in project chordatlas by twak.
the class MiniGen method inBounds.
private boolean inBounds(Matrix4d mini, List<double[]> bounds) {
// mini matrix is in mini-mesh format: a translation from a 255^3 cube in the first quadrant
// trans.offset is a transform from that space, into jme rendered space (cartesian in meters, around the origin)
Matrix4d m = new Matrix4d();
m.mul(Jme3z.fromMatrix(trans.offset), mini);
for (Point2d p : Arrays.stream(cubeCorners).map(c -> {
Point3d tmp = new Point3d();
m.transform(c, tmp);
return new Point2d(tmp.x, tmp.z);
}).collect(Collectors.toList())) {
for (double[] bound : bounds) {
if (bound[0] < p.x && bound[1] > p.x && bound[2] < p.y && bound[3] > p.y)
return true;
}
}
return false;
}
Aggregations