2013-06-21 16:49:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
#include "ResourceManager.h"
|
2013-06-21 16:49:29 +00:00
|
|
|
|
|
|
|
#include <string>
|
2013-07-17 03:41:39 +00:00
|
|
|
#include <Eigen/Dense>
|
2013-06-21 16:49:29 +00:00
|
|
|
#include "../platform.h"
|
|
|
|
#include GLHEADER
|
|
|
|
|
2014-01-24 22:21:10 +00:00
|
|
|
// An OpenGL texture.
|
|
|
|
// Automatically recreates the texture with renderer deinit/reinit.
|
2013-07-09 05:44:24 +00:00
|
|
|
class TextureResource : public IReloadable
|
2013-06-21 16:49:29 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-01-19 18:23:01 +00:00
|
|
|
static std::shared_ptr<TextureResource> get(const std::string& path, bool tile = false);
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
virtual ~TextureResource();
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2014-03-20 01:13:59 +00:00
|
|
|
virtual void unload(std::shared_ptr<ResourceManager>& rm) override;
|
|
|
|
virtual void reload(std::shared_ptr<ResourceManager>& rm) override;
|
2013-07-09 05:44:24 +00:00
|
|
|
|
2014-03-24 21:29:56 +00:00
|
|
|
bool isInitialized() const;
|
2014-01-19 18:23:01 +00:00
|
|
|
bool isTiled() const;
|
2014-03-20 01:13:59 +00:00
|
|
|
const Eigen::Vector2i& getSize() const;
|
2013-07-09 05:44:24 +00:00
|
|
|
void bind() const;
|
|
|
|
|
2014-01-24 22:21:10 +00:00
|
|
|
// Warning: will NOT correctly reinitialize when this texture is reloaded (e.g. ES starts/stops playing a game).
|
2014-03-20 01:13:59 +00:00
|
|
|
virtual void initFromMemory(const char* file, size_t length);
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2014-03-20 01:13:59 +00:00
|
|
|
// Warning: will NOT correctly reinitialize when this texture is reloaded (e.g. ES starts/stops playing a game).
|
|
|
|
void initFromPixels(const unsigned char* dataRGBA, size_t width, size_t height);
|
2013-07-09 05:44:24 +00:00
|
|
|
|
2014-03-20 01:13:59 +00:00
|
|
|
protected:
|
|
|
|
TextureResource(const std::string& path, bool tile);
|
2013-07-09 05:44:24 +00:00
|
|
|
void deinit();
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector2i mTextureSize;
|
2013-07-09 05:44:24 +00:00
|
|
|
const std::string mPath;
|
2014-01-19 18:23:01 +00:00
|
|
|
const bool mTile;
|
2013-07-09 05:44:24 +00:00
|
|
|
|
2014-03-20 01:13:59 +00:00
|
|
|
private:
|
|
|
|
GLuint mTextureID;
|
2014-01-19 18:23:01 +00:00
|
|
|
typedef std::pair<std::string, bool> TextureKeyType;
|
|
|
|
static std::map< TextureKeyType, std::weak_ptr<TextureResource> > sTextureMap;
|
2013-06-21 16:49:29 +00:00
|
|
|
};
|