Beispiel #1
0
        /// <summary>
        /// Gets a copy of 3D texture data, specifying a mipmap level, source box, start index, and number of elements.
        /// </summary>
        /// <typeparam name="T">The type of the elements in the array.</typeparam>
        /// <param name="level">Mipmap level.</param>
        /// <param name="left">Position of the left side of the box on the x-axis.</param>
        /// <param name="top">Position of the top of the box on the y-axis.</param>
        /// <param name="right">Position of the right side of the box on the x-axis.</param>
        /// <param name="bottom">Position of the bottom of the box on the y-axis.</param>
        /// <param name="front">Position of the front of the box on the z-axis.</param>
        /// <param name="back">Position of the back of the box on the z-axis.</param>
        /// <param name="data">Array of data.</param>
        /// <param name="startIndex">Index of the first element to get.</param>
        /// <param name="elementCount">Number of elements to get.</param>
        public void GetData <T>(
            int level,
            int left,
            int top,
            int right,
            int bottom,
            int front,
            int back,
            T[] data,
            int startIndex,
            int elementCount
            ) where T : struct
        {
            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("data cannot be null");
            }
            if (data.Length < startIndex + elementCount)
            {
                throw new ArgumentException(
                          "The data passed has a length of " + data.Length.ToString() +
                          " but " + elementCount.ToString() + " pixels have been requested."
                          );
            }
            if ((left < 0 || left >= right) ||
                (top < 0 || top >= bottom) ||
                (front < 0 || front >= back))
            {
                throw new ArgumentException("Neither box size nor box position can be negative");
            }

            int elementSizeInBytes = Marshal.SizeOf(typeof(T));

            ValidateGetDataFormat(Format, elementSizeInBytes);

            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            FNA3D.FNA3D_GetTextureData3D(
                GraphicsDevice.GLDevice,
                texture,
                left,
                top,
                front,
                right - left,
                bottom - top,
                back - front,
                level,
                handle.AddrOfPinnedObject() + (startIndex * elementSizeInBytes),
                elementCount * elementSizeInBytes
                );
            handle.Free();
        }