This commit is contained in:
2022-05-29 11:59:17 +02:00
parent 3cfdd7a3f2
commit 76ac6e2f6d
5 changed files with 14 additions and 17 deletions

View File

@@ -54,13 +54,12 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
// TODO: use geometry shader instead of model and load skybox before models.
Skybox::Prototype skyboxPrototype = modelParser.getSkyboxPrototype();
std::thread skyboxThread([=]() {
m_skybox = new Skybox(skyboxPrototype,
std::static_pointer_cast<Model>(ResourceHandler::instance().resource("cube")).get(),
Controller::getShaderProgramByName("skyboxProgram", shaderPrograms));
m_skybox =
new Skybox(skyboxPrototype, std::static_pointer_cast<Model>(ResourceHandler::instance().resource("cube")).get(),
Controller::getShaderProgramByName("skyboxProgram", shaderPrograms));
Log::logger().info("Loaded skybox: {}", skyboxPrototype.texturePath);
});
Log::logger().info("Loaded skybox: {}", skyboxPrototype.texturePath);
m_skybox->initializeOnGPU();
std::vector<ModelEntity::Prototype> entityPrototypes = modelParser.getEntityPrototypes();
@@ -127,9 +126,6 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
}
}
m_lights = lights;
skyboxThread.join();
m_skybox->initializeOnGPU();
}
Scene::~Scene()

View File

@@ -30,7 +30,7 @@ struct TextureCubeMapDescriptor
class AbstractCubeMap : public AbstractTexture
{
public:
AbstractCubeMap(const std::string path) : AbstractTexture(path)
AbstractCubeMap(const std::string &path) : AbstractTexture(path)
{}
void bind(ShaderProgram *shaderProgram) const;

View File

@@ -3,9 +3,9 @@
ResourceId Resource::s_idCounter = 0;
Resource::Resource(const std::string &path) : m_id(s_idCounter++), m_path(path)
Resource::Resource(const std::filesystem::path &path) : m_id(s_idCounter++), m_path(path)
{
Log::logger().info("Resource \"{}\" with id {} created", m_path, m_id);
Log::logger().info("Resource \"{}\" with id {} created", m_path.string(), m_id);
}
ResourceId Resource::id() const
@@ -18,7 +18,7 @@ bool Resource::isInitialized() const
return m_initialized;
}
const std::string &Resource::resourcePath() const
const std::filesystem::path &Resource::resourcePath() const
{
return m_path;
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <filesystem>
#include <glad/glad.h>
#include <string>
@@ -9,14 +10,14 @@ using ResourceId = uint64_t;
class Resource
{
public:
Resource(const std::string &path);
Resource(const std::filesystem::path &path);
Resource(const Resource &other) = delete;
Resource(Resource &&other) = delete;
Resource &operator=(const Resource &other) = delete;
Resource &operator=(Resource &&other) = delete;
ResourceId id() const;
const std::string &resourcePath() const;
const std::filesystem::path &resourcePath() const;
protected:
bool isInitialized() const;
@@ -28,7 +29,7 @@ private:
ResourceId m_id;
static ResourceId s_idCounter;
std::string m_path;
std::filesystem::path m_path;
friend class ResourceHandler;
};

View File

@@ -9,7 +9,7 @@ Texture::Texture(const TextureDescriptor &descriptor)
m_textureBuffer = stbi_load(resourcePath().c_str(), &m_textureWidth, &m_textureHeight, &m_numComponents, 0);
if (!m_textureBuffer)
Log::logger().warn("Texture {} could not be loaded", resourcePath());
Log::logger().warn("Texture {} could not be loaded", resourcePath().string());
}
void Texture::initialize()