cgv
Loading...
Searching...
No Matches
box_wire_renderer.h
1#pragma once
2
3#include "line_renderer.h"
4
5#include "gl/lib_begin.h"
6
7namespace cgv { // @<
8 namespace render { // @<
9 class CGV_API box_wire_renderer;
10
12
15 extern CGV_API box_wire_renderer& ref_box_wire_renderer(context& ctx, int ref_count_change = 0);
16
19 {
21 vec3 default_extent = { 1.0f };
23 vec3 relative_anchor = { 0.0f };
24 };
25
27 class CGV_API box_wire_renderer : public line_renderer
28 {
29 protected:
30 bool has_extents = false;
32 bool has_translations = false;
34 bool has_rotations = false;
36 bool position_is_center = true;
38 std::string get_default_prog_name() const override { return "box_wire.glpr"; }
40 render_style* create_render_style() const override { return new box_wire_render_style(); }
41 public:
43 void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam) override;
45 void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam) override;
47 void set_position_is_center(bool _position_is_center);
49 bool enable(context& ctx) override;
51 template <typename T>
52 void set_extent(const context& ctx, const T& extent) { has_extents = true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx, "extent"), extent); }
54 template <typename T>
55 void set_extent_array(const context& ctx, const std::vector<T>& extents) { has_extents = true; set_attribute_array(ctx, "extent", extents); }
57 template <typename T>
58 void set_extent_array(const context& ctx, const T* extents, size_t nr_elements, unsigned stride_in_bytes = 0) { has_extents = true; set_attribute_array(ctx, "extent", extents, nr_elements, stride_in_bytes); }
60 void remove_extent_array(const context& ctx);
62 template <typename T>
63 void set_box(const context& ctx, const cgv::media::axis_aligned_box<T, 3>& box) {
64 set_position(ctx, box.get_min_pnt());
65 set_extent(ctx, box.get_max_pnt());
66 set_position_is_center(false);
67 }
69 template <typename T>
70 void set_box_array(const context& ctx, const std::vector<cgv::media::axis_aligned_box<T, 3> > & boxes) {
71 set_composed_attribute_array(ctx, "position", &boxes.front(), boxes.size(), boxes[0].get_min_pnt());
72 ref_composed_attribute_array(ctx, "extent", "position", &boxes.front(), boxes.size(), boxes[0].get_max_pnt());
73 has_positions = true;
74 has_extents = true;
75 set_position_is_center(false);
76 }
78 template <typename T>
79 void set_box_array(const context& ctx, const cgv::media::axis_aligned_box<T, 3> * boxes, size_t count) {
80 set_composed_attribute_array(ctx, "position", boxes, count, boxes[0].get_min_pnt());
81 ref_composed_attribute_array(ctx, "extent", "position", boxes, count, boxes[0].get_max_pnt());
82 has_positions = true;
83 has_extents = true;
84 set_position_is_center(false);
85 }
87 template <typename T>
88 void set_translation_array(const context& ctx, const std::vector<T>& translations) { has_translations = true; set_attribute_array(ctx, "translation", translations); }
90 template <typename T>
91 void set_translation_array(const context& ctx, const T* translations, size_t nr_elements, unsigned stride_in_bytes = 0) { has_translations = true; set_attribute_array(ctx, "translation", translations, nr_elements, stride_in_bytes); }
93 void remove_translation_array(const context& ctx);
95 template <typename T>
96 void set_rotation_array(const context& ctx, const std::vector<T>& rotations) { has_rotations = true; set_attribute_array(ctx, "rotation", rotations); }
98 template <typename T>
99 void set_rotation_array(const context& ctx, const T* rotations, size_t nr_elements, unsigned stride_in_bytes = 0) { has_rotations = true; set_attribute_array(ctx, "rotation", rotations, nr_elements, stride_in_bytes); }
101 void remove_rotation_array(const context& ctx);
103 bool disable(context& ctx) override;
105 void draw(context& ctx, size_t start, size_t count,
106 bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1) override;
107 };
109 {
110 bool self_reflect(cgv::reflect::reflection_handler& rh);
111 };
113 }
114}
115
116#include <cgv/config/lib_end.h>
An axis aligned box, defined by to points: min and max.
const fpnt_type & get_max_pnt() const
return a const reference to corner 7
const fpnt_type & get_min_pnt() const
return a const reference to corner 0
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
attribute array manager used to upload arrays to gpu
renderer that supports point splatting
void set_extent_array(const context &ctx, const T *extents, size_t nr_elements, unsigned stride_in_bytes=0)
extent array specifies box extends in case of position_is_center=true, otherwise the maximum point of...
void set_rotation_array(const context &ctx, const std::vector< T > &rotations)
template method to set the rotation from a vector of quaternions of type T, which should have 4 compo...
void set_translation_array(const context &ctx, const std::vector< T > &translations)
template method to set the translations from a vector of vectors of type T, which should have 3 compo...
render_style * create_render_style() const override
create and return the default render style
void set_box(const context &ctx, const cgv::media::axis_aligned_box< T, 3 > &box)
specify a single box. This sets position_is_center to false as well as position and extent attributes
void set_box_array(const context &ctx, const std::vector< cgv::media::axis_aligned_box< T, 3 > > &boxes)
specify box array directly. This sets position_is_center to false as well as position and extent arra...
void set_box_array(const context &ctx, const cgv::media::axis_aligned_box< T, 3 > *boxes, size_t count)
specify box array directly. This sets position_is_center to false as well as position and extent arra...
void set_extent(const context &ctx, const T &extent)
specify a single extent for all boxes
void set_translation_array(const context &ctx, const T *translations, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the translations from a vector of vectors of type T, which should have 3 compo...
void set_rotation_array(const context &ctx, const T *rotations, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the rotation from a vector of quaternions of type T, which should have 4 compo...
std::string get_default_prog_name() const override
return the default shader program name
void set_extent_array(const context &ctx, const std::vector< T > &extents)
extent array specifies box extends in case of position_is_center=true, otherwise the maximum point of...
base class for all drawables, which is independent of the used rendering API.
Definition context.h:627
renderer that supports point splatting
box_wire_renderer & ref_box_wire_renderer(context &ctx, int ref_count_change)
reference to a singleton box_wire renderer that can be shared among drawables
the cgv namespace
Definition print.h:11
this reflection traits implementation is used for external self_reflect implementations of instances ...
box wires extend line render styles
base class for all render styles
Definition renderer.h:16