Go to the documentation of this file.
12 #ifndef VIDEO_OPENGL_H
13 #define VIDEO_OPENGL_H
15 #include "../core/alloc_type.hpp"
16 #include "../core/geometry_type.hpp"
17 #include "../gfx_type.h"
18 #include "../spriteloader/spriteloader.hpp"
19 #include "../misc/lrucache.hpp"
21 typedef void (*OGLProc)();
22 typedef OGLProc (*GetOGLProcAddressProc)(
const char *proc);
90 static const char *
Create(GetOGLProcAddressProc get_proc,
const Dimension &screen_res);
93 void PrepareContext();
96 bool Resize(
int w,
int h,
bool force =
false);
100 void PopulateCursorCache();
Point cursor_pos
Cursor position.
GLsync sync_vid_mapping
Sync object for the persistently mapped video buffer.
void RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, int x, int y, ZoomLevel zoom)
Render a sprite to the back buffer.
uint GetSpriteAlignment() override
Get the value which the height and width on a sprite have to be aligned by.
static GLuint pal_tex
Texture for palette remap.
GLuint pal_program
Shader program for rendering a paletted video buffer.
@ TEX_RGBA
RGBA texture part.
bool Is32BppSupported() override
Can the sprite encoder make use of RGBA sprites?
Dimensions (a width and height) of a rectangle in 2D.
Dimension GetSize(ZoomLevel level) const
Query the sprite size at a certain zoom level.
static GLuint pal_identity
Identity texture mapping.
static void Destroy()
Free all common resources for sprite rendering.
GLuint tex[NUM_TEX]
The texture objects.
OpenGLSprite(uint width, uint height, uint levels, SpriteColourComponent components)
Create an OpenGL sprite with a palette remap part.
@ TEX_REMAP
Remap texture part.
@ ZOOM_LVL_COUNT
Number of zoom levels.
void * vid_buffer
Pointer to the mapped video buffer.
ZoomLevel
All zoom levels we know.
static GLuint pal_pbo
Pixel buffer object for remap upload.
~OpenGLBackend()
Free allocated resources.
GLint sprite_zoom_loc
Uniform location for sprite zoom;.
static OpenGLBackend * Get()
Get singleton instance of this class.
GLuint anim_pbo
Pixel buffer object storing the memory used for the animation buffer.
Platform-independent back-end class for OpenGL video drivers.
GLuint vid_texture
Texture handle for the video buffer texture.
GLint remap_rgb_loc
Uniform location for RGB mode flag;.
void DrawMouseCursor()
Draw mouse cursor on screen.
PaletteID last_sprite_pal
Last uploaded remap palette.
void * anim_buffer
Pointer to the mapped animation buffer.
void ReleaseVideoBuffer(const Rect &update_rect)
Update video buffer texture after the video buffer was filled.
Base class that provides memory initialization on dynamically created objects.
GLuint vbo_quad
Vertex buffer with a fullscreen quad.
static bool Create()
Create all common resources for sprite rendering.
Definition of a common pixel in OpenTTD's realm.
void * GetVideoBuffer()
Get a pointer to the memory for the video driver to draw to.
static OpenGLBackend * instance
Singleton instance pointer.
bool cursor_in_window
Cursor inside this window.
GLuint anim_texture
Texture handle for the animation buffer texture.
GLint sprite_screen_loc
Uniform location for screen size;.
static const char * Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res)
Create and initialize the singleton back-end class.
GLsync sync_anim_mapping
Sync object for the persistently mapped animation buffer.
Coordinates of a point in 2D.
static void Destroy()
Free resources and destroy singleton back-end class.
Interface for something that can encode a sprite.
bool persistent_mapping_supported
Persistent pixel buffer mapping supported.
LRUCache< SpriteID, Sprite > cursor_cache
Cache of encoded cursor sprites.
PalSpriteID cursor_sprite_seq[16]
Current image of cursor.
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
GLuint vao_quad
Vertex array object storing the rendering state for the fullscreen quad.
static GLuint dummy_tex[NUM_TEX]
1x1 dummy textures to substitute for unused sprite components.
void ClearCursorCache()
Queue a request for cursor cache clear.
void Update(uint width, uint height, uint level, const SpriteLoader::CommonPixel *data)
Update a single mip-map level with new pixel data.
GLuint pal_texture
Palette lookup texture.
const char * FindStringInExtensionList(const char *string, const char *substring)
Find a substring in a string made of space delimited elements.
uint cursor_sprite_count
Number of cursor sprites to draw.
uint32 PaletteID
The number of the palette.
void InternalClearCursorCache()
Clear all cached cursor sprites.
GLint sprite_sprite_loc
Uniform location for sprite parameters.
Combination of a palette sprite and a 'real' sprite.
Structure for passing information from the sprite loader to the blitter.
bool BindTextures()
Bind textures for rendering this sprite.
void Paint()
Render video buffer to the screen.
GLint remap_sprite_loc
Uniform location for sprite parameters.
void UpdatePalette(const Colour *pal, uint first, uint length)
Update the stored palette.
GLuint sprite_program
Shader program for blending and rendering a sprite to the video buffer.
GLint sprite_crash_loc
Uniform location for crash remap mode flag;.
Class that encapsulates a RGBA texture together with a paletted remap texture.
bool clear_cursor_cache
A clear of the cursor cache is pending.
OpenGLBackend()
Construct OpenGL back-end class.
GLint sprite_rgb_loc
Uniform location for RGB mode flag;.
GLint remap_zoom_loc
Uniform location for sprite zoom;.
GLint remap_screen_loc
Uniform location for screen size;.
Specification of a rectangle with absolute coordinates of all edges.
GLuint vid_pbo
Pixel buffer object storing the memory used for the video driver to draw to.
Data structure describing a sprite.
void ReleaseAnimBuffer(const Rect &update_rect)
Update animation buffer texture after the animation buffer was filled.
GLuint remap_program
Shader program for blending and rendering a RGBA + remap texture.
const char * Init(const Dimension &screen_res)
Check for the needed OpenGL functionality and allocate all resources.
GLuint vid_program
Shader program for rendering a RGBA video buffer.
bool Resize(int w, int h, bool force=false)
Change the size of the drawing window and allocate matching resources.
uint8 * GetAnimBuffer()
Get a pointer to the memory for the separate animation buffer.
Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override
Convert a sprite from the loader to our own format.
bool IsOpenGLVersionAtLeast(byte major, byte minor)
Check if the current OpenGL version is equal or higher than a given one.
Point cursor_sprite_pos[16]
Relative position of individual cursor sprites.
bool InitShaders()
Create all needed shader programs.
SpriteColourComponent
The different colour components a sprite can have.
Texture
Enum of all used OpenGL texture objects.