openMSX
GLImage.hh
Go to the documentation of this file.
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
12class SDLSurfacePtr;
13
14namespace openmsx {
15
16// TODO does this belong here or in GLUtil?
17gl::Texture loadTexture(const std::string& filename, gl::ivec2& size);
18
20{
21public:
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
43 static void checkSize(gl::ivec2 size);
44
45private:
46 void initBuffers() const;
47
48private:
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
std::string image
Definition HDImageCLI.cc:16
int g
Wrapper around a SDL_Surface.
Most basic/generic texture: only contains a texture ID.
Definition GLUtil.hh:39
gl::ivec2 getSize() const
Definition GLImage.hh:36
static void checkSize(gl::ivec2 size)
Performs a sanity check on image size.
Definition GLImage.cc:23
void draw(gl::ivec2 pos, uint8_t alpha=255)
Definition GLImage.hh:30
This file implemented 3 utility functions:
Definition Autofire.cc:11
gl::Texture loadTexture(const std::string &filename, ivec2 &size)
Definition GLImage.cc:63