Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TexImage"/> class.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="dataSize">Size of the data.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="format">The format.</param>
        /// <param name="mipmapCount">The mipmap count.</param>
        /// <param name="arraySize">Size of the array.</param>
        /// <param name="dimension">The dimension.</param>
        /// <param name="faceCount">The face count (multiple of 6 if Texture Cube, 1 otherwise).</param>
        /// <param name="alphaDepth">The depth of the alpha channel</param>
        public TexImage(IntPtr data, int dataSize, int width, int height, int depth, PixelFormat format, int mipmapCount, int arraySize, TextureDimension dimension, int faceCount = 1, int alphaDepth = -1)
        {
            Data = data;
            DataSize = dataSize;
            Width = width;
            Height = height;
            Depth = depth;
            Format = format;
            MipmapCount = mipmapCount;
            ArraySize = arraySize;
            Dimension = dimension;
            FaceCount = faceCount;
            OriginalAlphaDepth = alphaDepth;
            Name = "";

            int imageCount;
            if (Dimension == TextureDimension.Texture3D)
            {
                int subImagePerArrayElementCount = 0;
                int curDepth = Depth;
                for (int i = 0; i < MipmapCount; ++i)
                {
                    subImagePerArrayElementCount += curDepth;
                    curDepth = curDepth > 1 ? curDepth >>= 1 : curDepth;
                }

                imageCount = (int)(ArraySize * FaceCount * subImagePerArrayElementCount);
            }
            else
            {
                imageCount = (int)(ArraySize * FaceCount * MipmapCount);
            }

            SubImageArray = new SubImage[imageCount];
            int ct = 0;
            int rowPitch, slicePitch, curHeight, curWidth;

            Tools.ComputePitch(Format, Width, Height, out rowPitch, out slicePitch);
            RowPitch = rowPitch;
            SlicePitch = slicePitch;

            for (uint i = 0; i < FaceCount; ++i)
            {
                for (uint j = 0; j < ArraySize; ++j)
                {
                    depth = Depth;
                    for (uint k = 0; k < MipmapCount; ++k)
                    {
                        curWidth = Width;
                        curHeight = Height;
                        Tools.ComputePitch(Format, curWidth, curHeight, out rowPitch, out slicePitch);

                        for (int l = 0; l < depth; ++l)
                        {
                            SubImageArray[ct] = new TexImage.SubImage();
                            SubImageArray[ct].Width = curWidth;
                            SubImageArray[ct].Height = curHeight;
                            SubImageArray[ct].RowPitch = rowPitch;
                            SubImageArray[ct].SlicePitch = slicePitch;
                            SubImageArray[ct].DataSize = slicePitch;
                            SubImageArray[ct].Data = new IntPtr(Data.ToInt64() + l * slicePitch);
                            ++ct;
                        }
                        depth = depth > 1 ? depth >>= 1 : depth;
                    }
                }
            }

            LibraryData = new Dictionary<ITexLibrary, ITextureLibraryData>();

            Disposed = false;
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TexImage"/> class.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="dataSize">Size of the data.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="format">The format.</param>
        /// <param name="mipmapCount">The mipmap count.</param>
        /// <param name="arraySize">Size of the array.</param>
        /// <param name="dimension">The dimension.</param>
        /// <param name="faceCount">The face count (multiple of 6 if Texture Cube, 1 otherwise).</param>
        /// <param name="alphaDepth">The depth of the alpha channel</param>
        public TexImage(IntPtr data, int dataSize, int width, int height, int depth, PixelFormat format, int mipmapCount, int arraySize, TextureDimension dimension, int faceCount = 1, int alphaDepth = -1)
        {
            Data               = data;
            DataSize           = dataSize;
            Width              = width;
            Height             = height;
            Depth              = depth;
            Format             = format;
            MipmapCount        = mipmapCount;
            ArraySize          = arraySize;
            Dimension          = dimension;
            FaceCount          = faceCount;
            OriginalAlphaDepth = alphaDepth;
            Name               = "";

            int imageCount;

            if (Dimension == TextureDimension.Texture3D)
            {
                int subImagePerArrayElementCount = 0;
                int curDepth = Depth;
                for (int i = 0; i < MipmapCount; ++i)
                {
                    subImagePerArrayElementCount += curDepth;
                    curDepth = curDepth > 1 ? curDepth >>= 1 : curDepth;
                }

                imageCount = (int)(ArraySize * FaceCount * subImagePerArrayElementCount);
            }
            else
            {
                imageCount = (int)(ArraySize * FaceCount * MipmapCount);
            }

            SubImageArray = new SubImage[imageCount];
            int ct = 0;
            int rowPitch, slicePitch, curHeight, curWidth;

            Tools.ComputePitch(Format, Width, Height, out rowPitch, out slicePitch);
            RowPitch   = rowPitch;
            SlicePitch = slicePitch;

            for (uint i = 0; i < FaceCount; ++i)
            {
                for (uint j = 0; j < ArraySize; ++j)
                {
                    depth = Depth;
                    for (uint k = 0; k < MipmapCount; ++k)
                    {
                        curWidth  = Width;
                        curHeight = Height;
                        Tools.ComputePitch(Format, curWidth, curHeight, out rowPitch, out slicePitch);

                        for (int l = 0; l < depth; ++l)
                        {
                            SubImageArray[ct]            = new TexImage.SubImage();
                            SubImageArray[ct].Width      = curWidth;
                            SubImageArray[ct].Height     = curHeight;
                            SubImageArray[ct].RowPitch   = rowPitch;
                            SubImageArray[ct].SlicePitch = slicePitch;
                            SubImageArray[ct].DataSize   = slicePitch;
                            SubImageArray[ct].Data       = new IntPtr(Data.ToInt64() + l * slicePitch);
                            ++ct;
                        }
                        depth = depth > 1 ? depth >>= 1 : depth;
                    }
                }
            }

            LibraryData = new Dictionary <ITexLibrary, ITextureLibraryData>();

            Disposed = false;
        }