blob: c372998ef19e8cdae5fdb318df2b856aca7ced1a (
plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#pragma once
#include "RcPtr.hpp"
#include <glad/glad.h>
#include <glm/glm.hpp>
#include <memory>
// TODO abstract texture traits such as component sizes from OpenGL
class TextureInfo {
public:
glm::ivec2 size;
bool isAtlas = false;
};
class Texture : public RefCounted {
friend class TextureStitcher;
private:
TextureInfo mInfo;
GLuint mHandle = 0;
public:
Texture() = default;
~Texture();
Texture(const Texture&) = delete;
Texture& operator=(const Texture&) = delete;
Texture(Texture&&) = default;
Texture& operator=(Texture&&) = default;
enum Filtering {
LinearFilter,
NearestFilter,
};
struct TextureProperties {
Filtering minifyingFilter = LinearFilter;
Filtering magnifyingFilter = LinearFilter;
};
bool InitFromFile(const char* filePath, const TextureProperties& props, bool flipVertically = false);
// bool InitFromImage(const Image& image, const TextureProperties& props, bool flipVertically = false);
const TextureInfo& GetInfo() const;
GLuint GetHandle() const;
bool IsValid() const;
};
/// A pure numerical subregion of a texture. u0/v0 are the UV coordinates of bottom left
/// corner, and u1/v1 are the top left corner.
struct Subregion {
/// Bottom left corner
float u0 = 0.0f;
float v0 = 0.0f;
/// Top right corner
float u1 = 0.0f;
float v1 = 0.0f;
};
/// A subregion of a specific texture.
struct TextureSubregion : public Subregion {
RcPtr<Texture> atlasTexture;
};
|