opengl.hpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #ifndef OPENCV_CORE_OPENGL_HPP
  43. #define OPENCV_CORE_OPENGL_HPP
  44. #ifndef __cplusplus
  45. # error opengl.hpp header must be compiled as C++
  46. #endif
  47. #include "opencv2/core.hpp"
  48. #include "ocl.hpp"
  49. namespace cv { namespace ogl {
  50. /** @addtogroup core_opengl
  51. This section describes OpenGL interoperability.
  52. To enable OpenGL support, configure OpenCV using CMake with WITH_OPENGL=ON . Currently OpenGL is
  53. supported only with WIN32, GTK and Qt backends on Windows and Linux (MacOS and Android are not
  54. supported). For GTK backend gtkglext-1.0 library is required.
  55. To use OpenGL functionality you should first create OpenGL context (window or frame buffer). You can
  56. do this with namedWindow function or with other OpenGL toolkit (GLUT, for example).
  57. */
  58. //! @{
  59. /////////////////// OpenGL Objects ///////////////////
  60. /** @brief Smart pointer for OpenGL buffer object with reference counting.
  61. Buffer Objects are OpenGL objects that store an array of unformatted memory allocated by the OpenGL
  62. context. These can be used to store vertex data, pixel data retrieved from images or the
  63. framebuffer, and a variety of other things.
  64. ogl::Buffer has interface similar with Mat interface and represents 2D array memory.
  65. ogl::Buffer supports memory transfers between host and device and also can be mapped to CUDA memory.
  66. */
  67. class CV_EXPORTS Buffer
  68. {
  69. public:
  70. /** @brief The target defines how you intend to use the buffer object.
  71. */
  72. enum Target
  73. {
  74. ARRAY_BUFFER = 0x8892, //!< The buffer will be used as a source for vertex data
  75. ELEMENT_ARRAY_BUFFER = 0x8893, //!< The buffer will be used for indices (in glDrawElements, for example)
  76. PIXEL_PACK_BUFFER = 0x88EB, //!< The buffer will be used for reading from OpenGL textures
  77. PIXEL_UNPACK_BUFFER = 0x88EC //!< The buffer will be used for writing to OpenGL textures
  78. };
  79. enum Access
  80. {
  81. READ_ONLY = 0x88B8,
  82. WRITE_ONLY = 0x88B9,
  83. READ_WRITE = 0x88BA
  84. };
  85. /** @brief The constructors.
  86. Creates empty ogl::Buffer object, creates ogl::Buffer object from existed buffer ( abufId
  87. parameter), allocates memory for ogl::Buffer object or copies from host/device memory.
  88. */
  89. Buffer();
  90. /** @overload
  91. @param arows Number of rows in a 2D array.
  92. @param acols Number of columns in a 2D array.
  93. @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
  94. @param abufId Buffer object name.
  95. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  96. */
  97. Buffer(int arows, int acols, int atype, unsigned int abufId, bool autoRelease = false);
  98. /** @overload
  99. @param asize 2D array size.
  100. @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
  101. @param abufId Buffer object name.
  102. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  103. */
  104. Buffer(Size asize, int atype, unsigned int abufId, bool autoRelease = false);
  105. /** @overload
  106. @param arows Number of rows in a 2D array.
  107. @param acols Number of columns in a 2D array.
  108. @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
  109. @param target Buffer usage. See cv::ogl::Buffer::Target .
  110. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  111. */
  112. Buffer(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
  113. /** @overload
  114. @param asize 2D array size.
  115. @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
  116. @param target Buffer usage. See cv::ogl::Buffer::Target .
  117. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  118. */
  119. Buffer(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
  120. /** @overload
  121. @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ).
  122. @param target Buffer usage. See cv::ogl::Buffer::Target .
  123. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  124. */
  125. explicit Buffer(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
  126. /** @brief Allocates memory for ogl::Buffer object.
  127. @param arows Number of rows in a 2D array.
  128. @param acols Number of columns in a 2D array.
  129. @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
  130. @param target Buffer usage. See cv::ogl::Buffer::Target .
  131. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  132. */
  133. void create(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
  134. /** @overload
  135. @param asize 2D array size.
  136. @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
  137. @param target Buffer usage. See cv::ogl::Buffer::Target .
  138. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  139. */
  140. void create(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
  141. /** @brief Decrements the reference counter and destroys the buffer object if needed.
  142. The function will call setAutoRelease(true) .
  143. */
  144. void release();
  145. /** @brief Sets auto release mode.
  146. The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was
  147. bound to a window it could be released at any time (user can close a window). If object's destructor
  148. is called after destruction of the context it will cause an error. Thus ogl::Buffer doesn't destroy
  149. OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL context).
  150. This function can force ogl::Buffer destructor to destroy OpenGL object.
  151. @param flag Auto release mode (if true, release will be called in object's destructor).
  152. */
  153. void setAutoRelease(bool flag);
  154. /** @brief Copies from host/device memory to OpenGL buffer.
  155. @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ).
  156. @param target Buffer usage. See cv::ogl::Buffer::Target .
  157. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  158. */
  159. void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
  160. /** @overload */
  161. void copyFrom(InputArray arr, cuda::Stream& stream, Target target = ARRAY_BUFFER, bool autoRelease = false);
  162. /** @brief Copies from OpenGL buffer to host/device memory or another OpenGL buffer object.
  163. @param arr Destination array (host or device memory, can be Mat , cuda::GpuMat , std::vector or
  164. ogl::Buffer ).
  165. */
  166. void copyTo(OutputArray arr) const;
  167. /** @overload */
  168. void copyTo(OutputArray arr, cuda::Stream& stream) const;
  169. /** @brief Creates a full copy of the buffer object and the underlying data.
  170. @param target Buffer usage for destination buffer.
  171. @param autoRelease Auto release mode for destination buffer.
  172. */
  173. Buffer clone(Target target = ARRAY_BUFFER, bool autoRelease = false) const;
  174. /** @brief Binds OpenGL buffer to the specified buffer binding point.
  175. @param target Binding point. See cv::ogl::Buffer::Target .
  176. */
  177. void bind(Target target) const;
  178. /** @brief Unbind any buffers from the specified binding point.
  179. @param target Binding point. See cv::ogl::Buffer::Target .
  180. */
  181. static void unbind(Target target);
  182. /** @brief Maps OpenGL buffer to host memory.
  183. mapHost maps to the client's address space the entire data store of the buffer object. The data can
  184. then be directly read and/or written relative to the returned pointer, depending on the specified
  185. access policy.
  186. A mapped data store must be unmapped with ogl::Buffer::unmapHost before its buffer object is used.
  187. This operation can lead to memory transfers between host and device.
  188. Only one buffer object can be mapped at a time.
  189. @param access Access policy, indicating whether it will be possible to read from, write to, or both
  190. read from and write to the buffer object's mapped data store. The symbolic constant must be
  191. ogl::Buffer::READ_ONLY , ogl::Buffer::WRITE_ONLY or ogl::Buffer::READ_WRITE .
  192. */
  193. Mat mapHost(Access access);
  194. /** @brief Unmaps OpenGL buffer.
  195. */
  196. void unmapHost();
  197. //! map to device memory (blocking)
  198. cuda::GpuMat mapDevice();
  199. void unmapDevice();
  200. /** @brief Maps OpenGL buffer to CUDA device memory.
  201. This operation doesn't copy data. Several buffer objects can be mapped to CUDA memory at a time.
  202. A mapped data store must be unmapped with ogl::Buffer::unmapDevice before its buffer object is used.
  203. */
  204. cuda::GpuMat mapDevice(cuda::Stream& stream);
  205. /** @brief Unmaps OpenGL buffer.
  206. */
  207. void unmapDevice(cuda::Stream& stream);
  208. int rows() const;
  209. int cols() const;
  210. Size size() const;
  211. bool empty() const;
  212. int type() const;
  213. int depth() const;
  214. int channels() const;
  215. int elemSize() const;
  216. int elemSize1() const;
  217. //! get OpenGL opject id
  218. unsigned int bufId() const;
  219. class Impl;
  220. private:
  221. Ptr<Impl> impl_;
  222. int rows_;
  223. int cols_;
  224. int type_;
  225. };
  226. /** @brief Smart pointer for OpenGL 2D texture memory with reference counting.
  227. */
  228. class CV_EXPORTS Texture2D
  229. {
  230. public:
  231. /** @brief An Image Format describes the way that the images in Textures store their data.
  232. */
  233. enum Format
  234. {
  235. NONE = 0,
  236. DEPTH_COMPONENT = 0x1902, //!< Depth
  237. RGB = 0x1907, //!< Red, Green, Blue
  238. RGBA = 0x1908 //!< Red, Green, Blue, Alpha
  239. };
  240. /** @brief The constructors.
  241. Creates empty ogl::Texture2D object, allocates memory for ogl::Texture2D object or copies from
  242. host/device memory.
  243. */
  244. Texture2D();
  245. /** @overload */
  246. Texture2D(int arows, int acols, Format aformat, unsigned int atexId, bool autoRelease = false);
  247. /** @overload */
  248. Texture2D(Size asize, Format aformat, unsigned int atexId, bool autoRelease = false);
  249. /** @overload
  250. @param arows Number of rows.
  251. @param acols Number of columns.
  252. @param aformat Image format. See cv::ogl::Texture2D::Format .
  253. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  254. */
  255. Texture2D(int arows, int acols, Format aformat, bool autoRelease = false);
  256. /** @overload
  257. @param asize 2D array size.
  258. @param aformat Image format. See cv::ogl::Texture2D::Format .
  259. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  260. */
  261. Texture2D(Size asize, Format aformat, bool autoRelease = false);
  262. /** @overload
  263. @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ).
  264. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  265. */
  266. explicit Texture2D(InputArray arr, bool autoRelease = false);
  267. /** @brief Allocates memory for ogl::Texture2D object.
  268. @param arows Number of rows.
  269. @param acols Number of columns.
  270. @param aformat Image format. See cv::ogl::Texture2D::Format .
  271. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  272. */
  273. void create(int arows, int acols, Format aformat, bool autoRelease = false);
  274. /** @overload
  275. @param asize 2D array size.
  276. @param aformat Image format. See cv::ogl::Texture2D::Format .
  277. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  278. */
  279. void create(Size asize, Format aformat, bool autoRelease = false);
  280. /** @brief Decrements the reference counter and destroys the texture object if needed.
  281. The function will call setAutoRelease(true) .
  282. */
  283. void release();
  284. /** @brief Sets auto release mode.
  285. @param flag Auto release mode (if true, release will be called in object's destructor).
  286. The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was
  287. bound to a window it could be released at any time (user can close a window). If object's destructor
  288. is called after destruction of the context it will cause an error. Thus ogl::Texture2D doesn't
  289. destroy OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL
  290. context). This function can force ogl::Texture2D destructor to destroy OpenGL object.
  291. */
  292. void setAutoRelease(bool flag);
  293. /** @brief Copies from host/device memory to OpenGL texture.
  294. @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ).
  295. @param autoRelease Auto release mode (if true, release will be called in object's destructor).
  296. */
  297. void copyFrom(InputArray arr, bool autoRelease = false);
  298. /** @brief Copies from OpenGL texture to host/device memory or another OpenGL texture object.
  299. @param arr Destination array (host or device memory, can be Mat , cuda::GpuMat , ogl::Buffer or
  300. ogl::Texture2D ).
  301. @param ddepth Destination depth.
  302. @param autoRelease Auto release mode for destination buffer (if arr is OpenGL buffer or texture).
  303. */
  304. void copyTo(OutputArray arr, int ddepth = CV_32F, bool autoRelease = false) const;
  305. /** @brief Binds texture to current active texture unit for GL_TEXTURE_2D target.
  306. */
  307. void bind() const;
  308. int rows() const;
  309. int cols() const;
  310. Size size() const;
  311. bool empty() const;
  312. Format format() const;
  313. //! get OpenGL opject id
  314. unsigned int texId() const;
  315. class Impl;
  316. private:
  317. Ptr<Impl> impl_;
  318. int rows_;
  319. int cols_;
  320. Format format_;
  321. };
  322. /** @brief Wrapper for OpenGL Client-Side Vertex arrays.
  323. ogl::Arrays stores vertex data in ogl::Buffer objects.
  324. */
  325. class CV_EXPORTS Arrays
  326. {
  327. public:
  328. /** @brief Default constructor
  329. */
  330. Arrays();
  331. /** @brief Sets an array of vertex coordinates.
  332. @param vertex array with vertex coordinates, can be both host and device memory.
  333. */
  334. void setVertexArray(InputArray vertex);
  335. /** @brief Resets vertex coordinates.
  336. */
  337. void resetVertexArray();
  338. /** @brief Sets an array of vertex colors.
  339. @param color array with vertex colors, can be both host and device memory.
  340. */
  341. void setColorArray(InputArray color);
  342. /** @brief Resets vertex colors.
  343. */
  344. void resetColorArray();
  345. /** @brief Sets an array of vertex normals.
  346. @param normal array with vertex normals, can be both host and device memory.
  347. */
  348. void setNormalArray(InputArray normal);
  349. /** @brief Resets vertex normals.
  350. */
  351. void resetNormalArray();
  352. /** @brief Sets an array of vertex texture coordinates.
  353. @param texCoord array with vertex texture coordinates, can be both host and device memory.
  354. */
  355. void setTexCoordArray(InputArray texCoord);
  356. /** @brief Resets vertex texture coordinates.
  357. */
  358. void resetTexCoordArray();
  359. /** @brief Releases all inner buffers.
  360. */
  361. void release();
  362. /** @brief Sets auto release mode all inner buffers.
  363. @param flag Auto release mode.
  364. */
  365. void setAutoRelease(bool flag);
  366. /** @brief Binds all vertex arrays.
  367. */
  368. void bind() const;
  369. /** @brief Returns the vertex count.
  370. */
  371. int size() const;
  372. bool empty() const;
  373. private:
  374. int size_;
  375. Buffer vertex_;
  376. Buffer color_;
  377. Buffer normal_;
  378. Buffer texCoord_;
  379. };
  380. /////////////////// Render Functions ///////////////////
  381. //! render mode
  382. enum RenderModes {
  383. POINTS = 0x0000,
  384. LINES = 0x0001,
  385. LINE_LOOP = 0x0002,
  386. LINE_STRIP = 0x0003,
  387. TRIANGLES = 0x0004,
  388. TRIANGLE_STRIP = 0x0005,
  389. TRIANGLE_FAN = 0x0006,
  390. QUADS = 0x0007,
  391. QUAD_STRIP = 0x0008,
  392. POLYGON = 0x0009
  393. };
  394. /** @brief Render OpenGL texture or primitives.
  395. @param tex Texture to draw.
  396. @param wndRect Region of window, where to draw a texture (normalized coordinates).
  397. @param texRect Region of texture to draw (normalized coordinates).
  398. */
  399. CV_EXPORTS void render(const Texture2D& tex,
  400. Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
  401. Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
  402. /** @overload
  403. @param arr Array of privitives vertices.
  404. @param mode Render mode. One of cv::ogl::RenderModes
  405. @param color Color for all vertices. Will be used if arr doesn't contain color array.
  406. */
  407. CV_EXPORTS void render(const Arrays& arr, int mode = POINTS, Scalar color = Scalar::all(255));
  408. /** @overload
  409. @param arr Array of privitives vertices.
  410. @param indices Array of vertices indices (host or device memory).
  411. @param mode Render mode. One of cv::ogl::RenderModes
  412. @param color Color for all vertices. Will be used if arr doesn't contain color array.
  413. */
  414. CV_EXPORTS void render(const Arrays& arr, InputArray indices, int mode = POINTS, Scalar color = Scalar::all(255));
  415. /////////////////// CL-GL Interoperability Functions ///////////////////
  416. namespace ocl {
  417. using namespace cv::ocl;
  418. // TODO static functions in the Context class
  419. /** @brief Creates OpenCL context from GL.
  420. @return Returns reference to OpenCL Context
  421. */
  422. CV_EXPORTS Context& initializeContextFromGL();
  423. } // namespace cv::ogl::ocl
  424. /** @brief Converts InputArray to Texture2D object.
  425. @param src - source InputArray.
  426. @param texture - destination Texture2D object.
  427. */
  428. CV_EXPORTS void convertToGLTexture2D(InputArray src, Texture2D& texture);
  429. /** @brief Converts Texture2D object to OutputArray.
  430. @param texture - source Texture2D object.
  431. @param dst - destination OutputArray.
  432. */
  433. CV_EXPORTS void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst);
  434. /** @brief Maps Buffer object to process on CL side (convert to UMat).
  435. Function creates CL buffer from GL one, and then constructs UMat that can be used
  436. to process buffer data with OpenCV functions. Note that in current implementation
  437. UMat constructed this way doesn't own corresponding GL buffer object, so it is
  438. the user responsibility to close down CL/GL buffers relationships by explicitly
  439. calling unmapGLBuffer() function.
  440. @param buffer - source Buffer object.
  441. @param accessFlags - data access flags (ACCESS_READ|ACCESS_WRITE).
  442. @return Returns UMat object
  443. */
  444. CV_EXPORTS UMat mapGLBuffer(const Buffer& buffer, AccessFlag accessFlags = ACCESS_READ | ACCESS_WRITE);
  445. /** @brief Unmaps Buffer object (releases UMat, previously mapped from Buffer).
  446. Function must be called explicitly by the user for each UMat previously constructed
  447. by the call to mapGLBuffer() function.
  448. @param u - source UMat, created by mapGLBuffer().
  449. */
  450. CV_EXPORTS void unmapGLBuffer(UMat& u);
  451. //! @}
  452. }} // namespace cv::ogl
  453. namespace cv { namespace cuda {
  454. /** @brief Sets a CUDA device and initializes it for the current thread with OpenGL interoperability.
  455. This function should be explicitly called after OpenGL context creation and before any CUDA calls.
  456. @param device System index of a CUDA device starting with 0.
  457. @ingroup core_opengl
  458. */
  459. CV_EXPORTS void setGlDevice(int device = 0);
  460. }}
  461. //! @cond IGNORED
  462. ////////////////////////////////////////////////////////////////////////
  463. ////////////////////////////////////////////////////////////////////////
  464. ////////////////////////////////////////////////////////////////////////
  465. inline
  466. cv::ogl::Buffer::Buffer(int arows, int acols, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
  467. {
  468. create(arows, acols, atype, target, autoRelease);
  469. }
  470. inline
  471. cv::ogl::Buffer::Buffer(Size asize, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
  472. {
  473. create(asize, atype, target, autoRelease);
  474. }
  475. inline
  476. void cv::ogl::Buffer::create(Size asize, int atype, Target target, bool autoRelease)
  477. {
  478. create(asize.height, asize.width, atype, target, autoRelease);
  479. }
  480. inline
  481. int cv::ogl::Buffer::rows() const
  482. {
  483. return rows_;
  484. }
  485. inline
  486. int cv::ogl::Buffer::cols() const
  487. {
  488. return cols_;
  489. }
  490. inline
  491. cv::Size cv::ogl::Buffer::size() const
  492. {
  493. return Size(cols_, rows_);
  494. }
  495. inline
  496. bool cv::ogl::Buffer::empty() const
  497. {
  498. return rows_ == 0 || cols_ == 0;
  499. }
  500. inline
  501. int cv::ogl::Buffer::type() const
  502. {
  503. return type_;
  504. }
  505. inline
  506. int cv::ogl::Buffer::depth() const
  507. {
  508. return CV_MAT_DEPTH(type_);
  509. }
  510. inline
  511. int cv::ogl::Buffer::channels() const
  512. {
  513. return CV_MAT_CN(type_);
  514. }
  515. inline
  516. int cv::ogl::Buffer::elemSize() const
  517. {
  518. return CV_ELEM_SIZE(type_);
  519. }
  520. inline
  521. int cv::ogl::Buffer::elemSize1() const
  522. {
  523. return CV_ELEM_SIZE1(type_);
  524. }
  525. ///////
  526. inline
  527. cv::ogl::Texture2D::Texture2D(int arows, int acols, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE)
  528. {
  529. create(arows, acols, aformat, autoRelease);
  530. }
  531. inline
  532. cv::ogl::Texture2D::Texture2D(Size asize, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE)
  533. {
  534. create(asize, aformat, autoRelease);
  535. }
  536. inline
  537. void cv::ogl::Texture2D::create(Size asize, Format aformat, bool autoRelease)
  538. {
  539. create(asize.height, asize.width, aformat, autoRelease);
  540. }
  541. inline
  542. int cv::ogl::Texture2D::rows() const
  543. {
  544. return rows_;
  545. }
  546. inline
  547. int cv::ogl::Texture2D::cols() const
  548. {
  549. return cols_;
  550. }
  551. inline
  552. cv::Size cv::ogl::Texture2D::size() const
  553. {
  554. return Size(cols_, rows_);
  555. }
  556. inline
  557. bool cv::ogl::Texture2D::empty() const
  558. {
  559. return rows_ == 0 || cols_ == 0;
  560. }
  561. inline
  562. cv::ogl::Texture2D::Format cv::ogl::Texture2D::format() const
  563. {
  564. return format_;
  565. }
  566. ///////
  567. inline
  568. cv::ogl::Arrays::Arrays() : size_(0)
  569. {
  570. }
  571. inline
  572. int cv::ogl::Arrays::size() const
  573. {
  574. return size_;
  575. }
  576. inline
  577. bool cv::ogl::Arrays::empty() const
  578. {
  579. return size_ == 0;
  580. }
  581. //! @endcond
  582. #endif /* OPENCV_CORE_OPENGL_HPP */