2024-04-09 16:41:12 +02:00
|
|
|
#include "RenderPass.h"
|
2024-04-10 08:43:56 +02:00
|
|
|
#include "Enums.h"
|
2024-04-09 16:41:12 +02:00
|
|
|
#include "Graphics/RenderTarget.h"
|
|
|
|
|
#include "Metal/MTLRenderPass.hpp"
|
2024-04-10 08:43:56 +02:00
|
|
|
#include "Texture.h"
|
2024-04-09 16:41:12 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
using namespace Seele::Metal;
|
|
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout,
|
|
|
|
|
Array<Gfx::SubPassDependency> dependencies,
|
2024-08-26 21:49:09 +02:00
|
|
|
Gfx::PViewport viewport, const std::string& name)
|
2024-06-09 12:20:04 +02:00
|
|
|
: Gfx::RenderPass(layout, dependencies), graphics(graphics),
|
|
|
|
|
viewport(viewport) {
|
2024-04-18 13:33:35 +02:00
|
|
|
renderPass = MTL::RenderPassDescriptor::renderPassDescriptor();
|
2024-04-10 08:43:56 +02:00
|
|
|
renderPass->setRenderTargetArrayLength(1);
|
|
|
|
|
renderPass->setRenderTargetWidth(viewport->getWidth());
|
|
|
|
|
renderPass->setRenderTargetHeight(viewport->getHeight());
|
|
|
|
|
renderPass->setDefaultRasterSampleCount(viewport->getSamples());
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < layout.colorAttachments.size(); ++i) {
|
2024-06-09 12:20:04 +02:00
|
|
|
const auto &color = layout.colorAttachments[i];
|
|
|
|
|
MTL::RenderPassColorAttachmentDescriptor *desc =
|
|
|
|
|
renderPass->colorAttachments()->object(i);
|
|
|
|
|
desc->setClearColor(MTL::ClearColor(
|
|
|
|
|
color.clear.color.float32[0], color.clear.color.float32[1],
|
|
|
|
|
color.clear.color.float32[2], color.clear.color.float32[3]));
|
2024-04-10 08:43:56 +02:00
|
|
|
desc->setLoadAction(cast(color.getLoadOp()));
|
|
|
|
|
desc->setStoreAction(cast(color.getStoreOp()));
|
|
|
|
|
desc->setLevel(0);
|
|
|
|
|
if (!layout.resolveAttachments.empty()) {
|
2024-06-09 12:20:04 +02:00
|
|
|
const auto &resolve = layout.resolveAttachments[i];
|
2024-04-10 08:43:56 +02:00
|
|
|
desc->setResolveLevel(0);
|
|
|
|
|
desc->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
|
2024-06-09 12:20:04 +02:00
|
|
|
desc->setResolveTexture(
|
2024-08-26 21:49:09 +02:00
|
|
|
resolve.getTexture().cast<TextureBase>()->getImage());
|
2024-04-10 08:43:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (layout.depthAttachment.getTexture() != nullptr) {
|
2024-04-18 13:33:35 +02:00
|
|
|
auto depth = renderPass->depthAttachment();
|
2024-04-10 08:43:56 +02:00
|
|
|
depth->setClearDepth(layout.depthAttachment.clear.depthStencil.depth);
|
|
|
|
|
depth->setLoadAction(cast(layout.depthAttachment.getLoadOp()));
|
|
|
|
|
depth->setStoreAction(cast(layout.depthAttachment.getStoreOp()));
|
2024-04-18 13:33:35 +02:00
|
|
|
|
2024-04-10 08:43:56 +02:00
|
|
|
if (layout.depthResolveAttachment.getTexture() != nullptr) {
|
2024-06-09 12:20:04 +02:00
|
|
|
depth->setResolveTexture(layout.depthResolveAttachment.getTexture()
|
|
|
|
|
.cast<TextureBase>()
|
2024-08-26 21:49:09 +02:00
|
|
|
->getImage());
|
2024-04-10 08:43:56 +02:00
|
|
|
depth->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// TODO: stencil
|
2024-04-09 16:41:12 +02:00
|
|
|
}
|
2024-04-18 13:33:35 +02:00
|
|
|
RenderPass::~RenderPass() {}
|
|
|
|
|
|
|
|
|
|
void RenderPass::updateRenderPass() {
|
|
|
|
|
for (size_t i = 0; i < layout.colorAttachments.size(); ++i) {
|
2024-06-09 12:20:04 +02:00
|
|
|
const auto &color = layout.colorAttachments[i];
|
2024-04-18 13:33:35 +02:00
|
|
|
auto desc = renderPass->colorAttachments()->object(i);
|
2024-08-26 21:49:09 +02:00
|
|
|
desc->setTexture(color.getTexture().cast<TextureBase>()->getImage());
|
2024-04-18 13:33:35 +02:00
|
|
|
}
|
|
|
|
|
if (layout.depthAttachment.getTexture() != nullptr) {
|
|
|
|
|
auto depth = renderPass->depthAttachment();
|
2024-06-09 12:20:04 +02:00
|
|
|
depth->setTexture(
|
2024-08-26 21:49:09 +02:00
|
|
|
layout.depthAttachment.getTexture().cast<TextureBase>()->getImage());
|
2024-04-18 13:33:35 +02:00
|
|
|
}
|
2024-04-09 16:41:12 +02:00
|
|
|
}
|