2014-06-16 21:18:15 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
2016-04-22 18:31:59 +02:00
|
|
|
#include "engine/core/resource.h"
|
2015-10-01 02:07:22 +02:00
|
|
|
#include <bgfx/bgfx.h>
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace Lumix
|
|
|
|
{
|
|
|
|
namespace FS
|
|
|
|
{
|
|
|
|
class FileSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-17 23:45:26 +02:00
|
|
|
class LUMIX_RENDERER_API Texture : public Resource
|
2014-06-16 21:18:15 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-11-09 14:32:37 +01:00
|
|
|
Texture(const Path& path, ResourceManager& resource_manager, IAllocator& allocator);
|
2014-06-16 21:18:15 +02:00
|
|
|
~Texture();
|
|
|
|
|
2015-08-14 22:12:51 +02:00
|
|
|
bool create(int w, int h, void* data);
|
|
|
|
void destroy();
|
2015-08-20 00:24:04 +02:00
|
|
|
|
|
|
|
int getDepth() const { return m_depth; }
|
2014-06-16 21:18:15 +02:00
|
|
|
int getWidth() const { return m_width; }
|
|
|
|
int getHeight() const { return m_height; }
|
|
|
|
int getBytesPerPixel() const { return m_BPP; }
|
2015-11-11 21:54:25 +01:00
|
|
|
const uint8* getData() const { return m_data.empty() ? nullptr : &m_data[0]; }
|
|
|
|
uint8* getData() { return m_data.empty() ? nullptr : &m_data[0]; }
|
2014-07-17 22:28:45 +02:00
|
|
|
void addDataReference();
|
|
|
|
void removeDataReference();
|
2015-10-03 13:24:58 +02:00
|
|
|
void onDataUpdated(int x, int y, int w, int h);
|
2014-08-06 21:37:03 +02:00
|
|
|
void save();
|
2015-11-11 21:54:25 +01:00
|
|
|
void setFlags(uint32 flags);
|
|
|
|
void setFlag(uint32 flag, bool value);
|
|
|
|
uint32 getFlags() const { return m_flags; }
|
|
|
|
uint32 getPixelNearest(int x, int y) const;
|
|
|
|
uint32 getPixel(float x, float y) const;
|
2015-06-06 15:04:58 +02:00
|
|
|
bgfx::TextureHandle getTextureHandle() const { return m_texture_handle; }
|
2014-08-02 01:56:37 +02:00
|
|
|
|
2015-11-11 21:54:25 +01:00
|
|
|
static bool saveTGA(IAllocator& allocator, FS::IFile* file, int width, int height, int bits_per_pixel, const uint8* data, const Path& path);
|
2015-01-29 23:58:30 +01:00
|
|
|
static unsigned int compareTGA(IAllocator& allocator, FS::IFile* file1, FS::IFile* file2, int difference);
|
2015-10-04 13:37:29 +02:00
|
|
|
int getAtlasSize() const { return m_atlas_size; }
|
|
|
|
void setAtlasSize(int size) { m_atlas_size = size; }
|
2015-01-03 12:13:13 +01:00
|
|
|
|
2014-06-16 21:18:15 +02:00
|
|
|
private:
|
2015-08-20 00:24:04 +02:00
|
|
|
bool load3D(FS::IFile& file);
|
2014-06-16 21:18:15 +02:00
|
|
|
bool loadDDS(FS::IFile& file);
|
|
|
|
bool loadTGA(FS::IFile& file);
|
2014-07-04 00:39:15 +02:00
|
|
|
bool loadRaw(FS::IFile& file);
|
2014-08-06 21:37:03 +02:00
|
|
|
void saveTGA();
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2015-11-20 16:58:10 +01:00
|
|
|
void unload(void) override;
|
|
|
|
bool load(FS::IFile& file) override;
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
private:
|
2014-11-09 14:32:37 +01:00
|
|
|
IAllocator& m_allocator;
|
2015-10-04 13:37:29 +02:00
|
|
|
int m_atlas_size;
|
2014-06-16 21:18:15 +02:00
|
|
|
int m_width;
|
|
|
|
int m_height;
|
|
|
|
int m_BPP;
|
2015-08-20 00:24:04 +02:00
|
|
|
int m_depth;
|
2014-07-17 22:28:45 +02:00
|
|
|
int m_data_reference;
|
2015-11-11 21:54:25 +01:00
|
|
|
uint32 m_flags;
|
|
|
|
Array<uint8> m_data;
|
2015-06-06 15:04:58 +02:00
|
|
|
bgfx::TextureHandle m_texture_handle;
|
2014-06-16 21:18:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // ~namespace Lumix
|