Version: 2023.2
LanguageEnglish
  • C#

GraphicsTexture.active

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static Rendering.GraphicsTexture active;

Description

Currently active graphics texture.

All rendering goes into the active GraphicsTexture. If the active GraphicsTexture is null everything is rendered in the main window. If the active render target is a RenderTexture, GraphicsTexture.active will return the graphicsTexture of RenderTexture.active.

In order to set the active render target to a GraphicsTexture, it must have GraphicsTextureDescFlags.RenderTarget enabled in GraphicsTexture.descriptor.flags on texture creation.

Setting GraphicsTexture.active is the same as calling Graphics.SetRenderTarget with a single GraphicsTexture. Typically you change or query the active render target when implementing custom graphics effects; if all you need is to make a Camera render into a texture, then use Camera.targetTexture with a RenderTexture instead.

See Also: GraphicsTextureDescFlags.RenderTarget, Graphics.SetRenderTarget, RenderTexture.active.

using UnityEngine;
using UnityEngine.Rendering;
using System.Collections;

// Get the contents of a GraphicsTexture into a Texture2D public class ExampleClass : MonoBehaviour { static public Texture2D GetGfxTexPixels(GraphicsTexture gfxTex) { // Remember currently active render target GraphicsTexture currentActiveRT = GraphicsTexture.active;

// Set the supplied GraphicsTexture as the active one GraphicsTexture.active = gfxTex;

// Create a new Texture2D and read the GraphicsTexture image into it Texture2D tex = new Texture2D(gfxTex.descriptor.width, gfxTex.descriptor.height); tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0); tex.Apply();

// Restore previously active render texture GraphicsTexture.active = currentActiveRT; return tex; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961