use of com.jme3.texture.Texture 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.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class TextureUtil method uploadTexture.
public void uploadTexture(Image image, int target, int index, boolean linearizeSrgb) {
boolean getSrgbFormat = image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb;
Image.Format jmeFormat = image.getFormat();
GLImageFormat oglFormat = getImageFormatWithError(jmeFormat, getSrgbFormat);
ByteBuffer data = null;
int sliceCount = 1;
if (index >= 0) {
data = image.getData(index);
}
if (image.getData() != null && image.getData().size() > 0) {
sliceCount = image.getData().size();
}
int width = image.getWidth();
int height = image.getHeight();
int depth = image.getDepth();
int[] mipSizes = image.getMipMapSizes();
int pos = 0;
// TODO: Remove unneccessary allocation
if (mipSizes == null) {
if (data != null) {
mipSizes = new int[] { data.capacity() };
} else {
mipSizes = new int[] { width * height * jmeFormat.getBitsPerPixel() / 8 };
}
}
int samples = image.getMultiSamples();
// For OGL3 core: setup texture swizzle.
if (oglFormat.swizzleRequired) {
setupTextureSwizzle(target, jmeFormat);
}
for (int i = 0; i < mipSizes.length; i++) {
int mipWidth = Math.max(1, width >> i);
int mipHeight = Math.max(1, height >> i);
int mipDepth = Math.max(1, depth >> i);
if (data != null) {
data.position(pos);
data.limit(pos + mipSizes[i]);
}
uploadTextureLevel(oglFormat, target, i, index, sliceCount, mipWidth, mipHeight, mipDepth, samples, data);
pos += mipSizes[i];
}
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class TextureUtil method uploadSubTexture.
public void uploadSubTexture(Image image, int target, int index, int x, int y, boolean linearizeSrgb) {
if (target != GL.GL_TEXTURE_2D || image.getDepth() > 1) {
throw new UnsupportedOperationException("Updating non-2D texture is not supported");
}
if (image.getMipMapSizes() != null) {
throw new UnsupportedOperationException("Updating mip-mappped images is not supported");
}
if (image.getMultiSamples() > 1) {
throw new UnsupportedOperationException("Updating multisampled images is not supported");
}
Image.Format jmeFormat = image.getFormat();
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");
}
boolean getSrgbFormat = image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb;
GLImageFormat oglFormat = getImageFormatWithError(jmeFormat, getSrgbFormat);
ByteBuffer data = null;
if (index >= 0) {
data = image.getData(index);
}
if (data == null) {
throw new IndexOutOfBoundsException("The image index " + index + " is not valid for the given image");
}
data.position(0);
data.limit(data.capacity());
gl.glTexSubImage2D(target, 0, x, y, image.getWidth(), image.getHeight(), oglFormat.format, oglFormat.dataType, data);
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class Ray method intersects.
/**
* <code>intersects</code> does the actual intersection work.
*
* @param v0
* first point of the triangle.
* @param v1
* second point of the triangle.
* @param v2
* third point of the triangle.
* @param store
* storage vector - if null, no intersection is calc'd
* @param doPlanar
* true if we are calcing planar results.
* @param quad
* @return true if ray intersects triangle
*/
private boolean intersects(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f store, boolean doPlanar, boolean quad) {
TempVars vars = TempVars.get();
Vector3f tempVa = vars.vect1, tempVb = vars.vect2, tempVc = vars.vect3, tempVd = vars.vect4;
Vector3f diff = origin.subtract(v0, tempVa);
Vector3f edge1 = v1.subtract(v0, tempVb);
Vector3f edge2 = v2.subtract(v0, tempVc);
Vector3f norm = edge1.cross(edge2, tempVd);
float dirDotNorm = direction.dot(norm);
float sign;
if (dirDotNorm > FastMath.FLT_EPSILON) {
sign = 1;
} else if (dirDotNorm < -FastMath.FLT_EPSILON) {
sign = -1f;
dirDotNorm = -dirDotNorm;
} else {
// ray and triangle/quad are parallel
vars.release();
return false;
}
float dirDotDiffxEdge2 = sign * direction.dot(diff.cross(edge2, edge2));
if (dirDotDiffxEdge2 >= 0.0f) {
float dirDotEdge1xDiff = sign * direction.dot(edge1.crossLocal(diff));
if (dirDotEdge1xDiff >= 0.0f) {
if (!quad ? dirDotDiffxEdge2 + dirDotEdge1xDiff <= dirDotNorm : dirDotEdge1xDiff <= dirDotNorm) {
float diffDotNorm = -sign * diff.dot(norm);
if (diffDotNorm >= 0.0f) {
// this method always returns
vars.release();
// if storage vector is null, just return true,
if (store == null) {
return true;
}
// else fill in.
float inv = 1f / dirDotNorm;
float t = diffDotNorm * inv;
if (!doPlanar) {
store.set(origin).addLocal(direction.x * t, direction.y * t, direction.z * t);
} else {
// these weights can be used to determine
// interpolated values, such as texture coord.
// eg. texcoord s,t at intersection point:
// s = w0*s0 + w1*s1 + w2*s2;
// t = w0*t0 + w1*t1 + w2*t2;
float w1 = dirDotDiffxEdge2 * inv;
float w2 = dirDotEdge1xDiff * inv;
//float w0 = 1.0f - w1 - w2;
store.set(t, w1, w2);
}
return true;
}
}
}
}
vars.release();
return false;
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class TestMipMapGen method simpleInitApp.
@Override
public void simpleInitApp() {
BitmapText txt = guiFont.createLabel("Left: HW Mips");
txt.setLocalTranslation(0, settings.getHeight() - txt.getLineHeight() * 4, 0);
guiNode.attachChild(txt);
txt = guiFont.createLabel("Right: AWT Mips");
txt.setLocalTranslation(0, settings.getHeight() - txt.getLineHeight() * 3, 0);
guiNode.attachChild(txt);
// create a simple plane/quad
Quad quadMesh = new Quad(1, 1);
quadMesh.updateGeometry(1, 1, false);
quadMesh.updateBound();
Geometry quad1 = new Geometry("Textured Quad", quadMesh);
Geometry quad2 = new Geometry("Textured Quad 2", quadMesh);
Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.png");
tex.setMinFilter(Texture.MinFilter.Trilinear);
Texture texCustomMip = tex.clone();
Image imageCustomMip = texCustomMip.getImage().clone();
MipMapGenerator.generateMipMaps(imageCustomMip);
texCustomMip.setImage(imageCustomMip);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setTexture("ColorMap", tex);
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setTexture("ColorMap", texCustomMip);
quad1.setMaterial(mat1);
// quad1.setLocalTranslation(1, 0, 0);
quad2.setMaterial(mat2);
quad2.setLocalTranslation(1, 0, 0);
rootNode.attachChild(quad1);
rootNode.attachChild(quad2);
}
Aggregations