hellovulkanwindow.cpp Example File
hellovulkanwindow/hellovulkanwindow.cpp
#include "hellovulkanwindow.h"
#include <QVulkanFunctions>
QVulkanWindowRenderer *VulkanWindow::createRenderer()
{
return new VulkanRenderer(this);
}
VulkanRenderer::VulkanRenderer(QVulkanWindow *w)
: m_window(w)
{
}
void VulkanRenderer::initResources()
{
qDebug("initResources");
m_devFuncs = m_window->vulkanInstance()->deviceFunctions(m_window->device());
}
void VulkanRenderer::initSwapChainResources()
{
qDebug("initSwapChainResources");
}
void VulkanRenderer::releaseSwapChainResources()
{
qDebug("releaseSwapChainResources");
}
void VulkanRenderer::releaseResources()
{
qDebug("releaseResources");
}
void VulkanRenderer::startNextFrame()
{
m_green += 0.005f;
if (m_green > 1.0f)
m_green = 0.0f;
VkClearColorValue clearColor = {{ 0.0f, m_green, 0.0f, 1.0f }};
VkClearDepthStencilValue clearDS = { 1.0f, 0 };
VkClearValue clearValues[2];
memset(clearValues, 0, sizeof(clearValues));
clearValues[0].color = clearColor;
clearValues[1].depthStencil = clearDS;
VkRenderPassBeginInfo rpBeginInfo;
memset(&rpBeginInfo, 0, sizeof(rpBeginInfo));
rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
rpBeginInfo.renderPass = m_window->defaultRenderPass();
rpBeginInfo.framebuffer = m_window->currentFramebuffer();
const QSize sz = m_window->swapChainImageSize();
rpBeginInfo.renderArea.extent.width = sz.width();
rpBeginInfo.renderArea.extent.height = sz.height();
rpBeginInfo.clearValueCount = 2;
rpBeginInfo.pClearValues = clearValues;
VkCommandBuffer cmdBuf = m_window->currentCommandBuffer();
m_devFuncs->vkCmdBeginRenderPass(cmdBuf, &rpBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
m_devFuncs->vkCmdEndRenderPass(cmdBuf);
m_window->frameReady();
m_window->requestUpdate();
}