#region License /* FNA - XNA4 Reimplementation for Desktop Platforms * Copyright 2009-2016 Ethan Lee and the MonoGame Team * * Released under the Microsoft Public License. * See LICENSE for details. */ #endregion #region Using Statements using System; using System.Runtime.InteropServices; #endregion namespace Microsoft.Xna.Framework.Graphics { public class Texture3D : Texture { #region Public Properties public int Width { get; private set; } public int Height { get; private set; } public int Depth { get; private set; } #endregion #region Public Constructor public Texture3D( GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat format ) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } GraphicsDevice = graphicsDevice; Width = width; Height = height; Depth = depth; LevelCount = mipMap ? CalculateMipLevels(width, height) : 1; Format = format; texture = GraphicsDevice.GLDevice.CreateTexture3D( format, width, height, depth, LevelCount ); } #endregion #region Public SetData Methods public void SetData(T[] data) where T : struct { SetData( data, 0, data.Length ); } public void SetData( T[] data, int startIndex, int elementCount ) where T : struct { SetData( 0, 0, 0, Width, Height, 0, Depth, data, startIndex, elementCount ); } public void SetData( 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) { throw new ArgumentNullException("data"); } GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); GraphicsDevice.GLDevice.SetTextureData3D( texture, Format, level, left, top, right, bottom, front, back, handle.AddrOfPinnedObject(), startIndex, elementCount, Marshal.SizeOf(typeof(T)) ); handle.Free(); } #endregion #region Public GetData Methods /// /// Gets a copy of 3D texture data. /// /// The type of the elements in the array. /// Array of data. public void GetData(T[] data) where T : struct { GetData( data, 0, data.Length ); } /// /// Gets a copy of 3D texture data, specifying a start index and number of elements. /// /// The type of the elements in the array. /// Array of data. /// Index of the first element to get. /// Number of elements to get. public void GetData( T[] data, int startIndex, int elementCount ) where T : struct { GetData( 0, 0, 0, Width, Height, 0, Depth, data, startIndex, elementCount ); } /// /// Gets a copy of 3D texture data, specifying a mipmap level, source box, start index, and number of elements. /// /// The type of the elements in the array. /// Mipmap level. /// Position of the left side of the box on the x-axis. /// Position of the top of the box on the y-axis. /// Position of the right side of the box on the x-axis. /// Position of the bottom of the box on the y-axis. /// Position of the front of the box on the z-axis. /// Position of the back of the box on the z-axis. /// Array of data. /// Index of the first element to get. /// Number of elements to get. public void GetData( 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"); } throw new NotImplementedException(); } #endregion } }