OXYGENHUB
◆ main openmsx / src / video / GLImage.hh
1.5 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef GLTEXTURE_HH
2
#define GLTEXTURE_HH
3
4
#include "GLUtil.hh"
5
#include "gl_vec.hh"
6
7
#include <array>
8
#include <cstdint>
9
#include <span>
10
#include <string>
11
12
class SDLSurfacePtr;
13
14
namespace openmsx {
15
16
// TODO does this belong here or in GLUtil?
17
gl::Texture loadTexture(const std::string& filename, gl::ivec2& size);
18
19
class GLImage
20
{
21
public:
22
	explicit GLImage(const std::string& filename);
23
	explicit GLImage(SDLSurfacePtr image);
24
	GLImage(const std::string& filename, float scaleFactor);
25
	GLImage(const std::string& filename, gl::ivec2 size);
26
	GLImage(gl::ivec2 size, uint32_t rgba);
27
	GLImage(gl::ivec2 size, std::span<const uint32_t, 4> rgba,
28
	        int borderSize, uint32_t borderRGBA);
29
30
	void draw(gl::ivec2 pos, uint8_t alpha = 255) {
31
		draw(pos, 255, 255, 255, alpha);
32
	}
33
	void draw(gl::ivec2 pos,
34
	          uint8_t r, uint8_t g, uint8_t b, uint8_t alpha);
35
36
	[[nodiscard]] gl::ivec2 getSize() const { return size; }
37
38
	/**
39
	 * Performs a sanity check on image size.
40
	 * Throws MSXException if width or height is excessively large.
41
	 * Negative image sizes are valid and flip the image.
42
	 */
43
	static void checkSize(gl::ivec2 size);
44
45
private:
46
	void initBuffers() const;
47
48
private:
49
	gl::ivec2 size;
50
	std::array<gl::BufferObject, 3> vbo;
51
	gl::BufferObject elementsBuffer;
52
	gl::Texture texture{gl::Null()}; // must come after size
53
	int borderSize{0};
54
	std::array<uint16_t, 4> bgA; // 0..256
55
	uint16_t borderA{0}; // 0..256
56
	std::array<uint8_t, 4> bgR, bgG, bgB;
57
	uint8_t borderR{0}, borderG{0}, borderB{0};
58
};
59
60
} // namespace openmsx
61
62
#endif