1 /* 2 * Copyright (c) 2017-2019 Arm Limited. 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in all 14 * copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 #ifndef ARM_COMPUTE_OPENGLES_H 25 #define ARM_COMPUTE_OPENGLES_H 26 27 #include "arm_compute/core/Log.h" 28 29 #include <EGL/egl.h> 30 #include <EGL/eglext.h> 31 #include <EGL/eglplatform.h> 32 #include <GLES3/gl31.h> 33 #include <GLES3/gl3ext.h> 34 #include <cstddef> 35 36 #ifdef ARM_COMPUTE_DEBUG_ENABLED 37 #define ARM_COMPUTE_GL_CHECK(x) \ 38 x; \ 39 { \ 40 GLenum error = glGetError(); \ 41 if(error != GL_NO_ERROR) \ 42 ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE("glGetError() = %i (0x%.8x)\n", error, error); \ 43 } 44 #else /* ARM_COMPUTE_DEBUG_ENABLED */ 45 #define ARM_COMPUTE_GL_CHECK(x) x 46 #endif /* ARM_COMPUTE_DEBUG_ENABLED */ 47 48 namespace arm_compute 49 { 50 namespace gles 51 { 52 /** Class interface for specifying NDRange values. */ 53 class NDRange 54 { 55 private: 56 size_t _sizes[3]; 57 size_t _dimensions; 58 59 public: 60 /** Default constructor - resulting range has zero dimensions. */ NDRange()61 NDRange() 62 : _dimensions(0) 63 { 64 _sizes[0] = 0; 65 _sizes[1] = 0; 66 _sizes[2] = 0; 67 } 68 69 /** Constructs one-dimensional range. 70 * 71 * @param[in] size0 Size of the first dimension. 72 */ NDRange(size_t size0)73 NDRange(size_t size0) 74 : _dimensions(1) 75 { 76 _sizes[0] = size0; 77 _sizes[1] = 1; 78 _sizes[2] = 1; 79 } 80 81 /** Constructs two-dimensional range. 82 * 83 * @param[in] size0 Size of the first dimension. 84 * @param[in] size1 Size of the second dimension. 85 */ NDRange(size_t size0,size_t size1)86 NDRange(size_t size0, size_t size1) 87 : _dimensions(2) 88 { 89 _sizes[0] = size0; 90 _sizes[1] = size1; 91 _sizes[2] = 1; 92 } 93 94 /** Constructs three-dimensional range. 95 * 96 * @param[in] size0 Size of the first dimension. 97 * @param[in] size1 Size of the second dimension. 98 * @param[in] size2 Size of the third dimension. 99 */ NDRange(size_t size0,size_t size1,size_t size2)100 NDRange(size_t size0, size_t size1, size_t size2) 101 : _dimensions(3) 102 { 103 _sizes[0] = size0; 104 _sizes[1] = size1; 105 _sizes[2] = size2; 106 } 107 108 /** Conversion operator to const size_t *. 109 * 110 * @returns A pointer to the size of the first dimension. 111 */ 112 operator const size_t *() const 113 { 114 return _sizes; 115 } 116 117 /** Queries the number of dimensions in the range. 118 * 119 * @returns The number of dimensions. 120 */ dimensions()121 size_t dimensions() const 122 { 123 return _dimensions; 124 } 125 126 /** Returns the size of the object in bytes based on the runtime number of dimensions 127 * 128 * @returns The size of the object in bytes. 129 */ size()130 size_t size() const 131 { 132 return _dimensions * sizeof(size_t); 133 } 134 135 /** Returns the sizes array for each dimensions. 136 * 137 * @returns The sizes array 138 */ get()139 size_t *get() 140 { 141 return _sizes; 142 } 143 144 /** Returns the sizes array for each dimensions. 145 * 146 * @returns The sizes array 147 */ get()148 const size_t *get() const 149 { 150 return _sizes; 151 } 152 }; 153 154 static const NDRange NullRange; 155 static const NDRange Range_128_1 = NDRange(128, 1); 156 } // namespace gles 157 158 /** Check if the OpenGL ES 3.1 API is available at runtime. 159 * 160 * @returns true if the OpenGL ES 3.1 API is available. 161 */ 162 bool opengles31_is_available(); 163 } // namespace arm_compute 164 165 #endif /* ARM_COMPUTE_OPENGLES_H */ 166