コード例 #1
0
        /// <summary>
        /// Composite layers
        /// </summary>
        /// <param name="callback">Callback to be invoked with the composite texture</param>
        public void Composite(CompositeCallback callback)
        {
            // Null checking
            if (callback == null)
            {
                Debug.LogError("Compositor: Callback must not be null");
                return;
            }
            if (composite == null)
            {
                Debug.LogError("Compositor: No layers to composite. You might have called Dispose() too early");
                return;
            }
            // If immediate, composite
            foreach (var layer in layers)
            {
                Composite(layer);
            }
            // Create a result texture
            var result = new Texture2D(width, height);

            // Load the composite data into the texture
            result.SetPixels32(composite);
            result.Apply();
            // Invoke callback
            callback(result);
        }
コード例 #2
0
 /// <summary>
 /// Create a new composition layer
 /// </summary>
 /// <param name="texture">Layer texture</param>
 /// <param name="offset">Offset of the layer's bottom left corner before any rotation is applied</param>
 /// <param name="rotation">Layer's rotation in degrees</param>
 /// <param name="scale">Layer's scale. To use natural scale, use (1, 1)<param>
 /// <param name="callback">Callback to be invoked once the layer has been composited. Use this for resource or memory management</summary>
 public Layer(Texture2D texture, Point offset, float rotation, Vector2 scale, CompositeCallback callback = null)
 {
     this.texture  = texture;
     this.offset   = offset;
     this.rotation = rotation;
     this.scale    = scale;
     this.callback = callback;
 }
コード例 #3
0
 /// <summary>
 /// Composite layers
 /// </summary>
 /// <param name="callback">Callback to be invoked with the composite texture</param>
 public void Composite(CompositeCallback callback)
 {
     // Null checking
     if (callback == null)
     {
         Debug.LogError("Compositor: Callback must not be null");
         return;
     }
     // ...
 }
コード例 #4
0
 private void Readback(CompositeCallback callback)
 {
     commandQueue.Enqueue(() => {
         // Create a result texture
         var result            = new Texture2D(composite.width, composite.height);
         RenderTexture current = RenderTexture.active;
         RenderTexture.active  = composite;
         // Read back
         result.ReadPixels(new Rect(0, 0, composite.width, composite.height), 0, 0);
         result.Apply();
         RenderTexture.active = current;
         // Invoke callback
         callback(result);
     });
 }
コード例 #5
0
 /// <summary>
 /// Composite layers
 /// </summary>
 /// <param name="callback">Callback to be invoked with the composite texture</param>
 public void Composite(CompositeCallback callback)
 {
     // Null checking
     if (callback == null)
     {
         Debug.LogError("Compositor: Callback must not be null");
         return;
     }
     // Count checking
     if (layers.Count == 0)
     {
         Debug.LogError("Compositor: No layers provided");
         return;
     }
     // Composite all layers
     foreach (var layer in layers)
     {
         Composite(layer);
     }
     // Readback
     Readback(callback);
 }