Home | History | Annotate | Download | only in utils
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *   http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  ******************************************************************************/
     16 
     17 package com.badlogic.gdx.graphics.g3d.utils;
     18 
     19 import com.badlogic.gdx.Gdx;
     20 import com.badlogic.gdx.assets.AssetManager;
     21 import com.badlogic.gdx.graphics.Texture;
     22 import com.badlogic.gdx.graphics.g3d.Model;
     23 import com.badlogic.gdx.graphics.g3d.model.data.ModelData;
     24 
     25 /** Used by {@link Model} to load textures from {@link ModelData}.
     26  * @author badlogic */
     27 public interface TextureProvider {
     28 	public Texture load (String fileName);
     29 
     30 	public static class FileTextureProvider implements TextureProvider {
     31 		private Texture.TextureFilter minFilter, magFilter;
     32 		private Texture.TextureWrap uWrap, vWrap;
     33 		private boolean useMipMaps;
     34 
     35 		public FileTextureProvider () {
     36 			minFilter = magFilter = Texture.TextureFilter.Linear;
     37 			uWrap = vWrap = Texture.TextureWrap.Repeat;
     38 			useMipMaps = false;
     39 		}
     40 
     41 		public FileTextureProvider (Texture.TextureFilter minFilter, Texture.TextureFilter magFilter, Texture.TextureWrap uWrap,
     42 			Texture.TextureWrap vWrap, boolean useMipMaps) {
     43 			this.minFilter = minFilter;
     44 			this.magFilter = magFilter;
     45 			this.uWrap = uWrap;
     46 			this.vWrap = vWrap;
     47 			this.useMipMaps = useMipMaps;
     48 		}
     49 
     50 		@Override
     51 		public Texture load (String fileName) {
     52 			Texture result = new Texture(Gdx.files.internal(fileName), useMipMaps);
     53 			result.setFilter(minFilter, magFilter);
     54 			result.setWrap(uWrap, vWrap);
     55 			return result;
     56 		}
     57 	}
     58 
     59 	public static class AssetTextureProvider implements TextureProvider {
     60 		public final AssetManager assetManager;
     61 
     62 		public AssetTextureProvider (final AssetManager assetManager) {
     63 			this.assetManager = assetManager;
     64 		}
     65 
     66 		@Override
     67 		public Texture load (String fileName) {
     68 			return assetManager.get(fileName, Texture.class);
     69 		}
     70 	}
     71 }
     72