Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GraphicsResource.Direct3D.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 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
4 using System;
5 using System.Diagnostics;
6 using System.Runtime.InteropServices;
7 using SharpDX;
8 using SharpDX.Direct3D;
9 using SharpDX.Direct3D11;
10 using SharpDX.DXGI;
11 
12 using SiliconStudio.Core;
13 
14 namespace SiliconStudio.Paradox.Graphics
15 {
16  /// <summary>
17  /// GraphicsResource class
18  /// </summary>
19  public abstract partial class GraphicsResource
20  {
21  protected ShaderResourceView nativeShaderResourceView;
22  private UnorderedAccessView unorderedAccessView;
23 
24  protected override void OnNameChanged()
25  {
26  base.OnNameChanged();
27  if (GraphicsDevice != null && GraphicsDevice.IsDebugMode)
28  {
29  if (this.nativeShaderResourceView != null)
30  {
31  nativeShaderResourceView.DebugName = Name == null ? null : String.Format("{0} SRV", Name);
32  }
33 
34  if (this.unorderedAccessView != null)
35  {
36  unorderedAccessView.DebugName = Name == null ? null : String.Format("{0} UAV", Name);
37  }
38  }
39  }
40 
41  /// <summary>
42  /// Gets or sets the ShaderResourceView attached to this GraphicsResource.
43  /// Note that only Texture2D, Texture3D, RenderTarget2D, RenderTarget3D, DepthStencil are using this ShaderResourceView
44  /// </summary>
45  /// <value>The device child.</value>
46  protected internal SharpDX.Direct3D11.ShaderResourceView NativeShaderResourceView
47  {
48  get
49  {
50  return nativeShaderResourceView;
51  }
52  set
53  {
54  Debug.Assert(nativeShaderResourceView == null);
55  nativeShaderResourceView = value;
56 
57  if (nativeShaderResourceView != null)
58  {
59  // Associate PrivateData to this DeviceResource
60  SetDebugName(GraphicsDevice, nativeShaderResourceView, "SRV " + Name);
61  }
62  }
63  }
64 
65  /// <summary>
66  /// Gets or sets the UnorderedAccessView attached to this GraphicsResource.
67  /// </summary>
68  /// <value>The device child.</value>
69  protected internal UnorderedAccessView NativeUnorderedAccessView
70  {
71  get
72  {
73  return unorderedAccessView;
74  }
75  set
76  {
77  Debug.Assert(unorderedAccessView == null);
78  unorderedAccessView = value;
79 
80  if (unorderedAccessView != null)
81  {
82  // Associate PrivateData to this DeviceResource
83  SetDebugName(GraphicsDevice, unorderedAccessView, "UAV " + Name);
84  }
85  }
86  }
87 
88  protected override void DestroyImpl()
89  {
90  if (nativeShaderResourceView != null)
91  {
92  ((IUnknown)nativeShaderResourceView).Release();
93  nativeShaderResourceView = null;
94  }
95 
96  if (unorderedAccessView != null)
97  {
98  ((IUnknown)unorderedAccessView).Release();
99  unorderedAccessView = null;
100  }
101 
102  base.DestroyImpl();
103  }
104  }
105 }
106 
107 #endif