OpenTTD Source 20261112-master-gbcbec5e63f
sdl3_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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "sdl3_v.h"
11#include <SDL3/SDL_video.h>
12
15public:
18
19 std::optional<std::string_view> Start(const StringList &param) override;
20
21 void Stop() override;
22
23 bool HasEfficient8Bpp() const override { return true; }
24
25 bool UseSystemCursor() override { return true; }
26
27 void ClearSystemSprites() override;
28
29 void PopulateSystemSprites() override;
30
31 void ToggleVsync(bool vsync) override;
32
33 std::string_view GetName() const override { return "sdl-opengl"; }
34
35protected:
36 bool AllocateBackingStore(int w, int h, bool force = false) override;
37 void *GetVideoPointer() override;
38 void ReleaseVideoPointer() override;
39 void Paint() override;
40 bool CreateMainWindow(uint w, uint h, uint flags) override;
41
42private:
43 SDL_GLContext gl_context = nullptr;
44
45 std::optional<std::string_view> AllocateContext();
46 void DestroyContext();
47};
48
51public:
53 FVideoDriver_SDL_OpenGL() : DriverFactoryBase(Driver::Type::Video, 8, "sdl-opengl", "SDL OpenGL Video Driver") {}
54 std::unique_ptr<Driver> CreateInstance() const override { return std::make_unique<VideoDriver_SDL_OpenGL>(); }
55
56protected:
57 bool UsesHardwareAcceleration() const override { return true; }
58};
DriverFactoryBase(Driver::Type type, int priority, std::string_view name, std::string_view description)
Construct a new DriverFactory.
Definition driver.cpp:246
A driver for communicating with the user.
Definition driver.h:21
bool UsesHardwareAcceleration() const override
Does the driver use hardware acceleration (video-drivers only).
FVideoDriver_SDL_OpenGL()
Create the factory.
std::unique_ptr< Driver > CreateInstance() const override
Create an instance of this driver-class.
VideoDriver_SDL_Base(bool uses_hardware_acceleration=false, bool supports_animation_buffer=false)
Create the video driver.
Definition sdl3_v.h:23
void Paint() override
Paint the window.
void ReleaseVideoPointer() override
Hand video buffer back to the painting backend.
std::string_view GetName() const override
Get the name of this driver.
void DestroyContext()
Destroy and release the OpenGL context.
bool HasEfficient8Bpp() const override
Has this video driver an efficient code path for palette animated 8-bpp sprites?
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.
bool UseSystemCursor() override
Get whether the mouse cursor is drawn by the video 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 &param) override
Start this driver.
void PopulateSystemSprites() override
Populate all sprites in cache.
SDL_GLContext gl_context
OpenGL context.
VideoDriver_SDL_OpenGL()
Create the driver.
@ Video
Speed of painting drawn video buffer.
Base of the SDL3 video driver.
std::vector< std::string > StringList
Type for a list of strings.
Definition string_type.h:61