gdk-graphics 0b051eb9b5c1eaa0658babaa4463dd7a80aa9d2c
Loading...
Searching...
No Matches
webgl1es2_scene.h
1// © Joseph Cameron - All Rights Reserved
2
3#ifndef GDK_GFX_WEBGL1ES2_SCENE
4#define GDK_GFX_WEBGL1ES2_SCENE
5
6#include <gdk/scene.h>
7#include <gdk/webgl1es2_material.h>
8#include <gdk/webgl1es2_model.h>
9#include <gdk/webgl1es2_screen_camera.h>
10#include <gdk/webgl1es2_texture_camera.h>
11
12#include <unordered_set>
13
14// TODO handle entity material & model changes. -> Will need to implement signals... vec<functor> likely. Maybe. This adds bookkeeping complexity, runtime complexity. it may be preferrable for the user to "change" an entities properties by removing the one you no longer want and inserting a new one with new properties.
15namespace gdk {
17 class render_set {
18 public:
19 using entity_ptr_type = std::shared_ptr<const entity>;
20 using material_ptr_type = std::shared_ptr<webgl1es2_material>;
21 using model_ptr_type = std::shared_ptr<webgl1es2_model>;
22 using model_to_entity_collection = std::unordered_map<model_ptr_type,
23 std::unordered_set<entity_ptr_type>>;
24 using material_to_model_to_entity_collection_collection =
25 std::unordered_map<material_ptr_type, model_to_entity_collection>;
26
27 virtual void draw(const webgl1es2_camera *r) const;
28
29 virtual void try_add(entity_ptr_type);
30
31 virtual ~render_set() = default;
32
33 protected:
34 material_to_model_to_entity_collection_collection m_MaterialToModelToEntityCollection;
35
36 std::unordered_set<entity_ptr_type> m_unique_entities;
37 };
38
39 class sorted_render_set final : public render_set {
40 public:
41 virtual void draw(const webgl1es2_camera *r) const;
42
43 virtual void try_add(entity_ptr_type) override;
44
45 sorted_render_set() = default;
46
47 private:
48
49 };
50
52 class webgl1es2_scene final : public scene {
53 public:
55 using material_ptr_type = std::shared_ptr<webgl1es2_material>;
57 using model_ptr_type = std::shared_ptr<webgl1es2_model>;
58
61 using model_to_entity_collection = std::unordered_map<model_ptr_type,
62 std::unordered_set<std::shared_ptr<const entity>>>;
66 std::unordered_map<material_ptr_type, model_to_entity_collection>;
67
70 //
71 //TODO: these fail silently on nullptr. should probably throw?
72 virtual void add(const std::shared_ptr<const screen_camera> &pCamera) override;
73 virtual void add(const std::shared_ptr<const texture_camera> &pCamera) override;
74 virtual void add(const std::shared_ptr<const entity> &pEntity) override;
75
76 virtual void remove(const std::shared_ptr<const screen_camera> &pCamera) override;
77 virtual void remove(const std::shared_ptr<const texture_camera> &pCamera) override;
78 virtual void remove(const std::shared_ptr<const entity> &pEntity) override;
79
80 virtual void draw(const gdk::graphics_intvector2_type &aFrameBufferSize) const override;
82
83 private:
85 std::unordered_set<std::shared_ptr<const webgl1es2_screen_camera>> m_screen_cameras;
86
88 std::unordered_set<std::shared_ptr<const webgl1es2_texture_camera>> m_texture_cameras;
89
91 material_to_model_to_entity_collection_collection m_MaterialToModelToEntityCollection;
92
93 render_set m_opaque_set;
94
95 sorted_render_set m_translucent_set;
96 };
97}
98
99#endif
set of objects to render
Definition webgl1es2_scene.h:17
a 3d environment within which cameras draw entities
Definition scene.h:16
Definition webgl1es2_scene.h:39
webgl1es2_camera implementation of camera
Definition webgl1es2_camera.h:21
render scene.
Definition webgl1es2_scene.h:52
virtual void remove(const std::shared_ptr< const entity > &pEntity) override
remove an entity from the scene
std::unordered_map< model_ptr_type, std::unordered_set< std::shared_ptr< const entity > > > model_to_entity_collection
Definition webgl1es2_scene.h:61
virtual void add(const std::shared_ptr< const entity > &pEntity) override
add an entity to the scene
virtual void add(const std::shared_ptr< const screen_camera > &pCamera) override
add a screen camera to the scene
std::shared_ptr< webgl1es2_model > model_ptr_type
models can be shared across webgl1es2_scenes
Definition webgl1es2_scene.h:57
std::shared_ptr< webgl1es2_material > material_ptr_type
materials can be shared across webgl1es2_scenes
Definition webgl1es2_scene.h:55
virtual void remove(const std::shared_ptr< const screen_camera > &pCamera) override
remove a screen camera from the scene
virtual void draw(const gdk::graphics_intvector2_type &aFrameBufferSize) const override
draws the scene
virtual void remove(const std::shared_ptr< const texture_camera > &pCamera) override
remove a texture camera from the scene
std::unordered_map< material_ptr_type, model_to_entity_collection > material_to_model_to_entity_collection_collection
Definition webgl1es2_scene.h:65
virtual void add(const std::shared_ptr< const texture_camera > &pCamera) override
add a texture camera to the scene