libvgcode - Use plain textures in place of texture buffers for OpenGL ES (partial implementation using one texture per buffer)

This commit is contained in:
enricoturri1966 2024-02-28 08:36:03 +01:00 committed by Lukas Matena
parent 9579c9c212
commit 461d30537f
5 changed files with 273 additions and 94 deletions

View File

@ -132,7 +132,7 @@ static const char* Segments_Vertex_Shader =
" }\n"
" vec3 eye_position = (view_matrix * vec4(pos, 1.0)).xyz;\n"
" vec3 eye_normal = (view_matrix * vec4(normalize(pos - endpoint_pos), 0.0)).xyz;\n"
" vec3 color_base = decode_color(texelFetch(color_tex, id).x);\n"
" vec3 color_base = decode_color(texelFetch(color_tex, id).r);\n"
" color = color_base * lighting(eye_position, eye_normal);\n"
" gl_Position = projection_matrix * vec4(eye_position, 1.0);\n"
"}\n";
@ -190,7 +190,7 @@ static const char* Options_Vertex_Shader =
" 0.0, 0.0, height_width.x);\n"
" vec3 eye_position = (view_matrix * vec4(scale_matrix * in_position + offset, 1.0)).xyz;\n"
" vec3 eye_normal = (view_matrix * vec4(in_normal, 0.0)).xyz;\n"
" vec3 color_base = decode_color(texelFetch(color_tex, id).x);\n"
" vec3 color_base = decode_color(texelFetch(color_tex, id).r);\n"
" color = color_base * lighting(eye_position, eye_normal);\n"
" gl_Position = projection_matrix * vec4(eye_position, 1.0);\n"
"}\n";

View File

@ -26,10 +26,10 @@ static const char* Segments_Vertex_Shader_ES =
"uniform mat4 view_matrix;\n"
"uniform mat4 projection_matrix;\n"
"uniform vec3 camera_position;\n"
"uniform samplerBuffer position_tex;\n"
"uniform samplerBuffer height_width_angle_tex;\n"
"uniform samplerBuffer color_tex;\n"
"uniform usamplerBuffer segment_index_tex;\n"
"uniform sampler2D position_tex;\n"
"uniform sampler2D height_width_angle_tex;\n"
"uniform sampler2D color_tex;\n"
"uniform usampler2D segment_index_tex;\n"
"in int vertex_id;\n"
"out vec3 color;\n"
"vec3 decode_color(float color) {\n"
@ -47,10 +47,10 @@ static const char* Segments_Vertex_Shader_ES =
" return ambient + top_diffuse + front_diffuse + top_specular + emission;\n"
"}\n"
"void main() {\n"
" int id_a = int(texelFetch(segment_index_tex, gl_InstanceID).r);\n"
" int id_a = int(texelFetch(segment_index_tex, ivec2(gl_InstanceID, 0), 0).r);\n"
" int id_b = id_a + 1;\n"
" vec3 pos_a = texelFetch(position_tex, id_a).xyz;\n"
" vec3 pos_b = texelFetch(position_tex, id_b).xyz;\n"
" vec3 pos_a = texelFetch(position_tex, ivec2(id_a, 0), 0).xyz;\n"
" vec3 pos_b = texelFetch(position_tex, ivec2(id_b, 0), 0).xyz;\n"
" vec3 line = pos_b - pos_a;\n"
" // directions of the line box in world space\n"
" float line_len = length(line);\n"
@ -90,12 +90,12 @@ static const char* Segments_Vertex_Shader_ES =
" );\n"
" int id = vertex_id < 4 ? id_a : id_b;\n"
" vec3 endpoint_pos = vertex_id < 4 ? pos_a : pos_b;\n"
" vec3 height_width_angle = texelFetch(height_width_angle_tex, id).xyz;\n"
" vec3 height_width_angle = texelFetch(height_width_angle_tex, ivec2(id, 0), 0).xyz;\n"
"#ifdef FIX_TWISTING\n"
" int closer_id = (dot(camera_position - pos_a, camera_position - pos_a) < dot(camera_position - pos_b, camera_position - pos_b)) ? id_a : id_b;\n"
" vec3 closer_pos = (closer_id == id_a) ? pos_a : pos_b;\n"
" vec3 camera_view_dir = normalize(closer_pos - camera_position);\n"
" vec3 closer_height_width_angle = texelFetch(height_width_angle_tex, closer_id).xyz;\n"
" vec3 closer_height_width_angle = texelFetch(height_width_angle_tex, ivec2(closer_id, 0), 0).xyz;\n"
" vec3 diagonal_dir_border = normalize(closer_height_width_angle.x * line_up_dir + closer_height_width_angle.y * line_right_dir);\n"
"#else\n"
" vec3 camera_view_dir = normalize(endpoint_pos - camera_position);\n"
@ -132,7 +132,7 @@ static const char* Segments_Vertex_Shader_ES =
" }\n"
" vec3 eye_position = (view_matrix * vec4(pos, 1.0)).xyz;\n"
" vec3 eye_normal = (view_matrix * vec4(normalize(pos - endpoint_pos), 0.0)).xyz;\n"
" vec3 color_base = decode_color(texelFetch(color_tex, id).x);\n"
" vec3 color_base = decode_color(texelFetch(color_tex, ivec2(id, 0), 0).r);\n"
" color = color_base * lighting(eye_position, eye_normal);\n"
" gl_Position = projection_matrix * vec4(eye_position, 1.0);\n"
"}\n";
@ -159,10 +159,10 @@ static const char* Options_Vertex_Shader_ES =
"const float scaling_factor = 1.5;\n"
"uniform mat4 view_matrix;\n"
"uniform mat4 projection_matrix;\n"
"uniform samplerBuffer position_tex;\n"
"uniform samplerBuffer height_width_angle_tex;\n"
"uniform samplerBuffer color_tex;\n"
"uniform usamplerBuffer segment_index_tex;\n"
"uniform sampler2D position_tex;\n"
"uniform sampler2D height_width_angle_tex;\n"
"uniform sampler2D color_tex;\n"
"uniform usampler2D segment_index_tex;\n"
"in vec3 in_position;\n"
"in vec3 in_normal;\n"
"out vec3 color;\n"
@ -181,9 +181,9 @@ static const char* Options_Vertex_Shader_ES =
" return ambient + top_diffuse + front_diffuse + top_specular + emission;\n"
"}\n"
"void main() {\n"
" int id = int(texelFetch(segment_index_tex, gl_InstanceID).r);\n"
" vec2 height_width = texelFetch(height_width_angle_tex, id).xy;\n"
" vec3 offset = texelFetch(position_tex, id).xyz - vec3(0.0, 0.0, 0.5 * height_width.x);\n"
" int id = int(texelFetch(segment_index_tex, ivec2(gl_InstanceID, 0), 0).r);\n"
" vec2 height_width = texelFetch(height_width_angle_tex, ivec2(id, 0), 0).xy;\n"
" vec3 offset = texelFetch(position_tex, ivec2(id, 0), 0).xyz - vec3(0.0, 0.0, 0.5 * height_width.x);\n"
" height_width *= scaling_factor;\n"
" mat3 scale_matrix = mat3(\n"
" height_width.y, 0.0, 0.0,\n"
@ -191,7 +191,7 @@ static const char* Options_Vertex_Shader_ES =
" 0.0, 0.0, height_width.x);\n"
" vec3 eye_position = (view_matrix * vec4(scale_matrix * in_position + offset, 1.0)).xyz;\n"
" vec3 eye_normal = (view_matrix * vec4(in_normal, 0.0)).xyz;\n"
" vec3 color_base = decode_color(texelFetch(color_tex, id).x);\n"
" vec3 color_base = decode_color(texelFetch(color_tex, ivec2(id, 0), 0).r);\n"
" color = color_base * lighting(eye_position, eye_normal);\n"
" gl_Position = projection_matrix * vec4(eye_position, 1.0);\n"
"}\n";

View File

@ -467,19 +467,29 @@ void ViewerImpl::reset()
m_enabled_options_count = 0;
delete_textures(m_enabled_options_tex_id);
#if !VGCODE_ENABLE_OPENGL_ES
delete_buffers(m_enabled_options_buf_id);
#endif // !VGCODE_ENABLE_OPENGL_ES
delete_textures(m_enabled_segments_tex_id);
#if !VGCODE_ENABLE_OPENGL_ES
delete_buffers(m_enabled_segments_buf_id);
#endif // !VGCODE_ENABLE_OPENGL_ES
delete_textures(m_colors_tex_id);
#if !VGCODE_ENABLE_OPENGL_ES
delete_buffers(m_colors_buf_id);
#endif // !VGCODE_ENABLE_OPENGL_ES
delete_textures(m_heights_widths_angles_tex_id);
#if !VGCODE_ENABLE_OPENGL_ES
delete_buffers(m_heights_widths_angles_buf_id);
#endif // !VGCODE_ENABLE_OPENGL_ES
delete_textures(m_positions_tex_id);
#if !VGCODE_ENABLE_OPENGL_ES
delete_buffers(m_positions_buf_id);
#endif // !VGCODE_ENABLE_OPENGL_ES
}
void ViewerImpl::load(GCodeInputData&& gcode_data)
@ -597,36 +607,69 @@ void ViewerImpl::load(GCodeInputData&& gcode_data)
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &old_bound_texture));
// create and fill positions buffer
#if VGCODE_ENABLE_OPENGL_ES
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_bound_texture));
int max_texture_size = 0;
glsafe(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size));
const size_t size = std::min<size_t>(positions.size(), max_texture_size);
glsafe(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
glsafe(glGenTextures(1, &m_positions_tex_id));
glsafe(glBindTexture(GL_TEXTURE_2D, m_positions_tex_id));
glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, static_cast<GLsizei>(size), 1, 0, GL_RGB, GL_FLOAT, positions.data()));
// glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, static_cast<GLsizei>(positions.size()), 1, 0, GL_RGB, GL_FLOAT, positions.data()));
glsafe(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
#else
glsafe(glGenBuffers(1, &m_positions_buf_id));
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_positions_buf_id));
glsafe(glBufferData(GL_TEXTURE_BUFFER, positions.size() * sizeof(Vec3), positions.data(), GL_STATIC_DRAW));
glsafe(glGenTextures(1, &m_positions_tex_id));
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_positions_tex_id));
#endif // VGCODE_ENABLE_OPENGL_ES
// create and fill height, width and angles buffer
#if VGCODE_ENABLE_OPENGL_ES
glsafe(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
glsafe(glGenTextures(1, &m_heights_widths_angles_tex_id));
glsafe(glBindTexture(GL_TEXTURE_2D, m_heights_widths_angles_tex_id));
glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, static_cast<GLsizei>(size), 1, 0, GL_RGB, GL_FLOAT, heights_widths_angles.data()));
// glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, static_cast<GLsizei>(heights_widths_angles.size()), 1, 0, GL_RGB, GL_FLOAT, heights_widths_angles.data()));
glsafe(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
glsafe(glBindTexture(GL_TEXTURE_2D, curr_bound_texture));
#else
glsafe(glGenBuffers(1, &m_heights_widths_angles_buf_id));
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_heights_widths_angles_buf_id));
glsafe(glBufferData(GL_TEXTURE_BUFFER, heights_widths_angles.size() * sizeof(Vec3), heights_widths_angles.data(), GL_DYNAMIC_DRAW));
glsafe(glGenTextures(1, &m_heights_widths_angles_tex_id));
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_heights_widths_angles_tex_id));
#endif // VGCODE_ENABLE_OPENGL_ES
#if !VGCODE_ENABLE_OPENGL_ES
// create (but do not fill) colors buffer (data is set in update_colors())
glsafe(glGenBuffers(1, &m_colors_buf_id));
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_colors_buf_id));
glsafe(glGenTextures(1, &m_colors_tex_id));
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_colors_tex_id));
#endif // !VGCODE_ENABLE_OPENGL_ES
#if !VGCODE_ENABLE_OPENGL_ES
// create (but do not fill) enabled segments buffer (data is set in update_enabled_entities())
glsafe(glGenBuffers(1, &m_enabled_segments_buf_id));
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_enabled_segments_buf_id));
glsafe(glGenTextures(1, &m_enabled_segments_tex_id));
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_enabled_segments_tex_id));
#endif // !VGCODE_ENABLE_OPENGL_ES
#if !VGCODE_ENABLE_OPENGL_ES
// create (but do not fill) enabled options buffer (data is set in update_enabled_entities())
glsafe(glGenBuffers(1, &m_enabled_options_buf_id));
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_enabled_options_buf_id));
glsafe(glGenTextures(1, &m_enabled_options_tex_id));
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_enabled_options_tex_id));
#endif // !VGCODE_ENABLE_OPENGL_ES
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, 0));
glsafe(glBindTexture(GL_TEXTURE_BUFFER, old_bound_texture));
@ -703,14 +746,57 @@ void ViewerImpl::update_enabled_entities()
m_enabled_options_tex_size = enabled_options.size() * sizeof(uint32_t);
// update gpu buffer for enabled segments
#if VGCODE_ENABLE_OPENGL_ES
delete_textures(m_enabled_segments_tex_id);
if (!enabled_segments.empty()) {
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_bound_texture));
int max_texture_size = 0;
glsafe(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size));
const size_t size = std::min<size_t>(enabled_segments.size(), max_texture_size);
glsafe(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
glsafe(glGenTextures(1, &m_enabled_segments_tex_id));
glsafe(glBindTexture(GL_TEXTURE_2D, m_enabled_segments_tex_id));
glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, static_cast<GLsizei>(size), 1, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, enabled_segments.data()));
// glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, static_cast<GLsizei>(enabled_segments.size()), 1, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, enabled_segments.data()));
glsafe(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
glsafe(glBindTexture(GL_TEXTURE_2D, curr_bound_texture));
}
#else
assert(m_enabled_segments_buf_id > 0);
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_enabled_segments_buf_id));
if (!enabled_segments.empty())
glsafe(glBufferData(GL_TEXTURE_BUFFER, enabled_segments.size() * sizeof(uint32_t), enabled_segments.data(), GL_STATIC_DRAW));
else
glsafe(glBufferData(GL_TEXTURE_BUFFER, 0, nullptr, GL_STATIC_DRAW));
#endif // VGCODE_ENABLE_OPENGL_ES
// update gpu buffer for enabled options
#if VGCODE_ENABLE_OPENGL_ES
delete_textures(m_enabled_options_tex_id);
if (!enabled_options.empty()) {
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_bound_texture));
int max_texture_size = 0;
glsafe(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size));
const size_t size = std::min<size_t>(enabled_options.size(), max_texture_size);
glsafe(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
glsafe(glGenTextures(1, &m_enabled_options_tex_id));
glsafe(glBindTexture(GL_TEXTURE_2D, m_enabled_options_tex_id));
glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, static_cast<GLsizei>(size), 1, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, enabled_options.data()));
// glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, static_cast<GLsizei>(enabled_options.size()), 1, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, enabled_options.data()));
glsafe(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
glsafe(glBindTexture(GL_TEXTURE_2D, curr_bound_texture));
}
#else
assert(m_enabled_options_buf_id > 0);
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_enabled_options_buf_id));
if (!enabled_options.empty())
@ -719,6 +805,7 @@ void ViewerImpl::update_enabled_entities()
glsafe(glBufferData(GL_TEXTURE_BUFFER, 0, nullptr, GL_STATIC_DRAW));
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, 0));
#endif // VGCODE_ENABLE_OPENGL_ES
m_settings.update_enabled_entities = false;
}
@ -733,8 +820,10 @@ static float encode_color(const Color& color) {
void ViewerImpl::update_colors()
{
#if !VGCODE_ENABLE_OPENGL_ES
if (m_colors_buf_id == 0)
return;
#endif // !VGCODE_ENABLE_OPENGL_ES
if (!m_used_extruders.empty()) {
// ensure that the number of defined tool colors matches the max id of the used extruders
@ -760,11 +849,34 @@ void ViewerImpl::update_colors()
m_colors_tex_size = colors.size() * sizeof(float);
#if VGCODE_ENABLE_OPENGL_ES
// update gpu texture for colors
delete_textures(m_colors_tex_id);
if (!colors.empty()) {
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_bound_texture));
int max_texture_size = 0;
glsafe(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size));
const size_t size = std::min<size_t>(colors.size(), max_texture_size);
glsafe(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
glsafe(glGenTextures(1, &m_colors_tex_id));
glsafe(glBindTexture(GL_TEXTURE_2D, m_colors_tex_id));
glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, static_cast<GLsizei>(size), 1, 0, GL_RED, GL_FLOAT, colors.data()));
// glsafe(glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, static_cast<GLsizei>(colors.size()), 1, 0, GL_RED, GL_FLOAT, colors.data()));
glsafe(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
glsafe(glBindTexture(GL_TEXTURE_2D, curr_bound_texture));
}
#else
// update gpu buffer for colors
assert(m_colors_buf_id > 0);
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_colors_buf_id));
glsafe(glBufferData(GL_TEXTURE_BUFFER, colors.size() * sizeof(float), colors.data(), GL_STATIC_DRAW));
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, 0));
#endif // VGCODE_ENABLE_OPENGL_ES
m_settings.update_colors = false;
}
@ -1315,24 +1427,28 @@ void ViewerImpl::update_color_ranges()
void ViewerImpl::update_heights_widths()
{
#if VGCODE_ENABLE_OPENGL_ES
// TODO: Fix for plain textures
//for (size_t i = 0; i < m_vertices.size(); ++i) {
// const PathVertex& v = m_vertices[i];
// const size_t offset = i * sizeof(Vec3);
// if (v.is_travel()) {
// const std::array<float, 2> radii = { m_travels_radius, m_travels_radius };
// glsafe(glBufferSubData(GL_TEXTURE_BUFFER, offset, radii.size() * sizeof(float), radii.data()));
// }
// else if (v.is_wipe()) {
// const std::array<float, 2> radii = { m_wipes_radius, m_wipes_radius };
// glsafe(glBufferSubData(GL_TEXTURE_BUFFER, offset, radii.size() * sizeof(float), radii.data()));
// }
//}
#else
if (m_heights_widths_angles_buf_id == 0)
return;
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_heights_widths_angles_buf_id));
#if VGCODE_ENABLE_OPENGL_ES
for (size_t i = 0; i < m_vertices.size(); ++i) {
const PathVertex& v = m_vertices[i];
const size_t offset = i * sizeof(Vec3);
if (v.is_travel()) {
const std::array<float, 2> radii = { m_travels_radius, m_travels_radius };
glsafe(glBufferSubData(GL_TEXTURE_BUFFER, offset, radii.size() * sizeof(float), radii.data()));
}
else if (v.is_wipe()) {
const std::array<float, 2> radii = { m_wipes_radius, m_wipes_radius };
glsafe(glBufferSubData(GL_TEXTURE_BUFFER, offset, radii.size() * sizeof(float), radii.data()));
}
}
#else
Vec3* buffer = static_cast<Vec3*>(glMapBuffer(GL_TEXTURE_BUFFER, GL_WRITE_ONLY));
glcheck();
@ -1349,8 +1465,8 @@ void ViewerImpl::update_heights_widths()
}
glsafe(glUnmapBuffer(GL_TEXTURE_BUFFER));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, 0));
#endif // VGCODE_ENABLE_OPENGL_ES
}
void ViewerImpl::render_segments(const Mat4x4& view_matrix, const Mat4x4& projection_matrix, const Vec3& camera_position)
@ -1360,28 +1476,48 @@ void ViewerImpl::render_segments(const Mat4x4& view_matrix, const Mat4x4& projec
int curr_active_texture = 0;
glsafe(glGetIntegerv(GL_ACTIVE_TEXTURE, &curr_active_texture));
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &curr_bound_texture));
int curr_shader;
glsafe(glGetIntegerv(GL_CURRENT_PROGRAM, &curr_shader));
const bool curr_cull_face = glIsEnabled(GL_CULL_FACE);
glcheck();
glsafe(glActiveTexture(GL_TEXTURE0));
#if VGCODE_ENABLE_OPENGL_ES
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_bound_texture));
glsafe(glBindTexture(GL_TEXTURE_2D, m_positions_tex_id));
#else
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &curr_bound_texture));
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_positions_tex_id));
glsafe(glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, m_positions_buf_id));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glActiveTexture(GL_TEXTURE1));
#if VGCODE_ENABLE_OPENGL_ES
glsafe(glBindTexture(GL_TEXTURE_2D, m_heights_widths_angles_tex_id));
#else
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_heights_widths_angles_tex_id));
glsafe(glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, m_heights_widths_angles_buf_id));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glActiveTexture(GL_TEXTURE2));
#if VGCODE_ENABLE_OPENGL_ES
glsafe(glBindTexture(GL_TEXTURE_2D, m_colors_tex_id));
#else
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_colors_tex_id));
glsafe(glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, m_colors_buf_id));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glActiveTexture(GL_TEXTURE3));
#if VGCODE_ENABLE_OPENGL_ES
glsafe(glBindTexture(GL_TEXTURE_2D, m_enabled_segments_tex_id));
#else
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_enabled_segments_tex_id));
glsafe(glTexBuffer(GL_TEXTURE_BUFFER, GL_R32UI, m_enabled_segments_buf_id));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glUseProgram(m_segments_shader_id));
@ -1401,7 +1537,11 @@ void ViewerImpl::render_segments(const Mat4x4& view_matrix, const Mat4x4& projec
glsafe(glEnable(GL_CULL_FACE));
glsafe(glUseProgram(curr_shader));
#if VGCODE_ENABLE_OPENGL_ES
glsafe(glBindTexture(GL_TEXTURE_2D, curr_bound_texture));
#else
glsafe(glBindTexture(GL_TEXTURE_BUFFER, curr_bound_texture));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glActiveTexture(curr_active_texture));
}
@ -1412,28 +1552,48 @@ void ViewerImpl::render_options(const Mat4x4& view_matrix, const Mat4x4& project
int curr_active_texture = 0;
glsafe(glGetIntegerv(GL_ACTIVE_TEXTURE, &curr_active_texture));
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &curr_bound_texture));
int curr_shader;
glsafe(glGetIntegerv(GL_CURRENT_PROGRAM, &curr_shader));
const bool curr_cull_face = glIsEnabled(GL_CULL_FACE);
glcheck();
glsafe(glActiveTexture(GL_TEXTURE0));
#if VGCODE_ENABLE_OPENGL_ES
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_bound_texture));
glsafe(glBindTexture(GL_TEXTURE_2D, m_positions_tex_id));
#else
int curr_bound_texture = 0;
glsafe(glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &curr_bound_texture));
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_positions_tex_id));
glsafe(glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, m_positions_buf_id));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glActiveTexture(GL_TEXTURE1));
#if VGCODE_ENABLE_OPENGL_ES
glsafe(glBindTexture(GL_TEXTURE_2D, m_heights_widths_angles_tex_id));
#else
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_heights_widths_angles_tex_id));
glsafe(glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, m_heights_widths_angles_buf_id));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glActiveTexture(GL_TEXTURE2));
#if VGCODE_ENABLE_OPENGL_ES
glsafe(glBindTexture(GL_TEXTURE_2D, m_colors_tex_id));
#else
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_colors_tex_id));
glsafe(glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, m_colors_buf_id));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glActiveTexture(GL_TEXTURE3));
#if VGCODE_ENABLE_OPENGL_ES
glsafe(glBindTexture(GL_TEXTURE_2D, m_enabled_options_tex_id));
#else
glsafe(glBindTexture(GL_TEXTURE_BUFFER, m_enabled_options_tex_id));
glsafe(glTexBuffer(GL_TEXTURE_BUFFER, GL_R32UI, m_enabled_options_buf_id));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glEnable(GL_CULL_FACE));
@ -1452,7 +1612,11 @@ void ViewerImpl::render_options(const Mat4x4& view_matrix, const Mat4x4& project
glsafe(glDisable(GL_CULL_FACE));
glsafe(glUseProgram(curr_shader));
#if VGCODE_ENABLE_OPENGL_ES
glsafe(glBindTexture(GL_TEXTURE_2D, curr_bound_texture));
#else
glsafe(glBindTexture(GL_TEXTURE_BUFFER, curr_bound_texture));
#endif // VGCODE_ENABLE_OPENGL_ES
glsafe(glActiveTexture(curr_active_texture));
}

View File

@ -342,28 +342,48 @@ private:
//
// OpenGL buffers to store positions
//
#if VGCODE_ENABLE_OPENGL_ES
unsigned int m_positions_tex_id{ 0 };
#else
unsigned int m_positions_buf_id{ 0 };
unsigned int m_positions_tex_id{ 0 };
#endif // VGCODE_ENABLE_OPENGL_ES
//
// OpenGL buffers to store heights, widths and angles
//
#if VGCODE_ENABLE_OPENGL_ES
unsigned int m_heights_widths_angles_tex_id{ 0 };
#else
unsigned int m_heights_widths_angles_buf_id{ 0 };
unsigned int m_heights_widths_angles_tex_id{ 0 };
#endif // VGCODE_ENABLE_OPENGL_ES
//
// OpenGL buffers to store colors
//
#if VGCODE_ENABLE_OPENGL_ES
unsigned int m_colors_tex_id{ 0 };
#else
unsigned int m_colors_buf_id{ 0 };
unsigned int m_colors_tex_id{ 0 };
#endif // VGCODE_ENABLE_OPENGL_ES
//
// OpenGL buffers to store enabled segments
//
#if VGCODE_ENABLE_OPENGL_ES
unsigned int m_enabled_segments_tex_id{ 0 };
#else
unsigned int m_enabled_segments_buf_id{ 0 };
unsigned int m_enabled_segments_tex_id{ 0 };
#endif // VGCODE_ENABLE_OPENGL_ES
//
// OpenGL buffers to store enabled options
//
#if VGCODE_ENABLE_OPENGL_ES
unsigned int m_enabled_options_tex_id{ 0 };
#else
unsigned int m_enabled_options_buf_id{ 0 };
unsigned int m_enabled_options_tex_id{ 0 };
#endif // VGCODE_ENABLE_OPENGL_ES
//
// Caches for size of data sent to gpu, in bytes
//

View File

@ -1715,7 +1715,6 @@ void GCodeViewer::render_toolpaths()
if (ImGui::BeginTable("Data", 2)) {
/*
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "# vertices");
@ -1723,7 +1722,6 @@ void GCodeViewer::render_toolpaths()
imgui.text(std::to_string(m_viewer.get_vertices_count()));
ImGui::Separator();
*/
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
@ -1737,7 +1735,6 @@ void GCodeViewer::render_toolpaths()
ImGui::TableSetColumnIndex(1);
imgui.text(format_memsize(m_viewer.get_used_gpu_memory()));
/*
ImGui::Separator();
ImGui::TableNextRow();
@ -1794,6 +1791,7 @@ void GCodeViewer::render_toolpaths()
add_range_property_row("layer time logarithmic range", m_viewer.get_color_range(libvgcode::EViewType::LayerTimeLogarithmic).get_range());
ImGui::EndTable();
}
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
ImGui::Separator();
@ -1848,7 +1846,6 @@ void GCodeViewer::render_toolpaths()
ImGui::EndTable();
}
#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
}
ImGui::Separator();
if (ImGui::BeginTable("Radii", 2)) {
@ -1871,8 +1868,6 @@ void GCodeViewer::render_toolpaths()
if (imgui.slider_float("##WipesRadius", &wipes_radius, 0.05f, 0.5f))
m_viewer.set_wipes_radius(wipes_radius);
*/
ImGui::EndTable();
}