void cv::ogl::Arrays::setColorArray(InputArray color) { const int cn = color.channels(); CV_Assert( cn == 3 || cn == 4 ); if (color.kind() == _InputArray::OPENGL_BUFFER) color_ = color.getOGlBuffer(); else color_.copyFrom(color); }
void cv::ogl::Buffer::copyFrom(InputArray arr, Target target, bool autoRelease) { #ifndef HAVE_OPENGL (void) arr; (void) target; (void) autoRelease; throw_nogl(); #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); switch (kind) { case _InputArray::OPENGL_BUFFER: { ogl::Buffer buf = arr.getOGlBuffer(); impl_->copyFrom(buf.bufId(), asize.area() * CV_ELEM_SIZE(atype)); break; } case _InputArray::GPU_MAT: { #if !defined HAVE_CUDA || defined(CUDA_DISABLER) throw_nocuda(); #else GpuMat dmat = arr.getGpuMat(); impl_->copyFrom(dmat.data, dmat.step, dmat.cols * dmat.elemSize(), dmat.rows); #endif break; } default: { Mat mat = arr.getMat(); CV_Assert( mat.isContinuous() ); impl_->copyFrom(asize.area() * CV_ELEM_SIZE(atype), mat.data); } } #endif }
void cv::ogl::Arrays::setTexCoordArray(InputArray texCoord) { const int cn = texCoord.channels(); const int depth = texCoord.depth(); CV_Assert( cn >= 1 && cn <= 4 ); CV_Assert( depth == CV_16S || depth == CV_32S || depth == CV_32F || depth == CV_64F ); if (texCoord.kind() == _InputArray::OPENGL_BUFFER) texCoord_ = texCoord.getOGlBuffer(); else texCoord_.copyFrom(texCoord); }
void cv::ogl::Arrays::setNormalArray(InputArray normal) { const int cn = normal.channels(); const int depth = normal.depth(); CV_Assert( cn == 3 ); CV_Assert( depth == CV_8S || depth == CV_16S || depth == CV_32S || depth == CV_32F || depth == CV_64F ); if (normal.kind() == _InputArray::OPENGL_BUFFER) normal_ = normal.getOGlBuffer(); else normal_.copyFrom(normal); }
void cv::ogl::Arrays::setVertexArray(InputArray vertex) { const int cn = vertex.channels(); const int depth = vertex.depth(); CV_Assert( cn == 2 || cn == 3 || cn == 4 ); CV_Assert( depth == CV_16S || depth == CV_32S || depth == CV_32F || depth == CV_64F ); if (vertex.kind() == _InputArray::OPENGL_BUFFER) vertex_ = vertex.getOGlBuffer(); else vertex_.copyFrom(vertex); size_ = vertex_.size().area(); }
GpuMat cv::superres::arrGetGpuMat(InputArray arr, GpuMat& buf) { switch (arr.kind()) { case _InputArray::GPU_MAT: return arr.getGpuMat(); case _InputArray::OPENGL_BUFFER: arr.getOGlBuffer().copyTo(buf); return buf; default: buf.upload(arr.getMat()); return buf; } }
UMat cv::superres::arrGetUMat(InputArray arr, UMat& buf) { switch (arr.kind()) { case _InputArray::CUDA_GPU_MAT: arr.getGpuMat().download(buf); return buf; case _InputArray::OPENGL_BUFFER: arr.getOGlBuffer().copyTo(buf); return buf; default: return arr.getUMat(); } }
void cv::ogl::Buffer::copyFrom(InputArray arr, Target target, bool autoRelease) { #ifndef HAVE_OPENGL (void) arr; (void) target; (void) autoRelease; throw_no_ogl(); #else const int kind = arr.kind(); const Size asize = arr.size(); const int atype = arr.type(); create(asize, atype, target, autoRelease); switch (kind) { case _InputArray::OPENGL_BUFFER: { ogl::Buffer buf = arr.getOGlBuffer(); impl_->copyFrom(buf.bufId(), asize.area() * CV_ELEM_SIZE(atype)); break; } case _InputArray::CUDA_GPU_MAT: { #ifndef HAVE_CUDA throw_no_cuda(); #else GpuMat dmat = arr.getGpuMat(); impl_->copyFrom(dmat.data, dmat.step, dmat.cols * dmat.elemSize(), dmat.rows); #endif break; } default: { Mat mat = arr.getMat(); CV_Assert( mat.isContinuous() ); impl_->copyFrom(asize.area() * CV_ELEM_SIZE(atype), mat.data); } } #endif }
cv::ogl::Texture2D::Texture2D(InputArray arr, bool autoRelease) : rows_(0), cols_(0), format_(NONE) { #ifndef HAVE_OPENGL (void) arr; (void) autoRelease; throw_no_ogl(); #else const int kind = arr.kind(); const Size asize = arr.size(); const int atype = arr.type(); const int depth = CV_MAT_DEPTH(atype); const int cn = CV_MAT_CN(atype); CV_Assert( depth <= CV_32F ); CV_Assert( cn == 1 || cn == 3 || cn == 4 ); const Format internalFormats[] = { NONE, DEPTH_COMPONENT, NONE, RGB, RGBA }; const GLenum srcFormats[] = { 0, gl::DEPTH_COMPONENT, 0, gl::BGR, gl::BGRA }; switch (kind) { case _InputArray::OPENGL_BUFFER: { ogl::Buffer buf = arr.getOGlBuffer(); buf.bind(ogl::Buffer::PIXEL_UNPACK_BUFFER); impl_.reset(new Impl(internalFormats[cn], asize.width, asize.height, srcFormats[cn], gl_types[depth], 0, autoRelease)); ogl::Buffer::unbind(ogl::Buffer::PIXEL_UNPACK_BUFFER); break; } case _InputArray::GPU_MAT: { #ifndef HAVE_CUDA throw_no_cuda(); #else GpuMat dmat = arr.getGpuMat(); ogl::Buffer buf(dmat, ogl::Buffer::PIXEL_UNPACK_BUFFER); buf.bind(ogl::Buffer::PIXEL_UNPACK_BUFFER); impl_.reset(new Impl(internalFormats[cn], asize.width, asize.height, srcFormats[cn], gl_types[depth], 0, autoRelease)); ogl::Buffer::unbind(ogl::Buffer::PIXEL_UNPACK_BUFFER); #endif break; } default: { Mat mat = arr.getMat(); CV_Assert( mat.isContinuous() ); ogl::Buffer::unbind(ogl::Buffer::PIXEL_UNPACK_BUFFER); impl_.reset(new Impl(internalFormats[cn], asize.width, asize.height, srcFormats[cn], gl_types[depth], mat.data, autoRelease)); break; } } rows_ = asize.height; cols_ = asize.width; format_ = internalFormats[cn]; #endif }
void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scalar color) { #ifndef HAVE_OPENGL (void) arr; (void) indices; (void) mode; (void) color; throw_no_ogl(); #else if (!arr.empty() && !indices.empty()) { gl::Color3d(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0); arr.bind(); const int kind = indices.kind(); switch (kind) { case _InputArray::OPENGL_BUFFER : { ogl::Buffer buf = indices.getOGlBuffer(); const int depth = buf.depth(); CV_Assert( buf.channels() == 1 ); CV_Assert( depth <= CV_32S ); GLenum type; if (depth < CV_16U) type = gl::UNSIGNED_BYTE; else if (depth < CV_32S) type = gl::UNSIGNED_SHORT; else type = gl::UNSIGNED_INT; buf.bind(ogl::Buffer::ELEMENT_ARRAY_BUFFER); gl::DrawElements(mode, buf.size().area(), type, 0); ogl::Buffer::unbind(ogl::Buffer::ELEMENT_ARRAY_BUFFER); break; } default: { Mat mat = indices.getMat(); const int depth = mat.depth(); CV_Assert( mat.channels() == 1 ); CV_Assert( depth <= CV_32S ); CV_Assert( mat.isContinuous() ); GLenum type; if (depth < CV_16U) type = gl::UNSIGNED_BYTE; else if (depth < CV_32S) type = gl::UNSIGNED_SHORT; else type = gl::UNSIGNED_INT; ogl::Buffer::unbind(ogl::Buffer::ELEMENT_ARRAY_BUFFER); gl::DrawElements(mode, mat.size().area(), type, mat.data); } } } #endif }
void cv::ogl::Texture2D::copyFrom(InputArray arr, bool autoRelease) { #ifndef HAVE_OPENGL (void) arr; (void) autoRelease; throw_nogl(); #else const int kind = arr.kind(); const Size asize = arr.size(); const int atype = arr.type(); const int depth = CV_MAT_DEPTH(atype); const int cn = CV_MAT_CN(atype); CV_Assert( depth <= CV_32F ); CV_Assert( cn == 1 || cn == 3 || cn == 4 ); const Format internalFormats[] = { NONE, DEPTH_COMPONENT, NONE, RGB, RGBA }; const GLenum srcFormats[] = { 0, gl::DEPTH_COMPONENT, 0, gl::BGR, gl::BGRA }; create(asize, internalFormats[cn], autoRelease); switch(kind) { case _InputArray::OPENGL_BUFFER: { ogl::Buffer buf = arr.getOGlBuffer(); buf.bind(ogl::Buffer::PIXEL_UNPACK_BUFFER); impl_->copyFrom(asize.width, asize.height, srcFormats[cn], gl_types[depth], 0); ogl::Buffer::unbind(ogl::Buffer::PIXEL_UNPACK_BUFFER); break; } case _InputArray::GPU_MAT: { #if !defined HAVE_CUDA || defined(CUDA_DISABLER) throw_nocuda(); #else GpuMat dmat = arr.getGpuMat(); ogl::Buffer buf(dmat, ogl::Buffer::PIXEL_UNPACK_BUFFER); buf.bind(ogl::Buffer::PIXEL_UNPACK_BUFFER); impl_->copyFrom(asize.width, asize.height, srcFormats[cn], gl_types[depth], 0); ogl::Buffer::unbind(ogl::Buffer::PIXEL_UNPACK_BUFFER); #endif break; } default: { Mat mat = arr.getMat(); CV_Assert( mat.isContinuous() ); ogl::Buffer::unbind(ogl::Buffer::PIXEL_UNPACK_BUFFER); impl_->copyFrom(asize.width, asize.height, srcFormats[cn], gl_types[depth], mat.data); } } #endif }