Pioneer
Background.h
Go to the documentation of this file.
1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef _BACKGROUND_H
5 #define _BACKGROUND_H
6 
7 #include "graphics/Drawables.h"
8 
9 class Random;
10 class Galaxy;
11 class Space;
12 
13 namespace Graphics {
14  class Renderer;
15  class Material;
16  class RenderState;
17  class Texture;
18 
19 } // namespace Graphics
20 
21 /*
22  * Classes to draw background stars and the milky way
23  */
24 
25 namespace Background {
27  public:
28  void SetIntensity(float intensity);
29 
30  protected:
34 
35  float m_rMin;
36  float m_rMax;
37  float m_gMin;
38  float m_gMax;
39  float m_bMin;
40  float m_bMax;
41  };
42 
43  class UniverseBox : public BackgroundElement {
44  public:
46  ~UniverseBox();
47 
49  void LoadCubeMap(Random &rand);
50 
51  private:
52  void Init();
53 
54  std::unique_ptr<Graphics::VertexBuffer> m_vertexBuffer;
56 
57  Uint32 m_numCubemaps;
58  };
59 
60  class Starfield : public BackgroundElement {
61  public:
62  //does not Fill the starfield
63  Starfield(Graphics::Renderer *r, Random &rand, const Space *space, RefCountedPtr<Galaxy> galaxy);
65  //create or recreate the starfield
66  void Fill(Random &rand, const Space *space, RefCountedPtr<Galaxy> galaxy);
67 
68  private:
69  void Init();
70 
71  std::unique_ptr<Graphics::Drawables::PointSprites> m_pointSprites;
72  Graphics::RenderState *m_renderState; // NB: we don't own RenderState pointers, just borrow them
73 
74  //hyperspace animation vertex data
75  std::unique_ptr<vector3f[]> m_hyperVtx; // BG_STAR_MAX * 3
76  std::unique_ptr<Color[]> m_hyperCol; // BG_STAR_MAX * 3
77  std::unique_ptr<Graphics::VertexBuffer> m_animBuffer;
78 
79  float m_visibleRadiusLy;
80  float m_medianPosition;
81  float m_brightnessPower;
82  float m_brightnessApparentSizeOffset;
83  float m_brightnessApparentSizeFactor;
84  float m_brightnessColorFactor;
85  float m_brightnessColorOffset;
86  };
87 
88  class MilkyWay : public BackgroundElement {
89  public:
92 
93  private:
94  std::unique_ptr<Graphics::VertexBuffer> m_vertexBuffer;
95  };
96 
97  // contains starfield, milkyway, possibly other Background elements
98  class Container {
99  public:
101  DRAW_STARS = 1 << 0,
102  DRAW_MILKY = 1 << 1,
103  DRAW_SKYBOX = 1 << 2
104  };
105 
106  Container(Graphics::Renderer *, Random &rand, const Space *space, RefCountedPtr<Galaxy> galaxy);
107  void Draw(const matrix4x4d &transform);
108 
109  void SetIntensity(float intensity);
110  void SetDrawFlags(const Uint32 flags);
111  Uint32 GetDrawFlags() const { return m_drawFlags; }
112 
113  private:
114  Graphics::Renderer *m_renderer;
115  MilkyWay m_milkyWay;
116  Starfield m_starField;
117  UniverseBox m_universeBox;
118  Uint32 m_drawFlags;
119  Graphics::RenderState *m_renderState;
120  };
121 
122 } //namespace Background
123 
124 #endif
Definition: Background.h:26
float m_rMax
Definition: Background.h:36
RefCountedPtr< Graphics::Material > m_materialStreaks
Definition: Background.h:33
Graphics::Renderer * m_renderer
Definition: Background.h:31
RefCountedPtr< Graphics::Material > m_material
Definition: Background.h:32
void SetIntensity(float intensity)
Definition: Background.cpp:73
float m_gMin
Definition: Background.h:37
float m_bMax
Definition: Background.h:40
float m_bMin
Definition: Background.h:39
float m_rMin
Definition: Background.h:35
float m_gMax
Definition: Background.h:38
Definition: Background.h:98
Uint32 GetDrawFlags() const
Definition: Background.h:111
void Draw(const matrix4x4d &transform)
Definition: Background.cpp:549
Container(Graphics::Renderer *, Random &rand, const Space *space, RefCountedPtr< Galaxy > galaxy)
Definition: Background.cpp:535
BackgroundDrawFlags
Definition: Background.h:100
@ DRAW_SKYBOX
Definition: Background.h:103
@ DRAW_STARS
Definition: Background.h:101
@ DRAW_MILKY
Definition: Background.h:102
void SetDrawFlags(const Uint32 flags)
Definition: Background.cpp:574
void SetIntensity(float intensity)
Definition: Background.cpp:565
Definition: Background.h:88
void Draw(Graphics::RenderState *)
Definition: Background.cpp:528
MilkyWay(Graphics::Renderer *)
Definition: Background.cpp:452
Definition: Background.h:60
void Fill(Random &rand, const Space *space, RefCountedPtr< Galaxy > galaxy)
Definition: Background.cpp:237
void Draw(Graphics::RenderState *)
Definition: Background.cpp:416
Starfield(Graphics::Renderer *r, Random &rand, const Space *space, RefCountedPtr< Galaxy > galaxy)
Definition: Background.cpp:195
Definition: Background.h:43
UniverseBox(Graphics::Renderer *r)
Definition: Background.cpp:78
~UniverseBox()
Definition: Background.cpp:84
void Draw(Graphics::RenderState *)
Definition: Background.cpp:171
void LoadCubeMap(Random &rand)
Definition: Background.cpp:177
Definition: Galaxy.h:18
Definition: Material.h:81
Definition: RenderState.h:25
Definition: Renderer.h:39
Definition: Texture.h:106
Definition: Random.h:27
Definition: Space.h:19
Definition: Background.cpp:54
Definition: Background.h:13