Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
MainPlugin.cs
Go to the documentation of this file.
1 // Copyright (c) 2011 Silicon Studio
2 
3 using System.Linq;
4 using SiliconStudio.Paradox.Effects.Modules;
5 using SiliconStudio.Paradox.Engine;
6 using SiliconStudio.Paradox.Games;
7 using SiliconStudio.Paradox.Graphics;
8 using SiliconStudio.Core;
9 
10 namespace SiliconStudio.Paradox.Effects
11 {
12  /// <summary>
13  /// Plugin used for the main rendering view.
14  /// </summary>
16  {
17  public static readonly PropertyKey<ParameterCollection> ViewParametersSourceKey = new PropertyKey<ParameterCollection>("ViewParametersSource", typeof(MainPlugin), new StaticDefaultValueMetadata(null)
18  {
19  PropertyUpdateCallback = delegate(ref PropertyContainer container, PropertyKey key, object newValue, object oldValue)
20  {
21  // ViewParameters is added to Parameters inheritance
22  if (oldValue != null)
23  ((RenderPassPlugin)container.Owner).Parameters.RemoveSource((ParameterCollection)oldValue);
24  if (newValue != null)
25  ((RenderPassPlugin)container.Owner).Parameters.AddSources((ParameterCollection)newValue);
26  }
27  });
28 
29  /// <summary>
30  /// Initializes a new instance of the <see cref="MainPlugin"/> class.
31  /// </summary>
32  public MainPlugin() : this("Main")
33  {
34  }
35 
36  /// <summary>
37  /// Initializes a new instance of the <see cref="MainPlugin"/> class.
38  /// </summary>
39  /// <param name="name">The name.</param>
40  public MainPlugin(string name)
41  : base(name)
42  {
43  ViewParameters = new RenderViewport("ViewParameters");
44  ViewParameters.RegisterParameter(GlobalKeys.Time);
45  ViewParameters.RegisterParameter(GlobalKeys.TimeStep);
46 
47  Parameters.AddSources(ViewParameters);
48  //Parameters.RegisterParameter(TransformationKeys.ViewProjection);
49  }
50 
51  public override void Initialize()
52  {
53  base.Initialize();
54 
55  bool isDepthStencilAsShaderResourceRequired = RenderSystem.ConfigContext.RenderPassPlugins.Any(plugin => plugin.Value.Tags.Get(RenderTargetKeys.RequireDepthStencilShaderResource));
56 
57  // By default, the MainPlugin is using the back buffer as the render target
58  RenderTarget = GraphicsDevice.BackBuffer;
59 
60  // Create depth stencil
61 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
62  var depthStencilFormat = PixelFormat.D16_UNorm;
63 #else
64  var depthStencilFormat = PixelFormat.D24_UNorm_S8_UInt;
65 #endif
66 
68  {
69  DepthStencil = GraphicsDevice.DepthStencilBuffer;
70  }
71  else
72  {
73  var depthStencil = Texture2D.New(GraphicsDevice, RenderTarget.Width, RenderTarget.Height, depthStencilFormat, TextureFlags.DepthStencil | (isDepthStencilAsShaderResourceRequired ? TextureFlags.ShaderResource : TextureFlags.None));
74  DepthStencil = depthStencil.ToDepthStencilBuffer(false);
75  }
76 
77  if (DepthStencilBuffer.IsReadOnlySupported(GraphicsDevice))
78  DepthStencilReadOnly = DepthStencil.Texture.ToDepthStencilBuffer(true);
79  }
80 
81  public RenderViewport ViewParameters { get; private set; }
82 
83  public RenderTarget RenderTarget { get; set; }
84 
85  public DepthStencilBuffer DepthStencil { get; set; }
86 
87  public DepthStencilBuffer DepthStencilReadOnly { get; set; }
88  }
89 }
MainPlugin(string name)
Initializes a new instance of the MainPlugin class.
Definition: MainPlugin.cs:40
Represents a container that can hold properties, lightweight to embed (lazy initialized).
Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. See The+GraphicsDevice+class to learn more about the class.
MainPlugin()
Initializes a new instance of the MainPlugin class.
Definition: MainPlugin.cs:32
Plugin used for the main rendering view.
Definition: MainPlugin.cs:15
DepthStencilBuffer DepthStencilBuffer
Gets the depth stencil buffer sets by the current Presenter setup on this device. ...
A class that represents a tag propety.
Definition: PropertyKey.cs:17
A container to handle a hierarchical collection of effect variables.