Microsoft.Xna.Framework.Graphics.Texture.CalculateMipLevels C# (CSharp) Method

CalculateMipLevels() static private method

static private CalculateMipLevels ( int width, int height, int depth ) : int
width int
height int
depth int
return int
        internal static int CalculateMipLevels(int width, int height = 0, int depth = 0)
        {
            int levels = 1;
            int size = Math.Max(Math.Max(width, height), depth);
            while (size > 1)
            {
                size = size / 2;
                levels++;
            }
            return levels;
        }

Usage Example

Example #1
0
 internal TextureCube(GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format, bool renderTarget)
 {
     if (graphicsDevice == null)
     {
         throw new ArgumentNullException("graphicsDevice");
     }
     this.GraphicsDevice = graphicsDevice;
     this.size           = size;
     this.format         = format;
     this.levelCount     = mipMap ? Texture.CalculateMipLevels(size, 0, 0) : 1;
     this.glTarget       = TextureTarget.TextureCubeMap;
     GL.GenTextures(1, out this.glTexture);
     GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture);
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, mipMap ? 9987 : 9729);
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, 9729);
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, 33071);
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, 33071);
     GraphicsExtensions.GetGLFormat(format, out this.glInternalFormat, out this.glFormat, out this.glType);
     for (int index = 0; index < 6; ++index)
     {
         TextureTarget glCubeFace = this.GetGLCubeFace((CubeMapFace)index);
         if (this.glFormat == (PixelFormat)34467)
         {
             throw new NotImplementedException();
         }
         GL.TexImage2D(glCubeFace, 0, this.glInternalFormat, size, size, 0, this.glFormat, this.glType, IntPtr.Zero);
     }
     if (!mipMap)
     {
         return;
     }
     GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.GenerateMipmap, 1);
 }
All Usage Examples Of Microsoft.Xna.Framework.Graphics.Texture::CalculateMipLevels