Commit 05d842bc authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

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
parent 08fbf667
......@@ -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;
......
This diff is collapsed.
......@@ -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
#endif // OPENGL_NOLOAD_STYLE_HPP
This diff is collapsed.
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment