Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Texture2D.LoadRawTextureData

Switch to Manual
public function LoadRawTextureData(data: byte[]): void;

Parameters

data Byte array to initialize texture pixels with.

Description

Fills texture pixels with raw preformatted data.

This function fills texture pixel memory with raw data. This is mostly useful for loading compressed texture format data into a texture.

Passed data should be of required size to fill the whole texture according to its width, height, data format and mipmapCount. Mipmaps are laid out in memory starting from largest, with smaller mip level data immediately following.

For example, a 16x8 texture of ARGB32 type with no mipmaps can be filled with a 512-byte array (16x8x4).

Call Apply after setting image data to actually upload it to the GPU.

See Also: SetPixels, SetPixels32, LoadImage, Apply.

#pragma strict
public class ExampleScript extends MonoBehaviour {
	public function Start() {
		// and will it with raw PVRTC bytes.
		var tex: var = new Texture2D(16, 16, TextureFormat.PVRTC_RGBA4, false);
		// blue and red lines.
		var pvrtcBytes: var = [0x30, 0x32, 0x32, 0x32, 0xe7, 0x30, 0xaa, 0x7f, 0x32, 0x32, 0x32, 0x32, 0xf9, 0x40, 0xbc, 0x7f, 0x03, 0x03, 0x03, 0x03, 0xf6, 0x30, 0x02, 0x05, 0x03, 0x03, 0x03, 0x03, 0xf4, 0x30, 0x03, 0x06, 0x32, 0x32, 0x32, 0x32, 0xf7, 0x40, 0xaa, 0x7f, 0x32, 0xf2, 0x02, 0xa8, 0xe7, 0x30, 0xff, 0xff, 0x03, 0x03, 0x03, 0xff, 0xe6, 0x40, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xaa, 0xe9, 0x40, 0x9f, 0xff, 0x5b, 0x03, 0x03, 0x03, 0xca, 0x6a, 0x0f, 0x30, 0x03, 0x03, 0x03, 0xff, 0xca, 0x68, 0x0f, 0x30, 0xaa, 0x94, 0x90, 0x40, 0xba, 0x5b, 0xaf, 0x68, 0x40, 0x00, 0x00, 0xff, 0xca, 0x58, 0x0f, 0x20, 0x00, 0x00, 0x00, 0xff, 0xe6, 0x40, 0x01, 0x2c, 0x00, 0xff, 0x00, 0xaa, 0xdb, 0x41, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xe8, 0x40, 0x01, 0x1c, 0x00, 0xff, 0x00, 0xaa, 0xbb, 0x40, 0xff, 0xff];
		// Load data into the texture and upload it to the GPU.
		tex.LoadRawTextureData(pvrtcBytes);
		tex.Apply();
		// Assign texture to renderer's material.
		GetComponent.<Renderer>().material.mainTexture = tex;
	}
}