OpenTTD Source 20261123-master-g1c55c72fd0
cocoa_ogl.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#ifndef VIDEO_COCOA_OGL_H
11#define VIDEO_COCOA_OGL_H
12
13#include "cocoa_v.h"
14
15@class OTTD_OpenGLView;
16
17class VideoDriver_CocoaOpenGL : public VideoDriver_Cocoa {
18 CGLContextObj gl_context = nullptr;
19
20 std::string driver_info;
21
22 std::optional<std::string_view> AllocateContext(bool allow_software);
23
24public:
25 VideoDriver_CocoaOpenGL() : VideoDriver_Cocoa(true, true), driver_info(this->GetName()) {}
26
27 std::optional<std::string_view> Start(const StringList &param) override;
28 void Stop() override;
29
30 bool HasEfficient8Bpp() const override { return true; }
31
32 bool UseSystemCursor() override { return true; }
33
34 void ClearSystemSprites() override;
35
36 void PopulateSystemSprites() override;
37
38 std::string_view GetName() const override { return "cocoa-opengl"; }
39
40 std::string_view GetInfoString() const override { return this->driver_info; }
41
42 void AllocateBackingStore(bool force = false) override;
43
44protected:
45 void Paint() override;
46
47 void *GetVideoPointer() override;
48 void ReleaseVideoPointer() override;
49
50 NSView *AllocateDrawView() override;
51};
52
53class FVideoDriver_CocoaOpenGL : public DriverFactoryBase {
54public:
55 FVideoDriver_CocoaOpenGL() : DriverFactoryBase(Driver::Type::Video, 9, "cocoa-opengl", "Cocoa OpenGL Video Driver") {}
56 std::unique_ptr<Driver> CreateInstance() const override { return std::make_unique<VideoDriver_CocoaOpenGL>(); }
57
58protected:
59 bool UsesHardwareAcceleration() const override { return true; }
60};
61
62#endif /* VIDEO_COCOA_OGL_H */
DriverFactoryBase(Driver::Type type, int priority, std::string_view name, std::string_view description)
Construct a new DriverFactory.
Definition driver.cpp:246
@ Video
A video driver.
Definition driver.h:43
std::unique_ptr< Driver > CreateInstance() const override
Create an instance of this driver-class.
Definition cocoa_ogl.h:56
bool UsesHardwareAcceleration() const override
Does the driver use hardware acceleration (video-drivers only).
Definition cocoa_ogl.h:59
CGLContextObj gl_context
The OpenGL context.
Definition cocoa_ogl.h:18
void * GetVideoPointer() override
Get a pointer to the video buffer.
Definition cocoa_ogl.mm:291
std::string driver_info
Information string about selected driver.
Definition cocoa_ogl.h:20
void PopulateSystemSprites() override
Populate all sprites in cache.
Definition cocoa_ogl.mm:238
void ReleaseVideoPointer() override
Hand video buffer back to the drawing backend.
Definition cocoa_ogl.mm:301
std::optional< std::string_view > Start(const StringList &param) override
Start this driver.
Definition cocoa_ogl.mm:186
std::string_view GetName() const override
Get the name of this driver.
Definition cocoa_ogl.h:38
void Paint() override
Paint the window.
Definition cocoa_ogl.mm:313
bool HasEfficient8Bpp() const override
Has this video driver an efficient code path for palette animated 8-bpp sprites?
Definition cocoa_ogl.h:30
NSView * AllocateDrawView() override
Allocate the view to show the game on.
Definition cocoa_ogl.mm:270
std::string_view GetInfoString() const override
Get some information about the selected driver/backend to be shown to the user.
Definition cocoa_ogl.h:40
void ClearSystemSprites() override
Clear all cached sprites.
Definition cocoa_ogl.mm:245
void Stop() override
Stop Cocoa video driver.
Definition cocoa_ogl.mm:229
void AllocateBackingStore(bool force=false) override
Resize the window.
Definition cocoa_ogl.mm:275
bool UseSystemCursor() override
Get whether the mouse cursor is drawn by the video driver.
Definition cocoa_ogl.h:32
VideoDriver_Cocoa(bool uses_hardware_acceleration=false, bool supports_animation_buffer=false)
Create the video driver.
Definition cocoa_v.mm:71
The Cocoa video driver.
std::vector< std::string > StringList
Type for a list of strings.
Definition string_type.h:61