skybox.h 1.48 KB
Newer Older
unknown's avatar
unknown committed
1
2
3
4
5
6
7
#ifndef INCLUDE_SKYBOX_H 
#define INCLUDE_SKYBOX_H 

#include <filesystem>
#include <memory>
#include <vector>

Johannes Braun's avatar
Johannes Braun committed
8
9
#include <util/color.h>

unknown's avatar
unknown committed
10
#include <core/base/program.h>
11
#include <core/graph/component.h>
Johannes Braun's avatar
Johannes Braun committed
12
#include <core/rendering/batch_drawable.h>
13
#include <core/base/texture.h>
unknown's avatar
unknown committed
14
15
#include "mesh.h"

16
namespace glare::core
unknown's avatar
unknown committed
17
{
18
19
20
21
22
	namespace fs = std::experimental::filesystem;

	/**
	 * \brief A Simple skybox wrapper which draws a cube map with a dedicated shader onto a cube mesh.
	 */
Johannes Braun's avatar
Johannes Braun committed
23
	class Skybox : public SceneComponent
unknown's avatar
unknown committed
24
	{
25
26
27
28
29
	public:
		/**
		 * \brief Loads the given paths into a cubemap texture and creates the cube mesh, as well as the cubemap shader.
		 * \param faces The cubemap face image paths in order: posx, negx, posy, negy, posz, negz
		 */
Johannes Braun's avatar
Johannes Braun committed
30
31
		explicit Skybox(const std::vector<fs::path>& faces);
		explicit Skybox(const fs::path& faces);
32
33
34
		Skybox();
		~Skybox() = default;

Johannes Braun's avatar
Johannes Braun committed
35
		void reset(const fs::path& directory);
36
37
		void reset(const std::vector<fs::path>& faces);

Johannes Braun's avatar
Johannes Braun committed
38
		const Texture& texture() const;
39
		bool isInitialized() const;
Johannes Braun's avatar
Johannes Braun committed
40
41
42
		
		void uniformUpdate(const Program& program, const std::string& name) const;

43

Johannes Braun's avatar
Johannes Braun committed
44
45
46
47
48
49
	protected:
		/**
		* \brief Draws the cube map.
		*/
		void onDraw(DrawMode mode) override;

50
51
	private:
		bool m_initialized = false;
52

Johannes Braun's avatar
Johannes Braun committed
53
		color::rgba32f m_background{ 0.7f, 0.9f, 0.97f, 1.f };
54
55
		std::shared_ptr<Texture> m_texture;

56
57
58
59
		std::shared_ptr<Program> m_cubemap_shader;
		std::shared_ptr<Mesh> m_triangle_mesh;
		std::shared_ptr<BatchDrawable> m_drawable;
	};
unknown's avatar
unknown committed
60
61
62
}

#endif //INCLUDE_SKYBOX_H