-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTexture.h
More file actions
71 lines (52 loc) · 2.33 KB
/
Copy pathTexture.h
File metadata and controls
71 lines (52 loc) · 2.33 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (C) 2026 - 2026 Settlers Freaks <sf-team at siedler25.org>
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "Rect.h"
#include <Point.h>
#include <SDL.h>
/// Wraps a texture with RAII and provides draw methods.
class Texture
{
public:
Texture() = default;
~Texture();
Texture(Texture&&) noexcept;
Texture& operator=(Texture&&) noexcept;
// No copy
Texture(const Texture&) = delete;
Texture& operator=(const Texture&) = delete;
/// Load from a 32-bit or 8-bit paletted SDL surface.
/// For 8-bit surfaces, optional colorkey is respected (keyed pixels become transparent).
bool load(SDL_Surface* surface, bool filterLinear = false);
/// Create an empty texture of the given size (for use as a render-target).
void createEmpty(Extent size, bool filterLinear = false);
/// Upload new pixel data to an existing texture (glTexSubImage2D).
void upload(const void* bgraPixels);
/// Draw the texture stretched to fill the given rect.
void draw(const Rect& destRect) const;
/// Draw the texture at native size at the given position.
void draw(Position pos) const;
/// Tile the texture to fill the given rectangle.
void drawTiled(const Rect& destRect) const;
/// Returns the raw GL texture name (for use with glBindTexture).
unsigned getHandle() const { return texture_; }
/// Size in pixels.
Extent getSize() const { return size_; }
/// Returns true if the texture has been created.
bool isValid() const { return texture_ != 0; }
private:
unsigned int texture_ = 0;
Extent size_;
/// Internal: create or recreate texture from raw BGRA pixel data.
void load(const void* bgraPixels, Extent size, bool filterLinear);
};
/// Draw a filled rectangle with a 32-bit ARGB colour.
void drawRect(const Rect& rect, unsigned color);
/// Draw a 3D-style button box: tiled background, 2px black frame (sunken if pressed, raised otherwise),
/// and tiled foreground inset by 2px.
void drawButtonBox(const Rect& area, bool pressed, unsigned baseTex, unsigned faceTex);
/// Get or create the cached OpenGL texture for a bitmap index.
/// The texture is loaded from the SDL surface on first access.
/// @param filterLinear Whether to use linear filtering (for scaled backgrounds).
Texture& getBmpTexture(unsigned idx, bool filterLinear = false);