OpenTTD Source  20241111-master-gce64d5f5d9
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 <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef VIDEO_COCOA_OGL_H
11 #define VIDEO_COCOA_OGL_H
12 
13 #include "cocoa_v.h"
14 
15 @class OTTD_OpenGLView;
16 
18  CGLContextObj gl_context;
19 
20  uint8_t *anim_buffer;
21  std::string driver_info;
22 
23  std::optional<std::string_view> AllocateContext(bool allow_software);
24 
25 public:
26  VideoDriver_CocoaOpenGL() : VideoDriver_Cocoa(true), gl_context(nullptr), anim_buffer(nullptr), driver_info(this->GetName()) {}
27 
28  std::optional<std::string_view> Start(const StringList &param) override;
29  void Stop() override;
30 
31  bool HasEfficient8Bpp() const override { return true; }
32 
33  bool UseSystemCursor() override { return true; }
34 
35  void ClearSystemSprites() override;
36 
37  void PopulateSystemSprites() override;
38 
39  bool HasAnimBuffer() override { return true; }
40  uint8_t *GetAnimBuffer() override { return this->anim_buffer; }
41 
43  std::string_view GetName() const override { return "cocoa-opengl"; }
44 
45  std::string_view GetInfoString() const override { return this->driver_info; }
46 
47  void AllocateBackingStore(bool force = false) override;
48 
49 protected:
50  void Paint() override;
51 
52  void *GetVideoPointer() override;
53  void ReleaseVideoPointer() override;
54 
55  NSView *AllocateDrawView() override;
56 };
57 
59 public:
60  FVideoDriver_CocoaOpenGL() : DriverFactoryBase(Driver::DT_VIDEO, 9, "cocoa-opengl", "Cocoa OpenGL Video Driver") {}
61  Driver *CreateInstance() const override { return new VideoDriver_CocoaOpenGL(); }
62 
63 protected:
64  bool UsesHardwareAcceleration() const override { return true; }
65 };
66 
67 #endif /* VIDEO_COCOA_OGL_H */
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
bool UsesHardwareAcceleration() const override
Does the driver use hardware acceleration (video-drivers only).
Definition: cocoa_ogl.h:64
Driver * CreateInstance() const override
Create an instance of this driver-class.
Definition: cocoa_ogl.h:61
uint8_t * anim_buffer
Animation buffer from OpenGL back-end.
Definition: cocoa_ogl.h:20
std::optional< std::string_view > Start(const StringList &param) override
Start this driver.
std::string driver_info
Information string about selected driver.
Definition: cocoa_ogl.h:21
void PopulateSystemSprites() override
Populate all sprites in cache.
void ReleaseVideoPointer() override
Hand video buffer back to the drawing backend.
std::string_view GetName() const override
Return driver name.
Definition: cocoa_ogl.h:43
uint8_t * GetAnimBuffer() override
Get a pointer to the animation buffer of the video back-end.
Definition: cocoa_ogl.h:40
void Paint() override
Paint the window.
bool HasEfficient8Bpp() const override
Has this video driver an efficient code path for palette animated 8-bpp sprites?
Definition: cocoa_ogl.h:31
bool HasAnimBuffer() override
Does this video driver support a separate animation buffer in addition to the colour buffer?
Definition: cocoa_ogl.h:39
void ClearSystemSprites() override
Clear all cached sprites.
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: cocoa_ogl.h:33
The Cocoa video driver.
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:60