13#include "../core/alloc_type.hpp"
14#include "../core/geometry_type.hpp"
15#include "../gfx_type.h"
16#include "../spriteloader/spriteloader.hpp"
17#include "../misc/lrucache.hpp"
19typedef void (*OGLProc)();
20typedef OGLProc (*GetOGLProcAddressProc)(
const char *proc);
73 std::optional<std::string_view>
Init(
const Dimension &screen_res);
86 static std::optional<std::string_view>
Create(GetOGLProcAddressProc get_proc,
const Dimension &screen_res);
89 void PrepareContext();
91 std::string GetDriverName();
94 bool Resize(
int w,
int h,
bool force =
false);
98 void PopulateCursorCache();
Size limited cache with a least recently used eviction strategy.
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.
void RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, int x, int y, ZoomLevel zoom)
Render a sprite to the back buffer.
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.
Sprite * Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
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.
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.
PaletteID last_sprite_pal
Last uploaded remap palette.
GLuint anim_pbo
Pixel buffer object storing the memory used for the animation buffer.
LRUCache< SpriteID, Sprite > cursor_cache
Cache of encoded cursor sprites.
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.
static GLuint dummy_tex[NUM_TEX]
1x1 dummy textures to substitute for unused sprite components.
bool BindTextures()
Bind textures for rendering this sprite.
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.
GLuint tex[NUM_TEX]
The texture objects.
static GLuint pal_identity
Identity texture mapping.
static GLuint pal_tex
Texture for palette remap.
void Update(uint width, uint height, uint level, const SpriteLoader::CommonPixel *data)
Update a single mip-map level with new pixel data.
Texture
Enum of all used OpenGL texture objects.
@ TEX_RGBA
RGBA texture part.
@ TEX_REMAP
Remap texture part.
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.
std::array< Sprite, ZOOM_LVL_END > SpriteCollection
Type defining a collection of sprites, one for each zoom level.
Base class that provides memory initialization on dynamically created objects.
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.
const char * FindStringInExtensionList(const char *string, const char *substring)
Find a substring in a string made of space delimited elements.
SpriteColourComponent
The different colour components a sprite can have.
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.
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
ZoomLevel
All zoom levels we know.
@ ZOOM_LVL_END
End for iteration.