use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class KTXLoader method getImageFormat.
/**
* returns the JME image format from gl formats and types.
* @param glFormat
* @param glInternalFormat
* @param glType
* @return
*/
private Image.Format getImageFormat(int glFormat, int glInternalFormat, int glType) {
EnumSet<Caps> caps = EnumSet.allOf(Caps.class);
GLImageFormat[][] formats = GLImageFormats.getFormatsForCaps(caps);
for (GLImageFormat[] format : formats) {
for (int j = 0; j < format.length; j++) {
GLImageFormat glImgFormat = format[j];
if (glImgFormat != null) {
if (glImgFormat.format == glFormat && glImgFormat.dataType == glType) {
if (glFormat == glInternalFormat || glImgFormat.internalFormat == glInternalFormat) {
return Image.Format.values()[j];
}
}
}
}
}
return null;
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class JmeBatchRenderBackend method loadImage.
@Override
public Image loadImage(final String filename) {
TextureKey key = new TextureKey(filename, false);
key.setAnisotropy(0);
key.setGenerateMips(false);
Texture2D texture = (Texture2D) display.getAssetManager().loadTexture(key);
return new ImageImpl(texture.getImage());
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class JmeBatchRenderBackend method createNonAtlasTexture.
@Override
public int createNonAtlasTexture(final Image image) {
ImageImpl imageImpl = (ImageImpl) image;
Texture2D texture = new Texture2D(imageImpl.image);
texture.setMinFilter(MinFilter.NearestNoMipMaps);
texture.setMagFilter(MagFilter.Nearest);
return addTexture(texture);
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class JmeBatchRenderBackend method modifyTexture.
private void modifyTexture(final Texture2D textureAtlas, final com.jme3.texture.Image image, final int x, final int y) {
Renderer renderer = display.getRenderer();
if (renderer == null) {
// we have no renderer (yet) so we'll need to cache this call to the next beginFrame() call
modifyTextureCalls.add(new ModifyTexture(textureAtlas, image, x, y));
return;
}
// all is well, we can execute the modify right away
renderer.modifyTexture(textureAtlas, image, x, y);
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class CombinedTexture method isWithoutAlpha.
/**
* This method determines if the given texture has no alpha channel.
*
* @param texture
* the texture to check for alpha channel
* @return <b>true</b> if the texture has no alpha channel and <b>false</b>
* otherwise
*/
private boolean isWithoutAlpha(TextureData textureData, BlenderContext blenderContext) {
ColorBand colorBand = new ColorBand(textureData.textureStructure, blenderContext);
if (!colorBand.hasTransparencies()) {
int type = ((Number) textureData.textureStructure.getFieldValue("type")).intValue();
if (type == TextureHelper.TEX_MAGIC) {
return true;
}
if (type == TextureHelper.TEX_VORONOI) {
int voronoiColorType = ((Number) textureData.textureStructure.getFieldValue("vn_coltype")).intValue();
// voronoiColorType == 0:
return voronoiColorType != 0;
// intensity, voronoiColorType
// != 0: col1, col2 or col3
}
if (type == TextureHelper.TEX_CLOUDS) {
int sType = ((Number) textureData.textureStructure.getFieldValue("stype")).intValue();
// sType==0: without colors, sType==1: with
return sType == 1;
// colors
}
// checking the flat textures for alpha values presence
if (type == TextureHelper.TEX_IMAGE) {
Image image = textureData.texture.getImage();
switch(image.getFormat()) {
case BGR8:
case DXT1:
case Luminance16F:
case Luminance32F:
case Luminance8:
case RGB111110F:
case RGB16F:
case RGB32F:
case RGB565:
case RGB8:
// these types have no alpha by definition
return true;
case ABGR8:
case DXT1A:
case DXT3:
case DXT5:
case Luminance16FAlpha16F:
case Luminance8Alpha8:
case RGBA16F:
case RGBA32F:
case RGBA8:
case ARGB8:
case BGRA8:
case // with these types it is better to make sure if the texture is or is not transparent
RGB5A1:
PixelInputOutput pixelInputOutput = PixelIOFactory.getPixelIO(image.getFormat());
TexturePixel pixel = new TexturePixel();
int depth = image.getDepth() == 0 ? 1 : image.getDepth();
for (int layerIndex = 0; layerIndex < depth; ++layerIndex) {
for (int x = 0; x < image.getWidth(); ++x) {
for (int y = 0; y < image.getHeight(); ++y) {
pixelInputOutput.read(image, layerIndex, pixel, x, y);
if (pixel.alpha < 1.0f) {
return false;
}
}
}
}
return true;
default:
throw new IllegalStateException("Unknown image format: " + image.getFormat());
}
}
}
return false;
}
Aggregations