Split resource and store
This commit is contained in:
parent
c29875ef17
commit
913d14642f
|
@ -2,6 +2,7 @@
|
|||
#include "program.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "camera.hpp"
|
||||
#include "store.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
|
|
|
@ -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 <glm/glm.hpp>
|
||||
|
||||
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;
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
#ifndef _MTLLIB_HPP_
|
||||
#define _MTLLIB_HPP_
|
||||
|
||||
#include "store.hpp"
|
||||
#include "resource.hpp"
|
||||
#include "material.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
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<std::string, const Material*> materials;
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
#ifndef _PROGRAM_HPP_
|
||||
#define _PROGRAM_HPP_
|
||||
|
||||
#include "store.hpp"
|
||||
#include "resource.hpp"
|
||||
#include "gl.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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_
|
|
@ -5,17 +5,11 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class Resource;
|
||||
|
||||
class Store
|
||||
{
|
||||
public:
|
||||
class Resource
|
||||
{
|
||||
friend class Store;
|
||||
|
||||
__attribute__((unused)) // Used by friend class Store
|
||||
unsigned long _ref_count = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
const T *load(const std::string &name);
|
||||
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
#ifndef _TEXTURE_HPP_
|
||||
#define _TEXTURE_HPP_
|
||||
|
||||
#include "store.hpp"
|
||||
#include "resource.hpp"
|
||||
#include "gl.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
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:
|
||||
|
||||
|
|
Reference in New Issue