public RenderPipeline(Game game) { _renderList = new RenderList(); var graphicsDevice = game.GraphicsDevice; _loadContext = game.GraphicsLoadContext; _globalShaderResources = game.GraphicsLoadContext.ShaderResources.Global; _globalShaderResourceData = AddDisposable(new GlobalShaderResourceData(game.GraphicsDevice, _globalShaderResources, game.GraphicsLoadContext.StandardGraphicsResources)); _commandList = AddDisposable(graphicsDevice.ResourceFactory.CreateCommandList()); _drawingContext = AddDisposable(new DrawingContext2D( game.ContentManager, game.GraphicsLoadContext, BlendStateDescription.SingleAlphaBlend, GameOutputDescription)); _shadowMapRenderer = AddDisposable(new ShadowMapRenderer(game.GraphicsDevice)); _waterMapRenderer = AddDisposable(new WaterMapRenderer(game.AssetStore, _loadContext, game.GraphicsDevice, game.GraphicsLoadContext.ShaderResources.Global)); _textureCopier = AddDisposable(new TextureCopier( game, game.Panel.OutputDescription)); }
public WaterMapRenderer( AssetStore assetStore, GraphicsLoadContext graphicsLoadContext, GraphicsDevice graphicsDevice, GlobalShaderResources globalShaderResources) { _waterShaderResources = graphicsLoadContext.ShaderResources.Water; var _waterSets = assetStore.WaterSets; _waterTextureSet = new Dictionary <TimeOfDay, Texture>(); _waterUvScrollSet = new Dictionary <TimeOfDay, Vector2>(); _waterDiffuseColorSet = new Dictionary <TimeOfDay, ColorRgba>(); _waterTransparentDiffuseColorSet = new Dictionary <TimeOfDay, ColorRgba>(); foreach (var waterSet in _waterSets) { _waterTextureSet.Add(waterSet.TimeOfDay, waterSet.WaterTexture.Value.Texture); _waterUvScrollSet.Add(waterSet.TimeOfDay, new Vector2(waterSet.UScrollPerMS, waterSet.VScrollPerMS)); _waterDiffuseColorSet.Add(waterSet.TimeOfDay, waterSet.DiffuseColor); _waterTransparentDiffuseColorSet.Add(waterSet.TimeOfDay, waterSet.TransparentDiffuseColor); } _bumpTexture = graphicsLoadContext.StandardGraphicsResources.SolidWhiteTexture; _waterConstantsPSBuffer = AddDisposable(new ConstantBuffer <GlobalShaderResources.WaterConstantsPS>( graphicsDevice, "WaterConstantsPS")); _uvOffset = Vector2.Zero; _transparentWaterDepth = assetStore.WaterTransparency.Current.TransparentWaterDepth; _transparentWaterMinOpacity = assetStore.WaterTransparency.Current.TransparentWaterMinOpacity; }
public RenderPipeline(Game game) { _renderList = new RenderList(); var graphicsDevice = game.GraphicsDevice; _loadContext = game.GraphicsLoadContext; _globalShaderResources = game.GraphicsLoadContext.ShaderResources.Global; _globalShaderResourceData = AddDisposable(new GlobalShaderResourceData(game.GraphicsDevice, _globalShaderResources)); _renderItemConstantsBufferVS = AddDisposable(new ConstantBuffer <MeshShaderResources.RenderItemConstantsVS>(graphicsDevice, "RenderItemConstantsVS")); _renderItemConstantsBufferPS = AddDisposable(new ConstantBuffer <MeshShaderResources.RenderItemConstantsPS>(graphicsDevice, "RenderItemConstantsPS")); _renderItemConstantsResourceSet = AddDisposable(graphicsDevice.ResourceFactory.CreateResourceSet( new ResourceSetDescription( game.GraphicsLoadContext.ShaderResources.Mesh.RenderItemConstantsResourceLayout, _renderItemConstantsBufferVS.Buffer, _renderItemConstantsBufferPS.Buffer))); _commandList = AddDisposable(graphicsDevice.ResourceFactory.CreateCommandList()); _drawingContext = AddDisposable(new DrawingContext2D( game.ContentManager, game.GraphicsLoadContext, BlendStateDescription.SingleAlphaBlend, GameOutputDescription)); _shadowMapRenderer = AddDisposable(new ShadowMapRenderer(game.GraphicsDevice, game.GraphicsLoadContext.ShaderResources.Global)); _textureCopier = AddDisposable(new TextureCopier( game, game.Panel.OutputDescription)); }
protected override Texture CreateTexture(Size size, GraphicsLoadContext loadContext) { return(MappedImageUtility.CreateTexture(loadContext, size, spriteBatch => { var requiresFlip = !loadContext.GraphicsDevice.IsUvOriginTopLeft; var leftWidth = _left.Coords.Width; var rightWidth = _right.Coords.Width; var leftRect = new Rectangle(0, 0, leftWidth, size.Height); spriteBatch.DrawImage( _left.Texture.Value, _left.Coords, leftRect.ToRectangleF(), ColorRgbaF.White, requiresFlip); var middleRect = new Rectangle(leftRect.Right, 0, size.Width - leftWidth - rightWidth, size.Height); spriteBatch.DrawImage( _middle.Texture.Value, _middle.Coords, middleRect.ToRectangleF(), ColorRgbaF.White, requiresFlip); var rightRect = new Rectangle(middleRect.Right, 0, rightWidth, size.Height); spriteBatch.DrawImage( _right.Texture.Value, _right.Coords, rightRect.ToRectangleF(), ColorRgbaF.White, requiresFlip); })); }
/// <summary> /// Creates a texture from a mapped image. We need to do this to avoid alpha bleeding artifacts /// when blitting a portion of a texture. /// </summary> public static Texture CreateTexture( GraphicsLoadContext loadContext, Size size, Action <SpriteBatch> drawCallback) { var graphicsDevice = loadContext.GraphicsDevice; var imageTexture = graphicsDevice.ResourceFactory.CreateTexture( TextureDescription.Texture2D( (uint)size.Width, (uint)size.Height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled | TextureUsage.RenderTarget)); imageTexture.Name = "WndImage"; var framebuffer = graphicsDevice.ResourceFactory.CreateFramebuffer(new FramebufferDescription(null, imageTexture)); var spriteBatch = new SpriteBatch( loadContext, BlendStateDescription.SingleDisabled, framebuffer.OutputDescription); var commandList = graphicsDevice.ResourceFactory.CreateCommandList(); commandList.Begin(); commandList.SetFramebuffer(framebuffer); spriteBatch.Begin( commandList, loadContext.StandardGraphicsResources.PointClampSampler, new SizeF(imageTexture.Width, imageTexture.Height)); spriteBatch.DrawImage( loadContext.StandardGraphicsResources.SolidWhiteTexture, null, new RectangleF(0, 0, imageTexture.Width, imageTexture.Height), ColorRgbaF.Transparent); drawCallback(spriteBatch); spriteBatch.End(); commandList.End(); graphicsDevice.SubmitCommands(commandList); graphicsDevice.DisposeWhenIdle(commandList); graphicsDevice.DisposeWhenIdle(spriteBatch); graphicsDevice.DisposeWhenIdle(framebuffer); graphicsDevice.WaitForIdle(); return(imageTexture); }
protected override Texture CreateTexture(Size size, GraphicsLoadContext loadContext) { return MappedImageUtility.CreateTexture(loadContext, size, spriteBatch => { spriteBatch.DrawImage( _mappedImage.Texture.Value, _mappedImage.Coords, new Rectangle(Point2D.Zero, size).ToRectangleF(), ColorRgbaF.White); }); }
public ShapeRenderer( Geometry shape, ContentManager contentManager, GraphicsLoadContext graphicsLoadContext, AssetStore assetStore, ImageMap map, string movieName) { _shape = shape; _context = new AptContext(map, movieName, assetStore); _renderingContext = new AptRenderingContext(null, contentManager, graphicsLoadContext, _context); }
protected override Texture CreateTexture(Size size, GraphicsLoadContext loadContext) { return(MappedImageUtility.CreateTexture(loadContext, size, spriteBatch => { var requiresFlip = !loadContext.GraphicsDevice.IsUvOriginTopLeft; spriteBatch.DrawImage( _mappedImage.Texture.Value, _mappedImage.Coords, new Rectangle(Point2D.Zero, size).ToRectangleF(), ColorRgbaF.White, requiresFlip); })); }
/// <summary> /// Creates a texture from a mapped image. /// This version does a simple copy of the original image part /// </summary> public static Texture CreateTexture( GraphicsLoadContext loadContext, MappedImage mappedImage) { var graphicsDevice = loadContext.GraphicsDevice; var src = mappedImage.Coords; var width = (uint)src.Width; var height = (uint)src.Height; var imageTexture = graphicsDevice.ResourceFactory.CreateTexture( TextureDescription.Texture2D( width, height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled)); imageTexture.Name = "WndImage"; var commandList = graphicsDevice.ResourceFactory.CreateCommandList(); commandList.Begin(); commandList.CopyTexture( mappedImage.Texture.Value, (uint)src.Left, (uint)src.Top, 0, 0, 0, // Source imageTexture, 0, 0, 0, 0, 0, width, height, 1, 1); // Destination commandList.End(); graphicsDevice.SubmitCommands(commandList); graphicsDevice.DisposeWhenIdle(commandList); graphicsDevice.WaitForIdle(); return(imageTexture); }
internal AptRenderingContext( AptWindow window, ContentManager contentManager, GraphicsLoadContext graphicsLoadContext, AptContext aptContext) { _contentManager = contentManager; _aptContext = aptContext; _graphicsLoadContext = graphicsLoadContext; Window = window; _transformStack = new Stack <ItemTransform>(); _clipMaskDrawingContext = AddDisposable( new DrawingContext2D( contentManager, graphicsLoadContext, BlendStateDescription.SingleAlphaBlend, RenderTarget.OutputDescription)); _commandList = AddDisposable(contentManager.GraphicsDevice.ResourceFactory.CreateCommandList()); }
protected override Texture CreateTexture(Size size, GraphicsLoadContext loadContext) { return(MappedImageUtility.CreateTexture(loadContext, _mappedImage)); }
internal SpriteBatch( GraphicsLoadContext loadContext, in BlendStateDescription blendStateDescription,
internal DrawingContext2D( ContentManager contentManager, GraphicsLoadContext loadContext, in BlendStateDescription blendStateDescription,
protected abstract Texture CreateTexture(Size size, GraphicsLoadContext loadContext);
public ImageTextureCache(GraphicsLoadContext loadContext) { _loadContext = loadContext; }
public void CanReadIniFiles() { var gameDefinitions = new[] { GameDefinition.FromGame(SageGame.CncGenerals), GameDefinition.FromGame(SageGame.CncGeneralsZeroHour), GameDefinition.FromGame(SageGame.Bfme), GameDefinition.FromGame(SageGame.Bfme2), GameDefinition.FromGame(SageGame.Bfme2Rotwk), }; using var graphicsDevice = GraphicsDeviceUtility.CreateGraphicsDevice(null, null); using var standardGraphicsResources = new StandardGraphicsResources(graphicsDevice); using var shaderSetStore = new ShaderSetStore(graphicsDevice, RenderPipeline.GameOutputDescription); using var shaderResources = new ShaderResourceManager(graphicsDevice, standardGraphicsResources, shaderSetStore); var graphicsLoadContext = new GraphicsLoadContext(graphicsDevice, standardGraphicsResources, shaderResources, shaderSetStore); foreach (var gameDefinition in gameDefinitions) { foreach (var installation in InstallationLocators.FindAllInstallations(gameDefinition)) { using var fileSystem = installation.CreateFileSystem(); var assetStore = new AssetStore( gameDefinition.Game, fileSystem, LanguageUtility.ReadCurrentLanguage(gameDefinition, fileSystem), graphicsDevice, standardGraphicsResources, shaderResources, shaderSetStore, gameDefinition.CreateAssetLoadStrategy()); assetStore.PushScope(); var dataContext = new IniDataContext(); void LoadIniFile(FileSystemEntry entry) { var parser = new IniParser( entry, assetStore, gameDefinition.Game, dataContext, LocaleSpecificEncoding); parser.ParseFile(); } switch (gameDefinition.Game) { case SageGame.Bfme: case SageGame.Bfme2: case SageGame.Bfme2Rotwk: LoadIniFile(fileSystem.GetFile(@"Data\INI\GameData.ini")); break; } foreach (var file in fileSystem.GetFilesInDirectory("", $"*.ini", SearchOption.AllDirectories)) { var filename = Path.GetFileName(file.FilePath).ToLowerInvariant(); switch (filename) { case "webpages.ini": // Don't care about this case "buttonsets.ini": // Doesn't seem to be used? case "scripts.ini": // Only needed by World Builder? case "commandmapdebug.ini": // Only applies to DEBUG and INTERNAL builds case "fxparticlesystemcustom.ini": // Don't know if this is used, it uses Emitter property not used elsewhere case "lightpoints.ini": // Don't know if this is used. //added in BFME and subsequent games case "optionregistry.ini": // Don't know if this is used case "localization.ini": // Don't know if we need this continue; case "credits.ini": if (gameDefinition.Game == SageGame.Bfme2Rotwk) //corrupted in rotwk (start of the block is commented out) { continue; } break; //mods specific //edain mod case "einstellungen.ini": case "einstellungendeakt.ini": case "einstellungenedain.ini": case "news.ini": continue; //unofficial patch 2.02 case "desktop.ini": //got into a big file somehow case "2.01.ini": case "disable timer.ini": case "enable timer.ini": case "old music.ini": continue; default: if (filename.StartsWith("2.02")) { continue; } break; } _output.WriteLine($"Reading file {file.FilePath}."); LoadIniFile(file); } } } }