Table of Contents

Class Texture3D

Namespace
Microsoft.Xna.Framework.Graphics
Assembly
MonoGame.Framework.dll

Represents a 3D volume of texels.

public class Texture3D : Texture, IDisposable
Inheritance
Texture3D
Implements
Inherited Members

Remarks

A texel represents the smallest unit of a texture that can be read from or written to by the GPU. A texel is composed of 1 to 4 components. Specifically, a texel may be any one of the available texture formats represented in the SurfaceFormat enumeration.

A Texture3D resource (also known as a volume texture) contains a 3D volume of texels. Since it is a texture resource, it may contain mipmap levels.

When a Texture3D mipmap slice is bound as a render target output (by creating a RenderTargetCube), the Texture3D behaves identically to an array of Texture2D objects with n array slices, where n is the depth (third dimension) of the Texture3D.

Constructors

Texture3D(GraphicsDevice, int, int, int, bool, SurfaceFormat)

Creates an uninitialized Texture3D resource with the specified parameters.

public Texture3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat format)

Parameters

graphicsDevice GraphicsDevice

The graphics device used to display the texture.

width int

The width, in pixels, of the texture.

height int

The height, in pixels, of the texture.

depth int

The depth, in pixels, of the texture.

mipMap bool

true if mimapping is enabled for the texture; otherwise, false.

format SurfaceFormat

The surface format of the texture.

Remarks

To initialize the texture with data after creating, you can use one of the SetData methods.

To initialize a Texture3D from an existing file use the ContentManager.Load method if loading a pipeline preprocessed Texture3D from an .xnb file.

Exceptions

ArgumentNullException

The graphicsDevice parameter is null.

ArgumentOutOfRangeException

The width, height, and/or depth parameters are less than or equal to zero.

Texture3D(GraphicsDevice, int, int, int, bool, SurfaceFormat, bool)

protected Texture3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat format, bool renderTarget)

Parameters

graphicsDevice GraphicsDevice
width int
height int
depth int
mipMap bool
format SurfaceFormat
renderTarget bool

Properties

Depth

Gets the depth, in pixels, of this texture resource.

public int Depth { get; }

Property Value

int

Height

Gets the height, in pixels, of this texture resource.

public int Height { get; }

Property Value

int

Width

Gets the width, in pixels, of this texture resource.

public int Width { get; }

Property Value

int

Methods

GetData<T>(int, int, int, int, int, int, int, T[], int, int)

Copies texture data into an array.

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

Parameters

level int

The mipmap level where the data will be placed.

left int

Position of the left side of the box on the x-axis.

top int

Position of the top of the box on the y-axis.

right int

Position of the right side of the box on the x-axis.

bottom int

Position of the bottom of the box on the y-axis.

front int

Position of the front of the box on the z-axis.

back int

Position of the back of the box on the z-axis.

data T[]

The array of data to copy.

startIndex int

The index of the element in the array at which to start copying.

elementCount int

The number of elements to copy.

Type Parameters

T

The type of the elements in the array.

Exceptions

ArgumentException

One of the following conditions is true:

  • The level parameter is larger than the number of levels in this texture.
  • The T type size is invalid for the format of this texture.
  • The startIndex parameter is less than zero or is greater than or equal to the length of the data array.
  • The data array parameter is too small.
  • The left, top, back, and/or right parameters are less than zero.
  • The right parameter is greater than the width of the texture.
  • The bottom parameter is greater than the height of the texture.
  • The top parameter is greater than the depth of the texture.
  • The elementCount parameter is the incorrect size.
ArgumentNullException

The data parameter is null.

GetData<T>(T[])

Copies texture data into an array.

public void GetData<T>(T[] data) where T : struct

Parameters

data T[]

The array of data to copy.

Type Parameters

T

The type of the elements in the array.

Exceptions

ArgumentException

One of the following conditions is true:

  • The T type size is invalid for the format of this texture.
  • The data array parameter is too small.
ArgumentNullException

The data parameter is null.

GetData<T>(T[], int, int)

Copies texture data into an array.

public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct

Parameters

data T[]

The array of data to copy.

startIndex int

The index of the element in the array at which to start copying.

elementCount int

The number of elements to copy.

Type Parameters

T

The type of the elements in the array.

Exceptions

ArgumentException

One of the following conditions is true:

  • The T type size is invalid for the format of this texture.
  • The startIndex parameter is less than zero or is greater than or equal to the length of the data array.
  • The data array parameter is too small.
  • The elementCount parameter is the incorrect size.
ArgumentNullException

The data parameter is null.

SetData<T>(int, int, int, int, int, int, int, T[], int, int)

Copies an array of data to the texture.

public void SetData<T>(int level, int left, int top, int right, int bottom, int front, int back, T[] data, int startIndex, int elementCount) where T : struct

Parameters

level int

The mipmap level where the data will be placed.

left int

Position of the left side of the box on the x-axis.

top int

Position of the top of the box on the y-axis.

right int

Position of the right side of the box on the x-axis.

bottom int

Position of the bottom of the box on the y-axis.

front int

Position of the front of the box on the z-axis.

back int

Position of the back of the box on the z-axis.

data T[]

The array of data to copy.

startIndex int

The index of the element in the array at which to start copying.

elementCount int

The number of elements to copy.

Type Parameters

T

The type of the elements in the array.

Exceptions

ArgumentException

One of the following conditions is true:

  • The level parameter is larger than the number of levels in this texture.
  • The T type size is invalid for the format of this texture.
  • The startIndex parameter is less than zero or is greater than or equal to the length of the data array.
  • The data array parameter is too small.
  • The left, top, back, and/or right parameters are less than zero.
  • The right parameter is greater than the width of the texture.
  • The bottom parameter is greater than the height of the texture.
  • The top parameter is greater than the depth of the texture.
  • The elementCount parameter is the incorrect size.
ArgumentNullException

The data parameter is null.

SetData<T>(T[])

Copies an array of data to the texture.

public void SetData<T>(T[] data) where T : struct

Parameters

data T[]

The array of data to copy.

Type Parameters

T

The type of the elements in the array.

Exceptions

ArgumentException

One of the following conditions is true:

  • The T type size is invalid for the format of this texture.
  • The data array parameter is too small.
ArgumentNullException

The data parameter is null.

SetData<T>(T[], int, int)

Copies an array of data to the texture.

public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct

Parameters

data T[]

The array of data to copy.

startIndex int

The index of the element in the array at which to start copying.

elementCount int

The number of elements to copy.

Type Parameters

T

The type of the elements in the array.

Exceptions

ArgumentException

One of the following conditions is true:

  • The T type size is invalid for the format of this texture.
  • The startIndex parameter is less than zero or is greater than or equal to the length of the data array.
  • The data array parameter is too small.
ArgumentNullException

The data parameter is null.