Archived
1
Fork 0

Pass by reference in asset functions

This commit is contained in:
Joshua Goins 2022-02-21 00:11:13 -05:00
parent d91cd98fcb
commit 82eab9bd91
2 changed files with 11 additions and 12 deletions

View file

@ -126,11 +126,11 @@ using AssetManager = AssetPool<Mesh, Material, Texture>;
inline std::unique_ptr<AssetManager> assetm;
std::unique_ptr<Mesh> load_mesh(prism::path path);
std::unique_ptr<Material> load_material(prism::path path);
std::unique_ptr<Texture> load_texture(prism::path path);
std::unique_ptr<Mesh> load_mesh(const prism::path& path);
std::unique_ptr<Material> load_material(const prism::path& path);
std::unique_ptr<Texture> load_texture(const prism::path& path);
void save_material(Material* material, prism::path path);
void save_material(Material* material, const prism::path& path);
template<typename T>
std::unique_ptr<T> load_asset(const prism::path& path) {

View file

@ -15,7 +15,7 @@
#include "physics.hpp"
#include "imgui_backend.hpp"
std::unique_ptr<Mesh> load_mesh(const prism::path path) {
std::unique_ptr<Mesh> load_mesh(const prism::path& path) {
Expects(!path.empty());
auto file = prism::open_file(path, true);
@ -91,7 +91,7 @@ std::unique_ptr<Mesh> load_mesh(const prism::path path) {
file->read(&mesh->global_inverse_transformation);
std::map<std::string, uint32_t> boneMapping;
std::map<int, std::string> parentQueue;
std::map<size_t, std::string> parentQueue;
for (int v = 0; v < bone_len; v++) {
std::string bone, parent;
@ -189,7 +189,7 @@ std::unique_ptr<Mesh> load_mesh(const prism::path path) {
return mesh;
}
std::unique_ptr<Texture> load_texture(const prism::path path) {
std::unique_ptr<Texture> load_texture(const prism::path& path) {
Expects(!path.empty());
auto file = prism::open_file(path, true);
@ -233,12 +233,11 @@ std::unique_ptr<Texture> load_texture(const prism::path path) {
engine->get_gfx()->copy_texture(texture->handle, data, width * height * 4);
if(createInfo.mip_count > 1) {
GFXCommandBuffer* cmd_buf = engine->get_gfx()->acquire_command_buffer();
GFXCommandBuffer* cmd_buf = engine->get_gfx()->acquire_command_buffer(false);
cmd_buf->generate_mipmaps(texture->handle, createInfo.mip_count);
engine->get_gfx()->submit(cmd_buf);
engine->get_gfx()->submit(cmd_buf, nullptr);
}
stbi_image_free(data);
@ -246,7 +245,7 @@ std::unique_ptr<Texture> load_texture(const prism::path path) {
return texture;
}
std::unique_ptr<Material> load_material(const prism::path path) {
std::unique_ptr<Material> load_material(const prism::path& path) {
Expects(!path.empty());
auto file = prism::open_file(path);
@ -287,7 +286,7 @@ std::unique_ptr<Material> load_material(const prism::path path) {
return mat;
}
void save_material(Material* material, const prism::path path) {
void save_material(Material* material, const prism::path& path) {
Expects(material != nullptr);
Expects(!path.empty());