From 6eb76a1da58cb61081dbc1b15071c00e56e59e4d Mon Sep 17 00:00:00 2001 From: kallaballa Date: Thu, 27 Oct 2022 01:32:46 +0200 Subject: [PATCH 01/11] replaced glx with egl --- modules/core/CMakeLists.txt | 3 +-- modules/core/src/opengl.cpp | 10 ++-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index eab909843b..d2f77e972f 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -145,8 +145,7 @@ ocv_create_module(${extra_libs}) ocv_target_link_libraries(${the_module} PRIVATE "${ZLIB_LIBRARIES}" "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" - "${OPENGL_LIBRARIES}" - "${GLX_LIBRARIES}" + "${OPENGL_LIBRARIES}" "${OPENGL_egl_LIBRARY}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}" "${ITT_LIBRARIES}" "${OPENCV_HAL_LINKER_LIBS}" diff --git a/modules/core/src/opengl.cpp b/modules/core/src/opengl.cpp index ab39b1b8ac..67d4fd98e5 100644 --- a/modules/core/src/opengl.cpp +++ b/modules/core/src/opengl.cpp @@ -1587,10 +1587,8 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala #endif // HAVE_OPENCL #if defined(HAVE_OPENGL) -# if defined(__ANDROID__) +# if defined(__ANDROID__) || defined(__linux__) # include -# elif defined(__linux__) -# include # endif #endif // HAVE_OPENGL @@ -1684,14 +1682,10 @@ Context& initializeContextFromGL() CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), -#elif defined(__ANDROID__) +#elif defined(__ANDROID__) || defined(__linux__) CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], CL_GL_CONTEXT_KHR, (cl_context_properties)eglGetCurrentContext(), CL_EGL_DISPLAY_KHR, (cl_context_properties)eglGetCurrentDisplay(), -#elif defined(__linux__) - CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], - CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(), - CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(), #endif 0 }; From de6bb169928dc17aa04a53e150cb674f25c4e971 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Sat, 5 Nov 2022 16:06:48 +0100 Subject: [PATCH 02/11] made egl based opengl/opencl interop optional --- modules/core/CMakeLists.txt | 3 +++ modules/core/src/opengl.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index d2f77e972f..8e5bbb6042 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -107,6 +107,9 @@ endif() if(OPENCV_LIBVA_LINK) ocv_append_source_file_compile_definitions("${CMAKE_CURRENT_LIST_DIR}/src/va_intel.cpp" "OPENCV_LIBVA_LINK=1") endif() +if(HAVE_EGL_INTEROP) + add_definitions(-DHAVE_EGL_INTEROP) +endif() option(OPENCV_ENABLE_ALLOCATOR_STATS "Enable Allocator metrics" ON) diff --git a/modules/core/src/opengl.cpp b/modules/core/src/opengl.cpp index 67d4fd98e5..0e3b1794b1 100644 --- a/modules/core/src/opengl.cpp +++ b/modules/core/src/opengl.cpp @@ -1587,8 +1587,10 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala #endif // HAVE_OPENCL #if defined(HAVE_OPENGL) -# if defined(__ANDROID__) || defined(__linux__) +# if defined(__ANDROID__) || defined(HAVE_EGL_INTEROP) # include +# elif defined(__linux__) +# include # endif #endif // HAVE_OPENGL @@ -1682,10 +1684,14 @@ Context& initializeContextFromGL() CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), -#elif defined(__ANDROID__) || defined(__linux__) +#elif defined(__ANDROID__) || defined(HAVE_EGL_INTEROP) CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], CL_GL_CONTEXT_KHR, (cl_context_properties)eglGetCurrentContext(), CL_EGL_DISPLAY_KHR, (cl_context_properties)eglGetCurrentDisplay(), +#elif defined(__linux__) + CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], + CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(), + CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(), #endif 0 }; From 5fe059627b43d0509196cbd0e7f6752d9f96cf75 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Wed, 9 Nov 2022 20:12:11 +0100 Subject: [PATCH 03/11] create a proper option for egl-based opengl-interop (OPENCV_ENABLE_EGL_INTEROP) --- CMakeLists.txt | 2 ++ modules/core/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aba65ba23f..c9d3ad3da4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -321,6 +321,8 @@ OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ((WIN32 OR ANDROID OR OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF VISIBLE_IF NOT ANDROID AND NOT WINRT VERIFY HAVE_OPENGL) +OCV_OPTION(OPENCV_ENABLE_EGL_INTEROP "Enable support for EGL based OpenGL interop" OFF + VISIBLE_IF WITH_OPENGL) OCV_OPTION(WITH_OPENVX "Include OpenVX support" OFF VISIBLE_IF TRUE VERIFY HAVE_OPENVX) diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 8e5bbb6042..a4a95e3df0 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -107,8 +107,8 @@ endif() if(OPENCV_LIBVA_LINK) ocv_append_source_file_compile_definitions("${CMAKE_CURRENT_LIST_DIR}/src/va_intel.cpp" "OPENCV_LIBVA_LINK=1") endif() -if(HAVE_EGL_INTEROP) - add_definitions(-DHAVE_EGL_INTEROP) +if(OPENCV_ENABLE_EGL_INTEROP) + ocv_append_source_file_compile_definitions("${CMAKE_CURRENT_LIST_DIR}/src/opengl.cpp" "HAVE_EGL_INTEROP") endif() option(OPENCV_ENABLE_ALLOCATOR_STATS "Enable Allocator metrics" ON) From 735a0f295ffa2bf1e9ace89293b7b38bbf807b31 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Sun, 20 Nov 2022 13:23:09 +0100 Subject: [PATCH 04/11] properly detect and report EGL --- CMakeLists.txt | 10 ++++++++-- cmake/OpenCVFindLibsGUI.cmake | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9d3ad3da4..f499d5487b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -320,9 +320,11 @@ OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ((WIN32 OR ANDROID OR VERIFY HAVE_OPENEXR) OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF VISIBLE_IF NOT ANDROID AND NOT WINRT - VERIFY HAVE_OPENGL) + VERIFY HAVE_OPENGL + ) OCV_OPTION(OPENCV_ENABLE_EGL_INTEROP "Enable support for EGL based OpenGL interop" OFF - VISIBLE_IF WITH_OPENGL) + VISIBLE_IF WITH_OPENGL + VERIFY HAVE_EGL) OCV_OPTION(WITH_OPENVX "Include OpenVX support" OFF VISIBLE_IF TRUE VERIFY HAVE_OPENVX) @@ -1337,6 +1339,10 @@ if(WITH_OPENGL OR HAVE_OPENGL) status(" OpenGL support:" HAVE_OPENGL THEN "YES (${OPENGL_LIBRARIES})" ELSE NO) endif() +if(HAVE_EGL) + status(" EGL support:" HAVE_EGL THEN "YES (${OPENGL_egl_LIBRARY})" ELSE NO) +endif() + if(WITH_VTK OR HAVE_VTK) status(" VTK support:" HAVE_VTK THEN "YES (ver ${VTK_VERSION})" ELSE NO) endif() diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 79758fa813..a9e92f648d 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -72,6 +72,9 @@ if(WITH_OPENGL) ocv_include_directories(${OPENGL_INCLUDE_DIR}) endif() endif() + if(OpenGL_EGL_FOUND) + set(HAVE_EGL TRUE) + endif() endif() endif(WITH_OPENGL) From 49f64dd463708c6403e57e2fa06ed675ea425b4b Mon Sep 17 00:00:00 2001 From: kallaballa Date: Mon, 21 Nov 2022 05:49:22 +0100 Subject: [PATCH 05/11] make GLX a prerequisite to OpenGL --- CMakeLists.txt | 6 +++++- cmake/OpenCVFindLibsGUI.cmake | 12 ++++++++---- modules/highgui/cmake/detect_gtk.cmake | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f499d5487b..d355545745 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -320,7 +320,7 @@ OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ((WIN32 OR ANDROID OR VERIFY HAVE_OPENEXR) OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF VISIBLE_IF NOT ANDROID AND NOT WINRT - VERIFY HAVE_OPENGL + VERIFY HAVE_OPENGL AND HAVE_GLX ) OCV_OPTION(OPENCV_ENABLE_EGL_INTEROP "Enable support for EGL based OpenGL interop" OFF VISIBLE_IF WITH_OPENGL @@ -1339,6 +1339,10 @@ if(WITH_OPENGL OR HAVE_OPENGL) status(" OpenGL support:" HAVE_OPENGL THEN "YES (${OPENGL_LIBRARIES})" ELSE NO) endif() +if(HAVE_GLX) + status(" GLX support:" HAVE_GLX THEN "YES (${OPENGL_glx_LIBRARY})" ELSE NO) +endif() + if(HAVE_EGL) status(" EGL support:" HAVE_EGL THEN "YES (${OPENGL_egl_LIBRARY})" ELSE NO) endif() diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index a9e92f648d..52fa25d01e 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -64,7 +64,14 @@ ocv_clear_vars(HAVE_OPENGL HAVE_QT_OPENGL) if(WITH_OPENGL) if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR HAVE_GTKGLEXT) find_package (OpenGL QUIET) - if(OPENGL_FOUND) + if(OpenGL_EGL_FOUND) + set(HAVE_EGL TRUE) + endif() + if(OpenGL_GLX_FOUND) + set(HAVE_GLX TRUE) + endif() + + if(OPENGL_FOUND AND HAVE_GLX) set(HAVE_OPENGL TRUE) if(QT_QTOPENGL_FOUND) set(HAVE_QT_OPENGL TRUE) @@ -72,9 +79,6 @@ if(WITH_OPENGL) ocv_include_directories(${OPENGL_INCLUDE_DIR}) endif() endif() - if(OpenGL_EGL_FOUND) - set(HAVE_EGL TRUE) - endif() endif() endif(WITH_OPENGL) diff --git a/modules/highgui/cmake/detect_gtk.cmake b/modules/highgui/cmake/detect_gtk.cmake index c58246ac54..add4117c2c 100644 --- a/modules/highgui/cmake/detect_gtk.cmake +++ b/modules/highgui/cmake/detect_gtk.cmake @@ -38,7 +38,7 @@ endif() if(WITH_OPENGL AND HAVE_GTKGLEXT) find_package(OpenGL QUIET) - if(OPENGL_FOUND) + if(OPENGL_FOUND AND HAVE_GLX) set(HAVE_OPENGL TRUE) ocv_add_external_target(gtk_opengl "${OPENGL_INCLUDE_DIRS}" "${OPENGL_LIBRARIES}" "HAVE_OPENGL") endif() From a1010638c66c0c1463f19e82ab5ef47eec667c49 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Wed, 23 Nov 2022 19:36:26 +0100 Subject: [PATCH 06/11] move gtk detection-code into OpenCVFindLibsGUI.cmake (like QT) to enable proper detection of OpenGL support --- cmake/OpenCVFindLibsGUI.cmake | 50 ++++++++++++++++++++++++-- modules/highgui/cmake/detect_gtk.cmake | 45 ----------------------- modules/highgui/cmake/init.cmake | 2 +- 3 files changed, 48 insertions(+), 49 deletions(-) delete mode 100644 modules/highgui/cmake/detect_gtk.cmake diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 79758fa813..6ddcca299d 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -59,12 +59,56 @@ if(WITH_QT) endif() endif() +# --- GTK --- +ocv_clear_vars(HAVE_GTK HAVE_GTK2 HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) +if(WITH_GTK) + if(NOT WITH_GTK_2_X) + ocv_check_modules(GTK3 gtk+-3.0) + if(HAVE_GTK3) + ocv_add_external_target(gtk3 "${GTK3_INCLUDE_DIRS}" "${GTK3_LIBRARIES}" "HAVE_GTK3;HAVE_GTK") + set(HAVE_GTK TRUE) + endif() + endif() + if((PROJECT_NAME STREQUAL "OpenCV" AND HIGHGUI_ENABLE_PLUGINS) OR NOT HAVE_GTK3) + ocv_check_modules(GTK2 gtk+-2.0) + if(HAVE_GTK2) + set(MIN_VER_GTK "2.18.0") + if(GTK2_VERSION VERSION_LESS MIN_VER_GTK) + message(FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${GTK2_VERSION} found)") + else() + ocv_add_external_target(gtk2 "${GTK2_INCLUDE_DIRS}" "${GTK2_LIBRARIES}" "HAVE_GTK2;HAVE_GTK") + set(HAVE_GTK TRUE) + endif() + endif() + endif() + ocv_check_modules(GTHREAD gthread-2.0) + if(HAVE_GTK AND NOT HAVE_GTHREAD) + message(FATAL_ERROR "gthread not found. This library is required when building with GTK support") + else() + ocv_add_external_target(gthread "${GTHREAD_INCLUDE_DIRS}" "${GTHREAD_LIBRARIES}" "HAVE_GTHREAD") + endif() + if((WITH_OPENGL OR HAVE_OPENGL) AND HAVE_GTK2) + ocv_check_modules(GTKGLEXT gtkglext-1.0) + if(HAVE_GTKGLEXT) + ocv_add_external_target(gtkglext "${GTKGLEXT_INCLUDE_DIRS}" "${GTKGLEXT_LIBRARIES}" "HAVE_GTKGLEXT") + endif() + endif() +elseif(HAVE_GTK) + ocv_add_external_target(gtk "${GTK_INCLUDE_DIRS}" "${GTK_LIBRARIES}" "${GTK_DEFINES};HAVE_GTK") +endif() + # --- OpenGl --- ocv_clear_vars(HAVE_OPENGL HAVE_QT_OPENGL) if(WITH_OPENGL) - if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR HAVE_GTKGLEXT) - find_package (OpenGL QUIET) - if(OPENGL_FOUND) + find_package (OpenGL QUIET) + if(OpenGL_EGL_FOUND) + set(HAVE_EGL TRUE) + endif() + if(OpenGL_GLX_FOUND) + set(HAVE_GLX TRUE) + endif() + if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR (HAVE_GTKGLEXT AND HAVE_GLX)) + if(OPENGL_FOUND AND (HAVE_GLX OR HAVE_EGL)) set(HAVE_OPENGL TRUE) if(QT_QTOPENGL_FOUND) set(HAVE_QT_OPENGL TRUE) diff --git a/modules/highgui/cmake/detect_gtk.cmake b/modules/highgui/cmake/detect_gtk.cmake deleted file mode 100644 index c58246ac54..0000000000 --- a/modules/highgui/cmake/detect_gtk.cmake +++ /dev/null @@ -1,45 +0,0 @@ -# --- GTK --- -ocv_clear_vars(HAVE_GTK HAVE_GTK2 HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) -if(WITH_GTK) - if(NOT WITH_GTK_2_X) - ocv_check_modules(GTK3 gtk+-3.0) - if(HAVE_GTK3) - ocv_add_external_target(gtk3 "${GTK3_INCLUDE_DIRS}" "${GTK3_LIBRARIES}" "HAVE_GTK3;HAVE_GTK") - set(HAVE_GTK TRUE) - endif() - endif() - if((PROJECT_NAME STREQUAL "OpenCV" AND HIGHGUI_ENABLE_PLUGINS) OR NOT HAVE_GTK3) - ocv_check_modules(GTK2 gtk+-2.0) - if(HAVE_GTK2) - set(MIN_VER_GTK "2.18.0") - if(GTK2_VERSION VERSION_LESS MIN_VER_GTK) - message(FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${GTK2_VERSION} found)") - else() - ocv_add_external_target(gtk2 "${GTK2_INCLUDE_DIRS}" "${GTK2_LIBRARIES}" "HAVE_GTK2;HAVE_GTK") - set(HAVE_GTK TRUE) - endif() - endif() - endif() - ocv_check_modules(GTHREAD gthread-2.0) - if(HAVE_GTK AND NOT HAVE_GTHREAD) - message(FATAL_ERROR "gthread not found. This library is required when building with GTK support") - else() - ocv_add_external_target(gthread "${GTHREAD_INCLUDE_DIRS}" "${GTHREAD_LIBRARIES}" "HAVE_GTHREAD") - endif() - if((WITH_OPENGL OR HAVE_OPENGL) AND HAVE_GTK2) - ocv_check_modules(GTKGLEXT gtkglext-1.0) - if(HAVE_GTKGLEXT) - ocv_add_external_target(gtkglext "${GTKGLEXT_INCLUDE_DIRS}" "${GTKGLEXT_LIBRARIES}" "HAVE_GTKGLEXT") - endif() - endif() -elseif(HAVE_GTK) - ocv_add_external_target(gtk "${GTK_INCLUDE_DIRS}" "${GTK_LIBRARIES}" "${GTK_DEFINES};HAVE_GTK") -endif() - -if(WITH_OPENGL AND HAVE_GTKGLEXT) - find_package(OpenGL QUIET) - if(OPENGL_FOUND) - set(HAVE_OPENGL TRUE) - ocv_add_external_target(gtk_opengl "${OPENGL_INCLUDE_DIRS}" "${OPENGL_LIBRARIES}" "HAVE_OPENGL") - endif() -endif() diff --git a/modules/highgui/cmake/init.cmake b/modules/highgui/cmake/init.cmake index 49d4799b30..2ce66789e6 100644 --- a/modules/highgui/cmake/init.cmake +++ b/modules/highgui/cmake/init.cmake @@ -36,10 +36,10 @@ macro(add_backend backend_id cond_var) endif() endmacro() -add_backend("gtk" WITH_GTK) add_backend("win32ui" WITH_WIN32UI) add_backend("wayland" WITH_WAYLAND) # TODO cocoa +# TODO gtk # TODO qt # TODO opengl From 13bbd26fdc70a8f23a69cd077cf16878498abdaf Mon Sep 17 00:00:00 2001 From: kallaballa Date: Thu, 26 Oct 2023 07:16:38 +0200 Subject: [PATCH 07/11] ported latest EGL/OpenGL changes proper branch --- CMakeLists.txt | 72 +++++++++++++++++++------- cmake/OpenCVFindLibsGUI.cmake | 60 +++++---------------- modules/core/src/opengl.cpp | 65 +++++++++++++++-------- modules/highgui/cmake/detect_gtk.cmake | 45 ++++++++++++++++ 4 files changed, 153 insertions(+), 89 deletions(-) create mode 100644 modules/highgui/cmake/detect_gtk.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fef3ce0ba..b2d4b4ad75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,10 @@ if(POLICY CMP0077) cmake_policy(SET CMP0077 NEW) # CMake 3.13+: option() honors normal variables. endif() +if(POLICY CMP0146) + cmake_policy(SET CMP0146 OLD) # CMake 3.27+: use CMake FindCUDA if available. +endif() + # # Configure OpenCV CMake hooks # @@ -240,6 +244,8 @@ OCV_OPTION(WITH_1394 "Include IEEE1394 support" ON OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/Mac)" ON VISIBLE_IF APPLE VERIFY HAVE_AVFOUNDATION) +OCV_OPTION(WITH_AVIF "Enable AVIF support" OFF + VERIFY HAVE_AVIF) OCV_OPTION(WITH_CAP_IOS "Enable iOS video capture" ON VISIBLE_IF IOS VERIFY HAVE_CAP_IOS) @@ -263,10 +269,10 @@ OCV_OPTION(WITH_CUBLAS "Include NVidia Cuda Basic Linear Algebra Subprograms (BL OCV_OPTION(WITH_CUDNN "Include NVIDIA CUDA Deep Neural Network (cuDNN) library support" WITH_CUDA VISIBLE_IF WITH_CUDA VERIFY HAVE_CUDNN) -OCV_OPTION(WITH_NVCUVID "Include NVidia Video Decoding library support" OFF # disabled, details: https://github.com/opencv/opencv/issues/14850 +OCV_OPTION(WITH_NVCUVID "Include NVidia Video Decoding library support" ON VISIBLE_IF WITH_CUDA VERIFY HAVE_NVCUVID) -OCV_OPTION(WITH_NVCUVENC "Include NVidia Video Encoding library support" OFF +OCV_OPTION(WITH_NVCUVENC "Include NVidia Video Encoding library support" ON VISIBLE_IF WITH_CUDA VERIFY HAVE_NVCUVENC) OCV_OPTION(WITH_EIGEN "Include Eigen2/Eigen3 support" (NOT CV_DISABLE_OPTIMIZATION AND NOT CMAKE_CROSSCOMPILING) @@ -320,11 +326,9 @@ OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ((WIN32 OR ANDROID OR VERIFY HAVE_OPENEXR) OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF VISIBLE_IF NOT ANDROID AND NOT WINRT - VERIFY HAVE_OPENGL AND HAVE_GLX + VERIFY HAVE_OPENGL + AND HAVE_GLX OR HAVE_EGL OR HAVE_CGL ) -OCV_OPTION(OPENCV_ENABLE_EGL_INTEROP "Enable support for EGL based OpenGL interop" OFF - VISIBLE_IF WITH_OPENGL - VERIFY HAVE_EGL) OCV_OPTION(WITH_OPENVX "Include OpenVX support" OFF VISIBLE_IF TRUE VERIFY HAVE_OPENVX) @@ -460,9 +464,6 @@ OCV_OPTION(WITH_ANDROID_MEDIANDK "Use Android Media NDK for Video I/O (Android)" OCV_OPTION(WITH_ANDROID_NATIVE_CAMERA "Use Android NDK for Camera I/O (Android)" (ANDROID_NATIVE_API_LEVEL GREATER 23) VISIBLE_IF ANDROID VERIFY HAVE_ANDROID_NATIVE_CAMERA) -OCV_OPTION(WITH_TENGINE "Include Arm Inference Tengine support" OFF - VISIBLE_IF (ARM OR AARCH64) AND (UNIX OR ANDROID) AND NOT IOS - VERIFY HAVE_TENGINE) OCV_OPTION(WITH_ONNX "Include Microsoft ONNX Runtime support" OFF VISIBLE_IF TRUE VERIFY HAVE_ONNX) @@ -472,6 +473,12 @@ OCV_OPTION(WITH_TIMVX "Include Tim-VX support" OFF OCV_OPTION(WITH_OBSENSOR "Include obsensor support (Orbbec RGB-D modules: Astra+/Femto)" ON VISIBLE_IF (WIN32 AND NOT ARM AND NOT WINRT) OR ( UNIX AND NOT APPLE AND NOT ANDROID) VERIFY HAVE_OBSENSOR) +OCV_OPTION(WITH_CANN "Include CANN support" OFF + VISIBLE_IF TRUE + VERIFY HAVE_CANN) +OCV_OPTION(WITH_FLATBUFFERS "Include Flatbuffers support (required by DNN/TFLite importer)" ON + VISIBLE_IF TRUE + VERIFY HAVE_FLATBUFFERS) # OpenCV build components # =================================================== @@ -509,6 +516,7 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar # =================================================== OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja" OR CMAKE_GENERATOR MATCHES "Xcode")) ) OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" MSVC IF (MSVC OR (NOT IOS AND NOT CMAKE_CROSSCOMPILING) ) ) +OCV_OPTION(ENABLE_DELAYLOAD "Enable delayed loading of OpenCV DLLs" OFF VISIBLE_IF MSVC AND BUILD_SHARED_LIBS) OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) ) OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CV_GCC ) OCV_OPTION(ENABLE_COVERAGE "Enable coverage collection with GCov" OFF IF CV_GCC ) @@ -751,12 +759,13 @@ include(cmake/OpenCVFindLibsVideo.cmake) include(cmake/OpenCVFindLibsPerf.cmake) include(cmake/OpenCVFindLAPACK.cmake) include(cmake/OpenCVFindProtobuf.cmake) -if(WITH_TENGINE) - include(cmake/OpenCVFindTengine.cmake) -endif() +include(cmake/OpenCVDetectFlatbuffers.cmake) if(WITH_TIMVX) include(cmake/OpenCVFindTIMVX.cmake) endif() +if(WITH_CANN) + include(cmake/OpenCVFindCANN.cmake) +endif() # ---------------------------------------------------------------------------- # Detect other 3rd-party libraries/tools @@ -768,6 +777,15 @@ if(BUILD_JAVA) include(cmake/android/OpenCVDetectAndroidSDK.cmake) else() include(cmake/OpenCVDetectApacheAnt.cmake) + if(ANT_EXECUTABLE AND NOT OPENCV_JAVA_IGNORE_ANT) + ocv_update(OPENCV_JAVA_SDK_BUILD_TYPE "ANT") + elseif(NOT ANDROID) + find_package(Java) + if(Java_FOUND) + include(UseJava) + ocv_update(OPENCV_JAVA_SDK_BUILD_TYPE "JAVA") + endif() + endif() find_package(JNI) endif() endif() @@ -910,7 +928,7 @@ foreach(hal ${OpenCV_HAL}) endif() endif() endforeach() -configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/custom_hal.hpp.in" "${CMAKE_BINARY_DIR}/custom_hal.hpp" @ONLY) +configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/custom_hal.hpp.in" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/custom_hal.hpp" @ONLY) unset(_hal_includes) @@ -1380,6 +1398,14 @@ if(WITH_WEBP OR HAVE_WEBP) status(" WEBP:" WEBP_FOUND THEN "${WEBP_LIBRARY} (ver ${WEBP_VERSION})" ELSE "build (ver ${WEBP_VERSION})") endif() +if(WITH_AVIF OR HAVE_AVIF) + if(AVIF_VERSION) + status(" AVIF:" AVIF_FOUND THEN "${AVIF_LIBRARY} (ver ${AVIF_VERSION})" ELSE "NO") + else() + status(" AVIF:" AVIF_FOUND THEN "${AVIF_LIBRARY}" ELSE "NO") + endif() +endif() + if(WITH_PNG OR HAVE_PNG OR WITH_SPNG) if(WITH_SPNG) status(" PNG:" "build-${SPNG_LIBRARY} (ver ${SPNG_VERSION})") @@ -1590,10 +1616,6 @@ if(WITH_VA OR HAVE_VA) status(" VA:" HAVE_VA THEN "YES" ELSE NO) endif() -if(WITH_TENGINE OR HAVE_TENGINE) - status(" Tengine:" HAVE_TENGINE THEN "YES (${TENGINE_LIBRARIES})" ELSE NO) -endif() - if(WITH_LAPACK OR HAVE_LAPACK) status(" Lapack:" HAVE_LAPACK THEN "YES (${LAPACK_LIBRARIES})" ELSE NO) endif() @@ -1660,6 +1682,10 @@ else() endif() endif() +if(BUILD_opencv_dnn AND OPENCV_DNN_BACKEND_DEFAULT) + status(" Default DNN backend:" ${OPENCV_DNN_BACKEND_DEFAULT}) +endif() + if(WITH_EIGEN OR HAVE_EIGEN) status(" Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO) endif() @@ -1748,6 +1774,15 @@ if(WITH_ONNX OR HAVE_ONNX) endif() endif() +if(WITH_CANN) + status("") + status(" CANN:" HAVE_CANN THEN "YES" ELSE "NO") + if(HAVE_CANN) + status(" Include path" CANN_INCLUDE_DIRS THEN "${CANN_INCLUDE_DIRS}" ELSE "NO") + status(" Link libraries:" CANN_LIBRARIES THEN "${CANN_LIBRARIES}" ELSE "NO") + endif() +endif() + # ========================== python ========================== if(BUILD_opencv_python2) status("") @@ -1784,9 +1819,10 @@ if(BUILD_JAVA) status(" Java:" BUILD_FAT_JAVA_LIB THEN "export all functions" ELSE "") status(" ant:" ANT_EXECUTABLE THEN "${ANT_EXECUTABLE} (ver ${ANT_VERSION})" ELSE NO) if(NOT ANDROID) + status(" Java:" Java_FOUND THEN "YES (ver ${Java_VERSION})" ELSE NO) status(" JNI:" JNI_INCLUDE_DIRS THEN "${JNI_INCLUDE_DIRS}" ELSE NO) endif() - status(" Java wrappers:" HAVE_opencv_java THEN YES ELSE NO) + status(" Java wrappers:" HAVE_opencv_java THEN "YES (${OPENCV_JAVA_SDK_BUILD_TYPE})" ELSE NO) status(" Java tests:" BUILD_TESTS AND opencv_test_java_BINARY_DIR THEN YES ELSE NO) endif() diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 6ddcca299d..361c11ba56 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -59,56 +59,20 @@ if(WITH_QT) endif() endif() -# --- GTK --- -ocv_clear_vars(HAVE_GTK HAVE_GTK2 HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) -if(WITH_GTK) - if(NOT WITH_GTK_2_X) - ocv_check_modules(GTK3 gtk+-3.0) - if(HAVE_GTK3) - ocv_add_external_target(gtk3 "${GTK3_INCLUDE_DIRS}" "${GTK3_LIBRARIES}" "HAVE_GTK3;HAVE_GTK") - set(HAVE_GTK TRUE) - endif() - endif() - if((PROJECT_NAME STREQUAL "OpenCV" AND HIGHGUI_ENABLE_PLUGINS) OR NOT HAVE_GTK3) - ocv_check_modules(GTK2 gtk+-2.0) - if(HAVE_GTK2) - set(MIN_VER_GTK "2.18.0") - if(GTK2_VERSION VERSION_LESS MIN_VER_GTK) - message(FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${GTK2_VERSION} found)") - else() - ocv_add_external_target(gtk2 "${GTK2_INCLUDE_DIRS}" "${GTK2_LIBRARIES}" "HAVE_GTK2;HAVE_GTK") - set(HAVE_GTK TRUE) - endif() - endif() - endif() - ocv_check_modules(GTHREAD gthread-2.0) - if(HAVE_GTK AND NOT HAVE_GTHREAD) - message(FATAL_ERROR "gthread not found. This library is required when building with GTK support") - else() - ocv_add_external_target(gthread "${GTHREAD_INCLUDE_DIRS}" "${GTHREAD_LIBRARIES}" "HAVE_GTHREAD") - endif() - if((WITH_OPENGL OR HAVE_OPENGL) AND HAVE_GTK2) - ocv_check_modules(GTKGLEXT gtkglext-1.0) - if(HAVE_GTKGLEXT) - ocv_add_external_target(gtkglext "${GTKGLEXT_INCLUDE_DIRS}" "${GTKGLEXT_LIBRARIES}" "HAVE_GTKGLEXT") - endif() - endif() -elseif(HAVE_GTK) - ocv_add_external_target(gtk "${GTK_INCLUDE_DIRS}" "${GTK_LIBRARIES}" "${GTK_DEFINES};HAVE_GTK") -endif() - # --- OpenGl --- +set(OpenGL_GL_PREFERENCE GLVND) ocv_clear_vars(HAVE_OPENGL HAVE_QT_OPENGL) if(WITH_OPENGL) - find_package (OpenGL QUIET) - if(OpenGL_EGL_FOUND) - set(HAVE_EGL TRUE) - endif() - if(OpenGL_GLX_FOUND) - set(HAVE_GLX TRUE) - endif() - if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR (HAVE_GTKGLEXT AND HAVE_GLX)) - if(OPENGL_FOUND AND (HAVE_GLX OR HAVE_EGL)) + if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR HAVE_GTKGLEXT OR EMSCRIPTEN OR APPLE) + find_package (OpenGL QUIET) + if(OpenGL_EGL_FOUND) + set(HAVE_EGL TRUE AND OPENCV_ENABLE_EGL) + endif() + if(OpenGL_GLX_FOUND AND OPENCV_ENABLE_GLX) + set(HAVE_GLX TRUE) + endif() + + if(OPENGL_FOUND AND (HAVE_GLX OR HAVE_EGL OR EMSCRIPTEN)) set(HAVE_OPENGL TRUE) if(QT_QTOPENGL_FOUND) set(HAVE_QT_OPENGL TRUE) @@ -116,7 +80,7 @@ if(WITH_OPENGL) ocv_include_directories(${OPENGL_INCLUDE_DIR}) endif() endif() - endif() +endif() endif(WITH_OPENGL) # --- Cocoa --- diff --git a/modules/core/src/opengl.cpp b/modules/core/src/opengl.cpp index 0e3b1794b1..9792b11021 100644 --- a/modules/core/src/opengl.cpp +++ b/modules/core/src/opengl.cpp @@ -1587,10 +1587,15 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala #endif // HAVE_OPENCL #if defined(HAVE_OPENGL) -# if defined(__ANDROID__) || defined(HAVE_EGL_INTEROP) +# if defined(__ANDROID__) # include # elif defined(__linux__) -# include +# if defined(OPENCV_ENABLE_EGL) +# include +# endif +# if defined(OPENCV_ENABLE_GLX) +# include +# endif # endif #endif // HAVE_OPENGL @@ -1638,14 +1643,14 @@ Context& initializeContextFromGL() cl_uint numPlatforms; cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't get number of platforms"); + CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: Can't get number of platforms: %d", status)); if (numPlatforms == 0) CV_Error(cv::Error::OpenCLInitError, "OpenCL: No available platforms"); std::vector platforms(numPlatforms); status = clGetPlatformIDs(numPlatforms, &platforms[0], NULL); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't get number of platforms"); + CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: Can't get number of platforms: %d", status)); // TODO Filter platforms by name from OPENCV_OPENCL_DEVICE @@ -1667,7 +1672,7 @@ Context& initializeContextFromGL() status = clGetPlatformInfo(platforms[i], CL_PLATFORM_EXTENSIONS, extensionSize, (char*)extensionStr.data(), NULL); } if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't get platform extension string"); + CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: Can't get platform extension string: %d", status)); if (!strstr((const char*)extensionStr.data(), "cl_khr_gl_sharing")) continue; @@ -1684,18 +1689,32 @@ Context& initializeContextFromGL() CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), -#elif defined(__ANDROID__) || defined(HAVE_EGL_INTEROP) +#elif defined(__ANDROID__) CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], CL_GL_CONTEXT_KHR, (cl_context_properties)eglGetCurrentContext(), CL_EGL_DISPLAY_KHR, (cl_context_properties)eglGetCurrentDisplay(), #elif defined(__linux__) +# if defined(OPENCV_ENABLE_EGL) // prefer EGL + CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], + CL_GL_CONTEXT_KHR, (cl_context_properties)eglGetCurrentContext(), + CL_EGL_DISPLAY_KHR, (cl_context_properties)eglGetCurrentDisplay(), +# elif defined(OPENCV_ENABLE_GLX) CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i], CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(), CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(), +# endif #endif 0 }; +#if defined(OPENCV_ENABLE_EGL) && defined(OPENCV_ENABLE_GLX) //GLX fallback + if(properties[4] == CL_EGL_DISPLAY_KHR && properties[3] == (cl_context_properties)EGL_NO_CONTEXT) { + properties[3] = (cl_context_properties)glXGetCurrentContext(); + properties[4] = (cl_context_properties)CL_GLX_DISPLAY_KHR; + properties[5] = (cl_context_properties)glXGetCurrentDisplay(); + } +#endif + // query device device = NULL; status = clGetGLContextInfoKHR(properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof(cl_device_id), (void*)&device, NULL); @@ -1759,31 +1778,31 @@ void convertToGLTexture2D(InputArray src, Texture2D& texture) cl_int status = 0; cl_mem clImage = clCreateFromGLTexture(context, CL_MEM_WRITE_ONLY, gl::TEXTURE_2D, 0, texture.texId(), &status); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromGLTexture failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clCreateFromGLTexture failed: %d", status)); cl_mem clBuffer = (cl_mem)u.handle(ACCESS_READ); cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr(); status = clEnqueueAcquireGLObjects(q, 1, &clImage, 0, NULL, NULL); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireGLObjects failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clEnqueueAcquireGLObjects failed: %d", status)); size_t offset = 0; // TODO size_t dst_origin[3] = {0, 0, 0}; size_t region[3] = { (size_t)u.cols, (size_t)u.rows, 1}; status = clEnqueueCopyBufferToImage(q, clBuffer, clImage, offset, dst_origin, region, 0, NULL, NULL); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueCopyBufferToImage failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clEnqueueCopyBufferToImage failed: %d", status)); status = clEnqueueReleaseGLObjects(q, 1, &clImage, 0, NULL, NULL); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseGLObjects failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clEnqueueReleaseGLObjects failed: %d", status)); status = clFinish(q); // TODO Use events if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clFinish failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clFinish failed: %d", status)); status = clReleaseMemObject(clImage); // TODO RAII if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMemObject failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clReleaseMemObject failed: %d", status)); #endif } @@ -1821,31 +1840,31 @@ void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst) cl_int status = 0; cl_mem clImage = clCreateFromGLTexture(context, CL_MEM_READ_ONLY, gl::TEXTURE_2D, 0, texture.texId(), &status); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromGLTexture failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clCreateFromGLTexture failed: %d", status)); cl_mem clBuffer = (cl_mem)u.handle(ACCESS_READ); cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr(); status = clEnqueueAcquireGLObjects(q, 1, &clImage, 0, NULL, NULL); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireGLObjects failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clEnqueueAcquireGLObjects failed: %d", status)); size_t offset = 0; // TODO size_t src_origin[3] = {0, 0, 0}; size_t region[3] = { (size_t)u.cols, (size_t)u.rows, 1}; status = clEnqueueCopyImageToBuffer(q, clImage, clBuffer, src_origin, region, offset, 0, NULL, NULL); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueCopyImageToBuffer failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clEnqueueCopyImageToBuffer failed: %d", status)); status = clEnqueueReleaseGLObjects(q, 1, &clImage, 0, NULL, NULL); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseGLObjects failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clEnqueueReleaseGLObjects failed: %d", status)); status = clFinish(q); // TODO Use events if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clFinish failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clFinish failed: %d", status)); status = clReleaseMemObject(clImage); // TODO RAII if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMemObject failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clReleaseMemObject failed: %d", status)); #endif } @@ -1883,13 +1902,13 @@ UMat mapGLBuffer(const Buffer& buffer, AccessFlag accessFlags) cl_int status = 0; cl_mem clBuffer = clCreateFromGLBuffer(context, clAccessFlags, buffer.bufId(), &status); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromGLBuffer failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clCreateFromGLBuffer failed: %d", status)); gl::Finish(); status = clEnqueueAcquireGLObjects(clQueue, 1, &clBuffer, 0, NULL, NULL); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireGLObjects failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clEnqueueAcquireGLObjects failed: %d", status)); size_t step = buffer.cols() * buffer.elemSize(); int rows = buffer.rows(); @@ -1921,15 +1940,15 @@ void unmapGLBuffer(UMat& u) cl_int status = clEnqueueReleaseGLObjects(clQueue, 1, &clBuffer, 0, NULL, NULL); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseGLObjects failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clEnqueueReleaseGLObjects failed: %d", status)); status = clFinish(clQueue); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clFinish failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clFinish failed: %d", status)); status = clReleaseMemObject(clBuffer); if (status != CL_SUCCESS) - CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMemObject failed"); + CV_Error_(cv::Error::OpenCLApiCallError, ("OpenCL: clReleaseMemObject failed: %d", status)); #endif } diff --git a/modules/highgui/cmake/detect_gtk.cmake b/modules/highgui/cmake/detect_gtk.cmake new file mode 100644 index 0000000000..a25f590183 --- /dev/null +++ b/modules/highgui/cmake/detect_gtk.cmake @@ -0,0 +1,45 @@ +# --- GTK --- +ocv_clear_vars(HAVE_GTK HAVE_GTK2 HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) +if(WITH_GTK) + if(NOT WITH_GTK_2_X) + ocv_check_modules(GTK3 gtk+-3.0) + if(HAVE_GTK3) + ocv_add_external_target(gtk3 "${GTK3_INCLUDE_DIRS}" "${GTK3_LIBRARIES}" "HAVE_GTK3;HAVE_GTK") + set(HAVE_GTK TRUE) + endif() + endif() + if((PROJECT_NAME STREQUAL "OpenCV" AND HIGHGUI_ENABLE_PLUGINS) OR NOT HAVE_GTK3) + ocv_check_modules(GTK2 gtk+-2.0) + if(HAVE_GTK2) + set(MIN_VER_GTK "2.18.0") + if(GTK2_VERSION VERSION_LESS MIN_VER_GTK) + message(FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${GTK2_VERSION} found)") + else() + ocv_add_external_target(gtk2 "${GTK2_INCLUDE_DIRS}" "${GTK2_LIBRARIES}" "HAVE_GTK2;HAVE_GTK") + set(HAVE_GTK TRUE) + endif() + endif() + endif() + ocv_check_modules(GTHREAD gthread-2.0>=2.32) + if(HAVE_GTK AND NOT HAVE_GTHREAD) + message(FATAL_ERROR "gthread not found. This library is required when building with GTK support") + else() + ocv_add_external_target(gthread "${GTHREAD_INCLUDE_DIRS}" "${GTHREAD_LIBRARIES}" "HAVE_GTHREAD") + endif() + if((WITH_OPENGL OR HAVE_OPENGL) AND HAVE_GTK2) + ocv_check_modules(GTKGLEXT gtkglext-1.0) + if(HAVE_GTKGLEXT) + ocv_add_external_target(gtkglext "${GTKGLEXT_INCLUDE_DIRS}" "${GTKGLEXT_LIBRARIES}" "HAVE_GTKGLEXT") + endif() + endif() +elseif(HAVE_GTK) + ocv_add_external_target(gtk "${GTK_INCLUDE_DIRS}" "${GTK_LIBRARIES}" "${GTK_DEFINES};HAVE_GTK") +endif() + +if(WITH_OPENGL AND HAVE_GTKGLEXT) + find_package(OpenGL QUIET) + if(OPENGL_FOUND AND (HAVE_GLX OR HAVE_EGL)) + set(HAVE_OPENGL TRUE) + ocv_add_external_target(gtk_opengl "${OPENGL_INCLUDE_DIRS}" "${OPENGL_LIBRARIES}" "HAVE_OPENGL") + endif() +endif() From 27f612e8b08f1cdf1d9cdc16b78d8456466378c8 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Thu, 26 Oct 2023 07:22:03 +0200 Subject: [PATCH 08/11] recover gtk plugins --- modules/highgui/cmake/init.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/cmake/init.cmake b/modules/highgui/cmake/init.cmake index 2ce66789e6..49d4799b30 100644 --- a/modules/highgui/cmake/init.cmake +++ b/modules/highgui/cmake/init.cmake @@ -36,10 +36,10 @@ macro(add_backend backend_id cond_var) endif() endmacro() +add_backend("gtk" WITH_GTK) add_backend("win32ui" WITH_WIN32UI) add_backend("wayland" WITH_WAYLAND) # TODO cocoa -# TODO gtk # TODO qt # TODO opengl From 78d50d0970408ee26a33737b6741672436f9aa47 Mon Sep 17 00:00:00 2001 From: Amir Hassan Date: Thu, 2 Jan 2025 08:43:51 +0100 Subject: [PATCH 09/11] Removed obsolete code --- modules/core/src/opengl.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/core/src/opengl.cpp b/modules/core/src/opengl.cpp index 121e63e875..0b6c29189c 100644 --- a/modules/core/src/opengl.cpp +++ b/modules/core/src/opengl.cpp @@ -1790,12 +1790,6 @@ Context& initializeContextFromGL() context = clCreateContext(props, 1, &devices[devUsed], NULL, NULL, &status); #endif - // query device - device = NULL; - status = clGetGLContextInfoKHR(properties, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, sizeof(cl_device_id), (void*)&device, NULL); - if (status != CL_SUCCESS) - continue; - if (status != CL_SUCCESS) CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: Can't create context for OpenGL interop: %d", status)); else From 66f9b6ffe0ae09c4055c9d668b0494e3bc08359f Mon Sep 17 00:00:00 2001 From: kallaballa Date: Fri, 3 Jan 2025 09:29:44 +0100 Subject: [PATCH 10/11] opengl.cpp: fixed macro flow --- modules/core/src/opengl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/core/src/opengl.cpp b/modules/core/src/opengl.cpp index 0b6c29189c..0c1d9e46aa 100644 --- a/modules/core/src/opengl.cpp +++ b/modules/core/src/opengl.cpp @@ -1776,10 +1776,8 @@ Context& initializeContextFromGL() CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(), CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(), # endif -#endif 0 }; - # if defined(OPENCV_ENABLE_EGL) && defined(OPENCV_ENABLE_GLX) //GLX fallback if(properties[4] == CL_EGL_DISPLAY_KHR && properties[3] == (cl_context_properties)EGL_NO_CONTEXT) { properties[3] = (cl_context_properties)glXGetCurrentContext(); @@ -1794,6 +1792,7 @@ Context& initializeContextFromGL() CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: Can't create context for OpenGL interop: %d", status)); else break; + } } From 3b3f415af86513c9a126168f7c77cf2e54be9ea2 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 12 May 2025 19:00:08 +0300 Subject: [PATCH 11/11] Simplified cmake checks to presume existing behaviour. --- CMakeLists.txt | 2 +- cmake/OpenCVFindLibsGUI.cmake | 7 +++---- modules/core/CMakeLists.txt | 6 +++++- modules/highgui/cmake/detect_gtk.cmake | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c38c6ec9df..4c764f4838 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -318,7 +318,7 @@ OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ((WIN32 OR ANDROID OR OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF VISIBLE_IF NOT ANDROID AND NOT WINRT VERIFY HAVE_OPENGL - AND HAVE_GLX OR HAVE_EGL OR HAVE_CGL + AND HAVE_GLX OR HAVE_EGL ) OCV_OPTION(WITH_OPENVX "Include OpenVX support" OFF VISIBLE_IF TRUE diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 2e02d3e78d..b5d89ef6db 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -67,12 +67,11 @@ if(WITH_OPENGL) find_package (OpenGL QUIET) if(OpenGL_EGL_FOUND) set(HAVE_EGL TRUE AND OPENCV_ENABLE_EGL) - endif() - if(OpenGL_GLX_FOUND AND OPENCV_ENABLE_GLX) + else() set(HAVE_GLX TRUE) endif() - if(OPENGL_FOUND AND (HAVE_GLX OR HAVE_EGL OR EMSCRIPTEN)) + if(OPENGL_FOUND) set(HAVE_OPENGL TRUE) if(QT_QTOPENGL_FOUND) set(HAVE_QT_OPENGL TRUE) @@ -80,7 +79,7 @@ if(WITH_OPENGL) ocv_include_directories(${OPENGL_INCLUDE_DIR}) endif() endif() -endif() + endif() endif(WITH_OPENGL) # --- Cocoa --- diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 20a4173017..71007dc2f3 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -170,12 +170,16 @@ ocv_create_module(${extra_libs}) ocv_target_link_libraries(${the_module} PRIVATE "${ZLIB_LIBRARIES}" "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" - "${OPENGL_LIBRARIES}" "${OPENGL_egl_LIBRARY}" + "${OPENGL_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}" "${ITT_LIBRARIES}" "${OPENCV_HAL_LINKER_LIBS}" ) +if (OPENCV_ENABLE_EGL_INTEROP) + ocv_target_link_libraries(${the_module} PRIVATE "${OPENGL_egl_LIBRARY}") +endif() + if(OPENCV_CORE_EXCLUDE_C_API) ocv_target_compile_definitions(${the_module} PRIVATE "OPENCV_EXCLUDE_C_API=1") endif() diff --git a/modules/highgui/cmake/detect_gtk.cmake b/modules/highgui/cmake/detect_gtk.cmake index ccf2b8dffd..e41da1c68e 100644 --- a/modules/highgui/cmake/detect_gtk.cmake +++ b/modules/highgui/cmake/detect_gtk.cmake @@ -42,7 +42,7 @@ endif() if(WITH_OPENGL) find_package(OpenGL QUIET) - if(OPENGL_FOUND AND (HAVE_GLX OR HAVE_EGL)) + if(OPENGL_FOUND) set(HAVE_OPENGL TRUE) ocv_add_external_target(gtk_opengl "${OPENGL_INCLUDE_DIRS}" "${OPENGL_LIBRARIES}" "HAVE_OPENGL") endif()