blob: 19aa376dd1cc4a1bf36c0f81ae8f1ada57daf0aa [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// validationES2.cpp: Validation functions for OpenGL ES 2.0 entry point parameters
8
Jamie Madill778bf092018-11-14 09:54:36 -05009#include "libANGLE/validationES2_autogen.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030010
11#include <cstdint>
12
Geoff Lange8ebe7f2013-08-05 15:03:13 -040013#include "common/mathutil.h"
Sami Väisänen46eaa942016-06-29 10:26:37 +030014#include "common/string_utils.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040015#include "common/utilities.h"
Jamie Madillef300b12016-10-07 15:12:09 -040016#include "libANGLE/Context.h"
Brandon Jones6cad5662017-06-14 13:25:13 -070017#include "libANGLE/ErrorStrings.h"
Jamie Madill2b7bbc22017-12-21 17:30:38 -050018#include "libANGLE/Fence.h"
Jamie Madillef300b12016-10-07 15:12:09 -040019#include "libANGLE/Framebuffer.h"
20#include "libANGLE/FramebufferAttachment.h"
21#include "libANGLE/Renderbuffer.h"
22#include "libANGLE/Shader.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040023#include "libANGLE/Texture.h"
Jamie Madillef300b12016-10-07 15:12:09 -040024#include "libANGLE/Uniform.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040025#include "libANGLE/VertexArray.h"
Jamie Madillef300b12016-10-07 15:12:09 -040026#include "libANGLE/formatutils.h"
27#include "libANGLE/validationES.h"
Jamie Madill778bf092018-11-14 09:54:36 -050028#include "libANGLE/validationES2.h"
29#include "libANGLE/validationES3_autogen.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040030
31namespace gl
32{
Jamie Madille0472f32018-11-27 16:32:45 -050033using namespace err;
Geoff Lange8ebe7f2013-08-05 15:03:13 -040034
Jamie Madillc29968b2016-01-20 11:17:23 -050035namespace
36{
37
38bool IsPartialBlit(gl::Context *context,
39 const FramebufferAttachment *readBuffer,
40 const FramebufferAttachment *writeBuffer,
41 GLint srcX0,
42 GLint srcY0,
43 GLint srcX1,
44 GLint srcY1,
45 GLint dstX0,
46 GLint dstY0,
47 GLint dstX1,
48 GLint dstY1)
49{
50 const Extents &writeSize = writeBuffer->getSize();
51 const Extents &readSize = readBuffer->getSize();
52
53 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width ||
54 dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height)
55 {
56 return true;
57 }
58
Jamie Madillc3dc5d42018-12-30 12:12:04 -050059 if (context->getState().isScissorTestEnabled())
Jamie Madillc29968b2016-01-20 11:17:23 -050060 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -050061 const Rectangle &scissor = context->getState().getScissor();
Jamie Madillc29968b2016-01-20 11:17:23 -050062 return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width ||
63 scissor.height < writeSize.height;
64 }
65
66 return false;
67}
68
Sami Väisänend59ca052016-06-21 16:10:00 +030069template <typename T>
70bool ValidatePathInstances(gl::Context *context,
71 GLsizei numPaths,
72 const void *paths,
73 GLuint pathBase)
74{
75 const auto *array = static_cast<const T *>(paths);
76
77 for (GLsizei i = 0; i < numPaths; ++i)
78 {
79 const GLuint pathName = array[i] + pathBase;
Brandon Jones59770802018-04-02 13:18:42 -070080 if (context->isPathGenerated(pathName) && !context->isPath(pathName))
Sami Väisänend59ca052016-06-21 16:10:00 +030081 {
Jamie Madille0472f32018-11-27 16:32:45 -050082 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänend59ca052016-06-21 16:10:00 +030083 return false;
84 }
85 }
86 return true;
87}
88
89bool ValidateInstancedPathParameters(gl::Context *context,
90 GLsizei numPaths,
91 GLenum pathNameType,
92 const void *paths,
93 GLuint pathBase,
94 GLenum transformType,
95 const GLfloat *transformValues)
96{
97 if (!context->getExtensions().pathRendering)
98 {
Jamie Madillc3e37312018-11-30 15:25:39 -050099 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänend59ca052016-06-21 16:10:00 +0300100 return false;
101 }
102
103 if (paths == nullptr)
104 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500105 context->validationError(GL_INVALID_VALUE, kInvalidPathNameArray);
Sami Väisänend59ca052016-06-21 16:10:00 +0300106 return false;
107 }
108
109 if (numPaths < 0)
110 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500111 context->validationError(GL_INVALID_VALUE, kInvalidPathNumPaths);
Sami Väisänend59ca052016-06-21 16:10:00 +0300112 return false;
113 }
114
115 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths))
116 {
Jamie Madille0472f32018-11-27 16:32:45 -0500117 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänend59ca052016-06-21 16:10:00 +0300118 return false;
119 }
120
121 std::uint32_t pathNameTypeSize = 0;
122 std::uint32_t componentCount = 0;
123
124 switch (pathNameType)
125 {
126 case GL_UNSIGNED_BYTE:
127 pathNameTypeSize = sizeof(GLubyte);
128 if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase))
129 return false;
130 break;
131
132 case GL_BYTE:
133 pathNameTypeSize = sizeof(GLbyte);
134 if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase))
135 return false;
136 break;
137
138 case GL_UNSIGNED_SHORT:
139 pathNameTypeSize = sizeof(GLushort);
140 if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase))
141 return false;
142 break;
143
144 case GL_SHORT:
145 pathNameTypeSize = sizeof(GLshort);
146 if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase))
147 return false;
148 break;
149
150 case GL_UNSIGNED_INT:
151 pathNameTypeSize = sizeof(GLuint);
152 if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase))
153 return false;
154 break;
155
156 case GL_INT:
157 pathNameTypeSize = sizeof(GLint);
158 if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase))
159 return false;
160 break;
161
162 default:
Jamie Madillc3e37312018-11-30 15:25:39 -0500163 context->validationError(GL_INVALID_ENUM, kInvalidPathNameType);
Sami Väisänend59ca052016-06-21 16:10:00 +0300164 return false;
165 }
166
167 switch (transformType)
168 {
169 case GL_NONE:
170 componentCount = 0;
171 break;
172 case GL_TRANSLATE_X_CHROMIUM:
173 case GL_TRANSLATE_Y_CHROMIUM:
174 componentCount = 1;
175 break;
176 case GL_TRANSLATE_2D_CHROMIUM:
177 componentCount = 2;
178 break;
179 case GL_TRANSLATE_3D_CHROMIUM:
180 componentCount = 3;
181 break;
182 case GL_AFFINE_2D_CHROMIUM:
183 case GL_TRANSPOSE_AFFINE_2D_CHROMIUM:
184 componentCount = 6;
185 break;
186 case GL_AFFINE_3D_CHROMIUM:
187 case GL_TRANSPOSE_AFFINE_3D_CHROMIUM:
188 componentCount = 12;
189 break;
190 default:
Jamie Madillc3e37312018-11-30 15:25:39 -0500191 context->validationError(GL_INVALID_ENUM, kInvalidTransformation);
Sami Väisänend59ca052016-06-21 16:10:00 +0300192 return false;
193 }
194 if (componentCount != 0 && transformValues == nullptr)
195 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500196 context->validationError(GL_INVALID_VALUE, kNoTransformArray);
Sami Väisänend59ca052016-06-21 16:10:00 +0300197 return false;
198 }
199
200 angle::CheckedNumeric<std::uint32_t> checkedSize(0);
201 checkedSize += (numPaths * pathNameTypeSize);
202 checkedSize += (numPaths * sizeof(GLfloat) * componentCount);
203 if (!checkedSize.IsValid())
204 {
Jamie Madille0472f32018-11-27 16:32:45 -0500205 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänend59ca052016-06-21 16:10:00 +0300206 return false;
207 }
208
209 return true;
210}
211
Geoff Lang4f0e0032017-05-01 16:04:35 -0400212bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat)
Geoff Lang97073d12016-04-20 10:42:34 -0700213{
Geoff Lang4f0e0032017-05-01 16:04:35 -0400214 // Table 1.1 from the CHROMIUM_copy_texture spec
Geoff Langca271392017-04-05 12:30:00 -0400215 switch (GetUnsizedFormat(internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -0700216 {
Geoff Lang4f0e0032017-05-01 16:04:35 -0400217 case GL_RED:
Geoff Lang97073d12016-04-20 10:42:34 -0700218 case GL_ALPHA:
219 case GL_LUMINANCE:
220 case GL_LUMINANCE_ALPHA:
221 case GL_RGB:
222 case GL_RGBA:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400223 case GL_RGB8:
224 case GL_RGBA8:
225 case GL_BGRA_EXT:
226 case GL_BGRA8_EXT:
Geoff Lang97073d12016-04-20 10:42:34 -0700227 return true;
228
Geoff Lang4f0e0032017-05-01 16:04:35 -0400229 default:
230 return false;
231 }
232}
Geoff Lang97073d12016-04-20 10:42:34 -0700233
Geoff Lang4f0e0032017-05-01 16:04:35 -0400234bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat)
235{
236 return IsValidCopyTextureSourceInternalFormatEnum(internalFormat);
237}
238
Geoff Lang4f0e0032017-05-01 16:04:35 -0400239bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat)
240{
241 // Table 1.0 from the CHROMIUM_copy_texture spec
242 switch (internalFormat)
243 {
244 case GL_RGB:
245 case GL_RGBA:
246 case GL_RGB8:
247 case GL_RGBA8:
Geoff Lang97073d12016-04-20 10:42:34 -0700248 case GL_BGRA_EXT:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400249 case GL_BGRA8_EXT:
250 case GL_SRGB_EXT:
251 case GL_SRGB_ALPHA_EXT:
252 case GL_R8:
253 case GL_R8UI:
254 case GL_RG8:
255 case GL_RG8UI:
256 case GL_SRGB8:
257 case GL_RGB565:
258 case GL_RGB8UI:
Geoff Lang6be3d4c2017-06-16 15:54:15 -0400259 case GL_RGB10_A2:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400260 case GL_SRGB8_ALPHA8:
261 case GL_RGB5_A1:
262 case GL_RGBA4:
263 case GL_RGBA8UI:
264 case GL_RGB9_E5:
265 case GL_R16F:
266 case GL_R32F:
267 case GL_RG16F:
268 case GL_RG32F:
269 case GL_RGB16F:
270 case GL_RGB32F:
271 case GL_RGBA16F:
272 case GL_RGBA32F:
273 case GL_R11F_G11F_B10F:
Brandon Jones340b7b82017-06-26 13:02:31 -0700274 case GL_LUMINANCE:
275 case GL_LUMINANCE_ALPHA:
276 case GL_ALPHA:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400277 return true;
Geoff Lang97073d12016-04-20 10:42:34 -0700278
279 default:
280 return false;
281 }
282}
283
Geoff Lang6be3d4c2017-06-16 15:54:15 -0400284bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat)
285{
286 return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat);
287}
288
Geoff Lang97073d12016-04-20 10:42:34 -0700289bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type)
290{
Geoff Lang4f0e0032017-05-01 16:04:35 -0400291 if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -0700292 {
Jamie Madille0472f32018-11-27 16:32:45 -0500293 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400294 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700295 }
296
Geoff Langc0094ec2017-08-16 14:16:24 -0400297 if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat))
298 {
Jamie Madille0472f32018-11-27 16:32:45 -0500299 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Langc0094ec2017-08-16 14:16:24 -0400300 return false;
301 }
302
Geoff Lang4f0e0032017-05-01 16:04:35 -0400303 const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type);
304 if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Geoff Lang97073d12016-04-20 10:42:34 -0700305 {
Jamie Madille0472f32018-11-27 16:32:45 -0500306 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400307 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700308 }
309
310 return true;
311}
312
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800313bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target)
Geoff Lang97073d12016-04-20 10:42:34 -0700314{
315 switch (target)
316 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800317 case TextureTarget::_2D:
318 case TextureTarget::CubeMapNegativeX:
319 case TextureTarget::CubeMapNegativeY:
320 case TextureTarget::CubeMapNegativeZ:
321 case TextureTarget::CubeMapPositiveX:
322 case TextureTarget::CubeMapPositiveY:
323 case TextureTarget::CubeMapPositiveZ:
Geoff Lang63458a32017-10-30 15:16:53 -0400324 return true;
Geoff Lang97073d12016-04-20 10:42:34 -0700325
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 case TextureTarget::Rectangle:
Geoff Lang63458a32017-10-30 15:16:53 -0400327 return context->getExtensions().textureRectangle;
Geoff Lang97073d12016-04-20 10:42:34 -0700328
329 default:
330 return false;
331 }
332}
333
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334bool IsValidCopyTextureDestinationTarget(Context *context,
335 TextureType textureType,
336 TextureTarget target)
Geoff Lang63458a32017-10-30 15:16:53 -0400337{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800338 return TextureTargetToType(target) == textureType;
Geoff Lang63458a32017-10-30 15:16:53 -0400339}
340
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800341bool IsValidCopyTextureSourceTarget(Context *context, TextureType type)
Geoff Lang97073d12016-04-20 10:42:34 -0700342{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800343 switch (type)
Geoff Lang97073d12016-04-20 10:42:34 -0700344 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800345 case TextureType::_2D:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400346 return true;
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800347 case TextureType::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400348 return context->getExtensions().textureRectangle;
Geoff Langbe607ad2018-11-29 10:14:22 -0500349 case TextureType::External:
350 return context->getExtensions().eglImageExternal;
Geoff Lang4f0e0032017-05-01 16:04:35 -0400351 default:
352 return false;
353 }
354}
355
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800356bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400357{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 if (!ValidMipLevel(context, type, level))
Geoff Lang4f0e0032017-05-01 16:04:35 -0400359 {
360 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700361 }
362
Geoff Lang4f0e0032017-05-01 16:04:35 -0400363 if (level > 0 && context->getClientVersion() < ES_3_0)
364 {
365 return false;
366 }
Geoff Lang97073d12016-04-20 10:42:34 -0700367
Geoff Lang4f0e0032017-05-01 16:04:35 -0400368 return true;
369}
370
371bool IsValidCopyTextureDestinationLevel(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800372 TextureType type,
Geoff Lang4f0e0032017-05-01 16:04:35 -0400373 GLint level,
374 GLsizei width,
Brandon Jones28783792018-03-05 09:37:32 -0800375 GLsizei height,
376 bool isSubImage)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400377{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800378 if (!ValidMipLevel(context, type, level))
Geoff Lang4f0e0032017-05-01 16:04:35 -0400379 {
380 return false;
381 }
382
Brandon Jones28783792018-03-05 09:37:32 -0800383 if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage))
384 {
385 return false;
386 }
387
Geoff Lang4f0e0032017-05-01 16:04:35 -0400388 const Caps &caps = context->getCaps();
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800389 switch (type)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400390 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 case TextureType::_2D:
392 return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) &&
393 static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level);
394 case TextureType::Rectangle:
395 ASSERT(level == 0);
396 return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) &&
397 static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400398
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800399 case TextureType::CubeMap:
400 return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) &&
401 static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level);
402 default:
403 return true;
404 }
Geoff Lang97073d12016-04-20 10:42:34 -0700405}
406
Jamie Madillc1d770e2017-04-13 17:31:24 -0400407bool IsValidStencilFunc(GLenum func)
408{
409 switch (func)
410 {
411 case GL_NEVER:
412 case GL_ALWAYS:
413 case GL_LESS:
414 case GL_LEQUAL:
415 case GL_EQUAL:
416 case GL_GEQUAL:
417 case GL_GREATER:
418 case GL_NOTEQUAL:
419 return true;
420
421 default:
422 return false;
423 }
424}
425
426bool IsValidStencilFace(GLenum face)
427{
428 switch (face)
429 {
430 case GL_FRONT:
431 case GL_BACK:
432 case GL_FRONT_AND_BACK:
433 return true;
434
435 default:
436 return false;
437 }
438}
439
440bool IsValidStencilOp(GLenum op)
441{
442 switch (op)
443 {
444 case GL_ZERO:
445 case GL_KEEP:
446 case GL_REPLACE:
447 case GL_INCR:
448 case GL_DECR:
449 case GL_INVERT:
450 case GL_INCR_WRAP:
451 case GL_DECR_WRAP:
452 return true;
453
454 default:
455 return false;
456 }
457}
458
Jamie Madill5b772312018-03-08 20:28:32 -0500459bool ValidateES2CopyTexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800460 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -0400461 GLint level,
462 GLenum internalformat,
463 bool isSubImage,
464 GLint xoffset,
465 GLint yoffset,
466 GLint x,
467 GLint y,
468 GLsizei width,
469 GLsizei height,
470 GLint border)
471{
472 if (!ValidTexture2DDestinationTarget(context, target))
473 {
Jamie Madille0472f32018-11-27 16:32:45 -0500474 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -0400475 return false;
476 }
477
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800478 TextureType texType = TextureTargetToType(target);
479 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Jamie Madillbe849e42017-05-02 15:49:00 -0400480 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500481 // Error is already handled.
Jamie Madillbe849e42017-05-02 15:49:00 -0400482 return false;
483 }
484
485 Format textureFormat = Format::Invalid();
486 if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
487 xoffset, yoffset, 0, x, y, width, height, border,
488 &textureFormat))
489 {
490 return false;
491 }
492
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500493 const gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madillbe849e42017-05-02 15:49:00 -0400494 GLenum colorbufferFormat =
Jamie Madill4e71b2b2019-07-08 13:23:38 -0400495 framebuffer->getReadColorAttachment()->getFormat().info->sizedInternalFormat;
Jamie Madillbe849e42017-05-02 15:49:00 -0400496 const auto &formatInfo = *textureFormat.info;
497
498 // [OpenGL ES 2.0.24] table 3.9
499 if (isSubImage)
500 {
501 switch (formatInfo.format)
502 {
503 case GL_ALPHA:
504 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400505 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
506 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400507 {
Jamie Madille0472f32018-11-27 16:32:45 -0500508 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400509 return false;
510 }
511 break;
512 case GL_LUMINANCE:
513 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
514 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
515 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400516 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT &&
517 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400518 {
Jamie Madille0472f32018-11-27 16:32:45 -0500519 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400520 return false;
521 }
522 break;
523 case GL_RED_EXT:
524 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
525 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
526 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
527 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F &&
528 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400529 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
530 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400531 {
Jamie Madille0472f32018-11-27 16:32:45 -0500532 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400533 return false;
534 }
535 break;
536 case GL_RG_EXT:
537 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
538 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
539 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
540 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400541 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
542 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400543 {
Jamie Madille0472f32018-11-27 16:32:45 -0500544 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400545 return false;
546 }
547 break;
548 case GL_RGB:
549 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
550 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
551 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400552 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
553 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400554 {
Jamie Madille0472f32018-11-27 16:32:45 -0500555 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400556 return false;
557 }
558 break;
559 case GL_LUMINANCE_ALPHA:
560 case GL_RGBA:
561 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400562 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F &&
563 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400564 {
Jamie Madille0472f32018-11-27 16:32:45 -0500565 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400566 return false;
567 }
568 break;
569 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
570 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
571 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
572 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
573 case GL_ETC1_RGB8_OES:
574 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
575 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
576 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
577 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
578 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
Olli Etuahof2ed2992018-10-04 13:54:42 +0300579 case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT:
580 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:
581 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT:
582 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT:
Jamie Madille0472f32018-11-27 16:32:45 -0500583 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400584 return false;
585 case GL_DEPTH_COMPONENT:
586 case GL_DEPTH_STENCIL_OES:
Jamie Madille0472f32018-11-27 16:32:45 -0500587 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400588 return false;
589 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500590 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400591 return false;
592 }
593
594 if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat)
595 {
Jamie Madille0472f32018-11-27 16:32:45 -0500596 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400597 return false;
598 }
599 }
600 else
601 {
602 switch (internalformat)
603 {
604 case GL_ALPHA:
605 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
606 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
607 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
608 {
Jamie Madille0472f32018-11-27 16:32:45 -0500609 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400610 return false;
611 }
612 break;
613 case GL_LUMINANCE:
614 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
615 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
616 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
617 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
618 colorbufferFormat != GL_BGR5_A1_ANGLEX)
619 {
Jamie Madille0472f32018-11-27 16:32:45 -0500620 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400621 return false;
622 }
623 break;
624 case GL_RED_EXT:
625 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
626 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
627 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
628 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
629 colorbufferFormat != GL_BGR5_A1_ANGLEX)
630 {
Jamie Madille0472f32018-11-27 16:32:45 -0500631 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400632 return false;
633 }
634 break;
635 case GL_RG_EXT:
636 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
637 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
638 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
639 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
640 {
Jamie Madille0472f32018-11-27 16:32:45 -0500641 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400642 return false;
643 }
644 break;
645 case GL_RGB:
646 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
647 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
648 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
649 colorbufferFormat != GL_BGR5_A1_ANGLEX)
650 {
Jamie Madille0472f32018-11-27 16:32:45 -0500651 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400652 return false;
653 }
654 break;
655 case GL_LUMINANCE_ALPHA:
656 case GL_RGBA:
657 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
658 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
659 colorbufferFormat != GL_BGR5_A1_ANGLEX)
660 {
Jamie Madille0472f32018-11-27 16:32:45 -0500661 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400662 return false;
663 }
664 break;
665 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
666 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
667 if (context->getExtensions().textureCompressionDXT1)
668 {
Jamie Madille0472f32018-11-27 16:32:45 -0500669 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400670 return false;
671 }
672 else
673 {
Jamie Madille0472f32018-11-27 16:32:45 -0500674 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400675 return false;
676 }
677 break;
678 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
679 if (context->getExtensions().textureCompressionDXT3)
680 {
Jamie Madille0472f32018-11-27 16:32:45 -0500681 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400682 return false;
683 }
684 else
685 {
Jamie Madille0472f32018-11-27 16:32:45 -0500686 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400687 return false;
688 }
689 break;
690 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
691 if (context->getExtensions().textureCompressionDXT5)
692 {
Jamie Madille0472f32018-11-27 16:32:45 -0500693 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400694 return false;
695 }
696 else
697 {
Jamie Madille0472f32018-11-27 16:32:45 -0500698 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400699 return false;
700 }
701 break;
702 case GL_ETC1_RGB8_OES:
703 if (context->getExtensions().compressedETC1RGB8Texture)
704 {
Jamie Madille0472f32018-11-27 16:32:45 -0500705 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400706 return false;
707 }
708 else
709 {
Jamie Madille0472f32018-11-27 16:32:45 -0500710 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400711 return false;
712 }
713 break;
714 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
715 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
716 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
717 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
718 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
719 if (context->getExtensions().lossyETCDecode)
720 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500721 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400722 return false;
723 }
724 else
725 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500726 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400727 return false;
728 }
729 break;
730 case GL_DEPTH_COMPONENT:
731 case GL_DEPTH_COMPONENT16:
732 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600733 if (context->getExtensions().depthTextureAny())
Jamie Madillbe849e42017-05-02 15:49:00 -0400734 {
Jamie Madille0472f32018-11-27 16:32:45 -0500735 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400736 return false;
737 }
738 else
739 {
Jamie Madille0472f32018-11-27 16:32:45 -0500740 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400741 return false;
742 }
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600743 break;
744 case GL_DEPTH_STENCIL_OES:
745 case GL_DEPTH24_STENCIL8_OES:
746 if (context->getExtensions().depthTextureAny() ||
747 context->getExtensions().packedDepthStencil)
748 {
749 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
750 return false;
751 }
752 else
753 {
754 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
755 return false;
756 }
757 break;
Jamie Madillbe849e42017-05-02 15:49:00 -0400758 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500759 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400760 return false;
761 }
762 }
763
764 // If width or height is zero, it is a no-op. Return false without setting an error.
765 return (width > 0 && height > 0);
766}
767
768bool ValidCap(const Context *context, GLenum cap, bool queryOnly)
769{
770 switch (cap)
771 {
772 // EXT_multisample_compatibility
773 case GL_MULTISAMPLE_EXT:
774 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
775 return context->getExtensions().multisampleCompatibility;
776
777 case GL_CULL_FACE:
778 case GL_POLYGON_OFFSET_FILL:
779 case GL_SAMPLE_ALPHA_TO_COVERAGE:
780 case GL_SAMPLE_COVERAGE:
781 case GL_SCISSOR_TEST:
782 case GL_STENCIL_TEST:
783 case GL_DEPTH_TEST:
784 case GL_BLEND:
785 case GL_DITHER:
786 return true;
787
788 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
789 case GL_RASTERIZER_DISCARD:
790 return (context->getClientMajorVersion() >= 3);
791
792 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
793 case GL_DEBUG_OUTPUT:
794 return context->getExtensions().debug;
795
796 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
797 return queryOnly && context->getExtensions().bindGeneratesResource;
798
799 case GL_CLIENT_ARRAYS_ANGLE:
800 return queryOnly && context->getExtensions().clientArrays;
801
802 case GL_FRAMEBUFFER_SRGB_EXT:
803 return context->getExtensions().sRGBWriteControl;
804
805 case GL_SAMPLE_MASK:
806 return context->getClientVersion() >= Version(3, 1);
807
Geoff Langb433e872017-10-05 14:01:47 -0400808 case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
Jamie Madillbe849e42017-05-02 15:49:00 -0400809 return queryOnly && context->getExtensions().robustResourceInitialization;
810
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700811 // GLES1 emulation: GLES1-specific caps
812 case GL_ALPHA_TEST:
Lingfeng Yang01074432018-04-16 10:19:51 -0700813 case GL_VERTEX_ARRAY:
814 case GL_NORMAL_ARRAY:
815 case GL_COLOR_ARRAY:
816 case GL_TEXTURE_COORD_ARRAY:
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700817 case GL_TEXTURE_2D:
Lingfeng Yangd0febe72018-05-17 22:36:52 -0700818 case GL_LIGHTING:
819 case GL_LIGHT0:
820 case GL_LIGHT1:
821 case GL_LIGHT2:
822 case GL_LIGHT3:
823 case GL_LIGHT4:
824 case GL_LIGHT5:
825 case GL_LIGHT6:
826 case GL_LIGHT7:
827 case GL_NORMALIZE:
828 case GL_RESCALE_NORMAL:
829 case GL_COLOR_MATERIAL:
Lingfeng Yang060088a2018-05-30 20:40:57 -0700830 case GL_CLIP_PLANE0:
831 case GL_CLIP_PLANE1:
832 case GL_CLIP_PLANE2:
833 case GL_CLIP_PLANE3:
834 case GL_CLIP_PLANE4:
835 case GL_CLIP_PLANE5:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -0700836 case GL_FOG:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700837 case GL_POINT_SMOOTH:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -0700838 case GL_LINE_SMOOTH:
839 case GL_COLOR_LOGIC_OP:
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700840 return context->getClientVersion() < Version(2, 0);
Lingfeng Yang01074432018-04-16 10:19:51 -0700841 case GL_POINT_SIZE_ARRAY_OES:
842 return context->getClientVersion() < Version(2, 0) &&
843 context->getExtensions().pointSizeArray;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700844 case GL_TEXTURE_CUBE_MAP:
845 return context->getClientVersion() < Version(2, 0) &&
846 context->getExtensions().textureCubeMap;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700847 case GL_POINT_SPRITE_OES:
848 return context->getClientVersion() < Version(2, 0) &&
849 context->getExtensions().pointSprite;
Jamie Madillbe849e42017-05-02 15:49:00 -0400850 default:
851 return false;
852 }
853}
854
Geoff Langfc32e8b2017-05-31 14:16:59 -0400855// Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section
856// 3.1.
Geoff Langcab92ee2017-07-19 17:32:07 -0400857bool IsValidESSLCharacter(unsigned char c)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400858{
859 // Printing characters are valid except " $ ` @ \ ' DEL.
Geoff Langcab92ee2017-07-19 17:32:07 -0400860 if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' &&
861 c != '\'')
Geoff Langfc32e8b2017-05-31 14:16:59 -0400862 {
863 return true;
864 }
865
866 // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid.
867 if (c >= 9 && c <= 13)
868 {
869 return true;
870 }
871
872 return false;
873}
874
Geoff Langcab92ee2017-07-19 17:32:07 -0400875bool IsValidESSLString(const char *str, size_t len)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400876{
Geoff Langa71a98e2017-06-19 15:15:00 -0400877 for (size_t i = 0; i < len; i++)
878 {
Geoff Langcab92ee2017-07-19 17:32:07 -0400879 if (!IsValidESSLCharacter(str[i]))
Geoff Langa71a98e2017-06-19 15:15:00 -0400880 {
881 return false;
882 }
883 }
884
885 return true;
Geoff Langfc32e8b2017-05-31 14:16:59 -0400886}
887
Geoff Langcab92ee2017-07-19 17:32:07 -0400888bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed)
889{
890 enum class ParseState
891 {
892 // Have not seen an ASCII non-whitespace character yet on
893 // this line. Possible that we might see a preprocessor
894 // directive.
895 BEGINING_OF_LINE,
896
897 // Have seen at least one ASCII non-whitespace character
898 // on this line.
899 MIDDLE_OF_LINE,
900
901 // Handling a preprocessor directive. Passes through all
902 // characters up to the end of the line. Disables comment
903 // processing.
904 IN_PREPROCESSOR_DIRECTIVE,
905
906 // Handling a single-line comment. The comment text is
907 // replaced with a single space.
908 IN_SINGLE_LINE_COMMENT,
909
910 // Handling a multi-line comment. Newlines are passed
911 // through to preserve line numbers.
912 IN_MULTI_LINE_COMMENT
913 };
914
915 ParseState state = ParseState::BEGINING_OF_LINE;
916 size_t pos = 0;
917
918 while (pos < len)
919 {
920 char c = str[pos];
921 char next = pos + 1 < len ? str[pos + 1] : 0;
922
923 // Check for newlines
924 if (c == '\n' || c == '\r')
925 {
926 if (state != ParseState::IN_MULTI_LINE_COMMENT)
927 {
928 state = ParseState::BEGINING_OF_LINE;
929 }
930
931 pos++;
932 continue;
933 }
934
935 switch (state)
936 {
937 case ParseState::BEGINING_OF_LINE:
938 if (c == ' ')
939 {
940 // Maintain the BEGINING_OF_LINE state until a non-space is seen
941 pos++;
942 }
943 else if (c == '#')
944 {
945 state = ParseState::IN_PREPROCESSOR_DIRECTIVE;
946 pos++;
947 }
948 else
949 {
950 // Don't advance, re-process this character with the MIDDLE_OF_LINE state
951 state = ParseState::MIDDLE_OF_LINE;
952 }
953 break;
954
955 case ParseState::MIDDLE_OF_LINE:
956 if (c == '/' && next == '/')
957 {
958 state = ParseState::IN_SINGLE_LINE_COMMENT;
959 pos++;
960 }
961 else if (c == '/' && next == '*')
962 {
963 state = ParseState::IN_MULTI_LINE_COMMENT;
964 pos++;
965 }
966 else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r'))
967 {
968 // Skip line continuation characters
969 }
970 else if (!IsValidESSLCharacter(c))
971 {
972 return false;
973 }
974 pos++;
975 break;
976
977 case ParseState::IN_PREPROCESSOR_DIRECTIVE:
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -0700978 // Line-continuation characters may not be permitted.
979 // Otherwise, just pass it through. Do not parse comments in this state.
980 if (!lineContinuationAllowed && c == '\\')
981 {
982 return false;
983 }
Geoff Langcab92ee2017-07-19 17:32:07 -0400984 pos++;
985 break;
986
987 case ParseState::IN_SINGLE_LINE_COMMENT:
988 // Line-continuation characters are processed before comment processing.
989 // Advance string if a new line character is immediately behind
990 // line-continuation character.
991 if (c == '\\' && (next == '\n' || next == '\r'))
992 {
993 pos++;
994 }
995 pos++;
996 break;
997
998 case ParseState::IN_MULTI_LINE_COMMENT:
999 if (c == '*' && next == '/')
1000 {
1001 state = ParseState::MIDDLE_OF_LINE;
1002 pos++;
1003 }
1004 pos++;
1005 break;
1006 }
1007 }
1008
1009 return true;
1010}
1011
Jamie Madill5b772312018-03-08 20:28:32 -05001012bool ValidateWebGLNamePrefix(Context *context, const GLchar *name)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001013{
1014 ASSERT(context->isWebGL());
1015
1016 // WebGL 1.0 [Section 6.16] GLSL Constructs
1017 // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL.
1018 if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0)
1019 {
Jamie Madille0472f32018-11-27 16:32:45 -05001020 context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001021 return false;
1022 }
1023
1024 return true;
1025}
1026
Jamie Madill5b772312018-03-08 20:28:32 -05001027bool ValidateWebGLNameLength(Context *context, size_t length)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001028{
1029 ASSERT(context->isWebGL());
1030
1031 if (context->isWebGL1() && length > 256)
1032 {
1033 // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths
1034 // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute
1035 // locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001036 context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001037
1038 return false;
1039 }
1040 else if (length > 1024)
1041 {
1042 // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of
1043 // uniform and attribute locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001044 context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001045 return false;
1046 }
1047
1048 return true;
1049}
1050
Jamie Madill007530e2017-12-28 14:27:04 -05001051bool ValidateMatrixMode(Context *context, GLenum matrixMode)
1052{
1053 if (!context->getExtensions().pathRendering)
1054 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001055 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05001056 return false;
1057 }
1058
1059 if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM)
1060 {
Jamie Madille0472f32018-11-27 16:32:45 -05001061 context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode);
Jamie Madill007530e2017-12-28 14:27:04 -05001062 return false;
1063 }
1064 return true;
1065}
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001066
1067bool ValidBlendFunc(const Context *context, GLenum val)
1068{
1069 const gl::Extensions &ext = context->getExtensions();
1070
1071 // these are always valid for src and dst.
1072 switch (val)
1073 {
1074 case GL_ZERO:
1075 case GL_ONE:
1076 case GL_SRC_COLOR:
1077 case GL_ONE_MINUS_SRC_COLOR:
1078 case GL_DST_COLOR:
1079 case GL_ONE_MINUS_DST_COLOR:
1080 case GL_SRC_ALPHA:
1081 case GL_ONE_MINUS_SRC_ALPHA:
1082 case GL_DST_ALPHA:
1083 case GL_ONE_MINUS_DST_ALPHA:
1084 case GL_CONSTANT_COLOR:
1085 case GL_ONE_MINUS_CONSTANT_COLOR:
1086 case GL_CONSTANT_ALPHA:
1087 case GL_ONE_MINUS_CONSTANT_ALPHA:
1088 return true;
1089
1090 // EXT_blend_func_extended.
1091 case GL_SRC1_COLOR_EXT:
1092 case GL_SRC1_ALPHA_EXT:
1093 case GL_ONE_MINUS_SRC1_COLOR_EXT:
1094 case GL_ONE_MINUS_SRC1_ALPHA_EXT:
1095 case GL_SRC_ALPHA_SATURATE_EXT:
1096 return ext.blendFuncExtended;
1097
1098 default:
1099 return false;
1100 }
1101}
1102
1103bool ValidSrcBlendFunc(const Context *context, GLenum val)
1104{
1105 if (ValidBlendFunc(context, val))
1106 return true;
1107
1108 if (val == GL_SRC_ALPHA_SATURATE)
1109 return true;
1110
1111 return false;
1112}
1113
1114bool ValidDstBlendFunc(const Context *context, GLenum val)
1115{
1116 if (ValidBlendFunc(context, val))
1117 return true;
1118
1119 if (val == GL_SRC_ALPHA_SATURATE)
1120 {
1121 if (context->getClientMajorVersion() >= 3)
1122 return true;
1123 }
1124
1125 return false;
1126}
Michael Spangab6a59b2019-05-21 21:26:26 -04001127
1128bool IsValidImageLayout(ImageLayout layout)
1129{
1130 switch (layout)
1131 {
Michael Spang6c824a12019-06-18 15:43:33 -04001132 case ImageLayout::Undefined:
Michael Spangab6a59b2019-05-21 21:26:26 -04001133 case ImageLayout::General:
1134 case ImageLayout::ColorAttachment:
1135 case ImageLayout::DepthStencilAttachment:
1136 case ImageLayout::DepthStencilReadOnlyAttachment:
1137 case ImageLayout::ShaderReadOnly:
1138 case ImageLayout::TransferSrc:
1139 case ImageLayout::TransferDst:
1140 case ImageLayout::DepthReadOnlyStencilAttachment:
1141 case ImageLayout::DepthAttachmentStencilReadOnly:
1142 return true;
1143
1144 default:
1145 return false;
1146 }
1147}
1148
Geoff Langff5b2d52016-09-07 11:32:23 -04001149bool ValidateES2TexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001150 TextureTarget target,
Geoff Langff5b2d52016-09-07 11:32:23 -04001151 GLint level,
1152 GLenum internalformat,
1153 bool isCompressed,
1154 bool isSubImage,
1155 GLint xoffset,
1156 GLint yoffset,
1157 GLsizei width,
1158 GLsizei height,
1159 GLint border,
1160 GLenum format,
1161 GLenum type,
1162 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001163 const void *pixels)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001164{
Jamie Madill6f38f822014-06-06 17:12:20 -04001165 if (!ValidTexture2DDestinationTarget(context, target))
1166 {
Jamie Madille0472f32018-11-27 16:32:45 -05001167 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001168 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001169 }
1170
Geoff Lang857880e2019-05-27 13:39:15 -04001171 return ValidateES2TexImageParametersBase(context, target, level, internalformat, isCompressed,
1172 isSubImage, xoffset, yoffset, width, height, border,
1173 format, type, imageSize, pixels);
1174}
1175
1176} // anonymous namespace
1177
1178bool ValidateES2TexImageParametersBase(Context *context,
1179 TextureTarget target,
1180 GLint level,
1181 GLenum internalformat,
1182 bool isCompressed,
1183 bool isSubImage,
1184 GLint xoffset,
1185 GLint yoffset,
1186 GLsizei width,
1187 GLsizei height,
1188 GLint border,
1189 GLenum format,
1190 GLenum type,
1191 GLsizei imageSize,
1192 const void *pixels)
1193{
1194
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001195 TextureType texType = TextureTargetToType(target);
1196 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001197 {
Jamie Madill610640f2018-11-21 17:28:41 -05001198 // Error already handled.
Geoff Langb1196682014-07-23 13:47:29 -04001199 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001200 }
1201
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001202 if (!ValidMipLevel(context, texType, level))
Brandon Jones6cad5662017-06-14 13:25:13 -07001203 {
Jamie Madille0472f32018-11-27 16:32:45 -05001204 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Brandon Jones6cad5662017-06-14 13:25:13 -07001205 return false;
1206 }
1207
1208 if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width ||
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001209 std::numeric_limits<GLsizei>::max() - yoffset < height)
1210 {
Jamie Madille0472f32018-11-27 16:32:45 -05001211 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Geoff Langb1196682014-07-23 13:47:29 -04001212 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001213 }
1214
Geoff Langaae65a42014-05-26 12:43:44 -04001215 const gl::Caps &caps = context->getCaps();
1216
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001217 switch (texType)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001218 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001219 case TextureType::_2D:
Geoff Lang857880e2019-05-27 13:39:15 -04001220 case TextureType::External:
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001221 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
1222 static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
1223 {
Jamie Madille0472f32018-11-27 16:32:45 -05001224 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001225 return false;
1226 }
1227 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001228
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001229 case TextureType::Rectangle:
1230 ASSERT(level == 0);
1231 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1232 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1233 {
Jamie Madille0472f32018-11-27 16:32:45 -05001234 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001235 return false;
1236 }
1237 if (isCompressed)
1238 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001239 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001240 return false;
1241 }
1242 break;
1243
1244 case TextureType::CubeMap:
1245 if (!isSubImage && width != height)
1246 {
Jamie Madille0472f32018-11-27 16:32:45 -05001247 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001248 return false;
1249 }
1250
1251 if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) ||
1252 static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level))
1253 {
Jamie Madille0472f32018-11-27 16:32:45 -05001254 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001255 return false;
1256 }
1257 break;
1258
1259 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001260 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langa9be0dc2014-12-17 12:34:40 -05001261 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001262 }
1263
Jamie Madillcfc73cc2019-04-08 16:26:51 -04001264 gl::Texture *texture = context->getTextureByType(texType);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001265 if (!texture)
1266 {
Jamie Madille0472f32018-11-27 16:32:45 -05001267 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Geoff Langb1196682014-07-23 13:47:29 -04001268 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001269 }
1270
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001271 // Verify zero border
1272 if (border != 0)
1273 {
Jamie Madille0472f32018-11-27 16:32:45 -05001274 context->validationError(GL_INVALID_VALUE, kInvalidBorder);
Geoff Langb1196682014-07-23 13:47:29 -04001275 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001276 }
1277
Tim Van Patten208af3e2019-03-19 09:15:55 -06001278 bool nonEqualFormatsAllowed = false;
1279
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001280 if (isCompressed)
1281 {
tmartino0ccd5ae2015-10-01 14:33:14 -04001282 GLenum actualInternalFormat =
Geoff Langca271392017-04-05 12:30:00 -04001283 isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat
1284 : internalformat;
Geoff Lange88e4542018-05-03 15:05:57 -04001285
1286 const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat);
1287
1288 if (!internalFormatInfo.compressed)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001289 {
Jamie Madille0472f32018-11-27 16:32:45 -05001290 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001291 return false;
1292 }
1293
1294 if (!internalFormatInfo.textureSupport(context->getClientVersion(),
1295 context->getExtensions()))
1296 {
Jamie Madille0472f32018-11-27 16:32:45 -05001297 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001298 return false;
tmartino0ccd5ae2015-10-01 14:33:14 -04001299 }
Geoff Lang966c9402017-04-18 12:38:27 -04001300
1301 if (isSubImage)
tmartino0ccd5ae2015-10-01 14:33:14 -04001302 {
Geoff Lange88e4542018-05-03 15:05:57 -04001303 // From the OES_compressed_ETC1_RGB8_texture spec:
1304 // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or
1305 // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format
1306 // ETC1_RGB8_OES.
1307 if (actualInternalFormat == GL_ETC1_RGB8_OES)
1308 {
Jamie Madille0472f32018-11-27 16:32:45 -05001309 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001310 return false;
1311 }
1312
Geoff Langd9c17102019-07-10 14:56:26 -04001313 if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, 0,
1314 width, height, 1, texture->getWidth(target, level),
1315 texture->getHeight(target, level),
1316 texture->getDepth(target, level)))
Geoff Lang966c9402017-04-18 12:38:27 -04001317 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001318 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001319 return false;
1320 }
1321
1322 if (format != actualInternalFormat)
1323 {
Jamie Madille0472f32018-11-27 16:32:45 -05001324 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Geoff Lang966c9402017-04-18 12:38:27 -04001325 return false;
1326 }
1327 }
1328 else
1329 {
Geoff Langd9c17102019-07-10 14:56:26 -04001330 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height, 1))
Geoff Lang966c9402017-04-18 12:38:27 -04001331 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001332 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001333 return false;
1334 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001335 }
1336 }
1337 else
1338 {
1339 // validate <type> by itself (used as secondary key below)
1340 switch (type)
1341 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001342 case GL_UNSIGNED_BYTE:
1343 case GL_UNSIGNED_SHORT_5_6_5:
1344 case GL_UNSIGNED_SHORT_4_4_4_4:
1345 case GL_UNSIGNED_SHORT_5_5_5_1:
1346 case GL_UNSIGNED_SHORT:
1347 case GL_UNSIGNED_INT:
1348 case GL_UNSIGNED_INT_24_8_OES:
1349 case GL_HALF_FLOAT_OES:
1350 case GL_FLOAT:
1351 break;
1352 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001353 context->validationError(GL_INVALID_ENUM, kInvalidType);
He Yunchaoced53ae2016-11-29 15:00:51 +08001354 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001355 }
1356
1357 // validate <format> + <type> combinations
1358 // - invalid <format> -> sets INVALID_ENUM
1359 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
1360 switch (format)
1361 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001362 case GL_ALPHA:
1363 case GL_LUMINANCE:
1364 case GL_LUMINANCE_ALPHA:
1365 switch (type)
1366 {
1367 case GL_UNSIGNED_BYTE:
1368 case GL_FLOAT:
1369 case GL_HALF_FLOAT_OES:
1370 break;
1371 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001372 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001373 return false;
1374 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001375 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001376 case GL_RED:
1377 case GL_RG:
1378 if (!context->getExtensions().textureRG)
1379 {
Jamie Madille0472f32018-11-27 16:32:45 -05001380 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001381 return false;
1382 }
1383 switch (type)
1384 {
1385 case GL_UNSIGNED_BYTE:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001386 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001387 case GL_FLOAT:
1388 case GL_HALF_FLOAT_OES:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001389 if (!context->getExtensions().textureFloat)
1390 {
Jamie Madille0472f32018-11-27 16:32:45 -05001391 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001392 return false;
1393 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001394 break;
1395 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001396 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001397 return false;
1398 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001399 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001400 case GL_RGB:
1401 switch (type)
1402 {
1403 case GL_UNSIGNED_BYTE:
1404 case GL_UNSIGNED_SHORT_5_6_5:
1405 case GL_FLOAT:
1406 case GL_HALF_FLOAT_OES:
1407 break;
1408 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001409 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001410 return false;
1411 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001412 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001413 case GL_RGBA:
1414 switch (type)
1415 {
1416 case GL_UNSIGNED_BYTE:
1417 case GL_UNSIGNED_SHORT_4_4_4_4:
1418 case GL_UNSIGNED_SHORT_5_5_5_1:
1419 case GL_FLOAT:
1420 case GL_HALF_FLOAT_OES:
1421 break;
1422 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001423 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001424 return false;
1425 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001426 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001427 case GL_BGRA_EXT:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001428 if (!context->getExtensions().textureFormatBGRA8888)
1429 {
Jamie Madille0472f32018-11-27 16:32:45 -05001430 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001431 return false;
1432 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001433 switch (type)
1434 {
1435 case GL_UNSIGNED_BYTE:
1436 break;
1437 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001438 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001439 return false;
1440 }
1441 break;
1442 case GL_SRGB_EXT:
1443 case GL_SRGB_ALPHA_EXT:
1444 if (!context->getExtensions().sRGB)
1445 {
Jamie Madille0472f32018-11-27 16:32:45 -05001446 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001447 return false;
1448 }
1449 switch (type)
1450 {
1451 case GL_UNSIGNED_BYTE:
1452 break;
1453 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001454 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001455 return false;
1456 }
1457 break;
1458 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are
1459 // handled below
1460 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1461 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1462 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1463 break;
1464 case GL_DEPTH_COMPONENT:
1465 switch (type)
1466 {
1467 case GL_UNSIGNED_SHORT:
1468 case GL_UNSIGNED_INT:
1469 break;
1470 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001471 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001472 return false;
1473 }
1474 break;
1475 case GL_DEPTH_STENCIL_OES:
1476 switch (type)
1477 {
1478 case GL_UNSIGNED_INT_24_8_OES:
1479 break;
1480 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001481 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001482 return false;
1483 }
1484 break;
1485 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001486 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001487 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001488 }
1489
1490 switch (format)
1491 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001492 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1493 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1494 if (context->getExtensions().textureCompressionDXT1)
1495 {
Jamie Madille0472f32018-11-27 16:32:45 -05001496 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001497 return false;
1498 }
1499 else
1500 {
Jamie Madille0472f32018-11-27 16:32:45 -05001501 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001502 return false;
1503 }
1504 break;
1505 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1506 if (context->getExtensions().textureCompressionDXT3)
1507 {
Jamie Madille0472f32018-11-27 16:32:45 -05001508 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001509 return false;
1510 }
1511 else
1512 {
Jamie Madille0472f32018-11-27 16:32:45 -05001513 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001514 return false;
1515 }
1516 break;
1517 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1518 if (context->getExtensions().textureCompressionDXT5)
1519 {
Jamie Madille0472f32018-11-27 16:32:45 -05001520 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001521 return false;
1522 }
1523 else
1524 {
Jamie Madille0472f32018-11-27 16:32:45 -05001525 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001526 return false;
1527 }
1528 break;
1529 case GL_ETC1_RGB8_OES:
1530 if (context->getExtensions().compressedETC1RGB8Texture)
1531 {
Jamie Madille0472f32018-11-27 16:32:45 -05001532 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001533 return false;
1534 }
1535 else
1536 {
Jamie Madille0472f32018-11-27 16:32:45 -05001537 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001538 return false;
1539 }
1540 break;
1541 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001542 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1543 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1544 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1545 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001546 if (context->getExtensions().lossyETCDecode)
1547 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001548 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001549 return false;
1550 }
1551 else
1552 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001553 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001554 return false;
1555 }
1556 break;
1557 case GL_DEPTH_COMPONENT:
1558 case GL_DEPTH_STENCIL_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001559 if (!context->getExtensions().depthTextureANGLE &&
1560 !(context->getExtensions().packedDepthStencil &&
1561 context->getExtensions().depthTextureOES))
He Yunchaoced53ae2016-11-29 15:00:51 +08001562 {
Jamie Madille0472f32018-11-27 16:32:45 -05001563 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001564 return false;
1565 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001566 if (target != TextureTarget::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001567 {
Jamie Madille0472f32018-11-27 16:32:45 -05001568 context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001569 return false;
1570 }
1571 // OES_depth_texture supports loading depth data and multiple levels,
1572 // but ANGLE_depth_texture does not
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001573 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001574 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001575 if (pixels != nullptr)
1576 {
1577 context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
1578 return false;
1579 }
1580 if (level != 0)
1581 {
1582 context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
1583 return false;
1584 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001585 }
1586 break;
1587 default:
1588 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001589 }
1590
Geoff Lang6e898aa2017-06-02 11:17:26 -04001591 if (!isSubImage)
1592 {
1593 switch (internalformat)
1594 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001595 // Core ES 2.0 formats
1596 case GL_ALPHA:
1597 case GL_LUMINANCE:
1598 case GL_LUMINANCE_ALPHA:
1599 case GL_RGB:
1600 case GL_RGBA:
1601 break;
1602
Geoff Lang6e898aa2017-06-02 11:17:26 -04001603 case GL_RGBA32F:
1604 if (!context->getExtensions().colorBufferFloatRGBA)
1605 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001606 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001607 return false;
1608 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001609
1610 nonEqualFormatsAllowed = true;
1611
Geoff Lang6e898aa2017-06-02 11:17:26 -04001612 if (type != GL_FLOAT)
1613 {
Jamie Madille0472f32018-11-27 16:32:45 -05001614 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001615 return false;
1616 }
1617 if (format != GL_RGBA)
1618 {
Jamie Madille0472f32018-11-27 16:32:45 -05001619 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001620 return false;
1621 }
1622 break;
1623
1624 case GL_RGB32F:
1625 if (!context->getExtensions().colorBufferFloatRGB)
1626 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001627 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001628 return false;
1629 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001630
1631 nonEqualFormatsAllowed = true;
1632
Geoff Lang6e898aa2017-06-02 11:17:26 -04001633 if (type != GL_FLOAT)
1634 {
Jamie Madille0472f32018-11-27 16:32:45 -05001635 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001636 return false;
1637 }
1638 if (format != GL_RGB)
1639 {
Jamie Madille0472f32018-11-27 16:32:45 -05001640 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001641 return false;
1642 }
1643 break;
1644
Tim Van Patten208af3e2019-03-19 09:15:55 -06001645 case GL_BGRA_EXT:
1646 if (!context->getExtensions().textureFormatBGRA8888)
1647 {
1648 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1649 return false;
1650 }
Geoff Lang6e898aa2017-06-02 11:17:26 -04001651 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001652
1653 case GL_DEPTH_COMPONENT:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001654 if (!(context->getExtensions().depthTextureAny()))
1655 {
1656 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1657 return false;
1658 }
1659 break;
1660
Tim Van Patten208af3e2019-03-19 09:15:55 -06001661 case GL_DEPTH_STENCIL:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001662 if (!(context->getExtensions().depthTextureANGLE ||
1663 context->getExtensions().packedDepthStencil))
Tim Van Patten208af3e2019-03-19 09:15:55 -06001664 {
1665 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1666 return false;
1667 }
1668 break;
1669
1670 case GL_RED:
1671 case GL_RG:
1672 if (!context->getExtensions().textureRG)
1673 {
1674 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1675 return false;
1676 }
1677 break;
1678
1679 case GL_SRGB_EXT:
1680 case GL_SRGB_ALPHA_EXT:
1681 if (!context->getExtensions().sRGB)
1682 {
1683 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1684 return false;
1685 }
1686 break;
1687
1688 default:
1689 context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat);
1690 return false;
Geoff Lang6e898aa2017-06-02 11:17:26 -04001691 }
1692 }
1693
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001694 if (type == GL_FLOAT)
1695 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001696 if (!context->getExtensions().textureFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001697 {
Jamie Madille0472f32018-11-27 16:32:45 -05001698 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001699 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001700 }
1701 }
1702 else if (type == GL_HALF_FLOAT_OES)
1703 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001704 if (!context->getExtensions().textureHalfFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001705 {
Jamie Madille0472f32018-11-27 16:32:45 -05001706 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001707 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001708 }
1709 }
1710 }
1711
Tim Van Patten208af3e2019-03-19 09:15:55 -06001712 if (isSubImage)
Geoff Langff5b2d52016-09-07 11:32:23 -04001713 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001714 const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info;
1715 if (textureInternalFormat.internalFormat == GL_NONE)
1716 {
1717 context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel);
1718 return false;
1719 }
1720
Tim Van Patten5f388c22019-03-14 09:54:23 -06001721 if (format != textureInternalFormat.format)
1722 {
1723 context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch);
1724 return false;
1725 }
1726
1727 if (context->getExtensions().webglCompatibility)
Tim Van Patten208af3e2019-03-19 09:15:55 -06001728 {
1729 if (GetInternalFormatInfo(format, type).sizedInternalFormat !=
1730 textureInternalFormat.sizedInternalFormat)
1731 {
Tim Van Patten5f388c22019-03-14 09:54:23 -06001732 context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch);
Tim Van Patten208af3e2019-03-19 09:15:55 -06001733 return false;
1734 }
1735 }
1736
1737 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
1738 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level))
1739 {
1740 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
1741 return false;
1742 }
1743
1744 if (width > 0 && height > 0 && pixels == nullptr &&
1745 context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr)
1746 {
1747 context->validationError(GL_INVALID_VALUE, kPixelDataNull);
1748 return false;
1749 }
1750 }
1751 else
1752 {
1753 if (texture->getImmutableFormat())
1754 {
1755 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
1756 return false;
1757 }
1758 }
1759
1760 // From GL_CHROMIUM_color_buffer_float_rgb[a]:
1761 // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
1762 // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
1763 // internalformat parameter and format parameter of TexImage2D must match is lifted for this
1764 // case.
1765 if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
1766 {
1767 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Langff5b2d52016-09-07 11:32:23 -04001768 return false;
1769 }
1770
Tim Van Patten208af3e2019-03-19 09:15:55 -06001771 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
1772 return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels,
1773 imageSize);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001774}
1775
He Yunchaoced53ae2016-11-29 15:00:51 +08001776bool ValidateES2TexStorageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001777 TextureType target,
He Yunchaoced53ae2016-11-29 15:00:51 +08001778 GLsizei levels,
1779 GLenum internalformat,
1780 GLsizei width,
1781 GLsizei height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001782{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001783 if (target != TextureType::_2D && target != TextureType::CubeMap &&
1784 target != TextureType::Rectangle)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001785 {
Jamie Madille0472f32018-11-27 16:32:45 -05001786 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001787 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001788 }
1789
1790 if (width < 1 || height < 1 || levels < 1)
1791 {
Jamie Madille0472f32018-11-27 16:32:45 -05001792 context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall);
Geoff Langb1196682014-07-23 13:47:29 -04001793 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001794 }
1795
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001796 if (target == TextureType::CubeMap && width != height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001797 {
Jamie Madille0472f32018-11-27 16:32:45 -05001798 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Langb1196682014-07-23 13:47:29 -04001799 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001800 }
1801
1802 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1803 {
Jamie Madille0472f32018-11-27 16:32:45 -05001804 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
Geoff Langb1196682014-07-23 13:47:29 -04001805 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001806 }
1807
Geoff Langca271392017-04-05 12:30:00 -04001808 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Lang5d601382014-07-22 15:14:06 -04001809 if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001810 {
Jamie Madille0472f32018-11-27 16:32:45 -05001811 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Langb1196682014-07-23 13:47:29 -04001812 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001813 }
1814
Geoff Langaae65a42014-05-26 12:43:44 -04001815 const gl::Caps &caps = context->getCaps();
1816
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001817 switch (target)
1818 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001819 case TextureType::_2D:
He Yunchaoced53ae2016-11-29 15:00:51 +08001820 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
1821 static_cast<GLuint>(height) > caps.max2DTextureSize)
1822 {
Jamie Madille0472f32018-11-27 16:32:45 -05001823 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001824 return false;
1825 }
1826 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001827 case TextureType::Rectangle:
Jamie Madill610640f2018-11-21 17:28:41 -05001828 if (levels != 1)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001829 {
Jamie Madille0472f32018-11-27 16:32:45 -05001830 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madill610640f2018-11-21 17:28:41 -05001831 return false;
1832 }
1833
1834 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1835 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1836 {
Jamie Madille0472f32018-11-27 16:32:45 -05001837 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001838 return false;
1839 }
1840 if (formatInfo.compressed)
1841 {
Jamie Madille0472f32018-11-27 16:32:45 -05001842 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001843 return false;
1844 }
1845 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001846 case TextureType::CubeMap:
He Yunchaoced53ae2016-11-29 15:00:51 +08001847 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize ||
1848 static_cast<GLuint>(height) > caps.maxCubeMapTextureSize)
1849 {
Jamie Madille0472f32018-11-27 16:32:45 -05001850 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001851 return false;
1852 }
1853 break;
1854 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001855 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001856 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001857 }
1858
Geoff Langc0b9ef42014-07-02 10:02:37 -04001859 if (levels != 1 && !context->getExtensions().textureNPOT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001860 {
1861 if (!gl::isPow2(width) || !gl::isPow2(height))
1862 {
Jamie Madille0472f32018-11-27 16:32:45 -05001863 context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2);
Geoff Langb1196682014-07-23 13:47:29 -04001864 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001865 }
1866 }
1867
1868 switch (internalformat)
1869 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001870 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1871 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1872 if (!context->getExtensions().textureCompressionDXT1)
1873 {
Jamie Madille0472f32018-11-27 16:32:45 -05001874 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001875 return false;
1876 }
1877 break;
1878 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1879 if (!context->getExtensions().textureCompressionDXT3)
1880 {
Jamie Madille0472f32018-11-27 16:32:45 -05001881 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001882 return false;
1883 }
1884 break;
1885 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1886 if (!context->getExtensions().textureCompressionDXT5)
1887 {
Jamie Madille0472f32018-11-27 16:32:45 -05001888 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001889 return false;
1890 }
1891 break;
1892 case GL_ETC1_RGB8_OES:
1893 if (!context->getExtensions().compressedETC1RGB8Texture)
1894 {
Jamie Madille0472f32018-11-27 16:32:45 -05001895 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001896 return false;
1897 }
1898 break;
1899 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001900 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1901 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1902 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1903 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001904 if (!context->getExtensions().lossyETCDecode)
1905 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001906 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001907 return false;
1908 }
1909 break;
1910 case GL_RGBA32F_EXT:
1911 case GL_RGB32F_EXT:
1912 case GL_ALPHA32F_EXT:
1913 case GL_LUMINANCE32F_EXT:
1914 case GL_LUMINANCE_ALPHA32F_EXT:
1915 if (!context->getExtensions().textureFloat)
1916 {
Jamie Madille0472f32018-11-27 16:32:45 -05001917 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001918 return false;
1919 }
1920 break;
1921 case GL_RGBA16F_EXT:
1922 case GL_RGB16F_EXT:
1923 case GL_ALPHA16F_EXT:
1924 case GL_LUMINANCE16F_EXT:
1925 case GL_LUMINANCE_ALPHA16F_EXT:
1926 if (!context->getExtensions().textureHalfFloat)
1927 {
Jamie Madille0472f32018-11-27 16:32:45 -05001928 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001929 return false;
1930 }
1931 break;
1932 case GL_R8_EXT:
1933 case GL_RG8_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001934 if (!context->getExtensions().textureRG)
1935 {
Jamie Madille0472f32018-11-27 16:32:45 -05001936 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001937 return false;
1938 }
1939 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001940 case GL_R16F_EXT:
1941 case GL_RG16F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001942 if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat)
1943 {
Jamie Madille0472f32018-11-27 16:32:45 -05001944 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001945 return false;
1946 }
1947 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001948 case GL_R32F_EXT:
1949 case GL_RG32F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001950 if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat)
He Yunchaoced53ae2016-11-29 15:00:51 +08001951 {
Jamie Madille0472f32018-11-27 16:32:45 -05001952 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001953 return false;
1954 }
1955 break;
1956 case GL_DEPTH_COMPONENT16:
1957 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001958 if (!(context->getExtensions().depthTextureAny()))
He Yunchaoced53ae2016-11-29 15:00:51 +08001959 {
Jamie Madille0472f32018-11-27 16:32:45 -05001960 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001961 return false;
1962 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001963 if (target != TextureType::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001964 {
Jamie Madille0472f32018-11-27 16:32:45 -05001965 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001966 return false;
1967 }
1968 // ANGLE_depth_texture only supports 1-level textures
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001969 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001970 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001971 if (levels != 1)
1972 {
1973 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1974 return false;
1975 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001976 }
1977 break;
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001978 case GL_DEPTH24_STENCIL8_OES:
1979 if (!(context->getExtensions().depthTextureANGLE ||
1980 (context->getExtensions().packedDepthStencil &&
1981 context->getExtensions().textureStorage)))
1982 {
1983 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1984 return false;
1985 }
1986 if (target != TextureType::_2D)
1987 {
1988 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
1989 return false;
1990 }
1991 if (!context->getExtensions().packedDepthStencil)
1992 {
1993 // ANGLE_depth_texture only supports 1-level textures
1994 if (levels != 1)
1995 {
1996 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1997 return false;
1998 }
1999 }
2000 break;
2001
He Yunchaoced53ae2016-11-29 15:00:51 +08002002 default:
2003 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002004 }
2005
Jamie Madillcfc73cc2019-04-08 16:26:51 -04002006 gl::Texture *texture = context->getTextureByType(target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002007 if (!texture || texture->id() == 0)
2008 {
Jamie Madille0472f32018-11-27 16:32:45 -05002009 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
Geoff Langb1196682014-07-23 13:47:29 -04002010 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002011 }
2012
Geoff Lang69cce582015-09-17 13:20:36 -04002013 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002014 {
Jamie Madille0472f32018-11-27 16:32:45 -05002015 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
Geoff Langb1196682014-07-23 13:47:29 -04002016 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002017 }
2018
2019 return true;
2020}
2021
He Yunchaoced53ae2016-11-29 15:00:51 +08002022bool ValidateDiscardFramebufferEXT(Context *context,
2023 GLenum target,
2024 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07002025 const GLenum *attachments)
2026{
Jamie Madillc29968b2016-01-20 11:17:23 -05002027 if (!context->getExtensions().discardFramebuffer)
2028 {
Jamie Madille0472f32018-11-27 16:32:45 -05002029 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002030 return false;
2031 }
2032
Austin Kinross08332632015-05-05 13:35:47 -07002033 bool defaultFramebuffer = false;
2034
2035 switch (target)
2036 {
He Yunchaoced53ae2016-11-29 15:00:51 +08002037 case GL_FRAMEBUFFER:
2038 defaultFramebuffer =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002039 (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0);
He Yunchaoced53ae2016-11-29 15:00:51 +08002040 break;
2041 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002042 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08002043 return false;
Austin Kinross08332632015-05-05 13:35:47 -07002044 }
2045
He Yunchaoced53ae2016-11-29 15:00:51 +08002046 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
2047 defaultFramebuffer);
Austin Kinross08332632015-05-05 13:35:47 -07002048}
2049
Austin Kinrossbc781f32015-10-26 09:27:38 -07002050bool ValidateBindVertexArrayOES(Context *context, GLuint array)
2051{
2052 if (!context->getExtensions().vertexArrayObject)
2053 {
Jamie Madille0472f32018-11-27 16:32:45 -05002054 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002055 return false;
2056 }
2057
2058 return ValidateBindVertexArrayBase(context, array);
2059}
2060
Jamie Madilld7576732017-08-26 18:49:50 -04002061bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002062{
2063 if (!context->getExtensions().vertexArrayObject)
2064 {
Jamie Madille0472f32018-11-27 16:32:45 -05002065 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002066 return false;
2067 }
2068
Olli Etuaho41997e72016-03-10 13:38:39 +02002069 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002070}
2071
Jamie Madilld7576732017-08-26 18:49:50 -04002072bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002073{
2074 if (!context->getExtensions().vertexArrayObject)
2075 {
Jamie Madille0472f32018-11-27 16:32:45 -05002076 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002077 return false;
2078 }
2079
Olli Etuaho41997e72016-03-10 13:38:39 +02002080 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002081}
2082
Jamie Madilld7576732017-08-26 18:49:50 -04002083bool ValidateIsVertexArrayOES(Context *context, GLuint array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002084{
2085 if (!context->getExtensions().vertexArrayObject)
2086 {
Jamie Madille0472f32018-11-27 16:32:45 -05002087 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002088 return false;
2089 }
2090
2091 return true;
2092}
Geoff Langc5629752015-12-07 16:29:04 -05002093
2094bool ValidateProgramBinaryOES(Context *context,
2095 GLuint program,
2096 GLenum binaryFormat,
2097 const void *binary,
2098 GLint length)
2099{
2100 if (!context->getExtensions().getProgramBinary)
2101 {
Jamie Madille0472f32018-11-27 16:32:45 -05002102 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002103 return false;
2104 }
2105
2106 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
2107}
2108
2109bool ValidateGetProgramBinaryOES(Context *context,
2110 GLuint program,
2111 GLsizei bufSize,
2112 GLsizei *length,
2113 GLenum *binaryFormat,
2114 void *binary)
2115{
2116 if (!context->getExtensions().getProgramBinary)
2117 {
Jamie Madille0472f32018-11-27 16:32:45 -05002118 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002119 return false;
2120 }
2121
2122 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
2123}
Geoff Lange102fee2015-12-10 11:23:30 -05002124
Geoff Lang70d0f492015-12-10 17:45:46 -05002125static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication)
2126{
2127 switch (source)
2128 {
2129 case GL_DEBUG_SOURCE_API:
2130 case GL_DEBUG_SOURCE_SHADER_COMPILER:
2131 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
2132 case GL_DEBUG_SOURCE_OTHER:
2133 // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted
2134 return !mustBeThirdPartyOrApplication;
2135
2136 case GL_DEBUG_SOURCE_THIRD_PARTY:
2137 case GL_DEBUG_SOURCE_APPLICATION:
2138 return true;
2139
2140 default:
2141 return false;
2142 }
2143}
2144
2145static bool ValidDebugType(GLenum type)
2146{
2147 switch (type)
2148 {
2149 case GL_DEBUG_TYPE_ERROR:
2150 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
2151 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
2152 case GL_DEBUG_TYPE_PERFORMANCE:
2153 case GL_DEBUG_TYPE_PORTABILITY:
2154 case GL_DEBUG_TYPE_OTHER:
2155 case GL_DEBUG_TYPE_MARKER:
2156 case GL_DEBUG_TYPE_PUSH_GROUP:
2157 case GL_DEBUG_TYPE_POP_GROUP:
2158 return true;
2159
2160 default:
2161 return false;
2162 }
2163}
2164
2165static bool ValidDebugSeverity(GLenum severity)
2166{
2167 switch (severity)
2168 {
2169 case GL_DEBUG_SEVERITY_HIGH:
2170 case GL_DEBUG_SEVERITY_MEDIUM:
2171 case GL_DEBUG_SEVERITY_LOW:
2172 case GL_DEBUG_SEVERITY_NOTIFICATION:
2173 return true;
2174
2175 default:
2176 return false;
2177 }
2178}
2179
Geoff Lange102fee2015-12-10 11:23:30 -05002180bool ValidateDebugMessageControlKHR(Context *context,
2181 GLenum source,
2182 GLenum type,
2183 GLenum severity,
2184 GLsizei count,
2185 const GLuint *ids,
2186 GLboolean enabled)
2187{
2188 if (!context->getExtensions().debug)
2189 {
Jamie Madille0472f32018-11-27 16:32:45 -05002190 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002191 return false;
2192 }
2193
Geoff Lang70d0f492015-12-10 17:45:46 -05002194 if (!ValidDebugSource(source, false) && source != GL_DONT_CARE)
2195 {
Jamie Madille0472f32018-11-27 16:32:45 -05002196 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002197 return false;
2198 }
2199
2200 if (!ValidDebugType(type) && type != GL_DONT_CARE)
2201 {
Jamie Madille0472f32018-11-27 16:32:45 -05002202 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002203 return false;
2204 }
2205
2206 if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE)
2207 {
Jamie Madille0472f32018-11-27 16:32:45 -05002208 context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002209 return false;
2210 }
2211
2212 if (count > 0)
2213 {
2214 if (source == GL_DONT_CARE || type == GL_DONT_CARE)
2215 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002216 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002217 return false;
2218 }
2219
2220 if (severity != GL_DONT_CARE)
2221 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002222 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002223 return false;
2224 }
2225 }
2226
Geoff Lange102fee2015-12-10 11:23:30 -05002227 return true;
2228}
2229
2230bool ValidateDebugMessageInsertKHR(Context *context,
2231 GLenum source,
2232 GLenum type,
2233 GLuint id,
2234 GLenum severity,
2235 GLsizei length,
2236 const GLchar *buf)
2237{
2238 if (!context->getExtensions().debug)
2239 {
Jamie Madille0472f32018-11-27 16:32:45 -05002240 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002241 return false;
2242 }
2243
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002244 if (!context->getState().getDebug().isOutputEnabled())
Geoff Lang70d0f492015-12-10 17:45:46 -05002245 {
2246 // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do
2247 // not generate an error.
2248 return false;
2249 }
2250
2251 if (!ValidDebugSeverity(severity))
2252 {
Jamie Madille0472f32018-11-27 16:32:45 -05002253 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002254 return false;
2255 }
2256
2257 if (!ValidDebugType(type))
2258 {
Jamie Madille0472f32018-11-27 16:32:45 -05002259 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002260 return false;
2261 }
2262
2263 if (!ValidDebugSource(source, true))
2264 {
Jamie Madille0472f32018-11-27 16:32:45 -05002265 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002266 return false;
2267 }
2268
2269 size_t messageLength = (length < 0) ? strlen(buf) : length;
2270 if (messageLength > context->getExtensions().maxDebugMessageLength)
2271 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002272 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002273 return false;
2274 }
2275
Geoff Lange102fee2015-12-10 11:23:30 -05002276 return true;
2277}
2278
2279bool ValidateDebugMessageCallbackKHR(Context *context,
2280 GLDEBUGPROCKHR callback,
2281 const void *userParam)
2282{
2283 if (!context->getExtensions().debug)
2284 {
Jamie Madille0472f32018-11-27 16:32:45 -05002285 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002286 return false;
2287 }
2288
Geoff Lange102fee2015-12-10 11:23:30 -05002289 return true;
2290}
2291
2292bool ValidateGetDebugMessageLogKHR(Context *context,
2293 GLuint count,
2294 GLsizei bufSize,
2295 GLenum *sources,
2296 GLenum *types,
2297 GLuint *ids,
2298 GLenum *severities,
2299 GLsizei *lengths,
2300 GLchar *messageLog)
2301{
2302 if (!context->getExtensions().debug)
2303 {
Jamie Madille0472f32018-11-27 16:32:45 -05002304 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002305 return false;
2306 }
2307
Geoff Lang70d0f492015-12-10 17:45:46 -05002308 if (bufSize < 0 && messageLog != nullptr)
2309 {
Jamie Madille0472f32018-11-27 16:32:45 -05002310 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002311 return false;
2312 }
2313
Geoff Lange102fee2015-12-10 11:23:30 -05002314 return true;
2315}
2316
2317bool ValidatePushDebugGroupKHR(Context *context,
2318 GLenum source,
2319 GLuint id,
2320 GLsizei length,
2321 const GLchar *message)
2322{
2323 if (!context->getExtensions().debug)
2324 {
Jamie Madille0472f32018-11-27 16:32:45 -05002325 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002326 return false;
2327 }
2328
Geoff Lang70d0f492015-12-10 17:45:46 -05002329 if (!ValidDebugSource(source, true))
2330 {
Jamie Madille0472f32018-11-27 16:32:45 -05002331 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002332 return false;
2333 }
2334
2335 size_t messageLength = (length < 0) ? strlen(message) : length;
2336 if (messageLength > context->getExtensions().maxDebugMessageLength)
2337 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002338 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002339 return false;
2340 }
2341
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002342 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002343 if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth)
2344 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002345 context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth);
Geoff Lang70d0f492015-12-10 17:45:46 -05002346 return false;
2347 }
2348
Geoff Lange102fee2015-12-10 11:23:30 -05002349 return true;
2350}
2351
2352bool ValidatePopDebugGroupKHR(Context *context)
2353{
2354 if (!context->getExtensions().debug)
2355 {
Jamie Madille0472f32018-11-27 16:32:45 -05002356 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002357 return false;
2358 }
2359
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002360 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002361 if (currentStackSize <= 1)
2362 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002363 context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup);
Geoff Lang70d0f492015-12-10 17:45:46 -05002364 return false;
2365 }
2366
2367 return true;
2368}
2369
2370static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name)
2371{
2372 switch (identifier)
2373 {
2374 case GL_BUFFER:
2375 if (context->getBuffer(name) == nullptr)
2376 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002377 context->validationError(GL_INVALID_VALUE, kInvalidBufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002378 return false;
2379 }
2380 return true;
2381
2382 case GL_SHADER:
2383 if (context->getShader(name) == nullptr)
2384 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002385 context->validationError(GL_INVALID_VALUE, kInvalidShaderName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002386 return false;
2387 }
2388 return true;
2389
2390 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002391 if (context->getProgramNoResolveLink(name) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002392 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002393 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002394 return false;
2395 }
2396 return true;
2397
2398 case GL_VERTEX_ARRAY:
2399 if (context->getVertexArray(name) == nullptr)
2400 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002401 context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002402 return false;
2403 }
2404 return true;
2405
2406 case GL_QUERY:
2407 if (context->getQuery(name) == nullptr)
2408 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002409 context->validationError(GL_INVALID_VALUE, kInvalidQueryName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002410 return false;
2411 }
2412 return true;
2413
2414 case GL_TRANSFORM_FEEDBACK:
2415 if (context->getTransformFeedback(name) == nullptr)
2416 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002417 context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002418 return false;
2419 }
2420 return true;
2421
2422 case GL_SAMPLER:
2423 if (context->getSampler(name) == nullptr)
2424 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002425 context->validationError(GL_INVALID_VALUE, kInvalidSamplerName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002426 return false;
2427 }
2428 return true;
2429
2430 case GL_TEXTURE:
2431 if (context->getTexture(name) == nullptr)
2432 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002433 context->validationError(GL_INVALID_VALUE, kInvalidTextureName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002434 return false;
2435 }
2436 return true;
2437
2438 case GL_RENDERBUFFER:
Jamie Madill7c7dec02019-08-06 17:44:11 -04002439 if (!context->isRenderbuffer({name}))
Geoff Lang70d0f492015-12-10 17:45:46 -05002440 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002441 context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002442 return false;
2443 }
2444 return true;
2445
2446 case GL_FRAMEBUFFER:
2447 if (context->getFramebuffer(name) == nullptr)
2448 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002449 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002450 return false;
2451 }
2452 return true;
2453
2454 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05002455 context->validationError(GL_INVALID_ENUM, kInvalidIndentifier);
Geoff Lang70d0f492015-12-10 17:45:46 -05002456 return false;
2457 }
Geoff Lange102fee2015-12-10 11:23:30 -05002458}
2459
Martin Radev9d901792016-07-15 15:58:58 +03002460static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label)
2461{
2462 size_t labelLength = 0;
2463
2464 if (length < 0)
2465 {
2466 if (label != nullptr)
2467 {
2468 labelLength = strlen(label);
2469 }
2470 }
2471 else
2472 {
2473 labelLength = static_cast<size_t>(length);
2474 }
2475
2476 if (labelLength > context->getExtensions().maxLabelLength)
2477 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002478 context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength);
Martin Radev9d901792016-07-15 15:58:58 +03002479 return false;
2480 }
2481
2482 return true;
2483}
2484
Geoff Lange102fee2015-12-10 11:23:30 -05002485bool ValidateObjectLabelKHR(Context *context,
2486 GLenum identifier,
2487 GLuint name,
2488 GLsizei length,
2489 const GLchar *label)
2490{
2491 if (!context->getExtensions().debug)
2492 {
Jamie Madille0472f32018-11-27 16:32:45 -05002493 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002494 return false;
2495 }
2496
Geoff Lang70d0f492015-12-10 17:45:46 -05002497 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2498 {
2499 return false;
2500 }
2501
Martin Radev9d901792016-07-15 15:58:58 +03002502 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002503 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002504 return false;
2505 }
2506
Geoff Lange102fee2015-12-10 11:23:30 -05002507 return true;
2508}
2509
2510bool ValidateGetObjectLabelKHR(Context *context,
2511 GLenum identifier,
2512 GLuint name,
2513 GLsizei bufSize,
2514 GLsizei *length,
2515 GLchar *label)
2516{
2517 if (!context->getExtensions().debug)
2518 {
Jamie Madille0472f32018-11-27 16:32:45 -05002519 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002520 return false;
2521 }
2522
Geoff Lang70d0f492015-12-10 17:45:46 -05002523 if (bufSize < 0)
2524 {
Jamie Madille0472f32018-11-27 16:32:45 -05002525 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002526 return false;
2527 }
2528
2529 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2530 {
2531 return false;
2532 }
2533
Martin Radev9d901792016-07-15 15:58:58 +03002534 return true;
Geoff Lang70d0f492015-12-10 17:45:46 -05002535}
2536
2537static bool ValidateObjectPtrName(Context *context, const void *ptr)
2538{
Jamie Madill70b5bb02017-08-28 13:32:37 -04002539 if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002540 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002541 context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer);
Geoff Lang70d0f492015-12-10 17:45:46 -05002542 return false;
2543 }
2544
Geoff Lange102fee2015-12-10 11:23:30 -05002545 return true;
2546}
2547
2548bool ValidateObjectPtrLabelKHR(Context *context,
2549 const void *ptr,
2550 GLsizei length,
2551 const GLchar *label)
2552{
2553 if (!context->getExtensions().debug)
2554 {
Jamie Madille0472f32018-11-27 16:32:45 -05002555 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002556 return false;
2557 }
2558
Geoff Lang70d0f492015-12-10 17:45:46 -05002559 if (!ValidateObjectPtrName(context, ptr))
2560 {
2561 return false;
2562 }
2563
Martin Radev9d901792016-07-15 15:58:58 +03002564 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002565 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002566 return false;
2567 }
2568
Geoff Lange102fee2015-12-10 11:23:30 -05002569 return true;
2570}
2571
2572bool ValidateGetObjectPtrLabelKHR(Context *context,
2573 const void *ptr,
2574 GLsizei bufSize,
2575 GLsizei *length,
2576 GLchar *label)
2577{
2578 if (!context->getExtensions().debug)
2579 {
Jamie Madille0472f32018-11-27 16:32:45 -05002580 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002581 return false;
2582 }
2583
Geoff Lang70d0f492015-12-10 17:45:46 -05002584 if (bufSize < 0)
2585 {
Jamie Madille0472f32018-11-27 16:32:45 -05002586 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002587 return false;
2588 }
2589
2590 if (!ValidateObjectPtrName(context, ptr))
2591 {
2592 return false;
2593 }
2594
Martin Radev9d901792016-07-15 15:58:58 +03002595 return true;
Geoff Lange102fee2015-12-10 11:23:30 -05002596}
2597
2598bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params)
2599{
2600 if (!context->getExtensions().debug)
2601 {
Jamie Madille0472f32018-11-27 16:32:45 -05002602 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002603 return false;
2604 }
2605
Geoff Lang70d0f492015-12-10 17:45:46 -05002606 // TODO: represent this in Context::getQueryParameterInfo.
2607 switch (pname)
2608 {
2609 case GL_DEBUG_CALLBACK_FUNCTION:
2610 case GL_DEBUG_CALLBACK_USER_PARAM:
2611 break;
2612
2613 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002614 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang70d0f492015-12-10 17:45:46 -05002615 return false;
2616 }
2617
Geoff Lange102fee2015-12-10 11:23:30 -05002618 return true;
2619}
Jamie Madillc29968b2016-01-20 11:17:23 -05002620
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002621bool ValidateGetPointervRobustANGLERobustANGLE(Context *context,
2622 GLenum pname,
2623 GLsizei bufSize,
2624 GLsizei *length,
2625 void **params)
2626{
2627 UNIMPLEMENTED();
2628 return false;
2629}
2630
Jamie Madillc29968b2016-01-20 11:17:23 -05002631bool ValidateBlitFramebufferANGLE(Context *context,
2632 GLint srcX0,
2633 GLint srcY0,
2634 GLint srcX1,
2635 GLint srcY1,
2636 GLint dstX0,
2637 GLint dstY0,
2638 GLint dstX1,
2639 GLint dstY1,
2640 GLbitfield mask,
2641 GLenum filter)
2642{
2643 if (!context->getExtensions().framebufferBlit)
2644 {
Jamie Madille0472f32018-11-27 16:32:45 -05002645 context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable);
Jamie Madillc29968b2016-01-20 11:17:23 -05002646 return false;
2647 }
2648
2649 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
2650 {
2651 // TODO(jmadill): Determine if this should be available on other implementations.
Jamie Madille0472f32018-11-27 16:32:45 -05002652 context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip);
Jamie Madillc29968b2016-01-20 11:17:23 -05002653 return false;
2654 }
2655
2656 if (filter == GL_LINEAR)
2657 {
Jamie Madille0472f32018-11-27 16:32:45 -05002658 context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear);
Jamie Madillc29968b2016-01-20 11:17:23 -05002659 return false;
2660 }
2661
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002662 Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
2663 Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002664
2665 if (mask & GL_COLOR_BUFFER_BIT)
2666 {
Jamie Madill4e71b2b2019-07-08 13:23:38 -04002667 const FramebufferAttachment *readColorAttachment =
2668 readFramebuffer->getReadColorAttachment();
2669 const FramebufferAttachment *drawColorAttachment =
2670 drawFramebuffer->getFirstColorAttachment();
Jamie Madillc29968b2016-01-20 11:17:23 -05002671
2672 if (readColorAttachment && drawColorAttachment)
2673 {
2674 if (!(readColorAttachment->type() == GL_TEXTURE &&
Kenneth Russellcbdf8612019-07-09 20:30:45 -07002675 (readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D ||
2676 readColorAttachment->getTextureImageIndex().getType() ==
2677 TextureType::Rectangle)) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002678 readColorAttachment->type() != GL_RENDERBUFFER &&
2679 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2680 {
Jamie Madill610640f2018-11-21 17:28:41 -05002681 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002682 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002683 return false;
2684 }
2685
Geoff Langa15472a2015-08-11 11:48:03 -04002686 for (size_t drawbufferIdx = 0;
2687 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002688 {
Geoff Langa15472a2015-08-11 11:48:03 -04002689 const FramebufferAttachment *attachment =
2690 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2691 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002692 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002693 if (!(attachment->type() == GL_TEXTURE &&
Kenneth Russellcbdf8612019-07-09 20:30:45 -07002694 (attachment->getTextureImageIndex().getType() == TextureType::_2D ||
2695 attachment->getTextureImageIndex().getType() ==
2696 TextureType::Rectangle)) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002697 attachment->type() != GL_RENDERBUFFER &&
2698 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2699 {
Jamie Madill610640f2018-11-21 17:28:41 -05002700 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002701 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002702 return false;
2703 }
2704
2705 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002706 if (!Format::EquivalentForBlit(attachment->getFormat(),
2707 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002708 {
Jamie Madill610640f2018-11-21 17:28:41 -05002709 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002710 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002711 return false;
2712 }
2713 }
2714 }
2715
Jamie Madill427064d2018-04-13 16:20:34 -04002716 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002717 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002718 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2719 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2720 {
Jamie Madill610640f2018-11-21 17:28:41 -05002721 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002722 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002723 return false;
2724 }
2725 }
2726 }
2727
2728 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2729 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2730 for (size_t i = 0; i < 2; i++)
2731 {
2732 if (mask & masks[i])
2733 {
2734 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002735 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002736 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002737 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002738
2739 if (readBuffer && drawBuffer)
2740 {
2741 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2742 dstX0, dstY0, dstX1, dstY1))
2743 {
2744 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002745 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002746 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002747 return false;
2748 }
2749
2750 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2751 {
Jamie Madill610640f2018-11-21 17:28:41 -05002752 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002753 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002754 return false;
2755 }
2756 }
2757 }
2758 }
2759
2760 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2761 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002762}
Jamie Madillc29968b2016-01-20 11:17:23 -05002763
Jamie Madill5b772312018-03-08 20:28:32 -05002764bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002765{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002766 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002767 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002768
Jamie Madill427064d2018-04-13 16:20:34 -04002769 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002770 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002771 return false;
2772 }
2773
2774 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2775 {
Jamie Madille0472f32018-11-27 16:32:45 -05002776 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002777 return false;
2778 }
2779
Olli Etuaho94c91a92018-07-19 15:10:24 +03002780 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002781 {
2782 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2783 GL_SIGNED_NORMALIZED};
2784
Corentin Wallez59c41592017-07-11 13:19:54 -04002785 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002786 drawBufferIdx++)
2787 {
2788 if (!ValidateWebGLFramebufferAttachmentClearType(
2789 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2790 {
2791 return false;
2792 }
2793 }
2794 }
2795
Mingyu Huebab6702019-04-19 14:36:45 -07002796 if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery)
Olli Etuaho94c91a92018-07-19 15:10:24 +03002797 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002798 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002799 Framebuffer *framebuffer = state.getDrawFramebuffer();
2800 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2801 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002802 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002803 return false;
2804 }
2805 }
2806
Jamie Madillc29968b2016-01-20 11:17:23 -05002807 return true;
2808}
2809
Jamie Madill5b772312018-03-08 20:28:32 -05002810bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002811{
2812 if (!context->getExtensions().drawBuffers)
2813 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002814 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002815 return false;
2816 }
2817
2818 return ValidateDrawBuffersBase(context, n, bufs);
2819}
2820
Jamie Madill73a84962016-02-12 09:27:23 -05002821bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002822 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002823 GLint level,
2824 GLint internalformat,
2825 GLsizei width,
2826 GLsizei height,
2827 GLint border,
2828 GLenum format,
2829 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002830 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002831{
Martin Radev1be913c2016-07-11 17:59:16 +03002832 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002833 {
2834 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002835 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002836 }
2837
Martin Radev1be913c2016-07-11 17:59:16 +03002838 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002839 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002840 0, 0, width, height, 1, border, format, type, -1,
2841 pixels);
2842}
2843
Brandon Jones416aaf92018-04-10 08:10:16 -07002844bool ValidateTexImage2DRobustANGLE(Context *context,
2845 TextureTarget target,
2846 GLint level,
2847 GLint internalformat,
2848 GLsizei width,
2849 GLsizei height,
2850 GLint border,
2851 GLenum format,
2852 GLenum type,
2853 GLsizei bufSize,
2854 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04002855{
2856 if (!ValidateRobustEntryPoint(context, bufSize))
2857 {
2858 return false;
2859 }
2860
2861 if (context->getClientMajorVersion() < 3)
2862 {
2863 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
2864 0, 0, width, height, border, format, type, bufSize,
2865 pixels);
2866 }
2867
2868 ASSERT(context->getClientMajorVersion() >= 3);
2869 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
2870 0, 0, width, height, 1, border, format, type, bufSize,
2871 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002872}
2873
2874bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002875 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002876 GLint level,
2877 GLint xoffset,
2878 GLint yoffset,
2879 GLsizei width,
2880 GLsizei height,
2881 GLenum format,
2882 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002883 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002884{
2885
Martin Radev1be913c2016-07-11 17:59:16 +03002886 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002887 {
2888 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002889 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002890 }
2891
Martin Radev1be913c2016-07-11 17:59:16 +03002892 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002893 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002894 yoffset, 0, width, height, 1, 0, format, type, -1,
2895 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002896}
2897
Geoff Langc52f6f12016-10-14 10:18:00 -04002898bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002899 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04002900 GLint level,
2901 GLint xoffset,
2902 GLint yoffset,
2903 GLsizei width,
2904 GLsizei height,
2905 GLenum format,
2906 GLenum type,
2907 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002908 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04002909{
2910 if (!ValidateRobustEntryPoint(context, bufSize))
2911 {
2912 return false;
2913 }
2914
2915 if (context->getClientMajorVersion() < 3)
2916 {
2917 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
2918 yoffset, width, height, 0, format, type, bufSize,
2919 pixels);
2920 }
2921
2922 ASSERT(context->getClientMajorVersion() >= 3);
2923 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
2924 yoffset, 0, width, height, 1, 0, format, type, bufSize,
2925 pixels);
2926}
2927
Cody Northrop5faff912019-06-28 14:04:50 -06002928bool ValidateTexSubImage3DOES(Context *context,
2929 TextureTarget target,
2930 GLint level,
2931 GLint xoffset,
2932 GLint yoffset,
2933 GLint zoffset,
2934 GLsizei width,
2935 GLsizei height,
2936 GLsizei depth,
2937 GLenum format,
2938 GLenum type,
2939 const void *pixels)
2940{
2941 return ValidateTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, height,
2942 depth, format, type, pixels);
2943}
2944
Jamie Madill73a84962016-02-12 09:27:23 -05002945bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002946 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002947 GLint level,
2948 GLenum internalformat,
2949 GLsizei width,
2950 GLsizei height,
2951 GLint border,
2952 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002953 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002954{
Martin Radev1be913c2016-07-11 17:59:16 +03002955 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002956 {
2957 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002958 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002959 {
2960 return false;
2961 }
2962 }
2963 else
2964 {
Martin Radev1be913c2016-07-11 17:59:16 +03002965 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002966 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002967 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002968 data))
2969 {
2970 return false;
2971 }
2972 }
2973
Geoff Langca271392017-04-05 12:30:00 -04002974 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04002975
2976 GLuint blockSize = 0;
2977 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002978 {
Jamie Madille0472f32018-11-27 16:32:45 -05002979 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002980 return false;
2981 }
2982
Jamie Madillca2ff382018-07-11 09:01:17 -04002983 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002984 {
Jamie Madille0472f32018-11-27 16:32:45 -05002985 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05002986 return false;
2987 }
2988
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002989 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002990 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002991 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002992 return false;
2993 }
2994
Jamie Madill73a84962016-02-12 09:27:23 -05002995 return true;
2996}
2997
Corentin Wallezb2931602017-04-11 15:58:57 -04002998bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002999 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04003000 GLint level,
3001 GLenum internalformat,
3002 GLsizei width,
3003 GLsizei height,
3004 GLint border,
3005 GLsizei imageSize,
3006 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003007 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003008{
3009 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3010 {
3011 return false;
3012 }
3013
3014 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
3015 border, imageSize, data);
3016}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003017
Cody Northrop5faff912019-06-28 14:04:50 -06003018bool ValidateCompressedTexImage3DOES(Context *context,
3019 TextureTarget target,
3020 GLint level,
3021 GLenum internalformat,
3022 GLsizei width,
3023 GLsizei height,
3024 GLsizei depth,
3025 GLint border,
3026 GLsizei imageSize,
3027 const void *data)
3028{
3029 return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height,
3030 depth, border, imageSize, data);
3031}
3032
Corentin Wallezb2931602017-04-11 15:58:57 -04003033bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003034 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04003035 GLint level,
3036 GLint xoffset,
3037 GLint yoffset,
3038 GLsizei width,
3039 GLsizei height,
3040 GLenum format,
3041 GLsizei imageSize,
3042 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003043 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003044{
3045 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3046 {
3047 return false;
3048 }
3049
3050 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
3051 format, imageSize, data);
3052}
3053
Jamie Madill73a84962016-02-12 09:27:23 -05003054bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003055 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003056 GLint level,
3057 GLint xoffset,
3058 GLint yoffset,
3059 GLsizei width,
3060 GLsizei height,
3061 GLenum format,
3062 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003063 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003064{
Martin Radev1be913c2016-07-11 17:59:16 +03003065 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05003066 {
3067 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003068 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05003069 {
3070 return false;
3071 }
3072 }
3073 else
3074 {
Martin Radev1be913c2016-07-11 17:59:16 +03003075 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003076 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003077 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05003078 data))
3079 {
3080 return false;
3081 }
3082 }
3083
Geoff Langca271392017-04-05 12:30:00 -04003084 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04003085 GLuint blockSize = 0;
3086 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003087 {
Jamie Madille0472f32018-11-27 16:32:45 -05003088 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003089 return false;
3090 }
3091
Jamie Madillca2ff382018-07-11 09:01:17 -04003092 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003093 {
Jamie Madille0472f32018-11-27 16:32:45 -05003094 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05003095 return false;
3096 }
3097
3098 return true;
3099}
3100
Cody Northrop5faff912019-06-28 14:04:50 -06003101bool ValidateCompressedTexSubImage3DOES(Context *context,
3102 TextureTarget target,
3103 GLint level,
3104 GLint xoffset,
3105 GLint yoffset,
3106 GLint zoffset,
3107 GLsizei width,
3108 GLsizei height,
3109 GLsizei depth,
3110 GLenum format,
3111 GLsizei imageSize,
3112 const void *data)
3113{
3114 return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width,
3115 height, depth, format, imageSize, data);
3116}
3117
Corentin Wallez336129f2017-10-17 15:55:40 -04003118bool ValidateGetBufferPointervOES(Context *context,
3119 BufferBinding target,
3120 GLenum pname,
3121 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003122{
Jamie Madillc3e37312018-11-30 15:25:39 -05003123 if (!context->getExtensions().mapBuffer)
3124 {
3125 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3126 return false;
3127 }
3128
Geoff Lang496c02d2016-10-20 11:38:11 -07003129 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003130}
3131
Corentin Wallez336129f2017-10-17 15:55:40 -04003132bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003133{
3134 if (!context->getExtensions().mapBuffer)
3135 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003136 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003137 return false;
3138 }
3139
Corentin Walleze4477002017-12-01 14:39:58 -05003140 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03003141 {
Jamie Madille0472f32018-11-27 16:32:45 -05003142 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03003143 return false;
3144 }
3145
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003146 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003147
3148 if (buffer == nullptr)
3149 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003150 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03003151 return false;
3152 }
3153
3154 if (access != GL_WRITE_ONLY_OES)
3155 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003156 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03003157 return false;
3158 }
3159
3160 if (buffer->isMapped())
3161 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003162 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003163 return false;
3164 }
3165
Geoff Lang79f71042017-08-14 16:43:43 -04003166 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003167}
3168
Corentin Wallez336129f2017-10-17 15:55:40 -04003169bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003170{
3171 if (!context->getExtensions().mapBuffer)
3172 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003173 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003174 return false;
3175 }
3176
3177 return ValidateUnmapBufferBase(context, target);
3178}
3179
3180bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003181 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003182 GLintptr offset,
3183 GLsizeiptr length,
3184 GLbitfield access)
3185{
3186 if (!context->getExtensions().mapBufferRange)
3187 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003188 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003189 return false;
3190 }
3191
3192 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3193}
3194
Michael Spang7a8c3e52019-04-03 14:49:57 -04003195bool ValidateBufferStorageMemEXT(Context *context,
3196 TextureType target,
3197 GLsizeiptr size,
3198 GLuint memory,
3199 GLuint64 offset)
3200{
3201 if (!context->getExtensions().memoryObject)
3202 {
3203 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3204 return false;
3205 }
3206
3207 UNIMPLEMENTED();
3208 return false;
3209}
3210
3211bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects)
3212{
3213 if (!context->getExtensions().memoryObject)
3214 {
3215 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3216 return false;
3217 }
3218
Michael Spangfb201c52019-04-03 14:57:35 -04003219 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003220}
3221
3222bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects)
3223{
3224 if (!context->getExtensions().memoryObject)
3225 {
3226 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3227 return false;
3228 }
3229
Michael Spangfb201c52019-04-03 14:57:35 -04003230 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003231}
3232
3233bool ValidateGetMemoryObjectParameterivEXT(Context *context,
3234 GLuint memoryObject,
3235 GLenum pname,
3236 GLint *params)
3237{
3238 if (!context->getExtensions().memoryObject)
3239 {
3240 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3241 return false;
3242 }
3243
3244 UNIMPLEMENTED();
3245 return false;
3246}
3247
3248bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3249{
3250 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3251 {
3252 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3253 return false;
3254 }
3255
3256 UNIMPLEMENTED();
3257 return false;
3258}
3259
3260bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3261{
3262 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3263 {
3264 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3265 return false;
3266 }
3267
3268 UNIMPLEMENTED();
3269 return false;
3270}
3271
3272bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject)
3273{
3274 if (!context->getExtensions().memoryObject)
3275 {
3276 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3277 return false;
3278 }
3279
Michael Spangfb201c52019-04-03 14:57:35 -04003280 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003281}
3282
3283bool ValidateMemoryObjectParameterivEXT(Context *context,
3284 GLuint memoryObject,
3285 GLenum pname,
3286 const GLint *params)
3287{
3288 if (!context->getExtensions().memoryObject)
3289 {
3290 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3291 return false;
3292 }
3293
3294 UNIMPLEMENTED();
3295 return false;
3296}
3297
3298bool ValidateTexStorageMem2DEXT(Context *context,
3299 TextureType target,
3300 GLsizei levels,
3301 GLenum internalFormat,
3302 GLsizei width,
3303 GLsizei height,
3304 GLuint memory,
3305 GLuint64 offset)
3306{
3307 if (!context->getExtensions().memoryObject)
3308 {
3309 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3310 return false;
3311 }
3312
Michael Spangf02a7672019-04-09 18:45:23 -04003313 if (context->getClientMajorVersion() < 3)
3314 {
3315 return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width,
3316 height);
3317 }
3318
3319 ASSERT(context->getClientMajorVersion() >= 3);
3320 return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height,
3321 1);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003322}
3323
3324bool ValidateTexStorageMem3DEXT(Context *context,
3325 TextureType target,
3326 GLsizei levels,
3327 GLenum internalFormat,
3328 GLsizei width,
3329 GLsizei height,
3330 GLsizei depth,
3331 GLuint memory,
3332 GLuint64 offset)
3333{
3334 if (!context->getExtensions().memoryObject)
3335 {
3336 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3337 return false;
3338 }
3339
3340 UNIMPLEMENTED();
3341 return false;
3342}
3343
Michael Spang9de3ddb2019-04-03 16:23:40 -04003344bool ValidateImportMemoryFdEXT(Context *context,
3345 GLuint memory,
3346 GLuint64 size,
Michael Spange0da9ce2019-04-16 14:34:51 -04003347 HandleType handleType,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003348 GLint fd)
3349{
3350 if (!context->getExtensions().memoryObjectFd)
3351 {
3352 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3353 return false;
3354 }
3355
Michael Spang3b2c6bf2019-04-16 17:19:50 -04003356 switch (handleType)
3357 {
3358 case HandleType::OpaqueFd:
3359 break;
3360 default:
3361 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3362 return false;
3363 }
3364
3365 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003366}
3367
Michael Spang7a8c3e52019-04-03 14:49:57 -04003368bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores)
3369{
3370 if (!context->getExtensions().semaphore)
3371 {
3372 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3373 return false;
3374 }
3375
Michael Spang5093ba62019-05-14 17:36:36 -04003376 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003377}
3378
3379bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores)
3380{
3381 if (!context->getExtensions().semaphore)
3382 {
3383 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3384 return false;
3385 }
3386
Michael Spang5093ba62019-05-14 17:36:36 -04003387 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003388}
3389
3390bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
3391 GLuint semaphore,
3392 GLenum pname,
3393 GLuint64 *params)
3394{
3395 if (!context->getExtensions().semaphore)
3396 {
3397 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3398 return false;
3399 }
3400
3401 UNIMPLEMENTED();
3402 return false;
3403}
3404
3405bool ValidateIsSemaphoreEXT(Context *context, GLuint semaphore)
3406{
3407 if (!context->getExtensions().semaphore)
3408 {
3409 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3410 return false;
3411 }
3412
Michael Spang5093ba62019-05-14 17:36:36 -04003413 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003414}
3415
3416bool ValidateSemaphoreParameterui64vEXT(Context *context,
3417 GLuint semaphore,
3418 GLenum pname,
3419 const GLuint64 *params)
3420{
3421 if (!context->getExtensions().semaphore)
3422 {
3423 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3424 return false;
3425 }
3426
3427 UNIMPLEMENTED();
3428 return false;
3429}
3430
3431bool ValidateSignalSemaphoreEXT(Context *context,
3432 GLuint semaphore,
3433 GLuint numBufferBarriers,
3434 const GLuint *buffers,
3435 GLuint numTextureBarriers,
3436 const GLuint *textures,
3437 const GLenum *dstLayouts)
3438{
3439 if (!context->getExtensions().semaphore)
3440 {
3441 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3442 return false;
3443 }
3444
Michael Spangab6a59b2019-05-21 21:26:26 -04003445 for (GLuint i = 0; i < numTextureBarriers; ++i)
3446 {
3447 if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i])))
3448 {
3449 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3450 return false;
3451 }
3452 }
3453
3454 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003455}
3456
3457bool ValidateWaitSemaphoreEXT(Context *context,
3458 GLuint semaphore,
3459 GLuint numBufferBarriers,
3460 const GLuint *buffers,
3461 GLuint numTextureBarriers,
3462 const GLuint *textures,
3463 const GLenum *srcLayouts)
3464{
3465 if (!context->getExtensions().semaphore)
3466 {
3467 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3468 return false;
3469 }
3470
Michael Spangab6a59b2019-05-21 21:26:26 -04003471 for (GLuint i = 0; i < numTextureBarriers; ++i)
3472 {
3473 if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i])))
3474 {
3475 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3476 return false;
3477 }
3478 }
3479
3480 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003481}
3482
Michael Spange0da9ce2019-04-16 14:34:51 -04003483bool ValidateImportSemaphoreFdEXT(Context *context,
3484 GLuint semaphore,
3485 HandleType handleType,
3486 GLint fd)
Michael Spang9de3ddb2019-04-03 16:23:40 -04003487{
3488 if (!context->getExtensions().semaphoreFd)
3489 {
3490 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3491 return false;
3492 }
3493
Michael Spang6bb193c2019-05-22 16:32:21 -04003494 switch (handleType)
3495 {
3496 case HandleType::OpaqueFd:
3497 break;
3498 default:
3499 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3500 return false;
3501 }
3502
3503 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003504}
3505
Corentin Wallez336129f2017-10-17 15:55:40 -04003506bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003507{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003508 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003509 ASSERT(buffer != nullptr);
3510
3511 // Check if this buffer is currently being used as a transform feedback output buffer
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003512 if (context->getState().isTransformFeedbackActive())
Geoff Lang79f71042017-08-14 16:43:43 -04003513 {
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003514 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003515 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3516 {
3517 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3518 if (transformFeedbackBuffer.get() == buffer)
3519 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003520 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003521 return false;
3522 }
3523 }
3524 }
3525
James Darpiniane8a93c62018-01-04 18:02:24 -08003526 if (context->getExtensions().webglCompatibility &&
3527 buffer->isBoundForTransformFeedbackAndOtherUse())
3528 {
Jamie Madille0472f32018-11-27 16:32:45 -05003529 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003530 return false;
3531 }
3532
Geoff Lang79f71042017-08-14 16:43:43 -04003533 return true;
3534}
3535
Olli Etuaho4f667482016-03-30 15:56:35 +03003536bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003537 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003538 GLintptr offset,
3539 GLsizeiptr length)
3540{
3541 if (!context->getExtensions().mapBufferRange)
3542 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003543 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003544 return false;
3545 }
3546
3547 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3548}
3549
Geoff Langd8605522016-04-13 10:19:12 -04003550bool ValidateBindUniformLocationCHROMIUM(Context *context,
3551 GLuint program,
3552 GLint location,
3553 const GLchar *name)
3554{
3555 if (!context->getExtensions().bindUniformLocation)
3556 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003557 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003558 return false;
3559 }
3560
3561 Program *programObject = GetValidProgram(context, program);
3562 if (!programObject)
3563 {
3564 return false;
3565 }
3566
3567 if (location < 0)
3568 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003569 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003570 return false;
3571 }
3572
3573 const Caps &caps = context->getCaps();
3574 if (static_cast<size_t>(location) >=
3575 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3576 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003577 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003578 return false;
3579 }
3580
Geoff Langfc32e8b2017-05-31 14:16:59 -04003581 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3582 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003583 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003584 {
Jamie Madille0472f32018-11-27 16:32:45 -05003585 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003586 return false;
3587 }
3588
Geoff Langd8605522016-04-13 10:19:12 -04003589 if (strncmp(name, "gl_", 3) == 0)
3590 {
Jamie Madille0472f32018-11-27 16:32:45 -05003591 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003592 return false;
3593 }
3594
3595 return true;
3596}
3597
Jamie Madille2e406c2016-06-02 13:04:10 -04003598bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003599{
3600 if (!context->getExtensions().framebufferMixedSamples)
3601 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003602 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003603 return false;
3604 }
3605 switch (components)
3606 {
3607 case GL_RGB:
3608 case GL_RGBA:
3609 case GL_ALPHA:
3610 case GL_NONE:
3611 break;
3612 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003613 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003614 return false;
3615 }
3616
3617 return true;
3618}
3619
Sami Väisänene45e53b2016-05-25 10:36:04 +03003620// CHROMIUM_path_rendering
3621
Jamie Madill007530e2017-12-28 14:27:04 -05003622bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003623{
Jamie Madill007530e2017-12-28 14:27:04 -05003624 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003625 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003626 return false;
3627 }
Jamie Madill007530e2017-12-28 14:27:04 -05003628
Sami Väisänene45e53b2016-05-25 10:36:04 +03003629 if (matrix == nullptr)
3630 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003631 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003632 return false;
3633 }
Jamie Madill007530e2017-12-28 14:27:04 -05003634
Sami Väisänene45e53b2016-05-25 10:36:04 +03003635 return true;
3636}
3637
Jamie Madill007530e2017-12-28 14:27:04 -05003638bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003639{
Jamie Madill007530e2017-12-28 14:27:04 -05003640 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003641}
3642
Jamie Madill007530e2017-12-28 14:27:04 -05003643bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003644{
3645 if (!context->getExtensions().pathRendering)
3646 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003647 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003648 return false;
3649 }
3650
3651 // range = 0 is undefined in NV_path_rendering.
3652 // we add stricter semantic check here and require a non zero positive range.
3653 if (range <= 0)
3654 {
Jamie Madille0472f32018-11-27 16:32:45 -05003655 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003656 return false;
3657 }
3658
3659 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3660 {
Jamie Madille0472f32018-11-27 16:32:45 -05003661 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003662 return false;
3663 }
3664
3665 return true;
3666}
3667
Jamie Madill007530e2017-12-28 14:27:04 -05003668bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003669{
3670 if (!context->getExtensions().pathRendering)
3671 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003672 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003673 return false;
3674 }
3675
3676 // range = 0 is undefined in NV_path_rendering.
3677 // we add stricter semantic check here and require a non zero positive range.
3678 if (range <= 0)
3679 {
Jamie Madille0472f32018-11-27 16:32:45 -05003680 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003681 return false;
3682 }
3683
3684 angle::CheckedNumeric<std::uint32_t> checkedRange(path);
3685 checkedRange += range;
3686
3687 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3688 {
Jamie Madille0472f32018-11-27 16:32:45 -05003689 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003690 return false;
3691 }
3692 return true;
3693}
3694
Jamie Madill007530e2017-12-28 14:27:04 -05003695bool ValidatePathCommandsCHROMIUM(Context *context,
3696 GLuint path,
3697 GLsizei numCommands,
3698 const GLubyte *commands,
3699 GLsizei numCoords,
3700 GLenum coordType,
3701 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003702{
3703 if (!context->getExtensions().pathRendering)
3704 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003705 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003706 return false;
3707 }
Brandon Jones59770802018-04-02 13:18:42 -07003708 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003709 {
Jamie Madille0472f32018-11-27 16:32:45 -05003710 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003711 return false;
3712 }
3713
3714 if (numCommands < 0)
3715 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003716 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003717 return false;
3718 }
3719 else if (numCommands > 0)
3720 {
3721 if (!commands)
3722 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003723 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003724 return false;
3725 }
3726 }
3727
3728 if (numCoords < 0)
3729 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003730 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003731 return false;
3732 }
3733 else if (numCoords > 0)
3734 {
3735 if (!coords)
3736 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003737 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003738 return false;
3739 }
3740 }
3741
3742 std::uint32_t coordTypeSize = 0;
3743 switch (coordType)
3744 {
3745 case GL_BYTE:
3746 coordTypeSize = sizeof(GLbyte);
3747 break;
3748
3749 case GL_UNSIGNED_BYTE:
3750 coordTypeSize = sizeof(GLubyte);
3751 break;
3752
3753 case GL_SHORT:
3754 coordTypeSize = sizeof(GLshort);
3755 break;
3756
3757 case GL_UNSIGNED_SHORT:
3758 coordTypeSize = sizeof(GLushort);
3759 break;
3760
3761 case GL_FLOAT:
3762 coordTypeSize = sizeof(GLfloat);
3763 break;
3764
3765 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003766 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003767 return false;
3768 }
3769
3770 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3771 checkedSize += (coordTypeSize * numCoords);
3772 if (!checkedSize.IsValid())
3773 {
Jamie Madille0472f32018-11-27 16:32:45 -05003774 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003775 return false;
3776 }
3777
3778 // early return skips command data validation when it doesn't exist.
3779 if (!commands)
3780 return true;
3781
3782 GLsizei expectedNumCoords = 0;
3783 for (GLsizei i = 0; i < numCommands; ++i)
3784 {
3785 switch (commands[i])
3786 {
3787 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3788 break;
3789 case GL_MOVE_TO_CHROMIUM:
3790 case GL_LINE_TO_CHROMIUM:
3791 expectedNumCoords += 2;
3792 break;
3793 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3794 expectedNumCoords += 4;
3795 break;
3796 case GL_CUBIC_CURVE_TO_CHROMIUM:
3797 expectedNumCoords += 6;
3798 break;
3799 case GL_CONIC_CURVE_TO_CHROMIUM:
3800 expectedNumCoords += 5;
3801 break;
3802 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003803 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003804 return false;
3805 }
3806 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003807
Sami Väisänene45e53b2016-05-25 10:36:04 +03003808 if (expectedNumCoords != numCoords)
3809 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003810 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003811 return false;
3812 }
3813
3814 return true;
3815}
3816
Jamie Madill007530e2017-12-28 14:27:04 -05003817bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003818{
3819 if (!context->getExtensions().pathRendering)
3820 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003821 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003822 return false;
3823 }
Brandon Jones59770802018-04-02 13:18:42 -07003824 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003825 {
Jamie Madille0472f32018-11-27 16:32:45 -05003826 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003827 return false;
3828 }
3829
3830 switch (pname)
3831 {
3832 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3833 if (value < 0.0f)
3834 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003835 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003836 return false;
3837 }
3838 break;
3839 case GL_PATH_END_CAPS_CHROMIUM:
3840 switch (static_cast<GLenum>(value))
3841 {
3842 case GL_FLAT_CHROMIUM:
3843 case GL_SQUARE_CHROMIUM:
3844 case GL_ROUND_CHROMIUM:
3845 break;
3846 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003847 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003848 return false;
3849 }
3850 break;
3851 case GL_PATH_JOIN_STYLE_CHROMIUM:
3852 switch (static_cast<GLenum>(value))
3853 {
3854 case GL_MITER_REVERT_CHROMIUM:
3855 case GL_BEVEL_CHROMIUM:
3856 case GL_ROUND_CHROMIUM:
3857 break;
3858 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003859 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003860 return false;
3861 }
Nico Weber41b072b2018-02-09 10:01:32 -05003862 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03003863 case GL_PATH_MITER_LIMIT_CHROMIUM:
3864 if (value < 0.0f)
3865 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003866 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003867 return false;
3868 }
3869 break;
3870
3871 case GL_PATH_STROKE_BOUND_CHROMIUM:
3872 // no errors, only clamping.
3873 break;
3874
3875 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003876 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003877 return false;
3878 }
3879 return true;
3880}
3881
Jamie Madill007530e2017-12-28 14:27:04 -05003882bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value)
3883{
3884 // TODO(jmadill): Use proper clamping cast.
3885 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
3886}
3887
3888bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003889{
3890 if (!context->getExtensions().pathRendering)
3891 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003892 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003893 return false;
3894 }
3895
Brandon Jones59770802018-04-02 13:18:42 -07003896 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003897 {
Jamie Madille0472f32018-11-27 16:32:45 -05003898 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003899 return false;
3900 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003901
Sami Väisänene45e53b2016-05-25 10:36:04 +03003902 if (!value)
3903 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003904 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003905 return false;
3906 }
3907
3908 switch (pname)
3909 {
3910 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3911 case GL_PATH_END_CAPS_CHROMIUM:
3912 case GL_PATH_JOIN_STYLE_CHROMIUM:
3913 case GL_PATH_MITER_LIMIT_CHROMIUM:
3914 case GL_PATH_STROKE_BOUND_CHROMIUM:
3915 break;
3916
3917 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003918 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003919 return false;
3920 }
3921
3922 return true;
3923}
3924
Jamie Madill007530e2017-12-28 14:27:04 -05003925bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value)
3926{
3927 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
3928 reinterpret_cast<GLfloat *>(value));
3929}
3930
3931bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003932{
3933 if (!context->getExtensions().pathRendering)
3934 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003935 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003936 return false;
3937 }
3938
3939 switch (func)
3940 {
3941 case GL_NEVER:
3942 case GL_ALWAYS:
3943 case GL_LESS:
3944 case GL_LEQUAL:
3945 case GL_EQUAL:
3946 case GL_GEQUAL:
3947 case GL_GREATER:
3948 case GL_NOTEQUAL:
3949 break;
3950 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003951 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003952 return false;
3953 }
3954
3955 return true;
3956}
3957
3958// Note that the spec specifies that for the path drawing commands
3959// if the path object is not an existing path object the command
3960// does nothing and no error is generated.
3961// However if the path object exists but has not been specified any
3962// commands then an error is generated.
3963
Jamie Madill007530e2017-12-28 14:27:04 -05003964bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003965{
3966 if (!context->getExtensions().pathRendering)
3967 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003968 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003969 return false;
3970 }
Brandon Jones59770802018-04-02 13:18:42 -07003971 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003972 {
Jamie Madille0472f32018-11-27 16:32:45 -05003973 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003974 return false;
3975 }
3976
3977 switch (fillMode)
3978 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06003979 case GL_INVERT:
Sami Väisänene45e53b2016-05-25 10:36:04 +03003980 case GL_COUNT_UP_CHROMIUM:
3981 case GL_COUNT_DOWN_CHROMIUM:
3982 break;
3983 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003984 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003985 return false;
3986 }
3987
3988 if (!isPow2(mask + 1))
3989 {
Jamie Madille0472f32018-11-27 16:32:45 -05003990 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003991 return false;
3992 }
3993
3994 return true;
3995}
3996
Jamie Madill007530e2017-12-28 14:27:04 -05003997bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003998{
3999 if (!context->getExtensions().pathRendering)
4000 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004001 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004002 return false;
4003 }
Jamie Madillc3e37312018-11-30 15:25:39 -05004004
Brandon Jones59770802018-04-02 13:18:42 -07004005 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004006 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004007 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004008 return false;
4009 }
4010
4011 return true;
4012}
4013
Jamie Madill007530e2017-12-28 14:27:04 -05004014bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004015{
4016 if (!context->getExtensions().pathRendering)
4017 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004018 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004019 return false;
4020 }
Brandon Jones59770802018-04-02 13:18:42 -07004021 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004022 {
Jamie Madille0472f32018-11-27 16:32:45 -05004023 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004024 return false;
4025 }
4026
4027 switch (coverMode)
4028 {
4029 case GL_CONVEX_HULL_CHROMIUM:
4030 case GL_BOUNDING_BOX_CHROMIUM:
4031 break;
4032 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004033 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004034 return false;
4035 }
4036 return true;
4037}
4038
Jamie Madill778bf092018-11-14 09:54:36 -05004039bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
4040{
4041 return ValidateCoverPathCHROMIUM(context, path, coverMode);
4042}
4043
4044bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
4045{
4046 return ValidateCoverPathCHROMIUM(context, path, coverMode);
4047}
4048
Jamie Madill007530e2017-12-28 14:27:04 -05004049bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
4050 GLuint path,
4051 GLenum fillMode,
4052 GLuint mask,
4053 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004054{
Jamie Madill007530e2017-12-28 14:27:04 -05004055 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
4056 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004057}
4058
Jamie Madill007530e2017-12-28 14:27:04 -05004059bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
4060 GLuint path,
4061 GLint reference,
4062 GLuint mask,
4063 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004064{
Jamie Madill007530e2017-12-28 14:27:04 -05004065 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
4066 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004067}
4068
Brandon Jonesd1049182018-03-28 10:02:20 -07004069bool ValidateIsPathCHROMIUM(Context *context, GLuint path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004070{
4071 if (!context->getExtensions().pathRendering)
4072 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004073 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004074 return false;
4075 }
4076 return true;
4077}
4078
Jamie Madill007530e2017-12-28 14:27:04 -05004079bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
4080 GLsizei numPaths,
4081 GLenum pathNameType,
4082 const void *paths,
4083 GLuint pathBase,
4084 GLenum coverMode,
4085 GLenum transformType,
4086 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004087{
4088 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4089 transformType, transformValues))
4090 return false;
4091
4092 switch (coverMode)
4093 {
4094 case GL_CONVEX_HULL_CHROMIUM:
4095 case GL_BOUNDING_BOX_CHROMIUM:
4096 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4097 break;
4098 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004099 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004100 return false;
4101 }
4102
4103 return true;
4104}
4105
Jamie Madill007530e2017-12-28 14:27:04 -05004106bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
4107 GLsizei numPaths,
4108 GLenum pathNameType,
4109 const void *paths,
4110 GLuint pathBase,
4111 GLenum coverMode,
4112 GLenum transformType,
4113 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004114{
4115 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4116 transformType, transformValues))
4117 return false;
4118
4119 switch (coverMode)
4120 {
4121 case GL_CONVEX_HULL_CHROMIUM:
4122 case GL_BOUNDING_BOX_CHROMIUM:
4123 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4124 break;
4125 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004126 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004127 return false;
4128 }
4129
4130 return true;
4131}
4132
Jamie Madill007530e2017-12-28 14:27:04 -05004133bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
4134 GLsizei numPaths,
4135 GLenum pathNameType,
4136 const void *paths,
4137 GLuint pathBase,
4138 GLenum fillMode,
4139 GLuint mask,
4140 GLenum transformType,
4141 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004142{
4143
4144 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4145 transformType, transformValues))
4146 return false;
4147
4148 switch (fillMode)
4149 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004150 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004151 case GL_COUNT_UP_CHROMIUM:
4152 case GL_COUNT_DOWN_CHROMIUM:
4153 break;
4154 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004155 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004156 return false;
4157 }
4158 if (!isPow2(mask + 1))
4159 {
Jamie Madille0472f32018-11-27 16:32:45 -05004160 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004161 return false;
4162 }
4163 return true;
4164}
4165
Jamie Madill007530e2017-12-28 14:27:04 -05004166bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
4167 GLsizei numPaths,
4168 GLenum pathNameType,
4169 const void *paths,
4170 GLuint pathBase,
4171 GLint reference,
4172 GLuint mask,
4173 GLenum transformType,
4174 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004175{
4176 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4177 transformType, transformValues))
4178 return false;
4179
4180 // no more validation here.
4181
4182 return true;
4183}
4184
Jamie Madill007530e2017-12-28 14:27:04 -05004185bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
4186 GLsizei numPaths,
4187 GLenum pathNameType,
4188 const void *paths,
4189 GLuint pathBase,
4190 GLenum fillMode,
4191 GLuint mask,
4192 GLenum coverMode,
4193 GLenum transformType,
4194 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004195{
4196 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4197 transformType, transformValues))
4198 return false;
4199
4200 switch (coverMode)
4201 {
4202 case GL_CONVEX_HULL_CHROMIUM:
4203 case GL_BOUNDING_BOX_CHROMIUM:
4204 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4205 break;
4206 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004207 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004208 return false;
4209 }
4210
4211 switch (fillMode)
4212 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004213 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004214 case GL_COUNT_UP_CHROMIUM:
4215 case GL_COUNT_DOWN_CHROMIUM:
4216 break;
4217 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004218 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004219 return false;
4220 }
4221 if (!isPow2(mask + 1))
4222 {
Jamie Madille0472f32018-11-27 16:32:45 -05004223 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004224 return false;
4225 }
4226
4227 return true;
4228}
4229
Jamie Madill007530e2017-12-28 14:27:04 -05004230bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4231 GLsizei numPaths,
4232 GLenum pathNameType,
4233 const void *paths,
4234 GLuint pathBase,
4235 GLint reference,
4236 GLuint mask,
4237 GLenum coverMode,
4238 GLenum transformType,
4239 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004240{
4241 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4242 transformType, transformValues))
4243 return false;
4244
4245 switch (coverMode)
4246 {
4247 case GL_CONVEX_HULL_CHROMIUM:
4248 case GL_BOUNDING_BOX_CHROMIUM:
4249 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4250 break;
4251 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004252 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004253 return false;
4254 }
4255
4256 return true;
4257}
4258
Jamie Madill007530e2017-12-28 14:27:04 -05004259bool ValidateBindFragmentInputLocationCHROMIUM(Context *context,
4260 GLuint program,
4261 GLint location,
4262 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004263{
4264 if (!context->getExtensions().pathRendering)
4265 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004266 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004267 return false;
4268 }
4269
4270 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4271 if (location >= MaxLocation)
4272 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004273 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004274 return false;
4275 }
4276
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004277 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004278 if (!programObject)
4279 {
Jamie Madille0472f32018-11-27 16:32:45 -05004280 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004281 return false;
4282 }
4283
4284 if (!name)
4285 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004286 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004287 return false;
4288 }
4289
4290 if (angle::BeginsWith(name, "gl_"))
4291 {
Jamie Madille0472f32018-11-27 16:32:45 -05004292 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004293 return false;
4294 }
4295
4296 return true;
4297}
4298
Jamie Madill007530e2017-12-28 14:27:04 -05004299bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
4300 GLuint program,
4301 GLint location,
4302 GLenum genMode,
4303 GLint components,
4304 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004305{
4306 if (!context->getExtensions().pathRendering)
4307 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004308 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004309 return false;
4310 }
4311
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004312 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004313 if (!programObject || programObject->isFlaggedForDeletion())
4314 {
Jamie Madille0472f32018-11-27 16:32:45 -05004315 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004316 return false;
4317 }
4318
4319 if (!programObject->isLinked())
4320 {
Jamie Madille0472f32018-11-27 16:32:45 -05004321 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004322 return false;
4323 }
4324
4325 switch (genMode)
4326 {
4327 case GL_NONE:
4328 if (components != 0)
4329 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004330 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004331 return false;
4332 }
4333 break;
4334
4335 case GL_OBJECT_LINEAR_CHROMIUM:
4336 case GL_EYE_LINEAR_CHROMIUM:
4337 case GL_CONSTANT_CHROMIUM:
4338 if (components < 1 || components > 4)
4339 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004340 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004341 return false;
4342 }
4343 if (!coeffs)
4344 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004345 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004346 return false;
4347 }
4348 break;
4349
4350 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004351 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004352 return false;
4353 }
4354
4355 // If the location is -1 then the command is silently ignored
4356 // and no further validation is needed.
4357 if (location == -1)
4358 return true;
4359
jchen103fd614d2018-08-13 12:21:58 +08004360 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004361
4362 if (!binding.valid)
4363 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004364 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004365 return false;
4366 }
4367
4368 if (binding.type != GL_NONE)
4369 {
4370 GLint expectedComponents = 0;
4371 switch (binding.type)
4372 {
4373 case GL_FLOAT:
4374 expectedComponents = 1;
4375 break;
4376 case GL_FLOAT_VEC2:
4377 expectedComponents = 2;
4378 break;
4379 case GL_FLOAT_VEC3:
4380 expectedComponents = 3;
4381 break;
4382 case GL_FLOAT_VEC4:
4383 expectedComponents = 4;
4384 break;
4385 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004386 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004387 return false;
4388 }
4389 if (expectedComponents != components && genMode != GL_NONE)
4390 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004391 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004392 return false;
4393 }
4394 }
4395 return true;
4396}
4397
Geoff Lang97073d12016-04-20 10:42:34 -07004398bool ValidateCopyTextureCHROMIUM(Context *context,
4399 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004400 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004401 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004402 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004403 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004404 GLint internalFormat,
4405 GLenum destType,
4406 GLboolean unpackFlipY,
4407 GLboolean unpackPremultiplyAlpha,
4408 GLboolean unpackUnmultiplyAlpha)
4409{
4410 if (!context->getExtensions().copyTexture)
4411 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004412 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004413 return false;
4414 }
4415
Geoff Lang4f0e0032017-05-01 16:04:35 -04004416 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004417 if (source == nullptr)
4418 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004419 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004420 return false;
4421 }
4422
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004423 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004424 {
Jamie Madille0472f32018-11-27 16:32:45 -05004425 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004426 return false;
4427 }
4428
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004429 TextureType sourceType = source->getType();
4430 ASSERT(sourceType != TextureType::CubeMap);
4431 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004432
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004433 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004434 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004435 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004436 return false;
4437 }
4438
Geoff Lang4f0e0032017-05-01 16:04:35 -04004439 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4440 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4441 if (sourceWidth == 0 || sourceHeight == 0)
4442 {
Jamie Madille0472f32018-11-27 16:32:45 -05004443 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004444 return false;
4445 }
4446
4447 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4448 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004449 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004450 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004451 return false;
4452 }
4453
Geoff Lang63458a32017-10-30 15:16:53 -04004454 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4455 {
Jamie Madille0472f32018-11-27 16:32:45 -05004456 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004457 return false;
4458 }
4459
Geoff Lang4f0e0032017-05-01 16:04:35 -04004460 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004461 if (dest == nullptr)
4462 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004463 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004464 return false;
4465 }
4466
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004467 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004468 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004469 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004470 return false;
4471 }
4472
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004473 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004474 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004475 {
Jamie Madille0472f32018-11-27 16:32:45 -05004476 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004477 return false;
4478 }
4479
Geoff Lang97073d12016-04-20 10:42:34 -07004480 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4481 {
Geoff Lang97073d12016-04-20 10:42:34 -07004482 return false;
4483 }
4484
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004485 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004486 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004487 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004488 return false;
4489 }
4490
Geoff Lang97073d12016-04-20 10:42:34 -07004491 if (dest->getImmutableFormat())
4492 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004493 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004494 return false;
4495 }
4496
4497 return true;
4498}
4499
4500bool ValidateCopySubTextureCHROMIUM(Context *context,
4501 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004502 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004503 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004504 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004505 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004506 GLint xoffset,
4507 GLint yoffset,
4508 GLint x,
4509 GLint y,
4510 GLsizei width,
4511 GLsizei height,
4512 GLboolean unpackFlipY,
4513 GLboolean unpackPremultiplyAlpha,
4514 GLboolean unpackUnmultiplyAlpha)
4515{
4516 if (!context->getExtensions().copyTexture)
4517 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004518 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004519 return false;
4520 }
4521
Geoff Lang4f0e0032017-05-01 16:04:35 -04004522 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004523 if (source == nullptr)
4524 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004525 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004526 return false;
4527 }
4528
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004529 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004530 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004531 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004532 return false;
4533 }
4534
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004535 TextureType sourceType = source->getType();
4536 ASSERT(sourceType != TextureType::CubeMap);
4537 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004538
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004539 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004540 {
Jamie Madille0472f32018-11-27 16:32:45 -05004541 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004542 return false;
4543 }
4544
4545 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4546 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004547 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004548 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004549 return false;
4550 }
4551
4552 if (x < 0 || y < 0)
4553 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004554 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004555 return false;
4556 }
4557
4558 if (width < 0 || height < 0)
4559 {
Jamie Madille0472f32018-11-27 16:32:45 -05004560 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004561 return false;
4562 }
4563
Geoff Lang4f0e0032017-05-01 16:04:35 -04004564 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4565 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004566 {
Jamie Madille0472f32018-11-27 16:32:45 -05004567 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004568 return false;
4569 }
4570
Geoff Lang4f0e0032017-05-01 16:04:35 -04004571 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4572 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004573 {
Jamie Madille0472f32018-11-27 16:32:45 -05004574 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004575 return false;
4576 }
4577
Geoff Lang63458a32017-10-30 15:16:53 -04004578 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4579 {
Jamie Madille0472f32018-11-27 16:32:45 -05004580 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004581 return false;
4582 }
4583
Geoff Lang4f0e0032017-05-01 16:04:35 -04004584 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004585 if (dest == nullptr)
4586 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004587 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004588 return false;
4589 }
4590
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004591 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004592 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004593 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004594 return false;
4595 }
4596
Brandon Jones28783792018-03-05 09:37:32 -08004597 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4598 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004599 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004600 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004601 return false;
4602 }
4603
Geoff Lang4f0e0032017-05-01 16:04:35 -04004604 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4605 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004606 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004607 return false;
4608 }
4609
4610 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4611 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004612 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004613 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004614 return false;
4615 }
4616
4617 if (xoffset < 0 || yoffset < 0)
4618 {
Jamie Madille0472f32018-11-27 16:32:45 -05004619 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004620 return false;
4621 }
4622
Geoff Lang4f0e0032017-05-01 16:04:35 -04004623 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4624 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004625 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004626 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004627 return false;
4628 }
4629
4630 return true;
4631}
4632
Geoff Lang47110bf2016-04-20 11:13:22 -07004633bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId)
4634{
4635 if (!context->getExtensions().copyCompressedTexture)
4636 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004637 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004638 return false;
4639 }
4640
4641 const gl::Texture *source = context->getTexture(sourceId);
4642 if (source == nullptr)
4643 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004644 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004645 return false;
4646 }
4647
Corentin Wallez99d492c2018-02-27 15:17:10 -05004648 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004649 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004650 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004651 return false;
4652 }
4653
Corentin Wallez99d492c2018-02-27 15:17:10 -05004654 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4655 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004656 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004657 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004658 return false;
4659 }
4660
Corentin Wallez99d492c2018-02-27 15:17:10 -05004661 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004662 if (!sourceFormat.info->compressed)
4663 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004664 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004665 return false;
4666 }
4667
4668 const gl::Texture *dest = context->getTexture(destId);
4669 if (dest == nullptr)
4670 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004671 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004672 return false;
4673 }
4674
Corentin Wallez99d492c2018-02-27 15:17:10 -05004675 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004676 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004677 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004678 return false;
4679 }
4680
4681 if (dest->getImmutableFormat())
4682 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004683 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004684 return false;
4685 }
4686
4687 return true;
4688}
4689
Jiawei Shao385b3e02018-03-21 09:43:28 +08004690bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004691{
4692 switch (type)
4693 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004694 case ShaderType::Vertex:
4695 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004696 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004697
Jiawei Shao385b3e02018-03-21 09:43:28 +08004698 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004699 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004700 {
Jamie Madille0472f32018-11-27 16:32:45 -05004701 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004702 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004703 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004704 break;
4705
Jiawei Shao385b3e02018-03-21 09:43:28 +08004706 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004707 if (!context->getExtensions().geometryShader)
4708 {
Jamie Madille0472f32018-11-27 16:32:45 -05004709 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004710 return false;
4711 }
4712 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004713 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004714 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004715 return false;
4716 }
Jamie Madill29639852016-09-02 15:00:09 -04004717
4718 return true;
4719}
4720
Jamie Madill5b772312018-03-08 20:28:32 -05004721bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004722 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004723 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004724 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004725 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004726{
4727 if (size < 0)
4728 {
Jamie Madille0472f32018-11-27 16:32:45 -05004729 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004730 return false;
4731 }
4732
4733 switch (usage)
4734 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004735 case BufferUsage::StreamDraw:
4736 case BufferUsage::StaticDraw:
4737 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004738 break;
4739
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004740 case BufferUsage::StreamRead:
4741 case BufferUsage::StaticRead:
4742 case BufferUsage::DynamicRead:
4743 case BufferUsage::StreamCopy:
4744 case BufferUsage::StaticCopy:
4745 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004746 if (context->getClientMajorVersion() < 3)
4747 {
Jamie Madille0472f32018-11-27 16:32:45 -05004748 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004749 return false;
4750 }
4751 break;
4752
4753 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004754 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004755 return false;
4756 }
4757
Corentin Walleze4477002017-12-01 14:39:58 -05004758 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004759 {
Jamie Madille0472f32018-11-27 16:32:45 -05004760 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004761 return false;
4762 }
4763
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004764 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004765
4766 if (!buffer)
4767 {
Jamie Madille0472f32018-11-27 16:32:45 -05004768 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004769 return false;
4770 }
4771
James Darpiniane8a93c62018-01-04 18:02:24 -08004772 if (context->getExtensions().webglCompatibility &&
4773 buffer->isBoundForTransformFeedbackAndOtherUse())
4774 {
Jamie Madille0472f32018-11-27 16:32:45 -05004775 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004776 return false;
4777 }
4778
Jamie Madill29639852016-09-02 15:00:09 -04004779 return true;
4780}
4781
Jamie Madill5b772312018-03-08 20:28:32 -05004782bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004783 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004784 GLintptr offset,
4785 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004786 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004787{
Brandon Jones6cad5662017-06-14 13:25:13 -07004788 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004789 {
Jamie Madille0472f32018-11-27 16:32:45 -05004790 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004791 return false;
4792 }
4793
4794 if (offset < 0)
4795 {
Jamie Madille0472f32018-11-27 16:32:45 -05004796 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004797 return false;
4798 }
4799
Corentin Walleze4477002017-12-01 14:39:58 -05004800 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004801 {
Jamie Madille0472f32018-11-27 16:32:45 -05004802 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004803 return false;
4804 }
4805
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004806 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004807
4808 if (!buffer)
4809 {
Jamie Madille0472f32018-11-27 16:32:45 -05004810 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004811 return false;
4812 }
4813
4814 if (buffer->isMapped())
4815 {
Jamie Madille0472f32018-11-27 16:32:45 -05004816 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004817 return false;
4818 }
4819
James Darpiniane8a93c62018-01-04 18:02:24 -08004820 if (context->getExtensions().webglCompatibility &&
4821 buffer->isBoundForTransformFeedbackAndOtherUse())
4822 {
Jamie Madille0472f32018-11-27 16:32:45 -05004823 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004824 return false;
4825 }
4826
Jamie Madill29639852016-09-02 15:00:09 -04004827 // Check for possible overflow of size + offset
4828 angle::CheckedNumeric<size_t> checkedSize(size);
4829 checkedSize += offset;
4830 if (!checkedSize.IsValid())
4831 {
Jamie Madille0472f32018-11-27 16:32:45 -05004832 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004833 return false;
4834 }
4835
4836 if (size + offset > buffer->getSize())
4837 {
Jamie Madille0472f32018-11-27 16:32:45 -05004838 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004839 return false;
4840 }
4841
Martin Radev4c4c8e72016-08-04 12:25:34 +03004842 return true;
4843}
4844
Geoff Lang111a99e2017-10-17 10:58:41 -04004845bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04004846{
Geoff Langc339c4e2016-11-29 10:37:36 -05004847 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04004848 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004849 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04004850 return false;
4851 }
4852
Geoff Lang111a99e2017-10-17 10:58:41 -04004853 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04004854 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004855 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04004856 return false;
4857 }
4858
4859 return true;
4860}
4861
Jamie Madill5b772312018-03-08 20:28:32 -05004862bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04004863{
Lingfeng Yang038dd532018-03-29 17:31:52 -07004864 if (context->getClientMajorVersion() < 2)
4865 {
4866 return ValidateMultitextureUnit(context, texture);
4867 }
4868
Jamie Madillef300b12016-10-07 15:12:09 -04004869 if (texture < GL_TEXTURE0 ||
4870 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
4871 {
Jamie Madille0472f32018-11-27 16:32:45 -05004872 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04004873 return false;
4874 }
4875
4876 return true;
4877}
4878
Jamie Madill5b772312018-03-08 20:28:32 -05004879bool ValidateAttachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillef300b12016-10-07 15:12:09 -04004880{
4881 Program *programObject = GetValidProgram(context, program);
4882 if (!programObject)
4883 {
4884 return false;
4885 }
4886
4887 Shader *shaderObject = GetValidShader(context, shader);
4888 if (!shaderObject)
4889 {
4890 return false;
4891 }
4892
Jiawei Shao385b3e02018-03-21 09:43:28 +08004893 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04004894 {
Jamie Madille0472f32018-11-27 16:32:45 -05004895 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08004896 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04004897 }
4898
4899 return true;
4900}
4901
Jamie Madill5b772312018-03-08 20:28:32 -05004902bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004903{
4904 if (index >= MAX_VERTEX_ATTRIBS)
4905 {
Jamie Madille0472f32018-11-27 16:32:45 -05004906 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004907 return false;
4908 }
4909
4910 if (strncmp(name, "gl_", 3) == 0)
4911 {
Jamie Madille0472f32018-11-27 16:32:45 -05004912 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004913 return false;
4914 }
4915
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004916 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04004917 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004918 const size_t length = strlen(name);
4919
4920 if (!IsValidESSLString(name, length))
4921 {
4922 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
4923 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05004924 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004925 return false;
4926 }
4927
4928 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
4929 {
4930 return false;
4931 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04004932 }
4933
Jamie Madill01a80ee2016-11-07 12:06:18 -05004934 return GetValidProgram(context, program) != nullptr;
4935}
4936
Jamie Madill5b772312018-03-08 20:28:32 -05004937bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004938{
Geoff Lange8afa902017-09-27 15:00:43 -04004939 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05004940 {
Jamie Madille0472f32018-11-27 16:32:45 -05004941 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004942 return false;
4943 }
4944
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004945 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004946 !context->isFramebufferGenerated(framebuffer))
4947 {
Jamie Madille0472f32018-11-27 16:32:45 -05004948 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004949 return false;
4950 }
4951
4952 return true;
4953}
4954
Jamie Madill7c7dec02019-08-06 17:44:11 -04004955bool ValidateBindRenderbuffer(Context *context, GLenum target, RenderbufferID renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004956{
4957 if (target != GL_RENDERBUFFER)
4958 {
Jamie Madille0472f32018-11-27 16:32:45 -05004959 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004960 return false;
4961 }
4962
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004963 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004964 !context->isRenderbufferGenerated(renderbuffer))
4965 {
Jamie Madille0472f32018-11-27 16:32:45 -05004966 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004967 return false;
4968 }
4969
4970 return true;
4971}
4972
Jamie Madill5b772312018-03-08 20:28:32 -05004973static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004974{
4975 switch (mode)
4976 {
4977 case GL_FUNC_ADD:
4978 case GL_FUNC_SUBTRACT:
4979 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04004980 return true;
4981
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004982 case GL_MIN:
4983 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04004984 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004985
4986 default:
4987 return false;
4988 }
4989}
4990
Jamie Madill5b772312018-03-08 20:28:32 -05004991bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004992{
4993 return true;
4994}
4995
Jamie Madill5b772312018-03-08 20:28:32 -05004996bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004997{
Geoff Lang50cac572017-09-26 17:37:43 -04004998 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004999 {
Jamie Madille0472f32018-11-27 16:32:45 -05005000 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005001 return false;
5002 }
5003
5004 return true;
5005}
5006
Jamie Madill5b772312018-03-08 20:28:32 -05005007bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005008{
Geoff Lang50cac572017-09-26 17:37:43 -04005009 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005010 {
Jamie Madille0472f32018-11-27 16:32:45 -05005011 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005012 return false;
5013 }
5014
Geoff Lang50cac572017-09-26 17:37:43 -04005015 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005016 {
Jamie Madille0472f32018-11-27 16:32:45 -05005017 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005018 return false;
5019 }
5020
5021 return true;
5022}
5023
Jamie Madill5b772312018-03-08 20:28:32 -05005024bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005025{
5026 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
5027}
5028
Jamie Madill5b772312018-03-08 20:28:32 -05005029bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005030 GLenum srcRGB,
5031 GLenum dstRGB,
5032 GLenum srcAlpha,
5033 GLenum dstAlpha)
5034{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005035 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005036 {
Jamie Madille0472f32018-11-27 16:32:45 -05005037 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005038 return false;
5039 }
5040
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005041 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005042 {
Jamie Madille0472f32018-11-27 16:32:45 -05005043 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005044 return false;
5045 }
5046
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005047 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005048 {
Jamie Madille0472f32018-11-27 16:32:45 -05005049 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005050 return false;
5051 }
5052
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005053 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005054 {
Jamie Madille0472f32018-11-27 16:32:45 -05005055 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005056 return false;
5057 }
5058
Frank Henigman146e8a12017-03-02 23:22:37 -05005059 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
5060 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005061 {
5062 bool constantColorUsed =
5063 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
5064 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
5065
5066 bool constantAlphaUsed =
5067 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
5068 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
5069
5070 if (constantColorUsed && constantAlphaUsed)
5071 {
Frank Henigman146e8a12017-03-02 23:22:37 -05005072 if (context->getExtensions().webglCompatibility)
5073 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005074 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
5075 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05005076 }
Jamie Madillc3e37312018-11-30 15:25:39 -05005077
5078 WARN() << kConstantColorAlphaLimitation;
5079 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005080 return false;
5081 }
5082 }
5083
5084 return true;
5085}
5086
Geoff Langc339c4e2016-11-29 10:37:36 -05005087bool ValidateGetString(Context *context, GLenum name)
5088{
5089 switch (name)
5090 {
5091 case GL_VENDOR:
5092 case GL_RENDERER:
5093 case GL_VERSION:
5094 case GL_SHADING_LANGUAGE_VERSION:
5095 case GL_EXTENSIONS:
5096 break;
5097
5098 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
5099 if (!context->getExtensions().requestExtension)
5100 {
Jamie Madille0472f32018-11-27 16:32:45 -05005101 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005102 return false;
5103 }
5104 break;
5105
5106 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005107 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005108 return false;
5109 }
5110
5111 return true;
5112}
5113
Jamie Madill5b772312018-03-08 20:28:32 -05005114bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05005115{
5116 if (width <= 0.0f || isNaN(width))
5117 {
Jamie Madille0472f32018-11-27 16:32:45 -05005118 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05005119 return false;
5120 }
5121
5122 return true;
5123}
5124
Jamie Madill5b772312018-03-08 20:28:32 -05005125bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05005126{
5127 if (context->getExtensions().webglCompatibility && zNear > zFar)
5128 {
Jamie Madille0472f32018-11-27 16:32:45 -05005129 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05005130 return false;
5131 }
5132
5133 return true;
5134}
5135
Jamie Madill5b772312018-03-08 20:28:32 -05005136bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005137 GLenum target,
5138 GLenum internalformat,
5139 GLsizei width,
5140 GLsizei height)
5141{
5142 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
5143 height);
5144}
5145
Jamie Madill5b772312018-03-08 20:28:32 -05005146bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005147 GLenum target,
5148 GLsizei samples,
5149 GLenum internalformat,
5150 GLsizei width,
5151 GLsizei height)
5152{
5153 if (!context->getExtensions().framebufferMultisample)
5154 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005155 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05005156 return false;
5157 }
5158
5159 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05005160 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05005161 // generated.
5162 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
5163 {
Jamie Madille0472f32018-11-27 16:32:45 -05005164 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005165 return false;
5166 }
5167
5168 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
5169 // the specified storage. This is different than ES 3.0 in which a sample number higher
5170 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
5171 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
5172 if (context->getClientMajorVersion() >= 3)
5173 {
5174 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
5175 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
5176 {
Jamie Madille0472f32018-11-27 16:32:45 -05005177 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005178 return false;
5179 }
5180 }
5181
5182 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
5183 width, height);
5184}
5185
Jamie Madill5b772312018-03-08 20:28:32 -05005186bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005187{
Geoff Lange8afa902017-09-27 15:00:43 -04005188 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005189 {
Jamie Madille0472f32018-11-27 16:32:45 -05005190 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005191 return false;
5192 }
5193
5194 return true;
5195}
5196
Jamie Madill5b772312018-03-08 20:28:32 -05005197bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005198{
5199 return true;
5200}
5201
Jamie Madill5b772312018-03-08 20:28:32 -05005202bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005203{
5204 return true;
5205}
5206
Jamie Madill5b772312018-03-08 20:28:32 -05005207bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005208{
5209 return true;
5210}
5211
Jamie Madill5b772312018-03-08 20:28:32 -05005212bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005213 GLboolean red,
5214 GLboolean green,
5215 GLboolean blue,
5216 GLboolean alpha)
5217{
5218 return true;
5219}
5220
Jamie Madill5b772312018-03-08 20:28:32 -05005221bool ValidateCompileShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005222{
5223 return true;
5224}
5225
Jamie Madill5b772312018-03-08 20:28:32 -05005226bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005227{
5228 return true;
5229}
5230
Jamie Madill5b772312018-03-08 20:28:32 -05005231bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005232{
5233 switch (mode)
5234 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005235 case CullFaceMode::Front:
5236 case CullFaceMode::Back:
5237 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005238 break;
5239
5240 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005241 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005242 return false;
5243 }
5244
5245 return true;
5246}
5247
Jamie Madill5b772312018-03-08 20:28:32 -05005248bool ValidateDeleteProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005249{
5250 if (program == 0)
5251 {
5252 return false;
5253 }
5254
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005255 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005256 {
5257 if (context->getShader(program))
5258 {
Jamie Madille0472f32018-11-27 16:32:45 -05005259 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005260 return false;
5261 }
5262 else
5263 {
Jamie Madille0472f32018-11-27 16:32:45 -05005264 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005265 return false;
5266 }
5267 }
5268
5269 return true;
5270}
5271
Jamie Madill5b772312018-03-08 20:28:32 -05005272bool ValidateDeleteShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005273{
5274 if (shader == 0)
5275 {
5276 return false;
5277 }
5278
5279 if (!context->getShader(shader))
5280 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005281 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005282 {
Jamie Madille0472f32018-11-27 16:32:45 -05005283 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005284 return false;
5285 }
5286 else
5287 {
Jamie Madille0472f32018-11-27 16:32:45 -05005288 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005289 return false;
5290 }
5291 }
5292
5293 return true;
5294}
5295
Jamie Madill5b772312018-03-08 20:28:32 -05005296bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005297{
5298 switch (func)
5299 {
5300 case GL_NEVER:
5301 case GL_ALWAYS:
5302 case GL_LESS:
5303 case GL_LEQUAL:
5304 case GL_EQUAL:
5305 case GL_GREATER:
5306 case GL_GEQUAL:
5307 case GL_NOTEQUAL:
5308 break;
5309
5310 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005311 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005312 return false;
5313 }
5314
5315 return true;
5316}
5317
Jamie Madill5b772312018-03-08 20:28:32 -05005318bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005319{
5320 return true;
5321}
5322
Jamie Madill5b772312018-03-08 20:28:32 -05005323bool ValidateDetachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005324{
5325 Program *programObject = GetValidProgram(context, program);
5326 if (!programObject)
5327 {
5328 return false;
5329 }
5330
5331 Shader *shaderObject = GetValidShader(context, shader);
5332 if (!shaderObject)
5333 {
5334 return false;
5335 }
5336
Jiawei Shao385b3e02018-03-21 09:43:28 +08005337 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005338 if (attachedShader != shaderObject)
5339 {
Jamie Madille0472f32018-11-27 16:32:45 -05005340 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005341 return false;
5342 }
5343
5344 return true;
5345}
5346
Jamie Madill5b772312018-03-08 20:28:32 -05005347bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005348{
5349 if (index >= MAX_VERTEX_ATTRIBS)
5350 {
Jamie Madille0472f32018-11-27 16:32:45 -05005351 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005352 return false;
5353 }
5354
5355 return true;
5356}
5357
Jamie Madill5b772312018-03-08 20:28:32 -05005358bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005359{
5360 if (index >= MAX_VERTEX_ATTRIBS)
5361 {
Jamie Madille0472f32018-11-27 16:32:45 -05005362 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005363 return false;
5364 }
5365
5366 return true;
5367}
5368
Jamie Madill5b772312018-03-08 20:28:32 -05005369bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005370{
5371 return true;
5372}
5373
Jamie Madill5b772312018-03-08 20:28:32 -05005374bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005375{
5376 return true;
5377}
5378
Jamie Madill5b772312018-03-08 20:28:32 -05005379bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005380{
5381 switch (mode)
5382 {
5383 case GL_CW:
5384 case GL_CCW:
5385 break;
5386 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005387 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005388 return false;
5389 }
5390
5391 return true;
5392}
5393
Jamie Madill5b772312018-03-08 20:28:32 -05005394bool ValidateGetActiveAttrib(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005395 GLuint program,
5396 GLuint index,
5397 GLsizei bufsize,
5398 GLsizei *length,
5399 GLint *size,
5400 GLenum *type,
5401 GLchar *name)
5402{
5403 if (bufsize < 0)
5404 {
Jamie Madille0472f32018-11-27 16:32:45 -05005405 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005406 return false;
5407 }
5408
5409 Program *programObject = GetValidProgram(context, program);
5410
5411 if (!programObject)
5412 {
5413 return false;
5414 }
5415
5416 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5417 {
Jamie Madille0472f32018-11-27 16:32:45 -05005418 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005419 return false;
5420 }
5421
5422 return true;
5423}
5424
Jamie Madill5b772312018-03-08 20:28:32 -05005425bool ValidateGetActiveUniform(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005426 GLuint program,
5427 GLuint index,
5428 GLsizei bufsize,
5429 GLsizei *length,
5430 GLint *size,
5431 GLenum *type,
5432 GLchar *name)
5433{
5434 if (bufsize < 0)
5435 {
Jamie Madille0472f32018-11-27 16:32:45 -05005436 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005437 return false;
5438 }
5439
5440 Program *programObject = GetValidProgram(context, program);
5441
5442 if (!programObject)
5443 {
5444 return false;
5445 }
5446
5447 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5448 {
Jamie Madille0472f32018-11-27 16:32:45 -05005449 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005450 return false;
5451 }
5452
5453 return true;
5454}
5455
Jamie Madill5b772312018-03-08 20:28:32 -05005456bool ValidateGetAttachedShaders(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005457 GLuint program,
5458 GLsizei maxcount,
5459 GLsizei *count,
5460 GLuint *shaders)
5461{
5462 if (maxcount < 0)
5463 {
Jamie Madille0472f32018-11-27 16:32:45 -05005464 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005465 return false;
5466 }
5467
5468 Program *programObject = GetValidProgram(context, program);
5469
5470 if (!programObject)
5471 {
5472 return false;
5473 }
5474
5475 return true;
5476}
5477
Jamie Madill5b772312018-03-08 20:28:32 -05005478bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005479{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005480 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5481 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005482 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005483 {
Jamie Madille0472f32018-11-27 16:32:45 -05005484 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005485 return false;
5486 }
5487
Jamie Madillc1d770e2017-04-13 17:31:24 -04005488 Program *programObject = GetValidProgram(context, program);
5489
5490 if (!programObject)
5491 {
Jamie Madille0472f32018-11-27 16:32:45 -05005492 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005493 return false;
5494 }
5495
5496 if (!programObject->isLinked())
5497 {
Jamie Madille0472f32018-11-27 16:32:45 -05005498 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005499 return false;
5500 }
5501
5502 return true;
5503}
5504
Jamie Madill5b772312018-03-08 20:28:32 -05005505bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005506{
5507 GLenum nativeType;
5508 unsigned int numParams = 0;
5509 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5510}
5511
Jamie Madill5b772312018-03-08 20:28:32 -05005512bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005513{
5514 return true;
5515}
5516
Jamie Madill5b772312018-03-08 20:28:32 -05005517bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005518{
5519 GLenum nativeType;
5520 unsigned int numParams = 0;
5521 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5522}
5523
Jamie Madill5b772312018-03-08 20:28:32 -05005524bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005525{
5526 GLenum nativeType;
5527 unsigned int numParams = 0;
5528 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5529}
5530
Jamie Madill5b772312018-03-08 20:28:32 -05005531bool ValidateGetProgramInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005532 GLuint program,
5533 GLsizei bufsize,
5534 GLsizei *length,
5535 GLchar *infolog)
5536{
5537 if (bufsize < 0)
5538 {
Jamie Madille0472f32018-11-27 16:32:45 -05005539 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005540 return false;
5541 }
5542
5543 Program *programObject = GetValidProgram(context, program);
5544 if (!programObject)
5545 {
5546 return false;
5547 }
5548
5549 return true;
5550}
5551
Jamie Madill5b772312018-03-08 20:28:32 -05005552bool ValidateGetShaderInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005553 GLuint shader,
5554 GLsizei bufsize,
5555 GLsizei *length,
5556 GLchar *infolog)
5557{
5558 if (bufsize < 0)
5559 {
Jamie Madille0472f32018-11-27 16:32:45 -05005560 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005561 return false;
5562 }
5563
5564 Shader *shaderObject = GetValidShader(context, shader);
5565 if (!shaderObject)
5566 {
5567 return false;
5568 }
5569
5570 return true;
5571}
5572
Jamie Madill5b772312018-03-08 20:28:32 -05005573bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005574 GLenum shadertype,
5575 GLenum precisiontype,
5576 GLint *range,
5577 GLint *precision)
5578{
5579 switch (shadertype)
5580 {
5581 case GL_VERTEX_SHADER:
5582 case GL_FRAGMENT_SHADER:
5583 break;
5584 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005585 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005586 return false;
5587 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005588 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005589 return false;
5590 }
5591
5592 switch (precisiontype)
5593 {
5594 case GL_LOW_FLOAT:
5595 case GL_MEDIUM_FLOAT:
5596 case GL_HIGH_FLOAT:
5597 case GL_LOW_INT:
5598 case GL_MEDIUM_INT:
5599 case GL_HIGH_INT:
5600 break;
5601
5602 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005603 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005604 return false;
5605 }
5606
5607 return true;
5608}
5609
Jamie Madill5b772312018-03-08 20:28:32 -05005610bool ValidateGetShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005611 GLuint shader,
5612 GLsizei bufsize,
5613 GLsizei *length,
5614 GLchar *source)
5615{
5616 if (bufsize < 0)
5617 {
Jamie Madille0472f32018-11-27 16:32:45 -05005618 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005619 return false;
5620 }
5621
5622 Shader *shaderObject = GetValidShader(context, shader);
5623 if (!shaderObject)
5624 {
5625 return false;
5626 }
5627
5628 return true;
5629}
5630
Jamie Madill5b772312018-03-08 20:28:32 -05005631bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005632{
5633 if (strstr(name, "gl_") == name)
5634 {
5635 return false;
5636 }
5637
Geoff Langfc32e8b2017-05-31 14:16:59 -04005638 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5639 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005640 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005641 {
Jamie Madille0472f32018-11-27 16:32:45 -05005642 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005643 return false;
5644 }
5645
Jamie Madillc1d770e2017-04-13 17:31:24 -04005646 Program *programObject = GetValidProgram(context, program);
5647
5648 if (!programObject)
5649 {
5650 return false;
5651 }
5652
5653 if (!programObject->isLinked())
5654 {
Jamie Madille0472f32018-11-27 16:32:45 -05005655 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005656 return false;
5657 }
5658
5659 return true;
5660}
5661
Jamie Madill5b772312018-03-08 20:28:32 -05005662bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005663{
5664 switch (mode)
5665 {
5666 case GL_FASTEST:
5667 case GL_NICEST:
5668 case GL_DONT_CARE:
5669 break;
5670
5671 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005672 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005673 return false;
5674 }
5675
5676 switch (target)
5677 {
5678 case GL_GENERATE_MIPMAP_HINT:
5679 break;
5680
Geoff Lange7bd2182017-06-16 16:13:13 -04005681 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5682 if (context->getClientVersion() < ES_3_0 &&
5683 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005684 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005685 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005686 return false;
5687 }
5688 break;
5689
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005690 case GL_PERSPECTIVE_CORRECTION_HINT:
5691 case GL_POINT_SMOOTH_HINT:
5692 case GL_LINE_SMOOTH_HINT:
5693 case GL_FOG_HINT:
5694 if (context->getClientMajorVersion() >= 2)
5695 {
Jamie Madille0472f32018-11-27 16:32:45 -05005696 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005697 return false;
5698 }
5699 break;
5700
Jamie Madillc1d770e2017-04-13 17:31:24 -04005701 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005702 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005703 return false;
5704 }
5705
5706 return true;
5707}
5708
Jamie Madill5b772312018-03-08 20:28:32 -05005709bool ValidateIsBuffer(Context *context, GLuint buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005710{
5711 return true;
5712}
5713
Jamie Madill5b772312018-03-08 20:28:32 -05005714bool ValidateIsFramebuffer(Context *context, GLuint framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005715{
5716 return true;
5717}
5718
Jamie Madill5b772312018-03-08 20:28:32 -05005719bool ValidateIsProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005720{
5721 return true;
5722}
5723
Jamie Madill7c7dec02019-08-06 17:44:11 -04005724bool ValidateIsRenderbuffer(Context *context, RenderbufferID renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005725{
5726 return true;
5727}
5728
Jamie Madill5b772312018-03-08 20:28:32 -05005729bool ValidateIsShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005730{
5731 return true;
5732}
5733
Jamie Madill5b772312018-03-08 20:28:32 -05005734bool ValidateIsTexture(Context *context, GLuint texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005735{
5736 return true;
5737}
5738
Jamie Madill5b772312018-03-08 20:28:32 -05005739bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005740{
5741 if (context->getClientMajorVersion() < 3)
5742 {
5743 switch (pname)
5744 {
5745 case GL_UNPACK_IMAGE_HEIGHT:
5746 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005747 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005748 return false;
5749
5750 case GL_UNPACK_ROW_LENGTH:
5751 case GL_UNPACK_SKIP_ROWS:
5752 case GL_UNPACK_SKIP_PIXELS:
5753 if (!context->getExtensions().unpackSubimage)
5754 {
Jamie Madille0472f32018-11-27 16:32:45 -05005755 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005756 return false;
5757 }
5758 break;
5759
5760 case GL_PACK_ROW_LENGTH:
5761 case GL_PACK_SKIP_ROWS:
5762 case GL_PACK_SKIP_PIXELS:
5763 if (!context->getExtensions().packSubimage)
5764 {
Jamie Madille0472f32018-11-27 16:32:45 -05005765 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005766 return false;
5767 }
5768 break;
5769 }
5770 }
5771
5772 if (param < 0)
5773 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005774 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005775 return false;
5776 }
5777
5778 switch (pname)
5779 {
5780 case GL_UNPACK_ALIGNMENT:
5781 if (param != 1 && param != 2 && param != 4 && param != 8)
5782 {
Jamie Madille0472f32018-11-27 16:32:45 -05005783 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005784 return false;
5785 }
5786 break;
5787
5788 case GL_PACK_ALIGNMENT:
5789 if (param != 1 && param != 2 && param != 4 && param != 8)
5790 {
Jamie Madille0472f32018-11-27 16:32:45 -05005791 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005792 return false;
5793 }
5794 break;
5795
5796 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005797 if (!context->getExtensions().packReverseRowOrder)
5798 {
Jamie Madille0472f32018-11-27 16:32:45 -05005799 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005800 }
5801 break;
5802
Jamie Madillc1d770e2017-04-13 17:31:24 -04005803 case GL_UNPACK_ROW_LENGTH:
5804 case GL_UNPACK_IMAGE_HEIGHT:
5805 case GL_UNPACK_SKIP_IMAGES:
5806 case GL_UNPACK_SKIP_ROWS:
5807 case GL_UNPACK_SKIP_PIXELS:
5808 case GL_PACK_ROW_LENGTH:
5809 case GL_PACK_SKIP_ROWS:
5810 case GL_PACK_SKIP_PIXELS:
5811 break;
5812
5813 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005814 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005815 return false;
5816 }
5817
5818 return true;
5819}
5820
Jamie Madill5b772312018-03-08 20:28:32 -05005821bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005822{
5823 return true;
5824}
5825
Jamie Madill5b772312018-03-08 20:28:32 -05005826bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005827{
5828 return true;
5829}
5830
Jamie Madill5b772312018-03-08 20:28:32 -05005831bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005832{
5833 return true;
5834}
5835
Jamie Madill5b772312018-03-08 20:28:32 -05005836bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005837{
5838 if (width < 0 || height < 0)
5839 {
Jamie Madille0472f32018-11-27 16:32:45 -05005840 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005841 return false;
5842 }
5843
5844 return true;
5845}
5846
Jamie Madill5b772312018-03-08 20:28:32 -05005847bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005848 GLsizei n,
5849 const GLuint *shaders,
5850 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005851 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005852 GLsizei length)
5853{
5854 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
5855 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
5856 shaderBinaryFormats.end())
5857 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005858 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005859 return false;
5860 }
5861
5862 return true;
5863}
5864
Jamie Madill5b772312018-03-08 20:28:32 -05005865bool ValidateShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005866 GLuint shader,
5867 GLsizei count,
5868 const GLchar *const *string,
5869 const GLint *length)
5870{
5871 if (count < 0)
5872 {
Jamie Madille0472f32018-11-27 16:32:45 -05005873 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005874 return false;
5875 }
5876
Geoff Langfc32e8b2017-05-31 14:16:59 -04005877 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5878 // shader-related entry points
5879 if (context->getExtensions().webglCompatibility)
5880 {
5881 for (GLsizei i = 0; i < count; i++)
5882 {
Geoff Langcab92ee2017-07-19 17:32:07 -04005883 size_t len =
5884 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04005885
5886 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04005887 if (!IsValidESSLShaderSourceString(string[i], len,
5888 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005889 {
Jamie Madille0472f32018-11-27 16:32:45 -05005890 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005891 return false;
5892 }
5893 }
5894 }
5895
Jamie Madillc1d770e2017-04-13 17:31:24 -04005896 Shader *shaderObject = GetValidShader(context, shader);
5897 if (!shaderObject)
5898 {
5899 return false;
5900 }
5901
5902 return true;
5903}
5904
Jamie Madill5b772312018-03-08 20:28:32 -05005905bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005906{
5907 if (!IsValidStencilFunc(func))
5908 {
Jamie Madille0472f32018-11-27 16:32:45 -05005909 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005910 return false;
5911 }
5912
5913 return true;
5914}
5915
Jamie Madill5b772312018-03-08 20:28:32 -05005916bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005917{
5918 if (!IsValidStencilFace(face))
5919 {
Jamie Madille0472f32018-11-27 16:32:45 -05005920 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005921 return false;
5922 }
5923
5924 if (!IsValidStencilFunc(func))
5925 {
Jamie Madille0472f32018-11-27 16:32:45 -05005926 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005927 return false;
5928 }
5929
5930 return true;
5931}
5932
Jamie Madill5b772312018-03-08 20:28:32 -05005933bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005934{
5935 return true;
5936}
5937
Jamie Madill5b772312018-03-08 20:28:32 -05005938bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005939{
5940 if (!IsValidStencilFace(face))
5941 {
Jamie Madille0472f32018-11-27 16:32:45 -05005942 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005943 return false;
5944 }
5945
5946 return true;
5947}
5948
Jamie Madill5b772312018-03-08 20:28:32 -05005949bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005950{
5951 if (!IsValidStencilOp(fail))
5952 {
Jamie Madille0472f32018-11-27 16:32:45 -05005953 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005954 return false;
5955 }
5956
5957 if (!IsValidStencilOp(zfail))
5958 {
Jamie Madille0472f32018-11-27 16:32:45 -05005959 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005960 return false;
5961 }
5962
5963 if (!IsValidStencilOp(zpass))
5964 {
Jamie Madille0472f32018-11-27 16:32:45 -05005965 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005966 return false;
5967 }
5968
5969 return true;
5970}
5971
Jamie Madill5b772312018-03-08 20:28:32 -05005972bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005973 GLenum face,
5974 GLenum fail,
5975 GLenum zfail,
5976 GLenum zpass)
5977{
5978 if (!IsValidStencilFace(face))
5979 {
Jamie Madille0472f32018-11-27 16:32:45 -05005980 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005981 return false;
5982 }
5983
5984 return ValidateStencilOp(context, fail, zfail, zpass);
5985}
5986
Jamie Madill5b772312018-03-08 20:28:32 -05005987bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005988{
5989 return ValidateUniform(context, GL_FLOAT, location, 1);
5990}
5991
Jamie Madill5b772312018-03-08 20:28:32 -05005992bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005993{
5994 return ValidateUniform(context, GL_FLOAT, location, count);
5995}
5996
Jamie Madill5b772312018-03-08 20:28:32 -05005997bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04005998{
5999 return ValidateUniform1iv(context, location, 1, &x);
6000}
6001
Jamie Madill5b772312018-03-08 20:28:32 -05006002bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006003{
6004 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
6005}
6006
Jamie Madill5b772312018-03-08 20:28:32 -05006007bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006008{
6009 return ValidateUniform(context, GL_INT_VEC2, location, 1);
6010}
6011
Jamie Madill5b772312018-03-08 20:28:32 -05006012bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006013{
6014 return ValidateUniform(context, GL_INT_VEC2, location, count);
6015}
6016
Jamie Madill5b772312018-03-08 20:28:32 -05006017bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006018{
6019 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
6020}
6021
Jamie Madill5b772312018-03-08 20:28:32 -05006022bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006023{
6024 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
6025}
6026
Jamie Madill5b772312018-03-08 20:28:32 -05006027bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006028{
6029 return ValidateUniform(context, GL_INT_VEC3, location, 1);
6030}
6031
Jamie Madill5b772312018-03-08 20:28:32 -05006032bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006033{
6034 return ValidateUniform(context, GL_INT_VEC3, location, count);
6035}
6036
Jamie Madill5b772312018-03-08 20:28:32 -05006037bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006038{
6039 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
6040}
6041
Jamie Madill5b772312018-03-08 20:28:32 -05006042bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006043{
6044 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
6045}
6046
Jamie Madill5b772312018-03-08 20:28:32 -05006047bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006048{
6049 return ValidateUniform(context, GL_INT_VEC4, location, 1);
6050}
6051
Jamie Madill5b772312018-03-08 20:28:32 -05006052bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006053{
6054 return ValidateUniform(context, GL_INT_VEC4, location, count);
6055}
6056
Jamie Madill5b772312018-03-08 20:28:32 -05006057bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006058 GLint location,
6059 GLsizei count,
6060 GLboolean transpose,
6061 const GLfloat *value)
6062{
6063 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
6064}
6065
Jamie Madill5b772312018-03-08 20:28:32 -05006066bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006067 GLint location,
6068 GLsizei count,
6069 GLboolean transpose,
6070 const GLfloat *value)
6071{
6072 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
6073}
6074
Jamie Madill5b772312018-03-08 20:28:32 -05006075bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006076 GLint location,
6077 GLsizei count,
6078 GLboolean transpose,
6079 const GLfloat *value)
6080{
6081 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
6082}
6083
Jamie Madill5b772312018-03-08 20:28:32 -05006084bool ValidateValidateProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006085{
6086 Program *programObject = GetValidProgram(context, program);
6087
6088 if (!programObject)
6089 {
6090 return false;
6091 }
6092
6093 return true;
6094}
6095
Jamie Madill5b772312018-03-08 20:28:32 -05006096bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006097{
6098 return ValidateVertexAttribIndex(context, index);
6099}
6100
Jamie Madill5b772312018-03-08 20:28:32 -05006101bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006102{
6103 return ValidateVertexAttribIndex(context, index);
6104}
6105
Jamie Madill5b772312018-03-08 20:28:32 -05006106bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006107{
6108 return ValidateVertexAttribIndex(context, index);
6109}
6110
Jamie Madill5b772312018-03-08 20:28:32 -05006111bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006112{
6113 return ValidateVertexAttribIndex(context, index);
6114}
6115
Jamie Madill5b772312018-03-08 20:28:32 -05006116bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006117{
6118 return ValidateVertexAttribIndex(context, index);
6119}
6120
Jamie Madill5b772312018-03-08 20:28:32 -05006121bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006122{
6123 return ValidateVertexAttribIndex(context, index);
6124}
6125
Jamie Madill5b772312018-03-08 20:28:32 -05006126bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006127 GLuint index,
6128 GLfloat x,
6129 GLfloat y,
6130 GLfloat z,
6131 GLfloat w)
6132{
6133 return ValidateVertexAttribIndex(context, index);
6134}
6135
Jamie Madill5b772312018-03-08 20:28:32 -05006136bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006137{
6138 return ValidateVertexAttribIndex(context, index);
6139}
6140
Jamie Madill5b772312018-03-08 20:28:32 -05006141bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006142{
6143 if (width < 0 || height < 0)
6144 {
Jamie Madille0472f32018-11-27 16:32:45 -05006145 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006146 return false;
6147 }
6148
6149 return true;
6150}
6151
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08006152bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006153 GLenum target,
6154 GLenum attachment,
6155 GLenum pname,
6156 GLint *params)
6157{
6158 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
6159 nullptr);
6160}
6161
Jamie Madill5b772312018-03-08 20:28:32 -05006162bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006163{
6164 return ValidateGetProgramivBase(context, program, pname, nullptr);
6165}
6166
Jamie Madill5b772312018-03-08 20:28:32 -05006167bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006168 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006169 GLint level,
6170 GLenum internalformat,
6171 GLint x,
6172 GLint y,
6173 GLsizei width,
6174 GLsizei height,
6175 GLint border)
6176{
6177 if (context->getClientMajorVersion() < 3)
6178 {
6179 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
6180 0, x, y, width, height, border);
6181 }
6182
6183 ASSERT(context->getClientMajorVersion() == 3);
6184 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
6185 0, x, y, width, height, border);
6186}
6187
6188bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006189 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006190 GLint level,
6191 GLint xoffset,
6192 GLint yoffset,
6193 GLint x,
6194 GLint y,
6195 GLsizei width,
6196 GLsizei height)
6197{
6198 if (context->getClientMajorVersion() < 3)
6199 {
6200 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
6201 yoffset, x, y, width, height, 0);
6202 }
6203
6204 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
6205 yoffset, 0, x, y, width, height, 0);
6206}
6207
Cody Northrop5faff912019-06-28 14:04:50 -06006208bool ValidateCopyTexSubImage3DOES(Context *context,
6209 TextureTarget target,
6210 GLint level,
6211 GLint xoffset,
6212 GLint yoffset,
6213 GLint zoffset,
6214 GLint x,
6215 GLint y,
6216 GLsizei width,
6217 GLsizei height)
6218{
6219 return ValidateCopyTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, x, y, width,
6220 height);
6221}
6222
Jamie Madillbe849e42017-05-02 15:49:00 -04006223bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *)
6224{
6225 return ValidateGenOrDelete(context, n);
6226}
6227
6228bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *)
6229{
6230 return ValidateGenOrDelete(context, n);
6231}
6232
Jamie Madill7c7dec02019-08-06 17:44:11 -04006233bool ValidateDeleteRenderbuffers(Context *context, GLint n, const RenderbufferID *renderbuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006234{
6235 return ValidateGenOrDelete(context, n);
6236}
6237
6238bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *)
6239{
6240 return ValidateGenOrDelete(context, n);
6241}
6242
6243bool ValidateDisable(Context *context, GLenum cap)
6244{
6245 if (!ValidCap(context, cap, false))
6246 {
Jamie Madille0472f32018-11-27 16:32:45 -05006247 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006248 return false;
6249 }
6250
6251 return true;
6252}
6253
6254bool ValidateEnable(Context *context, GLenum cap)
6255{
6256 if (!ValidCap(context, cap, false))
6257 {
Jamie Madille0472f32018-11-27 16:32:45 -05006258 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006259 return false;
6260 }
6261
6262 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6263 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6264 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006265 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006266
6267 // We also output an error message to the debugger window if tracing is active, so that
6268 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006269 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006270 return false;
6271 }
6272
6273 return true;
6274}
6275
6276bool ValidateFramebufferRenderbuffer(Context *context,
6277 GLenum target,
6278 GLenum attachment,
6279 GLenum renderbuffertarget,
Jamie Madill7c7dec02019-08-06 17:44:11 -04006280 RenderbufferID renderbuffer)
Jamie Madillbe849e42017-05-02 15:49:00 -04006281{
Geoff Lange8afa902017-09-27 15:00:43 -04006282 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006283 {
Jamie Madille0472f32018-11-27 16:32:45 -05006284 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006285 return false;
6286 }
6287
Jamie Madill7c7dec02019-08-06 17:44:11 -04006288 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer.value != 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006289 {
Jamie Madille0472f32018-11-27 16:32:45 -05006290 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006291 return false;
6292 }
6293
6294 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6295 renderbuffertarget, renderbuffer);
6296}
6297
6298bool ValidateFramebufferTexture2D(Context *context,
6299 GLenum target,
6300 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006301 TextureTarget textarget,
Jamie Madillbe849e42017-05-02 15:49:00 -04006302 GLuint texture,
6303 GLint level)
6304{
6305 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6306 // extension
6307 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6308 level != 0)
6309 {
Jamie Madille0472f32018-11-27 16:32:45 -05006310 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006311 return false;
6312 }
6313
6314 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6315 {
6316 return false;
6317 }
6318
6319 if (texture != 0)
6320 {
6321 gl::Texture *tex = context->getTexture(texture);
6322 ASSERT(tex);
6323
6324 const gl::Caps &caps = context->getCaps();
6325
6326 switch (textarget)
6327 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006328 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006329 {
6330 if (level > gl::log2(caps.max2DTextureSize))
6331 {
Jamie Madille0472f32018-11-27 16:32:45 -05006332 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006333 return false;
6334 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006335 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006336 {
Jamie Madille0472f32018-11-27 16:32:45 -05006337 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006338 return false;
6339 }
6340 }
6341 break;
6342
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006343 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006344 {
6345 if (level != 0)
6346 {
Jamie Madille0472f32018-11-27 16:32:45 -05006347 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006348 return false;
6349 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006350 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006351 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006352 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006353 return false;
6354 }
6355 }
6356 break;
6357
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006358 case TextureTarget::CubeMapNegativeX:
6359 case TextureTarget::CubeMapNegativeY:
6360 case TextureTarget::CubeMapNegativeZ:
6361 case TextureTarget::CubeMapPositiveX:
6362 case TextureTarget::CubeMapPositiveY:
6363 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006364 {
6365 if (level > gl::log2(caps.maxCubeMapTextureSize))
6366 {
Jamie Madille0472f32018-11-27 16:32:45 -05006367 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006368 return false;
6369 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006370 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006371 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006372 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006373 return false;
6374 }
6375 }
6376 break;
6377
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006378 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006379 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006380 if (context->getClientVersion() < ES_3_1 &&
6381 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006382 {
Jamie Madill610640f2018-11-21 17:28:41 -05006383 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006384 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006385 return false;
6386 }
6387
6388 if (level != 0)
6389 {
Jamie Madille0472f32018-11-27 16:32:45 -05006390 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006391 return false;
6392 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006393 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006394 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006395 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006396 return false;
6397 }
6398 }
6399 break;
6400
6401 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006402 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006403 return false;
6404 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006405 }
6406
6407 return true;
6408}
6409
Cody Northrop5faff912019-06-28 14:04:50 -06006410bool ValidateFramebufferTexture3DOES(Context *context,
6411 GLenum target,
6412 GLenum attachment,
6413 TextureTarget textargetPacked,
6414 GLuint texture,
6415 GLint level,
6416 GLint zoffset)
6417{
Cody Northrop90958e32019-08-07 16:26:14 -06006418 // We don't call into a base ValidateFramebufferTexture3D here because
6419 // it doesn't exist for OpenGL ES. This function is replaced by
6420 // FramebufferTextureLayer in ES 3.x, which has broader support.
6421 if (!context->getExtensions().texture3DOES)
6422 {
6423 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6424 return false;
6425 }
6426
6427 // Attachments are required to be bound to level 0 without ES3 or the
6428 // GL_OES_fbo_render_mipmap extension
6429 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6430 level != 0)
6431 {
6432 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
6433 return false;
6434 }
6435
6436 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6437 {
6438 return false;
6439 }
6440
6441 if (texture != 0)
6442 {
6443 gl::Texture *tex = context->getTexture(texture);
6444 ASSERT(tex);
6445
6446 const gl::Caps &caps = context->getCaps();
6447
6448 switch (textargetPacked)
6449 {
6450 case TextureTarget::_3D:
6451 {
6452 if (level > gl::log2(caps.max3DTextureSize))
6453 {
6454 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
6455 return false;
6456 }
6457 if (static_cast<size_t>(zoffset) >= caps.max3DTextureSize)
6458 {
6459 context->validationError(GL_INVALID_VALUE, kInvalidZOffset);
6460 return false;
6461 }
6462 if (tex->getType() != TextureType::_3D)
6463 {
6464 context->validationError(GL_INVALID_OPERATION, kInvalidTextureType);
6465 return false;
6466 }
6467 }
6468 break;
6469
6470 default:
6471 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
6472 return false;
6473 }
6474 }
6475
6476 return true;
Cody Northrop5faff912019-06-28 14:04:50 -06006477}
6478
Jamie Madillbe849e42017-05-02 15:49:00 -04006479bool ValidateGenBuffers(Context *context, GLint n, GLuint *)
6480{
6481 return ValidateGenOrDelete(context, n);
6482}
6483
6484bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *)
6485{
6486 return ValidateGenOrDelete(context, n);
6487}
6488
Jamie Madill7c7dec02019-08-06 17:44:11 -04006489bool ValidateGenRenderbuffers(Context *context, GLint n, RenderbufferID *renderbuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006490{
6491 return ValidateGenOrDelete(context, n);
6492}
6493
6494bool ValidateGenTextures(Context *context, GLint n, GLuint *)
6495{
6496 return ValidateGenOrDelete(context, n);
6497}
6498
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006499bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006500{
6501 if (!ValidTextureTarget(context, target))
6502 {
Jamie Madille0472f32018-11-27 16:32:45 -05006503 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006504 return false;
6505 }
6506
Jamie Madillcfc73cc2019-04-08 16:26:51 -04006507 Texture *texture = context->getTextureByType(target);
Jamie Madillbe849e42017-05-02 15:49:00 -04006508
6509 if (texture == nullptr)
6510 {
Jamie Madille0472f32018-11-27 16:32:45 -05006511 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006512 return false;
6513 }
6514
6515 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6516
6517 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6518 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6519 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6520 {
Jamie Madille0472f32018-11-27 16:32:45 -05006521 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006522 return false;
6523 }
6524
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006525 TextureTarget baseTarget = (target == TextureType::CubeMap)
6526 ? TextureTarget::CubeMapPositiveX
6527 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006528 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6529 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6530 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006531 {
Jamie Madille0472f32018-11-27 16:32:45 -05006532 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006533 return false;
6534 }
6535
Geoff Lang536eca12017-09-13 11:23:35 -04006536 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6537 bool formatUnsized = !format.sized;
6538 bool formatColorRenderableAndFilterable =
6539 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006540 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006541 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006542 {
Jamie Madille0472f32018-11-27 16:32:45 -05006543 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006544 return false;
6545 }
6546
Geoff Lang536eca12017-09-13 11:23:35 -04006547 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6548 // generation
6549 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6550 {
Jamie Madille0472f32018-11-27 16:32:45 -05006551 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006552 return false;
6553 }
6554
Jiange2c00842018-07-13 16:50:49 +08006555 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6556 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6557 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006558 {
Jamie Madille0472f32018-11-27 16:32:45 -05006559 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006560 return false;
6561 }
6562
6563 // Non-power of 2 ES2 check
6564 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6565 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6566 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6567 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006568 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6569 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006570 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006571 return false;
6572 }
6573
6574 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006575 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006576 {
Jamie Madille0472f32018-11-27 16:32:45 -05006577 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006578 return false;
6579 }
6580
James Darpinian83b2f0e2018-11-27 15:56:01 -08006581 if (context->getExtensions().webglCompatibility &&
6582 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6583 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6584 {
6585 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6586 return false;
6587 }
6588
Jamie Madillbe849e42017-05-02 15:49:00 -04006589 return true;
6590}
6591
Jamie Madill5b772312018-03-08 20:28:32 -05006592bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006593 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006594 GLenum pname,
6595 GLint *params)
6596{
6597 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6598}
6599
6600bool ValidateGetRenderbufferParameteriv(Context *context,
6601 GLenum target,
6602 GLenum pname,
6603 GLint *params)
6604{
6605 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6606}
6607
6608bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params)
6609{
6610 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6611}
6612
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006613bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006614{
6615 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6616}
6617
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006618bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006619{
6620 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6621}
6622
Till Rathmannb8543632018-10-02 19:46:14 +02006623bool ValidateGetTexParameterIivOES(Context *context,
6624 TextureType target,
6625 GLenum pname,
6626 GLint *params)
6627{
6628 if (context->getClientMajorVersion() < 3)
6629 {
Jamie Madille0472f32018-11-27 16:32:45 -05006630 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006631 return false;
6632 }
6633 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6634}
6635
6636bool ValidateGetTexParameterIuivOES(Context *context,
6637 TextureType target,
6638 GLenum pname,
6639 GLuint *params)
6640{
6641 if (context->getClientMajorVersion() < 3)
6642 {
Jamie Madille0472f32018-11-27 16:32:45 -05006643 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006644 return false;
6645 }
6646 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6647}
6648
Jamie Madillbe849e42017-05-02 15:49:00 -04006649bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params)
6650{
6651 return ValidateGetUniformBase(context, program, location);
6652}
6653
6654bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params)
6655{
6656 return ValidateGetUniformBase(context, program, location);
6657}
6658
6659bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6660{
6661 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6662}
6663
6664bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6665{
6666 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6667}
6668
6669bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6670{
6671 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6672}
6673
6674bool ValidateIsEnabled(Context *context, GLenum cap)
6675{
6676 if (!ValidCap(context, cap, true))
6677 {
Jamie Madille0472f32018-11-27 16:32:45 -05006678 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006679 return false;
6680 }
6681
6682 return true;
6683}
6684
6685bool ValidateLinkProgram(Context *context, GLuint program)
6686{
6687 if (context->hasActiveTransformFeedback(program))
6688 {
6689 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006690 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006691 return false;
6692 }
6693
6694 Program *programObject = GetValidProgram(context, program);
6695 if (!programObject)
6696 {
6697 return false;
6698 }
6699
6700 return true;
6701}
6702
Jamie Madill4928b7c2017-06-20 12:57:39 -04006703bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006704 GLint x,
6705 GLint y,
6706 GLsizei width,
6707 GLsizei height,
6708 GLenum format,
6709 GLenum type,
6710 void *pixels)
6711{
6712 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6713 nullptr, pixels);
6714}
6715
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006716bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006717{
Till Rathmannb8543632018-10-02 19:46:14 +02006718 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006719}
6720
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006721bool ValidateTexParameterfv(Context *context,
6722 TextureType target,
6723 GLenum pname,
6724 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006725{
Till Rathmannb8543632018-10-02 19:46:14 +02006726 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006727}
6728
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006729bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006730{
Till Rathmannb8543632018-10-02 19:46:14 +02006731 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006732}
6733
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006734bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006735{
Till Rathmannb8543632018-10-02 19:46:14 +02006736 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6737}
6738
6739bool ValidateTexParameterIivOES(Context *context,
6740 TextureType target,
6741 GLenum pname,
6742 const GLint *params)
6743{
6744 if (context->getClientMajorVersion() < 3)
6745 {
Jamie Madille0472f32018-11-27 16:32:45 -05006746 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006747 return false;
6748 }
6749 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6750}
6751
6752bool ValidateTexParameterIuivOES(Context *context,
6753 TextureType target,
6754 GLenum pname,
6755 const GLuint *params)
6756{
6757 if (context->getClientMajorVersion() < 3)
6758 {
Jamie Madille0472f32018-11-27 16:32:45 -05006759 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006760 return false;
6761 }
6762 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006763}
6764
6765bool ValidateUseProgram(Context *context, GLuint program)
6766{
6767 if (program != 0)
6768 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006769 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006770 if (!programObject)
6771 {
6772 // ES 3.1.0 section 7.3 page 72
6773 if (context->getShader(program))
6774 {
Jamie Madille0472f32018-11-27 16:32:45 -05006775 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006776 return false;
6777 }
6778 else
6779 {
Jamie Madille0472f32018-11-27 16:32:45 -05006780 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006781 return false;
6782 }
6783 }
6784 if (!programObject->isLinked())
6785 {
Jamie Madille0472f32018-11-27 16:32:45 -05006786 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006787 return false;
6788 }
6789 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006790 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006791 {
6792 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006793 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006794 return false;
6795 }
6796
6797 return true;
6798}
6799
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006800bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences)
6801{
6802 if (!context->getExtensions().fence)
6803 {
Jamie Madille0472f32018-11-27 16:32:45 -05006804 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006805 return false;
6806 }
6807
6808 if (n < 0)
6809 {
Jamie Madille0472f32018-11-27 16:32:45 -05006810 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006811 return false;
6812 }
6813
6814 return true;
6815}
6816
6817bool ValidateFinishFenceNV(Context *context, GLuint fence)
6818{
6819 if (!context->getExtensions().fence)
6820 {
Jamie Madille0472f32018-11-27 16:32:45 -05006821 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006822 return false;
6823 }
6824
6825 FenceNV *fenceObject = context->getFenceNV(fence);
6826
6827 if (fenceObject == nullptr)
6828 {
Jamie Madille0472f32018-11-27 16:32:45 -05006829 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006830 return false;
6831 }
6832
6833 if (!fenceObject->isSet())
6834 {
Jamie Madille0472f32018-11-27 16:32:45 -05006835 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006836 return false;
6837 }
6838
6839 return true;
6840}
6841
6842bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences)
6843{
6844 if (!context->getExtensions().fence)
6845 {
Jamie Madille0472f32018-11-27 16:32:45 -05006846 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006847 return false;
6848 }
6849
6850 if (n < 0)
6851 {
Jamie Madille0472f32018-11-27 16:32:45 -05006852 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006853 return false;
6854 }
6855
6856 return true;
6857}
6858
6859bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params)
6860{
6861 if (!context->getExtensions().fence)
6862 {
Jamie Madille0472f32018-11-27 16:32:45 -05006863 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006864 return false;
6865 }
6866
6867 FenceNV *fenceObject = context->getFenceNV(fence);
6868
6869 if (fenceObject == nullptr)
6870 {
Jamie Madille0472f32018-11-27 16:32:45 -05006871 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006872 return false;
6873 }
6874
6875 if (!fenceObject->isSet())
6876 {
Jamie Madille0472f32018-11-27 16:32:45 -05006877 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006878 return false;
6879 }
6880
6881 switch (pname)
6882 {
6883 case GL_FENCE_STATUS_NV:
6884 case GL_FENCE_CONDITION_NV:
6885 break;
6886
6887 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006888 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006889 return false;
6890 }
6891
6892 return true;
6893}
6894
6895bool ValidateGetGraphicsResetStatusEXT(Context *context)
6896{
6897 if (!context->getExtensions().robustness)
6898 {
Jamie Madille0472f32018-11-27 16:32:45 -05006899 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006900 return false;
6901 }
6902
6903 return true;
6904}
6905
6906bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
6907 GLuint shader,
6908 GLsizei bufsize,
6909 GLsizei *length,
6910 GLchar *source)
6911{
6912 if (!context->getExtensions().translatedShaderSource)
6913 {
Jamie Madille0472f32018-11-27 16:32:45 -05006914 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006915 return false;
6916 }
6917
6918 if (bufsize < 0)
6919 {
Jamie Madille0472f32018-11-27 16:32:45 -05006920 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006921 return false;
6922 }
6923
6924 Shader *shaderObject = context->getShader(shader);
6925
6926 if (!shaderObject)
6927 {
Jamie Madille0472f32018-11-27 16:32:45 -05006928 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006929 return false;
6930 }
6931
6932 return true;
6933}
6934
6935bool ValidateIsFenceNV(Context *context, GLuint fence)
6936{
6937 if (!context->getExtensions().fence)
6938 {
Jamie Madille0472f32018-11-27 16:32:45 -05006939 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006940 return false;
6941 }
6942
6943 return true;
6944}
6945
Jamie Madill007530e2017-12-28 14:27:04 -05006946bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition)
6947{
6948 if (!context->getExtensions().fence)
6949 {
Jamie Madille0472f32018-11-27 16:32:45 -05006950 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006951 return false;
6952 }
6953
6954 if (condition != GL_ALL_COMPLETED_NV)
6955 {
Jamie Madille0472f32018-11-27 16:32:45 -05006956 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05006957 return false;
6958 }
6959
6960 FenceNV *fenceObject = context->getFenceNV(fence);
6961
6962 if (fenceObject == nullptr)
6963 {
Jamie Madille0472f32018-11-27 16:32:45 -05006964 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006965 return false;
6966 }
6967
6968 return true;
6969}
6970
6971bool ValidateTestFenceNV(Context *context, GLuint fence)
6972{
6973 if (!context->getExtensions().fence)
6974 {
Jamie Madille0472f32018-11-27 16:32:45 -05006975 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006976 return false;
6977 }
6978
6979 FenceNV *fenceObject = context->getFenceNV(fence);
6980
6981 if (fenceObject == nullptr)
6982 {
Jamie Madille0472f32018-11-27 16:32:45 -05006983 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006984 return false;
6985 }
6986
6987 if (fenceObject->isSet() != GL_TRUE)
6988 {
Jamie Madille0472f32018-11-27 16:32:45 -05006989 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05006990 return false;
6991 }
6992
6993 return true;
6994}
6995
6996bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006997 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05006998 GLsizei levels,
6999 GLenum internalformat,
7000 GLsizei width,
7001 GLsizei height)
7002{
7003 if (!context->getExtensions().textureStorage)
7004 {
Jamie Madille0472f32018-11-27 16:32:45 -05007005 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007006 return false;
7007 }
7008
7009 if (context->getClientMajorVersion() < 3)
7010 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007011 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05007012 height);
7013 }
7014
7015 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007016 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05007017 1);
7018}
7019
7020bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
7021{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05007022 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05007023 {
Jamie Madille0472f32018-11-27 16:32:45 -05007024 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007025 return false;
7026 }
7027
7028 if (index >= MAX_VERTEX_ATTRIBS)
7029 {
Jamie Madille0472f32018-11-27 16:32:45 -05007030 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05007031 return false;
7032 }
7033
7034 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
7035 {
7036 if (index == 0 && divisor != 0)
7037 {
Jamie Madillc3e37312018-11-30 15:25:39 -05007038 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05007039
7040 // We also output an error message to the debugger window if tracing is active, so
7041 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05007042 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05007043 return false;
7044 }
7045 }
7046
7047 return true;
7048}
7049
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05007050bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
7051{
7052 if (!context->getExtensions().instancedArraysEXT)
7053 {
7054 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7055 return false;
7056 }
7057
7058 if (index >= MAX_VERTEX_ATTRIBS)
7059 {
7060 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
7061 return false;
7062 }
7063
7064 return true;
7065}
7066
Jamie Madill007530e2017-12-28 14:27:04 -05007067bool ValidateTexImage3DOES(Context *context,
Cody Northrop5faff912019-06-28 14:04:50 -06007068 TextureTarget target,
Jamie Madill007530e2017-12-28 14:27:04 -05007069 GLint level,
7070 GLenum internalformat,
7071 GLsizei width,
7072 GLsizei height,
7073 GLsizei depth,
7074 GLint border,
7075 GLenum format,
7076 GLenum type,
7077 const void *pixels)
7078{
Cody Northrop5faff912019-06-28 14:04:50 -06007079 return ValidateTexImage3D(context, target, level, internalformat, width, height, depth, border,
7080 format, type, pixels);
Jamie Madill007530e2017-12-28 14:27:04 -05007081}
7082
7083bool ValidatePopGroupMarkerEXT(Context *context)
7084{
7085 if (!context->getExtensions().debugMarker)
7086 {
7087 // The debug marker calls should not set error state
7088 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05007089 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007090 return false;
7091 }
7092
7093 return true;
7094}
7095
Jamie Madillfa920eb2018-01-04 11:45:50 -05007096bool ValidateTexStorage1DEXT(Context *context,
7097 GLenum target,
7098 GLsizei levels,
7099 GLenum internalformat,
7100 GLsizei width)
7101{
7102 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05007103 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007104 return false;
7105}
7106
7107bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007108 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05007109 GLsizei levels,
7110 GLenum internalformat,
7111 GLsizei width,
7112 GLsizei height,
7113 GLsizei depth)
7114{
7115 if (!context->getExtensions().textureStorage)
7116 {
Jamie Madille0472f32018-11-27 16:32:45 -05007117 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007118 return false;
7119 }
7120
7121 if (context->getClientMajorVersion() < 3)
7122 {
Jamie Madille0472f32018-11-27 16:32:45 -05007123 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007124 return false;
7125 }
7126
7127 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
7128 depth);
7129}
7130
jchen1082af6202018-06-22 10:59:52 +08007131bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
7132{
7133 if (!context->getExtensions().parallelShaderCompile)
7134 {
Jamie Madille0472f32018-11-27 16:32:45 -05007135 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08007136 return false;
7137 }
7138 return true;
7139}
7140
Austin Eng1bf18ce2018-10-19 15:34:02 -07007141bool ValidateMultiDrawArraysANGLE(Context *context,
7142 PrimitiveMode mode,
7143 const GLint *firsts,
7144 const GLsizei *counts,
7145 GLsizei drawcount)
7146{
7147 if (!context->getExtensions().multiDraw)
7148 {
Jamie Madille0472f32018-11-27 16:32:45 -05007149 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007150 return false;
7151 }
7152 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7153 {
7154 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
7155 {
7156 return false;
7157 }
7158 }
7159 return true;
7160}
7161
7162bool ValidateMultiDrawElementsANGLE(Context *context,
7163 PrimitiveMode mode,
7164 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05007165 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08007166 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07007167 GLsizei drawcount)
7168{
7169 if (!context->getExtensions().multiDraw)
7170 {
Jamie Madille0472f32018-11-27 16:32:45 -05007171 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007172 return false;
7173 }
7174 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7175 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08007176 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07007177 {
7178 return false;
7179 }
7180 }
7181 return true;
7182}
7183
Clemen Dengce330592019-07-16 10:02:21 -04007184bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertexConvention modePacked)
Jeff Gilbert465d6092019-01-02 16:21:18 -08007185{
7186 if (!context->getExtensions().provokingVertex)
7187 {
7188 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7189 return false;
7190 }
7191
7192 switch (modePacked)
7193 {
Clemen Dengce330592019-07-16 10:02:21 -04007194 case ProvokingVertexConvention::FirstVertexConvention:
7195 case ProvokingVertexConvention::LastVertexConvention:
Jeff Gilbert465d6092019-01-02 16:21:18 -08007196 break;
7197 default:
7198 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
7199 return false;
7200 }
7201
7202 return true;
7203}
7204
Jamie Madilla5410482019-01-31 19:55:55 -05007205void RecordBindTextureTypeError(Context *context, TextureType target)
7206{
7207 ASSERT(!context->getStateCache().isValidBindTextureType(target));
7208
7209 switch (target)
7210 {
7211 case TextureType::Rectangle:
7212 ASSERT(!context->getExtensions().textureRectangle);
7213 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
7214 break;
7215
7216 case TextureType::_3D:
7217 case TextureType::_2DArray:
7218 ASSERT(context->getClientMajorVersion() < 3);
7219 context->validationError(GL_INVALID_ENUM, kES3Required);
7220 break;
7221
7222 case TextureType::_2DMultisample:
7223 ASSERT(context->getClientVersion() < Version(3, 1) &&
7224 !context->getExtensions().textureMultisample);
7225 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
7226 break;
7227
7228 case TextureType::_2DMultisampleArray:
7229 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
7230 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
7231 break;
7232
7233 case TextureType::External:
7234 ASSERT(!context->getExtensions().eglImageExternal &&
7235 !context->getExtensions().eglStreamConsumerExternal);
7236 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
7237 break;
7238
7239 default:
7240 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
7241 }
7242}
7243
Jamie Madillc29968b2016-01-20 11:17:23 -05007244} // namespace gl