返回介绍

Texture2D.Apply 应用

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

JavaScript => public function Apply(updateMipmaps: bool = true, makeNoLongerReadable: bool = false): void;
C# => public void Apply(bool updateMipmaps = true, bool makeNoLongerReadable = false);

Description 描述

Actually apply all previous SetPixel and SetPixels changes.

实际应用所有之前SetPixel和Setpixels的更改。

If updateMipmaps is true, the mipmap levels are recalculated as well, using the base level as a source. Usually you want to use true in all cases except when you've modified the mip levels yourself using SetPixels. By default updateMipmaps is set to true.

如果updateMipmaps为true,mipmap的级别将进行重新计算,并使用基本级别。通常你会希望在所有情况下为true,除非你使用SetPixels修改了mipmap级别。默认updateMipmaps为true。

If makeNoLongerReadable is true, texture will be marked as no longer readable and memory will be freed after uploading to GPU. By default makeNoLongerReadable is set to false.

This is a potentially expensive operation, so you'll want to change as many pixels as possible between Apply calls.

这是很耗性能的操作,因此你要在调用 Apply前尽可能多的更改像素。

The texture has to have Is Readable flag set in the import settings.

在纹理导入设置,纹理必须勾选可读写标识。

JavaScript:

#pragma strict
// Create a new texture and assign it to the renderer's material
function Start() {
	var texture: Texture2D = new Texture2D(128, 128);
	GetComponent.<Renderer>().material.mainTexture = texture;
	for (var y: int = 0; y < texture.height; y++) {
		for (var x: int = 0; x < texture.width; x++) {
			var color: Color = ((x & y) != 0 ? Color.white : Color.gray);
			texture.SetPixel(x, y, color);
		}
	}
	texture.Apply();
}

C#:

// Create a new texture and assign it to the renderer's material
using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Start() {
        Texture2D texture = new Texture2D(128, 128);
        GetComponent<Renderer>().material.mainTexture = texture;
 
        for (int y = 0; y < texture.height; y++) {
            for (int x = 0; x < texture.width; x++) {
                Color color = ((x & y) != 0 ? Color.white : Color.gray);
                texture.SetPixel(x, y, color);
            }
        }
        texture.Apply();
    }
}

See Also: SetPixel, SetPixels functions.

Texture2D

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

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

发布评论

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