Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
RenderPass.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Collections.ObjectModel;
6 using System.Collections.Specialized;
7 using SiliconStudio.Core;
8 using SiliconStudio.Core.Collections;
9 using SiliconStudio.Core.Extensions;
10 using SiliconStudio.Paradox.Engine;
11 
12 namespace SiliconStudio.Paradox.Effects
13 {
14  public delegate void UpdateMeshesDelegate(RenderPass currentRenderPass, ref FastList<RenderMesh> meshes);
15 
16  /// <summary>
17  /// RenderPass is a hierarchy that defines how to collect and render meshes.
18  /// </summary>
19  public class RenderPass : ComponentBase
20  {
21  private readonly TrackingCollection<Renderer> renderers;
22  private readonly TrackingCollection<RenderPass> children;
23 
24  /// <summary>
25  /// Initializes a new instance of the <see cref="RenderPass"/> class.
26  /// </summary>
27  public RenderPass() : this(null)
28  {
29  }
30 
31  /// <summary>
32  /// Initializes a new instance of the <see cref="RenderPass"/> class.
33  /// </summary>
34  /// <param name="name">The name.</param>
35  public RenderPass(string name) : base(name)
36  {
37  Parameters = new ParameterCollection();
38  Enabled = true;
39  // create Renderers lists
40  renderers = new TrackingCollection<Renderer>();
41  renderers.CollectionChanged += (o, e) =>
42  {
43  var processor = (Renderer)e.Item;
44  switch (e.Action)
45  {
46  case NotifyCollectionChangedAction.Add:
47  // Check consistency of Parent before setting it
48  if (processor.Pass != null)
49  throw new InvalidOperationException("Renderer.Pass is already attached to another pass.");
50  processor.Pass = this;
51  break;
52  case NotifyCollectionChangedAction.Remove:
53  // Check consistency of Parent before setting it
54  if (processor.Pass != this)
55  throw new InvalidOperationException("Renderer.Pass is not attached to a this pass..");
56  //processor.Pass = null;
57  break;
58  }
59  };
60 
61  // Create children passes
62  children = new TrackingCollection<RenderPass>();
63  children.CollectionChanged += (o, e) =>
64  {
65  var renderPass = (RenderPass)e.Item;
66  switch (e.Action)
67  {
68  case NotifyCollectionChangedAction.Add:
69  // Check consistency of Parent before setting it
70  if (renderPass.Parent != null)
71  throw new InvalidOperationException("Pass.Parent should be null.");
72  renderPass.Parent = this;
73  break;
74  case NotifyCollectionChangedAction.Remove:
75  // Check consistency of Parent before setting it
76  if (renderPass.Parent != this)
77  throw new InvalidOperationException("Pass.Parent is not set properly.");
78  renderPass.Parent = null;
79  break;
80  }
81  };
82  }
83 
84  /// <summary>
85  /// Gets or sets a value indicating whether this <see cref="RenderPass"/> is enabled for collection.
86  /// </summary>
87  /// <value>
88  /// <c>true</c> if enabled for collection; otherwise, <c>false</c>.
89  /// </value>
90  public bool Enabled { get; set; }
91 
92  /// <summary>
93  /// Gets the parent pass.
94  /// </summary>
95  /// <value>
96  /// The parent pass.
97  /// </value>
98  public RenderPass Parent { get; internal set; }
99 
100  /// <summary>
101  /// Gets the pipeline (root node, which should be of type <see cref="RenderPipeline"/>).
102  /// </summary>
103  /// <value>
104  /// The root pass.
105  /// </value>
106  public RenderPipeline Pipeline
107  {
108  get
109  {
110  var current = this;
111 
112  while (current.Parent != null)
113  {
114  current = current.Parent;
115  }
116 
117  // Not sure yet if we should throw an exception or return null?
118  return current as RenderPipeline;
119  }
120  }
121 
122  /// <summary>
123  /// The start action.
124  /// </summary>
125  public DelegateHolder<RenderContext> StartPass;
126 
127  /// <summary>
128  /// The end action.
129  /// </summary>
130  public DelegateHolder<RenderContext> EndPass;
131 
132  /// <summary>
133  /// Gets or sets the parameters.
134  /// </summary>
135  /// <value>
136  /// The parameters.
137  /// </value>
138  public ParameterCollection Parameters { get; private set; }
139 
140  /// <summary>
141  /// Gets the Renderers attached to this renderpass.
142  /// </summary>
143  /// <value>The Renderers.</value>
144  public TrackingCollection<Renderer> Renderers
145  {
146  get
147  {
148  return renderers;
149  }
150  }
151 
152  /// <summary>
153  /// Gets the sub render passes.
154  /// </summary>
155  /// <value>
156  /// The sub render passes.
157  /// </value>
158  public TrackingCollection<RenderPass> Children
159  {
160  get { return children; }
161  }
162 
163  public override string ToString()
164  {
165  return string.Format("{0}({1})", GetType().Name, Name ?? "");
166  }
167  }
168 }
DelegateHolder< RenderContext > EndPass
The end action.
Definition: RenderPass.cs:130
RenderPass(string name)
Initializes a new instance of the RenderPass class.
Definition: RenderPass.cs:35
Performs render pipeline transformations attached to a specific RenderPass.
Definition: Renderer.cs:13
Base class for a framework component.
RenderPass()
Initializes a new instance of the RenderPass class.
Definition: RenderPass.cs:27
switch(inFormat)
DelegateHolder< RenderContext > StartPass
The start action.
Definition: RenderPass.cs:125
delegate void UpdateMeshesDelegate(RenderPass currentRenderPass, ref FastList< RenderMesh > meshes)
RenderPass is a hierarchy that defines how to collect and render meshes.
Definition: RenderPass.cs:19
Defines an entry point for mesh instantiation and recursive rendering.
A container to handle a hierarchical collection of effect variables.