Starting implementation of UI framework
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include "MeshLoader.h"
|
||||
#include "Material/Material.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/WindowManager.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace Seele;
|
||||
@@ -133,10 +133,14 @@ void AssetRegistry::registerMaterial(PMaterialAsset material)
|
||||
|
||||
std::ofstream AssetRegistry::internalCreateWriteStream(const std::string& relativePath, std::ios_base::openmode openmode)
|
||||
{
|
||||
return std::ofstream(rootFolder.generic_string().append(relativePath), openmode);
|
||||
auto fullPath = rootFolder;
|
||||
fullPath.append(relativePath);
|
||||
return std::ofstream(fullPath.string(), openmode);
|
||||
}
|
||||
|
||||
std::ifstream AssetRegistry::internalCreateReadStream(const std::string& relativePath, std::ios_base::openmode openmode)
|
||||
{
|
||||
return std::ifstream(rootFolder.generic_string().append(relativePath), openmode);
|
||||
auto fullPath = rootFolder;
|
||||
fullPath.append(relativePath);
|
||||
return std::ifstream(fullPath.string(), openmode);
|
||||
}
|
||||
|
||||
@@ -44,39 +44,39 @@ void MeshLoader::loadMaterials(const aiScene* scene, Array<PMaterialAsset>& glob
|
||||
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
|
||||
aiString texPath;
|
||||
//TODO make samplers based on used textures
|
||||
matCode["params"]["texSampler"] =
|
||||
matCode["params"]["textureSampler"] =
|
||||
{
|
||||
{"type", "SamplerState"}
|
||||
};
|
||||
if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS)
|
||||
{
|
||||
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
|
||||
std::string texFilename = std::filesystem::path(texPath.C_Str()).replace_extension("asset").stem().string();
|
||||
matCode["params"]["diffuseTexture"] =
|
||||
{
|
||||
{"type", "Texture2D"},
|
||||
{"default", texPath.C_Str()}
|
||||
{"default", texFilename}
|
||||
};
|
||||
matCode["code"]["baseColor"] = "return diffuseTexture.Sample(textureSampler, geometry.texCoord).xyz;";
|
||||
matCode["code"]["baseColor"] = "return diffuseTexture.Sample(textureSampler, input.texCoords[0]).xyz;";
|
||||
}
|
||||
if(material->GetTexture(aiTextureType_SPECULAR, 0, &texPath) == AI_SUCCESS)
|
||||
{
|
||||
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
|
||||
std::string texFilename = std::filesystem::path(texPath.C_Str()).replace_extension("asset").stem().string();
|
||||
matCode["params"]["specularTexture"] =
|
||||
{
|
||||
{"type", "Texture2D"},
|
||||
{"default", texPath.C_Str()}
|
||||
{"default", texFilename}
|
||||
};
|
||||
matCode["code"]["specular"] = "return specularTexture.Sample(textureSampler, geometry.texCoord).xyz;";
|
||||
matCode["code"]["specular"] = "return specularTexture.Sample(textureSampler, input.texCoords[0]).x;";
|
||||
}
|
||||
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
|
||||
{
|
||||
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
|
||||
std::string texFilename = std::filesystem::path(texPath.C_Str()).replace_extension("asset").stem().string();
|
||||
matCode["params"]["normalTexture"] =
|
||||
{
|
||||
{"type", "Texture2D"},
|
||||
{"default", texPath.C_Str()}
|
||||
{"default", texFilename}
|
||||
};
|
||||
matCode["code"]["normal"] = "return normalTexture.Sample(textureSampler, geometry.texCoord).xyz;";
|
||||
matCode["code"]["normal"] = "return normalTexture.Sample(textureSampler, input.texCoords[0]).xyz;";
|
||||
}
|
||||
std::string outMatFilename = matCode["name"].get<std::string>().append(".asset");
|
||||
std::ofstream outMatFile = AssetRegistry::createWriteStream(outMatFilename);
|
||||
@@ -198,13 +198,14 @@ void MeshLoader::convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numP
|
||||
dst[i * 4 + 3] = src[i].a;
|
||||
}
|
||||
}
|
||||
void MeshLoader::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& meshDirectory)
|
||||
{
|
||||
for (uint32 i = 0; i < scene->mNumTextures; ++i)
|
||||
{
|
||||
aiTexture* tex = scene->mTextures[i];
|
||||
auto texPath = std::filesystem::path(tex->mFilename.C_Str());
|
||||
auto texPngPath = meshPath.parent_path().append(texPath.filename().string());
|
||||
auto texPngPath = meshDirectory;
|
||||
texPngPath.append(texPath.filename().string());
|
||||
if(tex->mHeight == 0)
|
||||
{
|
||||
// already compressed, just dump it to the disk
|
||||
@@ -237,7 +238,7 @@ void MeshLoader::import(const std::filesystem::path &path)
|
||||
const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
|
||||
|
||||
Array<PMaterialAsset> globalMaterials(scene->mNumMaterials);
|
||||
loadTextures(scene, graphics, path);
|
||||
loadTextures(scene, graphics, path.parent_path());
|
||||
loadMaterials(scene, globalMaterials, graphics);
|
||||
|
||||
Array<PMesh> globalMeshes(scene->mNumMeshes);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "TextureAsset.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/WindowManager.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include <stb_image.h>
|
||||
#include <stb_image_write.h>
|
||||
|
||||
@@ -28,6 +28,7 @@ TextureAsset::~TextureAsset()
|
||||
void TextureAsset::save()
|
||||
{
|
||||
//TODO: make this an actual file, not just a png wrapper
|
||||
assert(false && "Editing textures is not yet supported");
|
||||
}
|
||||
|
||||
void TextureAsset::load()
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
}
|
||||
private:
|
||||
Gfx::PTexture texture;
|
||||
friend class TextureLoader;
|
||||
};
|
||||
DEFINE_REF(TextureAsset);
|
||||
} // namespace Seele
|
||||
|
||||
@@ -28,7 +28,7 @@ void TextureLoader::importAsset(const std::filesystem::path& filePath)
|
||||
PTextureAsset asset = new TextureAsset(assetFileName.replace_extension("asset").filename().generic_string());
|
||||
asset->setStatus(Asset::Status::Loading);
|
||||
asset->setTexture(placeholderTexture);
|
||||
AssetRegistry::get().textures[filePath.string()] = asset;
|
||||
AssetRegistry::get().textures[asset->getFileName()] = asset;
|
||||
//futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
|
||||
Gfx::PTexture2D texture = import(filePath);
|
||||
asset->setTexture(texture);
|
||||
@@ -45,8 +45,9 @@ Gfx::PTexture2D TextureLoader::import(const std::filesystem::path& path)
|
||||
{
|
||||
int x, y, n;
|
||||
unsigned char* data = stbi_load(path.string().c_str(), &x, &y, &n, 4);
|
||||
|
||||
TextureCreateInfo createInfo;
|
||||
createInfo.format = Gfx::SE_FORMAT_R8G8B8A8_UINT;
|
||||
createInfo.format = Gfx::SE_FORMAT_R8G8B8A8_SRGB;
|
||||
createInfo.resourceData.data = data;
|
||||
createInfo.resourceData.size = x * y * 4 * sizeof(unsigned char);
|
||||
createInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
|
||||
|
||||
Reference in New Issue
Block a user