fixed OpenGL tests

now create window only once per test case
This commit is contained in:
Vladislav Vinogradov 2012-12-05 14:18:57 +04:00
parent aabc33c772
commit b689eca8a0
3 changed files with 80 additions and 215 deletions

View File

@ -106,10 +106,10 @@ public:
void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false); void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
//! copy to host/device memory //! copy to host/device memory
void copyTo(OutputArray arr, Target target = ARRAY_BUFFER) const; void copyTo(OutputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false) const;
//! create copy of current buffer //! create copy of current buffer
GlBuffer clone(Target target = ARRAY_BUFFER) const; GlBuffer clone(Target target = ARRAY_BUFFER, bool autoRelease = false) const;
//! bind buffer for specified target //! bind buffer for specified target
void bind(Target target) const; void bind(Target target) const;
@ -189,7 +189,7 @@ public:
void copyFrom(InputArray arr, bool autoRelease = false); void copyFrom(InputArray arr, bool autoRelease = false);
//! copy to host/device memory //! copy to host/device memory
void copyTo(OutputArray arr, int ddepth = CV_32F) const; void copyTo(OutputArray arr, int ddepth = CV_32F, bool autoRelease = false) const;
//! bind texture to current active texture unit for GL_TEXTURE_2D target //! bind texture to current active texture unit for GL_TEXTURE_2D target
void bind() const; void bind() const;

View File

@ -672,11 +672,12 @@ void cv::GlBuffer::copyFrom(InputArray arr, Target target, bool autoRelease)
#endif #endif
} }
void cv::GlBuffer::copyTo(OutputArray arr, Target target) const void cv::GlBuffer::copyTo(OutputArray arr, Target target, bool autoRelease) const
{ {
#ifndef HAVE_OPENGL #ifndef HAVE_OPENGL
(void) arr; (void) arr;
(void) target; (void) target;
(void) autoRelease;
throw_nogl(); throw_nogl();
#else #else
const int kind = arr.kind(); const int kind = arr.kind();
@ -685,13 +686,13 @@ void cv::GlBuffer::copyTo(OutputArray arr, Target target) const
{ {
case _InputArray::OPENGL_BUFFER: case _InputArray::OPENGL_BUFFER:
{ {
arr.getGlBufferRef().copyFrom(*this, target); arr.getGlBufferRef().copyFrom(*this, target, autoRelease);
break; break;
} }
case _InputArray::OPENGL_TEXTURE2D: case _InputArray::OPENGL_TEXTURE2D:
{ {
arr.getGlTexture2DRef().copyFrom(*this); arr.getGlTexture2DRef().copyFrom(*this, autoRelease);
break; break;
} }
@ -719,15 +720,16 @@ void cv::GlBuffer::copyTo(OutputArray arr, Target target) const
#endif #endif
} }
GlBuffer cv::GlBuffer::clone(Target target) const GlBuffer cv::GlBuffer::clone(Target target, bool autoRelease) const
{ {
#ifndef HAVE_OPENGL #ifndef HAVE_OPENGL
(void) target; (void) target;
(void) autoRelease;
throw_nogl(); throw_nogl();
return GlBuffer(); return GlBuffer();
#else #else
GlBuffer buf; GlBuffer buf;
buf.copyFrom(*this, target); buf.copyFrom(*this, target, autoRelease);
return buf; return buf;
#endif #endif
} }
@ -1156,11 +1158,12 @@ void cv::GlTexture2D::copyFrom(InputArray arr, bool autoRelease)
#endif #endif
} }
void cv::GlTexture2D::copyTo(OutputArray arr, int ddepth) const void cv::GlTexture2D::copyTo(OutputArray arr, int ddepth, bool autoRelease) const
{ {
#ifndef HAVE_OPENGL #ifndef HAVE_OPENGL
(void) arr; (void) arr;
(void) ddepth; (void) ddepth;
(void) autoRelease;
throw_nogl(); throw_nogl();
#else #else
const int kind = arr.kind(); const int kind = arr.kind();
@ -1173,7 +1176,7 @@ void cv::GlTexture2D::copyTo(OutputArray arr, int ddepth) const
case _InputArray::OPENGL_BUFFER: case _InputArray::OPENGL_BUFFER:
{ {
GlBuffer& buf = arr.getGlBufferRef(); GlBuffer& buf = arr.getGlBufferRef();
buf.create(rows_, cols_, CV_MAKE_TYPE(ddepth, cn), GlBuffer::PIXEL_PACK_BUFFER); buf.create(rows_, cols_, CV_MAKE_TYPE(ddepth, cn), GlBuffer::PIXEL_PACK_BUFFER, autoRelease);
buf.bind(GlBuffer::PIXEL_PACK_BUFFER); buf.bind(GlBuffer::PIXEL_PACK_BUFFER);
impl_->copyTo(dstFormat, gl_types[ddepth], 0); impl_->copyTo(dstFormat, gl_types[ddepth], 0);
GlBuffer::unbind(GlBuffer::PIXEL_PACK_BUFFER); GlBuffer::unbind(GlBuffer::PIXEL_PACK_BUFFER);

View File

@ -48,6 +48,16 @@
PARAM_TEST_CASE(GlBuffer, cv::Size, MatType) PARAM_TEST_CASE(GlBuffer, cv::Size, MatType)
{ {
static void SetUpTestCase()
{
cv::namedWindow("test", cv::WINDOW_OPENGL);
}
static void TearDownTestCase()
{
cv::destroyAllWindows();
}
cv::Size size; cv::Size size;
int type; int type;
@ -60,83 +70,57 @@ PARAM_TEST_CASE(GlBuffer, cv::Size, MatType)
TEST_P(GlBuffer, Constructor1) TEST_P(GlBuffer, Constructor1)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL); cv::GlBuffer buf(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer buf(size.height, size.width, type);
EXPECT_EQ(size.height, buf.rows()); EXPECT_EQ(size.height, buf.rows());
EXPECT_EQ(size.width, buf.cols()); EXPECT_EQ(size.width, buf.cols());
EXPECT_EQ(type, buf.type()); EXPECT_EQ(type, buf.type());
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, Constructor2) TEST_P(GlBuffer, Constructor2)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL); cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer buf(size, type);
EXPECT_EQ(size.height, buf.rows()); EXPECT_EQ(size.height, buf.rows());
EXPECT_EQ(size.width, buf.cols()); EXPECT_EQ(size.width, buf.cols());
EXPECT_EQ(type, buf.type()); EXPECT_EQ(type, buf.type());
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, ConstructorFromMat) TEST_P(GlBuffer, ConstructorFromMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold); cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, ConstructorFromGpuMat) TEST_P(GlBuffer, ConstructorFromGpuMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::gpu::GpuMat d_gold(gold); cv::gpu::GpuMat d_gold(gold);
cv::GlBuffer buf(d_gold); cv::GlBuffer buf(d_gold, cv::GlBuffer::ARRAY_BUFFER);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
buf.release();
d_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, ConstructorFromGlBuffer) TEST_P(GlBuffer, ConstructorFromGlBuffer)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL); cv::GlBuffer buf_gold(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer buf_gold(size, type);
cv::GlBuffer buf(buf_gold); cv::GlBuffer buf(buf_gold);
EXPECT_EQ(buf_gold.bufId(), buf.bufId()); EXPECT_EQ(buf_gold.bufId(), buf.bufId());
EXPECT_EQ(buf_gold.rows(), buf.rows()); EXPECT_EQ(buf_gold.rows(), buf.rows());
EXPECT_EQ(buf_gold.cols(), buf.cols()); EXPECT_EQ(buf_gold.cols(), buf.cols());
EXPECT_EQ(buf_gold.type(), buf.type()); EXPECT_EQ(buf_gold.type(), buf.type());
buf.release();
buf_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, ConstructorFromGlTexture2D) TEST_P(GlBuffer, ConstructorFromGlTexture2D)
@ -147,85 +131,61 @@ TEST_P(GlBuffer, ConstructorFromGlTexture2D)
if (depth != CV_32F || cn == 2) if (depth != CV_32F || cn == 2)
return; return;
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, 1.0); cv::Mat gold = randomMat(size, type, 0, 1.0);
cv::GlTexture2D tex_gold(gold); cv::GlTexture2D tex_gold(gold, true);
cv::GlBuffer buf(tex_gold); cv::GlBuffer buf(tex_gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 1e-2); EXPECT_MAT_NEAR(gold, bufData, 1e-2);
buf.release();
tex_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, Create) TEST_P(GlBuffer, Create)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::GlBuffer buf; cv::GlBuffer buf;
buf.create(size.height, size.width, type); buf.create(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_EQ(size.height, buf.rows()); EXPECT_EQ(size.height, buf.rows());
EXPECT_EQ(size.width, buf.cols()); EXPECT_EQ(size.width, buf.cols());
EXPECT_EQ(type, buf.type()); EXPECT_EQ(type, buf.type());
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, CopyFromMat) TEST_P(GlBuffer, CopyFromMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf; cv::GlBuffer buf;
buf.copyFrom(gold); buf.copyFrom(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, CopyFromGpuMat) TEST_P(GlBuffer, CopyFromGpuMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::gpu::GpuMat d_gold(gold); cv::gpu::GpuMat d_gold(gold);
cv::GlBuffer buf; cv::GlBuffer buf;
buf.copyFrom(d_gold); buf.copyFrom(d_gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
buf.release();
d_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, CopyFromGlBuffer) TEST_P(GlBuffer, CopyFromGlBuffer)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf_gold(gold); cv::GlBuffer buf_gold(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer buf; cv::GlBuffer buf;
buf.copyFrom(buf_gold); buf.copyFrom(buf_gold, cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_NE(buf_gold.bufId(), buf.bufId()); EXPECT_NE(buf_gold.bufId(), buf.bufId());
@ -233,10 +193,6 @@ TEST_P(GlBuffer, CopyFromGlBuffer)
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
buf.release();
buf_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, CopyFromGlTexture2D) TEST_P(GlBuffer, CopyFromGlTexture2D)
@ -247,50 +203,38 @@ TEST_P(GlBuffer, CopyFromGlTexture2D)
if (depth != CV_32F || cn == 2) if (depth != CV_32F || cn == 2)
return; return;
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, 1.0); cv::Mat gold = randomMat(size, type, 0, 1.0);
cv::GlTexture2D tex_gold(gold); cv::GlTexture2D tex_gold(gold, true);
cv::GlBuffer buf; cv::GlBuffer buf;
buf.copyFrom(tex_gold); buf.copyFrom(tex_gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 1e-2); EXPECT_MAT_NEAR(gold, bufData, 1e-2);
buf.release();
tex_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, CopyToGpuMat) TEST_P(GlBuffer, CopyToGpuMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold); cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
buf.copyTo(dst); buf.copyTo(dst);
EXPECT_MAT_NEAR(gold, dst, 0); EXPECT_MAT_NEAR(gold, dst, 0);
dst.release();
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, CopyToGlBuffer) TEST_P(GlBuffer, CopyToGlBuffer)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold);
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer dst; cv::GlBuffer dst;
buf.copyTo(dst); buf.copyTo(dst, cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_NE(buf.bufId(), dst.bufId()); EXPECT_NE(buf.bufId(), dst.bufId());
@ -298,10 +242,6 @@ TEST_P(GlBuffer, CopyToGlBuffer)
dst.copyTo(bufData); dst.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
dst.release();
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, CopyToGlTexture2D) TEST_P(GlBuffer, CopyToGlTexture2D)
@ -312,32 +252,26 @@ TEST_P(GlBuffer, CopyToGlTexture2D)
if (depth != CV_32F || cn == 2) if (depth != CV_32F || cn == 2)
return; return;
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, 1.0); cv::Mat gold = randomMat(size, type, 0, 1.0);
cv::GlBuffer buf(gold);
cv::GlBuffer buf(gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
cv::GlTexture2D tex; cv::GlTexture2D tex;
buf.copyTo(tex); buf.copyTo(tex, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData); tex.copyTo(texData);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
tex.release();
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, Clone) TEST_P(GlBuffer, Clone)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold);
cv::GlBuffer dst = buf.clone(); cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer dst = buf.clone(cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_NE(buf.bufId(), dst.bufId()); EXPECT_NE(buf.bufId(), dst.bufId());
@ -345,35 +279,26 @@ TEST_P(GlBuffer, Clone)
dst.copyTo(bufData); dst.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
dst.release();
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, MapHostRead) TEST_P(GlBuffer, MapHostRead)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold);
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat dst = buf.mapHost(cv::GlBuffer::READ_ONLY); cv::Mat dst = buf.mapHost(cv::GlBuffer::READ_ONLY);
EXPECT_MAT_NEAR(gold, dst, 0); EXPECT_MAT_NEAR(gold, dst, 0);
buf.unmapHost(); buf.unmapHost();
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, MapHostWrite) TEST_P(GlBuffer, MapHostWrite)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(size, type);
cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat dst = buf.mapHost(cv::GlBuffer::WRITE_ONLY); cv::Mat dst = buf.mapHost(cv::GlBuffer::WRITE_ONLY);
gold.copyTo(dst); gold.copyTo(dst);
@ -384,26 +309,19 @@ TEST_P(GlBuffer, MapHostWrite)
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
buf.release();
cv::destroyAllWindows();
} }
TEST_P(GlBuffer, MapDevice) TEST_P(GlBuffer, MapDevice)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type); cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold);
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::gpu::GpuMat dst = buf.mapDevice(); cv::gpu::GpuMat dst = buf.mapDevice();
EXPECT_MAT_NEAR(gold, dst, 0); EXPECT_MAT_NEAR(gold, dst, 0);
buf.unmapDevice(); buf.unmapDevice();
buf.release();
cv::destroyAllWindows();
} }
INSTANTIATE_TEST_CASE_P(OpenGL, GlBuffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES)); INSTANTIATE_TEST_CASE_P(OpenGL, GlBuffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES));
@ -413,6 +331,16 @@ INSTANTIATE_TEST_CASE_P(OpenGL, GlBuffer, testing::Combine(DIFFERENT_SIZES, ALL_
PARAM_TEST_CASE(GlTexture2D, cv::Size, MatType) PARAM_TEST_CASE(GlTexture2D, cv::Size, MatType)
{ {
static void SetUpTestCase()
{
cv::namedWindow("test", cv::WINDOW_OPENGL);
}
static void TearDownTestCase()
{
cv::destroyAllWindows();
}
cv::Size size; cv::Size size;
int type; int type;
int depth; int depth;
@ -432,213 +360,147 @@ PARAM_TEST_CASE(GlTexture2D, cv::Size, MatType)
TEST_P(GlTexture2D, Constructor1) TEST_P(GlTexture2D, Constructor1)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL); cv::GlTexture2D tex(size.height, size.width, format, true);
cv::GlTexture2D tex(size.height, size.width, format);
EXPECT_EQ(size.height, tex.rows()); EXPECT_EQ(size.height, tex.rows());
EXPECT_EQ(size.width, tex.cols()); EXPECT_EQ(size.width, tex.cols());
EXPECT_EQ(format, tex.format()); EXPECT_EQ(format, tex.format());
tex.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, Constructor2) TEST_P(GlTexture2D, Constructor2)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL); cv::GlTexture2D tex(size, format, true);
cv::GlTexture2D tex(size, format);
EXPECT_EQ(size.height, tex.rows()); EXPECT_EQ(size.height, tex.rows());
EXPECT_EQ(size.width, tex.cols()); EXPECT_EQ(size.width, tex.cols());
EXPECT_EQ(format, tex.format()); EXPECT_EQ(format, tex.format());
tex.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, ConstructorFromMat) TEST_P(GlTexture2D, ConstructorFromMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlTexture2D tex(gold); cv::GlTexture2D tex(gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
tex.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, ConstructorFromGpuMat) TEST_P(GlTexture2D, ConstructorFromGpuMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::gpu::GpuMat d_gold(gold); cv::gpu::GpuMat d_gold(gold);
cv::GlTexture2D tex(d_gold); cv::GlTexture2D tex(d_gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
tex.release();
d_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, ConstructorFromGlBuffer) TEST_P(GlTexture2D, ConstructorFromGlBuffer)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlBuffer buf_gold(gold); cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
cv::GlTexture2D tex(buf_gold); cv::GlTexture2D tex(buf_gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
tex.release();
buf_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, ConstructorFromGlTexture2D) TEST_P(GlTexture2D, ConstructorFromGlTexture2D)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL); cv::GlTexture2D tex_gold(size, format, true);
cv::GlTexture2D tex_gold(size, format);
cv::GlTexture2D tex(tex_gold); cv::GlTexture2D tex(tex_gold);
EXPECT_EQ(tex_gold.texId(), tex.texId()); EXPECT_EQ(tex_gold.texId(), tex.texId());
EXPECT_EQ(tex_gold.rows(), tex.rows()); EXPECT_EQ(tex_gold.rows(), tex.rows());
EXPECT_EQ(tex_gold.cols(), tex.cols()); EXPECT_EQ(tex_gold.cols(), tex.cols());
EXPECT_EQ(tex_gold.format(), tex.format()); EXPECT_EQ(tex_gold.format(), tex.format());
tex.release();
tex_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, Create) TEST_P(GlTexture2D, Create)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::GlTexture2D tex; cv::GlTexture2D tex;
tex.create(size.height, size.width, format); tex.create(size.height, size.width, format, true);
EXPECT_EQ(size.height, tex.rows()); EXPECT_EQ(size.height, tex.rows());
EXPECT_EQ(size.width, tex.cols()); EXPECT_EQ(size.width, tex.cols());
EXPECT_EQ(format, tex.format()); EXPECT_EQ(format, tex.format());
tex.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, CopyFromMat) TEST_P(GlTexture2D, CopyFromMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlTexture2D tex; cv::GlTexture2D tex;
tex.copyFrom(gold); tex.copyFrom(gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
tex.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, CopyFromGpuMat) TEST_P(GlTexture2D, CopyFromGpuMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::gpu::GpuMat d_gold(gold); cv::gpu::GpuMat d_gold(gold);
cv::GlTexture2D tex; cv::GlTexture2D tex;
tex.copyFrom(d_gold); tex.copyFrom(d_gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
tex.release();
d_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, CopyFromGlBuffer) TEST_P(GlTexture2D, CopyFromGlBuffer)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlBuffer buf_gold(gold); cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
cv::GlTexture2D tex; cv::GlTexture2D tex;
tex.copyFrom(buf_gold); tex.copyFrom(buf_gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
tex.release();
buf_gold.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, CopyToGpuMat) TEST_P(GlTexture2D, CopyToGpuMat)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlTexture2D tex(gold); cv::GlTexture2D tex(gold, true);
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
tex.copyTo(dst, depth); tex.copyTo(dst, depth);
EXPECT_MAT_NEAR(gold, dst, 1e-2); EXPECT_MAT_NEAR(gold, dst, 1e-2);
dst.release();
tex.release();
cv::destroyAllWindows();
} }
TEST_P(GlTexture2D, CopyToGlBuffer) TEST_P(GlTexture2D, CopyToGlBuffer)
{ {
cv::namedWindow("test", cv::WINDOW_OPENGL);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlTexture2D tex(gold); cv::GlTexture2D tex(gold, true);
cv::GlBuffer dst; cv::GlBuffer dst;
tex.copyTo(dst, depth); tex.copyTo(dst, depth, true);
cv::Mat bufData; cv::Mat bufData;
dst.copyTo(bufData); dst.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 1e-2); EXPECT_MAT_NEAR(gold, bufData, 1e-2);
dst.release();
tex.release();
cv::destroyAllWindows();
} }
INSTANTIATE_TEST_CASE_P(OpenGL, GlTexture2D, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4))); INSTANTIATE_TEST_CASE_P(OpenGL, GlTexture2D, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4)));