~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/ThirdParty/ANGLE/src/libANGLE/validationESEXT.cpp

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
 
3
// Use of this source code is governed by a BSD-style license that can be
 
4
// found in the LICENSE file.
 
5
//
 
6
// validationESEXT.cpp: Validation functions for OpenGL ES extension entry points.
 
7
 
 
8
#include "libANGLE/validationESEXT_autogen.h"
 
9
 
 
10
#include "libANGLE/Context.h"
 
11
#include "libANGLE/ErrorStrings.h"
 
12
#include "libANGLE/validationES.h"
 
13
 
 
14
namespace gl
 
15
{
 
16
using namespace err;
 
17
 
 
18
namespace
 
19
{
 
20
template <typename ObjectT>
 
21
bool ValidateGetImageFormatAndType(Context *context, ObjectT *obj, GLenum format, GLenum type)
 
22
{
 
23
    GLenum implFormat = obj->getImplementationColorReadFormat(context);
 
24
    if (!ValidES3Format(format) && (format != implFormat || format == GL_NONE))
 
25
    {
 
26
        context->validationError(GL_INVALID_ENUM, kInvalidFormat);
 
27
        return false;
 
28
    }
 
29
 
 
30
    GLenum implType = obj->getImplementationColorReadType(context);
 
31
    if (!ValidES3Type(type) && (type != implType || type == GL_NONE))
 
32
    {
 
33
        context->validationError(GL_INVALID_ENUM, kInvalidType);
 
34
        return false;
 
35
    }
 
36
 
 
37
    // Format/type combinations are not yet validated.
 
38
 
 
39
    return true;
 
40
}
 
41
 
 
42
}  // namespace
 
43
 
 
44
bool ValidateGetTexImageANGLE(Context *context,
 
45
                              TextureTarget target,
 
46
                              GLint level,
 
47
                              GLenum format,
 
48
                              GLenum type,
 
49
                              void *pixels)
 
50
{
 
51
    if (!context->getExtensions().getImageANGLE)
 
52
    {
 
53
        context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
 
54
        return false;
 
55
    }
 
56
 
 
57
    if (!ValidTexture2DDestinationTarget(context, target) &&
 
58
        !ValidTexture3DDestinationTarget(context, target))
 
59
    {
 
60
        context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
 
61
        return false;
 
62
    }
 
63
 
 
64
    if (level < 0)
 
65
    {
 
66
        context->validationError(GL_INVALID_VALUE, kNegativeLevel);
 
67
        return false;
 
68
    }
 
69
 
 
70
    TextureType textureType = TextureTargetToType(target);
 
71
    if (!ValidMipLevel(context, textureType, level))
 
72
    {
 
73
        context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
 
74
        return false;
 
75
    }
 
76
 
 
77
    Texture *texture = context->getTextureByTarget(target);
 
78
 
 
79
    if (!ValidateGetImageFormatAndType(context, texture, format, type))
 
80
    {
 
81
        return false;
 
82
    }
 
83
 
 
84
    GLsizei width  = static_cast<GLsizei>(texture->getWidth(target, level));
 
85
    GLsizei height = static_cast<GLsizei>(texture->getHeight(target, level));
 
86
    if (!ValidatePixelPack(context, format, type, 0, 0, width, height, -1, nullptr, pixels))
 
87
    {
 
88
        return false;
 
89
    }
 
90
 
 
91
    return true;
 
92
}
 
93
 
 
94
bool ValidateGetRenderbufferImageANGLE(Context *context,
 
95
                                       GLenum target,
 
96
                                       GLenum format,
 
97
                                       GLenum type,
 
98
                                       void *pixels)
 
99
{
 
100
    if (!context->getExtensions().getImageANGLE)
 
101
    {
 
102
        context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
 
103
        return false;
 
104
    }
 
105
 
 
106
    if (target != GL_RENDERBUFFER)
 
107
    {
 
108
        context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
 
109
        return false;
 
110
    }
 
111
 
 
112
    Renderbuffer *renderbuffer = context->getState().getCurrentRenderbuffer();
 
113
 
 
114
    if (!ValidateGetImageFormatAndType(context, renderbuffer, format, type))
 
115
    {
 
116
        return false;
 
117
    }
 
118
 
 
119
    GLsizei width  = renderbuffer->getWidth();
 
120
    GLsizei height = renderbuffer->getHeight();
 
121
    if (!ValidatePixelPack(context, format, type, 0, 0, width, height, -1, nullptr, pixels))
 
122
    {
 
123
        return false;
 
124
    }
 
125
 
 
126
    return true;
 
127
}
 
128
 
 
129
bool ValidateDrawElementsBaseVertexEXT(Context *context,
 
130
                                       PrimitiveMode mode,
 
131
                                       GLsizei count,
 
132
                                       DrawElementsType type,
 
133
                                       const void *indices,
 
134
                                       GLint basevertex)
 
135
{
 
136
    if (!context->getExtensions().drawElementsBaseVertexAny())
 
137
    {
 
138
        context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
 
139
        return false;
 
140
    }
 
141
 
 
142
    return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
 
143
}
 
144
 
 
145
bool ValidateDrawElementsInstancedBaseVertexEXT(Context *context,
 
146
                                                PrimitiveMode mode,
 
147
                                                GLsizei count,
 
148
                                                DrawElementsType type,
 
149
                                                const void *indices,
 
150
                                                GLsizei instancecount,
 
151
                                                GLint basevertex)
 
152
{
 
153
    if (!context->getExtensions().drawElementsBaseVertexAny())
 
154
    {
 
155
        context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
 
156
        return false;
 
157
    }
 
158
 
 
159
    return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, instancecount);
 
160
}
 
161
 
 
162
bool ValidateDrawRangeElementsBaseVertexEXT(Context *context,
 
163
                                            PrimitiveMode mode,
 
164
                                            GLuint start,
 
165
                                            GLuint end,
 
166
                                            GLsizei count,
 
167
                                            DrawElementsType type,
 
168
                                            const void *indices,
 
169
                                            GLint basevertex)
 
170
{
 
171
    if (!context->getExtensions().drawElementsBaseVertexAny())
 
172
    {
 
173
        context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
 
174
        return false;
 
175
    }
 
176
 
 
177
    if (end < start)
 
178
    {
 
179
        context->validationError(GL_INVALID_VALUE, kInvalidElementRange);
 
180
        return false;
 
181
    }
 
182
 
 
183
    if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0))
 
184
    {
 
185
        return false;
 
186
    }
 
187
 
 
188
    // Skip range checks for no-op calls.
 
189
    if (count <= 0)
 
190
    {
 
191
        return true;
 
192
    }
 
193
 
 
194
    // Note that resolving the index range is a bit slow. We should probably optimize this.
 
195
    IndexRange indexRange;
 
196
    ANGLE_VALIDATION_TRY(context->getState().getVertexArray()->getIndexRange(context, type, count,
 
197
                                                                             indices, &indexRange));
 
198
 
 
199
    if (indexRange.end > end || indexRange.start < start)
 
200
    {
 
201
        // GL spec says that behavior in this case is undefined - generating an error is fine.
 
202
        context->validationError(GL_INVALID_OPERATION, kExceedsElementRange);
 
203
        return false;
 
204
    }
 
205
    return true;
 
206
}
 
207
 
 
208
bool ValidateMultiDrawElementsBaseVertexEXT(Context *context,
 
209
                                            PrimitiveMode mode,
 
210
                                            const GLsizei *count,
 
211
                                            DrawElementsType type,
 
212
                                            const void *const *indices,
 
213
                                            GLsizei drawcount,
 
214
                                            const GLint *basevertex)
 
215
{
 
216
    return true;
 
217
}
 
218
 
 
219
bool ValidateDrawElementsBaseVertexOES(Context *context,
 
220
                                       PrimitiveMode mode,
 
221
                                       GLsizei count,
 
222
                                       DrawElementsType type,
 
223
                                       const void *indices,
 
224
                                       GLint basevertex)
 
225
{
 
226
    if (!context->getExtensions().drawElementsBaseVertexAny())
 
227
    {
 
228
        context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
 
229
        return false;
 
230
    }
 
231
 
 
232
    return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
 
233
}
 
234
 
 
235
bool ValidateDrawElementsInstancedBaseVertexOES(Context *context,
 
236
                                                PrimitiveMode mode,
 
237
                                                GLsizei count,
 
238
                                                DrawElementsType type,
 
239
                                                const void *indices,
 
240
                                                GLsizei instancecount,
 
241
                                                GLint basevertex)
 
242
{
 
243
    if (!context->getExtensions().drawElementsBaseVertexAny())
 
244
    {
 
245
        context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
 
246
        return false;
 
247
    }
 
248
 
 
249
    return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, instancecount);
 
250
}
 
251
 
 
252
bool ValidateDrawRangeElementsBaseVertexOES(Context *context,
 
253
                                            PrimitiveMode mode,
 
254
                                            GLuint start,
 
255
                                            GLuint end,
 
256
                                            GLsizei count,
 
257
                                            DrawElementsType type,
 
258
                                            const void *indices,
 
259
                                            GLint basevertex)
 
260
{
 
261
    if (!context->getExtensions().drawElementsBaseVertexAny())
 
262
    {
 
263
        context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
 
264
        return false;
 
265
    }
 
266
 
 
267
    if (end < start)
 
268
    {
 
269
        context->validationError(GL_INVALID_VALUE, kInvalidElementRange);
 
270
        return false;
 
271
    }
 
272
 
 
273
    if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0))
 
274
    {
 
275
        return false;
 
276
    }
 
277
 
 
278
    // Skip range checks for no-op calls.
 
279
    if (count <= 0)
 
280
    {
 
281
        return true;
 
282
    }
 
283
 
 
284
    // Note that resolving the index range is a bit slow. We should probably optimize this.
 
285
    IndexRange indexRange;
 
286
    ANGLE_VALIDATION_TRY(context->getState().getVertexArray()->getIndexRange(context, type, count,
 
287
                                                                             indices, &indexRange));
 
288
 
 
289
    if (indexRange.end > end || indexRange.start < start)
 
290
    {
 
291
        // GL spec says that behavior in this case is undefined - generating an error is fine.
 
292
        context->validationError(GL_INVALID_OPERATION, kExceedsElementRange);
 
293
        return false;
 
294
    }
 
295
    return true;
 
296
}
 
297
}  // namespace gl