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