1#include "surface_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4#include <cgv_gl/gl/gl_context.h>
12 prog.
set_uniform(ctx, name +
".brdf_type", (
int)material.get_brdf_type());
13 prog.
set_uniform(ctx, name +
".diffuse_reflectance", material.get_diffuse_reflectance());
14 prog.
set_uniform(ctx, name +
".roughness", material.get_roughness());
15 prog.
set_uniform(ctx, name +
".ambient_occlusion", material.get_ambient_occlusion());
16 prog.
set_uniform(ctx, name +
".emission", material.get_emission());
17 prog.
set_uniform(ctx, name +
".specular_reflectance", material.get_specular_reflectance());
18 prog.
set_uniform(ctx, name +
".roughness_anisotropy", material.get_roughness_anisotropy());
19 prog.
set_uniform(ctx, name +
".roughness_orientation", material.get_roughness_orientation());
21 prog.
set_uniform(ctx, name +
".transparency", material.get_transparency());
22 prog.
set_uniform(ctx, name +
".metalness", material.get_metalness());
25 surface_render_style::surface_render_style() : material(
"default")
28 surface_opacity = 1.0f;
29 culling_mode = CM_OFF;
30 illumination_mode = IM_ONE_SIDED;
31 map_color_to_material = CM_COLOR;
32 material.ref_brdf_type() = cgv::media::illum::BrdfType(cgv::media::illum::BT_STRAUSS_DIFFUSE + cgv::media::illum::BT_STRAUSS);
35 surface_renderer::surface_renderer()
37 cull_per_primitive =
true;
39 has_texcoords =
false;
44 group_renderer::enable_attribute_array_manager(ctx, aam);
45 if (has_attribute(ctx,
"normal"))
47 if (has_attribute(ctx,
"texcoord"))
53 group_renderer::disable_attribute_array_manager(ctx, aam);
55 has_texcoords =
false;
57 void surface_renderer::remove_normal_array(
const context& ctx) {
59 remove_attribute_array(ctx,
"normal");
61 void surface_renderer::remove_texcoord_array(
const context& ctx) {
62 has_texcoords =
false;
63 remove_attribute_array(ctx,
"texcoord");
67 GLfloat v[4] = { c[0], c[1], c[2], c[3] * alpha };
68 glMaterialfv(side, type, v);
75 unsigned side = gl::map_to_gl(ms);
76 set_gl_material_color(side, mat.get_ambient(), alpha, GL_AMBIENT);
77 set_gl_material_color(side, mat.get_diffuse(), alpha, GL_DIFFUSE);
78 set_gl_material_color(side, mat.get_specular(), alpha, GL_SPECULAR);
79 set_gl_material_color(side, mat.get_emission(), alpha, GL_EMISSION);
80 glMaterialf(side, GL_SHININESS, mat.get_shininess());
84 void surface_renderer::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)
87 set_attribute_array(ctx,
"normal", element_type, vbo, offset_in_bytes, nr_elements, stride_in_bytes);
91 void surface_renderer::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)
94 set_attribute_array(ctx,
"texcoord", element_type, vbo, offset_in_bytes, nr_elements, stride_in_bytes);
97 bool surface_renderer::enable(
context& ctx)
99 bool res = group_renderer::enable(ctx);
101 if (cull_per_primitive) {
103 glDisable(GL_CULL_FACE);
106 glCullFace(srs.
culling_mode == CM_FRONTFACE ? GL_FRONT : GL_BACK);
107 glEnable(GL_CULL_FACE);
110 if (ref_prog().is_linked()) {
115 ref_prog().set_uniform(ctx,
"culling_mode",
int(srs.
culling_mode));
126 if (cull_per_primitive) {
128 glDisable(GL_CULL_FACE);
130 if (!attributes_persist()) {
132 has_texcoords =
false;
134 return group_renderer::disable(ctx);
142 rh.
reflect_member(
"map_color_to_material", map_color_to_material) &&
154#include <cgv/gui/provider.h>
163 void* value_ptr,
const std::string& value_type,
164 const std::string& gui_type,
const std::string& options,
bool*)
173 "enums='Color Front=1,Color Back=2,Opacity Front=4,Opacity Back=8'");
202#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...
A vector with zero based index.
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.
virtual void set_color(const rgba &clr)
set the current color
virtual void set_material(const cgv::media::illum::surface_material &mat)
set the current material
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,...
a vertex buffer is an unstructured memory block on the GPU.
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 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
traits class with a static function get_name() of type const char* that returns the type name of the ...