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