use of com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter in project commons-gdx by gemserk.
the class AssetManagerRestoreHack method load.
@Override
public synchronized <T> void load(String fileName, Class<T> type, AssetLoaderParameters<T> parameter) {
TextureParameter textureParameters = (TextureParameter) parameter;
textures.add(textureParameters);
}
use of com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter in project libgdx by libgdx.
the class TextureAtlasLoader method getDependencies.
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle atlasFile, TextureAtlasParameter parameter) {
FileHandle imgDir = atlasFile.parent();
if (parameter != null)
data = new TextureAtlasData(atlasFile, imgDir, parameter.flip);
else {
data = new TextureAtlasData(atlasFile, imgDir, false);
}
Array<AssetDescriptor> dependencies = new Array();
for (Page page : data.getPages()) {
TextureParameter params = new TextureParameter();
params.format = page.format;
params.genMipMaps = page.useMipMaps;
params.minFilter = page.minFilter;
params.magFilter = page.magFilter;
dependencies.add(new AssetDescriptor(page.textureFile, Texture.class, params));
}
return dependencies;
}
use of com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter in project libgdx by libgdx.
the class Texture method invalidateAllTextures.
/** Invalidate all managed textures. This is an internal method. Do not use it! */
public static void invalidateAllTextures(Application app) {
Array<Texture> managedTextureArray = managedTextures.get(app);
if (managedTextureArray == null)
return;
if (assetManager == null) {
for (int i = 0; i < managedTextureArray.size; i++) {
Texture texture = managedTextureArray.get(i);
texture.reload();
}
} else {
// first we have to make sure the AssetManager isn't loading anything anymore,
// otherwise the ref counting trick below wouldn't work (when a texture is
// currently on the task stack of the manager.)
assetManager.finishLoading();
// next we go through each texture and reload either directly or via the
// asset manager.
Array<Texture> textures = new Array<Texture>(managedTextureArray);
for (Texture texture : textures) {
String fileName = assetManager.getAssetFileName(texture);
if (fileName == null) {
texture.reload();
} else {
// get the ref count of the texture, then set it to 0 so we
// can actually remove it from the assetmanager. Also set the
// handle to zero, otherwise we might accidentially dispose
// already reloaded textures.
final int refCount = assetManager.getReferenceCount(fileName);
assetManager.setReferenceCount(fileName, 0);
texture.glHandle = 0;
// create the parameters, passing the reference to the texture as
// well as a callback that sets the ref count.
TextureParameter params = new TextureParameter();
params.textureData = texture.getTextureData();
params.minFilter = texture.getMinFilter();
params.magFilter = texture.getMagFilter();
params.wrapU = texture.getUWrap();
params.wrapV = texture.getVWrap();
// not sure about this?
params.genMipMaps = texture.data.useMipMaps();
// special parameter which will ensure that the references stay the same.
params.texture = texture;
params.loadedCallback = new LoadedCallback() {
@Override
public void finishedLoading(AssetManager assetManager, String fileName, Class type) {
assetManager.setReferenceCount(fileName, refCount);
}
};
// unload the texture, create a new gl handle then reload it.
assetManager.unload(fileName);
texture.glHandle = Gdx.gl.glGenTexture();
assetManager.load(fileName, Texture.class, params);
}
}
managedTextureArray.clear();
managedTextureArray.addAll(textures);
}
}
use of com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter in project libgdx by libgdx.
the class TmxMapLoader method getDependencies.
/** Retrieves TiledMap resource dependencies
*
* @param fileName
* @param parameter not used for now
* @return dependencies for the given .tmx file */
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle tmxFile, Parameters parameter) {
Array<AssetDescriptor> dependencies = new Array<AssetDescriptor>();
try {
root = xml.parse(tmxFile);
boolean generateMipMaps = (parameter != null ? parameter.generateMipMaps : false);
TextureLoader.TextureParameter texParams = new TextureParameter();
texParams.genMipMaps = generateMipMaps;
if (parameter != null) {
texParams.minFilter = parameter.textureMinFilter;
texParams.magFilter = parameter.textureMagFilter;
}
for (FileHandle image : loadTilesets(root, tmxFile)) {
dependencies.add(new AssetDescriptor(image, Texture.class, texParams));
}
for (FileHandle image : loadImages(root, tmxFile)) {
dependencies.add(new AssetDescriptor(image, Texture.class, texParams));
}
return dependencies;
} catch (IOException e) {
throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
}
}
use of com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter in project libgdx by libgdx.
the class TextureLoaderPanel method initializeComponents.
@Override
protected void initializeComponents() {
super.initializeComponents();
JButton atlasButton = new JButton("Open Atlas");
JButton textureButton = new JButton("Open Texture");
JButton defaultTextureButton = new JButton("Default Texture");
final JCheckBox genMipMaps = new JCheckBox("Generate MipMaps");
final JComboBox minFilterBox = new JComboBox(new DefaultComboBoxModel(TextureFilter.values()));
final JComboBox magFilterBox = new JComboBox(new DefaultComboBoxModel(TextureFilter.values()));
minFilterBox.setSelectedItem(editor.getTexture().getMinFilter());
magFilterBox.setSelectedItem(editor.getTexture().getMagFilter());
ActionListener filterListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
editor.getTexture().setFilter((TextureFilter) minFilterBox.getSelectedItem(), (TextureFilter) magFilterBox.getSelectedItem());
}
};
minFilterBox.addActionListener(filterListener);
magFilterBox.addActionListener(filterListener);
atlasButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
File file = editor.showFileLoadDialog();
if (file != null) {
TextureAtlas atlas = editor.load(file.getAbsolutePath(), TextureAtlas.class, null, null);
if (atlas != null) {
editor.setAtlas(atlas);
}
}
}
});
textureButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
File file = editor.showFileLoadDialog();
if (file != null) {
TextureParameter params = new TextureParameter();
params.genMipMaps = genMipMaps.isSelected();
params.minFilter = (TextureFilter) minFilterBox.getSelectedItem();
params.magFilter = (TextureFilter) magFilterBox.getSelectedItem();
Texture texture = editor.load(file.getAbsolutePath(), Texture.class, null, params);
if (texture != null) {
editor.setTexture(texture);
}
}
}
});
defaultTextureButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editor.setTexture(editor.assetManager.get(FlameMain.DEFAULT_BILLBOARD_PARTICLE, Texture.class));
}
});
contentPanel.add(new JLabel("Min. Filter"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(minFilterBox, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(new JLabel("Mag. Filter"), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(magFilterBox, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(genMipMaps, new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(atlasButton, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(textureButton, new GridBagConstraints(1, 3, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(defaultTextureButton, new GridBagConstraints(2, 3, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
}
Aggregations