public ShaderSet( GraphicsDevice graphicsDevice, string shaderName, GlobalResourceSetIndices globalResourceSetIndices, params VertexLayoutDescription[] vertexDescriptors) { GlobalResourceSetIndices = globalResourceSetIndices; Id = NextId++; #if DEBUG const bool debug = true; #else const bool debug = false; #endif GetShaders( graphicsDevice.ResourceFactory, shaderName, debug, out var vertexShader, out var fragmentShader); AddDisposable(vertexShader); AddDisposable(fragmentShader); vertexShader.Name = $"{shaderName}.vert"; fragmentShader.Name = $"{shaderName}.frag"; Description = new ShaderSetDescription( vertexDescriptors, new[] { vertexShader, fragmentShader }); }
protected ShaderResourcesBase( GraphicsDevice graphicsDevice, string shaderName, GlobalResourceSetIndices globalResourceSetIndices, params VertexLayoutDescription[] vertexDescriptors) { GraphicsDevice = graphicsDevice; ShaderSet = AddDisposable(new ShaderSet( graphicsDevice, shaderName, globalResourceSetIndices, vertexDescriptors)); }
public ShaderSet( GraphicsDevice graphicsDevice, string shaderName, GlobalResourceSetIndices globalResourceSetIndices, params VertexLayoutDescription[] vertexDescriptors) { GlobalResourceSetIndices = globalResourceSetIndices; Id = _nextId++; #if DEBUG const bool debug = true; #else const bool debug = false; #endif var assembly = typeof(ShaderSet).Assembly; byte[] ReadShader(string shaderType) { var bytecodeShaderName = $"OpenSage.Assets.Shaders.{shaderName}.{shaderType}.spv"; using (var shaderStream = assembly.GetManifestResourceStream(bytecodeShaderName)) { return(shaderStream.ReadAllBytes()); } } var vsBytes = ReadShader("vert"); var fsBytes = ReadShader("frag"); var shaders = graphicsDevice.ResourceFactory.CreateFromSpirv( new ShaderDescription(ShaderStages.Vertex, vsBytes, "main", debug), new ShaderDescription(ShaderStages.Fragment, fsBytes, "main", debug), new CrossCompileOptions()); var vertexShader = AddDisposable(shaders[0]); var fragmentShader = AddDisposable(shaders[1]); vertexShader.Name = $"{shaderName}.vert"; fragmentShader.Name = $"{shaderName}.frag"; Description = new ShaderSetDescription( vertexDescriptors, new[] { vertexShader, fragmentShader }); }