| 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 | #include <SDL_video.h> |
| 8 | |
| 9 | #include <atomic> |
| 10 | #include <cstddef> |
| 11 | #include <cstdint> |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
| 15 | struct SBackendCapabilities; |
| 16 | |
| 17 | enum EDebugGfxModes |
| 18 | { |
| 19 | DEBUG_GFX_MODE_NONE = 0, |
| 20 | DEBUG_GFX_MODE_MINIMUM, |
| 21 | DEBUG_GFX_MODE_AFFECTS_PERFORMANCE, |
| 22 | DEBUG_GFX_MODE_VERBOSE, |
| 23 | DEBUG_GFX_MODE_ALL, |
| 24 | }; |
| 25 | |
| 26 | enum ERunCommandReturnTypes |
| 27 | { |
| 28 | RUN_COMMAND_COMMAND_HANDLED = 0, |
| 29 | RUN_COMMAND_COMMAND_UNHANDLED, |
| 30 | RUN_COMMAND_COMMAND_WARNING, |
| 31 | RUN_COMMAND_COMMAND_ERROR, |
| 32 | }; |
| 33 | |
| 34 | enum EGfxErrorType |
| 35 | { |
| 36 | GFX_ERROR_TYPE_NONE = 0, |
| 37 | GFX_ERROR_TYPE_INIT, |
| 38 | GFX_ERROR_TYPE_OUT_OF_MEMORY_IMAGE, |
| 39 | GFX_ERROR_TYPE_OUT_OF_MEMORY_BUFFER, |
| 40 | GFX_ERROR_TYPE_OUT_OF_MEMORY_STAGING, |
| 41 | GFX_ERROR_TYPE_RENDER_RECORDING, |
| 42 | GFX_ERROR_TYPE_RENDER_CMD_FAILED, |
| 43 | GFX_ERROR_TYPE_RENDER_SUBMIT_FAILED, |
| 44 | GFX_ERROR_TYPE_SWAP_FAILED, |
| 45 | GFX_ERROR_TYPE_UNKNOWN, |
| 46 | }; |
| 47 | |
| 48 | enum EGfxWarningType |
| 49 | { |
| 50 | GFX_WARNING_TYPE_NONE = 0, |
| 51 | GFX_WARNING_TYPE_INIT_FAILED, |
| 52 | GFX_WARNING_TYPE_INIT_FAILED_MISSING_INTEGRATED_GPU_DRIVER, |
| 53 | GFX_WARNING_TYPE_INIT_FAILED_NO_DEVICE_WITH_REQUIRED_VERSION, |
| 54 | GFX_WARNING_LOW_ON_MEMORY, |
| 55 | GFX_WARNING_MISSING_EXTENSION, |
| 56 | GFX_WARNING_TYPE_UNKNOWN, |
| 57 | }; |
| 58 | |
| 59 | struct 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 | |
| 75 | struct SGfxWarningContainer |
| 76 | { |
| 77 | EGfxWarningType m_WarningType = EGfxWarningType::GFX_WARNING_TYPE_NONE; |
| 78 | std::vector<std::string> m_vWarnings; |
| 79 | }; |
| 80 | |
| 81 | class CCommandProcessorFragment_GLBase |
| 82 | { |
| 83 | protected: |
| 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 | |
| 91 | public: |
| 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 | SBackendCapabilities *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 | |