blob: c300d1763c6827b0b7ad1234286a9417aa45e12f [file] [log] [blame]
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
Geoff Lange8ebe7f2013-08-05 15:03:13 -04003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// validationES3.cpp: Validation functions for OpenGL ES 3.0 entry point parameters
8
Geoff Lang2b5420c2014-11-19 14:20:15 -05009#include "libANGLE/validationES3.h"
Jamie Madille2e406c2016-06-02 13:04:10 -040010
Jamie Madill5ea762a2017-06-07 14:59:51 -040011#include "anglebase/numerics/safe_conversions.h"
Jamie Madilld2f0c742016-11-02 10:34:41 -040012#include "common/mathutil.h"
13#include "common/utilities.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050014#include "libANGLE/Context.h"
Martin Radev137032d2017-07-13 10:11:12 +030015#include "libANGLE/ErrorStrings.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050016#include "libANGLE/Framebuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050017#include "libANGLE/FramebufferAttachment.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040018#include "libANGLE/Renderbuffer.h"
19#include "libANGLE/Texture.h"
20#include "libANGLE/formatutils.h"
21#include "libANGLE/validationES.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040022
Jamie Madille2e406c2016-06-02 13:04:10 -040023using namespace angle;
24
Geoff Lange8ebe7f2013-08-05 15:03:13 -040025namespace gl
26{
27
Martin Radev137032d2017-07-13 10:11:12 +030028namespace
29{
30bool ValidateFramebufferTextureMultiviewBaseANGLE(Context *context,
31 GLenum target,
32 GLenum attachment,
33 GLuint texture,
34 GLint level,
35 GLsizei numViews)
36{
37 if (!context->getExtensions().multiview)
38 {
39 context->handleError(InvalidOperation() << "ANGLE_multiview is not available.");
40 return false;
41 }
42
43 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
44 {
45 return false;
46 }
47
Martin Radev14b21262017-08-25 13:54:37 +030048 if (texture != 0 && numViews < 1)
Martin Radev137032d2017-07-13 10:11:12 +030049 {
50 context->handleError(InvalidValue() << "numViews cannot be less than 1.");
51 return false;
52 }
53
54 const Extensions &extensions = context->getExtensions();
55 if (static_cast<GLuint>(numViews) > extensions.maxViews)
56 {
57 context->handleError(InvalidValue()
58 << "numViews cannot be greater than GL_MAX_VIEWS_ANGLE.");
59 return false;
60 }
61
62 return true;
63}
64
65bool ValidateFramebufferTextureMultiviewLevelAndFormat(Context *context,
66 Texture *texture,
67 GLint level)
68{
69 GLenum texTarget = texture->getTarget();
70 if (!ValidMipLevel(context, texTarget, level))
71 {
72 ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel);
73 return false;
74 }
75
76 const auto &format = texture->getFormat(texTarget, level);
77 if (format.info->compressed)
78 {
79 ANGLE_VALIDATION_ERR(context, InvalidOperation(), CompressedTexturesNotAttachable);
80 return false;
81 }
82 return true;
83}
84
Jamie Madillff325f12017-08-26 15:06:05 -040085bool ValidateUniformES3(Context *context, GLenum uniformType, GLint location, GLint count)
86{
87 if (context->getClientMajorVersion() < 3)
88 {
89 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
90 return false;
91 }
92
93 return ValidateUniform(context, uniformType, location, count);
94}
95
Jamie Madillc8c95812017-08-26 18:40:09 -040096bool ValidateUniformMatrixES3(Context *context,
97 GLenum valueType,
98 GLint location,
99 GLsizei count,
100 GLboolean transpose)
101{
102 // Check for ES3 uniform entry points
103 if (context->getClientMajorVersion() < 3)
104 {
105 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
106 return false;
107 }
108
109 return ValidateUniformMatrix(context, valueType, location, count, transpose);
110}
111
Yunchao Hef0fd87d2017-09-12 04:55:05 +0800112bool ValidateGenOrDeleteES3(Context *context, GLint n)
113{
114 if (context->getClientMajorVersion() < 3)
115 {
116 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
117 return false;
118 }
119 return ValidateGenOrDelete(context, n);
120}
121
122bool ValidateGenOrDeleteCountES3(Context *context, GLint count)
123{
124 if (context->getClientMajorVersion() < 3)
125 {
126 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
127 return false;
128 }
129 if (count < 0)
130 {
131 ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount);
132 return false;
133 }
134 return true;
135}
136
Jamie Madillff325f12017-08-26 15:06:05 -0400137} // anonymous namespace
Martin Radev137032d2017-07-13 10:11:12 +0300138
He Yunchaoced53ae2016-11-29 15:00:51 +0800139static bool ValidateTexImageFormatCombination(gl::Context *context,
Geoff Langca271392017-04-05 12:30:00 -0400140 GLenum target,
He Yunchaoced53ae2016-11-29 15:00:51 +0800141 GLenum internalFormat,
142 GLenum format,
143 GLenum type)
Geoff Lang5d601382014-07-22 15:14:06 -0400144{
Geoff Lang5d601382014-07-22 15:14:06 -0400145
146 // The type and format are valid if any supported internal format has that type and format
Geoff Lang6d1ccf02017-04-24 14:09:58 -0400147 if (!ValidES3Format(format))
Geoff Lang5d601382014-07-22 15:14:06 -0400148 {
Brandon Jonesafa75152017-07-21 13:11:29 -0700149 ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFormat);
Geoff Lang6d1ccf02017-04-24 14:09:58 -0400150 return false;
151 }
152
153 if (!ValidES3Type(type))
154 {
Brandon Jonesafa75152017-07-21 13:11:29 -0700155 ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType);
Geoff Lang6d1ccf02017-04-24 14:09:58 -0400156 return false;
157 }
158
159 // For historical reasons, glTexImage2D and glTexImage3D pass in their internal format as a
160 // GLint instead of a GLenum. Therefor an invalid internal format gives a GL_INVALID_VALUE
161 // error instead of a GL_INVALID_ENUM error. As this validation function is only called in
162 // the validation codepaths for glTexImage2D/3D, we record a GL_INVALID_VALUE error.
163 if (!ValidES3InternalFormat(internalFormat))
164 {
Brandon Jonesafa75152017-07-21 13:11:29 -0700165 ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidInternalFormat);
Geoff Langb1196682014-07-23 13:47:29 -0400166 return false;
Geoff Lang5d601382014-07-22 15:14:06 -0400167 }
168
Geoff Langca271392017-04-05 12:30:00 -0400169 // From the ES 3.0 spec section 3.8.3:
170 // Textures with a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL are supported by
171 // texture image specification commands only if target is TEXTURE_2D, TEXTURE_2D_ARRAY, or
172 // TEXTURE_CUBE_MAP.Using these formats in conjunction with any other target will result in an
173 // INVALID_OPERATION error.
174 if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
175 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500176 context->handleError(InvalidOperation() << "Format cannot be GL_DEPTH_COMPONENT or "
177 "GL_DEPTH_STENCIL if target is "
178 "GL_TEXTURE_3D");
Geoff Langca271392017-04-05 12:30:00 -0400179 return false;
180 }
181
Geoff Lang5d601382014-07-22 15:14:06 -0400182 // Check if this is a valid format combination to load texture data
Jamie Madill55e98212016-10-05 16:39:13 -0400183 if (!ValidES3FormatCombination(format, type, internalFormat))
Geoff Lang5d601382014-07-22 15:14:06 -0400184 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500185 context->handleError(InvalidOperation()
186 << "Invalid combination of format, type and internalFormat.");
Geoff Lang6d1ccf02017-04-24 14:09:58 -0400187 return false;
188 }
189
190 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type);
191 if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
192 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500193 context->handleError(InvalidOperation() << "Unsupported internal format.");
Geoff Langb1196682014-07-23 13:47:29 -0400194 return false;
Geoff Lang5d601382014-07-22 15:14:06 -0400195 }
196
197 return true;
198}
199
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500200bool ValidateES3TexImageParametersBase(Context *context,
201 GLenum target,
202 GLint level,
203 GLenum internalformat,
204 bool isCompressed,
205 bool isSubImage,
206 GLint xoffset,
207 GLint yoffset,
208 GLint zoffset,
209 GLsizei width,
210 GLsizei height,
211 GLsizei depth,
212 GLint border,
213 GLenum format,
214 GLenum type,
Geoff Langff5b2d52016-09-07 11:32:23 -0400215 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -0400216 const void *pixels)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400217{
218 // Validate image size
Austin Kinross08528e12015-10-07 16:24:40 -0700219 if (!ValidImageSizeParameters(context, target, level, width, height, depth, isSubImage))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400220 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500221 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400222 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400223 }
224
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400225 // Verify zero border
226 if (border != 0)
227 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500228 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400229 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400230 }
231
Jamie Madill6f38f822014-06-06 17:12:20 -0400232 if (xoffset < 0 || yoffset < 0 || zoffset < 0 ||
233 std::numeric_limits<GLsizei>::max() - xoffset < width ||
234 std::numeric_limits<GLsizei>::max() - yoffset < height ||
235 std::numeric_limits<GLsizei>::max() - zoffset < depth)
236 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500237 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400238 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -0400239 }
240
Geoff Langaae65a42014-05-26 12:43:44 -0400241 const gl::Caps &caps = context->getCaps();
242
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400243 switch (target)
244 {
He Yunchaoced53ae2016-11-29 15:00:51 +0800245 case GL_TEXTURE_2D:
246 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
247 static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
248 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500249 context->handleError(InvalidValue());
He Yunchaoced53ae2016-11-29 15:00:51 +0800250 return false;
251 }
252 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400253
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400254 case GL_TEXTURE_RECTANGLE_ANGLE:
255 ASSERT(level == 0);
256 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
257 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
258 {
259 context->handleError(InvalidValue());
260 return false;
261 }
262 if (isCompressed)
263 {
264 context->handleError(InvalidEnum()
265 << "Rectangle texture cannot have a compressed format.");
266 return false;
267 }
268 break;
269
He Yunchaoced53ae2016-11-29 15:00:51 +0800270 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
271 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
272 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
273 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
274 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
275 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
276 if (!isSubImage && width != height)
277 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500278 context->handleError(InvalidValue());
He Yunchaoced53ae2016-11-29 15:00:51 +0800279 return false;
280 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400281
He Yunchaoced53ae2016-11-29 15:00:51 +0800282 if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level))
283 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500284 context->handleError(InvalidValue());
He Yunchaoced53ae2016-11-29 15:00:51 +0800285 return false;
286 }
287 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400288
He Yunchaoced53ae2016-11-29 15:00:51 +0800289 case GL_TEXTURE_3D:
290 if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) ||
291 static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) ||
292 static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level))
293 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500294 context->handleError(InvalidValue());
He Yunchaoced53ae2016-11-29 15:00:51 +0800295 return false;
296 }
297 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400298
He Yunchaoced53ae2016-11-29 15:00:51 +0800299 case GL_TEXTURE_2D_ARRAY:
300 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
301 static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) ||
302 static_cast<GLuint>(depth) > caps.maxArrayTextureLayers)
303 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500304 context->handleError(InvalidValue());
He Yunchaoced53ae2016-11-29 15:00:51 +0800305 return false;
306 }
307 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400308
He Yunchaoced53ae2016-11-29 15:00:51 +0800309 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500310 context->handleError(InvalidEnum());
He Yunchaoced53ae2016-11-29 15:00:51 +0800311 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400312 }
313
He Yunchaoced53ae2016-11-29 15:00:51 +0800314 gl::Texture *texture =
315 context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400316 if (!texture)
317 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500318 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400319 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400320 }
321
Geoff Lang69cce582015-09-17 13:20:36 -0400322 if (texture->getImmutableFormat() && !isSubImage)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400323 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500324 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400325 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400326 }
327
328 // Validate texture formats
Jamie Madilla3944d42016-07-22 22:13:26 -0400329 GLenum actualInternalFormat =
Geoff Langc4e93662017-05-01 10:45:59 -0400330 isSubImage ? texture->getFormat(target, level).info->internalFormat : internalformat;
Geoff Langc51642b2016-11-14 16:18:26 -0500331 if (isSubImage && actualInternalFormat == GL_NONE)
332 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500333 context->handleError(InvalidOperation() << "Texture level does not exist.");
Geoff Langc51642b2016-11-14 16:18:26 -0500334 return false;
335 }
336
Geoff Langc4e93662017-05-01 10:45:59 -0400337 const gl::InternalFormat &actualFormatInfo = isSubImage
338 ? *texture->getFormat(target, level).info
339 : GetInternalFormatInfo(internalformat, type);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400340 if (isCompressed)
341 {
tmartino7c102692015-10-02 16:43:40 -0400342 if (!actualFormatInfo.compressed)
Geoff Langd4f180b2013-09-24 13:57:44 -0400343 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500344 context->handleError(
345 InvalidEnum() << "internalformat is not a supported compressed internal format.");
Geoff Langb1196682014-07-23 13:47:29 -0400346 return false;
Geoff Langd4f180b2013-09-24 13:57:44 -0400347 }
348
Geoff Lang966c9402017-04-18 12:38:27 -0400349 if (isSubImage)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400350 {
Geoff Lang966c9402017-04-18 12:38:27 -0400351 if (!ValidCompressedSubImageSize(
352 context, actualFormatInfo.internalFormat, xoffset, yoffset, width, height,
353 texture->getWidth(target, level), texture->getHeight(target, level)))
354 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500355 context->handleError(InvalidOperation() << "Invalid compressed format dimension.");
Geoff Lang966c9402017-04-18 12:38:27 -0400356 return false;
357 }
358
359 if (format != actualInternalFormat)
360 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500361 context->handleError(InvalidOperation()
362 << "Format must match the internal format of the texture.");
Geoff Lang966c9402017-04-18 12:38:27 -0400363 return false;
364 }
Geoff Lang86f81162017-10-30 15:10:45 -0400365
366 if (actualInternalFormat == GL_ETC1_RGB8_OES)
367 {
368 ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat);
369 return false;
370 }
Geoff Lang966c9402017-04-18 12:38:27 -0400371 }
372 else
373 {
374 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height))
375 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500376 context->handleError(InvalidOperation() << "Invalid compressed format dimension.");
Geoff Lang966c9402017-04-18 12:38:27 -0400377 return false;
378 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400379 }
380
Geoff Langeb66a6e2016-10-31 13:06:12 -0400381 if (!actualFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Geoff Lang839ce0b2015-10-23 13:13:12 -0400382 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500383 context->handleError(InvalidEnum());
Geoff Lang839ce0b2015-10-23 13:13:12 -0400384 return false;
385 }
386
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400387 if (target == GL_TEXTURE_3D)
388 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500389 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400390 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400391 }
392 }
393 else
394 {
Geoff Langca271392017-04-05 12:30:00 -0400395 if (!ValidateTexImageFormatCombination(context, target, actualInternalFormat, format, type))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400396 {
Geoff Lang5d601382014-07-22 15:14:06 -0400397 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400398 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400399 }
400
401 // Validate sub image parameters
402 if (isSubImage)
403 {
Geoff Langa9be0dc2014-12-17 12:34:40 -0500404 if (isCompressed != actualFormatInfo.compressed)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400405 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500406 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400407 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400408 }
409
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400410 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
411 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500412 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400413 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400414 }
415
416 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
417 std::numeric_limits<GLsizei>::max() - yoffset < height ||
418 std::numeric_limits<GLsizei>::max() - zoffset < depth)
419 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500420 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400421 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400422 }
423
Geoff Langa9be0dc2014-12-17 12:34:40 -0500424 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
425 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) ||
426 static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400427 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500428 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400429 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400430 }
Geoff Langfb052642017-10-24 13:42:09 -0400431
432 if (width > 0 && height > 0 && depth > 0 && pixels == nullptr &&
Corentin Wallez336129f2017-10-17 15:55:40 -0400433 context->getGLState().getTargetBuffer(gl::BufferBinding::PixelUnpack) == nullptr)
Geoff Langfb052642017-10-24 13:42:09 -0400434 {
435 ANGLE_VALIDATION_ERR(context, InvalidValue(), PixelDataNull);
436 return false;
437 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400438 }
439
Geoff Langdbcced82017-06-06 15:55:54 -0400440 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
441 if (!ValidImageDataSize(context, target, width, height, depth, sizeCheckFormat, type, pixels,
442 imageSize))
Geoff Langff5b2d52016-09-07 11:32:23 -0400443 {
444 return false;
445 }
446
Jamie Madillefb2a6f2013-09-24 10:22:42 -0400447 // Check for pixel unpack buffer related API errors
Corentin Wallez336129f2017-10-17 15:55:40 -0400448 gl::Buffer *pixelUnpackBuffer =
449 context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack);
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400450 if (pixelUnpackBuffer != nullptr)
Jamie Madillefb2a6f2013-09-24 10:22:42 -0400451 {
He Yunchaoced53ae2016-11-29 15:00:51 +0800452 // ...data is not evenly divisible into the number of bytes needed to store in memory a
453 // datum
Jamie Madillefb2a6f2013-09-24 10:22:42 -0400454 // indicated by type.
Jamie Madillc751d1e2014-10-21 17:46:29 -0400455 if (!isCompressed)
Jamie Madillefb2a6f2013-09-24 10:22:42 -0400456 {
Geoff Langff5b2d52016-09-07 11:32:23 -0400457 size_t offset = reinterpret_cast<size_t>(pixels);
Jamie Madillc751d1e2014-10-21 17:46:29 -0400458 size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes);
459
Geoff Langff5b2d52016-09-07 11:32:23 -0400460 if ((offset % dataBytesPerPixel) != 0)
Jamie Madillc751d1e2014-10-21 17:46:29 -0400461 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500462 context->handleError(InvalidOperation()
463 << "Reads would overflow the pixel unpack buffer.");
Jamie Madillc751d1e2014-10-21 17:46:29 -0400464 return false;
465 }
Jamie Madillefb2a6f2013-09-24 10:22:42 -0400466 }
467
Jamie Madill7a5f7382014-03-05 15:01:24 -0500468 // ...the buffer object's data store is currently mapped.
Brandon Jonesd38f9262014-06-18 16:26:45 -0700469 if (pixelUnpackBuffer->isMapped())
Jamie Madill7a5f7382014-03-05 15:01:24 -0500470 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500471 context->handleError(InvalidOperation() << "Pixel unpack buffer is mapped.");
Geoff Langb1196682014-07-23 13:47:29 -0400472 return false;
Jamie Madill7a5f7382014-03-05 15:01:24 -0500473 }
Jamie Madillefb2a6f2013-09-24 10:22:42 -0400474 }
475
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400476 return true;
477}
478
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500479bool ValidateES3TexImage2DParameters(Context *context,
480 GLenum target,
481 GLint level,
482 GLenum internalformat,
483 bool isCompressed,
484 bool isSubImage,
485 GLint xoffset,
486 GLint yoffset,
487 GLint zoffset,
488 GLsizei width,
489 GLsizei height,
490 GLsizei depth,
491 GLint border,
492 GLenum format,
493 GLenum type,
Geoff Langff5b2d52016-09-07 11:32:23 -0400494 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -0400495 const void *pixels)
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500496{
497 if (!ValidTexture2DDestinationTarget(context, target))
498 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500499 context->handleError(InvalidEnum());
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500500 return false;
501 }
502
503 return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed,
504 isSubImage, xoffset, yoffset, zoffset, width, height,
Geoff Langff5b2d52016-09-07 11:32:23 -0400505 depth, border, format, type, imageSize, pixels);
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500506}
507
508bool ValidateES3TexImage3DParameters(Context *context,
509 GLenum target,
510 GLint level,
511 GLenum internalformat,
512 bool isCompressed,
513 bool isSubImage,
514 GLint xoffset,
515 GLint yoffset,
516 GLint zoffset,
517 GLsizei width,
518 GLsizei height,
519 GLsizei depth,
520 GLint border,
521 GLenum format,
522 GLenum type,
Geoff Langc52f6f12016-10-14 10:18:00 -0400523 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -0400524 const void *pixels)
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500525{
526 if (!ValidTexture3DDestinationTarget(context, target))
527 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500528 context->handleError(InvalidEnum());
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500529 return false;
530 }
531
532 return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed,
533 isSubImage, xoffset, yoffset, zoffset, width, height,
Geoff Langc52f6f12016-10-14 10:18:00 -0400534 depth, border, format, type, bufSize, pixels);
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500535}
536
Geoff Lang5d601382014-07-22 15:14:06 -0400537struct EffectiveInternalFormatInfo
538{
Jamie Madill76648fe2016-10-05 17:01:41 -0400539 GLenum effectiveFormat;
540 GLenum destFormat;
541 GLuint minRedBits;
542 GLuint maxRedBits;
543 GLuint minGreenBits;
544 GLuint maxGreenBits;
545 GLuint minBlueBits;
546 GLuint maxBlueBits;
547 GLuint minAlphaBits;
548 GLuint maxAlphaBits;
Geoff Lang5d601382014-07-22 15:14:06 -0400549};
550
Jamie Madill76648fe2016-10-05 17:01:41 -0400551static bool QueryEffectiveFormatList(const InternalFormat &srcFormat,
552 GLenum targetFormat,
553 const EffectiveInternalFormatInfo *list,
554 size_t size,
555 GLenum *outEffectiveFormat)
Geoff Lang5d601382014-07-22 15:14:06 -0400556{
Jamie Madill76648fe2016-10-05 17:01:41 -0400557 for (size_t curFormat = 0; curFormat < size; ++curFormat)
558 {
559 const EffectiveInternalFormatInfo &formatInfo = list[curFormat];
560 if ((formatInfo.destFormat == targetFormat) &&
561 (formatInfo.minRedBits <= srcFormat.redBits &&
562 formatInfo.maxRedBits >= srcFormat.redBits) &&
563 (formatInfo.minGreenBits <= srcFormat.greenBits &&
564 formatInfo.maxGreenBits >= srcFormat.greenBits) &&
565 (formatInfo.minBlueBits <= srcFormat.blueBits &&
566 formatInfo.maxBlueBits >= srcFormat.blueBits) &&
567 (formatInfo.minAlphaBits <= srcFormat.alphaBits &&
568 formatInfo.maxAlphaBits >= srcFormat.alphaBits))
569 {
570 *outEffectiveFormat = formatInfo.effectiveFormat;
571 return true;
572 }
573 }
Geoff Lang5d601382014-07-22 15:14:06 -0400574
Jamie Madill76648fe2016-10-05 17:01:41 -0400575 *outEffectiveFormat = GL_NONE;
576 return false;
Geoff Lang5d601382014-07-22 15:14:06 -0400577}
578
Jamie Madill76648fe2016-10-05 17:01:41 -0400579bool GetSizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat,
580 GLenum *outEffectiveFormat)
Geoff Lang5d601382014-07-22 15:14:06 -0400581{
Jamie Madill76648fe2016-10-05 17:01:41 -0400582 // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141:
583 // Effective internal format coresponding to destination internal format and linear source
584 // buffer component sizes.
585 // | Source channel min/max sizes |
586 // Effective Internal Format | N/A | R | G | B | A |
587 // clang-format off
588 constexpr EffectiveInternalFormatInfo list[] = {
589 { GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8 },
590 { GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0 },
591 { GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0 },
592 { GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0 },
593 { GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0 },
594 { GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4 },
595 { GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1 },
596 { GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8 },
597 { GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2 },
598 };
599 // clang-format on
Geoff Lang5d601382014-07-22 15:14:06 -0400600
Jamie Madill76648fe2016-10-05 17:01:41 -0400601 return QueryEffectiveFormatList(srcFormat, GL_NONE, list, ArraySize(list), outEffectiveFormat);
602}
Geoff Lang5d601382014-07-22 15:14:06 -0400603
Jamie Madill76648fe2016-10-05 17:01:41 -0400604bool GetUnsizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat,
605 const InternalFormat &destFormat,
606 GLenum *outEffectiveFormat)
607{
608 constexpr GLuint umax = UINT_MAX;
609
610 // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141:
611 // Effective internal format coresponding to destination internal format andlinear source buffer
612 // component sizes.
613 // | Source channel min/max sizes |
614 // Effective Internal Format | Dest Format | R | G | B | A |
615 // clang-format off
616 constexpr EffectiveInternalFormatInfo list[] = {
617 { GL_ALPHA8_EXT, GL_ALPHA, 0, umax, 0, umax, 0, umax, 1, 8 },
618 { GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, umax, 0, umax, 0, umax },
619 { GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, umax, 0, umax, 1, 8 },
620 { GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, umax },
621 { GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, umax },
622 { GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4 },
623 { GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1 },
624 { GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8 },
625 };
626 // clang-format on
627
628 return QueryEffectiveFormatList(srcFormat, destFormat.format, list, ArraySize(list),
629 outEffectiveFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400630}
631
He Yunchaoced53ae2016-11-29 15:00:51 +0800632static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat,
633 const InternalFormat &destFormat,
Geoff Lang5d601382014-07-22 15:14:06 -0400634 GLenum *outEffectiveFormat)
635{
Geoff Langca271392017-04-05 12:30:00 -0400636 if (destFormat.sized)
Geoff Lang5d601382014-07-22 15:14:06 -0400637 {
Jamie Madill76648fe2016-10-05 17:01:41 -0400638 return GetSizedEffectiveInternalFormatInfo(srcFormat, outEffectiveFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400639 }
640 else
641 {
Jamie Madill76648fe2016-10-05 17:01:41 -0400642 return GetUnsizedEffectiveInternalFormatInfo(srcFormat, destFormat, outEffectiveFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400643 }
Geoff Lang5d601382014-07-22 15:14:06 -0400644}
645
Corentin Wallez76287682016-04-25 09:23:38 -0400646static bool EqualOrFirstZero(GLuint first, GLuint second)
647{
648 return first == 0 || first == second;
649}
650
Geoff Langca271392017-04-05 12:30:00 -0400651static bool IsValidES3CopyTexImageCombination(const InternalFormat &textureFormatInfo,
652 const InternalFormat &framebufferFormatInfo,
Jamie Madill0c8abca2016-07-22 20:21:26 -0400653 GLuint readBufferHandle)
Geoff Lang5d601382014-07-22 15:14:06 -0400654{
Jamie Madill21b786b2016-11-01 17:41:31 -0400655 if (!ValidES3CopyConversion(textureFormatInfo.format, framebufferFormatInfo.format))
Geoff Lang5d601382014-07-22 15:14:06 -0400656 {
Jamie Madill21b786b2016-11-01 17:41:31 -0400657 return false;
658 }
Geoff Lang5d601382014-07-22 15:14:06 -0400659
Jamie Madill21b786b2016-11-01 17:41:31 -0400660 // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats
661 // must both be signed, unsigned, or fixed point and both source and destinations
662 // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed
663 // conversion between fixed and floating point.
664
665 if ((textureFormatInfo.colorEncoding == GL_SRGB) !=
666 (framebufferFormatInfo.colorEncoding == GL_SRGB))
667 {
668 return false;
669 }
670
671 if (((textureFormatInfo.componentType == GL_INT) !=
672 (framebufferFormatInfo.componentType == GL_INT)) ||
673 ((textureFormatInfo.componentType == GL_UNSIGNED_INT) !=
674 (framebufferFormatInfo.componentType == GL_UNSIGNED_INT)))
675 {
676 return false;
677 }
678
679 if ((textureFormatInfo.componentType == GL_UNSIGNED_NORMALIZED ||
680 textureFormatInfo.componentType == GL_SIGNED_NORMALIZED ||
681 textureFormatInfo.componentType == GL_FLOAT) &&
682 !(framebufferFormatInfo.componentType == GL_UNSIGNED_NORMALIZED ||
683 framebufferFormatInfo.componentType == GL_SIGNED_NORMALIZED ||
684 framebufferFormatInfo.componentType == GL_FLOAT))
685 {
686 return false;
687 }
688
689 // GLES specification 3.0.3, sec 3.8.5, pg 139-140:
690 // The effective internal format of the source buffer is determined with the following rules
691 // applied in order:
692 // * If the source buffer is a texture or renderbuffer that was created with a sized internal
693 // format then the effective internal format is the source buffer's sized internal format.
694 // * If the source buffer is a texture that was created with an unsized base internal format,
695 // then the effective internal format is the source image array's effective internal
696 // format, as specified by table 3.12, which is determined from the <format> and <type>
697 // that were used when the source image array was specified by TexImage*.
698 // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18
699 // where Destination Internal Format matches internalformat and where the [source channel
700 // sizes] are consistent with the values of the source buffer's [channel sizes]. Table 3.17
701 // is used if the FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the
702 // FRAMEBUFFER_ATTACHMENT_ENCODING is SRGB.
Yunchao Hed7297bf2017-04-19 15:27:10 +0800703 const InternalFormat *sourceEffectiveFormat = nullptr;
Jamie Madill21b786b2016-11-01 17:41:31 -0400704 if (readBufferHandle != 0)
705 {
706 // Not the default framebuffer, therefore the read buffer must be a user-created texture or
707 // renderbuffer
Geoff Langca271392017-04-05 12:30:00 -0400708 if (framebufferFormatInfo.sized)
Geoff Lang5d601382014-07-22 15:14:06 -0400709 {
Jamie Madill21b786b2016-11-01 17:41:31 -0400710 sourceEffectiveFormat = &framebufferFormatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400711 }
Jamie Madill21b786b2016-11-01 17:41:31 -0400712 else
Geoff Lang5d601382014-07-22 15:14:06 -0400713 {
Jamie Madill21b786b2016-11-01 17:41:31 -0400714 // Renderbuffers cannot be created with an unsized internal format, so this must be an
715 // unsized-format texture. We can use the same table we use when creating textures to
716 // get its effective sized format.
Geoff Langca271392017-04-05 12:30:00 -0400717 sourceEffectiveFormat =
718 &GetSizedInternalFormatInfo(framebufferFormatInfo.sizedInternalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400719 }
Jamie Madill21b786b2016-11-01 17:41:31 -0400720 }
721 else
722 {
723 // The effective internal format must be derived from the source framebuffer's channel
724 // sizes. This is done in GetEffectiveInternalFormat for linear buffers (table 3.17)
725 if (framebufferFormatInfo.colorEncoding == GL_LINEAR)
Geoff Lang5d601382014-07-22 15:14:06 -0400726 {
Jamie Madill21b786b2016-11-01 17:41:31 -0400727 GLenum effectiveFormat;
728 if (GetEffectiveInternalFormat(framebufferFormatInfo, textureFormatInfo,
729 &effectiveFormat))
Geoff Lang5d601382014-07-22 15:14:06 -0400730 {
Geoff Langca271392017-04-05 12:30:00 -0400731 sourceEffectiveFormat = &GetSizedInternalFormatInfo(effectiveFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400732 }
733 else
734 {
Jamie Madill21b786b2016-11-01 17:41:31 -0400735 return false;
736 }
737 }
738 else if (framebufferFormatInfo.colorEncoding == GL_SRGB)
739 {
740 // SRGB buffers can only be copied to sized format destinations according to table 3.18
Geoff Langca271392017-04-05 12:30:00 -0400741 if (textureFormatInfo.sized &&
Jamie Madill21b786b2016-11-01 17:41:31 -0400742 (framebufferFormatInfo.redBits >= 1 && framebufferFormatInfo.redBits <= 8) &&
743 (framebufferFormatInfo.greenBits >= 1 && framebufferFormatInfo.greenBits <= 8) &&
744 (framebufferFormatInfo.blueBits >= 1 && framebufferFormatInfo.blueBits <= 8) &&
745 (framebufferFormatInfo.alphaBits >= 1 && framebufferFormatInfo.alphaBits <= 8))
746 {
Geoff Langca271392017-04-05 12:30:00 -0400747 sourceEffectiveFormat = &GetSizedInternalFormatInfo(GL_SRGB8_ALPHA8);
Jamie Madill21b786b2016-11-01 17:41:31 -0400748 }
749 else
750 {
751 return false;
Geoff Lang5d601382014-07-22 15:14:06 -0400752 }
753 }
754 else
755 {
Jamie Madill21b786b2016-11-01 17:41:31 -0400756 UNREACHABLE();
757 return false;
Geoff Lang5d601382014-07-22 15:14:06 -0400758 }
Geoff Lang5d601382014-07-22 15:14:06 -0400759 }
760
Geoff Langca271392017-04-05 12:30:00 -0400761 if (textureFormatInfo.sized)
Jamie Madill21b786b2016-11-01 17:41:31 -0400762 {
763 // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is
764 // sized, component sizes of the source and destination formats must exactly match if the
765 // destination format exists.
766 if (!EqualOrFirstZero(textureFormatInfo.redBits, sourceEffectiveFormat->redBits) ||
767 !EqualOrFirstZero(textureFormatInfo.greenBits, sourceEffectiveFormat->greenBits) ||
768 !EqualOrFirstZero(textureFormatInfo.blueBits, sourceEffectiveFormat->blueBits) ||
769 !EqualOrFirstZero(textureFormatInfo.alphaBits, sourceEffectiveFormat->alphaBits))
770 {
771 return false;
772 }
773 }
774
775 return true; // A conversion function exists, and no rule in the specification has precluded
776 // conversion between these formats.
Geoff Lang5d601382014-07-22 15:14:06 -0400777}
778
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500779bool ValidateES3CopyTexImageParametersBase(ValidationContext *context,
780 GLenum target,
781 GLint level,
782 GLenum internalformat,
783 bool isSubImage,
784 GLint xoffset,
785 GLint yoffset,
786 GLint zoffset,
787 GLint x,
788 GLint y,
789 GLsizei width,
790 GLsizei height,
791 GLint border)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400792{
Jamie Madill0c8abca2016-07-22 20:21:26 -0400793 Format textureFormat = Format::Invalid();
Jamie Madill560a8d82014-05-21 13:06:20 -0400794 if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
Jamie Madill0c8abca2016-07-22 20:21:26 -0400795 xoffset, yoffset, zoffset, x, y, width, height, border,
796 &textureFormat))
Shannon Woods4dfed832014-03-17 20:03:39 -0400797 {
Jamie Madill560a8d82014-05-21 13:06:20 -0400798 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400799 }
Jamie Madill0c8abca2016-07-22 20:21:26 -0400800 ASSERT(textureFormat.valid() || !isSubImage);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400801
Jamie Madill51f40ec2016-06-15 14:06:00 -0400802 const auto &state = context->getGLState();
803 gl::Framebuffer *framebuffer = state.getReadFramebuffer();
804 GLuint readFramebufferID = framebuffer->id();
Jamie Madill3c7fa222014-06-05 13:08:51 -0400805
Jamie Madilldd43e6c2017-03-24 14:18:49 -0400806 if (framebuffer->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madill3c7fa222014-06-05 13:08:51 -0400807 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500808 context->handleError(InvalidFramebufferOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400809 return false;
Jamie Madill3c7fa222014-06-05 13:08:51 -0400810 }
811
Jamie Madilldd43e6c2017-03-24 14:18:49 -0400812 if (readFramebufferID != 0 && framebuffer->getSamples(context) != 0)
Jamie Madill3c7fa222014-06-05 13:08:51 -0400813 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500814 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400815 return false;
Jamie Madill3c7fa222014-06-05 13:08:51 -0400816 }
817
Jamie Madill0c8abca2016-07-22 20:21:26 -0400818 const FramebufferAttachment *source = framebuffer->getReadColorbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400819
820 if (isSubImage)
821 {
Geoff Langca271392017-04-05 12:30:00 -0400822 if (!IsValidES3CopyTexImageCombination(*textureFormat.info, *source->getFormat().info,
Jamie Madillc29968b2016-01-20 11:17:23 -0500823 readFramebufferID))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400824 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500825 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400826 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400827 }
828 }
Shannon Woods4d161ba2014-03-17 18:13:30 -0400829 else
830 {
Jamie Madill0c8abca2016-07-22 20:21:26 -0400831 // Use format/type from the source FBO. (Might not be perfect for all cases?)
Geoff Langca271392017-04-05 12:30:00 -0400832 const InternalFormat &framebufferFormat = *source->getFormat().info;
833 const InternalFormat &copyFormat = GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE);
Jamie Madill0c8abca2016-07-22 20:21:26 -0400834 if (!IsValidES3CopyTexImageCombination(copyFormat, framebufferFormat, readFramebufferID))
Shannon Woods4d161ba2014-03-17 18:13:30 -0400835 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500836 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400837 return false;
Shannon Woods4d161ba2014-03-17 18:13:30 -0400838 }
839 }
840
Geoff Lang784a8fd2013-09-24 12:33:16 -0400841 // If width or height is zero, it is a no-op. Return false without setting an error.
842 return (width > 0 && height > 0);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400843}
844
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500845bool ValidateES3CopyTexImage2DParameters(ValidationContext *context,
846 GLenum target,
847 GLint level,
848 GLenum internalformat,
849 bool isSubImage,
850 GLint xoffset,
851 GLint yoffset,
852 GLint zoffset,
853 GLint x,
854 GLint y,
855 GLsizei width,
856 GLsizei height,
857 GLint border)
858{
859 if (!ValidTexture2DDestinationTarget(context, target))
860 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500861 context->handleError(InvalidEnum());
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500862 return false;
863 }
864
865 return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
866 xoffset, yoffset, zoffset, x, y, width, height,
867 border);
868}
869
870bool ValidateES3CopyTexImage3DParameters(ValidationContext *context,
871 GLenum target,
872 GLint level,
873 GLenum internalformat,
874 bool isSubImage,
875 GLint xoffset,
876 GLint yoffset,
877 GLint zoffset,
878 GLint x,
879 GLint y,
880 GLsizei width,
881 GLsizei height,
882 GLint border)
883{
884 if (!ValidTexture3DDestinationTarget(context, target))
885 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500886 context->handleError(InvalidEnum());
Ian Ewellfc7cf8e2016-01-20 15:57:46 -0500887 return false;
888 }
889
890 return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
891 xoffset, yoffset, zoffset, x, y, width, height,
892 border);
893}
894
895bool ValidateES3TexStorageParametersBase(Context *context,
896 GLenum target,
897 GLsizei levels,
898 GLenum internalformat,
899 GLsizei width,
900 GLsizei height,
901 GLsizei depth)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400902{
903 if (width < 1 || height < 1 || depth < 1 || levels < 1)
904 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500905 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400906 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400907 }
908
Geoff Langb92c1332015-09-04 12:54:55 -0400909 GLsizei maxDim = std::max(width, height);
910 if (target != GL_TEXTURE_2D_ARRAY)
911 {
912 maxDim = std::max(maxDim, depth);
913 }
914
915 if (levels > gl::log2(maxDim) + 1)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400916 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500917 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400918 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400919 }
920
Geoff Langaae65a42014-05-26 12:43:44 -0400921 const gl::Caps &caps = context->getCaps();
922
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400923 switch (target)
924 {
He Yunchaoced53ae2016-11-29 15:00:51 +0800925 case GL_TEXTURE_2D:
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400926 {
Geoff Langaae65a42014-05-26 12:43:44 -0400927 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
928 static_cast<GLuint>(height) > caps.max2DTextureSize)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400929 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500930 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400931 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400932 }
933 }
934 break;
935
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400936 case GL_TEXTURE_RECTANGLE_ANGLE:
937 {
938 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
939 static_cast<GLuint>(height) > caps.maxRectangleTextureSize || levels != 1)
940 {
941 context->handleError(InvalidValue());
942 return false;
943 }
944 }
945 break;
946
He Yunchaoced53ae2016-11-29 15:00:51 +0800947 case GL_TEXTURE_CUBE_MAP:
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400948 {
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400949 if (width != height)
950 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500951 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400952 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400953 }
954
Geoff Langaae65a42014-05-26 12:43:44 -0400955 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400956 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500957 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400958 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400959 }
960 }
961 break;
962
He Yunchaoced53ae2016-11-29 15:00:51 +0800963 case GL_TEXTURE_3D:
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400964 {
Geoff Langaae65a42014-05-26 12:43:44 -0400965 if (static_cast<GLuint>(width) > caps.max3DTextureSize ||
966 static_cast<GLuint>(height) > caps.max3DTextureSize ||
967 static_cast<GLuint>(depth) > caps.max3DTextureSize)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400968 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500969 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400970 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400971 }
972 }
973 break;
974
He Yunchaoced53ae2016-11-29 15:00:51 +0800975 case GL_TEXTURE_2D_ARRAY:
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400976 {
Geoff Langaae65a42014-05-26 12:43:44 -0400977 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
978 static_cast<GLuint>(height) > caps.max2DTextureSize ||
979 static_cast<GLuint>(depth) > caps.maxArrayTextureLayers)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400980 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500981 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -0400982 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400983 }
984 }
985 break;
986
He Yunchaoced53ae2016-11-29 15:00:51 +0800987 default:
988 UNREACHABLE();
989 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400990 }
991
Geoff Lang691e58c2014-12-19 17:03:25 -0500992 gl::Texture *texture = context->getTargetTexture(target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400993 if (!texture || texture->id() == 0)
994 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500995 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -0400996 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400997 }
998
Geoff Lang69cce582015-09-17 13:20:36 -0400999 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001000 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001001 context->handleError(InvalidOperation());
Geoff Langb1196682014-07-23 13:47:29 -04001002 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001003 }
1004
Geoff Langca271392017-04-05 12:30:00 -04001005 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Langeb66a6e2016-10-31 13:06:12 -04001006 if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001007 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001008 context->handleError(InvalidEnum());
Geoff Langb1196682014-07-23 13:47:29 -04001009 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001010 }
1011
Geoff Langca271392017-04-05 12:30:00 -04001012 if (!formatInfo.sized)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001013 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001014 context->handleError(InvalidEnum());
Geoff Langb1196682014-07-23 13:47:29 -04001015 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001016 }
1017
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001018 if (formatInfo.compressed && target == GL_TEXTURE_RECTANGLE_ANGLE)
1019 {
1020 context->handleError(InvalidEnum() << "Rectangle texture cannot have a compressed format.");
1021 return false;
1022 }
1023
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001024 return true;
1025}
1026
Ian Ewellfc7cf8e2016-01-20 15:57:46 -05001027bool ValidateES3TexStorage2DParameters(Context *context,
1028 GLenum target,
1029 GLsizei levels,
1030 GLenum internalformat,
1031 GLsizei width,
1032 GLsizei height,
1033 GLsizei depth)
1034{
1035 if (!ValidTexture2DTarget(context, target))
1036 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001037 context->handleError(InvalidEnum());
Ian Ewellfc7cf8e2016-01-20 15:57:46 -05001038 return false;
1039 }
1040
1041 return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width,
1042 height, depth);
1043}
1044
1045bool ValidateES3TexStorage3DParameters(Context *context,
1046 GLenum target,
1047 GLsizei levels,
1048 GLenum internalformat,
1049 GLsizei width,
1050 GLsizei height,
1051 GLsizei depth)
1052{
1053 if (!ValidTexture3DTarget(context, target))
1054 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001055 context->handleError(InvalidEnum());
Ian Ewellfc7cf8e2016-01-20 15:57:46 -05001056 return false;
1057 }
1058
1059 return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width,
1060 height, depth);
1061}
1062
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001063bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id)
1064{
Martin Radev1be913c2016-07-11 17:59:16 +03001065 if (context->getClientMajorVersion() < 3)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001066 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001067 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001068 return false;
1069 }
1070
1071 return ValidateBeginQueryBase(context, target, id);
1072}
1073
1074bool ValidateEndQuery(gl::Context *context, GLenum target)
1075{
Martin Radev1be913c2016-07-11 17:59:16 +03001076 if (context->getClientMajorVersion() < 3)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001077 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001078 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001079 return false;
1080 }
1081
1082 return ValidateEndQueryBase(context, target);
1083}
1084
1085bool ValidateGetQueryiv(Context *context, GLenum target, GLenum pname, GLint *params)
1086{
Martin Radev1be913c2016-07-11 17:59:16 +03001087 if (context->getClientMajorVersion() < 3)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001088 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001089 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001090 return false;
1091 }
1092
Geoff Lang2186c382016-10-14 10:54:54 -04001093 return ValidateGetQueryivBase(context, target, pname, nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001094}
1095
1096bool ValidateGetQueryObjectuiv(Context *context, GLuint id, GLenum pname, GLuint *params)
1097{
Martin Radev1be913c2016-07-11 17:59:16 +03001098 if (context->getClientMajorVersion() < 3)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001099 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001100 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001101 return false;
1102 }
1103
Geoff Lang2186c382016-10-14 10:54:54 -04001104 return ValidateGetQueryObjectValueBase(context, id, pname, nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001105}
1106
He Yunchaoced53ae2016-11-29 15:00:51 +08001107bool ValidateFramebufferTextureLayer(Context *context,
1108 GLenum target,
1109 GLenum attachment,
1110 GLuint texture,
1111 GLint level,
1112 GLint layer)
Jamie Madill570f7c82014-07-03 10:38:54 -04001113{
Martin Radev1be913c2016-07-11 17:59:16 +03001114 if (context->getClientMajorVersion() < 3)
Jamie Madill570f7c82014-07-03 10:38:54 -04001115 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001116 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langb1196682014-07-23 13:47:29 -04001117 return false;
Jamie Madill570f7c82014-07-03 10:38:54 -04001118 }
1119
Jamie Madill55ec3b12014-07-03 10:38:57 -04001120 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
1121 {
1122 return false;
1123 }
1124
1125 const gl::Caps &caps = context->getCaps();
1126 if (texture != 0)
1127 {
Geoff Lang23e02842017-10-17 13:24:09 -04001128 if (layer < 0)
1129 {
1130 context->handleError(InvalidValue());
1131 return false;
1132 }
1133
Jamie Madill55ec3b12014-07-03 10:38:57 -04001134 gl::Texture *tex = context->getTexture(texture);
1135 ASSERT(tex);
1136
1137 switch (tex->getTarget())
1138 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001139 case GL_TEXTURE_2D_ARRAY:
Jamie Madill55ec3b12014-07-03 10:38:57 -04001140 {
1141 if (level > gl::log2(caps.max2DTextureSize))
1142 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001143 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -04001144 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001145 }
1146
1147 if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers)
1148 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001149 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -04001150 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001151 }
Jamie Madill55ec3b12014-07-03 10:38:57 -04001152 }
1153 break;
1154
He Yunchaoced53ae2016-11-29 15:00:51 +08001155 case GL_TEXTURE_3D:
Jamie Madill55ec3b12014-07-03 10:38:57 -04001156 {
1157 if (level > gl::log2(caps.max3DTextureSize))
1158 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001159 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -04001160 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001161 }
1162
1163 if (static_cast<GLuint>(layer) >= caps.max3DTextureSize)
1164 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001165 context->handleError(InvalidValue());
Geoff Langb1196682014-07-23 13:47:29 -04001166 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001167 }
Jamie Madill55ec3b12014-07-03 10:38:57 -04001168 }
1169 break;
1170
He Yunchaoced53ae2016-11-29 15:00:51 +08001171 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001172 context->handleError(InvalidOperation());
He Yunchaoced53ae2016-11-29 15:00:51 +08001173 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001174 }
Geoff Langa9be0dc2014-12-17 12:34:40 -05001175
Jamie Madilla3944d42016-07-22 22:13:26 -04001176 const auto &format = tex->getFormat(tex->getTarget(), level);
1177 if (format.info->compressed)
Geoff Langa9be0dc2014-12-17 12:34:40 -05001178 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001179 context->handleError(InvalidOperation());
Geoff Langa9be0dc2014-12-17 12:34:40 -05001180 return false;
1181 }
Jamie Madill55ec3b12014-07-03 10:38:57 -04001182 }
1183
1184 return true;
Jamie Madill570f7c82014-07-03 10:38:54 -04001185}
1186
He Yunchaoced53ae2016-11-29 15:00:51 +08001187bool ValidateInvalidateFramebuffer(Context *context,
1188 GLenum target,
1189 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07001190 const GLenum *attachments)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001191{
Martin Radev1be913c2016-07-11 17:59:16 +03001192 if (context->getClientMajorVersion() < 3)
Austin Kinross08332632015-05-05 13:35:47 -07001193 {
Brandon Jonesafa75152017-07-21 13:11:29 -07001194 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Austin Kinross08332632015-05-05 13:35:47 -07001195 return false;
1196 }
1197
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001198 bool defaultFramebuffer = false;
1199
1200 switch (target)
1201 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001202 case GL_DRAW_FRAMEBUFFER:
1203 case GL_FRAMEBUFFER:
1204 defaultFramebuffer = context->getGLState().getDrawFramebuffer()->id() == 0;
1205 break;
1206 case GL_READ_FRAMEBUFFER:
1207 defaultFramebuffer = context->getGLState().getReadFramebuffer()->id() == 0;
1208 break;
1209 default:
Brandon Jonesafa75152017-07-21 13:11:29 -07001210 ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001211 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001212 }
1213
He Yunchaoced53ae2016-11-29 15:00:51 +08001214 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
1215 defaultFramebuffer);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001216}
1217
Jamie Madill3ef140a2017-08-26 23:11:21 -04001218bool ValidateInvalidateSubFramebuffer(Context *context,
1219 GLenum target,
1220 GLsizei numAttachments,
1221 const GLenum *attachments,
1222 GLint x,
1223 GLint y,
1224 GLsizei width,
1225 GLsizei height)
1226{
1227 return ValidateInvalidateFramebuffer(context, target, numAttachments, attachments);
1228}
1229
Jamie Madillc29968b2016-01-20 11:17:23 -05001230bool ValidateClearBuffer(ValidationContext *context)
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001231{
Martin Radev1be913c2016-07-11 17:59:16 +03001232 if (context->getClientMajorVersion() < 3)
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001233 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001234 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langb1196682014-07-23 13:47:29 -04001235 return false;
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001236 }
1237
Jamie Madilldd43e6c2017-03-24 14:18:49 -04001238 if (context->getGLState().getDrawFramebuffer()->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001239 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001240 context->handleError(InvalidFramebufferOperation());
Geoff Langb1196682014-07-23 13:47:29 -04001241 return false;
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001242 }
1243
1244 return true;
1245}
1246
Olli Etuaho71dfb362016-03-10 14:04:27 +02001247bool ValidateDrawRangeElements(Context *context,
1248 GLenum mode,
1249 GLuint start,
1250 GLuint end,
1251 GLsizei count,
1252 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001253 const void *indices)
Olli Etuaho71dfb362016-03-10 14:04:27 +02001254{
Martin Radev1be913c2016-07-11 17:59:16 +03001255 if (context->getClientMajorVersion() < 3)
Olli Etuaho71dfb362016-03-10 14:04:27 +02001256 {
Brandon Jonesafa75152017-07-21 13:11:29 -07001257 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Olli Etuaho71dfb362016-03-10 14:04:27 +02001258 return false;
1259 }
1260
1261 if (end < start)
1262 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001263 context->handleError(InvalidValue() << "end < start");
Olli Etuaho71dfb362016-03-10 14:04:27 +02001264 return false;
1265 }
1266
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001267 if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0))
Olli Etuaho71dfb362016-03-10 14:04:27 +02001268 {
1269 return false;
1270 }
1271
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001272 // Use the parameter buffer to retrieve and cache the index range.
1273 const auto &params = context->getParams<HasIndexRange>();
1274 const auto &indexRangeOpt = params.getIndexRange();
1275 if (!indexRangeOpt.valid())
1276 {
1277 // Unexpected error.
1278 return false;
1279 }
1280
1281 if (indexRangeOpt.value().end > end || indexRangeOpt.value().start < start)
Olli Etuaho71dfb362016-03-10 14:04:27 +02001282 {
1283 // GL spec says that behavior in this case is undefined - generating an error is fine.
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001284 context->handleError(InvalidOperation() << "Indices are out of the start, end range.");
Olli Etuaho71dfb362016-03-10 14:04:27 +02001285 return false;
1286 }
1287 return true;
1288}
1289
He Yunchaoced53ae2016-11-29 15:00:51 +08001290bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint *params)
Jamie Madill0063c512014-08-25 15:47:53 -04001291{
Martin Radev1be913c2016-07-11 17:59:16 +03001292 if (context->getClientMajorVersion() < 3)
Jamie Madill0063c512014-08-25 15:47:53 -04001293 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001294 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langb1196682014-07-23 13:47:29 -04001295 return false;
Jamie Madill0063c512014-08-25 15:47:53 -04001296 }
1297
Jamie Madill78f41802014-08-25 15:47:55 -04001298 return ValidateGetUniformBase(context, program, location);
Jamie Madill0063c512014-08-25 15:47:53 -04001299}
1300
Jamie Madillb885e572015-02-03 16:16:04 -05001301bool ValidateReadBuffer(Context *context, GLenum src)
1302{
Martin Radev1be913c2016-07-11 17:59:16 +03001303 if (context->getClientMajorVersion() < 3)
Jamie Madillb885e572015-02-03 16:16:04 -05001304 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001305 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madillb885e572015-02-03 16:16:04 -05001306 return false;
1307 }
1308
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001309 const Framebuffer *readFBO = context->getGLState().getReadFramebuffer();
Jamie Madillb885e572015-02-03 16:16:04 -05001310
1311 if (readFBO == nullptr)
1312 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001313 context->handleError(InvalidOperation() << "No active read framebuffer.");
Jamie Madillb885e572015-02-03 16:16:04 -05001314 return false;
1315 }
1316
1317 if (src == GL_NONE)
1318 {
1319 return true;
1320 }
1321
Olli Etuaho84c9f592016-03-09 14:37:25 +02001322 if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT31))
Jamie Madillb885e572015-02-03 16:16:04 -05001323 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001324 context->handleError(InvalidEnum() << "Unknown enum for 'src' in ReadBuffer");
Jamie Madillb885e572015-02-03 16:16:04 -05001325 return false;
1326 }
1327
1328 if (readFBO->id() == 0)
1329 {
1330 if (src != GL_BACK)
1331 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001332 context->handleError(
1333 InvalidOperation()
1334 << "'src' must be GL_NONE or GL_BACK when reading from the default framebuffer.");
Jamie Madillb885e572015-02-03 16:16:04 -05001335 return false;
1336 }
1337 }
1338 else
1339 {
1340 GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0);
1341
1342 if (drawBuffer >= context->getCaps().maxDrawBuffers)
1343 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001344 context->handleError(InvalidOperation() << "'src' is greater than MAX_DRAW_BUFFERS.");
Jamie Madillb885e572015-02-03 16:16:04 -05001345 return false;
1346 }
1347 }
1348
1349 return true;
1350}
1351
Jamie Madill86af3d22015-07-21 15:14:07 -04001352bool ValidateCompressedTexImage3D(Context *context,
1353 GLenum target,
1354 GLint level,
1355 GLenum internalformat,
1356 GLsizei width,
1357 GLsizei height,
1358 GLsizei depth,
1359 GLint border,
1360 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001361 const void *data)
Jamie Madill86af3d22015-07-21 15:14:07 -04001362{
Martin Radev1be913c2016-07-11 17:59:16 +03001363 if (context->getClientMajorVersion() < 3)
Jamie Madill86af3d22015-07-21 15:14:07 -04001364 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001365 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madill86af3d22015-07-21 15:14:07 -04001366 return false;
1367 }
1368
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001369 if (!ValidTextureTarget(context, target))
1370 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001371 context->handleError(InvalidEnum());
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001372 return false;
1373 }
1374
Jamie Madille2e406c2016-06-02 13:04:10 -04001375 // Validate image size
1376 if (!ValidImageSizeParameters(context, target, level, width, height, depth, false))
1377 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001378 context->handleError(InvalidValue());
Jamie Madille2e406c2016-06-02 13:04:10 -04001379 return false;
1380 }
1381
Geoff Langca271392017-04-05 12:30:00 -04001382 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001383 if (!formatInfo.compressed)
1384 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001385 context->handleError(InvalidEnum() << "Not a valid compressed texture format");
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001386 return false;
1387 }
1388
Jeff Gilbert48590352017-11-07 16:03:38 -08001389 auto blockSizeOrErr = formatInfo.computeCompressedImageSize(gl::Extents(width, height, depth));
Jamie Madille2e406c2016-06-02 13:04:10 -04001390 if (blockSizeOrErr.isError())
1391 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001392 context->handleError(InvalidValue());
Jamie Madille2e406c2016-06-02 13:04:10 -04001393 return false;
1394 }
1395 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult())
Jamie Madill86af3d22015-07-21 15:14:07 -04001396 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001397 context->handleError(InvalidValue());
Jamie Madill86af3d22015-07-21 15:14:07 -04001398 return false;
1399 }
1400
1401 // 3D texture target validation
1402 if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY)
1403 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001404 context->handleError(InvalidEnum() << "Must specify a valid 3D texture destination target");
Jamie Madill86af3d22015-07-21 15:14:07 -04001405 return false;
1406 }
1407
1408 // validateES3TexImageFormat sets the error code if there is an error
Ian Ewellfc7cf8e2016-01-20 15:57:46 -05001409 if (!ValidateES3TexImage3DParameters(context, target, level, internalformat, true, false, 0, 0,
Geoff Langc52f6f12016-10-14 10:18:00 -04001410 0, width, height, depth, border, GL_NONE, GL_NONE, -1,
1411 data))
Jamie Madill86af3d22015-07-21 15:14:07 -04001412 {
1413 return false;
1414 }
1415
1416 return true;
1417}
Austin Kinrossbc781f32015-10-26 09:27:38 -07001418
Corentin Wallezb2931602017-04-11 15:58:57 -04001419bool ValidateCompressedTexImage3DRobustANGLE(Context *context,
1420 GLenum target,
1421 GLint level,
1422 GLenum internalformat,
1423 GLsizei width,
1424 GLsizei height,
1425 GLsizei depth,
1426 GLint border,
1427 GLsizei imageSize,
1428 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001429 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04001430{
1431 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
1432 {
1433 return false;
1434 }
1435
1436 return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height,
1437 depth, border, imageSize, data);
1438}
1439
Austin Kinrossbc781f32015-10-26 09:27:38 -07001440bool ValidateBindVertexArray(Context *context, GLuint array)
1441{
Martin Radev1be913c2016-07-11 17:59:16 +03001442 if (context->getClientMajorVersion() < 3)
Austin Kinrossbc781f32015-10-26 09:27:38 -07001443 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001444 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001445 return false;
1446 }
1447
1448 return ValidateBindVertexArrayBase(context, array);
1449}
1450
Jamie Madilld7576732017-08-26 18:49:50 -04001451bool ValidateIsVertexArray(Context *context, GLuint array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07001452{
Martin Radev1be913c2016-07-11 17:59:16 +03001453 if (context->getClientMajorVersion() < 3)
Austin Kinrossbc781f32015-10-26 09:27:38 -07001454 {
Jamie Madilld7576732017-08-26 18:49:50 -04001455 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001456 return false;
1457 }
1458
1459 return true;
1460}
Geoff Langc5629752015-12-07 16:29:04 -05001461
Jiajia Qin6eafb042016-12-27 17:04:07 +08001462static bool ValidateBindBufferCommon(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04001463 BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08001464 GLuint index,
1465 GLuint buffer,
1466 GLintptr offset,
1467 GLsizeiptr size)
1468{
1469 if (context->getClientMajorVersion() < 3)
1470 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001471 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001472 return false;
1473 }
1474
1475 if (buffer != 0 && offset < 0)
1476 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001477 context->handleError(InvalidValue() << "buffer is non-zero and offset is negative.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001478 return false;
1479 }
1480
1481 if (!context->getGLState().isBindGeneratesResourceEnabled() &&
1482 !context->isBufferGenerated(buffer))
1483 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001484 context->handleError(InvalidOperation() << "Buffer was not generated.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001485 return false;
1486 }
1487
1488 const Caps &caps = context->getCaps();
1489 switch (target)
1490 {
Corentin Wallez336129f2017-10-17 15:55:40 -04001491 case BufferBinding::TransformFeedback:
Jiajia Qin6eafb042016-12-27 17:04:07 +08001492 {
1493 if (index >= caps.maxTransformFeedbackSeparateAttributes)
1494 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001495 context->handleError(InvalidValue() << "index is greater than or equal to the "
1496 "number of TRANSFORM_FEEDBACK_BUFFER "
1497 "indexed binding points.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001498 return false;
1499 }
1500 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
1501 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001502 context->handleError(InvalidValue() << "offset and size must be multiple of 4.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001503 return false;
1504 }
1505
1506 TransformFeedback *curTransformFeedback =
1507 context->getGLState().getCurrentTransformFeedback();
1508 if (curTransformFeedback && curTransformFeedback->isActive())
1509 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001510 context->handleError(InvalidOperation()
1511 << "target is TRANSFORM_FEEDBACK_BUFFER and transform "
1512 "feedback is currently active.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001513 return false;
1514 }
1515 break;
1516 }
Corentin Wallez336129f2017-10-17 15:55:40 -04001517 case BufferBinding::Uniform:
Jiajia Qin6eafb042016-12-27 17:04:07 +08001518 {
1519 if (index >= caps.maxUniformBufferBindings)
1520 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001521 context->handleError(InvalidValue() << "index is greater than or equal to the "
1522 "number of UNIFORM_BUFFER indexed "
1523 "binding points.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001524 return false;
1525 }
1526
1527 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
1528 {
1529 context->handleError(
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001530 InvalidValue()
1531 << "offset must be multiple of value of UNIFORM_BUFFER_OFFSET_ALIGNMENT.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001532 return false;
1533 }
1534 break;
1535 }
Corentin Wallez336129f2017-10-17 15:55:40 -04001536 case BufferBinding::AtomicCounter:
Jiajia Qin6eafb042016-12-27 17:04:07 +08001537 {
1538 if (context->getClientVersion() < ES_3_1)
1539 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001540 context->handleError(InvalidEnum()
1541 << "ATOMIC_COUNTER_BUFFER is not supported before GLES 3.1");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001542 return false;
1543 }
1544 if (index >= caps.maxAtomicCounterBufferBindings)
1545 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001546 context->handleError(InvalidValue() << "index is greater than or equal to the "
1547 "number of ATOMIC_COUNTER_BUFFER "
1548 "indexed binding points.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001549 return false;
1550 }
1551 if (buffer != 0 && (offset % 4) != 0)
1552 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001553 context->handleError(InvalidValue() << "offset must be a multiple of 4.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001554 return false;
1555 }
1556 break;
1557 }
Corentin Wallez336129f2017-10-17 15:55:40 -04001558 case BufferBinding::ShaderStorage:
Jiajia Qin6eafb042016-12-27 17:04:07 +08001559 {
1560 if (context->getClientVersion() < ES_3_1)
1561 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001562 context->handleError(InvalidEnum()
1563 << "SHADER_STORAGE_BUFFER is not supported in GLES3.");
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001564 return false;
1565 }
1566 if (index >= caps.maxShaderStorageBufferBindings)
1567 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001568 context->handleError(InvalidValue() << "index is greater than or equal to the "
1569 "number of SHADER_STORAGE_BUFFER "
1570 "indexed binding points.");
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001571 return false;
1572 }
1573 if (buffer != 0 && (offset % caps.shaderStorageBufferOffsetAlignment) != 0)
1574 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001575 context->handleError(InvalidValue() << "offset must be multiple of value of "
1576 "SHADER_STORAGE_BUFFER_OFFSET_"
1577 "ALIGNMENT.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001578 return false;
1579 }
1580 break;
1581 }
1582 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001583 context->handleError(InvalidEnum() << "the target is not supported.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001584 return false;
1585 }
1586
1587 return true;
1588}
1589
Corentin Wallez336129f2017-10-17 15:55:40 -04001590bool ValidateBindBufferBase(Context *context, BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08001591{
1592 return ValidateBindBufferCommon(context, target, index, buffer, 0, 0);
1593}
1594
1595bool ValidateBindBufferRange(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04001596 BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08001597 GLuint index,
1598 GLuint buffer,
1599 GLintptr offset,
1600 GLsizeiptr size)
1601{
1602 if (buffer != 0 && size <= 0)
1603 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001604 context->handleError(InvalidValue()
1605 << "buffer is non-zero and size is less than or equal to zero.");
Jiajia Qin6eafb042016-12-27 17:04:07 +08001606 return false;
1607 }
1608 return ValidateBindBufferCommon(context, target, index, buffer, offset, size);
1609}
1610
Geoff Langc5629752015-12-07 16:29:04 -05001611bool ValidateProgramBinary(Context *context,
1612 GLuint program,
1613 GLenum binaryFormat,
1614 const void *binary,
1615 GLint length)
1616{
Martin Radev1be913c2016-07-11 17:59:16 +03001617 if (context->getClientMajorVersion() < 3)
Geoff Langc5629752015-12-07 16:29:04 -05001618 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001619 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langc5629752015-12-07 16:29:04 -05001620 return false;
1621 }
1622
1623 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
1624}
1625
1626bool ValidateGetProgramBinary(Context *context,
1627 GLuint program,
1628 GLsizei bufSize,
1629 GLsizei *length,
1630 GLenum *binaryFormat,
1631 void *binary)
1632{
Martin Radev1be913c2016-07-11 17:59:16 +03001633 if (context->getClientMajorVersion() < 3)
Geoff Langc5629752015-12-07 16:29:04 -05001634 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001635 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langc5629752015-12-07 16:29:04 -05001636 return false;
1637 }
1638
1639 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
1640}
1641
Olli Etuahof0fee072016-03-30 15:11:58 +03001642bool ValidateProgramParameteri(Context *context, GLuint program, GLenum pname, GLint value)
Geoff Langc5629752015-12-07 16:29:04 -05001643{
Martin Radev1be913c2016-07-11 17:59:16 +03001644 if (context->getClientMajorVersion() < 3)
Geoff Langc5629752015-12-07 16:29:04 -05001645 {
Brandon Jonesafa75152017-07-21 13:11:29 -07001646 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langc5629752015-12-07 16:29:04 -05001647 return false;
1648 }
1649
1650 if (GetValidProgram(context, program) == nullptr)
1651 {
1652 return false;
1653 }
1654
1655 switch (pname)
1656 {
1657 case GL_PROGRAM_BINARY_RETRIEVABLE_HINT:
Olli Etuahof0fee072016-03-30 15:11:58 +03001658 if (value != GL_FALSE && value != GL_TRUE)
1659 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001660 context->handleError(InvalidValue()
1661 << "Invalid value, expected GL_FALSE or GL_TRUE: " << value);
Olli Etuahof0fee072016-03-30 15:11:58 +03001662 return false;
1663 }
Geoff Langc5629752015-12-07 16:29:04 -05001664 break;
1665
Yunchao He61afff12017-03-14 15:34:03 +08001666 case GL_PROGRAM_SEPARABLE:
1667 if (context->getClientVersion() < ES_3_1)
1668 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001669 context->handleError(InvalidEnum()
1670 << "PROGRAM_SEPARABLE is not supported before GLES 3.1");
Yunchao He61afff12017-03-14 15:34:03 +08001671 return false;
1672 }
1673
1674 if (value != GL_FALSE && value != GL_TRUE)
1675 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001676 context->handleError(InvalidValue()
1677 << "Invalid value, expected GL_FALSE or GL_TRUE: " << value);
Yunchao He61afff12017-03-14 15:34:03 +08001678 return false;
1679 }
1680 break;
1681
Geoff Langc5629752015-12-07 16:29:04 -05001682 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001683 context->handleError(InvalidEnum()
1684 << "Invalid pname: 0x" << std::hex << std::uppercase << pname);
Geoff Langc5629752015-12-07 16:29:04 -05001685 return false;
1686 }
1687
1688 return true;
1689}
Jamie Madillc29968b2016-01-20 11:17:23 -05001690
1691bool ValidateBlitFramebuffer(Context *context,
1692 GLint srcX0,
1693 GLint srcY0,
1694 GLint srcX1,
1695 GLint srcY1,
1696 GLint dstX0,
1697 GLint dstY0,
1698 GLint dstX1,
1699 GLint dstY1,
1700 GLbitfield mask,
1701 GLenum filter)
1702{
Martin Radev1be913c2016-07-11 17:59:16 +03001703 if (context->getClientMajorVersion() < 3)
Jamie Madillc29968b2016-01-20 11:17:23 -05001704 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001705 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madillc29968b2016-01-20 11:17:23 -05001706 return false;
1707 }
1708
1709 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
1710 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001711}
Jamie Madillc29968b2016-01-20 11:17:23 -05001712
1713bool ValidateClearBufferiv(ValidationContext *context,
1714 GLenum buffer,
1715 GLint drawbuffer,
1716 const GLint *value)
1717{
1718 switch (buffer)
1719 {
1720 case GL_COLOR:
1721 if (drawbuffer < 0 ||
1722 static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
1723 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001724 context->handleError(InvalidValue());
Jamie Madillc29968b2016-01-20 11:17:23 -05001725 return false;
1726 }
Geoff Lang76e65652017-03-27 14:58:02 -04001727 if (context->getExtensions().webglCompatibility)
1728 {
1729 constexpr GLenum validComponentTypes[] = {GL_INT};
Geoff Lang0fb08642017-07-04 15:07:23 -04001730 if (!ValidateWebGLFramebufferAttachmentClearType(
Geoff Lang76e65652017-03-27 14:58:02 -04001731 context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes)))
1732 {
1733 return false;
1734 }
1735 }
Jamie Madillc29968b2016-01-20 11:17:23 -05001736 break;
1737
1738 case GL_STENCIL:
1739 if (drawbuffer != 0)
1740 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001741 context->handleError(InvalidValue());
Jamie Madillc29968b2016-01-20 11:17:23 -05001742 return false;
1743 }
1744 break;
1745
1746 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001747 context->handleError(InvalidEnum());
Jamie Madillc29968b2016-01-20 11:17:23 -05001748 return false;
1749 }
1750
1751 return ValidateClearBuffer(context);
1752}
1753
1754bool ValidateClearBufferuiv(ValidationContext *context,
1755 GLenum buffer,
1756 GLint drawbuffer,
1757 const GLuint *value)
1758{
1759 switch (buffer)
1760 {
1761 case GL_COLOR:
1762 if (drawbuffer < 0 ||
1763 static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
1764 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001765 context->handleError(InvalidValue());
Jamie Madillc29968b2016-01-20 11:17:23 -05001766 return false;
1767 }
Geoff Lang76e65652017-03-27 14:58:02 -04001768 if (context->getExtensions().webglCompatibility)
1769 {
1770 constexpr GLenum validComponentTypes[] = {GL_UNSIGNED_INT};
Geoff Lang0fb08642017-07-04 15:07:23 -04001771 if (!ValidateWebGLFramebufferAttachmentClearType(
Geoff Lang76e65652017-03-27 14:58:02 -04001772 context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes)))
1773 {
1774 return false;
1775 }
1776 }
Jamie Madillc29968b2016-01-20 11:17:23 -05001777 break;
1778
1779 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001780 context->handleError(InvalidEnum());
Jamie Madillc29968b2016-01-20 11:17:23 -05001781 return false;
1782 }
1783
1784 return ValidateClearBuffer(context);
1785}
1786
1787bool ValidateClearBufferfv(ValidationContext *context,
1788 GLenum buffer,
1789 GLint drawbuffer,
1790 const GLfloat *value)
1791{
1792 switch (buffer)
1793 {
1794 case GL_COLOR:
1795 if (drawbuffer < 0 ||
1796 static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
1797 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001798 context->handleError(InvalidValue());
Jamie Madillc29968b2016-01-20 11:17:23 -05001799 return false;
1800 }
Geoff Lang76e65652017-03-27 14:58:02 -04001801 if (context->getExtensions().webglCompatibility)
1802 {
1803 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
1804 GL_SIGNED_NORMALIZED};
Geoff Lang0fb08642017-07-04 15:07:23 -04001805 if (!ValidateWebGLFramebufferAttachmentClearType(
Geoff Lang76e65652017-03-27 14:58:02 -04001806 context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes)))
1807 {
1808 return false;
1809 }
1810 }
Jamie Madillc29968b2016-01-20 11:17:23 -05001811 break;
1812
1813 case GL_DEPTH:
1814 if (drawbuffer != 0)
1815 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001816 context->handleError(InvalidValue());
Jamie Madillc29968b2016-01-20 11:17:23 -05001817 return false;
1818 }
1819 break;
1820
1821 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001822 context->handleError(InvalidEnum());
Jamie Madillc29968b2016-01-20 11:17:23 -05001823 return false;
1824 }
1825
1826 return ValidateClearBuffer(context);
1827}
1828
1829bool ValidateClearBufferfi(ValidationContext *context,
1830 GLenum buffer,
1831 GLint drawbuffer,
1832 GLfloat depth,
1833 GLint stencil)
1834{
1835 switch (buffer)
1836 {
1837 case GL_DEPTH_STENCIL:
1838 if (drawbuffer != 0)
1839 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001840 context->handleError(InvalidValue());
Jamie Madillc29968b2016-01-20 11:17:23 -05001841 return false;
1842 }
1843 break;
1844
1845 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001846 context->handleError(InvalidEnum());
Jamie Madillc29968b2016-01-20 11:17:23 -05001847 return false;
1848 }
1849
1850 return ValidateClearBuffer(context);
1851}
1852
1853bool ValidateDrawBuffers(ValidationContext *context, GLsizei n, const GLenum *bufs)
1854{
Martin Radev1be913c2016-07-11 17:59:16 +03001855 if (context->getClientMajorVersion() < 3)
Jamie Madillc29968b2016-01-20 11:17:23 -05001856 {
Brandon Jonesafa75152017-07-21 13:11:29 -07001857 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madillc29968b2016-01-20 11:17:23 -05001858 return false;
1859 }
1860
1861 return ValidateDrawBuffersBase(context, n, bufs);
1862}
1863
1864bool ValidateCopyTexSubImage3D(Context *context,
1865 GLenum target,
1866 GLint level,
1867 GLint xoffset,
1868 GLint yoffset,
1869 GLint zoffset,
1870 GLint x,
1871 GLint y,
1872 GLsizei width,
1873 GLsizei height)
1874{
Martin Radev1be913c2016-07-11 17:59:16 +03001875 if (context->getClientMajorVersion() < 3)
Jamie Madillc29968b2016-01-20 11:17:23 -05001876 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001877 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madillc29968b2016-01-20 11:17:23 -05001878 return false;
1879 }
1880
Ian Ewellfc7cf8e2016-01-20 15:57:46 -05001881 return ValidateES3CopyTexImage3DParameters(context, target, level, GL_NONE, true, xoffset,
1882 yoffset, zoffset, x, y, width, height, 0);
Jamie Madillc29968b2016-01-20 11:17:23 -05001883}
1884
Jamie Madill73a84962016-02-12 09:27:23 -05001885bool ValidateTexImage3D(Context *context,
1886 GLenum target,
1887 GLint level,
1888 GLint internalformat,
1889 GLsizei width,
1890 GLsizei height,
1891 GLsizei depth,
1892 GLint border,
1893 GLenum format,
1894 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001895 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05001896{
Martin Radev1be913c2016-07-11 17:59:16 +03001897 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05001898 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001899 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madill73a84962016-02-12 09:27:23 -05001900 return false;
1901 }
1902
1903 return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langc52f6f12016-10-14 10:18:00 -04001904 0, 0, width, height, depth, border, format, type, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05001905 pixels);
1906}
1907
Geoff Langc52f6f12016-10-14 10:18:00 -04001908bool ValidateTexImage3DRobustANGLE(Context *context,
1909 GLenum target,
1910 GLint level,
1911 GLint internalformat,
1912 GLsizei width,
1913 GLsizei height,
1914 GLsizei depth,
1915 GLint border,
1916 GLenum format,
1917 GLenum type,
1918 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001919 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04001920{
1921 if (context->getClientMajorVersion() < 3)
1922 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001923 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langc52f6f12016-10-14 10:18:00 -04001924 return false;
1925 }
1926
1927 if (!ValidateRobustEntryPoint(context, bufSize))
1928 {
1929 return false;
1930 }
1931
1932 return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0,
1933 0, 0, width, height, depth, border, format, type,
1934 bufSize, pixels);
1935}
1936
Jamie Madill73a84962016-02-12 09:27:23 -05001937bool ValidateTexSubImage3D(Context *context,
1938 GLenum target,
1939 GLint level,
1940 GLint xoffset,
1941 GLint yoffset,
1942 GLint zoffset,
1943 GLsizei width,
1944 GLsizei height,
1945 GLsizei depth,
1946 GLenum format,
1947 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001948 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05001949{
Martin Radev1be913c2016-07-11 17:59:16 +03001950 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05001951 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001952 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madill73a84962016-02-12 09:27:23 -05001953 return false;
1954 }
1955
1956 return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset,
1957 yoffset, zoffset, width, height, depth, 0, format, type,
Geoff Langc52f6f12016-10-14 10:18:00 -04001958 -1, pixels);
1959}
1960
1961bool ValidateTexSubImage3DRobustANGLE(Context *context,
1962 GLenum target,
1963 GLint level,
1964 GLint xoffset,
1965 GLint yoffset,
1966 GLint zoffset,
1967 GLsizei width,
1968 GLsizei height,
1969 GLsizei depth,
1970 GLenum format,
1971 GLenum type,
1972 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001973 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04001974{
1975 if (context->getClientMajorVersion() < 3)
1976 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08001977 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langc52f6f12016-10-14 10:18:00 -04001978 return false;
1979 }
1980
1981 if (!ValidateRobustEntryPoint(context, bufSize))
1982 {
1983 return false;
1984 }
1985
1986 return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset,
1987 yoffset, zoffset, width, height, depth, 0, format, type,
1988 bufSize, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05001989}
1990
1991bool ValidateCompressedTexSubImage3D(Context *context,
1992 GLenum target,
1993 GLint level,
1994 GLint xoffset,
1995 GLint yoffset,
1996 GLint zoffset,
1997 GLsizei width,
1998 GLsizei height,
1999 GLsizei depth,
2000 GLenum format,
2001 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002002 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002003{
Martin Radev1be913c2016-07-11 17:59:16 +03002004 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002005 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08002006 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madill73a84962016-02-12 09:27:23 -05002007 return false;
2008 }
2009
Geoff Langca271392017-04-05 12:30:00 -04002010 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Geoff Langc5508d62017-02-10 14:58:38 -05002011 if (!formatInfo.compressed)
2012 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002013 context->handleError(InvalidEnum() << "Not a valid compressed texture format");
Geoff Langc5508d62017-02-10 14:58:38 -05002014 return false;
2015 }
2016
Jeff Gilbert48590352017-11-07 16:03:38 -08002017 auto blockSizeOrErr = formatInfo.computeCompressedImageSize(gl::Extents(width, height, depth));
Jamie Madille2e406c2016-06-02 13:04:10 -04002018 if (blockSizeOrErr.isError())
2019 {
2020 context->handleError(blockSizeOrErr.getError());
2021 return false;
2022 }
2023 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult())
Jamie Madill73a84962016-02-12 09:27:23 -05002024 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002025 context->handleError(InvalidValue());
Jamie Madill73a84962016-02-12 09:27:23 -05002026 return false;
2027 }
2028
2029 if (!data)
2030 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002031 context->handleError(InvalidValue());
Jamie Madill73a84962016-02-12 09:27:23 -05002032 return false;
2033 }
2034
Geoff Lang5ca5c652017-10-27 17:29:54 -04002035 return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, true, true, xoffset,
2036 yoffset, zoffset, width, height, depth, 0, format,
2037 GL_NONE, -1, data);
Jamie Madill73a84962016-02-12 09:27:23 -05002038}
Corentin Wallezb2931602017-04-11 15:58:57 -04002039bool ValidateCompressedTexSubImage3DRobustANGLE(Context *context,
2040 GLenum target,
2041 GLint level,
2042 GLint xoffset,
2043 GLint yoffset,
2044 GLint zoffset,
2045 GLsizei width,
2046 GLsizei height,
2047 GLsizei depth,
2048 GLenum format,
2049 GLsizei imageSize,
2050 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002051 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002052{
2053 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2054 {
2055 return false;
2056 }
2057
2058 return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width,
2059 height, depth, format, imageSize, data);
2060}
Jamie Madill73a84962016-02-12 09:27:23 -05002061
Olli Etuaho41997e72016-03-10 13:38:39 +02002062bool ValidateGenQueries(Context *context, GLint n, GLuint *)
2063{
2064 return ValidateGenOrDeleteES3(context, n);
2065}
2066
2067bool ValidateDeleteQueries(Context *context, GLint n, const GLuint *)
2068{
2069 return ValidateGenOrDeleteES3(context, n);
2070}
2071
2072bool ValidateGenSamplers(Context *context, GLint count, GLuint *)
2073{
2074 return ValidateGenOrDeleteCountES3(context, count);
2075}
2076
2077bool ValidateDeleteSamplers(Context *context, GLint count, const GLuint *)
2078{
2079 return ValidateGenOrDeleteCountES3(context, count);
2080}
2081
2082bool ValidateGenTransformFeedbacks(Context *context, GLint n, GLuint *)
2083{
2084 return ValidateGenOrDeleteES3(context, n);
2085}
2086
2087bool ValidateDeleteTransformFeedbacks(Context *context, GLint n, const GLuint *ids)
2088{
2089 if (!ValidateGenOrDeleteES3(context, n))
2090 {
2091 return false;
2092 }
2093 for (GLint i = 0; i < n; ++i)
2094 {
2095 auto *transformFeedback = context->getTransformFeedback(ids[i]);
2096 if (transformFeedback != nullptr && transformFeedback->isActive())
2097 {
2098 // ES 3.0.4 section 2.15.1 page 86
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002099 context->handleError(InvalidOperation()
2100 << "Attempt to delete active transform feedback.");
Olli Etuaho41997e72016-03-10 13:38:39 +02002101 return false;
2102 }
2103 }
2104 return true;
2105}
2106
2107bool ValidateGenVertexArrays(Context *context, GLint n, GLuint *)
2108{
2109 return ValidateGenOrDeleteES3(context, n);
2110}
2111
2112bool ValidateDeleteVertexArrays(Context *context, GLint n, const GLuint *)
2113{
2114 return ValidateGenOrDeleteES3(context, n);
2115}
2116
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002117bool ValidateBeginTransformFeedback(Context *context, GLenum primitiveMode)
2118{
Martin Radev1be913c2016-07-11 17:59:16 +03002119 if (context->getClientMajorVersion() < 3)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002120 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002121 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002122 return false;
2123 }
2124 switch (primitiveMode)
2125 {
2126 case GL_TRIANGLES:
2127 case GL_LINES:
2128 case GL_POINTS:
2129 break;
2130
2131 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002132 context->handleError(InvalidEnum() << "Invalid primitive mode.");
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002133 return false;
2134 }
2135
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002136 TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002137 ASSERT(transformFeedback != nullptr);
2138
2139 if (transformFeedback->isActive())
2140 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002141 context->handleError(InvalidOperation() << "Transform feedback is already active.");
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002142 return false;
2143 }
Geoff Lang79f71042017-08-14 16:43:43 -04002144
2145 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
2146 {
2147 const auto &buffer = transformFeedback->getIndexedBuffer(i);
2148 if (buffer.get() && buffer->isMapped())
2149 {
2150 context->handleError(InvalidOperation() << "Transform feedback has a mapped buffer.");
2151 return false;
2152 }
2153 }
2154
Jamie Madillacf2f3a2017-11-21 19:22:44 -05002155 Program *program = context->getGLState().getProgram();
Olli Etuaho02032bd2017-10-13 18:10:17 +03002156
2157 if (!program)
2158 {
2159 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotBound);
2160 return false;
2161 }
2162
2163 if (program->getTransformFeedbackVaryingCount() == 0)
2164 {
2165 ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoTransformFeedbackOutputVariables);
2166 return false;
2167 }
2168
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002169 return true;
2170}
2171
Corentin Wallez336129f2017-10-17 15:55:40 -04002172bool ValidateGetBufferPointerv(Context *context, BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03002173{
Geoff Lang496c02d2016-10-20 11:38:11 -07002174 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
2175}
2176
2177bool ValidateGetBufferPointervRobustANGLE(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04002178 BufferBinding target,
Geoff Lang496c02d2016-10-20 11:38:11 -07002179 GLenum pname,
2180 GLsizei bufSize,
2181 GLsizei *length,
Jamie Madill876429b2017-04-20 15:46:24 -04002182 void **params)
Geoff Lang496c02d2016-10-20 11:38:11 -07002183{
2184 if (!ValidateRobustEntryPoint(context, bufSize))
Olli Etuaho4f667482016-03-30 15:56:35 +03002185 {
Olli Etuaho4f667482016-03-30 15:56:35 +03002186 return false;
2187 }
2188
Geoff Lang496c02d2016-10-20 11:38:11 -07002189 if (!ValidateGetBufferPointervBase(context, target, pname, length, params))
2190 {
2191 return false;
2192 }
2193
2194 if (!ValidateRobustBufferSize(context, bufSize, *length))
2195 {
2196 return false;
2197 }
2198
2199 return true;
Olli Etuaho4f667482016-03-30 15:56:35 +03002200}
2201
Corentin Wallez336129f2017-10-17 15:55:40 -04002202bool ValidateUnmapBuffer(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03002203{
Martin Radev1be913c2016-07-11 17:59:16 +03002204 if (context->getClientMajorVersion() < 3)
Olli Etuaho4f667482016-03-30 15:56:35 +03002205 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08002206 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Olli Etuaho4f667482016-03-30 15:56:35 +03002207 return false;
2208 }
2209
2210 return ValidateUnmapBufferBase(context, target);
2211}
2212
2213bool ValidateMapBufferRange(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04002214 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03002215 GLintptr offset,
2216 GLsizeiptr length,
2217 GLbitfield access)
2218{
Martin Radev1be913c2016-07-11 17:59:16 +03002219 if (context->getClientMajorVersion() < 3)
Olli Etuaho4f667482016-03-30 15:56:35 +03002220 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002221 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Olli Etuaho4f667482016-03-30 15:56:35 +03002222 return false;
2223 }
2224
2225 return ValidateMapBufferRangeBase(context, target, offset, length, access);
2226}
2227
2228bool ValidateFlushMappedBufferRange(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04002229 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03002230 GLintptr offset,
2231 GLsizeiptr length)
2232{
Martin Radev1be913c2016-07-11 17:59:16 +03002233 if (context->getClientMajorVersion() < 3)
Olli Etuaho4f667482016-03-30 15:56:35 +03002234 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002235 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Olli Etuaho4f667482016-03-30 15:56:35 +03002236 return false;
2237 }
2238
2239 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
2240}
2241
Geoff Lang2e43dbb2016-10-14 12:27:35 -04002242bool ValidateIndexedStateQuery(ValidationContext *context,
2243 GLenum pname,
2244 GLuint index,
2245 GLsizei *length)
Martin Radev66fb8202016-07-28 11:45:20 +03002246{
Geoff Lang2e43dbb2016-10-14 12:27:35 -04002247 if (length)
2248 {
2249 *length = 0;
2250 }
2251
Martin Radev66fb8202016-07-28 11:45:20 +03002252 GLenum nativeType;
2253 unsigned int numParams;
2254 if (!context->getIndexedQueryParameterInfo(pname, &nativeType, &numParams))
2255 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002256 context->handleError(InvalidEnum());
Martin Radev66fb8202016-07-28 11:45:20 +03002257 return false;
2258 }
2259
2260 const Caps &caps = context->getCaps();
2261 switch (pname)
2262 {
2263 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
2264 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
2265 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
2266 if (index >= caps.maxTransformFeedbackSeparateAttributes)
2267 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002268 context->handleError(InvalidValue());
Martin Radev66fb8202016-07-28 11:45:20 +03002269 return false;
2270 }
2271 break;
2272
2273 case GL_UNIFORM_BUFFER_START:
2274 case GL_UNIFORM_BUFFER_SIZE:
2275 case GL_UNIFORM_BUFFER_BINDING:
2276 if (index >= caps.maxUniformBufferBindings)
2277 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002278 context->handleError(InvalidValue());
Martin Radev66fb8202016-07-28 11:45:20 +03002279 return false;
2280 }
2281 break;
Shao80957d92017-02-20 21:25:59 +08002282
Martin Radev66fb8202016-07-28 11:45:20 +03002283 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
2284 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
2285 if (index >= 3u)
2286 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002287 context->handleError(InvalidValue());
Martin Radev66fb8202016-07-28 11:45:20 +03002288 return false;
2289 }
2290 break;
Shao80957d92017-02-20 21:25:59 +08002291
Jiajia Qin6eafb042016-12-27 17:04:07 +08002292 case GL_ATOMIC_COUNTER_BUFFER_START:
2293 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
2294 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
2295 if (context->getClientVersion() < ES_3_1)
2296 {
2297 context->handleError(
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002298 InvalidEnum()
2299 << "Atomic Counter buffers are not supported in this version of GL");
Jiajia Qin6eafb042016-12-27 17:04:07 +08002300 return false;
2301 }
2302 if (index >= caps.maxAtomicCounterBufferBindings)
2303 {
2304 context->handleError(
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002305 InvalidValue()
2306 << "index is outside the valid range for GL_ATOMIC_COUNTER_BUFFER_BINDING");
Jiajia Qin6eafb042016-12-27 17:04:07 +08002307 return false;
2308 }
2309 break;
Shao80957d92017-02-20 21:25:59 +08002310
Jiajia Qinf546e7d2017-03-27 14:12:59 +08002311 case GL_SHADER_STORAGE_BUFFER_START:
2312 case GL_SHADER_STORAGE_BUFFER_SIZE:
2313 case GL_SHADER_STORAGE_BUFFER_BINDING:
2314 if (context->getClientVersion() < ES_3_1)
2315 {
2316 context->handleError(
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002317 InvalidEnum()
2318 << "Shader storage buffers are not supported in this version of GL");
Jiajia Qinf546e7d2017-03-27 14:12:59 +08002319 return false;
2320 }
2321 if (index >= caps.maxShaderStorageBufferBindings)
2322 {
2323 context->handleError(
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002324 InvalidValue()
2325 << "index is outside the valid range for GL_SHADER_STORAGE_BUFFER_BINDING");
Jiajia Qinf546e7d2017-03-27 14:12:59 +08002326 return false;
2327 }
2328 break;
2329
Shao80957d92017-02-20 21:25:59 +08002330 case GL_VERTEX_BINDING_BUFFER:
2331 case GL_VERTEX_BINDING_DIVISOR:
2332 case GL_VERTEX_BINDING_OFFSET:
2333 case GL_VERTEX_BINDING_STRIDE:
2334 if (context->getClientVersion() < ES_3_1)
2335 {
2336 context->handleError(
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002337 InvalidEnum()
2338 << "Vertex Attrib Bindings are not supported in this version of GL");
Shao80957d92017-02-20 21:25:59 +08002339 return false;
2340 }
2341 if (index >= caps.maxVertexAttribBindings)
2342 {
2343 context->handleError(
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002344 InvalidValue()
2345 << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS.");
Shao80957d92017-02-20 21:25:59 +08002346 return false;
2347 }
2348 break;
Jiawei Shaodb342272017-09-27 10:21:45 +08002349 case GL_SAMPLE_MASK_VALUE:
2350 if (context->getClientVersion() < ES_3_1)
2351 {
2352 ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31);
2353 return false;
2354 }
2355 if (index >= caps.maxSampleMaskWords)
2356 {
2357 ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidSampleMaskNumber);
2358 return false;
2359 }
2360 break;
Xinghua Cao9c8e1a32017-12-06 17:59:58 +08002361 case GL_IMAGE_BINDING_NAME:
2362 case GL_IMAGE_BINDING_LEVEL:
2363 case GL_IMAGE_BINDING_LAYERED:
2364 case GL_IMAGE_BINDING_LAYER:
2365 case GL_IMAGE_BINDING_ACCESS:
2366 case GL_IMAGE_BINDING_FORMAT:
2367 if (context->getClientVersion() < ES_3_1)
2368 {
2369 ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31);
2370 return false;
2371 }
2372 if (index >= caps.maxImageUnits)
2373 {
2374 ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidImageUnit);
2375 return false;
2376 }
2377 break;
Martin Radev66fb8202016-07-28 11:45:20 +03002378 default:
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002379 context->handleError(InvalidEnum());
Martin Radev66fb8202016-07-28 11:45:20 +03002380 return false;
2381 }
2382
Geoff Lang2e43dbb2016-10-14 12:27:35 -04002383 if (length)
Martin Radev66fb8202016-07-28 11:45:20 +03002384 {
Geoff Lang2e43dbb2016-10-14 12:27:35 -04002385 *length = 1;
Martin Radev66fb8202016-07-28 11:45:20 +03002386 }
2387
2388 return true;
2389}
2390
2391bool ValidateGetIntegeri_v(ValidationContext *context, GLenum target, GLuint index, GLint *data)
2392{
Geoff Langeb66a6e2016-10-31 13:06:12 -04002393 if (context->getClientVersion() < ES_3_0)
Martin Radev66fb8202016-07-28 11:45:20 +03002394 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002395 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Martin Radev66fb8202016-07-28 11:45:20 +03002396 return false;
2397 }
Geoff Lang2e43dbb2016-10-14 12:27:35 -04002398 return ValidateIndexedStateQuery(context, target, index, nullptr);
Martin Radev66fb8202016-07-28 11:45:20 +03002399}
2400
Geoff Langcf255ea2016-10-20 11:39:09 -07002401bool ValidateGetIntegeri_vRobustANGLE(ValidationContext *context,
2402 GLenum target,
2403 GLuint index,
2404 GLsizei bufSize,
2405 GLsizei *length,
2406 GLint *data)
2407{
Geoff Langeb66a6e2016-10-31 13:06:12 -04002408 if (context->getClientVersion() < ES_3_0)
Geoff Langcf255ea2016-10-20 11:39:09 -07002409 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002410 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langcf255ea2016-10-20 11:39:09 -07002411 return false;
2412 }
2413
2414 if (!ValidateRobustEntryPoint(context, bufSize))
2415 {
2416 return false;
2417 }
2418
2419 if (!ValidateIndexedStateQuery(context, target, index, length))
2420 {
2421 return false;
2422 }
2423
2424 if (!ValidateRobustBufferSize(context, bufSize, *length))
2425 {
2426 return false;
2427 }
2428
2429 return true;
2430}
2431
Martin Radev66fb8202016-07-28 11:45:20 +03002432bool ValidateGetInteger64i_v(ValidationContext *context, GLenum target, GLuint index, GLint64 *data)
2433{
Geoff Langeb66a6e2016-10-31 13:06:12 -04002434 if (context->getClientVersion() < ES_3_0)
Martin Radev66fb8202016-07-28 11:45:20 +03002435 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002436 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Martin Radev66fb8202016-07-28 11:45:20 +03002437 return false;
2438 }
Geoff Lang2e43dbb2016-10-14 12:27:35 -04002439 return ValidateIndexedStateQuery(context, target, index, nullptr);
2440}
2441
2442bool ValidateGetInteger64i_vRobustANGLE(ValidationContext *context,
2443 GLenum target,
2444 GLuint index,
2445 GLsizei bufSize,
2446 GLsizei *length,
2447 GLint64 *data)
2448{
Geoff Langeb66a6e2016-10-31 13:06:12 -04002449 if (context->getClientVersion() < ES_3_0)
Geoff Lang2e43dbb2016-10-14 12:27:35 -04002450 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002451 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Lang2e43dbb2016-10-14 12:27:35 -04002452 return false;
2453 }
2454
2455 if (!ValidateRobustEntryPoint(context, bufSize))
2456 {
2457 return false;
2458 }
2459
2460 if (!ValidateIndexedStateQuery(context, target, index, length))
2461 {
2462 return false;
2463 }
2464
2465 if (!ValidateRobustBufferSize(context, bufSize, *length))
2466 {
2467 return false;
2468 }
2469
2470 return true;
Martin Radev66fb8202016-07-28 11:45:20 +03002471}
2472
Jamie Madillb0817d12016-11-01 15:48:31 -04002473bool ValidateCopyBufferSubData(ValidationContext *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04002474 BufferBinding readTarget,
2475 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04002476 GLintptr readOffset,
2477 GLintptr writeOffset,
2478 GLsizeiptr size)
2479{
2480 if (context->getClientMajorVersion() < 3)
2481 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002482 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madillb0817d12016-11-01 15:48:31 -04002483 return false;
2484 }
2485
Corentin Walleze4477002017-12-01 14:39:58 -05002486 if (!context->isValidBufferBinding(readTarget) || !context->isValidBufferBinding(writeTarget))
Jamie Madillb0817d12016-11-01 15:48:31 -04002487 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002488 context->handleError(InvalidEnum() << "Invalid buffer target");
Jamie Madillb0817d12016-11-01 15:48:31 -04002489 return false;
2490 }
2491
2492 Buffer *readBuffer = context->getGLState().getTargetBuffer(readTarget);
2493 Buffer *writeBuffer = context->getGLState().getTargetBuffer(writeTarget);
2494
2495 if (!readBuffer || !writeBuffer)
2496 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002497 context->handleError(InvalidOperation() << "No buffer bound to target");
Jamie Madillb0817d12016-11-01 15:48:31 -04002498 return false;
2499 }
2500
2501 // Verify that readBuffer and writeBuffer are not currently mapped
2502 if (readBuffer->isMapped() || writeBuffer->isMapped())
2503 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002504 context->handleError(InvalidOperation()
2505 << "Cannot call CopyBufferSubData on a mapped buffer");
Jamie Madillb0817d12016-11-01 15:48:31 -04002506 return false;
2507 }
2508
Jamie Madilld2f0c742016-11-02 10:34:41 -04002509 CheckedNumeric<GLintptr> checkedReadOffset(readOffset);
2510 CheckedNumeric<GLintptr> checkedWriteOffset(writeOffset);
2511 CheckedNumeric<GLintptr> checkedSize(size);
2512
2513 auto checkedReadSum = checkedReadOffset + checkedSize;
2514 auto checkedWriteSum = checkedWriteOffset + checkedSize;
2515
2516 if (!checkedReadSum.IsValid() || !checkedWriteSum.IsValid() ||
2517 !IsValueInRangeForNumericType<GLintptr>(readBuffer->getSize()) ||
2518 !IsValueInRangeForNumericType<GLintptr>(writeBuffer->getSize()))
Jamie Madillb0817d12016-11-01 15:48:31 -04002519 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002520 context->handleError(InvalidValue() << "Integer overflow when validating copy offsets.");
Jamie Madillb0817d12016-11-01 15:48:31 -04002521 return false;
2522 }
2523
Jamie Madilld2f0c742016-11-02 10:34:41 -04002524 if (readOffset < 0 || writeOffset < 0 || size < 0)
Jamie Madillb0817d12016-11-01 15:48:31 -04002525 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002526 context->handleError(InvalidValue()
2527 << "readOffset, writeOffset and size must all be non-negative");
Jamie Madillb0817d12016-11-01 15:48:31 -04002528 return false;
2529 }
2530
Jamie Madilld2f0c742016-11-02 10:34:41 -04002531 if (checkedReadSum.ValueOrDie() > readBuffer->getSize() ||
2532 checkedWriteSum.ValueOrDie() > writeBuffer->getSize())
2533 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002534 context->handleError(InvalidValue() << "Buffer offset overflow in CopyBufferSubData");
Jamie Madilld2f0c742016-11-02 10:34:41 -04002535 return false;
2536 }
2537
2538 if (readBuffer == writeBuffer)
2539 {
2540 auto checkedOffsetDiff = (checkedReadOffset - checkedWriteOffset).Abs();
2541 if (!checkedOffsetDiff.IsValid())
2542 {
2543 // This shold not be possible.
2544 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002545 context->handleError(InvalidValue()
2546 << "Integer overflow when validating same buffer copy.");
Jamie Madilld2f0c742016-11-02 10:34:41 -04002547 return false;
2548 }
2549
2550 if (checkedOffsetDiff.ValueOrDie() < size)
2551 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002552 context->handleError(InvalidValue());
Jamie Madilld2f0c742016-11-02 10:34:41 -04002553 return false;
2554 }
2555 }
2556
Jamie Madillb0817d12016-11-01 15:48:31 -04002557 return true;
2558}
2559
Geoff Langc339c4e2016-11-29 10:37:36 -05002560bool ValidateGetStringi(Context *context, GLenum name, GLuint index)
2561{
2562 if (context->getClientMajorVersion() < 3)
2563 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002564 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langc339c4e2016-11-29 10:37:36 -05002565 return false;
2566 }
2567
2568 switch (name)
2569 {
2570 case GL_EXTENSIONS:
2571 if (index >= context->getExtensionStringCount())
2572 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002573 context->handleError(InvalidValue()
2574 << "index must be less than the number of extension strings.");
Geoff Langc339c4e2016-11-29 10:37:36 -05002575 return false;
2576 }
2577 break;
2578
2579 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2580 if (!context->getExtensions().requestExtension)
2581 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002582 ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05002583 return false;
2584 }
2585 if (index >= context->getRequestableExtensionStringCount())
2586 {
2587 context->handleError(
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002588 InvalidValue()
2589 << "index must be less than the number of requestable extension strings.");
Geoff Langc339c4e2016-11-29 10:37:36 -05002590 return false;
2591 }
2592 break;
2593
2594 default:
Brandon Jonesafa75152017-07-21 13:11:29 -07002595 ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05002596 return false;
2597 }
2598
2599 return true;
2600}
2601
Jamie Madille8fb6402017-02-14 17:56:40 -05002602bool ValidateRenderbufferStorageMultisample(ValidationContext *context,
2603 GLenum target,
2604 GLsizei samples,
2605 GLenum internalformat,
2606 GLsizei width,
2607 GLsizei height)
2608{
2609 if (context->getClientMajorVersion() < 3)
2610 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08002611 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madille8fb6402017-02-14 17:56:40 -05002612 return false;
2613 }
2614
2615 if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width,
2616 height))
2617 {
2618 return false;
2619 }
2620
2621 // The ES3 spec(section 4.4.2) states that the internal format must be sized and not an integer
2622 // format if samples is greater than zero.
Geoff Langca271392017-04-05 12:30:00 -04002623 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05002624 if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) &&
2625 samples > 0)
2626 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002627 context->handleError(InvalidOperation());
Jamie Madille8fb6402017-02-14 17:56:40 -05002628 return false;
2629 }
2630
2631 // The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY.
2632 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
2633 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
2634 {
2635 context->handleError(
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002636 InvalidOperation()
2637 << "Samples must not be greater than maximum supported value for the format.");
Jamie Madille8fb6402017-02-14 17:56:40 -05002638 return false;
2639 }
2640
2641 return true;
2642}
2643
Geoff Langaa086d62017-03-23 16:47:21 -04002644bool ValidateVertexAttribIPointer(ValidationContext *context,
2645 GLuint index,
2646 GLint size,
2647 GLenum type,
2648 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04002649 const void *pointer)
Geoff Langaa086d62017-03-23 16:47:21 -04002650{
2651 if (context->getClientMajorVersion() < 3)
2652 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002653 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Langaa086d62017-03-23 16:47:21 -04002654 return false;
2655 }
2656
Shao80957d92017-02-20 21:25:59 +08002657 if (!ValidateVertexFormatBase(context, index, size, type, true))
Geoff Langaa086d62017-03-23 16:47:21 -04002658 {
Geoff Langaa086d62017-03-23 16:47:21 -04002659 return false;
2660 }
2661
Geoff Langaa086d62017-03-23 16:47:21 -04002662 if (stride < 0)
2663 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002664 ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStride);
Geoff Langaa086d62017-03-23 16:47:21 -04002665 return false;
2666 }
2667
Shao80957d92017-02-20 21:25:59 +08002668 const Caps &caps = context->getCaps();
2669 if (context->getClientVersion() >= ES_3_1)
2670 {
2671 if (stride > caps.maxVertexAttribStride)
2672 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002673 context->handleError(InvalidValue()
2674 << "stride cannot be greater than MAX_VERTEX_ATTRIB_STRIDE.");
Shao80957d92017-02-20 21:25:59 +08002675 return false;
2676 }
2677
2678 // [OpenGL ES 3.1] Section 10.3.1 page 245:
2679 // glVertexAttribBinding is part of the equivalent code of VertexAttribIPointer, so its
2680 // validation should be inherited.
2681 if (index >= caps.maxVertexAttribBindings)
2682 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002683 context->handleError(InvalidValue()
2684 << "index must be smaller than MAX_VERTEX_ATTRIB_BINDINGS.");
Shao80957d92017-02-20 21:25:59 +08002685 return false;
2686 }
2687 }
2688
Geoff Langaa086d62017-03-23 16:47:21 -04002689 // [OpenGL ES 3.0.2] Section 2.8 page 24:
2690 // An INVALID_OPERATION error is generated when a non-zero vertex array object
2691 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
2692 // and the pointer argument is not NULL.
2693 if (context->getGLState().getVertexArrayId() != 0 &&
Corentin Wallez336129f2017-10-17 15:55:40 -04002694 context->getGLState().getTargetBuffer(BufferBinding::Array) == 0 && pointer != nullptr)
Geoff Langaa086d62017-03-23 16:47:21 -04002695 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002696 context
2697 ->handleError(InvalidOperation()
2698 << "Client data cannot be used with a non-default vertex array object.");
Geoff Langaa086d62017-03-23 16:47:21 -04002699 return false;
2700 }
2701
Geoff Lang2d62ab72017-03-23 16:54:40 -04002702 if (context->getExtensions().webglCompatibility)
2703 {
2704 if (!ValidateWebGLVertexAttribPointer(context, type, false, stride, pointer, true))
2705 {
2706 return false;
2707 }
2708 }
2709
Geoff Langaa086d62017-03-23 16:47:21 -04002710 return true;
2711}
2712
Geoff Lang38f2cfb2017-04-11 15:23:08 -04002713bool ValidateGetSynciv(Context *context,
2714 GLsync sync,
2715 GLenum pname,
2716 GLsizei bufSize,
2717 GLsizei *length,
2718 GLint *values)
2719{
2720 if (context->getClientMajorVersion() < 3)
2721 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002722 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Geoff Lang38f2cfb2017-04-11 15:23:08 -04002723 return false;
2724 }
2725
2726 if (bufSize < 0)
2727 {
Brandon Jonesafa75152017-07-21 13:11:29 -07002728 ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize);
Geoff Lang38f2cfb2017-04-11 15:23:08 -04002729 return false;
2730 }
2731
Jamie Madill70b5bb02017-08-28 13:32:37 -04002732 Sync *syncObject = context->getSync(sync);
2733 if (!syncObject)
Geoff Lang38f2cfb2017-04-11 15:23:08 -04002734 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05002735 context->handleError(InvalidValue() << "Invalid sync object.");
Geoff Lang38f2cfb2017-04-11 15:23:08 -04002736 return false;
2737 }
2738
2739 switch (pname)
2740 {
2741 case GL_OBJECT_TYPE:
2742 case GL_SYNC_CONDITION:
2743 case GL_SYNC_FLAGS:
2744 case GL_SYNC_STATUS:
2745 break;
2746
2747 default:
Brandon Jonesafa75152017-07-21 13:11:29 -07002748 ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname);
Geoff Lang38f2cfb2017-04-11 15:23:08 -04002749 return false;
2750 }
2751
2752 return true;
2753}
2754
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002755bool ValidateDrawElementsInstanced(ValidationContext *context,
2756 GLenum mode,
2757 GLsizei count,
2758 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002759 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002760 GLsizei instanceCount)
2761{
2762 if (context->getClientMajorVersion() < 3)
2763 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08002764 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002765 return false;
2766 }
2767
2768 return ValidateDrawElementsInstancedCommon(context, mode, count, type, indices, instanceCount);
2769}
2770
Martin Radev137032d2017-07-13 10:11:12 +03002771bool ValidateFramebufferTextureMultiviewLayeredANGLE(Context *context,
2772 GLenum target,
2773 GLenum attachment,
2774 GLuint texture,
2775 GLint level,
2776 GLint baseViewIndex,
2777 GLsizei numViews)
2778{
2779
2780 if (!ValidateFramebufferTextureMultiviewBaseANGLE(context, target, attachment, texture, level,
2781 numViews))
2782 {
2783 return false;
2784 }
2785
Martin Radev137032d2017-07-13 10:11:12 +03002786 if (texture != 0)
2787 {
Martin Radev14b21262017-08-25 13:54:37 +03002788 if (baseViewIndex < 0)
2789 {
2790 context->handleError(InvalidValue() << "baseViewIndex cannot be less than 0.");
2791 return false;
2792 }
2793
Martin Radev137032d2017-07-13 10:11:12 +03002794 Texture *tex = context->getTexture(texture);
2795 ASSERT(tex);
2796
2797 switch (tex->getTarget())
2798 {
2799 case GL_TEXTURE_2D_ARRAY:
2800 {
2801 const Caps &caps = context->getCaps();
2802 if (static_cast<GLuint>(baseViewIndex + numViews) > caps.maxArrayTextureLayers)
2803 {
2804 context->handleError(InvalidValue() << "baseViewIndex+numViews cannot be "
2805 "greater than "
2806 "GL_MAX_ARRAY_TEXTURE_LAYERS.");
2807 return false;
2808 }
2809 }
2810 break;
2811 default:
2812 context->handleError(InvalidOperation()
2813 << "Texture's target must be GL_TEXTURE_2D_ARRAY.");
2814 return false;
2815 }
2816
2817 if (!ValidateFramebufferTextureMultiviewLevelAndFormat(context, tex, level))
2818 {
2819 return false;
2820 }
2821 }
2822
2823 return true;
2824}
2825
2826bool ValidateFramebufferTextureMultiviewSideBySideANGLE(Context *context,
2827 GLenum target,
2828 GLenum attachment,
2829 GLuint texture,
2830 GLint level,
2831 GLsizei numViews,
2832 const GLint *viewportOffsets)
2833{
2834 if (!ValidateFramebufferTextureMultiviewBaseANGLE(context, target, attachment, texture, level,
2835 numViews))
2836 {
2837 return false;
2838 }
2839
Martin Radev137032d2017-07-13 10:11:12 +03002840 if (texture != 0)
2841 {
Martin Radev14b21262017-08-25 13:54:37 +03002842 const GLsizei numViewportOffsetValues = numViews * 2;
2843 for (GLsizei i = 0; i < numViewportOffsetValues; ++i)
2844 {
2845 if (viewportOffsets[i] < 0)
2846 {
2847 context->handleError(InvalidValue()
2848 << "viewportOffsets cannot contain negative values.");
2849 return false;
2850 }
2851 }
2852
Martin Radev137032d2017-07-13 10:11:12 +03002853 Texture *tex = context->getTexture(texture);
2854 ASSERT(tex);
2855
2856 switch (tex->getTarget())
2857 {
2858 case GL_TEXTURE_2D:
2859 break;
2860 default:
2861 context->handleError(InvalidOperation()
2862 << "Texture's target must be GL_TEXTURE_2D.");
2863 return false;
2864 }
2865
2866 if (!ValidateFramebufferTextureMultiviewLevelAndFormat(context, tex, level))
2867 {
2868 return false;
2869 }
2870 }
2871
2872 return true;
2873}
2874
Jamie Madillff325f12017-08-26 15:06:05 -04002875bool ValidateUniform1ui(Context *context, GLint location, GLuint v0)
2876{
2877 return ValidateUniformES3(context, GL_UNSIGNED_INT, location, 1);
2878}
2879
2880bool ValidateUniform2ui(Context *context, GLint location, GLuint v0, GLuint v1)
2881{
2882 return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC2, location, 1);
2883}
2884
2885bool ValidateUniform3ui(Context *context, GLint location, GLuint v0, GLuint v1, GLuint v2)
2886{
2887 return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC3, location, 1);
2888}
2889
2890bool ValidateUniform4ui(Context *context,
2891 GLint location,
2892 GLuint v0,
2893 GLuint v1,
2894 GLuint v2,
2895 GLuint v3)
2896{
2897 return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC4, location, 1);
2898}
2899
2900bool ValidateUniform1uiv(Context *context, GLint location, GLsizei count, const GLuint *value)
2901{
2902 return ValidateUniformES3(context, GL_UNSIGNED_INT, location, count);
2903}
2904
2905bool ValidateUniform2uiv(Context *context, GLint location, GLsizei count, const GLuint *value)
2906{
2907 return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC2, location, count);
2908}
2909
2910bool ValidateUniform3uiv(Context *context, GLint location, GLsizei count, const GLuint *value)
2911{
2912 return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC3, location, count);
2913}
2914
2915bool ValidateUniform4uiv(Context *context, GLint location, GLsizei count, const GLuint *value)
2916{
2917 return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC4, location, count);
2918}
2919
Jamie Madillf0e04492017-08-26 15:28:42 -04002920bool ValidateIsQuery(Context *context, GLuint id)
2921{
2922 if (context->getClientMajorVersion() < 3)
2923 {
2924 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
2925 return false;
2926 }
2927
2928 return true;
2929}
2930
Jamie Madillc8c95812017-08-26 18:40:09 -04002931bool ValidateUniformMatrix2x3fv(Context *context,
2932 GLint location,
2933 GLsizei count,
2934 GLboolean transpose,
2935 const GLfloat *value)
2936{
2937 return ValidateUniformMatrixES3(context, GL_FLOAT_MAT2x3, location, count, transpose);
2938}
2939
2940bool ValidateUniformMatrix3x2fv(Context *context,
2941 GLint location,
2942 GLsizei count,
2943 GLboolean transpose,
2944 const GLfloat *value)
2945{
2946 return ValidateUniformMatrixES3(context, GL_FLOAT_MAT3x2, location, count, transpose);
2947}
2948
2949bool ValidateUniformMatrix2x4fv(Context *context,
2950 GLint location,
2951 GLsizei count,
2952 GLboolean transpose,
2953 const GLfloat *value)
2954{
2955 return ValidateUniformMatrixES3(context, GL_FLOAT_MAT2x4, location, count, transpose);
2956}
2957
2958bool ValidateUniformMatrix4x2fv(Context *context,
2959 GLint location,
2960 GLsizei count,
2961 GLboolean transpose,
2962 const GLfloat *value)
2963{
2964 return ValidateUniformMatrixES3(context, GL_FLOAT_MAT4x2, location, count, transpose);
2965}
2966
2967bool ValidateUniformMatrix3x4fv(Context *context,
2968 GLint location,
2969 GLsizei count,
2970 GLboolean transpose,
2971 const GLfloat *value)
2972{
2973 return ValidateUniformMatrixES3(context, GL_FLOAT_MAT3x4, location, count, transpose);
2974}
2975
2976bool ValidateUniformMatrix4x3fv(Context *context,
2977 GLint location,
2978 GLsizei count,
2979 GLboolean transpose,
2980 const GLfloat *value)
2981{
2982 return ValidateUniformMatrixES3(context, GL_FLOAT_MAT4x3, location, count, transpose);
2983}
2984
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002985bool ValidateEndTransformFeedback(Context *context)
2986{
2987 if (context->getClientMajorVersion() < 3)
2988 {
2989 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
2990 return false;
2991 }
2992
2993 TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback();
2994 ASSERT(transformFeedback != nullptr);
2995
2996 if (!transformFeedback->isActive())
2997 {
2998 context->handleError(InvalidOperation());
2999 return false;
3000 }
3001
3002 return true;
3003}
3004
3005bool ValidateTransformFeedbackVaryings(Context *context,
3006 GLuint program,
3007 GLsizei count,
3008 const GLchar *const *varyings,
3009 GLenum bufferMode)
3010{
3011 if (context->getClientMajorVersion() < 3)
3012 {
3013 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3014 return false;
3015 }
3016
3017 if (count < 0)
3018 {
3019 ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount);
3020 return false;
3021 }
3022
3023 switch (bufferMode)
3024 {
3025 case GL_INTERLEAVED_ATTRIBS:
3026 break;
3027 case GL_SEPARATE_ATTRIBS:
3028 {
3029 const Caps &caps = context->getCaps();
3030 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
3031 {
3032 context->handleError(InvalidValue());
3033 return false;
3034 }
3035 break;
3036 }
3037 default:
3038 context->handleError(InvalidEnum());
3039 return false;
3040 }
3041
3042 Program *programObject = GetValidProgram(context, program);
3043 if (!programObject)
3044 {
3045 return false;
3046 }
3047
3048 return true;
3049}
3050
3051bool ValidateGetTransformFeedbackVarying(Context *context,
3052 GLuint program,
3053 GLuint index,
3054 GLsizei bufSize,
3055 GLsizei *length,
3056 GLsizei *size,
3057 GLenum *type,
3058 GLchar *name)
3059{
3060 if (context->getClientMajorVersion() < 3)
3061 {
3062 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3063 return false;
3064 }
3065
3066 if (bufSize < 0)
3067 {
3068 ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize);
3069 return false;
3070 }
3071
3072 Program *programObject = GetValidProgram(context, program);
3073 if (!programObject)
3074 {
3075 return false;
3076 }
3077
3078 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
3079 {
3080 context->handleError(InvalidValue());
3081 return false;
3082 }
3083
3084 return true;
3085}
3086
3087bool ValidateBindTransformFeedback(Context *context, GLenum target, GLuint id)
3088{
3089 if (context->getClientMajorVersion() < 3)
3090 {
3091 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3092 return false;
3093 }
3094
3095 switch (target)
3096 {
3097 case GL_TRANSFORM_FEEDBACK:
3098 {
3099 // Cannot bind a transform feedback object if the current one is started and not
3100 // paused (3.0.2 pg 85 section 2.14.1)
3101 TransformFeedback *curTransformFeedback =
3102 context->getGLState().getCurrentTransformFeedback();
3103 if (curTransformFeedback && curTransformFeedback->isActive() &&
3104 !curTransformFeedback->isPaused())
3105 {
3106 context->handleError(InvalidOperation());
3107 return false;
3108 }
3109
3110 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section
3111 // 2.14.1)
3112 if (!context->isTransformFeedbackGenerated(id))
3113 {
3114 ANGLE_VALIDATION_ERR(context, InvalidOperation(), TransformFeedbackDoesNotExist);
3115 return false;
3116 }
3117 }
3118 break;
3119
3120 default:
3121 context->handleError(InvalidEnum());
3122 return false;
3123 }
3124
3125 return true;
3126}
3127
3128bool ValidateIsTransformFeedback(Context *context, GLuint id)
3129{
3130 if (context->getClientMajorVersion() < 3)
3131 {
3132 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3133 return false;
3134 }
3135
3136 return true;
3137}
3138
3139bool ValidatePauseTransformFeedback(Context *context)
3140{
3141 if (context->getClientMajorVersion() < 3)
3142 {
3143 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3144 return false;
3145 }
3146
3147 TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback();
3148 ASSERT(transformFeedback != nullptr);
3149
3150 // Current transform feedback must be active and not paused in order to pause (3.0.2 pg 86)
3151 if (!transformFeedback->isActive() || transformFeedback->isPaused())
3152 {
3153 context->handleError(InvalidOperation());
3154 return false;
3155 }
3156
3157 return true;
3158}
3159
3160bool ValidateResumeTransformFeedback(Context *context)
3161{
3162 if (context->getClientMajorVersion() < 3)
3163 {
3164 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3165 return false;
3166 }
3167
3168 TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback();
3169 ASSERT(transformFeedback != nullptr);
3170
3171 // Current transform feedback must be active and paused in order to resume (3.0.2 pg 86)
3172 if (!transformFeedback->isActive() || !transformFeedback->isPaused())
3173 {
3174 context->handleError(InvalidOperation());
3175 return false;
3176 }
3177
3178 return true;
3179}
3180
Jamie Madill12e957f2017-08-26 21:42:26 -04003181bool ValidateVertexAttribI4i(Context *context, GLuint index, GLint x, GLint y, GLint z, GLint w)
3182{
3183 if (context->getClientMajorVersion() < 3)
3184 {
3185 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3186 return false;
3187 }
3188
3189 return ValidateVertexAttribIndex(context, index);
3190}
3191
3192bool ValidateVertexAttribI4ui(Context *context,
3193 GLuint index,
3194 GLuint x,
3195 GLuint y,
3196 GLuint z,
3197 GLuint w)
3198{
3199 if (context->getClientMajorVersion() < 3)
3200 {
3201 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3202 return false;
3203 }
3204
3205 return ValidateVertexAttribIndex(context, index);
3206}
3207
3208bool ValidateVertexAttribI4iv(Context *context, GLuint index, const GLint *v)
3209{
3210 if (context->getClientMajorVersion() < 3)
3211 {
3212 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3213 return false;
3214 }
3215
3216 return ValidateVertexAttribIndex(context, index);
3217}
3218
3219bool ValidateVertexAttribI4uiv(Context *context, GLuint index, const GLuint *v)
3220{
3221 if (context->getClientMajorVersion() < 3)
3222 {
3223 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3224 return false;
3225 }
3226
3227 return ValidateVertexAttribIndex(context, index);
3228}
3229
3230bool ValidateGetFragDataLocation(Context *context, GLuint program, const GLchar *name)
3231{
3232 if (context->getClientMajorVersion() < 3)
3233 {
3234 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3235 return false;
3236 }
3237
3238 Program *programObject = GetValidProgram(context, program);
3239 if (!programObject)
3240 {
3241 return false;
3242 }
3243
3244 if (!programObject->isLinked())
3245 {
3246 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked);
3247 return false;
3248 }
3249
3250 return true;
3251}
3252
3253bool ValidateGetUniformIndices(Context *context,
3254 GLuint program,
3255 GLsizei uniformCount,
3256 const GLchar *const *uniformNames,
3257 GLuint *uniformIndices)
3258{
3259 if (context->getClientMajorVersion() < 3)
3260 {
3261 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3262 return false;
3263 }
3264
3265 if (uniformCount < 0)
3266 {
3267 context->handleError(InvalidValue());
3268 return false;
3269 }
3270
3271 Program *programObject = GetValidProgram(context, program);
3272 if (!programObject)
3273 {
3274 return false;
3275 }
3276
3277 return true;
3278}
3279
3280bool ValidateGetActiveUniformsiv(Context *context,
3281 GLuint program,
3282 GLsizei uniformCount,
3283 const GLuint *uniformIndices,
3284 GLenum pname,
3285 GLint *params)
3286{
3287 if (context->getClientMajorVersion() < 3)
3288 {
3289 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3290 return false;
3291 }
3292
3293 if (uniformCount < 0)
3294 {
3295 context->handleError(InvalidValue());
3296 return false;
3297 }
3298
3299 Program *programObject = GetValidProgram(context, program);
3300 if (!programObject)
3301 {
3302 return false;
3303 }
3304
3305 switch (pname)
3306 {
3307 case GL_UNIFORM_TYPE:
3308 case GL_UNIFORM_SIZE:
3309 case GL_UNIFORM_NAME_LENGTH:
3310 case GL_UNIFORM_BLOCK_INDEX:
3311 case GL_UNIFORM_OFFSET:
3312 case GL_UNIFORM_ARRAY_STRIDE:
3313 case GL_UNIFORM_MATRIX_STRIDE:
3314 case GL_UNIFORM_IS_ROW_MAJOR:
3315 break;
3316
3317 default:
3318 context->handleError(InvalidEnum());
3319 return false;
3320 }
3321
3322 if (uniformCount > programObject->getActiveUniformCount())
3323 {
3324 context->handleError(InvalidValue());
3325 return false;
3326 }
3327
3328 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
3329 {
3330 const GLuint index = uniformIndices[uniformId];
3331
3332 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
3333 {
3334 context->handleError(InvalidValue());
3335 return false;
3336 }
3337 }
3338
3339 return true;
3340}
3341
3342bool ValidateGetUniformBlockIndex(Context *context, GLuint program, const GLchar *uniformBlockName)
3343{
3344 if (context->getClientMajorVersion() < 3)
3345 {
3346 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3347 return false;
3348 }
3349
3350 Program *programObject = GetValidProgram(context, program);
3351 if (!programObject)
3352 {
3353 return false;
3354 }
3355
3356 return true;
3357}
3358
3359bool ValidateGetActiveUniformBlockiv(Context *context,
3360 GLuint program,
3361 GLuint uniformBlockIndex,
3362 GLenum pname,
3363 GLint *params)
3364{
3365 return ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, nullptr);
3366}
3367
3368bool ValidateGetActiveUniformBlockName(Context *context,
3369 GLuint program,
3370 GLuint uniformBlockIndex,
3371 GLsizei bufSize,
3372 GLsizei *length,
3373 GLchar *uniformBlockName)
3374{
3375 if (context->getClientMajorVersion() < 3)
3376 {
3377 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3378 return false;
3379 }
3380
3381 Program *programObject = GetValidProgram(context, program);
3382 if (!programObject)
3383 {
3384 return false;
3385 }
3386
3387 if (uniformBlockIndex >= programObject->getActiveUniformBlockCount())
3388 {
3389 context->handleError(InvalidValue());
3390 return false;
3391 }
3392
3393 return true;
3394}
3395
3396bool ValidateUniformBlockBinding(Context *context,
3397 GLuint program,
3398 GLuint uniformBlockIndex,
3399 GLuint uniformBlockBinding)
3400{
3401 if (context->getClientMajorVersion() < 3)
3402 {
3403 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3404 return false;
3405 }
3406
3407 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
3408 {
3409 context->handleError(InvalidValue());
3410 return false;
3411 }
3412
3413 Program *programObject = GetValidProgram(context, program);
3414 if (!programObject)
3415 {
3416 return false;
3417 }
3418
3419 // if never linked, there won't be any uniform blocks
3420 if (uniformBlockIndex >= programObject->getActiveUniformBlockCount())
3421 {
3422 context->handleError(InvalidValue());
3423 return false;
3424 }
3425
3426 return true;
3427}
3428
3429bool ValidateDrawArraysInstanced(Context *context,
3430 GLenum mode,
3431 GLint first,
3432 GLsizei count,
3433 GLsizei primcount)
3434{
3435 if (context->getClientMajorVersion() < 3)
3436 {
3437 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3438 return false;
3439 }
3440
3441 return ValidateDrawArraysInstancedBase(context, mode, first, count, primcount);
3442}
3443
Jamie Madill7f0c5a42017-08-26 22:43:26 -04003444bool ValidateFenceSync(Context *context, GLenum condition, GLbitfield flags)
3445{
3446 if (context->getClientMajorVersion() < 3)
3447 {
3448 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3449 return false;
3450 }
3451
3452 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
3453 {
3454 context->handleError(InvalidEnum());
3455 return false;
3456 }
3457
3458 if (flags != 0)
3459 {
3460 context->handleError(InvalidValue());
3461 return false;
3462 }
3463
3464 return true;
3465}
3466
3467bool ValidateIsSync(Context *context, GLsync sync)
3468{
3469 if (context->getClientMajorVersion() < 3)
3470 {
3471 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3472 return false;
3473 }
3474
3475 return true;
3476}
3477
3478bool ValidateDeleteSync(Context *context, GLsync sync)
3479{
3480 if (context->getClientMajorVersion() < 3)
3481 {
3482 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3483 return false;
3484 }
3485
Jamie Madill70b5bb02017-08-28 13:32:37 -04003486 if (sync != static_cast<GLsync>(0) && !context->getSync(sync))
Jamie Madill7f0c5a42017-08-26 22:43:26 -04003487 {
3488 context->handleError(InvalidValue());
3489 return false;
3490 }
3491
3492 return true;
3493}
3494
3495bool ValidateClientWaitSync(Context *context, GLsync sync, GLbitfield flags, GLuint64 timeout)
3496{
3497 if (context->getClientMajorVersion() < 3)
3498 {
3499 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3500 return false;
3501 }
3502
3503 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
3504 {
3505 context->handleError(InvalidValue());
3506 return false;
3507 }
3508
Jamie Madill70b5bb02017-08-28 13:32:37 -04003509 Sync *clientWaitSync = context->getSync(sync);
3510 if (!clientWaitSync)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04003511 {
3512 context->handleError(InvalidValue());
3513 return false;
3514 }
3515
3516 return true;
3517}
3518
3519bool ValidateWaitSync(Context *context, GLsync sync, GLbitfield flags, GLuint64 timeout)
3520{
3521 if (context->getClientMajorVersion() < 3)
3522 {
3523 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3524 return false;
3525 }
3526
3527 if (flags != 0)
3528 {
3529 context->handleError(InvalidValue());
3530 return false;
3531 }
3532
3533 if (timeout != GL_TIMEOUT_IGNORED)
3534 {
3535 context->handleError(InvalidValue());
3536 return false;
3537 }
3538
Jamie Madill70b5bb02017-08-28 13:32:37 -04003539 Sync *waitSync = context->getSync(sync);
3540 if (!waitSync)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04003541 {
3542 context->handleError(InvalidValue());
3543 return false;
3544 }
3545
3546 return true;
3547}
3548
3549bool ValidateGetInteger64v(Context *context, GLenum pname, GLint64 *params)
3550{
3551 if (context->getClientMajorVersion() < 3)
3552 {
3553 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3554 return false;
3555 }
3556
3557 GLenum nativeType = GL_NONE;
3558 unsigned int numParams = 0;
3559 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
3560 {
3561 return false;
3562 }
3563
3564 return true;
3565}
3566
Jamie Madill3ef140a2017-08-26 23:11:21 -04003567bool ValidateIsSampler(Context *context, GLuint sampler)
3568{
3569 if (context->getClientMajorVersion() < 3)
3570 {
Yunchao Hef0fd87d2017-09-12 04:55:05 +08003571 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
Jamie Madill3ef140a2017-08-26 23:11:21 -04003572 return false;
3573 }
3574
3575 return true;
3576}
3577
3578bool ValidateBindSampler(Context *context, GLuint unit, GLuint sampler)
3579{
3580 if (context->getClientMajorVersion() < 3)
3581 {
3582 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3583 return false;
3584 }
3585
3586 if (sampler != 0 && !context->isSampler(sampler))
3587 {
3588 context->handleError(InvalidOperation());
3589 return false;
3590 }
3591
3592 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
3593 {
3594 context->handleError(InvalidValue());
3595 return false;
3596 }
3597
3598 return true;
3599}
3600
3601bool ValidateVertexAttribDivisor(Context *context, GLuint index, GLuint divisor)
3602{
3603 if (context->getClientMajorVersion() < 3)
3604 {
3605 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3606 return false;
3607 }
3608
3609 return ValidateVertexAttribIndex(context, index);
3610}
3611
3612bool ValidateTexStorage2D(Context *context,
3613 GLenum target,
3614 GLsizei levels,
3615 GLenum internalformat,
3616 GLsizei width,
3617 GLsizei height)
3618{
3619 if (context->getClientMajorVersion() < 3)
3620 {
3621 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3622 return false;
3623 }
3624
3625 if (!ValidateES3TexStorage2DParameters(context, target, levels, internalformat, width, height,
3626 1))
3627 {
3628 return false;
3629 }
3630
3631 return true;
3632}
3633
3634bool ValidateTexStorage3D(Context *context,
3635 GLenum target,
3636 GLsizei levels,
3637 GLenum internalformat,
3638 GLsizei width,
3639 GLsizei height,
3640 GLsizei depth)
3641{
3642 if (context->getClientMajorVersion() < 3)
3643 {
3644 ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required);
3645 return false;
3646 }
3647
3648 if (!ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
3649 depth))
3650 {
3651 return false;
3652 }
3653
3654 return true;
3655}
3656
Jamie Madill9696d072017-08-26 23:19:57 -04003657bool ValidateGetBufferParameteri64v(ValidationContext *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003658 BufferBinding target,
Jamie Madill9696d072017-08-26 23:19:57 -04003659 GLenum pname,
3660 GLint64 *params)
3661{
3662 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
3663}
3664
3665bool ValidateGetSamplerParameterfv(Context *context, GLuint sampler, GLenum pname, GLfloat *params)
3666{
3667 return ValidateGetSamplerParameterBase(context, sampler, pname, nullptr);
3668}
3669
3670bool ValidateGetSamplerParameteriv(Context *context, GLuint sampler, GLenum pname, GLint *params)
3671{
3672 return ValidateGetSamplerParameterBase(context, sampler, pname, nullptr);
3673}
3674
3675bool ValidateSamplerParameterf(Context *context, GLuint sampler, GLenum pname, GLfloat param)
3676{
3677 return ValidateSamplerParameterBase(context, sampler, pname, -1, &param);
3678}
3679
3680bool ValidateSamplerParameterfv(Context *context,
3681 GLuint sampler,
3682 GLenum pname,
3683 const GLfloat *params)
3684{
3685 return ValidateSamplerParameterBase(context, sampler, pname, -1, params);
3686}
3687
3688bool ValidateSamplerParameteri(Context *context, GLuint sampler, GLenum pname, GLint param)
3689{
3690 return ValidateSamplerParameterBase(context, sampler, pname, -1, &param);
3691}
3692
3693bool ValidateSamplerParameteriv(Context *context, GLuint sampler, GLenum pname, const GLint *params)
3694{
3695 return ValidateSamplerParameterBase(context, sampler, pname, -1, params);
3696}
3697
3698bool ValidateGetVertexAttribIiv(Context *context, GLuint index, GLenum pname, GLint *params)
3699{
3700 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, true);
3701}
3702
3703bool ValidateGetVertexAttribIuiv(Context *context, GLuint index, GLenum pname, GLuint *params)
3704{
3705 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, true);
3706}
3707
3708bool ValidateGetInternalformativ(Context *context,
3709 GLenum target,
3710 GLenum internalformat,
3711 GLenum pname,
3712 GLsizei bufSize,
3713 GLint *params)
3714{
3715 return ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize,
3716 nullptr);
3717}
3718
Jamie Madillc29968b2016-01-20 11:17:23 -05003719} // namespace gl