Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TextureExtensions.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 System.IO;
4 
5 using SiliconStudio.Paradox.Graphics;
6 
7 namespace SiliconStudio.Paradox.UI
8 {
9  /// <summary>
10  /// Extension methods for <see cref="Texture"/>
11  /// </summary>
12  internal static class TextureExtensions
13  {
14  /// <summary>
15  /// Creates a 2D texture from an image file data (png, dds, ...).
16  /// </summary>
17  /// <param name="graphicsDevice">The graphics device in which to create the texture</param>
18  /// <param name="data">The image file data</param>
19  /// <returns>A 2D texture</returns>
20  public static Texture2D CreateTextureFromFileData(GraphicsDevice graphicsDevice, byte[] data)
21  {
22  Texture2D result;
23 
24  {
25  using (var imageStream = new MemoryStream(data))
26  {
27  using (var image = Image.Load(imageStream))
28  result = Texture2D.New(graphicsDevice, image);
29  }
30  }
31 
32  result.Reload = graphicsResource =>
33  {
34  using (var imageStream = new MemoryStream(data))
35  {
36  using (var image = Image.Load(imageStream))
37  ((Texture2D)graphicsResource).Recreate(image.ToDataBox());
38  }
39  };
40 
41  return result;
42  }
43  }
44 }
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 Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
Definition: Texture2D.cs:37