Go to the documentation of this file.
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));
61 error = this->AllocateContext();
62 if (
error !=
nullptr) {
77 if (_screen.dst_ptr ==
nullptr) {
79 return "Can't get pointer to screen buffer";
89 this->DestroyContext();
93 void VideoDriver_SDL_OpenGL::DestroyContext()
105 SDL_GL_SetSwapInterval(vsync);
108 const char *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;
bool AllocateBackingStore(int w, int h, bool force=false) override
(Re-)create the backing store.
@ PFE_VIDEO
Speed of painting drawn video buffer.
std::string driver_info
Information string about selected driver.
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
How all blitters should look like.
void Stop() override
Stop this driver.
bool CreateMainWindow(uint w, uint h, uint flags) override
Create the main window.
void PopulateSystemSprites() override
Populate all sprites in cache.
static OpenGLBackend * Get()
Get singleton instance of this class.
void DrawMouseCursor()
Draw mouse cursor on screen.
void Stop() override
Stop this driver.
void Paint() override
Paint the window.
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
void ReleaseVideoBuffer(const Rect &update_rect)
Update video buffer texture after the video buffer was filled.
Palette local_palette
Current palette to use for drawing.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
void * GetVideoBuffer()
Get a pointer to the memory for the video driver to draw to.
std::vector< std::string > StringList
Type for a list of strings.
static const char * Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res)
Create and initialize the singleton back-end class.
static void Destroy()
Free resources and destroy singleton back-end class.
virtual bool CreateMainWindow(uint w, uint h, uint flags=0)
Create the main window.
int count_dirty
The number of dirty elements.
void ToggleVsync(bool vsync) override
Change the vsync setting.
const char * Start(const StringList ¶m) override
Start this driver.
void ClearCursorCache()
Queue a request for cursor cache clear.
void ReleaseVideoPointer() override
Hand video buffer back to the painting backend.
void ClientSizeChanged(int w, int h, bool force)
Indicate to the driver the client-side might have changed.
void * GetVideoPointer() override
Get a pointer to the video buffer.
static OGLProc GetOGLProcAddressCallback(const char *proc)
Platform-specific callback to get an OpenGL funtion pointer.
bool CopyPalette(Palette &local_palette, bool force_copy)
Copy the current palette if the palette was updated.
Rect dirty_rect
Rectangle encompassing the dirty area of the video buffer.
void Paint()
Render video buffer to the screen.
The factory for SDL' OpenGL video driver.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
bool _video_vsync
Whether we should use vsync (only if _video_hw_accel is enabled).
void UpdatePalette(const Colour *pal, uint first, uint length)
Update the stored palette.
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...
@ PALETTE_ANIMATION_BLITTER
The blitter takes care of the palette animation.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
void ClearSystemSprites() override
Clear all cached sprites.
void ReleaseAnimBuffer(const Rect &update_rect)
Update animation buffer texture after the animation buffer was filled.
Dimension GetScreenSize() const override
Get the resolution of the main screen.
void * gl_context
OpenGL context.
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.
uint8 * anim_buffer
Animation buffer from OpenGL back-end.
struct SDL_Window * sdl_window
Main SDL window.
const char * Start(const StringList ¶m) override
Start this driver.