cgv
Loading...
Searching...
No Matches
context.cxx
1#include <cgv/base/group.h>
2#include "context.h"
3#include <cgv/media/image/image_writer.h>
4#include <cgv/math/ftransform.h>
5#include <cgv/base/traverser.h>
6#include <cgv/render/drawable.h>
7#include <cgv/render/shader_program.h>
8
9using namespace cgv::base;
10using namespace cgv::media::image;
11
12#define SAFE_STACK_POP(STACK, WHERE) \
13if(STACK.size() == 1) error("context::" WHERE "() ... attempt to completely empty stack avoided."); \
14else STACK.pop();
15
16namespace cgv {
17 namespace render {
18
19
20const int nr_backgrounds = 5;
21float background_colors[] = {
22 0,0,0,0,
23 1.0f, 0.4f, 0.5f,0,
24 0.4f, 1, 0.7f,0,
25 0.5f, 0.5f, 1,0,
26 1,1,1,0,
27};
28
29
32{
33 depth_buffer = true;
34 double_buffer = true;
35 alpha_buffer = true;
36 stencil_bits = -1;
38 depth_bits = -1;
39 forward_compatible = false;
40 stencil_buffer = false;
41 accumulation_buffer = false;
42 multi_sample_buffer = false;
43 stereo_buffer = false;
44
46#ifdef _DEBUG
47 debug = true;
48#else
49 debug = false;
50#endif
51 core_profile = true;
53 version_major = -1;
54 version_minor = -1;
56}
57
60{
61 return false;
62}
63
66{
67 return
68 srh.reflect_member("version_major", version_major) &&
69 srh.reflect_member("version_minor", version_minor) &&
70 srh.reflect_member("core_profile", core_profile) &&
71 srh.reflect_member("debug", debug) &&
72 srh.reflect_member("double_buffer", context_config::double_buffer) &&
73 srh.reflect_member("alpha_buffer", alpha_buffer) &&
74 srh.reflect_member("stencil_buffer", stencil_buffer) &&
75 srh.reflect_member("depth_buffer", depth_buffer) &&
76 srh.reflect_member("depth_bits", depth_bits) &&
77 srh.reflect_member("stencil_bits", stencil_bits) &&
78 srh.reflect_member("accumulation_buffer", accumulation_buffer) &&
79 srh.reflect_member("accumulation_bits", accumulation_bits) &&
80 srh.reflect_member("multi_sample_buffer", multi_sample_buffer) &&
81 srh.reflect_member("nr_multi_samples", nr_multi_samples) &&
82 srh.reflect_member("stereo_buffer", stereo_buffer);
83}
84
101
104{
105 return "render_config";
106}
107
110{
111 return
113 srh.reflect_member("fullscreen_monitor", fullscreen_monitor) &&
114 srh.reflect_member("window_width", window_width) &&
115 srh.reflect_member("window_height", window_height) &&
116 srh.reflect_member("abort_on_error", abort_on_error) &&
117 srh.reflect_member("dialog_on_error", dialog_on_error) &&
118 srh.reflect_member("show_error_on_console", show_error_on_console);
119}
120
123{
124 static render_config_ptr rcp = new render_config();
125 return rcp;
126}
127
129{
130 *static_cast<context_config*>(this) = *get_render_config();
131
132 gpu_vendor = GPU_VENDOR_UNKNOWN;
133
135 bg_color_stack.push(vec4(0.0f));
136 bg_depth_stack.push(1.0f);
137 bg_stencil_stack.push(0);
138 bg_accum_color_stack.push(vec4(0.0f));
139
141 depth_test_state.enabled = false;
142 depth_test_state.test_func = CF_LESS;
144
145 cull_state_stack.push(CM_OFF);
146
148 blend_state.enabled = false;
149 blend_state.src_color = BF_ONE;
150 blend_state.src_alpha = BF_ONE;
151 blend_state.dst_color = BF_ZERO;
152 blend_state.dst_alpha = BF_ZERO;
154
156 buffer_mask.depth_flag = true;
157 buffer_mask.red_flag = true;
158 buffer_mask.green_flag = true;
159 buffer_mask.blue_flag = true;
160 buffer_mask.alpha_flag = true;
162
163 static frame_buffer_base fbb;
164 frame_buffer_stack.push(&fbb);
165 modelview_matrix_stack.push(cgv::math::identity4<double>());
166 projection_matrix_stack.push(cgv::math::identity4<double>());
167 window_transformation_stack.push(std::vector<window_transformation>());
169 wt.viewport = ivec4(0, 0, 640, 480);
170 wt.depth_range = dvec2(0, 1);
171 window_transformation_stack.top().push_back(wt);
172
173 x_offset = 10;
174 y_offset = 20;
175 tab_size = 5;
177 cursor_y = y_offset;
178 nr_identations = 0;
179 at_line_begin = true;
180 enable_vsync = true;
181 current_color = rgba(1, 1, 1, 1);
182 sRGB_framebuffer = false;
183 gamma3 = vec3(2.2f);
184
186
188
189 phong_shading = true;
190
191 do_screen_shot = false;
193
201 debug_render_passes = false;
202
203 default_light_source[0].set_local_to_eye(true);
204 default_light_source[0].set_position(vec3(-0.4f, 0.3f, 0.8f));
205 default_light_source[0].set_emission(rgb(0.74f));
206 default_light_source[0].set_ambient_scale(0.07f);
207 default_light_source[1].set_local_to_eye(true);
208 default_light_source[1].set_position(vec3(0.0f, 1.0f, 0.0f));
209 default_light_source[1].set_emission(rgb(0.74f));
210 default_light_source[1].set_ambient_scale(0.07f);
213
216}
217
219void context::error(const std::string& message, const render_component* rc) const
220{
221 if (rc)
222 rc->last_error = message;
223 if (get_render_config()->show_error_on_console)
224 std::cerr << message << std::endl;
225 if (get_render_config()->abort_on_error)
226 abort();
227}
228
231{
232 return gpu_vendor;
233}
234
239
240void context::init_render_pass()
241{
242}
243
245void context::draw_textual_info()
246{
247}
248
250void context::perform_screen_shot()
251{
252}
253
254void context::destruct_render_objects()
255{
256
257}
258
260void context::finish_render_pass()
261{
262}
263
264
267{
268 if (is_created()) {
269 make_current();
270
271 // use last traverser constructor argument to ensure that set_context and init are also called on hidden drawables
272
274 traverser(sma, "nc", cgv::base::TS_DEPTH_FIRST, false, true).traverse(child);
275
277 if (!traverser(sma1, "nc", cgv::base::TS_DEPTH_FIRST, false, true).traverse(child))
278 error(child->get_type_name()+"::init(context&) failed");
279
280 post_redraw();
281 }
282}
283
287
289 SAFE_STACK_POP(bg_color_stack, "pop_bg_color");
291}
292
296
297void context::set_bg_color(float r, float g, float b, float a)
298{
299 set_bg_color(vec4(r, g, b, a));
300}
301
303 return bg_color_stack.top();
304}
305
306void context::put_bg_color(float* rgba) const {
307 auto& c = bg_color_stack.top();
308 rgba[0] = c[0];
309 rgba[1] = c[1];
310 rgba[2] = c[2];
311 rgba[3] = c[3];
312}
313
315{
316 bg_color_stack.top()[3] = a;
317}
318
320 return bg_color_stack.top()[3];
321}
322
323void context::set_bg_clr_idx(unsigned int idx) {
324 current_background = idx;
325 if(idx == -1)
326 current_background = nr_backgrounds - 1;
327 else if(current_background >= nr_backgrounds)
329 set_bg_color(background_colors[4 * current_background], background_colors[4 * current_background + 1], background_colors[4 * current_background + 2], background_colors[4 * current_background + 3]);
330}
331
332unsigned int context::get_bg_clr_idx() const {
333 return current_background;
334}
335
339
341 SAFE_STACK_POP(bg_depth_stack, "pop_bg_depth");
343}
344
346 bg_depth_stack.top() = d;
347}
348
350 return bg_depth_stack.top();
351}
352
356
358 SAFE_STACK_POP(bg_stencil_stack, "pop_bg_stencil");
360}
361
363 bg_stencil_stack.top() = s;
364}
365
367 return bg_stencil_stack.top();
368}
369
373
375 SAFE_STACK_POP(bg_accum_color_stack, "pop_bg_accum_color");
377}
378
382
383void context::set_bg_accum_color(float r, float g, float b, float a) {
384 set_bg_accum_color(vec4(r, g, b, a));
385}
386
390
392 auto& c = bg_accum_color_stack.top();
393 rgba[0] = c[0];
394 rgba[1] = c[1];
395 rgba[2] = c[2];
396 rgba[3] = c[3];
397}
398
400 bg_accum_color_stack.top()[3] = a;
401}
402
404 return bg_accum_color_stack.top()[3];
405}
406
409{
410 phong_shading = true;
411 error("context::enable_phong_shading() deprecated");
412}
413
414void context::disable_phong_shading()
415{
416 phong_shading = false;
417 error("context::disable_phong_shading() deprecated");
418}
419
420void context::enable_material(const cgv::media::illum::phong_material& mat, MaterialSide ms, float alpha)
421{
422 error("context::enable_material(phong_material) deprecated");
423
424}
425void context::disable_material(const cgv::media::illum::phong_material& mat)
426{
427 error("context::disable_material(phong_material) deprecated");
428}
429void context::enable_material(const textured_material& mat, MaterialSide ms, float alpha)
430{
431 error("context::enable_material(textured_material) deprecated");
432}
433
438
441{
442 if (shader_program_stack.empty()) {
443 //error("context::get_current_program() called in core profile without current shader program");
444 return 0;
445 }
447 return &prog;
448}
449
455
461
467
470{
471 return light_sources.size();
472}
473
476{
477 vec3 Le = light.get_position();
478 if (place_now && !light.is_local_to_eye()) {
479 dvec4 hL(Le, light.get_type() == cgv::media::illum::LT_DIRECTIONAL ? 0.0f : 1.0f);
481 Le = (const dvec3&)hL;
482 if (light.get_type() != cgv::media::illum::LT_DIRECTIONAL)
483 Le /= float(hL(3));
484 }
485 return Le;
486}
487
490{
491 vec3 sd = light.get_spot_direction();
492 if (place_now && !light.is_local_to_eye()) {
493 dvec4 hSd(sd, 0.0f);
495 sd = (const dvec3&)hSd;
496 }
497 float norm = sd.length();
498 if (norm > 1e-8f)
499 sd /= norm;
500 return sd;
501}
502
505{
506 // construct new light source handle
508 void* handle = reinterpret_cast<void*>(light_source_handle);
509 // determine light source position
512 //
513 int idx = -1;
514 if (enabled) {
515 idx = int(enabled_light_source_handles.size());
516 enabled_light_source_handles.push_back(handle);
517 }
518 // store new light source in map
519 light_sources[handle] = std::pair<cgv::media::illum::light_source, light_source_status>(
520 light, { enabled, Le, sd, idx });
521 // set light sources in shader code if necessary
522 if (enabled)
524 // return handle of new light source
525 return handle;
526}
529{
530 // find handle in map
531 auto iter = light_sources.find(handle);
532 if (iter == light_sources.end())
533 return false;
534 // check if light source was enabled
535 if (iter->second.second.enabled) {
536 // then remove from list of enabled light sources
537 enabled_light_source_handles.erase(enabled_light_source_handles.begin() + iter->second.second.light_source_index);
538 // and correct indices of moved light sources
539 for (int i = iter->second.second.light_source_index; i < (int)enabled_light_source_handles.size(); ++i)
540 light_sources[enabled_light_source_handles[i]].second.light_source_index = i;
542 }
543 // remove from map
544 light_sources.erase(iter);
545 return true;
546}
549{
550 const auto iter = light_sources.find(handle);
551 return iter->second.first;
552}
553
556{
557 const auto iter = light_sources.find(handle);
558 return iter->second.second;
559}
560
561
564{
565 auto iter = light_sources.find(handle);
566 iter->second.first = light;
567 if (place_now)
568 place_light_source(handle);
569 else {
570 if (iter->second.second.enabled)
572 }
573}
574
577{
578 if (modelview_deps) {
580 prog.set_uniform(*this, "modelview_matrix", V);
581 prog.set_uniform(*this, "inverse_modelview_matrix", inv(V));
583 NM(0, 0) = V(0, 0);
584 NM(0, 1) = V(0, 1);
585 NM(0, 2) = V(0, 2);
586 NM(1, 0) = V(1, 0);
587 NM(1, 1) = V(1, 1);
588 NM(1, 2) = V(1, 2);
589 NM(2, 0) = V(2, 0);
590 NM(2, 1) = V(2, 1);
591 NM(2, 2) = V(2, 2);
592 NM.transpose();
593 prog.set_uniform(*this, "inverse_normal_matrix", NM);
594 NM = inv(NM);
595 prog.set_uniform(*this, "normal_matrix", NM);
596 }
597 if (projection_deps) {
598 cgv::math::fmat<float, 4, 4> P(projection_matrix_stack.top());
599 prog.set_uniform(*this, "projection_matrix", P);
600 prog.set_uniform(*this, "inverse_projection_matrix", inv(P));
601 }
602}
603
606{
608 return;
609
610 prog.set_material_uniform(*this, "material", *current_material_ptr);
612
613 }
614}
615
618{
620 for (size_t i = 0; i < nr_lights; ++i) {
621 std::string prefix = std::string("light_sources[") + cgv::utils::to_string(i) + "]";
623 const auto iter = light_sources.find(light_source_handle);
624 if (prog.set_light_uniform(*this, prefix, iter->second.first)) {
625 prog.set_uniform(*this, prefix + ".position", iter->second.second.eye_position);
626 prog.set_uniform(*this, prefix + ".spot_direction", iter->second.second.eye_spot_direction);
627 }
628 }
629 prog.set_uniform(*this, "nr_light_sources", (int)nr_lights);
630}
631
633{
635 return;
636
637 if (shader_program_stack.empty())
638 return;
639
641 if (!prog.does_use_lights())
642 return;
643
644 set_current_lights(prog);
645}
646
649{
650 auto iter = light_sources.find(handle);
651 // determine light source position
652 iter->second.second.eye_position = get_light_eye_position(iter->second.first, true);
653 iter->second.second.eye_spot_direction = get_light_eye_spot_direction(iter->second.first, true);
654 if (iter->second.second.enabled)
656}
657
660{
661 return 8;
662}
663
666{
667 return enabled_light_source_handles.size();
668}
669
677{
678 auto iter = light_sources.find(handle);
679 if (iter == light_sources.end())
680 return false;
681 return iter->second.second.enabled;
682}
683
686{
687 auto iter = light_sources.find(handle);
688 if (iter == light_sources.end())
689 return false;
690 if (iter->second.second.enabled)
691 return true;
692 iter->second.second.enabled = true;
693 iter->second.second.light_source_index = int(enabled_light_source_handles.size());
694 enabled_light_source_handles.push_back(handle);
696 return true;
697}
698
701{
702 auto iter = light_sources.find(handle);
703 if (iter == light_sources.end())
704 return false;
705 if (!iter->second.second.enabled)
706 return true;
707 iter->second.second.enabled = false;
708 enabled_light_source_handles.erase(enabled_light_source_handles.begin()+iter->second.second.light_source_index);
709 for (int i= iter->second.second.light_source_index; i < (int)enabled_light_source_handles.size(); ++i)
710 light_sources[enabled_light_source_handles[i]].second.light_source_index = i;
711 iter->second.second.light_source_index = -1;
713 return true;
714
715}
721
727
729{
730 const char* render_pass_names[] = {
731 "RP_NONE",
732 "RP_MAIN",
733 "RP_STEREO",
734 "RP_SHADOW_MAP",
735 "RP_SHADOW_VOLUME",
736 "RP_OPAQUE_SURFACES",
737 "RP_TRANSPARENT_SURFACES",
738 "RP_PICK",
739 "RP_USER_DEFINED"
740 };
741 return render_pass_names[rp];
742};
743
746{
747 return (unsigned)render_pass_stack.size();
748}
749
752{
753 if (render_pass_stack.empty())
754 return RP_NONE;
755 return render_pass_stack.top().pass;
756}
759{
760 if (render_pass_stack.empty())
761 return RPF_NONE;
762 return render_pass_stack.top().flags;
763}
764
777
780{
781 return render_pass_stack.top().user_data;
782}
783
789
792{
793 // ensure that default light sources are created
794 if (default_light_source_handles[0] == 0) {
795 for (unsigned i=0; i<nr_default_light_sources; ++i)
797 }
799 ri.pass = rp;
800 ri.flags = rpf;
801 ri.user_data = user_data;
803 std::cout << std::string(2 * render_pass_stack.size(), ' ') << get_render_pass_name(rp) << " <" << user_data << ">" << std::endl;
804 }
805 render_pass_stack.push(ri);
806
807 init_render_pass();
808
810 for (unsigned i = 0; i < nr_default_light_sources; ++i)
812 }
813
814 group* grp = dynamic_cast<group*>(this);
815 if (grp && (rpf&RPF_DRAWABLES_DRAW)) {
817 mma(*this, &drawable::draw, &drawable::finish_draw, true, true);
819 }
821 draw_textual_info();
824 sma(*this, &drawable::finish_frame, true, true);
826 }
829 sma(*this, &drawable::after_finish, true, true);
831 }
832 if ((rpf&RPF_HANDLE_SCREEN_SHOT) && do_screen_shot) {
833 perform_screen_shot();
834 do_screen_shot = false;
835 }
836
837 finish_render_pass();
838
839 render_pass_stack.pop();
840}
841
843void context::process_text(const std::string& text)
844{
846 unsigned int i, j = 0;
847 for (i = 0; i<text.size(); ++i) {
848 int n = i-j;
849 switch (text[i]) {
850 case '\a' :
851 draw_text(text.substr(j,n));
853 if (at_line_begin)
855 j = i+1;
856 break;
857 case '\b' :
858 draw_text(text.substr(j,n));
859 if (nr_identations > 0) {
861 if (at_line_begin)
863 }
864 j = i+1;
865 break;
866 case '\t' :
867 draw_text(text.substr(j,n));
869 at_line_begin = false;
870 j = i+1;
871 break;
872 case '\n' :
873 draw_text(text.substr(j,n));
875 cursor_y -= (int)(1.2f*current_font_size);
876 at_line_begin = true;
877 j = i+1;
878 break;
879 default:
880 at_line_begin = false;
881 }
882 }
883 draw_text(text.substr(j,i-j));
885}
886
888void context::draw_text(const std::string& text)
889{
891 return;
892 float x = (float)cursor_x;
893 float y = (float)cursor_y;
894 current_font_face->draw_text(x, y, text);
895 cursor_x = int(x + 0.5f);
896 cursor_y = int(y + 0.5f);
897}
898
899
902{
903 return out_stream;
904}
905
907{
908 if (!(font_face == current_font_face) || font_size != current_font_size) {
909 font_face->enable(this, font_size);
910 current_font_face = font_face;
911 current_font_size = font_size;
912 }
913}
914
917{
918 return current_font_size;
919}
920
926
927
930 FrameBufferType buffer_type, unsigned int x, unsigned int y, int w, int h,
931 float depth_offset, float depth_scale)
932{
934 if (cf == cgv::data::CF_D) {
936 cgv::data::data_format df("uint8[L]");
937 df.set_width(dv.get_format()->get_width());
938 df.set_height(dv.get_format()->get_height());
940 size_t n = df.get_width()*df.get_height();
941 const float* src = dv.get_ptr<float>();
942 unsigned char* dst = dv1.get_ptr<unsigned char>();
943 for (size_t i=0; i<n; ++i, ++dst, ++src)
944 *dst = (unsigned char)((*src - depth_offset)*depth_scale*255);
945 image_writer w(file_name);
946 if (w.write_image(dv1)) {
947 return true;
948 }
949 }
950 }
951 else if (read_frame_buffer(dv, x, y, buffer_type, cgv::type::info::TI_UINT8, cf, w, h)) {
952 if (cf == cgv::data::CF_S) {
953 const_cast<cgv::data::data_format*>(dv.get_format())->set_component_names("L");
954 size_t n = dv.get_format()->get_width()*dv.get_format()->get_height();
955 unsigned char* dst = dv.get_ptr<unsigned char>();
956 unsigned char s = (int)depth_scale;
957 for (size_t i=0; i<n; ++i, ++dst)
958 *dst *= s;
959 }
960 image_writer w(file_name);
961 if (w.write_image(dv)) {
962 return true;
963 }
964 }
965 return false;
966}
967
968std::string to_string(TextureWrap wrap)
969{
970 const char* wrap_str[] = {
971 "repeat", "clamp", "clamp_to_edge", "clamp_to_border", "mirror_clamp",
972 "mirror_clamp_to_edge", "mirror_clamp_to_border"
973 };
974 return wrap_str[wrap];
975}
976
977
979std::string to_string(TextureType tt)
980{
981 const char* tt_str[] = {
982 "undefined", "Texture1D", "Texture2D", "Texture3D", "CubeTexture"
983 };
984 return tt_str[tt];
985}
986
988std::string to_string(TextureCubeSides tcs)
989{
990 const char* tcs_str[] = {
991 "x+", "x-", "y+", "y-", "z+", "z-"
992 };
993 return tcs_str[tcs];
994}
995
997std::string to_string(PrimitiveType pt)
998{
999 const char* pt_str[] = {
1000 "undef", "points", "lines", "lines_adjacency", "line_strip", "line_strip_adjacency", "line_loop",
1001 "triangles", "triangles_adjacency", "triangle_strip", "triangle_strip_adjacency", "triangle_fan",
1002 "quads", "quad_strip", "polygon", "patches"
1003 };
1004 return pt_str[pt];
1005}
1006
1007
1008std::string to_string(TextureFilter filter_type)
1009{
1010 const char* filter_str[] = {
1011 "nearest",
1012 "linear",
1013 "nearest_mipmap_nearest",
1014 "linear_mipmap_nearest",
1015 "nearest_mipmap_linear",
1016 "linear_mipmap_linear",
1017 "anisotrop"
1018 };
1019 return filter_str[filter_type];
1020}
1021
1022// declare some colors by name
1023float black[4] = { 0, 0, 0, 1 };
1024float white[4] = { 1, 1, 1, 1 };
1025float gray[4] = { 0.25f, 0.25f, 0.25f, 1 };
1026float green[4] = { 0, 1, 0, 1 };
1027float brown[4] = { 0.3f, 0.1f, 0, 1 };
1028float dark_red[4] = { 0.4f, 0, 0, 1 };
1029float cyan[4] = { 0, 1, 1, 1 };
1030float yellow[4] = { 1, 1, 0, 1 };
1031float red[4] = { 1, 0, 0, 1 };
1032float blue[4] = { 0, 0, 1, 1 };
1033
1034void compute_face_normals(const float* vertices, float* normals, const int* vertex_indices, int* normal_indices, int nr_faces, int face_degree)
1035{
1036 for (int i = 0; i < nr_faces; ++i) {
1037 vec3& normal = reinterpret_cast<vec3&>(normals[3 * i]);
1038 normal.zeros();
1039 vec3 reference_pnt = *reinterpret_cast<const vec3*>(vertices + 3 * vertex_indices[face_degree*i + face_degree - 1]);
1041 last_difference.zeros();
1042 for (int j = 0; j < face_degree; ++j) {
1043 vec3 new_difference = *reinterpret_cast<const vec3*>(vertices + 3 * vertex_indices[face_degree*i + j]) - reference_pnt;
1044 normal += cross(last_difference, new_difference);
1046 }
1047 normal.normalize();
1048 for (int j = 0; j<face_degree; ++j)
1049 normal_indices[face_degree*i+j] = i;
1050 }
1051}
1052
1055{
1056 static float V[8*3] = {
1057 -1,-1,+1,
1058 +1,-1,+1,
1059 -1,+1,+1,
1060 +1,+1,+1,
1061 -1,-1,-1,
1062 +1,-1,-1,
1063 -1,+1,-1,
1064 +1,+1,-1
1065 };
1066 static float N[6*3] = {
1067 -1,0,0, +1,0,0,
1068 0,-1,0, 0,+1,0,
1069 0,0,-1, 0,0,+1
1070 };
1071 static const float ot = float(1.0 / 3);
1072 static const float tt = float(2.0 / 3);
1073 static float T[14*2] = {
1074 0,ot , 0,tt ,
1075 0.25f,0 , 0.25f,ot ,
1076 0.25f,tt , 0.25f,1 ,
1077 0.5f,0 , 0.5f,ot ,
1078 0.5f,tt , 0.5f,1 ,
1079 0.75f,ot , 0.75f,tt ,
1080 1,ot , 1,tt
1081 };
1082 static int F[6*4] = {
1083 0,2,6,4,
1084 1,5,7,3,
1085 0,4,5,1,
1086 2,3,7,6,
1087 4,6,7,5,
1088 0,1,3,2
1089 };
1090 static int FN[6*4] = {
1091 0,0,0,0, 1,1,1,1,
1092 2,2,2,2, 3,3,3,3,
1093 4,4,4,4, 5,5,5,5
1094 };
1095 static int FT[6*4] = {
1096 3,4,1,0 ,7,10,11,8 ,
1097 3,2,6,7 ,4,8,9,5 ,
1098 12,13,11,10 ,3,7,8,4
1099 };
1100 if (edges)
1101 draw_edges_of_faces(V, N, T, F, FN, FT, 6, 4, flip_normals);
1102 else
1103 draw_faces(V,N,T,F,FN,FT,6,4, flip_normals);
1104}
1105
1108{
1109 static float N[6 * 3] = {
1110 -1, 0, 0, +1, 0, 0,
1111 0, -1, 0, 0, +1, 0,
1112 0, 0, -1, 0, 0, +1
1113 };
1114 static int F[6 * 4] = {
1115 0, 2, 6, 4,
1116 1, 5, 7, 3,
1117 0, 4, 5, 1,
1118 2, 3, 7, 6,
1119 4, 6, 7, 5,
1120 0, 1, 3, 2
1121 };
1122 static int FN[6 * 4] = {
1123 0, 0, 0, 0, 1, 1, 1, 1,
1124 2, 2, 2, 2, 3, 3, 3, 3,
1125 4, 4, 4, 4, 5, 5, 5, 5
1126 };
1127 float V[8 * 3];
1128
1129 for (unsigned i = 0; i < 8; ++i) {
1130 V[3 * i] = float((i & 1) == 0 ? B.get_min_pnt()(0) : B.get_max_pnt()(0));
1131 V[3 * i + 1] = float((i & 2) == 0 ? B.get_min_pnt()(1) : B.get_max_pnt()(1));
1132 V[3 * i + 2] = float((i & 4) != 0 ? B.get_min_pnt()(2) : B.get_max_pnt()(2));
1133 }
1134 if (edges)
1135 draw_edges_of_faces(V, N, 0, F, FN, 0, 6, 4, flip_normals);
1136 else
1137 draw_faces(V, N, 0, F, FN, 0, 6, 4, flip_normals);
1138}
1139
1142{
1143 static const float V[6*3] = {
1144 -1, -1, -1,
1145 1, -1, -1,
1146 0, -1, 1,
1147 -1, 1, -1,
1148 1, 1, -1,
1149 0, 1, 1
1150 };
1151 static float a = 1.0f/sqrt(5.0f);
1152 static float b = 2*a;
1153 static const float N[5*3] = {
1154 0,-1, 0,
1155 0, 1, 0,
1156 0, 0,-1,
1157 -b, 0, a,
1158 b, 0, a
1159 };
1160 static const int FT[2*3] = { 0,1,2, 5,4,3 };
1161 static const int FQ[8] = { 4,1, 3,0, 5,2, 4,1};
1162 static const int FTN[2*3] = { 0,0,0, 1,1,1 };
1163 static const int FQN[8] = { 2,2, 2,2, 3,3, 4,4, };
1164
1165 if (edges) {
1166 draw_edges_of_faces(V, N, 0, FT, FTN, 0, 2, 3, flip_normals);
1167 draw_edges_of_strip_or_fan(V, N, 0, FQ, FQN, 0, 3, 4, flip_normals);
1168 }
1169 else {
1170 draw_faces(V, N, 0, FT, FTN, 0, 2, 3, flip_normals);
1171 draw_strip_or_fan(V, N, 0, FQ, FQN, 0, 3, 4, flip_normals);
1172 }
1173}
1174
1176void context::tesselate_unit_disk(int resolution, bool flip_normals, bool edges)
1177{
1178 std::vector<float> V; V.reserve(3*(resolution+1));
1179 std::vector<float> N; N.reserve(3*(resolution+1));
1180 std::vector<float> T; T.reserve(2*(resolution+1));
1181
1182 std::vector<int> F; F.resize(resolution+1);
1183 int i;
1184 for (i = 0; i <= resolution; ++i)
1185 F[i] = i;
1186
1187 float step = float(2*M_PI/resolution);
1188 float phi = 0;
1189 for (i = 0; i <= resolution; ++i, phi += step) {
1190 float cp = cos(phi);
1191 float sp = sin(phi);
1192 N.push_back(0);
1193 N.push_back(0);
1194 N.push_back(1);
1195 T.push_back((float)i/resolution);
1196 T.push_back(1);
1197 V.push_back(cp);
1198 V.push_back(sp);
1199 V.push_back(0);
1200 }
1201 if (edges)
1202 draw_edges_of_faces(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], 1, resolution + 1, flip_normals);
1203 else
1204 draw_faces(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], 1, resolution + 1, flip_normals);
1205}
1206
1208void context::tesselate_unit_cone(int resolution, bool flip_normals, bool edges)
1209{
1210 std::vector<float> V; V.reserve(6*(resolution+1));
1211 std::vector<float> N; N.reserve(6*(resolution+1));
1212 std::vector<float> T; T.reserve(4*(resolution+1));
1213
1214 std::vector<int> F; F.resize(2*resolution+2);
1215 int i;
1216 for (i = 0; i <= 2*resolution+1; ++i)
1217 F[i] = i;
1218
1219 static float a = 1.0f/sqrt(5.0f);
1220 static float b = 2*a;
1221 float step = float(2*M_PI/resolution);
1222 float phi = 0;
1223 float u = 0;
1224 float duv = float(1.0/resolution);
1225 for (int i = 0; i <= resolution; ++i, u += duv, phi += step) {
1226 float cp = cos(phi);
1227 float sp = sin(phi);
1228 N.push_back(b*cp);
1229 N.push_back(b*sp);
1230 N.push_back(a);
1231 T.push_back(u);
1232 T.push_back(1);
1233 V.push_back(0);
1234 V.push_back(0);
1235 V.push_back(1);
1236 N.push_back(b*cp);
1237 N.push_back(b*sp);
1238 N.push_back(a);
1239 T.push_back(u);
1240 T.push_back(0);
1241 V.push_back(cp);
1242 V.push_back(sp);
1243 V.push_back(-1);
1244 }
1245 if (edges)
1246 draw_edges_of_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1247 else
1248 draw_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1249}
1250
1252void context::tesselate_unit_cylinder(int resolution, bool flip_normals, bool edges)
1253{
1254 std::vector<float> V; V.reserve(6*(resolution+1));
1255 std::vector<float> N; N.reserve(6*(resolution+1));
1256 std::vector<float> T; T.reserve(4*(resolution+1));
1257
1258 std::vector<int> F; F.resize(2*(resolution+1));
1259 int i;
1260 for (i = 0; i <= 2*resolution+1; ++i)
1261 F[i] = i;
1262
1263 float step = float(2*M_PI/resolution);
1264 float phi = 0;
1265 float u = 0;
1266 float duv = float(1.0/resolution);
1267 for (int i = 0; i <= resolution; ++i, u += duv, phi += step) {
1268 float cp = cos(phi);
1269 float sp = sin(phi);
1270 N.push_back(cp);
1271 N.push_back(sp);
1272 N.push_back(0);
1273 T.push_back(u);
1274 T.push_back(1);
1275 V.push_back(cp);
1276 V.push_back(sp);
1277 V.push_back(1);
1278 N.push_back(cp);
1279 N.push_back(sp);
1280 N.push_back(0);
1281 T.push_back(u);
1282 T.push_back(0);
1283 V.push_back(cp);
1284 V.push_back(sp);
1285 V.push_back(-1);
1286 }
1287 if (edges)
1288 draw_edges_of_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1289 else
1290 draw_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1291}
1292
1294void context::tesselate_unit_torus(float minor_radius, int resolution, bool flip_normals, bool edges)
1295{
1296 std::vector<float> V; V.resize(6*(resolution+1));
1297 std::vector<float> N; N.resize(6*(resolution+1));
1298 std::vector<float> T; T.resize(4*(resolution+1));
1299 std::vector<int> F; F.resize(2*(resolution+1));
1300 int i;
1301 for (int i = 0; i <= resolution; ++i) {
1302 F[2*i] = 2*i;
1303 F[2*i+1] = 2*i+1;
1304 }
1305 float step = float(2*M_PI/resolution);
1306 float phi = 0;
1307 float cp1 = 1, sp1 = 0;
1308 float u = 0;
1309 float duv = float(1.0/resolution);
1310 for (i = 0; i < resolution; ++i, u += duv) {
1311 float cp0 = cp1, sp0 = sp1;
1312 phi += step;
1313 cp1 = cos(phi);
1314 sp1 = sin(phi);
1315 float theta = 0;
1316 float v = 0;
1317 int kv=0, kn=0, kt=0;
1318 for (int j = 0; j <= resolution; ++j, theta += step, v += duv) {
1319 float ct = cos(theta), st = sin(theta);
1320 N[kn++] = ct*cp0;
1321 N[kn++] = ct*sp0;
1322 N[kn++] = st;
1323 T[kt++] = u;
1324 T[kt++] = v;
1325 V[kv++] = cp0+minor_radius*cp0*ct;
1326 V[kv++] = sp0+minor_radius*sp0*ct;
1327 V[kv++] = minor_radius*st;
1328 N[kn++] = ct*cp1;
1329 N[kn++] = ct*sp1;
1330 N[kn++] = st;
1331 T[kt++] = u+duv;
1332 T[kt++] = v;
1333 V[kv++] = cp1+minor_radius*cp1*ct;
1334 V[kv++] = sp1+minor_radius*sp1*ct;
1335 V[kv++] = minor_radius*st;
1336 }
1337 if (edges)
1338 draw_edges_of_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1339 else
1340 draw_strip_or_fan(&V[0],&N[0],&T[0],&F[0],&F[0],&F[0],resolution,4,false, flip_normals);
1341 }
1342}
1344void context::tesselate_unit_sphere(int resolution, bool flip_normals, bool edges)
1345{
1346 std::vector<float> V; V.resize(6*(resolution+1));
1347 std::vector<float> N; N.resize(6*(resolution+1));
1348 std::vector<float> T; T.resize(4*(resolution+1));
1349 std::vector<int> F; F.resize(2*(resolution+1));
1350 int i;
1351 for (int i = 0; i <= resolution; ++i) {
1352 F[2*i] = 2*i;
1353 F[2*i+1] = 2*i+1;
1354 }
1355 float step = float(M_PI/resolution);
1356 float phi = 0;
1357 float cp1 = 1, sp1 = 0;
1358 float u = 0;
1359 float duv = float(1.0/resolution);
1360 for (i = 0; i < resolution; ++i, u += duv) {
1361 float cp0 = cp1, sp0 = sp1;
1362 phi += 2*step;
1363 cp1 = cos(phi);
1364 sp1 = sin(phi);
1365 float theta = float(-0.5*M_PI);
1366 float v = 0;
1367 int kv=0, kn=0, kt=0;
1368 for (int j = 0; j <= resolution; ++j, theta += step, v += duv) {
1369 float ct = cos(theta), st = sin(theta);
1370 N[kn++] = ct*cp0;
1371 N[kn++] = ct*sp0;
1372 N[kn++] = st;
1373 T[kt++] = u;
1374 T[kt++] = v;
1375 V[kv++] = ct*cp0;
1376 V[kv++] = ct*sp0;
1377 V[kv++] = st;
1378 N[kn++] = ct*cp1;
1379 N[kn++] = ct*sp1;
1380 N[kn++] = st;
1381 T[kt++] = u+duv;
1382 T[kt++] = v;
1383 V[kv++] = ct*cp1;
1384 V[kv++] = ct*sp1;
1385 V[kv++] = st;
1386 }
1387 if (edges)
1388 draw_edges_of_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1389 else
1390 draw_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1391 }
1392
1393}
1396{
1397 static const float a = float(1.0/(2*sqrt(3.0)));
1398 static const float b = float(1.0/(3*sqrt(3.0/2)));
1399 static const float V[4*3] = {
1400 -0.5, -a, -b,
1401 0.5, -a, -b,
1402 0,2*a, -b,
1403 0, 0,2*b
1404 };
1405 static const int F[4*3] = {
1406 0,2,1,3,2,0,3,0,1,3,1,2
1407 };
1408 static int FN[4*3];
1409 static float N[4*3];
1410 static bool computed = false;
1411 if (!computed) {
1412 compute_face_normals(V, N, F, FN, 4, 3);
1413 computed = true;
1414 }
1415 if (edges)
1416 draw_edges_of_faces(V, N, 0, F, FN, 0, 4, 3, flip_normals);
1417 else
1418 draw_faces(V, N, 0, F, FN, 0, 4, 3, flip_normals);
1419}
1420
1421
1424{
1425 static float N[1*3] = {
1426 0,0,+1
1427 };
1428 static float V[4*3] = {
1429 -1,-1,0, +1,-1,0,
1430 +1,+1,0, -1,+1,0
1431 };
1432 static float T[4*2] = {
1433 0,0, 1,0,
1434 1,1, 0,1
1435 };
1436 static int FN[1*4] = {
1437 0,0,0,0
1438 };
1439 static int F[1*4] = {
1440 0,1,2,3
1441 };
1442 if (edges)
1443 draw_edges_of_faces(V, N, T, F, FN, F, 1, 4, flip_normals);
1444 else
1445 draw_faces(V, N, T, F, FN, F, 1, 4, flip_normals);
1446}
1447
1448
1451{
1452 static float N[8*3] = {
1453 -1,-1,+1, +1,-1,+1, -1,+1,+1, +1,+1,+1,
1454 -1,-1,-1, +1,-1,-1, -1,+1,-1, +1,+1,-1
1455 };
1456 static float V[6*3] = {
1457 -1,0,0, +1,0,0,
1458 0,-1,0, 0,+1,0,
1459 0,0,-1, 0,0,+1
1460 };
1461 static int FN[8*3] = {
1462 0,0,0,
1463 1,1,1,
1464 2,2,2,
1465 3,3,3,
1466 4,4,4,
1467 5,5,5,
1468 6,6,6,
1469 7,7,7
1470 };
1471 static int F[8*3] = {
1472 0,2,5,
1473 1,5,2,
1474 5,3,0,
1475 3,5,1,
1476 4,2,0,
1477 4,1,2,
1478 3,4,0,
1479 1,4,3
1480 };
1481 if (edges)
1482 draw_edges_of_faces(V, N, 0, F, FN, 0, 8, 3, flip_normals);
1483 else
1484 draw_faces(V, N, 0, F, FN, 0, 8, 3, flip_normals);
1485}
1486
1489{
1490 static const float h = 0.4472135956f;
1491 static const float r = 0.8944271912f;
1492 static const float s = float(M_PI/2.5);
1493 static const float o = float(M_PI/5);
1494 static const float V[13*3] = {
1495 0,0,-1,
1496 r*sin(1*s),r*cos(1*s),-h,
1497 r*sin(2*s),r*cos(2*s),-h,
1498 r*sin(3*s),r*cos(3*s),-h,
1499 r*sin(4*s),r*cos(4*s),-h,
1500 r*sin(5*s),r*cos(5*s),-h,
1501 r*sin(1*s+o),r*cos(1*s+o),h,
1502 r*sin(2*s+o),r*cos(2*s+o),h,
1503 r*sin(3*s+o),r*cos(3*s+o),h,
1504 r*sin(4*s+o),r*cos(4*s+o),h,
1505 r*sin(5*s+o),r*cos(5*s+o),h,
1506 0,0,1,
1507 0,0,0
1508 };
1509 static int F[20*3] = {
1510 0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,1,
1511 6,2,1, 2,6,7, 7,3,2, 3,7,8, 8,4,3, 4,8,9, 9,5,4, 5,9,10, 10,1,5, 6,1,10,
1512 11,6,10, 11,10,9, 11,9,8, 11,8,7, 11,7,6
1513 };
1514 static int DF[12*5] = {
1515 0,1,2,3,4,
1516 5,6,7,1,0,
1517 7,8,9,2,1,
1518 9,10,11,3,2,
1519 11,12,13,4,3,
1520 13,14,5,0,4,
1521 16,15,14,13,12,
1522 17,16,12,11,10,
1523 18,17,10,9,8,
1524 19,18,8,7,6,
1525 15,19,6,5,14,
1526 15,16,17,18,19
1527 };
1528 static float N[20*3];
1529 static int FN[20*3];
1530 static int DFN[12*5] = {
1531 0,0,0,0,0,
1532 2,2,2,2,2,
1533 3,3,3,3,3,
1534 4,4,4,4,4,
1535 5,5,5,5,5,
1536 1,1,1,1,1,
1537 10,10,10,10,10,
1538 9,9,9,9,9,
1539 8,8,8,8,8,
1540 7,7,7,7,7,
1541 6,6,6,6,6,
1542 11,11,11,11,11
1543 };
1544
1545 static bool computed = false;
1546 if (!computed) {
1547 compute_face_normals(V, N, F, FN, 20, 3);
1548 computed = true;
1549 }
1550 if (!dual) {
1551 if (edges)
1552 c.draw_edges_of_faces(V, N, 0, F, FN, 0, 20, 3, flip_normals);
1553 else
1554 c.draw_faces(V, N, 0, F, FN, 0, 20, 3, flip_normals);
1555 }
1556 else {
1557 if (edges)
1558 c.draw_edges_of_faces(N, V, 0, DF, DFN, 0, 12, 5, flip_normals);
1559 else
1560 c.draw_faces(N, V, 0, DF, DFN, 0, 12, 5, flip_normals);
1561 }
1562}
1563
1574
1576{
1578}
1581{
1582 int gi = prog.get_uniform_location(*this, "gamma");
1583 if (gi != -1)
1584 prog.set_uniform(*this, gi, get_gamma());
1585 int gi3 = prog.get_uniform_location(*this, "gamma3");
1586 if (gi3 != -1)
1587 prog.set_uniform(*this, gi3, get_gamma3());
1588}
1589
1591{
1592 gamma3 = _gamma3;
1594 return;
1595
1596 if (shader_program_stack.empty())
1597 return;
1598
1600 if (prog.does_use_gamma())
1601 set_current_gamma(prog);
1602}
1603
1609
1612{
1613 return current_color;
1614}
1615
1618{
1620 if (shader_program_stack.empty())
1621 return;
1623 if (!prog.does_context_set_color())
1624 return;
1625 int clr_loc = prog.get_color_index();
1626 if (clr_loc == -1)
1627 return;
1628 prog.set_attribute(*this, clr_loc, clr);
1629}
1630
1633{
1634 current_material_ptr = &material;
1636
1638 return;
1639
1640 if (shader_program_stack.empty())
1641 return;
1642
1644 if (!prog.does_use_material())
1645 return;
1646
1647 prog.set_material_uniform(*this, "material", material);
1648}
1649
1652{
1653 current_material_ptr = &material;
1655
1657 return;
1658
1659 if (shader_program_stack.empty())
1660 return;
1661
1663 if (!prog.does_use_material())
1664 return;
1665
1666 prog.set_textured_material_uniform(*this, "material", material);
1667}
1668
1672
1674 SAFE_STACK_POP(depth_test_state_stack, "pop_depth_test_state");
1676}
1677
1681
1685
1687 depth_test_state_stack.top().test_func = func;
1688}
1689
1690
1692 depth_test_state_stack.top().enabled = true;
1693}
1694
1696 depth_test_state_stack.top().enabled = false;
1697}
1698
1702
1704 SAFE_STACK_POP(cull_state_stack, "pop_cull_state");
1706}
1707
1709 return cull_state_stack.top();
1710}
1711
1713 cull_state_stack.push(culling_mode);
1714}
1715
1719
1721 SAFE_STACK_POP(blend_state_stack, "pop_blend_state");
1723}
1724
1728
1730 blend_state_stack.top() = state;
1731}
1732
1740
1748
1750 set_blend_func(BF_ONE_MINUS_DST_ALPHA, BF_ONE);
1751}
1753 set_blend_func(BF_SRC_ALPHA, BF_ONE_MINUS_SRC_ALPHA);
1754}
1755
1757 blend_state_stack.top().enabled = true;
1758}
1759
1761 blend_state_stack.top().enabled = false;
1762}
1763
1767
1769 SAFE_STACK_POP(buffer_mask_stack, "pop_buffer_mask");
1771}
1772
1776
1780
1782 return buffer_mask_stack.top().depth_flag;
1783}
1784
1786 buffer_mask_stack.top().depth_flag = flag;
1787}
1788
1790 auto& mask = buffer_mask_stack.top();
1791 return bvec4(mask.red_flag, mask.green_flag, mask.blue_flag, mask.alpha_flag);
1792}
1793
1795 auto& mask = buffer_mask_stack.top();
1796 mask.red_flag = flags[0];
1797 mask.green_flag = flags[1];
1798 mask.blue_flag = flags[2];
1799 mask.alpha_flag = flags[3];
1800}
1801
1806
1812
1815{
1816 SAFE_STACK_POP(modelview_matrix_stack, "pop_modelview_matrix");
1818}
1821{
1822 projection_matrix_stack.push(get_projection_matrix());
1823}
1826{
1827 SAFE_STACK_POP(projection_matrix_stack, "pop_projection_matrix");
1828 set_projection_matrix(projection_matrix_stack.top());
1829}
1835
1837{
1838 // set new modelview matrix on matrix stack
1839 modelview_matrix_stack.top() = V;
1840
1841 // update in current shader
1843 return;
1844
1845 if (shader_program_stack.empty())
1846 return;
1848 if (!prog.does_use_view())
1849 return;
1850 set_current_view(prog, true, false);
1851}
1852
1854{
1855 // set new projection matrix on matrix stack
1856 projection_matrix_stack.top() = P;
1857
1858 // update in current shader
1860 return;
1861
1862 if (shader_program_stack.empty())
1863 return;
1865 if (!prog.does_use_view())
1866 return;
1867 set_current_view(prog, false, true);
1868}
1869
1876{
1877 SAFE_STACK_POP(window_transformation_stack, "pop_window_transformation_array");
1878}
1879
1880bool context::ensure_window_transformation_index(int& array_index)
1881{
1882 if (array_index == -1) {
1883 window_transformation_stack.top().resize(1);
1884 array_index = 0;
1885 return true;
1886 }
1887 else {
1888 if (array_index >= (int)window_transformation_stack.top().size()) {
1890 std::string message("context::ensure_window_transformation_index() ... attempt to resize window transformation array larger than maximum allowed size of ");
1892 error(message);
1893 return false;
1894 }
1895 window_transformation_stack.top().resize(array_index + 1);
1896 }
1897 }
1898 return true;
1899}
1900
1901void context::set_viewport(const ivec4& viewport, int array_index)
1902{
1903 if (!ensure_window_transformation_index(array_index))
1904 return;
1905 window_transformation_stack.top().at(array_index).viewport = viewport;
1906}
1907
1908void context::set_depth_range(const dvec2& depth_range, int array_index)
1909{
1910 if (!ensure_window_transformation_index(array_index))
1911 return;
1912 window_transformation_stack.top().at(array_index).depth_range = depth_range;
1913}
1914
1915const std::vector<window_transformation>& context::get_window_transformation_array() const
1916{
1917 return window_transformation_stack.top();
1918}
1919
1922{
1923 if (array_index >= window_transformation_stack.top().size()) {
1924 std::string message("context::get_window_matrix() ... attempt to query window matrix with array index ");
1926 message += " out of range [0,";
1927 message += cgv::utils::to_string(window_transformation_stack.top().size());
1928 message += "[";
1929 error(message);
1930 return cgv::math::identity4<double>();
1931 }
1933 dmat4 M = cgv::math::identity4<double>();
1934 M(0, 0) = 0.5*wt.viewport[2];
1935 M(0, 3) = M(0, 0) + wt.viewport[0];
1936 M(1, 1) = 0.5*wt.viewport[3];
1937 M(1, 3) = M(1, 1) + wt.viewport[1];
1938 M(2, 2) = 0.5*(wt.depth_range[1] - wt.depth_range[0]);
1939 M(2, 3) = M(2, 2) + wt.depth_range[0];
1940 return M;
1941}
1947
1950{
1952 dvecn x;
1953 dvecn b(p_window(0), p_window(1), p_window(2), 1.0);
1954 svd_solve(A, b, x);
1955 return vec3(float(x(0) / x(3)), float(x(1) / x(3)), float(x(2) / x(3)));
1956}
1957
1959void context::set_cursor(int x, int y)
1960{
1961 output_stream().flush();
1962 cursor_x = x;
1963 cursor_y = y;
1964 x_offset = x;
1965 y_offset = y;
1966 nr_identations = 0;
1967 at_line_begin = true;
1968}
1969
1971void context::put_cursor_coords(const vecn& p, int& x, int& y) const
1972{
1973 dvec4 p4(0, 0, 0, 1);
1974 for (unsigned int c = 0; c < p.size(); ++c)
1975 p4(c) = p(c);
1976
1978
1979 x = (int)(p4(0) / p4(3));
1980 y = (int)(p4(1) / p4(3));
1981}
1982
1984void context::set_cursor(const vecn& pos,
1985 const std::string& text, TextAlignment ta,
1986 int x_offset, int y_offset)
1987{
1988 int x,y;
1989 put_cursor_coords(pos, x, y);
1990 if (!text.empty() && get_current_font_face()) {
1991 float h = get_current_font_size();
1992 float w = get_current_font_face()->measure_text_width(text, h);
1993 switch (ta&3) {
1994 case 0 : x -= (int)(floor(w)*0.5f);break;
1995 case 2 : x -= (int)floor(w);break;
1996 default: break;
1997 }
1998 switch (ta&12) {
1999 case 0 : y -= (int)(floor(h)*0.3f);break;
2000 case 4 : y -= (int)(floor(h)*0.6f); break;
2001 default: break;
2002 }
2003 }
2004 x += x_offset;
2005 y += y_offset;
2006 set_cursor(x,y);
2007}
2008
2010void context::get_cursor(int& x, int& y) const
2011{
2012 x = cursor_x;
2013 y = cursor_y;
2014}
2015
2021
2022void context::tesselate_arrow(double length, double aspect, double rel_tip_radius, double tip_aspect, int res, bool edges)
2023{
2024 std::cout << "tesselate_arrow not implemented in cgv::render::context" << std::endl;
2025}
2026
2027void context::tesselate_arrow(const cgv::math::fvec<double, 3>& start, const cgv::math::fvec<double, 3>& end, double aspect, double rel_tip_radius, double tip_aspect, int res, bool edges)
2028{
2029 std::cout << "tesselate_arrow not implemented in cgv::render::context" << std::endl;
2030}
2031
2033{
2034 std::cout << "draw_light_source not implemented in cgv::render::context" << std::endl;
2035}
2036
2038{
2039 handle = 0;
2040 internal_format = 0;
2041 user_data = 0;
2042 ctx_ptr = 0;
2043}
2044
2047{
2048 return handle != 0;
2049}
2050
2051
2053{
2054 if (!ctx_ptr) {
2055 std::cerr << "no context set when render_component::put_id_void was called" << std::endl;
2056 return;
2057 }
2058 ctx_ptr->put_id(handle, ptr);
2059}
2060
2061render_buffer_base::render_buffer_base()
2062{
2063}
2064
2067{
2068 mag_filter = TF_LINEAR;
2069 min_filter = TF_LINEAR_MIPMAP_LINEAR;
2070 wrap_s = TW_CLAMP_TO_EDGE;
2071 wrap_t = TW_CLAMP_TO_EDGE;
2072 wrap_r = TW_CLAMP_TO_EDGE;
2073 anisotropy = 1;
2074 priority = 0.5f;
2075 border_color[0] = 1;
2076 border_color[1] = 1;
2077 border_color[2] = 1;
2078 border_color[3] = 1;
2079 tt = _tt;
2080 compare_function = CF_LEQUAL;
2081 use_compare_function = false;
2082 have_mipmaps = false;
2083}
2084
2085void shader_program_base::allow_context_to_set_color(bool allow)
2086{
2087 context_sets_color = allow;
2088}
2089
2091{
2092 is_enabled = false;
2093 geometry_shader_input_type = PT_POINTS;
2094 geometry_shader_output_type = PT_POINTS;
2095 geometry_shader_output_count = 1;
2096
2097 auto_detect_uniforms = true;
2098 auto_detect_vertex_attributes = true;
2099
2100 uses_view = false;
2101 uses_material = false;
2102 uses_lights = false;
2103 uses_gamma = false;
2104
2105 position_index = -1;
2106 normal_index = -1;
2107 color_index = -1;
2108 context_sets_color = true;
2109 texcoord_index = -1;
2110}
2111
2112// configure program
2113void shader_program_base::specify_standard_uniforms(bool view, bool material, bool lights, bool gamma)
2114{
2115 auto_detect_uniforms = false;
2116 uses_view = view;
2117 uses_material = material;
2118 uses_lights = lights;
2119 uses_gamma = gamma;
2120}
2121
2122void shader_program_base::specify_standard_vertex_attribute_names(context& ctx, bool color, bool normal, bool texcoord)
2123{
2124 auto_detect_vertex_attributes = false;
2125 position_index = ctx.get_attribute_location(*this, "position");
2126 color_index = color ? ctx.get_attribute_location(*this, "color") : -1;
2127 normal_index = normal ? ctx.get_attribute_location(*this, "normal") : -1;
2128 texcoord_index = texcoord ? ctx.get_attribute_location(*this, "texcoord") : -1;
2129}
2130
2131void shader_program_base::specify_vertex_attribute_names(context& ctx, const std::string& position, const std::string& color, const std::string& normal, const std::string& texcoord)
2132{
2133 auto_detect_vertex_attributes = false;
2134 position_index = position.empty() ? -1 : ctx.get_attribute_location(*this, position);
2135 color_index = color.empty() ? -1 : ctx.get_attribute_location(*this, color);
2136 normal_index = normal.empty() ? -1 : ctx.get_attribute_location(*this, normal);
2137 texcoord_index = texcoord.empty() ? -1 : ctx.get_attribute_location(*this, texcoord);
2138}
2139bool context::shader_program_link(shader_program_base& spb) const
2140{
2141 if (spb.handle == 0)
2142 return false;
2143 if (spb.auto_detect_vertex_attributes) {
2144 spb.position_index = get_attribute_location(spb, "position");
2145 spb.color_index = get_attribute_location(spb, "color");
2146 spb.normal_index = get_attribute_location(spb, "normal");
2147 spb.texcoord_index = get_attribute_location(spb, "texcoord");
2148 spb.auto_detect_vertex_attributes = false;
2149 }
2150 if (spb.auto_detect_uniforms) {
2151 spb.uses_lights = get_uniform_location(spb, "light_sources[0].light_source_type") != -1;
2152 spb.uses_material = get_uniform_location(spb, "material.brdf_type") != -1;
2153 spb.uses_view =
2154 get_uniform_location(spb, "modelview_matrix") != -1 ||
2155 get_uniform_location(spb, "projection_matrix") != -1 ||
2156 get_uniform_location(spb, "inverse_projection_matrix") != -1 ||
2157 get_uniform_location(spb, "normal_matrix") != -1 ||
2158 get_uniform_location(spb, "inverse_modelview_matrix") != -1 ||
2159 get_uniform_location(spb, "inverse_normal_matrix") != -1;
2160 spb.uses_gamma = get_uniform_location(spb, "gamma3") != -1 || get_uniform_location(spb, "gamma") != -1;
2161 spb.auto_detect_uniforms = false;
2162 }
2163 return true;
2164}
2165
2166bool context::shader_program_enable(shader_program_base& spb)
2167{
2168 if (spb.is_enabled) {
2169 if (shader_program_stack.top() == &spb) {
2170 error("context::shader_program_enable() called with program that is currently active", &spb);
2171 return false;
2172 }
2173 error("context::shader_program_enable() called with program that is recursively reactivated", &spb);
2174 return false;
2175 }
2177 spb.is_enabled = true;
2178 return true;
2179}
2180
2181bool context::shader_program_disable(shader_program_base& spb)
2182{
2183 if (shader_program_stack.empty()) {
2184 error("context::shader_program_disable() called with empty stack", &spb);
2185 return false;
2186 }
2187 if (!spb.is_enabled) {
2188 error("context::shader_program_disable() called with disabled program", &spb);
2189 return false;
2190 }
2191 if (shader_program_stack.top() != &spb) {
2192 error("context::shader_program_disable() called with program that was not on top of shader program stack", &spb);
2193 return false;
2194 }
2196 spb.is_enabled = false;
2197 return true;
2198}
2199
2200bool context::shader_program_destruct(shader_program_base& spb) const
2201{
2202 if (spb.is_enabled) {
2203 error("context::shader_program_destruct() on shader program that was still enabled", &spb);
2204/* if (shader_program_stack.top() == &spb)
2205 shader_program_disable(spb);
2206 else {
2207 error("context::shader_program_destruct() on shader program that was still enabled", &spb);
2208 // remove destructed program from stack
2209 std::vector<shader_program_base*> tmp;
2210 while (!shader_program_stack.empty()) {
2211 shader_program_base* t = shader_program_stack.top();
2212 shader_program_stack.pop();
2213 if (t == &spb)
2214 break;
2215 tmp.push_back(t);
2216 }
2217 while (!tmp.empty()) {
2218 shader_program_stack.push(tmp.back());
2219 tmp.pop_back();
2220 }
2221 }*/
2222 return false;
2223 }
2224 return true;
2225}
2226
2231
2232
2233bool context::attribute_array_binding_destruct(attribute_array_binding_base& aab) const
2234{
2235 if (aab.is_enabled) {
2236 error("context::attribute_array_binding_destruct() on array binding that was still enabled", &aab);
2237 /*
2238 if (attribute_array_binding_stack.top() == &aab)
2239 attribute_array_binding_disable(aab);
2240 else {
2241 // remove destructed binding from stack
2242 std::vector<attribute_array_binding_base*> tmp;
2243 while (!attribute_array_binding_stack.empty()) {
2244 attribute_array_binding_base* t = attribute_array_binding_stack.top();
2245 attribute_array_binding_stack.pop();
2246 if (t == &aab)
2247 break;
2248 tmp.push_back(t);
2249 }
2250 while (!tmp.empty()) {
2251 attribute_array_binding_stack.push(tmp.back());
2252 tmp.pop_back();
2253 }
2254 }
2255 */
2256 return false;
2257 }
2258 return true;
2259}
2260
2261bool context::attribute_array_binding_enable(attribute_array_binding_base& aab)
2262{
2263 if (!aab.handle) {
2264 error("context::attribute_array_binding_enable() called in not created attribute array binding.", &aab);
2265 return false;
2266 }
2267 if (aab.is_enabled) {
2268 if (attribute_array_binding_stack.top() == &aab) {
2269 error("context::attribute_array_binding_enable() called with array binding that is currently active", &aab);
2270 return false;
2271 }
2272 error("context::attribute_array_binding_enable() called with array binding that is recursively reactivated", &aab);
2273 return false;
2274 }
2276 aab.is_enabled = true;
2277 return true;
2278}
2279
2280bool context::attribute_array_binding_disable(attribute_array_binding_base& aab)
2281{
2282 if (attribute_array_binding_stack.empty()) {
2283 error("context::attribute_array_binding_disable() called with empty stack", &aab);
2284 return false;
2285 }
2286 if (!aab.is_enabled) {
2287 error("context::attribute_array_binding_disable() called with disabled array binding", &aab);
2288 return false;
2289 }
2290 if (attribute_array_binding_stack.top() != &aab) {
2291 error("context::attribute_array_binding_disable() called with array binding that was not on top of array binding stack", &aab);
2292 return false;
2293 }
2295 aab.is_enabled = false;
2296 return true;
2297}
2298
2304
2305
2308{
2309 is_enabled = false;
2310 width = -1;
2311 height = -1;
2312 depth_attached = false;
2313 std::fill(attached, attached+16,false);
2314}
2315
2316void context::get_buffer_list(frame_buffer_base& fbb, bool& depth_buffer, std::vector<int>& buffers, int offset)
2317{
2318 if (fbb.enabled_color_attachments.size() == 0) {
2319 for (int i = 0; i < 16; ++i)
2320 if (fbb.attached[i])
2321 buffers.push_back(i + offset);
2322 }
2323 else {
2324 for (int i = 0; i < (int)fbb.enabled_color_attachments.size(); ++i)
2325 if (fbb.attached[fbb.enabled_color_attachments[i]])
2326 buffers.push_back(fbb.enabled_color_attachments[i]+offset);
2327 }
2328 depth_buffer = fbb.depth_attached;
2329}
2330
2331bool context::frame_buffer_create(frame_buffer_base& fbb) const
2332{
2333 if (fbb.width == -1)
2334 fbb.width = get_width();
2335 if (fbb.height == -1)
2336 fbb.height = get_height();
2337 return true;
2338}
2339
2340bool context::frame_buffer_attach(frame_buffer_base& fbb, const render_buffer_base& rb, bool is_depth, int i) const
2341{
2342 if (fbb.handle == 0) {
2343 error("gl_context::frame_buffer_attach: attempt to attach to frame buffer that is not created", &fbb);
2344 return false;
2345 }
2346 if (rb.handle == 0) {
2347 error("gl_context::frame_buffer_attach: attempt to attach empty render buffer", &fbb);
2348 return false;
2349 }
2350 if (is_depth)
2351 fbb.depth_attached = true;
2352 else
2353 fbb.attached[i] = true;
2354
2355 return true;
2356}
2357
2358bool context::frame_buffer_attach(frame_buffer_base& fbb, const texture_base& t, bool is_depth, int level, int i, int z_or_cube_side) const
2359{
2360 if (fbb.handle == 0) {
2361 error("context::frame_buffer_attach: attempt to attach to frame buffer that is not created", &fbb);
2362 return false;
2363 }
2364 if (t.handle == 0) {
2365 error("context::frame_buffer_attach: attempt to attach texture that is not created", &fbb);
2366 return false;
2367 }
2368 if(is_depth)
2369 fbb.depth_attached = true;
2370 else
2371 fbb.attached[i] = true;
2372
2373 return true;
2374}
2375
2376bool context::frame_buffer_enable(frame_buffer_base& fbb)
2377{
2378 if (fbb.handle == 0) {
2379 error("context::frame_buffer_enable: attempt to enable not created frame buffer", &fbb);
2380 return false;
2381 }
2382 if (fbb.is_enabled) {
2383 if (frame_buffer_stack.top() == &fbb) {
2384 error("context::frame_buffer_enable() called with frame buffer that is currently active", &fbb);
2385 return false;
2386 }
2387 error("context::frame_buffer_enable() called with frame buffer that is recursively reactivated", &fbb);
2388 return false;
2389 }
2390 frame_buffer_stack.push(&fbb);
2391 fbb.is_enabled = true;
2392 return true;
2393}
2394
2395bool context::frame_buffer_disable(frame_buffer_base& fbb)
2396{
2397 if (frame_buffer_stack.size() == 1) {
2398 error("gl_context::frame_buffer_disable called with empty stack", &fbb);
2399 return false;
2400 }
2401 if (frame_buffer_stack.top() != &fbb) {
2402 error("gl_context::frame_buffer_disable called with different frame buffer enabled", &fbb);
2403 return false;
2404 }
2405 frame_buffer_stack.pop();
2406 fbb.is_enabled = false;
2407 return true;
2408}
2409
2410bool context::frame_buffer_destruct(frame_buffer_base& fbb) const
2411{
2412 if (fbb.handle == 0) {
2413 error("context::frame_buffer_destruct: attempt to destruct not created frame buffer", &fbb);
2414 return false;
2415 }
2416 if (fbb.is_enabled) {
2417 error("context::frame_buffer_destruct() on frame buffer that was still enabled", &fbb);
2418 return false;
2419 }
2420 return true;
2421}
2422
2423std::vector<context_creation_function_type>& ref_context_creation_functions()
2424{
2425 static std::vector<context_creation_function_type> ccfs;
2426 return ccfs;
2427}
2428
2430void register_context_factory(context_creation_function_type fp)
2431{
2432 ref_context_creation_functions().push_back(fp);
2433}
2434
2435context_factory_registration::context_factory_registration(context_creation_function_type fp)
2436{
2438};
2439
2444 unsigned int w, unsigned int h,
2445 const std::string& title, bool show)
2446{
2447 std::vector<context_creation_function_type>& ccfs = ref_context_creation_functions();
2448 for (unsigned i=0; i<ccfs.size(); ++i) {
2449 context* ctx = ccfs[i](api,w,h,title,show);
2450 if (ctx) {
2451 ctx->make_current();
2452 return ctx;
2453 }
2454 }
2455 std::cerr << "could not create context for given parameters" << std::endl;
2456 return 0;
2457}
2458
2459
2460 }
2461}
2462
2463#include <cgv/base/register.h>
2464
2466{
2468 {
2469 cgv::base::register_object(cgv::render::get_render_config(), "register global render config");
2470 }
2471};
2472
2473render_config_registration render_config_registration_instance;
2474
2475#undef SAFE_STACK_POP
virtual bool end()
perform the leave part of the action on the current object
Definition action.cxx:48
The group class is a node with children.
Definition group.h:20
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
class used to traverse a tree structure
Definition traverser.h:102
bool traverse(base_ptr start, traverse_callback_handler *tch=0)
traverse a tree starting at given node according to set strategy, order and dest and previously comin...
A data_format describes a multidimensional data block of data entries.
Definition data_format.h:17
void set_height(size_t _height)
set the resolution in the second dimension, add dimensions if necessary
void set_width(size_t _width)
set the resolution in the first dimension, add dimensions if necessary
size_t get_width() const
return the resolution in the first dimension, or 1 if not defined
size_t get_height() const
return the resolution in the second dimension, or 1 if not defined
const data_format * get_format() const
return the component format
Definition data_view.cxx:73
cgv::type::func::transfer_const< P, S * >::type get_ptr() const
return a data pointer to type S
Definition data_view.h:61
the data view gives access to a data array of one, two, three or four dimensions.
Definition data_view.h:153
reference counted pointer, which can work together with types that are derived from ref_counted,...
Definition ref_ptr.h:160
bool empty() const
check if pointer is not yet set
Definition ref_ptr.h:230
matrix of fixed size dimensions
Definition fmat.h:23
T normalize()
normalize the vector using the L2-Norm and return the length
Definition fvec.h:302
void zeros()
fill the vector with zeros
Definition fvec.h:133
A matrix type (full column major storage) The matrix can be loaded directly into OpenGL without need ...
Definition mat.h:208
A column vector class.
Definition vec.h:28
unsigned size() const
number of elements
Definition vec.h:59
An axis aligned box, defined by to points: min and max.
const fpnt_type & get_max_pnt() const
return a const reference to corner 7
const fpnt_type & get_min_pnt() const
return a const reference to corner 0
>simple class to hold the properties of a light source
>simple class to hold the material properties of a phong material
simple class to hold the material properties of a phong material
the image writer chooses a specific writer automatically based on the extension of the given file nam...
bool write_image(const cgv::data::const_data_view &dv, const std::vector< cgv::data::const_data_view > *palettes=0, double duration=0)
write the data stored in the data view to a file with the file name given in the constructor.
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
base class for attribute_array_bindings
Definition context.h:403
attribute_array_binding_base()
nothing to be done heremembers
Definition context.cxx:2227
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
void push_window_transformation_array()
push a copy of the current viewport and depth range arrays defining the window transformations
Definition context.cxx:1870
void tesselate_unit_prism(bool flip_normals=false, bool edges=false)
tesselate a prism
Definition context.cxx:1141
void * add_light_source(const cgv::media::illum::light_source &light, bool enabled=true, bool place_now=false)
add a new light source, enable it if enable is true and place it relative to current model view trans...
Definition context.cxx:504
virtual void set_blend_func(BlendFunction src_factor, BlendFunction dst_factor)
set the blend function
Definition context.cxx:1733
void enable_shader_file_cache()
enable the usage of the shader file caches
Definition context.cxx:451
virtual std::ostream & output_stream()
returns an output stream whose output is printed at the current cursor location, which is managed by ...
Definition context.cxx:901
virtual bool read_frame_buffer(data::data_view &dv, unsigned int x=0, unsigned int y=0, FrameBufferType buffer_type=FB_BACK, cgv::type::info::TypeId type=cgv::type::info::TI_UINT8, data::ComponentFormat cf=data::CF_RGB, int w=-1, int h=-1)=0
read the current frame buffer or a rectangular region of it into the given data view.
void set_blend_func_back_to_front()
set the default blend function for back to front blending
Definition context.cxx:1752
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
Definition context.cxx:1808
virtual void render_pass(RenderPass render_pass=RP_MAIN, RenderPassFlags render_pass_flags=RPF_ALL, void *user_data=0)
perform the given render task
Definition context.cxx:791
void pop_bg_color()
pop the top of the current background color from the stack
Definition context.cxx:288
virtual void set_depth_range(const dvec2 &depth_range=dvec2(0, 1), int array_index=-1)
set the current depth range or one of the depth ranges in the window transformation array
Definition context.cxx:1908
vec3 gamma3
per color channel gamma value passed to shader programs that have gamma uniform
Definition context.h:698
virtual bool in_render_process() const =0
return whether the context is currently in process of rendering
virtual void process_text(const std::string &text)
callback method for processing of text from the output stream
Definition context.cxx:843
virtual void set_color(const rgba &clr)
set the current color
Definition context.cxx:1617
virtual void draw_light_source(const cgv::media::illum::light_source &l, float intensity_scale, float light_scale)
draw a light source with an emissive material
Definition context.cxx:2032
virtual bool is_created() const =0
return whether the context is created
virtual void set_gamma3(const vec3 &_gamma3)
set the current per channel gamma values to single value
Definition context.cxx:1590
virtual void enable_sRGB_framebuffer(bool do_enable=true)
enable or disable sRGB framebuffer
Definition context.cxx:434
virtual void draw_edges_of_faces(const float *vertices, const float *normals, const float *tex_coords, const int *vertex_indices, const int *normal_indices, const int *tex_coord_indices, int nr_faces, int face_degree, bool flip_normals=false) const =0
pass geometry of given faces to current shader program and generate draw calls to render lines for th...
RenderPassFlags default_render_flags
default render flags with which the main render pass is initialized
Definition context.h:776
void pop_buffer_mask()
pop the top of the current buffer mask from the stack
Definition context.cxx:1768
vec3 get_model_point(int x_window, int y_window) const
compute model space 3D point from the given opengl pixel location (window location)
Definition context.h:1423
shader_program_base * get_current_program() const
check for current program, prepare it for rendering and return pointer to it
Definition context.cxx:440
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
Definition context.cxx:219
std::stack< render_info > render_pass_stack
store the current render pass
Definition context.h:774
virtual void draw_edges_of_strip_or_fan(const float *vertices, const float *normals, const float *tex_coords, const int *vertex_indices, const int *normal_indices, const int *tex_coord_indices, int nr_faces, int face_degree, bool is_fan, bool flip_normals=false) const =0
pass geometry of given strip or fan to current shader program and generate draw calls to render lines...
virtual GPUVendorID get_gpu_vendor_id() const
device information
Definition context.cxx:230
void set_current_view(shader_program &prog, bool modelview_deps=true, bool projection_deps=true) const
set the shader program view matrices to the currently enabled view matrices
Definition context.cxx:576
float current_font_size
store current font size
Definition context.h:786
bool enable_vsync
whether vsync should be enabled
Definition context.h:692
const light_source_status & get_light_source_status(void *handle) const
read access to light source status
Definition context.cxx:555
void place_light_source(void *handle)
place the given light source relative to current model viel transformation
Definition context.cxx:648
void tesselate_unit_cube(bool flip_normals=false, bool edges=false)
tesselate a unit cube with extent from [-1,-1,-1] to [1,1,1] with face normals that can be flipped
Definition context.cxx:1054
virtual void get_cursor(int &x, int &y) const
return current cursor location in opengl coordinates with (0,0) in lower left corner
Definition context.cxx:2010
std::stack< BufferMask > buffer_mask_stack
stack of buffer masks
Definition context.h:716
void set_bg_clr_idx(unsigned int idx)
set an indexed background color
Definition context.cxx:323
virtual void set_buffer_mask(BufferMask mask)
set the buffer mask for depth and color buffers
Definition context.cxx:1777
virtual void draw_strip_or_fan(const float *vertices, const float *normals, const float *tex_coords, const int *vertex_indices, const int *normal_indices, const int *tex_coord_indices, int nr_faces, int face_degree, bool is_fan, bool flip_normals=false) const =0
pass geometry of given strip or fan to current shader program and generate draw calls to render trian...
bool auto_set_lights_in_current_shader_program
whether to automatically set lights in current shader program, defaults to true
Definition context.h:680
float get_bg_accum_alpha() const
return the current alpha value for clearing the accumulation buffer
Definition context.cxx:403
void set_bg_alpha(float a)
set a user defined background alpha value
Definition context.cxx:314
virtual void set_blend_func_separate(BlendFunction src_color_factor, BlendFunction dst_color_factor, BlendFunction src_alpha_factor, BlendFunction dst_alpha_factor)
set the blend function separately for color and alpha
Definition context.cxx:1741
size_t light_source_handle
counter to construct light source handles
Definition context.h:749
virtual void on_lights_changed()
helper function to send light update events
Definition context.cxx:632
context()
init the cursor position to (0,0)
Definition context.cxx:128
void push_depth_test_state()
push a copy of the current depth test state onto the stack saved attributes: depth test enablement,...
Definition context.cxx:1669
virtual void tesselate_arrow(double length=1, double aspect=0.1, double rel_tip_radius=2.0, double tip_aspect=0.3, int res=25, bool edges=false)
tesselate an arrow from the origin in z-direction
Definition context.cxx:2022
void put_bg_color(float *rgba) const
copy the current background rgba color into the given float array
Definition context.cxx:306
std::stack< shader_program_base * > shader_program_stack
stack of currently enabled shader programs
Definition context.h:725
void push_blend_state()
push a copy of the current blend state onto the stack saved attributes: blend enablement,...
Definition context.cxx:1716
bool is_light_source_enabled(void *handle)
check whether light source is enabled
Definition context.cxx:676
virtual void disable_depth_test()
disable the depth test
Definition context.cxx:1695
void pop_bg_depth()
pop the top of the current background depth value from the stack
Definition context.cxx:340
int get_bg_stencil() const
return the current stencil value for clearing the background
Definition context.cxx:366
virtual float get_current_font_size() const
return the size in pixels of the currently enabled font face
Definition context.cxx:916
void pop_blend_state()
pop the top of the current culling state from the stack
Definition context.cxx:1720
virtual unsigned int get_width() const =0
return the width of the window
const cgv::media::illum::surface_material * get_current_material() const
return pointer to current material or nullptr if no current material is available
Definition context.cxx:1605
void set_bg_accum_alpha(float a)
set a user defined background alpha value for the accumulation buffer
Definition context.cxx:399
float get_gamma() const
query current gamma computed as average over gamma3 per channel values
Definition context.h:1080
bool disable_light_source(void *handle)
disable a given light source and return whether there existed a light source with given handle
Definition context.cxx:700
int current_background
current back ground color index
Definition context.h:780
void set_blend_func_front_to_back()
set the default blend function for front to back blending
Definition context.cxx:1749
virtual RenderPass get_render_pass() const
return the current render pass
Definition context.cxx:751
void pop_depth_test_state()
pop the top of the current depth test state from the stack
Definition context.cxx:1673
void tesselate_unit_sphere(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a sphere of radius 1
Definition context.cxx:1344
virtual RenderPassFlags get_render_pass_flags() const
return the current render pass flags
Definition context.cxx:758
void tesselate_unit_cylinder(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a cylinder of radius 1
Definition context.cxx:1252
float get_bg_alpha() const
return the current alpha value for clearing the background
Definition context.cxx:319
bool write_frame_buffer_to_image(const std::string &file_name, data::ComponentFormat cf=data::CF_RGB, FrameBufferType buffer_type=FB_BACK, unsigned int x=0, unsigned int y=0, int w=-1, int h=-1, float depth_offset=0.9f, float depth_scale=10.0f)
write the content of the frame buffer to an image file.
Definition context.cxx:929
unsigned int get_bg_clr_idx() const
return the current index of the background color
Definition context.cxx:332
void tesselate_unit_tetrahedron(bool flip_normals=false, bool edges=false)
tesselate a tetrahedron
Definition context.cxx:1395
virtual bool recreate_context()
recreate context based on current context config settings
Definition context.cxx:59
virtual void configure_new_child(cgv::base::base_ptr child)
helper method to integrate a new child
Definition context.cxx:266
virtual void set_bg_color(vec4 rgba)
set a user defined background color
Definition context.cxx:293
virtual void set_depth_test_state(DepthTestState state)
set the depth test state
Definition context.cxx:1682
void tesselate_unit_octahedron(bool flip_normals=false, bool edges=false)
tesselate a octahedron
Definition context.cxx:1450
size_t get_nr_enabled_light_sources() const
return the number of light sources
Definition context.cxx:665
virtual unsigned int get_height() const =0
return the height of the window
vec3 get_gamma3() const
query current per color channel gamma
Definition context.h:1082
void set_default_light_source(size_t i, const cgv::media::illum::light_source &ls)
set i-th default light source
Definition context.cxx:723
virtual void disable_blending()
disable blending
Definition context.cxx:1760
BufferMask get_buffer_mask() const
return the current buffer mask
Definition context.cxx:1773
void push_cull_state()
push a copy of the current culling state onto the stack saved attributes: cull face enablement,...
Definition context.cxx:1699
virtual void enable_font_face(media::font::font_face_ptr font_face, float font_size)
enable the given font face with the given size in pixels
Definition context.cxx:906
dmat4 get_modelview_projection_window_matrix(unsigned array_index=0) const
return a homogeneous 4x4 matrix to transfrom from model to window coordinates, i.e....
Definition context.cxx:1943
dmat4 get_window_matrix(unsigned array_index=0) const
return a homogeneous 4x4 matrix to transform clip to window coordinates
Definition context.cxx:1921
void pop_bg_stencil()
pop the top of the current background stencil value from the stack
Definition context.cxx:357
virtual void draw_faces(const float *vertices, const float *normals, const float *tex_coords, const int *vertex_indices, const int *normal_indices, const int *tex_coord_indices, int nr_faces, int face_degree, bool flip_normals=false) const =0
pass geometry of given faces to current shader program and generate draw calls to render triangles
std::stack< dmat4 > modelview_matrix_stack
keep two matrix stacks for model view and projection matrices
Definition context.h:719
vec3 get_light_eye_position(const cgv::media::illum::light_source &light, bool place_now) const
helper function to place lights
Definition context.cxx:475
void push_bg_stencil()
push a copy of the current background stencil value onto the stack
Definition context.cxx:353
virtual unsigned get_max_nr_enabled_light_sources() const
return maximum number of light sources, that can be enabled in parallel
Definition context.cxx:659
virtual void pop_window_transformation_array()
restore previous viewport and depth range arrays defining the window transformations
Definition context.cxx:1875
const cgv::media::illum::light_source & get_default_light_source(size_t i) const
return i-th default light source
Definition context.cxx:717
bool use_shader_file_cache
whether to use the caching facilities of shader_program and shader_code to store loaded shader file c...
Definition context.h:676
virtual void set_color_mask(bvec4 flags)
set the color buffer mask
Definition context.cxx:1794
virtual void set_material(const cgv::media::illum::surface_material &mat)
set the current material
Definition context.cxx:1632
DepthTestState get_depth_test_state() const
return the current depth test state
Definition context.cxx:1678
int nr_identations
current number of indentations
Definition context.h:794
void tesselate_unit_dodecahedron(bool flip_normals=false, bool edges=false)
tesselate a dodecahedron
Definition context.cxx:1565
bool auto_set_material_in_current_shader_program
whether to automatically set material in current shader program, defaults to true
Definition context.h:682
void set_current_lights(shader_program &prog) const
set the shader program lights to the currently enabled lights
Definition context.cxx:617
virtual void tesselate_box(const cgv::media::axis_aligned_box< double, 3 > &B, bool flip_normals, bool edges=false) const
tesselate an axis aligned box
Definition context.cxx:1107
bool enable_light_source(void *handle)
enable a given light source and return whether there existed a light source with given handle
Definition context.cxx:685
virtual void * get_render_pass_user_data() const
return the current render pass user data
Definition context.cxx:779
void tesselate_unit_disk(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a circular disk of radius 1
Definition context.cxx:1176
std::stack< float > bg_depth_stack
stack of background depth values
Definition context.h:703
virtual void enable_depth_test()
enable the depth test
Definition context.cxx:1691
bool support_compatibility_mode
whether to support view and lighting management of compatibility mode, defaults to true
Definition context.h:686
void set_current_gamma(shader_program &prog) const
set the shader program gamma values
Definition context.cxx:1580
void tesselate_unit_torus(float minor_radius=0.2f, int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a torus with major radius of one and given minor radius
Definition context.cxx:1294
vec4 get_bg_color() const
return the current color value for clearing the background
Definition context.cxx:302
void pop_projection_matrix()
see push_P for an explanation
Definition context.cxx:1825
std::stack< attribute_array_binding_base * > attribute_array_binding_stack
stack of currently enabled attribute array binding
Definition context.h:737
BlendState get_blend_state() const
return the current blend state
Definition context.cxx:1725
virtual void set_cull_state(CullingMode culling_mode)
set the culling state
Definition context.cxx:1712
void tesselate_unit_icosahedron(bool flip_normals=false, bool edges=false)
tesselate an icosahedron
Definition context.cxx:1570
virtual void set_depth_func(CompareFunction func)
set the depth test function
Definition context.cxx:1686
void set_light_source(void *handle, const cgv::media::illum::light_source &light, bool place_now=true)
set light source newly
Definition context.cxx:563
std::stack< DepthTestState > depth_test_state_stack
stack of depth test states
Definition context.h:710
std::stack< CullingMode > cull_state_stack
stack of culling mode states
Definition context.h:712
void push_bg_depth()
push a copy of the current background depth value onto the stack
Definition context.cxx:336
bool get_depth_mask() const
get the depth buffer mask
Definition context.cxx:1781
void disable_shader_file_cache()
disable the usage of the shader file caches
Definition context.cxx:457
bool phong_shading
whether to use phong shading
Definition context.h:778
virtual void push_pixel_coords()=0
use this to push new modelview and new projection matrices onto the transformation stacks such that x...
void push_projection_matrix()
same as push_V but for the projection matrix - a different matrix stack is used.
Definition context.cxx:1820
bvec4 get_color_mask() const
get the color buffer mask
Definition context.cxx:1789
const rgba & get_color() const
return current color
Definition context.cxx:1611
bool is_shader_file_cache_enabled() const
whether the shader file caches are enabled
Definition context.cxx:463
bool current_material_is_textured
store flag to tell whether current material is textured
Definition context.h:765
void push_bg_accum_color()
push a copy of the current background accumulation color onto the stack
Definition context.cxx:370
virtual media::font::font_face_ptr get_current_font_face() const
return the currently enabled font face
Definition context.cxx:922
virtual void set_projection_matrix(const dmat4 &P)
set the current projection matrix, which transforms from eye to clip space
Definition context.cxx:1853
rgba current_color
current color value
Definition context.h:694
static const unsigned nr_default_light_sources
number of default light sources
Definition context.h:755
cgv::media::illum::light_source default_light_source[nr_default_light_sources]
default light sources
Definition context.h:757
std::stack< int > bg_stencil_stack
stack of background stencil values
Definition context.h:705
virtual dmat4 get_projection_matrix() const =0
return homogeneous 4x4 projection matrix, which transforms from eye to clip space
int tab_size
size a tabs
Definition context.h:790
dmat4 get_modelview_projection_device_matrix() const
return matrix to transfrom from model to device coordinates, i.e. the product of modelview,...
Definition context.cxx:2017
std::stack< vec4 > bg_accum_color_stack
stack of background accumulation colors
Definition context.h:707
virtual void set_cursor(int x, int y)
flush the output_stream and set a new cursor position given in opengl coordinates with (0,...
Definition context.cxx:1959
void pop_bg_accum_color()
pop the top of the current background accumulation color from the stack
Definition context.cxx:374
virtual void set_bg_stencil(int s)
set a user defined background stencil value
Definition context.cxx:362
virtual void put_cursor_coords(const vecn &p, int &x, int &y) const
transform point p in current world coordinates into opengl coordinates with (0,0) in lower left corne...
Definition context.cxx:1971
virtual void set_bg_accum_color(vec4 rgba)
set a user defined background color for the accumulation buffer
Definition context.cxx:379
virtual void set_default_render_pass_flags(RenderPassFlags)
return the default render pass flags
Definition context.cxx:771
float get_bg_depth() const
return the current depth value for clearing the background
Definition context.cxx:349
const std::vector< window_transformation > & get_window_transformation_array() const
return the current window transformation array
Definition context.cxx:1915
virtual unsigned get_max_window_transformation_array_size() const =0
query the maximum number of supported window transformations, which is at least 1
int x_offset
offset in x and y direction where text starts
Definition context.h:792
void put_bg_accum_color(float *rgba) const
copy the current accumulation background rgba color into the given float array
Definition context.cxx:391
std::map< void *, std::pair< cgv::media::illum::light_source, light_source_status > > light_sources
map handle to light source and light source status information
Definition context.h:751
virtual void set_textured_material(const textured_material &mat)
set the current material
Definition context.cxx:1651
std::stack< std::vector< window_transformation > > window_transformation_stack
keep stack of window transformations
Definition context.h:721
int cursor_x
current cursor location for textual output
Definition context.h:782
vec4 get_bg_accum_color() const
return the current color value for clearing the accumulation buffer
Definition context.cxx:387
const cgv::media::illum::light_source & get_light_source(void *handle) const
read access to light source
Definition context.cxx:548
virtual bool make_current() const =0
make the current context current if possible
bool draw_in_compatibility_mode
whether to do all drawing in compatibility mode, only possible if support_compatibility_mode is true,...
Definition context.h:688
virtual void set_blend_state(BlendState state)
set the complete blend state
Definition context.cxx:1729
bool remove_light_source(void *handle)
remove a light source by handle and whether it existed
Definition context.cxx:528
bool sRGB_framebuffer
whether to use opengl option to support sRGB framebuffer
Definition context.h:696
virtual RenderPassFlags get_default_render_pass_flags() const
return the default render pass flags
Definition context.cxx:766
virtual void set_bg_depth(float d)
set a user defined background depth value
Definition context.cxx:345
void set_gamma(float _gamma)
set the current per channel gamma values to single value
Definition context.cxx:1575
virtual void enable_blending()
enable blending
Definition context.cxx:1756
virtual dmat4 get_modelview_matrix() const =0
return homogeneous 4x4 viewing matrix, which transforms from world to eye space
vec3 get_light_eye_spot_direction(const cgv::media::illum::light_source &light, bool place_now) const
helper function to place spot lights
Definition context.cxx:489
void set_current_material(shader_program &prog) const
set the shader program material to the currently enabled material
Definition context.cxx:605
void pop_cull_state()
pop the top of the current culling state from the stack
Definition context.cxx:1703
virtual void draw_text(const std::string &text)
draw some text at cursor position and update cursor position
Definition context.cxx:888
void pop_modelview_matrix()
see push_V for an explanation
Definition context.cxx:1814
virtual ~context()
virtual destructor
Definition context.cxx:236
void * default_light_source_handles[nr_default_light_sources]
handles of default light sources
Definition context.h:759
void push_modelview_matrix()
push the current viewing matrix onto a matrix stack for viewing matrices.
Definition context.cxx:1802
std::stack< frame_buffer_base * > frame_buffer_stack
stack of currently enabled frame buffers
Definition context.h:723
virtual void pop_pixel_coords()=0
pop previously pushed transformation matrices from modelview and projection stacks
bool at_line_begin
store whether we are at the beginning of the line
Definition context.h:796
size_t get_nr_light_sources() const
return the number of light sources
Definition context.cxx:469
void tesselate_unit_square(bool flip_normals=false, bool edges=false)
tesselate a unit square in the xy-plane with texture coordinates
Definition context.cxx:1423
bool auto_set_view_in_current_shader_program
whether to automatically set viewing matrixes in current shader program, defaults to true
Definition context.h:678
bool debug_render_passes
whether to debug render passes
Definition context.h:690
std::vector< void * > enabled_light_source_handles
keep track of enabled light source handles
Definition context.h:747
void tesselate_unit_cone(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a cone of radius 1
Definition context.cxx:1208
CullingMode get_cull_state() const
return the current culling state
Definition context.cxx:1708
virtual void mul_projection_matrix(const dmat4 &P)
multiply given matrix from right to current projection matrix
Definition context.cxx:1831
virtual void set_viewport(const ivec4 &viewport, int array_index=-1)
set the current viewport or one of the viewports in the window transformation array
Definition context.cxx:1901
virtual void post_redraw()=0
the context will be redrawn when the system is idle again
const cgv::media::illum::surface_material * current_material_ptr
store pointer to current material
Definition context.h:763
virtual void set_modelview_matrix(const dmat4 &MV)
set the current modelview matrix, which transforms from world to eye space
Definition context.cxx:1836
void push_bg_color()
push a copy of the current background color onto the stack
Definition context.cxx:284
void * get_enabled_light_source_handle(size_t i) const
access to handle of i-th light source
Definition context.cxx:671
void push_buffer_mask()
push a copy of the current buffer mask onto the stack saved attributes: depth mask,...
Definition context.cxx:1764
virtual void enable_phong_shading()
enable phong shading with the help of a shader (enabled by default)
Definition context.cxx:408
void set_debug_render_passes(bool _debug)
set flag whether to debug render passes
Definition context.cxx:785
cgv::media::font::font_face_ptr current_font_face
store current font
Definition context.h:788
cgv::signal::callback_stream out_stream
use a callback stream to write text to the opengl context
Definition context.h:784
std::stack< vec4 > bg_color_stack
stack of background colors
Definition context.h:701
unsigned get_render_pass_recursion_depth() const
return current render pass recursion depth
Definition context.cxx:745
std::stack< BlendState > blend_state_stack
stack of blend states
Definition context.h:714
virtual void set_depth_mask(bool flag)
set the depth buffer mask
Definition context.cxx:1785
bool auto_set_gamma_in_current_shader_program
whether to automatically set gamma in current shader program, defaults to true
Definition context.h:684
void set_context(context *_ctx)
set the current focus context, this should only be called by the context itself
Definition drawable.cxx:9
virtual void finish_draw(context &)
this method is called when the current drawable is left in a tree traversal that calls the draw metho...
Definition drawable.cxx:116
virtual void draw(context &)
overload to draw the content of this drawable
Definition drawable.cxx:112
virtual void after_finish(context &)
this method is called in one pass over all drawables after finish frame
Definition drawable.cxx:125
virtual void finish_frame(context &)
this method is called in one pass over all drawables after drawing
Definition drawable.cxx:120
virtual bool init(context &)
this method is called after creation or recreation of the context, return whether all necessary funct...
Definition drawable.cxx:99
base interface for framebuffer
Definition context.h:471
frame_buffer_base()
initialize members
Definition context.cxx:2307
base interface for all render components
Definition context.h:301
virtual bool is_created() const
return whether component has been created
Definition context.cxx:2046
const context * ctx_ptr
keep pointer to my context
Definition context.h:307
render_component()
initialize members
Definition context.cxx:2037
void put_id_void(void *ptr) const
copy the rendering api specific id the component to the memory location of the given pointer.
Definition context.cxx:2052
base interface for shader programs
Definition context.h:355
shader_program_base()
initializes members
Definition context.cxx:2090
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_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 set_textured_material_uniform(const context &ctx, const std::string &name, const textured_material &material, bool generate_error=false)
set a uniform of type textured_material
bool set_light_uniform(const context &ctx, const std::string &name, const cgv::media::illum::light_source &light, bool generate_error=false)
set a uniform of type light source
int get_uniform_location(const context &ctx, const std::string &name) const
query location index of an uniform
bool set_material_uniform(const context &ctx, const std::string &name, const cgv::media::illum::surface_material &material, bool generate_error=false)
set a uniform of type material
texture_base(TextureType _tt=TT_UNDEF)
initialize members
Definition context.cxx:2066
class that extends obj_material with the management of textures
vertex_buffer_base()
initialize members
Definition context.cxx:2299
VertexBufferType type
buffer type defaults to VBT_VERTICES
Definition context.h:453
VertexBufferUsage usage
usage defaults to VBU_STATIC_DRAW
Definition context.h:455
defines a symmetric view with the following quantities:
Definition view.h:22
the base namespace holds the base hierarchy, support for plugin registration and signals
Definition action.cxx:4
data::ref_ptr< group, true > group_ptr
ref counted pointer to a node
Definition group.h:14
void register_object(base_ptr object, const std::string &options)
register an object and send event to all current registration ref_listeners()
Definition register.cxx:581
ComponentFormat
define standard formats, which should be used to avoid wrong assignment of component names
@ CF_S
depth component
@ CF_D
color format with components B, G, R and A
namespace for image processing
RenderAPI
enumeration of rendering APIs which can be queried from the context
Definition context.h:70
CullingMode
different culling modes
Definition context.h:143
void register_context_factory(context_creation_function_type fp)
registration context creation functions
Definition context.cxx:2430
BlendFunction
different blend functions
Definition context.h:150
TextAlignment
different text alignments
Definition context.h:273
std::string get_render_pass_name(RenderPass rp)
convert render pass type into string
Definition context.cxx:728
TextureFilter
different texture filter
Definition context.h:189
render_config_ptr get_render_config()
return a pointer to the current shader configuration
Definition context.cxx:122
TextureWrap
different texture wrap modes
Definition context.h:173
FrameBufferType
different frame buffer types which can be combined together with or
Definition context.h:488
MaterialSide
different sides of a material
Definition context.h:128
context * create_context(RenderAPI api, unsigned int w, unsigned int h, const std::string &title, bool show)
construct a context of the given size.
Definition context.cxx:2443
@ VBU_STATIC_DRAW
Modified once and used many times; Modified by the application, and used as the source for GL drawing...
Definition context.h:434
TextureCubeSides
the six different sides of a cube
Definition context.h:215
void tesselate_unit_dodecahedron_or_icosahedron(context &c, bool dual, bool flip_normals, bool edges)
render an icosahedron at a given center.
Definition context.cxx:1488
PrimitiveType
different primitive types
Definition context.h:225
@ VBT_VERTICES
The buffer contains vertices and will be bound to GL_ARRAY_BUFFER.
Definition context.h:416
RenderPass
Enumeration of different render passes, which can be queried from the context and used to specify a n...
Definition context.h:77
@ RP_NONE
no renderpass
Definition context.h:78
TextureType
different texture types
Definition context.h:201
RenderPassFlags
available flags that can be queried from the context and set for a new render pass
Definition context.h:93
@ RPF_DRAWABLES_FINISH_FRAME
whether to call finish frame method of drawables
Definition context.h:118
@ RPF_SET_LIGHTS
whether to define default lights
Definition context.h:99
@ RPF_DRAWABLES_DRAW
whether to call draw and finish_draw methods of drawables
Definition context.h:117
@ RPF_DRAWABLES_AFTER_FINISH
whether to call after finish method of drawables
Definition context.h:120
@ RPF_DEFAULT
all flags set, defines default render pass
Definition context.h:123
@ RPF_NONE
no frame initialization is performed
Definition context.h:94
@ RPF_HANDLE_SCREEN_SHOT
whether to perform a screen shot if this was scheduled
Definition context.h:121
@ RPF_DRAW_TEXTUAL_INFO
whether to draw textual information
Definition context.h:119
CompareFunction
different comparison functions used for depth testing or texture comparisons
Definition context.h:254
GPUVendorID
IDs for GPU vendors.
Definition context.h:31
@ TI_FLT32
floating point type stored in 16 bits
Definition type_id.h:28
@ TI_UINT8
signed integer stored in 64 bits
Definition type_id.h:23
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
the cgv namespace
Definition print.h:11
cgv::math::fvec< float, 4 > vec4
declare type of 4d single precision floating point vectors (used for homogeneous coordinates)
Definition fvec.h:671
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > rgba
declare rgba color type with 32 bit components
Definition color.h:855
cgv::math::fvec< int32_t, 4 > ivec4
declare type of 4d 32 bit integer vectors
Definition fvec.h:698
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
Definition color.h:853
cgv::math::fvec< bool, 4 > bvec4
declare type of 4d boolean vectors
Definition fvec.h:664
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:669
cgv::math::fvec< double, 2 > dvec2
declare type of 2d double precision floating point vectors
Definition fvec.h:674
Represents a blend state used to configure fragment blending.
Definition context.h:645
BlendFunction dst_color
the destination color (rgb) factor
Definition context.h:651
BlendFunction dst_alpha
the destination alpha factor
Definition context.h:655
BlendFunction src_alpha
the source alpha factor
Definition context.h:653
BlendFunction src_color
the source color (rgb) factor
Definition context.h:649
Represents a buffer mask used to mask depth and color buffer outputs.
Definition context.h:660
Represents a depth test state used to configure depth testing.
Definition context.h:637
status information of light sources
Definition context.h:740
information necessary for a rendering pass
Definition context.h:768
configuration object used to define context parameters that need to be set already at creation time
Definition context.h:525
bool multi_sample_buffer
default: false
Definition context.h:541
bool stencil_buffer
default: false
Definition context.h:537
int version_minor
default: -1 ... minor version of maximum supported OpenGL version
Definition context.h:554
int depth_bits
default: -1
Definition context.h:543
bool double_buffer
default: true
Definition context.h:531
int version_major
default: -1 ... major version of maximum supported OpenGL version
Definition context.h:552
context_config()
construct config with default parameters
Definition context.cxx:31
bool debug
default: false in release and true in debug version
Definition context.h:558
bool forward_compatible
default: false
Definition context.h:556
bool stereo_buffer
default: false
Definition context.h:535
bool alpha_buffer
default: false
Definition context.h:533
bool self_reflect(cgv::reflect::reflection_handler &srh)
reflect the shader_path member
Definition context.cxx:65
bool core_profile
default: true
Definition context.h:560
int stencil_bits
default: -1
Definition context.h:545
int nr_multi_samples
default: -1
Definition context.h:549
bool accumulation_buffer
default: false
Definition context.h:539
int accumulation_bits
default: -1
Definition context.h:547
bool depth_buffer
default: true
Definition context.h:529
configuration object used to define render view creation parameters including error handling configur...
Definition context.h:575
int window_width
default: 640
Definition context.h:581
render_config()
construct config with default parameters
Definition context.cxx:86
bool dialog_on_error
default: true (only in case a gui_driver, which supports this, is loaded)
Definition context.h:591
bool self_reflect(cgv::reflect::reflection_handler &srh)
reflect the shader_path member
Definition context.cxx:109
int fullscreen_monitor
default: -1 ... no fullscreen
Definition context.h:579
int window_height
default: 480
Definition context.h:583
bool abort_on_error
default: false
Definition context.h:589
std::string get_type_name() const
return "render_config"
Definition context.cxx:103
bool show_error_on_console
default: true
Definition context.h:593
parameters necessary to define window transformation
Definition context.h:612