4 using System.Collections.Generic;
5 using SiliconStudio.Paradox.Shaders;
7 namespace SiliconStudio.
Paradox.Graphics
9 internal partial class EffectProgram : GraphicsResourceBase
11 public static EffectProgram
New(GraphicsDevice graphicsDevice,
EffectBytecode bytecode)
13 var effectProgramLibrary = graphicsDevice.GetOrCreateSharedData(GraphicsDeviceSharedDataType.PerDevice, typeof(EffectProgram), () =>
new EffectProgramLibrary());
14 return effectProgramLibrary.GetOrCreateShader(graphicsDevice, bytecode);
17 private class EffectProgramLibrary : IDisposable
19 private readonly Dictionary<EffectBytecode, EffectProgram> ShaderLibrary =
new Dictionary<EffectBytecode, EffectProgram>();
21 public EffectProgram GetOrCreateShader(GraphicsDevice graphicsDevice,
EffectBytecode bytecode)
25 EffectProgram effectProgram;
26 if (!ShaderLibrary.TryGetValue(bytecode, out effectProgram))
28 effectProgram =
new EffectProgram(graphicsDevice, bytecode);
29 ShaderLibrary.Add(bytecode, effectProgram);
39 foreach (var effectProgram
in ShaderLibrary)
41 effectProgram.Value.Dispose();
43 ShaderLibrary.Clear();
Contains a compiled shader with bytecode for each stage.