This commit is contained in:
Amir Hassan 2025-06-02 14:55:47 +02:00 committed by GitHub
commit 5b80385c04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 8 deletions

View File

@ -317,7 +317,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)
VERIFY HAVE_OPENGL
AND HAVE_GLX OR HAVE_EGL
)
OCV_OPTION(WITH_OPENVX "Include OpenVX support" OFF
VISIBLE_IF TRUE
VERIFY HAVE_OPENVX)
@ -1481,6 +1483,14 @@ 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()
if(WITH_VTK OR HAVE_VTK)
status(" VTK support:" HAVE_VTK THEN "YES (ver ${VTK_VERSION})" ELSE NO)
endif()

View File

@ -65,6 +65,12 @@ ocv_clear_vars(HAVE_OPENGL HAVE_QT_OPENGL)
if(WITH_OPENGL)
if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR HAVE_GTK3 OR (HAVE_GTK AND NOT HAVE_GTK3 AND HAVE_GTKGLEXT))
find_package (OpenGL QUIET)
if(OpenGL_EGL_FOUND)
set(HAVE_EGL TRUE AND OPENCV_ENABLE_EGL)
else()
set(HAVE_GLX TRUE)
endif()
if(OPENGL_FOUND)
set(HAVE_OPENGL TRUE)
if(QT_QTOPENGL_FOUND)

View File

@ -128,6 +128,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(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)
@ -175,12 +178,15 @@ ocv_create_module(${extra_libs})
ocv_target_link_libraries(${the_module} PRIVATE
"${ZLIB_LIBRARIES}" "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}"
"${OPENGL_LIBRARIES}"
"${GLX_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()

View File

@ -1596,8 +1596,13 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala
# if defined(__ANDROID__)
# include <EGL/egl.h>
# elif defined(__linux__)
# if defined(OPENCV_ENABLE_EGL)
# include <EGL/egl.h>
# endif
# if defined(OPENCV_ENABLE_GLX)
# include <GL/glx.h>
# endif
# endif
#endif // HAVE_OPENGL
namespace cv { namespace ogl {
@ -1762,20 +1767,33 @@ Context& initializeContextFromGL()
#elif defined(__linux__)
cl_context_properties props[] =
{
# 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(),
CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[i],
# 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
context = clCreateContext(props, 1, &devices[devUsed], NULL, NULL, &status);
#endif
}
if (status != CL_SUCCESS)
CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: Can't create context for OpenGL interop: %d", status));
else
break;
}
}
cl_platform_id platform = platforms[devUsed];