Panda3D

shadowAtlas.h
1 /**
2 *
3 * RenderPipeline
4 *
5 * Copyright (c) 2014-2016 tobspr <tobias.springer1@gmail.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 */
26
27 #ifndef SHADOWATLAS_H
28 #define SHADOWATLAS_H
29
30 #include "pandabase.h"
31 #include "luse.h"
32
33 NotifyCategoryDecl(shadowatlas, EXPORT_CLASS, EXPORT_TEMPL);
34
35
36 /**
37 * @brief Class which manages distributing shadow maps in an atlas.
38 * @details This class manages the shadow atlas. It handles finding and reserving
39 * space for new shadow maps.
40 */
41 class ShadowAtlas {
42 PUBLISHED:
43 ShadowAtlas(size_t size, size_t tile_size = 32);
44 ~ShadowAtlas();
45
46 inline int get_num_used_tiles() const;
47 inline float get_coverage() const;
48
49 MAKE_PROPERTY(num_used_tiles, get_num_used_tiles);
50 MAKE_PROPERTY(coverage, get_coverage);
51
52 public:
53
54 LVecBase4i find_and_reserve_region(size_t tile_width, size_t tile_height);
55 void free_region(const LVecBase4i& region);
56 inline LVecBase4 region_to_uv(const LVecBase4i& region);
57
58 inline int get_tile_size() const;
59 inline int get_required_tiles(size_t resolution) const;
60
61 protected:
62
63 void init_tiles();
64
65 inline void set_tile(size_t x, size_t y, bool flag);
66 inline bool get_tile(size_t x, size_t y) const;
67
68 inline bool region_is_free(size_t x, size_t y, size_t w, size_t h) const;
69 void reserve_region(size_t x, size_t y, size_t w, size_t h);
70
71 size_t _size;
72 size_t _num_tiles;
73 size_t _tile_size;
74 size_t _num_used_tiles;
75 bool* _flags;
76 };
77
78 #include "shadowAtlas.I"
79
80 #endif // SHADOWATLAS_H
ShadowAtlas
Class which manages distributing shadow maps in an atlas.
Definition: shadowAtlas.h:41
ShadowAtlas::find_and_reserve_region
LVecBase4i find_and_reserve_region(size_t tile_width, size_t tile_height)
Finds space for a map of the given size in the atlas.
Definition: shadowAtlas.cxx:130
ShadowAtlas::free_region
void free_region(const LVecBase4i &region)
Frees a given region.
Definition: shadowAtlas.cxx:173
ShadowAtlas::region_to_uv
LVecBase4 region_to_uv(const LVecBase4i &region)
Converts a tile-space region to uv space.
Definition: shadowAtlas.I:136
ShadowAtlas::ShadowAtlas
ShadowAtlas(size_t size, size_t tile_size=32)
Constructs a new shadow atlas.
Definition: shadowAtlas.cxx:52
ShadowAtlas::get_coverage
get_coverage
Returns the amount of used tiles in percentage.
Definition: shadowAtlas.h:50
ShadowAtlas::~ShadowAtlas
~ShadowAtlas()
Destructs the shadow atlas.
Definition: shadowAtlas.cxx:65
ShadowAtlas::get_tile_size
int get_tile_size() const
RenderPipeline.
Definition: shadowAtlas.I:35
ShadowAtlas::get_required_tiles
int get_required_tiles(size_t resolution) const
Returns the amount of tiles required to store a resolution.
Definition: shadowAtlas.I:116
ShadowAtlas::get_num_used_tiles
get_num_used_tiles
Returns the amount of used tiles.
Definition: shadowAtlas.h:49
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.