Trying to fix invalid descriptorlayout

This commit is contained in:
Dynamitos
2020-10-03 11:00:10 +02:00
parent 79388bf41a
commit ceee96b462
69 changed files with 1087 additions and 393 deletions
+15 -6
View File
@@ -24,7 +24,6 @@ void AssetRegistry::importFile(const std::string &filePath)
{
std::filesystem::path fsPath = std::filesystem::path(filePath);
std::string extension = fsPath.extension().string();
std::cout << extension << std::endl;
if (extension.compare(".fbx") == 0
|| extension.compare(".obj") == 0)
{
@@ -46,6 +45,16 @@ PMeshAsset AssetRegistry::findMesh(const std::string &filePath)
return get().meshes[filePath];
}
PTextureAsset AssetRegistry::findTexture(const std::string &filePath)
{
PTextureAsset result = get().textures[filePath];
if(result == nullptr)
{
return get().textureLoader->getPlaceholderTexture();
}
return result;
}
PMaterialAsset AssetRegistry::findMaterial(const std::string &filePath)
{
return get().materials[filePath];
@@ -61,11 +70,6 @@ std::ifstream AssetRegistry::createReadStream(const std::string& relativePath, s
return get().internalCreateReadStream(relativePath, openmode);
}
PTextureAsset AssetRegistry::findTexture(const std::string &filePath)
{
return get().textures[filePath];
}
AssetRegistry &AssetRegistry::get()
{
static AssetRegistry instance;
@@ -122,6 +126,11 @@ void AssetRegistry::registerMesh(PMeshAsset mesh)
}
}
void AssetRegistry::registerMaterial(PMaterialAsset material)
{
materials[material->getFileName()] = material;
}
std::ofstream AssetRegistry::internalCreateWriteStream(const std::string& relativePath, std::ios_base::openmode openmode)
{
return std::ofstream(rootFolder.generic_string().append(relativePath), openmode);
+7
View File
@@ -1,6 +1,7 @@
#include "MaterialLoader.h"
#include "Material/Material.h"
#include "Graphics/Graphics.h"
#include "AssetRegistry.h"
using namespace Seele;
@@ -21,7 +22,13 @@ PMaterial MaterialLoader::queueAsset(const std::filesystem::path& filePath)
PMaterial result = new Material(filePath);
result->compile();
graphics->getShaderCompiler()->registerMaterial(result);
AssetRegistry::get().registerMaterial(result);
// TODO: There is actually no real reason to import a standalone material,
// maybe in the future there could be a substance loader or something
return result;
}
PMaterial MaterialLoader::getPlaceHolderMaterial()
{
return placeholderMaterial;
}
+1
View File
@@ -15,6 +15,7 @@ public:
MaterialLoader(Gfx::PGraphics graphic);
~MaterialLoader();
PMaterial queueAsset(const std::filesystem::path& filePath);
PMaterial getPlaceHolderMaterial();
private:
Gfx::PGraphics graphics;
List<std::future<void>> futures;
+24 -23
View File
@@ -33,7 +33,7 @@ void MeshLoader::importAsset(const std::filesystem::path &path)
import(path);
}
void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials, Gfx::PGraphics graphics)
void MeshLoader::loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials, Gfx::PGraphics graphics)
{
using json = nlohmann::json;
for(uint32 i = 0; i < scene->mNumMaterials; ++i)
@@ -42,7 +42,6 @@ void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials,
json matCode;
matCode["name"] = material->GetName().C_Str();
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
std::vector<std::string> code;
aiString texPath;
//TODO make samplers based on used textures
matCode["params"]["texSampler"] =
@@ -57,7 +56,7 @@ void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials,
{"type", "Texture2D"},
{"default", texPath.C_Str()}
};
code.push_back("result.baseColor = diffuseTexture.Sample(textureSampler, geometry.texCoord).xyz;\n");
matCode["code"]["baseColor"] = "return diffuseTexture.Sample(textureSampler, geometry.texCoord).xyz;";
}
if(material->GetTexture(aiTextureType_SPECULAR, 0, &texPath) == AI_SUCCESS)
{
@@ -67,7 +66,7 @@ void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials,
{"type", "Texture2D"},
{"default", texPath.C_Str()}
};
code.push_back("result.specular = specularTexture.Sample(textureSampler, geometry.texCoord).xyz;\n");
matCode["code"]["specular"] = "return specularTexture.Sample(textureSampler, geometry.texCoord).xyz;";
}
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
{
@@ -77,21 +76,20 @@ void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials,
{"type", "Texture2D"},
{"default", texPath.C_Str()}
};
code.push_back("float3 bumpMapNormal = normalTexture.Sample(textureSampler, geometry.texCoord).xyz;\n");
code.push_back("bumpMapNormal = 2.0 * bumpMapNormal - float3(1.0f, 1.0f, 1.0f);\n");
code.push_back("result.normal = geometry.transformLocalToWorld(bumpMapNormal);\n");
matCode["code"]["normal"] = "return normalTexture.Sample(textureSampler, geometry.texCoord).xyz;";
}
code.push_back("return result;\n");
matCode["code"] = code;
std::string outMatFilename = matCode["name"].get<std::string>().append(".asset");
std::ofstream outMatFile = AssetRegistry::createWriteStream(outMatFilename);
outMatFile << std::setw(4) << matCode;
outMatFile.flush();
outMatFile.close();
//TODO: let the material loader handle this instead
std::cout << matCode["name"] << std::endl;
AssetRegistry::importFile(outMatFilename);
PMaterialAsset asset = AssetRegistry::findMaterial(outMatFilename);
//std::cout << matCode << std::endl;
PMaterial result = new Material(outMatFilename);
result->compile();
graphics->getShaderCompiler()->registerMaterial(result);
AssetRegistry::get().registerMaterial(result);
PMaterialAsset asset = AssetRegistry::findMaterial(result->getFileName());
globalMaterials[i] = asset;
}
}
@@ -148,35 +146,38 @@ VertexStreamComponent createVertexStream(uint32 size, aiVector2D* sourceData, Gf
Gfx::PVertexBuffer vertexBuffer = graphics->createVertexBuffer(vbInfo);
return VertexStreamComponent(vertexBuffer, 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32_SFLOAT);
}
void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, Array<PMaterialAsset> materials, Gfx::PGraphics graphics)
void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, Array<PMaterialAsset> materials, Gfx::PGraphics graphics)
{
for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex)
{
aiMesh *mesh = scene->mMeshes[meshIndex];
PStaticMeshVertexInput vertexShaderInput = new StaticMeshVertexInput(std::string(mesh->mName.C_Str()));
VertexStreamComponent positionStream = createVertexStream(mesh->mNumVertices, mesh->mVertices, graphics);
vertexShaderInput->setPositionStream(positionStream);
StaticMeshDataType data;
data.positionStream = createVertexStream(mesh->mNumVertices, mesh->mVertices, graphics);
for(uint32 i = 0; i < MAX_TEXCOORDS; ++i)
{
if(mesh->HasTextureCoords(i))
{
VertexStreamComponent texCoordStream = createVertexStream(mesh->mNumVertices, mesh->mTextureCoords[i], graphics);
vertexShaderInput->setTexCoordStream(i, texCoordStream);
data.textureCoordinates.add(createVertexStream(mesh->mNumVertices, mesh->mTextureCoords[i], graphics));
}
}
if(mesh->HasNormals())
{
VertexStreamComponent normalStream = createVertexStream(mesh->mNumVertices, mesh->mNormals, graphics);
vertexShaderInput->setTangentXStream(normalStream);
data.tangentBasisComponents[0] = createVertexStream(mesh->mNumVertices, mesh->mNormals, graphics);
}
if(mesh->HasTangentsAndBitangents())
{
//TODO: use bitangent to calculate sign for 4th coordinate of tangentstream
VertexStreamComponent tangentStream = createVertexStream(mesh->mNumVertices, mesh->mTangents, graphics);
vertexShaderInput->setTangentZStream(tangentStream);
data.tangentBasisComponents[1] = createVertexStream(mesh->mNumVertices, mesh->mTangents, graphics);
}
if(mesh->HasVertexColors(0))
{
//data.colorComponent = createVertexStream(mesh->mNumVertices, mesh->mColors[0], graphics);
}
vertexShaderInput->setData(data);
vertexShaderInput->init(graphics);
Array<uint32> indices(mesh->mNumFaces * 3);
for (uint32 faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
@@ -197,7 +198,7 @@ void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, Array<PM
globalMeshes[meshIndex]->referencedMaterial = materials[mesh->mMaterialIndex];
}
}
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels)
void MeshLoader::convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels)
{
for(uint32 i = 0; i < numPixels; ++i)
{
@@ -207,7 +208,7 @@ void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels)
dst[i * 4 + 3] = src[i].a;
}
}
void loadTextures(const aiScene* scene, Gfx::PGraphics graphics, const std::filesystem::path& meshPath)
void MeshLoader::loadTextures(const aiScene* scene, Gfx::PGraphics graphics, const std::filesystem::path& meshPath)
{
for (uint32 i = 0; i < scene->mNumTextures; ++i)
{
+10 -1
View File
@@ -5,9 +5,13 @@
#include <future>
#include <filesystem>
struct aiScene;
struct aiTexel;
namespace Seele
{
DECLARE_REF(MeshAsset)
DECLARE_REF(Mesh);
DECLARE_REF(MeshAsset);
DECLARE_REF(MaterialAsset);
DECLARE_NAME_REF(Gfx, Graphics);
class MeshLoader
{
@@ -16,6 +20,11 @@ public:
~MeshLoader();
void importAsset(const std::filesystem::path& filePath);
private:
void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials, Gfx::PGraphics graphics);
void loadTextures(const aiScene* scene, Gfx::PGraphics graphics, const std::filesystem::path& meshPath);
void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, Array<PMaterialAsset> materials, Gfx::PGraphics graphics);
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
void import(const std::filesystem::path& path);
List<std::future<void>> futures;
Gfx::PGraphics graphics;
+10 -2
View File
@@ -12,7 +12,10 @@ using namespace Seele;
TextureLoader::TextureLoader(Gfx::PGraphics graphics)
: graphics(graphics)
{
placeholderAsset = new TextureAsset();
placeholderTexture = import("./textures/placeholder.png");
placeholderAsset->setTexture(placeholderTexture);
placeholderAsset->setStatus(Asset::Status::Ready);
}
TextureLoader::~TextureLoader()
@@ -26,11 +29,16 @@ void TextureLoader::importAsset(const std::filesystem::path& filePath)
asset->setStatus(Asset::Status::Loading);
asset->setTexture(placeholderTexture);
AssetRegistry::get().textures[filePath.string()] = asset;
futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
//futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
Gfx::PTexture2D texture = import(filePath);
asset->setTexture(texture);
asset->setStatus(Asset::Status::Ready);
}));
//}));
}
PTextureAsset TextureLoader::getPlaceholderTexture()
{
return placeholderAsset;
}
Gfx::PTexture2D TextureLoader::import(const std::filesystem::path& path)
+2
View File
@@ -16,11 +16,13 @@ public:
TextureLoader(Gfx::PGraphics graphic);
~TextureLoader();
void importAsset(const std::filesystem::path& filePath);
PTextureAsset getPlaceholderTexture();
private:
Gfx::PTexture2D import(const std::filesystem::path& path);
Gfx::PGraphics graphics;
List<std::future<void>> futures;
Gfx::PTexture2D placeholderTexture;
PTextureAsset placeholderAsset;
};
DEFINE_REF(TextureLoader);
} // namespace Seele