From d6ca3d351cf15c6f62abef56a285add170e94ace Mon Sep 17 00:00:00 2001 From: kallaballa Date: Wed, 12 Apr 2023 10:44:39 +0200 Subject: [PATCH] raise minimal OpenGL version to 3.2 compat --- modules/viz2d/include/opencv2/viz2d/viz2d.hpp | 4 +-- modules/viz2d/src/detail/nanovgcontext.cpp | 28 +++++++++++++++++++ modules/viz2d/src/viz2d.cpp | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/viz2d/include/opencv2/viz2d/viz2d.hpp b/modules/viz2d/include/opencv2/viz2d/viz2d.hpp index c70216726..6f4d529d3 100644 --- a/modules/viz2d/include/opencv2/viz2d/viz2d.hpp +++ b/modules/viz2d/include/opencv2/viz2d/viz2d.hpp @@ -168,7 +168,7 @@ public: */ CV_EXPORTS static cv::Ptr make(const cv::Size& initialSize, const cv::Size& frameBufferSize, bool offscreen, const string& title, int major = 3, - int minor = 0, int samples = 0, bool debug = false); + int minor = 2, int samples = 0, bool debug = false); /*! * Default destructor */ @@ -427,7 +427,7 @@ private: * @param debug Create a debug OpenGL context. */ CV_EXPORTS Viz2D(const cv::Size& initialSize, const cv::Size& frameBufferSize, bool offscreen, - const string& title, int major = 3, int minor = 0, int samples = 0, bool debug = false); + const string& title, int major = 3, int minor = 2, int samples = 0, bool debug = false); void setDefaultKeyboardEventCallback(); void setKeyboardEventCallback( std::function fn); diff --git a/modules/viz2d/src/detail/nanovgcontext.cpp b/modules/viz2d/src/detail/nanovgcontext.cpp index ef9e0b0b0..07b553607 100644 --- a/modules/viz2d/src/detail/nanovgcontext.cpp +++ b/modules/viz2d/src/detail/nanovgcontext.cpp @@ -26,7 +26,34 @@ void NanoVGContext::render(std::function fn) { cv::viz::nvg::detail::NVG::initializeContext(context_), fn(clglContext_.getSize()); } +void push() { +#ifndef VIZ2D_USE_ES3 + GL_CHECK(glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS)); + GL_CHECK(glPushAttrib(GL_ALL_ATTRIB_BITS)); + GL_CHECK(glMatrixMode(GL_MODELVIEW)); + GL_CHECK(glPushMatrix()); + GL_CHECK(glMatrixMode(GL_PROJECTION)); + GL_CHECK(glPushMatrix()); + GL_CHECK(glMatrixMode(GL_TEXTURE)); + GL_CHECK(glPushMatrix()); +#endif +} + +void pop() { +#ifndef VIZ2D_USE_ES3 + GL_CHECK(glMatrixMode(GL_TEXTURE)); + GL_CHECK(glPopMatrix()); + GL_CHECK(glMatrixMode(GL_PROJECTION)); + GL_CHECK(glPopMatrix()); + GL_CHECK(glMatrixMode(GL_MODELVIEW)); + GL_CHECK(glPopMatrix()); + GL_CHECK(glPopClientAttrib()); + GL_CHECK(glPopAttrib()); +#endif +} + void NanoVGContext::begin() { + push(); float w = v2d_.getFrameBufferSize().width; float h = v2d_.getFrameBufferSize().height; float r = v2d_.getXPixelRatio(); @@ -43,6 +70,7 @@ void NanoVGContext::end() { //FIXME make nvgCancelFrame possible nvgEndFrame(context_); nvgRestore(context_); + pop(); } } } diff --git a/modules/viz2d/src/viz2d.cpp b/modules/viz2d/src/viz2d.cpp index e736a6d46..0abebb998 100644 --- a/modules/viz2d/src/viz2d.cpp +++ b/modules/viz2d/src/viz2d.cpp @@ -132,8 +132,8 @@ bool Viz2D::initializeWindowing() { #else glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major_); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor_); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); - glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API) ; #endif glfwWindowHint(GLFW_SAMPLES, samples_);