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.
6
// validationESEXT.cpp: Validation functions for OpenGL ES extension entry points.
8
#include "libANGLE/validationESEXT_autogen.h"
10
#include "libANGLE/Context.h"
11
#include "libANGLE/ErrorStrings.h"
12
#include "libANGLE/validationES.h"
20
template <typename ObjectT>
21
bool ValidateGetImageFormatAndType(Context *context, ObjectT *obj, GLenum format, GLenum type)
23
GLenum implFormat = obj->getImplementationColorReadFormat(context);
24
if (!ValidES3Format(format) && (format != implFormat || format == GL_NONE))
26
context->validationError(GL_INVALID_ENUM, kInvalidFormat);
30
GLenum implType = obj->getImplementationColorReadType(context);
31
if (!ValidES3Type(type) && (type != implType || type == GL_NONE))
33
context->validationError(GL_INVALID_ENUM, kInvalidType);
37
// Format/type combinations are not yet validated.
44
bool ValidateGetTexImageANGLE(Context *context,
51
if (!context->getExtensions().getImageANGLE)
53
context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
57
if (!ValidTexture2DDestinationTarget(context, target) &&
58
!ValidTexture3DDestinationTarget(context, target))
60
context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
66
context->validationError(GL_INVALID_VALUE, kNegativeLevel);
70
TextureType textureType = TextureTargetToType(target);
71
if (!ValidMipLevel(context, textureType, level))
73
context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
77
Texture *texture = context->getTextureByTarget(target);
79
if (!ValidateGetImageFormatAndType(context, texture, format, type))
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))
94
bool ValidateGetRenderbufferImageANGLE(Context *context,
100
if (!context->getExtensions().getImageANGLE)
102
context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
106
if (target != GL_RENDERBUFFER)
108
context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
112
Renderbuffer *renderbuffer = context->getState().getCurrentRenderbuffer();
114
if (!ValidateGetImageFormatAndType(context, renderbuffer, format, type))
119
GLsizei width = renderbuffer->getWidth();
120
GLsizei height = renderbuffer->getHeight();
121
if (!ValidatePixelPack(context, format, type, 0, 0, width, height, -1, nullptr, pixels))
129
bool ValidateDrawElementsBaseVertexEXT(Context *context,
132
DrawElementsType type,
136
if (!context->getExtensions().drawElementsBaseVertexAny())
138
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
142
return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
145
bool ValidateDrawElementsInstancedBaseVertexEXT(Context *context,
148
DrawElementsType type,
150
GLsizei instancecount,
153
if (!context->getExtensions().drawElementsBaseVertexAny())
155
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
159
return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, instancecount);
162
bool ValidateDrawRangeElementsBaseVertexEXT(Context *context,
167
DrawElementsType type,
171
if (!context->getExtensions().drawElementsBaseVertexAny())
173
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
179
context->validationError(GL_INVALID_VALUE, kInvalidElementRange);
183
if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0))
188
// Skip range checks for no-op calls.
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));
199
if (indexRange.end > end || indexRange.start < start)
201
// GL spec says that behavior in this case is undefined - generating an error is fine.
202
context->validationError(GL_INVALID_OPERATION, kExceedsElementRange);
208
bool ValidateMultiDrawElementsBaseVertexEXT(Context *context,
210
const GLsizei *count,
211
DrawElementsType type,
212
const void *const *indices,
214
const GLint *basevertex)
219
bool ValidateDrawElementsBaseVertexOES(Context *context,
222
DrawElementsType type,
226
if (!context->getExtensions().drawElementsBaseVertexAny())
228
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
232
return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
235
bool ValidateDrawElementsInstancedBaseVertexOES(Context *context,
238
DrawElementsType type,
240
GLsizei instancecount,
243
if (!context->getExtensions().drawElementsBaseVertexAny())
245
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
249
return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, instancecount);
252
bool ValidateDrawRangeElementsBaseVertexOES(Context *context,
257
DrawElementsType type,
261
if (!context->getExtensions().drawElementsBaseVertexAny())
263
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
269
context->validationError(GL_INVALID_VALUE, kInvalidElementRange);
273
if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0))
278
// Skip range checks for no-op calls.
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));
289
if (indexRange.end > end || indexRange.start < start)
291
// GL spec says that behavior in this case is undefined - generating an error is fine.
292
context->validationError(GL_INVALID_OPERATION, kExceedsElementRange);