Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
graphite/engine/assets/include/cubemap.hpp
2024-01-03 16:05:02 -05:00

93 lines
No EOL
1.9 KiB
C++

#pragma once
#include <asset.hpp>
#include <glm/glm.hpp>
#include <vector>
#include <filesystem.hpp>
#include <json.hpp>
class Cubemap : public Asset
{
public:
Cubemap(const std::string& path)
{
m_filepath = path;
LoadCube();
}
void Load(Renderer* renderer) override;
void Unload(Renderer* renderer) override;
void LoadCube()
{
int size;
File handle = Filesystem::GetFileHandle(m_filepath, size);
if(handle != nullptr)
{
nlohmann::json file = nlohmann::json::parse(handle);
faceIDs[0] = file["face0"];
faceIDs[1] = file["face1"];
faceIDs[2] = file["face2"];
faceIDs[3] = file["face3"];
faceIDs[4] = file["face4"];
faceIDs[5] = file["face5"];
Filesystem::FreeFileHandle(handle);
}
else
{
if(!Filesystem::IsPacked())
{
Log::Error("Cubemap file %s not found! Creating new one...", m_filepath.c_str());
SaveCube();
LoadCube();
}
}
}
void SaveCube()
{
nlohmann::json file;
file["face0"] = faceIDs[0];
file["face1"] = faceIDs[1];
file["face2"] = faceIDs[2];
file["face3"] = faceIDs[3];
file["face4"] = faceIDs[4];
file["face5"] = faceIDs[5];
std::ofstream out;
out.open(m_filepath);
out << file.dump(1);
out.close();
}
std::string GetName() override
{
return Utility::GetFilename(m_filepath);
}
std::string GetPath() override
{
return m_filepath;
}
std::type_index GetType() override
{
return typeid(Cubemap);
}
std::vector<int> GetDependencies() override
{
return { faceIDs[0], faceIDs[1], faceIDs[2], faceIDs[3], faceIDs[4], faceIDs[5] };
}
int faceIDs[6];
private:
std::string m_filepath;
};