14 #include "../stdafx.h"
15 #include "../openttd.h"
16 #include "../gfx_func.h"
18 #include "../blitter/factory.hpp"
19 #include "../network/network.h"
20 #include "../thread.h"
21 #include "../progress.h"
22 #include "../core/random_func.hpp"
23 #include "../core/math_func.hpp"
24 #include "../core/mem_func.hpp"
25 #include "../core/geometry_func.hpp"
26 #include "../fileio_func.h"
27 #include "../framerate_type.h"
28 #include "../window_func.h"
32 #include <condition_variable>
34 #include "../3rdparty/opengl/glext.h"
37 # include <emscripten.h>
38 # include <emscripten/html5.h>
41 #include "../safeguards.h"
48 return reinterpret_cast<OGLProc
>(SDL_GL_GetProcAddress(proc));
59 if (error)
return error;
61 error = this->AllocateContext();
77 if (_screen.dst_ptr ==
nullptr) {
79 return "Can't get pointer to screen buffer";
89 this->DestroyContext();
93 void VideoDriver_SDL_OpenGL::DestroyContext()
103 void VideoDriver_SDL_OpenGL::ToggleVsync(
bool vsync)
105 SDL_GL_SetSwapInterval(vsync);
108 std::optional<std::string_view> VideoDriver_SDL_OpenGL::AllocateContext()
110 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
111 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
112 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
113 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
114 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
115 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
117 if (_debug_driver_level >= 8) {
118 SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
122 if (this->
gl_context ==
nullptr)
return "SDL2: Can't active GL context";
141 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.
@ PALETTE_ANIMATION_BLITTER
The blitter takes care of the palette animation.
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...
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.
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.
static OpenGLBackend * Get()
Get singleton instance of this 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-side 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.
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.
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.
@ PFE_VIDEO
Speed of painting drawn video buffer.
void MemSetT(T *ptr, uint8_t value, size_t num=1)
Type-safe version of memset().
OpenGL video driver support.
bool CopyPalette(Palette &local_palette, bool force_copy)
Copy the current palette if the palette was updated.
static OGLProc GetOGLProcAddressCallback(const char *proc)
Platform-specific callback to get an OpenGL funtion pointer.
OpenGL backend of the SDL2 video driver.
std::vector< std::string > StringList
Type for a list of strings.
int count_dirty
The number of dirty elements.
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
bool _video_vsync
Whether we should use vsync (only if active video driver supports HW acceleration).