2020-08-06 00:54:43 +02:00
|
|
|
#include "BasePass.h"
|
|
|
|
|
#include "Graphics/Graphics.h"
|
|
|
|
|
#include "Graphics/Window.h"
|
|
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
|
|
|
|
BasePassMeshProcessor::BasePassMeshProcessor(const PScene scene, Gfx::PGraphics graphics, uint8 translucentBasePass)
|
|
|
|
|
: MeshProcessor(scene, graphics)
|
|
|
|
|
, translucentBasePass(translucentBasePass)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BasePassMeshProcessor::~BasePassMeshProcessor()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasePassMeshProcessor::addMeshBatch(
|
|
|
|
|
const MeshBatch& batch,
|
|
|
|
|
const PPrimitiveComponent primitiveComponent,
|
|
|
|
|
const Gfx::PRenderPass renderPass,
|
|
|
|
|
int32 staticMeshId)
|
|
|
|
|
{
|
2020-08-11 21:23:20 +02:00
|
|
|
const PMaterial material = batch.material;
|
2020-08-06 00:54:43 +02:00
|
|
|
const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
|
|
|
|
|
|
|
|
|
const PVertexShaderInput vertexInput = batch.vertexInput;
|
|
|
|
|
|
|
|
|
|
//TODO query tesselation
|
|
|
|
|
|
2020-09-19 14:36:50 +02:00
|
|
|
const Gfx::ShaderCollection* collection = material->getShaders(Gfx::RenderPassType::BasePass, vertexInput->getType());
|
|
|
|
|
assert(collection != nullptr);
|
2020-08-06 00:54:43 +02:00
|
|
|
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand();
|
|
|
|
|
buildMeshDrawCommand(batch,
|
|
|
|
|
primitiveComponent,
|
|
|
|
|
renderPass,
|
|
|
|
|
renderCommand,
|
|
|
|
|
material,
|
|
|
|
|
collection->vertexShader,
|
|
|
|
|
collection->controlShader,
|
|
|
|
|
collection->evalutionShader,
|
|
|
|
|
collection->geometryShader,
|
|
|
|
|
collection->fragmentShader,
|
|
|
|
|
false);
|
|
|
|
|
renderCommands.add(renderCommand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Array<Gfx::PRenderCommand> BasePassMeshProcessor::getRenderCommands()
|
|
|
|
|
{
|
|
|
|
|
return renderCommands;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasePassMeshProcessor::clearCommands()
|
|
|
|
|
{
|
|
|
|
|
renderCommands.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport)
|
|
|
|
|
: processor(new BasePassMeshProcessor(scene, graphics, false))
|
|
|
|
|
, scene(scene)
|
|
|
|
|
, graphics(graphics)
|
|
|
|
|
{
|
|
|
|
|
Gfx::PRenderTargetAttachment colorAttachment = new Gfx::SwapchainAttachment(viewport->getOwner());
|
|
|
|
|
TextureCreateInfo depthBufferInfo;
|
|
|
|
|
depthBufferInfo.width = viewport->getSizeX();
|
|
|
|
|
depthBufferInfo.height = viewport->getSizeY();
|
|
|
|
|
depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT;
|
|
|
|
|
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
|
|
|
|
depthBuffer = graphics->createTexture2D(depthBufferInfo);
|
|
|
|
|
Gfx::PRenderTargetAttachment depthAttachment =
|
|
|
|
|
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
|
|
|
|
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
|
|
|
|
|
renderPass = graphics->createRenderPass(layout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BasePass::~BasePass()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasePass::render()
|
|
|
|
|
{
|
|
|
|
|
processor->clearCommands();
|
|
|
|
|
graphics->beginRenderPass(renderPass);
|
2020-09-19 14:36:50 +02:00
|
|
|
for (auto &&primitive : scene->getStaticMeshes())
|
2020-08-06 00:54:43 +02:00
|
|
|
{
|
2020-09-19 14:36:50 +02:00
|
|
|
processor->addMeshBatch(primitive, nullptr, renderPass);
|
2020-08-06 00:54:43 +02:00
|
|
|
}
|
|
|
|
|
graphics->executeCommands(processor->getRenderCommands());
|
|
|
|
|
graphics->endRenderPass();
|
|
|
|
|
}
|