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