Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
BufferDataConverter.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;
4 using SiliconStudio.Core.Serialization.Assets;
5 using SiliconStudio.Core.Serialization.Converters;
6 
7 namespace SiliconStudio.Paradox.Graphics.Data
8 {
9  public class BufferDataConverter : DataConverter<BufferData, Buffer>
10  {
11  public override void ConvertFromData(ConverterContext converterContext, BufferData data, ref Buffer buffer)
12  {
13  var services = converterContext.Tags.Get(ServiceRegistry.ServiceRegistryKey);
14  var graphicsDeviceService = services.GetSafeServiceAs<IGraphicsDeviceService>();
15 
16  buffer = Buffer.New(graphicsDeviceService.GraphicsDevice, data.Content, data.StructureByteStride, data.BufferFlags, PixelFormat.None, data.Usage);
17 
18  var assetManager = (AssetManager)services.GetServiceAs<IAssetManager>();
19 
20  // Setup reload callback (reload from asset manager)
21  string url;
22  if (assetManager.TryGetAssetUrl(data, out url))
23  {
24  buffer.Reload = (graphicsResource) =>
25  {
26  // TODO: Avoid loading/unloading the same data
27  var loadedBufferData = assetManager.Load<BufferData>(url);
28  ((Buffer)graphicsResource).Recreate(loadedBufferData.Content);
29  assetManager.Unload(loadedBufferData);
30  };
31  }
32  }
33 
34  public override void ConvertToData(ConverterContext converterContext, ref BufferData data, Buffer obj)
35  {
36  data = new BufferData { Content = obj.GetData<byte>(), BufferFlags = obj.Description.BufferFlags, StructureByteStride = obj.Description.StructureByteStride, Usage = obj.Description.Usage };
37  }
38  }
39 }
Service providing method to access GraphicsDevice life-cycle.
override void ConvertFromData(ConverterContext converterContext, BufferData data, ref Buffer buffer)
Base class for converters to/from a data type.
BufferFlags BufferFlags
Buffer flags describing the type of buffer.
int StructureByteStride
The size of the structure (in bytes) when it represents a structured/typed buffer.
All-in-One Buffer class linked SharpDX.Direct3D11.Buffer.
SiliconStudio.Paradox.Graphics.Buffer Buffer
Definition: BasicEffect.cs:15
GraphicsResourceUsage Usage
Usage of this buffer.
override void ConvertToData(ConverterContext converterContext, ref BufferData data, Buffer obj)
readonly BufferDescription Description
Gets the description of this buffer.
Definition: Buffer.cs:44
Only valid for a property / field that has a class or struct type. When restored, instead of recreati...
Content of a GPU buffer (vertex buffer, index buffer, etc...).
Definition: BufferData.cs:10