2017-10-30 23:44:40 +01:00
|
|
|
#ifndef _LIBRW_TEXTUREDATA_HPP_
|
|
|
|
#define _LIBRW_TEXTUREDATA_HPP_
|
2018-12-09 23:06:02 +01:00
|
|
|
|
2016-04-07 02:13:46 +02:00
|
|
|
#include <gl/gl_core_3_3.h>
|
2018-12-09 23:06:02 +01:00
|
|
|
#include <glm/vec2.hpp>
|
2015-02-16 01:36:11 +01:00
|
|
|
|
2018-08-29 22:46:00 +02:00
|
|
|
#include <map>
|
2015-02-16 01:36:11 +01:00
|
|
|
#include <memory>
|
2017-10-30 23:44:40 +01:00
|
|
|
#include <string>
|
2015-02-16 01:36:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores a handle and metadata about a loaded texture.
|
|
|
|
*/
|
2016-09-09 22:13:21 +02:00
|
|
|
class TextureData {
|
2015-02-16 01:36:11 +01:00
|
|
|
public:
|
2016-09-09 22:13:21 +02:00
|
|
|
TextureData(GLuint name, const glm::ivec2& dims, bool alpha)
|
|
|
|
: texName(name), size(dims), hasAlpha(alpha) {
|
|
|
|
}
|
|
|
|
|
rwlib: Delete textures on close
Should fix these memory leaks:
==22737== 513,622,016 bytes in 6,650 blocks are definitely lost in loss record 3,126 of 3,126
==22737== at 0x14F996E4: ??? (in /usr/lib64/dri/i965_dri.so)
==22737== by 0x14FE717A: ??? (in /usr/lib64/dri/i965_dri.so)
==22737== by 0x14FE622E: ??? (in /usr/lib64/dri/i965_dri.so)
==22737== by 0x14CDED2A: ??? (in /usr/lib64/dri/i965_dri.so)
==22737== by 0x14CDF85F: ??? (in /usr/lib64/dri/i965_dri.so)
==22737== by 0x91602C: createTexture(RW::BSTextureNative&, RW::BinaryStreamSection&) (LoaderTXD.cpp:79)
==22737== by 0x91649E: TextureLoader::loadFromMemory(std::shared_ptr<FileContentsInfo>, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::shared_ptr<TextureData>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<TextureData> > > >&) (LoaderTXD.cpp:183)
==22737== by 0x7BBCE0: GameData::loadTextureArchive(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameData.cpp:372)
==22737== by 0x7BBABA: GameData::loadTXD(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameData.cpp:358)
==22737== by 0x7BCA80: GameData::loadModel(unsigned short) (GameData.cpp:466)
==22737== by 0x7DF7BC: GameWorld::createInstance(unsigned short, glm::tvec3<float, (glm::precision)0> const&, glm::tquat<float, (glm::precision)0> const&) (GameWorld.cpp:144)
==22737== by 0x7DF44C: GameWorld::placeItems(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameWorld.cpp:120)
2017-09-13 01:14:21 +02:00
|
|
|
~TextureData() {
|
|
|
|
glDeleteTextures(1, &texName);
|
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
GLuint getName() const {
|
|
|
|
return texName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const glm::ivec2& getSize() const {
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isTransparent() const {
|
|
|
|
return hasAlpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::shared_ptr<TextureData> Handle;
|
|
|
|
|
|
|
|
static Handle create(GLuint name, const glm::ivec2& size,
|
|
|
|
bool transparent) {
|
2017-11-08 00:03:28 +01:00
|
|
|
return std::make_shared<TextureData>(name, size, transparent);
|
2016-09-09 22:13:21 +02:00
|
|
|
}
|
|
|
|
|
2015-02-16 01:36:11 +01:00
|
|
|
private:
|
2016-09-09 22:13:21 +02:00
|
|
|
GLuint texName;
|
|
|
|
glm::ivec2 size;
|
|
|
|
bool hasAlpha;
|
2016-04-07 02:13:46 +02:00
|
|
|
};
|
2016-12-03 22:04:07 +01:00
|
|
|
using TextureArchive = std::map<std::string, TextureData::Handle>;
|
2017-10-30 23:44:40 +01:00
|
|
|
|
|
|
|
#endif
|