-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTexture.hpp
More file actions
55 lines (47 loc) · 2.42 KB
/
Texture.hpp
File metadata and controls
55 lines (47 loc) · 2.42 KB
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
#ifndef TEXTURE_HPP
#define TEXTURE_HPP
#include <cstdint>
#include <vector>
#include "Shader.hpp"
#include "Config.hpp"
namespace Renderer
{
/// @brief How out-of-range UVs are resolved.
enum TextureAddressMode
{
WRAP, ///< UVs wrap (tile).
CLAMP, ///< UVs are clamped to the [0,1) range.
ZERO ///< Out-of-range UVs return colour 0.
};
/// @brief Static 2D image used for diffuse / reflection / screen-space sampling.
class Texture
{
public:
int width; ///< Width in pixels.
int height; ///< Height in pixels.
uint16_t *data; ///< Pixel data; RGB565 unless `palette` is set, in which case it is paletted indices.
bool hasAlpha; ///< When true, pixels equal to `alphaColor` are treated as transparent.
uint16_t alphaColor; ///< Colour key sampled as fully transparent.
bool screenSpace; ///< When true, the texture is sampled in screen space rather than UV space.
TextureAddressMode addressMode; ///< UV addressing mode.
uint16_t *palette; ///< Optional 256-entry palette; when non-null `data` is treated as indices.
bool reflectionMap = false; ///< When true, sampled via reflected view direction instead of UV.
char* name = nullptr; ///< Optional name for asset lookup.
/// @brief Construct a texture.
/// @param w Width in pixels.
/// @param h Height in pixels.
/// @param data Pixel data (caller-owned).
/// @param hasAlpha Enable colour-key transparency.
/// @param alphaColor Colour to treat as transparent when `hasAlpha` is true.
/// @param screenSpace Sample in screen space instead of UV.
/// @param addressMode UV addressing mode (WRAP/CLAMP/ZERO).
/// @param palette Optional palette (caller-owned).
Texture(int w, int h, uint16_t *data, bool hasAlpha = false, uint16_t alphaColor = 0, bool screenSpace = false, TextureAddressMode addressMode = WRAP, uint16_t *palette = nullptr);
/// @brief Sample the texture at a UV coordinate.
/// @param u Fixed-point U coordinate.
/// @param v Fixed-point V coordinate.
/// @return Sampled RGB565 colour.
uint16_t getPixel(int u, int v);
};
} // namespace Renderer
#endif // TEXTURE_HPP