cgv
surface_renderer.h
1 #pragma once
2 
3 #include "group_renderer.h"
4 #include <cgv_reflect_types/media/illum/textured_surface_material.h>
5 #include <cgv/media/illum/textured_surface_material.h>
6 
7 #include "gl/lib_begin.h"
8 
9 namespace cgv { // @<
10  namespace render { // @<
11 
13  enum ColorMapping {
14  CM_NONE = 0,
15  CM_COLOR_FRONT = 1,
16  CM_COLOR_BACK = 2,
17  CM_COLOR = CM_COLOR_FRONT | CM_COLOR_BACK,
18  CM_OPACITY_FRONT = 4,
19  CM_OPACITY_BACK = 8,
20  CM_OPACITY = CM_OPACITY_FRONT | CM_OPACITY_BACK,
21  CM_COLOR_AND_OPACITY = CM_COLOR | CM_OPACITY
22  };
23 
25  struct CGV_API surface_render_style : public group_render_style
26  {
39  };
40 
42  class CGV_API surface_renderer : public group_renderer
43  {
44  protected:
45  bool has_normals;
46  bool has_texcoords;
47  bool cull_per_primitive;
48  public:
51  void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
53  void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
55  bool enable(context& ctx);
57  bool disable(context& ctx);
59  template <typename T>
60  void set_normal(const context& ctx, const cgv::math::fvec<T, 3>& normal) { has_normals = true; ref_prog().set_attribute(ctx, ref_prog().get_attribute_location(ctx, "normal"), normal); }
62  template <typename T>
63  void set_normal_array(const context& ctx, const std::vector<T>& normals) { has_normals = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "normal"), normals); }
65  template <typename T>
66  void set_normal_array(const context& ctx, const T* normals, size_t nr_elements, unsigned stride_in_bytes = 0) { has_normals = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "normal"), normals, nr_elements, stride_in_bytes); }
68  void set_normal_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 = 0);
70  template <typename T>
71  void set_normal_array(const context& ctx, const vertex_buffer& vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes = 0) { set_normal_array(ctx, type_descriptor(element_descriptor_traits<T>::get_type_descriptor(T()), true), vbo, offset_in_bytes, nr_elements, stride_in_bytes); }
73  template <typename T>
74  void set_texcoord(const context& ctx, const T& texcoord) { has_texcoords = true; ref_prog().set_attribute(ctx, ref_prog().get_texcoord_index(), texcoord); }
76  template <typename T>
77  void set_texcoord_array(const context& ctx, const std::vector<T>& texcoords) { has_texcoords = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "texcoord"), texcoords); }
79  template <typename T>
80  void set_texcoord_array(const context& ctx, const T* texcoords, size_t nr_elements, unsigned stride_in_bytes = 0) { has_texcoords = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "texcoord"), texcoords, nr_elements, stride_in_bytes); }
82  void set_texcoord_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 = 0);
84  template <typename T>
85  void set_texcoord_array(const context& ctx, const vertex_buffer& vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes = 0) { set_texcoord_array(ctx, type_descriptor(element_descriptor_traits<T>::get_type_descriptor(T()), true), vbo, offset_in_bytes, nr_elements, stride_in_bytes); }
86  };
87  struct CGV_API surface_render_style_reflect : public surface_render_style
88  {
89  bool self_reflect(cgv::reflect::reflection_handler& rh);
90  };
91  extern CGV_API cgv::reflect::extern_reflection_traits<surface_render_style, surface_render_style_reflect> get_reflection_traits(const surface_render_style&);
92  }
93 }
94 
95 #include <cgv/config/lib_end.h>
cgv::render::surface_render_style::map_color_to_material
ColorMapping map_color_to_material
material side[s] where color is to be mapped to the diffuse material component, defaults to MS_FRONT_...
Definition: surface_renderer.h:34
cgv::render::type_descriptor
compact type description of data that can be sent to the context; convertible to int
Definition: context.h:36
cgv::render::surface_render_style::surface_color
cgv::media::illum::surface_material::color_type surface_color
default value for color when map color to material is used
Definition: surface_renderer.h:28
cgv::math::fvec< T, 3 >
cgv::render::vertex_buffer
Definition: vertex_buffer.h:13
cgv::render::surface_render_style
Definition: surface_renderer.h:26
cgv::render::surface_renderer::set_normal
void set_normal(const context &ctx, const cgv::math::fvec< T, 3 > &normal)
specify a single normal for all lines
Definition: surface_renderer.h:60
cgv::render::group_render_style
Definition: group_renderer.h:15
cgv::render::surface_renderer::set_texcoord_array
void set_texcoord_array(const context &ctx, const T *texcoords, size_t nr_elements, unsigned stride_in_bytes=0)
templated method to set the texcoord attribute from an array of texcoords of type T
Definition: surface_renderer.h:80
cgv::render::surface_render_style::culling_mode
CullingMode culling_mode
culling mode for point splats, set to CM_OFF in constructor
Definition: surface_renderer.h:30
cgv::render::attribute_array_manager
attribute array manager used to upload arrays to gpu
Definition: renderer.h:21
cgv::render::surface_renderer::set_normal_array
void set_normal_array(const context &ctx, const std::vector< T > &normals)
templated method to set the normal attribute array from a vector of normals of type T,...
Definition: surface_renderer.h:63
cgv::media::color< float, RGB >
cgv::reflect::reflection_handler
Definition: reflection_handler.h:63
cgv::render::surface_render_style::material
cgv::media::illum::textured_surface_material material
material of surface
Definition: surface_renderer.h:36
cgv::render::surface_renderer::set_texcoord_array
void set_texcoord_array(const context &ctx, const vertex_buffer &vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the texcoord attribute from a vertex buffer object, the element type must be g...
Definition: surface_renderer.h:85
cgv::render::surface_renderer
base classes for renderers that support surface rendering
Definition: surface_renderer.h:43
cgv::render::surface_render_style::illumination_mode
IlluminationMode illumination_mode
illumination mode defaults to IM_ONE_SIDED
Definition: surface_renderer.h:32
cgv::reflect::extern_reflection_traits
this reflection traits implementation is used for external self_reflect implementations of instances ...
Definition: reflect_extern.h:28
cgv::render::ColorMapping
ColorMapping
color and opacity can be mapped independently to surface material
Definition: surface_renderer.h:13
cgv::render::CullingMode
CullingMode
different culling modes
Definition: context.h:121
cgv::render::IlluminationMode
IlluminationMode
different illumination modes
Definition: context.h:116
cgv::media::illum::textured_surface_material
simple class to hold the material properties of a phong material
Definition: textured_surface_material.h:15
cgv::render::surface_renderer::set_normal_array
void set_normal_array(const context &ctx, const T *normals, size_t nr_elements, unsigned stride_in_bytes=0)
templated method to set the normal attribute from an array of normals of type T, which should have 3 ...
Definition: surface_renderer.h:66
cgv::render::surface_renderer::set_normal_array
void set_normal_array(const context &ctx, const vertex_buffer &vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the normal attribute from a vertex buffer object, the element type must be giv...
Definition: surface_renderer.h:71
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::render::context
Definition: context.h:525
cgv::render::surface_renderer::set_texcoord
void set_texcoord(const context &ctx, const T &texcoord)
templated method to set the texcoord attribute without array
Definition: surface_renderer.h:74
cgv::render::surface_renderer::set_texcoord_array
void set_texcoord_array(const context &ctx, const std::vector< T > &texcoords)
templated method to set the texcoord attribute array from a vector of texcoords of type T
Definition: surface_renderer.h:77
cgv::render::group_renderer
abstract renderer class that provides functionality for grouping primitives
Definition: group_renderer.h:26