scene.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 
30 #pragma once
31 
32 #include "api_scene3d.h"
33 #include "../Display/Render/graphic_context.h"
34 #include "Performance/gpu_timer.h"
35 #include <memory>
36 
37 namespace clan
38 {
41 
42 class ResourceManager;
43 class Scene_Impl;
44 class SceneLight;
45 class SceneParticleEmitter;
46 class SceneObject;
47 class SceneCamera;
48 class ScenePass;
49 
50 class CL_API_SCENE Scene
51 {
52 public:
53  Scene();
54  Scene(GraphicContext &gc, const ResourceManager &resources, const std::string &shader_path);
55 
56  bool is_null() const;
57 
58  const SceneCamera &get_camera() const;
59  SceneCamera &get_camera();
60 
61  ResourceContainer &get_inout_container();
62 
63  template<typename Type>
64  Resource<Type> get_inout(const std::string &name)
65  {
66  return get_inout_container().get<Type>(name);
67  }
68 
69  void set_viewport(const Rect &box);
70  void set_camera(const SceneCamera &camera);
71 
72  void render(GraphicContext &gc);
73 
74  void update(GraphicContext &gc, float time_elapsed);
75 
76  Mat4f world_to_eye() const;
77  Mat4f eye_to_projection() const;
78  Mat4f world_to_projection() const;
79 
80  void unproject(const Vec2i &screen_pos, Vec3f &out_ray_start, Vec3f &out_ray_direction);
81 
82  void set_cull_oct_tree(const AxisAlignedBoundingBox &aabb);
83  void set_cull_oct_tree(const Vec3f &aabb_min, const Vec3f &aabb_max);
84  void set_cull_oct_tree(float max_size);
85 
86  ScenePass add_pass(const std::string &name, const std::string &insert_before = std::string());
87  void remove_pass(const std::string &name);
88 
89  void show_skybox_stars(bool enable);
90  void set_skybox_gradient(GraphicContext &gc, std::vector<Colorf> &colors);
91 
92  // To do: should not be static, should be getter functions, etc.
93  static int models_drawn;
94  static int instances_drawn;
95  static int draw_calls;
96  static int triangles_drawn;
97  static int scene_visits;
98  static std::vector<GPUTimer::Result> gpu_results;
99 
100 private:
101  std::shared_ptr<Scene_Impl> impl;
102 
103  friend class SceneLight;
104  friend class SceneParticleEmitter;
105  friend class SceneObject;
106  friend class SceneCamera;
107  friend class SceneModel;
108  friend class SceneLightProbe;
109  friend class ScenePass;
110 };
111 
112 }
113 
Resource proxy of a specific type.
Definition: resource.h:59
Resource< Type > get(const std::string &name)
Definition: resource_container.h:56
static int triangles_drawn
Definition: scene.h:96
static int models_drawn
Definition: scene.h:93
Definition: scene_light.h:46
Definition: resource_container.h:48
Definition: scene_object.h:44
static std::vector< GPUTimer::Result > gpu_results
Definition: scene.h:98
Resource< Type > get_inout(const std::string &name)
Definition: scene.h:64
Definition: scene_light_probe.h:43
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:453
static int scene_visits
Definition: scene.h:97
Definition: scene_camera.h:45
Definition: aabb.h:40
Definition: scene.h:50
Definition: scene_model.h:45
Definition: scene_particle_emitter.h:46
Resource manager.
Definition: resource_manager.h:45
Interface to drawing graphics.
Definition: graphic_context.h:257
4D matrix
Definition: mat2.h:52
static int draw_calls
Definition: scene.h:95
Definition: scene_pass.h:45
static int instances_drawn
Definition: scene.h:94