Improving Material shader code generation

This commit is contained in:
Dynamitos
2020-09-19 14:36:50 +02:00
parent 6814587b54
commit facbfed79c
72 changed files with 1049 additions and 329 deletions
+44 -29
View File
@@ -5,49 +5,64 @@
using namespace Seele;
List<PVertexShaderInput> VertexShaderInput::registeredInputs;
std::mutex VertexShaderInput::registeredInputsLock;
List<VertexInputType*> VertexInputType::globalTypeList;
List<VertexInputType*> VertexInputType::getTypeList()
{
return globalTypeList;
}
VertexInputType* VertexInputType::getVertexInputByName(const std::string& name)
{
for(auto type : globalTypeList)
{
if(name.compare(type->getName()) == 0)
{
return type;
}
}
return nullptr;
}
VertexInputType::VertexInputType(const char* name,
const char* shaderFilename)
: name(name)
, shaderFilename(shaderFilename)
{
globalTypeList.add(this);
}
VertexInputType::~VertexInputType()
{
globalTypeList.remove(globalTypeList.find(this));
}
const char* VertexInputType::getName()
{
return name;
}
const char* VertexInputType::getShaderFilename()
{
return shaderFilename;
}
VertexShaderInput::VertexShaderInput(std::string name)
: name(name)
{
std::scoped_lock lock(registeredInputsLock);
registeredInputs.add(this);
}
VertexShaderInput::VertexShaderInput(MeshDescription description, std::string name)
: declaration(description.declaration)
, layout(description.layout)
, name(name)
{
auto declStreams = declaration->getVertexStreams();
std::copy(declStreams.begin(), declStreams.end(), streams.begin());
uint32 positionStreamIndex = 0;
declaration = new Gfx::VertexDeclaration();
positionDeclaration = new Gfx::VertexDeclaration();
for (uint32 i = 0; i < declStreams.size(); i++)
{
if(description.layout[i] == Gfx::VertexAttribute::POSITION)
{
positionStreams[positionStreamIndex++] = declStreams[i];
positionDeclaration->addVertexStream(declStreams[i]);
}
}
std::scoped_lock lock(registeredInputsLock);
registeredInputs.add(this);
}
VertexShaderInput::~VertexShaderInput()
{
registeredInputs.remove(registeredInputs.find(this));
}
void VertexShaderInput::getStreams(VertexInputStreamArray& outVertexStreams) const
{
for(uint32 i = 0; i < streams.size(); ++i)
{
const Gfx::VertexStream& stream = streams[i];
const VertexInputStream& stream = streams[i];
if(stream.vertexBuffer == nullptr)
{
outVertexStreams.add(VertexInputStream(i, 0, nullptr));
@@ -63,7 +78,7 @@ void VertexShaderInput::getPositionOnlyStream(VertexInputStreamArray& outVertexS
{
for (uint32 i = 0; i < positionStreams.size(); ++i)
{
const Gfx::VertexStream& stream = positionStreams[i];
const VertexInputStream& stream = positionStreams[i];
outVertexStreams.add(VertexInputStream(i, stream.offset, stream.vertexBuffer));
}
}