mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 13:47:32 +08:00
a bit more opengl refactoring:
* added Access parameter to GlBuffer::mapHost * added autoRelease parameter to all create methods * fixed indentation in gl_core_3_1 * minor improvments for opengl sample
This commit is contained in:
parent
08fbf667f9
commit
05d842bcd8
@ -71,6 +71,13 @@ public:
|
||||
PIXEL_UNPACK_BUFFER = 0x88EC //!< The buffer will be used for writing to OpenGL textures
|
||||
};
|
||||
|
||||
enum Access
|
||||
{
|
||||
READ_ONLY = 0x88B8,
|
||||
WRITE_ONLY = 0x88B9,
|
||||
READ_WRITE = 0x88BA
|
||||
};
|
||||
|
||||
//! create empty buffer
|
||||
GlBuffer();
|
||||
|
||||
@ -79,15 +86,15 @@ public:
|
||||
GlBuffer(Size asize, int atype, unsigned int abufId, bool autoRelease = false);
|
||||
|
||||
//! create buffer
|
||||
GlBuffer(int arows, int acols, int atype, Target target = ARRAY_BUFFER);
|
||||
GlBuffer(Size asize, int atype, Target target = ARRAY_BUFFER);
|
||||
GlBuffer(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
GlBuffer(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
//! copy from host/device memory
|
||||
explicit GlBuffer(InputArray arr, Target target = ARRAY_BUFFER);
|
||||
explicit GlBuffer(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
//! create buffer
|
||||
void create(int arows, int acols, int atype, Target target = ARRAY_BUFFER);
|
||||
void create(Size asize, int atype, Target target = ARRAY_BUFFER) { create(asize.height, asize.width, atype, target); }
|
||||
void create(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
void create(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false) { create(asize.height, asize.width, atype, target, autoRelease); }
|
||||
|
||||
//! release memory and delete buffer object
|
||||
void release();
|
||||
@ -96,7 +103,7 @@ public:
|
||||
void setAutoRelease(bool flag);
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray arr, Target target = ARRAY_BUFFER);
|
||||
void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
//! copy to host/device memory
|
||||
void copyTo(OutputArray arr, Target target = ARRAY_BUFFER) const;
|
||||
@ -111,7 +118,7 @@ public:
|
||||
static void unbind(Target target);
|
||||
|
||||
//! map to host memory
|
||||
Mat mapHost();
|
||||
Mat mapHost(Access access);
|
||||
void unmapHost();
|
||||
|
||||
//! map to device memory
|
||||
@ -162,15 +169,15 @@ public:
|
||||
GlTexture2D(Size asize, Format aformat, unsigned int atexId, bool autoRelease = false);
|
||||
|
||||
//! create texture
|
||||
GlTexture2D(int arows, int acols, Format aformat);
|
||||
GlTexture2D(Size asize, Format aformat);
|
||||
GlTexture2D(int arows, int acols, Format aformat, bool autoRelease = false);
|
||||
GlTexture2D(Size asize, Format aformat, bool autoRelease = false);
|
||||
|
||||
//! copy from host/device memory
|
||||
explicit GlTexture2D(InputArray arr);
|
||||
explicit GlTexture2D(InputArray arr, bool autoRelease = false);
|
||||
|
||||
//! create texture
|
||||
void create(int arows, int acols, Format aformat);
|
||||
void create(Size asize, Format aformat) { create(asize.height, asize.width, aformat); }
|
||||
void create(int arows, int acols, Format aformat, bool autoRelease = false);
|
||||
void create(Size asize, Format aformat, bool autoRelease = false) { create(asize.height, asize.width, aformat, autoRelease); }
|
||||
|
||||
//! release memory and delete texture object
|
||||
void release();
|
||||
@ -179,7 +186,7 @@ public:
|
||||
void setAutoRelease(bool flag);
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray arr);
|
||||
void copyFrom(InputArray arr, bool autoRelease = false);
|
||||
|
||||
//! copy to host/device memory
|
||||
void copyTo(OutputArray arr, int ddepth = CV_32F) const;
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
#ifdef HAVE_OPENGL
|
||||
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include "gl_core_3_1.hpp"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
@ -11,25 +10,19 @@
|
||||
|
||||
static void* AppleGLGetProcAddress (const GLubyte *name)
|
||||
{
|
||||
static const struct mach_header* image = NULL;
|
||||
NSSymbol symbol;
|
||||
char* symbolName;
|
||||
if (NULL == image)
|
||||
{
|
||||
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;
|
||||
}
|
||||
/* prepend a '_' for the Unix C symbol mangling convention */
|
||||
symbolName = malloc(strlen((const char*)name) + 2);
|
||||
strcpy(symbolName+1, (const char*)name);
|
||||
symbolName[0] = '_';
|
||||
symbol = NULL;
|
||||
/* if (NSIsSymbolNameDefined(symbolName))
|
||||
symbol = NSLookupAndBindSymbol(symbolName); */
|
||||
symbol = image ? NSLookupSymbolInImage(image, symbolName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : NULL;
|
||||
free(symbolName);
|
||||
return symbol ? NSAddressOfSymbol(symbol) : NULL;
|
||||
}
|
||||
#endif /* __APPLE__ */
|
||||
#endif // __APPLE__
|
||||
|
||||
#if defined(__sgi) || defined (__sun)
|
||||
#include <dlfcn.h>
|
||||
@ -37,24 +30,24 @@ static void* AppleGLGetProcAddress (const GLubyte *name)
|
||||
|
||||
static void* SunGetProcAddress (const GLubyte* name)
|
||||
{
|
||||
static void* h = NULL;
|
||||
static void* gpa;
|
||||
typedef void* (func_t*)(const GLubyte*);
|
||||
|
||||
if (h == NULL)
|
||||
static void* h = 0;
|
||||
static func_t gpa = 0;
|
||||
|
||||
if (!h)
|
||||
{
|
||||
if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
|
||||
gpa = dlsym(h, "glXGetProcAddress");
|
||||
h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!h)
|
||||
return 0;
|
||||
gpa = (func_t) dlsym(h, "glXGetProcAddress");
|
||||
}
|
||||
|
||||
if (gpa != NULL)
|
||||
return ((void*(*)(const GLubyte*))gpa)(name);
|
||||
else
|
||||
return dlsym(h, (const char*)name);
|
||||
return gpa ? gpa(name) : dlsym(h, (const char*) name);
|
||||
}
|
||||
#endif /* __sgi || __sun */
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4055)
|
||||
#pragma warning(disable: 4054)
|
||||
@ -62,24 +55,24 @@ static void* SunGetProcAddress (const GLubyte* name)
|
||||
|
||||
static int TestPointer(const PROC pTest)
|
||||
{
|
||||
ptrdiff_t iTest;
|
||||
if(!pTest) return 0;
|
||||
iTest = (ptrdiff_t)pTest;
|
||||
if(!pTest)
|
||||
return 0;
|
||||
|
||||
if(iTest == 1 || iTest == 2 || iTest == 3 || iTest == -1) return 0;
|
||||
ptrdiff_t iTest = (ptrdiff_t) pTest;
|
||||
|
||||
if (iTest == 1 || iTest == 2 || iTest == 3 || iTest == -1)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static PROC WinGetProcAddress(const char* name)
|
||||
{
|
||||
HMODULE glMod = NULL;
|
||||
PROC pFunc = wglGetProcAddress((LPCSTR) name);
|
||||
if (TestPointer(pFunc))
|
||||
{
|
||||
return pFunc;
|
||||
}
|
||||
glMod = GetModuleHandleA("OpenGL32.dll");
|
||||
|
||||
HMODULE glMod = GetModuleHandleA("OpenGL32.dll");
|
||||
return (PROC) GetProcAddress(glMod, (LPCSTR) name);
|
||||
}
|
||||
|
||||
@ -100,9 +93,8 @@ static PROC WinGetProcAddress(const char *name)
|
||||
|
||||
namespace gl
|
||||
{
|
||||
namespace exts
|
||||
{
|
||||
}
|
||||
//////////////////////////////////////////////
|
||||
// Function pointer types
|
||||
|
||||
// Extension: 1.1
|
||||
typedef void (CODEGEN_FUNCPTR *PFNCULLFACEPROC)(GLenum );
|
||||
@ -396,22 +388,20 @@ namespace gl
|
||||
typedef void (CODEGEN_FUNCPTR *PFNPRIMITIVERESTARTINDEXPROC)(GLuint );
|
||||
|
||||
// Legacy
|
||||
typedef void (CODEGEN_FUNCPTR *PFNENABLECLIENTSTATEPROC)(GLenum cap);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNDISABLECLIENTSTATEPROC)(GLenum cap);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNVERTEXPOINTERPROC)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNNORMALPOINTERPROC)(GLenum type, GLsizei stride, const GLvoid *ptr);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNCOLORPOINTERPROC)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNTEXCOORDPOINTERPROC)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
|
||||
|
||||
typedef void (CODEGEN_FUNCPTR *PFNTEXENVIPROC)(GLenum target, GLenum pname, GLint param);
|
||||
|
||||
typedef void (CODEGEN_FUNCPTR *PFNMATRIXMODEPROC)(GLenum modem);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNENABLECLIENTSTATEPROC)(GLenum );
|
||||
typedef void (CODEGEN_FUNCPTR *PFNDISABLECLIENTSTATEPROC)(GLenum );
|
||||
typedef void (CODEGEN_FUNCPTR *PFNVERTEXPOINTERPROC)(GLint , GLenum , GLsizei , const GLvoid *);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNNORMALPOINTERPROC)(GLenum , GLsizei , const GLvoid *);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNCOLORPOINTERPROC)(GLint , GLenum , GLsizei , const GLvoid *);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNTEXCOORDPOINTERPROC)(GLint , GLenum , GLsizei , const GLvoid *);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNTEXENVIPROC)(GLenum , GLenum , GLint );
|
||||
typedef void (CODEGEN_FUNCPTR *PFNMATRIXMODEPROC)(GLenum );
|
||||
typedef void (CODEGEN_FUNCPTR *PFNLOADIDENTITYPROC)(void);
|
||||
typedef void (CODEGEN_FUNCPTR *PFNORTHOPROC)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
|
||||
|
||||
typedef void (CODEGEN_FUNCPTR *PFNCOLOR3DPROC)(GLdouble red, GLdouble green, GLdouble blue);
|
||||
|
||||
typedef void (CODEGEN_FUNCPTR *PFNORTHOPROC)(GLdouble , GLdouble , GLdouble , GLdouble , GLdouble , GLdouble );
|
||||
typedef void (CODEGEN_FUNCPTR *PFNCOLOR3DPROC)(GLdouble , GLdouble , GLdouble );
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Function pointers
|
||||
|
||||
// Extension: 1.1
|
||||
PFNCULLFACEPROC CullFace;
|
||||
@ -720,8 +710,11 @@ namespace gl
|
||||
|
||||
PFNCOLOR3DPROC Color3d;
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Switch functions
|
||||
|
||||
// Extension: 1.1
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_CullFace(GLenum mode)
|
||||
{
|
||||
CullFace = (PFNCULLFACEPROC)IntGetProcAddress("glCullFace");
|
||||
@ -1106,8 +1099,8 @@ namespace gl
|
||||
Indexubv(c);
|
||||
}
|
||||
|
||||
|
||||
// Extension: 1.2
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_BlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
|
||||
{
|
||||
BlendColor = (PFNBLENDCOLORPROC)IntGetProcAddress("glBlendColor");
|
||||
@ -1138,8 +1131,8 @@ namespace gl
|
||||
CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height);
|
||||
}
|
||||
|
||||
|
||||
// Extension: 1.3
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_ActiveTexture(GLenum texture)
|
||||
{
|
||||
ActiveTexture = (PFNACTIVETEXTUREPROC)IntGetProcAddress("glActiveTexture");
|
||||
@ -1194,8 +1187,8 @@ namespace gl
|
||||
GetCompressedTexImage(target, level, img);
|
||||
}
|
||||
|
||||
|
||||
// Extension: 1.4
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_BlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha)
|
||||
{
|
||||
BlendFuncSeparate = (PFNBLENDFUNCSEPARATEPROC)IntGetProcAddress("glBlendFuncSeparate");
|
||||
@ -1238,8 +1231,8 @@ namespace gl
|
||||
PointParameteriv(pname, params);
|
||||
}
|
||||
|
||||
|
||||
// Extension: 1.5
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_GenQueries(GLsizei n, GLuint *ids)
|
||||
{
|
||||
GenQueries = (PFNGENQUERIESPROC)IntGetProcAddress("glGenQueries");
|
||||
@ -1354,8 +1347,8 @@ namespace gl
|
||||
GetBufferPointerv(target, pname, params);
|
||||
}
|
||||
|
||||
|
||||
// Extension: 2.0
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
|
||||
{
|
||||
BlendEquationSeparate = (PFNBLENDEQUATIONSEPARATEPROC)IntGetProcAddress("glBlendEquationSeparate");
|
||||
@ -1698,8 +1691,8 @@ namespace gl
|
||||
VertexAttribPointer(index, size, type, normalized, stride, pointer);
|
||||
}
|
||||
|
||||
|
||||
// Extension: 2.1
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
|
||||
{
|
||||
UniformMatrix2x3fv = (PFNUNIFORMMATRIX2X3FVPROC)IntGetProcAddress("glUniformMatrix2x3fv");
|
||||
@ -1736,8 +1729,8 @@ namespace gl
|
||||
UniformMatrix4x3fv(location, count, transpose, value);
|
||||
}
|
||||
|
||||
|
||||
// Extension: ARB_vertex_array_object
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_BindVertexArray(GLuint ren_array)
|
||||
{
|
||||
BindVertexArray = (PFNBINDVERTEXARRAYPROC)IntGetProcAddress("glBindVertexArray");
|
||||
@ -1762,8 +1755,8 @@ namespace gl
|
||||
return IsVertexArray(ren_array);
|
||||
}
|
||||
|
||||
|
||||
// Extension: ARB_map_buffer_range
|
||||
|
||||
static GLvoid* CODEGEN_FUNCPTR Switch_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
|
||||
{
|
||||
MapBufferRange = (PFNMAPBUFFERRANGEPROC)IntGetProcAddress("glMapBufferRange");
|
||||
@ -1776,8 +1769,8 @@ namespace gl
|
||||
FlushMappedBufferRange(target, offset, length);
|
||||
}
|
||||
|
||||
|
||||
// Extension: ARB_framebuffer_object
|
||||
|
||||
static GLboolean CODEGEN_FUNCPTR Switch_IsRenderbuffer(GLuint renderbuffer)
|
||||
{
|
||||
IsRenderbuffer = (PFNISRENDERBUFFERPROC)IntGetProcAddress("glIsRenderbuffer");
|
||||
@ -1898,8 +1891,8 @@ namespace gl
|
||||
FramebufferTextureLayer(target, attachment, texture, level, layer);
|
||||
}
|
||||
|
||||
|
||||
// Extension: 3.0
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_ColorMaski(GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a)
|
||||
{
|
||||
ColorMaski = (PFNCOLORMASKIPROC)IntGetProcAddress("glColorMaski");
|
||||
@ -2248,8 +2241,8 @@ namespace gl
|
||||
return GetStringi(name, index);
|
||||
}
|
||||
|
||||
|
||||
// Extension: ARB_uniform_buffer_object
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_GetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices)
|
||||
{
|
||||
GetUniformIndices = (PFNGETUNIFORMINDICESPROC)IntGetProcAddress("glGetUniformIndices");
|
||||
@ -2292,16 +2285,16 @@ namespace gl
|
||||
UniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding);
|
||||
}
|
||||
|
||||
|
||||
// Extension: ARB_copy_buffer
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
|
||||
{
|
||||
CopyBufferSubData = (PFNCOPYBUFFERSUBDATAPROC)IntGetProcAddress("glCopyBufferSubData");
|
||||
CopyBufferSubData(readTarget, writeTarget, readOffset, writeOffset, size);
|
||||
}
|
||||
|
||||
|
||||
// Extension: 3.1
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instancecount)
|
||||
{
|
||||
DrawArraysInstanced = (PFNDRAWARRAYSINSTANCEDPROC)IntGetProcAddress("glDrawArraysInstanced");
|
||||
@ -2327,6 +2320,7 @@ namespace gl
|
||||
}
|
||||
|
||||
// Legacy
|
||||
|
||||
static void CODEGEN_FUNCPTR Switch_EnableClientState(GLenum cap)
|
||||
{
|
||||
EnableClientState = (PFNENABLECLIENTSTATEPROC)IntGetProcAddress("glEnableClientState");
|
||||
@ -2393,10 +2387,6 @@ namespace gl
|
||||
Color3d(red, green, blue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
struct InitializeVariables
|
||||
{
|
||||
InitializeVariables()
|
||||
@ -2699,82 +2689,15 @@ namespace gl
|
||||
NormalPointer = Switch_NormalPointer;
|
||||
ColorPointer = Switch_ColorPointer;
|
||||
TexCoordPointer = Switch_TexCoordPointer;
|
||||
|
||||
TexEnvi = Switch_TexEnvi;
|
||||
|
||||
MatrixMode = Switch_MatrixMode;
|
||||
LoadIdentity = Switch_LoadIdentity;
|
||||
Ortho = Switch_Ortho;
|
||||
|
||||
Color3d = Switch_Color3d;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
InitializeVariables g_initVariables;
|
||||
}
|
||||
|
||||
namespace sys
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void ClearExtensionVariables()
|
||||
{
|
||||
}
|
||||
|
||||
struct MapEntry
|
||||
{
|
||||
const char *extName;
|
||||
bool *extVariable;
|
||||
};
|
||||
|
||||
struct MapCompare
|
||||
{
|
||||
MapCompare(const char *test_) : test(test_) {}
|
||||
bool operator()(const MapEntry &other) { return strcmp(test, other.extName) == 0; }
|
||||
const char *test;
|
||||
};
|
||||
|
||||
struct ClearEntry
|
||||
{
|
||||
void operator()(MapEntry &entry) { *(entry.extVariable) = false;}
|
||||
};
|
||||
|
||||
MapEntry g_mappingTable[1] =
|
||||
{
|
||||
};
|
||||
|
||||
void LoadExtByName(const char *extensionName)
|
||||
{
|
||||
MapEntry *tableEnd = &g_mappingTable[0];
|
||||
MapEntry *entry = std::find_if(&g_mappingTable[0], tableEnd, MapCompare(extensionName));
|
||||
|
||||
if(entry != tableEnd)
|
||||
*(entry->extVariable) = true;
|
||||
}
|
||||
|
||||
void ProcExtsFromExtList()
|
||||
{
|
||||
GLint iLoop;
|
||||
GLint iNumExtensions = 0;
|
||||
GetIntegerv(NUM_EXTENSIONS, &iNumExtensions);
|
||||
|
||||
for(iLoop = 0; iLoop < iNumExtensions; iLoop++)
|
||||
{
|
||||
const char *strExtensionName = (const char *)GetStringi(EXTENSIONS, iLoop);
|
||||
LoadExtByName(strExtensionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
void CheckExtensions()
|
||||
{
|
||||
ClearExtensionVariables();
|
||||
std::for_each(&g_mappingTable[0], &g_mappingTable[0], ClearEntry());
|
||||
|
||||
ProcExtsFromExtList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -37,7 +37,7 @@
|
||||
#else
|
||||
#define APIENTRY
|
||||
#endif
|
||||
#endif /*APIENTRY*/
|
||||
#endif // APIENTRY
|
||||
|
||||
#ifndef CODEGEN_FUNCPTR
|
||||
#define CODEGEN_REMOVE_FUNCPTR
|
||||
@ -46,16 +46,10 @@
|
||||
#else
|
||||
#define CODEGEN_FUNCPTR
|
||||
#endif
|
||||
#endif /*CODEGEN_FUNCPTR*/
|
||||
|
||||
#ifndef GLAPI
|
||||
#define GLAPI extern
|
||||
#endif
|
||||
|
||||
#endif // CODEGEN_FUNCPTR
|
||||
|
||||
#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
|
||||
typedef unsigned int GLenum;
|
||||
typedef unsigned char GLboolean;
|
||||
typedef unsigned int GLbitfield;
|
||||
@ -71,41 +65,47 @@
|
||||
typedef double GLdouble;
|
||||
typedef double GLclampd;
|
||||
#define GLvoid void
|
||||
|
||||
#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/
|
||||
#endif // GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef GL_VERSION_2_0
|
||||
/* GL type for program/shader text */
|
||||
// GL type for program/shader text
|
||||
typedef char GLchar;
|
||||
#endif
|
||||
|
||||
#ifndef GL_VERSION_1_5
|
||||
/* GL types for handling large vertex buffer objects */
|
||||
// GL types for handling large vertex buffer objects
|
||||
typedef ptrdiff_t GLintptr;
|
||||
typedef ptrdiff_t GLsizeiptr;
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARB_vertex_buffer_object
|
||||
/* GL types for handling large vertex buffer objects */
|
||||
// GL types for handling large vertex buffer objects
|
||||
typedef ptrdiff_t GLintptrARB;
|
||||
typedef ptrdiff_t GLsizeiptrARB;
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARB_shader_objects
|
||||
/* GL types for program/shader text and shader object handles */
|
||||
// GL types for program/shader text and shader object handles
|
||||
typedef char GLcharARB;
|
||||
typedef unsigned int GLhandleARB;
|
||||
#endif
|
||||
/* GL type for "half" precision (s10e5) float data in host memory */
|
||||
|
||||
// GL type for "half" precision (s10e5) float data in host memory
|
||||
#ifndef GL_ARB_half_float_pixel
|
||||
typedef unsigned short GLhalfARB;
|
||||
#endif
|
||||
#ifndef GL_NV_half_float
|
||||
typedef unsigned short GLhalfNV;
|
||||
#endif
|
||||
|
||||
#ifndef GLEXT_64_TYPES_DEFINED
|
||||
/* This code block is duplicated in glxext.h, so must be protected */
|
||||
// This code block is duplicated in glxext.h, so must be protected
|
||||
#define GLEXT_64_TYPES_DEFINED
|
||||
/* Define int32_t, int64_t, and uint64_t types for UST/MSC */
|
||||
/* (as used in the GL_EXT_timer_query extension). */
|
||||
|
||||
// Define int32_t, int64_t, and uint64_t types for UST/MSC
|
||||
// (as used in the GL_EXT_timer_query extension)
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
||||
#include <inttypes.h>
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
@ -117,8 +117,8 @@
|
||||
#else
|
||||
typedef long long int int64_t;
|
||||
typedef unsigned long long int uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#endif /* __STDC__ */
|
||||
#endif // __arch64__
|
||||
#endif // __STDC__
|
||||
#elif defined( __VMS ) || defined(__sgi)
|
||||
#include <inttypes.h>
|
||||
#elif defined(__SCO__) || defined(__USLC__)
|
||||
@ -134,45 +134,46 @@
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
/* Fallback if nothing above works */
|
||||
// Fallback if nothing above works
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef GL_EXT_timer_query
|
||||
typedef int64_t GLint64EXT;
|
||||
typedef uint64_t GLuint64EXT;
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARB_sync
|
||||
typedef int64_t GLint64;
|
||||
typedef uint64_t GLuint64;
|
||||
typedef struct __GLsync *GLsync;
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARB_cl_event
|
||||
/* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */
|
||||
// These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event
|
||||
struct _cl_context;
|
||||
struct _cl_event;
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARB_debug_output
|
||||
typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
|
||||
#endif
|
||||
|
||||
#ifndef GL_AMD_debug_output
|
||||
typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
|
||||
#endif
|
||||
|
||||
#ifndef GL_KHR_debug
|
||||
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
|
||||
#endif
|
||||
|
||||
#ifndef GL_NV_vdpau_interop
|
||||
typedef GLintptr GLvdpauSurfaceNV;
|
||||
#endif
|
||||
|
||||
namespace gl
|
||||
{
|
||||
/////////////////////////
|
||||
// Extension Variables
|
||||
namespace exts
|
||||
{
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
// Version: 1.1
|
||||
@ -1010,6 +1011,16 @@ namespace gl
|
||||
PRIMITIVE_RESTART = 0x8F9D,
|
||||
PRIMITIVE_RESTART_INDEX = 0x8F9E,
|
||||
|
||||
// Legacy
|
||||
VERTEX_ARRAY = 0x8074,
|
||||
NORMAL_ARRAY = 0x8075,
|
||||
COLOR_ARRAY = 0x8076,
|
||||
TEXTURE_COORD_ARRAY = 0x8078,
|
||||
TEXTURE_ENV = 0x2300,
|
||||
TEXTURE_ENV_MODE = 0x2200,
|
||||
MODELVIEW = 0x1700,
|
||||
PROJECTION = 0x1701,
|
||||
LIGHTING = 0x0B50
|
||||
};
|
||||
|
||||
// Extension: 1.1
|
||||
@ -1304,39 +1315,17 @@ namespace gl
|
||||
extern void (CODEGEN_FUNCPTR *PrimitiveRestartIndex)(GLuint index);
|
||||
|
||||
// Legacy
|
||||
enum
|
||||
{
|
||||
VERTEX_ARRAY = 0x8074,
|
||||
NORMAL_ARRAY = 0x8075,
|
||||
COLOR_ARRAY = 0x8076,
|
||||
TEXTURE_COORD_ARRAY = 0x8078,
|
||||
|
||||
TEXTURE_ENV = 0x2300,
|
||||
TEXTURE_ENV_MODE = 0x2200,
|
||||
|
||||
MODELVIEW = 0x1700,
|
||||
PROJECTION = 0x1701,
|
||||
LIGHTING = 0x0B50
|
||||
};
|
||||
|
||||
extern void (CODEGEN_FUNCPTR *EnableClientState)(GLenum cap);
|
||||
extern void (CODEGEN_FUNCPTR *DisableClientState)(GLenum cap);
|
||||
extern void (CODEGEN_FUNCPTR *VertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
|
||||
extern void (CODEGEN_FUNCPTR *NormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
|
||||
extern void (CODEGEN_FUNCPTR *ColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
|
||||
extern void (CODEGEN_FUNCPTR *TexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
|
||||
|
||||
extern void (CODEGEN_FUNCPTR *TexEnvi)(GLenum target, GLenum pname, GLint param);
|
||||
|
||||
extern void (CODEGEN_FUNCPTR *MatrixMode)(GLenum mode);
|
||||
extern void (CODEGEN_FUNCPTR *LoadIdentity)(void);
|
||||
extern void (CODEGEN_FUNCPTR *Ortho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
|
||||
|
||||
extern void (CODEGEN_FUNCPTR *Color3d)(GLdouble red, GLdouble green, GLdouble blue);
|
||||
}
|
||||
|
||||
namespace sys
|
||||
{
|
||||
void CheckExtensions();
|
||||
}
|
||||
}
|
||||
#endif // OPENGL_NOLOAD_STYLE_HPP
|
||||
|
@ -327,7 +327,7 @@ public:
|
||||
static const Ptr<Impl>& empty();
|
||||
|
||||
Impl(GLuint bufId, bool autoRelease);
|
||||
Impl(GLsizeiptr size, const GLvoid* data, GLenum target);
|
||||
Impl(GLsizeiptr size, const GLvoid* data, GLenum target, bool autoRelease);
|
||||
~Impl();
|
||||
|
||||
void bind(GLenum target) const;
|
||||
@ -337,7 +337,7 @@ public:
|
||||
void copyFrom(GLsizeiptr size, const GLvoid* data);
|
||||
void copyTo(GLsizeiptr size, GLvoid* data) const;
|
||||
|
||||
void* mapHost();
|
||||
void* mapHost(GLenum access);
|
||||
void unmapHost();
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
@ -377,7 +377,7 @@ cv::GlBuffer::Impl::Impl(GLuint abufId, bool autoRelease) : bufId_(abufId), auto
|
||||
{
|
||||
}
|
||||
|
||||
cv::GlBuffer::Impl::Impl(GLsizeiptr size, const GLvoid* data, GLenum target) : bufId_(0), autoRelease_(true)
|
||||
cv::GlBuffer::Impl::Impl(GLsizeiptr size, const GLvoid* data, GLenum target, bool autoRelease) : bufId_(0), autoRelease_(autoRelease)
|
||||
{
|
||||
gl::GenBuffers(1, &bufId_);
|
||||
CV_CheckGlError();
|
||||
@ -436,12 +436,12 @@ void cv::GlBuffer::Impl::copyTo(GLsizeiptr size, GLvoid* data) const
|
||||
CV_CheckGlError();
|
||||
}
|
||||
|
||||
void* cv::GlBuffer::Impl::mapHost()
|
||||
void* cv::GlBuffer::Impl::mapHost(GLenum access)
|
||||
{
|
||||
gl::BindBuffer(gl::COPY_READ_BUFFER, bufId_);
|
||||
CV_CheckGlError();
|
||||
|
||||
GLvoid* data = gl::MapBuffer(gl::COPY_READ_BUFFER, gl::READ_WRITE);
|
||||
GLvoid* data = gl::MapBuffer(gl::COPY_READ_BUFFER, access);
|
||||
CV_CheckGlError();
|
||||
|
||||
return data;
|
||||
@ -521,17 +521,17 @@ cv::GlBuffer::GlBuffer(Size asize, int atype, unsigned int abufId, bool autoRele
|
||||
#endif
|
||||
}
|
||||
|
||||
cv::GlBuffer::GlBuffer(int arows, int acols, int atype, Target target) : rows_(0), cols_(0), type_(0)
|
||||
cv::GlBuffer::GlBuffer(int arows, int acols, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
|
||||
{
|
||||
create(arows, acols, atype, target);
|
||||
create(arows, acols, atype, target, autoRelease);
|
||||
}
|
||||
|
||||
cv::GlBuffer::GlBuffer(Size asize, int atype, Target target) : rows_(0), cols_(0), type_(0)
|
||||
cv::GlBuffer::GlBuffer(Size asize, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
|
||||
{
|
||||
create(asize, atype, target);
|
||||
create(asize, atype, target, autoRelease);
|
||||
}
|
||||
|
||||
cv::GlBuffer::GlBuffer(InputArray arr, Target target) : rows_(0), cols_(0), type_(0)
|
||||
cv::GlBuffer::GlBuffer(InputArray arr, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void) arr;
|
||||
@ -544,19 +544,19 @@ cv::GlBuffer::GlBuffer(InputArray arr, Target target) : rows_(0), cols_(0), type
|
||||
{
|
||||
case _InputArray::OPENGL_BUFFER:
|
||||
{
|
||||
copyFrom(arr, target);
|
||||
copyFrom(arr, target, autoRelease);
|
||||
break;
|
||||
}
|
||||
|
||||
case _InputArray::OPENGL_TEXTURE2D:
|
||||
{
|
||||
copyFrom(arr, target);
|
||||
copyFrom(arr, target, autoRelease);
|
||||
break;
|
||||
}
|
||||
|
||||
case _InputArray::GPU_MAT:
|
||||
{
|
||||
copyFrom(arr, target);
|
||||
copyFrom(arr, target, autoRelease);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -565,7 +565,7 @@ cv::GlBuffer::GlBuffer(InputArray arr, Target target) : rows_(0), cols_(0), type
|
||||
Mat mat = arr.getMat();
|
||||
CV_Assert( mat.isContinuous() );
|
||||
const GLsizeiptr asize = mat.rows * mat.cols * mat.elemSize();
|
||||
impl_ = new Impl(asize, mat.data, target);
|
||||
impl_ = new Impl(asize, mat.data, target, autoRelease);
|
||||
rows_ = mat.rows;
|
||||
cols_ = mat.cols;
|
||||
type_ = mat.type();
|
||||
@ -575,7 +575,7 @@ cv::GlBuffer::GlBuffer(InputArray arr, Target target) : rows_(0), cols_(0), type
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::GlBuffer::create(int arows, int acols, int atype, Target target)
|
||||
void cv::GlBuffer::create(int arows, int acols, int atype, Target target, bool autoRelease)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void) arows;
|
||||
@ -587,7 +587,7 @@ void cv::GlBuffer::create(int arows, int acols, int atype, Target target)
|
||||
if (rows_ != arows || cols_ != acols || type_ != atype)
|
||||
{
|
||||
const GLsizeiptr asize = arows * acols * CV_ELEM_SIZE(atype);
|
||||
impl_ = new Impl(asize, 0, target);
|
||||
impl_ = new Impl(asize, 0, target, autoRelease);
|
||||
rows_ = arows;
|
||||
cols_ = acols;
|
||||
type_ = atype;
|
||||
@ -598,6 +598,8 @@ void cv::GlBuffer::create(int arows, int acols, int atype, Target target)
|
||||
void cv::GlBuffer::release()
|
||||
{
|
||||
#ifdef HAVE_OPENGL
|
||||
if (*impl_.refcount == 1)
|
||||
impl_->setAutoRelease(true);
|
||||
impl_ = Impl::empty();
|
||||
rows_ = 0;
|
||||
cols_ = 0;
|
||||
@ -615,7 +617,7 @@ void cv::GlBuffer::setAutoRelease(bool flag)
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::GlBuffer::copyFrom(InputArray arr, Target target)
|
||||
void cv::GlBuffer::copyFrom(InputArray arr, Target target, bool autoRelease)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void) arr;
|
||||
@ -628,12 +630,13 @@ void cv::GlBuffer::copyFrom(InputArray arr, Target target)
|
||||
{
|
||||
GlTexture2D tex = arr.getGlTexture2D();
|
||||
tex.copyTo(*this);
|
||||
setAutoRelease(autoRelease);
|
||||
return;
|
||||
}
|
||||
|
||||
const Size asize = arr.size();
|
||||
const int atype = arr.type();
|
||||
create(asize, atype, target);
|
||||
create(asize, atype, target, autoRelease);
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
@ -747,13 +750,14 @@ void cv::GlBuffer::unbind(Target target)
|
||||
#endif
|
||||
}
|
||||
|
||||
Mat cv::GlBuffer::mapHost()
|
||||
Mat cv::GlBuffer::mapHost(Access access)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void) access;
|
||||
throw_nogl();
|
||||
return Mat();
|
||||
#else
|
||||
return Mat(rows_, cols_, type_, impl_->mapHost());
|
||||
return Mat(rows_, cols_, type_, impl_->mapHost(access));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -826,7 +830,7 @@ public:
|
||||
static const Ptr<Impl> empty();
|
||||
|
||||
Impl(GLuint texId, bool autoRelease);
|
||||
Impl(GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels);
|
||||
Impl(GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels, bool autoRelease);
|
||||
~Impl();
|
||||
|
||||
void copyFrom(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
|
||||
@ -859,7 +863,7 @@ cv::GlTexture2D::Impl::Impl(GLuint atexId, bool autoRelease) : texId_(atexId), a
|
||||
{
|
||||
}
|
||||
|
||||
cv::GlTexture2D::Impl::Impl(GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels) : texId_(0), autoRelease_(true)
|
||||
cv::GlTexture2D::Impl::Impl(GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels, bool autoRelease) : texId_(0), autoRelease_(autoRelease)
|
||||
{
|
||||
gl::GenTextures(1, &texId_);
|
||||
CV_CheckGlError();
|
||||
@ -962,17 +966,17 @@ cv::GlTexture2D::GlTexture2D(Size asize, Format aformat, unsigned int atexId, bo
|
||||
#endif
|
||||
}
|
||||
|
||||
cv::GlTexture2D::GlTexture2D(int arows, int acols, Format aformat) : rows_(0), cols_(0), format_(NONE)
|
||||
cv::GlTexture2D::GlTexture2D(int arows, int acols, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE)
|
||||
{
|
||||
create(arows, acols, aformat);
|
||||
create(arows, acols, aformat, autoRelease);
|
||||
}
|
||||
|
||||
cv::GlTexture2D::GlTexture2D(Size asize, Format aformat) : rows_(0), cols_(0), format_(NONE)
|
||||
cv::GlTexture2D::GlTexture2D(Size asize, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE)
|
||||
{
|
||||
create(asize, aformat);
|
||||
create(asize, aformat, autoRelease);
|
||||
}
|
||||
|
||||
cv::GlTexture2D::GlTexture2D(InputArray arr) : rows_(0), cols_(0), format_(NONE)
|
||||
cv::GlTexture2D::GlTexture2D(InputArray arr, bool autoRelease) : rows_(0), cols_(0), format_(NONE)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void) arr;
|
||||
@ -1004,7 +1008,7 @@ cv::GlTexture2D::GlTexture2D(InputArray arr) : rows_(0), cols_(0), format_(NONE)
|
||||
{
|
||||
GlBuffer buf = arr.getGlBuffer();
|
||||
buf.bind(GlBuffer::PIXEL_UNPACK_BUFFER);
|
||||
impl_ = new Impl(internalFormats[cn], asize.width, asize.height, srcFormats[cn], gl_types[depth], 0);
|
||||
impl_ = new Impl(internalFormats[cn], asize.width, asize.height, srcFormats[cn], gl_types[depth], 0, autoRelease);
|
||||
GlBuffer::unbind(GlBuffer::PIXEL_UNPACK_BUFFER);
|
||||
break;
|
||||
}
|
||||
@ -1017,7 +1021,7 @@ cv::GlTexture2D::GlTexture2D(InputArray arr) : rows_(0), cols_(0), format_(NONE)
|
||||
GpuMat dmat = arr.getGpuMat();
|
||||
GlBuffer buf(dmat, GlBuffer::PIXEL_UNPACK_BUFFER);
|
||||
buf.bind(GlBuffer::PIXEL_UNPACK_BUFFER);
|
||||
impl_ = new Impl(internalFormats[cn], asize.width, asize.height, srcFormats[cn], gl_types[depth], 0);
|
||||
impl_ = new Impl(internalFormats[cn], asize.width, asize.height, srcFormats[cn], gl_types[depth], 0, autoRelease);
|
||||
GlBuffer::unbind(GlBuffer::PIXEL_UNPACK_BUFFER);
|
||||
#endif
|
||||
|
||||
@ -1029,7 +1033,7 @@ cv::GlTexture2D::GlTexture2D(InputArray arr) : rows_(0), cols_(0), format_(NONE)
|
||||
Mat mat = arr.getMat();
|
||||
CV_Assert( mat.isContinuous() );
|
||||
GlBuffer::unbind(GlBuffer::PIXEL_UNPACK_BUFFER);
|
||||
impl_ = new Impl(internalFormats[cn], asize.width, asize.height, srcFormats[cn], gl_types[depth], mat.data);
|
||||
impl_ = new Impl(internalFormats[cn], asize.width, asize.height, srcFormats[cn], gl_types[depth], mat.data, autoRelease);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1040,7 +1044,7 @@ cv::GlTexture2D::GlTexture2D(InputArray arr) : rows_(0), cols_(0), format_(NONE)
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::GlTexture2D::create(int arows, int acols, Format aformat)
|
||||
void cv::GlTexture2D::create(int arows, int acols, Format aformat, bool autoRelease)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void) arows;
|
||||
@ -1051,7 +1055,7 @@ void cv::GlTexture2D::create(int arows, int acols, Format aformat)
|
||||
if (rows_ != arows || cols_ != acols || format_ != aformat)
|
||||
{
|
||||
GlBuffer::unbind(GlBuffer::PIXEL_UNPACK_BUFFER);
|
||||
impl_ = new Impl(aformat, acols, arows, aformat, gl::FLOAT, 0);
|
||||
impl_ = new Impl(aformat, acols, arows, aformat, gl::FLOAT, 0, autoRelease);
|
||||
rows_ = arows;
|
||||
cols_ = acols;
|
||||
format_ = aformat;
|
||||
@ -1062,6 +1066,8 @@ void cv::GlTexture2D::create(int arows, int acols, Format aformat)
|
||||
void cv::GlTexture2D::release()
|
||||
{
|
||||
#ifdef HAVE_OPENGL
|
||||
if (*impl_.refcount == 1)
|
||||
impl_->setAutoRelease(true);
|
||||
impl_ = Impl::empty();
|
||||
rows_ = 0;
|
||||
cols_ = 0;
|
||||
@ -1079,7 +1085,7 @@ void cv::GlTexture2D::setAutoRelease(bool flag)
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::GlTexture2D::copyFrom(InputArray arr)
|
||||
void cv::GlTexture2D::copyFrom(InputArray arr, bool autoRelease)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void) arr;
|
||||
@ -1105,7 +1111,7 @@ void cv::GlTexture2D::copyFrom(InputArray arr)
|
||||
0, gl::DEPTH_COMPONENT, 0, gl::BGR, gl::BGRA
|
||||
};
|
||||
|
||||
create(asize, internalFormats[cn]);
|
||||
create(asize, internalFormats[cn], autoRelease);
|
||||
|
||||
switch(kind)
|
||||
{
|
||||
|
@ -351,14 +351,14 @@ TEST_P(GlBuffer, Clone)
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
TEST_P(GlBuffer, MapHost)
|
||||
TEST_P(GlBuffer, MapHostRead)
|
||||
{
|
||||
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||||
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
cv::GlBuffer buf(gold);
|
||||
|
||||
cv::Mat dst = buf.mapHost();
|
||||
cv::Mat dst = buf.mapHost(cv::GlBuffer::READ_ONLY);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||
|
||||
@ -368,6 +368,27 @@ TEST_P(GlBuffer, MapHost)
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
TEST_P(GlBuffer, MapHostWrite)
|
||||
{
|
||||
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||||
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
cv::GlBuffer buf(size, type);
|
||||
|
||||
cv::Mat dst = buf.mapHost(cv::GlBuffer::WRITE_ONLY);
|
||||
gold.copyTo(dst);
|
||||
buf.unmapHost();
|
||||
dst.release();
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
|
||||
buf.release();
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
TEST_P(GlBuffer, MapDevice)
|
||||
{
|
||||
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||||
|
@ -56,14 +56,18 @@ void CV_CDECL draw(void* userdata)
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(0, 0, 4, 0, 0, 0, 0, 1, 0);
|
||||
gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
|
||||
glRotated(angle, 0, 1, 0);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
data->tex.bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
|
||||
|
||||
render(data->arr, data->indices, RenderMode::TRIANGLES);
|
||||
|
||||
@ -101,13 +105,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
data.arr.setVertexArray(vertex);
|
||||
data.arr.setTexCoordArray(texCoords);
|
||||
data.arr.setAutoRelease(false);
|
||||
|
||||
data.indices.copyFrom(indices);
|
||||
data.indices.setAutoRelease(false);
|
||||
|
||||
data.tex.copyFrom(img);
|
||||
data.tex.setAutoRelease(false);
|
||||
|
||||
setOpenGlDrawCallback("OpenGL", draw, &data);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user