1 /**
  2  * potree.js 
  3  * http://potree.org
  4  *
  5  * Copyright 2012, Markus Sch�tz
  6  * Licensed under the GPL Version 2 or later.
  7  * - http://potree.org/wp/?page_id=7
  8  * - http://www.gnu.org/licenses/gpl-3.0.html
  9  *
 10  */
 11 /**
 12  * Textures have to be loaded first by invoking loadTexture(). Once its loaded, it can be accessed with getTexture()
 13  * 
 14  * @class
 15  */
 16 function TextureManager(){
 17 	
 18 }
 19 
 20 TextureManager.textures = new Array();
 21 
 22 
 23 TextureManager.getTexture = function(name){
 24 	for(var i = 0; i < this.textures.length; i++){
 25 		var texture = this.textures[i];
 26 		if(texture.name == name){
 27 			return texture;
 28 		}
 29 	}
 30 	
 31 	return null;
 32 }
 33 
 34 /**
 35  * 
 36  * @param source
 37  * @param name each texture is stored with this unique name. this name can be used to retrieve the texture with getTexture 
 38  * @returns
 39  */
 40 TextureManager.loadTexture = function(source, name){
 41 	var textureId = gl.createTexture();
 42 	var image = new Image();
 43 	image.onload = function() {
 44 		var texture = new Texture();
 45 		texture.glid = textureId;
 46 		texture.source = source;
 47 		texture.name = name;
 48 		texture.image = image;
 49 		
 50 		gl.bindTexture(gl.TEXTURE_2D, texture.glid);
 51 	    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
 52 	    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.image);
 53 	    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
 54 	    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
 55 	    gl.bindTexture(gl.TEXTURE_2D, null);
 56 		
 57 	    TextureManager.textures.push(texture);
 58 	};
 59 	image.src = source;
 60 }
 61 
 62 /**
 63  * @class
 64  */
 65 function Texture(){
 66 	
 67 }