返回介绍

Texture2D.LoadRawTextureData 加载原始纹理数据

发布于 2019-12-18 15:38:39 字数 5106 浏览 1758 评论 0 收藏 0

JavaScript => public function LoadRawTextureData(data: byte[]): void;
JavaScript =>public function LoadRawTextureData(data: IntPtr, size: int): void;
C# => public void LoadRawTextureData(byte[] data);
C# => public void LoadRawTextureData(IntPtr data, int size);

Parameters 参数

dataByte array to initialize texture pixels with.
初始化纹理像素的字节组。
sizeSize of data in bytes.
字节数据的大小。

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.

传入的数据填充整个纹理所需的大小根据它的宽、高、数据格式和mipmap数。Mipmap是在内存布局从最大值开始,较小的MIP级别的数据紧随其后。

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

例如,ARGB32类型16×8的纹理,无Mipmap,填充有512字节数组(16x8x4)。

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

设置图像数据之后,调用Apply才实际上传到GPU。

See Also: SetPixels, SetPixels32, LoadImage, Apply.

JavaScript:

#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;
	}
}

C#:

using UnityEngine;
 
public class ExampleScript : MonoBehaviour {
 
	public void Start () {
		// Create a 16x16 texture with PVRTC RGBA4 format
		// and will it with raw PVRTC bytes.
		var tex = new Texture2D(16, 16, TextureFormat.PVRTC_RGBA4, false);
		// Raw PVRTC4 data for a 16x16 texture. This format is four bits
		// per pixel, so data should be 16*16/2=128 bytes in size.
		// Texture that is encoded here is mostly green with some angular
		// blue and red lines.
		var pvrtcBytes = new byte[] {
			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;
	}
}

Texture2D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文