Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
geom_culler.h
1 #pragma once
2 
3 #include <vector>
4 #include <memory>
5 #include <functional>
6 #include "../../types.h"
7 
8 
9 namespace smlt {
10 
11 namespace batcher {
12 class RenderQueue;
13 }
14 
15 struct Renderable;
16 
17 /*
18  * A GeomCuller is a class which compiles a mesh into some kind of internal representation
19  * and then given a frustum will return a list of renderables for rendering.
20  *
21  * This is a second-step per-geom culling phase after the broadphase culling of the scen
22  * partitioner.
23  */
24 
25 typedef std::shared_ptr<Renderable> RenderablePtr;
26 typedef std::vector<RenderablePtr> RenderableList;
27 
28 typedef std::function<void (Renderable*)> EachRenderableCallback;
29 
30 class Renderer;
31 
32 class GeomCuller {
33 public:
34  GeomCuller(Geom* geom, const MeshPtr mesh);
35  virtual ~GeomCuller();
36 
37  bool is_compiled() const;
38 
39  void compile(const Vec3& pos, const Quaternion& rot, const Vec3& scale);
40  void renderables_visible(const Frustum& frustum, batcher::RenderQueue* render_queue);
41 
42  void each_renderable(EachRenderableCallback cb);
43 
44  Geom* geom() const { return geom_; }
45 protected:
46  Geom* geom_ = nullptr;
47  MeshPtr mesh_;
48 
49 private:
50  bool compiled_ = false;
51 
52  virtual void _compile(const Vec3& pos, const Quaternion& rot, const Vec3& scale) = 0;
53  virtual void _gather_renderables(const Frustum& frustum, batcher::RenderQueue* render_queue) = 0;
54  virtual void _all_renderables(batcher::RenderQueue* rendre_queue) = 0;
55 
56  friend class GeomCullerRenderable;
57 
58  /* We need to hold on to the materials that were attached to the source
59  * mesh, otherwise they'll be garbage collected!
60  */
61  std::vector<MaterialPtr> material_refs_;
62 };
63 
64 }
smlt::Frustum
Definition: frustum.h:43
smlt::Geom
The Geom class.
Definition: geom.h:64
smlt::Vec3
Definition: vec3.h:23
smlt::Quaternion
Definition: quaternion.h:24
smlt
Definition: animation.cpp:25
smlt::batcher::RenderQueue
Definition: render_queue.h:156
smlt::GeomCuller
Definition: geom_culler.h:32