Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DefaultModalElementRenderer.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 SiliconStudio.Core;
4 using SiliconStudio.Core.Mathematics;
5 using SiliconStudio.Paradox.Graphics;
6 using SiliconStudio.Paradox.UI.Controls;
7 
8 namespace SiliconStudio.Paradox.UI.Renderers
9 {
10  /// <summary>
11  /// The default renderer for <see cref="ModalElement"/>.
12  /// </summary>
13  internal class DefaultModalElementRenderer : ElementRenderer
14  {
15  private Matrix identity = Matrix.Identity;
16 
17  private DepthStencilState noStencilNoDepth;
18 
19  public DefaultModalElementRenderer(IServiceRegistry services)
20  : base(services)
21  {
22  }
23 
24  public override void Load()
25  {
26  base.Load();
27 
28  noStencilNoDepth = DepthStencilState.New(GraphicsDevice, new DepthStencilStateDescription(false, false));
29  }
30 
31  public override void Unload()
32  {
33  base.Unload();
34 
35  noStencilNoDepth.Dispose();
36  }
37 
38  public override void RenderColor(UIElement element, UIRenderingContext context)
39  {
40  var modalElement = (ModalElement)element;
41 
42  // end the current UI image batching so that the overlay is written over it with correct transparency
43  Batch.End();
44 
45  var uiResolution = new Vector3(Resolution.X, Resolution.Y, 0);
46  Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.AlphaBlend, noStencilNoDepth, 0);
47  Batch.DrawRectangle(ref identity, ref uiResolution, ref modalElement.OverlayColorInternal, context.DepthBias);
48  Batch.End(); // ensure that overlay is written before possible next transparent element.
49 
50  // restart the image batch session
51  Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue);
52 
53  context.DepthBias += 1;
54 
55  base.RenderColor(element, context);
56  }
57  }
58 }
Contains depth-stencil state for the device.
Represents a modal element that puts an overlay upon the underneath elements and freeze their input...
Definition: ModalElement.cs:16
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.
SiliconStudio.Core.Mathematics.Vector3 Vector3
Represents a 4x4 mathematical matrix.
Definition: Matrix.cs:47