Voxellancer  0.3
A game about voxels in space
 All Classes Functions Pages
starfield.h
1 #pragma once
2 
3 #include <deque>
4 
5 #include <glm/glm.hpp>
6 #include <glm/gtc/quaternion.hpp>
7 
8 #include <glow/ref_ptr.h>
9 #include <glow/Array.h>
10 
11 #include "property/property.h"
12 #include "display/rendering/renderpass.h"
13 #include "etc/contextdependant.h"
14 
15 
16 namespace glow {
17  class Texture;
18  class Program;
19  class VertexArrayObject;
20  class Buffer;
21 };
22 
23 
24 
25 /*
26  Renders a starfield around the camera.
27  Old camera positions/orientations are stored in order to stretch the
28  Stars on movement. As stereorendering renders twice per frame
29  with slightly different cameras, the Starfield needs to know which
30  side is drawn currently.
31  http://chrdw.de/uploads/Eyeside.pdf
32 */
33 class Starfield : public RenderPass, public ContextDependant {
34 public:
35  Starfield();
36 
37  virtual void update(float deltaSec, const glm::vec3& cameraPosition);
38  virtual void apply(FrameBuffer& frameBuffer, const RenderMetaData& metadata) override;
39 
40 
41 protected:
42  struct StarData {
43  glm::vec3 pos;
44  float brightness;
45  float size;
46  };
47  struct CameraLocation {
48  float time;
49  glm::vec3 position;
50  glm::quat orientation;
51  };
52 
53  std::deque<CameraLocation> m_locations[2];
54  float m_time;
55  Property<float> m_starfieldAge;
56  Property<float> m_starSize;
57  Property<int> m_starCount;
58  Property<float> m_fieldRadius;
59  float m_oldFieldRadius;
60 
61  glow::ref_ptr<glow::Program> m_shaderProgram;
62  glow::ref_ptr<glow::VertexArrayObject> m_vertexArrayObject;
63  glow::ref_ptr<glow::Buffer> m_gpuBuffer;
64  glow::Array<StarData> m_cpuBuffer;
65 
66  void createAndSetupShaders();
67  void createAndSetupGeometry();
68 
69  virtual void beforeContextDestroy() override;
70  virtual void afterContextRebuild() override;
71 
72  void createBinding(int index, std::string name, int offset, int size);
73 
74  void addLocation(const Camera& camera, int side);
75  glm::mat4 getMatrixFromPast(const Camera& camera, int side);
76  void cleanUp(int side);
77 };
78 
Definition: starfield.h:42
Definition: contextdependant.h:7
Definition: rendermetadata.h:9
Definition: renderpass.h:15
Definition: camera.h:10
Definition: framebuffer.h:17
Definition: starfield.h:47
Definition: starfield.h:33