cubemap.SetName ("skybox Texture");
cubemap.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, renderPass.Samples, false);
- cfg.RenderPass = renderPass;
- cfg.Layout = plLayout;
- cfg.AddVertexBinding (0, 3 * sizeof (float));
- cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat);
- cfg.AddShaders (
- new ShaderInfo (Dev, VkShaderStageFlags.Vertex, "#EnvironmentPipeline.skybox.vert.spv"),
- new ShaderInfo (Dev, VkShaderStageFlags.Fragment, STR_FRAG_PATH)
- );
+ using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, renderPass.Samples, false)) {
+ cfg.RenderPass = renderPass;
+ cfg.Layout = plLayout;
+ cfg.AddVertexBinding (0, 3 * sizeof (float));
+ cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat);
+ cfg.AddShaders (
+ new ShaderInfo (Dev, VkShaderStageFlags.Vertex, "#EnvironmentPipeline.skybox.vert.spv"),
+ new ShaderInfo (Dev, VkShaderStageFlags.Fragment, STR_FRAG_PATH)
+ );
- cfg.multisampleState.rasterizationSamples = Samples;
+ cfg.multisampleState.rasterizationSamples = Samples;
- layout = cfg.Layout;
+ layout = cfg.Layout;
- init (cfg);
-
- cfg.DisposeShaders ();
+ init (cfg);
+ }
generateBRDFLUT (staggingQ, cmdPool);
generateCubemaps (staggingQ, cmdPool);
new ShaderInfo (Dev, VkShaderStageFlags.Fragment, "#EnvironmentPipeline.genbrdflut.frag.spv"));
using (GraphicPipeline pl = new GraphicPipeline (cfg)) {
- cfg.DisposeShaders ();
+ cfg.Dispose ();
using (FrameBuffer fb = new FrameBuffer (cfg.RenderPass, dim, dim, lutBrdf)) {
PrimaryCommandBuffer cmd = cmdPool.AllocateCommandBuffer ();
cmd.Start (VkCommandBufferUsageFlags.OneTimeSubmit);
VkImageSubresourceRange subRes = new VkImageSubresourceRange (VkImageAspectFlags.Color, 0, numMips, 0, 6);
using (GraphicPipeline pl = new GraphicPipeline (cfg)) {
- cfg.DisposeShaders ();
+ cfg.Dispose ();
DescriptorSet dset = dsPool.Allocate (dsLayout);
DescriptorSetWrites dsUpdate = new DescriptorSetWrites (dsLayout);
dsUpdate.Write (Dev, dset, cubemap.Descriptor);
dsLayout = new DescriptorSetLayout (dev, 0,
new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer),
new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));
-
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount4);
- cfg.Layout = new PipelineLayout (dev, dsLayout);
- cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), cfg.Samples);
+ using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount4)) {
- cfg.AddVertexBinding (0, 5 * sizeof(float));
- cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat);
+ cfg.Layout = new PipelineLayout (dev, dsLayout);
+ cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), cfg.Samples);
- cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv");
- cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv");
+ cfg.AddVertexBinding (0, 5 * sizeof (float));
+ cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat);
- pipeline = new GraphicPipeline (cfg);
+ cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv");
+ cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv");
- cfg.DisposeShaders ();
+ pipeline = new GraphicPipeline (cfg);
+ }
uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices);
new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer),
new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, samples);
+ using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, samples)) {
- cfg.Layout = new PipelineLayout (dev, dsLayout);
- cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), cfg.Samples);
+ cfg.Layout = new PipelineLayout (dev, dsLayout);
+ cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), cfg.Samples);
- cfg.AddVertexBinding (0, 5 * sizeof (float));
- cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat);
+ cfg.AddVertexBinding (0, 5 * sizeof (float));
+ cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat);
- cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.skybox.vert.spv");
- cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.skybox.frag.spv");
+ cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.skybox.vert.spv");
+ cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.skybox.frag.spv");
- pipeline = new GraphicPipeline (cfg);
-
- cfg.DisposeShaders ();
+ pipeline = new GraphicPipeline (cfg);
+ }
uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices);
uboMats.Map ();//permanent map
descriptorPool = new DescriptorPool (dev, 1, new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer));
//Graphic pipeline configuration are predefined by the GraphicPipelineConfig class, which ease sharing config for several pipelines having lots in common.
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false);
- //Create the pipeline layout, it will be automatically activated on pipeline creation, so that sharing layout among different pipelines will benefit
- //from the reference counting to automatically dispose unused layout on pipeline clean up. It's the same for DescriptorSetLayout.
- cfg.Layout = new PipelineLayout (dev,
- new DescriptorSetLayout (dev, new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer)));
- //create a default renderpass with just a color attachment for the swapchain image, a default subpass is automatically created and the renderpass activation
- //will follow the pipeline life cicle and will be automatically disposed when no longuer used.
- cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, cfg.Samples);
- //configuration of vertex bindings and attributes
- cfg.AddVertexBinding<Vertex> (0);
- cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat);//position + color
-
- //shader are automatically compiled by SpirVTasks if added to the project. The resulting shaders are automatically embedded in the assembly.
- //To specifiy that the shader path is a resource name, put the '#' prefix. Else the path will be search on disk.
- cfg.AddShaders (
- new ShaderInfo (dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv"),
- new ShaderInfo (dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv")
- );
-
- //create and activate the pipeline with the configuration we've just done.
- pipeline = new GraphicPipeline (cfg);
-
- //ShaderInfo used in this configuration with create the VkShaderModule's used
- //for creating the pipeline. They have to be disposed to destroy those modules
- //used only during pipeline creation.
- cfg.DisposeShaders ();
+ using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false)) {
+ //Create the pipeline layout, it will be automatically activated on pipeline creation, so that sharing layout among different pipelines will benefit
+ //from the reference counting to automatically dispose unused layout on pipeline clean up. It's the same for DescriptorSetLayout.
+ cfg.Layout = new PipelineLayout (dev,
+ new DescriptorSetLayout (dev, new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer)));
+ //create a default renderpass with just a color attachment for the swapchain image, a default subpass is automatically created and the renderpass activation
+ //will follow the pipeline life cicle and will be automatically disposed when no longuer used.
+ cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, cfg.Samples);
+ //configuration of vertex bindings and attributes
+ cfg.AddVertexBinding<Vertex> (0);
+ cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat);//position + color
+
+ //shader are automatically compiled by SpirVTasks if added to the project. The resulting shaders are automatically embedded in the assembly.
+ //To specifiy that the shader path is a resource name, put the '#' prefix. Else the path will be search on disk.
+ cfg.AddShaders (
+ new ShaderInfo (dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv"),
+ new ShaderInfo (dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv")
+ );
+
+ //create and activate the pipeline with the configuration we've just done.
+ pipeline = new GraphicPipeline (cfg);
+ }
//because descriptor layout used for a pipeline are only activated on pipeline activation, descriptor set must not be allocated before, except if the layout has been manually activated,
//but in this case, layout will need also to be explicitly disposed.
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, NUM_SAMPLES);
- cfg.rasterizationState.cullMode = VkCullModeFlags.Back;
- if (NUM_SAMPLES != VkSampleCountFlags.SampleCount1) {
- cfg.multisampleState.sampleShadingEnable = true;
- cfg.multisampleState.minSampleShading = 0.5f;
- }
- cfg.Cache = pipelineCache;
- if (TEXTURE_ARRAY)
- cfg.Layout = new PipelineLayout (dev, descLayoutMain, descLayoutGBuff);
- else
- cfg.Layout = new PipelineLayout (dev, descLayoutMain, descLayoutGBuff, descLayoutTextures);
-
- cfg.Layout.AddPushConstants (
- new VkPushConstantRange (VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf<Matrix4x4> ()),
- new VkPushConstantRange (VkShaderStageFlags.Fragment, sizeof (int), 64)
- );
- cfg.RenderPass = renderPass;
- cfg.SubpassIndex = SP_MODELS;
- cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
- cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
- cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
- //cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
-
- cfg.AddVertex<PbrModelTexArray.Vertex> ();
-
- using (SpecializationInfo constants = new SpecializationInfo (
- new SpecializationConstant<float> (0, nearPlane),
- new SpecializationConstant<float> (1, farPlane),
- new SpecializationConstant<float> (2, MAX_MATERIAL_COUNT))) {
-
- cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.GBuffPbr.vert.spv");
- if (TEXTURE_ARRAY)
- cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.GBuffPbrTexArray.frag.spv", constants);
+ using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, NUM_SAMPLES)) {
+ cfg.rasterizationState.cullMode = VkCullModeFlags.Back;
+ if (NUM_SAMPLES != VkSampleCountFlags.SampleCount1) {
+ cfg.multisampleState.sampleShadingEnable = true;
+ cfg.multisampleState.minSampleShading = 0.5f;
+ }
+ cfg.Cache = pipelineCache;
+ if (TEXTURE_ARRAY)
+ cfg.Layout = new PipelineLayout (dev, descLayoutMain, descLayoutGBuff);
else
- cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.GBuffPbr.frag.spv", constants);
-
- gBuffPipeline = new GraphicPipeline (cfg);
- }
- cfg.rasterizationState.cullMode = VkCullModeFlags.Front;
- //COMPOSE PIPELINE
- cfg.blendAttachments.Clear ();
- cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
- cfg.ResetShadersAndVerticesInfos ();
- cfg.SubpassIndex = SP_COMPOSE;
- cfg.Layout = gBuffPipeline.Layout;
- cfg.depthStencilState.depthTestEnable = false;
- cfg.depthStencilState.depthWriteEnable = false;
- using (SpecializationInfo constants = new SpecializationInfo (
- new SpecializationConstant<uint> (0, (uint)lights.Length))) {
- cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv");
+ cfg.Layout = new PipelineLayout (dev, descLayoutMain, descLayoutGBuff, descLayoutTextures);
+
+ cfg.Layout.AddPushConstants (
+ new VkPushConstantRange (VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf<Matrix4x4> ()),
+ new VkPushConstantRange (VkShaderStageFlags.Fragment, sizeof (int), 64)
+ );
+ cfg.RenderPass = renderPass;
+ cfg.SubpassIndex = SP_MODELS;
+ cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
+ cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
+ cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
+ //cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
+
+ cfg.AddVertex<PbrModelTexArray.Vertex> ();
+
+ using (SpecializationInfo constants = new SpecializationInfo (
+ new SpecializationConstant<float> (0, nearPlane),
+ new SpecializationConstant<float> (1, farPlane),
+ new SpecializationConstant<float> (2, MAX_MATERIAL_COUNT))) {
+
+ cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.GBuffPbr.vert.spv");
+ if (TEXTURE_ARRAY)
+ cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.GBuffPbrTexArray.frag.spv", constants);
+ else
+ cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.GBuffPbr.frag.spv", constants);
+
+ gBuffPipeline = new GraphicPipeline (cfg);
+ }
+ cfg.ResetShadersAndVerticesInfos ();
+
+ cfg.rasterizationState.cullMode = VkCullModeFlags.Front;
+ //COMPOSE PIPELINE
+ cfg.blendAttachments.Clear ();
+ cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
+ cfg.SubpassIndex = SP_COMPOSE;
+ cfg.Layout = gBuffPipeline.Layout;
+ cfg.depthStencilState.depthTestEnable = false;
+ cfg.depthStencilState.depthWriteEnable = false;
+ using (SpecializationInfo constants = new SpecializationInfo (
+ new SpecializationConstant<uint> (0, (uint)lights.Length))) {
+ cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv");
#if WITH_SHADOWS
- cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.compose_with_shadows.frag.spv", constants);
+ cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.compose_with_shadows.frag.spv", constants);
#else
cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.compose.frag.spv", constants);
#endif
- composePipeline = new GraphicPipeline (cfg);
+ composePipeline = new GraphicPipeline (cfg);
+ }
+ //DEBUG DRAW use subpass of compose
+ cfg.ReplaceShader (1, new ShaderInfo (dev, VkShaderStageFlags.Fragment, "#shaders.show_gbuff.frag.spv"));
+ cfg.SubpassIndex = SP_COMPOSE;
+ debugPipeline = new GraphicPipeline (cfg);
+ ////TONE MAPPING
+ //cfg.shaders[1] = new ShaderInfo (VkShaderStageFlags.Fragment, "#shaders.tone_mapping.frag.spv");
+ //cfg.SubpassIndex = SP_TONE_MAPPING;
+ //toneMappingPipeline = new GraphicPipeline (cfg);
}
- //DEBUG DRAW use subpass of compose
- cfg.Shaders[1].Dispose ();
- cfg.Shaders[1] = new ShaderInfo (dev, VkShaderStageFlags.Fragment, "#shaders.show_gbuff.frag.spv");
- cfg.SubpassIndex = SP_COMPOSE;
- debugPipeline = new GraphicPipeline (cfg);
- ////TONE MAPPING
- //cfg.shaders[1] = new ShaderInfo (VkShaderStageFlags.Fragment, "#shaders.tone_mapping.frag.spv");
- //cfg.SubpassIndex = SP_TONE_MAPPING;
- //toneMappingPipeline = new GraphicPipeline (cfg);
-
- cfg.DisposeShaders ();
dsMain = descriptorPool.Allocate (descLayoutMain);
dsGBuff = descriptorPool.Allocate (descLayoutGBuff);
new VkDescriptorSetLayoutBinding (3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
);
-
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, renderPass.Samples);
- cfg.Layout = new PipelineLayout (Dev, descLayoutMain, descLayoutTextures);
- cfg.Layout.AddPushConstants (
- new VkPushConstantRange (VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf<Matrix4x4> ()),
- new VkPushConstantRange (VkShaderStageFlags.Fragment, sizeof(int), 64)
- );
- cfg.RenderPass = renderPass;
- cfg.AddVertexBinding<PbrModel.Vertex> (0);
- cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat, VkFormat.R32g32Sfloat);
- cfg.AddShader (Dev, VkShaderStageFlags.Vertex, "#shaders.pbr.vert.spv");
- cfg.AddShader (Dev, VkShaderStageFlags.Fragment, "#shaders.pbr_khr.frag.spv");
+ using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, renderPass.Samples)) {
+ cfg.Layout = new PipelineLayout (Dev, descLayoutMain, descLayoutTextures);
+ cfg.Layout.AddPushConstants (
+ new VkPushConstantRange (VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf<Matrix4x4> ()),
+ new VkPushConstantRange (VkShaderStageFlags.Fragment, sizeof (int), 64)
+ );
+ cfg.RenderPass = renderPass;
+ cfg.AddVertexBinding<PbrModel.Vertex> (0);
+ cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat, VkFormat.R32g32Sfloat);
- layout = cfg.Layout;
+ cfg.AddShader (Dev, VkShaderStageFlags.Vertex, "#shaders.pbr.vert.spv");
+ cfg.AddShader (Dev, VkShaderStageFlags.Fragment, "#shaders.pbr_khr.frag.spv");
- init (cfg);
+ layout = cfg.Layout;
- cfg.DisposeShaders ();
+ init (cfg);
+ }
dsMain = descriptorPool.Allocate (descLayoutMain);
bool queryUpdatePrefilCube, showDebugImg;
Vector4 lightPos = new Vector4 (1, 0, 0, 0);
- uint curModelIndex = 0;
+ uint curModelIndex = 13;
protected override void initVulkan () {
base.initVulkan ();
vboLength = maxVertices * 6 * sizeof(float);
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.LineList, samples, false);
- cfg.rasterizationState.lineWidth = 1.0f;
- cfg.RenderPass = RenderPass;
- cfg.Layout = new PipelineLayout(Dev, new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf<Matrix4x4>() * 2));
- cfg.AddVertexBinding (0, 6 * sizeof(float));
- cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat);
- cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState (true);
-
- cfg.AddShaders (
- new ShaderInfo (Dev, VkShaderStageFlags.Vertex, "#vke.debug.vert.spv"),
- new ShaderInfo (Dev, VkShaderStageFlags.Fragment, "#vke.debug.frag.spv")
- );
-
- layout = cfg.Layout;
-
- init (cfg);
-
- cfg.DisposeShaders ();
+ using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.LineList, samples, false)) {
+ cfg.rasterizationState.lineWidth = 1.0f;
+ cfg.RenderPass = RenderPass;
+ cfg.Layout = new PipelineLayout (Dev, new VkPushConstantRange (VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf<Matrix4x4> () * 2));
+ cfg.AddVertexBinding (0, 6 * sizeof (float));
+ cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat);
+ cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState (true);
+
+ cfg.AddShaders (
+ new ShaderInfo (Dev, VkShaderStageFlags.Vertex, "#vke.debug.vert.spv"),
+ new ShaderInfo (Dev, VkShaderStageFlags.Fragment, "#vke.debug.frag.spv")
+ );
+
+ layout = cfg.Layout;
+
+ init (cfg);
+ }
Vertices = new HostBuffer (Dev, VkBufferUsageFlags.VertexBuffer, vboLength);
Vertices.Map ();
/// This class has some facilities for chaining multiple pipelines creations that have small differencies
/// in their configurations.
/// </summary>
- public class GraphicPipelineConfig {
+ public class GraphicPipelineConfig : IDisposable {
public uint SubpassIndex;
/// <summary>
/// Pipeline layout. Note that layout will not be activated (handle creation) until
}
uint currentAttributeIndex = 0;
- public void AddVertexAttributes (uint binding, params VkFormat[] attribsDesc) {
+ private bool disposedValue;
+
+ public void AddVertexAttributes (uint binding, params VkFormat[] attribsDesc) {
uint currentAttributeoffset = 0;
for (uint i = 0; i < attribsDesc.Length; i++) {
vertexAttributes.Add (new VkVertexInputAttributeDescription (binding, i + currentAttributeIndex, attribsDesc[i], currentAttributeoffset));
}
/// <summary>
/// Dispose ShaderInfo at index 'shaderIndex' in the Shaders list, and replace it
- /// with the new 'ShaderInfo' given in arguments.
+ /// with the new 'ShaderInfo' given in arguments. If new `ShaderInfo` is null, the shader list element at the given index will be removed.
/// </summary>
/// <param name="shaderIndex">ShaderInfo index in the Shaders list of this configuration object</param>
- /// <param name="info">the new Shader to use.</param>
+ /// <param name="info">the new Shader to use or null to remove the list item.</param>
public void ReplaceShader (int shaderIndex, ShaderInfo info) {
Shaders[shaderIndex].Dispose ();
- Shaders[shaderIndex] = info;
+ if (info == null)
+ Shaders.RemoveAt (shaderIndex);
+ else
+ Shaders[shaderIndex] = info;
}
/// <summary>
/// Dispose ShaderInfo at index 'shaderIndex' in the Shaders list, and replace it with a new one.
currentAttributeIndex = 0;
vertexBindings.Clear ();
vertexAttributes.Clear ();
- DisposeShaders ();
- }
- /// <summary>
- /// Resets shaders in current config to ease reause of current 'GraphicPipelineConfig
- /// for creating another similar pipeline with different shaders.
- /// </summary>
- public void DisposeShaders () {
foreach (ShaderInfo shader in Shaders)
shader.Dispose ();
Shaders.Clear ();
}
+
+ #region IDispable implementation
+ protected virtual void Dispose (bool disposing) {
+ if (!disposedValue) {
+ if (disposing) {
+ foreach (ShaderInfo shader in Shaders)
+ shader.Dispose ();
+ Shaders.Clear ();
+ }
+ disposedValue = true;
+ }
+ }
+ /// <summary>
+ /// PipelineConfig may create shader modules that have to be disposed after the pipeline creation.
+ /// </summary>
+ public void Dispose () {
+ // Ne changez pas ce code. Placez le code de nettoyage dans la méthode 'Dispose(bool disposing)'
+ Dispose (disposing: true);
+ GC.SuppressFinalize (this);
+ }
+ #endregion
+
}
}