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