Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CubemapSourceProcessor.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 
4 using System.Collections.Generic;
5 
6 using SiliconStudio.Core;
7 using SiliconStudio.Paradox.Engine;
8 using SiliconStudio.Paradox.EntityModel;
9 using SiliconStudio.Paradox.Graphics;
10 
11 namespace SiliconStudio.Paradox.Effects.Modules.Processors
12 {
13  /// <summary>
14  /// Keeps tracks of the active cubemaps.
15  /// </summary>
16  public sealed class CubemapSourceProcessor : EntityProcessor<CubemapSourceComponent>
17  {
18  #region Private members
19 
20  private readonly GraphicsDevice graphicsDevice;
21 
22  #endregion
23 
24  #region Public properties
25 
26  /// <summary>
27  /// The active cubemaps.
28  /// </summary>
29  public Dictionary<Entity, CubemapSourceComponent> Cubemaps
30  {
31  get
32  {
33  return this.enabledEntities;
34  }
35  }
36 
37  #endregion
38 
39  #region Constructor
40 
42  : base(new PropertyKey[] { CubemapSourceComponent.Key })
43  {
44  graphicsDevice = device;
45  }
46 
47  #endregion
48 
49  #region Protected methods
50 
51  /// <inheritdoc/>
52  protected override void OnEntityAdding(Entity entity, CubemapSourceComponent data)
53  {
54  base.OnEntityAdding(entity, data);
55  if (data.IsDynamic)
56  {
57  // TODO: move texture creation when it is actually needed (first time use)?
58  data.Texture = TextureCube.New(graphicsDevice, data.Size, 1, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
59  }
60  }
61 
62  /// <inheritdoc/>
63  protected override void OnEntityRemoved(Entity entity, CubemapSourceComponent data)
64  {
65  base.OnEntityRemoved(entity, data);
66  // TODO: remove texture?
67  }
68 
69  /// <inheritdoc/>
71  {
72  return entity.Get<CubemapSourceComponent>();
73  }
74 
75  #endregion
76  }
77 }
Game entity. It usually aggregates multiple EntityComponent
Definition: Entity.cs:28
Puts a cubemap at the containing entity location. This could be dynamic (runtime rendered) or static ...
Entity processor, triggered on various EntitySystem events such as Entity and Component additions and...
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.
override void OnEntityRemoved(Entity entity, CubemapSourceComponent data)
bool IsDynamic
Enables runtime cubemap creation.
override void OnEntityAdding(Entity entity, CubemapSourceComponent data)
A class that represents a tag propety.
Definition: PropertyKey.cs:17