From cabb833e9b4ca10b9f350f3be6c351dce6a66822 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 20 Sep 2015 14:18:27 +0300 Subject: [PATCH] Pass the resource collection to async loaders This way they can access the loading parameters specified in that collection. --- source/mesh.cpp | 2 +- source/mesh.h | 2 +- source/resource.h | 3 ++- source/resourcemanager.cpp | 4 +++- source/texture1d.h | 2 +- source/texture2d.cpp | 2 +- source/texture2d.h | 2 +- source/texture3d.h | 2 +- source/texturecube.h | 2 +- 9 files changed, 12 insertions(+), 9 deletions(-) diff --git a/source/mesh.cpp b/source/mesh.cpp index 44568697..8f7c517b 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -200,7 +200,7 @@ void Mesh::unbind() glBindVertexArray(0); } -Resource::AsyncLoader *Mesh::load(IO::Seekable &io) +Resource::AsyncLoader *Mesh::load(IO::Seekable &io, const Resources *) { return new AsyncLoader(*this, io); } diff --git a/source/mesh.h b/source/mesh.h index 388d4d88..7e455cd9 100644 --- a/source/mesh.h +++ b/source/mesh.h @@ -95,7 +95,7 @@ public: static void unbind(); - virtual Resource::AsyncLoader *load(IO::Seekable &); + virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0); virtual UInt64 get_data_size() const; virtual void unload(); }; diff --git a/source/resource.h b/source/resource.h index 8d34c357..09d60e44 100644 --- a/source/resource.h +++ b/source/resource.h @@ -8,6 +8,7 @@ namespace Msp { namespace GL { class ResourceManager; +class Resources; class Resource { @@ -34,7 +35,7 @@ public: void set_manager(ResourceManager *); ResourceManager *get_manager() const { return manager; } void *get_manager_data() const { return manager_data; } - virtual AsyncLoader *load(IO::Seekable &) = 0; + virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) = 0; virtual bool is_loaded() const; virtual UInt64 get_data_size() const = 0; virtual void unload() = 0; diff --git a/source/resourcemanager.cpp b/source/resourcemanager.cpp index 733cfaff..481e9a17 100644 --- a/source/resourcemanager.cpp +++ b/source/resourcemanager.cpp @@ -4,6 +4,7 @@ #include #include #include "resourcemanager.h" +#include "resources.h" #include "resourcewatcher.h" using namespace std; @@ -283,7 +284,8 @@ void ResourceManager::ManagedResource::start_loading() if(!io) throw resource_load_error(location.name, "open failed"); - loader = resource->load(*io); + const Resources *res = dynamic_cast(location.collection); + loader = resource->load(*io, res); if(!loader) { delete io; diff --git a/source/texture1d.h b/source/texture1d.h index ea673c3b..63b25c13 100644 --- a/source/texture1d.h +++ b/source/texture1d.h @@ -27,7 +27,7 @@ private: unsigned get_level_size(unsigned); public: - virtual AsyncLoader *load(IO::Seekable &) { return 0; } + virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } virtual UInt64 get_data_size() const; virtual void unload() { } }; diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 7cad81d9..28b07bfe 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -136,7 +136,7 @@ void Texture2D::get_level_size(unsigned level, unsigned &w, unsigned &h) h = 1; } -Resource::AsyncLoader *Texture2D::load(IO::Seekable &io) +Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *) { return new AsyncLoader(*this, io); } diff --git a/source/texture2d.h b/source/texture2d.h index eba3286f..7504f321 100644 --- a/source/texture2d.h +++ b/source/texture2d.h @@ -85,7 +85,7 @@ private: void get_level_size(unsigned, unsigned &, unsigned &); public: - virtual Resource::AsyncLoader *load(IO::Seekable &); + virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0); virtual UInt64 get_data_size() const; virtual void unload(); }; diff --git a/source/texture3d.h b/source/texture3d.h index fa4c050f..c55a3c1a 100644 --- a/source/texture3d.h +++ b/source/texture3d.h @@ -62,7 +62,7 @@ private: void get_level_size(unsigned, unsigned &, unsigned &, unsigned &); public: - virtual AsyncLoader *load(IO::Seekable &) { return 0; } + virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } virtual UInt64 get_data_size() const; virtual void unload() { } }; diff --git a/source/texturecube.h b/source/texturecube.h index fe343c73..4530a97a 100644 --- a/source/texturecube.h +++ b/source/texturecube.h @@ -103,7 +103,7 @@ public: /** Returns a vector pointing to the center a texel. */ Vector3 get_texel_direction(TextureCubeFace, unsigned, unsigned); - virtual AsyncLoader *load(IO::Seekable &) { return 0; } + virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } virtual UInt64 get_data_size() const; virtual void unload() { } }; -- 2.45.2