Fixing slang compilation temporarily, renaming vertexfactory
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
#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)
|
||||
{
|
||||
const PMaterialAsset material = batch.material;
|
||||
const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
||||
|
||||
const PVertexShaderInput vertexInput = batch.vertexInput;
|
||||
|
||||
//TODO query tesselation
|
||||
|
||||
const Gfx::ShaderCollection* collection = material->getShaders(Gfx::RenderPassType::BasePass, vertexInput);
|
||||
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);
|
||||
for (auto &&primitive : scene->getPrimitives())
|
||||
{
|
||||
for (auto &&meshBatch : primitive->staticMeshes)
|
||||
{
|
||||
processor->addMeshBatch(meshBatch, primitive, renderPass);
|
||||
}
|
||||
}
|
||||
graphics->executeCommands(processor->getRenderCommands());
|
||||
graphics->endRenderPass();
|
||||
}
|
||||
|
||||
@@ -1,15 +1,39 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "MeshProcessor.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class BasePassMeshProcessor : public MeshProcessor
|
||||
{
|
||||
public:
|
||||
BasePassMeshProcessor(const PScene scene, Gfx::PGraphics graphics, uint8 translucentBasePass);
|
||||
virtual ~BasePassMeshProcessor();
|
||||
|
||||
virtual void addMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass renderPass,
|
||||
int32 staticMeshId = -1) override;
|
||||
Array<Gfx::PRenderCommand> getRenderCommands();
|
||||
void clearCommands();
|
||||
private:
|
||||
Array<Gfx::PRenderCommand> renderCommands;
|
||||
uint8 translucentBasePass;
|
||||
};
|
||||
DEFINE_REF(BasePassMeshProcessor);
|
||||
class BasePass
|
||||
{
|
||||
public:
|
||||
BasePass();
|
||||
BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport);
|
||||
~BasePass();
|
||||
|
||||
void render();
|
||||
private:
|
||||
|
||||
Gfx::PRenderPass renderPass;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
const PScene scene;
|
||||
UPBasePassMeshProcessor processor;
|
||||
Gfx::PGraphics graphics;
|
||||
};
|
||||
DEFINE_REF(BasePass);
|
||||
} // namespace Seele
|
||||
|
||||
@@ -5,6 +5,4 @@ target_sources(SeeleEngine
|
||||
DepthPrepass.h
|
||||
DepthPrepass.cpp
|
||||
MeshProcessor.h
|
||||
MeshProcessor.cpp
|
||||
VertexFactory.h
|
||||
VertexFactory.cpp)
|
||||
MeshProcessor.cpp)
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "MeshProcessor.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "VertexFactory.h"
|
||||
#include "Graphics/VertexShaderInput.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -28,11 +28,11 @@ void MeshProcessor::buildMeshDrawCommand(
|
||||
Gfx::PFragmentShader fragmentShader,
|
||||
bool positionOnly)
|
||||
{
|
||||
const PVertexFactory vertexFactory = meshBatch.vertexFactory;
|
||||
const PVertexShaderInput vertexInput = meshBatch.vertexInput;
|
||||
|
||||
GraphicsPipelineCreateInfo pipelineInitializer;
|
||||
pipelineInitializer.topology = meshBatch.topology;
|
||||
Gfx::PVertexDeclaration vertexDecl = positionOnly ? vertexFactory->getPositionDeclaration() : vertexFactory->getDeclaration();
|
||||
Gfx::PVertexDeclaration vertexDecl = positionOnly ? vertexInput->getPositionDeclaration() : vertexInput->getDeclaration();
|
||||
pipelineInitializer.vertexDeclaration = vertexDecl;
|
||||
pipelineInitializer.vertexShader = vertexShader;
|
||||
pipelineInitializer.controlShader = controlShader;
|
||||
@@ -44,11 +44,11 @@ void MeshProcessor::buildMeshDrawCommand(
|
||||
VertexInputStreamArray vertexStreams;
|
||||
if(positionOnly)
|
||||
{
|
||||
vertexFactory->getPositionOnlyStream(vertexStreams);
|
||||
vertexInput->getPositionOnlyStream(vertexStreams);
|
||||
}
|
||||
else
|
||||
{
|
||||
vertexFactory->getStreams(vertexStreams);
|
||||
vertexInput->getStreams(vertexStreams);
|
||||
}
|
||||
drawCommand->bindVertexBuffer(vertexStreams);
|
||||
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInitializer);
|
||||
|
||||
@@ -11,12 +11,13 @@ class MeshProcessor
|
||||
public:
|
||||
MeshProcessor(const PScene scene, Gfx::PGraphics graphics);
|
||||
virtual ~MeshProcessor();
|
||||
private:
|
||||
protected:
|
||||
PScene scene;
|
||||
Gfx::PGraphics graphics;
|
||||
virtual void addMeshBatch(
|
||||
const MeshBatch& meshBatch,
|
||||
const PPrimitiveComponent primitiveComponent,
|
||||
const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass renderPass,
|
||||
int32 staticMeshId = -1) = 0;
|
||||
void buildMeshDrawCommand(
|
||||
const MeshBatch& meshBatch,
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
#include "VertexFactory.h"
|
||||
#include "Graphics/Mesh.h"
|
||||
#include <memory>
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
List<PVertexFactory> VertexFactory::registeredVertexFactories;
|
||||
std::mutex VertexFactory::registeredVertexFactoryLock;
|
||||
|
||||
VertexFactory::VertexFactory()
|
||||
{
|
||||
std::scoped_lock lock(registeredVertexFactoryLock);
|
||||
registeredVertexFactories.add(this);
|
||||
}
|
||||
|
||||
VertexFactory::VertexFactory(MeshDescription description)
|
||||
: declaration(description.declaration)
|
||||
{
|
||||
auto declStreams = declaration->getVertexStreams();
|
||||
std::copy(declStreams.begin(), declStreams.end(), streams.begin());
|
||||
|
||||
uint32 positionStreamIndex = 0;
|
||||
positionDeclaration = new Gfx::VertexDeclaration();
|
||||
for (uint32 i = 0; i < declStreams.size(); i++)
|
||||
{
|
||||
if(description.layout[i] == VertexAttribute::POSITION)
|
||||
{
|
||||
positionStream[positionStreamIndex++] = declStreams[i];
|
||||
positionDeclaration->addVertexStream(declStreams[i]);
|
||||
}
|
||||
}
|
||||
|
||||
std::scoped_lock lock(registeredVertexFactoryLock);
|
||||
registeredVertexFactories.add(this);
|
||||
}
|
||||
|
||||
VertexFactory::~VertexFactory()
|
||||
{
|
||||
registeredVertexFactories.remove(registeredVertexFactories.find(this));
|
||||
}
|
||||
|
||||
void VertexFactory::getStreams(VertexInputStreamArray& outVertexStreams) const
|
||||
{
|
||||
for(uint32 i = 0; i < streams.size(); ++i)
|
||||
{
|
||||
const Gfx::VertexStream& stream = streams[i];
|
||||
if(stream.vertexBuffer == nullptr)
|
||||
{
|
||||
outVertexStreams.add(VertexInputStream(i, 0, nullptr));
|
||||
}
|
||||
else
|
||||
{
|
||||
outVertexStreams.add(VertexInputStream(i, stream.offset, stream.vertexBuffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VertexFactory::getPositionOnlyStream(VertexInputStreamArray& outVertexStreams) const
|
||||
{
|
||||
for (uint32 i = 0; i < positionStream.size(); ++i)
|
||||
{
|
||||
const Gfx::VertexStream& stream = positionStream[i];
|
||||
outVertexStreams.add(VertexInputStream(i, stream.offset, stream.vertexBuffer));
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
struct VertexInputStream
|
||||
{
|
||||
uint32 streamIndex : 4;
|
||||
uint32 offset : 28;
|
||||
Gfx::PVertexBuffer vertexBuffer;
|
||||
|
||||
VertexInputStream()
|
||||
: streamIndex(0), offset(0), vertexBuffer(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
VertexInputStream(uint32 streamIndex, uint32 offset, Gfx::PVertexBuffer vertexBuffer)
|
||||
: streamIndex(streamIndex), offset(offset), vertexBuffer(vertexBuffer)
|
||||
{
|
||||
assert(this->streamIndex == streamIndex && this->offset == offset);
|
||||
}
|
||||
|
||||
inline bool operator==(const VertexInputStream &rhs) const
|
||||
{
|
||||
if (streamIndex != rhs.streamIndex || offset != rhs.offset || vertexBuffer != rhs.vertexBuffer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
inline bool operator!=(const VertexInputStream &rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
/*struct VertexStreamComponent
|
||||
{
|
||||
const Gfx::PVertexBuffer vertexBuffer = nullptr;
|
||||
|
||||
uint32 streamOffset = 0;
|
||||
|
||||
uint8 offset = 0;
|
||||
|
||||
uint8 stride;
|
||||
|
||||
Gfx::SeFormat type;
|
||||
|
||||
VertexStreamComponent()
|
||||
{
|
||||
}
|
||||
|
||||
VertexStreamComponent(const Gfx::PVertexBuffer vertexBuffer, uint32 offset, uint32 stride, Gfx::SeFormat type)
|
||||
: vertexBuffer(vertexBuffer)
|
||||
, streamOffset(0)
|
||||
, offset(offset)
|
||||
, stride(stride)
|
||||
, type(type)
|
||||
{
|
||||
}
|
||||
|
||||
VertexStreamComponent(const Gfx::PVertexBuffer vertexBuffer, uint32 streamOffset, uint32 offset, uint32 stride, Gfx::SeFormat type)
|
||||
: vertexBuffer(vertexBuffer)
|
||||
, streamOffset(streamOffset)
|
||||
, offset(offset)
|
||||
, stride(stride)
|
||||
, type(type)
|
||||
{
|
||||
}
|
||||
};*/
|
||||
|
||||
typedef Array<VertexInputStream> VertexInputStreamArray;
|
||||
struct MeshDescription;
|
||||
DECLARE_REF(VertexFactory);
|
||||
class VertexFactory
|
||||
{
|
||||
public:
|
||||
VertexFactory();
|
||||
VertexFactory(MeshDescription description);
|
||||
~VertexFactory();
|
||||
void getStreams(VertexInputStreamArray& outVertexStreams) const;
|
||||
void getPositionOnlyStream(VertexInputStreamArray& outVertexStreams) const;
|
||||
virtual bool supportsTesselation() { return false; }
|
||||
Gfx::PVertexDeclaration getDeclaration() const {return declaration;}
|
||||
Gfx::PVertexDeclaration getPositionDeclaration() const {return positionDeclaration;}
|
||||
private:
|
||||
static List<PVertexFactory> registeredVertexFactories;
|
||||
static std::mutex registeredVertexFactoryLock;
|
||||
StaticArray<Gfx::VertexStream, 16> streams;
|
||||
StaticArray<Gfx::VertexStream, 16> positionStream;
|
||||
Gfx::PVertexDeclaration declaration;
|
||||
Gfx::PVertexDeclaration positionDeclaration;
|
||||
};
|
||||
DEFINE_REF(VertexFactory);
|
||||
} // namespace Seele
|
||||
Reference in New Issue
Block a user