Package de.nameless.graphicEngine.texture

Source Code of de.nameless.graphicEngine.texture.NEMaterialManager

package de.nameless.graphicEngine.texture;

import java.util.Hashtable;

import de.nameless.gameEngine.gui.LoadingScreen;

/**
* @author Stefan Wittek
* Diese Klasse Verwaltet die Texturen.
* Sie wird ben�tigt um Texturen zu binden.
*/
public class NEMaterialManager {
  private  TextureContainer bound = null;
 
  /**
   * Weist einem pfad den entsprechenden Texture container zu.
   */
  private Hashtable<String,TextureContainer> PathMap; 
 
  private static NEMaterialManager instance;
 
  public static NEMaterialManager getInstance(){
    if (instance == null ) instance = new NEMaterialManager();
    return instance;
  }
 
  private NEMaterialManager(){
    PathMap = new Hashtable<String,TextureContainer>();
  }
 
  /**
   * L�dt die angegebene Textur in den Manager.
   * @param path Pfad der Bilddatei innerhalb von "resources/Images/" des Ordners innerhalb des root verzeichnisses.
   */
  public void load(String path){
    TextureContainer neu = new TextureContainer(path,TextureLoader.load("resources/Images/" + path));
    PathMap.put(path, neu);
    bound = neu;
    bound.getTexture().bind()
  }
 
  /**
   * L�dt die �bergebenen Texturen vor
  */
  public void preLoad(String[] pathes){
    LoadingScreen l = new LoadingScreen("lade: ");
    for (int i = 0; i < pathes.length; i++) {
      l.DoNextStep(pathes.length+1, i, pathes[i]);
      load(pathes[i]);     
    }
    l.dispose();
  }

 
  /**
   * Liefert die gew�nschte Textur in einem kontainer. Falls N�tig wird sie zufor in das system geladen.
   * @param path Pfad der Bilddatei innerhalb von "resources/Images/" des Ordners innerhalb des root verzeichnisses.
  */
  public de.nameless.graphicEngine.texture.TextureContainer getTexture(String path){
      TextureContainer t = PathMap.get(path);
    if (t == null){
      this.load(path);
   
      return PathMap.get(path);
     
  }
  /**
   * Bindet die angegebene Texture, falls nicht bereits gebunden.
   * Ist die textur noch nicht geladen geschied auch das.
   * @param path Pfad der Bilddatei innerhalb von "resources/Images/" des Ordners innerhalb des root Verzeichnisses.
   */
  public void bindTexture(String path){
    if (bound != null){
      if (path != bound.getPath()){
        bound = getTexture(path);
        bound.getTexture().bind();
       
      }
    } else {
      bound = getTexture(path);
      bound.getTexture().bind();
    }
   
  } 

  /**
   * Bindet, falls noch nicht geschehen, die textur des Objektes
   * @param o Objekt dessen textur gebunden werden soll.
   */
  public void bindObjectTexture(Textured o){
    bindTexture(o.getTexturePath());
  }
 
 
}
TOP

Related Classes of de.nameless.graphicEngine.texture.NEMaterialManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.