1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00
openrw/rwcore/gl/TextureData.hpp

49 lines
1008 B
C++
Raw Normal View History

#ifndef _LIBRW_TEXTUREDATA_HPP_
#define _LIBRW_TEXTUREDATA_HPP_
2018-12-09 23:06:02 +01:00
#include <gl/gl_core_3_3.h>
2018-12-09 23:06:02 +01:00
#include <glm/vec2.hpp>
#include <memory>
#include <string>
2019-01-18 03:46:59 +01:00
#include <unordered_map>
/**
* Stores a handle and metadata about a loaded texture.
*/
2016-09-09 22:13:21 +02:00
class TextureData {
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;
}
2019-01-18 03:46:59 +01:00
static auto create(GLuint name, const glm::ivec2& size,
2016-09-09 22:13:21 +02:00
bool transparent) {
2019-01-18 03:46:59 +01:00
return std::make_unique<TextureData>(name, size, transparent);
2016-09-09 22:13:21 +02:00
}
private:
2016-09-09 22:13:21 +02:00
GLuint texName;
glm::ivec2 size;
bool hasAlpha;
};
2019-01-18 03:46:59 +01:00
using TextureArchive = std::unordered_map<std::string, std::unique_ptr<TextureData>>;
#endif