Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
MultipleRenderTargetsSetter.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 
4 using SiliconStudio.Core;
5 using SiliconStudio.Core.Mathematics;
6 using SiliconStudio.Paradox.Effects.Modules;
7 using SiliconStudio.Paradox.Graphics;
8 
9 namespace SiliconStudio.Paradox.Effects
10 {
12  {
14  : base(services)
15  {
16  RenderTargets = null;
17  ClearColors = null;
18  }
19 
20  /// <summary>
21  /// Gets or sets the key to get the render targets from <see cref="RenderPipeline.Parameters"/>.
22  /// </summary>
23  /// <value>
24  /// The render target key.
25  /// </value>
26  public RenderTarget[] RenderTargets { get; set; }
27 
28  /// <summary>
29  /// Gets or sets the color used to clear the render target.
30  /// </summary>
31  /// <value>
32  /// The colosr used to clear the render targets.
33  /// </value>
34  public Color[] ClearColors { get; set; }
35 
36  protected override void OnRendering(RenderContext context)
37  {
38  var graphicsDevice = context.GraphicsDevice;
39 
40  // clear the targets
41  if ((EnableClearDepth || EnableClearStencil) && DepthStencil != null)
42  {
43  var clearOptions = (DepthStencilClearOptions)0;
44  if (EnableClearDepth)
45  clearOptions |= DepthStencilClearOptions.DepthBuffer;
46  if (EnableClearStencil)
47  clearOptions |= DepthStencilClearOptions.Stencil;
48 
49  graphicsDevice.Clear(DepthStencil, clearOptions, ClearDepth, ClearStencil);
50  }
51  if (EnableClearTarget && RenderTargets != null)
52  {
53  for (var i = 0; i < RenderTargets.Length; ++i)
54  {
55  if (RenderTargets[i] != null)
56  {
57  if (ClearColors != null && i < ClearColors.Length)
58  graphicsDevice.Clear(RenderTargets[i], ClearColors[i]);
59  else
60  graphicsDevice.Clear(RenderTargets[i], ClearColor);
61  }
62  }
63  }
64 
65  // set the view size parameter
66  var pass = context.CurrentPass;
67  var viewParameters = pass.Parameters;
68  viewParameters.Set(CameraKeys.ViewSize, new Vector2(Viewport.Width, Viewport.Height));
69 
70  // set the targets
71  if (EnableSetTargets)
72  {
73  if (RenderTargets != null)
74  {
75  graphicsDevice.SetRenderTargets(DepthStencil, RenderTargets);
76  }
77 
78  var viewPort = Viewport;
79  if (viewPort != Viewport.Empty)
80  graphicsDevice.SetViewport(viewPort);
81  }
82  }
83  }
84 }
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
float Width
Gets or sets the width dimension of the viewport on the render-target surface, in pixels...
Definition: Viewport.cs:30
float Height
Gets or sets the height dimension of the viewport on the render-target surface, in pixels...
Definition: Viewport.cs:33
A service registry is a IServiceProvider that provides methods to register and unregister services...
Thread-local storage context used during rendering.
Defines the window dimensions of a render-target surface onto which a 3D volume projects.
Definition: Viewport.cs:14
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Definition: Color.cs:16
static readonly Viewport Empty
Empty value for an undefined viewport.
Definition: Viewport.cs:19
A processor that setup a RenderTarget and a DepthStencil on a RenderPass.
DepthStencilClearOptions
Specifies the buffer to use when calling Clear.