1#include "rectangle_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
14 "RTM_MULTIPLY_SECONDARY_COLOR,"
15 "RTM_MULTIPLY_BORDER_COLOR,"
16 "RTM_MIX_COLOR_AND_SECONDARY_COLOR,"
17 "RTM_MIX_COLOR_AND_BORDER_COLOR,"
18 "RTM_MIX_SECONDARY_COLOR_AND_COLOR,"
19 "RTM_MIX_BORDER_COLOR_AND_COLOR,"
20 "RTM_RED_MIX_COLOR_AND_SECONDARY_COLOR,"
21 "RTM_RED_MIX_COLOR_AND_BORDER_COLOR,"
22 "RTM_RED_MIX_SECONDARY_COLOR_AND_COLOR,"
23 "RTM_RED_MIX_BORDER_COLOR_AND_COLOR"
38 static int ref_count = 0;
64 rectangle_renderer::rectangle_renderer() {
71 has_texcoords =
false;
76 void rectangle_renderer::set_y_view_angle(
float _y_view_angle)
78 y_view_angle = _y_view_angle;
84 set_attribute_array(ctx,
"secondary_color", element_type, vbo, offset_in_bytes, nr_elements, stride_in_bytes);
89 set_attribute_array(ctx,
"border_color", element_type, vbo, offset_in_bytes, nr_elements, stride_in_bytes);
91 void rectangle_renderer::rectangle_renderer::set_border_info_array(
const context& ctx,
type_descriptor element_type,
const vertex_buffer& vbo,
size_t offset_in_bytes,
size_t nr_elements,
unsigned stride_in_bytes)
93 has_border_infos =
true;
94 set_attribute_array(ctx,
"border_info", element_type, vbo, offset_in_bytes, nr_elements, stride_in_bytes);
98 remove_attribute_array(ctx,
"extent");
102 remove_attribute_array(ctx,
"secondary_color");
106 remove_attribute_array(ctx,
"border_color");
110 remove_attribute_array(ctx,
"border_info");
114 remove_attribute_array(ctx,
"depth_offset");
118 remove_attribute_array(ctx,
"translation");
122 remove_attribute_array(ctx,
"rotation");
158 has_texcoords =
true;
167 return prog.
build_program(ctx,
"rectangle.glpr",
true, defines);
176 get_style<rectangle_render_style>().position_is_center = _position_is_center;
183 ctx.
error(
"rectangle_renderer::enable() extent attribute not set");
210 ref_prog().
set_uniform(ctx,
"position_is_center", get_style<rectangle_render_style>().position_is_center);
238 draw_impl(ctx, PT_POINTS, start, count,
false,
false, -1);
263#include <cgv/gui/provider.h>
272 void* value_ptr,
const std::string& value_type,
273 const std::string& gui_type,
const std::string& options,
bool*)
286 "enums='Separate=0,Width,Height,Minimum Width/Height'");
289 "enums='Replace,Replace Alpha,Multiply Color,Multiply Secondary Color,Multiply Border Color,"
290 "Mix Color and Secondary Color,Mix Color and Border Color,Mix Secondary Color and Color,Mix Border Color and Color,"
291 "Red Mix Color and Secondary Color,Red Mix Color and Border Color,Red Mix Secondary Color and Color,Red Mix Border Color and Color'");
306#include "gl/lib_begin.h"
base class for all classes that can be registered with support for dynamic properties (see also secti...
helper template for registration of gui creators
derive from this class to provide a gui to the current viewer
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.
void align(const std::string &_align)
send pure alignment information
bool begin_tree_node(const std::string &label, const T &value, bool initial_visibility=false, const std::string &options="", gui_group_ptr ggp=gui_group_ptr())
Begin a sub tree of a tree structured gui.
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
void end_tree_node(const T &value)
template specialization that allows to specify value reference plus node_instance by using the result...
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.
void set_blend_func_back_to_front()
set the default blend function for back to front blending
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
void push_blend_state()
push a copy of the current blend state onto the stack saved attributes: blend enablement,...
void pop_blend_state()
pop the top of the current culling state from the stack
virtual unsigned int get_height() const =0
return the height of the window
virtual void enable_blending()
enable blending
bool validate_attributes(const context &ctx) const
check additionally the group attributes
renderer that supports plane rendering
void draw(context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
convenience function to render with default settings
void remove_secondary_color_array(const context &ctx)
remove the secondary color attribute
bool has_extents
whether extent array has been specified
bool build_shader_program(context &ctx, shader_program &prog, const shader_define_map &defines)
build rectangle program
void remove_depth_offset_array(const context &ctx)
remove the depth offset attribute
void set_border_color_array(const context &ctx, const std::vector< T > &colors)
template method to set the border color attribute from a vector of colors of type T
bool has_border_colors
whether border color or color array was set
render_style * create_render_style() const
overload to allow instantiation of rectangle_renderer
bool validate_attributes(const context &ctx) const
check additionally the group attributes
bool has_secondary_colors
whether secondary color or color array was set
void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam)
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
bool has_depth_offsets
whether depth offset array has been specified
void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam)
call this before setting attribute arrays to manage attribute array in given manager
void remove_border_info_array(const context &ctx)
remove the border info attribute
bool init(context &ctx)
call init() once before using renderer
bool enable(context &ctx)
overload to activate group style
void remove_rotation_array(const context &ctx)
remove the rotation attribute
void remove_translation_array(const context &ctx)
remove the translation attribute
bool has_border_infos
whether border info or info array was set
bool disable(context &ctx)
disable renderer
bool has_translations
whether translation array has been specified
void set_secondary_color_array(const context &ctx, const std::vector< T > &colors)
template method to set the secondary color attribute from a vector of colors of type T
void remove_extent_array(const context &ctx)
remove the extent attribute
void remove_border_color_array(const context &ctx)
remove the border color attribute
void set_position_is_center(bool _position_is_center)
set the flag of the render style, whether the position is interpreted as the box center
bool has_rotations
whether rotation array has been specified
void set_textured_rectangle(const context &ctx, const textured_rectangle &tcr)
specify rectangle without array. This sets position_is_center to false as well as position and extent...
void manage_singleton(context &ctx, const std::string &renderer_name, int &ref_count, int ref_count_change)
used by derived classes to manage singletons
bool has_attribute(const context &ctx, const std::string &name)
check for attribute
virtual bool init(context &ctx)
call init() once before using renderer
shader_program & ref_prog()
derived renderer classes have access to shader program
bool has_positions
track whether position attribute is defined
bool attributes_persist() const
return whether attributes persist after a call to disable
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...
a shader program combines several shader code fragments to a complete definition of the shading pipel...
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,...
int get_attribute_location(const context &ctx, const std::string &name) const
query location index of an attribute
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...
bool build_program(const context &ctx, const std::string &file_name, bool show_error=false, const shader_define_map &defines=shader_define_map())
successively calls create, attach_program and link.
void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam)
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam)
call this before setting attribute arrays to manage attribute array in given manager
bool disable(context &ctx)
disable renderer
bool enable(context &ctx)
overload to activate group style
a vertex buffer is an unstructured memory block on the GPU.
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
rectangle_renderer & ref_rectangle_renderer(context &ctx, int ref_count_change)
reference to a singleton plane renderer that can be shared among drawables
RectangleTextureMode
different modes to use texture during rectangle rendering
RectangleBoderMode
different modes to compute relative border with for rectangle rendering
DummyEnum
some enum to mark an integral parameter to be of enum type
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > rgba
declare rgba color type with 32 bit components
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
interface for gui creators
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
this type specific reflection traits class is used by the reflect_enum function to reflect enum types
this reflection traits implementation is used for external self_reflect implementations of instances ...
bool use_group_color
whether to use group colors indexed through group index, defaults to false
configuration of rectangle renderer
rgba default_secondary_color
default value of secondary color which is ignored if set_secondary_color_array() is used to set per r...
bool blend_rectangles
if true the renderer enables blending in the enable method and recovers previous blending mode on dis...
RectangleBoderMode border_mode
different modes of computing the width of the border (default: RBM_MIN)
float pixel_blend
number of pixels around the rectangle splat used for antialiasing (default: 0.0f)
RectangleTextureMode texture_mode
mode of using texture during rastrization (default: RTM_REPLACE)
bool position_is_center
flag whether position attribute is the rectangle center; otherwise position is lower left corner (def...
float border_width_in_pixel
border width measured in pixels (default: 0)
rgba default_border_color
default value for the border color attribute which is ignored when set_border_color_array() is used t...
rectangle_render_style()
default constructor initializes members as specified in member comments
float default_depth_offset
default depth offset added to depth value of fragment. (default: 0.0f)
float percentual_border_width
border width measured relative to rectangle extent computed according to current border_mode (default...
base class for all render styles
This type provides a simple helper class to store rectangles with texture coordinates.
compact type description of data that can be sent to the context; convertible to int
traits class with a static function get_name() of type const char* that returns the type name of the ...