Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SamplerState.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.ReferenceCounting;
4 using SiliconStudio.Core.Serialization.Contents;
5 
6 namespace SiliconStudio.Paradox.Graphics
7 {
8  [ContentSerializer(typeof(SamplerStateSerializer))]
9  public partial class SamplerState : GraphicsResourceBase
10  {
11  /// <summary>
12  /// Gets the sampler state description.
13  /// </summary>
15 
16  // For FakeSamplerState.
17  protected SamplerState()
18  {
19  }
20 
21  // For FakeSamplerState.
22  protected SamplerState(SamplerStateDescription description)
23  {
24  Description = description;
25  }
26 
27  public static SamplerState New(GraphicsDevice graphicsDevice, SamplerStateDescription samplerStateDescription)
28  {
29  // Store SamplerState in a cache (D3D seems to have quite bad concurrency when using CreateSampler while rendering)
30  SamplerState samplerState;
31  lock (graphicsDevice.CachedSamplerStates)
32  {
33  if (graphicsDevice.CachedSamplerStates.TryGetValue(samplerStateDescription, out samplerState))
34  {
35  // TODO: Appropriate destroy
36  samplerState.AddReferenceInternal();
37  }
38  else
39  {
40  samplerState = new SamplerState(graphicsDevice, samplerStateDescription);
41  graphicsDevice.CachedSamplerStates.Add(samplerStateDescription, samplerState);
42  }
43  }
44  return samplerState;
45  }
46 
47  protected override void Destroy()
48  {
49  lock (GraphicsDevice.CachedSamplerStates)
50  {
51  GraphicsDevice.CachedSamplerStates.Remove(Description);
52  }
53 
54  base.Destroy();
55  }
56  }
57 }
SamplerState(SamplerStateDescription description)
Definition: SamplerState.cs:22
override void Destroy()
Disposes of object resources.
Definition: SamplerState.cs:47
static SamplerState New(GraphicsDevice graphicsDevice, SamplerStateDescription samplerStateDescription)
Definition: SamplerState.cs:27
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.
readonly SamplerStateDescription Description
Gets the sampler state description.
Definition: SamplerState.cs:14