cgv
Loading...
Searching...
No Matches
ellipsoid_renderer.cxx
1#include "ellipsoid_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4
5namespace cgv {
6 namespace render {
8 {
9 static int ref_count = 0;
10 static ellipsoid_renderer r;
11 r.manage_singleton(ctx, "ellipsoid_renderer", ref_count, ref_count_change);
12 return r;
13 }
14 ellipsoid_renderer::ellipsoid_renderer()
15 {
16 cull_per_primitive = false;
17 }
20 {
22 if (has_attribute(ctx, "size"))
23 has_sizes = true;
24 if (has_attribute(ctx, "orientation"))
25 has_orientations = true;
26 }
29 {
31 has_sizes = false;
32 has_orientations = false;
33 }
35 has_sizes = false;
36 remove_attribute_array(ctx, "size");
37 }
39 has_orientations = false;
40 remove_attribute_array(ctx, "orientation");
41 }
43 {
44 const ellipsoid_render_style& rs = get_style<ellipsoid_render_style>();
46 }
48 {
49 const ellipsoid_render_style& rs = get_style<ellipsoid_render_style>();
50
52 return false;
53
54 if (!ref_prog().is_linked())
55 return false;
56
57 if (!has_sizes)
58 ref_prog().set_attribute(ctx, "size", rs.size);
59
60 if (!has_orientations)
61 ref_prog().set_attribute(ctx, "orientation", cgv::quat());
62
63 ref_prog().set_uniform(ctx, "size_scale", rs.size_scale);
64 return true;
65 }
66
68 {
69 if (!attributes_persist()) {
70 has_sizes = false;
71 has_orientations = false;
72 }
73 return surface_renderer::disable(ctx);
74 }
75
76 void ellipsoid_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
77 {
78 draw_impl(ctx, PT_POINTS, start, count, false, false, -1);
79 }
80
81 bool ellipsoid_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
82 {
83 return
84 rh.reflect_base(*static_cast<surface_render_style*>(this)) &&
85 rh.reflect_member("size_scale", size_scale);
86 }
87
89 {
91 }
92 }
93}
94
95#include <cgv/gui/provider.h>
96
97namespace cgv {
98 namespace gui {
99
101 {
103 bool create(provider* p, const std::string& label,
104 void* value_ptr, const std::string& value_type,
105 const std::string& gui_type, const std::string& options, bool*)
106 {
108 return false;
109 cgv::render::ellipsoid_render_style* rs_ptr = reinterpret_cast<cgv::render::ellipsoid_render_style*>(value_ptr);
110 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
111
112 p->add_member_control(b, "Default Size", rs_ptr->size, "value_slider", "min=0.01;max=100;log=true;ticks=true");
113 p->add_member_control(b, "Size Scale", rs_ptr->size_scale, "value_slider", "min=0.01;max=100;log=true;ticks=true");
114
115 p->add_gui("surface_render_style", *static_cast<cgv::render::surface_render_style*>(rs_ptr));
116 return true;
117 }
118 };
119
120#include "gl/lib_begin.h"
121
122CGV_API cgv::gui::gui_creator_registration<ellipsoid_render_style_gui_creator> ellipsoid_rs_gc_reg("ellipsoid_render_style_gui_creator");
123
124 }
125}
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
helper template for registration of gui creators
Definition gui_creator.h:32
derive from this class to provide a gui to the current viewer
Definition provider.h:64
bool add_gui(const std::string &label, T &value, const std::string &gui_type="", const std::string &options="")
Add a composed gui of the given gui_type for the given value.
Definition provider.h:247
data::ref_ptr< control< T > > add_member_control(cgv::base::base *base_ptr, const std::string &label, T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
add control with callback to cgv::base::on_set method on cgv::gui::control::value_change
Definition provider.h:137
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
bool reflect_base(B &base_ref)
reflect a base class with its members
bool reflect_member(const std::string &member_name, T &member_ref, bool hard_cast=false)
call this to reflect a member by member name and reference to the member.
attribute array manager used to upload arrays to gpu
base class for all drawables, which is independent of the used rendering API.
Definition context.h:627
renderer that supports splatting of ellipsoids
bool validate_attributes(const context &ctx) const override
call to validate, whether essential position attribute is defined
void remove_size_array(const context &ctx)
remove the size attribute
void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
void draw(context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1) override
Draw a range of vertices or indexed elements.
bool enable(context &ctx) override
enables renderer
void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this before setting attribute arrays to manage attribute array in given manager
bool disable(context &ctx) override
disable renderer
void remove_orientation_array(const context &ctx)
remove the orientation attribute
bool validate_attributes(const context &ctx) const
check additionally the group attributes
void manage_singleton(context &ctx, const std::string &renderer_name, int &ref_count, int ref_count_change)
used by derived classes to manage singletons
Definition renderer.cxx:10
bool has_attribute(const context &ctx, const std::string &name)
check for attribute
Definition renderer.h:62
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:79
bool attributes_persist() const
return whether attributes persist after a call to disable
Definition renderer.h:70
void draw_impl(context &ctx, PrimitiveType pt, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
default implementation of draw method with support for indexed rendering and different primitive type...
Definition renderer.cxx:248
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
bool set_attribute(const context &ctx, const std::string &name, const T &value)
set constant default value of a vertex attribute by attribute name, if name does not specify an attri...
void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this before setting attribute arrays to manage attribute array in given manager
void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
bool enable(context &ctx) override
overload to activate group style
bool disable(context &ctx) override
disable renderer
ellipsoid_renderer & ref_ellipsoid_renderer(context &ctx, int ref_count_change)
reference to a singleton ellipsoid renderer that can be shared among drawables
the cgv namespace
Definition print.h:11
bool create(provider *p, const std::string &label, void *value_ptr, const std::string &value_type, const std::string &gui_type, const std::string &options, bool *)
attempt to create a gui and return whether this was successful
interface for gui creators
Definition gui_creator.h:14
this reflection traits implementation is used for external self_reflect implementations of instances ...
render style for ellipsoid rendere
cgv::vec3 size
default value assigned to size attribute in enable method of ellipsoid renderer, set to 1 in construc...
float size_scale
multiplied to the ellipsoid sizes, initialized to 1
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54