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#include <array>
7#include <cstdint>
8#include <span>
9#include <string>
10
11class SDLSurfacePtr;
12
13namespace openmsx {
14
15// TODO does this belong here or in GLUtil?
16gl::Texture loadTexture(const std::string& filename, gl::ivec2& size);
17
19{
20public:
21 explicit GLImage(const std::string& filename);
22 explicit GLImage(SDLSurfacePtr image);
23 GLImage(const std::string& filename, float scaleFactor);
24 GLImage(const std::string& filename, gl::ivec2 size);
25 GLImage(gl::ivec2 size, uint32_t rgba);
26 GLImage(gl::ivec2 size, std::span<const uint32_t, 4> rgba,
27 int borderSize, uint32_t borderRGBA);
28
29 void draw(gl::ivec2 pos, uint8_t alpha = 255) {
30 draw(pos, 255, 255, 255, alpha);
31 }
32 void draw(gl::ivec2 pos,
33 uint8_t r, uint8_t g, uint8_t b, uint8_t alpha);
34
35 [[nodiscard]] gl::ivec2 getSize() const { return size; }
36
42 static void checkSize(gl::ivec2 size);
43
44private:
45 void initBuffers();
46
47private:
48 gl::ivec2 size;
49 std::array<gl::BufferObject, 3> vbo;
50 gl::BufferObject elementsBuffer;
51 gl::Texture texture{gl::Null()}; // must come after size
52 int borderSize{0};
53 std::array<uint16_t, 4> bgA; // 0..256
54 uint16_t borderA{0}; // 0..256
55 std::array<uint8_t, 4> bgR, bgG, bgB;
56 uint8_t borderR{0}, borderG{0}, borderB{0};
57};
58
59} // namespace openmsx
60
61#endif
std::string image
Definition: HDImageCLI.cc:13
int g
Wrapper around a SDL_Surface.
Most basic/generic texture: only contains a texture ID.
Definition: GLUtil.hh:36
gl::ivec2 getSize() const
Definition: GLImage.hh:35
static void checkSize(gl::ivec2 size)
Performs a sanity check on image size.
Definition: GLImage.cc:18
void draw(gl::ivec2 pos, uint8_t alpha=255)
Definition: GLImage.hh:29
GLImage(const std::string &filename)
Definition: GLImage.cc:70
This file implemented 3 utility functions:
Definition: Autofire.cc:9
gl::Texture loadTexture(const std::string &filename, ivec2 &size)
Definition: GLImage.cc:58
size_t size(std::string_view utf8)