active
Currently active graphics texture.
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Property
- Namespace: UnityEngine.Rendering
- Assembly: UnityEngine.CoreModule
public static GraphicsTexture active { get; set; }
Remarks
All rendering goes into the active GraphicsTexture. If the active GraphicsTexture is , everything renders in the main window. If the active render target is a RenderTexture, returns the graphicsTexture of RenderTexture.active.
nullGraphicsTexture.activeIn order to set the active render target to a GraphicsTexture, it must have GraphicsTextureDescriptorFlags.RenderTarget enabled in GraphicsTextureDescriptor.flags on texture creation.
Setting 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.
GraphicsTexture.activeAdditional Resources: GraphicsTextureDescriptorFlags.RenderTarget, Graphics.SetRenderTarget, RenderTexture.active.
Examples
using UnityEngine;using UnityEngine.Rendering;using System.Collections;// Get the contents of a GraphicsTexture into a Texture2Dpublic 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; }}