Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GraphicsResourceBase.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 
6 namespace SiliconStudio.Paradox.Graphics
7 {
8  public partial class GraphicsResourceBase : ComponentBase
9  {
10  internal GraphicsResourceLifetimeState LifetimeState;
11  public Action<GraphicsResourceBase> Reload;
12 
13  /// <summary>
14  /// Gets the graphics device attached to this instance.
15  /// </summary>
16  /// <value>The graphics device.</value>
18  {
19  get;
20  private set;
21  }
22 
23  /// <summary>
24  /// Initializes a new instance of the <see cref="GraphicsResourceBase"/> class.
25  /// </summary>
27  : this(null, null)
28  {
29  }
30 
31  /// <summary>
32  /// Initializes a new instance of the <see cref="GraphicsResourceBase"/> class.
33  /// </summary>
34  /// <param name="device">The device.</param>
35  protected GraphicsResourceBase(GraphicsDevice device) : this(device, null)
36  {
37  }
38 
39  /// <summary>
40  /// Initializes a new instance of the <see cref="GraphicsResourceBase"/> class.
41  /// </summary>
42  /// <param name="device">The device.</param>
43  /// <param name="name">The name.</param>
44  protected GraphicsResourceBase(GraphicsDevice device, string name) : base(name)
45  {
46  GraphicsDevice = device;
47 
48  if (device != null)
49  {
50  // Add GraphicsResourceBase to device resources
51  var resources = device.Resources;
52  lock (resources)
53  {
54  resources.Add(this);
55  }
56  }
57 
58  Initialize();
59  }
60 
61  /// <summary>
62  /// Called when graphics device is inactive (put in the background and rendering is paused).
63  /// It should voluntarily release objects that can be easily recreated, such as FBO and dynamic buffers.
64  /// </summary>
65  /// <returns>True if item transitionned to a <see cref="GraphicsResourceLifetimeState.Paused"/> state.</returns>
66  protected internal virtual bool OnPause()
67  {
68  return false;
69  }
70 
71  /// <summary>
72  /// Called when graphics device is resumed from either paused or destroyed state.
73  /// If possible, resource should be recreated.
74  /// </summary>
75  protected internal virtual void OnResume()
76  {
77  }
78 
79  /// <inheritdoc/>
80  protected override void Destroy()
81  {
82  var device = GraphicsDevice;
83 
84  if (device != null)
85  {
86  // Add GraphicsResourceBase to device resources
87  var resources = device.Resources;
88  lock (resources)
89  {
90  resources.Remove(this);
91  }
92  DestroyImpl();
93  }
94 
95  base.Destroy();
96  }
97  }
98 }
GraphicsResourceBase(GraphicsDevice device, string name)
Initializes a new instance of the GraphicsResourceBase class.
Base class for a framework component.
GraphicsResourceBase(GraphicsDevice device)
Initializes a new instance of the GraphicsResourceBase class.
override void Destroy()
Disposes of object resources.
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.
GraphicsResourceLifetimeState
Describes the lifetime state of a graphics resource.
GraphicsResourceBase()
Initializes a new instance of the GraphicsResourceBase class.