cgv
Loading...
Searching...
No Matches
context.h
1#pragma once
2
3// make sure this is the first thing the compiler sees, while preventing warnings if
4// it happened to already be defined by something else including this header
5#ifndef _USE_MATH_DEFINES
6 #define _USE_MATH_DEFINES 1
7#endif
8#include <cgv/defines/deprecated.h>
9#include <cgv/data/data_view.h>
10#include <cgv/media/font/font.h>
11#include <cgv/media/axis_aligned_box.h>
12#include <cgv/media/illum/phong_material.h>
13#include <cgv/media/illum/textured_surface_material.h>
14#include <cgv/media/illum/light_source.h>
15#include <cgv/signal/callback_stream.h>
16#include <cgv/math/vec.h>
17#include <cgv/math/inv.h>
18#include <stack>
19#include <vector>
20#include <string>
21
22#include "lib_begin.h"
23
24namespace cgv {
25 namespace render {
26
27class CGV_API drawable;
28class CGV_API textured_material;
29
32 GPU_VENDOR_UNKNOWN,
33 GPU_VENDOR_AMD,
34 GPU_VENDOR_INTEL,
35 GPU_VENDOR_NVIDIA
36};
37
45
48 ET_VALUE,
49 ET_VECTOR,
50 ET_MATRIX
51};
52
55{
56 cgv::type::info::TypeId coordinate_type : 8;
57 ElementType element_type : 4;
58 unsigned nr_rows : 4;
59 unsigned nr_columns : 4;
60 bool is_row_major : 1;
61 bool is_array : 1;
62 bool normalize : 1;
64 type_descriptor(int td = 0) { *reinterpret_cast<int*>(this) = td; }
66 type_descriptor(cgv::type::info::TypeId _coordinate_type, bool _normalize = false) : coordinate_type(_coordinate_type), element_type(ET_VALUE), nr_rows(1), nr_columns(1), is_row_major(false), is_array(false), normalize(_normalize) {}
68 type_descriptor(cgv::type::info::TypeId _coordinate_type, unsigned _nr_entries, bool _normalize = false) : coordinate_type(_coordinate_type), element_type(ET_VECTOR), nr_rows(_nr_entries), nr_columns(1), is_row_major(false), is_array(false), normalize(_normalize) {}
70 type_descriptor(cgv::type::info::TypeId _coordinate_type, unsigned _nr_rows, unsigned _nr_cols, bool _is_row_major, bool _normalize = false) : coordinate_type(_coordinate_type), element_type(ET_MATRIX), nr_rows(_nr_rows), nr_columns(_nr_cols), is_row_major(_is_row_major), is_array(false), normalize(_normalize) {}
72 type_descriptor(const type_descriptor& td, bool _is_array) : coordinate_type(td.coordinate_type), element_type(td.element_type), nr_rows(td.nr_rows), nr_columns(td.nr_columns), is_row_major(td.is_row_major), normalize(td.normalize), is_array(_is_array) {}
74 operator int() const { return *reinterpret_cast<const int*>(this); }
75};
76
79 RA_OPENGL,
80 RA_DIRECTX
81};
82
83
96
98extern CGV_API std::string get_render_pass_name(RenderPass rp);
99
134
137 MS_NONE,
138 MS_FRONT,
139 MS_BACK,
140 MS_FRONT_AND_BACK
141};
142
145 IM_OFF,
146 IM_ONE_SIDED,
147 IM_TWO_SIDED
148};
149
152 CM_OFF,
153 CM_BACKFACE,
154 CM_FRONTFACE
155};
156
159 BF_ZERO,
160 BF_ONE,
161 BF_SRC_COLOR,
162 BF_ONE_MINUS_SRC_COLOR,
163 BF_DST_COLOR,
164 BF_ONE_MINUS_DST_COLOR,
165 BF_SRC_ALPHA,
166 BF_ONE_MINUS_SRC_ALPHA,
167 BF_DST_ALPHA,
168 BF_ONE_MINUS_DST_ALPHA,
169 BF_CONSTANT_COLOR,
170 BF_ONE_MINUS_CONSTANT_COLOR,
171 BF_CONSTANT_ALPHA,
172 BF_ONE_MINUS_CONSTANT_ALPHA,
173 BF_SRC_ALPHA_SATURATE,
174 BF_SRC1_COLOR,
175 BF_ONE_MINUS_SRC1_COLOR,
176 BF_SRC1_ALPHA,
177 BF_ONE_MINUS_SRC1_ALPHA
178};
179
182 TW_REPEAT = 0,
183 TW_CLAMP = 1,
184 TW_CLAMP_TO_EDGE = 2,
185 TW_CLAMP_TO_BORDER = 3,
186 TW_MIRROR_CLAMP = 4,
187 TW_MIRROR_CLAMP_TO_EDGE = 5,
188 TW_MIRROR_CLAMP_TO_BORDER = 6,
189 TW_MIRRORED_REPEAT = 7,
190 TW_LAST
191};
192
194extern CGV_API std::string to_string(TextureWrap wrap);
195
198 TF_NEAREST = 0,
199 TF_LINEAR = 1,
200 TF_NEAREST_MIPMAP_NEAREST = 2,
201 TF_LINEAR_MIPMAP_NEAREST = 3,
202 TF_NEAREST_MIPMAP_LINEAR = 4,
203 TF_LINEAR_MIPMAP_LINEAR = 5,
204 TF_ANISOTROP = 6,
205 TF_LAST
206};
207
210 TT_UNDEF,
211 TT_1D = 1,
212 TT_2D,
213 TT_3D,
214 TT_1D_ARRAY,
215 TT_2D_ARRAY,
216 TT_CUBEMAP,
217 TT_MULTISAMPLE_2D,
218 TT_MULTISAMPLE_2D_ARRAY,
219 TT_BUFFER
220};
221
224 TCS_PLUS_X,
225 TCS_MINUS_X,
226 TCS_PLUS_Y,
227 TCS_MINUS_Y,
228 TCS_PLUS_Z,
229 TCS_MINUS_Z
230};
231
234 PT_UNDEF,
235 PT_POINTS,
236 PT_LINES,
237 PT_LINES_ADJACENCY,
238 PT_LINE_STRIP,
239 PT_LINE_STRIP_ADJACENCY,
240 PT_LINE_LOOP,
241 PT_TRIANGLES,
242 PT_TRIANGLES_ADJACENCY,
243 PT_TRIANGLE_STRIP,
244 PT_TRIANGLE_STRIP_ADJACENCY,
245 PT_TRIANGLE_FAN,
246 PT_QUADS,
247 PT_QUAD_STRIP,
248 PT_POLYGON,
249 PT_PATCHES,
250 PT_LAST
251};
252
259
262{
263 CF_LEQUAL,
264 CF_GEQUAL,
265 CF_LESS,
266 CF_GREATER,
267 CF_EQUAL,
268 CF_NOTEQUAL,
269 CF_ALWAYS,
270 CF_NEVER
271};
272
275 AT_READ_ONLY,
276 AT_WRITE_ONLY,
277 AT_READ_WRITE
278};
279
292
294extern CGV_API std::string to_string(TextureFilter filter_type);
295
297extern CGV_API std::string to_string(PrimitiveType pt);
298
300extern CGV_API std::string to_string(TextureType tt);
301
303extern CGV_API std::string to_string(TextureCubeSides tcs);
304
305class CGV_API context;
306
308class CGV_API render_component
309{
310public:
311 void* handle;
312 void* internal_format;
313 void* user_data;
317 mutable std::string last_error;
321 virtual bool is_created() const;
324 void put_id_void(void* ptr) const;
326 template <typename T>
327 void put_id(T& id) const { put_id_void(&id); }
328};
329
332{
333public:
334 unsigned nr_multi_samples = 0;
336};
337
339class CGV_API texture_base : public render_component
340{
341public:
342 TextureFilter mag_filter;
343 TextureFilter min_filter;
344 TextureWrap wrap_s;
345 TextureWrap wrap_t;
346 TextureWrap wrap_r;
347 float anisotropy;
348 float priority;
349 float border_color[4];
350 CompareFunction compare_function;
351 bool use_compare_function;
352 TextureType tt;
353 bool have_mipmaps;
354 unsigned nr_multi_samples = 5;
355 bool fixed_sample_locations = true;
357 texture_base(TextureType _tt = TT_UNDEF);
358};
359
360
363{
364protected:
365 bool is_enabled;
366 friend class context;
367
368 bool auto_detect_uniforms;
369 bool auto_detect_vertex_attributes;
370
371 // uniforms
372 bool uses_view;
373 bool uses_material;
374 bool uses_lights;
375 bool uses_gamma;
376 // maps uniform names to their locations in the shader program
377 std::map<std::string, int> uniform_locations;
378
379 // vertex attribute names
380 int position_index;
381 int color_index;
382 bool context_sets_color;
383 int normal_index;
384 int texcoord_index;
385
386public:
387 PrimitiveType geometry_shader_input_type;
388 PrimitiveType geometry_shader_output_type;
389 int geometry_shader_output_count;
392 // configure program
393 void specify_standard_uniforms(bool view, bool material, bool lights, bool gamma);
394 void specify_standard_vertex_attribute_names(context& ctx, bool color = true, bool normal = true, bool texcoord = true);
395 void specify_vertex_attribute_names(context& ctx, const std::string& position, const std::string& color = "", const std::string& normal = "", const std::string& texcoord = "");
396 // uniforms
397 bool does_use_view() const { return uses_view; }
398 bool does_use_material() const { return uses_material; }
399 bool does_use_lights() const { return uses_lights; }
400 bool does_use_gamma() const { return uses_gamma; }
401
402 // vertex attribute names
403 void allow_context_to_set_color(bool allow);
404 int get_position_index() const { return position_index; }
405 int get_color_index() const { return color_index; }
406 bool does_context_set_color() const { return context_sets_color; }
407 int get_normal_index() const { return normal_index; }
408 int get_texcoord_index() const { return texcoord_index; }
409};
410
413{
414protected:
415 bool is_enabled;
416 friend class context;
417public:
420};
421
422
435
457
469
478
481{
482protected:
483 friend class context;
484 bool is_enabled;
485 std::vector<int> enabled_color_attachments;
486 bool depth_attached;
487 bool attached[16];
488 int width, height;
489public:
492};
493
495enum ShaderType { ST_DETECT, ST_COMPUTE, ST_VERTEX, ST_TESS_CONTROL, ST_TESS_EVALUATION, ST_GEOMETRY, ST_FRAGMENT };
496
499 FB_0 = 0,
500 FB_1 = 1,
501 FB_2 = 2,
502 FB_3 = 3,
503 FB_4 = 4,
504 FB_5 = 5,
505 FB_6 = 6,
506 FB_7 = 7,
507 FB_BACK = 128,
508 FB_FRONT = 129,
509 FB_LEFT = 512,
510 FB_RIGHT = 1024,
511 FB_BACK_LEFT = FB_BACK+FB_LEFT,
512 FB_BACK_RIGHT = FB_BACK+FB_RIGHT,
513 FB_FRONT_LEFT = FB_FRONT+FB_LEFT,
514 FB_FRONT_RIGHT = FB_FRONT+FB_RIGHT
515};
516
517// forward declaration of all render components
518class CGV_API texture;
519class CGV_API render_buffer;
520class CGV_API frame_buffer;
521class CGV_API shader_code;
522class CGV_API shader_program;
523
524// declare some colors by name
525extern CGV_API float black[4], white[4], gray[4], green[4], brown[4], dark_red[4];
526extern CGV_API float cyan[4], yellow[4], red[4], blue[4];
527
574
577
579struct CGV_API render_config : public cgv::base::base, public context_config
580{
590
600
604 std::string get_type_name() const;
606 bool self_reflect(cgv::reflect::reflection_handler& srh);
607};
608
611
613extern CGV_API render_config_ptr get_render_config();
614
623
625class CGV_API context : public context_config
626{
627protected:
628 // store the GPU vendor id
629 GPUVendorID gpu_vendor;
630 // store the GPU device capabilities
631 device_capabilities gpu_capabilities;
632public:
633 friend class CGV_API attribute_array_manager;
634 friend class CGV_API render_component;
635 friend class CGV_API texture;
636 friend class CGV_API render_buffer;
637 friend class CGV_API frame_buffer;
638 friend class CGV_API shader_code;
639 friend class CGV_API shader_program;
640 friend class CGV_API attribute_array_binding;
641 friend class CGV_API vertex_buffer;
642
646 bool enabled = false;
648 CompareFunction test_func = CF_LESS;
649 };
650
652 struct BlendState {
654 bool enabled = false;
656 BlendFunction src_color = BF_ZERO;
658 BlendFunction dst_color = BF_ZERO;
660 BlendFunction src_alpha = BF_ZERO;
662 BlendFunction dst_alpha = BF_ZERO;
663 // TODO: Add blend equation?
664 };
665
667 struct BufferMask {
669 bool depth_flag = true;
671 bool red_flag = true;
673 bool green_flag = true;
675 bool blue_flag = true;
677 bool alpha_flag = true;
678 };
679protected:
680 friend class shader_program_base;
681
706
708 std::stack<vec4> bg_color_stack;
710 std::stack<float> bg_depth_stack;
712 std::stack<int> bg_stencil_stack;
714 std::stack<vec4> bg_accum_color_stack;
715
717 std::stack<DepthTestState> depth_test_state_stack;
719 std::stack<CullingMode> cull_state_stack;
721 std::stack<BlendState> blend_state_stack;
723 std::stack<BufferMask> buffer_mask_stack;
724
726 std::stack<dmat4> modelview_matrix_stack, projection_matrix_stack;
728 std::stack<std::vector<window_transformation>> window_transformation_stack;
730 std::stack<frame_buffer_base*> frame_buffer_stack;
732 std::stack<shader_program_base*> shader_program_stack;
733public:
735 shader_program_base* get_current_program() const;
737 void enable_shader_file_cache();
739 void disable_shader_file_cache();
741 bool is_shader_file_cache_enabled() const;
742protected:
744 std::stack<attribute_array_binding_base*> attribute_array_binding_stack;
747 {
748 bool enabled;
749 vec3 eye_position;
750 vec3 eye_spot_direction;
751 int light_source_index;
752 };
758 std::map<void*, std::pair<cgv::media::illum::light_source, light_source_status> > light_sources;
760 virtual void on_lights_changed();
762 static const unsigned nr_default_light_sources = 2;
764 cgv::media::illum::light_source default_light_source[nr_default_light_sources];
766 void* default_light_source_handles[nr_default_light_sources];
775 {
776 RenderPass pass;
777 RenderPassFlags flags;
778 void* user_data;
779 };
781 std::stack<render_info> render_pass_stack;
789 int cursor_x, cursor_y;
799 int x_offset, y_offset;
805 bool do_screen_shot;
807 virtual void process_text(const std::string& text);
809 virtual void draw_text(const std::string& text);
810
811 virtual void destruct_render_objects();
812 virtual void put_id(void* handle, void* ptr) const = 0;
813
814 virtual cgv::data::component_format texture_find_best_format(const cgv::data::component_format& cf, render_component& rc, const std::vector<cgv::data::data_view>* palettes = 0) const = 0;
815 virtual bool texture_create (texture_base& tb, cgv::data::data_format& df) const = 0;
816 virtual bool texture_create (texture_base& tb, cgv::data::data_format& target_format, const cgv::data::const_data_view& data, int level, int cube_side = -1, int num_array_layers = 0, const std::vector<cgv::data::data_view>* palettes = 0) const = 0;
817 virtual bool texture_create_from_buffer (texture_base& tb, cgv::data::data_format& df, int x, int y, int level) const = 0;
818 virtual bool texture_replace (texture_base& tb, int x, int y, int z_or_cube_side, const cgv::data::const_data_view& data, int level, const std::vector<cgv::data::data_view>* palettes = 0) const = 0;
819 virtual bool texture_replace_from_buffer(texture_base& tb, int x, int y, int z_or_cube_side, int x_buffer, int y_buffer, unsigned int width, unsigned int height, int level) const = 0;
820 virtual bool texture_create_mipmaps (texture_base& tb, cgv::data::data_format& df) const = 0;
821 virtual bool texture_generate_mipmaps (texture_base& tb, unsigned int dim) const = 0;
822 virtual bool texture_destruct (texture_base& tb) const = 0;
823 virtual bool texture_set_state (const texture_base& tb) const = 0;
824 virtual bool texture_enable (texture_base& tb, int tex_unit, unsigned int nr_dims) const = 0;
825 virtual bool texture_disable (texture_base& tb, int tex_unit, unsigned int nr_dims) const = 0;
826 virtual bool texture_bind_as_image (texture_base& tb, int tex_unit, int level, bool bind_array, int layer, AccessType access) const = 0;
827
828 virtual bool render_buffer_create (render_buffer_base& rc, cgv::data::component_format& cf, int& _width, int& _height) const = 0;
829 virtual bool render_buffer_destruct (render_buffer_base& rc) const = 0;
830
831 static void get_buffer_list(frame_buffer_base& fbb, bool& depth_buffer, std::vector<int>& buffers, int offset = 0);
832 virtual bool frame_buffer_create (frame_buffer_base& fbb) const;
833 virtual bool frame_buffer_attach (frame_buffer_base& fbb, const render_buffer_base& rb, bool is_depth, int i) const;
834 virtual bool frame_buffer_attach (frame_buffer_base& fbb, const texture_base& t, bool is_depth, int level, int i, int z) const;
835 virtual bool frame_buffer_is_complete(const frame_buffer_base& fbb) const = 0;
836 virtual bool frame_buffer_enable (frame_buffer_base& fbb);
837 virtual bool frame_buffer_disable (frame_buffer_base& fbb);
838 virtual bool frame_buffer_destruct(frame_buffer_base& fbb) const;
839 virtual void frame_buffer_blit(const frame_buffer_base* src_fbb_ptr, const ivec4& S, frame_buffer_base* dst_fbb_ptr, const ivec4& _D, BufferTypeBits btbs, bool interpolate) const = 0;
840 virtual int frame_buffer_get_max_nr_color_attachments() const = 0;
841 virtual int frame_buffer_get_max_nr_draw_buffers() const = 0;
842
843 virtual bool shader_code_create (render_component& sc, ShaderType st, const std::string& source) const = 0;
844 virtual bool shader_code_compile (render_component& sc) const = 0;
845 virtual void shader_code_destruct(render_component& sc) const = 0;
846
847 virtual bool shader_program_create (shader_program_base& spb) const = 0;
848 virtual void shader_program_attach(shader_program_base& spb, const render_component& sc) const = 0;
849 virtual void shader_program_detach(shader_program_base& spb, const render_component& sc) const = 0;
850 virtual bool shader_program_link(shader_program_base& spb) const;
851 virtual bool shader_program_set_state(shader_program_base& spb) const = 0;
852 virtual bool shader_program_enable (shader_program_base& spb);
853 virtual bool shader_program_disable(shader_program_base& spb);
854 virtual bool shader_program_destruct(shader_program_base& spb) const;
855 virtual void shader_program_set_uniform_locations(shader_program_base& spb) const;
856 virtual bool shader_program_get_active_uniforms(shader_program_base& spb, std::vector<std::string>& names) const = 0;
857 virtual int get_uniform_location(const shader_program_base& spb, const std::string& name) const = 0;
858 virtual bool set_uniform_void(shader_program_base& spb, int loc, type_descriptor value_type, const void* value_ptr) const = 0;
859 virtual bool set_uniform_array_void(shader_program_base& spb, int loc, type_descriptor value_type, const void* value_ptr, size_t nr_elements) const = 0;
860 virtual int get_attribute_location(const shader_program_base& spb, const std::string& name) const = 0;
861 virtual bool set_attribute_void(shader_program_base& spb, int loc, type_descriptor value_type, const void* value_ptr) const = 0;
862
863 virtual bool attribute_array_binding_create (attribute_array_binding_base& aab) const = 0;
864 virtual bool attribute_array_binding_destruct(attribute_array_binding_base& aab) const;
865 virtual bool attribute_array_binding_enable (attribute_array_binding_base& aab);
866 virtual bool attribute_array_binding_disable (attribute_array_binding_base& aab);
867 virtual bool set_attribute_array_void(attribute_array_binding_base* aab, int loc, type_descriptor value_type, const vertex_buffer_base* vbb, const void* ptr, size_t nr_elements = 0, unsigned stride_in_bytes = 0) const = 0;
868 virtual bool set_element_array(attribute_array_binding_base* aab, const vertex_buffer_base* vbb) const = 0;
869 virtual bool enable_attribute_array(attribute_array_binding_base* aab, int loc, bool do_enable) const = 0;
870 virtual bool is_attribute_array_enabled(const attribute_array_binding_base* aab, int loc) const = 0;
871
872 virtual bool vertex_buffer_bind(const vertex_buffer_base& vbb, VertexBufferType _type, unsigned _idx = -1) const = 0;
873 virtual bool vertex_buffer_unbind(const vertex_buffer_base& vbb, VertexBufferType _type, unsigned _idx = -1) const = 0;
874 virtual bool vertex_buffer_create(vertex_buffer_base& vbb, const void* array_ptr, size_t size_in_bytes) const = 0;
875 virtual bool vertex_buffer_resize(vertex_buffer_base& vbb, const void* array_ptr, size_t size_in_bytes) const = 0;
876 virtual bool vertex_buffer_replace(vertex_buffer_base& vbb, size_t offset, size_t size_in_bytes, const void* array_ptr) const = 0;
877 virtual bool vertex_buffer_copy(const vertex_buffer_base& src, size_t src_offset, vertex_buffer_base& target, size_t target_offset, size_t size_in_bytes) const = 0;
878 virtual bool vertex_buffer_copy_back(vertex_buffer_base& vbb, size_t offset, size_t size_in_bytes, void* array_ptr) const = 0;
879 virtual bool vertex_buffer_destruct(vertex_buffer_base& vbb) const = 0;
880public:
882 context();
884 virtual ~context();
886 virtual void error(const std::string& message, const render_component* rc = 0) const;
888 virtual GPUVendorID get_gpu_vendor_id() const;
889 const device_capabilities& get_device_capabilities() const;
890
894 virtual void init_render_pass();
896 virtual void draw_textual_info();
898 virtual void perform_screen_shot();
900 virtual void finish_render_pass();
902
906 virtual void configure_new_child(cgv::base::base_ptr child);
908 virtual RenderAPI get_render_api() const = 0;
910 unsigned get_render_pass_recursion_depth() const;
912 virtual RenderPass get_render_pass() const;
914 virtual RenderPassFlags get_render_pass_flags() const;
916 virtual void* get_render_pass_user_data() const;
918 virtual RenderPassFlags get_default_render_pass_flags() const;
920 virtual void set_default_render_pass_flags(RenderPassFlags);
922 virtual void render_pass(RenderPass render_pass = RP_MAIN,
923 RenderPassFlags render_pass_flags = RPF_ALL,
924 void* user_data = 0);
926 void set_debug_render_passes(bool _debug);
928 bool get_debug_render_passes() const { return debug_render_passes; }
930 virtual bool in_render_process() const = 0;
932 virtual bool is_created() const = 0;
934 virtual bool is_current() const = 0;
936 virtual bool recreate_context();
938 virtual bool make_current() const = 0;
940 virtual void clear_current() const = 0;
942 virtual void attach_alpha_buffer(bool attach = true) = 0;
944 virtual void attach_depth_buffer(bool attach = true) = 0;
946 virtual void attach_stencil_buffer(bool attach = true) = 0;
948 virtual bool is_stereo_buffer_supported() const = 0;
950 virtual void attach_stereo_buffer(bool attach = true) = 0;
952 virtual void attach_accumulation_buffer(bool attach = true) = 0;
954 virtual void attach_multi_sample_buffer(bool attach = true) = 0;
956
958 virtual unsigned int get_width() const = 0;
960 virtual unsigned int get_height() const = 0;
962 virtual void resize(unsigned int width, unsigned int height) = 0;
963
964
980 virtual bool read_frame_buffer(
981 data::data_view& dv,
982 unsigned int x = 0, unsigned int y = 0,
983 FrameBufferType buffer_type = FB_BACK,
985 data::ComponentFormat cf = data::CF_RGB,
986 int w = -1, int h = -1) = 0;
990 bool write_frame_buffer_to_image(
991 const std::string& file_name,
992 data::ComponentFormat cf = data::CF_RGB,
993 FrameBufferType buffer_type = FB_BACK,
994 unsigned int x = 0, unsigned int y = 0,
995 int w = -1, int h = -1,
996 float depth_offset = 0.9f, float depth_scale = 10.0f);
997
999 void push_bg_color();
1001 void pop_bg_color();
1003 virtual void set_bg_color(vec4 rgba);
1005 void set_bg_color(float r, float g, float b, float a);
1007 vec4 get_bg_color() const;
1009 void put_bg_color(float* rgba) const;
1011 void set_bg_alpha(float a);
1013 float get_bg_alpha() const;
1015 void set_bg_clr_idx(unsigned int idx);
1017 unsigned int get_bg_clr_idx() const;
1018
1020 void push_bg_depth();
1022 void pop_bg_depth();
1024 virtual void set_bg_depth(float d);
1026 float get_bg_depth() const;
1027
1029 void push_bg_stencil();
1031 void pop_bg_stencil();
1033 virtual void set_bg_stencil(int s);
1035 int get_bg_stencil() const;
1036
1038 void push_bg_accum_color();
1040 void pop_bg_accum_color();
1042 virtual void set_bg_accum_color(vec4 rgba);
1044 void set_bg_accum_color(float r, float g, float b, float a);
1046 vec4 get_bg_accum_color() const;
1048 void put_bg_accum_color(float* rgba) const;
1050 void set_bg_accum_alpha(float a);
1052 float get_bg_accum_alpha() const;
1053
1055 virtual void clear_background(bool color_flag, bool depth_flag, bool stencil_flag = false, bool accum_flag = false) = 0;
1056
1058 virtual void post_redraw() = 0;
1060 virtual void force_redraw() = 0;
1062 virtual void announce_external_frame_buffer_change(void*& cgv_fbo_storage) = 0;
1064 virtual void recover_from_external_frame_buffer_change(void* cgv_fbo_storage) = 0;
1065
1069 virtual void enable_font_face(media::font::font_face_ptr font_face, float font_size);
1071 virtual float get_current_font_size() const;
1073 virtual media::font::font_face_ptr get_current_font_face() const;
1075
1078 DEPRECATED("deprecated and ignored.") virtual void enable_phong_shading();
1079 DEPRECATED("deprecated and ignored.") virtual void disable_phong_shading();
1080 DEPRECATED("deprecated, use set_material instead.") virtual void enable_material(const cgv::media::illum::phong_material& mat = cgv::media::illum::default_material(), MaterialSide ms = MS_FRONT_AND_BACK, float alpha = 1);
1081 DEPRECATED("deprecated and ignored.") virtual void disable_material(const cgv::media::illum::phong_material& mat = cgv::media::illum::default_material());
1082 DEPRECATED("deprecated, use enable_material(textured_surface_material) instead.") virtual void enable_material(const textured_material& mat, MaterialSide ms = MS_FRONT_AND_BACK, float alpha = 1);
1083 //DEPRECATED("deprecated, use disable_material(textured_surface_material) instead.") virtual void disable_material(const textured_material& mat) = 0;
1085 void set_gamma(float _gamma);
1087 virtual void set_gamma3(const vec3& _gamma3);
1089 float get_gamma() const { return (gamma3.x() + gamma3.y() + gamma3.z()) / 3.0f; }
1091 vec3 get_gamma3() const { return gamma3; }
1093 virtual void enable_sRGB_framebuffer(bool do_enable = true);
1095 bool sRGB_framebuffer_enabled() { return sRGB_framebuffer; }
1097 const rgba& get_color() const;
1099 virtual void set_color(const rgba& clr);
1101 virtual void set_color(const rgb& clr, float opacity = 1.0f) { set_color(rgba(clr[0], clr[1], clr[2], opacity)); }
1103 virtual void set_material(const cgv::media::illum::surface_material& mat);
1105 const cgv::media::illum::surface_material* get_current_material() const;
1107 virtual void set_textured_material(const textured_material& mat);
1109 virtual void enable_material(textured_material& mat) = 0;
1111 virtual void disable_material(textured_material& mat) = 0;
1113 void set_current_gamma(shader_program& prog) const;
1115 void set_current_view(shader_program& prog, bool modelview_deps = true, bool projection_deps = true) const;
1117 void set_current_material(shader_program& prog) const;
1119 void set_current_lights(shader_program& prog) const;
1121 vec3 get_light_eye_position(const cgv::media::illum::light_source& light, bool place_now) const;
1123 vec3 get_light_eye_spot_direction(const cgv::media::illum::light_source& light, bool place_now) const;
1125 virtual shader_program& ref_default_shader_program(bool texture_support = false) = 0;
1127 virtual shader_program& ref_surface_shader_program(bool texture_support = false) = 0;
1129 virtual void enumerate_program_uniforms(shader_program& prog, std::vector<std::string>& names, std::vector<int>* locations_ptr = 0, std::vector<int>* sizes_ptr = 0, std::vector<int>* types_ptr = 0, bool show = false) const = 0;
1131 virtual void enumerate_program_attributes(shader_program& prog, std::vector<std::string>& names, std::vector<int>* locations_ptr = 0, std::vector<int>* sizes_ptr = 0, std::vector<int>* types_ptr = 0, bool show = false) const = 0;
1133
1136 DEPRECATED("deprecated, use add_light_source instead.") void* enable_light(const cgv::media::illum::light_source& light) { return add_light_source(light); }
1137 DEPRECATED("deprecated, use enable_light_source instead.") void disable_light(void* handle) { disable_light_source(handle); }
1138 DEPRECATED("deprecated, use get_max_nr_enabled_light_sources instead.") unsigned get_max_nr_lights() const { return get_max_nr_enabled_light_sources(); }
1140 size_t get_nr_light_sources() const;
1142 void* add_light_source(const cgv::media::illum::light_source& light, bool enabled = true, bool place_now = false);
1144 bool remove_light_source(void* handle);
1146 const cgv::media::illum::light_source& get_light_source(void* handle) const;
1148 const light_source_status& get_light_source_status(void* handle) const;
1150 void set_light_source(void* handle, const cgv::media::illum::light_source& light, bool place_now = true);
1152 void place_light_source(void* handle);
1153
1155 virtual unsigned get_max_nr_enabled_light_sources() const;
1157 size_t get_nr_enabled_light_sources() const;
1159 void* get_enabled_light_source_handle(size_t i) const;
1161 bool is_light_source_enabled(void* handle);
1163 bool enable_light_source(void* handle);
1165 bool disable_light_source(void* handle);
1167 size_t get_nr_default_light_sources() const { return nr_default_light_sources; }
1169 const cgv::media::illum::light_source& get_default_light_source(size_t i) const;
1171 void set_default_light_source(size_t i, const cgv::media::illum::light_source& ls);
1173
1183 virtual std::ostream& output_stream();
1185 virtual void set_cursor(int x, int y);
1187 virtual void get_cursor(int& x, int& y) const;
1190 virtual void put_cursor_coords(const vecn& p, int& x, int& y) const;
1196 virtual void set_cursor(const vecn& pos,
1197 const std::string& text = "", TextAlignment ta = TA_BOTTOM_LEFT,
1198 int x_offset=0, int y_offset=0);
1200
1205 const float* vertices, const float* normals, const float* tex_coords,
1206 const int* vertex_indices, const int* normal_indices, const int* tex_coord_indices,
1207 int nr_faces, int face_degree, bool flip_normals = false) const = 0;
1210 const float* vertices, const float* normals, const float* tex_coords,
1211 const int* vertex_indices, const int* normal_indices, const int* tex_coord_indices,
1212 int nr_faces, int face_degree, bool is_fan, bool flip_normals = false) const = 0;
1214 virtual void draw_faces(
1215 const float* vertices, const float* normals, const float* tex_coords,
1216 const int* vertex_indices, const int* normal_indices, const int* tex_coord_indices,
1217 int nr_faces, int face_degree, bool flip_normals = false) const = 0;
1219 virtual void draw_strip_or_fan(
1220 const float* vertices, const float* normals, const float* tex_coords,
1221 const int* vertex_indices, const int* normal_indices, const int* tex_coord_indices,
1222 int nr_faces, int face_degree, bool is_fan, bool flip_normals = false) const = 0;
1223
1225 void tesselate_unit_square(bool flip_normals = false, bool edges = false);
1227 void tesselate_unit_cube(bool flip_normals = false, bool edges = false);
1229 virtual void tesselate_box(const cgv::media::axis_aligned_box<double, 3>& B, bool flip_normals, bool edges = false) const;
1231 void tesselate_unit_prism(bool flip_normals = false, bool edges = false);
1233 void tesselate_unit_disk(int resolution = 25, bool flip_normals = false, bool edges = false);
1235 void tesselate_unit_cone(int resolution = 25, bool flip_normals = false, bool edges = false);
1237 void tesselate_unit_cylinder(int resolution = 25, bool flip_normals = false, bool edges = false);
1239 void tesselate_unit_sphere(int resolution = 25, bool flip_normals = false, bool edges = false);
1241 void tesselate_unit_tetrahedron(bool flip_normals = false, bool edges = false);
1243 void tesselate_unit_octahedron(bool flip_normals = false, bool edges = false);
1245 void tesselate_unit_dodecahedron(bool flip_normals = false, bool edges = false);
1247 void tesselate_unit_icosahedron(bool flip_normals = false, bool edges = false);
1249 void tesselate_unit_torus(float minor_radius = 0.2f, int resolution = 25, bool flip_normals = false, bool edges = false);
1251
1258 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);
1260 virtual void tesselate_arrow(const dvec3& start, const dvec3& end, double aspect = 0.1f, double rel_tip_radius = 2.0f, double tip_aspect = 0.3f, int res = 25, bool edges = false);
1262
1265 virtual void draw_light_source(const cgv::media::illum::light_source& l, float intensity_scale, float light_scale);
1267
1270
1273 void push_depth_test_state();
1275 void pop_depth_test_state();
1277 DepthTestState get_depth_test_state() const;
1279 virtual void set_depth_test_state(DepthTestState state);
1281 virtual void set_depth_func(CompareFunction func);
1283 virtual void enable_depth_test();
1285 virtual void disable_depth_test();
1286
1289 void push_cull_state();
1291 void pop_cull_state();
1293 CullingMode get_cull_state() const;
1295 virtual void set_cull_state(CullingMode culling_mode);
1296
1299 void push_blend_state();
1301 void pop_blend_state();
1303 BlendState get_blend_state() const;
1305 virtual void set_blend_state(BlendState state);
1307 virtual void set_blend_func(BlendFunction src_factor, BlendFunction dst_factor);
1309 virtual void set_blend_func_separate(BlendFunction src_color_factor, BlendFunction dst_color_factor, BlendFunction src_alpha_factor, BlendFunction dst_alpha_factor);
1311 void set_blend_func_front_to_back();
1313 void set_blend_func_back_to_front();
1315 virtual void enable_blending();
1317 virtual void disable_blending();
1318
1321 void push_buffer_mask();
1323 void pop_buffer_mask();
1325 BufferMask get_buffer_mask() const;
1327 virtual void set_buffer_mask(BufferMask mask);
1329 bool get_depth_mask() const;
1331 virtual void set_depth_mask(bool flag);
1333 bvec4 get_color_mask() const;
1335 virtual void set_color_mask(bvec4 flags);
1336
1338
1341 DEPRECATED("deprecated: use get_modelview_matrix() instead.") dmatn get_V() const { return dmatn(4,4,&get_modelview_matrix()(0,0)); }
1342 DEPRECATED("deprecated: use set_modelview_matrix() instead.") void set_V(const dmatn& V) const { const_cast<context*>(this)->set_modelview_matrix(dmat4(4,4,&V(0,0))); }
1343 DEPRECATED("deprecated: use push_modelview_matrix() instead.") void push_V() { push_modelview_matrix(); }
1344 DEPRECATED("deprecated: use pop_modelview_matrix() instead.") void pop_V() { pop_modelview_matrix(); }
1345 DEPRECATED("deprecated: use get_projection_matrix() instead.") dmatn get_P() const { return dmatn(4, 4, &get_projection_matrix()(0, 0)); }
1346 DEPRECATED("deprecated: use set_projection_matrix() instead.") void set_P(const dmatn& P) const { const_cast<context*>(this)->set_projection_matrix(dmat4(4,4,&P(0, 0))); }
1347 DEPRECATED("deprecated: use push_projection_matrix() instead.") void push_P() { push_projection_matrix(); }
1348 DEPRECATED("deprecated: use pop_projection_matrix() instead.") void pop_P() { pop_projection_matrix(); }
1349 DEPRECATED("deprecated: use get_device_matrix() instead.") dmatn get_D() const { return dmatn(4, 4, &get_window_matrix()(0, 0)); }
1350 DEPRECATED("deprecated: use get_modelview_projection_device_matrix() instead.") dmatn get_DPV() const { return dmatn(4, 4, &get_modelview_projection_window_matrix()(0, 0)); }
1354 virtual void push_pixel_coords() = 0;
1356 virtual void pop_pixel_coords() = 0;
1358 virtual dmat4 get_modelview_matrix() const = 0;
1360 virtual void set_modelview_matrix(const dmat4& MV);
1362 virtual void mul_modelview_matrix(const dmat4& MV);
1364
1370 void push_modelview_matrix();
1372 void pop_modelview_matrix();
1374 virtual dmat4 get_projection_matrix() const = 0;
1376 virtual void set_projection_matrix(const dmat4& P);
1378 virtual void mul_projection_matrix(const dmat4& P);
1380 void push_projection_matrix();
1382 void pop_projection_matrix();
1384 void push_window_transformation_array();
1386
1388 virtual void pop_window_transformation_array();
1390 virtual void announce_external_viewport_change(ivec4& cgv_viewport_storage) = 0;
1392 virtual void recover_from_external_viewport_change(const ivec4& cgv_viewport_storage) = 0;
1394 virtual unsigned get_max_window_transformation_array_size() const = 0;
1396
1397protected:
1398 bool ensure_window_transformation_index(int& array_index);
1399public:
1401
1411 virtual void set_viewport(const ivec4& viewport, int array_index = -1);
1413
1415 virtual void set_depth_range(const dvec2& depth_range = dvec2(0, 1), int array_index = -1);
1417 const std::vector<window_transformation>& get_window_transformation_array() const;
1419
1424 dmat4 get_window_matrix(unsigned array_index = 0) const;
1426 dmat4 get_modelview_projection_window_matrix(unsigned array_index = 0) const;
1428 virtual double get_window_z(int x_window, int y_window) const = 0;
1430
1432 inline vec3 get_model_point(int x_window, int y_window) const {
1433 return get_model_point(x_window, y_window, get_window_z(x_window, y_window));
1434 }
1436
1438 inline vec3 get_model_point(int x_window, int y_window, double z_window) const {
1439 return get_model_point(x_window, y_window, z_window, get_modelview_projection_window_matrix());
1440 }
1442
1444 inline vec3 get_model_point(int x_window, int y_window, const dmat4& modelview_projection_window_matrix) const {
1445 return get_model_point(x_window, y_window, get_window_z(x_window, y_window), modelview_projection_window_matrix);
1446 }
1448
1450 inline static vec3 get_model_point(int x_window, int y_window, double z_window, const dmat4& modelview_projection_window_matrix) {
1451 return get_model_point(dvec3(x_window+0.5, y_window+0.5, z_window), modelview_projection_window_matrix);
1452 }
1454
1456 inline vec3 get_model_point(const vec3& p_window) const {
1457 return get_model_point(p_window, get_modelview_projection_window_matrix());
1458 }
1460
1462 static vec3 get_model_point(const dvec3& p_window, const dmat4& modelview_projection_window_matrix);
1464 DEPRECATED("use get_window_matrix() instead.") dmat4 get_device_matrix() const { return get_window_matrix(); }
1466 DEPRECATED("use get_modelview_projection_window_matrix() instead.") dmat4 get_modelview_projection_device_matrix() const;
1468 DEPRECATED("use get_window_z()") double get_z_D(int x_D, int y_D) const { return get_window_z(x_D, y_D); }
1470 DEPRECATED("use get_model_point()") vec3 get_point_W(int x_D, int y_D) const { return get_model_point(x_D, y_D); }
1472 DEPRECATED("use get_model_point()") vec3 get_point_W(int x_D, int y_D, const dmat4& MPD) const { return get_model_point(x_D, y_D, MPD); }
1474 DEPRECATED("use get_model_point()") vec3 get_point_W(int x_D, int y_D, double z_D) const { return get_model_point(x_D, y_D, z_D); }
1476 DEPRECATED("use get_model_point()") vec3 get_point_W(int x_D, int y_D, double z_D, const dmat4& MPD) const { return get_model_point(x_D, y_D, z_D, MPD); }
1478 DEPRECATED("use get_model_point()") vec3 get_point_W(const vec3& p_D) const { return get_model_point(p_D); }
1480 DEPRECATED("use get_model_point()") vec3 get_point_W(const vec3& p_D, const dmat4& MPD) const { return get_model_point(p_D, MPD); }
1482};
1483
1488extern CGV_API context* create_context(RenderAPI api = RA_OPENGL,
1489 unsigned int w = 800, unsigned int h = 600,
1490 const std::string& title = "", bool show = false);
1491
1492typedef context* (*context_creation_function_type)(RenderAPI api, unsigned int w, unsigned int h, const std::string& title, bool show);
1493
1495extern CGV_API void register_context_factory(context_creation_function_type);
1496
1498{
1499 context_factory_registration(context_creation_function_type fp);
1500};
1501
1502 }
1503}
1504
1505#include <cgv/config/lib_end.h>
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
the component format inherits the information of a packing_info and adds information on the component...
The const_data_view has the functionality of the data_view but uses a const pointer and therefore doe...
Definition data_view.h:221
A data_format describes a multidimensional data block of data entries.
Definition data_format.h:17
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
matrix of fixed size dimensions
Definition fmat.h:23
T & z()
third element
Definition fvec.h:164
T & y()
second element
Definition fvec.h:160
T & x()
first element
Definition fvec.h:156
A matrix type (full column major storage) The matrix can be loaded directly into OpenGL without need ...
Definition mat.h:208
An axis aligned box, defined by to points: min and max.
>simple class to hold the properties of a light source
simple class to hold the material properties of a phong material
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:413
the attribute_array_binding allows to define vertex attributes (i.e.
attribute array manager used to upload arrays to gpu
base class for all drawables, which is independent of the used rendering API.
Definition context.h:626
virtual void announce_external_viewport_change(ivec4 &cgv_viewport_storage)=0
announce an external viewport change performed with rendering API to the cgv framework providing spac...
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.
vec3 get_model_point(int x_window, int y_window, const dmat4 &modelview_projection_window_matrix) const
compute model space 3D point from the given opengl pixel location (window location) and modelview_pro...
Definition context.h:1444
vec3 gamma3
per color channel gamma value passed to shader programs that have gamma uniform
Definition context.h:705
virtual bool in_render_process() const =0
return whether the context is currently in process of rendering
virtual bool is_created() const =0
return whether the context is created
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...
virtual void recover_from_external_viewport_change(const ivec4 &cgv_viewport_storage)=0
restore cgv viewport to the state before the external change
RenderPassFlags default_render_flags
default render flags with which the main render pass is initialized
Definition context.h:783
virtual void announce_external_frame_buffer_change(void *&cgv_fbo_storage)=0
announce an external frame buffer change performed with rendering API to the cgv framework providing ...
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:1432
std::stack< render_info > render_pass_stack
store the current render pass
Definition context.h:781
virtual void enumerate_program_uniforms(shader_program &prog, std::vector< std::string > &names, std::vector< int > *locations_ptr=0, std::vector< int > *sizes_ptr=0, std::vector< int > *types_ptr=0, bool show=false) const =0
get list of program uniforms
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...
float current_font_size
store current font size
Definition context.h:793
bool enable_vsync
whether vsync should be enabled
Definition context.h:699
virtual void disable_material(textured_material &mat)=0
disable a material with textures
virtual void attach_alpha_buffer(bool attach=true)=0
attach or detach (attach=false) an alpha buffer to the current frame buffer if not present
virtual void attach_stencil_buffer(bool attach=true)=0
attach or detach (attach=false) stencil buffer to the current frame buffer if not present
std::stack< BufferMask > buffer_mask_stack
stack of buffer masks
Definition context.h:723
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...
virtual bool is_current() const =0
return whether the context is current
bool auto_set_lights_in_current_shader_program
whether to automatically set lights in current shader program, defaults to true
Definition context.h:687
size_t light_source_handle
counter to construct light source handles
Definition context.h:756
virtual void attach_stereo_buffer(bool attach=true)=0
attach or detach (attach=false) stereo buffer to the current frame buffer if not present
std::stack< shader_program_base * > shader_program_stack
stack of currently enabled shader programs
Definition context.h:732
virtual unsigned int get_width() const =0
return the width of the window
size_t get_nr_default_light_sources() const
return number of default light sources
Definition context.h:1167
virtual void set_color(const rgb &clr, float opacity=1.0f)
set the current color
Definition context.h:1101
virtual shader_program & ref_default_shader_program(bool texture_support=false)=0
return a reference to a shader program used to render without illumination
int current_background
current back ground color index
Definition context.h:787
virtual void clear_background(bool color_flag, bool depth_flag, bool stencil_flag=false, bool accum_flag=false)=0
clear the buffer contents of the flagged buffers to the set background colors
virtual bool is_stereo_buffer_supported() const =0
return whether the graphics card supports stereo buffer mode
virtual void resize(unsigned int width, unsigned int height)=0
resize the context to the given dimensions
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:1091
vec3 get_model_point(const vec3 &p_window) const
compute model space 3D point from the given window space point
Definition context.h:1456
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:726
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:683
virtual double get_window_z(int x_window, int y_window) const =0
read the window z-coordinate from the depth buffer for the given opengl x- and y-coordinates
int nr_identations
current number of indentations
Definition context.h:801
virtual void clear_current() const =0
clear the current context, typically used in multi-threaded rendering to allow usage of context in se...
bool auto_set_material_in_current_shader_program
whether to automatically set material in current shader program, defaults to true
Definition context.h:689
virtual void recover_from_external_frame_buffer_change(void *cgv_fbo_storage)=0
restore cgv frame buffer to the state before the external change
static vec3 get_model_point(int x_window, int y_window, double z_window, const dmat4 &modelview_projection_window_matrix)
compute model space 3D point from the given opengl pixel location (window location) with the given mo...
Definition context.h:1450
virtual RenderAPI get_render_api() const =0
return the used rendering API
std::stack< float > bg_depth_stack
stack of background depth values
Definition context.h:710
bool support_compatibility_mode
whether to support view and lighting management of compatibility mode, defaults to true
Definition context.h:693
std::stack< attribute_array_binding_base * > attribute_array_binding_stack
stack of currently enabled attribute array binding
Definition context.h:744
std::stack< DepthTestState > depth_test_state_stack
stack of depth test states
Definition context.h:717
std::stack< CullingMode > cull_state_stack
stack of culling mode states
Definition context.h:719
bool phong_shading
whether to use phong shading
Definition context.h:785
virtual void push_pixel_coords()=0
use this to push new modelview and new projection matrices onto the transformation stacks such that x...
virtual void force_redraw()=0
the context will be redrawn right now. This method cannot be called inside the following methods of a...
bool current_material_is_textured
store flag to tell whether current material is textured
Definition context.h:772
rgba current_color
current color value
Definition context.h:701
std::stack< int > bg_stencil_stack
stack of background stencil values
Definition context.h:712
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:797
std::stack< vec4 > bg_accum_color_stack
stack of background accumulation colors
Definition context.h:714
vec3 get_model_point(int x_window, int y_window, double z_window) const
compute model space 3D point from the given opengl pixel location (window location)
Definition context.h:1438
cgv::media::illum::surface_material default_material
store a default material
Definition context.h:768
bool sRGB_framebuffer_enabled()
check whether sRGB framebuffer is enabled
Definition context.h:1095
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:799
virtual void attach_depth_buffer(bool attach=true)=0
attach or detach (attach=false) depth buffer to the current frame buffer if not present
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:758
std::stack< std::vector< window_transformation > > window_transformation_stack
keep stack of window transformations
Definition context.h:728
int cursor_x
current cursor location for textual output
Definition context.h:789
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:695
bool sRGB_framebuffer
whether to use opengl option to support sRGB framebuffer
Definition context.h:703
virtual void enumerate_program_attributes(shader_program &prog, std::vector< std::string > &names, std::vector< int > *locations_ptr=0, std::vector< int > *sizes_ptr=0, std::vector< int > *types_ptr=0, bool show=false) const =0
get list of program attributes
virtual dmat4 get_modelview_matrix() const =0
return homogeneous 4x4 viewing matrix, which transforms from world to eye space
std::stack< frame_buffer_base * > frame_buffer_stack
stack of currently enabled frame buffers
Definition context.h:730
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:803
virtual void enable_material(textured_material &mat)=0
enable a material with textures
bool auto_set_view_in_current_shader_program
whether to automatically set viewing matrixes in current shader program, defaults to true
Definition context.h:685
bool debug_render_passes
whether to debug render passes
Definition context.h:697
std::vector< void * > enabled_light_source_handles
keep track of enabled light source handles
Definition context.h:754
virtual void attach_accumulation_buffer(bool attach=true)=0
attach or detach (attach=false) accumulation buffer to the current frame buffer if not present
virtual void attach_multi_sample_buffer(bool attach=true)=0
attach or detach (attach=false) multi sample buffer to the current frame buffer if not present
virtual shader_program & ref_surface_shader_program(bool texture_support=false)=0
return a reference to the default shader program used to render surfaces
virtual void post_redraw()=0
the context will be redrawn when the system is idle again
bool get_debug_render_passes() const
check whether render passes are debugged
Definition context.h:928
const cgv::media::illum::surface_material * current_material_ptr
store pointer to current material
Definition context.h:770
cgv::media::font::font_face_ptr current_font_face
store current font
Definition context.h:795
cgv::signal::callback_stream out_stream
use a callback stream to write text to the opengl context
Definition context.h:791
std::stack< vec4 > bg_color_stack
stack of background colors
Definition context.h:708
std::stack< BlendState > blend_state_stack
stack of blend states
Definition context.h:721
bool auto_set_gamma_in_current_shader_program
whether to automatically set gamma in current shader program, defaults to true
Definition context.h:691
base interface for framebuffer
Definition context.h:481
this class encapsulate frame buffers that live on the GPU and can be used as destination for the rend...
base interface for a render_buffer
Definition context.h:332
this class encapsulate render buffers that live on the GPU which must support frame buffer objects fo...
base interface for all render components
Definition context.h:309
void put_id(T &id) const
cast the refence to rendering api specific representation of component id to the specified type
Definition context.h:327
const context * ctx_ptr
keep pointer to my context
Definition context.h:315
std::string last_error
a string that contains the last error
Definition context.h:317
a shader code object holds a code fragment of a geometry vertex or fragment shader and can be added t...
base interface for shader programs
Definition context.h:363
a shader program combines several shader code fragments to a complete definition of the shading pipel...
base interface for a texture
Definition context.h:340
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
class that extends obj_material with the management of textures
base interface for a vertex buffer
Definition context.h:460
VertexBufferType type
buffer type defaults to VBT_VERTICES
Definition context.h:463
VertexBufferUsage usage
usage defaults to VBU_STATIC_DRAW
Definition context.h:465
a vertex buffer is an unstructured memory block on the GPU.
defines a symmetric view with the following quantities:
Definition view.h:22
connect to the write signal of the callback stream in order to process all text written to the stream
ComponentFormat
define standard formats, which should be used to avoid wrong assignment of component names
RenderAPI
enumeration of rendering APIs which can be queried from the context
Definition context.h:78
CullingMode
different culling modes
Definition context.h:151
cgv::data::ref_ptr< render_config > render_config_ptr
type of ref counted pointer to render configuration
Definition context.h:610
cgv::data::ref_ptr< context_config > context_config_ptr
type of ref counted pointer to context creation configuration
Definition context.h:576
void register_context_factory(context_creation_function_type fp)
registration context creation functions
Definition context.cxx:2447
BlendFunction
different blend functions
Definition context.h:158
TextAlignment
different text alignments
Definition context.h:281
@ TA_TOP
center of top edge of text bounds
Definition context.h:285
@ TA_BOTTOM_RIGHT
bottom right corner of text bounds
Definition context.h:290
@ TA_BOTTOM
center of bottom edge of text bounds
Definition context.h:286
@ TA_NONE
no alignment
Definition context.h:282
@ TA_RIGHT
center of right edge of text bounds
Definition context.h:284
@ TA_BOTTOM_LEFT
bottom left corner of text bounds
Definition context.h:289
@ TA_TOP_LEFT
top left corner of text bounds
Definition context.h:287
@ TA_LEFT
center of left edge of text bounds
Definition context.h:283
@ TA_TOP_RIGHT
top right corner of text bounds
Definition context.h:288
AccessType
different access types
Definition context.h:274
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:197
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:181
FrameBufferType
different frame buffer types which can be combined together with or
Definition context.h:498
MaterialSide
different sides of a material
Definition context.h:136
TextureSampling
different sampling strategies for rendering to textures that steer the computation of the tex_coord i...
Definition context.h:255
@ TS_VERTEX
tex_coord ranges from [0,0,0] to [1,1,1]
Definition context.h:257
@ TS_CELL
for texture resulution N x M x L the tex_coord ranges from [1/2N, 1/2M, 1/2L] to [1-1/2N,...
Definition context.h:256
ElementType
different compond types for data elements
Definition context.h:47
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:2460
VertexBufferUsage
Provides vertex buffer usage hints as defined in OpenGL.
Definition context.h:437
@ VBU_STATIC_COPY
Modified once and used many times; Modified by reading data from the GL, and used as the source for G...
Definition context.h:448
@ VBU_STREAM_COPY
Modified once and used at most a few times; Modified by reading data from the GL, and used as the sou...
Definition context.h:442
@ VBU_DYNAMIC_DRAW
Modified repeatedly and used many times; Modified by the application, and used as the source for GL d...
Definition context.h:450
@ VBU_STREAM_READ
Modified once and used at most a few times; Modified by reading data from the GL, and used to return ...
Definition context.h:440
@ VBU_DYNAMIC_COPY
Modified repeatedly and used many times; Modified by reading data from the GL, and used as the source...
Definition context.h:454
@ VBU_STATIC_READ
Modified once and used many times; Modified by reading data from the GL, and used to return that data...
Definition context.h:446
@ VBU_STATIC_DRAW
Modified once and used many times; Modified by the application, and used as the source for GL drawing...
Definition context.h:444
@ VBU_DYNAMIC_READ
Modified repeatedly and used many times; Modified by reading data from the GL, and used to return tha...
Definition context.h:452
@ VBU_STREAM_DRAW
Modified once and used at most a few times; Modified by the application, and used as the source for G...
Definition context.h:438
TextureCubeSides
the six different sides of a cube
Definition context.h:223
IlluminationMode
different illumination modes
Definition context.h:144
ShaderType
different shader types
Definition context.h:495
PrimitiveType
different primitive types
Definition context.h:233
VertexBufferType
Provides vertex buffer types to allow implicit binding.
Definition context.h:424
@ VBT_VERTICES
The buffer contains vertices and will be bound to GL_ARRAY_BUFFER.
Definition context.h:426
@ VBT_TEXTURE
The buffer contains texture data and will be bound to GL_TEXTURE_BUFFER.
Definition context.h:428
@ VBT_UNDEF
The buffer has no type.
Definition context.h:425
@ VBT_INDICES
The buffer contains indices and will be bound to GL_ELEMENT_ARRAY_BUFFER.
Definition context.h:427
@ VBT_ATOMIC_COUNTER
The buffer contains atomic counter and will be bound to GL_ATOMIC_COUNTER_BUFFER.
Definition context.h:432
@ VBT_STORAGE
The buffer contains arbitrary data and will be bound to GL_SHADER_STORAGE_BUFFER.
Definition context.h:431
@ VBT_UNIFORM
The buffer contains uniforms and will be bound to GL_UNIFORM_BUFFER.
Definition context.h:429
@ VBT_INDIRECT
The buffer contains indirect draw commands and will be bound to GL_DRAW_INDIRECT_BUFFER.
Definition context.h:433
@ VBT_FEEDBACK
The buffer is used for transform&feedback and will be bound to GL_TRANSFORM_FEEDBACK_BUFFER.
Definition context.h:430
BufferTypeBits
Bits for the selection of different buffer types.
Definition context.h:471
@ BTB_COLOR_BIT
color buffer type
Definition context.h:472
@ BTB_STENCIL_BIT
stencil buffer type
Definition context.h:475
@ BTB_ALL_BITS
all buffer types
Definition context.h:476
@ BTB_COLOR_AND_DEPTH_BITS
color and depth buffer types
Definition context.h:474
@ BTB_DEPTH_BIT
depth buffer type
Definition context.h:473
RenderPass
Enumeration of different render passes, which can be queried from the context and used to specify a n...
Definition context.h:85
@ RP_SHADOW_VOLUME
construction of shadow map
Definition context.h:90
@ RP_STEREO
rendering of second eye
Definition context.h:88
@ RP_USER_DEFINED
user defined renderpass
Definition context.h:94
@ RP_OPAQUE_SURFACES
opaque surface rendering using z-Buffer
Definition context.h:91
@ RP_NONE
no renderpass
Definition context.h:86
@ RP_MAIN
the main rendering pass triggered by the redraw event
Definition context.h:87
@ RP_TRANSPARENT_SURFACES
transparent surface rendering using depth peeling
Definition context.h:92
@ RP_PICK
in picking pass a small rectangle around the mouse is rendered
Definition context.h:93
@ RP_SHADOW_MAP
construction of shadow map
Definition context.h:89
TextureType
different texture types
Definition context.h:209
RenderPassFlags
available flags that can be queried from the context and set for a new render pass
Definition context.h:101
@ RPF_CLEAR_ACCUM
whether to clear the accumulation buffer
Definition context.h:116
@ RPF_SET_MODELVIEW
whether to set default modelview matrix
Definition context.h:104
@ RPF_DRAWABLES_FINISH_FRAME
whether to call finish frame method of drawables
Definition context.h:126
@ RPF_SET_MATERIAL
whether to define default material
Definition context.h:108
@ RPF_SET_CLEAR_DEPTH
whether to set the clear color
Definition context.h:122
@ RPF_ALL
all flags set, defines default render pass
Definition context.h:130
@ RPF_SET_LIGHTS
whether to define default lights
Definition context.h:107
@ RPF_CLEAR_COLOR
whether to clear the color buffer
Definition context.h:113
@ RPF_DRAWABLES_DRAW
whether to call draw and finish_draw methods of drawables
Definition context.h:125
@ RPF_CLEAR_STENCIL
whether to clear the depth buffer
Definition context.h:115
@ RPF_SET_MODELVIEW_PROJECTION
whether to set default modelview and projection matrix
Definition context.h:105
@ RPF_SET_CLEAR_STENCIL
whether to set the clear color
Definition context.h:123
@ RPF_ENABLE_MATERIAL
whether to enable material
Definition context.h:110
@ RPF_DRAWABLES_INIT_FRAME
whether to call the init_frame method of the drawables
Definition context.h:119
@ RPF_DRAWABLES_AFTER_FINISH
whether to call after finish method of drawables
Definition context.h:128
@ RPF_DEFAULT
all flags set, defines default render pass
Definition context.h:131
@ RPF_NONE
no frame initialization is performed
Definition context.h:102
@ RPF_HANDLE_SCREEN_SHOT
whether to perform a screen shot if this was scheduled
Definition context.h:129
@ RPF_CLEAR_DEPTH
whether to clear the depth buffer
Definition context.h:114
@ RPF_SET_STATE_FLAGS
whether to set depth buffer and culling flags
Definition context.h:120
@ RPF_CLEAR_ALL
whether to clear all buffers
Definition context.h:117
@ RPF_DRAW_TEXTUAL_INFO
whether to draw textual information
Definition context.h:127
@ RPF_SET_PROJECTION
whether to set default projection matrix
Definition context.h:103
@ RPF_SET_LIGHTING
whether to define and enable default lighting
Definition context.h:111
@ RPF_SET_CLEAR_ACCUM
whether to set the accumulation buffer clear color
Definition context.h:124
@ RPF_SET_CLEAR_COLOR
whether to set the clear color
Definition context.h:121
@ RPF_SET_LIGHTS_ON
whether to turn on default lights
Definition context.h:109
CompareFunction
different comparison functions used for depth testing or texture comparisons
Definition context.h:262
GPUVendorID
IDs for GPU vendors.
Definition context.h:31
TypeId
ids for the different types and type constructs
Definition type_id.h:12
@ TI_UINT8
signed integer stored in 64 bits
Definition type_id.h:23
the cgv namespace
Definition print.h:11
cgv::math::fmat< double, 4, 4 > dmat4
declare type of 4x4 matrices
Definition fmat.h:369
cgv::math::mat< double > dmatn
declare type of matrices of varying dimensions
Definition mat.h:1383
Represents a blend state used to configure fragment blending.
Definition context.h:652
Represents a buffer mask used to mask depth and color buffer outputs.
Definition context.h:667
Represents a depth test state used to configure depth testing.
Definition context.h:644
status information of light sources
Definition context.h:747
information necessary for a rendering pass
Definition context.h:775
configuration object used to define context parameters that need to be set already at creation time
Definition context.h:530
bool multi_sample_buffer
default: false
Definition context.h:546
bool stencil_buffer
default: false
Definition context.h:542
int version_minor
default: -1 ... minor version of maximum supported OpenGL version
Definition context.h:559
int depth_bits
default: -1
Definition context.h:548
bool double_buffer
default: true
Definition context.h:536
int version_major
default: -1 ... major version of maximum supported OpenGL version
Definition context.h:557
bool debug
default: false in release and true in debug version
Definition context.h:563
bool forward_compatible
default: false
Definition context.h:561
std::vector< int > context_creation_attrib_list
provide integer vector to store context creation attribute list
Definition context.h:572
bool stereo_buffer
default: false
Definition context.h:540
bool alpha_buffer
default: false
Definition context.h:538
bool core_profile
default: true
Definition context.h:565
int stencil_bits
default: -1
Definition context.h:550
int nr_multi_samples
default: -1
Definition context.h:554
bool accumulation_buffer
default: false
Definition context.h:544
int accumulation_bits
default: -1
Definition context.h:552
bool depth_buffer
default: true
Definition context.h:534
int max_compute_shared_memory_size
the maximum number that can be provided to the max_vertices output layout qualifier in a geometry sha...
Definition context.h:40
ivec3 max_compute_work_group_count
the number of invocations in a single local work group (i.e., the product of the three dimensions) th...
Definition context.h:42
int max_compute_work_group_invocations
total available storage size in bytes for all shared variables in a compute shader
Definition context.h:41
ivec3 max_compute_work_group_size
the maximum number of work groups that may be dispatched to a compute shader; dimension index 0,...
Definition context.h:43
configuration object used to define render view creation parameters including error handling configur...
Definition context.h:580
int window_width
default: 640
Definition context.h:586
bool dialog_on_error
default: true (only in case a gui_driver, which supports this, is loaded)
Definition context.h:596
int fullscreen_monitor
default: -1 ... no fullscreen
Definition context.h:584
int window_height
default: 480
Definition context.h:588
bool abort_on_error
default: false
Definition context.h:594
bool show_error_on_console
default: true
Definition context.h:598
compact type description of data that can be sent to the context; convertible to int
Definition context.h:55
type_descriptor(const type_descriptor &td, bool _is_array)
construct descriptor for an array
Definition context.h:72
type_descriptor(cgv::type::info::TypeId _coordinate_type, bool _normalize=false)
construct descriptor for values
Definition context.h:66
type_descriptor(cgv::type::info::TypeId _coordinate_type, unsigned _nr_rows, unsigned _nr_cols, bool _is_row_major, bool _normalize=false)
construct descriptor for matrices
Definition context.h:70
type_descriptor(cgv::type::info::TypeId _coordinate_type, unsigned _nr_entries, bool _normalize=false)
construct descriptor for vectors
Definition context.h:68
type_descriptor(int td=0)
construct from int
Definition context.h:64
parameters necessary to define window transformation
Definition context.h:617
dvec2 depth_range
range of depth values [min_depth, max_depth]
Definition context.h:621
ivec4 viewport
viewport parameters [x0,y0,width,height]
Definition context.h:619