diff --git a/cmake/checks/opencl.cpp b/cmake/checks/opencl.cpp index 95a36f3ac..b71b92f67 100644 --- a/cmake/checks/opencl.cpp +++ b/cmake/checks/opencl.cpp @@ -1,8 +1,5 @@ -#if defined __APPLE__ -#include -#else +// custom OpenCL headers are located in "CL" subfolder (3rdparty/include/...) #include -#endif #ifndef _MSC_VER #ifdef CL_VERSION_1_2 diff --git a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp index f824ce933..801709e2c 100644 --- a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp +++ b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp @@ -95,11 +95,7 @@ #define clUnloadPlatformCompiler clUnloadPlatformCompiler_ #define clWaitForEvents clWaitForEvents_ -#if defined __APPLE__ -#include -#else #include -#endif // generated by parser_cl.py #undef clBuildProgram diff --git a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp index f37ad158e..1ad4a6acc 100644 --- a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp +++ b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp @@ -17,11 +17,7 @@ #define clGetGLObjectInfo clGetGLObjectInfo_ #define clGetGLTextureInfo clGetGLTextureInfo_ -#if defined __APPLE__ -#include -#else #include -#endif // generated by parser_cl.py #undef clCreateFromGLBuffer @@ -45,6 +41,8 @@ #undef clGetGLTextureInfo #define clGetGLTextureInfo clGetGLTextureInfo_pfn +#ifdef cl_khr_gl_sharing + // generated by parser_cl.py extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLBuffer)(cl_context, cl_mem_flags, cl_GLuint, int*); extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLRenderbuffer)(cl_context, cl_mem_flags, cl_GLuint, cl_int*); @@ -56,3 +54,5 @@ extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReleaseGLObjects)(cl_comma extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLContextInfoKHR)(const cl_context_properties*, cl_gl_context_info, size_t, void*, size_t*); extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLObjectInfo)(cl_mem, cl_gl_object_type*, cl_GLuint*); extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLTextureInfo)(cl_mem, cl_gl_texture_info, size_t, void*, size_t*); + +#endif // cl_khr_gl_sharing diff --git a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp index 105867f47..8338ac681 100644 --- a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp +++ b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp @@ -5,6 +5,8 @@ #error "Invalid usage" #endif +#ifdef cl_khr_gl_sharing + // generated by parser_cl.py #undef clCreateFromGLBuffer #define clCreateFromGLBuffer clCreateFromGLBuffer_fn @@ -36,3 +38,5 @@ inline cl_int clGetGLObjectInfo(cl_mem p0, cl_gl_object_type* p1, cl_GLuint* p2) #undef clGetGLTextureInfo #define clGetGLTextureInfo clGetGLTextureInfo_fn inline cl_int clGetGLTextureInfo(cl_mem p0, cl_gl_texture_info p1, size_t p2, void* p3, size_t* p4) { return clGetGLTextureInfo_pfn(p0, p1, p2, p3, p4); } + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/autogenerated/opencl_gl_impl.hpp b/modules/core/src/opencl/runtime/autogenerated/opencl_gl_impl.hpp index 6d9718050..5b371330c 100644 --- a/modules/core/src/opencl/runtime/autogenerated/opencl_gl_impl.hpp +++ b/modules/core/src/opencl/runtime/autogenerated/opencl_gl_impl.hpp @@ -139,6 +139,8 @@ struct opencl_gl_fn14 } // anonymous namespace +#ifdef cl_khr_gl_sharing + // generated by parser_cl.py cl_mem (CL_API_CALL*clCreateFromGLBuffer)(cl_context, cl_mem_flags, cl_GLuint, int*) = opencl_gl_fn4::switch_fn; @@ -196,3 +198,5 @@ static const struct DynamicFnEntry* opencl_gl_fn_list[] = { }; // number of enabled functions: 10 + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/generator/common.py b/modules/core/src/opencl/runtime/generator/common.py index 80c545295..5f81e8ee5 100644 --- a/modules/core/src/opencl/runtime/generator/common.py +++ b/modules/core/src/opencl/runtime/generator/common.py @@ -254,6 +254,6 @@ def ProcessTemplate(inputFile, ctx, noteLine='//\n// AUTOGENERATED, DO NOT EDIT\ assert line[-1] == '@' name = line[1:-1] assert ctx.has_key(name), name - line = ctx[name] - print line, + line = ctx[name] + ('\n' if len(ctx[name]) > 0 and ctx[name][-1] != '\n' else '') + sys.stdout.write(line) f.close() diff --git a/modules/core/src/opencl/runtime/generator/generate.sh b/modules/core/src/opencl/runtime/generator/generate.sh old mode 100644 new mode 100755 diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in index 4196622c0..b6c8f05d5 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in @@ -4,11 +4,7 @@ @CL_REMAP_ORIGIN@ -#if defined __APPLE__ -#include -#else #include -#endif @CL_REMAP_DYNAMIC@ diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in index 24434d2de..13a33c715 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in @@ -4,12 +4,12 @@ @CL_REMAP_ORIGIN@ -#if defined __APPLE__ -#include -#else #include -#endif @CL_REMAP_DYNAMIC@ +#ifdef cl_khr_gl_sharing + @CL_FN_DECLARATIONS@ + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in index 14586017a..cba1278a3 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in @@ -4,8 +4,12 @@ namespace { @CL_FN_SWITCH@ } // anonymous namespace +#ifdef cl_khr_gl_sharing + @CL_FN_ENTRY_DEFINITIONS@ @CL_FN_ENTRY_LIST@ @CL_NUMBER_OF_ENABLED_FUNCTIONS@ + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in index 0aeefb4f4..fc0317914 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in @@ -2,4 +2,8 @@ #error "Invalid usage" #endif +#ifdef cl_khr_gl_sharing + @CL_FN_INLINE_WRAPPERS@ + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/opencl_core.cpp b/modules/core/src/opencl/runtime/opencl_core.cpp index 0ab338112..405a5936a 100644 --- a/modules/core/src/opencl/runtime/opencl_core.cpp +++ b/modules/core/src/opencl/runtime/opencl_core.cpp @@ -286,6 +286,8 @@ static void* opencl_check_fn(int ID) #include "opencv2/core/opencl/runtime/opencl_gl.hpp" +#ifdef cl_khr_gl_sharing + static void* opencl_gl_check_fn(int ID); #include "autogenerated/opencl_gl_impl.hpp" @@ -306,6 +308,8 @@ static void* opencl_gl_check_fn(int ID) return func; } +#endif // cl_khr_gl_sharing + #endif // HAVE_OPENGL #endif diff --git a/modules/core/src/opengl.cpp b/modules/core/src/opengl.cpp index 3bbc0f8e9..f3d106fd2 100644 --- a/modules/core/src/opengl.cpp +++ b/modules/core/src/opengl.cpp @@ -1580,6 +1580,11 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala #ifdef HAVE_OPENCL # include "opencv2/core/opencl/runtime/opencl_gl.hpp" +# ifdef cl_khr_gl_sharing +# define HAVE_OPENCL_OPENGL_SHARING +# else +# define NO_OPENCL_SHARING_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without OpenCL/OpenGL sharing support") +# endif #else // HAVE_OPENCL # define NO_OPENCL_SUPPORT_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without OpenCL support") #endif // HAVE_OPENCL @@ -1602,6 +1607,8 @@ Context& initializeContextFromGL() NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else cl_uint numPlatforms; cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms); @@ -1701,6 +1708,8 @@ void convertToGLTexture2D(InputArray src, Texture2D& texture) NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else Size srcSize = src.size(); CV_Assert(srcSize.width == (int)texture.cols() && srcSize.height == (int)texture.rows()); @@ -1753,6 +1762,8 @@ void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst) NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else // check texture format const int dtype = CV_8UC4; @@ -1812,6 +1823,8 @@ UMat mapGLBuffer(const Buffer& buffer, int accessFlags) NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else using namespace cv::ocl; Context& ctx = Context::getDefault(); @@ -1862,6 +1875,8 @@ void unmapGLBuffer(UMat& u) NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else using namespace cv::ocl; cl_command_queue clQueue = (cl_command_queue)Queue::getDefault().ptr();