1 
  2 /**
  3 	@private
  4 
  5 	Check if a texture has the correct dimensions for OpenGL.  The texture 
  6 	must not be too small, that is must be greater than 1x1. and must have
  7 	a size of a power of 2: 2x2, 4x4, 8x8, 16x16, etc.
  8 	
  9 	@param texture
 10 
 11 	@returns {boolean} true if the image has the correct dimensions, false otherwise.
 12 */
 13 c3dl.hasCorrectDimensions = function(texture)
 14 {					
 15 	// broke down cases where the texture could be invalid so user
 16 	// knows where to look first
 17 	var isCorrect = false;
 18 
 19 	// textures cannot have size 0 or 1.
 20 	if(texture.width <= 1 || texture.height <= 1)
 21 	{				
 22 		c3dl.debug.logWarning('Texture ' + texture.src + ' is too small.' +
 23 		'Dimensions are: ' + texture.width + "x" + texture.height + ". " +
 24 		'<br/>Texture was resized.');
 25 	}
 26 	
 27 	// Texture width and height must be a power of 2. By performing a 
 28 	// bitwise and, we can see if the bit to the far left is on and all
 29 	// other bits are off, thus, the size must be square.
 30 	// 10(bin) = 2(dec)		= power of 2
 31 	// 100(bin) = 4dec)		= power of 2
 32 	// 1000(bin) = 8(dec)	= power of 2
 33 	// etc..
 34 	else if((texture.width & (texture.width-1)) || (texture.height & (texture.height-1)))
 35 	{
 36 		c3dl.debug.logWarning('Texture ' + texture.src + ' must have a width and height of a power of 2.' +
 37 		'Dimensions are: ' + texture.width + "x" + texture.height + ". " +
 38 		'Dimensions must be something like: 2x2, 2x4, 4x4, 4x8, 8x8, 16x8, 16x16, etc..' +
 39 		'<br />Texture has been resized.');
 40 	}
 41 	
 42 	// if we didn't satisfy any of the conditionals, texture 
 43 	// should be okay
 44 	else{
 45 		isCorrect = true;
 46 	}
 47 	
 48 	return isCorrect;	
 49 }
 50