Texture2D
Create a new empty texture.
Read time 5 minutesLast updated 6 days ago
Definition
- Type: Constructor
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
Texture2D(int, int, TextureFormat, int, bool)
Create a new empty texture.
public Texture2D(int width, int height, TextureFormat textureFormat, int mipCount, bool linear)
Parameters
Remarks
The texture will be width by height size, with a given format, with mipmaps or without, and in either the linear color space or the sRGB color space. width and height must be greater than 0.
Usually you will want to set the colors of the texture after creating it, using Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply functions.
Texture2D(int, int, TextureFormat, int, bool, bool)
Create a new empty texture.
public Texture2D(int width, int height, TextureFormat textureFormat, int mipCount, bool linear, bool createUninitialized)
Parameters
Remarks
The texture will be width by height size, with a given format, with mipmaps or without, and in either the linear color space or the sRGB color space. width and height must be greater than 0.
Enable createUninitialized to make the texture reference uninitialized data (both on the CPU and GPU). When overriding all texels, this can lead to improved performance and reduced memory usage during construction. Note that sampling an uninitialized texture gives unpredictable values.
Usually you will want to set the colors of the texture after creating it, using Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply functions.
Texture2D(int, int, TextureFormat, int, bool, bool, MipmapLimitDescriptor)
Create a new empty texture.
public Texture2D(int width, int height, TextureFormat textureFormat, int mipCount, bool linear, bool createUninitialized, MipmapLimitDescriptor mipmapLimitDescriptor)
Parameters
Remarks
The texture will be width by height size, with a given format, with mipmaps or without, and in either the linear color space or the sRGB color space. width and height must be greater than 0.
Enable createUninitialized to make the texture reference uninitialized data (both on the CPU and GPU). When overriding all texels, this can lead to improved performance and reduced memory usage during construction. Note that sampling an uninitialized texture gives unpredictable values.
Use a MipmapLimitDescriptor to make the texture use the global mipmap limit from the current Quality Settings, or the mipmap limit of a TextureMipmapLimitGroup. Note that a readable CPU copy is required for the texture to reupload when quality settings change. If the texture is made nonreadable (see Texture2D.Apply), the uploaded resolution will no longer adapt to the active quality level.
Usually you will want to set the colors of the texture after creating it, using Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply functions.
Texture2D(int, int, TextureFormat, int, bool, bool, bool, string)
Create a new empty texture.
public Texture2D(int width, int height, TextureFormat textureFormat, int mipCount, bool linear, bool createUninitialized, bool ignoreMipmapLimit, string mipmapLimitGroupName)
Parameters
Remarks
The texture will be width by height size, with an RGBA32 TextureFormat, with mipmaps and in sRGB color space.
Usually you will want to set the colors of the texture after creating it, using Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply functions.
// Create a new texture and assign it to the renderer's materialusing UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Start() { Texture2D texture = new Texture2D(128, 128); Renderer renderer = GetComponent<Renderer>(); renderer.material.mainTexture = texture; }}
Texture2D(int, int, TextureFormat, bool, bool)
Create a new empty texture.
public Texture2D(int width, int height, TextureFormat textureFormat, bool mipChain, bool linear)
Parameters
Remarks
The texture will be width by height size, with a given format, with mipmaps or without, and in either the linear color space or the sRGB color space. width and height must be greater than 0.
Usually you will want to set the colors of the texture after creating it, using Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply functions.
Texture2D(int, int, TextureFormat, bool, bool, bool)
Create a new empty texture.
public Texture2D(int width, int height, TextureFormat textureFormat, bool mipChain, bool linear, bool createUninitialized)
Parameters
Remarks
The texture will be width by height size, with a given format, with mipmaps or without, and in either the linear color space or the sRGB color space. width and height must be greater than 0.
Enable createUninitialized to make the texture reference uninitialized data (both on the CPU and GPU). When overriding all texels, this can lead to improved performance and reduced memory usage during construction. Note that sampling an uninitialized texture gives unpredictable values.
Usually you will want to set the colors of the texture after creating it, using Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply functions.
Texture2D(int, int, TextureFormat, bool)
Create a new empty texture.
public Texture2D(int width, int height, TextureFormat textureFormat, bool mipChain)
Parameters
Remarks
The texture will be width by height size, with a given format, with mipmaps or without. width and height must be greater than 0.
Usually you will want to set the colors of the texture after creating it, using Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply functions.
Texture2D(int, int)
Create a new empty texture.
public Texture2D(int width, int height)
Parameters
Remarks
The texture will be width by height size, with an RGBA32 TextureFormat, with mipmaps and in sRGB color space.
Usually you will want to set the colors of the texture after creating it, using Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply functions.
// Create a new texture and assign it to the renderer's materialusing UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Start() { Texture2D texture = new Texture2D(128, 128); Renderer renderer = GetComponent<Renderer>(); renderer.material.mainTexture = texture; }}