2013-06-21 16:49:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "resources/ResourceManager.h"
|
2013-06-21 16:49:29 +00:00
|
|
|
|
|
|
|
#include <string>
|
2017-01-22 23:28:06 +00:00
|
|
|
#include <set>
|
|
|
|
#include <list>
|
2013-07-17 03:41:39 +00:00
|
|
|
#include <Eigen/Dense>
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "platform.h"
|
2017-01-22 23:28:06 +00:00
|
|
|
#include "resources/TextureData.h"
|
|
|
|
#include "resources/TextureDataManager.h"
|
2013-06-21 16:49:29 +00:00
|
|
|
#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:
|
2017-01-22 23:28:06 +00:00
|
|
|
static std::shared_ptr<TextureResource> get(const std::string& path, bool tile = false, bool forceLoad = false, bool dynamic = true);
|
|
|
|
void initFromPixels(const unsigned char* dataRGBA, size_t width, size_t height);
|
|
|
|
virtual void initFromMemory(const char* file, size_t length);
|
|
|
|
|
|
|
|
// For scalable source images in textures we want to set the resolution to rasterize at
|
|
|
|
void rasterizeAt(size_t width, size_t height);
|
|
|
|
Eigen::Vector2f getSourceImageSize() const;
|
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-24 21:29:56 +00:00
|
|
|
bool isInitialized() const;
|
2014-01-19 18:23:01 +00:00
|
|
|
bool isTiled() const;
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2017-01-22 23:28:06 +00:00
|
|
|
const Eigen::Vector2i getSize() const;
|
|
|
|
bool bind();
|
2013-07-09 05:44:24 +00:00
|
|
|
|
2014-03-27 21:47:25 +00:00
|
|
|
static size_t getTotalMemUsage(); // returns an approximation of total VRAM used by textures (in bytes)
|
2017-01-22 23:28:06 +00:00
|
|
|
static size_t getTotalTextureSize(); // returns the number of bytes that would be used if all textures were in memory
|
2014-03-27 21:47:25 +00:00
|
|
|
|
2014-03-20 01:13:59 +00:00
|
|
|
protected:
|
2017-01-22 23:28:06 +00:00
|
|
|
TextureResource(const std::string& path, bool tile, bool dynamic);
|
|
|
|
virtual void unload(std::shared_ptr<ResourceManager>& rm);
|
|
|
|
virtual void reload(std::shared_ptr<ResourceManager>& rm);
|
2013-07-09 05:44:24 +00:00
|
|
|
|
2014-03-20 01:13:59 +00:00
|
|
|
private:
|
2017-01-22 23:28:06 +00:00
|
|
|
// mTextureData is used for textures that are not loaded from a file - these ones
|
|
|
|
// are permanently allocated and cannot be loaded and unloaded based on resources
|
|
|
|
std::shared_ptr<TextureData> mTextureData;
|
|
|
|
|
|
|
|
// The texture data manager manages loading and unloading of filesystem based textures
|
|
|
|
static TextureDataManager sTextureDataManager;
|
|
|
|
|
|
|
|
Eigen::Vector2i mSize;
|
|
|
|
Eigen::Vector2f mSourceSize;
|
|
|
|
bool mForceLoad;
|
2014-03-27 21:47:25 +00:00
|
|
|
|
2014-01-19 18:23:01 +00:00
|
|
|
typedef std::pair<std::string, bool> TextureKeyType;
|
2014-03-27 21:47:25 +00:00
|
|
|
static std::map< TextureKeyType, std::weak_ptr<TextureResource> > sTextureMap; // map of textures, used to prevent duplicate textures
|
2017-01-22 23:28:06 +00:00
|
|
|
static std::set<TextureResource*> sAllTextures; // Set of all textures, used for memory management
|
2013-06-21 16:49:29 +00:00
|
|
|
};
|