From fa93b724ee219a48b9715555825639ee3f2cac83 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 30 Nov 2011 07:19:09 +0000 Subject: [PATCH] minor --- .../include/opencv2/core/opengl_interop.hpp | 26 ++--- modules/core/src/opengl_interop.cpp | 97 +++++++++++-------- 2 files changed, 71 insertions(+), 52 deletions(-) diff --git a/modules/core/include/opencv2/core/opengl_interop.hpp b/modules/core/include/opencv2/core/opengl_interop.hpp index 59fcbfcda..2782e8cf0 100644 --- a/modules/core/include/opencv2/core/opengl_interop.hpp +++ b/modules/core/include/opencv2/core/opengl_interop.hpp @@ -90,11 +90,10 @@ namespace cv gpu::GpuMat mapDevice(); void unmapDevice(); - int rows; - int cols; - - inline Size size() const { return Size(cols, rows); } - inline bool empty() const { return rows == 0 || cols == 0; } + inline int rows() const { return rows_; } + inline int cols() const { return cols_; } + inline Size size() const { return Size(cols_, rows_); } + inline bool empty() const { return rows_ == 0 || cols_ == 0; } inline int type() const { return type_; } inline int depth() const { return CV_MAT_DEPTH(type_); } @@ -105,6 +104,8 @@ namespace cv inline Usage usage() const { return usage_; } private: + int rows_; + int cols_; int type_; Usage usage_; @@ -138,11 +139,10 @@ namespace cv void bind() const; void unbind() const; - int rows; - int cols; - - inline Size size() const { return Size(cols, rows); } - inline bool empty() const { return rows == 0 || cols == 0; } + inline int rows() const { return rows_; } + inline int cols() const { return cols_; } + inline Size size() const { return Size(cols_, rows_); } + inline bool empty() const { return rows_ == 0 || cols_ == 0; } inline int type() const { return type_; } inline int depth() const { return CV_MAT_DEPTH(type_); } @@ -151,6 +151,8 @@ namespace cv inline int elemSize1() const { return CV_ELEM_SIZE1(type_); } private: + int rows_; + int cols_; int type_; class Impl; @@ -183,8 +185,8 @@ namespace cv void bind() const; void unbind() const; - inline int rows() const { return vertex_.rows; } - inline int cols() const { return vertex_.cols; } + inline int rows() const { return vertex_.rows(); } + inline int cols() const { return vertex_.cols(); } inline Size size() const { return vertex_.size(); } inline bool empty() const { return vertex_.empty(); } diff --git a/modules/core/src/opengl_interop.cpp b/modules/core/src/opengl_interop.cpp index e6bbddc8c..a63553462 100644 --- a/modules/core/src/opengl_interop.cpp +++ b/modules/core/src/opengl_interop.cpp @@ -282,7 +282,8 @@ class cv::GlBuffer::Impl class cv::GlBuffer::Impl { public: - Impl(); + static const Ptr& empty(); + Impl(int rows, int cols, int type, unsigned int target); Impl(const Mat& m, unsigned int target); ~Impl(); @@ -305,6 +306,8 @@ public: #endif private: + Impl(); + unsigned int buffer_; #ifdef HAVE_CUDA @@ -312,6 +315,12 @@ private: #endif }; +inline const Ptr& cv::GlBuffer::Impl::empty() +{ + static Ptr p(new Impl); + return p; +} + inline cv::GlBuffer::Impl::Impl() : buffer_(0) { } @@ -471,40 +480,40 @@ inline void cv::GlBuffer::Impl::unmapDevice(cudaStream_t stream) #endif // HAVE_OPENGL -cv::GlBuffer::GlBuffer(Usage usage) : rows(0), cols(0), type_(0), usage_(usage) +cv::GlBuffer::GlBuffer(Usage usage) : rows_(0), cols_(0), type_(0), usage_(usage) { #ifndef HAVE_OPENGL throw_nogl; #else - impl_ = new Impl; + impl_ = Impl::empty(); #endif } -cv::GlBuffer::GlBuffer(int rows_, int cols_, int type, Usage usage) : rows(0), cols(0), type_(0), usage_(usage) +cv::GlBuffer::GlBuffer(int rows, int cols, int type, Usage usage) : rows_(0), cols_(0), type_(0), usage_(usage) { #ifndef HAVE_OPENGL throw_nogl; #else - impl_ = new Impl(rows_, cols_, type, usage); - rows = rows_; - cols = cols_; + impl_ = new Impl(rows, cols, type, usage); + rows_ = rows; + cols_ = cols; type_ = type; #endif } -cv::GlBuffer::GlBuffer(Size size, int type, Usage usage) : rows(0), cols(0), type_(0), usage_(usage) +cv::GlBuffer::GlBuffer(Size size, int type, Usage usage) : rows_(0), cols_(0), type_(0), usage_(usage) { #ifndef HAVE_OPENGL throw_nogl; #else impl_ = new Impl(size.height, size.width, type, usage); - rows = size.height; - cols = size.width; + rows_ = size.height; + cols_ = size.width; type_ = type; #endif } -cv::GlBuffer::GlBuffer(InputArray mat_, Usage usage) : rows(0), cols(0), type_(0), usage_(usage) +cv::GlBuffer::GlBuffer(InputArray mat_, Usage usage) : rows_(0), cols_(0), type_(0), usage_(usage) { #ifndef HAVE_OPENGL throw_nogl; @@ -529,22 +538,22 @@ cv::GlBuffer::GlBuffer(InputArray mat_, Usage usage) : rows(0), cols(0), type_(0 impl_ = new Impl(mat, usage); } - rows = size.height; - cols = size.width; + rows_ = size.height; + cols_ = size.width; type_ = type; #endif } -void cv::GlBuffer::create(int rows_, int cols_, int type, Usage usage) +void cv::GlBuffer::create(int rows, int cols, int type, Usage usage) { #ifndef HAVE_OPENGL throw_nogl; #else if (rows_ != rows || cols_ != cols || type_ != type || usage_ != usage) { - impl_ = new Impl(rows_, cols_, type, usage); - rows = rows_; - cols = cols_; + impl_ = new Impl(rows, cols, type, usage); + rows_ = rows; + cols_ = cols; type_ = type; usage_ = usage; } @@ -556,7 +565,7 @@ void cv::GlBuffer::release() #ifndef HAVE_OPENGL throw_nogl; #else - impl_ = new Impl; + impl_ = Impl::empty(); #endif } @@ -623,7 +632,7 @@ Mat cv::GlBuffer::mapHost() throw_nogl; return Mat(); #else - return impl_->mapHost(rows, cols, type_, usage_); + return impl_->mapHost(rows_, cols_, type_, usage_); #endif } @@ -646,7 +655,7 @@ GpuMat cv::GlBuffer::mapDevice() throw_nocuda; return GpuMat(); #else - return impl_->mapDevice(rows, cols, type_); + return impl_->mapDevice(rows_, cols_, type_); #endif #endif } @@ -683,7 +692,7 @@ class cv::GlTexture::Impl class cv::GlTexture::Impl { public: - Impl(); + static const Ptr empty(); Impl(int rows, int cols, int type); @@ -699,9 +708,17 @@ public: void unbind() const; private: + Impl(); + GLuint tex_; }; +inline const Ptr cv::GlTexture::Impl::empty() +{ + static Ptr p(new Impl); + return p; +} + inline cv::GlTexture::Impl::Impl() : tex_(0) { } @@ -808,7 +825,7 @@ cv::GlTexture::Impl::Impl(const GlBuffer& buf, bool bgra) : tex_(0) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); CV_CheckGlError(); - glTexImage2D(GL_TEXTURE_2D, 0, cn, buf.cols, buf.rows, 0, format, gl_types[depth], 0); + glTexImage2D(GL_TEXTURE_2D, 0, cn, buf.cols(), buf.rows(), 0, format, gl_types[depth], 0); CV_CheckGlError(); buf.unbind(); @@ -853,7 +870,7 @@ void cv::GlTexture::Impl::copyFrom(const GlBuffer& buf, bool bgra) int cn = buf.channels(); GLenum format = cn == 1 ? GL_LUMINANCE : (cn == 3 ? (bgra ? GL_BGR : GL_RGB) : (bgra ? GL_BGRA : GL_RGBA)); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, buf.cols, buf.rows, format, gl_types[buf.depth()], 0); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, buf.cols(), buf.rows(), format, gl_types[buf.depth()], 0); CV_CheckGlError(); buf.unbind(); @@ -881,40 +898,40 @@ inline void cv::GlTexture::Impl::unbind() const #endif // HAVE_OPENGL -cv::GlTexture::GlTexture() : rows(0), cols(0), type_(0) +cv::GlTexture::GlTexture() : rows_(0), cols_(0), type_(0) { #ifndef HAVE_OPENGL throw_nogl; #else - impl_ = new Impl; + impl_ = Impl::empty(); #endif } -cv::GlTexture::GlTexture(int rows_, int cols_, int type) : rows(0), cols(0), type_(0) +cv::GlTexture::GlTexture(int rows, int cols, int type) : rows_(0), cols_(0), type_(0) { #ifndef HAVE_OPENGL throw_nogl; #else - impl_ = new Impl(rows_, cols_, type); - rows = rows_; - cols = cols_; + impl_ = new Impl(rows, cols, type); + rows_ = rows; + cols_ = cols; type_ = type; #endif } -cv::GlTexture::GlTexture(Size size, int type) : rows(0), cols(0), type_(0) +cv::GlTexture::GlTexture(Size size, int type) : rows_(0), cols_(0), type_(0) { #ifndef HAVE_OPENGL throw_nogl; #else impl_ = new Impl(size.height, size.width, type); - rows = size.height; - cols = size.width; + rows_ = size.height; + cols_ = size.width; type_ = type; #endif } -cv::GlTexture::GlTexture(InputArray mat_, bool bgra) : rows(0), cols(0), type_(0) +cv::GlTexture::GlTexture(InputArray mat_, bool bgra) : rows_(0), cols_(0), type_(0) { #ifndef HAVE_OPENGL throw_nogl; @@ -951,22 +968,22 @@ cv::GlTexture::GlTexture(InputArray mat_, bool bgra) : rows(0), cols(0), type_(0 } } - rows = size.height; - cols = size.width; + rows_ = size.height; + cols_ = size.width; type_ = type; #endif } -void cv::GlTexture::create(int rows_, int cols_, int type) +void cv::GlTexture::create(int rows, int cols, int type) { #ifndef HAVE_OPENGL throw_nogl; #else if (rows_ != rows || cols_ != cols || type_ != type) { - impl_ = new Impl(rows_, cols_, type); - rows = rows_; - cols = cols_; + impl_ = new Impl(rows, cols, type); + rows_ = rows; + cols_ = cols; type_ = type; } #endif @@ -977,7 +994,7 @@ void cv::GlTexture::release() #ifndef HAVE_OPENGL throw_nogl; #else - impl_ = new Impl; + impl_ = Impl::empty(); #endif }