1#ifndef ENGINE_CLIENT_BACKEND_BACKEND_BASE_H
2#define ENGINE_CLIENT_BACKEND_BACKEND_BASE_H
3
4#include <engine/graphics.h>
5
6#include <engine/client/graphics_threaded.h>
7
8#include <SDL_video.h>
9
10#include <atomic>
11#include <cstddef>
12#include <cstdint>
13#include <string>
14#include <vector>
15
16struct SBackendCapabilites;
17
18enum EDebugGfxModes
19{
20 DEBUG_GFX_MODE_NONE = 0,
21 DEBUG_GFX_MODE_MINIMUM,
22 DEBUG_GFX_MODE_AFFECTS_PERFORMANCE,
23 DEBUG_GFX_MODE_VERBOSE,
24 DEBUG_GFX_MODE_ALL,
25};
26
27enum ERunCommandReturnTypes
28{
29 RUN_COMMAND_COMMAND_HANDLED = 0,
30 RUN_COMMAND_COMMAND_UNHANDLED,
31 RUN_COMMAND_COMMAND_WARNING,
32 RUN_COMMAND_COMMAND_ERROR,
33};
34
35enum EGfxErrorType
36{
37 GFX_ERROR_TYPE_NONE = 0,
38 GFX_ERROR_TYPE_INIT,
39 GFX_ERROR_TYPE_OUT_OF_MEMORY_IMAGE,
40 GFX_ERROR_TYPE_OUT_OF_MEMORY_BUFFER,
41 GFX_ERROR_TYPE_OUT_OF_MEMORY_STAGING,
42 GFX_ERROR_TYPE_RENDER_RECORDING,
43 GFX_ERROR_TYPE_RENDER_CMD_FAILED,
44 GFX_ERROR_TYPE_RENDER_SUBMIT_FAILED,
45 GFX_ERROR_TYPE_SWAP_FAILED,
46 GFX_ERROR_TYPE_UNKNOWN,
47};
48
49enum EGfxWarningType
50{
51 GFX_WARNING_TYPE_NONE = 0,
52 GFX_WARNING_TYPE_INIT_FAILED,
53 GFX_WARNING_TYPE_INIT_FAILED_MISSING_INTEGRATED_GPU_DRIVER,
54 GFX_WARNING_LOW_ON_MEMORY,
55 GFX_WARNING_MISSING_EXTENSION,
56 GFX_WARNING_TYPE_UNKNOWN,
57};
58
59struct SGfxErrorContainer
60{
61 struct SError
62 {
63 bool m_RequiresTranslation;
64 std::string m_Err;
65
66 bool operator==(const SError &Other) const
67 {
68 return m_RequiresTranslation == Other.m_RequiresTranslation && m_Err == Other.m_Err;
69 }
70 };
71 EGfxErrorType m_ErrorType = EGfxErrorType::GFX_ERROR_TYPE_NONE;
72 std::vector<SError> m_vErrors;
73};
74
75struct SGfxWarningContainer
76{
77 EGfxWarningType m_WarningType = EGfxWarningType::GFX_WARNING_TYPE_NONE;
78 std::vector<std::string> m_vWarnings;
79};
80
81class CCommandProcessorFragment_GLBase
82{
83protected:
84 SGfxErrorContainer m_Error;
85 SGfxWarningContainer m_Warning;
86
87 static bool Texture2DTo3D(uint8_t *pImageBuffer, int ImageWidth, int ImageHeight, size_t PixelSize, int SplitCountWidth, int SplitCountHeight, uint8_t *pTarget3DImageData, int &Target3DImageWidth, int &Target3DImageHeight);
88
89 virtual bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector<uint8_t> &vDstData) = 0;
90
91public:
92 virtual ~CCommandProcessorFragment_GLBase() = default;
93 virtual ERunCommandReturnTypes RunCommand(const CCommandBuffer::SCommand *pBaseCommand) = 0;
94
95 virtual void StartCommands(size_t CommandCount, size_t EstimatedRenderCallCount) {}
96 virtual void EndCommands() {}
97
98 const SGfxErrorContainer &GetError() { return m_Error; }
99 virtual void ErroneousCleanup() {}
100
101 const SGfxWarningContainer &GetWarning() { return m_Warning; }
102
103 enum
104 {
105 CMD_PRE_INIT = CCommandBuffer::CMDGROUP_PLATFORM_GL,
106 CMD_INIT,
107 CMD_SHUTDOWN,
108 CMD_POST_SHUTDOWN,
109 };
110
111 struct SCommand_PreInit : public CCommandBuffer::SCommand
112 {
113 SCommand_PreInit() :
114 SCommand(CMD_PRE_INIT) {}
115
116 SDL_Window *m_pWindow;
117 uint32_t m_Width;
118 uint32_t m_Height;
119
120 char *m_pVendorString;
121 char *m_pVersionString;
122 char *m_pRendererString;
123
124 TTwGraphicsGpuList *m_pGpuList;
125 };
126
127 struct SCommand_Init : public CCommandBuffer::SCommand
128 {
129 SCommand_Init() :
130 SCommand(CMD_INIT) {}
131
132 SDL_Window *m_pWindow;
133 uint32_t m_Width;
134 uint32_t m_Height;
135
136 class IStorage *m_pStorage;
137 std::atomic<uint64_t> *m_pTextureMemoryUsage;
138 std::atomic<uint64_t> *m_pBufferMemoryUsage;
139 std::atomic<uint64_t> *m_pStreamMemoryUsage;
140 std::atomic<uint64_t> *m_pStagingMemoryUsage;
141
142 TTwGraphicsGpuList *m_pGpuList;
143
144 TGLBackendReadPresentedImageData *m_pReadPresentedImageDataFunc;
145
146 SBackendCapabilites *m_pCapabilities;
147 int *m_pInitError;
148
149 const char **m_pErrStringPtr;
150
151 char *m_pVendorString;
152 char *m_pVersionString;
153 char *m_pRendererString;
154
155 int m_RequestedMajor;
156 int m_RequestedMinor;
157 int m_RequestedPatch;
158
159 EBackendType m_RequestedBackend;
160
161 int m_GlewMajor;
162 int m_GlewMinor;
163 int m_GlewPatch;
164 };
165
166 struct SCommand_Shutdown : public CCommandBuffer::SCommand
167 {
168 SCommand_Shutdown() :
169 SCommand(CMD_SHUTDOWN) {}
170 };
171
172 struct SCommand_PostShutdown : public CCommandBuffer::SCommand
173 {
174 SCommand_PostShutdown() :
175 SCommand(CMD_POST_SHUTDOWN) {}
176 };
177};
178
179#endif
180