Line data Source code
1 : /* Copyright (C) 2025 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #ifndef INCLUDED_SHADERPROGRAM 19 : #define INCLUDED_SHADERPROGRAM 20 : 21 : #include "graphics/ShaderDefines.h" 22 : #include "graphics/ShaderProgramPtr.h" 23 : #include "lib/code_annotation.h" 24 : #include "lib/file/vfs/vfs_path.h" 25 : #include "ps/CStr.h" 26 : #include "renderer/backend/IShaderProgram.h" 27 : 28 : #include <memory> 29 : #include <vector> 30 : 31 : namespace Renderer::Backend { class IDevice; } 32 : 33 : /** 34 : * A wrapper for backend shader program to handle high-level operations like 35 : * file reloading and handling errors on reload. 36 : */ 37 : class CShaderProgram 38 : { 39 : NONCOPYABLE(CShaderProgram); 40 : 41 : public: 42 : static CShaderProgramPtr Create( 43 : Renderer::Backend::IDevice* device, const CStr& name, const CShaderDefines& defines); 44 : 45 : void Reload(); 46 : 47 : std::vector<VfsPath> GetFileDependencies() const; 48 : 49 0 : Renderer::Backend::IShaderProgram* GetBackendShaderProgram() { return m_BackendShaderProgram.get(); } 50 : 51 : // TODO: add reloadable handles. 52 : 53 : protected: 54 : CShaderProgram( 55 : Renderer::Backend::IDevice* device, const CStr& name, const CShaderDefines& defines); 56 : 57 : Renderer::Backend::IDevice* m_Device = nullptr; 58 : CStr m_Name; 59 : CShaderDefines m_Defines; 60 : std::unique_ptr<Renderer::Backend::IShaderProgram> m_BackendShaderProgram; 61 : }; 62 : 63 : #endif // INCLUDED_SHADERPROGRAM