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 : /* 19 : * Sky settings and texture management 20 : */ 21 : 22 : #ifndef INCLUDED_SKYMANAGER 23 : #define INCLUDED_SKYMANAGER 24 : 25 : #include "graphics/Texture.h" 26 : #include "ps/CStr.h" 27 : #include "renderer/VertexArray.h" 28 : 29 : #include <vector> 30 : 31 : namespace Renderer::Backend { class IDeviceCommandContext; } 32 : namespace Renderer::Backend { class ITexture; } 33 : namespace Renderer::Backend { class IVertexInputLayout; } 34 : 35 : /** 36 : * Class SkyManager: Maintain sky settings and textures, and render the sky. 37 : */ 38 : class SkyManager 39 : { 40 : public: 41 : SkyManager(); 42 : 43 : /** 44 : * Render the sky. 45 : */ 46 : void RenderSky( 47 : Renderer::Backend::IDeviceCommandContext* deviceCommandContext); 48 : 49 : /** 50 : * Return the currently selected sky set name. 51 : */ 52 0 : inline const CStrW& GetSkySet() const 53 : { 54 0 : return m_SkySet; 55 : } 56 : 57 : Renderer::Backend::ITexture* GetSkyCube(); 58 : 59 : /** 60 : * Set the sky set name. 61 : */ 62 : void SetSkySet(const CStrW& name); 63 : 64 : /** 65 : * Return a sorted list of available sky sets, in a form suitable 66 : * for passing to SetSkySet. 67 : */ 68 : std::vector<CStrW> GetSkySets() const; 69 : 70 0 : bool IsSkyVisible() const 71 : { 72 0 : return m_SkyVisible; 73 : } 74 : 75 0 : void SetSkyVisible(bool value) 76 : { 77 0 : m_SkyVisible = value; 78 : } 79 : 80 : /** 81 : * Load all sky textures from files and upload to GPU. 82 : */ 83 : void LoadAndUploadSkyTexturesIfNeeded( 84 : Renderer::Backend::IDeviceCommandContext* deviceCommandContext); 85 : 86 : private: 87 : void CreateSkyCube(); 88 : 89 : bool m_SkyVisible = true; 90 : 91 : /// Name of current skyset (a directory within art/textures/skies) 92 : CStrW m_SkySet; 93 : 94 : // Indices into m_SkyTexture 95 : enum 96 : { 97 : FRONT, 98 : BACK, 99 : RIGHT, 100 : LEFT, 101 : TOP, 102 : NUMBER_OF_TEXTURES 103 : }; 104 : 105 : // Sky textures 106 : CTexturePtr m_SkyTexture[NUMBER_OF_TEXTURES]; 107 : CTexturePtr m_SkyTextureCube; 108 : 109 : VertexArray m_VertexArray; 110 : VertexArray::Attribute m_AttributePosition; 111 : VertexArray::Attribute m_AttributeUV; 112 : 113 : Renderer::Backend::IVertexInputLayout* m_VertexInputLayout = nullptr; 114 : }; 115 : 116 : 117 : #endif // INCLUDED_SKYMANAGER