/// <summary> /// Initializes a new instance of the <see cref="SpriteBatch" /> class. /// </summary> /// <param name="graphicsDevice"> The graphics device. </param> /// <param name="center"> (Optional) True to center the coordinate system in the viewport. </param> /// <param name="sortAlgorithm"> (Optional) The sort algorithm. </param> /// <exception cref="ArgumentException"> /// Thrown when one or more arguments have unsupported or /// illegal values. /// </exception> /// <exception cref="NullReferenceException"> Thrown when a value was unexpectedly null. </exception> public SpriteBatch(IGraphicsDevice graphicsDevice, bool center = false, SpriteSortAlgorithm sortAlgorithm = SpriteSortAlgorithm.MergeSort) { _device = graphicsDevice.Device; _context = graphicsDevice.DeviceContext; _center = center; _spriteSort = sortAlgorithm switch { SpriteSortAlgorithm.MergeSort => new SpriteMergeSort(), _ => throw new ArgumentException($"invalid sort algorithm ({sortAlgorithm})", nameof(sortAlgorithm)) }; _defaultBlendState = graphicsDevice.BlendStates.AlphaBlend; _defaultSamplerState = graphicsDevice.SamplerStates.LinearWrap; _defaultDepthStencilState = graphicsDevice.DepthStencilStates.None; _defaultRasterizerState = graphicsDevice.RasterizerStates.CullBackDepthClipOff; _defaultRasterizerScissorEnabledState = graphicsDevice.RasterizerStates.CullBackDepthClipOffScissorEnabled; _whiteTexture = graphicsDevice.Textures.White; _indexBuffer = IndexBuffer.Create(graphicsDevice, s_indices); Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{Shaders.POSITION_COLOR_TEXTURE}") ?? throw new NullReferenceException($"{assembly.GetName().Name}.{Shaders.POSITION_COLOR_TEXTURE}")) { Shader.Shader.Group group = (_shader = ShaderFileLoader.FromStream(graphicsDevice, stream) ?? throw new NullReferenceException(nameof(ShaderFileLoader.FromStream)))["DEFAULT"];
private void addShaders() { _shaders.Add( ShaderFileLoader.CreateDefault(asset("shaders/")).Load(".") ); new[] { "uvcolor", "photon" }.ForEach(name => _shaders.MakeShaderProgram(name)); }
public ShaderManager() { var loader = ShaderFileLoader.CreateDefault("data/shaders"); var man = new amulware.Graphics.ShaderManagement.ShaderManager(); man.Add(loader.Load("")); this.Primitives = man.MakeShaderProgram("primitives"); this.UVColor = man.MakeShaderProgram("uvcolor"); }
public GameRenderer() { this.shaderMan = new ShaderManager(); var shaderLoader = ShaderFileLoader.CreateDefault("data/shaders"); this.shaderMan.Add(shaderLoader.Load("")); this.surfaces = new SurfaceManager(this.shaderMan); new GeometryManager(this.surfaces); }
public SurfaceManager() { Shaders.Add( ShaderFileLoader.CreateDefault(asset("Shaders/")).Load(".") ); new[] { "geometry", "uvcolor", "Deferred/gSprite", "Deferred/gLevel", "Deferred/debug", "Deferred/compose", "Deferred/pointlight" }.ForEach(name => Shaders.MakeShaderProgram(name)); Primitives = new IndexedSurface <PrimitiveVertexData>() .WithShader(Shaders["geometry"]) .AndSettings(ViewMatrix, ProjectionMatrix); ConsoleBackground = new IndexedSurface <PrimitiveVertexData>() .WithShader(Shaders["geometry"]) .AndSettings(ViewMatrix, ProjectionMatrix); ConsoleFont = Font.FromJsonFile(font("Inconsolata.json")); ConsoleFontSurface = new IndexedSurface <UVColorVertexData>() .WithShader(Shaders["uvcolor"]) .AndSettings( ViewMatrix, ProjectionMatrix, new TextureUniform("diffuse", new Texture(font("Inconsolata.png"), preMultiplyAlpha: true)) ); UIFont = Font.FromJsonFile(font("HelveticaNeue.json")); UIFontSurface = new IndexedSurface <UVColorVertexData>() .WithShader(Shaders["uvcolor"]) .AndSettings( ViewMatrix, ProjectionMatrix, new TextureUniform("diffuse", new Texture(font("HelveticaNeue.png"), preMultiplyAlpha: true)) ); LevelSurface = new IndexedSurface <LevelVertex>() .WithShader(Shaders["Deferred/gLevel"]) .AndSettings(ViewMatrix, ProjectionMatrix); PointLights = new IndexedSurface <PointLightVertex>() .WithShader(Shaders["Deferred/pointlight"]) .AndSettings(ViewMatrix, ProjectionMatrix); GameSurfaces = new GameSurfaceManager(Shaders, ViewMatrix, ProjectionMatrix); }
public SurfaceManager() { shaders.Add( ShaderFileLoader.CreateDefault(asset("shaders/")).Load(".") ); new[] { "geometry", "uvcolor" }.ForEach(name => shaders.MakeShaderProgram(name)); ConsoleBackground = new IndexedSurface <PrimitiveVertexData>() .WithShader(shaders["geometry"]) .AndSettings(ViewMatrix, ProjectionMatrix); ConsoleFont = Font.FromJsonFile(font("inconsolata.json")); ConsoleFontSurface = new IndexedSurface <UVColorVertexData>() .WithShader(shaders["uvcolor"]) .AndSettings( ViewMatrix, ProjectionMatrix, new TextureUniform("diffuse", new Texture(font("inconsolata.png"), preMultiplyAlpha: true)) ); }
/// <summary> /// Initializes a new instance of the <see cref="Canvas" /> class. /// </summary> /// <param name="graphicsDevice"> The graphics device. </param> /// <exception cref="NullReferenceException"> Thrown when a value was unexpectedly null. </exception> public Canvas(IGraphicsDevice graphicsDevice) { _context = graphicsDevice.DeviceContext; _defaultBlendState = graphicsDevice.BlendStates.AlphaBlend; _defaultSamplerState = graphicsDevice.SamplerStates.LinearWrap; _defaultDepthStencilState = graphicsDevice.DepthStencilStates.None; _defaultRasterizerState = graphicsDevice.RasterizerStates.CullBackDepthClipOff; _defaultRasterizerScissorEnabledState = graphicsDevice.RasterizerStates.CullBackDepthClipOffScissorEnabled; _indexBuffer = IndexBuffer.Create(graphicsDevice, s_indices); Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{Shaders.CANVAS}") ?? throw new NullReferenceException($"{assembly.GetName().Name}.{Shaders.CANVAS}")) { Shader.Shader.Group group = (_shader = ShaderFileLoader.FromStream(graphicsDevice, stream) ?? throw new NullReferenceException(nameof(ShaderFileLoader.FromStream)))["DEFAULT"];