/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != BackingTexture.Width || screenObject.AbsoluteArea.Height != BackingTexture.Height) { BackingTexture?.Dispose(); _cachedTexture?.Dispose(); BackingTexture = new RenderTarget2D(Host.Global.GraphicsDevice, screenObject.AbsoluteArea.Width, screenObject.AbsoluteArea.Height, false, Host.Global.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); _cachedTexture = new Host.GameTexture(BackingTexture); result = true; } if (result || _controlsHost.IsDirty || isForced) { Host.Global.GraphicsDevice.SetRenderTarget(BackingTexture); Host.Global.GraphicsDevice.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Begin(SpriteSortMode.Deferred, ((ScreenSurfaceRenderer)renderer).MonoGameBlendState, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone); ProcessContainer(_controlsHost, ((ScreenSurfaceRenderer)renderer), screenObject); Host.Global.SharedSpriteBatch.End(); Host.Global.GraphicsDevice.SetRenderTarget(null); result = true; _controlsHost.IsDirty = false; } return(result); }
/// <inheritdoc/> public void Reset() { BackingTexture?.Dispose(); BackingTexture = null; _cachedTexture?.Dispose(); _cachedTexture = null; }
/// <summary> /// Disposes the object. /// </summary> /// <param name="disposing"><see langword="true"/> to indicate this method was called from <see cref="Dispose()"/>.</param> protected void Dispose(bool disposing) { BackingTexture?.Dispose(); BackingTexture = null; _cachedTexture?.Dispose(); _cachedTexture = null; }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != (int)BackingTexture.Size.X || screenObject.AbsoluteArea.Height != (int)BackingTexture.Size.Y) { BackingTexture?.Dispose(); _cachedTexture?.Dispose(); BackingTexture = new RenderTexture((uint)screenObject.AbsoluteArea.Width, (uint)screenObject.AbsoluteArea.Height); _cachedTexture = new Host.GameTexture(BackingTexture.Texture); result = true; } // Redraw is needed if (result || _controlsHost.IsDirty || isForced) { BackingTexture.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Reset(BackingTexture, ((ScreenSurfaceRenderer)renderer).SFMLBlendState, Transform.Identity); ProcessContainer(_controlsHost, ((ScreenSurfaceRenderer)renderer), screenObject); Host.Global.SharedSpriteBatch.End(); BackingTexture.Display(); result = true; _controlsHost.IsDirty = false; } return(result); }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != (int)BackingTexture.Size.X || screenObject.AbsoluteArea.Height != (int)BackingTexture.Size.Y) { BackingTexture?.Dispose(); BackingTexture = new RenderTexture((uint)screenObject.AbsoluteArea.Width, (uint)screenObject.AbsoluteArea.Height); _cachedTexture?.Dispose(); _cachedTexture = new Host.GameTexture(BackingTexture.Texture); result = true; } var sfmlRenderer = (ScreenSurfaceRenderer)renderer; // Redraw is needed if (result || screenObject.IsDirty || isForced) { BackingTexture.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Reset(BackingTexture, sfmlRenderer.SFMLBlendState, Transform.Identity); int rectIndex = 0; ColoredGlyph cell; IFont font = screenObject.Font; if (screenObject.Surface.DefaultBackground.A != 0) { Host.Global.SharedSpriteBatch.DrawQuad(new IntRect(0, 0, (int)BackingTexture.Size.X, (int)BackingTexture.Size.Y), font.SolidGlyphRectangle.ToIntRect(), screenObject.Surface.DefaultBackground.ToSFMLColor(), ((SadConsole.Host.GameTexture)font.Image).Texture); } for (int y = 0; y < screenObject.Surface.View.Height; y++) { int i = ((y + screenObject.Surface.ViewPosition.Y) * screenObject.Surface.Width) + screenObject.Surface.ViewPosition.X; for (int x = 0; x < screenObject.Surface.View.Width; x++) { cell = screenObject.Surface[i]; cell.IsDirty = false; if (cell.IsVisible) { Host.Global.SharedSpriteBatch.DrawCell(cell, sfmlRenderer.CachedRenderRects[rectIndex], cell.Background != SadRogue.Primitives.Color.Transparent && cell.Background != screenObject.Surface.DefaultBackground, font); } i++; rectIndex++; } } Host.Global.SharedSpriteBatch.End(); BackingTexture.Display(); result = true; screenObject.IsDirty = false; } return(result); }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != (int)BackingTexture.Size.X || screenObject.AbsoluteArea.Height != (int)BackingTexture.Size.Y) { BackingTexture?.Dispose(); BackingTexture = new RenderTexture((uint)screenObject.AbsoluteArea.Width, (uint)screenObject.AbsoluteArea.Height); _cachedTexture?.Dispose(); _cachedTexture = new Host.GameTexture(BackingTexture.Texture); result = true; } // Redraw is needed if (result || _entityManager.IsDirty || isForced) { BackingTexture.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Reset(BackingTexture, ((ScreenSurfaceRenderer)renderer).SFMLBlendState, Transform.Identity); ColoredGlyph cell; IntRect renderRect; foreach (Entities.Entity item in _entityManager.EntitiesVisible) { if (!item.IsVisible) { continue; } renderRect = _entityManager.GetRenderRectangle(item.Position, item.UsePixelPositioning).ToIntRect(); cell = item.Appearance; cell.IsDirty = false; Host.Global.SharedSpriteBatch.DrawCell(cell, renderRect, true, screenObject.Font); } Host.Global.SharedSpriteBatch.End(); BackingTexture.Display(); result = true; _entityManager.IsDirty = false; } return(result); }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != BackingTexture.Width || screenObject.AbsoluteArea.Height != BackingTexture.Height) { BackingTexture?.Dispose(); BackingTexture = new RenderTarget2D(Host.Global.GraphicsDevice, screenObject.AbsoluteArea.Width, screenObject.AbsoluteArea.Height, false, Host.Global.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); _cachedTexture?.Dispose(); _cachedTexture = new Host.GameTexture(BackingTexture); result = true; } var monoRenderer = (ScreenSurfaceRenderer)renderer; // Redraw is needed if (result || screenObject.IsDirty || isForced) { Host.Global.GraphicsDevice.SetRenderTarget(BackingTexture); Host.Global.GraphicsDevice.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Begin(SpriteSortMode.Deferred, monoRenderer.MonoGameBlendState, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone); IFont font = screenObject.Font; Texture2D fontImage = ((Host.GameTexture)font.Image).Texture; ColoredGlyph cell; if (screenObject.Surface.DefaultBackground.A != 0) { Host.Global.SharedSpriteBatch.Draw(fontImage, new XnaRectangle(0, 0, BackingTexture.Width, BackingTexture.Height), font.SolidGlyphRectangle.ToMonoRectangle(), screenObject.Surface.DefaultBackground.ToMonoColor(), 0f, Vector2.Zero, SpriteEffects.None, 0.2f); } int rectIndex = 0; for (int y = 0; y < screenObject.Surface.View.Height; y++) { int i = ((y + screenObject.Surface.ViewPosition.Y) * screenObject.Surface.Width) + screenObject.Surface.ViewPosition.X; for (int x = 0; x < screenObject.Surface.View.Width; x++) { cell = screenObject.Surface[i]; cell.IsDirty = false; if (cell.IsVisible) { if (cell.Background != SadRogue.Primitives.Color.Transparent && cell.Background != screenObject.Surface.DefaultBackground) { Host.Global.SharedSpriteBatch.Draw(fontImage, monoRenderer.CachedRenderRects[rectIndex], font.SolidGlyphRectangle.ToMonoRectangle(), cell.Background.ToMonoColor(), 0f, Vector2.Zero, SpriteEffects.None, 0.3f); } if (cell.Foreground != SadRogue.Primitives.Color.Transparent && cell.Foreground != cell.Background) { Host.Global.SharedSpriteBatch.Draw(fontImage, monoRenderer.CachedRenderRects[rectIndex], font.GetGlyphSourceRectangle(cell.Glyph).ToMonoRectangle(), cell.Foreground.ToMonoColor(), 0f, Vector2.Zero, cell.Mirror.ToMonoGame(), 0.4f); } foreach (CellDecorator decorator in cell.Decorators) { if (decorator.Color != SadRogue.Primitives.Color.Transparent) { Host.Global.SharedSpriteBatch.Draw(fontImage, monoRenderer.CachedRenderRects[rectIndex], font.GetGlyphSourceRectangle(decorator.Glyph).ToMonoRectangle(), decorator.Color.ToMonoColor(), 0f, Vector2.Zero, decorator.Mirror.ToMonoGame(), 0.5f); } } } i++; rectIndex++; } } Host.Global.SharedSpriteBatch.End(); Host.Global.GraphicsDevice.SetRenderTarget(null); result = true; screenObject.IsDirty = false; } return(result); }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != BackingTexture.Width || screenObject.AbsoluteArea.Height != BackingTexture.Height) { BackingTexture?.Dispose(); BackingTexture = new RenderTarget2D(Host.Global.GraphicsDevice, screenObject.AbsoluteArea.Width, screenObject.AbsoluteArea.Height, false, Host.Global.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); _cachedTexture?.Dispose(); _cachedTexture = new Host.GameTexture(BackingTexture); result = true; } if (result || _entityManager.IsDirty || isForced) { Host.Global.GraphicsDevice.SetRenderTarget(BackingTexture); Host.Global.GraphicsDevice.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Begin(SpriteSortMode.Deferred, ((ScreenSurfaceRenderer)renderer).MonoGameBlendState, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone); Texture2D fontImage = ((Host.GameTexture)screenObject.Font.Image).Texture; IFont font = screenObject.Font; ColoredGlyph cell; XnaRectangle renderRect; foreach (Entities.Entity item in _entityManager.EntitiesVisible) { if (!item.IsVisible) { continue; } renderRect = _entityManager.GetRenderRectangle(item.Position, item.UsePixelPositioning).ToMonoRectangle(); cell = item.Appearance; cell.IsDirty = false; if (cell.Background != SadRogue.Primitives.Color.Transparent) { Host.Global.SharedSpriteBatch.Draw(fontImage, renderRect, font.SolidGlyphRectangle.ToMonoRectangle(), cell.Background.ToMonoColor(), 0f, Vector2.Zero, SpriteEffects.None, 0.3f); } if (cell.Foreground != SadRogue.Primitives.Color.Transparent) { Host.Global.SharedSpriteBatch.Draw(fontImage, renderRect, font.GetGlyphSourceRectangle(cell.Glyph).ToMonoRectangle(), cell.Foreground.ToMonoColor(), 0f, Vector2.Zero, cell.Mirror.ToMonoGame(), 0.4f); } foreach (CellDecorator decorator in cell.Decorators) { if (decorator.Color != SadRogue.Primitives.Color.Transparent) { Host.Global.SharedSpriteBatch.Draw(fontImage, renderRect, font.GetGlyphSourceRectangle(decorator.Glyph).ToMonoRectangle(), decorator.Color.ToMonoColor(), 0f, Vector2.Zero, decorator.Mirror.ToMonoGame(), 0.5f); } } } Host.Global.SharedSpriteBatch.End(); Host.Global.GraphicsDevice.SetRenderTarget(null); result = true; _entityManager.IsDirty = false; } return(result); }