1#include "cone_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
9 static int ref_count = 0;
28 enable_texturing =
false;
29 texture_blend_mode = TBM_MIX;
30 texture_blend_factor = 1.0f;
31 texture_tile_from_center =
false;
32 texture_offset =
vec2(0.0f);
33 texture_tiling =
vec2(1.0f);
34 texture_use_reference_length =
false;
35 texture_reference_length = 1.0f;
37 enable_ambient_occlusion =
false;
42 tex_offset =
vec3(0.0f);
43 tex_scaling =
vec3(1.0f);
44 tex_coord_scaling =
vec3(1.0f);
47 cone_angle_factor = 1.0f;
48 sample_dirs.resize(3);
49 sample_dirs[0] =
vec3(0.0f, 1.0f, 0.0f);
50 sample_dirs[1] =
vec3(0.0f, 1.0f, 0.0f);
51 sample_dirs[2] =
vec3(0.0f, 1.0f, 0.0f);
58 albedo_texture =
nullptr;
59 density_texture =
nullptr;
77 remove_attribute_array(ctx,
"radius");
88 shader_code::set_define(defines,
"CAPS", crs.show_caps,
true);
89 shader_code::set_define(defines,
"CAP_TYPE", crs.rounded_caps,
false);
90 shader_code::set_define(defines,
"ENABLE_TEXTURING", crs.enable_texturing,
false);
91 shader_code::set_define(defines,
"TEXTURE_BLEND_MODE", crs.texture_blend_mode, cone_render_style::TBM_MIX);
92 shader_code::set_define(defines,
"TEXTURE_TILE_FROM_CENTER", crs.texture_tile_from_center,
false);
93 shader_code::set_define(defines,
"TEXTURE_USE_REFERENCE_LENGTH", crs.texture_use_reference_length,
false);
94 shader_code::set_define(defines,
"ENABLE_AMBIENT_OCCLUSION", crs.enable_ambient_occlusion,
false);
100 bool cone_renderer::set_albedo_texture(
texture* tex)
104 albedo_texture = tex;
107 bool cone_renderer::set_density_texture(texture* tex)
109 if(!tex || tex->get_nr_dimensions() != 3)
111 density_texture = tex;
129 if(crs.enable_texturing && !albedo_texture)
132 if(crs.enable_ambient_occlusion && !density_texture)
135 if(crs.enable_ambient_occlusion) {
152 albedo_texture->
enable(ctx, 0);
154 if(density_texture) density_texture->
enable(ctx, 1);
161 if(albedo_texture) albedo_texture->
disable(ctx);
162 if(density_texture) density_texture->
disable(ctx);
179 draw_impl(ctx, PT_LINES, start, count, use_strips, use_adjacency, strip_restart_index);
185 albedo_texture =
nullptr;
186 density_texture =
nullptr;
196#include <cgv/gui/provider.h>
204 void* value_ptr,
const std::string& value_type,
205 const std::string& gui_type,
const std::string& options,
bool*) {
211 p->
add_member_control(b,
"Default Radius", crs_ptr->
radius,
"value_slider",
"min=0.001;step=0.0001;max=10.0;log=true;ticks=true");
217 if(p->
begin_tree_node(
"Texturing", crs_ptr->enable_texturing,
false,
"level=3")) {
220 p->
add_member_control(b,
"Blend Mode", crs_ptr->texture_blend_mode,
"dropdown",
"enums='Mix,Tint,Multiply,Inverse Multiply,Add'");
221 p->
add_member_control(b,
"Blend Factor", crs_ptr->texture_blend_factor,
"value_slider",
"min=0.0;step=0.0001;max=1.0;ticks=true");
225 p->
add_member_control(b,
"Tile from Center", crs_ptr->texture_tile_from_center,
"check");
227 p->
add_member_control(b,
"Offset", crs_ptr->texture_offset[0],
"value",
"w=95;min=-1;max=1;step=0.001",
" ");
228 p->
add_member_control(b,
"", crs_ptr->texture_offset[1],
"value",
"w=95;min=-1;max=1;step=0.001");
229 p->
add_member_control(b,
"", crs_ptr->texture_offset[0],
"slider",
"w=95;min=-1;max=1;step=0.001;ticks=true",
" ");
230 p->
add_member_control(b,
"", crs_ptr->texture_offset[1],
"slider",
"w=95;min=-1;max=1;step=0.001;ticks=true");
232 p->
add_member_control(b,
"Tiling", crs_ptr->texture_tiling[0],
"value",
"w=95;min=-5;max=5;step=0.001",
" ");
233 p->
add_member_control(b,
"", crs_ptr->texture_tiling[1],
"value",
"w=95;min=-5;max=5;step=0.001");
234 p->
add_member_control(b,
"", crs_ptr->texture_tiling[0],
"slider",
"w=95;min=-5;max=5;step=0.001;ticks=true",
" ");
235 p->
add_member_control(b,
"", crs_ptr->texture_tiling[1],
"slider",
"w=95;min=-5;max=5;step=0.001;ticks=true");
237 p->
add_member_control(b,
"Use Reference Length", crs_ptr->texture_use_reference_length,
"check");
238 p->
add_member_control(b,
"Reference Length", crs_ptr->texture_reference_length,
"value_slider",
"min=0.0;step=0.0001;max=5.0;log=true;ticks=true");
244 if(p->
begin_tree_node(
"Ambient Occlusion", crs_ptr->enable_ambient_occlusion,
false,
"level=3")) {
247 p->
add_member_control(b,
"Offset", crs_ptr->ao_offset,
"value_slider",
"min=0.0;step=0.0001;max=0.2;log=true;ticks=true");
248 p->
add_member_control(b,
"Distance", crs_ptr->ao_distance,
"value_slider",
"min=0.0;step=0.0001;max=1.0;log=true;ticks=true");
249 p->
add_member_control(b,
"Strength", crs_ptr->ao_strength,
"value_slider",
"min=0.0;step=0.0001;max=10.0;log=true;ticks=true");
258#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
renderer that supports raycasting of cones
render_style * create_render_style() const
overload to allow instantiation of cone_renderer
void update_defines(shader_define_map &defines)
update shader defines based on render style
virtual void clear(const context &ctx)
the clear function destructs the shader program and resets the texture pointers
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 disable(context &ctx)
disable renderer
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
shader_define_map shader_defines
the shader defines used to build the shader, used to comapre against new defines to determine if the ...
bool build_shader_program(context &ctx, shader_program &prog, const shader_define_map &defines)
build cone program
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_radius_array(const context &ctx)
remove the radius attribute
cone_renderer()
initializes member variables
bool validate_attributes(const context &ctx) const
call to validate, whether essential position attribute is defined
bool enable(context &ctx)
enables renderer
base class for all drawables, which is independent of the used rendering API.
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
bool has_attribute(const context &ctx, const std::string &name)
check for attribute
shader_program & ref_prog()
derived renderer classes have access to shader program
virtual void clear(const context &ctx)
the clear function destructs the shader program
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,...
bool set_uniform_array(const context &ctx, const std::string &name, const T &array)
set uniform array from array array where number elements can be derived from array through array_desc...
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
the texture class encapsulates all functionality independent of the rendering api.
bool disable(const context &ctx)
disable texture and restore state from before last enable call
bool enable(const context &ctx, int tex_unit=-1)
enable this texture in the given texture unit, -1 corresponds to the current unit.
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
cone_renderer & ref_cone_renderer(context &ctx, int ref_count_change)
reference to a singleton cone renderer that is shared among drawables
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
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
this reflection traits implementation is used for external self_reflect implementations of instances ...
cone_render_style()
construct with default values
float radius
default value assigned to radius attribute in enable method of cone renderer, set to 1 in constructor
float radius_scale
multiplied to the sphere radii, initialized to 1
base class for all render styles
traits class with a static function get_name() of type const char* that returns the type name of the ...