cgv
Loading...
Searching...
No Matches
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
9namespace cgv { // @<
10 namespace render { // @<
11
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
42
44 class CGV_API surface_renderer : public group_renderer
45 {
46 protected:
47 bool has_normals;
48 bool has_texcoords;
49 bool cull_per_primitive;
50 public:
53 void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
55 void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
57 bool enable(context& ctx);
59 bool disable(context& ctx);
61 template <typename T>
62 void set_normal(const context& ctx, const cgv::math::fvec<T, 3>& normal) { has_normals = true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx, "normal"), normal); }
64 template <typename T>
65 void set_normal_array(const context& ctx, const std::vector<T>& normals) { has_normals = true; set_attribute_array(ctx, "normal", normals); }
67 template <typename T>
68 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, "normal", normals, nr_elements, stride_in_bytes); }
70 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);
72 template <typename T>
73 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); }
75 void remove_normal_array(const context& ctx);
77 template <typename T>
78 void set_texcoord(const context& ctx, const T& texcoord) { has_texcoords = true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx, "texcoord"), texcoord); }
80 template <typename T>
81 void set_texcoord_array(const context& ctx, const std::vector<T>& texcoords) { has_texcoords = true; set_attribute_array(ctx, "texcoord", texcoords); }
83 template <typename T>
84 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, "texcoord", texcoords, nr_elements, stride_in_bytes); }
86 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);
88 template <typename T>
89 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); }
91 void remove_texcoord_array(const context& ctx);
92 };
94 {
95 bool self_reflect(cgv::reflect::reflection_handler& rh);
96 };
98 }
99}
100
101#include <cgv/config/lib_end.h>
A vector with zero based index.
Definition fvec.h:27
simple class to hold the material properties of a phong material
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
base class for all drawables, which is independent of the used rendering API.
Definition context.h:626
abstract renderer class that provides functionality for grouping primitives
base classes for renderers that support surface rendering
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
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
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,...
void set_texcoord(const context &ctx, const T &texcoord)
templated method to set the texcoord attribute without array
void set_normal(const context &ctx, const cgv::math::fvec< T, 3 > &normal)
specify a single normal for all lines
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...
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...
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 ...
a vertex buffer is an unstructured memory block on the GPU.
CullingMode
different culling modes
Definition context.h:151
IlluminationMode
different illumination modes
Definition context.h:144
ColorMapping
color and opacity can be mapped independently to surface material
the cgv namespace
Definition print.h:11
this reflection traits implementation is used for external self_reflect implementations of instances ...
render style used for group information
CullingMode culling_mode
culling mode for point splats, set to CM_OFF in constructor
float surface_opacity
default value for the surface opacity when map color to material is used
ColorMapping map_color_to_material
material side[s] where color is to be mapped to the diffuse material component, defaults to MS_FRONT_...
IlluminationMode illumination_mode
illumination mode defaults to IM_ONE_SIDED
cgv::media::illum::textured_surface_material material
material of surface
cgv::media::illum::surface_material::color_type surface_color
default value for color when map color to material is used
compact type description of data that can be sent to the context; convertible to int
Definition context.h:55