2016-12-27 22:26:49 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2017-05-18 12:52:03 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/thin3d.h"
|
2020-10-04 20:48:47 +02:00
|
|
|
#include "Common/UI/View.h"
|
2021-05-06 01:31:38 +02:00
|
|
|
#include "Common/File/Path.h"
|
2016-12-27 22:26:49 +01:00
|
|
|
|
|
|
|
|
enum ImageFileType {
|
|
|
|
|
PNG,
|
|
|
|
|
JPEG,
|
|
|
|
|
ZIM,
|
|
|
|
|
DETECT,
|
|
|
|
|
TYPE_UNKNOWN,
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-07 14:56:19 +01:00
|
|
|
class ManagedTexture {
|
2016-12-27 22:26:49 +01:00
|
|
|
public:
|
2017-04-02 23:58:27 +02:00
|
|
|
ManagedTexture(Draw::DrawContext *draw) : draw_(draw) {
|
2016-12-27 22:26:49 +01:00
|
|
|
}
|
|
|
|
|
~ManagedTexture() {
|
2017-05-18 13:17:10 +02:00
|
|
|
if (texture_)
|
|
|
|
|
texture_->Release();
|
2016-12-27 22:26:49 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-11 14:43:42 +01:00
|
|
|
bool LoadFromFile(const std::string &filename, ImageFileType type = ImageFileType::DETECT, bool generateMips = false);
|
2020-08-08 23:18:17 +02:00
|
|
|
bool LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips, const char *name);
|
2018-03-27 23:10:33 +02:00
|
|
|
Draw::Texture *GetTexture(); // For immediate use, don't store.
|
2016-12-27 22:26:49 +01:00
|
|
|
int Width() const { return texture_->Width(); }
|
|
|
|
|
int Height() const { return texture_->Height(); }
|
|
|
|
|
|
2018-03-27 23:10:33 +02:00
|
|
|
void DeviceLost();
|
|
|
|
|
void DeviceRestored(Draw::DrawContext *draw);
|
|
|
|
|
|
2016-12-27 22:26:49 +01:00
|
|
|
private:
|
2017-04-02 23:58:27 +02:00
|
|
|
Draw::Texture *texture_ = nullptr;
|
2016-12-27 22:26:49 +01:00
|
|
|
Draw::DrawContext *draw_;
|
|
|
|
|
std::string filename_; // Textures that are loaded from files can reload themselves automatically.
|
2018-03-27 23:10:33 +02:00
|
|
|
bool generateMips_ = false;
|
|
|
|
|
bool loadPending_ = false;
|
2016-12-27 22:26:49 +01:00
|
|
|
};
|
|
|
|
|
|
2020-08-09 09:35:56 +02:00
|
|
|
std::unique_ptr<ManagedTexture> CreateTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType fileType, bool generateMips);
|
|
|
|
|
std::unique_ptr<ManagedTexture> CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, int size, ImageFileType fileType, bool generateMips, const char *name);
|
2019-10-11 17:34:38 +02:00
|
|
|
|