1
0
Fork 0

Split resource and store

This commit is contained in:
Meoweg 2015-11-11 20:17:11 +00:00
parent c29875ef17
commit 913d14642f
7 changed files with 35 additions and 36 deletions

View File

@ -2,6 +2,7 @@
#include "program.hpp"
#include "scene.hpp"
#include "camera.hpp"
#include "store.hpp"
#include <cstdlib>

View File

@ -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;

View File

@ -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;

View File

@ -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;

20
src/resource.hpp Normal file
View File

@ -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_

View File

@ -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);

View File

@ -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: