diff --git a/src/main.cpp b/src/main.cpp index 4cbb8d9..80a3e48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "program.hpp" #include "scene.hpp" #include "camera.hpp" +#include "store.hpp" #include diff --git a/src/model.hpp b/src/model.hpp index 311876a..a4a9ea6 100644 --- a/src/model.hpp +++ b/src/model.hpp @@ -1,7 +1,7 @@ #ifndef _MODEL_HPP_ #define _MODEL_HPP_ -#include "store.hpp" +#include "resource.hpp" #include "gl.hpp" #include "material.hpp" @@ -11,13 +11,9 @@ #include class Model: - public Store::Resource + public Resource { - friend class Store; - - Model(const std::string &name); - - static const std::string filename(const std::string &name); + RESOURCE(Model) public: void draw() const; diff --git a/src/mtllib.hpp b/src/mtllib.hpp index d6f92ee..a0e8291 100644 --- a/src/mtllib.hpp +++ b/src/mtllib.hpp @@ -1,20 +1,16 @@ #ifndef _MTLLIB_HPP_ #define _MTLLIB_HPP_ -#include "store.hpp" +#include "resource.hpp" #include "material.hpp" #include #include class Mtllib: - public Store::Resource + public Resource { - friend class Store; - - Mtllib(const std::string &name); - - static const std::string filename(const std::string &name); + RESOURCE(Mtllib) public: std::map materials; diff --git a/src/program.hpp b/src/program.hpp index 509b828..c88c034 100644 --- a/src/program.hpp +++ b/src/program.hpp @@ -1,19 +1,15 @@ #ifndef _PROGRAM_HPP_ #define _PROGRAM_HPP_ -#include "store.hpp" +#include "resource.hpp" #include "gl.hpp" #include class Program: - public Store::Resource + public Resource { - friend class Store; - - Program(const std::string &name); - - static const std::string filename(const std::string &name); + RESOURCE(Program) public: void use() const; diff --git a/src/resource.hpp b/src/resource.hpp new file mode 100644 index 0000000..6f1c45f --- /dev/null +++ b/src/resource.hpp @@ -0,0 +1,20 @@ +#ifndef _RESOURCE_HPP_ +#define _RESOURCE_HPP_ + +#include "store.hpp" + +class Resource +{ + friend class Store; + + __attribute__((unused)) // Used by friend class Store + unsigned long _ref_count = 0; +}; + +#define RESOURCE(T) \ +private: \ + friend class Store; \ + T(const std::string &name); \ + static const std::string filename(const std::string &name); + +#endif // _RESOURCE_HPP_ diff --git a/src/store.hpp b/src/store.hpp index e8c313f..beb8915 100644 --- a/src/store.hpp +++ b/src/store.hpp @@ -5,17 +5,11 @@ #include #include +class Resource; + class Store { public: - class Resource - { - friend class Store; - - __attribute__((unused)) // Used by friend class Store - unsigned long _ref_count = 0; - }; - template const T *load(const std::string &name); diff --git a/src/texture.hpp b/src/texture.hpp index d43f310..c138b71 100644 --- a/src/texture.hpp +++ b/src/texture.hpp @@ -1,19 +1,15 @@ #ifndef _TEXTURE_HPP_ #define _TEXTURE_HPP_ -#include "store.hpp" +#include "resource.hpp" #include "gl.hpp" #include class Texture: - public Store::Resource + public Resource { - friend class Store; - - Texture(const std::string &name); - - static const std::string filename(const std::string &name); + RESOURCE(Texture) public: