fixed build with CUDA and witout OpenGL
This commit is contained in:
parent
0d880479f0
commit
c6263eb253
@ -1,94 +1,111 @@
|
|||||||
#include "cvconfig.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_OPENGL
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include "cvconfig.h"
|
||||||
|
#include "opencv2/core/core.hpp"
|
||||||
#include "gl_core_3_1.hpp"
|
#include "gl_core_3_1.hpp"
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#ifdef HAVE_OPENGL
|
||||||
#include <mach-o/dyld.h>
|
#if defined(__APPLE__)
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
|
||||||
static void* AppleGLGetProcAddress (const GLubyte *name)
|
static void* AppleGLGetProcAddress (const char* name)
|
||||||
{
|
|
||||||
static const struct mach_header* image = 0;
|
|
||||||
if (!image)
|
|
||||||
image = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
|
||||||
|
|
||||||
// prepend a '_' for the Unix C symbol mangling convention
|
|
||||||
std::string symbolName = "_";
|
|
||||||
symbolName += std::string((const char*)name);
|
|
||||||
|
|
||||||
NSSymbol symbol = image ? NSLookupSymbolInImage(image, &symbolName[0], NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : 0;
|
|
||||||
|
|
||||||
return symbol ? NSAddressOfSymbol(symbol) : 0;
|
|
||||||
}
|
|
||||||
#endif // __APPLE__
|
|
||||||
|
|
||||||
#if defined(__sgi) || defined (__sun)
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
static void* SunGetProcAddress (const GLubyte* name)
|
|
||||||
{
|
|
||||||
typedef void* (func_t*)(const GLubyte*);
|
|
||||||
|
|
||||||
static void* h = 0;
|
|
||||||
static func_t gpa = 0;
|
|
||||||
|
|
||||||
if (!h)
|
|
||||||
{
|
{
|
||||||
h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
|
static const struct mach_header* image = 0;
|
||||||
|
if (!image)
|
||||||
|
image = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
||||||
|
|
||||||
|
// prepend a '_' for the Unix C symbol mangling convention
|
||||||
|
std::string symbolName = "_";
|
||||||
|
symbolName += std::string(name);
|
||||||
|
|
||||||
|
NSSymbol symbol = image ? NSLookupSymbolInImage(image, &symbolName[0], NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : 0;
|
||||||
|
|
||||||
|
return symbol ? NSAddressOfSymbol(symbol) : 0;
|
||||||
|
}
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
|
#if defined(__sgi) || defined (__sun)
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static void* SunGetProcAddress (const char* name)
|
||||||
|
{
|
||||||
|
typedef void* (func_t*)(const GLubyte*);
|
||||||
|
|
||||||
|
static void* h = 0;
|
||||||
|
static func_t gpa = 0;
|
||||||
|
|
||||||
if (!h)
|
if (!h)
|
||||||
|
{
|
||||||
|
h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!h)
|
||||||
|
return 0;
|
||||||
|
gpa = (func_t) dlsym(h, "glXGetProcAddress");
|
||||||
|
}
|
||||||
|
|
||||||
|
return gpa ? gpa((const GLubyte*) name) : dlsym(h, name);
|
||||||
|
}
|
||||||
|
#endif // __sgi || __sun
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable: 4055)
|
||||||
|
#pragma warning(disable: 4054)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int TestPointer(const PROC pTest)
|
||||||
|
{
|
||||||
|
if(!pTest)
|
||||||
return 0;
|
return 0;
|
||||||
gpa = (func_t) dlsym(h, "glXGetProcAddress");
|
|
||||||
|
ptrdiff_t iTest = (ptrdiff_t) pTest;
|
||||||
|
|
||||||
|
if (iTest == 1 || iTest == 2 || iTest == 3 || iTest == -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return gpa ? gpa(name) : dlsym(h, (const char*) name);
|
static PROC WinGetProcAddress(const char* name)
|
||||||
}
|
{
|
||||||
#endif /* __sgi || __sun */
|
PROC pFunc = wglGetProcAddress((LPCSTR) name);
|
||||||
|
if (TestPointer(pFunc))
|
||||||
|
return pFunc;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
HMODULE glMod = GetModuleHandleA("OpenGL32.dll");
|
||||||
#ifdef _MSC_VER
|
return (PROC) GetProcAddress(glMod, (LPCSTR) name);
|
||||||
#pragma warning(disable: 4055)
|
}
|
||||||
#pragma warning(disable: 4054)
|
#endif // _WIN32
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define CV_GL_GET_PROC_ADDRESS(name) WinGetProcAddress(name)
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#define CV_GL_GET_PROC_ADDRESS(name) AppleGLGetProcAddress(name)
|
||||||
|
#elif defined(__sgi) || defined(__sun)
|
||||||
|
#define CV_GL_GET_PROC_ADDRESS(name) SunGetProcAddress(name)
|
||||||
|
#else // GLX
|
||||||
|
#include <GL/glx.h>
|
||||||
|
|
||||||
|
#define CV_GL_GET_PROC_ADDRESS(name) (*glXGetProcAddressARB)((const GLubyte*) name)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int TestPointer(const PROC pTest)
|
static void* IntGetProcAddress(const char* name)
|
||||||
{
|
{
|
||||||
if(!pTest)
|
void* func = CV_GL_GET_PROC_ADDRESS(name);
|
||||||
return 0;
|
if (!func)
|
||||||
|
{
|
||||||
ptrdiff_t iTest = (ptrdiff_t) pTest;
|
std::ostringstream msg;
|
||||||
|
msg << "Can't load OpenGL extension [" << name << "]";
|
||||||
if (iTest == 1 || iTest == 2 || iTest == 3 || iTest == -1)
|
CV_Error(CV_OpenGlApiCallError, msg.str());
|
||||||
return 0;
|
}
|
||||||
|
return func;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PROC WinGetProcAddress(const char* name)
|
|
||||||
{
|
|
||||||
PROC pFunc = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (TestPointer(pFunc))
|
|
||||||
return pFunc;
|
|
||||||
|
|
||||||
HMODULE glMod = GetModuleHandleA("OpenGL32.dll");
|
|
||||||
return (PROC) GetProcAddress(glMod, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define IntGetProcAddress(name) WinGetProcAddress(name)
|
|
||||||
#else
|
#else
|
||||||
#if defined(__APPLE__)
|
static void* IntGetProcAddress(const char*)
|
||||||
#define IntGetProcAddress(name) AppleGLGetProcAddress(name)
|
{
|
||||||
#else
|
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||||
#if defined(__sgi) || defined(__sun)
|
return 0;
|
||||||
#define IntGetProcAddress(name) SunGetProcAddress(name)
|
}
|
||||||
#else /* GLX */
|
|
||||||
#include <GL/glx.h>
|
|
||||||
|
|
||||||
#define IntGetProcAddress(name) (*glXGetProcAddressARB)((const GLubyte*) name)
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace gl
|
namespace gl
|
||||||
@ -2699,5 +2716,3 @@ namespace gl
|
|||||||
|
|
||||||
InitializeVariables g_initVariables;
|
InitializeVariables g_initVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -44,13 +44,11 @@
|
|||||||
#include "opencv2/core/opengl_interop.hpp"
|
#include "opencv2/core/opengl_interop.hpp"
|
||||||
#include "opencv2/core/gpumat.hpp"
|
#include "opencv2/core/gpumat.hpp"
|
||||||
|
|
||||||
#ifdef HAVE_OPENGL
|
#include "gl_core_3_1.hpp"
|
||||||
#include "gl_core_3_1.hpp"
|
|
||||||
|
|
||||||
#ifdef HAVE_CUDA
|
#ifdef HAVE_CUDA
|
||||||
#include <cuda_runtime.h>
|
#include <cuda_runtime.h>
|
||||||
#include <cuda_gl_interop.h>
|
#include <cuda_gl_interop.h>
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -59,6 +57,12 @@ using namespace cv::gpu;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
#ifndef HAVE_OPENGL
|
||||||
|
void throw_nogl() { CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support"); }
|
||||||
|
#else
|
||||||
|
void throw_nogl() { CV_Error(CV_OpenGlApiCallError, "OpenGL context doesn't exist"); }
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_CUDA
|
#ifndef HAVE_CUDA
|
||||||
void throw_nocuda() { CV_Error(CV_GpuNotSupported, "The library is compiled without GPU support"); }
|
void throw_nocuda() { CV_Error(CV_GpuNotSupported, "The library is compiled without GPU support"); }
|
||||||
#else
|
#else
|
||||||
@ -76,12 +80,6 @@ namespace
|
|||||||
cv::gpu::error(cudaGetErrorString(err), file, line, func);
|
cv::gpu::error(cudaGetErrorString(err), file, line, func);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_OPENGL
|
|
||||||
void throw_nogl() { CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support"); }
|
|
||||||
#else
|
|
||||||
void throw_nogl() { CV_Error(CV_OpenGlApiCallError, "OpenGL context doesn't exist"); }
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cv::checkGlError(const char* file, const int line, const char* func)
|
bool cv::checkGlError(const char* file, const int line, const char* func)
|
||||||
@ -145,12 +143,7 @@ void cv::gpu::setGlDevice(int device)
|
|||||||
(void) device;
|
(void) device;
|
||||||
throw_nocuda();
|
throw_nocuda();
|
||||||
#else
|
#else
|
||||||
#ifndef HAVE_OPENGL
|
cudaSafeCall( cudaGLSetGLDevice(device) );
|
||||||
(void) device;
|
|
||||||
throw_nogl();
|
|
||||||
#else
|
|
||||||
cudaSafeCall( cudaGLSetGLDevice(device) );
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user