Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Renderer.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 SiliconStudio.Core;
5 using SiliconStudio.Core.Mathematics;
6 using SiliconStudio.Paradox.Graphics;
7 
8 namespace SiliconStudio.Paradox.Effects
9 {
10  /// <summary>
11  /// Performs render pipeline transformations attached to a specific <see cref="RenderPass"/>.
12  /// </summary>
13  public abstract class Renderer
14  {
15  private readonly IGraphicsDeviceService graphicsDeviceService;
16 
17  /// <summary>
18  /// Initializes a new instance of the <see cref="Renderer"/> class.
19  /// </summary>
20  /// <param name="services">The services.</param>
21  /// <exception cref="System.ArgumentNullException">services</exception>
22  protected Renderer(IServiceRegistry services)
23  {
24  if (services == null) throw new ArgumentNullException("services");
25 
26  Services = services;
27  RenderSystem = services.GetSafeServiceAs<RenderSystem>();
28  EffectSystem = services.GetSafeServiceAs<EffectSystem>();
29  graphicsDeviceService = services.GetSafeServiceAs<IGraphicsDeviceService>();
30  DebugName = GetType().Name;
31  }
32 
33  /// <summary>
34  /// Gets the services.
35  /// </summary>
36  /// <value>The services.</value>
37  public IServiceRegistry Services { get; private set; }
38 
39  /// <summary>
40  /// Gets the graphics device.
41  /// </summary>
42  /// <value>The graphics device.</value>
44  {
45  get
46  {
47  return (graphicsDeviceService != null) ? graphicsDeviceService.GraphicsDevice : null;
48  }
49  }
50 
51  /// <summary>
52  /// Gets the render system.
53  /// </summary>
54  /// <value>The render system.</value>
55  public RenderSystem RenderSystem { get; private set; }
56 
57  /// <summary>
58  /// Gets the effect system.
59  /// </summary>
60  /// <value>The effect system.</value>
61  public EffectSystem EffectSystem { get; private set; }
62 
63  /// <summary>
64  /// Gets the pass this processor is attached to.
65  /// </summary>
66  /// <value>The pass.</value>
67  public RenderPass Pass { get; internal set; }
68 
69  /// <summary>
70  /// Gets or sets the name of the debug.
71  /// </summary>
72  /// <value>The name of the debug.</value>
73  public string DebugName { get; set; }
74 
75  /// <summary>
76  /// Loads this instance. This method is called when a RenderPass is attached (directly or indirectly) to the children of <see cref="SiliconStudio.Paradox.Effects.RenderSystem.Pipeline"/>
77  /// </summary>
78  public virtual void Load()
79  {
80  Pass.StartPass += PassRendering;
81  }
82 
83  /// <summary>
84  /// Unloads this instance. This method is called when a RenderPass is de-attached (directly or indirectly) to the children of <see cref="SiliconStudio.Paradox.Effects.RenderSystem.Pipeline"/>
85  /// </summary>
86  public virtual void Unload()
87  {
88  Pass.StartPass -= PassRendering;
89  }
90 
91  protected virtual void BeginRendering(RenderContext context)
92  {
93  if (DebugName != null)
94  {
95  context.GraphicsDevice.BeginProfile(Color.Green, DebugName);
96  }
97  }
98 
99  protected virtual void EndRendering(RenderContext context)
100  {
101  if (DebugName != null)
102  {
103  context.GraphicsDevice.EndProfile();
104  }
105  }
106 
107  protected virtual void OnRendering(RenderContext context)
108  {
109  }
110 
111  private void PassRendering(RenderContext context)
112  {
113  BeginRendering(context);
114  OnRendering(context);
115  EndRendering(context);
116  }
117  }
118 }
Service providing method to access GraphicsDevice life-cycle.
virtual void OnRendering(RenderContext context)
Definition: Renderer.cs:107
Performs render pipeline transformations attached to a specific RenderPass.
Definition: Renderer.cs:13
virtual void EndRendering(RenderContext context)
Definition: Renderer.cs:99
A service registry is a IServiceProvider that provides methods to register and unregister services...
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.
virtual void BeginRendering(RenderContext context)
Definition: Renderer.cs:91
Thread-local storage context used during rendering.
Renders its RenderSystem.Pipeline, which will usually result in drawing all meshes, UI, etc...
Definition: RenderSystem.cs:18
Renderer(IServiceRegistry services)
Initializes a new instance of the Renderer class.
Definition: Renderer.cs:22
virtual void Unload()
Unloads this instance. This method is called when a RenderPass is de-attached (directly or indirectly...
Definition: Renderer.cs:86
RenderPass is a hierarchy that defines how to collect and render meshes.
Definition: RenderPass.cs:19
virtual void Load()
Loads this instance. This method is called when a RenderPass is attached (directly or indirectly) to ...
Definition: Renderer.cs:78