NWengine 0.9
Loading...
Searching...
No Matches
Texture.h
1#pragma once
2#include"Globals.h"
3#include"Asset.h"
4
5#include<unordered_map>
6
7typedef void* TextureIdentifierPtr;
8
13 std::string name;
14 uint8 alpha;
21 bool operator==(const TextureIdentifier& other) const {
22 return alpha == other.alpha && name == other.name;
23 }
24};
25
26template <>
27struct std::hash<TextureIdentifier>
28{
34 std::size_t operator()(const TextureIdentifier& t) const
35 {
36 std::size_t res = 0;
37 hashCombine(res, t.name);
38 hashCombine(res, t.alpha);
39 return res;
40 }
41};
42
46enum TexChannelInfo {
47 NW_R = 0x1903,
48 NW_RGB = 0x1907,
49 NW_RGBA = 0x1908
50};
51
55enum TexMinFilter {
56 NW_MIN_LINEAR = 0x2601,
57 NW_MIN_NEAREST = 0x2600,
58 NW_NEAREST_MIPMAP_NEAREST = 0x2700,
59 NW_NEAREST_MIPMAP_LINEAR = 0x2702
60};
61
65enum TexMaxFilter {
66 NW_LINEAR = 0x2601,
67 NW_NEAREST = 0x2600
68};
69
73enum TexEdge {
74 NW_REPEAT = 0x2901,
75 NW_CLAMP = 0x2900
76};
77
81class Texture : public Asset {
82public:
83 uint32 _glID = 0;
87 Texture() = default;
88
92 void Clean() override;
93
98 void Bind(uint32 slot = 0);
99
105 void _GPUGen(uint8* data, TexChannelInfo channelInfo);
106
110 void GenMipMap();
111
116 void SetMinFilter(TexMinFilter minFilter);
117
122 void SetMaxFilter(TexMaxFilter maxFilter);
123
128 void SetEdgesBehaviour(TexEdge edge);
129
135 Asset* GetFromCache(void* identifier) override;
136
143 Asset* LoadFromFile(const char* path, TextureIdentifierPtr identifier) override;
144
151 Asset* LoadFromBuffer(void* buffer, void* data) override;
152
153 NW_DECL_RES_LIST(TextureIdentifier, Texture)
154};
The base class for all assets.
Definition Asset.h:9
Class representing a texture asset.
Definition Texture.h:81
void SetMaxFilter(TexMaxFilter maxFilter)
Sets the magnification filter for the texture.
Definition Texture.cpp:38
bool _hasMipMap
Definition Texture.h:85
void SetMinFilter(TexMinFilter minFilter)
Sets the minification filter for the texture.
Definition Texture.cpp:33
void GenMipMap()
Generates mipmaps for the texture.
Definition Texture.cpp:27
Asset * LoadFromFile(const char *path, TextureIdentifierPtr identifier) override
Loads the texture from a file.
Definition Texture.cpp:61
Vector2< int > _size
Definition Texture.h:84
void _GPUGen(uint8 *data, TexChannelInfo channelInfo)
Generates the texture on the GPU.
Definition Texture.cpp:6
Asset * GetFromCache(void *identifier) override
Gets the texture from the cache based on the identifier.
Definition Texture.cpp:55
Asset * LoadFromBuffer(void *buffer, void *data) override
Loads the texture from a buffer.
Definition Texture.cpp:70
void Clean() override
Cleans up the texture.
Definition Texture.cpp:87
void SetEdgesBehaviour(TexEdge edge)
Sets the edge behavior for the texture.
Definition Texture.cpp:43
uint32 _glID
Definition Texture.h:83
void Bind(uint32 slot=0)
Binds the texture to a specified texture slot.
Definition Texture.cpp:49
Definition Maths.h:21
Struct representing the identifier of a texture.
Definition Texture.h:12
uint8 alpha
Definition Texture.h:14
std::string name
Definition Texture.h:13
bool operator==(const TextureIdentifier &other) const
Overloaded equality operator for comparing TextureIdentifier objects.
Definition Texture.h:21
std::size_t operator()(const TextureIdentifier &t) const
Hash function for TextureIdentifier objects.
Definition Texture.h:34