LumixEngine/src/renderer/texture.h

68 lines
1.7 KiB
C
Raw Normal View History

2014-06-16 21:18:15 +02:00
#pragma once
#include "core/resource.h"
#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-07-25 19:33:19 +02:00
const uint8_t* getData() const { return m_data.empty() ? nullptr : &m_data[0]; }
uint8_t* getData() { return m_data.empty() ? nullptr : &m_data[0]; }
2014-07-17 22:28:45 +02:00
void addDataReference();
void removeDataReference();
void onDataUpdated(int x, int y, int w, int h);
void save();
2015-08-20 00:24:04 +02:00
void setFlags(uint32_t flags);
2015-09-25 23:03:10 +02:00
uint32_t getFlags() const { return m_flags; }
2015-08-27 14:13:55 +02:00
uint32_t getPixelNearest(int x, int y) const;
uint32_t 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-01-03 12:13:13 +01:00
static bool saveTGA(IAllocator& allocator, FS::IFile* file, int width, int height, int bits_per_pixel, const uint8_t* 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-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);
void saveTGA();
2014-06-16 21:18:15 +02:00
2015-10-03 01:14:38 +02:00
virtual void unload(void) override;
virtual 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;
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-08-20 00:24:04 +02:00
uint32_t m_flags;
2014-06-16 21:18:15 +02:00
Array<uint8_t> 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