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