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;
478 for(
unsigned i = 0;
i < 3; ++
i)
480 for(
unsigned i = 0;
i < 3; ++
i)
498 if (!check_gl_error(
"gl_context::configure() debug output"))
518 for (
unsigned i = 0;
i<
grp->get_nr_children(); ++
i)
527void gl_context::resize_gl()
587void gl_context::init_render_pass()
639 if (check_gl_error(
"gl_context::init_render_pass before init_frame"))
648 if (check_gl_error(
"gl_context::init_render_pass after init_frame"))
671void gl_context::finish_render_pass()
696void gl_context::draw_textual_info()
698 if (show_help || show_stats) {
710 if (
bg[0] +
bg[1] +
bg[2] < 1.5f)
718 if (
grp && show_stats) {
724 if(
bg[0] +
bg[1] +
bg[2] < 1.5f)
729 if (
grp && show_help) {
740void gl_context::perform_screen_shot()
746 std::string
ext(
"bmp");
762 for (
int i = 0;
i < count; ++
i) {
778 std::cout <<
i <<
" at " <<
loc <<
" = " <<
name_str <<
":" << type <<
"[" << size <<
"]" << std::endl;
787 for (
int i = 0;
i < count; ++
i) {
803 std::cout <<
i <<
" at " <<
loc <<
" = " <<
name_str <<
":" << type <<
"[" << size <<
"]" << std::endl;
817 if (!prog.does_context_set_color())
819 int clr_loc = prog.get_color_index();
829 unsigned side = map_to_gl(MS_FRONT_AND_BACK);
830 float alpha = 1.0f - material.get_transparency();
831 gl_set_material_color(
side, material.get_ambient_occlusion()*material.get_diffuse_reflectance(), alpha,
GL_AMBIENT);
832 gl_set_material_color(
side, material.get_diffuse_reflectance(), alpha,
GL_DIFFUSE);
833 gl_set_material_color(
side, material.get_specular_reflectance(), alpha,
GL_SPECULAR);
834 gl_set_material_color(
side, material.get_emission(), alpha,
GL_EMISSION);
844 mat.enable_textures(*
this);
850 mat.disable_textures(*
this);
855void gl_context::destruct_render_objects()
857 for (
unsigned i = 0;
i < 4; ++
i)
858 progs[
i].destruct(*
this);
866 if (!progs[0].build_program(*
this,
"default.glpr")) {
867 error(
"could not build default shader program from default.glpr");
870 progs[0].specify_standard_uniforms(
true,
false,
false,
true);
871 progs[0].specify_standard_vertex_attribute_names(*
this,
true,
false,
false);
872 progs[0].allow_context_to_set_color(
true);
877 if (!progs[1].build_program(*
this,
"textured_default.glpr")) {
878 error(
"could not build default shader program with texture support from textured_default.glpr");
882 progs[1].specify_standard_uniforms(
true,
false,
false,
true);
883 progs[1].specify_standard_vertex_attribute_names(*
this,
true,
false,
true);
884 progs[1].allow_context_to_set_color(
true);
894 if (!progs[2].build_program(*
this,
"default_surface.glpr")) {
895 error(
"could not build surface shader program from default_surface.glpr");
898 progs[2].specify_standard_uniforms(
true,
true,
true,
true);
899 progs[2].specify_standard_vertex_attribute_names(*
this,
true,
true,
false);
900 progs[2].allow_context_to_set_color(
true);
905 if (!progs[3].build_program(*
this,
"textured_surface.glpr")) {
906 error(
"could not build surface shader program with texture support from textured_surface.glpr");
909 progs[3].specify_standard_uniforms(
true,
true,
true,
true);
910 progs[3].specify_standard_vertex_attribute_names(*
this,
true,
true,
true);
911 progs[3].allow_context_to_set_color(
true);
935 GLfloat pos[4] = { 0,0,0,
light.get_type() == cgv::media::illum::LT_DIRECTIONAL ? 0.0f : 1.0f };
938 if (
light.get_type() != cgv::media::illum::LT_DIRECTIONAL) {
948 if (
light.get_type() == cgv::media::illum::LT_SPOT) {
956 static float dir[3] = { 0,0,1 };
997 compute_rotation_axis_and_angle_from_vector_pair(vector, target, axis, angle);
1004 if ((start - end).length() < 1
e-8) {
1005 error(
"ignored tesselate arrow called with start and end closer then 1e-8");
1019 switch (
l.get_type()) {
1020 case LT_DIRECTIONAL :
1026 cgv::math::translate4<double>(
l.get_position())*
1032 cgv::math::translate4<double>(
l.get_position())*
1037 float t =
tan(
l.get_spot_cutoff()*(
float)M_PI/180);
1038 if (
l.get_spot_cutoff() > 45.0f)
1055 error(
"gl_context::announce_external_frame_buffer_change() called with empty frame buffer stack");
1075 error(
"gl_context::announce_external_viewport_change() called with empty window transformation stack");
1106 glOrtho(vp[0], vp[0]+vp[2], vp[1], vp[1]+vp[3], -1, 1);
1134 if (w < 1 || h < 1) {
1140 if (w < 1 || h < 1) {
1143 w = w < 1 ? vp[2] : w;
1144 h = h < 1 ? vp[3] : h;
1200void render_vertex(
int k,
const float* vertices,
const float* normals,
const float* tex_coords,
1201 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
bool flip_normals)
1203 if (normals && normal_indices) {
1205 float n[3] = { -normals[3*normal_indices[k]],-normals[3*normal_indices[k]+1],-normals[3*normal_indices[k]+2] };
1211 if (tex_coords && tex_coord_indices)
1216attribute_array_binding*& get_aab_ptr()
1218 static attribute_array_binding* aab_ptr = 0;
1222vertex_buffer*& get_vbo_ptr()
1224 static vertex_buffer* vbo_ptr = 0;
1231 if (!prog_ptr || prog_ptr->get_position_index() == -1)
1237 if (prog_ptr->get_normal_index() != -1 && normals && normal_indices)
1239 if (prog_ptr->get_texcoord_index() != -1 && tex_coords && tex_coord_indices)
1244 aab_ptr->
disable_array(*
this, prog_ptr->get_position_index());
1245 if (prog_ptr->get_normal_index() != -1 && normals && normal_indices)
1247 if (prog_ptr->get_texcoord_index() != -1 && tex_coords && tex_coord_indices)
1258 const float* vertices,
const float* normals,
const float* tex_coords,
1259 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
bool flip_normals)
const
1263 if (!prog_ptr || prog_ptr->get_position_index() == -1)
1265 P.resize(nr_vertices);
1266 for (
i = 0;
i < nr_vertices; ++
i)
1267 P[
i] = *
reinterpret_cast<const vec3*
>(vertices + 3 * vertex_indices[
i]);
1269 if (prog_ptr->get_normal_index() != -1 && normals && normal_indices) {
1270 N.resize(nr_vertices);
1271 for (
i = 0;
i < nr_vertices; ++
i) {
1272 N[
i] = *
reinterpret_cast<const vec3*
>(normals + 3 * normal_indices[
i]);
1277 if (prog_ptr->get_texcoord_index() != -1 && tex_coords && tex_coord_indices) {
1278 T.resize(nr_vertices);
1279 for (
i = 0;
i < nr_vertices; ++
i)
1280 T[
i] = *
reinterpret_cast<const vec2*
>(tex_coords + 2 * tex_coord_indices[
i]);
1289 attribute_array_binding::set_global_attribute_array<>(*
this, prog_ptr->get_position_index(),
P);
1291 if (prog_ptr->get_normal_index() != -1) {
1292 if (normals && normal_indices) {
1293 attribute_array_binding::set_global_attribute_array<>(*
this, prog_ptr->get_normal_index(), N);
1299 if (prog_ptr->get_texcoord_index() != -1) {
1300 if (tex_coords && tex_coord_indices) {
1301 attribute_array_binding::set_global_attribute_array<>(*
this, prog_ptr->get_texcoord_index(),
T);
1314 vbo_ptr->
create(*
this,
P.size() *
sizeof(
vec3) + N.size() *
sizeof(
vec3) +
T.size() *
sizeof(
vec2));
1327 aab_ptr->
enable_array(*
this, prog_ptr->get_position_index());
1328 if (prog_ptr->get_normal_index() != -1) {
1329 if (normals && normal_indices) {
1331 aab_ptr->
enable_array(*
this, prog_ptr->get_normal_index());
1334 aab_ptr->
disable_array(*
this, prog_ptr->get_normal_index());
1336 if (prog_ptr->get_texcoord_index() != -1) {
1337 if (tex_coords && tex_coord_indices) {
1340 aab_ptr->
enable_array(*
this, prog_ptr->get_texcoord_index());
1343 aab_ptr->
disable_array(*
this, prog_ptr->get_texcoord_index());
1352 const float* vertices,
const float* normals,
const float* tex_coords,
1353 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
1354 int nr_faces,
int face_degree,
bool flip_normals)
const
1358 for (
int i = 0;
i < nr_faces; ++
i) {
1360 for (
int j = 0;
j < face_degree; ++
j, ++k)
1361 render_vertex(k, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1366 unsigned nr_vertices = face_degree * nr_faces;
1367 std::vector<vec3>
P, N;
1368 std::vector<vec2>
T;
1369 if (!
prepare_attributes(
P, N,
T, nr_vertices, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals))
1371 for (
int i = 0;
i < nr_faces; ++
i)
1379 ensure_configured();
1384 if (count > max_nr_indices)
1385 count =
size_t(max_nr_indices);
1391size_t max_nr_indices, max_nr_vertices;
1392void gl_context::ensure_configured()
const
1394 if (max_nr_indices != 0)
1402 const float* vertices,
const float* normals,
const float* tex_coords,
1403 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
1406 int s = face_degree - 2;
1408 std::vector<GLuint>
I;
1409 I.push_back(0);
I.push_back(1);
1410 for (
i = 0;
i < nr_faces; ++
i) {
1412 I.push_back(k - 1);
I.push_back(k);
1413 I.push_back(0);
I.push_back(k);
1417 I.push_back(k - 1);
I.push_back(k);
1418 I.push_back(k - 2);
I.push_back(k);
1421 I.push_back(k - 1);
I.push_back(k + 1);
1422 I.push_back(k - 2);
I.push_back(k);
1423 I.push_back(k);
I.push_back(k + 1);
1431 render_vertex(
j, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1435 unsigned nr_vertices = 2 + (face_degree - 2) * nr_faces;
1436 std::vector<vec3>
P, N;
1437 std::vector<vec2>
T;
1438 if (!
prepare_attributes(
P, N,
T, nr_vertices, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals))
1445 const float* vertices,
const float* normals,
const float* tex_coords,
1446 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
1447 int nr_faces,
int face_degree,
bool flip_normals)
const
1451 if (face_degree < 5)
1453 for (
int i = 0;
i < nr_faces; ++
i) {
1454 if (face_degree >= 5)
1456 for (
int j = 0;
j < face_degree; ++
j, ++k)
1457 render_vertex(k, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1458 if (face_degree >= 5)
1461 if (face_degree < 5)
1465 unsigned nr_vertices = face_degree * nr_faces;
1466 std::vector<vec3>
P, N;
1467 std::vector<vec2>
T;
1468 if (!
prepare_attributes(
P, N,
T, nr_vertices, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals))
1480 if (face_degree == 3)
1483 for (
int i = 0;
i < nr_faces; ++
i) {
1491 const float* vertices,
const float* normals,
const float* tex_coords,
1492 const int* vertex_indices,
const int* normal_indices,
const int* tex_coord_indices,
1495 int s = face_degree - 2;
1499 render_vertex(0, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1500 render_vertex(1, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1501 for (
int i = 0;
i < nr_faces; ++
i)
1502 for (
int j = 0;
j < s; ++
j, ++k)
1503 render_vertex(k, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals);
1507 unsigned nr_vertices = 2 + (face_degree-2) * nr_faces;
1508 std::vector<vec3>
P, N;
1509 std::vector<vec2>
T;
1510 if (!
prepare_attributes(
P, N,
T, nr_vertices, vertices, normals, tex_coords, vertex_indices, normal_indices, tex_coord_indices,
flip_normals))
1541 switch(culling_mode) {
1605 map_to_gl(
mask.red_flag),
1606 map_to_gl(
mask.green_flag),
1607 map_to_gl(
mask.blue_flag),
1608 map_to_gl(
mask.alpha_flag)
1620 map_to_gl(flags[0]),
1621 map_to_gl(flags[1]),
1622 map_to_gl(flags[2]),
1649 if (projection_matrix_stack.empty())
1651 return projection_matrix_stack.top();
1657 update_window_transformation_array();
1660void gl_context::update_window_transformation_array()
1663 if (
wta.size() == 1) {
1664 const ivec4& viewport =
wta.front().viewport;
1665 const dvec2& depth_range =
wta.front().depth_range;
1683 GLint max_value = 1;
1695 update_window_transformation_array();
1714 update_window_transformation_array();
1724gl_context::dmat4 gl_context::get_device_matrix() const
1727 glGetIntegerv(GL_VIEWPORT, vp);
1729 D(0, 0) = 0.5*vp[2];
1730 D(0, 3) = 0.5*vp[2] + vp[0];
1731 D(1, 1) = -0.5*vp[3]; // flip y-coordinate
1732 D(1, 3) = get_height() - 0.5*vp[3] - vp[1];
1802std::string gl_error_to_string(
GLenum eid) {
1813 return "undefined error (id: " + std::to_string(
eid) +
")";
1818std::string gl_error() {
1820 return gl_error_to_string(
eid);
1860 error(
where+
": compute shader need not supported OpenGL version 4.3",
rc);
1863 case ST_TESS_CONTROL:
1864 case ST_TESS_EVALUATION:
1868 error(
where+
": tessellation shader need not supported OpenGL version 4.0",
rc);
1875 error(
where +
": geometry shader need not supported OpenGL version 3.2",
rc);
1882 error(
where +
": shaders need not supported OpenGL version 2.0",
rc);
1891 error(
where +
": framebuffer objects not supported",
rc);
1897GLuint gl_context::texture_generate(texture_base&
tb)
const
1899 if (!check_texture_support(
tb.tt,
"gl_context::texture_generate", &
tb))
1900 return get_gl_id(0);
1901 GLuint tex_id = get_gl_id(0);
1904 error(
"gl_context::texture_generate: attempt to create texture inside glBegin-glEnd-block", &
tb);
1925 if (
tb.tt == TT_UNDEF)
1927 GLuint tex_id = texture_generate(
tb);
1928 if (tex_id == get_gl_id(0))
1933 unsigned int transfer_format = map_to_gl(df.get_standard_component_format(), df.get_integer_interpretation());
1935 error(
"could not determine transfer format", &
tb);
1950 case TT_MULTISAMPLE_2D:
1956 case TT_MULTISAMPLE_2D_ARRAY:
1979 if (check_gl_error(
"gl_context::texture_create", &
tb)) {
1986 tb.have_mipmaps =
false;
1987 tb.handle = get_handle(tex_id);
1991bool gl_context::texture_create(
2001 tb.tt = (
TextureType)data.get_format()->get_nr_dimensions();
2008 unsigned n_dims = data.get_format()->get_nr_dimensions();
2010 tb.tt = TT_1D_ARRAY;
2012 tb.tt = TT_2D_ARRAY;
2015 case TT_1D:
tb.tt = TT_1D_ARRAY;
break;
2016 case TT_2D:
tb.tt = TT_2D_ARRAY;
break;
2017 case TT_3D:
tb.tt = TT_2D_ARRAY;
break;
2025 if (
tb.is_created())
2026 tex_id = get_gl_id(
tb.handle);
2028 tex_id = texture_generate(
tb);
2029 if (tex_id == get_gl_id(0))
2031 tb.handle = get_handle(tex_id);
2039 bool result = !check_gl_error(
"gl_context::texture_create", &
tb);
2045bool gl_context::texture_create_from_buffer(
2048 int x,
int y,
int level)
const
2053 if (
tb.tt != TT_2D) {
2054 tb.last_error =
"texture creation from buffer only possible for 2d textures";
2058 if (
tb.is_created())
2059 tex_id = get_gl_id(
tb.handle);
2061 tex_id = texture_generate(
tb);
2062 if (tex_id == get_gl_id(0))
2064 tb.handle = get_handle(tex_id);
2074 bool result =
false;
2075 std::string
error_string(
"gl_context::texture_create_from_buffer: ");
2084 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"
2085 "or border was not zero or 1.\n"
2086 "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.";
2089 error_string +=
"glCopyTexImage2D was called between a call to glBegin and the corresponding call to glEnd.";
2100 result = texture_generate_mipmaps(
tb,
tb.tt == TT_CUBEMAP ? 2 : (
int)
tb.tt);
2105bool gl_context::texture_replace(
2107 int x,
int y,
int z,
2109 int level,
const std::vector<cgv::data::data_view>*
palettes)
const
2111 if (!
tb.is_created()) {
2112 error(
"gl_context::texture_replace: attempt to replace in not created texture", &
tb);
2116 unsigned int dim = 1;
2123 if (
tb.tt == TT_CUBEMAP) {
2125 error(
"gl_context::texture_replace: replace on cubemap without the side defined", &
tb);
2129 error(
"gl_context::texture_replace: replace on cubemap with invalid side specification", &
tb);
2135 error(
"gl_context::texture_replace: replace on texture with invalid position specification", &
tb);
2143 bool result = !check_gl_error(
"gl_context::texture_replace", &
tb);
2148bool gl_context::texture_replace_from_buffer(
2150 int x,
int y,
int z,
2152 unsigned int width,
unsigned int height,
2155 if (!
tb.is_created()) {
2156 error(
"gl_context::texture_replace_from_buffer: attempt to replace in not created texture", &
tb);
2160 unsigned int dim = 2;
2165 if (
tb.tt == TT_CUBEMAP) {
2167 error(
"gl_context::texture_replace_from_buffer: replace on cubemap without the side defined", &
tb);
2171 error(
"gl_context::texture_replace_from_buffer: replace on cubemap without invalid side specification", &
tb);
2177 tb.last_error =
"replace on texture with invalid position specification";
2194 bool result = !check_gl_error(
"gl_context::texture_replace_from_buffer", &
tb);
2198 result = texture_generate_mipmaps(
tb,
tb.tt == TT_CUBEMAP ? 2 : (
int)
tb.tt);
2208 unsigned int transfer_format = map_to_gl(df.get_standard_component_format(), df.get_integer_interpretation());
2211 error(
"could not determine transfer format", &
tb);
2216 uvec3 size(
unsigned(df.get_width()),
unsigned(df.get_height()),
unsigned(df.get_depth()));
2218 unsigned max_size = cgv::math::max_value(size);
2225 for(
unsigned level = 1; level <
num_levels; ++level) {
2238 for(
unsigned level = 1; level <
num_levels; ++level) {
2245 error(
"create mipmaps not implemented for 1D array textures", &
tb);
2249 for(
unsigned level = 1; level <
num_levels; ++level) {
2254 case TT_MULTISAMPLE_2D:
2256 error(
"create mipmaps not implemented for 2D multisample textures", &
tb);
2261 error(
"create mipmaps not implemented for 2D array textures", &
tb);
2264 case TT_MULTISAMPLE_2D_ARRAY:
2266 error(
"create mipmaps not implemented for 2D multisample array textures", &
tb);
2270 for(
unsigned level = 1; level <
num_levels; ++level) {
2289 error(
"create mipmaps not implemented for cubemap textures", &
tb);
2295 if(check_gl_error(
"gl_context::texture_create_mipmaps", &
tb))
2299 tb.have_mipmaps =
true;
2305bool gl_context::texture_generate_mipmaps(texture_base&
tb,
unsigned int dim)
const
2309 bool is_array =
tb.tt == TT_1D_ARRAY ||
tb.tt == TT_2D_ARRAY;
2314 tb.have_mipmaps =
true;
2322bool gl_context::texture_destruct(texture_base&
tb)
const
2324 if (!
tb.is_created()) {
2325 error(
"gl_context::texture_destruct: attempt to destruct not created texture", &
tb);
2328 GLuint tex_id = get_gl_id(
tb.handle);
2330 bool result = !check_gl_error(
"gl_context::texture_destruct", &
tb);
2335bool gl_context::texture_set_state(
const texture_base&
tb)
const
2337 if (
tb.tt == TT_UNDEF) {
2338 error(
"gl_context::texture_set_state: attempt to set state on texture without type", &
tb);
2343 error(
"gl_context::texture_set_state: attempt of setting texture state of not created texture", &
tb);
2348 if (
tb.tt != TT_MULTISAMPLE_2D &&
tb.tt != TT_MULTISAMPLE_2D_ARRAY) {
2351 if (
tb.min_filter == TF_ANISOTROP)
2368 bool result = !check_gl_error(
"gl_context::texture_set_state", &
tb);
2373bool gl_context::texture_enable(texture_base&
tb,
int tex_unit,
unsigned int dim)
const
2376 error(
"gl_context::texture_enable: invalid texture dimension", &
tb);
2381 error(
"gl_context::texture_enable: texture not created", &
tb);
2384 if (tex_unit >= 0) {
2386 error(
"gl_context::texture_enable: multi texturing not supported", &
tb);
2398 bool result = !check_gl_error(
"gl_context::texture_enable", &
tb);
2404bool gl_context::texture_disable(
2406 int tex_unit,
unsigned int dim)
const
2409 error(
"gl_context::texture_disable: invalid texture dimension", &
tb);
2412 if (tex_unit == -2) {
2413 error(
"gl_context::texture_disable: invalid texture unit", &
tb);
2423 bool result = !check_gl_error(
"gl_context::texture_disable", &
tb);
2434 error(
"gl_context::texture_enable: texture not created", &
tb);
2439 error(
"gl_context::texture_bind_as_image: image textures not supported", &
tb);
2446 bool result = !check_gl_error(
"gl_context::texture_bind_as_image", &
tb);
2453 error(
"gl_context::render_buffer_create: frame buffer objects not supported", &
rb);
2477 if (
rb.nr_multi_samples == 0)
2482 if (check_gl_error(
"gl_context::render_buffer_create", &
rb))
2484 rb.handle = get_handle(
rb_id);
2488bool gl_context::render_buffer_destruct(render_buffer_base&
rc)
const
2491 error(
"gl_context::render_buffer_destruct: frame buffer objects not supported", &
rc);
2496 if (check_gl_error(
"gl_context::render_buffer_destruct", &
rc))
2502bool gl_context::frame_buffer_create(frame_buffer_base&
fbb)
const
2504 if (!check_fbo_support(
"gl_context::frame_buffer_create", &
fbb))
2507 if (!context::frame_buffer_create(
fbb))
2514 error(
"gl_context::frame_buffer_create: could not allocate framebuffer object", &
fbb);
2517 fbb.handle = get_handle(fbo_id);
2521bool gl_context::frame_buffer_enable(frame_buffer_base&
fbb)
2523 if (!context::frame_buffer_enable(
fbb))
2525 std::vector<int> buffers;
2530 if (buffers.size() == 1)
2532 else if (buffers.size() > 1) {
2539 error(
"gl_context::frame_buffer_enable: no attached draw buffer selected!!", &
fbb);
2548 if (!context::frame_buffer_disable(
fbb))
2551 error(
"gl_context::frame_buffer_disable called with empty frame buffer stack!!", &
fbb);
2561 if (!context::frame_buffer_destruct(
fbb))
2569void complete_rect_from_vp(
ivec4& D,
GLint vp[4])
2576 D(2) = vp[0] + vp[2];
2578 D(3) = vp[1] + vp[3];
2581void gl_context::frame_buffer_blit(
2597 if ((
src_fbb_ptr == 0 && (S(0) == -1 || S(1) == -1 || S(2) == -1 || S(3) == -1)) ||
2598 (
dst_fbb_ptr == 0 && (D(0) == -1 || D(1) == -1 || D(2) == -1 || D(3) == -1))) {
2602 complete_rect_from_vp(S, vp);
2604 complete_rect_from_vp(D, vp);
2622bool gl_context::frame_buffer_attach(frame_buffer_base&
fbb,
const render_buffer_base&
rb,
bool is_depth,
int i)
const
2632 get_gl_id(
rb.handle));
2654 if (t.tt == TT_CUBEMAP) {
2665 bool result = !check_gl_error(
"gl_context::frame_buffer_attach", &
fbb);
2673 if (
fbb.handle == 0) {
2674 error(
"gl_context::frame_buffer_is_complete: attempt to check completeness on frame buffer that is not created", &
fbb);
2686 fbb.last_error =
"undefined framebuffer";
2689 fbb.last_error =
"incomplete attachment";
2692 fbb.last_error =
"incomplete or missing attachment";
2695 fbb.last_error =
"incomplete multisample";
2698 fbb.last_error =
"incomplete layer targets";
2701 fbb.last_error =
"incomplete draw buffer";
2704 fbb.last_error =
"incomplete read buffer";
2707 fbb.last_error =
"framebuffer objects unsupported";
2710 fbb.last_error =
"unknown error";
2714int gl_context::frame_buffer_get_max_nr_color_attachments()
const
2716 if (!check_fbo_support(
"gl_context::frame_buffer_get_max_nr_color_attachments"))
2724int gl_context::frame_buffer_get_max_nr_draw_buffers()
const
2726 if (!check_fbo_support(
"gl_context::frame_buffer_get_max_nr_draw_buffers"))
2739void gl_context::shader_code_destruct(render_component&
sc)
const
2741 if (
sc.handle == 0) {
2742 error(
"gl_context::shader_code_destruct: shader not created", &
sc);
2746 check_gl_error(
"gl_context::shader_code_destruct", &
sc);
2749bool gl_context::shader_code_create(render_component&
sc,
ShaderType st,
const std::string& source)
const
2751 if (!check_shader_support(st,
"gl_context::shader_code_create", &
sc))
2756 error(std::string(
"gl_context::shader_code_create: ")+gl_error(), &
sc);
2759 sc.handle = get_handle(
s_id);
2761 const char* s = source.c_str();
2763 if (check_gl_error(
"gl_context::shader_code_create", &
sc))
2769bool gl_context::shader_code_compile(render_component&
sc)
const
2771 if (
sc.handle == 0) {
2772 error(
"gl_context::shader_code_compile: shader not created", &
sc);
2781 sc.last_error = std::string();
2794bool gl_context::shader_program_create(shader_program_base&
spb)
const
2796 if (!check_shader_support(ST_VERTEX,
"gl_context::shader_program_create", &
spb))
2802void gl_context::shader_program_attach(shader_program_base&
spb,
const render_component&
sc)
const
2804 if (
spb.handle == 0) {
2805 error(
"gl_context::shader_program_attach: shader program not created", &
spb);
2811void gl_context::shader_program_detach(shader_program_base&
spb,
const render_component&
sc)
const
2813 if (
spb.handle == 0) {
2814 error(
"gl_context::shader_program_detach: shader program not created", &
spb);
2820bool gl_context::shader_program_link(shader_program_base&
spb)
const
2822 if (
spb.handle == 0) {
2823 error(
"gl_context::shader_program_link: shader program not created", &
spb);
2831 return context::shader_program_link(
spb);
2839 error(std::string(
"gl_context::shader_program_link\n")+
infoLog, &
spb);
2845bool gl_context::shader_program_set_state(shader_program_base&
spb)
const
2847 if (
spb.handle == 0) {
2848 error(
"gl_context::shader_program_set_state: shader program not created", &
spb);
2858bool gl_context::shader_program_enable(shader_program_base&
spb)
2860 if (!context::shader_program_enable(
spb))
2863 shader_program& prog =
static_cast<shader_program&
>(
spb);
2872 if (prog.does_context_set_color() && prog.get_color_index() >= 0)
2873 prog.set_attribute(*
this, prog.get_color_index(),
current_color);
2877bool gl_context::shader_program_disable(shader_program_base&
spb)
2879 if (!context::shader_program_disable(
spb))
2888bool gl_context::shader_program_destruct(shader_program_base&
spb)
const
2890 if (!context::shader_program_destruct(
spb))
2896bool gl_context::shader_program_get_active_uniforms(shader_program_base&
spb, std::vector<std::string>&
names)
const
2898 if (
spb.handle == 0)
2908 std::vector<GLchar> buffer(256);
2915 std::string name(
static_cast<char*
>(buffer.data()),
actual_length);
2926 names.push_back(name);
2929 names.push_back(name +
"[" + std::to_string(
i) +
"]");
2933 names.push_back(name);
2939int gl_context::get_uniform_location(
const shader_program_base&
spb,
const std::string& name)
const
2944std::string value_type_index_to_string(type_descriptor
td)
2947 switch (
td.element_type) {
2953 if (
td.is_row_major)
2963bool gl_context::set_uniform_void(shader_program_base&
spb,
int loc, type_descriptor value_type,
const void* value_ptr)
const
2965 if (value_type.is_array) {
2966 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);
2970 error(
"gl_context::set_uniform_void() called on not created program", &
spb);
2977 switch (value_type.element_type) {
2979 switch (value_type.coordinate_type) {
2990 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
2995 switch (value_type.nr_rows) {
2997 switch (value_type.coordinate_type) {
3008 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3013 switch (value_type.coordinate_type) {
3024 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3029 switch (value_type.coordinate_type) {
3040 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3047 switch (value_type.coordinate_type) {
3049 switch (value_type.nr_rows) {
3051 switch (value_type.nr_columns) {
3056 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3061 switch (value_type.nr_columns) {
3066 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3071 switch (value_type.nr_columns) {
3076 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3081 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of rows outside [2,..,4].", &
spb);
3086 switch (value_type.nr_rows) {
3088 switch (value_type.nr_columns) {
3093 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3098 switch (value_type.nr_columns) {
3103 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3108 switch (value_type.nr_columns) {
3113 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..,4].", &
spb);
3118 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") matrix number of rows outside [2,..,4].", &
spb);
3123 error(std::string(
"gl_context::set_uniform_void(") + value_type_index_to_string(value_type) +
") non float coordinate type not supported.", &
spb);
3131 if (check_gl_error(
"gl_context::set_uniform_void()", &
spb))
3136bool 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
3138 if (!value_type.is_array) {
3139 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") non array type not allowed.", &
spb);
3143 error(
"gl_context::set_uniform_array_void() called on not created program", &
spb);
3150 switch (value_type.coordinate_type) {
3152 switch (value_type.element_type) {
3157 switch (value_type.nr_rows) {
3162 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") vector dimension outside [2,..4].", &
spb);
3168 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") type not supported.", &
spb);
3174 switch (value_type.element_type) {
3179 switch (value_type.nr_rows) {
3184 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") vector dimension outside [2,..4].", &
spb);
3190 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") type not supported.", &
spb);
3196 switch (value_type.element_type) {
3201 switch (value_type.nr_rows) {
3206 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") vector dimension outside [2,..4].", &
spb);
3212 switch (value_type.nr_rows) {
3214 switch (value_type.nr_columns) {
3219 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..4].", &
spb);
3225 switch (value_type.nr_columns) {
3230 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..4].", &
spb);
3236 switch (value_type.nr_columns) {
3241 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") matrix number of columns outside [2,..4].", &
spb);
3247 error(std::string(
"gl_context::set_uniform_array_void(") + value_type_index_to_string(value_type) +
") matrix number of rows outside [2,..4].", &
spb);
3255 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);
3259 if (check_gl_error(
"gl_context::set_uniform_array_void()", &
spb))
3268int gl_context::get_attribute_location(
const shader_program_base&
spb,
const std::string& name)
const
3274bool gl_context::set_attribute_void(shader_program_base&
spb,
int loc, type_descriptor value_type,
const void* value_ptr)
const
3277 error(
"gl_context::set_attribute_void() called on not created program", &
spb);
3284 switch (value_type.element_type) {
3286 switch (value_type.coordinate_type) {
3297 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") type not supported!", &
spb);
3303 switch (value_type.nr_rows) {
3305 switch (value_type.coordinate_type) {
3316 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3322 switch (value_type.coordinate_type) {
3333 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3338 switch (value_type.coordinate_type) {
3349 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") unsupported coordinate type.", &
spb);
3355 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") vector dimension outside [2..4]", &
spb);
3361 error(std::string(
"gl_context::set_attribute_void(") + value_type_index_to_string(value_type) +
") matrix type not supported!", &
spb);
3368 if (check_gl_error(
"gl_context::set_uniform_array_void()", &
spb))
3373bool gl_context::attribute_array_binding_create(attribute_array_binding_base& aab)
const
3376 error(
"gl_context::attribute_array_binding_create() array attribute bindings not supported", &aab);
3382 error(std::string(
"gl_context::attribute_array_binding_create(): ") + gl_error(), &aab);
3386 aab.handle = get_handle(
a_id);
3390bool gl_context::attribute_array_binding_destruct(attribute_array_binding_base& aab)
3394 if (!context::attribute_array_binding_destruct(aab))
3397 error(
"gl_context::attribute_array_binding_destruct(): called on not created attribute array binding", &aab);
3402 return !check_gl_error(
"gl_context::attribute_array_binding_destruct");
3405bool gl_context::attribute_array_binding_enable(attribute_array_binding_base& aab)
3407 if (!context::attribute_array_binding_enable(aab))
3410 return !check_gl_error(
"gl_context::attribute_array_binding_enable");
3413bool gl_context::attribute_array_binding_disable(attribute_array_binding_base& aab)
3415 if (!context::attribute_array_binding_disable(aab))
3424bool gl_context::set_element_array(attribute_array_binding_base* aab,
const vertex_buffer_base*
vbb)
const
3427 error(
"gl_context::set_element_array(): called without a vertex buffer object", aab);
3431 error(
"gl_context::set_element_array(): called with not created vertex buffer object",
vbb);
3435 std::cout <<
"gl_context::set_element_array() : called on vertex buffer object that is not of type VBT_INDICES" << std::endl;
3441 error(
"gl_context::set_element_array(): called on not created attribute array binding", aab);
3456 return !check_gl_error(
"gl_context::set_element_array_void()", aab);
3460bool 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
3462 if (value_type == ET_MATRIX) {
3463 error(
"gl_context::set_attribute_array_void(): called with matrix elements not supported", aab);
3468 error(
"gl_context::set_attribute_array_void(): called with not created vertex buffer object",
vbb);
3474 error(
"gl_context::set_attribute_array_void(): called on not created attribute array binding", aab);
3487 unsigned n = value_type.element_type == ET_VALUE ? 1 : value_type.nr_rows;
3488 switch (value_type.coordinate_type) {
3500 error(
"gl_context::set_attribute_array_void(): called with coordinates of type double only supported starting with OpenGL 4.1", aab);
3505 error(
"gl_context::set_attribute_array_void(): called with unsupported coordinate type", aab);
3519 return res && !check_gl_error(
"gl_context::set_attribute_array_void()", aab);
3522bool gl_context::enable_attribute_array(attribute_array_binding_base* aab,
int loc,
bool do_enable)
const
3527 error(
"gl_context::enable_attribute_array(): called on not created attribute array binding", aab);
3542 return !check_gl_error(
"gl_context::enable_attribute_array()");
3545bool gl_context::is_attribute_array_enabled(
const attribute_array_binding_base* aab,
int loc)
const
3550 error(
"gl_context::is_attribute_array_enabled(): called on not created attribute array binding", aab);
3599 if (
_idx ==
unsigned(-1))
3603 return !check_gl_error(
"gl_context::vertex_buffer_bind", &
vbb);
3607 if(
_idx ==
unsigned(-1))
3611 return !check_gl_error(
"gl_context::vertex_buffer_unbind", &
vbb);
3614bool gl_context::vertex_buffer_create(vertex_buffer_base&
vbb,
const void*
array_ptr,
size_t size_in_bytes)
const
3617 error(
"gl_context::vertex_buffer_create() vertex buffer objects not supported", &
vbb);
3623 error(std::string(
"gl_context::vertex_buffer_create(): ") + gl_error(), &
vbb);
3626 vbb.handle = get_handle(
b_id);
3630 return !check_gl_error(
"gl_context::vertex_buffer_create", &
vbb);
3633bool gl_context::vertex_buffer_resize(vertex_buffer_base&
vbb,
const void*
array_ptr,
size_t size_in_bytes)
const {
3635 error(
"gl_context::vertex_buffer_resize() vertex buffer object must be created before", &
vbb);
3642 return !check_gl_error(
"gl_context::vertex_buffer_resize", &
vbb);
3645bool gl_context::vertex_buffer_replace(vertex_buffer_base&
vbb,
size_t offset,
size_t size_in_bytes,
const void*
array_ptr)
const
3648 error(
"gl_context::vertex_buffer_replace() vertex buffer object must be created before", &
vbb);
3655 return !check_gl_error(
"gl_context::vertex_buffer_replace", &
vbb);
3658bool 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
3660 if (!
src.handle || !target.handle) {
3661 error(
"gl_context::vertex_buffer_copy() source and destination vertex buffer objects must have been created before", &
src);
3670 return !check_gl_error(
"gl_context::vertex_buffer_copy", &
src);
3674bool gl_context::vertex_buffer_copy_back(vertex_buffer_base&
vbb,
size_t offset,
size_t size_in_bytes,
void*
array_ptr)
const
3677 error(
"gl_context::vertex_buffer_copy_back() vertex buffer object must be created", &
vbb);
3684 return !check_gl_error(
"gl_context::vertex_buffer_copy_back", &
vbb);
3687bool gl_context::vertex_buffer_destruct(vertex_buffer_base&
vbb)
const
3692 return !check_gl_error(
"gl_context::vertex_buffer_destruct");
3695 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.
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
int max_compute_shared_memory_size
the maximum number that can be provided to the max_vertices output layout qualifier in a geometry sha...
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...
int max_compute_work_group_invocations
total available storage size in bytes for all shared variables in a compute shader
int max_geometry_shader_output_vertex_count
the maximum supported size for renderbuffers in any dimension
ivec3 max_compute_work_group_size
the maximum number of work groups that may be dispatched to a compute shader; dimension index 0,...
compact type description of data that can be sent to the context; convertible to int