New gcode visualization integration - Added check of OpenGL version

This commit is contained in:
enricoturri1966 2023-12-01 13:43:10 +01:00 committed by Lukas Matena
parent 08b6369ae4
commit f20f5cc153
4 changed files with 28 additions and 1 deletions

View File

@ -16,8 +16,10 @@
#include <iostream>
#include <assert.h>
#include <cctype>
namespace libvgcode {
#ifdef HAS_GLSAFE
void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char* function_name)
{
@ -40,6 +42,21 @@ void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char
}
#endif // HAS_GLSAFE
bool check_opengl_version()
{
bool ret = false;
const GLubyte* version = glGetString(GL_VERSION);
if (version != nullptr) {
const std::string version_str(reinterpret_cast<const char*>(version));
if (version_str.length() > 4 && isdigit(version_str[0]) && isdigit(version_str[2])) {
const int major = version_str[0] - '0';
const int minor = version_str[2] - '0';
ret = major > 3 || (major == 3 && minor >= 2);
}
}
return ret;
}
} // namespace libvgcode
//################################################################################################################################

View File

@ -31,6 +31,8 @@ inline void glAssertRecentCall() { }
#define glcheck()
#endif // HAS_GLSAFE
extern bool check_opengl_version();
} // namespace libvgcode
//################################################################################################################################

View File

@ -298,9 +298,14 @@ ViewerImpl::~ViewerImpl()
void ViewerImpl::init()
{
if (m_segments_shader_id != 0)
if (m_initialized)
return;
const bool is_valid_opengl_version = check_opengl_version();
assert(is_valid_opengl_version);
if (!is_valid_opengl_version)
throw std::runtime_error("LibVGCode requires an active OpenGL context based on OpenGL 3.2 or higher:\n");
// segments shader
m_segments_shader_id = init_shader("segments", Segments_Vertex_Shader, Segments_Fragment_Shader);
@ -375,6 +380,8 @@ void ViewerImpl::init()
m_tool_marker.init(32, 2.0f, 4.0f, 1.0f, 8.0f);
#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
m_initialized = true;
}
void ViewerImpl::reset()

View File

@ -171,6 +171,7 @@ private:
std::array<float, Time_Modes_Count> m_travels_time{ 0.0f, 0.0f };
std::vector<uint8_t> m_used_extruders_ids;
bool m_initialized{ false };
bool m_loading{ false };
//