OpenTTD Source  20240919-master-gdf0233f4c2
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 };
VideoDriver_SDL_OpenGL::HasAnimBuffer
bool HasAnimBuffer() override
Does this video driver support a separate animation buffer in addition to the colour buffer?
Definition: sdl2_opengl_v.h:29
VideoDriver_SDL_OpenGL::Start
std::optional< std::string_view > Start(const StringList &param) override
Start this driver.
Definition: sdl2_opengl_v.cpp:56
VideoDriver_SDL_OpenGL
The OpenGL video driver for windows.
Definition: sdl2_opengl_v.h:13
VideoDriver_SDL_OpenGL::AllocateBackingStore
bool AllocateBackingStore(int w, int h, bool force=false) override
(Re-)create the backing store.
Definition: sdl2_opengl_v.cpp:139
VideoDriver_SDL_OpenGL::GetName
std::string_view GetName() const override
Get the name of this driver.
Definition: sdl2_opengl_v.h:34
VideoDriver_SDL_OpenGL::Stop
void Stop() override
Stop this driver.
Definition: sdl2_opengl_v.cpp:87
VideoDriver_SDL_OpenGL::CreateMainWindow
bool CreateMainWindow(uint w, uint h, uint flags) override
Create the main window.
Definition: sdl2_opengl_v.cpp:51
DriverFactoryBase::DriverFactoryBase
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description)
Construct a new DriverFactory.
Definition: driver.cpp:244
VideoDriver_SDL_OpenGL::PopulateSystemSprites
void PopulateSystemSprites() override
Populate all sprites in cache.
Definition: sdl2_opengl_v.cpp:129
sdl2_v.h
FVideoDriver_SDL_OpenGL::CreateInstance
Driver * CreateInstance() const override
Create an instance of this driver-class.
Definition: sdl2_opengl_v.h:55
FVideoDriver_SDL_OpenGL::UsesHardwareAcceleration
bool UsesHardwareAcceleration() const override
Does the driver use hardware acceleration (video-drivers only).
Definition: sdl2_opengl_v.h:58
VideoDriver_SDL_OpenGL::HasEfficient8Bpp
bool HasEfficient8Bpp() const override
Has this video driver an efficient code path for palette animated 8-bpp sprites?
Definition: sdl2_opengl_v.h:21
VideoDriver_SDL_OpenGL::Paint
void Paint() override
Paint the window.
Definition: sdl2_opengl_v.cpp:174
VideoDriver_SDL_OpenGL::UseSystemCursor
bool UseSystemCursor() override
Get whether the mouse cursor is drawn by the video driver.
Definition: sdl2_opengl_v.h:23
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:60
VideoDriver_SDL_OpenGL::ReleaseVideoPointer
void ReleaseVideoPointer() override
Hand video buffer back to the painting backend.
Definition: sdl2_opengl_v.cpp:166
VideoDriver_SDL_OpenGL::GetVideoPointer
void * GetVideoPointer() override
Get a pointer to the video buffer.
Definition: sdl2_opengl_v.cpp:158
Driver::DT_VIDEO
@ DT_VIDEO
A video driver.
Definition: driver.h:42
VideoDriver_SDL_Base
The SDL video driver.
Definition: sdl2_v.h:18
FVideoDriver_SDL_OpenGL
The factory for SDL' OpenGL video driver.
Definition: sdl2_opengl_v.h:52
VideoDriver_SDL_OpenGL::GetAnimBuffer
uint8_t * GetAnimBuffer() override
Get a pointer to the animation buffer of the video back-end.
Definition: sdl2_opengl_v.h:30
Driver
A driver for communicating with the user.
Definition: driver.h:21
VideoDriver_SDL_OpenGL::ClearSystemSprites
void ClearSystemSprites() override
Clear all cached sprites.
Definition: sdl2_opengl_v.cpp:134
VideoDriver_SDL_OpenGL::gl_context
void * gl_context
OpenGL context.
Definition: sdl2_opengl_v.h:44
DriverFactoryBase
Base for all driver factories.
Definition: driver.h:57
VideoDriver_SDL_OpenGL::anim_buffer
uint8_t * anim_buffer
Animation buffer from OpenGL back-end.
Definition: sdl2_opengl_v.h:45