cgv
Loading...
Searching...
No Matches
clod_point_renderer.h
1#pragma once
2#include <cgv/render/context.h>
3#include <cgv/render/shader_program.h>
4#include <cgv/render/vertex_buffer.h>
5#include <cgv/render/attribute_array_binding.h>
6#include <cgv/reflect/reflect_extern.h>
7#include <cgv_gl/gl/gl_context.h>
8#include <cgv_reflect_types/render/context.h>
9#include <atomic>
10#include <mutex>
11#include <array>
12#include "renderer.h"
13
14#include "gl/lib_begin.h"
15
16// source code of the continous level of detail point cloud renderer adapted for the cgv framework
17
18// original paper: "Real-Time Continuous Level of Detail Rendering of Point Clouds" from Schutz, Markus and Krosl, Katharina and Wimmer, Michael
19// the reference implementation can be found at https://github.com/m-schuetz/ieeevr_2019_clod
20
21namespace cgv {
22 namespace render {
23
24 class clod_point_renderer;
25
26
27 //stores and manages point buffers modified by the reduce step
29 {
31 GLuint points;
33 GLuint indices;
35 GLuint draw_parameters;
36 GLuint vertex_array;
37 GLuint max_num_points = 0;
38 protected:
39 GLuint get_vertex_array();
40 public:
41 void init(context& ctx);
42
43 void clear(context& ctx);
44
45 void resize(GLuint size);
46
48 GLuint get_index_buffer();
49
51 GLuint get_draw_parameters();
52
54 GLuint get_reduced_points();
56 GLuint num_reduced_points();
58 GLuint size();
59
60 friend class clod_point_renderer;
61 };
62
63
64 extern CGV_API clod_point_renderer& ref_clod_point_renderer(context& ctx, int ref_count_change = 0);
65
67 struct CGV_API clod_point_render_style : public render_style
68 {
69 /*@name clod rendering attributes*/
71 // clod factor, affects the distance dependent target spacing
72 float CLOD;
75 float spacing;
76 // scales the target spacing
77 float scale;
78 // minimal size of the visible points
79 float min_millimeters;
80 float pointSize;
81 // draw circles instead of squares
82 bool draw_circles = false;
84 bool use_clod = false;
85 private:
86 char reserved_space[36]; //this is here to fix some mess in serialization
87
88 public:
91 };
92
93
94 //* */
95 class CGV_API clod_point_renderer {
96 public:
97 // internal point format, made to fit inside 16 bytes
98 struct Point {
99 vec3 p_position;
100 rgb8 p_color;
101 uint8_t p_level = 0;
102
103 Point() = default;
104
105 //conversion from other point formats
106 template <typename P>
107 Point(const P& pnt) {
108 p_position = pnt.position();
109 p_color = pnt.color();
110 p_level = pnt.level();
111 }
112
113 inline vec3& position() {
114 return p_position;
115 }
117 inline uint8_t& level() {
118 return p_level;
119 }
120 inline rgb8& color() {
121 return p_color;
122 }
123 inline const vec3& position() const {
124 return p_position;
125 }
127 inline const uint8_t& level() const {
128 return p_level;
129 }
130 inline const rgb8& color() const {
131 return p_color;
132 }
133 };
134
135 private:
136 shader_program reduce_prog; // filters points from the input buffer and writes them to the render_buffer (compute shader)
137 shader_program* draw_prog_ptr;
138 shader_program draw_prog; // draws render_buffer (vertex, geometry, fragment shader)
139
140 clod_point_buffer_manager buffer_manager;
141 clod_point_buffer_manager* active_buffer_manager_ptr;
142
143 GLuint active_vertex_array = 0;
144 //internal buffers,
145 // input buffer stores all points given by set points
146 // render buffer contains all points that should be drawn on screen
147 // draw_parameter_buffer contains the parameters required for indirect drawing
148 // render_buffer and draw_parameter_buffer are generated by the reduce methods and
149 GLuint input_buffer = 0;
150 //active buffers (may be externals)
151 GLuint active_render_buffer = 0, active_draw_parameter_buffer = 0, active_index_buffer = 0;
153 const int input_pos = 0, render_pos = 1, index_pos = 2,drawp_pos = 3, input_id_pos = 4;
154
155 GLsizeiptr input_buffer_size = 0;
156 GLuint input_buffer_num_points = 0;
157
158 bool buffers_outofdate = true;
159
160 float frustum_extend = 1.f;
161
162 vec4 pivot_point_in_view_space;
163
164
165
167 mutable render_style* default_render_style = nullptr;
169 const render_style* rs = nullptr;
170
171 //cached uniform locations
172 struct uniform_locations {
173 int batch_offset,
174 batch_size,
175 CLOD,
176 scale,
177 spacing,
178 screenSize,
179 pivot,
180 frustum_extent,
181 protection_zone_points,
182 target_buffer_size;
183 //uniform blocks
184 int CLODParameterBlock;
185 } uniforms;
186
187 protected:
188 const render_style* get_style_ptr() const;
189
190 template <typename T>
191 const T& get_style() const { return *static_cast<const T*>(get_style_ptr()); }
192
193 public:
194 clod_point_renderer();
195
196 render_style* create_render_style() const;
197
198 bool init(context& ctx);
199
201 bool enable(context& ctx);
202
203 bool enable(context& ctx, const mat4& reduction_model_view_matrix);
204
205 bool enable_buffer_manager(clod_point_buffer_manager& manager);
206
207 void disable_buffer_manager();
208
209 bool disable(context& ctx);
210
211 void clear(cgv::render::context& ctx);
212
214 void draw(context& ctx, size_t start=0, size_t count=0);
215
216 bool render(context& ctx, size_t start, size_t count);
217
219 void set_points(cgv::render::context& ctx, const Point* pnts, const size_t num_points);
220
227 void set_points(cgv::render::context& ctx, const vec3* positions, const rgb8* colors, const uint8_t* lods, const size_t num_points, const unsigned stride = 0);
228 /*
229 // sets an already existing buffer as input
230 void set_points(cgv::render::context& ctx, GLint input_buffer, const size_t num_points);
231
232
233 */
234 void set_frustum_extend(const float& fe);
235
236 void set_max_drawn_points(cgv::render::context& ctx, const unsigned max_points);
237
238 //sets the pivot point in view space coordinates
239 void set_pivot_point(const vec4& pivot);
240
241 void set_render_style(const render_style& rs);
242
243 void manage_singelton(context& ctx, const std::string& renderer_name, int& ref_count, int ref_count_change);
244
246 void set_prog(shader_program& one_shot_prog);
247
248
249 /* methods for step wise operation*/
250
253 void reduce_buffer_init(context& ctx, bool reset_parameters = true);
255 void reduce_buffer(context& ctx, const GLuint buffer,const GLuint point_id_buffer, size_t start, size_t count);
256
257 void reduce_buffer_finish(context& ctx);
258
260 void reduce_points(context& ctx, size_t start, size_t count);
265 void reduce_chunks(context& ctx, const uint32_t* chunk_starts, const uint32_t* chunk_point_counts, const uint32_t* reduction_sources, uint32_t num_reduction_sources);
266
268 void draw_points(context& ctx);
269
270 public:
272 unsigned int num_reduced_points();
273
274 private:
275 void add_shader(context& ctx, shader_program& prog, const std::string& sf, const cgv::render::ShaderType st);
276 void clear_buffers(context& ctx);
277 static void reset_draw_parameters(context& ctx, GLuint draw_parameter_buffer);
278 };
279
280
282 {
283 bool self_reflect(cgv::reflect::reflection_handler& rh);
284 };
286
287 }
288}
289#include <cgv/config/lib_end.h>
color()
standard constructor does not initialize components
Definition color.h:589
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
ShaderType
different shader types
Definition context.h:485
the cgv namespace
Definition print.h:11
this reflection traits implementation is used for external self_reflect implementations of instances ...
render style for sphere rendere
float spacing
:= root spacing, match this to your inputs point spacing in the octrees root level,...
uint8_t & level()
returns the level of detail
const uint8_t & level() const
return the level of detail
base class for all render styles
Definition renderer.h:16