aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/core/GLES_COMPUTE/OpenGLES.h
blob: 445443602d6008fb99da77a384bfa34189fa0c68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Copyright (c) 2017-2019 ARM Limited.
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef ARM_COMPUTE_OPENGLES_H
#define ARM_COMPUTE_OPENGLES_H

#include "arm_compute/core/Log.h"

#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <EGL/eglplatform.h>
#include <GLES3/gl31.h>
#include <GLES3/gl3ext.h>
#include <cstddef>

#ifdef ARM_COMPUTE_DEBUG_ENABLED
#define ARM_COMPUTE_GL_CHECK(x)                                                                      \
    x;                                                                                               \
    {                                                                                                \
        GLenum error = glGetError();                                                                 \
        if(error != GL_NO_ERROR)                                                                     \
            ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE("glGetError() = %i (0x%.8x)\n", error, error); \
    }
#else /* ARM_COMPUTE_DEBUG_ENABLED */
#define ARM_COMPUTE_GL_CHECK(x) x
#endif /* ARM_COMPUTE_DEBUG_ENABLED */

namespace arm_compute
{
namespace gles
{
/** Class interface for specifying NDRange values. */
class NDRange
{
private:
    size_t _sizes[3];
    size_t _dimensions;

public:
    /** Default constructor - resulting range has zero dimensions. */
    NDRange()
        : _dimensions(0)
    {
        _sizes[0] = 0;
        _sizes[1] = 0;
        _sizes[2] = 0;
    }

    /** Constructs one-dimensional range.
     *
     * @param[in] size0 Size of the first dimension.
     */
    NDRange(size_t size0)
        : _dimensions(1)
    {
        _sizes[0] = size0;
        _sizes[1] = 1;
        _sizes[2] = 1;
    }

    /** Constructs two-dimensional range.
     *
     * @param[in] size0 Size of the first dimension.
     * @param[in] size1 Size of the second dimension.
     */
    NDRange(size_t size0, size_t size1)
        : _dimensions(2)
    {
        _sizes[0] = size0;
        _sizes[1] = size1;
        _sizes[2] = 1;
    }

    /** Constructs three-dimensional range.
     *
     * @param[in] size0 Size of the first dimension.
     * @param[in] size1 Size of the second dimension.
     * @param[in] size2 Size of the third dimension.
     */
    NDRange(size_t size0, size_t size1, size_t size2)
        : _dimensions(3)
    {
        _sizes[0] = size0;
        _sizes[1] = size1;
        _sizes[2] = size2;
    }

    /** Conversion operator to const size_t *.
     *
     *  @returns A pointer to the size of the first dimension.
     */
    operator const size_t *() const
    {
        return _sizes;
    }

    /** Queries the number of dimensions in the range.
     *
     * @returns The number of dimensions.
    */
    size_t dimensions() const
    {
        return _dimensions;
    }

    /** Returns the size of the object in bytes based on the runtime number of dimensions
     *
     * @returns The size of the object in bytes.
     */
    size_t size() const
    {
        return _dimensions * sizeof(size_t);
    }

    /** Returns the sizes array for each dimensions.
     *
     * @returns The sizes array
     */
    size_t *get()
    {
        return _sizes;
    }

    /** Returns the sizes array for each dimensions.
     *
     * @returns The sizes array
     */
    const size_t *get() const
    {
        return _sizes;
    }
};

static const NDRange NullRange;
static const NDRange Range_128_1 = NDRange(128, 1);
} // namespace gles

/** Check if the OpenGL ES 3.1 API is available at runtime.
 *
 *  @returns true if the OpenGL ES 3.1 API is available.
 */
bool opengles31_is_available();
} // namespace arm_compute

#endif /* ARM_COMPUTE_OPENGLES_H */