mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
vulkan: partially implement clear
Only works for color attachments for now.
This commit is contained in:
@@ -82,6 +82,48 @@ namespace love {
|
|||||||
return new Buffer(this, settings, format, data, size, arraylength);
|
return new Buffer(this, settings, format, data, size, arraylength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: clear stencil and depth missing.
|
||||||
|
void Graphics::clear(OptionalColorD color, OptionalInt stencil, OptionalDouble depth) {
|
||||||
|
VkClearAttachment attachment{};
|
||||||
|
|
||||||
|
if (color.hasValue) {
|
||||||
|
attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
attachment.clearValue.color.float32[0] = static_cast<float>(color.value.r);
|
||||||
|
attachment.clearValue.color.float32[1] = static_cast<float>(color.value.g);
|
||||||
|
attachment.clearValue.color.float32[2] = static_cast<float>(color.value.b);
|
||||||
|
attachment.clearValue.color.float32[3] = static_cast<float>(color.value.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkClearRect rect{};
|
||||||
|
rect.layerCount = 1;
|
||||||
|
rect.rect.extent.width = currentViewportWidth;
|
||||||
|
rect.rect.extent.height = currentViewportHeight;
|
||||||
|
|
||||||
|
vkCmdClearAttachments(commandBuffers[imageIndex], 1, &attachment, 1, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graphics::clear(const std::vector<OptionalColorD>& colors, OptionalInt stencil, OptionalDouble depth) {
|
||||||
|
std::vector<VkClearAttachment> attachments;
|
||||||
|
for (const auto& color : colors) {
|
||||||
|
VkClearAttachment attachment{};
|
||||||
|
if (color.hasValue) {
|
||||||
|
attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
attachment.clearValue.color.float32[0] = static_cast<float>(color.value.r);
|
||||||
|
attachment.clearValue.color.float32[1] = static_cast<float>(color.value.g);
|
||||||
|
attachment.clearValue.color.float32[2] = static_cast<float>(color.value.b);
|
||||||
|
attachment.clearValue.color.float32[3] = static_cast<float>(color.value.a);
|
||||||
|
}
|
||||||
|
attachments.push_back(attachment);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkClearRect rect{};
|
||||||
|
rect.layerCount = 1;
|
||||||
|
rect.rect.extent.width = currentViewportWidth;
|
||||||
|
rect.rect.extent.height = currentViewportHeight;
|
||||||
|
|
||||||
|
vkCmdClearAttachments(commandBuffers[imageIndex], static_cast<uint32_t>(attachments.size()), attachments.data(), 1, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
void Graphics::present(void* screenshotCallbackdata) {
|
void Graphics::present(void* screenshotCallbackdata) {
|
||||||
flushBatchedDraws();
|
flushBatchedDraws();
|
||||||
|
|
||||||
@@ -1235,22 +1277,20 @@ namespace love {
|
|||||||
VkRenderingAttachmentInfo colorAttachmentInfo{};
|
VkRenderingAttachmentInfo colorAttachmentInfo{};
|
||||||
colorAttachmentInfo.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
colorAttachmentInfo.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
||||||
colorAttachmentInfo.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
colorAttachmentInfo.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
colorAttachmentInfo.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
if (texture) {
|
if (texture) {
|
||||||
colorAttachmentInfo.imageView = texture->getImageView();
|
colorAttachmentInfo.imageView = texture->getImageView();
|
||||||
colorAttachmentInfo.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // fixme: we want to clear a canvas sometimes.
|
|
||||||
auto vulkanFormat = Vulkan::getTextureFormat(texture->getPixelFormat());
|
auto vulkanFormat = Vulkan::getTextureFormat(texture->getPixelFormat());
|
||||||
currentFramebufferOutputFormat = vulkanFormat.internalFormat;
|
currentFramebufferOutputFormat = vulkanFormat.internalFormat;
|
||||||
|
|
||||||
renderTargetTexture = texture;
|
renderTargetTexture = texture;
|
||||||
} else {
|
} else {
|
||||||
colorAttachmentInfo.imageView = swapChainImageViews[imageIndex];
|
colorAttachmentInfo.imageView = swapChainImageViews[imageIndex];
|
||||||
colorAttachmentInfo.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
||||||
currentFramebufferOutputFormat = swapChainImageFormat;
|
currentFramebufferOutputFormat = swapChainImageFormat;
|
||||||
|
|
||||||
renderTargetTexture = nullptr;
|
renderTargetTexture = nullptr;
|
||||||
}
|
}
|
||||||
colorAttachmentInfo.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
colorAttachmentInfo.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
colorAttachmentInfo.clearValue = clearColor;
|
|
||||||
|
|
||||||
VkRenderingInfo renderingInfo{};
|
VkRenderingInfo renderingInfo{};
|
||||||
renderingInfo.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
renderingInfo.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ namespace love {
|
|||||||
// implementation for virtual functions
|
// implementation for virtual functions
|
||||||
love::graphics::Texture* newTexture(const love::graphics::Texture::Settings& settings, const love::graphics::Texture::Slices* data = nullptr) override;
|
love::graphics::Texture* newTexture(const love::graphics::Texture::Settings& settings, const love::graphics::Texture::Slices* data = nullptr) override;
|
||||||
love::graphics::Buffer* newBuffer(const love::graphics::Buffer::Settings& settings, const std::vector<love::graphics::Buffer::DataDeclaration>& format, const void* data, size_t size, size_t arraylength) override;
|
love::graphics::Buffer* newBuffer(const love::graphics::Buffer::Settings& settings, const std::vector<love::graphics::Buffer::DataDeclaration>& format, const void* data, size_t size, size_t arraylength) override;
|
||||||
void clear(OptionalColorD color, OptionalInt stencil, OptionalDouble depth) override { }
|
void clear(OptionalColorD color, OptionalInt stencil, OptionalDouble depth) override;
|
||||||
void clear(const std::vector<OptionalColorD>& colors, OptionalInt stencil, OptionalDouble depth) override { }
|
void clear(const std::vector<OptionalColorD>& colors, OptionalInt stencil, OptionalDouble depth) override;
|
||||||
Matrix4 computeDeviceProjection(const Matrix4& projection, bool rendertotexture) const override;
|
Matrix4 computeDeviceProjection(const Matrix4& projection, bool rendertotexture) const override;
|
||||||
void discard(const std::vector<bool>& colorbuffers, bool depthstencil) override { }
|
void discard(const std::vector<bool>& colorbuffers, bool depthstencil) override { }
|
||||||
void present(void* screenshotCallbackdata) override;
|
void present(void* screenshotCallbackdata) override;
|
||||||
@@ -198,7 +198,6 @@ namespace love {
|
|||||||
std::vector<VkPipelineLayout> graphicsPipelineLayouts;
|
std::vector<VkPipelineLayout> graphicsPipelineLayouts;
|
||||||
VkCommandPool commandPool = VK_NULL_HANDLE;
|
VkCommandPool commandPool = VK_NULL_HANDLE;
|
||||||
std::vector<VkCommandBuffer> commandBuffers;
|
std::vector<VkCommandBuffer> commandBuffers;
|
||||||
VkClearValue clearColor = { {{0.0f, 0.0f, 0.0f, 1.0f}} };
|
|
||||||
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
|
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
|
||||||
std::vector<VkSemaphore> imageAvailableSemaphores;
|
std::vector<VkSemaphore> imageAvailableSemaphores;
|
||||||
std::vector<VkSemaphore> renderFinishedSemaphores;
|
std::vector<VkSemaphore> renderFinishedSemaphores;
|
||||||
|
|||||||
@@ -162,7 +162,8 @@ namespace love {
|
|||||||
bool forwardCompat = true;
|
bool forwardCompat = true;
|
||||||
|
|
||||||
if (!tshader->parse(&defaultTBuiltInResource, defaultVersio, defaultProfile, forceDefault, forwardCompat, EShMsgSuppressWarnings)) {
|
if (!tshader->parse(&defaultTBuiltInResource, defaultVersio, defaultProfile, forceDefault, forwardCompat, EShMsgSuppressWarnings)) {
|
||||||
std::cout << "error while parsing shader" << std::endl;
|
const char* msg1 = tshader->getInfoLog();
|
||||||
|
const char* msg2 = tshader->getInfoDebugLog();
|
||||||
|
|
||||||
throw love::Exception("error while parsing shader");
|
throw love::Exception("error while parsing shader");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user