5 using System.Collections.Generic;
7 using SiliconStudio.Core;
8 using SiliconStudio.Core.Mathematics;
9 using SiliconStudio.Paradox.Effects.Modules;
10 using SiliconStudio.Paradox.Engine;
11 using SiliconStudio.Paradox.EntityModel;
12 using SiliconStudio.Paradox.Games;
13 using SiliconStudio.Paradox.Graphics;
15 namespace SiliconStudio.
Paradox.Effects
28 internal readonly List<Entity> EntitiesToRender =
new List<Entity>();
30 private static readonly Dictionary<string, List<Entity>> effectNamesToEntityDatas =
new Dictionary<string, List<Entity>>();
39 private void GameVirtualResolutionChanged(
object sender,
EventArgs eventArgs)
41 spriteBatch.VirtualResolution = gameVirtualResolution.VirtualResolution;
44 public override void Load()
50 gameVirtualResolution.VirtualResolutionChanged += GameVirtualResolutionChanged;
51 GameVirtualResolutionChanged(null,
EventArgs.Empty);
53 renderSystem.SpriteRenderProcessors.Add(
this);
60 renderSystem.SpriteRenderProcessors.Remove(
this);
62 gameVirtualResolution.VirtualResolutionChanged -= GameVirtualResolutionChanged;
64 spriteBatch.Dispose();
70 SelectAndSortEntitiesByEffects(SpriteIsOpaque);
74 SelectAndSortEntitiesByEffects(SpriteIsTransparent);
80 return spriteComponent.CurrentSprite.IsTransparent;
85 return !SpriteIsTransparent(spriteComponent);
88 private void SelectAndSortEntitiesByEffects(Func<SpriteComponent, bool> shouldSelect)
91 foreach (var entities
in effectNamesToEntityDatas.Values)
95 foreach (var entity
in EntitiesToRender)
97 var spriteComp = entity.Get(SpriteComponent.Key);
99 if (spriteComp.SpriteGroup == null || spriteComp.SpriteGroup.Images == null || !shouldSelect(spriteComp))
102 var effectName = spriteComp.Effect != null ? spriteComp.Effect.Name :
"SpriteBatch.DefaultEffect";
104 if (!effectNamesToEntityDatas.ContainsKey(effectName))
105 effectNamesToEntityDatas.Add(effectName,
new List<Entity>());
107 effectNamesToEntityDatas[effectName].Add(entity);
113 var viewParameters = context.CurrentPass.Parameters;
115 var viewMatrix = viewParameters.Get(TransformationKeys.View);
116 var projectionMatrix = viewParameters.Get(TransformationKeys.Projection);
118 foreach (var entities
in effectNamesToEntityDatas.Values)
120 if (entities.Count == 0)
123 spriteBatch.Begin(viewMatrix, projectionMatrix, sortMode, blendState, effect: entities[0].Get(SpriteComponent.Key).
Effect);
125 foreach (var entity
in entities)
127 var spriteComp = entity.Get(SpriteComponent.Key);
128 var transfoComp = entity.Get(TransformationComponent.Key);
130 var sprite = spriteComp.CurrentSprite;
136 new Vector2(transfoComp.Translation.X, transfoComp.Translation.Y),
138 new Vector2(transfoComp.Scaling.X, transfoComp.Scaling.Y),
139 transfoComp.RotationEulerXYZ.Z,
140 transfoComp.Translation.Z,
141 spriteComp.SpriteEffect);
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
Interface providing services to deal with the virtual resolution of the game. The virtual resolution ...
SpriteRenderer(IServiceRegistry services)
Performs render pipeline transformations attached to a specific RenderPass.
This Renderer is responsible to prepare and render sprites for a specific pass.
A service registry is a IServiceProvider that provides methods to register and unregister services...
Add a Sprite to an Entity. It could be an animated sprite.
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 OnRendering(RenderContext context)
readonly BlendState Opaque
A built-in state object with settings for opaque blend, that is overwriting the source with the desti...
SpriteSortMode
Defines sprite sort-rendering options.
Thread-local storage context used during rendering.
SiliconStudio.Core.Mathematics.Color Color
Renders its RenderSystem.Pipeline, which will usually result in drawing all meshes, UI, etc...
readonly BlendState AlphaBlend
A built-in state object with settings for alpha blend, that is blending the source and destination da...
override void Unload()
Unloads this instance. This method is called when a RenderPass is de-attached (directly or indirectly...
Renders a group of sprites.
BlendStateFactory BlendStates
Gets the BlendStates factory.
override void Load()
Loads this instance. This method is called when a RenderPass is attached (directly or indirectly) to ...