Files
Seele/src/Engine/Graphics/RenderPass/MeshProcessor.cpp
T

63 lines
2.0 KiB
C++
Raw Normal View History

2020-06-02 11:46:18 +02:00
#include "MeshProcessor.h"
#include "Graphics/Graphics.h"
#include "Graphics/VertexShaderInput.h"
2020-06-02 11:46:18 +02:00
using namespace Seele;
2021-10-01 19:55:04 +02:00
MeshProcessor::MeshProcessor(Gfx::PGraphics graphics)
: graphics(graphics)
2020-06-02 11:46:18 +02:00
{
}
MeshProcessor::~MeshProcessor()
{
}
2020-06-08 01:44:47 +02:00
void MeshProcessor::buildMeshDrawCommand(
2020-06-02 11:46:18 +02:00
const MeshBatch& meshBatch,
2020-10-03 11:00:10 +02:00
// const PPrimitiveComponent primitiveComponent,
2020-06-08 01:44:47 +02:00
const Gfx::PRenderPass renderPass,
2020-10-03 11:00:10 +02:00
Gfx::PPipelineLayout pipelineLayout,
2020-06-08 01:44:47 +02:00
Gfx::PRenderCommand drawCommand,
2020-10-14 01:49:43 +02:00
const Array<Gfx::PDescriptorSet>& descriptors,
2020-06-02 11:46:18 +02:00
Gfx::PVertexShader vertexShader,
Gfx::PControlShader controlShader,
Gfx::PEvaluationShader evaluationShader,
Gfx::PGeometryShader geometryShader,
Gfx::PFragmentShader fragmentShader,
bool positionOnly)
{
const PVertexShaderInput vertexInput = meshBatch.vertexInput;
2020-06-02 11:46:18 +02:00
GraphicsPipelineCreateInfo pipelineInitializer;
pipelineInitializer.topology = meshBatch.topology;
Gfx::PVertexDeclaration vertexDecl = positionOnly ? vertexInput->getPositionDeclaration() : vertexInput->getDeclaration();
2020-06-02 11:46:18 +02:00
pipelineInitializer.vertexDeclaration = vertexDecl;
pipelineInitializer.vertexShader = vertexShader;
pipelineInitializer.controlShader = controlShader;
pipelineInitializer.evalShader = evaluationShader;
pipelineInitializer.geometryShader = geometryShader;
pipelineInitializer.fragmentShader = fragmentShader;
2020-06-08 01:44:47 +02:00
pipelineInitializer.renderPass = renderPass;
2020-10-03 11:00:10 +02:00
pipelineInitializer.pipelineLayout = pipelineLayout;
2020-06-02 11:46:18 +02:00
VertexInputStreamArray vertexStreams;
if(positionOnly)
{
vertexInput->getPositionOnlyStream(vertexStreams);
2020-06-02 11:46:18 +02:00
}
else
{
vertexInput->getStreams(vertexStreams);
2020-06-02 11:46:18 +02:00
}
2020-06-08 01:44:47 +02:00
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInitializer);
drawCommand->bindPipeline(pipeline);
2020-10-03 11:00:10 +02:00
drawCommand->bindVertexBuffer(vertexStreams);
drawCommand->bindDescriptor(descriptors);
2020-06-08 01:44:47 +02:00
for(auto element : meshBatch.elements)
2020-06-02 11:46:18 +02:00
{
2020-06-08 01:44:47 +02:00
drawCommand->bindIndexBuffer(element.indexBuffer);
drawCommand->draw(element);
}
2020-06-02 11:46:18 +02:00
}