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
24 class CGV_API surface_renderer;
25
27
30 extern CGV_API surface_renderer& ref_surface_renderer(context& ctx, int ref_count_change = 0);
31
34 {
38 float surface_opacity = 1.0f;
40 CullingMode culling_mode = CM_OFF;
42 IlluminationMode illumination_mode = IM_ONE_SIDED;
44 ColorMapping map_color_to_material = CM_COLOR;
48 int max_nr_lights = 2;
49 };
50
52 class CGV_API surface_renderer : public group_renderer
53 {
54 protected:
55 bool has_normals = false;
56 bool has_texcoords = false;
57 bool cull_per_primitive = true;
59 std::string get_default_prog_name() const override { return "textured_surface.glpr"; }
61 render_style* create_render_style() const override { return new surface_render_style(); }
63 void update_shader_program_options(shader_compile_options& options) const override;
65 bool build_shader_program(context& ctx, shader_program& prog, const shader_compile_options& options) const override;
66 public:
68 void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam) override;
70 void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam) override;
72 bool enable(context& ctx) override;
74 bool disable(context& ctx) override;
76 template <typename T>
77 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); }
79 template <typename T>
80 void set_normal_array(const context& ctx, const std::vector<T>& normals) { has_normals = true; set_attribute_array(ctx, "normal", normals); }
82 template <typename T>
83 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); }
85 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);
87 template <typename T>
88 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); }
90 void remove_normal_array(const context& ctx);
92 template <typename T>
93 void set_texcoord(const context& ctx, const T& texcoord) { has_texcoords = true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx, "texcoord"), texcoord); }
95 template <typename T>
96 void set_texcoord_array(const context& ctx, const std::vector<T>& texcoords) { has_texcoords = true; set_attribute_array(ctx, "texcoord", texcoords); }
98 template <typename T>
99 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); }
101 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);
103 template <typename T>
104 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); }
106 void remove_texcoord_array(const context& ctx);
107 };
109 {
110 bool self_reflect(cgv::reflect::reflection_handler& rh);
111 };
113 }
114}
115
116#include <cgv/config/lib_end.h>
A vector with zero based index.
Definition fvec.h:29
Stores properties of a surface material with support for texturing.
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:670
abstract renderer class that provides functionality for grouping primitives
Stores preprocessor options used for conditionally compiling shader programs.
Definition shader_code.h:73
a shader program combines several shader code fragments to a complete definition of the shading pipel...
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
std::string get_default_prog_name() const override
return the default shader program name
void set_normal(const context &ctx, const cgv::math::fvec< T, 3 > &normal)
specify a single normal for all lines
render_style * create_render_style() const override
create and return the default render style
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:199
IlluminationMode
different illumination modes
Definition context.h:192
surface_renderer & ref_surface_renderer(context &ctx, int ref_count_change)
reference to a singleton surface renderer that can be shared among drawables
ColorMapping
color and opacity can be mapped independently to surface material
this header is dependency free
Definition print.h:11
this reflection traits implementation is used for external self_reflect implementations of instances ...
render style used for group information
base class for all render styles
Definition renderer.h:16
cgv::media::illum::textured_surface_material material
material of surface
compact type description of data that can be sent to the context; convertible to int
Definition context.h:61