From 2fae1d95074ac1b00a0309e61b6b60db424646e5 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 15 Apr 2013 11:29:21 +0400 Subject: [PATCH] removed ogl::Texture2D support from InputArray --- modules/core/include/opencv2/core/mat.hpp | 6 -- modules/core/src/matrix.cpp | 36 --------- .../src/{opengl_interop.cpp => opengl.cpp} | 20 ----- modules/gpu/test/test_opengl.cpp | 60 --------------- modules/highgui/include/opencv2/highgui.hpp | 2 + modules/highgui/src/window.cpp | 75 ++++++++++++------- modules/superres/src/input_array_utility.cpp | 34 +++------ 7 files changed, 61 insertions(+), 172 deletions(-) rename modules/core/src/{opengl_interop.cpp => opengl.cpp} (98%) diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index e0b943676..2432c3b03 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -77,7 +77,6 @@ public: STD_VECTOR_MAT = 5 << KIND_SHIFT, EXPR = 6 << KIND_SHIFT, OPENGL_BUFFER = 7 << KIND_SHIFT, - OPENGL_TEXTURE = 8 << KIND_SHIFT, GPU_MAT = 9 << KIND_SHIFT }; @@ -94,13 +93,11 @@ public: _InputArray(const double& val); _InputArray(const gpu::GpuMat& d_mat); _InputArray(const ogl::Buffer& buf); - _InputArray(const ogl::Texture2D& tex); virtual Mat getMat(int i=-1) const; virtual void getMatVector(std::vector& mv) const; virtual gpu::GpuMat getGpuMat() const; virtual ogl::Buffer getOGlBuffer() const; - virtual ogl::Texture2D getOGlTexture2D() const; virtual int kind() const; virtual Size size(int i=-1) const; @@ -143,7 +140,6 @@ public: _OutputArray(std::vector& vec); _OutputArray(gpu::GpuMat& d_mat); _OutputArray(ogl::Buffer& buf); - _OutputArray(ogl::Texture2D& tex); template _OutputArray(std::vector<_Tp>& vec); template _OutputArray(std::vector >& vec); template _OutputArray(std::vector >& vec); @@ -155,7 +151,6 @@ public: _OutputArray(const std::vector& vec); _OutputArray(const gpu::GpuMat& d_mat); _OutputArray(const ogl::Buffer& buf); - _OutputArray(const ogl::Texture2D& tex); template _OutputArray(const std::vector<_Tp>& vec); template _OutputArray(const std::vector >& vec); template _OutputArray(const std::vector >& vec); @@ -169,7 +164,6 @@ public: virtual Mat& getMatRef(int i=-1) const; virtual gpu::GpuMat& getGpuMatRef() const; virtual ogl::Buffer& getOGlBufferRef() const; - virtual ogl::Texture2D& getOGlTexture2DRef() const; virtual void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; virtual void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 93dd50aef..7b3af5514 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -948,7 +948,6 @@ _InputArray::_InputArray(const double& val) : flags(FIXED_TYPE + FIXED_SIZE + MA _InputArray::_InputArray(const MatExpr& expr) : flags(FIXED_TYPE + FIXED_SIZE + EXPR), obj((void*)&expr) {} _InputArray::_InputArray(const gpu::GpuMat& d_mat) : flags(GPU_MAT), obj((void*)&d_mat) {} _InputArray::_InputArray(const ogl::Buffer& buf) : flags(OPENGL_BUFFER), obj((void*)&buf) {} -_InputArray::_InputArray(const ogl::Texture2D& tex) : flags(OPENGL_TEXTURE), obj((void*)&tex) {} Mat _InputArray::getMat(int i) const { @@ -1108,16 +1107,6 @@ ogl::Buffer _InputArray::getOGlBuffer() const return *gl_buf; } -ogl::Texture2D _InputArray::getOGlTexture2D() const -{ - int k = kind(); - - CV_Assert(k == OPENGL_TEXTURE); - - const ogl::Texture2D* gl_tex = (const ogl::Texture2D*)obj; - return *gl_tex; -} - int _InputArray::kind() const { return flags & KIND_MASK; @@ -1186,13 +1175,6 @@ Size _InputArray::size(int i) const return buf->size(); } - if( k == OPENGL_TEXTURE ) - { - CV_Assert( i < 0 ); - const ogl::Texture2D* tex = (const ogl::Texture2D*)obj; - return tex->size(); - } - CV_Assert( k == GPU_MAT ); //if( k == GPU_MAT ) { @@ -1304,9 +1286,6 @@ bool _InputArray::empty() const if( k == OPENGL_BUFFER ) return ((const ogl::Buffer*)obj)->empty(); - if( k == OPENGL_TEXTURE ) - return ((const ogl::Texture2D*)obj)->empty(); - CV_Assert( k == GPU_MAT ); //if( k == GPU_MAT ) return ((const gpu::GpuMat*)obj)->empty(); @@ -1319,13 +1298,11 @@ _OutputArray::_OutputArray(Mat& m) : _InputArray(m) {} _OutputArray::_OutputArray(std::vector& vec) : _InputArray(vec) {} _OutputArray::_OutputArray(gpu::GpuMat& d_mat) : _InputArray(d_mat) {} _OutputArray::_OutputArray(ogl::Buffer& buf) : _InputArray(buf) {} -_OutputArray::_OutputArray(ogl::Texture2D& tex) : _InputArray(tex) {} _OutputArray::_OutputArray(const Mat& m) : _InputArray(m) {flags |= FIXED_SIZE|FIXED_TYPE;} _OutputArray::_OutputArray(const std::vector& vec) : _InputArray(vec) {flags |= FIXED_SIZE;} _OutputArray::_OutputArray(const gpu::GpuMat& d_mat) : _InputArray(d_mat) {flags |= FIXED_SIZE|FIXED_TYPE;} _OutputArray::_OutputArray(const ogl::Buffer& buf) : _InputArray(buf) {flags |= FIXED_SIZE|FIXED_TYPE;} -_OutputArray::_OutputArray(const ogl::Texture2D& tex) : _InputArray(tex) {flags |= FIXED_SIZE|FIXED_TYPE;} bool _OutputArray::fixedSize() const @@ -1615,12 +1592,6 @@ void _OutputArray::release() const return; } - if( k == OPENGL_TEXTURE ) - { - ((ogl::Texture2D*)obj)->release(); - return; - } - if( k == NONE ) return; @@ -1693,13 +1664,6 @@ ogl::Buffer& _OutputArray::getOGlBufferRef() const return *(ogl::Buffer*)obj; } -ogl::Texture2D& _OutputArray::getOGlTexture2DRef() const -{ - int k = kind(); - CV_Assert( k == OPENGL_TEXTURE ); - return *(ogl::Texture2D*)obj; -} - static _OutputArray _none; OutputArray noArray() { return _none; } diff --git a/modules/core/src/opengl_interop.cpp b/modules/core/src/opengl.cpp similarity index 98% rename from modules/core/src/opengl_interop.cpp rename to modules/core/src/opengl.cpp index 7c28d73ba..1a10cc397 100644 --- a/modules/core/src/opengl_interop.cpp +++ b/modules/core/src/opengl.cpp @@ -533,12 +533,6 @@ cv::ogl::Buffer::Buffer(InputArray arr, Target target, bool autoRelease) : rows_ break; } - case _InputArray::OPENGL_TEXTURE: - { - copyFrom(arr, target, autoRelease); - break; - } - case _InputArray::GPU_MAT: { copyFrom(arr, target, autoRelease); @@ -613,14 +607,6 @@ void cv::ogl::Buffer::copyFrom(InputArray arr, Target target, bool autoRelease) #else const int kind = arr.kind(); - if (kind == _InputArray::OPENGL_TEXTURE) - { - ogl::Texture2D tex = arr.getOGlTexture2D(); - tex.copyTo(*this); - setAutoRelease(autoRelease); - return; - } - const Size asize = arr.size(); const int atype = arr.type(); create(asize, atype, target, autoRelease); @@ -674,12 +660,6 @@ void cv::ogl::Buffer::copyTo(OutputArray arr, Target target, bool autoRelease) c break; } - case _InputArray::OPENGL_TEXTURE: - { - arr.getOGlTexture2DRef().copyFrom(*this, autoRelease); - break; - } - case _InputArray::GPU_MAT: { #if !defined HAVE_CUDA || defined(CUDA_DISABLER) diff --git a/modules/gpu/test/test_opengl.cpp b/modules/gpu/test/test_opengl.cpp index 8c0f64a93..41bdc8ef3 100644 --- a/modules/gpu/test/test_opengl.cpp +++ b/modules/gpu/test/test_opengl.cpp @@ -126,25 +126,6 @@ GPU_TEST_P(Buffer, ConstructorFromBuffer) EXPECT_EQ(buf_gold.type(), buf.type()); } -GPU_TEST_P(Buffer, ConstructorFromTexture2D) -{ - const int depth = CV_MAT_DEPTH(type); - const int cn = CV_MAT_CN(type); - - if (depth != CV_32F || cn == 2) - return; - - cv::Mat gold = randomMat(size, type, 0, 1.0); - cv::ogl::Texture2D tex_gold(gold, true); - - cv::ogl::Buffer buf(tex_gold, cv::ogl::Buffer::PIXEL_PACK_BUFFER, true); - - cv::Mat bufData; - buf.copyTo(bufData); - - EXPECT_MAT_NEAR(gold, bufData, 1e-2); -} - GPU_TEST_P(Buffer, Create) { cv::ogl::Buffer buf; @@ -198,26 +179,6 @@ GPU_TEST_P(Buffer, CopyFromBuffer) EXPECT_MAT_NEAR(gold, bufData, 0); } -GPU_TEST_P(Buffer, CopyFromTexture2D) -{ - const int depth = CV_MAT_DEPTH(type); - const int cn = CV_MAT_CN(type); - - if (depth != CV_32F || cn == 2) - return; - - cv::Mat gold = randomMat(size, type, 0, 1.0); - cv::ogl::Texture2D tex_gold(gold, true); - - cv::ogl::Buffer buf; - buf.copyFrom(tex_gold, cv::ogl::Buffer::ARRAY_BUFFER, true); - - cv::Mat bufData; - buf.copyTo(bufData); - - EXPECT_MAT_NEAR(gold, bufData, 1e-2); -} - GPU_TEST_P(Buffer, CopyToGpuMat) { cv::Mat gold = randomMat(size, type); @@ -247,27 +208,6 @@ GPU_TEST_P(Buffer, CopyToBuffer) EXPECT_MAT_NEAR(gold, bufData, 0); } -GPU_TEST_P(Buffer, CopyToTexture2D) -{ - const int depth = CV_MAT_DEPTH(type); - const int cn = CV_MAT_CN(type); - - if (depth != CV_32F || cn == 2) - return; - - cv::Mat gold = randomMat(size, type, 0, 1.0); - - cv::ogl::Buffer buf(gold, cv::ogl::Buffer::PIXEL_PACK_BUFFER, true); - - cv::ogl::Texture2D tex; - buf.copyTo(tex, cv::ogl::Buffer::PIXEL_PACK_BUFFER, true); - - cv::Mat texData; - tex.copyTo(texData); - - EXPECT_MAT_NEAR(gold, texData, 1e-2); -} - GPU_TEST_P(Buffer, Clone) { cv::Mat gold = randomMat(size, type); diff --git a/modules/highgui/include/opencv2/highgui.hpp b/modules/highgui/include/opencv2/highgui.hpp index f7e611900..c20cf883e 100644 --- a/modules/highgui/include/opencv2/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui.hpp @@ -148,6 +148,8 @@ CV_EXPORTS_W void setTrackbarPos(const String& trackbarname, const String& winna // OpenGL support +CV_EXPORTS void imshow(const String& winname, const ogl::Texture2D& tex); + CV_EXPORTS void setOpenGlDrawCallback(const String& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0); CV_EXPORTS void setOpenGlContext(const String& winname); diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index fdaadc7cb..701f5f578 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -281,39 +281,64 @@ void cv::imshow( const String& winname, InputArray _img ) setOpenGlContext(winname); - if (_img.kind() == _InputArray::OPENGL_TEXTURE) + cv::ogl::Texture2D& tex = ownWndTexs[winname]; + + if (_img.kind() == _InputArray::GPU_MAT) { - cv::ogl::Texture2D& tex = wndTexs[winname]; - - tex = _img.getOGlTexture2D(); + cv::ogl::Buffer& buf = ownWndBufs[winname]; + buf.copyFrom(_img); + buf.setAutoRelease(false); + tex.copyFrom(buf); tex.setAutoRelease(false); - - setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex); } else { - cv::ogl::Texture2D& tex = ownWndTexs[winname]; - - if (_img.kind() == _InputArray::GPU_MAT) - { - cv::ogl::Buffer& buf = ownWndBufs[winname]; - buf.copyFrom(_img); - buf.setAutoRelease(false); - - tex.copyFrom(buf); - tex.setAutoRelease(false); - } - else - { - tex.copyFrom(_img); - } - - tex.setAutoRelease(false); - - setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex); + tex.copyFrom(_img); } + tex.setAutoRelease(false); + + setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex); + + updateWindow(winname); + } +#endif +} + +void cv::imshow(const String& winname, const ogl::Texture2D& _tex) +{ +#ifndef HAVE_OPENGL + (void) winname; + (void) _tex; + CV_Error(cv::Error::OpenGlNotSupported, "The library is compiled without OpenGL support"); +#else + const double useGl = getWindowProperty(winname, WND_PROP_OPENGL); + + if (useGl <= 0) + { + CV_Error(cv::Error::OpenGlNotSupported, "The window was created without OpenGL context"); + } + else + { + const double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE); + + if (autoSize > 0) + { + Size size = _tex.size(); + resizeWindow(winname, size.width, size.height); + } + + setOpenGlContext(winname); + + cv::ogl::Texture2D& tex = wndTexs[winname]; + + tex = _tex; + + tex.setAutoRelease(false); + + setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex); + updateWindow(winname); } #endif diff --git a/modules/superres/src/input_array_utility.cpp b/modules/superres/src/input_array_utility.cpp index c2850206b..e74905089 100644 --- a/modules/superres/src/input_array_utility.cpp +++ b/modules/superres/src/input_array_utility.cpp @@ -57,10 +57,6 @@ Mat cv::superres::arrGetMat(InputArray arr, Mat& buf) arr.getOGlBuffer().copyTo(buf); return buf; - case _InputArray::OPENGL_TEXTURE: - arr.getOGlTexture2D().copyTo(buf); - return buf; - default: return arr.getMat(); } @@ -77,10 +73,6 @@ GpuMat cv::superres::arrGetGpuMat(InputArray arr, GpuMat& buf) arr.getOGlBuffer().copyTo(buf); return buf; - case _InputArray::OPENGL_TEXTURE: - arr.getOGlTexture2D().copyTo(buf); - return buf; - default: buf.upload(arr.getMat()); return buf; @@ -97,10 +89,6 @@ namespace { dst.getOGlBufferRef().copyFrom(src); } - void arr2tex(InputArray src, OutputArray dst) - { - dst.getOGlTexture2D().copyFrom(src); - } void mat2gpu(InputArray src, OutputArray dst) { dst.getGpuMatRef().upload(src.getMat()); @@ -109,10 +97,6 @@ namespace { src.getOGlBuffer().copyTo(dst); } - void tex2arr(InputArray src, OutputArray dst) - { - src.getOGlTexture2D().copyTo(dst); - } void gpu2mat(InputArray src, OutputArray dst) { GpuMat d = src.getGpuMat(); @@ -132,15 +116,15 @@ void cv::superres::arrCopy(InputArray src, OutputArray dst) static const func_t funcs[10][10] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu}, - {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu}, - {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu}, - {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu}, - {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu}, - {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu}, - {0, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr}, - {0, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr}, - {0, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, arr2buf, arr2tex, gpu2gpu} + {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu}, + {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu}, + {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu}, + {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu}, + {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu}, + {0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu}, + {0, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, 0 /*buf2arr*/, buf2arr}, + {0, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/}, + {0, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, arr2buf, 0 /*arr2tex*/, gpu2gpu} }; const int src_kind = src.kind() >> _InputArray::KIND_SHIFT;