28#include <condition_variable>
30#include "../3rdparty/opengl/glext.h"
33# include <emscripten.h>
34# include <emscripten/html5.h>
48 return reinterpret_cast<OGLProc
>(SDL_GL_GetProcAddress(proc));
59 if (error)
return error;
77 if (_screen.dst_ptr ==
nullptr) {
79 return "Can't get pointer to screen buffer";
108 SDL_GL_SetSwapInterval(vsync);
117 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
118 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
119 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
120 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
121 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
122 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
124 if (_debug_driver_level >= 8) {
125 SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
129 if (this->
gl_context ==
nullptr)
return "SDL2: Can't activate GL context";
148 if (this->
gl_context ==
nullptr)
return false;
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
How all blitters should look like.
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
virtual void PaletteAnimate(const Palette &palette)=0
Called when the 8bpp palette is changed; you should redraw all pixels on the screen that are equal to...
@ Blitter
The blitter takes care of the palette animation.
The factory for SDL' OpenGL video driver.
void Paint()
Render video buffer to the screen.
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 Resize(int w, int h, bool force=false)
Change the size of the drawing window and allocate matching resources.
static std::optional< std::string_view > Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res)
Create and initialize the singleton back-end class.
void UpdatePalette(const Colour *pal, uint first, uint length)
Update the stored palette.
void ReleaseAnimBuffer(const Rect &update_rect)
Update animation buffer texture after the animation buffer was filled.
void ClearCursorCache()
Queue a request for cursor cache clear.
static OpenGLBackend * Get()
Get singleton instance of this class.
void DrawMouseCursor()
Draw mouse cursor on screen.
void ReleaseVideoBuffer(const Rect &update_rect)
Update video buffer texture after the video buffer was filled.
static void Destroy()
Free resources and destroy singleton back-end class.
std::optional< std::string_view > Start(const StringList ¶m) override
Start this driver.
Dimension GetScreenSize() const override
Get the resolution of the main screen.
Palette local_palette
Current palette to use for drawing.
std::string driver_info
Information string about selected driver.
void ClientSizeChanged(int w, int h, bool force)
Indicate to the driver the client-size might have changed.
virtual bool CreateMainWindow(uint w, uint h, uint flags=0)
Create the main window.
void Stop() override
Stop this driver.
Rect dirty_rect
Rectangle encompassing the dirty area of the video buffer.
struct SDL_Window * sdl_window
Main SDL window.
void Paint() override
Paint the window.
void ReleaseVideoPointer() override
Hand video buffer back to the painting backend.
void * gl_context
OpenGL context.
void DestroyContext()
Destroy and release the OpenGL context.
void ToggleVsync(bool vsync) override
Change the vsync setting.
bool CreateMainWindow(uint w, uint h, uint flags) override
Create the main window.
void * GetVideoPointer() override
Get a pointer to the video buffer.
void Stop() override
Stop this driver.
std::optional< std::string_view > AllocateContext()
Allocate the OpenGL context.
void ClearSystemSprites() override
Clear all cached sprites.
bool AllocateBackingStore(int w, int h, bool force=false) override
(Re-)create the backing store.
std::optional< std::string_view > Start(const StringList ¶m) override
Start this driver.
void PopulateSystemSprites() override
Populate all sprites in cache.
uint8_t * anim_buffer
Animation buffer from OpenGL back-end.
static OGLProc GetOGLProcAddressCallback(const char *proc)
Platform-specific callback to get an OpenGL function pointer.
Factory to 'query' all available blitters.
Functions for standard in/out file operations.
Types for recording game performance data.
@ Video
Speed of painting drawn video buffer.
Functions related to the gfx engine.
Basic functions/variables used all over the place.
OpenGL video driver support.
bool CopyPalette(Palette &local_palette, bool force_copy)
Copy the current palette if the palette was updated.
Functions related to modal progress.
Declaration of OTTD revision dependent variables.
A number of safeguards to prevent using unsafe methods.
static OGLProc GetOGLProcAddressCallback(const char *proc)
Platform-specific callback to get an OpenGL function pointer.
static FVideoDriver_SDL_OpenGL iFVideoDriver_SDL_OpenGL
The OpenGL SDL video driver.
OpenGL backend of the SDL2 video driver.
Definition of base types and functions in a cross-platform compatible way.
std::vector< std::string > StringList
Type for a list of strings.
bool _video_vsync
Whether we should use vsync (only if active video driver supports HW acceleration).
Window functions not directly related to making/drawing windows.