protected override void buildCommandBuffers() { var cmdInfo = VkCommandBufferBeginInfo.Alloc(); var clearValues = VkClearValue.Alloc(2); clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = new VkClearDepthStencilValue() { depth = 1.0f, stencil = 0 }; var info = VkRenderPassBeginInfo.Alloc(); info[0].renderPass = renderPass; info[0].renderArea.offset.x = 0; info[0].renderArea.offset.y = 0; info[0].renderArea.extent.width = width; info[0].renderArea.extent.height = height; info[0].clearValues.count = 2; info[0].clearValues.pointer = clearValues; for (int i = 0; i < drawCmdBuffers.Length; ++i) { // Set target frame buffer info[0].framebuffer = frameBuffers[i]; vkBeginCommandBuffer(drawCmdBuffers[i], cmdInfo); vkCmdBeginRenderPass(drawCmdBuffers[i], info, VkSubpassContents.Inline); VkViewport viewport = new VkViewport((float)width, (float)height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = new VkRect2D(0, 0, width, height); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); { VkDescriptorSet set = descriptorSet; vkCmdBindDescriptorSets(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipelineLayout, 0, 1, &set, 0, null); } vkCmdBindPipeline(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipeline); { VkDeviceSize offsets = 0; VkBuffer buffer = vertexBuffer.buffer; vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &buffer, &offsets); } vkCmdBindIndexBuffer(drawCmdBuffers[i], indexBuffer.buffer, 0, VkIndexType.Uint32); vkCmdDrawIndexed(drawCmdBuffers[i], indexCount, 1, 0, 0, 0); vkCmdEndRenderPass(drawCmdBuffers[i]); vkEndCommandBuffer(drawCmdBuffers[i]); } }
protected override void buildCommandBuffers() { var cmdBufInfo = VkCommandBufferBeginInfo.Alloc(); var clearValues = new VkClearValue[2]; clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = new VkClearDepthStencilValue() { depth = 1.0f, stencil = 0 }; var renderPassBeginInfo = VkRenderPassBeginInfo.Alloc(); renderPassBeginInfo->renderPass = renderPass; renderPassBeginInfo->renderArea.offset.x = 0; renderPassBeginInfo->renderArea.offset.y = 0; renderPassBeginInfo->renderArea.extent.width = width; renderPassBeginInfo->renderArea.extent.height = height; renderPassBeginInfo->clearValues = clearValues; for (int i = 0; i < drawCmdBuffers.Length; ++i) { // Set target frame buffer renderPassBeginInfo->framebuffer = frameBuffers[i]; vkBeginCommandBuffer(drawCmdBuffers[i], cmdBufInfo); vkCmdBeginRenderPass(drawCmdBuffers[i], renderPassBeginInfo, VkSubpassContents.Inline); VkViewport viewport = new VkViewport(0, 0, width, height, 0, 1); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = new VkRect2D(); scissor.extent.width = width; scissor.extent.height = height; scissor.offset.x = 0; scissor.offset.y = 0; vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); { VkDescriptorSet set = descriptorSet; vkCmdBindDescriptorSets(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipelineLayout, 0, 1, &set, 0, null); } vkCmdBindPipeline(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, wireframe ? pipelines_wireframe : pipelines_solid); ulong offsets = 0; // Bind mesh vertex buffer { VkBuffer buffer = model_vertices_buffer; VkDeviceSize offset = offsets; vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &buffer, &offset); } // Bind mesh index buffer vkCmdBindIndexBuffer(drawCmdBuffers[i], model_indices_buffer, 0, VkIndexType.Uint32); // Render mesh vertex buffer using it's indices vkCmdDrawIndexed(drawCmdBuffers[i], (uint)model_indices_count, 1, 0, 0, 0); vkCmdEndRenderPass(drawCmdBuffers[i]); vkEndCommandBuffer(drawCmdBuffers[i]); } }
protected override void buildCommandBuffers() { var cmdBufInfo = VkCommandBufferBeginInfo.Alloc(); var clearValues = new VkClearValue[2]; clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = new VkClearDepthStencilValue { depth = 1.0f, stencil = 0 }; var renderPassBeginInfo = VkRenderPassBeginInfo.Alloc(); renderPassBeginInfo->renderPass = renderPass; renderPassBeginInfo->renderArea.offset.x = 0; renderPassBeginInfo->renderArea.offset.y = 0; renderPassBeginInfo->renderArea.extent.width = width; renderPassBeginInfo->renderArea.extent.height = height; //renderPassBeginInfo->clearValueCount = 2; //renderPassBeginInfo->pClearValues = &clearValues.First; renderPassBeginInfo->clearValues = clearValues; for (int i = 0; i < drawCmdBuffers.Length; ++i) { // Set target frame buffer renderPassBeginInfo->framebuffer = frameBuffers[i]; vkBeginCommandBuffer(drawCmdBuffers[i], cmdBufInfo); vkCmdBeginRenderPass(drawCmdBuffers[i], renderPassBeginInfo, VkSubpassContents.Inline);// VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport = new VkViewport(width, height, 0.0f, 1.0f); vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); VkRect2D scissor = new VkRect2D(0, 0, width, height); vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); // 3D scene { VkDescriptorSet set = setScene; vkCmdBindDescriptorSets(drawCmdBuffers[i], VkPipelineBindPoint.Graphics,// VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayoutScene, 0, 1, &set, 0, null); } vkCmdBindPipeline(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, // VK_PIPELINE_BIND_POINT_GRAPHICS, pipelinePhongPass); { VkBuffer buffer = model.vertices.buffer; VkDeviceSize offset = 0; vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &buffer, &offset); } vkCmdBindIndexBuffer(drawCmdBuffers[i], model.indices.buffer, 0, VkIndexType.Uint32);// VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(drawCmdBuffers[i], model.indexCount, 1, 0, 0, 0); // Fullscreen triangle (clipped to a quad) with radial blur if (blur) { { VkDescriptorSet set = setRadialBlur; vkCmdBindDescriptorSets(drawCmdBuffers[i], VkPipelineBindPoint.Graphics,// VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayoutRadialBlur, 0, 1, &set, 0, null); } vkCmdBindPipeline(drawCmdBuffers[i], VkPipelineBindPoint.Graphics,// VK_PIPELINE_BIND_POINT_GRAPHICS, (displayTexture) ? pipelineOffscreenDisplay : pipelineRadialBlur); vkCmdDraw(drawCmdBuffers[i], 3, 1, 0, 0); } vkCmdEndRenderPass(drawCmdBuffers[i]); vkEndCommandBuffer(drawCmdBuffers[i]); } }
// Sets up the command buffer that renders the scene to the offscreen frame buffer void buildOffscreenCommandBuffer() { if (offscreenPass.commandBuffer.handle == 0) { offscreenPass.commandBuffer = createCommandBuffer( VkCommandBufferLevel.Primary //VK_COMMAND_BUFFER_LEVEL_PRIMARY , false); } if (offscreenPass.semaphore.handle == 0) { var semaphoreCreateInfo = VkSemaphoreCreateInfo.Alloc(); VkSemaphore semaphore; vkCreateSemaphore(device, semaphoreCreateInfo, null, &semaphore); offscreenPass.semaphore = semaphore; } var cmdBufInfo = VkCommandBufferBeginInfo.Alloc(); var clearValues = new VkClearValue[2]; clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = new VkClearDepthStencilValue { depth = 1.0f, stencil = 0 }; var renderPassBeginInfo = VkRenderPassBeginInfo.Alloc(); renderPassBeginInfo->renderPass = offscreenPass.renderPass; renderPassBeginInfo->framebuffer = offscreenPass.framebuffer; renderPassBeginInfo->renderArea.extent.width = offscreenPass.width; renderPassBeginInfo->renderArea.extent.height = offscreenPass.height; renderPassBeginInfo->clearValues = clearValues; vkBeginCommandBuffer(offscreenPass.commandBuffer, cmdBufInfo); VkViewport viewport = new VkViewport(offscreenPass.width, offscreenPass.height, 0.0f, 1.0f); vkCmdSetViewport(offscreenPass.commandBuffer, 0, 1, &viewport); VkRect2D scissor = new VkRect2D(0, 0, offscreenPass.width, offscreenPass.height); vkCmdSetScissor(offscreenPass.commandBuffer, 0, 1, &scissor); vkCmdBeginRenderPass(offscreenPass.commandBuffer, renderPassBeginInfo, VkSubpassContents.Inline);// VK_SUBPASS_CONTENTS_INLINE); { VkDescriptorSet set = setScene; vkCmdBindDescriptorSets(offscreenPass.commandBuffer, VkPipelineBindPoint.Graphics,// VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayoutScene, 0, 1, &set, 0, null); } vkCmdBindPipeline(offscreenPass.commandBuffer, VkPipelineBindPoint.Graphics, // VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineColorPass); { VkBuffer buffer = model.vertices.buffer; VkDeviceSize offset = 0; vkCmdBindVertexBuffers(offscreenPass.commandBuffer, VERTEX_BUFFER_BIND_ID, 1, &buffer, &offset); } vkCmdBindIndexBuffer(offscreenPass.commandBuffer, model.indices.buffer, 0, VkIndexType.Uint32);// VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(offscreenPass.commandBuffer, model.indexCount, 1, 0, 0, 0); vkCmdEndRenderPass(offscreenPass.commandBuffer); vkEndCommandBuffer(offscreenPass.commandBuffer); }