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