cgv
Loading...
Searching...
No Matches
context.cxx
1#include "context.h"
2#include <cgv/base/group.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#include <cgv/render/attribute_array_binding.h>
9
10using namespace cgv::base;
11using namespace cgv::media::image;
12
13#define SAFE_STACK_POP(STACK, WHERE) \
14if(STACK.size() == 1) error("context::" WHERE "() ... attempt to completely empty stack avoided."); \
15else STACK.pop();
16
17namespace cgv {
18 namespace render {
19
20
21const int nr_backgrounds = 5;
22float background_colors[] = {
23 0,0,0,0,
24 1.0f, 0.4f, 0.5f,0,
25 0.4f, 1, 0.7f,0,
26 0.5f, 0.5f, 1,0,
27 1,1,1,0,
28};
29
30std::ostream& operator << (std::ostream& os, const type_descriptor& td)
31{
32 std::string prefix, postfix, type;
33 switch (td.coordinate_type) {
34 case cgv::type::info::TI_BOOL: type = "bool"; prefix = "b"; break;
35 case cgv::type::info::TI_FLT32: type = "float"; break;
36 case cgv::type::info::TI_FLT64: type = "double"; prefix = "d"; break;
37 case cgv::type::info::TI_INT32: type = "int"; prefix = "i"; break;
38 case cgv::type::info::TI_UINT32: type = "uint"; prefix = "u"; break;
39 }
40 switch (td.element_type) {
41 case cgv::render::ElementType::ET_VALUE:
42 prefix = "";
43 break;
44 case cgv::render::ElementType::ET_VECTOR:
45 type = "vec";
46 postfix = "0";
47 postfix[0] += td.nr_rows;
48 break;
49 case cgv::render::ElementType::ET_MATRIX: type = "mat"; break;
50 type = "mat";
51 postfix = "0";
52 postfix[0] += td.nr_rows;
53 if (td.nr_columns != td.nr_rows) {
54 postfix += "x0";
55 postfix[2] += td.nr_columns;
56 }
57 break;
58 }
59 return os << prefix << type << postfix;
60}
61
62void program_variable_info::compute_sizes(size_t& cnt, size_t& s, size_t& S) const
63{
64 cnt = 1;
65 if (type_descr.element_type == cgv::render::ET_VECTOR)
66 cnt = type_descr.nr_rows;
67 if (type_descr.element_type == cgv::render::ET_MATRIX)
68 cnt = type_descr.nr_rows * type_descr.nr_columns;
69 unsigned ctype_size = cgv::type::info::get_type_size(type_descr.coordinate_type);
70 if (type_descr.coordinate_type == cgv::type::info::TI_BOOL)
71 ctype_size = 4;
72 s = ctype_size * cnt;
73 S = s * array_size;
74}
75
77std::ostream& operator << (std::ostream& os, const program_variable_info& V)
78{
79 os << V.type_descr << " " << V.name;
80 if (V.array_size > 1)
81 os << "[" << V.array_size << "]";
82 if (V.program_location != -1)
83 os << " @" << V.program_location;
84 if (V.current_value.empty())
85 return os;
86
87 os << " = ";
88 size_t cnt, s, S;
89 V.compute_sizes(cnt, s, S);
90 if (V.array_size > 1)
91 os << "{";
92 for (size_t j = 0; j < V.array_size; ++j) {
93 if (j > 0)
94 os << ", ";
95 if (cnt > 1)
96 os << "[";
97 for (size_t k = 0; k < cnt; ++k) {
98 if (k > 0)
99 os << ", ";
100 const void* value_ptr = V.current_value.data() + j * s;
101 switch (V.type_descr.coordinate_type) {
102 case cgv::type::info::TI_BOOL: os << (*(const int32_t*)(value_ptr) != 0 ? "true" : "false"); break;
103 case cgv::type::info::TI_INT32: os << *(const int32_t*)(value_ptr); break;
104 case cgv::type::info::TI_UINT32: os << *(const uint32_t*)(value_ptr); break;
105 case cgv::type::info::TI_FLT32: os << *(const float*)(value_ptr); break;
106 case cgv::type::info::TI_FLT64: os << *(const double*)(value_ptr); break;
107 }
108 }
109 if (cnt > 1)
110 os << "]";
111 }
112 if (V.array_size > 1)
113 os << "}";
114 return os;
115}
116
117
120{
121 depth_buffer = true;
122 double_buffer = true;
123 alpha_buffer = true;
124 stencil_bits = -1;
126 depth_bits = -1;
127 forward_compatible = false;
128 stencil_buffer = false;
129 accumulation_buffer = false;
130 multi_sample_buffer = false;
131 stereo_buffer = false;
132
134#ifdef _DEBUG
135 debug = true;
136#else
137 debug = false;
138#endif
139 core_profile = true;
141 version_major = -1;
142 version_minor = -1;
143 nr_multi_samples = -1;
144}
145
148{
149 return false;
150}
151
154{
155 return
156 srh.reflect_member("version_major", version_major) &&
157 srh.reflect_member("version_minor", version_minor) &&
158 srh.reflect_member("core_profile", core_profile) &&
159 srh.reflect_member("debug", debug) &&
160 srh.reflect_member("double_buffer", context_config::double_buffer) &&
161 srh.reflect_member("alpha_buffer", alpha_buffer) &&
162 srh.reflect_member("stencil_buffer", stencil_buffer) &&
163 srh.reflect_member("depth_buffer", depth_buffer) &&
164 srh.reflect_member("depth_bits", depth_bits) &&
165 srh.reflect_member("stencil_bits", stencil_bits) &&
166 srh.reflect_member("accumulation_buffer", accumulation_buffer) &&
167 srh.reflect_member("accumulation_bits", accumulation_bits) &&
168 srh.reflect_member("multi_sample_buffer", multi_sample_buffer) &&
169 srh.reflect_member("nr_multi_samples", nr_multi_samples) &&
170 srh.reflect_member("stereo_buffer", stereo_buffer);
171}
172
175{
179 window_width = 640;
181 window_height = 480;
183 abort_on_error = false;;
185 dialog_on_error = true;
188}
189
192{
193 return "render_config";
194}
195
198{
199 return
201 srh.reflect_member("fullscreen_monitor", fullscreen_monitor) &&
202 srh.reflect_member("window_width", window_width) &&
203 srh.reflect_member("window_height", window_height) &&
204 srh.reflect_member("abort_on_error", abort_on_error) &&
205 srh.reflect_member("dialog_on_error", dialog_on_error) &&
206 srh.reflect_member("show_error_on_console", show_error_on_console);
207}
208
211{
212 static render_config_ptr rcp = new render_config();
213 return rcp;
214}
215
217{
218 *static_cast<context_config*>(this) = *get_render_config();
219
220 gpu_vendor = GPU_VENDOR_UNKNOWN;
221
223 bg_color_stack.push(vec4(0.0f));
224 bg_depth_stack.push(1.0f);
225 bg_stencil_stack.push(0);
226 bg_accum_color_stack.push(vec4(0.0f));
227
229 depth_test_state.enabled = false;
230 depth_test_state.test_func = CF_LESS;
232
233 cull_state_stack.push(CM_OFF);
234
236 blend_state.enabled = false;
237 blend_state.src_color = BF_ONE;
238 blend_state.src_alpha = BF_ONE;
239 blend_state.dst_color = BF_ZERO;
240 blend_state.dst_alpha = BF_ZERO;
242
244 buffer_mask.depth_flag = true;
245 buffer_mask.red_flag = true;
246 buffer_mask.green_flag = true;
247 buffer_mask.blue_flag = true;
248 buffer_mask.alpha_flag = true;
250
251 static frame_buffer_base fbb;
252 frame_buffer_stack.push(&fbb);
253 modelview_matrix_stack.push(cgv::math::identity4<double>());
254 projection_matrix_stack.push(cgv::math::identity4<double>());
255 window_transformation_stack.push(std::vector<window_transformation>());
257 wt.viewport = ivec4(0, 0, 640, 480);
258 wt.depth_range = dvec2(0, 1);
259 window_transformation_stack.top().push_back(wt);
260
261 x_offset = 10;
262 y_offset = 20;
263 tab_size = 5;
265 cursor_y = y_offset;
266 nr_identations = 0;
267 at_line_begin = true;
268 enable_vsync = true;
269 current_color = rgba(1, 1, 1, 1);
270 sRGB_framebuffer = false;
271 gamma3 = vec3(2.2f);
272
274
276
277 phong_shading = true;
278
279 do_screen_shot = false;
281
289 debug_render_passes = false;
290
291 default_light_source[0].set_local_to_eye(true);
292 default_light_source[0].set_position(vec3(-0.4f, 0.3f, 0.8f));
293 default_light_source[0].set_emission(rgb(0.74f));
294 default_light_source[0].set_ambient_scale(0.07f);
295 default_light_source[1].set_local_to_eye(true);
296 default_light_source[1].set_position(vec3(0.0f, 1.0f, 0.0f));
297 default_light_source[1].set_emission(rgb(0.74f));
298 default_light_source[1].set_ambient_scale(0.07f);
301
304}
305
307void context::error(const std::string& message, const render_component* rc) const
308{
309 if (rc)
310 rc->last_error = message;
311 if (get_render_config()->show_error_on_console)
312 std::cerr << message << std::endl;
313 if (get_render_config()->abort_on_error)
314 abort();
315}
316
319{
320 return gpu_vendor;
321}
322
323const device_capabilities& context::get_device_capabilities() const {
324 return gpu_capabilities;
325}
326
329{
330 if (dummy_aab) {
331 attribute_array_binding_destruct(*dummy_aab);
332 delete dummy_aab;
333 dummy_aab = 0;
334 }
335}
336
337void context::init_render_pass()
338{
339}
340
342void context::draw_textual_info()
343{
344}
345
347void context::perform_screen_shot()
348{
349}
350
351void context::destruct_render_objects()
352{
353
354}
355
357void context::finish_render_pass()
358{
359}
360
361
364{
365 if (is_created()) {
366 make_current();
367
368 // use last traverser constructor argument to ensure that set_context and init are also called on hidden drawables
369
371 traverser(sma, "nc", cgv::base::TS_DEPTH_FIRST, false, true).traverse(child);
372
374 if (!traverser(sma1, "nc", cgv::base::TS_DEPTH_FIRST, false, true).traverse(child))
375 error(child->get_type_name()+"::init(context&) failed");
376
377 post_redraw();
378 }
379}
380
384
386 SAFE_STACK_POP(bg_color_stack, "pop_bg_color");
388}
389
393
394void context::set_bg_color(float r, float g, float b, float a)
395{
396 set_bg_color(vec4(r, g, b, a));
397}
398
400 return bg_color_stack.top();
401}
402
403void context::put_bg_color(float* rgba) const {
404 auto& c = bg_color_stack.top();
405 rgba[0] = c[0];
406 rgba[1] = c[1];
407 rgba[2] = c[2];
408 rgba[3] = c[3];
409}
410
412{
413 bg_color_stack.top()[3] = a;
414}
415
417 return bg_color_stack.top()[3];
418}
419
420void context::set_bg_clr_idx(unsigned int idx) {
421 current_background = idx;
422 if(idx == -1)
423 current_background = nr_backgrounds - 1;
424 else if(current_background >= nr_backgrounds)
426 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]);
427}
428
429unsigned int context::get_bg_clr_idx() const {
430 return current_background;
431}
432
436
438 SAFE_STACK_POP(bg_depth_stack, "pop_bg_depth");
440}
441
443 bg_depth_stack.top() = d;
444}
445
447 return bg_depth_stack.top();
448}
449
453
455 SAFE_STACK_POP(bg_stencil_stack, "pop_bg_stencil");
457}
458
460 bg_stencil_stack.top() = s;
461}
462
464 return bg_stencil_stack.top();
465}
466
470
472 SAFE_STACK_POP(bg_accum_color_stack, "pop_bg_accum_color");
474}
475
479
480void context::set_bg_accum_color(float r, float g, float b, float a) {
481 set_bg_accum_color(vec4(r, g, b, a));
482}
483
487
489 auto& c = bg_accum_color_stack.top();
490 rgba[0] = c[0];
491 rgba[1] = c[1];
492 rgba[2] = c[2];
493 rgba[3] = c[3];
494}
495
497 bg_accum_color_stack.top()[3] = a;
498}
499
501 return bg_accum_color_stack.top()[3];
502}
503
506{
507 phong_shading = true;
508 error("context::enable_phong_shading() deprecated");
509}
510
511void context::disable_phong_shading()
512{
513 phong_shading = false;
514 error("context::disable_phong_shading() deprecated");
515}
516
517void context::enable_material(const cgv::media::illum::phong_material& mat, MaterialSide ms, float alpha)
518{
519 error("context::enable_material(phong_material) deprecated");
520
521}
522void context::disable_material(const cgv::media::illum::phong_material& mat)
523{
524 error("context::disable_material(phong_material) deprecated");
525}
526void context::enable_material(const textured_material& mat, MaterialSide ms, float alpha)
527{
528 error("context::enable_material(textured_material) deprecated");
529}
530
535
538{
539 if (shader_program_stack.empty()) {
540 //error("context::get_current_program() called in core profile without current shader program");
541 return 0;
542 }
544 return &prog;
545}
546
549{
550 if (frame_buffer_stack.empty())
551 return 0;
552 return frame_buffer_stack.top();
553}
554
555
561
567
573
576{
577 return light_sources.size();
578}
579
582{
583 vec3 Le = light.get_position();
584 if (place_now && !light.is_local_to_eye()) {
585 dvec4 hL(Le, light.get_type() == cgv::media::illum::LT_DIRECTIONAL ? 0.0f : 1.0f);
587 Le = (const dvec3&)hL;
588 if (light.get_type() != cgv::media::illum::LT_DIRECTIONAL)
589 Le /= float(hL(3));
590 }
591 return Le;
592}
593
596{
597 vec3 sd = light.get_spot_direction();
598 if (place_now && !light.is_local_to_eye()) {
599 dvec4 hSd(sd, 0.0f);
601 sd = (const dvec3&)hSd;
602 }
603 float norm = sd.length();
604 if (norm > 1e-8f)
605 sd /= norm;
606 return sd;
607}
608
611{
612 // construct new light source handle
614 void* handle = reinterpret_cast<void*>(light_source_handle);
615 // determine light source position
618 //
619 int idx = -1;
620 if (enabled) {
621 idx = int(enabled_light_source_handles.size());
622 enabled_light_source_handles.push_back(handle);
623 }
624 // store new light source in map
625 light_sources[handle] = std::pair<cgv::media::illum::light_source, light_source_status>(
626 light, { enabled, Le, sd, idx });
627 // set light sources in shader code if necessary
628 if (enabled)
630 // return handle of new light source
631 return handle;
632}
635{
636 // find handle in map
637 auto iter = light_sources.find(handle);
638 if (iter == light_sources.end())
639 return false;
640 // check if light source was enabled
641 if (iter->second.second.enabled) {
642 // then remove from list of enabled light sources
643 enabled_light_source_handles.erase(enabled_light_source_handles.begin() + iter->second.second.light_source_index);
644 // and correct indices of moved light sources
645 for (int i = iter->second.second.light_source_index; i < (int)enabled_light_source_handles.size(); ++i)
646 light_sources[enabled_light_source_handles[i]].second.light_source_index = i;
648 }
649 // remove from map
650 light_sources.erase(iter);
651 return true;
652}
655{
656 const auto iter = light_sources.find(handle);
657 return iter->second.first;
658}
659
662{
663 const auto iter = light_sources.find(handle);
664 return iter->second.second;
665}
666
667
670{
671 auto iter = light_sources.find(handle);
672 iter->second.first = light;
673 if (place_now)
674 place_light_source(handle);
675 else {
676 if (iter->second.second.enabled)
678 }
679}
680
683{
684 if (modelview_deps) {
686 prog.set_uniform(*this, "modelview_matrix", V);
687 prog.set_uniform(*this, "inverse_modelview_matrix", cgv::math::inverse(V));
689 NM(0, 0) = V(0, 0);
690 NM(0, 1) = V(0, 1);
691 NM(0, 2) = V(0, 2);
692 NM(1, 0) = V(1, 0);
693 NM(1, 1) = V(1, 1);
694 NM(1, 2) = V(1, 2);
695 NM(2, 0) = V(2, 0);
696 NM(2, 1) = V(2, 1);
697 NM(2, 2) = V(2, 2);
698 NM.transpose();
699 prog.set_uniform(*this, "inverse_normal_matrix", NM);
700 NM = cgv::math::inverse(NM);
701 prog.set_uniform(*this, "normal_matrix", NM);
702 }
703 if (projection_deps) {
704 cgv::math::fmat<float, 4, 4> P(projection_matrix_stack.top());
705 prog.set_uniform(*this, "projection_matrix", P);
706 prog.set_uniform(*this, "inverse_projection_matrix", cgv::math::inverse(P));
707 }
708}
709
712{
714 return;
715
716 prog.set_material_uniform(*this, "material", *current_material_ptr);
718
719 }
720}
721
724{
726 for (size_t i = 0; i < nr_lights; ++i) {
727 std::string prefix = std::string("light_sources[") + cgv::utils::to_string(i) + "]";
729 const auto iter = light_sources.find(light_source_handle);
730 if (prog.set_light_uniform(*this, prefix, iter->second.first)) {
731 prog.set_uniform(*this, prefix + ".position", iter->second.second.eye_position);
732 prog.set_uniform(*this, prefix + ".spot_direction", iter->second.second.eye_spot_direction);
733 }
734 }
735 prog.set_uniform(*this, "nr_light_sources", (int)nr_lights);
736}
737
739{
741 return;
742
743 if (shader_program_stack.empty())
744 return;
745
747 if (!prog.does_use_lights())
748 return;
749
750 set_current_lights(prog);
751}
752
755{
756 auto iter = light_sources.find(handle);
757 // determine light source position
758 iter->second.second.eye_position = get_light_eye_position(iter->second.first, true);
759 iter->second.second.eye_spot_direction = get_light_eye_spot_direction(iter->second.first, true);
760 if (iter->second.second.enabled)
762}
763
766{
767 return 8;
768}
769
772{
773 return enabled_light_source_handles.size();
774}
775
783{
784 auto iter = light_sources.find(handle);
785 if (iter == light_sources.end())
786 return false;
787 return iter->second.second.enabled;
788}
789
792{
793 auto iter = light_sources.find(handle);
794 if (iter == light_sources.end())
795 return false;
796 if (iter->second.second.enabled)
797 return true;
798 iter->second.second.enabled = true;
799 iter->second.second.light_source_index = int(enabled_light_source_handles.size());
800 enabled_light_source_handles.push_back(handle);
802 return true;
803}
804
807{
808 auto iter = light_sources.find(handle);
809 if (iter == light_sources.end())
810 return false;
811 if (!iter->second.second.enabled)
812 return true;
813 iter->second.second.enabled = false;
814 enabled_light_source_handles.erase(enabled_light_source_handles.begin()+iter->second.second.light_source_index);
815 for (int i= iter->second.second.light_source_index; i < (int)enabled_light_source_handles.size(); ++i)
816 light_sources[enabled_light_source_handles[i]].second.light_source_index = i;
817 iter->second.second.light_source_index = -1;
819 return true;
820
821}
827
833
835{
836 const char* render_pass_names[] = {
837 "RP_NONE",
838 "RP_MAIN",
839 "RP_STEREO",
840 "RP_SHADOW_MAP",
841 "RP_SHADOW_VOLUME",
842 "RP_OPAQUE_SURFACES",
843 "RP_TRANSPARENT_SURFACES",
844 "RP_PICK",
845 "RP_USER_DEFINED"
846 };
847 return render_pass_names[rp];
848};
849
852{
853 return (unsigned)render_pass_stack.size();
854}
855
858{
859 if (render_pass_stack.empty())
860 return RP_NONE;
861 return render_pass_stack.top().pass;
862}
865{
866 if (render_pass_stack.empty())
867 return RPF_NONE;
868 return render_pass_stack.top().flags;
869}
870
873{
874 if (render_pass_stack.empty())
875 return false;
876 auto& flags = render_pass_stack.top().flags;
877 flags = RenderPassFlags((flags & ~exclude_flags) | include_flags);
878 return true;
879}
880
893
896{
897 return render_pass_stack.top().user_data;
898}
899
905
906void context::render_pass_debug_output(const render_info& ri, const std::string& info)
907{
909 return;
910 std::cout
911 << std::string(2 * (render_pass_stack.size()-1), ' ')
912 << get_render_pass_name(ri.pass) << " <"
913 << ri.user_data;
914 if (ri.pass_index != -1)
915 std::cout << ":" << ri.pass_index;
916 std::cout << "> " << info << std::endl;
917}
918
921{
922 // ensure that default light sources are created
923 if (default_light_source_handles[0] == 0) {
924 for (unsigned i=0; i<nr_default_light_sources; ++i)
926 }
928 ri.pass = rp;
929 ri.flags = rpf;
930 ri.user_data = user_data;
931 ri.pass_index = rp_idx;
932 render_pass_stack.push(ri);
934 init_render_pass();
936 for (unsigned i = 0; i < nr_default_light_sources; ++i)
938 }
939
940 group* grp = dynamic_cast<group*>(this);
941 if (grp && (rpf&RPF_DRAWABLES_DRAW)) {
942 render_pass_debug_output(ri, "draw+finish_draw");
944 mma(*this, &drawable::draw, &drawable::finish_draw, true, true);
946 }
948 render_pass_debug_output(ri, "textual_info");
949 draw_textual_info();
950 }
952 render_pass_debug_output(ri, "finish_frame");
954 sma(*this, &drawable::finish_frame, true, true);
956 }
958 render_pass_debug_output(ri, "after_finish");
960 sma(*this, &drawable::after_finish, true, true);
962 }
963 if ((rpf&RPF_HANDLE_SCREEN_SHOT) && do_screen_shot) {
964 render_pass_debug_output(ri, "screenshot");
965 perform_screen_shot();
966 do_screen_shot = false;
967 }
968 render_pass_debug_output(ri, "finish render pass");
969 finish_render_pass();
970 render_pass_stack.pop();
971}
972
974void context::process_text(const std::string& text)
975{
977 unsigned int i, j = 0;
978 for (i = 0; i<text.size(); ++i) {
979 int n = i-j;
980 switch (text[i]) {
981 case '\a' :
982 draw_text(text.substr(j,n));
984 if (at_line_begin)
986 j = i+1;
987 break;
988 case '\b' :
989 draw_text(text.substr(j,n));
990 if (nr_identations > 0) {
992 if (at_line_begin)
994 }
995 j = i+1;
996 break;
997 case '\t' :
998 draw_text(text.substr(j,n));
1000 at_line_begin = false;
1001 j = i+1;
1002 break;
1003 case '\n' :
1004 draw_text(text.substr(j,n));
1006 cursor_y -= (int)(1.2f*current_font_size);
1007 at_line_begin = true;
1008 j = i+1;
1009 break;
1010 default:
1011 at_line_begin = false;
1012 }
1013 }
1014 draw_text(text.substr(j,i-j));
1016}
1017
1019void context::draw_text(const std::string& text)
1020{
1022 return;
1023 float x = (float)cursor_x;
1024 float y = (float)cursor_y;
1025 current_font_face->draw_text(x, y, text);
1026 cursor_x = int(x + 0.5f);
1027 cursor_y = int(y + 0.5f);
1028}
1029
1030
1033{
1034 return out_stream;
1035}
1036
1038{
1039 if (!(font_face == current_font_face) || font_size != current_font_size) {
1040 font_face->enable(this, font_size);
1041 current_font_face = font_face;
1042 current_font_size = font_size;
1043 }
1044}
1045
1048{
1049 return current_font_size;
1050}
1051
1057
1058
1061 FrameBufferType buffer_type, unsigned int x, unsigned int y, int w, int h,
1062 float depth_offset, float depth_scale)
1063{
1065 if (cf == cgv::data::CF_D) {
1067 cgv::data::data_format df("uint8[L]");
1068 df.set_width(dv.get_format()->get_width());
1069 df.set_height(dv.get_format()->get_height());
1071 size_t n = df.get_width()*df.get_height();
1072 const float* src = dv.get_ptr<float>();
1073 unsigned char* dst = dv1.get_ptr<unsigned char>();
1074 for (size_t i=0; i<n; ++i, ++dst, ++src)
1075 *dst = (unsigned char)((*src - depth_offset)*depth_scale*255);
1076 image_writer w(file_name);
1077 if (w.write_image(dv1)) {
1078 return true;
1079 }
1080 }
1081 }
1082 else if (read_frame_buffer(dv, x, y, buffer_type, cgv::type::info::TI_UINT8, cf, w, h)) {
1083 if (cf == cgv::data::CF_S) {
1084 const_cast<cgv::data::data_format*>(dv.get_format())->set_component_names("L");
1085 size_t n = dv.get_format()->get_width()*dv.get_format()->get_height();
1086 unsigned char* dst = dv.get_ptr<unsigned char>();
1087 unsigned char s = (int)depth_scale;
1088 for (size_t i=0; i<n; ++i, ++dst)
1089 *dst *= s;
1090 }
1091 image_writer w(file_name);
1092 if (w.write_image(dv)) {
1093 return true;
1094 }
1095 }
1096 return false;
1097}
1098
1099std::string to_string(TextureWrap wrap)
1100{
1101 const char* wrap_str[] = {
1102 "repeat", "clamp", "clamp_to_edge", "clamp_to_border", "mirror_clamp",
1103 "mirror_clamp_to_edge", "mirror_clamp_to_border"
1104 };
1105 return wrap_str[wrap];
1106}
1107
1108
1110std::string to_string(TextureType tt)
1111{
1112 const char* tt_str[] = {
1113 "undefined", "Texture1D", "Texture2D", "Texture3D", "CubeTexture"
1114 };
1115 return tt_str[tt];
1116}
1117
1119std::string to_string(TextureCubeSides tcs)
1120{
1121 const char* tcs_str[] = {
1122 "x+", "x-", "y+", "y-", "z+", "z-"
1123 };
1124 return tcs_str[tcs];
1125}
1126
1128std::string to_string(PrimitiveType pt)
1129{
1130 const char* pt_str[] = {
1131 "undef", "points", "lines", "lines_adjacency", "line_strip", "line_strip_adjacency", "line_loop",
1132 "triangles", "triangles_adjacency", "triangle_strip", "triangle_strip_adjacency", "triangle_fan",
1133 "quads", "quad_strip", "polygon", "patches"
1134 };
1135 return pt_str[pt];
1136}
1137
1138
1139std::string to_string(TextureFilter filter_type)
1140{
1141 const char* filter_str[] = {
1142 "nearest",
1143 "linear",
1144 "nearest_mipmap_nearest",
1145 "linear_mipmap_nearest",
1146 "nearest_mipmap_linear",
1147 "linear_mipmap_linear",
1148 "anisotrop"
1149 };
1150 return filter_str[filter_type];
1151}
1152
1153void compute_face_normals(const float* vertices, float* normals, const int* vertex_indices, int* normal_indices, int nr_faces, int face_degree)
1154{
1155 for (int i = 0; i < nr_faces; ++i) {
1156 vec3& normal = reinterpret_cast<vec3&>(normals[3 * i]);
1157 normal.zeros();
1158 vec3 reference_pnt = *reinterpret_cast<const vec3*>(vertices + 3 * vertex_indices[face_degree*i + face_degree - 1]);
1160 last_difference.zeros();
1161 for (int j = 0; j < face_degree; ++j) {
1162 vec3 new_difference = *reinterpret_cast<const vec3*>(vertices + 3 * vertex_indices[face_degree*i + j]) - reference_pnt;
1163 normal += cross(last_difference, new_difference);
1165 }
1166 normal.normalize();
1167 for (int j = 0; j<face_degree; ++j)
1168 normal_indices[face_degree*i+j] = i;
1169 }
1170}
1171
1174{
1175 static float V[8*3] = {
1176 -1,-1,+1,
1177 +1,-1,+1,
1178 -1,+1,+1,
1179 +1,+1,+1,
1180 -1,-1,-1,
1181 +1,-1,-1,
1182 -1,+1,-1,
1183 +1,+1,-1
1184 };
1185 static float N[6*3] = {
1186 -1,0,0, +1,0,0,
1187 0,-1,0, 0,+1,0,
1188 0,0,-1, 0,0,+1
1189 };
1190 static const float ot = float(1.0 / 3);
1191 static const float tt = float(2.0 / 3);
1192 static float T[14*2] = {
1193 0,ot , 0,tt ,
1194 0.25f,0 , 0.25f,ot ,
1195 0.25f,tt , 0.25f,1 ,
1196 0.5f,0 , 0.5f,ot ,
1197 0.5f,tt , 0.5f,1 ,
1198 0.75f,ot , 0.75f,tt ,
1199 1,ot , 1,tt
1200 };
1201 static int F[6*4] = {
1202 0,2,6,4,
1203 1,5,7,3,
1204 0,4,5,1,
1205 2,3,7,6,
1206 4,6,7,5,
1207 0,1,3,2
1208 };
1209 static int FN[6*4] = {
1210 0,0,0,0, 1,1,1,1,
1211 2,2,2,2, 3,3,3,3,
1212 4,4,4,4, 5,5,5,5
1213 };
1214 static int FT[6*4] = {
1215 3,4,1,0 ,7,10,11,8 ,
1216 3,2,6,7 ,4,8,9,5 ,
1217 12,13,11,10 ,3,7,8,4
1218 };
1219 if (edges)
1220 draw_edges_of_faces(V, N, T, F, FN, FT, 6, 4, flip_normals);
1221 else
1222 draw_faces(V,N,T,F,FN,FT,6,4, flip_normals);
1223}
1224
1227{
1228 static float N[6 * 3] = {
1229 -1, 0, 0, +1, 0, 0,
1230 0, -1, 0, 0, +1, 0,
1231 0, 0, -1, 0, 0, +1
1232 };
1233 static int F[6 * 4] = {
1234 0, 2, 6, 4,
1235 1, 5, 7, 3,
1236 0, 4, 5, 1,
1237 2, 3, 7, 6,
1238 4, 6, 7, 5,
1239 0, 1, 3, 2
1240 };
1241 static int FN[6 * 4] = {
1242 0, 0, 0, 0, 1, 1, 1, 1,
1243 2, 2, 2, 2, 3, 3, 3, 3,
1244 4, 4, 4, 4, 5, 5, 5, 5
1245 };
1246 float V[8 * 3];
1247
1248 for (unsigned i = 0; i < 8; ++i) {
1249 V[3 * i] = float((i & 1) == 0 ? B.get_min_pnt()(0) : B.get_max_pnt()(0));
1250 V[3 * i + 1] = float((i & 2) == 0 ? B.get_min_pnt()(1) : B.get_max_pnt()(1));
1251 V[3 * i + 2] = float((i & 4) != 0 ? B.get_min_pnt()(2) : B.get_max_pnt()(2));
1252 }
1253 if (edges)
1254 draw_edges_of_faces(V, N, 0, F, FN, 0, 6, 4, flip_normals);
1255 else
1256 draw_faces(V, N, 0, F, FN, 0, 6, 4, flip_normals);
1257}
1258
1261{
1262 static const float V[6*3] = {
1263 -1, -1, -1,
1264 1, -1, -1,
1265 0, -1, 1,
1266 -1, 1, -1,
1267 1, 1, -1,
1268 0, 1, 1
1269 };
1270 static float a = 1.0f/sqrt(5.0f);
1271 static float b = 2*a;
1272 static const float N[5*3] = {
1273 0,-1, 0,
1274 0, 1, 0,
1275 0, 0,-1,
1276 -b, 0, a,
1277 b, 0, a
1278 };
1279 static const int FT[2*3] = { 0,1,2, 5,4,3 };
1280 static const int FQ[8] = { 4,1, 3,0, 5,2, 4,1};
1281 static const int FTN[2*3] = { 0,0,0, 1,1,1 };
1282 static const int FQN[8] = { 2,2, 2,2, 3,3, 4,4, };
1283
1284 if (edges) {
1285 draw_edges_of_faces(V, N, 0, FT, FTN, 0, 2, 3, flip_normals);
1286 draw_edges_of_strip_or_fan(V, N, 0, FQ, FQN, 0, 3, 4, flip_normals);
1287 }
1288 else {
1289 draw_faces(V, N, 0, FT, FTN, 0, 2, 3, flip_normals);
1290 draw_strip_or_fan(V, N, 0, FQ, FQN, 0, 3, 4, flip_normals);
1291 }
1292}
1293
1295void context::tesselate_unit_disk(int resolution, bool flip_normals, bool edges)
1296{
1297 std::vector<float> V; V.reserve(3*(resolution+1));
1298 std::vector<float> N; N.reserve(3*(resolution+1));
1299 std::vector<float> T; T.reserve(2*(resolution+1));
1300
1301 std::vector<int> F; F.resize(resolution+1);
1302 int i;
1303 for (i = 0; i <= resolution; ++i)
1304 F[i] = i;
1305
1306 float step = float(2*M_PI/resolution);
1307 float phi = 0;
1308 for (i = 0; i <= resolution; ++i, phi += step) {
1309 float cp = cos(phi);
1310 float sp = sin(phi);
1311 N.push_back(0);
1312 N.push_back(0);
1313 N.push_back(1);
1314 T.push_back((float)i/resolution);
1315 T.push_back(1);
1316 V.push_back(cp);
1317 V.push_back(sp);
1318 V.push_back(0);
1319 }
1320 if (edges)
1321 draw_edges_of_faces(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], 1, resolution + 1, flip_normals);
1322 else
1323 draw_faces(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], 1, resolution + 1, flip_normals);
1324}
1325
1327void context::tesselate_unit_cone(int resolution, bool flip_normals, bool edges)
1328{
1329 std::vector<float> V; V.reserve(6*(resolution+1));
1330 std::vector<float> N; N.reserve(6*(resolution+1));
1331 std::vector<float> T; T.reserve(4*(resolution+1));
1332
1333 std::vector<int> F; F.resize(2*resolution+2);
1334 int i;
1335 for (i = 0; i <= 2*resolution+1; ++i)
1336 F[i] = i;
1337
1338 static float a = 1.0f/sqrt(5.0f);
1339 static float b = 2*a;
1340 float step = float(2*M_PI/resolution);
1341 float phi = 0;
1342 float u = 0;
1343 float duv = float(1.0/resolution);
1344 for (int i = 0; i <= resolution; ++i, u += duv, phi += step) {
1345 float cp = cos(phi);
1346 float sp = sin(phi);
1347 N.push_back(b*cp);
1348 N.push_back(b*sp);
1349 N.push_back(a);
1350 T.push_back(u);
1351 T.push_back(1);
1352 V.push_back(0);
1353 V.push_back(0);
1354 V.push_back(1);
1355 N.push_back(b*cp);
1356 N.push_back(b*sp);
1357 N.push_back(a);
1358 T.push_back(u);
1359 T.push_back(0);
1360 V.push_back(cp);
1361 V.push_back(sp);
1362 V.push_back(-1);
1363 }
1364 if (edges)
1365 draw_edges_of_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1366 else
1367 draw_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1368}
1369
1371void context::tesselate_unit_cylinder(int resolution, bool flip_normals, bool edges)
1372{
1373 std::vector<float> V; V.reserve(6*(resolution+1));
1374 std::vector<float> N; N.reserve(6*(resolution+1));
1375 std::vector<float> T; T.reserve(4*(resolution+1));
1376
1377 std::vector<int> F; F.resize(2*(resolution+1));
1378 int i;
1379 for (i = 0; i <= 2*resolution+1; ++i)
1380 F[i] = i;
1381
1382 float step = float(2*M_PI/resolution);
1383 float phi = 0;
1384 float u = 0;
1385 float duv = float(1.0/resolution);
1386 for (int i = 0; i <= resolution; ++i, u += duv, phi += step) {
1387 float cp = cos(phi);
1388 float sp = sin(phi);
1389 N.push_back(cp);
1390 N.push_back(sp);
1391 N.push_back(0);
1392 T.push_back(u);
1393 T.push_back(1);
1394 V.push_back(cp);
1395 V.push_back(sp);
1396 V.push_back(1);
1397 N.push_back(cp);
1398 N.push_back(sp);
1399 N.push_back(0);
1400 T.push_back(u);
1401 T.push_back(0);
1402 V.push_back(cp);
1403 V.push_back(sp);
1404 V.push_back(-1);
1405 }
1406 if (edges)
1407 draw_edges_of_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1408 else
1409 draw_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1410}
1411
1413void context::tesselate_unit_torus(float minor_radius, int resolution, bool flip_normals, bool edges)
1414{
1415 std::vector<float> V; V.resize(6*(resolution+1));
1416 std::vector<float> N; N.resize(6*(resolution+1));
1417 std::vector<float> T; T.resize(4*(resolution+1));
1418 std::vector<int> F; F.resize(2*(resolution+1));
1419 int i;
1420 for (int i = 0; i <= resolution; ++i) {
1421 F[2*i] = 2*i;
1422 F[2*i+1] = 2*i+1;
1423 }
1424 float step = float(2*M_PI/resolution);
1425 float phi = 0;
1426 float cp1 = 1, sp1 = 0;
1427 float u = 0;
1428 float duv = float(1.0/resolution);
1429 for (i = 0; i < resolution; ++i, u += duv) {
1430 float cp0 = cp1, sp0 = sp1;
1431 phi += step;
1432 cp1 = cos(phi);
1433 sp1 = sin(phi);
1434 float theta = 0;
1435 float v = 0;
1436 int kv=0, kn=0, kt=0;
1437 for (int j = 0; j <= resolution; ++j, theta += step, v += duv) {
1438 float ct = cos(theta), st = sin(theta);
1439 N[kn++] = ct*cp0;
1440 N[kn++] = ct*sp0;
1441 N[kn++] = st;
1442 T[kt++] = u;
1443 T[kt++] = v;
1444 V[kv++] = cp0+minor_radius*cp0*ct;
1445 V[kv++] = sp0+minor_radius*sp0*ct;
1446 V[kv++] = minor_radius*st;
1447 N[kn++] = ct*cp1;
1448 N[kn++] = ct*sp1;
1449 N[kn++] = st;
1450 T[kt++] = u+duv;
1451 T[kt++] = v;
1452 V[kv++] = cp1+minor_radius*cp1*ct;
1453 V[kv++] = sp1+minor_radius*sp1*ct;
1454 V[kv++] = minor_radius*st;
1455 }
1456 if (edges)
1457 draw_edges_of_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1458 else
1459 draw_strip_or_fan(&V[0],&N[0],&T[0],&F[0],&F[0],&F[0],resolution,4,false, flip_normals);
1460 }
1461}
1463void context::tesselate_unit_sphere(int resolution, bool flip_normals, bool edges)
1464{
1465 std::vector<float> V; V.resize(6*(resolution+1));
1466 std::vector<float> N; N.resize(6*(resolution+1));
1467 std::vector<float> T; T.resize(4*(resolution+1));
1468 std::vector<int> F; F.resize(2*(resolution+1));
1469 int i;
1470 for (int i = 0; i <= resolution; ++i) {
1471 F[2*i] = 2*i;
1472 F[2*i+1] = 2*i+1;
1473 }
1474 float step = float(M_PI/resolution);
1475 float phi = 0;
1476 float cp1 = 1, sp1 = 0;
1477 float u = 0;
1478 float duv = float(1.0/resolution);
1479 for (i = 0; i < resolution; ++i, u += duv) {
1480 float cp0 = cp1, sp0 = sp1;
1481 phi += 2*step;
1482 cp1 = cos(phi);
1483 sp1 = sin(phi);
1484 float theta = float(-0.5*M_PI);
1485 float v = 0;
1486 int kv=0, kn=0, kt=0;
1487 for (int j = 0; j <= resolution; ++j, theta += step, v += duv) {
1488 float ct = cos(theta), st = sin(theta);
1489 N[kn++] = ct*cp0;
1490 N[kn++] = ct*sp0;
1491 N[kn++] = st;
1492 T[kt++] = u;
1493 T[kt++] = v;
1494 V[kv++] = ct*cp0;
1495 V[kv++] = ct*sp0;
1496 V[kv++] = st;
1497 N[kn++] = ct*cp1;
1498 N[kn++] = ct*sp1;
1499 N[kn++] = st;
1500 T[kt++] = u+duv;
1501 T[kt++] = v;
1502 V[kv++] = ct*cp1;
1503 V[kv++] = ct*sp1;
1504 V[kv++] = st;
1505 }
1506 if (edges)
1507 draw_edges_of_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1508 else
1509 draw_strip_or_fan(&V[0], &N[0], &T[0], &F[0], &F[0], &F[0], resolution, 4, false, flip_normals);
1510 }
1511
1512}
1515{
1516 static const float a = float(1.0/(2*sqrt(3.0)));
1517 static const float b = float(1.0/(3*sqrt(3.0/2)));
1518 static const float V[4*3] = {
1519 -0.5, -a, -b,
1520 0.5, -a, -b,
1521 0,2*a, -b,
1522 0, 0,2*b
1523 };
1524 static const int F[4*3] = {
1525 0,2,1,3,2,0,3,0,1,3,1,2
1526 };
1527 static int FN[4*3];
1528 static float N[4*3];
1529 static bool computed = false;
1530 if (!computed) {
1531 compute_face_normals(V, N, F, FN, 4, 3);
1532 computed = true;
1533 }
1534 if (edges)
1535 draw_edges_of_faces(V, N, 0, F, FN, 0, 4, 3, flip_normals);
1536 else
1537 draw_faces(V, N, 0, F, FN, 0, 4, 3, flip_normals);
1538}
1539
1540
1543{
1544 static float N[1*3] = {
1545 0,0,+1
1546 };
1547 static float V[4*3] = {
1548 -1,-1,0, +1,-1,0,
1549 +1,+1,0, -1,+1,0
1550 };
1551 static float T[4*2] = {
1552 0,0, 1,0,
1553 1,1, 0,1
1554 };
1555 static int FN[1*4] = {
1556 0,0,0,0
1557 };
1558 static int F[1*4] = {
1559 0,1,2,3
1560 };
1561 if (edges)
1562 draw_edges_of_faces(V, N, T, F, FN, F, 1, 4, flip_normals);
1563 else
1564 draw_faces(V, N, T, F, FN, F, 1, 4, flip_normals);
1565}
1566
1567
1570{
1571 static float N[8*3] = {
1572 -1,-1,+1, +1,-1,+1, -1,+1,+1, +1,+1,+1,
1573 -1,-1,-1, +1,-1,-1, -1,+1,-1, +1,+1,-1
1574 };
1575 static float V[6*3] = {
1576 -1,0,0, +1,0,0,
1577 0,-1,0, 0,+1,0,
1578 0,0,-1, 0,0,+1
1579 };
1580 static int FN[8*3] = {
1581 0,0,0,
1582 1,1,1,
1583 2,2,2,
1584 3,3,3,
1585 4,4,4,
1586 5,5,5,
1587 6,6,6,
1588 7,7,7
1589 };
1590 static int F[8*3] = {
1591 0,2,5,
1592 1,5,2,
1593 5,3,0,
1594 3,5,1,
1595 4,2,0,
1596 4,1,2,
1597 3,4,0,
1598 1,4,3
1599 };
1600 if (edges)
1601 draw_edges_of_faces(V, N, 0, F, FN, 0, 8, 3, flip_normals);
1602 else
1603 draw_faces(V, N, 0, F, FN, 0, 8, 3, flip_normals);
1604}
1605
1608{
1609 static const float h = 0.4472135956f;
1610 static const float r = 0.8944271912f;
1611 static const float s = float(M_PI/2.5);
1612 static const float o = float(M_PI/5);
1613 static const float V[13*3] = {
1614 0,0,-1,
1615 r*sin(1*s),r*cos(1*s),-h,
1616 r*sin(2*s),r*cos(2*s),-h,
1617 r*sin(3*s),r*cos(3*s),-h,
1618 r*sin(4*s),r*cos(4*s),-h,
1619 r*sin(5*s),r*cos(5*s),-h,
1620 r*sin(1*s+o),r*cos(1*s+o),h,
1621 r*sin(2*s+o),r*cos(2*s+o),h,
1622 r*sin(3*s+o),r*cos(3*s+o),h,
1623 r*sin(4*s+o),r*cos(4*s+o),h,
1624 r*sin(5*s+o),r*cos(5*s+o),h,
1625 0,0,1,
1626 0,0,0
1627 };
1628 static int F[20*3] = {
1629 0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,1,
1630 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,
1631 11,6,10, 11,10,9, 11,9,8, 11,8,7, 11,7,6
1632 };
1633 static int DF[12*5] = {
1634 0,1,2,3,4,
1635 5,6,7,1,0,
1636 7,8,9,2,1,
1637 9,10,11,3,2,
1638 11,12,13,4,3,
1639 13,14,5,0,4,
1640 16,15,14,13,12,
1641 17,16,12,11,10,
1642 18,17,10,9,8,
1643 19,18,8,7,6,
1644 15,19,6,5,14,
1645 15,16,17,18,19
1646 };
1647 static float N[20*3];
1648 static int FN[20*3];
1649 static int DFN[12*5] = {
1650 0,0,0,0,0,
1651 2,2,2,2,2,
1652 3,3,3,3,3,
1653 4,4,4,4,4,
1654 5,5,5,5,5,
1655 1,1,1,1,1,
1656 10,10,10,10,10,
1657 9,9,9,9,9,
1658 8,8,8,8,8,
1659 7,7,7,7,7,
1660 6,6,6,6,6,
1661 11,11,11,11,11
1662 };
1663
1664 static bool computed = false;
1665 if (!computed) {
1666 compute_face_normals(V, N, F, FN, 20, 3);
1667 computed = true;
1668 }
1669 if (!dual) {
1670 if (edges)
1671 c.draw_edges_of_faces(V, N, 0, F, FN, 0, 20, 3, flip_normals);
1672 else
1673 c.draw_faces(V, N, 0, F, FN, 0, 20, 3, flip_normals);
1674 }
1675 else {
1676 if (edges)
1677 c.draw_edges_of_faces(N, V, 0, DF, DFN, 0, 12, 5, flip_normals);
1678 else
1679 c.draw_faces(N, V, 0, DF, DFN, 0, 12, 5, flip_normals);
1680 }
1681}
1682
1693
1695{
1697}
1700{
1701 int gi = prog.get_uniform_location(*this, "gamma");
1702 if (gi != -1)
1703 prog.set_uniform(*this, gi, get_gamma());
1704 int gi3 = prog.get_uniform_location(*this, "gamma3");
1705 if (gi3 != -1)
1706 prog.set_uniform(*this, gi3, get_gamma3());
1707}
1708
1710{
1711 gamma3 = _gamma3;
1713 return;
1714
1715 if (shader_program_stack.empty())
1716 return;
1717
1719 if (prog.does_use_gamma())
1720 set_current_gamma(prog);
1721}
1722
1728
1731{
1732 if (core_profile) {
1733 if (dummy_aab == 0) {
1735 attribute_array_binding_create(*dummy_aab);
1736 }
1737 attribute_array_binding_enable(*dummy_aab);
1738 }
1739}
1742{
1743 if (core_profile) {
1744 if (dummy_aab == 0)
1745 error("call to end_attribute_less_rendering() without call to begin_attribute_less_rendering()");
1746 else if (attribute_array_binding_stack.empty())
1747 error("call to end_attribute_less_rendering() with empty attribute array binding stack");
1748 else if (attribute_array_binding_stack.top() != dummy_aab)
1749 error("call to end_attribute_less_rendering() after another attribute array was bound");
1750 else
1751 attribute_array_binding_disable(*dummy_aab);
1752 }
1753}
1756{
1757 return current_color;
1758}
1759
1762{
1764 if (shader_program_stack.empty())
1765 return;
1767 if (!prog.does_context_set_color())
1768 return;
1769 int clr_loc = prog.get_color_index();
1770 if (clr_loc == -1)
1771 return;
1772 prog.set_attribute(*this, clr_loc, clr);
1773}
1774
1777{
1778 current_material_ptr = &material;
1780
1782 return;
1783
1784 if (shader_program_stack.empty())
1785 return;
1786
1788 if (!prog.does_use_material())
1789 return;
1790
1791 prog.set_material_uniform(*this, "material", material);
1792}
1793
1796{
1797 current_material_ptr = &material;
1799
1801 return;
1802
1803 if (shader_program_stack.empty())
1804 return;
1805
1807 if (!prog.does_use_material())
1808 return;
1809
1810 prog.set_textured_material_uniform(*this, "material", material);
1811}
1812
1816
1818 SAFE_STACK_POP(depth_test_state_stack, "pop_depth_test_state");
1820}
1821
1825
1829
1831 depth_test_state_stack.top().test_func = func;
1832}
1833
1834
1836 depth_test_state_stack.top().enabled = true;
1837}
1838
1840 depth_test_state_stack.top().enabled = false;
1841}
1842
1846
1848 SAFE_STACK_POP(cull_state_stack, "pop_cull_state");
1850}
1851
1853 return cull_state_stack.top();
1854}
1855
1857 cull_state_stack.push(culling_mode);
1858}
1859
1863
1865 SAFE_STACK_POP(blend_state_stack, "pop_blend_state");
1867}
1868
1872
1874 blend_state_stack.top() = state;
1875}
1876
1884
1892
1894 set_blend_func(BF_ONE_MINUS_DST_ALPHA, BF_ONE);
1895}
1897 set_blend_func(BF_SRC_ALPHA, BF_ONE_MINUS_SRC_ALPHA);
1898}
1899
1901 blend_state_stack.top().enabled = true;
1902}
1903
1905 blend_state_stack.top().enabled = false;
1906}
1907
1911
1913 SAFE_STACK_POP(buffer_mask_stack, "pop_buffer_mask");
1915}
1916
1920
1924
1926 return buffer_mask_stack.top().depth_flag;
1927}
1928
1930 buffer_mask_stack.top().depth_flag = flag;
1931}
1932
1934 auto& mask = buffer_mask_stack.top();
1935 return bvec4(mask.red_flag, mask.green_flag, mask.blue_flag, mask.alpha_flag);
1936}
1937
1939 auto& mask = buffer_mask_stack.top();
1940 mask.red_flag = flags[0];
1941 mask.green_flag = flags[1];
1942 mask.blue_flag = flags[2];
1943 mask.alpha_flag = flags[3];
1944}
1945
1950
1956
1959{
1960 SAFE_STACK_POP(modelview_matrix_stack, "pop_modelview_matrix");
1962}
1965{
1966 projection_matrix_stack.push(get_projection_matrix());
1967}
1970{
1971 SAFE_STACK_POP(projection_matrix_stack, "pop_projection_matrix");
1972 set_projection_matrix(projection_matrix_stack.top());
1973}
1979
1981{
1982 // set new modelview matrix on matrix stack
1983 modelview_matrix_stack.top() = V;
1984
1985 // update in current shader
1987 return;
1988
1989 if (shader_program_stack.empty())
1990 return;
1992 if (!prog.does_use_view())
1993 return;
1994 set_current_view(prog, true, false);
1995}
1996
1998{
1999 // set new projection matrix on matrix stack
2000 projection_matrix_stack.top() = P;
2001
2002 // update in current shader
2004 return;
2005
2006 if (shader_program_stack.empty())
2007 return;
2009 if (!prog.does_use_view())
2010 return;
2011 set_current_view(prog, false, true);
2012}
2013
2020{
2021 SAFE_STACK_POP(window_transformation_stack, "pop_window_transformation_array");
2022}
2023
2024bool context::ensure_window_transformation_index(int& array_index)
2025{
2026 if (array_index == -1) {
2027 window_transformation_stack.top().resize(1);
2028 array_index = 0;
2029 return true;
2030 }
2031 else {
2032 if (array_index >= (int)window_transformation_stack.top().size()) {
2034 std::string message("context::ensure_window_transformation_index() ... attempt to resize window transformation array larger than maximum allowed size of ");
2036 error(message);
2037 return false;
2038 }
2039 window_transformation_stack.top().resize(array_index + 1);
2040 }
2041 }
2042 return true;
2043}
2044
2045void context::set_viewport(const ivec4& viewport, int array_index)
2046{
2047 if (!ensure_window_transformation_index(array_index))
2048 return;
2049 window_transformation_stack.top().at(array_index).viewport = viewport;
2050}
2051
2052void context::set_depth_range(const dvec2& depth_range, int array_index)
2053{
2054 if (!ensure_window_transformation_index(array_index))
2055 return;
2056 window_transformation_stack.top().at(array_index).depth_range = depth_range;
2057}
2058
2059const std::vector<window_transformation>& context::get_window_transformation_array() const
2060{
2061 return window_transformation_stack.top();
2062}
2063
2066{
2067 if (array_index >= window_transformation_stack.top().size()) {
2068 std::string message("context::get_window_matrix() ... attempt to query window matrix with array index ");
2070 message += " out of range [0,";
2071 message += cgv::utils::to_string(window_transformation_stack.top().size());
2072 message += "[";
2073 error(message);
2074 return cgv::math::identity4<double>();
2075 }
2077 dmat4 M = cgv::math::identity4<double>();
2078 M(0, 0) = 0.5*wt.viewport[2];
2079 M(0, 3) = M(0, 0) + wt.viewport[0];
2080 M(1, 1) = 0.5*wt.viewport[3];
2081 M(1, 3) = M(1, 1) + wt.viewport[1];
2082 M(2, 2) = 0.5*(wt.depth_range[1] - wt.depth_range[0]);
2083 M(2, 3) = M(2, 2) + wt.depth_range[0];
2084 return M;
2085}
2091
2094{
2095 cgv::dvec4 p(p_window, 1.0);
2096 p = inverse(modelview_projection_window_matrix) * p;
2097 p /= p.w();
2098 return cgv::vec3(static_cast<cgv::vec4>(p));
2099}
2100
2102void context::set_cursor(int x, int y)
2103{
2104 output_stream().flush();
2105 cursor_x = x;
2106 cursor_y = y;
2107 x_offset = x;
2108 y_offset = y;
2109 nr_identations = 0;
2110 at_line_begin = true;
2111}
2112
2114void context::put_cursor_coords(const vecn& p, int& x, int& y) const
2115{
2116 dvec4 p4(0, 0, 0, 1);
2117 for (unsigned int c = 0; c < p.size(); ++c)
2118 p4(c) = p(c);
2119
2121
2122 x = (int)(p4(0) / p4(3));
2123 y = (int)(p4(1) / p4(3));
2124 error("context::put_cursor_coords() deprecated");
2125}
2126
2130{
2131 dvec4 p4(dvec3(p), 1.0);
2133 return cgv::ivec2(
2134 static_cast<int>(p4.x() / p4.w()),
2135 static_cast<int>(p4.y() / p4.w())
2136 );
2137}
2138
2140void context::set_cursor(const vecn& pos,
2141 const std::string& text, TextAlignment ta,
2142 int x_offset, int y_offset)
2143{
2144 int x,y;
2145 put_cursor_coords(pos, x, y);
2146 if (!text.empty() && get_current_font_face()) {
2147 float h = get_current_font_size();
2148 float w = get_current_font_face()->measure_text_width(text, h);
2149 switch (ta&3) {
2150 case 0 : x -= (int)(floor(w)*0.5f);break;
2151 case 2 : x -= (int)floor(w);break;
2152 default: break;
2153 }
2154 switch (ta&12) {
2155 case 0 : y -= (int)(floor(h)*0.3f);break;
2156 case 4 : y -= (int)(floor(h)*0.6f); break;
2157 default: break;
2158 }
2159 }
2160 x += x_offset;
2161 y += y_offset;
2162 set_cursor(x,y);
2163}
2164
2167 const std::string& text, TextAlignment ta,
2168 ivec2 offset)
2169{
2171 if(!text.empty() && get_current_font_face()) {
2172 float h = get_current_font_size();
2173 float w = get_current_font_face()->measure_text_width(text, h);
2174 switch(ta & 3) {
2175 case 0: cursor.x() -= static_cast<int>(std::floor(w) * 0.5f); break;
2176 case 2: cursor.x() -= static_cast<int>(std::floor(w)); break;
2177 default: break;
2178 }
2179 switch(ta & 12) {
2180 case 0: cursor.y() -= static_cast<int>(std::floor(h) * 0.3f); break;
2181 case 4: cursor.y() -= static_cast<int>(std::floor(h) * 0.6f); break;
2182 default: break;
2183 }
2184 }
2185 cursor += offset;
2186 set_cursor(cursor.x(), cursor.y());
2187}
2188
2190void context::get_cursor(int& x, int& y) const
2191{
2192 x = cursor_x;
2193 y = cursor_y;
2194}
2195
2201
2202void context::tesselate_arrow(double length, double aspect, double rel_tip_radius, double tip_aspect, int res, bool edges)
2203{
2204 std::cout << "tesselate_arrow not implemented in cgv::render::context" << std::endl;
2205}
2206
2207void 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)
2208{
2209 std::cout << "tesselate_arrow not implemented in cgv::render::context" << std::endl;
2210}
2211
2213{
2214 std::cout << "draw_light_source not implemented in cgv::render::context" << std::endl;
2215}
2216
2218{
2219 handle = 0;
2220 internal_format = 0;
2221 user_data = 0;
2222 ctx_ptr = 0;
2223}
2224
2227{
2228 return handle != 0;
2229}
2230
2231
2233{
2234 if (!ctx_ptr) {
2235 std::cerr << "no context set when render_component::put_id_void was called" << std::endl;
2236 return;
2237 }
2238 ctx_ptr->put_id(handle, ptr);
2239}
2240
2241render_buffer_base::render_buffer_base()
2242{
2243}
2244
2247{
2248 mag_filter = TF_LINEAR;
2249 min_filter = TF_LINEAR_MIPMAP_LINEAR;
2250 wrap_s = TW_CLAMP_TO_EDGE;
2251 wrap_t = TW_CLAMP_TO_EDGE;
2252 wrap_r = TW_CLAMP_TO_EDGE;
2253 anisotropy = 1;
2254 priority = 0.5f;
2255 border_color[0] = 1;
2256 border_color[1] = 1;
2257 border_color[2] = 1;
2258 border_color[3] = 1;
2259 tt = _tt;
2260 compare_function = CF_LEQUAL;
2261 use_compare_function = false;
2262 have_mipmaps = false;
2263}
2264
2265void shader_program_base::allow_context_to_set_color(bool allow)
2266{
2267 context_sets_color = allow;
2268}
2269
2271{
2272 is_enabled = false;
2273 geometry_shader_input_type = PT_POINTS;
2274 geometry_shader_output_type = PT_POINTS;
2275 geometry_shader_output_count = 1;
2276
2277 auto_detect_uniforms = true;
2278 auto_detect_vertex_attributes = true;
2279
2280 uses_view = false;
2281 uses_material = false;
2282 uses_lights = false;
2283 uses_gamma = false;
2284
2285 position_index = -1;
2286 normal_index = -1;
2287 color_index = -1;
2288 context_sets_color = true;
2289 texcoord_index = -1;
2290}
2291
2292// configure program
2293void shader_program_base::specify_standard_uniforms(bool view, bool material, bool lights, bool gamma)
2294{
2295 auto_detect_uniforms = false;
2296 uses_view = view;
2297 uses_material = material;
2298 uses_lights = lights;
2299 uses_gamma = gamma;
2300}
2301
2302void shader_program_base::specify_standard_vertex_attribute_names(context& ctx, bool color, bool normal, bool texcoord)
2303{
2304 auto_detect_vertex_attributes = false;
2305 position_index = ctx.get_attribute_location(*this, "position");
2306 color_index = color ? ctx.get_attribute_location(*this, "color") : -1;
2307 normal_index = normal ? ctx.get_attribute_location(*this, "normal") : -1;
2308 texcoord_index = texcoord ? ctx.get_attribute_location(*this, "texcoord") : -1;
2309}
2310
2311void 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)
2312{
2313 auto_detect_vertex_attributes = false;
2314 position_index = position.empty() ? -1 : ctx.get_attribute_location(*this, position);
2315 color_index = color.empty() ? -1 : ctx.get_attribute_location(*this, color);
2316 normal_index = normal.empty() ? -1 : ctx.get_attribute_location(*this, normal);
2317 texcoord_index = texcoord.empty() ? -1 : ctx.get_attribute_location(*this, texcoord);
2318}
2319bool context::shader_program_link(shader_program_base& spb) const
2320{
2321 if (spb.handle == 0)
2322 return false;
2323 if (spb.auto_detect_vertex_attributes) {
2324 spb.position_index = get_attribute_location(spb, "position");
2325 spb.color_index = get_attribute_location(spb, "color");
2326 spb.normal_index = get_attribute_location(spb, "normal");
2327 spb.texcoord_index = get_attribute_location(spb, "texcoord");
2328 spb.auto_detect_vertex_attributes = false;
2329 }
2330 if (spb.auto_detect_uniforms) {
2331 spb.uses_lights = get_uniform_location(spb, "light_sources[0].light_source_type") != -1;
2332 spb.uses_material = get_uniform_location(spb, "material.brdf_type") != -1;
2333 spb.uses_view =
2334 get_uniform_location(spb, "modelview_matrix") != -1 ||
2335 get_uniform_location(spb, "projection_matrix") != -1 ||
2336 get_uniform_location(spb, "inverse_projection_matrix") != -1 ||
2337 get_uniform_location(spb, "normal_matrix") != -1 ||
2338 get_uniform_location(spb, "inverse_modelview_matrix") != -1 ||
2339 get_uniform_location(spb, "inverse_normal_matrix") != -1;
2340 spb.uses_gamma = get_uniform_location(spb, "gamma3") != -1 || get_uniform_location(spb, "gamma") != -1;
2341 spb.auto_detect_uniforms = false;
2342 }
2343 return true;
2344}
2345
2346bool context::shader_program_enable(shader_program_base& spb)
2347{
2348 if (spb.is_enabled) {
2349 if (shader_program_stack.top() == &spb) {
2350 error("context::shader_program_enable() called with program that is currently active", &spb);
2351 return false;
2352 }
2353 error("context::shader_program_enable() called with program that is recursively reactivated", &spb);
2354 return false;
2355 }
2357 spb.is_enabled = true;
2358 return true;
2359}
2360
2361bool context::shader_program_disable(shader_program_base& spb)
2362{
2363 if (shader_program_stack.empty()) {
2364 error("context::shader_program_disable() called with empty stack", &spb);
2365 return false;
2366 }
2367 if (!spb.is_enabled) {
2368 error("context::shader_program_disable() called with disabled program", &spb);
2369 return false;
2370 }
2371 if (shader_program_stack.top() != &spb) {
2372 error("context::shader_program_disable() called with program that was not on top of shader program stack", &spb);
2373 return false;
2374 }
2376 spb.is_enabled = false;
2377 return true;
2378}
2379
2380bool context::shader_program_destruct(shader_program_base& spb) const
2381{
2382 if (spb.is_enabled) {
2383 error("context::shader_program_destruct() on shader program that was still enabled", &spb);
2384/* if (shader_program_stack.top() == &spb)
2385 shader_program_disable(spb);
2386 else {
2387 error("context::shader_program_destruct() on shader program that was still enabled", &spb);
2388 // remove destructed program from stack
2389 std::vector<shader_program_base*> tmp;
2390 while (!shader_program_stack.empty()) {
2391 shader_program_base* t = shader_program_stack.top();
2392 shader_program_stack.pop();
2393 if (t == &spb)
2394 break;
2395 tmp.push_back(t);
2396 }
2397 while (!tmp.empty()) {
2398 shader_program_stack.push(tmp.back());
2399 tmp.pop_back();
2400 }
2401 }*/
2402 return false;
2403 }
2404 return true;
2405}
2406
2407void context::shader_program_set_uniform_locations(shader_program_base& spb) const
2408{
2409 spb.uniform_locations.clear();
2410 std::vector<std::string> uniform_names;
2411 if(shader_program_get_active_uniforms(spb, uniform_names)) {
2412 for(size_t i = 0; i < uniform_names.size(); ++i) {
2413 int location = get_uniform_location(spb, uniform_names[i]);
2414 if(location > -1)
2415 spb.uniform_locations[uniform_names[i]] = location;
2416 }
2417 }
2418}
2419
2424
2425
2426bool context::attribute_array_binding_destruct(attribute_array_binding_base& aab) const
2427{
2428 if (aab.is_enabled) {
2429 error("context::attribute_array_binding_destruct() on array binding that was still enabled", &aab);
2430 /*
2431 if (attribute_array_binding_stack.top() == &aab)
2432 attribute_array_binding_disable(aab);
2433 else {
2434 // remove destructed binding from stack
2435 std::vector<attribute_array_binding_base*> tmp;
2436 while (!attribute_array_binding_stack.empty()) {
2437 attribute_array_binding_base* t = attribute_array_binding_stack.top();
2438 attribute_array_binding_stack.pop();
2439 if (t == &aab)
2440 break;
2441 tmp.push_back(t);
2442 }
2443 while (!tmp.empty()) {
2444 attribute_array_binding_stack.push(tmp.back());
2445 tmp.pop_back();
2446 }
2447 }
2448 */
2449 return false;
2450 }
2451 return true;
2452}
2453
2454bool context::attribute_array_binding_enable(attribute_array_binding_base& aab)
2455{
2456 if (!aab.handle) {
2457 error("context::attribute_array_binding_enable() called in not created attribute array binding.", &aab);
2458 return false;
2459 }
2460 if (aab.is_enabled) {
2461 if (attribute_array_binding_stack.top() == &aab) {
2462 error("context::attribute_array_binding_enable() called with array binding that is currently active", &aab);
2463 return false;
2464 }
2465 error("context::attribute_array_binding_enable() called with array binding that is recursively reactivated", &aab);
2466 return false;
2467 }
2469 aab.is_enabled = true;
2470 return true;
2471}
2472
2473bool context::attribute_array_binding_disable(attribute_array_binding_base& aab)
2474{
2475 if (attribute_array_binding_stack.empty()) {
2476 error("context::attribute_array_binding_disable() called with empty stack", &aab);
2477 return false;
2478 }
2479 if (!aab.is_enabled) {
2480 error("context::attribute_array_binding_disable() called with disabled array binding", &aab);
2481 return false;
2482 }
2483 if (attribute_array_binding_stack.top() != &aab) {
2484 error("context::attribute_array_binding_disable() called with array binding that was not on top of array binding stack", &aab);
2485 return false;
2486 }
2488 aab.is_enabled = false;
2489 return true;
2490}
2491
2494{
2495 is_enabled = false;
2496 width = -1;
2497 height = -1;
2498 depth_attached = false;
2499 std::fill(attached, attached+16,false);
2500}
2501
2502void context::get_buffer_list(frame_buffer_base& fbb, bool& depth_buffer, std::vector<int>& buffers, int offset)
2503{
2504 if (fbb.enabled_color_attachments.size() == 0) {
2505 for (int i = 0; i < 16; ++i)
2506 if (fbb.attached[i])
2507 buffers.push_back(i + offset);
2508 }
2509 else {
2510 for (int i = 0; i < (int)fbb.enabled_color_attachments.size(); ++i)
2511 if (fbb.attached[fbb.enabled_color_attachments[i]])
2512 buffers.push_back(fbb.enabled_color_attachments[i]+offset);
2513 }
2514 depth_buffer = fbb.depth_attached;
2515}
2516
2517bool context::frame_buffer_create(frame_buffer_base& fbb) const
2518{
2519 if (fbb.width == -1)
2520 fbb.width = get_width();
2521 if (fbb.height == -1)
2522 fbb.height = get_height();
2523 return true;
2524}
2525
2526bool context::frame_buffer_attach(frame_buffer_base& fbb, const render_buffer_base& rb, bool is_depth, int i) const
2527{
2528 if (fbb.handle == 0) {
2529 error("gl_context::frame_buffer_attach: attempt to attach to frame buffer that is not created", &fbb);
2530 return false;
2531 }
2532 if (rb.handle == 0) {
2533 error("gl_context::frame_buffer_attach: attempt to attach empty render buffer", &fbb);
2534 return false;
2535 }
2536 if (is_depth)
2537 fbb.depth_attached = true;
2538 else
2539 fbb.attached[i] = true;
2540
2541 return true;
2542}
2543
2544bool 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
2545{
2546 if (fbb.handle == 0) {
2547 error("context::frame_buffer_attach: attempt to attach to frame buffer that is not created", &fbb);
2548 return false;
2549 }
2550 if (t.handle == 0) {
2551 error("context::frame_buffer_attach: attempt to attach texture that is not created", &fbb);
2552 return false;
2553 }
2554 if(is_depth)
2555 fbb.depth_attached = true;
2556 else
2557 fbb.attached[i] = true;
2558
2559 return true;
2560}
2561
2562bool context::frame_buffer_enable(frame_buffer_base& fbb)
2563{
2564 if (fbb.handle == 0) {
2565 error("context::frame_buffer_enable: attempt to enable not created frame buffer", &fbb);
2566 return false;
2567 }
2568 if (fbb.is_enabled) {
2569 if (frame_buffer_stack.top() == &fbb) {
2570 error("context::frame_buffer_enable() called with frame buffer that is currently active", &fbb);
2571 return false;
2572 }
2573 error("context::frame_buffer_enable() called with frame buffer that is recursively reactivated", &fbb);
2574 return false;
2575 }
2576 frame_buffer_stack.push(&fbb);
2577 fbb.is_enabled = true;
2578 return true;
2579}
2580
2581bool context::frame_buffer_disable(frame_buffer_base& fbb)
2582{
2583 if (frame_buffer_stack.size() == 1) {
2584 error("gl_context::frame_buffer_disable called with empty stack", &fbb);
2585 return false;
2586 }
2587 if (frame_buffer_stack.top() != &fbb) {
2588 error("gl_context::frame_buffer_disable called with different frame buffer enabled", &fbb);
2589 return false;
2590 }
2591 frame_buffer_stack.pop();
2592 fbb.is_enabled = false;
2593 return true;
2594}
2595
2596bool context::frame_buffer_destruct(frame_buffer_base& fbb) const
2597{
2598 if (fbb.handle == 0) {
2599 error("context::frame_buffer_destruct: attempt to destruct not created frame buffer", &fbb);
2600 return false;
2601 }
2602 if (fbb.is_enabled) {
2603 error("context::frame_buffer_destruct() on frame buffer that was still enabled", &fbb);
2604 return false;
2605 }
2606 return true;
2607}
2608
2609std::vector<context_creation_function_type>& ref_context_creation_functions()
2610{
2611 static std::vector<context_creation_function_type> ccfs;
2612 return ccfs;
2613}
2614
2616void register_context_factory(context_creation_function_type fp)
2617{
2618 ref_context_creation_functions().push_back(fp);
2619}
2620
2621context_factory_registration::context_factory_registration(context_creation_function_type fp)
2622{
2624};
2625
2630 unsigned int w, unsigned int h,
2631 const std::string& title, bool show)
2632{
2633 std::vector<context_creation_function_type>& ccfs = ref_context_creation_functions();
2634 for (unsigned i=0; i<ccfs.size(); ++i) {
2635 context* ctx = ccfs[i](api,w,h,title,show);
2636 if (ctx) {
2637 ctx->make_current();
2638 return ctx;
2639 }
2640 }
2641 std::cerr << "could not create context for given parameters" << std::endl;
2642 return 0;
2643}
2644
2645
2646 }
2647}
2648
2649#include <cgv/base/register.h>
2650
2652{
2654 {
2655 cgv::base::register_object(cgv::render::get_render_config(), "register global render config");
2656 }
2657};
2658
2659render_config_registration render_config_registration_instance;
2660
2661#undef SAFE_STACK_POP
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:303
T & w()
return fourth component
Definition fvec.h:148
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
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:461
attribute_array_binding_base()
nothing to be done heremembers
Definition context.cxx:2420
the attribute_array_binding allows to define vertex attributes (i.e.
base class for all drawables, which is independent of the used rendering API.
Definition context.h:668
void push_window_transformation_array()
push a copy of the current viewport and depth range arrays defining the window transformations
Definition context.cxx:2014
void tesselate_unit_prism(bool flip_normals=false, bool edges=false)
tesselate a prism
Definition context.cxx:1260
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:610
virtual void set_blend_func(BlendFunction src_factor, BlendFunction dst_factor)
set the blend function
Definition context.cxx:1877
void enable_shader_file_cache()
enable the usage of the shader file caches
Definition context.cxx:557
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:1032
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 (source = BF_SRC_ALPHA, destination = BF_ON...
Definition context.cxx:1896
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
Definition context.cxx:1952
void pop_bg_color()
pop the top of the current background color from the stack
Definition context.cxx:385
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:2052
vec3 gamma3
per color channel gamma value passed to shader programs that have gamma uniform
Definition context.h:748
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:974
virtual void set_color(const rgba &clr)
set the current color
Definition context.cxx:1761
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:2212
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:1709
virtual void enable_sRGB_framebuffer(bool do_enable=true)
enable or disable sRGB framebuffer
Definition context.cxx:531
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:829
void pop_buffer_mask()
pop the top of the current buffer mask from the stack
Definition context.cxx:1912
shader_program_base * get_current_program() const
check for current program, prepare it for rendering and return pointer to it
Definition context.cxx:537
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
Definition context.cxx:307
std::stack< render_info > render_pass_stack
store the current render pass
Definition context.h:827
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:318
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:682
float current_font_size
store current font size
Definition context.h:839
bool enable_vsync
whether vsync should be enabled
Definition context.h:742
const light_source_status & get_light_source_status(void *handle) const
read access to light source status
Definition context.cxx:661
void place_light_source(void *handle)
place the given light source relative to current model viel transformation
Definition context.cxx:754
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:1173
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:2190
std::stack< BufferMask > buffer_mask_stack
stack of buffer masks
Definition context.h:766
void set_bg_clr_idx(unsigned int idx)
set an indexed background color
Definition context.cxx:420
virtual void set_buffer_mask(BufferMask mask)
set the buffer mask for depth and color buffers
Definition context.cxx:1921
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:730
float get_bg_accum_alpha() const
return the current alpha value for clearing the accumulation buffer
Definition context.cxx:500
void set_bg_alpha(float a)
set a user defined background alpha value
Definition context.cxx:411
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:1885
size_t light_source_handle
counter to construct light source handles
Definition context.h:801
virtual void on_lights_changed()
helper function to send light update events
Definition context.cxx:738
context()
init the cursor position to (0,0)
Definition context.cxx:216
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:1813
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:2202
void put_bg_color(float *rgba) const
copy the current background rgba color into the given float array
Definition context.cxx:403
std::stack< shader_program_base * > shader_program_stack
stack of currently enabled shader programs
Definition context.h:775
virtual ivec2 get_cursor_coords(const vec3 &p) const
transform point p in current world coordinates into opengl coordinates with (0,0) in lower left corne...
Definition context.cxx:2129
void push_blend_state()
push a copy of the current blend state onto the stack saved attributes: blend enablement,...
Definition context.cxx:1860
bool is_light_source_enabled(void *handle)
check whether light source is enabled
Definition context.cxx:782
virtual void disable_depth_test()
disable the depth test
Definition context.cxx:1839
void pop_bg_depth()
pop the top of the current background depth value from the stack
Definition context.cxx:437
int get_bg_stencil() const
return the current stencil value for clearing the background
Definition context.cxx:463
virtual float get_current_font_size() const
return the size in pixels of the currently enabled font face
Definition context.cxx:1047
void pop_blend_state()
pop the top of the current culling state from the stack
Definition context.cxx:1864
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:1724
void set_bg_accum_alpha(float a)
set a user defined background alpha value for the accumulation buffer
Definition context.cxx:496
float get_gamma() const
query current gamma computed as average over gamma3 per channel values
Definition context.h:1145
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:806
int current_background
current back ground color index
Definition context.h:833
void set_blend_func_front_to_back()
set the default blend function for front to back blending (source = BF_ONE_MINUS_DST_ALPHA,...
Definition context.cxx:1893
virtual RenderPass get_render_pass() const
return the current render pass
Definition context.cxx:857
void pop_depth_test_state()
pop the top of the current depth test state from the stack
Definition context.cxx:1817
void tesselate_unit_sphere(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a sphere of radius 1
Definition context.cxx:1463
virtual RenderPassFlags get_render_pass_flags() const
return the current render pass flags
Definition context.cxx:864
void tesselate_unit_cylinder(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a cylinder of radius 1
Definition context.cxx:1371
float get_bg_alpha() const
return the current alpha value for clearing the background
Definition context.cxx:416
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:1060
unsigned int get_bg_clr_idx() const
return the current index of the background color
Definition context.cxx:429
void tesselate_unit_tetrahedron(bool flip_normals=false, bool edges=false)
tesselate a tetrahedron
Definition context.cxx:1514
virtual bool recreate_context()
recreate context based on current context config settings
Definition context.cxx:147
virtual void configure_new_child(cgv::base::base_ptr child)
helper method to integrate a new child
Definition context.cxx:363
virtual void set_bg_color(vec4 rgba)
set a user defined background color
Definition context.cxx:390
virtual void set_depth_test_state(DepthTestState state)
set the depth test state
Definition context.cxx:1826
void render_pass_debug_output(const render_info &ri, const std::string &info="")
write out render pass debug info, if activated
Definition context.cxx:906
void tesselate_unit_octahedron(bool flip_normals=false, bool edges=false)
tesselate a octahedron
Definition context.cxx:1569
size_t get_nr_enabled_light_sources() const
return the number of light sources
Definition context.cxx:771
const frame_buffer_base * get_current_frame_buffer() const
check for current framebuffer, and return pointer to it
Definition context.cxx:548
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:1147
void set_default_light_source(size_t i, const cgv::media::illum::light_source &ls)
set i-th default light source
Definition context.cxx:829
virtual void disable_blending()
disable blending
Definition context.cxx:1904
BufferMask get_buffer_mask() const
return the current buffer mask
Definition context.cxx:1917
void push_cull_state()
push a copy of the current culling state onto the stack saved attributes: cull face enablement,...
Definition context.cxx:1843
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:1037
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:2087
dmat4 get_window_matrix(unsigned array_index=0) const
return a homogeneous 4x4 matrix to transform clip to window coordinates
Definition context.cxx:2065
bool update_render_pass_flags(int exclude_flags, int include_flags=0)
update the current render pass flags, return whether this was possible (fails outside of render passe...
Definition context.cxx:872
void pop_bg_stencil()
pop the top of the current background stencil value from the stack
Definition context.cxx:454
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:769
vec3 get_light_eye_position(const cgv::media::illum::light_source &light, bool place_now) const
helper function to place lights
Definition context.cxx:581
void push_bg_stencil()
push a copy of the current background stencil value onto the stack
Definition context.cxx:450
virtual unsigned get_max_nr_enabled_light_sources() const
return maximum number of light sources, that can be enabled in parallel
Definition context.cxx:765
virtual void pop_window_transformation_array()
restore previous viewport and depth range arrays defining the window transformations
Definition context.cxx:2019
const cgv::media::illum::light_source & get_default_light_source(size_t i) const
return i-th default light source
Definition context.cxx:823
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:726
virtual void set_color_mask(bvec4 flags)
set the color buffer mask
Definition context.cxx:1938
virtual void set_material(const cgv::media::illum::surface_material &mat)
set the current material
Definition context.cxx:1776
DepthTestState get_depth_test_state() const
return the current depth test state
Definition context.cxx:1822
int nr_identations
current number of indentations
Definition context.h:847
void tesselate_unit_dodecahedron(bool flip_normals=false, bool edges=false)
tesselate a dodecahedron
Definition context.cxx:1684
bool auto_set_material_in_current_shader_program
whether to automatically set material in current shader program, defaults to true
Definition context.h:732
void set_current_lights(shader_program &prog) const
set the shader program lights to the currently enabled lights
Definition context.cxx:723
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:1226
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:791
virtual void * get_render_pass_user_data() const
return the current render pass user data
Definition context.cxx:895
void tesselate_unit_disk(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a circular disk of radius 1
Definition context.cxx:1295
std::stack< float > bg_depth_stack
stack of background depth values
Definition context.h:753
virtual void enable_depth_test()
enable the depth test
Definition context.cxx:1835
bool support_compatibility_mode
whether to support view and lighting management of compatibility mode, defaults to true
Definition context.h:736
void set_current_gamma(shader_program &prog) const
set the shader program gamma values
Definition context.cxx:1699
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:1413
vec4 get_bg_color() const
return the current color value for clearing the background
Definition context.cxx:399
void pop_projection_matrix()
see push_P for an explanation
Definition context.cxx:1969
attribute_array_binding_base * dummy_aab
allocate a dummy attribute array binding used to support attribute-less rendering
Definition context.h:724
std::stack< attribute_array_binding_base * > attribute_array_binding_stack
stack of currently enabled attribute array binding
Definition context.h:789
BlendState get_blend_state() const
return the current blend state
Definition context.cxx:1869
virtual void set_cull_state(CullingMode culling_mode)
set the culling state
Definition context.cxx:1856
void tesselate_unit_icosahedron(bool flip_normals=false, bool edges=false)
tesselate an icosahedron
Definition context.cxx:1689
virtual void set_depth_func(CompareFunction func)
set the depth test function
Definition context.cxx:1830
void set_light_source(void *handle, const cgv::media::illum::light_source &light, bool place_now=true)
set light source newly
Definition context.cxx:669
std::stack< DepthTestState > depth_test_state_stack
stack of depth test states
Definition context.h:760
std::stack< CullingMode > cull_state_stack
stack of culling mode states
Definition context.h:762
void push_bg_depth()
push a copy of the current background depth value onto the stack
Definition context.cxx:433
bool get_depth_mask() const
get the depth buffer mask
Definition context.cxx:1925
void disable_shader_file_cache()
disable the usage of the shader file caches
Definition context.cxx:563
bool phong_shading
whether to use phong shading
Definition context.h:831
virtual void push_pixel_coords()=0
use this to push new modelview and new projection matrices onto the transformation stacks such that x...
void end_attribute_less_rendering()
unbind dummy attribute array after attribute-less rendering
Definition context.cxx:1741
void push_projection_matrix()
same as push_V but for the projection matrix - a different matrix stack is used.
Definition context.cxx:1964
bvec4 get_color_mask() const
get the color buffer mask
Definition context.cxx:1933
const rgba & get_color() const
return current color
Definition context.cxx:1755
bool is_shader_file_cache_enabled() const
whether the shader file caches are enabled
Definition context.cxx:569
bool current_material_is_textured
store flag to tell whether current material is textured
Definition context.h:817
void push_bg_accum_color()
push a copy of the current background accumulation color onto the stack
Definition context.cxx:467
virtual media::font::font_face_ptr get_current_font_face() const
return the currently enabled font face
Definition context.cxx:1053
virtual void set_projection_matrix(const dmat4 &P)
set the current projection matrix, which transforms from eye to clip space
Definition context.cxx:1997
rgba current_color
current color value
Definition context.h:744
static const unsigned nr_default_light_sources
number of default light sources
Definition context.h:807
cgv::media::illum::light_source default_light_source[nr_default_light_sources]
default light sources
Definition context.h:809
std::stack< int > bg_stencil_stack
stack of background stencil values
Definition context.h:755
virtual dmat4 get_projection_matrix() const =0
return homogeneous 4x4 projection matrix, which transforms from eye to clip space
void begin_attribute_less_rendering()
this function ensures that in core profile a dummy attribute array is bound, what is essential for at...
Definition context.cxx:1730
int tab_size
size a tabs
Definition context.h:843
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:2197
std::stack< vec4 > bg_accum_color_stack
stack of background accumulation colors
Definition context.h:757
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:2102
void pop_bg_accum_color()
pop the top of the current background accumulation color from the stack
Definition context.cxx:471
virtual void set_bg_stencil(int s)
set a user defined background stencil value
Definition context.cxx:459
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:2114
virtual void set_bg_accum_color(vec4 rgba)
set a user defined background color for the accumulation buffer
Definition context.cxx:476
virtual void set_default_render_pass_flags(RenderPassFlags)
return the default render pass flags
Definition context.cxx:887
float get_bg_depth() const
return the current depth value for clearing the background
Definition context.cxx:446
const std::vector< window_transformation > & get_window_transformation_array() const
return the current window transformation array
Definition context.cxx:2059
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:845
void put_bg_accum_color(float *rgba) const
copy the current accumulation background rgba color into the given float array
Definition context.cxx:488
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:803
virtual void set_textured_material(const textured_material &mat)
set the current material
Definition context.cxx:1795
std::stack< std::vector< window_transformation > > window_transformation_stack
keep stack of window transformations
Definition context.h:771
dvec3 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:1503
int cursor_x
current cursor location for textual output
Definition context.h:835
vec4 get_bg_accum_color() const
return the current color value for clearing the accumulation buffer
Definition context.cxx:484
const cgv::media::illum::light_source & get_light_source(void *handle) const
read access to light source
Definition context.cxx:654
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:738
virtual void set_blend_state(BlendState state)
set the complete blend state
Definition context.cxx:1873
virtual void render_pass(RenderPass render_pass=RP_MAIN, RenderPassFlags render_pass_flags=RPF_ALL, void *user_data=0, int rp_idx=-1)
perform the given render task
Definition context.cxx:920
bool remove_light_source(void *handle)
remove a light source by handle and whether it existed
Definition context.cxx:634
bool sRGB_framebuffer
whether to use opengl option to support sRGB framebuffer
Definition context.h:746
virtual RenderPassFlags get_default_render_pass_flags() const
return the default render pass flags
Definition context.cxx:882
virtual void set_bg_depth(float d)
set a user defined background depth value
Definition context.cxx:442
void set_gamma(float _gamma)
set the current per channel gamma values to single value
Definition context.cxx:1694
virtual void enable_blending()
enable blending
Definition context.cxx:1900
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:595
void set_current_material(shader_program &prog) const
set the shader program material to the currently enabled material
Definition context.cxx:711
void pop_cull_state()
pop the top of the current culling state from the stack
Definition context.cxx:1847
virtual void draw_text(const std::string &text)
draw some text at cursor position and update cursor position
Definition context.cxx:1019
void pop_modelview_matrix()
see push_V for an explanation
Definition context.cxx:1958
virtual ~context()
virtual destructor
Definition context.cxx:328
void * default_light_source_handles[nr_default_light_sources]
handles of default light sources
Definition context.h:811
void push_modelview_matrix()
push the current viewing matrix onto a matrix stack for viewing matrices.
Definition context.cxx:1946
std::stack< frame_buffer_base * > frame_buffer_stack
stack of currently enabled frame buffers
Definition context.h:773
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:849
size_t get_nr_light_sources() const
return the number of light sources
Definition context.cxx:575
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:1542
bool auto_set_view_in_current_shader_program
whether to automatically set viewing matrixes in current shader program, defaults to true
Definition context.h:728
bool debug_render_passes
whether to debug render passes
Definition context.h:740
std::vector< void * > enabled_light_source_handles
keep track of enabled light source handles
Definition context.h:799
void tesselate_unit_cone(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a cone of radius 1
Definition context.cxx:1327
CullingMode get_cull_state() const
return the current culling state
Definition context.cxx:1852
virtual void mul_projection_matrix(const dmat4 &P)
multiply given matrix from right to current projection matrix
Definition context.cxx:1975
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:2045
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:815
virtual void set_modelview_matrix(const dmat4 &MV)
set the current modelview matrix, which transforms from world to eye space
Definition context.cxx:1980
void push_bg_color()
push a copy of the current background color onto the stack
Definition context.cxx:381
void * get_enabled_light_source_handle(size_t i) const
access to handle of i-th light source
Definition context.cxx:777
void push_buffer_mask()
push a copy of the current buffer mask onto the stack saved attributes: depth mask,...
Definition context.cxx:1908
virtual void enable_phong_shading()
enable phong shading with the help of a shader (enabled by default)
Definition context.cxx:505
void set_debug_render_passes(bool _debug)
set flag whether to debug render passes
Definition context.cxx:901
cgv::media::font::font_face_ptr current_font_face
store current font
Definition context.h:841
cgv::signal::callback_stream out_stream
use a callback stream to write text to the opengl context
Definition context.h:837
std::stack< vec4 > bg_color_stack
stack of background colors
Definition context.h:751
unsigned get_render_pass_recursion_depth() const
return current render pass recursion depth
Definition context.cxx:851
std::stack< BlendState > blend_state_stack
stack of blend states
Definition context.h:764
virtual void set_depth_mask(bool flag)
set the depth buffer mask
Definition context.cxx:1929
bool auto_set_gamma_in_current_shader_program
whether to automatically set gamma in current shader program, defaults to true
Definition context.h:734
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:527
frame_buffer_base()
initialize members
Definition context.cxx:2493
base interface for all render components
Definition context.h:357
virtual bool is_created() const
return whether component has been created
Definition context.cxx:2226
const context * ctx_ptr
keep pointer to my context
Definition context.h:363
render_component()
initialize members
Definition context.cxx:2217
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:2232
base interface for shader programs
Definition context.h:411
shader_program_base()
initializes members
Definition context.cxx:2270
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:2246
class that extends obj_material with the management of textures
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:126
CullingMode
different culling modes
Definition context.h:199
void register_context_factory(context_creation_function_type fp)
registration context creation functions
Definition context.cxx:2616
BlendFunction
different blend functions
Definition context.h:206
std::ostream & operator<<(std::ostream &os, const type_descriptor &td)
operator to write textual description to stream
Definition context.cxx:30
TextAlignment
different text alignments
Definition context.h:329
std::string get_render_pass_name(RenderPass rp)
convert render pass type into string
Definition context.cxx:834
TextureFilter
different texture filter
Definition context.h:245
render_config_ptr get_render_config()
return a pointer to the current shader configuration
Definition context.cxx:210
TextureWrap
different texture wrap modes
Definition context.h:229
FrameBufferType
different frame buffer types which can be combined together with or
Definition context.h:544
MaterialSide
different sides of a material
Definition context.h:184
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:2629
TextureCubeSides
the six different sides of a cube
Definition context.h:271
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:1607
PrimitiveType
different primitive types
Definition context.h:281
RenderPass
Enumeration of different render passes, which can be queried from the context and used to specify a n...
Definition context.h:133
@ RP_NONE
no renderpass
Definition context.h:134
TextureType
different texture types
Definition context.h:257
RenderPassFlags
available flags that can be queried from the context and set for a new render pass
Definition context.h:149
@ RPF_DRAWABLES_FINISH_FRAME
whether to call finish frame method of drawables
Definition context.h:174
@ RPF_SET_LIGHTS
whether to define default lights
Definition context.h:155
@ RPF_DRAWABLES_DRAW
whether to call draw and finish_draw methods of drawables
Definition context.h:173
@ RPF_DRAWABLES_AFTER_FINISH
whether to call after finish method of drawables
Definition context.h:176
@ RPF_DEFAULT
all flags set, defines default render pass
Definition context.h:179
@ RPF_NONE
no frame initialization is performed
Definition context.h:150
@ RPF_HANDLE_SCREEN_SHOT
whether to perform a screen shot if this was scheduled
Definition context.h:177
@ RPF_DRAW_TEXTUAL_INFO
whether to draw textual information
Definition context.h:175
CompareFunction
different comparison functions used for depth testing or texture comparisons
Definition context.h:310
GPUVendorID
IDs for GPU vendors.
Definition context.h:34
unsigned int get_type_size(TypeId tid)
function that returns the size of a type specified through TypeId
Definition type_id.cxx:18
@ TI_INT32
signed integer stored in 16 bits
Definition type_id.h:21
@ TI_FLT32
floating point type stored in 16 bits
Definition type_id.h:28
@ TI_UINT32
unsigned integer stored in 16 bits
Definition type_id.h:25
@ TI_UINT8
signed integer stored in 64 bits
Definition type_id.h:23
@ TI_BOOL
void
Definition type_id.h:18
@ TI_FLT64
floating point type stored in 32 bits
Definition type_id.h:29
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
this header is dependency free
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:685
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > rgba
declare rgba color type with 32 bit components
Definition color.h:898
cgv::math::fvec< double, 3 > dvec3
declare type of 3d double precision floating point vectors
Definition fvec.h:690
cgv::math::fvec< int32_t, 4 > ivec4
declare type of 4d 32 bit integer vectors
Definition fvec.h:712
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
Definition color.h:896
cgv::math::fvec< int32_t, 2 > ivec2
declare type of 2d 32 bit integer vectors
Definition fvec.h:708
cgv::math::fvec< bool, 4 > bvec4
declare type of 4d boolean vectors
Definition fvec.h:678
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:683
cgv::math::fvec< double, 2 > dvec2
declare type of 2d double precision floating point vectors
Definition fvec.h:688
Stores properties of a phong brdf material.
Stores properties of a surface material.
Represents a blend state used to configure fragment blending.
Definition context.h:694
BlendFunction dst_color
the destination color (rgb) factor
Definition context.h:700
BlendFunction dst_alpha
the destination alpha factor
Definition context.h:704
BlendFunction src_alpha
the source alpha factor
Definition context.h:702
BlendFunction src_color
the source color (rgb) factor
Definition context.h:698
Represents a buffer mask used to mask depth and color buffer outputs.
Definition context.h:709
Represents a depth test state used to configure depth testing.
Definition context.h:686
status information of light sources
Definition context.h:792
information necessary for a rendering pass
Definition context.h:820
configuration object used to define context parameters that need to be set already at creation time
Definition context.h:572
bool multi_sample_buffer
default: false
Definition context.h:588
bool stencil_buffer
default: false
Definition context.h:584
int version_minor
default: -1 ... minor version of maximum supported OpenGL version
Definition context.h:601
int depth_bits
default: -1
Definition context.h:590
bool double_buffer
default: true
Definition context.h:578
int version_major
default: -1 ... major version of maximum supported OpenGL version
Definition context.h:599
context_config()
construct config with default parameters
Definition context.cxx:119
bool debug
default: false in release and true in debug version
Definition context.h:605
bool forward_compatible
default: false
Definition context.h:603
bool stereo_buffer
default: false
Definition context.h:582
bool alpha_buffer
default: false
Definition context.h:580
bool self_reflect(cgv::reflect::reflection_handler &srh)
reflect the shader_path member
Definition context.cxx:153
bool core_profile
default: true
Definition context.h:607
int stencil_bits
default: -1
Definition context.h:592
int nr_multi_samples
default: -1
Definition context.h:596
bool accumulation_buffer
default: false
Definition context.h:586
int accumulation_bits
default: -1
Definition context.h:594
bool depth_buffer
default: true
Definition context.h:576
structure to store information on a shader program variable, i.e.
Definition context.h:100
unsigned array_size
dimension of arrays
Definition context.h:106
void compute_sizes(size_t &cnt, size_t &s, size_t &S) const
helper member function to compute counts and sizes
Definition context.cxx:62
cgv::render::type_descriptor type_descr
type descriptor providing information on component and compositions (scalar, vector or matrix)
Definition context.h:104
configuration object used to define render view creation parameters including error handling configur...
Definition context.h:622
int window_width
default: 640
Definition context.h:628
render_config()
construct config with default parameters
Definition context.cxx:174
bool dialog_on_error
default: true (only in case a gui_driver, which supports this, is loaded)
Definition context.h:638
bool self_reflect(cgv::reflect::reflection_handler &srh)
reflect the shader_path member
Definition context.cxx:197
int fullscreen_monitor
default: -1 ... no fullscreen
Definition context.h:626
int window_height
default: 480
Definition context.h:630
bool abort_on_error
default: false
Definition context.h:636
std::string get_type_name() const
return "render_config"
Definition context.cxx:191
bool show_error_on_console
default: true
Definition context.h:640
compact type description of data that can be sent to the context; convertible to int
Definition context.h:61
parameters necessary to define window transformation
Definition context.h:659