Search in sources :

Example 1 with TextureParameter

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);
}
Also used : TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter)

Example 2 with TextureParameter

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;
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) FileHandle(com.badlogic.gdx.files.FileHandle) Page(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter) Texture(com.badlogic.gdx.graphics.Texture) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 3 with TextureParameter

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);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) LoadedCallback(com.badlogic.gdx.assets.AssetLoaderParameters.LoadedCallback) AssetManager(com.badlogic.gdx.assets.AssetManager) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter)

Example 4 with TextureParameter

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);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) IntArray(com.badlogic.gdx.utils.IntArray) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TextureLoader(com.badlogic.gdx.assets.loaders.TextureLoader) FileHandle(com.badlogic.gdx.files.FileHandle) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter) IOException(java.io.IOException) Texture(com.badlogic.gdx.graphics.Texture) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 5 with TextureParameter

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));
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) TextureFilter(com.badlogic.gdx.graphics.Texture.TextureFilter) Texture(com.badlogic.gdx.graphics.Texture) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter) File(java.io.File)

Aggregations

TextureParameter (com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter)5 Texture (com.badlogic.gdx.graphics.Texture)3 Array (com.badlogic.gdx.utils.Array)3 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)2 FileHandle (com.badlogic.gdx.files.FileHandle)2 LoadedCallback (com.badlogic.gdx.assets.AssetLoaderParameters.LoadedCallback)1 AssetManager (com.badlogic.gdx.assets.AssetManager)1 TextureLoader (com.badlogic.gdx.assets.loaders.TextureLoader)1 TextureFilter (com.badlogic.gdx.graphics.Texture.TextureFilter)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)1 Page (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 IntArray (com.badlogic.gdx.utils.IntArray)1 GridBagConstraints (java.awt.GridBagConstraints)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 IOException (java.io.IOException)1