Exemple #1
0
        private int AllocateMipMaps()
        {
            var len = HeightBlocks * DivSize * DeflatedStrideBytes;

            if (Header.MipMapCount <= 1)
            {
                return(len);
            }

            _mipMaps = new MipMapOffset[Header.MipMapCount - 1];
            var totalLen = len;

            for (int i = 1; i < Header.MipMapCount; i++)
            {
                var width        = Math.Max((int)(Header.Width / Math.Pow(2, i)), 1);
                var height       = Math.Max((int)(Header.Height / Math.Pow(2, i)), 1);
                var widthBlocks  = CalcBlocks(width);
                var heightBlocks = CalcBlocks(height);

                var stridePixels = widthBlocks * DivSize;
                var stride       = stridePixels * PixelDepthBytes;

                len             = heightBlocks * DivSize * stride;
                _mipMaps[i - 1] = new MipMapOffset(width, height, stride, totalLen, len);
                totalLen       += len;
            }

            return(totalLen);
        }
        private int AllocateMipMaps(DdsLoadInfo info)
        {
            var len = CalcSize(info);

            if (Header.MipMapCount <= 1)
            {
                return(len);
            }

            _mipMaps = new MipMapOffset[Header.MipMapCount - 1];
            var totalLen = len;

            for (int i = 0; i < Header.MipMapCount - 1; i++)
            {
                int width  = (int)Math.Max(info.DivSize, (int)(Header.Width / Math.Pow(2, i + 1)));
                int height = (int)Math.Max(info.DivSize, Header.Height / Math.Pow(2, i + 1));
                int stride = Util.Stride(width, BitsPerPixel);
                len = stride * height;

                _mipMaps[i] = new MipMapOffset(width, height, stride, totalLen, len);
                totalLen   += len;
            }

            return(totalLen);
        }