-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ManagedTexture.h
46 lines (37 loc) · 1.46 KB
/
ManagedTexture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <memory>
#include "Common/GPU/thin3d.h"
#include "Common/UI/View.h"
#include "Common/File/Path.h"
enum ImageFileType {
PNG,
JPEG,
ZIM,
DETECT,
TYPE_UNKNOWN,
};
class ManagedTexture {
public:
ManagedTexture(Draw::DrawContext *draw) : draw_(draw) {
}
~ManagedTexture() {
if (texture_)
texture_->Release();
}
bool LoadFromFile(const std::string &filename, ImageFileType type = ImageFileType::DETECT, bool generateMips = false);
bool LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips, const char *name);
Draw::Texture *GetTexture(); // For immediate use, don't store.
int Width() const { return texture_->Width(); }
int Height() const { return texture_->Height(); }
void DeviceLost();
void DeviceRestored(Draw::DrawContext *draw);
private:
Draw::Texture *texture_ = nullptr;
Draw::DrawContext *draw_;
std::string filename_; // Textures that are loaded from files can reload themselves automatically.
bool generateMips_ = false;
bool loadPending_ = false;
};
Draw::Texture *CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips, const char *name);
Draw::Texture *CreateTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType type, bool generateMips);
std::unique_ptr<ManagedTexture> CreateManagedTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType fileType, bool generateMips);