1#include <cgv/base/group.h>
4#include <cgv_gl/gl/wgl.h>
11#include <cgv/base/base.h>
12#include <cgv/base/action.h>
13#include <cgv/render/drawable.h>
14#include <cgv/render/shader_program.h>
15#include <cgv/render/attribute_array_binding.h>
16#include <cgv/render/vertex_buffer.h>
17#include <cgv/render/textured_material.h>
19#include <cgv/media/image/image_writer.h>
20#include <cgv/gui/event_handler.h>
21#include <cgv/math/ftransform.h>
22#include <cgv/math/geom.h>
23#include <cgv/math/inv.h>
24#include <cgv/type/standard_types.h>
25#include <cgv/os/clipboard.h>
31using namespace cgv::os;
32using namespace cgv::math;
34using namespace cgv::media::illum;
63 if (
cc.version_major < 1)
66 version = 10 *
cc.version_major + (
cc.version_minor >= 0 ?
cc.version_minor : 0);
67 if ((version > 30 &&
cc.forward_compatible) ||
cc.debug) {
73 if (
cc.version_major > 0) {
77 if (
cc.version_minor >= 0) {
175static const GLenum gl_depth_format_ids[] =
183static const GLenum gl_color_buffer_format_ids[] =
189static const char* depth_formats[] =
198static const char* color_buffer_formats[] =
271GLuint get_gl_id(
const void* handle)
273 return (
const GLuint&)handle - 1;
276void* get_handle(
GLuint id)
283void gl_context::put_id(
void* handle,
void* ptr)
const
285 *
static_cast<GLuint*
>(ptr) = get_gl_id(handle);
298 if (tex.internal_format)
299 return (
const GLuint&)tex.internal_format;
308 GLfloat v[4] = { c[0],c[1],c[2],c[3] * alpha };
317 unsigned side = map_to_gl(
ms);
371std::string get_source_tag_name(
GLenum tag)
373 static std::map<GLenum, const char*>
source_tags = {
386 static std::map<GLenum, const char*>
type_tags = {
400std::string get_severity_tag_name(
GLenum tag)
415 const gl_context* ctx =
reinterpret_cast<const gl_context*
>(
userParam);
417 msg = std::string(
"GLDebug Message[") +
cgv::utils::to_string(
id) +
"] from " + get_source_tag_name(source) +
" of type " + get_type_tag_name(type) +
" of severity " + get_severity_tag_name(
severity) +
"\n" +
msg;
425 error(
"gl_context::configure_gl could not initialize glew");
450 std::cerr <<
"WARNING: Ignoring that GL_CONTEXT_PROFILE_MASK yields compatibility profile for context created as core." << std::endl;
452 std::cerr <<
"WARNING: Ignoring that GL_CONTEXT_PROFILE_MASK does not yield compatibility profile for context created as such." << std::endl;
456 std::cerr <<
"WARNING: Ignoring that GL_CONTEXT_PROFILE_MASK yields zero." << std::endl;
467 gpu_vendor = GPU_VENDOR_NVIDIA;
469 gpu_vendor = GPU_VENDOR_INTEL;
471 gpu_vendor = GPU_VENDOR_AMD;
488 if (!check_gl_error(
"gl_context::configure() debug output"))
508 for (
unsigned i = 0;
i<
grp->get_nr_children(); ++
i)
517void gl_context::resize_gl()
577void gl_context::init_render_pass()
629 if (check_gl_error(
"gl_context::init_render_pass before init_frame"))
638 if (check_gl_error(
"gl_context::init_render_pass after init_frame"))
661void gl_context::finish_render_pass()
686void gl_context::draw_textual_info()
688 if (show_help || show_stats) {
700 if (
bg[0] +
bg[1] +
bg[2] < 1.5f)
708 if (
grp && show_stats) {
714 if(
bg[0] +
bg[1] +
bg[2] < 1.5f)
719 if (
grp && show_help) {
730void gl_context::perform_screen_shot()
736 std::string
ext(
"bmp");
752 for (
int i = 0;
i < count; ++
i) {
768 std::cout <<
i <<
" at " <<
loc <<
" = " <<
name_str <<
":" << type <<
"[" << size <<
"]" << std::endl;
777 for (
int i = 0;
i < count; ++
i) {
793 std::cout <<
i <<
" at " <<
loc <<
" = " <<
name_str <<
":" << type <<
"[" << size <<
"]" << std::endl;
807 if (!prog.does_context_set_color())
809 int clr_loc = prog.get_color_index();
819 unsigned side = map_to_gl(MS_FRONT_AND_BACK);
820 float alpha = 1.0f - material.get_transparency();
821 gl_set_material_color(
side, material.get_ambient_occlusion()*material.get_diffuse_reflectance(), alpha,
GL_AMBIENT);
822 gl_set_material_color(
side, material.get_diffuse_reflectance(), alpha,
GL_DIFFUSE);
823 gl_set_material_color(
side, material.get_specular_reflectance(), alpha,
GL_SPECULAR);
824 gl_set_material_color(
side, material.get_emission(), alpha,
GL_EMISSION);
834 mat.enable_textures(*
this);
840 mat.disable_textures(*
this);
845void gl_context::destruct_render_objects()
847 for (
unsigned i = 0;
i < 4; ++
i)
848 progs[
i].destruct(*
this);
856 if (!progs[0].build_program(*
this,
"default.glpr")) {
857 error(
"could not build default shader program from default.glpr");
860 progs[0].specify_standard_uniforms(
true,
false,
false,
true);
861 progs[0].specify_standard_vertex_attribute_names(*
this,
true,
false,
false);
862 progs[0].allow_context_to_set_color(
true);
867 if (!progs[1].build_program(*
this,
"textured_default.glpr")) {
868 error(
"could not build default shader program with texture support from textured_default.glpr");
872 progs[1].specify_standard_uniforms(
true,
false,
false,
true);
873 progs[1].specify_standard_vertex_attribute_names(*
this,
true,
false,
true);
874 progs[1].allow_context_to_set_color(
true);
884 if (!progs[2].build_program(*
this,
"default_surface.glpr")) {
885 error(
"could not build surface shader program from default_surface.glpr");
888 progs[2].specify_standard_uniforms(
true,
true,
true,
true);
889 progs[2].specify_standard_vertex_attribute_names(*
this,
true,
true,
false);
890 progs[2].allow_context_to_set_color(
true);
895 if (!progs[3].build_program(*
this,
"textured_surface.glpr")) {
896 error(
"could not build surface shader program with texture support from textured_surface.glpr");
899 progs[3].specify_standard_uniforms(
true,
true,
true,
true);
900 progs[3].specify_standard_vertex_attribute_names(*
this,
true,
true,
true);
901 progs[3].allow_context_to_set_color(
true);
925 GLfloat pos[4] = { 0,0,0,
light.get_type() == cgv::media::illum::LT_DIRECTIONAL ? 0.0f : 1.0f };
928 if (
light.get_type() != cgv::media::illum::LT_DIRECTIONAL) {
938 if (
light.get_type() == cgv::media::illum::LT_SPOT) {
946 static float dir[3] = { 0,0,1 };
987 compute_rotation_axis_and_angle_from_vector_pair(vector, target, axis, angle);
994 if ((start - end).length() < 1
e-8) {
995 error(
"ignored tesselate arrow called with start and end closer then 1e-8");
1009 switch (
l.get_type()) {
1010 case LT_DIRECTIONAL :
1016 cgv::math::translate4<double>(
l.get_position())*
1022 cgv::math::translate4<double>(
l.get_position())*
1027 float t =
tan(
l.get_spot_cutoff()*(
float)M_PI/180);
1028 if (
l.get_spot_cutoff() > 45.0f)
1045 error(
"gl_context::announce_external_frame_buffer_change() called with empty frame buffer stack");
1065 error(
"gl_context::announce_external_viewport_change() called with empty window transformation stack");
1096 glOrtho(vp[0], vp[0]+vp[2], vp[1], vp[1]+vp[3], -1, 1);
1124 if (w < 1 || h < 1) {
1130 if (w < 1 || h < 1) {
1133 w = w < 1 ? vp[2] : w;
1134 h = h < 1 ? vp[3] : h;
1190void render_vertex(
int k,
const float* vertices,
const float* normals,
const float* tex_coords,
1191 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
bool flip_normals)
1193 if (normals && normal_indices) {
1195 float n[3] = { -normals[3*normal_indices[k]],-normals[3*normal_indices[k]+1],-normals[3*normal_indices[k]+2] };
1201 if (tex_coords && tex_coord_indices)
1206attribute_array_binding*& get_aab_ptr()
1208 static attribute_array_binding* aab_ptr = 0;
1212vertex_buffer*& get_vbo_ptr()
1214 static vertex_buffer* vbo_ptr = 0;
1221 if (!prog_ptr || prog_ptr->get_position_index() == -1)
1227 if (prog_ptr->get_normal_index() != -1 && normals && normal_indices)
1229 if (prog_ptr->get_texcoord_index() != -1 && tex_coords && tex_coord_indices)
1234 aab_ptr->
disable_array(*
this, prog_ptr->get_position_index());
1235 if (prog_ptr->get_normal_index() != -1 && normals && normal_indices)
1237 if (prog_ptr->get_texcoord_index() != -1 && tex_coords && tex_coord_indices)
1248 const float* vertices,
const float* normals,
const float* tex_coords,
1249 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
bool flip_normals)
const
1253 if (!prog_ptr || prog_ptr->get_position_index() == -1)
1255 P.resize(nr_vertices);
1256 for (
i = 0;
i < nr_vertices; ++
i)
1257 P[
i] = *
reinterpret_cast<const vec3*
>(vertices + 3 * vertex_indices[
i]);
1259 if (prog_ptr->get_normal_index() != -1 && normals && normal_indices) {
1260 N.resize(nr_vertices);
1261 for (
i = 0;
i < nr_vertices; ++
i) {
1262 N[
i] = *
reinterpret_cast<const vec3*
>(normals + 3 * normal_indices[
i]);
1267 if (prog_ptr->get_texcoord_index() != -1 && tex_coords && tex_coord_indices) {
1268 T.resize(nr_vertices);
1269 for (
i = 0;
i < nr_vertices; ++
i)
1270 T[
i] = *
reinterpret_cast<const vec2*
>(tex_coords + 2 * tex_coord_indices[
i]);
1279 attribute_array_binding::set_global_attribute_array<>(*
this, prog_ptr->get_position_index(),
P);
1281 if (prog_ptr->get_normal_index() != -1) {
1282 if (normals && normal_indices) {
1283 attribute_array_binding::set_global_attribute_array<>(*
this, prog_ptr->get_normal_index(), N);
1289 if (prog_ptr->get_texcoord_index() != -1) {
1290 if (tex_coords && tex_coord_indices) {
1291 attribute_array_binding::set_global_attribute_array<>(*
this, prog_ptr->get_texcoord_index(),
T);
1304 vbo_ptr->
create(*
this,
P.size() *
sizeof(
vec3) + N.size() *
sizeof(
vec3) +
T.size() *
sizeof(
vec2));
1317 aab_ptr->
enable_array(*
this, prog_ptr->get_position_index());
1318 if (prog_ptr->get_normal_index() != -1) {
1319 if (normals && normal_indices) {
1321 aab_ptr->
enable_array(*
this, prog_ptr->get_normal_index());
1324 aab_ptr->
disable_array(*
this, prog_ptr->get_normal_index());
1326 if (prog_ptr->get_texcoord_index() != -1) {
1327 if (tex_coords && tex_coord_indices) {
1330 aab_ptr->
enable_array(*
this, prog_ptr->get_texcoord_index());
1333 aab_ptr->
disable_array(*
this, prog_ptr->get_texcoord_index());
1342 const float* vertices,
const float* normals,
const float* tex_coords,
1343 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
1344 int nr_faces,
int face_degree,
bool flip_normals)
const
1348 for (
int i = 0;
i < nr_faces; ++
i) {
1350 for (
int j = 0;
j < face_degree; ++
j, ++k)
1351 render_vertex(k, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1356 unsigned nr_vertices = face_degree * nr_faces;
1357 std::vector<vec3>
P, N;
1358 std::vector<vec2>
T;
1359 if (!
prepare_attributes(
P, N,
T, nr_vertices, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals))
1361 for (
int i = 0;
i < nr_faces; ++
i)
1369 ensure_configured();
1374 if (count > max_nr_indices)
1375 count =
size_t(max_nr_indices);
1381size_t max_nr_indices, max_nr_vertices;
1382void gl_context::ensure_configured()
const
1384 if (max_nr_indices != 0)
1392 const float* vertices,
const float* normals,
const float* tex_coords,
1393 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
1396 int s = face_degree - 2;
1398 std::vector<GLuint>
I;
1399 I.push_back(0);
I.push_back(1);
1400 for (
i = 0;
i < nr_faces; ++
i) {
1402 I.push_back(k - 1);
I.push_back(k);
1403 I.push_back(0);
I.push_back(k);
1407 I.push_back(k - 1);
I.push_back(k);
1408 I.push_back(k - 2);
I.push_back(k);
1411 I.push_back(k - 1);
I.push_back(k + 1);
1412 I.push_back(k - 2);
I.push_back(k);
1413 I.push_back(k);
I.push_back(k + 1);
1421 render_vertex(
j, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1425 unsigned nr_vertices = 2 + (face_degree - 2) * nr_faces;
1426 std::vector<vec3>
P, N;
1427 std::vector<vec2>
T;
1428 if (!
prepare_attributes(
P, N,
T, nr_vertices, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals))
1435 const float* vertices,
const float* normals,
const float* tex_coords,
1436 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
1437 int nr_faces,
int face_degree,
bool flip_normals)
const
1441 if (face_degree < 5)
1443 for (
int i = 0;
i < nr_faces; ++
i) {
1444 if (face_degree >= 5)
1446 for (
int j = 0;
j < face_degree; ++
j, ++k)
1447 render_vertex(k, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1448 if (face_degree >= 5)
1451 if (face_degree < 5)
1455 unsigned nr_vertices = face_degree * nr_faces;
1456 std::vector<vec3>
P, N;
1457 std::vector<vec2>
T;
1458 if (!
prepare_attributes(
P, N,
T, nr_vertices, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals))
1470 if (face_degree == 3)
1473 for (
int i = 0;
i < nr_faces; ++
i) {
1481 const float* vertices,
const float* normals,
const float* tex_coords,
1482 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
1485 int s = face_degree - 2;
1489 render_vertex(0, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1490 render_vertex(1, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1491 for (
int i = 0;
i < nr_faces; ++
i)
1492 for (
int j = 0;
j < s; ++
j, ++k)
1493 render_vertex(k, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1497 unsigned nr_vertices = 2 + (face_degree-2) * nr_faces;
1498 std::vector<vec3>
P, N;
1499 std::vector<vec2>
T;
1500 if (!
prepare_attributes(
P, N,
T, nr_vertices, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals))
1531 switch(culling_mode) {
1595 map_to_gl(
mask.red_flag),
1596 map_to_gl(
mask.green_flag),
1597 map_to_gl(
mask.blue_flag),
1598 map_to_gl(
mask.alpha_flag)
1610 map_to_gl(flags[0]),
1611 map_to_gl(flags[1]),
1612 map_to_gl(flags[2]),
1639 if (projection_matrix_stack.empty())
1641 return projection_matrix_stack.top();
1647 update_window_transformation_array();
1650void gl_context::update_window_transformation_array()
1653 if (
wta.size() == 1) {
1654 const ivec4& viewport =
wta.front().viewport;
1655 const dvec2& depth_range =
wta.front().depth_range;
1673 GLint max_value = 1;
1685 update_window_transformation_array();
1704 update_window_transformation_array();
1714gl_context::dmat4 gl_context::get_device_matrix() const
1717 glGetIntegerv(GL_VIEWPORT, vp);
1719 D(0, 0) = 0.5*vp[2];
1720 D(0, 3) = 0.5*vp[2] + vp[0];
1721 D(1, 1) = -0.5*vp[3]; // flip y-coordinate
1722 D(1, 3) = get_height() - 0.5*vp[3] - vp[1];
1792std::string gl_error_to_string(
GLenum eid) {
1803 return "undefined error (id: " + std::to_string(
eid) +
")";
1808std::string gl_error() {
1810 return gl_error_to_string(
eid);
1850 error(
where+
": compute shader need not supported OpenGL version 4.3",
rc);
1853 case ST_TESS_CONTROL:
1854 case ST_TESS_EVALUATION:
1858 error(
where+
": tessellation shader need not supported OpenGL version 4.0",
rc);
1865 error(
where +
": geometry shader need not supported OpenGL version 3.2",
rc);
1872 error(
where +
": shaders need not supported OpenGL version 2.0",
rc);
1881 error(
where +
": framebuffer objects not supported",
rc);
1887GLuint gl_context::texture_generate(texture_base&
tb)
const
1889 if (!check_texture_support(
tb.tt,
"gl_context::texture_generate", &
tb))
1890 return get_gl_id(0);
1891 GLuint tex_id = get_gl_id(0);
1894 error(
"gl_context::texture_generate: attempt to create texture inside glBegin-glEnd-block", &
tb);
1902 case MAX_NR_GEOMETRY_SHADER_OUTPUT_VERTICES :
1928 if (
tb.tt == TT_UNDEF)
1930 GLuint tex_id = texture_generate(
tb);
1931 if (tex_id == get_gl_id(0))
1936 unsigned int transfer_format = map_to_gl(df.get_standard_component_format(), df.get_integer_interpretation());
1938 error(
"could not determine transfer format", &
tb);
1953 case TT_MULTISAMPLE_2D:
1959 case TT_MULTISAMPLE_2D_ARRAY:
1982 if (check_gl_error(
"gl_context::texture_create", &
tb)) {
1989 tb.have_mipmaps =
false;
1990 tb.handle = get_handle(tex_id);
1994bool gl_context::texture_create(
2004 tb.tt = (
TextureType)data.get_format()->get_nr_dimensions();
2011 unsigned n_dims = data.get_format()->get_nr_dimensions();
2013 tb.tt = TT_1D_ARRAY;
2015 tb.tt = TT_2D_ARRAY;
2018 case TT_1D:
tb.tt = TT_1D_ARRAY;
break;
2019 case TT_2D:
tb.tt = TT_2D_ARRAY;
break;
2020 case TT_3D:
tb.tt = TT_2D_ARRAY;
break;
2028 if (
tb.is_created())
2029 tex_id = get_gl_id(
tb.handle);
2031 tex_id = texture_generate(
tb);
2032 if (tex_id == get_gl_id(0))
2034 tb.handle = get_handle(tex_id);
2042 bool result = !check_gl_error(
"gl_context::texture_create", &
tb);
2048bool gl_context::texture_create_from_buffer(
2051 int x,
int y,
int level)
const
2056 if (
tb.tt != TT_2D) {
2057 tb.last_error =
"texture creation from buffer only possible for 2d textures";
2061 if (
tb.is_created())
2062 tex_id = get_gl_id(
tb.handle);
2064 tex_id = texture_generate(
tb);
2065 if (tex_id == get_gl_id(0))
2067 tb.handle = get_handle(tex_id);
2077 bool result =
false;
2078 std::string
error_string(
"gl_context::texture_create_from_buffer: ");
2087 error_string +=
"level was less than zero or greater than log sub 2(max), where max is the returned value of GL_MAX_TEXTURE_SIZE.\n"
2088 "or border was not zero or 1.\n"
2089 "or width was less than zero, greater than 2 + GL_MAX_TEXTURE_SIZE; or width cannot be represented as 2n + 2 * border for some integer n.";
2092 error_string +=
"glCopyTexImage2D was called between a call to glBegin and the corresponding call to glEnd.";
2103 result = texture_generate_mipmaps(
tb,
tb.tt == TT_CUBEMAP ? 2 : (
int)
tb.tt);
2108bool gl_context::texture_replace(
2110 int x,
int y,
int z,
2112 int level,
const std::vector<cgv::data::data_view>*
palettes)
const
2114 if (!
tb.is_created()) {
2115 error(
"gl_context::texture_replace: attempt to replace in not created texture", &
tb);
2119 unsigned int dim = 1;
2126 if (
tb.tt == TT_CUBEMAP) {
2128 error(
"gl_context::texture_replace: replace on cubemap without the side defined", &
tb);
2132 error(
"gl_context::texture_replace: replace on cubemap with invalid side specification", &
tb);
2138 error(
"gl_context::texture_replace: replace on texture with invalid position specification", &
tb);
2146 bool result = !check_gl_error(
"gl_context::texture_replace", &
tb);
2151bool gl_context::texture_replace_from_buffer(
2153 int x,
int y,
int z,
2155 unsigned int width,
unsigned int height,
2158 if (!
tb.is_created()) {
2159 error(
"gl_context::texture_replace_from_buffer: attempt to replace in not created texture", &
tb);
2163 unsigned int dim = 2;
2168 if (
tb.tt == TT_CUBEMAP) {
2170 error(
"gl_context::texture_replace_from_buffer: replace on cubemap without the side defined", &
tb);
2174 error(
"gl_context::texture_replace_from_buffer: replace on cubemap without invalid side specification", &
tb);
2180 tb.last_error =
"replace on texture with invalid position specification";
2197 bool result = !check_gl_error(
"gl_context::texture_replace_from_buffer", &
tb);
2201 result = texture_generate_mipmaps(
tb,
tb.tt == TT_CUBEMAP ? 2 : (
int)
tb.tt);
2211 unsigned int transfer_format = map_to_gl(df.get_standard_component_format(), df.get_integer_interpretation());
2214 error(
"could not determine transfer format", &
tb);
2219 uvec3 size(
unsigned(df.get_width()),
unsigned(df.get_height()),
unsigned(df.get_depth()));
2221 unsigned max_size = cgv::math::max_value(size);
2228 for(
unsigned level = 1; level <
num_levels; ++level) {
2241 for(
unsigned level = 1; level <
num_levels; ++level) {
2248 error(
"create mipmaps not implemented for 1D array textures", &
tb);
2252 for(
unsigned level = 1; level <
num_levels; ++level) {
2257 case TT_MULTISAMPLE_2D:
2259 error(
"create mipmaps not implemented for 2D multisample textures", &
tb);
2264 error(
"create mipmaps not implemented for 2D array textures", &
tb);
2267 case TT_MULTISAMPLE_2D_ARRAY:
2269 error(
"create mipmaps not implemented for 2D multisample array textures", &
tb);
2273 for(
unsigned level = 1; level <
num_levels; ++level) {
2292 error(
"create mipmaps not implemented for cubemap textures", &
tb);
2298 if(check_gl_error(
"gl_context::texture_create_mipmaps", &
tb))
2302 tb.have_mipmaps =
true;
2308bool gl_context::texture_generate_mipmaps(texture_base&
tb,
unsigned int dim)
const
2312 bool is_array =
tb.tt == TT_1D_ARRAY ||
tb.tt == TT_2D_ARRAY;
2317 tb.have_mipmaps =
true;
2325bool gl_context::texture_destruct(texture_base&
tb)
const
2327 if (!
tb.is_created()) {
2328 error(
"gl_context::texture_destruct: attempt to destruct not created texture", &
tb);
2331 GLuint tex_id = get_gl_id(
tb.handle);
2333 bool result = !check_gl_error(
"gl_context::texture_destruct", &
tb);
2338bool gl_context::texture_set_state(
const texture_base&
tb)
const
2340 if (
tb.tt == TT_UNDEF) {
2341 error(
"gl_context::texture_set_state: attempt to set state on texture without type", &
tb);
2346 error(
"gl_context::texture_set_state: attempt of setting texture state of not created texture", &
tb);
2351 if (
tb.tt != TT_MULTISAMPLE_2D &&
tb.tt != TT_MULTISAMPLE_2D_ARRAY) {
2354 if (
tb.min_filter == TF_ANISOTROP)
2371 bool result = !check_gl_error(
"gl_context::texture_set_state", &
tb);
2376bool gl_context::texture_enable(texture_base&
tb,
int tex_unit,
unsigned int dim)
const
2379 error(
"gl_context::texture_enable: invalid texture dimension", &
tb);
2384 error(
"gl_context::texture_enable: texture not created", &
tb);
2387 if (tex_unit >= 0) {
2389 error(
"gl_context::texture_enable: multi texturing not supported", &
tb);
2401 bool result = !check_gl_error(
"gl_context::texture_enable", &
tb);
2407bool gl_context::texture_disable(
2409 int tex_unit,
unsigned int dim)
const
2412 error(
"gl_context::texture_disable: invalid texture dimension", &
tb);
2415 if (tex_unit == -2) {
2416 error(
"gl_context::texture_disable: invalid texture unit", &
tb);
2426 bool result = !check_gl_error(
"gl_context::texture_disable", &
tb);
2437 error(
"gl_context::texture_enable: texture not created", &
tb);
2442 error(
"gl_context::texture_bind_as_image: image textures not supported", &
tb);
2449 bool result = !check_gl_error(
"gl_context::texture_bind_as_image", &
tb);
2456 error(
"gl_context::render_buffer_create: frame buffer objects not supported", &
rb);
2480 if (
rb.nr_multi_samples == 0)
2485 if (check_gl_error(
"gl_context::render_buffer_create", &
rb))
2487 rb.handle = get_handle(
rb_id);
2491bool gl_context::render_buffer_destruct(render_buffer_base&
rc)
const
2494 error(
"gl_context::render_buffer_destruct: frame buffer objects not supported", &
rc);
2499 if (check_gl_error(
"gl_context::render_buffer_destruct", &
rc))
2505bool gl_context::frame_buffer_create(frame_buffer_base&
fbb)
const
2507 if (!check_fbo_support(
"gl_context::frame_buffer_create", &
fbb))
2510 if (!context::frame_buffer_create(
fbb))
2517 error(
"gl_context::frame_buffer_create: could not allocate framebuffer object", &
fbb);
2520 fbb.handle = get_handle(fbo_id);
2524bool gl_context::frame_buffer_enable(frame_buffer_base&
fbb)
2526 if (!context::frame_buffer_enable(
fbb))
2528 std::vector<int> buffers;
2533 if (buffers.size() == 1)
2535 else if (buffers.size() > 1) {
2542 error(
"gl_context::frame_buffer_enable: no attached draw buffer selected!!", &
fbb);
2551 if (!context::frame_buffer_disable(
fbb))
2554 error(
"gl_context::frame_buffer_disable called with empty frame buffer stack!!", &
fbb);
2564 if (!context::frame_buffer_destruct(
fbb))
2572void complete_rect_from_vp(
ivec4& D,
GLint vp[4])
2579 D(2) = vp[0] + vp[2];
2581 D(3) = vp[1] + vp[3];
2584void gl_context::frame_buffer_blit(
2600 if ((
src_fbb_ptr == 0 && (S(0) == -1 || S(1) == -1 || S(2) == -1 || S(3) == -1)) ||
2601 (
dst_fbb_ptr == 0 && (D(0) == -1 || D(1) == -1 || D(2) == -1 || D(3) == -1))) {
2605 complete_rect_from_vp(S, vp);
2607 complete_rect_from_vp(D, vp);
2625bool gl_context::frame_buffer_attach(frame_buffer_base&
fbb,
const render_buffer_base&
rb,
bool is_depth,
int i)
const
2635 get_gl_id(
rb.handle));
2657 if (t.tt == TT_CUBEMAP) {
2668 bool result = !check_gl_error(
"gl_context::frame_buffer_attach", &
fbb);
2676 if (
fbb.handle == 0) {
2677 error(
"gl_context::frame_buffer_is_complete: attempt to check completeness on frame buffer that is not created", &
fbb);
2689 fbb.last_error =
"undefined framebuffer";
2692 fbb.last_error =
"incomplete attachment";
2695 fbb.last_error =
"incomplete or missing attachment";
2698 fbb.last_error =
"incomplete multisample";
2701 fbb.last_error =
"incomplete layer targets";
2704 fbb.last_error =
"incomplete draw buffer";
2707 fbb.last_error =
"incomplete read buffer";
2710 fbb.last_error =
"framebuffer objects unsupported";
2713 fbb.last_error =
"unknown error";
2717int gl_context::frame_buffer_get_max_nr_color_attachments()
const
2719 if (!check_fbo_support(
"gl_context::frame_buffer_get_max_nr_color_attachments"))
2727int gl_context::frame_buffer_get_max_nr_draw_buffers()
const
2729 if (!check_fbo_support(
"gl_context::frame_buffer_get_max_nr_draw_buffers"))
2742void gl_context::shader_code_destruct(render_component&
sc)
const
2744 if (
sc.handle == 0) {
2745 error(
"gl_context::shader_code_destruct: shader not created", &
sc);
2749 check_gl_error(
"gl_context::shader_code_destruct", &
sc);
2752bool gl_context::shader_code_create(render_component&
sc,
ShaderType st,
const std::string& source)
const
2754 if (!check_shader_support(st,
"gl_context::shader_code_create", &
sc))
2759 error(std::string(
"gl_context::shader_code_create: ")+gl_error(), &
sc);
2762 sc.handle = get_handle(
s_id);
2764 const char* s = source.c_str();
2766 if (check_gl_error(
"gl_context::shader_code_create", &
sc))
2772bool gl_context::shader_code_compile(render_component&
sc)
const
2774 if (
sc.handle == 0) {
2775 error(
"gl_context::shader_code_compile: shader not created", &
sc);
2784 sc.last_error = std::string();
2797bool gl_context::shader_program_create(shader_program_base&
spb)
const
2799 if (!check_shader_support(ST_VERTEX,
"gl_context::shader_program_create", &
spb))
2805void gl_context::shader_program_attach(shader_program_base&
spb,
const render_component&
sc)
const
2807 if (
spb.handle == 0) {
2808 error(
"gl_context::shader_program_attach: shader program not created", &
spb);
2814void gl_context::shader_program_detach(shader_program_base&
spb,
const render_component&
sc)
const
2816 if (
spb.handle == 0) {
2817 error(
"gl_context::shader_program_detach: shader program not created", &
spb);
2823bool gl_context::shader_program_link(shader_program_base&
spb)
const
2825 if (
spb.handle == 0) {
2826 error(
"gl_context::shader_program_link: shader program not created", &
spb);
2834 return context::shader_program_link(
spb);
2842 error(std::string(
"gl_context::shader_program_link\n")+
infoLog, &
spb);
2848bool gl_context::shader_program_set_state(shader_program_base&
spb)
const
2850 if (
spb.handle == 0) {
2851 error(
"gl_context::shader_program_set_state: shader program not created", &
spb);
2861bool gl_context::shader_program_enable(shader_program_base&
spb)
2863 if (!context::shader_program_enable(
spb))
2866 shader_program& prog =
static_cast<shader_program&
>(
spb);
2875 if (prog.does_context_set_color() && prog.get_color_index() >= 0)
2876 prog.set_attribute(*
this, prog.get_color_index(),
current_color);
2880bool gl_context::shader_program_disable(shader_program_base&
spb)
2882 if (!context::shader_program_disable(
spb))
2891bool gl_context::shader_program_destruct(shader_program_base&
spb)
const
2893 if (!context::shader_program_destruct(
spb))
2899int gl_context::get_uniform_location(
const shader_program_base&
spb,
const std::string& name)
const
2904std::string value_type_index_to_string(type_descriptor
td)
2907 switch (
td.element_type) {
2913 if (
td.is_row_major)
2923bool gl_context::set_uniform_void(shader_program_base&
spb,
int loc, type_descriptor value_type,
const void* value_ptr)
const
2925 if (value_type.is_array) {
2926 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") array type not supported, please use set_uniform_array instead.", &
spb);
2930 error(
"gl_context::set_uniform_void() called on not created program", &
spb);
2937 switch (value_type.element_type) {
2939 switch (value_type.coordinate_type) {
2950 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
2955 switch (value_type.nr_rows) {
2957 switch (value_type.coordinate_type) {
2968 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
2973 switch (value_type.coordinate_type) {
2984 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
2989 switch (value_type.coordinate_type) {
3000 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3007 switch (value_type.coordinate_type) {
3009 switch (value_type.nr_rows) {
3011 switch (value_type.nr_columns) {
3016 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3021 switch (value_type.nr_columns) {
3026 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3031 switch (value_type.nr_columns) {
3036 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3041 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of rows outside [2,..,4].", &
spb);
3046 switch (value_type.nr_rows) {
3048 switch (value_type.nr_columns) {
3053 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3058 switch (value_type.nr_columns) {
3063 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3068 switch (value_type.nr_columns) {
3073 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3078 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of rows outside [2,..,4].", &
spb);
3083 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") non float coordinate type not supported.", &
spb);
3091 if (check_gl_error(
"gl_context::set_uniform_void()", &
spb))
3096bool gl_context::set_uniform_array_void(shader_program_base&
spb,
int loc, type_descriptor value_type,
const void* value_ptr,
size_t nr_elements)
const
3098 if (!value_type.is_array) {
3099 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") non array type not allowed.", &
spb);
3103 error(
"gl_context::set_uniform_array_void() called on not created program", &
spb);
3110 switch (value_type.coordinate_type) {
3112 switch (value_type.element_type) {
3117 switch (value_type.nr_rows) {
3122 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") vector dimension outside [2,..4].", &
spb);
3128 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") type not supported.", &
spb);
3134 switch (value_type.element_type) {
3139 switch (value_type.nr_rows) {
3144 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") vector dimension outside [2,..4].", &
spb);
3150 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") type not supported.", &
spb);
3156 switch (value_type.element_type) {
3161 switch (value_type.nr_rows) {
3166 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") vector dimension outside [2,..4].", &
spb);
3172 switch (value_type.nr_rows) {
3174 switch (value_type.nr_columns) {
3179 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..4].", &
spb);
3185 switch (value_type.nr_columns) {
3190 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..4].", &
spb);
3196 switch (value_type.nr_columns) {
3201 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..4].", &
spb);
3207 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") matrix number of rows outside [2,..4].", &
spb);
3215 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type (only int32, uint32, and flt32 supported).", &
spb);
3219 if (check_gl_error(
"gl_context::set_uniform_array_void()", &
spb))
3228int gl_context::get_attribute_location(
const shader_program_base&
spb,
const std::string& name)
const
3234bool gl_context::set_attribute_void(shader_program_base&
spb,
int loc, type_descriptor value_type,
const void* value_ptr)
const
3237 error(
"gl_context::set_attribute_void() called on not created program", &
spb);
3244 switch (value_type.element_type) {
3246 switch (value_type.coordinate_type) {
3257 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") type not supported!", &
spb);
3263 switch (value_type.nr_rows) {
3265 switch (value_type.coordinate_type) {
3276 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3282 switch (value_type.coordinate_type) {
3293 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3298 switch (value_type.coordinate_type) {
3309 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3315 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") vector dimension outside [2..4]", &
spb);
3321 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") matrix type not supported!", &
spb);
3328 if (check_gl_error(
"gl_context::set_uniform_array_void()", &
spb))
3333bool gl_context::attribute_array_binding_create(attribute_array_binding_base& aab)
const
3336 error(
"gl_context::attribute_array_binding_create() array attribute bindings not supported", &aab);
3342 error(std::string(
"gl_context::attribute_array_binding_create(): ") + gl_error(), &aab);
3346 aab.handle = get_handle(
a_id);
3350bool gl_context::attribute_array_binding_destruct(attribute_array_binding_base& aab)
3354 if (!context::attribute_array_binding_destruct(aab))
3357 error(
"gl_context::attribute_array_binding_destruct(): called on not created attribute array binding", &aab);
3362 return !check_gl_error(
"gl_context::attribute_array_binding_destruct");
3365bool gl_context::attribute_array_binding_enable(attribute_array_binding_base& aab)
3367 if (!context::attribute_array_binding_enable(aab))
3370 return !check_gl_error(
"gl_context::attribute_array_binding_enable");
3373bool gl_context::attribute_array_binding_disable(attribute_array_binding_base& aab)
3375 if (!context::attribute_array_binding_disable(aab))
3384bool gl_context::set_element_array(attribute_array_binding_base* aab,
const vertex_buffer_base*
vbb)
const
3387 error(
"gl_context::set_element_array(): called without a vertex buffer object", aab);
3391 error(
"gl_context::set_element_array(): called with not created vertex buffer object",
vbb);
3395 std::cout <<
"gl_context::set_element_array() : called on vertex buffer object that is not of type VBT_INDICES" << std::endl;
3401 error(
"gl_context::set_element_array(): called on not created attribute array binding", aab);
3416 return !check_gl_error(
"gl_context::set_element_array_void()", aab);
3420bool gl_context::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,
unsigned stride)
const
3422 if (value_type == ET_MATRIX) {
3423 error(
"gl_context::set_attribute_array_void(): called with matrix elements not supported", aab);
3428 error(
"gl_context::set_attribute_array_void(): called with not created vertex buffer object",
vbb);
3434 error(
"gl_context::set_attribute_array_void(): called on not created attribute array binding", aab);
3447 unsigned n = value_type.element_type == ET_VALUE ? 1 : value_type.nr_rows;
3448 switch (value_type.coordinate_type) {
3460 error(
"gl_context::set_attribute_array_void(): called with coordinates of type double only supported starting with OpenGL 4.1", aab);
3465 error(
"gl_context::set_attribute_array_void(): called with unsupported coordinate type", aab);
3479 return res && !check_gl_error(
"gl_context::set_attribute_array_void()", aab);
3482bool gl_context::enable_attribute_array(attribute_array_binding_base* aab,
int loc,
bool do_enable)
const
3487 error(
"gl_context::enable_attribute_array(): called on not created attribute array binding", aab);
3502 return !check_gl_error(
"gl_context::enable_attribute_array()");
3505bool gl_context::is_attribute_array_enabled(
const attribute_array_binding_base* aab,
int loc)
const
3510 error(
"gl_context::is_attribute_array_enabled(): called on not created attribute array binding", aab);
3559 if (
_idx ==
unsigned(-1))
3563 return !check_gl_error(
"gl_context::vertex_buffer_bind", &
vbb);
3567 if(
_idx ==
unsigned(-1))
3571 return !check_gl_error(
"gl_context::vertex_buffer_unbind", &
vbb);
3574bool gl_context::vertex_buffer_create(vertex_buffer_base&
vbb,
const void*
array_ptr,
size_t size_in_bytes)
const
3577 error(
"gl_context::vertex_buffer_create() vertex buffer objects not supported", &
vbb);
3583 error(std::string(
"gl_context::vertex_buffer_create(): ") + gl_error(), &
vbb);
3586 vbb.handle = get_handle(
b_id);
3590 return !check_gl_error(
"gl_context::vertex_buffer_create", &
vbb);
3593bool gl_context::vertex_buffer_resize(vertex_buffer_base&
vbb,
const void*
array_ptr,
size_t size_in_bytes)
const {
3595 error(
"gl_context::vertex_buffer_resize() vertex buffer object must be created before", &
vbb);
3602 return !check_gl_error(
"gl_context::vertex_buffer_resize", &
vbb);
3605bool gl_context::vertex_buffer_replace(vertex_buffer_base&
vbb,
size_t offset,
size_t size_in_bytes,
const void*
array_ptr)
const
3608 error(
"gl_context::vertex_buffer_replace() vertex buffer object must be created before", &
vbb);
3615 return !check_gl_error(
"gl_context::vertex_buffer_replace", &
vbb);
3618bool gl_context::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
3620 if (!
src.handle || !target.handle) {
3621 error(
"gl_context::vertex_buffer_copy() source and destination vertex buffer objects must have been created before", &
src);
3630 return !check_gl_error(
"gl_context::vertex_buffer_copy", &
src);
3634bool gl_context::vertex_buffer_copy_back(vertex_buffer_base&
vbb,
size_t offset,
size_t size_in_bytes,
void*
array_ptr)
const
3637 error(
"gl_context::vertex_buffer_copy_back() vertex buffer object must be created", &
vbb);
3644 return !check_gl_error(
"gl_context::vertex_buffer_copy_back", &
vbb);
3647bool gl_context::vertex_buffer_destruct(vertex_buffer_base&
vbb)
const
3652 return !check_gl_error(
"gl_context::vertex_buffer_destruct");
3655 error(
"gl_context::vertex_buffer_destruct(): called on not created vertex buffer", &
vbb);
virtual void stream_stats(std::ostream &)
overload to show the content of this object
The group class is a node with children.
complete implementation of method actions that only call one method when entering a node
interface of a handler for traverse callbacks
class used to traverse a tree structure
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...
The const_data_view has the functionality of the data_view but uses a const pointer and therefore doe...
void manage_format(bool enable=true)
whether to manage the data format pointer
const data_format * get_format() const
return the component format
cgv::type::func::transfer_const< P, S * >::type get_ptr() const
return a data pointer to type S
the data view gives access to a data array of one, two, three or four dimensions.
~data_view()
destruct view and delete data pointer if it is owned by the view
void reflect_horizontally()
reflect 2D data view at horizontal axis
unsigned int get_component_alignment() const
return the component alignment in bits in the packed case and in bytes in the unpacked case
bool empty() const
check if pointer is not yet set
virtual void stream_help(std::ostream &os)=0
overload to stream help information to the given output stream
matrix of fixed size dimensions
A matrix type (full column major storage) The matrix can be loaded directly into OpenGL without need ...
the attribute_array_binding allows to define vertex attributes (i.e.
bool enable(context &ctx)
enable whole the attribute array binding object
static bool enable_global_array(const context &ctx, int loc)
enable attribute array of given location
bool create(const context &ctx)
create the attribute array binding object
bool disable(context &ctx)
disable whole attribute array binding object
static bool disable_global_array(const context &ctx, int loc)
disable attribute array of given location
bool enable_array(const context &ctx, int loc)
enable array for vertex attribute at location loc
bool disable_array(const context &ctx, int loc)
disable array for attribute at location loc
bool set_attribute_array(const context &ctx, int loc, const T &array)
set vertex attribute location to given array and enable array
virtual void set_blend_func(BlendFunction src_factor, BlendFunction dst_factor)
set the blend function
virtual std::ostream & output_stream()
returns an output stream whose output is printed at the current cursor location, which is managed by ...
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
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
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
shader_program_base * get_current_program() const
check for current program, prepare it for rendering and return pointer to it
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
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
float current_font_size
store current font size
bool enable_vsync
whether vsync should be enabled
virtual void set_buffer_mask(BufferMask mask)
set the buffer mask for depth and color buffers
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
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
virtual void on_lights_changed()
helper function to send light update events
void push_depth_test_state()
push a copy of the current depth test state onto the stack saved attributes: depth test enablement,...
std::stack< shader_program_base * > shader_program_stack
stack of currently enabled shader programs
bool is_light_source_enabled(void *handle)
check whether light source is enabled
virtual void disable_depth_test()
disable the depth test
int get_bg_stencil() const
return the current stencil value for clearing the background
virtual unsigned int get_width() const =0
return the width of the window
bool disable_light_source(void *handle)
disable a given light source and return whether there existed a light source with given handle
void pop_depth_test_state()
pop the top of the current depth test state from the stack
void tesselate_unit_sphere(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a sphere of radius 1
virtual RenderPassFlags get_render_pass_flags() const
return the current render pass flags
void tesselate_unit_cylinder(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a cylinder of radius 1
virtual void set_bg_color(vec4 rgba)
set a user defined background color
virtual void set_depth_test_state(DepthTestState state)
set the depth test state
size_t get_nr_enabled_light_sources() const
return the number of light sources
virtual unsigned int get_height() const =0
return the height of the window
virtual void disable_blending()
disable blending
BufferMask get_buffer_mask() const
return the current buffer mask
void push_cull_state()
push a copy of the current culling state onto the stack saved attributes: cull face enablement,...
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
std::stack< dmat4 > modelview_matrix_stack
keep two matrix stacks for model view and projection matrices
virtual void pop_window_transformation_array()
restore previous viewport and depth range arrays defining the window transformations
virtual void set_color_mask(bvec4 flags)
set the color buffer mask
virtual void set_material(const cgv::media::illum::surface_material &mat)
set the current material
DepthTestState get_depth_test_state() const
return the current depth test state
bool auto_set_material_in_current_shader_program
whether to automatically set material in current shader program, defaults to true
void set_current_lights(shader_program &prog) const
set the shader program lights to the currently enabled lights
bool enable_light_source(void *handle)
enable a given light source and return whether there existed a light source with given handle
void tesselate_unit_disk(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a circular disk of radius 1
virtual void enable_depth_test()
enable the depth test
bool support_compatibility_mode
whether to support view and lighting management of compatibility mode, defaults to true
void set_current_gamma(shader_program &prog) const
set the shader program gamma values
vec4 get_bg_color() const
return the current color value for clearing the background
void pop_projection_matrix()
see push_P for an explanation
std::stack< attribute_array_binding_base * > attribute_array_binding_stack
stack of currently enabled attribute array binding
BlendState get_blend_state() const
return the current blend state
virtual void set_cull_state(CullingMode culling_mode)
set the culling state
virtual void set_depth_func(CompareFunction func)
set the depth test function
void set_light_source(void *handle, const cgv::media::illum::light_source &light, bool place_now=true)
set light source newly
void push_projection_matrix()
same as push_V but for the projection matrix - a different matrix stack is used.
bool current_material_is_textured
store flag to tell whether current material is textured
virtual void set_projection_matrix(const dmat4 &P)
set the current projection matrix, which transforms from eye to clip space
rgba current_color
current color value
static const unsigned nr_default_light_sources
number of default light sources
cgv::media::illum::light_source default_light_source[nr_default_light_sources]
default light sources
virtual void set_cursor(int x, int y)
flush the output_stream and set a new cursor position given in opengl coordinates with (0,...
virtual void set_bg_stencil(int s)
set a user defined background stencil value
virtual void set_bg_accum_color(vec4 rgba)
set a user defined background color for the accumulation buffer
cgv::media::illum::surface_material default_material
store a default material
float get_bg_depth() const
return the current depth value for clearing the background
virtual void set_textured_material(const textured_material &mat)
set the current material
std::stack< std::vector< window_transformation > > window_transformation_stack
keep stack of window transformations
vec4 get_bg_accum_color() const
return the current color value for clearing the accumulation buffer
const cgv::media::illum::light_source & get_light_source(void *handle) const
read access to light source
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,...
virtual void set_blend_state(BlendState state)
set the complete blend state
bool sRGB_framebuffer
whether to use opengl option to support sRGB framebuffer
virtual RenderPassFlags get_default_render_pass_flags() const
return the default render pass flags
virtual void set_bg_depth(float d)
set a user defined background depth value
virtual void enable_blending()
enable blending
void set_current_material(shader_program &prog) const
set the shader program material to the currently enabled material
void pop_cull_state()
pop the top of the current culling state from the stack
void pop_modelview_matrix()
see push_V for an explanation
void * default_light_source_handles[nr_default_light_sources]
handles of default light sources
void push_modelview_matrix()
push the current viewing matrix onto a matrix stack for viewing matrices.
std::stack< frame_buffer_base * > frame_buffer_stack
stack of currently enabled frame buffers
bool auto_set_view_in_current_shader_program
whether to automatically set viewing matrixes in current shader program, defaults to true
void tesselate_unit_cone(int resolution=25, bool flip_normals=false, bool edges=false)
tesselate a cone of radius 1
CullingMode get_cull_state() const
return the current culling state
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
const cgv::media::illum::surface_material * current_material_ptr
store pointer to current material
virtual void set_modelview_matrix(const dmat4 &MV)
set the current modelview matrix, which transforms from world to eye space
void * get_enabled_light_source_handle(size_t i) const
access to handle of i-th light source
cgv::media::font::font_face_ptr current_font_face
store current font
virtual void set_depth_mask(bool flag)
set the depth buffer mask
bool auto_set_gamma_in_current_shader_program
whether to automatically set gamma in current shader program, defaults to true
virtual void init_frame(context &)
this method is called in one pass over all drawables before the draw method
virtual void resize(unsigned int w, unsigned int h)
callback to announce resizing of the output window
virtual bool init(context &)
this method is called after creation or recreation of the context, return whether all necessary funct...
base interface for framebuffer
implementation of the context API for the OpenGL API excluding methods for font selection,...
media::font::font_face_ptr get_current_font_face() const override
overwrite function to return info font face in case no font is currently selected
void set_depth_func(CompareFunction func) override
set the depth test function
void push_pixel_coords() override
use this to push transformation matrices on the stack such that x and y coordinates correspond to win...
void set_depth_mask(bool flag) override
set the depth buffer mask
RenderAPI get_render_api() const override
return the used rendering API
bool frame_buffer_disable(frame_buffer_base &fbb) override
disable the framebuffer object
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) override
tesselate an arrow from the origin in z-direction
void set_color(const rgba &clr) override
set the current color
void set_buffer_mask(BufferMask mask) override
set the buffer mask for depth and color buffers
float info_font_size
font size to draw textual info
bool frame_buffer_is_complete(const frame_buffer_base &fbb) const override
check for completeness, if not complete, get the reason in last_error
void set_bg_color(vec4 rgba) override
set a user defined background color
void draw_light_source(const cgv::media::illum::light_source &l, float intensity_scale, float light_scale) override
draw a light source with an emissive material
void announce_external_viewport_change(ivec4 &cgv_viewport_storage) override
announce an external viewport change performed with rendering API to the cgv framework providing spac...
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 override
get list of program attributes
void enable_depth_test() override
enable the depth test
void pop_window_transformation_array() override
restore previous viewport and depth range arrays defining the window transformations
shader_program & ref_default_shader_program(bool texture_support=false) override
return a reference to a shader program used to render without illumination
bool prepare_attributes(std::vector< vec3 > &P, std::vector< vec3 > &N, std::vector< vec2 > &T, unsigned nr_vertices, const float *vertices, const float *normals, const float *tex_coords, const int *vertex_indices, const int *normal_indices, const int *tex_coord_indices, bool flip_normals) const
helper function to prepare attribute arrays
gl_context()
construct context and attach signals
cgv::media::font::font_face_ptr get_info_font_face() const
return info font face and ensure that it is created
void set_color_mask(bvec4 flags) override
set the color buffer mask
void recover_from_external_frame_buffer_change(void *cgv_fbo_storage) override
restore cgv frame buffer to the state before the external change
dmat4 get_modelview_matrix() const override
return homogeneous 4x4 viewing matrix, which transforms from world to eye space
void set_material(const cgv::media::illum::surface_material &mat) override
set the current material
void enable_blending() override
enable blending
void set_bg_stencil(int s) override
set a user defined background stencil value
void recover_from_external_viewport_change(const ivec4 &cgv_viewport_storage) override
restore cgv viewport to the state before the external change
void set_modelview_matrix(const dmat4 &V) override
set the current modelview matrix, which transforms from world to eye space
double get_window_z(int x_window, int y_window) const override
read the device z-coordinate from the z-buffer for the given device x- and y-coordinates
dmat4 get_projection_matrix() const override
return homogeneous 4x4 projection matrix, which transforms from eye to clip space
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 override
get list of program uniforms
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=type::info::TI_UINT8, data::ComponentFormat cf=data::CF_RGB, int w=-1, int h=-1) override
implement according to specification in context class
void enable_material(textured_material &mat) override
enable a material with textures
float get_info_font_size() const
return info font size
void set_bg_depth(float d) override
set a user defined background depth value
cgv::media::font::font_face_ptr info_font_face
font used to draw textual info
void clear_background(bool color_flag, bool depth_flag, bool stencil_flag=false, bool accum_flag=false) override
clear the buffer contents of the flagged buffers to the set background colors
shader_program & ref_surface_shader_program(bool texture_support=false) override
return a reference to the default shader program used to render surfaces
void set_depth_range(const dvec2 &depth_range=dvec2(0, 1), int array_index=-1) override
set the current depth range or one of the depth ranges in the window transformation array
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) const override
tesselate with one face strip
void set_blend_state(BlendState state) override
set the complete blend state
bool configure_gl()
ensure that glew is initialized, define lighting mode, viewing pyramid and the rendering mode and ret...
bool release_attributes(const float *normals, const float *tex_coords, const int *normal_indices, const int *tex_coord_indices) const
helper function to disable attribute arrays
float get_current_font_size() const override
overwrite function to return info font size in case no font is currently selected
void set_cull_state(CullingMode culling_mode) override
set the culling state
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 override
pass geometry of given faces to current shader program and generate draw calls to render lines for th...
void set_projection_matrix(const dmat4 &P) override
set the current projection matrix, which transforms from eye to clip space
unsigned get_max_window_transformation_array_size() const override
query the maximum number of supported window transformations, which is at least 1
void set_bg_accum_color(vec4 rgba) override
set a user defined background color for the accumulation buffer
void disable_blending() override
disable blending
void rotate_vector_to_target(const dvec3 &vector, const dvec3 &target)
helper function that multiplies a rotation to modelview matrix such that vector is rotated onto targe...
void set_blend_func(BlendFunction src_factor, BlendFunction dst_factor) override
set the blend function
void set_viewport(const ivec4 &viewport, int array_index=-1) override
set the current viewport or one of the viewports in the window transformation array
void pop_pixel_coords() override
pop previously changed transformation matrices
void disable_material(textured_material &mat) override
disable a material with textures
void on_lights_changed() override
helper function to send light update events
void disable_depth_test() override
disable the depth test
void set_blend_func_separate(BlendFunction src_color_factor, BlendFunction dst_color_factor, BlendFunction src_alpha_factor, BlendFunction dst_alpha_factor) override
set the blend function separately for color and alpha
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) const override
tesselate with independent faces
void set_depth_test_state(DepthTestState state) override
set the depth test state
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 override
pass geometry of given strip or fan to current shader program and generate draw calls to render lines...
void announce_external_frame_buffer_change(void *&cgv_fbo_storage) override
announce an external frame buffer change performed with rendering API to the cgv framework providing ...
base interface for all render components
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...
base interface for a texture
the texture class encapsulates all functionality independent of the rendering api.
void set_component_format(const component_format &cf)
change component format and clear internal format
class that extends obj_material with the management of textures
a vertex buffer is an unstructured memory block on the GPU.
bool create(const context &ctx, size_t size_in_bytes)
create empty vertex buffer of size size given in bytes
void destruct(const context &ctx)
destruct the render buffer
bool replace(const context &ctx, size_t buffer_offset_in_bytes, const T *array_ptr, size_t nr_elements)
replace part (starting at byte offset buffer_offset_in_bytes) or whole vertex buffer content from nr_...
the base namespace holds the base hierarchy, support for plugin registration and signals
data::ref_ptr< group, true > group_ptr
ref counted pointer to a node
ComponentFormat
define standard formats, which should be used to avoid wrong assignment of component names
@ CF_RGB
color format with two components R and G
@ CF_D
color format with components B, G, R and A
unsigned find_best_match(const component_format &fmt, const char **format_descriptions, const component_format *fmt0, bool(*fmt1_better_match)(const component_format &fmt, const component_format &fmt1, const component_format &fmt2))
find the best matching format in a list of formats described by strings and return index of best matc...
namespace that holds the abstract gui interface
void message(const std::string &_message)
tell the user something with a message box
bool load_texture(const cgv::data::const_data_view &data, unsigned gl_tex_format, unsigned level, unsigned cube_side, int num_array_layers, const std::vector< data_view > *palettes)
load data to a texture with the glTexImage commands and generate mipmaps if the level parameter is -1...
void gl_set_material(const cgv::media::illum::phong_material &mat, MaterialSide ms, float alpha)
enable a material without textures
bool replace_texture(const cgv::data::const_data_view &data, int level, int x, int y, int z, const std::vector< cgv::data::data_view > *palettes)
replace part or complete data of currently bound texture with the data in the given data view
bool ensure_glew_initialized()
initialize glew in the first call to this function and always return whether this was successful
void set_gl_format(texture &tex, GLuint gl_format, const std::string &component_format_description)
set a very specific texture format. This should be called after the texture is constructed and before...
bool generate_mipmaps(unsigned int dim, bool is_cubemap, bool is_array, std::string *last_error)
generate mipmaps for the currently bound texture, which has the given texture dimension; optionally p...
unsigned find_best_texture_format(const cgv::data::component_format &_cf, cgv::data::component_format *best_cf, const std::vector< data_view > *palettes)
map the given component format to the best matching available gl component format
unsigned get_gl_cube_map_target(unsigned side)
return one of the six cube map sides gl enums
std::vector< int > get_context_creation_attrib_list(cgv::render::context_config &cc)
construct a 0 terminated list of context creation attribute definitions
GLuint get_gl_format(const texture &tex)
return the texture format used for a given texture. If called before texture has been created,...
RenderAPI
enumeration of rendering APIs which can be queried from the context
CullingMode
different culling modes
BlendFunction
different blend functions
AccessType
different access types
TextureFilter
different texture filter
TextureWrap
different texture wrap modes
FrameBufferType
different frame buffer types which can be combined together with or
MaterialSide
different sides of a material
VertexBufferUsage
Provides vertex buffer usage hints as defined in OpenGL.
ContextIntegerConstant
integer constants that can be queried from context
ShaderType
different shader types
PrimitiveType
different primitive types
VertexBufferType
Provides vertex buffer types to allow implicit binding.
@ VBT_INDICES
The buffer contains indices and will be bound to GL_ELEMENT_ARRAY_BUFFER.
BufferTypeBits
Bits for the selection of different buffer types.
TextureType
different texture types
RenderPassFlags
available flags that can be queried from the context and set for a new render pass
@ RPF_CLEAR_ACCUM
whether to clear the accumulation buffer
@ RPF_SET_MODELVIEW
whether to set default modelview matrix
@ RPF_SET_MATERIAL
whether to define default material
@ RPF_SET_CLEAR_DEPTH
whether to set the clear color
@ RPF_SET_LIGHTS
whether to define default lights
@ RPF_CLEAR_COLOR
whether to clear the color buffer
@ RPF_CLEAR_STENCIL
whether to clear the depth buffer
@ RPF_SET_CLEAR_STENCIL
whether to set the clear color
@ RPF_ENABLE_MATERIAL
whether to enable material
@ RPF_DRAWABLES_INIT_FRAME
whether to call the init_frame method of the drawables
@ RPF_CLEAR_DEPTH
whether to clear the depth buffer
@ RPF_SET_STATE_FLAGS
whether to set depth buffer and culling flags
@ RPF_SET_PROJECTION
whether to set default projection matrix
@ RPF_SET_CLEAR_ACCUM
whether to set the accumulation buffer clear color
@ RPF_SET_CLEAR_COLOR
whether to set the clear color
@ RPF_SET_LIGHTS_ON
whether to turn on default lights
CompareFunction
different comparison functions used for depth testing or texture comparisons
namespace for templates that provide type information
const char * get_type_name(TypeId tid)
function that returns the name of a type specified through TypeId
TypeId
ids for the different types and type constructs
@ TI_INT16
signed integer stored in 8 bits
@ TI_INT32
signed integer stored in 16 bits
@ TI_FLT32
floating point type stored in 16 bits
@ TI_UINT32
unsigned integer stored in 16 bits
@ TI_UINT8
signed integer stored in 64 bits
@ TI_UINT16
unsigned integer stored in 8 bits
@ TI_FLT64
floating point type stored in 32 bits
namespace for compile time type information
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
char to_upper(char c)
convert char to upper case
bool is_element(char c, const std::string &s)
check if char c arises in string s
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > rgba
declare rgba color type with 32 bit components
cgv::math::fvec< double, 3 > dvec3
declare type of 3d double precision floating point vectors
cgv::math::fvec< uint32_t, 3 > uvec3
declare type of 3d 32 bit unsigned integer vectors
cgv::math::fvec< int32_t, 4 > ivec4
declare type of 4d 32 bit integer vectors
cgv::math::fmat< double, 4, 4 > dmat4
declare type of 4x4 matrices
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Helper functions to process strings.
Represents a blend state used to configure fragment blending.
bool enabled
whether blending is enabled
BlendFunction dst_color
the destination color (rgb) factor
BlendFunction dst_alpha
the destination alpha factor
BlendFunction src_alpha
the source alpha factor
BlendFunction src_color
the source color (rgb) factor
Represents a buffer mask used to mask depth and color buffer outputs.
Represents a depth test state used to configure depth testing.
bool enabled
whether the depth test is enabled
CompareFunction test_func
the function used to compare depth values
configuration object used to define context parameters that need to be set already at creation time
int version_minor
default: -1 ... minor version of maximum supported OpenGL version
int version_major
default: -1 ... major version of maximum supported OpenGL version
bool debug
default: false in release and true in debug version
bool forward_compatible
default: false
bool core_profile
default: true
bool depth_buffer
default: true
compact type description of data that can be sent to the context; convertible to int