requestedCropRegion.minY(), requestedCropRegion.maxY() + 1);
currentTextureCropRegion = requestedCropRegion;
}
Vector2f scale = mode.scaleForRegion(absoluteRegion, texture.getWidth(), texture.getHeight());
Rect2f textureArea = texture.getRegion();
Mesh mesh = billboard;
switch (mode) {
case TILED: {
TextureCacheKey key = new TextureCacheKey(texture.size(), absoluteRegion.size());
usedTextures.add(key);
mesh = cachedTextures.get(key);
if (mesh == null || mesh.isDisposed()) {
MeshBuilder builder = new MeshBuilder();
addTiles(builder, absoluteRegion, FULL_REGION, texture.size(), FULL_REGION);
mesh = builder.build();
cachedTextures.put(key, mesh);
}
textureMat.setFloat2("scale", scale);
textureMat.setFloat2("offset",
absoluteRegion.minX(),
absoluteRegion.minY());
textureMat.setFloat2("texOffset", textureArea.minX() + ux * textureArea.width(), textureArea.minY() + uy * textureArea.height());
textureMat.setFloat2("texSize", uw * textureArea.width(), uh * textureArea.height());
break;
}
case SCALE_FILL: {
textureMat.setFloat2("offset", absoluteRegion.minX(), absoluteRegion.minY());
textureMat.setFloat2("scale", absoluteRegion.width(), absoluteRegion.height());
float texBorderX = (scale.x - absoluteRegion.width()) / scale.x * uw;
float texBorderY = (scale.y - absoluteRegion.height()) / scale.y * uh;
textureMat.setFloat2("texOffset", textureArea.minX() + (ux + 0.5f * texBorderX) * textureArea.width()
, textureArea.minY() + (uy + 0.5f * texBorderY) * textureArea.height());
textureMat.setFloat2("texSize", (uw - texBorderX) * textureArea.width(), (uh - texBorderY) * textureArea.height());
break;
}
default: {
textureMat.setFloat2("scale", scale);
textureMat.setFloat2("offset",
absoluteRegion.minX() + 0.5f * (absoluteRegion.width() - scale.x),
absoluteRegion.minY() + 0.5f * (absoluteRegion.height() - scale.y));
textureMat.setFloat2("texOffset", textureArea.minX() + ux * textureArea.width(), textureArea.minY() + uy * textureArea.height());
textureMat.setFloat2("texSize", uw * textureArea.width(), uh * textureArea.height());
break;
}
}
textureMat.setTexture("texture", texture.getTexture());