13#include "../core/geometry_type.hpp"
14#include "../gfx_type.h"
15#include "../spriteloader/spriteloader.hpp"
16#include "../misc/lrucache.hpp"
18typedef void (*OGLProc)();
19typedef OGLProc (*GetOGLProcAddressProc)(
const char *proc);
74 std::optional<std::string_view>
Init(
const Dimension &screen_res);
87 static std::optional<std::string_view>
Create(GetOGLProcAddressProc get_proc,
const Dimension &screen_res);
90 void PrepareContext();
92 std::string GetDriverName();
94 void UpdatePalette(
const Colour *pal, uint first, uint length);
95 bool Resize(
int w,
int h,
bool force =
false);
99 void PopulateCursorCache();
126 std::array<GLuint, NUM_TEX>
tex{};
130 static std::array<GLuint, NUM_TEX>
dummy_tex;
Platform-independent back-end class for OpenGL video drivers.
GLint sprite_rgb_loc
Uniform location for RGB mode flag.
void * anim_buffer
Pointer to the mapped animation buffer.
GLuint remap_program
Shader program for blending and rendering a RGBA + remap texture.
bool cursor_in_window
Cursor inside this window.
uint GetSpriteAlignment() override
Get the value which the height and width on a sprite have to be aligned by.
void Paint()
Render video buffer to the screen.
GLuint pal_program
Shader program for rendering a paletted video buffer.
OpenGLSpriteLRUCache cursor_cache
Cache of encoded cursor sprites.
std::vector< CursorSprite > cursor_sprites
Sprites comprising cursor.
GLint remap_screen_loc
Uniform location for screen size.
static OpenGLBackend * instance
Singleton instance pointer.
uint8_t * GetAnimBuffer()
Get a pointer to the memory for the separate animation buffer.
void * GetVideoBuffer()
Get a pointer to the memory for the video driver to draw to.
bool persistent_mapping_supported
Persistent pixel buffer mapping supported.
GLuint vid_texture
Texture handle for the video buffer texture.
GLuint vao_quad
Vertex array object storing the rendering state for the fullscreen quad.
GLint sprite_zoom_loc
Uniform location for sprite zoom.
GLint remap_zoom_loc
Uniform location for sprite zoom.
bool Resize(int w, int h, bool force=false)
Change the size of the drawing window and allocate matching resources.
OpenGLBackend()
Construct OpenGL back-end class.
static std::optional< std::string_view > Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res)
Create and initialize the singleton back-end class.
void * vid_buffer
Pointer to the mapped video buffer.
void UpdatePalette(const Colour *pal, uint first, uint length)
Update the stored palette.
GLuint anim_texture
Texture handle for the animation buffer texture.
void InternalClearCursorCache()
Clear all cached cursor sprites.
Sprite * Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
GLuint sprite_program
Shader program for blending and rendering a sprite to the video buffer.
void ReleaseAnimBuffer(const Rect &update_rect)
Update animation buffer texture after the animation buffer was filled.
GLuint vid_pbo
Pixel buffer object storing the memory used for the video driver to draw to.
GLsync sync_anim_mapping
Sync object for the persistently mapped animation buffer.
~OpenGLBackend()
Free allocated resources.
GLuint vbo_quad
Vertex buffer with a fullscreen quad.
bool clear_cursor_cache
A clear of the cursor cache is pending.
GLint remap_rgb_loc
Uniform location for RGB mode flag.
void ClearCursorCache()
Queue a request for cursor cache clear.
GLuint vid_program
Shader program for rendering a RGBA video buffer.
GLuint pal_texture
Palette lookup texture.
bool Is32BppSupported() override
Can the sprite encoder make use of RGBA sprites?
GLint remap_sprite_loc
Uniform location for sprite parameters.
static OpenGLBackend * Get()
Get singleton instance of this class.
bool InitShaders()
Create all needed shader programs.
void DrawMouseCursor()
Draw mouse cursor on screen.
Point cursor_pos
Cursor position.
GLint sprite_crash_loc
Uniform location for crash remap mode flag.
void ReleaseVideoBuffer(const Rect &update_rect)
Update video buffer texture after the video buffer was filled.
GLint sprite_sprite_loc
Uniform location for sprite parameters.
void RenderOglSprite(const OpenGLSprite *gl_sprite, PaletteID pal, int x, int y, ZoomLevel zoom)
Render a sprite to the back buffer.
PaletteID last_sprite_pal
Last uploaded remap palette.
GLuint anim_pbo
Pixel buffer object storing the memory used for the animation buffer.
GLsync sync_vid_mapping
Sync object for the persistently mapped video buffer.
std::optional< std::string_view > Init(const Dimension &screen_res)
Check for the needed OpenGL functionality and allocate all resources.
static void Destroy()
Free resources and destroy singleton back-end class.
GLint sprite_screen_loc
Uniform location for screen size.
Class that encapsulates a RGBA texture together with a paletted remap texture.
std::array< GLuint, NUM_TEX > tex
The texture objects.
bool BindTextures() const
Bind textures for rendering this sprite.
Texture
Enum of all used OpenGL texture objects.
@ TEX_RGBA
RGBA texture part.
@ TEX_REMAP
Remap texture part.
Dimension GetSize(ZoomLevel level) const
Query the sprite size at a certain zoom level.
static bool Create()
Create all common resources for sprite rendering.
static GLuint pal_pbo
Pixel buffer object for remap upload.
static GLuint pal_identity
Identity texture mapping.
static GLuint pal_tex
Texture for palette remap.
int16_t y_offs
Number of pixels to shift the sprite downwards.
static std::array< GLuint, NUM_TEX > dummy_tex
1x1 dummy textures to substitute for unused sprite components.
int16_t x_offs
Number of pixels to shift the sprite to the right.
void Update(uint width, uint height, uint level, const SpriteLoader::CommonPixel *data)
Update a single mip-map level with new pixel data.
static void Destroy()
Free all common resources for sprite rendering.
Interface for something that can allocate memory for a sprite.
Interface for something that can encode a sprite.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
SpriteType
Types of sprites that might be loaded.
uint32_t PaletteID
The number of the palette.
bool IsOpenGLVersionAtLeast(uint8_t major, uint8_t minor)
Check if the current OpenGL version is equal or higher than a given one.
bool HasStringInExtensionList(std::string_view string, std::string_view substring)
Find a substring in a string made of space delimited elements.
Dimensions (a width and height) of a rectangle in 2D.
Coordinates of a point in 2D.
Specification of a rectangle with absolute coordinates of all edges.
Definition of a common pixel in OpenTTD's realm.
Data structure describing a sprite.
ZoomLevel
All zoom levels we know.