Exemple #1
0
        unsafe void CalculateMipInfosNoncompressed(int mipCount, int pitch, out int chainSize)
        {
            if (mipCount == -1)
                mipCount = 1;

            int bytesPerPixel = Helper.FormatBits(DxgiFormat, D3DFormat) / 8;

            if (pitch == -1)
            {
                pitch = Width * bytesPerPixel;
                if ((pitch & 0x3) != 0)
                    pitch += 4 - (pitch & 0x3);
            }

            MipInfos = new MipInfo[mipCount];
            fixed (MipInfo* infos = MipInfos)
            {
                infos[0] = new MipInfo
                {
                    Width = Width,
                    Height = Height,
                    Depth = Depth,
                    OffsetInBytes = 0,
                    SizeInBytes = Height * pitch
                };

                for (int i = 1; i < mipCount; i++)
                {
                    infos[i] = new MipInfo
                    {
                        Width = Math.Max(1, infos[i - 1].Width / 2),
                        Height = Math.Max(1, infos[i - 1].Height / 2),
                        Depth = Math.Max(1, infos[i - 1].Depth / 2),
                        OffsetInBytes = infos[i - 1].OffsetInBytes + infos[i - 1].SizeInBytes,
                    };

                    int mipPitch = infos[i].Width * bytesPerPixel;
                    if ((mipPitch & 0x3) != 0)
                        mipPitch += 4 - (mipPitch & 0x3);

                    infos[i].SizeInBytes = mipPitch * infos[i].Height * infos[i].Depth;
                }

                chainSize = infos[mipCount - 1].OffsetInBytes + infos[mipCount - 1].SizeInBytes;
            }
        }
Exemple #2
0
        unsafe void CalculateMipInfosCompressed(int mipCount, int linearSize, out int chainSize)
        {
            if (mipCount == -1)
                mipCount = 1;

            int multiplyer =
                        DxgiFormat == DxgiFormat.BC1_TYPELESS || DxgiFormat == DxgiFormat.BC1_UNORM ||
                        DxgiFormat == DxgiFormat.BC1_UNORM_SRGB || D3DFormat == D3DFormat.Dxt1
                            ? 8
                            : 16;

            if (linearSize == -1)
                linearSize = Math.Max(1, Width / 4) * Math.Max(1, Height / 4) * multiplyer;

            MipInfos = new MipInfo[mipCount];
            fixed (MipInfo* infos = MipInfos)
            {
                infos[0] = new MipInfo
                {
                    Width = Width,
                    Height = Height,
                    Depth = Depth,
                    OffsetInBytes = 0,
                    SizeInBytes = linearSize
                };

                for (int i = 1; i < mipCount; i++)
                {
                    infos[i] = new MipInfo
                    {
                        Width = Math.Max(1, infos[i - 1].Width / 2),
                        Height = Math.Max(1, infos[i - 1].Height / 2),
                        Depth = Math.Max(1, infos[i - 1].Depth / 2),
                        OffsetInBytes = infos[i - 1].OffsetInBytes + infos[i - 1].SizeInBytes,
                    };

                    infos[i].SizeInBytes =
                        Math.Max(1, infos[i].Width / 4) * Math.Max(1, infos[i].Height / 4)
                        * infos[i].Depth * multiplyer;
                }

                chainSize = infos[mipCount - 1].OffsetInBytes + infos[mipCount - 1].SizeInBytes;
            }
        }