5 using System.Collections.Generic;
7 using SiliconStudio.Core;
8 using SiliconStudio.Paradox.Graphics;
10 namespace SiliconStudio.
Paradox.Effects.Images
18 private readonly Dictionary<TextureDescription, List<TextureLink>> textureCache =
new Dictionary<TextureDescription, List<TextureLink>>();
35 Services = serviceRegistry;
36 Effects = serviceRegistry.GetSafeServiceAs<
EffectSystem>();
64 return GetTemporaryTexture(description).ToRenderTarget();
110 List<TextureLink> textureLinks = null;
111 if (!textureCache.TryGetValue(description, out textureLinks))
113 textureLinks =
new List<TextureLink>();
114 textureCache.Add(description, textureLinks);
118 foreach (var textureLink
in textureLinks)
120 if (textureLink.RefCount == 0)
122 textureLink.RefCount = 1;
123 return textureLink.Texture;
129 if (newTexture.Name == null)
131 newTexture.Name = string.Format(
"PostEffect{0}-{1}", Name == null ? string.Empty : string.Format(
"-{0}", Name), textureLinks.Count);
137 var newTextureLink =
new TextureLink(newTexture) { RefCount = 1 };
138 textureLinks.Add(newTextureLink);
154 List<TextureLink> textureLinks = null;
155 if (textureCache.TryGetValue(texture.
Description, out textureLinks))
157 foreach (var textureLink
in textureLinks)
159 if (textureLink.Texture == texture)
161 textureLink.RefCount++;
180 List<TextureLink> textureLinks = null;
181 if (textureCache.TryGetValue(texture.
Description, out textureLinks))
183 foreach (var textureLink
in textureLinks)
185 if (textureLink.Texture == texture)
187 textureLink.RefCount--;
191 if (textureLink.RefCount < 0)
193 throw new InvalidOperationException(
"Unexpected Texture RefCount < 0");
213 foreach (var textureLinks
in textureCache.Values)
215 foreach (var textureLink
in textureLinks)
217 textureLink.Texture.Dispose();
219 textureLinks.Clear();
221 textureCache.Clear();
226 private class TextureLink
228 public TextureLink(
Texture texture)
RenderTarget GetTemporaryRenderTarget2D(TextureDescription description)
Gets a RenderTarget output for the specified description.
TextureDescription DefaultTextureDescription
Service providing method to access GraphicsDevice life-cycle.
RenderTarget GetTemporaryRenderTarget2D(int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags flags=TextureFlags.RenderTarget|TextureFlags.ShaderResource, int arraySize=1)
Gets a RenderTarget output for the specified description.
void AddReferenceToTemporaryTexture(Texture texture)
Increments the reference to an temporary texture.
RenderTarget GetTemporaryRenderTarget2D(int width, int height, PixelFormat format, TextureFlags flags=TextureFlags.RenderTarget|TextureFlags.ShaderResource, int arraySize=1)
Gets a RenderTarget output for the specified description with a single mipmap.
A simple wrapper to specify number of mipmaps. Set to true to specify all mipmaps or sets an integer ...
A renderable texture view.
static TextureDescription NewDescription(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage)
ImageEffectContext(IServiceRegistry serviceRegistry)
Initializes a new instance of the ImageEffectContext class.
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ DXGI_FORMAT _In_ DWORD flags
GraphicsResourceUsage
Identifies expected resource use during rendering. The usage directly reflects whether a resource is ...
A service registry is a IServiceProvider that provides methods to register and unregister services...
Base class for a framework component.
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.
A Common description for all textures.
HRESULT CreateTexture(_In_ ID3D11Device *pDevice, _In_reads_(nimages) const Image *srcImages, _In_ size_t nimages, _In_ const TexMetadata &metadata, _Outptr_ ID3D11Resource **ppResource)
override void Destroy()
Disposes of object resources.
A Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
void ReleaseTemporaryTexture(Texture texture)
Decrements the reference to a temporary texture.
Context for post effects.
Texture GetTemporaryTexture(TextureDescription description)
Gets a texture for the specified description.
readonly TextureDescription Description
Common description for the original texture.
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
virtual Texture CreateTexture(TextureDescription description)
Creates a texture for output.
PixelFormat
Defines various types of pixel formats.
ImageEffectContext(Game game)
Initializes a new instance of the ImageEffectContext class.
Base class for texture resources.