OpenTTD Source  20241108-master-g80f628063a
sdl2_opengl_v.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "sdl2_v.h"
11 
14 public:
15  VideoDriver_SDL_OpenGL() : VideoDriver_SDL_Base(true), gl_context(nullptr), anim_buffer(nullptr) {}
16 
17  std::optional<std::string_view> Start(const StringList &param) override;
18 
19  void Stop() override;
20 
21  bool HasEfficient8Bpp() const override { return true; }
22 
23  bool UseSystemCursor() override { return true; }
24 
25  void ClearSystemSprites() override;
26 
27  void PopulateSystemSprites() override;
28 
29  bool HasAnimBuffer() override { return true; }
30  uint8_t *GetAnimBuffer() override { return this->anim_buffer; }
31 
32  void ToggleVsync(bool vsync) override;
33 
34  std::string_view GetName() const override { return "sdl-opengl"; }
35 
36 protected:
37  bool AllocateBackingStore(int w, int h, bool force = false) override;
38  void *GetVideoPointer() override;
39  void ReleaseVideoPointer() override;
40  void Paint() override;
41  bool CreateMainWindow(uint w, uint h, uint flags) override;
42 
43 private:
44  void *gl_context;
45  uint8_t *anim_buffer;
46 
47  std::optional<std::string_view> AllocateContext();
48  void DestroyContext();
49 };
50 
53 public:
54  FVideoDriver_SDL_OpenGL() : DriverFactoryBase(Driver::DT_VIDEO, 8, "sdl-opengl", "SDL OpenGL Video Driver") {}
55  /* virtual */ Driver *CreateInstance() const override { return new VideoDriver_SDL_OpenGL(); }
56 
57 protected:
58  bool UsesHardwareAcceleration() const override { return true; }
59 };
Base for all driver factories.
Definition: driver.h:57
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description)
Construct a new DriverFactory.
Definition: driver.cpp:244
A driver for communicating with the user.
Definition: driver.h:21
@ DT_VIDEO
A video driver.
Definition: driver.h:42
The factory for SDL' OpenGL video driver.
Definition: sdl2_opengl_v.h:52
bool UsesHardwareAcceleration() const override
Does the driver use hardware acceleration (video-drivers only).
Definition: sdl2_opengl_v.h:58
Driver * CreateInstance() const override
Create an instance of this driver-class.
Definition: sdl2_opengl_v.h:55
The SDL video driver.
Definition: sdl2_v.h:18
The OpenGL video driver for windows.
Definition: sdl2_opengl_v.h:13
uint8_t * GetAnimBuffer() override
Get a pointer to the animation buffer of the video back-end.
Definition: sdl2_opengl_v.h:30
void Paint() override
Paint the window.
void ReleaseVideoPointer() override
Hand video buffer back to the painting backend.
void * gl_context
OpenGL context.
Definition: sdl2_opengl_v.h:44
std::string_view GetName() const override
Get the name of this driver.
Definition: sdl2_opengl_v.h:34
bool HasEfficient8Bpp() const override
Has this video driver an efficient code path for palette animated 8-bpp sprites?
Definition: sdl2_opengl_v.h:21
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.
bool UseSystemCursor() override
Get whether the mouse cursor is drawn by the video driver.
Definition: sdl2_opengl_v.h:23
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 &param) override
Start this driver.
void PopulateSystemSprites() override
Populate all sprites in cache.
uint8_t * anim_buffer
Animation buffer from OpenGL back-end.
Definition: sdl2_opengl_v.h:45
bool HasAnimBuffer() override
Does this video driver support a separate animation buffer in addition to the colour buffer?
Definition: sdl2_opengl_v.h:29
Base of the SDL2 video driver.
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:60