blob: 4be4d2df86914eb559600e1f0f100b2e3122a9c8 [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 Lang966c9402017-04-18 12:38:27 -04001313 if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width,
1314 height, texture->getWidth(target, level),
1315 texture->getHeight(target, level)))
1316 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001317 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001318 return false;
1319 }
1320
1321 if (format != actualInternalFormat)
1322 {
Jamie Madille0472f32018-11-27 16:32:45 -05001323 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Geoff Lang966c9402017-04-18 12:38:27 -04001324 return false;
1325 }
1326 }
1327 else
1328 {
1329 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height))
1330 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001331 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001332 return false;
1333 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001334 }
1335 }
1336 else
1337 {
1338 // validate <type> by itself (used as secondary key below)
1339 switch (type)
1340 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001341 case GL_UNSIGNED_BYTE:
1342 case GL_UNSIGNED_SHORT_5_6_5:
1343 case GL_UNSIGNED_SHORT_4_4_4_4:
1344 case GL_UNSIGNED_SHORT_5_5_5_1:
1345 case GL_UNSIGNED_SHORT:
1346 case GL_UNSIGNED_INT:
1347 case GL_UNSIGNED_INT_24_8_OES:
1348 case GL_HALF_FLOAT_OES:
1349 case GL_FLOAT:
1350 break;
1351 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001352 context->validationError(GL_INVALID_ENUM, kInvalidType);
He Yunchaoced53ae2016-11-29 15:00:51 +08001353 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001354 }
1355
1356 // validate <format> + <type> combinations
1357 // - invalid <format> -> sets INVALID_ENUM
1358 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
1359 switch (format)
1360 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001361 case GL_ALPHA:
1362 case GL_LUMINANCE:
1363 case GL_LUMINANCE_ALPHA:
1364 switch (type)
1365 {
1366 case GL_UNSIGNED_BYTE:
1367 case GL_FLOAT:
1368 case GL_HALF_FLOAT_OES:
1369 break;
1370 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001371 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001372 return false;
1373 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001374 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001375 case GL_RED:
1376 case GL_RG:
1377 if (!context->getExtensions().textureRG)
1378 {
Jamie Madille0472f32018-11-27 16:32:45 -05001379 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001380 return false;
1381 }
1382 switch (type)
1383 {
1384 case GL_UNSIGNED_BYTE:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001385 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001386 case GL_FLOAT:
1387 case GL_HALF_FLOAT_OES:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001388 if (!context->getExtensions().textureFloat)
1389 {
Jamie Madille0472f32018-11-27 16:32:45 -05001390 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001391 return false;
1392 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001393 break;
1394 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001395 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001396 return false;
1397 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001398 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001399 case GL_RGB:
1400 switch (type)
1401 {
1402 case GL_UNSIGNED_BYTE:
1403 case GL_UNSIGNED_SHORT_5_6_5:
1404 case GL_FLOAT:
1405 case GL_HALF_FLOAT_OES:
1406 break;
1407 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001408 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001409 return false;
1410 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001411 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001412 case GL_RGBA:
1413 switch (type)
1414 {
1415 case GL_UNSIGNED_BYTE:
1416 case GL_UNSIGNED_SHORT_4_4_4_4:
1417 case GL_UNSIGNED_SHORT_5_5_5_1:
1418 case GL_FLOAT:
1419 case GL_HALF_FLOAT_OES:
1420 break;
1421 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001422 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001423 return false;
1424 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001425 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001426 case GL_BGRA_EXT:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001427 if (!context->getExtensions().textureFormatBGRA8888)
1428 {
Jamie Madille0472f32018-11-27 16:32:45 -05001429 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001430 return false;
1431 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001432 switch (type)
1433 {
1434 case GL_UNSIGNED_BYTE:
1435 break;
1436 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001437 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001438 return false;
1439 }
1440 break;
1441 case GL_SRGB_EXT:
1442 case GL_SRGB_ALPHA_EXT:
1443 if (!context->getExtensions().sRGB)
1444 {
Jamie Madille0472f32018-11-27 16:32:45 -05001445 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001446 return false;
1447 }
1448 switch (type)
1449 {
1450 case GL_UNSIGNED_BYTE:
1451 break;
1452 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001453 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001454 return false;
1455 }
1456 break;
1457 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are
1458 // handled below
1459 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1460 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1461 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1462 break;
1463 case GL_DEPTH_COMPONENT:
1464 switch (type)
1465 {
1466 case GL_UNSIGNED_SHORT:
1467 case GL_UNSIGNED_INT:
1468 break;
1469 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001470 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001471 return false;
1472 }
1473 break;
1474 case GL_DEPTH_STENCIL_OES:
1475 switch (type)
1476 {
1477 case GL_UNSIGNED_INT_24_8_OES:
1478 break;
1479 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001480 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001481 return false;
1482 }
1483 break;
1484 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001485 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001486 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001487 }
1488
1489 switch (format)
1490 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001491 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1492 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1493 if (context->getExtensions().textureCompressionDXT1)
1494 {
Jamie Madille0472f32018-11-27 16:32:45 -05001495 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001496 return false;
1497 }
1498 else
1499 {
Jamie Madille0472f32018-11-27 16:32:45 -05001500 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001501 return false;
1502 }
1503 break;
1504 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1505 if (context->getExtensions().textureCompressionDXT3)
1506 {
Jamie Madille0472f32018-11-27 16:32:45 -05001507 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001508 return false;
1509 }
1510 else
1511 {
Jamie Madille0472f32018-11-27 16:32:45 -05001512 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001513 return false;
1514 }
1515 break;
1516 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1517 if (context->getExtensions().textureCompressionDXT5)
1518 {
Jamie Madille0472f32018-11-27 16:32:45 -05001519 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001520 return false;
1521 }
1522 else
1523 {
Jamie Madille0472f32018-11-27 16:32:45 -05001524 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001525 return false;
1526 }
1527 break;
1528 case GL_ETC1_RGB8_OES:
1529 if (context->getExtensions().compressedETC1RGB8Texture)
1530 {
Jamie Madille0472f32018-11-27 16:32:45 -05001531 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001532 return false;
1533 }
1534 else
1535 {
Jamie Madille0472f32018-11-27 16:32:45 -05001536 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001537 return false;
1538 }
1539 break;
1540 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001541 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1542 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1543 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1544 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001545 if (context->getExtensions().lossyETCDecode)
1546 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001547 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001548 return false;
1549 }
1550 else
1551 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001552 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001553 return false;
1554 }
1555 break;
1556 case GL_DEPTH_COMPONENT:
1557 case GL_DEPTH_STENCIL_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001558 if (!context->getExtensions().depthTextureANGLE &&
1559 !(context->getExtensions().packedDepthStencil &&
1560 context->getExtensions().depthTextureOES))
He Yunchaoced53ae2016-11-29 15:00:51 +08001561 {
Jamie Madille0472f32018-11-27 16:32:45 -05001562 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001563 return false;
1564 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001565 if (target != TextureTarget::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001566 {
Jamie Madille0472f32018-11-27 16:32:45 -05001567 context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001568 return false;
1569 }
1570 // OES_depth_texture supports loading depth data and multiple levels,
1571 // but ANGLE_depth_texture does not
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001572 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001573 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001574 if (pixels != nullptr)
1575 {
1576 context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
1577 return false;
1578 }
1579 if (level != 0)
1580 {
1581 context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
1582 return false;
1583 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001584 }
1585 break;
1586 default:
1587 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001588 }
1589
Geoff Lang6e898aa2017-06-02 11:17:26 -04001590 if (!isSubImage)
1591 {
1592 switch (internalformat)
1593 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001594 // Core ES 2.0 formats
1595 case GL_ALPHA:
1596 case GL_LUMINANCE:
1597 case GL_LUMINANCE_ALPHA:
1598 case GL_RGB:
1599 case GL_RGBA:
1600 break;
1601
Geoff Lang6e898aa2017-06-02 11:17:26 -04001602 case GL_RGBA32F:
1603 if (!context->getExtensions().colorBufferFloatRGBA)
1604 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001605 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001606 return false;
1607 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001608
1609 nonEqualFormatsAllowed = true;
1610
Geoff Lang6e898aa2017-06-02 11:17:26 -04001611 if (type != GL_FLOAT)
1612 {
Jamie Madille0472f32018-11-27 16:32:45 -05001613 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001614 return false;
1615 }
1616 if (format != GL_RGBA)
1617 {
Jamie Madille0472f32018-11-27 16:32:45 -05001618 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001619 return false;
1620 }
1621 break;
1622
1623 case GL_RGB32F:
1624 if (!context->getExtensions().colorBufferFloatRGB)
1625 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001626 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001627 return false;
1628 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001629
1630 nonEqualFormatsAllowed = true;
1631
Geoff Lang6e898aa2017-06-02 11:17:26 -04001632 if (type != GL_FLOAT)
1633 {
Jamie Madille0472f32018-11-27 16:32:45 -05001634 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001635 return false;
1636 }
1637 if (format != GL_RGB)
1638 {
Jamie Madille0472f32018-11-27 16:32:45 -05001639 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001640 return false;
1641 }
1642 break;
1643
Tim Van Patten208af3e2019-03-19 09:15:55 -06001644 case GL_BGRA_EXT:
1645 if (!context->getExtensions().textureFormatBGRA8888)
1646 {
1647 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1648 return false;
1649 }
Geoff Lang6e898aa2017-06-02 11:17:26 -04001650 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001651
1652 case GL_DEPTH_COMPONENT:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001653 if (!(context->getExtensions().depthTextureAny()))
1654 {
1655 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1656 return false;
1657 }
1658 break;
1659
Tim Van Patten208af3e2019-03-19 09:15:55 -06001660 case GL_DEPTH_STENCIL:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001661 if (!(context->getExtensions().depthTextureANGLE ||
1662 context->getExtensions().packedDepthStencil))
Tim Van Patten208af3e2019-03-19 09:15:55 -06001663 {
1664 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1665 return false;
1666 }
1667 break;
1668
1669 case GL_RED:
1670 case GL_RG:
1671 if (!context->getExtensions().textureRG)
1672 {
1673 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1674 return false;
1675 }
1676 break;
1677
1678 case GL_SRGB_EXT:
1679 case GL_SRGB_ALPHA_EXT:
1680 if (!context->getExtensions().sRGB)
1681 {
1682 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1683 return false;
1684 }
1685 break;
1686
1687 default:
1688 context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat);
1689 return false;
Geoff Lang6e898aa2017-06-02 11:17:26 -04001690 }
1691 }
1692
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001693 if (type == GL_FLOAT)
1694 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001695 if (!context->getExtensions().textureFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001696 {
Jamie Madille0472f32018-11-27 16:32:45 -05001697 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001698 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001699 }
1700 }
1701 else if (type == GL_HALF_FLOAT_OES)
1702 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001703 if (!context->getExtensions().textureHalfFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001704 {
Jamie Madille0472f32018-11-27 16:32:45 -05001705 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001706 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001707 }
1708 }
1709 }
1710
Tim Van Patten208af3e2019-03-19 09:15:55 -06001711 if (isSubImage)
Geoff Langff5b2d52016-09-07 11:32:23 -04001712 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001713 const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info;
1714 if (textureInternalFormat.internalFormat == GL_NONE)
1715 {
1716 context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel);
1717 return false;
1718 }
1719
Tim Van Patten5f388c22019-03-14 09:54:23 -06001720 if (format != textureInternalFormat.format)
1721 {
1722 context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch);
1723 return false;
1724 }
1725
1726 if (context->getExtensions().webglCompatibility)
Tim Van Patten208af3e2019-03-19 09:15:55 -06001727 {
1728 if (GetInternalFormatInfo(format, type).sizedInternalFormat !=
1729 textureInternalFormat.sizedInternalFormat)
1730 {
Tim Van Patten5f388c22019-03-14 09:54:23 -06001731 context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch);
Tim Van Patten208af3e2019-03-19 09:15:55 -06001732 return false;
1733 }
1734 }
1735
1736 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
1737 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level))
1738 {
1739 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
1740 return false;
1741 }
1742
1743 if (width > 0 && height > 0 && pixels == nullptr &&
1744 context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr)
1745 {
1746 context->validationError(GL_INVALID_VALUE, kPixelDataNull);
1747 return false;
1748 }
1749 }
1750 else
1751 {
1752 if (texture->getImmutableFormat())
1753 {
1754 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
1755 return false;
1756 }
1757 }
1758
1759 // From GL_CHROMIUM_color_buffer_float_rgb[a]:
1760 // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
1761 // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
1762 // internalformat parameter and format parameter of TexImage2D must match is lifted for this
1763 // case.
1764 if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
1765 {
1766 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Langff5b2d52016-09-07 11:32:23 -04001767 return false;
1768 }
1769
Tim Van Patten208af3e2019-03-19 09:15:55 -06001770 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
1771 return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels,
1772 imageSize);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001773}
1774
He Yunchaoced53ae2016-11-29 15:00:51 +08001775bool ValidateES2TexStorageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001776 TextureType target,
He Yunchaoced53ae2016-11-29 15:00:51 +08001777 GLsizei levels,
1778 GLenum internalformat,
1779 GLsizei width,
1780 GLsizei height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001781{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001782 if (target != TextureType::_2D && target != TextureType::CubeMap &&
1783 target != TextureType::Rectangle)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001784 {
Jamie Madille0472f32018-11-27 16:32:45 -05001785 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001786 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001787 }
1788
1789 if (width < 1 || height < 1 || levels < 1)
1790 {
Jamie Madille0472f32018-11-27 16:32:45 -05001791 context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall);
Geoff Langb1196682014-07-23 13:47:29 -04001792 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001793 }
1794
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001795 if (target == TextureType::CubeMap && width != height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001796 {
Jamie Madille0472f32018-11-27 16:32:45 -05001797 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Langb1196682014-07-23 13:47:29 -04001798 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001799 }
1800
1801 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1802 {
Jamie Madille0472f32018-11-27 16:32:45 -05001803 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
Geoff Langb1196682014-07-23 13:47:29 -04001804 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001805 }
1806
Geoff Langca271392017-04-05 12:30:00 -04001807 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Lang5d601382014-07-22 15:14:06 -04001808 if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001809 {
Jamie Madille0472f32018-11-27 16:32:45 -05001810 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Langb1196682014-07-23 13:47:29 -04001811 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001812 }
1813
Geoff Langaae65a42014-05-26 12:43:44 -04001814 const gl::Caps &caps = context->getCaps();
1815
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001816 switch (target)
1817 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001818 case TextureType::_2D:
He Yunchaoced53ae2016-11-29 15:00:51 +08001819 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
1820 static_cast<GLuint>(height) > caps.max2DTextureSize)
1821 {
Jamie Madille0472f32018-11-27 16:32:45 -05001822 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001823 return false;
1824 }
1825 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001826 case TextureType::Rectangle:
Jamie Madill610640f2018-11-21 17:28:41 -05001827 if (levels != 1)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001828 {
Jamie Madille0472f32018-11-27 16:32:45 -05001829 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madill610640f2018-11-21 17:28:41 -05001830 return false;
1831 }
1832
1833 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1834 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1835 {
Jamie Madille0472f32018-11-27 16:32:45 -05001836 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001837 return false;
1838 }
1839 if (formatInfo.compressed)
1840 {
Jamie Madille0472f32018-11-27 16:32:45 -05001841 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001842 return false;
1843 }
1844 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001845 case TextureType::CubeMap:
He Yunchaoced53ae2016-11-29 15:00:51 +08001846 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize ||
1847 static_cast<GLuint>(height) > caps.maxCubeMapTextureSize)
1848 {
Jamie Madille0472f32018-11-27 16:32:45 -05001849 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001850 return false;
1851 }
1852 break;
1853 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001854 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001855 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001856 }
1857
Geoff Langc0b9ef42014-07-02 10:02:37 -04001858 if (levels != 1 && !context->getExtensions().textureNPOT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001859 {
1860 if (!gl::isPow2(width) || !gl::isPow2(height))
1861 {
Jamie Madille0472f32018-11-27 16:32:45 -05001862 context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2);
Geoff Langb1196682014-07-23 13:47:29 -04001863 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001864 }
1865 }
1866
1867 switch (internalformat)
1868 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001869 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1870 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1871 if (!context->getExtensions().textureCompressionDXT1)
1872 {
Jamie Madille0472f32018-11-27 16:32:45 -05001873 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001874 return false;
1875 }
1876 break;
1877 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1878 if (!context->getExtensions().textureCompressionDXT3)
1879 {
Jamie Madille0472f32018-11-27 16:32:45 -05001880 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001881 return false;
1882 }
1883 break;
1884 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1885 if (!context->getExtensions().textureCompressionDXT5)
1886 {
Jamie Madille0472f32018-11-27 16:32:45 -05001887 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001888 return false;
1889 }
1890 break;
1891 case GL_ETC1_RGB8_OES:
1892 if (!context->getExtensions().compressedETC1RGB8Texture)
1893 {
Jamie Madille0472f32018-11-27 16:32:45 -05001894 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001895 return false;
1896 }
1897 break;
1898 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001899 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1900 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1901 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1902 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001903 if (!context->getExtensions().lossyETCDecode)
1904 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001905 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001906 return false;
1907 }
1908 break;
1909 case GL_RGBA32F_EXT:
1910 case GL_RGB32F_EXT:
1911 case GL_ALPHA32F_EXT:
1912 case GL_LUMINANCE32F_EXT:
1913 case GL_LUMINANCE_ALPHA32F_EXT:
1914 if (!context->getExtensions().textureFloat)
1915 {
Jamie Madille0472f32018-11-27 16:32:45 -05001916 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001917 return false;
1918 }
1919 break;
1920 case GL_RGBA16F_EXT:
1921 case GL_RGB16F_EXT:
1922 case GL_ALPHA16F_EXT:
1923 case GL_LUMINANCE16F_EXT:
1924 case GL_LUMINANCE_ALPHA16F_EXT:
1925 if (!context->getExtensions().textureHalfFloat)
1926 {
Jamie Madille0472f32018-11-27 16:32:45 -05001927 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001928 return false;
1929 }
1930 break;
1931 case GL_R8_EXT:
1932 case GL_RG8_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001933 if (!context->getExtensions().textureRG)
1934 {
Jamie Madille0472f32018-11-27 16:32:45 -05001935 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001936 return false;
1937 }
1938 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001939 case GL_R16F_EXT:
1940 case GL_RG16F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001941 if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat)
1942 {
Jamie Madille0472f32018-11-27 16:32:45 -05001943 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001944 return false;
1945 }
1946 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001947 case GL_R32F_EXT:
1948 case GL_RG32F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001949 if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat)
He Yunchaoced53ae2016-11-29 15:00:51 +08001950 {
Jamie Madille0472f32018-11-27 16:32:45 -05001951 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001952 return false;
1953 }
1954 break;
1955 case GL_DEPTH_COMPONENT16:
1956 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001957 if (!(context->getExtensions().depthTextureAny()))
He Yunchaoced53ae2016-11-29 15:00:51 +08001958 {
Jamie Madille0472f32018-11-27 16:32:45 -05001959 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001960 return false;
1961 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001962 if (target != TextureType::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001963 {
Jamie Madille0472f32018-11-27 16:32:45 -05001964 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001965 return false;
1966 }
1967 // ANGLE_depth_texture only supports 1-level textures
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001968 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001969 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001970 if (levels != 1)
1971 {
1972 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1973 return false;
1974 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001975 }
1976 break;
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001977 case GL_DEPTH24_STENCIL8_OES:
1978 if (!(context->getExtensions().depthTextureANGLE ||
1979 (context->getExtensions().packedDepthStencil &&
1980 context->getExtensions().textureStorage)))
1981 {
1982 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1983 return false;
1984 }
1985 if (target != TextureType::_2D)
1986 {
1987 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
1988 return false;
1989 }
1990 if (!context->getExtensions().packedDepthStencil)
1991 {
1992 // ANGLE_depth_texture only supports 1-level textures
1993 if (levels != 1)
1994 {
1995 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1996 return false;
1997 }
1998 }
1999 break;
2000
He Yunchaoced53ae2016-11-29 15:00:51 +08002001 default:
2002 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002003 }
2004
Jamie Madillcfc73cc2019-04-08 16:26:51 -04002005 gl::Texture *texture = context->getTextureByType(target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002006 if (!texture || texture->id() == 0)
2007 {
Jamie Madille0472f32018-11-27 16:32:45 -05002008 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
Geoff Langb1196682014-07-23 13:47:29 -04002009 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002010 }
2011
Geoff Lang69cce582015-09-17 13:20:36 -04002012 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002013 {
Jamie Madille0472f32018-11-27 16:32:45 -05002014 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
Geoff Langb1196682014-07-23 13:47:29 -04002015 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002016 }
2017
2018 return true;
2019}
2020
He Yunchaoced53ae2016-11-29 15:00:51 +08002021bool ValidateDiscardFramebufferEXT(Context *context,
2022 GLenum target,
2023 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07002024 const GLenum *attachments)
2025{
Jamie Madillc29968b2016-01-20 11:17:23 -05002026 if (!context->getExtensions().discardFramebuffer)
2027 {
Jamie Madille0472f32018-11-27 16:32:45 -05002028 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002029 return false;
2030 }
2031
Austin Kinross08332632015-05-05 13:35:47 -07002032 bool defaultFramebuffer = false;
2033
2034 switch (target)
2035 {
He Yunchaoced53ae2016-11-29 15:00:51 +08002036 case GL_FRAMEBUFFER:
2037 defaultFramebuffer =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002038 (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0);
He Yunchaoced53ae2016-11-29 15:00:51 +08002039 break;
2040 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002041 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08002042 return false;
Austin Kinross08332632015-05-05 13:35:47 -07002043 }
2044
He Yunchaoced53ae2016-11-29 15:00:51 +08002045 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
2046 defaultFramebuffer);
Austin Kinross08332632015-05-05 13:35:47 -07002047}
2048
Austin Kinrossbc781f32015-10-26 09:27:38 -07002049bool ValidateBindVertexArrayOES(Context *context, GLuint array)
2050{
2051 if (!context->getExtensions().vertexArrayObject)
2052 {
Jamie Madille0472f32018-11-27 16:32:45 -05002053 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002054 return false;
2055 }
2056
2057 return ValidateBindVertexArrayBase(context, array);
2058}
2059
Jamie Madilld7576732017-08-26 18:49:50 -04002060bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002061{
2062 if (!context->getExtensions().vertexArrayObject)
2063 {
Jamie Madille0472f32018-11-27 16:32:45 -05002064 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002065 return false;
2066 }
2067
Olli Etuaho41997e72016-03-10 13:38:39 +02002068 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002069}
2070
Jamie Madilld7576732017-08-26 18:49:50 -04002071bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002072{
2073 if (!context->getExtensions().vertexArrayObject)
2074 {
Jamie Madille0472f32018-11-27 16:32:45 -05002075 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002076 return false;
2077 }
2078
Olli Etuaho41997e72016-03-10 13:38:39 +02002079 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002080}
2081
Jamie Madilld7576732017-08-26 18:49:50 -04002082bool ValidateIsVertexArrayOES(Context *context, GLuint array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002083{
2084 if (!context->getExtensions().vertexArrayObject)
2085 {
Jamie Madille0472f32018-11-27 16:32:45 -05002086 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002087 return false;
2088 }
2089
2090 return true;
2091}
Geoff Langc5629752015-12-07 16:29:04 -05002092
2093bool ValidateProgramBinaryOES(Context *context,
2094 GLuint program,
2095 GLenum binaryFormat,
2096 const void *binary,
2097 GLint length)
2098{
2099 if (!context->getExtensions().getProgramBinary)
2100 {
Jamie Madille0472f32018-11-27 16:32:45 -05002101 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002102 return false;
2103 }
2104
2105 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
2106}
2107
2108bool ValidateGetProgramBinaryOES(Context *context,
2109 GLuint program,
2110 GLsizei bufSize,
2111 GLsizei *length,
2112 GLenum *binaryFormat,
2113 void *binary)
2114{
2115 if (!context->getExtensions().getProgramBinary)
2116 {
Jamie Madille0472f32018-11-27 16:32:45 -05002117 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002118 return false;
2119 }
2120
2121 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
2122}
Geoff Lange102fee2015-12-10 11:23:30 -05002123
Geoff Lang70d0f492015-12-10 17:45:46 -05002124static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication)
2125{
2126 switch (source)
2127 {
2128 case GL_DEBUG_SOURCE_API:
2129 case GL_DEBUG_SOURCE_SHADER_COMPILER:
2130 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
2131 case GL_DEBUG_SOURCE_OTHER:
2132 // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted
2133 return !mustBeThirdPartyOrApplication;
2134
2135 case GL_DEBUG_SOURCE_THIRD_PARTY:
2136 case GL_DEBUG_SOURCE_APPLICATION:
2137 return true;
2138
2139 default:
2140 return false;
2141 }
2142}
2143
2144static bool ValidDebugType(GLenum type)
2145{
2146 switch (type)
2147 {
2148 case GL_DEBUG_TYPE_ERROR:
2149 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
2150 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
2151 case GL_DEBUG_TYPE_PERFORMANCE:
2152 case GL_DEBUG_TYPE_PORTABILITY:
2153 case GL_DEBUG_TYPE_OTHER:
2154 case GL_DEBUG_TYPE_MARKER:
2155 case GL_DEBUG_TYPE_PUSH_GROUP:
2156 case GL_DEBUG_TYPE_POP_GROUP:
2157 return true;
2158
2159 default:
2160 return false;
2161 }
2162}
2163
2164static bool ValidDebugSeverity(GLenum severity)
2165{
2166 switch (severity)
2167 {
2168 case GL_DEBUG_SEVERITY_HIGH:
2169 case GL_DEBUG_SEVERITY_MEDIUM:
2170 case GL_DEBUG_SEVERITY_LOW:
2171 case GL_DEBUG_SEVERITY_NOTIFICATION:
2172 return true;
2173
2174 default:
2175 return false;
2176 }
2177}
2178
Geoff Lange102fee2015-12-10 11:23:30 -05002179bool ValidateDebugMessageControlKHR(Context *context,
2180 GLenum source,
2181 GLenum type,
2182 GLenum severity,
2183 GLsizei count,
2184 const GLuint *ids,
2185 GLboolean enabled)
2186{
2187 if (!context->getExtensions().debug)
2188 {
Jamie Madille0472f32018-11-27 16:32:45 -05002189 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002190 return false;
2191 }
2192
Geoff Lang70d0f492015-12-10 17:45:46 -05002193 if (!ValidDebugSource(source, false) && source != GL_DONT_CARE)
2194 {
Jamie Madille0472f32018-11-27 16:32:45 -05002195 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002196 return false;
2197 }
2198
2199 if (!ValidDebugType(type) && type != GL_DONT_CARE)
2200 {
Jamie Madille0472f32018-11-27 16:32:45 -05002201 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002202 return false;
2203 }
2204
2205 if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE)
2206 {
Jamie Madille0472f32018-11-27 16:32:45 -05002207 context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002208 return false;
2209 }
2210
2211 if (count > 0)
2212 {
2213 if (source == GL_DONT_CARE || type == GL_DONT_CARE)
2214 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002215 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002216 return false;
2217 }
2218
2219 if (severity != GL_DONT_CARE)
2220 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002221 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002222 return false;
2223 }
2224 }
2225
Geoff Lange102fee2015-12-10 11:23:30 -05002226 return true;
2227}
2228
2229bool ValidateDebugMessageInsertKHR(Context *context,
2230 GLenum source,
2231 GLenum type,
2232 GLuint id,
2233 GLenum severity,
2234 GLsizei length,
2235 const GLchar *buf)
2236{
2237 if (!context->getExtensions().debug)
2238 {
Jamie Madille0472f32018-11-27 16:32:45 -05002239 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002240 return false;
2241 }
2242
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002243 if (!context->getState().getDebug().isOutputEnabled())
Geoff Lang70d0f492015-12-10 17:45:46 -05002244 {
2245 // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do
2246 // not generate an error.
2247 return false;
2248 }
2249
2250 if (!ValidDebugSeverity(severity))
2251 {
Jamie Madille0472f32018-11-27 16:32:45 -05002252 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002253 return false;
2254 }
2255
2256 if (!ValidDebugType(type))
2257 {
Jamie Madille0472f32018-11-27 16:32:45 -05002258 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002259 return false;
2260 }
2261
2262 if (!ValidDebugSource(source, true))
2263 {
Jamie Madille0472f32018-11-27 16:32:45 -05002264 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002265 return false;
2266 }
2267
2268 size_t messageLength = (length < 0) ? strlen(buf) : length;
2269 if (messageLength > context->getExtensions().maxDebugMessageLength)
2270 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002271 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002272 return false;
2273 }
2274
Geoff Lange102fee2015-12-10 11:23:30 -05002275 return true;
2276}
2277
2278bool ValidateDebugMessageCallbackKHR(Context *context,
2279 GLDEBUGPROCKHR callback,
2280 const void *userParam)
2281{
2282 if (!context->getExtensions().debug)
2283 {
Jamie Madille0472f32018-11-27 16:32:45 -05002284 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002285 return false;
2286 }
2287
Geoff Lange102fee2015-12-10 11:23:30 -05002288 return true;
2289}
2290
2291bool ValidateGetDebugMessageLogKHR(Context *context,
2292 GLuint count,
2293 GLsizei bufSize,
2294 GLenum *sources,
2295 GLenum *types,
2296 GLuint *ids,
2297 GLenum *severities,
2298 GLsizei *lengths,
2299 GLchar *messageLog)
2300{
2301 if (!context->getExtensions().debug)
2302 {
Jamie Madille0472f32018-11-27 16:32:45 -05002303 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002304 return false;
2305 }
2306
Geoff Lang70d0f492015-12-10 17:45:46 -05002307 if (bufSize < 0 && messageLog != nullptr)
2308 {
Jamie Madille0472f32018-11-27 16:32:45 -05002309 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002310 return false;
2311 }
2312
Geoff Lange102fee2015-12-10 11:23:30 -05002313 return true;
2314}
2315
2316bool ValidatePushDebugGroupKHR(Context *context,
2317 GLenum source,
2318 GLuint id,
2319 GLsizei length,
2320 const GLchar *message)
2321{
2322 if (!context->getExtensions().debug)
2323 {
Jamie Madille0472f32018-11-27 16:32:45 -05002324 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002325 return false;
2326 }
2327
Geoff Lang70d0f492015-12-10 17:45:46 -05002328 if (!ValidDebugSource(source, true))
2329 {
Jamie Madille0472f32018-11-27 16:32:45 -05002330 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002331 return false;
2332 }
2333
2334 size_t messageLength = (length < 0) ? strlen(message) : length;
2335 if (messageLength > context->getExtensions().maxDebugMessageLength)
2336 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002337 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002338 return false;
2339 }
2340
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002341 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002342 if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth)
2343 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002344 context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth);
Geoff Lang70d0f492015-12-10 17:45:46 -05002345 return false;
2346 }
2347
Geoff Lange102fee2015-12-10 11:23:30 -05002348 return true;
2349}
2350
2351bool ValidatePopDebugGroupKHR(Context *context)
2352{
2353 if (!context->getExtensions().debug)
2354 {
Jamie Madille0472f32018-11-27 16:32:45 -05002355 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002356 return false;
2357 }
2358
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002359 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002360 if (currentStackSize <= 1)
2361 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002362 context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup);
Geoff Lang70d0f492015-12-10 17:45:46 -05002363 return false;
2364 }
2365
2366 return true;
2367}
2368
2369static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name)
2370{
2371 switch (identifier)
2372 {
2373 case GL_BUFFER:
2374 if (context->getBuffer(name) == nullptr)
2375 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002376 context->validationError(GL_INVALID_VALUE, kInvalidBufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002377 return false;
2378 }
2379 return true;
2380
2381 case GL_SHADER:
2382 if (context->getShader(name) == nullptr)
2383 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002384 context->validationError(GL_INVALID_VALUE, kInvalidShaderName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002385 return false;
2386 }
2387 return true;
2388
2389 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002390 if (context->getProgramNoResolveLink(name) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002391 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002392 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002393 return false;
2394 }
2395 return true;
2396
2397 case GL_VERTEX_ARRAY:
2398 if (context->getVertexArray(name) == nullptr)
2399 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002400 context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002401 return false;
2402 }
2403 return true;
2404
2405 case GL_QUERY:
2406 if (context->getQuery(name) == nullptr)
2407 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002408 context->validationError(GL_INVALID_VALUE, kInvalidQueryName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002409 return false;
2410 }
2411 return true;
2412
2413 case GL_TRANSFORM_FEEDBACK:
2414 if (context->getTransformFeedback(name) == nullptr)
2415 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002416 context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002417 return false;
2418 }
2419 return true;
2420
2421 case GL_SAMPLER:
2422 if (context->getSampler(name) == nullptr)
2423 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002424 context->validationError(GL_INVALID_VALUE, kInvalidSamplerName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002425 return false;
2426 }
2427 return true;
2428
2429 case GL_TEXTURE:
2430 if (context->getTexture(name) == nullptr)
2431 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002432 context->validationError(GL_INVALID_VALUE, kInvalidTextureName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002433 return false;
2434 }
2435 return true;
2436
2437 case GL_RENDERBUFFER:
2438 if (context->getRenderbuffer(name) == nullptr)
2439 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002440 context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002441 return false;
2442 }
2443 return true;
2444
2445 case GL_FRAMEBUFFER:
2446 if (context->getFramebuffer(name) == nullptr)
2447 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002448 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002449 return false;
2450 }
2451 return true;
2452
2453 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05002454 context->validationError(GL_INVALID_ENUM, kInvalidIndentifier);
Geoff Lang70d0f492015-12-10 17:45:46 -05002455 return false;
2456 }
Geoff Lange102fee2015-12-10 11:23:30 -05002457}
2458
Martin Radev9d901792016-07-15 15:58:58 +03002459static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label)
2460{
2461 size_t labelLength = 0;
2462
2463 if (length < 0)
2464 {
2465 if (label != nullptr)
2466 {
2467 labelLength = strlen(label);
2468 }
2469 }
2470 else
2471 {
2472 labelLength = static_cast<size_t>(length);
2473 }
2474
2475 if (labelLength > context->getExtensions().maxLabelLength)
2476 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002477 context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength);
Martin Radev9d901792016-07-15 15:58:58 +03002478 return false;
2479 }
2480
2481 return true;
2482}
2483
Geoff Lange102fee2015-12-10 11:23:30 -05002484bool ValidateObjectLabelKHR(Context *context,
2485 GLenum identifier,
2486 GLuint name,
2487 GLsizei length,
2488 const GLchar *label)
2489{
2490 if (!context->getExtensions().debug)
2491 {
Jamie Madille0472f32018-11-27 16:32:45 -05002492 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002493 return false;
2494 }
2495
Geoff Lang70d0f492015-12-10 17:45:46 -05002496 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2497 {
2498 return false;
2499 }
2500
Martin Radev9d901792016-07-15 15:58:58 +03002501 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002502 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002503 return false;
2504 }
2505
Geoff Lange102fee2015-12-10 11:23:30 -05002506 return true;
2507}
2508
2509bool ValidateGetObjectLabelKHR(Context *context,
2510 GLenum identifier,
2511 GLuint name,
2512 GLsizei bufSize,
2513 GLsizei *length,
2514 GLchar *label)
2515{
2516 if (!context->getExtensions().debug)
2517 {
Jamie Madille0472f32018-11-27 16:32:45 -05002518 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002519 return false;
2520 }
2521
Geoff Lang70d0f492015-12-10 17:45:46 -05002522 if (bufSize < 0)
2523 {
Jamie Madille0472f32018-11-27 16:32:45 -05002524 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002525 return false;
2526 }
2527
2528 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2529 {
2530 return false;
2531 }
2532
Martin Radev9d901792016-07-15 15:58:58 +03002533 return true;
Geoff Lang70d0f492015-12-10 17:45:46 -05002534}
2535
2536static bool ValidateObjectPtrName(Context *context, const void *ptr)
2537{
Jamie Madill70b5bb02017-08-28 13:32:37 -04002538 if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002539 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002540 context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer);
Geoff Lang70d0f492015-12-10 17:45:46 -05002541 return false;
2542 }
2543
Geoff Lange102fee2015-12-10 11:23:30 -05002544 return true;
2545}
2546
2547bool ValidateObjectPtrLabelKHR(Context *context,
2548 const void *ptr,
2549 GLsizei length,
2550 const GLchar *label)
2551{
2552 if (!context->getExtensions().debug)
2553 {
Jamie Madille0472f32018-11-27 16:32:45 -05002554 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002555 return false;
2556 }
2557
Geoff Lang70d0f492015-12-10 17:45:46 -05002558 if (!ValidateObjectPtrName(context, ptr))
2559 {
2560 return false;
2561 }
2562
Martin Radev9d901792016-07-15 15:58:58 +03002563 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002564 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002565 return false;
2566 }
2567
Geoff Lange102fee2015-12-10 11:23:30 -05002568 return true;
2569}
2570
2571bool ValidateGetObjectPtrLabelKHR(Context *context,
2572 const void *ptr,
2573 GLsizei bufSize,
2574 GLsizei *length,
2575 GLchar *label)
2576{
2577 if (!context->getExtensions().debug)
2578 {
Jamie Madille0472f32018-11-27 16:32:45 -05002579 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002580 return false;
2581 }
2582
Geoff Lang70d0f492015-12-10 17:45:46 -05002583 if (bufSize < 0)
2584 {
Jamie Madille0472f32018-11-27 16:32:45 -05002585 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002586 return false;
2587 }
2588
2589 if (!ValidateObjectPtrName(context, ptr))
2590 {
2591 return false;
2592 }
2593
Martin Radev9d901792016-07-15 15:58:58 +03002594 return true;
Geoff Lange102fee2015-12-10 11:23:30 -05002595}
2596
2597bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params)
2598{
2599 if (!context->getExtensions().debug)
2600 {
Jamie Madille0472f32018-11-27 16:32:45 -05002601 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002602 return false;
2603 }
2604
Geoff Lang70d0f492015-12-10 17:45:46 -05002605 // TODO: represent this in Context::getQueryParameterInfo.
2606 switch (pname)
2607 {
2608 case GL_DEBUG_CALLBACK_FUNCTION:
2609 case GL_DEBUG_CALLBACK_USER_PARAM:
2610 break;
2611
2612 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002613 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang70d0f492015-12-10 17:45:46 -05002614 return false;
2615 }
2616
Geoff Lange102fee2015-12-10 11:23:30 -05002617 return true;
2618}
Jamie Madillc29968b2016-01-20 11:17:23 -05002619
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002620bool ValidateGetPointervRobustANGLERobustANGLE(Context *context,
2621 GLenum pname,
2622 GLsizei bufSize,
2623 GLsizei *length,
2624 void **params)
2625{
2626 UNIMPLEMENTED();
2627 return false;
2628}
2629
Jamie Madillc29968b2016-01-20 11:17:23 -05002630bool ValidateBlitFramebufferANGLE(Context *context,
2631 GLint srcX0,
2632 GLint srcY0,
2633 GLint srcX1,
2634 GLint srcY1,
2635 GLint dstX0,
2636 GLint dstY0,
2637 GLint dstX1,
2638 GLint dstY1,
2639 GLbitfield mask,
2640 GLenum filter)
2641{
2642 if (!context->getExtensions().framebufferBlit)
2643 {
Jamie Madille0472f32018-11-27 16:32:45 -05002644 context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable);
Jamie Madillc29968b2016-01-20 11:17:23 -05002645 return false;
2646 }
2647
2648 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
2649 {
2650 // TODO(jmadill): Determine if this should be available on other implementations.
Jamie Madille0472f32018-11-27 16:32:45 -05002651 context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip);
Jamie Madillc29968b2016-01-20 11:17:23 -05002652 return false;
2653 }
2654
2655 if (filter == GL_LINEAR)
2656 {
Jamie Madille0472f32018-11-27 16:32:45 -05002657 context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear);
Jamie Madillc29968b2016-01-20 11:17:23 -05002658 return false;
2659 }
2660
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002661 Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
2662 Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002663
2664 if (mask & GL_COLOR_BUFFER_BIT)
2665 {
Jamie Madill4e71b2b2019-07-08 13:23:38 -04002666 const FramebufferAttachment *readColorAttachment =
2667 readFramebuffer->getReadColorAttachment();
2668 const FramebufferAttachment *drawColorAttachment =
2669 drawFramebuffer->getFirstColorAttachment();
Jamie Madillc29968b2016-01-20 11:17:23 -05002670
2671 if (readColorAttachment && drawColorAttachment)
2672 {
2673 if (!(readColorAttachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002674 readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002675 readColorAttachment->type() != GL_RENDERBUFFER &&
2676 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2677 {
Jamie Madill610640f2018-11-21 17:28:41 -05002678 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002679 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002680 return false;
2681 }
2682
Geoff Langa15472a2015-08-11 11:48:03 -04002683 for (size_t drawbufferIdx = 0;
2684 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002685 {
Geoff Langa15472a2015-08-11 11:48:03 -04002686 const FramebufferAttachment *attachment =
2687 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2688 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002689 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002690 if (!(attachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002691 attachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002692 attachment->type() != GL_RENDERBUFFER &&
2693 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2694 {
Jamie Madill610640f2018-11-21 17:28:41 -05002695 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002696 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002697 return false;
2698 }
2699
2700 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002701 if (!Format::EquivalentForBlit(attachment->getFormat(),
2702 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002703 {
Jamie Madill610640f2018-11-21 17:28:41 -05002704 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002705 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002706 return false;
2707 }
2708 }
2709 }
2710
Jamie Madill427064d2018-04-13 16:20:34 -04002711 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002712 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002713 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2714 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2715 {
Jamie Madill610640f2018-11-21 17:28:41 -05002716 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002717 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002718 return false;
2719 }
2720 }
2721 }
2722
2723 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2724 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2725 for (size_t i = 0; i < 2; i++)
2726 {
2727 if (mask & masks[i])
2728 {
2729 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002730 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002731 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002732 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002733
2734 if (readBuffer && drawBuffer)
2735 {
2736 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2737 dstX0, dstY0, dstX1, dstY1))
2738 {
2739 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002740 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002741 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002742 return false;
2743 }
2744
2745 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2746 {
Jamie Madill610640f2018-11-21 17:28:41 -05002747 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002748 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002749 return false;
2750 }
2751 }
2752 }
2753 }
2754
2755 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2756 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002757}
Jamie Madillc29968b2016-01-20 11:17:23 -05002758
Jamie Madill5b772312018-03-08 20:28:32 -05002759bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002760{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002761 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002762 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002763
Jamie Madill427064d2018-04-13 16:20:34 -04002764 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002765 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002766 return false;
2767 }
2768
2769 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2770 {
Jamie Madille0472f32018-11-27 16:32:45 -05002771 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002772 return false;
2773 }
2774
Olli Etuaho94c91a92018-07-19 15:10:24 +03002775 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002776 {
2777 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2778 GL_SIGNED_NORMALIZED};
2779
Corentin Wallez59c41592017-07-11 13:19:54 -04002780 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002781 drawBufferIdx++)
2782 {
2783 if (!ValidateWebGLFramebufferAttachmentClearType(
2784 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2785 {
2786 return false;
2787 }
2788 }
2789 }
2790
Mingyu Huebab6702019-04-19 14:36:45 -07002791 if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery)
Olli Etuaho94c91a92018-07-19 15:10:24 +03002792 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002793 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002794 Framebuffer *framebuffer = state.getDrawFramebuffer();
2795 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2796 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002797 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002798 return false;
2799 }
2800 }
2801
Jamie Madillc29968b2016-01-20 11:17:23 -05002802 return true;
2803}
2804
Jamie Madill5b772312018-03-08 20:28:32 -05002805bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002806{
2807 if (!context->getExtensions().drawBuffers)
2808 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002809 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002810 return false;
2811 }
2812
2813 return ValidateDrawBuffersBase(context, n, bufs);
2814}
2815
Jamie Madill73a84962016-02-12 09:27:23 -05002816bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002817 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002818 GLint level,
2819 GLint internalformat,
2820 GLsizei width,
2821 GLsizei height,
2822 GLint border,
2823 GLenum format,
2824 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002825 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002826{
Martin Radev1be913c2016-07-11 17:59:16 +03002827 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002828 {
2829 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002830 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002831 }
2832
Martin Radev1be913c2016-07-11 17:59:16 +03002833 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002834 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002835 0, 0, width, height, 1, border, format, type, -1,
2836 pixels);
2837}
2838
Brandon Jones416aaf92018-04-10 08:10:16 -07002839bool ValidateTexImage2DRobustANGLE(Context *context,
2840 TextureTarget target,
2841 GLint level,
2842 GLint internalformat,
2843 GLsizei width,
2844 GLsizei height,
2845 GLint border,
2846 GLenum format,
2847 GLenum type,
2848 GLsizei bufSize,
2849 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04002850{
2851 if (!ValidateRobustEntryPoint(context, bufSize))
2852 {
2853 return false;
2854 }
2855
2856 if (context->getClientMajorVersion() < 3)
2857 {
2858 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
2859 0, 0, width, height, border, format, type, bufSize,
2860 pixels);
2861 }
2862
2863 ASSERT(context->getClientMajorVersion() >= 3);
2864 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
2865 0, 0, width, height, 1, border, format, type, bufSize,
2866 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002867}
2868
2869bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002870 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002871 GLint level,
2872 GLint xoffset,
2873 GLint yoffset,
2874 GLsizei width,
2875 GLsizei height,
2876 GLenum format,
2877 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002878 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002879{
2880
Martin Radev1be913c2016-07-11 17:59:16 +03002881 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002882 {
2883 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002884 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002885 }
2886
Martin Radev1be913c2016-07-11 17:59:16 +03002887 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002888 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002889 yoffset, 0, width, height, 1, 0, format, type, -1,
2890 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002891}
2892
Geoff Langc52f6f12016-10-14 10:18:00 -04002893bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002894 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04002895 GLint level,
2896 GLint xoffset,
2897 GLint yoffset,
2898 GLsizei width,
2899 GLsizei height,
2900 GLenum format,
2901 GLenum type,
2902 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002903 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04002904{
2905 if (!ValidateRobustEntryPoint(context, bufSize))
2906 {
2907 return false;
2908 }
2909
2910 if (context->getClientMajorVersion() < 3)
2911 {
2912 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
2913 yoffset, width, height, 0, format, type, bufSize,
2914 pixels);
2915 }
2916
2917 ASSERT(context->getClientMajorVersion() >= 3);
2918 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
2919 yoffset, 0, width, height, 1, 0, format, type, bufSize,
2920 pixels);
2921}
2922
Cody Northrop5faff912019-06-28 14:04:50 -06002923bool ValidateTexSubImage3DOES(Context *context,
2924 TextureTarget target,
2925 GLint level,
2926 GLint xoffset,
2927 GLint yoffset,
2928 GLint zoffset,
2929 GLsizei width,
2930 GLsizei height,
2931 GLsizei depth,
2932 GLenum format,
2933 GLenum type,
2934 const void *pixels)
2935{
2936 return ValidateTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, height,
2937 depth, format, type, pixels);
2938}
2939
Jamie Madill73a84962016-02-12 09:27:23 -05002940bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002941 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002942 GLint level,
2943 GLenum internalformat,
2944 GLsizei width,
2945 GLsizei height,
2946 GLint border,
2947 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002948 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002949{
Martin Radev1be913c2016-07-11 17:59:16 +03002950 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002951 {
2952 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002953 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002954 {
2955 return false;
2956 }
2957 }
2958 else
2959 {
Martin Radev1be913c2016-07-11 17:59:16 +03002960 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002961 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002962 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002963 data))
2964 {
2965 return false;
2966 }
2967 }
2968
Geoff Langca271392017-04-05 12:30:00 -04002969 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04002970
2971 GLuint blockSize = 0;
2972 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002973 {
Jamie Madille0472f32018-11-27 16:32:45 -05002974 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002975 return false;
2976 }
2977
Jamie Madillca2ff382018-07-11 09:01:17 -04002978 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002979 {
Jamie Madille0472f32018-11-27 16:32:45 -05002980 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05002981 return false;
2982 }
2983
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002984 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002985 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002986 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002987 return false;
2988 }
2989
Jamie Madill73a84962016-02-12 09:27:23 -05002990 return true;
2991}
2992
Corentin Wallezb2931602017-04-11 15:58:57 -04002993bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002994 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002995 GLint level,
2996 GLenum internalformat,
2997 GLsizei width,
2998 GLsizei height,
2999 GLint border,
3000 GLsizei imageSize,
3001 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003002 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003003{
3004 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3005 {
3006 return false;
3007 }
3008
3009 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
3010 border, imageSize, data);
3011}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003012
Cody Northrop5faff912019-06-28 14:04:50 -06003013bool ValidateCompressedTexImage3DOES(Context *context,
3014 TextureTarget target,
3015 GLint level,
3016 GLenum internalformat,
3017 GLsizei width,
3018 GLsizei height,
3019 GLsizei depth,
3020 GLint border,
3021 GLsizei imageSize,
3022 const void *data)
3023{
3024 return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height,
3025 depth, border, imageSize, data);
3026}
3027
Corentin Wallezb2931602017-04-11 15:58:57 -04003028bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003029 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04003030 GLint level,
3031 GLint xoffset,
3032 GLint yoffset,
3033 GLsizei width,
3034 GLsizei height,
3035 GLenum format,
3036 GLsizei imageSize,
3037 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003038 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003039{
3040 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3041 {
3042 return false;
3043 }
3044
3045 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
3046 format, imageSize, data);
3047}
3048
Jamie Madill73a84962016-02-12 09:27:23 -05003049bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003050 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003051 GLint level,
3052 GLint xoffset,
3053 GLint yoffset,
3054 GLsizei width,
3055 GLsizei height,
3056 GLenum format,
3057 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003058 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003059{
Martin Radev1be913c2016-07-11 17:59:16 +03003060 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05003061 {
3062 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003063 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05003064 {
3065 return false;
3066 }
3067 }
3068 else
3069 {
Martin Radev1be913c2016-07-11 17:59:16 +03003070 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003071 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003072 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05003073 data))
3074 {
3075 return false;
3076 }
3077 }
3078
Geoff Langca271392017-04-05 12:30:00 -04003079 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04003080 GLuint blockSize = 0;
3081 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003082 {
Jamie Madille0472f32018-11-27 16:32:45 -05003083 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003084 return false;
3085 }
3086
Jamie Madillca2ff382018-07-11 09:01:17 -04003087 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003088 {
Jamie Madille0472f32018-11-27 16:32:45 -05003089 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05003090 return false;
3091 }
3092
3093 return true;
3094}
3095
Cody Northrop5faff912019-06-28 14:04:50 -06003096bool ValidateCompressedTexSubImage3DOES(Context *context,
3097 TextureTarget target,
3098 GLint level,
3099 GLint xoffset,
3100 GLint yoffset,
3101 GLint zoffset,
3102 GLsizei width,
3103 GLsizei height,
3104 GLsizei depth,
3105 GLenum format,
3106 GLsizei imageSize,
3107 const void *data)
3108{
3109 return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width,
3110 height, depth, format, imageSize, data);
3111}
3112
Corentin Wallez336129f2017-10-17 15:55:40 -04003113bool ValidateGetBufferPointervOES(Context *context,
3114 BufferBinding target,
3115 GLenum pname,
3116 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003117{
Jamie Madillc3e37312018-11-30 15:25:39 -05003118 if (!context->getExtensions().mapBuffer)
3119 {
3120 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3121 return false;
3122 }
3123
Geoff Lang496c02d2016-10-20 11:38:11 -07003124 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003125}
3126
Corentin Wallez336129f2017-10-17 15:55:40 -04003127bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003128{
3129 if (!context->getExtensions().mapBuffer)
3130 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003131 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003132 return false;
3133 }
3134
Corentin Walleze4477002017-12-01 14:39:58 -05003135 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03003136 {
Jamie Madille0472f32018-11-27 16:32:45 -05003137 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03003138 return false;
3139 }
3140
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003141 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003142
3143 if (buffer == nullptr)
3144 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003145 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03003146 return false;
3147 }
3148
3149 if (access != GL_WRITE_ONLY_OES)
3150 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003151 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03003152 return false;
3153 }
3154
3155 if (buffer->isMapped())
3156 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003157 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003158 return false;
3159 }
3160
Geoff Lang79f71042017-08-14 16:43:43 -04003161 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003162}
3163
Corentin Wallez336129f2017-10-17 15:55:40 -04003164bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003165{
3166 if (!context->getExtensions().mapBuffer)
3167 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003168 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003169 return false;
3170 }
3171
3172 return ValidateUnmapBufferBase(context, target);
3173}
3174
3175bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003176 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003177 GLintptr offset,
3178 GLsizeiptr length,
3179 GLbitfield access)
3180{
3181 if (!context->getExtensions().mapBufferRange)
3182 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003183 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003184 return false;
3185 }
3186
3187 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3188}
3189
Michael Spang7a8c3e52019-04-03 14:49:57 -04003190bool ValidateBufferStorageMemEXT(Context *context,
3191 TextureType target,
3192 GLsizeiptr size,
3193 GLuint memory,
3194 GLuint64 offset)
3195{
3196 if (!context->getExtensions().memoryObject)
3197 {
3198 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3199 return false;
3200 }
3201
3202 UNIMPLEMENTED();
3203 return false;
3204}
3205
3206bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects)
3207{
3208 if (!context->getExtensions().memoryObject)
3209 {
3210 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3211 return false;
3212 }
3213
Michael Spangfb201c52019-04-03 14:57:35 -04003214 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003215}
3216
3217bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects)
3218{
3219 if (!context->getExtensions().memoryObject)
3220 {
3221 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3222 return false;
3223 }
3224
Michael Spangfb201c52019-04-03 14:57:35 -04003225 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003226}
3227
3228bool ValidateGetMemoryObjectParameterivEXT(Context *context,
3229 GLuint memoryObject,
3230 GLenum pname,
3231 GLint *params)
3232{
3233 if (!context->getExtensions().memoryObject)
3234 {
3235 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3236 return false;
3237 }
3238
3239 UNIMPLEMENTED();
3240 return false;
3241}
3242
3243bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3244{
3245 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3246 {
3247 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3248 return false;
3249 }
3250
3251 UNIMPLEMENTED();
3252 return false;
3253}
3254
3255bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3256{
3257 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3258 {
3259 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3260 return false;
3261 }
3262
3263 UNIMPLEMENTED();
3264 return false;
3265}
3266
3267bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject)
3268{
3269 if (!context->getExtensions().memoryObject)
3270 {
3271 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3272 return false;
3273 }
3274
Michael Spangfb201c52019-04-03 14:57:35 -04003275 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003276}
3277
3278bool ValidateMemoryObjectParameterivEXT(Context *context,
3279 GLuint memoryObject,
3280 GLenum pname,
3281 const GLint *params)
3282{
3283 if (!context->getExtensions().memoryObject)
3284 {
3285 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3286 return false;
3287 }
3288
3289 UNIMPLEMENTED();
3290 return false;
3291}
3292
3293bool ValidateTexStorageMem2DEXT(Context *context,
3294 TextureType target,
3295 GLsizei levels,
3296 GLenum internalFormat,
3297 GLsizei width,
3298 GLsizei height,
3299 GLuint memory,
3300 GLuint64 offset)
3301{
3302 if (!context->getExtensions().memoryObject)
3303 {
3304 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3305 return false;
3306 }
3307
Michael Spangf02a7672019-04-09 18:45:23 -04003308 if (context->getClientMajorVersion() < 3)
3309 {
3310 return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width,
3311 height);
3312 }
3313
3314 ASSERT(context->getClientMajorVersion() >= 3);
3315 return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height,
3316 1);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003317}
3318
3319bool ValidateTexStorageMem3DEXT(Context *context,
3320 TextureType target,
3321 GLsizei levels,
3322 GLenum internalFormat,
3323 GLsizei width,
3324 GLsizei height,
3325 GLsizei depth,
3326 GLuint memory,
3327 GLuint64 offset)
3328{
3329 if (!context->getExtensions().memoryObject)
3330 {
3331 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3332 return false;
3333 }
3334
3335 UNIMPLEMENTED();
3336 return false;
3337}
3338
Michael Spang9de3ddb2019-04-03 16:23:40 -04003339bool ValidateImportMemoryFdEXT(Context *context,
3340 GLuint memory,
3341 GLuint64 size,
Michael Spange0da9ce2019-04-16 14:34:51 -04003342 HandleType handleType,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003343 GLint fd)
3344{
3345 if (!context->getExtensions().memoryObjectFd)
3346 {
3347 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3348 return false;
3349 }
3350
Michael Spang3b2c6bf2019-04-16 17:19:50 -04003351 switch (handleType)
3352 {
3353 case HandleType::OpaqueFd:
3354 break;
3355 default:
3356 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3357 return false;
3358 }
3359
3360 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003361}
3362
Michael Spang7a8c3e52019-04-03 14:49:57 -04003363bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores)
3364{
3365 if (!context->getExtensions().semaphore)
3366 {
3367 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3368 return false;
3369 }
3370
Michael Spang5093ba62019-05-14 17:36:36 -04003371 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003372}
3373
3374bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores)
3375{
3376 if (!context->getExtensions().semaphore)
3377 {
3378 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3379 return false;
3380 }
3381
Michael Spang5093ba62019-05-14 17:36:36 -04003382 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003383}
3384
3385bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
3386 GLuint semaphore,
3387 GLenum pname,
3388 GLuint64 *params)
3389{
3390 if (!context->getExtensions().semaphore)
3391 {
3392 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3393 return false;
3394 }
3395
3396 UNIMPLEMENTED();
3397 return false;
3398}
3399
3400bool ValidateIsSemaphoreEXT(Context *context, GLuint semaphore)
3401{
3402 if (!context->getExtensions().semaphore)
3403 {
3404 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3405 return false;
3406 }
3407
Michael Spang5093ba62019-05-14 17:36:36 -04003408 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003409}
3410
3411bool ValidateSemaphoreParameterui64vEXT(Context *context,
3412 GLuint semaphore,
3413 GLenum pname,
3414 const GLuint64 *params)
3415{
3416 if (!context->getExtensions().semaphore)
3417 {
3418 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3419 return false;
3420 }
3421
3422 UNIMPLEMENTED();
3423 return false;
3424}
3425
3426bool ValidateSignalSemaphoreEXT(Context *context,
3427 GLuint semaphore,
3428 GLuint numBufferBarriers,
3429 const GLuint *buffers,
3430 GLuint numTextureBarriers,
3431 const GLuint *textures,
3432 const GLenum *dstLayouts)
3433{
3434 if (!context->getExtensions().semaphore)
3435 {
3436 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3437 return false;
3438 }
3439
Michael Spangab6a59b2019-05-21 21:26:26 -04003440 for (GLuint i = 0; i < numTextureBarriers; ++i)
3441 {
3442 if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i])))
3443 {
3444 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3445 return false;
3446 }
3447 }
3448
3449 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003450}
3451
3452bool ValidateWaitSemaphoreEXT(Context *context,
3453 GLuint semaphore,
3454 GLuint numBufferBarriers,
3455 const GLuint *buffers,
3456 GLuint numTextureBarriers,
3457 const GLuint *textures,
3458 const GLenum *srcLayouts)
3459{
3460 if (!context->getExtensions().semaphore)
3461 {
3462 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3463 return false;
3464 }
3465
Michael Spangab6a59b2019-05-21 21:26:26 -04003466 for (GLuint i = 0; i < numTextureBarriers; ++i)
3467 {
3468 if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i])))
3469 {
3470 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3471 return false;
3472 }
3473 }
3474
3475 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003476}
3477
Michael Spange0da9ce2019-04-16 14:34:51 -04003478bool ValidateImportSemaphoreFdEXT(Context *context,
3479 GLuint semaphore,
3480 HandleType handleType,
3481 GLint fd)
Michael Spang9de3ddb2019-04-03 16:23:40 -04003482{
3483 if (!context->getExtensions().semaphoreFd)
3484 {
3485 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3486 return false;
3487 }
3488
Michael Spang6bb193c2019-05-22 16:32:21 -04003489 switch (handleType)
3490 {
3491 case HandleType::OpaqueFd:
3492 break;
3493 default:
3494 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3495 return false;
3496 }
3497
3498 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003499}
3500
Corentin Wallez336129f2017-10-17 15:55:40 -04003501bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003502{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003503 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003504 ASSERT(buffer != nullptr);
3505
3506 // Check if this buffer is currently being used as a transform feedback output buffer
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003507 if (context->getState().isTransformFeedbackActive())
Geoff Lang79f71042017-08-14 16:43:43 -04003508 {
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003509 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003510 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3511 {
3512 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3513 if (transformFeedbackBuffer.get() == buffer)
3514 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003515 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003516 return false;
3517 }
3518 }
3519 }
3520
James Darpiniane8a93c62018-01-04 18:02:24 -08003521 if (context->getExtensions().webglCompatibility &&
3522 buffer->isBoundForTransformFeedbackAndOtherUse())
3523 {
Jamie Madille0472f32018-11-27 16:32:45 -05003524 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003525 return false;
3526 }
3527
Geoff Lang79f71042017-08-14 16:43:43 -04003528 return true;
3529}
3530
Olli Etuaho4f667482016-03-30 15:56:35 +03003531bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003532 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003533 GLintptr offset,
3534 GLsizeiptr length)
3535{
3536 if (!context->getExtensions().mapBufferRange)
3537 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003538 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003539 return false;
3540 }
3541
3542 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3543}
3544
Geoff Langd8605522016-04-13 10:19:12 -04003545bool ValidateBindUniformLocationCHROMIUM(Context *context,
3546 GLuint program,
3547 GLint location,
3548 const GLchar *name)
3549{
3550 if (!context->getExtensions().bindUniformLocation)
3551 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003552 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003553 return false;
3554 }
3555
3556 Program *programObject = GetValidProgram(context, program);
3557 if (!programObject)
3558 {
3559 return false;
3560 }
3561
3562 if (location < 0)
3563 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003564 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003565 return false;
3566 }
3567
3568 const Caps &caps = context->getCaps();
3569 if (static_cast<size_t>(location) >=
3570 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3571 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003572 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003573 return false;
3574 }
3575
Geoff Langfc32e8b2017-05-31 14:16:59 -04003576 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3577 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003578 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003579 {
Jamie Madille0472f32018-11-27 16:32:45 -05003580 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003581 return false;
3582 }
3583
Geoff Langd8605522016-04-13 10:19:12 -04003584 if (strncmp(name, "gl_", 3) == 0)
3585 {
Jamie Madille0472f32018-11-27 16:32:45 -05003586 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003587 return false;
3588 }
3589
3590 return true;
3591}
3592
Jamie Madille2e406c2016-06-02 13:04:10 -04003593bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003594{
3595 if (!context->getExtensions().framebufferMixedSamples)
3596 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003597 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003598 return false;
3599 }
3600 switch (components)
3601 {
3602 case GL_RGB:
3603 case GL_RGBA:
3604 case GL_ALPHA:
3605 case GL_NONE:
3606 break;
3607 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003608 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003609 return false;
3610 }
3611
3612 return true;
3613}
3614
Sami Väisänene45e53b2016-05-25 10:36:04 +03003615// CHROMIUM_path_rendering
3616
Jamie Madill007530e2017-12-28 14:27:04 -05003617bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003618{
Jamie Madill007530e2017-12-28 14:27:04 -05003619 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003620 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003621 return false;
3622 }
Jamie Madill007530e2017-12-28 14:27:04 -05003623
Sami Väisänene45e53b2016-05-25 10:36:04 +03003624 if (matrix == nullptr)
3625 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003626 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003627 return false;
3628 }
Jamie Madill007530e2017-12-28 14:27:04 -05003629
Sami Väisänene45e53b2016-05-25 10:36:04 +03003630 return true;
3631}
3632
Jamie Madill007530e2017-12-28 14:27:04 -05003633bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003634{
Jamie Madill007530e2017-12-28 14:27:04 -05003635 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003636}
3637
Jamie Madill007530e2017-12-28 14:27:04 -05003638bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003639{
3640 if (!context->getExtensions().pathRendering)
3641 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003642 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003643 return false;
3644 }
3645
3646 // range = 0 is undefined in NV_path_rendering.
3647 // we add stricter semantic check here and require a non zero positive range.
3648 if (range <= 0)
3649 {
Jamie Madille0472f32018-11-27 16:32:45 -05003650 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003651 return false;
3652 }
3653
3654 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3655 {
Jamie Madille0472f32018-11-27 16:32:45 -05003656 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003657 return false;
3658 }
3659
3660 return true;
3661}
3662
Jamie Madill007530e2017-12-28 14:27:04 -05003663bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003664{
3665 if (!context->getExtensions().pathRendering)
3666 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003667 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003668 return false;
3669 }
3670
3671 // range = 0 is undefined in NV_path_rendering.
3672 // we add stricter semantic check here and require a non zero positive range.
3673 if (range <= 0)
3674 {
Jamie Madille0472f32018-11-27 16:32:45 -05003675 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003676 return false;
3677 }
3678
3679 angle::CheckedNumeric<std::uint32_t> checkedRange(path);
3680 checkedRange += range;
3681
3682 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3683 {
Jamie Madille0472f32018-11-27 16:32:45 -05003684 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003685 return false;
3686 }
3687 return true;
3688}
3689
Jamie Madill007530e2017-12-28 14:27:04 -05003690bool ValidatePathCommandsCHROMIUM(Context *context,
3691 GLuint path,
3692 GLsizei numCommands,
3693 const GLubyte *commands,
3694 GLsizei numCoords,
3695 GLenum coordType,
3696 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003697{
3698 if (!context->getExtensions().pathRendering)
3699 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003700 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003701 return false;
3702 }
Brandon Jones59770802018-04-02 13:18:42 -07003703 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003704 {
Jamie Madille0472f32018-11-27 16:32:45 -05003705 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003706 return false;
3707 }
3708
3709 if (numCommands < 0)
3710 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003711 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003712 return false;
3713 }
3714 else if (numCommands > 0)
3715 {
3716 if (!commands)
3717 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003718 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003719 return false;
3720 }
3721 }
3722
3723 if (numCoords < 0)
3724 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003725 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003726 return false;
3727 }
3728 else if (numCoords > 0)
3729 {
3730 if (!coords)
3731 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003732 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003733 return false;
3734 }
3735 }
3736
3737 std::uint32_t coordTypeSize = 0;
3738 switch (coordType)
3739 {
3740 case GL_BYTE:
3741 coordTypeSize = sizeof(GLbyte);
3742 break;
3743
3744 case GL_UNSIGNED_BYTE:
3745 coordTypeSize = sizeof(GLubyte);
3746 break;
3747
3748 case GL_SHORT:
3749 coordTypeSize = sizeof(GLshort);
3750 break;
3751
3752 case GL_UNSIGNED_SHORT:
3753 coordTypeSize = sizeof(GLushort);
3754 break;
3755
3756 case GL_FLOAT:
3757 coordTypeSize = sizeof(GLfloat);
3758 break;
3759
3760 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003761 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003762 return false;
3763 }
3764
3765 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3766 checkedSize += (coordTypeSize * numCoords);
3767 if (!checkedSize.IsValid())
3768 {
Jamie Madille0472f32018-11-27 16:32:45 -05003769 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003770 return false;
3771 }
3772
3773 // early return skips command data validation when it doesn't exist.
3774 if (!commands)
3775 return true;
3776
3777 GLsizei expectedNumCoords = 0;
3778 for (GLsizei i = 0; i < numCommands; ++i)
3779 {
3780 switch (commands[i])
3781 {
3782 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3783 break;
3784 case GL_MOVE_TO_CHROMIUM:
3785 case GL_LINE_TO_CHROMIUM:
3786 expectedNumCoords += 2;
3787 break;
3788 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3789 expectedNumCoords += 4;
3790 break;
3791 case GL_CUBIC_CURVE_TO_CHROMIUM:
3792 expectedNumCoords += 6;
3793 break;
3794 case GL_CONIC_CURVE_TO_CHROMIUM:
3795 expectedNumCoords += 5;
3796 break;
3797 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003798 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003799 return false;
3800 }
3801 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003802
Sami Väisänene45e53b2016-05-25 10:36:04 +03003803 if (expectedNumCoords != numCoords)
3804 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003805 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003806 return false;
3807 }
3808
3809 return true;
3810}
3811
Jamie Madill007530e2017-12-28 14:27:04 -05003812bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003813{
3814 if (!context->getExtensions().pathRendering)
3815 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003816 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003817 return false;
3818 }
Brandon Jones59770802018-04-02 13:18:42 -07003819 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003820 {
Jamie Madille0472f32018-11-27 16:32:45 -05003821 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003822 return false;
3823 }
3824
3825 switch (pname)
3826 {
3827 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3828 if (value < 0.0f)
3829 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003830 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003831 return false;
3832 }
3833 break;
3834 case GL_PATH_END_CAPS_CHROMIUM:
3835 switch (static_cast<GLenum>(value))
3836 {
3837 case GL_FLAT_CHROMIUM:
3838 case GL_SQUARE_CHROMIUM:
3839 case GL_ROUND_CHROMIUM:
3840 break;
3841 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003842 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003843 return false;
3844 }
3845 break;
3846 case GL_PATH_JOIN_STYLE_CHROMIUM:
3847 switch (static_cast<GLenum>(value))
3848 {
3849 case GL_MITER_REVERT_CHROMIUM:
3850 case GL_BEVEL_CHROMIUM:
3851 case GL_ROUND_CHROMIUM:
3852 break;
3853 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003854 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003855 return false;
3856 }
Nico Weber41b072b2018-02-09 10:01:32 -05003857 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03003858 case GL_PATH_MITER_LIMIT_CHROMIUM:
3859 if (value < 0.0f)
3860 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003861 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003862 return false;
3863 }
3864 break;
3865
3866 case GL_PATH_STROKE_BOUND_CHROMIUM:
3867 // no errors, only clamping.
3868 break;
3869
3870 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003871 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003872 return false;
3873 }
3874 return true;
3875}
3876
Jamie Madill007530e2017-12-28 14:27:04 -05003877bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value)
3878{
3879 // TODO(jmadill): Use proper clamping cast.
3880 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
3881}
3882
3883bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003884{
3885 if (!context->getExtensions().pathRendering)
3886 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003887 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003888 return false;
3889 }
3890
Brandon Jones59770802018-04-02 13:18:42 -07003891 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003892 {
Jamie Madille0472f32018-11-27 16:32:45 -05003893 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003894 return false;
3895 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003896
Sami Väisänene45e53b2016-05-25 10:36:04 +03003897 if (!value)
3898 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003899 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003900 return false;
3901 }
3902
3903 switch (pname)
3904 {
3905 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3906 case GL_PATH_END_CAPS_CHROMIUM:
3907 case GL_PATH_JOIN_STYLE_CHROMIUM:
3908 case GL_PATH_MITER_LIMIT_CHROMIUM:
3909 case GL_PATH_STROKE_BOUND_CHROMIUM:
3910 break;
3911
3912 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003913 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003914 return false;
3915 }
3916
3917 return true;
3918}
3919
Jamie Madill007530e2017-12-28 14:27:04 -05003920bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value)
3921{
3922 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
3923 reinterpret_cast<GLfloat *>(value));
3924}
3925
3926bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003927{
3928 if (!context->getExtensions().pathRendering)
3929 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003930 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003931 return false;
3932 }
3933
3934 switch (func)
3935 {
3936 case GL_NEVER:
3937 case GL_ALWAYS:
3938 case GL_LESS:
3939 case GL_LEQUAL:
3940 case GL_EQUAL:
3941 case GL_GEQUAL:
3942 case GL_GREATER:
3943 case GL_NOTEQUAL:
3944 break;
3945 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003946 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003947 return false;
3948 }
3949
3950 return true;
3951}
3952
3953// Note that the spec specifies that for the path drawing commands
3954// if the path object is not an existing path object the command
3955// does nothing and no error is generated.
3956// However if the path object exists but has not been specified any
3957// commands then an error is generated.
3958
Jamie Madill007530e2017-12-28 14:27:04 -05003959bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003960{
3961 if (!context->getExtensions().pathRendering)
3962 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003963 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003964 return false;
3965 }
Brandon Jones59770802018-04-02 13:18:42 -07003966 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003967 {
Jamie Madille0472f32018-11-27 16:32:45 -05003968 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003969 return false;
3970 }
3971
3972 switch (fillMode)
3973 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06003974 case GL_INVERT:
Sami Väisänene45e53b2016-05-25 10:36:04 +03003975 case GL_COUNT_UP_CHROMIUM:
3976 case GL_COUNT_DOWN_CHROMIUM:
3977 break;
3978 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003979 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003980 return false;
3981 }
3982
3983 if (!isPow2(mask + 1))
3984 {
Jamie Madille0472f32018-11-27 16:32:45 -05003985 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003986 return false;
3987 }
3988
3989 return true;
3990}
3991
Jamie Madill007530e2017-12-28 14:27:04 -05003992bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003993{
3994 if (!context->getExtensions().pathRendering)
3995 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003996 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003997 return false;
3998 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003999
Brandon Jones59770802018-04-02 13:18:42 -07004000 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004001 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004002 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004003 return false;
4004 }
4005
4006 return true;
4007}
4008
Jamie Madill007530e2017-12-28 14:27:04 -05004009bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004010{
4011 if (!context->getExtensions().pathRendering)
4012 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004013 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004014 return false;
4015 }
Brandon Jones59770802018-04-02 13:18:42 -07004016 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004017 {
Jamie Madille0472f32018-11-27 16:32:45 -05004018 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004019 return false;
4020 }
4021
4022 switch (coverMode)
4023 {
4024 case GL_CONVEX_HULL_CHROMIUM:
4025 case GL_BOUNDING_BOX_CHROMIUM:
4026 break;
4027 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004028 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004029 return false;
4030 }
4031 return true;
4032}
4033
Jamie Madill778bf092018-11-14 09:54:36 -05004034bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
4035{
4036 return ValidateCoverPathCHROMIUM(context, path, coverMode);
4037}
4038
4039bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
4040{
4041 return ValidateCoverPathCHROMIUM(context, path, coverMode);
4042}
4043
Jamie Madill007530e2017-12-28 14:27:04 -05004044bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
4045 GLuint path,
4046 GLenum fillMode,
4047 GLuint mask,
4048 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004049{
Jamie Madill007530e2017-12-28 14:27:04 -05004050 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
4051 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004052}
4053
Jamie Madill007530e2017-12-28 14:27:04 -05004054bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
4055 GLuint path,
4056 GLint reference,
4057 GLuint mask,
4058 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004059{
Jamie Madill007530e2017-12-28 14:27:04 -05004060 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
4061 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004062}
4063
Brandon Jonesd1049182018-03-28 10:02:20 -07004064bool ValidateIsPathCHROMIUM(Context *context, GLuint path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004065{
4066 if (!context->getExtensions().pathRendering)
4067 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004068 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004069 return false;
4070 }
4071 return true;
4072}
4073
Jamie Madill007530e2017-12-28 14:27:04 -05004074bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
4075 GLsizei numPaths,
4076 GLenum pathNameType,
4077 const void *paths,
4078 GLuint pathBase,
4079 GLenum coverMode,
4080 GLenum transformType,
4081 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004082{
4083 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4084 transformType, transformValues))
4085 return false;
4086
4087 switch (coverMode)
4088 {
4089 case GL_CONVEX_HULL_CHROMIUM:
4090 case GL_BOUNDING_BOX_CHROMIUM:
4091 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4092 break;
4093 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004094 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004095 return false;
4096 }
4097
4098 return true;
4099}
4100
Jamie Madill007530e2017-12-28 14:27:04 -05004101bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
4102 GLsizei numPaths,
4103 GLenum pathNameType,
4104 const void *paths,
4105 GLuint pathBase,
4106 GLenum coverMode,
4107 GLenum transformType,
4108 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004109{
4110 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4111 transformType, transformValues))
4112 return false;
4113
4114 switch (coverMode)
4115 {
4116 case GL_CONVEX_HULL_CHROMIUM:
4117 case GL_BOUNDING_BOX_CHROMIUM:
4118 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4119 break;
4120 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004121 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004122 return false;
4123 }
4124
4125 return true;
4126}
4127
Jamie Madill007530e2017-12-28 14:27:04 -05004128bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
4129 GLsizei numPaths,
4130 GLenum pathNameType,
4131 const void *paths,
4132 GLuint pathBase,
4133 GLenum fillMode,
4134 GLuint mask,
4135 GLenum transformType,
4136 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004137{
4138
4139 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4140 transformType, transformValues))
4141 return false;
4142
4143 switch (fillMode)
4144 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004145 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004146 case GL_COUNT_UP_CHROMIUM:
4147 case GL_COUNT_DOWN_CHROMIUM:
4148 break;
4149 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004150 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004151 return false;
4152 }
4153 if (!isPow2(mask + 1))
4154 {
Jamie Madille0472f32018-11-27 16:32:45 -05004155 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004156 return false;
4157 }
4158 return true;
4159}
4160
Jamie Madill007530e2017-12-28 14:27:04 -05004161bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
4162 GLsizei numPaths,
4163 GLenum pathNameType,
4164 const void *paths,
4165 GLuint pathBase,
4166 GLint reference,
4167 GLuint mask,
4168 GLenum transformType,
4169 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004170{
4171 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4172 transformType, transformValues))
4173 return false;
4174
4175 // no more validation here.
4176
4177 return true;
4178}
4179
Jamie Madill007530e2017-12-28 14:27:04 -05004180bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
4181 GLsizei numPaths,
4182 GLenum pathNameType,
4183 const void *paths,
4184 GLuint pathBase,
4185 GLenum fillMode,
4186 GLuint mask,
4187 GLenum coverMode,
4188 GLenum transformType,
4189 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004190{
4191 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4192 transformType, transformValues))
4193 return false;
4194
4195 switch (coverMode)
4196 {
4197 case GL_CONVEX_HULL_CHROMIUM:
4198 case GL_BOUNDING_BOX_CHROMIUM:
4199 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4200 break;
4201 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004202 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004203 return false;
4204 }
4205
4206 switch (fillMode)
4207 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004208 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004209 case GL_COUNT_UP_CHROMIUM:
4210 case GL_COUNT_DOWN_CHROMIUM:
4211 break;
4212 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004213 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004214 return false;
4215 }
4216 if (!isPow2(mask + 1))
4217 {
Jamie Madille0472f32018-11-27 16:32:45 -05004218 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004219 return false;
4220 }
4221
4222 return true;
4223}
4224
Jamie Madill007530e2017-12-28 14:27:04 -05004225bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4226 GLsizei numPaths,
4227 GLenum pathNameType,
4228 const void *paths,
4229 GLuint pathBase,
4230 GLint reference,
4231 GLuint mask,
4232 GLenum coverMode,
4233 GLenum transformType,
4234 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004235{
4236 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4237 transformType, transformValues))
4238 return false;
4239
4240 switch (coverMode)
4241 {
4242 case GL_CONVEX_HULL_CHROMIUM:
4243 case GL_BOUNDING_BOX_CHROMIUM:
4244 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4245 break;
4246 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004247 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004248 return false;
4249 }
4250
4251 return true;
4252}
4253
Jamie Madill007530e2017-12-28 14:27:04 -05004254bool ValidateBindFragmentInputLocationCHROMIUM(Context *context,
4255 GLuint program,
4256 GLint location,
4257 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004258{
4259 if (!context->getExtensions().pathRendering)
4260 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004261 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004262 return false;
4263 }
4264
4265 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4266 if (location >= MaxLocation)
4267 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004268 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004269 return false;
4270 }
4271
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004272 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004273 if (!programObject)
4274 {
Jamie Madille0472f32018-11-27 16:32:45 -05004275 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004276 return false;
4277 }
4278
4279 if (!name)
4280 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004281 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004282 return false;
4283 }
4284
4285 if (angle::BeginsWith(name, "gl_"))
4286 {
Jamie Madille0472f32018-11-27 16:32:45 -05004287 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004288 return false;
4289 }
4290
4291 return true;
4292}
4293
Jamie Madill007530e2017-12-28 14:27:04 -05004294bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
4295 GLuint program,
4296 GLint location,
4297 GLenum genMode,
4298 GLint components,
4299 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004300{
4301 if (!context->getExtensions().pathRendering)
4302 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004303 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004304 return false;
4305 }
4306
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004307 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004308 if (!programObject || programObject->isFlaggedForDeletion())
4309 {
Jamie Madille0472f32018-11-27 16:32:45 -05004310 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004311 return false;
4312 }
4313
4314 if (!programObject->isLinked())
4315 {
Jamie Madille0472f32018-11-27 16:32:45 -05004316 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004317 return false;
4318 }
4319
4320 switch (genMode)
4321 {
4322 case GL_NONE:
4323 if (components != 0)
4324 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004325 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004326 return false;
4327 }
4328 break;
4329
4330 case GL_OBJECT_LINEAR_CHROMIUM:
4331 case GL_EYE_LINEAR_CHROMIUM:
4332 case GL_CONSTANT_CHROMIUM:
4333 if (components < 1 || components > 4)
4334 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004335 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004336 return false;
4337 }
4338 if (!coeffs)
4339 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004340 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004341 return false;
4342 }
4343 break;
4344
4345 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004346 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004347 return false;
4348 }
4349
4350 // If the location is -1 then the command is silently ignored
4351 // and no further validation is needed.
4352 if (location == -1)
4353 return true;
4354
jchen103fd614d2018-08-13 12:21:58 +08004355 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004356
4357 if (!binding.valid)
4358 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004359 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004360 return false;
4361 }
4362
4363 if (binding.type != GL_NONE)
4364 {
4365 GLint expectedComponents = 0;
4366 switch (binding.type)
4367 {
4368 case GL_FLOAT:
4369 expectedComponents = 1;
4370 break;
4371 case GL_FLOAT_VEC2:
4372 expectedComponents = 2;
4373 break;
4374 case GL_FLOAT_VEC3:
4375 expectedComponents = 3;
4376 break;
4377 case GL_FLOAT_VEC4:
4378 expectedComponents = 4;
4379 break;
4380 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004381 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004382 return false;
4383 }
4384 if (expectedComponents != components && genMode != GL_NONE)
4385 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004386 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004387 return false;
4388 }
4389 }
4390 return true;
4391}
4392
Geoff Lang97073d12016-04-20 10:42:34 -07004393bool ValidateCopyTextureCHROMIUM(Context *context,
4394 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004395 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004396 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004397 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004398 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004399 GLint internalFormat,
4400 GLenum destType,
4401 GLboolean unpackFlipY,
4402 GLboolean unpackPremultiplyAlpha,
4403 GLboolean unpackUnmultiplyAlpha)
4404{
4405 if (!context->getExtensions().copyTexture)
4406 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004407 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004408 return false;
4409 }
4410
Geoff Lang4f0e0032017-05-01 16:04:35 -04004411 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004412 if (source == nullptr)
4413 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004414 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004415 return false;
4416 }
4417
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004418 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004419 {
Jamie Madille0472f32018-11-27 16:32:45 -05004420 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004421 return false;
4422 }
4423
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004424 TextureType sourceType = source->getType();
4425 ASSERT(sourceType != TextureType::CubeMap);
4426 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004427
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004428 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004429 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004430 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004431 return false;
4432 }
4433
Geoff Lang4f0e0032017-05-01 16:04:35 -04004434 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4435 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4436 if (sourceWidth == 0 || sourceHeight == 0)
4437 {
Jamie Madille0472f32018-11-27 16:32:45 -05004438 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004439 return false;
4440 }
4441
4442 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4443 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004444 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004445 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004446 return false;
4447 }
4448
Geoff Lang63458a32017-10-30 15:16:53 -04004449 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4450 {
Jamie Madille0472f32018-11-27 16:32:45 -05004451 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004452 return false;
4453 }
4454
Geoff Lang4f0e0032017-05-01 16:04:35 -04004455 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004456 if (dest == nullptr)
4457 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004458 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004459 return false;
4460 }
4461
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004462 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004463 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004464 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004465 return false;
4466 }
4467
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004468 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004469 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004470 {
Jamie Madille0472f32018-11-27 16:32:45 -05004471 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004472 return false;
4473 }
4474
Geoff Lang97073d12016-04-20 10:42:34 -07004475 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4476 {
Geoff Lang97073d12016-04-20 10:42:34 -07004477 return false;
4478 }
4479
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004480 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004481 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004482 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004483 return false;
4484 }
4485
Geoff Lang97073d12016-04-20 10:42:34 -07004486 if (dest->getImmutableFormat())
4487 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004488 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004489 return false;
4490 }
4491
4492 return true;
4493}
4494
4495bool ValidateCopySubTextureCHROMIUM(Context *context,
4496 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004497 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004498 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004499 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004500 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004501 GLint xoffset,
4502 GLint yoffset,
4503 GLint x,
4504 GLint y,
4505 GLsizei width,
4506 GLsizei height,
4507 GLboolean unpackFlipY,
4508 GLboolean unpackPremultiplyAlpha,
4509 GLboolean unpackUnmultiplyAlpha)
4510{
4511 if (!context->getExtensions().copyTexture)
4512 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004513 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004514 return false;
4515 }
4516
Geoff Lang4f0e0032017-05-01 16:04:35 -04004517 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004518 if (source == nullptr)
4519 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004520 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004521 return false;
4522 }
4523
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004524 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004525 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004526 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004527 return false;
4528 }
4529
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004530 TextureType sourceType = source->getType();
4531 ASSERT(sourceType != TextureType::CubeMap);
4532 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004533
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004534 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004535 {
Jamie Madille0472f32018-11-27 16:32:45 -05004536 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004537 return false;
4538 }
4539
4540 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4541 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004542 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004543 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004544 return false;
4545 }
4546
4547 if (x < 0 || y < 0)
4548 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004549 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004550 return false;
4551 }
4552
4553 if (width < 0 || height < 0)
4554 {
Jamie Madille0472f32018-11-27 16:32:45 -05004555 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004556 return false;
4557 }
4558
Geoff Lang4f0e0032017-05-01 16:04:35 -04004559 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4560 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004561 {
Jamie Madille0472f32018-11-27 16:32:45 -05004562 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004563 return false;
4564 }
4565
Geoff Lang4f0e0032017-05-01 16:04:35 -04004566 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4567 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004568 {
Jamie Madille0472f32018-11-27 16:32:45 -05004569 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004570 return false;
4571 }
4572
Geoff Lang63458a32017-10-30 15:16:53 -04004573 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4574 {
Jamie Madille0472f32018-11-27 16:32:45 -05004575 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004576 return false;
4577 }
4578
Geoff Lang4f0e0032017-05-01 16:04:35 -04004579 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004580 if (dest == nullptr)
4581 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004582 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004583 return false;
4584 }
4585
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004586 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004587 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004588 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004589 return false;
4590 }
4591
Brandon Jones28783792018-03-05 09:37:32 -08004592 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4593 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004594 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004595 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004596 return false;
4597 }
4598
Geoff Lang4f0e0032017-05-01 16:04:35 -04004599 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4600 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004601 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004602 return false;
4603 }
4604
4605 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4606 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004607 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004608 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004609 return false;
4610 }
4611
4612 if (xoffset < 0 || yoffset < 0)
4613 {
Jamie Madille0472f32018-11-27 16:32:45 -05004614 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004615 return false;
4616 }
4617
Geoff Lang4f0e0032017-05-01 16:04:35 -04004618 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4619 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004620 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004621 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004622 return false;
4623 }
4624
4625 return true;
4626}
4627
Geoff Lang47110bf2016-04-20 11:13:22 -07004628bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId)
4629{
4630 if (!context->getExtensions().copyCompressedTexture)
4631 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004632 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004633 return false;
4634 }
4635
4636 const gl::Texture *source = context->getTexture(sourceId);
4637 if (source == nullptr)
4638 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004639 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004640 return false;
4641 }
4642
Corentin Wallez99d492c2018-02-27 15:17:10 -05004643 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004644 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004645 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004646 return false;
4647 }
4648
Corentin Wallez99d492c2018-02-27 15:17:10 -05004649 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4650 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004651 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004652 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004653 return false;
4654 }
4655
Corentin Wallez99d492c2018-02-27 15:17:10 -05004656 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004657 if (!sourceFormat.info->compressed)
4658 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004659 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004660 return false;
4661 }
4662
4663 const gl::Texture *dest = context->getTexture(destId);
4664 if (dest == nullptr)
4665 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004666 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004667 return false;
4668 }
4669
Corentin Wallez99d492c2018-02-27 15:17:10 -05004670 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004671 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004672 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004673 return false;
4674 }
4675
4676 if (dest->getImmutableFormat())
4677 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004678 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004679 return false;
4680 }
4681
4682 return true;
4683}
4684
Jiawei Shao385b3e02018-03-21 09:43:28 +08004685bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004686{
4687 switch (type)
4688 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004689 case ShaderType::Vertex:
4690 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004691 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004692
Jiawei Shao385b3e02018-03-21 09:43:28 +08004693 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004694 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004695 {
Jamie Madille0472f32018-11-27 16:32:45 -05004696 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004697 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004698 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004699 break;
4700
Jiawei Shao385b3e02018-03-21 09:43:28 +08004701 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004702 if (!context->getExtensions().geometryShader)
4703 {
Jamie Madille0472f32018-11-27 16:32:45 -05004704 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004705 return false;
4706 }
4707 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004708 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004709 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004710 return false;
4711 }
Jamie Madill29639852016-09-02 15:00:09 -04004712
4713 return true;
4714}
4715
Jamie Madill5b772312018-03-08 20:28:32 -05004716bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004717 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004718 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004719 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004720 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004721{
4722 if (size < 0)
4723 {
Jamie Madille0472f32018-11-27 16:32:45 -05004724 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004725 return false;
4726 }
4727
4728 switch (usage)
4729 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004730 case BufferUsage::StreamDraw:
4731 case BufferUsage::StaticDraw:
4732 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004733 break;
4734
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004735 case BufferUsage::StreamRead:
4736 case BufferUsage::StaticRead:
4737 case BufferUsage::DynamicRead:
4738 case BufferUsage::StreamCopy:
4739 case BufferUsage::StaticCopy:
4740 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004741 if (context->getClientMajorVersion() < 3)
4742 {
Jamie Madille0472f32018-11-27 16:32:45 -05004743 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004744 return false;
4745 }
4746 break;
4747
4748 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004749 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004750 return false;
4751 }
4752
Corentin Walleze4477002017-12-01 14:39:58 -05004753 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004754 {
Jamie Madille0472f32018-11-27 16:32:45 -05004755 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004756 return false;
4757 }
4758
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004759 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004760
4761 if (!buffer)
4762 {
Jamie Madille0472f32018-11-27 16:32:45 -05004763 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004764 return false;
4765 }
4766
James Darpiniane8a93c62018-01-04 18:02:24 -08004767 if (context->getExtensions().webglCompatibility &&
4768 buffer->isBoundForTransformFeedbackAndOtherUse())
4769 {
Jamie Madille0472f32018-11-27 16:32:45 -05004770 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004771 return false;
4772 }
4773
Jamie Madill29639852016-09-02 15:00:09 -04004774 return true;
4775}
4776
Jamie Madill5b772312018-03-08 20:28:32 -05004777bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004778 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004779 GLintptr offset,
4780 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004781 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004782{
Brandon Jones6cad5662017-06-14 13:25:13 -07004783 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004784 {
Jamie Madille0472f32018-11-27 16:32:45 -05004785 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004786 return false;
4787 }
4788
4789 if (offset < 0)
4790 {
Jamie Madille0472f32018-11-27 16:32:45 -05004791 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004792 return false;
4793 }
4794
Corentin Walleze4477002017-12-01 14:39:58 -05004795 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004796 {
Jamie Madille0472f32018-11-27 16:32:45 -05004797 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004798 return false;
4799 }
4800
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004801 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004802
4803 if (!buffer)
4804 {
Jamie Madille0472f32018-11-27 16:32:45 -05004805 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004806 return false;
4807 }
4808
4809 if (buffer->isMapped())
4810 {
Jamie Madille0472f32018-11-27 16:32:45 -05004811 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004812 return false;
4813 }
4814
James Darpiniane8a93c62018-01-04 18:02:24 -08004815 if (context->getExtensions().webglCompatibility &&
4816 buffer->isBoundForTransformFeedbackAndOtherUse())
4817 {
Jamie Madille0472f32018-11-27 16:32:45 -05004818 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004819 return false;
4820 }
4821
Jamie Madill29639852016-09-02 15:00:09 -04004822 // Check for possible overflow of size + offset
4823 angle::CheckedNumeric<size_t> checkedSize(size);
4824 checkedSize += offset;
4825 if (!checkedSize.IsValid())
4826 {
Jamie Madille0472f32018-11-27 16:32:45 -05004827 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004828 return false;
4829 }
4830
4831 if (size + offset > buffer->getSize())
4832 {
Jamie Madille0472f32018-11-27 16:32:45 -05004833 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004834 return false;
4835 }
4836
Martin Radev4c4c8e72016-08-04 12:25:34 +03004837 return true;
4838}
4839
Geoff Lang111a99e2017-10-17 10:58:41 -04004840bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04004841{
Geoff Langc339c4e2016-11-29 10:37:36 -05004842 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04004843 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004844 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04004845 return false;
4846 }
4847
Geoff Lang111a99e2017-10-17 10:58:41 -04004848 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04004849 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004850 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04004851 return false;
4852 }
4853
4854 return true;
4855}
4856
Jamie Madill5b772312018-03-08 20:28:32 -05004857bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04004858{
Lingfeng Yang038dd532018-03-29 17:31:52 -07004859 if (context->getClientMajorVersion() < 2)
4860 {
4861 return ValidateMultitextureUnit(context, texture);
4862 }
4863
Jamie Madillef300b12016-10-07 15:12:09 -04004864 if (texture < GL_TEXTURE0 ||
4865 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
4866 {
Jamie Madille0472f32018-11-27 16:32:45 -05004867 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04004868 return false;
4869 }
4870
4871 return true;
4872}
4873
Jamie Madill5b772312018-03-08 20:28:32 -05004874bool ValidateAttachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillef300b12016-10-07 15:12:09 -04004875{
4876 Program *programObject = GetValidProgram(context, program);
4877 if (!programObject)
4878 {
4879 return false;
4880 }
4881
4882 Shader *shaderObject = GetValidShader(context, shader);
4883 if (!shaderObject)
4884 {
4885 return false;
4886 }
4887
Jiawei Shao385b3e02018-03-21 09:43:28 +08004888 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04004889 {
Jamie Madille0472f32018-11-27 16:32:45 -05004890 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08004891 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04004892 }
4893
4894 return true;
4895}
4896
Jamie Madill5b772312018-03-08 20:28:32 -05004897bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004898{
4899 if (index >= MAX_VERTEX_ATTRIBS)
4900 {
Jamie Madille0472f32018-11-27 16:32:45 -05004901 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004902 return false;
4903 }
4904
4905 if (strncmp(name, "gl_", 3) == 0)
4906 {
Jamie Madille0472f32018-11-27 16:32:45 -05004907 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004908 return false;
4909 }
4910
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004911 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04004912 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004913 const size_t length = strlen(name);
4914
4915 if (!IsValidESSLString(name, length))
4916 {
4917 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
4918 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05004919 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004920 return false;
4921 }
4922
4923 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
4924 {
4925 return false;
4926 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04004927 }
4928
Jamie Madill01a80ee2016-11-07 12:06:18 -05004929 return GetValidProgram(context, program) != nullptr;
4930}
4931
Jamie Madill5b772312018-03-08 20:28:32 -05004932bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004933{
Geoff Lange8afa902017-09-27 15:00:43 -04004934 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05004935 {
Jamie Madille0472f32018-11-27 16:32:45 -05004936 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004937 return false;
4938 }
4939
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004940 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004941 !context->isFramebufferGenerated(framebuffer))
4942 {
Jamie Madille0472f32018-11-27 16:32:45 -05004943 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004944 return false;
4945 }
4946
4947 return true;
4948}
4949
Jamie Madill5b772312018-03-08 20:28:32 -05004950bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004951{
4952 if (target != GL_RENDERBUFFER)
4953 {
Jamie Madille0472f32018-11-27 16:32:45 -05004954 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004955 return false;
4956 }
4957
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004958 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004959 !context->isRenderbufferGenerated(renderbuffer))
4960 {
Jamie Madille0472f32018-11-27 16:32:45 -05004961 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004962 return false;
4963 }
4964
4965 return true;
4966}
4967
Jamie Madill5b772312018-03-08 20:28:32 -05004968static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004969{
4970 switch (mode)
4971 {
4972 case GL_FUNC_ADD:
4973 case GL_FUNC_SUBTRACT:
4974 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04004975 return true;
4976
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004977 case GL_MIN:
4978 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04004979 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004980
4981 default:
4982 return false;
4983 }
4984}
4985
Jamie Madill5b772312018-03-08 20:28:32 -05004986bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004987{
4988 return true;
4989}
4990
Jamie Madill5b772312018-03-08 20:28:32 -05004991bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004992{
Geoff Lang50cac572017-09-26 17:37:43 -04004993 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004994 {
Jamie Madille0472f32018-11-27 16:32:45 -05004995 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004996 return false;
4997 }
4998
4999 return true;
5000}
5001
Jamie Madill5b772312018-03-08 20:28:32 -05005002bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005003{
Geoff Lang50cac572017-09-26 17:37:43 -04005004 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005005 {
Jamie Madille0472f32018-11-27 16:32:45 -05005006 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005007 return false;
5008 }
5009
Geoff Lang50cac572017-09-26 17:37:43 -04005010 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005011 {
Jamie Madille0472f32018-11-27 16:32:45 -05005012 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005013 return false;
5014 }
5015
5016 return true;
5017}
5018
Jamie Madill5b772312018-03-08 20:28:32 -05005019bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005020{
5021 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
5022}
5023
Jamie Madill5b772312018-03-08 20:28:32 -05005024bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005025 GLenum srcRGB,
5026 GLenum dstRGB,
5027 GLenum srcAlpha,
5028 GLenum dstAlpha)
5029{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005030 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005031 {
Jamie Madille0472f32018-11-27 16:32:45 -05005032 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005033 return false;
5034 }
5035
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005036 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005037 {
Jamie Madille0472f32018-11-27 16:32:45 -05005038 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005039 return false;
5040 }
5041
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005042 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005043 {
Jamie Madille0472f32018-11-27 16:32:45 -05005044 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005045 return false;
5046 }
5047
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005048 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005049 {
Jamie Madille0472f32018-11-27 16:32:45 -05005050 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005051 return false;
5052 }
5053
Frank Henigman146e8a12017-03-02 23:22:37 -05005054 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
5055 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005056 {
5057 bool constantColorUsed =
5058 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
5059 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
5060
5061 bool constantAlphaUsed =
5062 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
5063 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
5064
5065 if (constantColorUsed && constantAlphaUsed)
5066 {
Frank Henigman146e8a12017-03-02 23:22:37 -05005067 if (context->getExtensions().webglCompatibility)
5068 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005069 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
5070 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05005071 }
Jamie Madillc3e37312018-11-30 15:25:39 -05005072
5073 WARN() << kConstantColorAlphaLimitation;
5074 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005075 return false;
5076 }
5077 }
5078
5079 return true;
5080}
5081
Geoff Langc339c4e2016-11-29 10:37:36 -05005082bool ValidateGetString(Context *context, GLenum name)
5083{
5084 switch (name)
5085 {
5086 case GL_VENDOR:
5087 case GL_RENDERER:
5088 case GL_VERSION:
5089 case GL_SHADING_LANGUAGE_VERSION:
5090 case GL_EXTENSIONS:
5091 break;
5092
5093 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
5094 if (!context->getExtensions().requestExtension)
5095 {
Jamie Madille0472f32018-11-27 16:32:45 -05005096 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005097 return false;
5098 }
5099 break;
5100
5101 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005102 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005103 return false;
5104 }
5105
5106 return true;
5107}
5108
Jamie Madill5b772312018-03-08 20:28:32 -05005109bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05005110{
5111 if (width <= 0.0f || isNaN(width))
5112 {
Jamie Madille0472f32018-11-27 16:32:45 -05005113 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05005114 return false;
5115 }
5116
5117 return true;
5118}
5119
Jamie Madill5b772312018-03-08 20:28:32 -05005120bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05005121{
5122 if (context->getExtensions().webglCompatibility && zNear > zFar)
5123 {
Jamie Madille0472f32018-11-27 16:32:45 -05005124 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05005125 return false;
5126 }
5127
5128 return true;
5129}
5130
Jamie Madill5b772312018-03-08 20:28:32 -05005131bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005132 GLenum target,
5133 GLenum internalformat,
5134 GLsizei width,
5135 GLsizei height)
5136{
5137 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
5138 height);
5139}
5140
Jamie Madill5b772312018-03-08 20:28:32 -05005141bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005142 GLenum target,
5143 GLsizei samples,
5144 GLenum internalformat,
5145 GLsizei width,
5146 GLsizei height)
5147{
5148 if (!context->getExtensions().framebufferMultisample)
5149 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005150 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05005151 return false;
5152 }
5153
5154 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05005155 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05005156 // generated.
5157 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
5158 {
Jamie Madille0472f32018-11-27 16:32:45 -05005159 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005160 return false;
5161 }
5162
5163 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
5164 // the specified storage. This is different than ES 3.0 in which a sample number higher
5165 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
5166 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
5167 if (context->getClientMajorVersion() >= 3)
5168 {
5169 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
5170 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
5171 {
Jamie Madille0472f32018-11-27 16:32:45 -05005172 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005173 return false;
5174 }
5175 }
5176
5177 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
5178 width, height);
5179}
5180
Jamie Madill5b772312018-03-08 20:28:32 -05005181bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005182{
Geoff Lange8afa902017-09-27 15:00:43 -04005183 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005184 {
Jamie Madille0472f32018-11-27 16:32:45 -05005185 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005186 return false;
5187 }
5188
5189 return true;
5190}
5191
Jamie Madill5b772312018-03-08 20:28:32 -05005192bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005193{
5194 return true;
5195}
5196
Jamie Madill5b772312018-03-08 20:28:32 -05005197bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005198{
5199 return true;
5200}
5201
Jamie Madill5b772312018-03-08 20:28:32 -05005202bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005203{
5204 return true;
5205}
5206
Jamie Madill5b772312018-03-08 20:28:32 -05005207bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005208 GLboolean red,
5209 GLboolean green,
5210 GLboolean blue,
5211 GLboolean alpha)
5212{
5213 return true;
5214}
5215
Jamie Madill5b772312018-03-08 20:28:32 -05005216bool ValidateCompileShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005217{
5218 return true;
5219}
5220
Jamie Madill5b772312018-03-08 20:28:32 -05005221bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005222{
5223 return true;
5224}
5225
Jamie Madill5b772312018-03-08 20:28:32 -05005226bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005227{
5228 switch (mode)
5229 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005230 case CullFaceMode::Front:
5231 case CullFaceMode::Back:
5232 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005233 break;
5234
5235 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005236 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005237 return false;
5238 }
5239
5240 return true;
5241}
5242
Jamie Madill5b772312018-03-08 20:28:32 -05005243bool ValidateDeleteProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005244{
5245 if (program == 0)
5246 {
5247 return false;
5248 }
5249
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005250 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005251 {
5252 if (context->getShader(program))
5253 {
Jamie Madille0472f32018-11-27 16:32:45 -05005254 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005255 return false;
5256 }
5257 else
5258 {
Jamie Madille0472f32018-11-27 16:32:45 -05005259 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005260 return false;
5261 }
5262 }
5263
5264 return true;
5265}
5266
Jamie Madill5b772312018-03-08 20:28:32 -05005267bool ValidateDeleteShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005268{
5269 if (shader == 0)
5270 {
5271 return false;
5272 }
5273
5274 if (!context->getShader(shader))
5275 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005276 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005277 {
Jamie Madille0472f32018-11-27 16:32:45 -05005278 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005279 return false;
5280 }
5281 else
5282 {
Jamie Madille0472f32018-11-27 16:32:45 -05005283 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005284 return false;
5285 }
5286 }
5287
5288 return true;
5289}
5290
Jamie Madill5b772312018-03-08 20:28:32 -05005291bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005292{
5293 switch (func)
5294 {
5295 case GL_NEVER:
5296 case GL_ALWAYS:
5297 case GL_LESS:
5298 case GL_LEQUAL:
5299 case GL_EQUAL:
5300 case GL_GREATER:
5301 case GL_GEQUAL:
5302 case GL_NOTEQUAL:
5303 break;
5304
5305 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005306 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005307 return false;
5308 }
5309
5310 return true;
5311}
5312
Jamie Madill5b772312018-03-08 20:28:32 -05005313bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005314{
5315 return true;
5316}
5317
Jamie Madill5b772312018-03-08 20:28:32 -05005318bool ValidateDetachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005319{
5320 Program *programObject = GetValidProgram(context, program);
5321 if (!programObject)
5322 {
5323 return false;
5324 }
5325
5326 Shader *shaderObject = GetValidShader(context, shader);
5327 if (!shaderObject)
5328 {
5329 return false;
5330 }
5331
Jiawei Shao385b3e02018-03-21 09:43:28 +08005332 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005333 if (attachedShader != shaderObject)
5334 {
Jamie Madille0472f32018-11-27 16:32:45 -05005335 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005336 return false;
5337 }
5338
5339 return true;
5340}
5341
Jamie Madill5b772312018-03-08 20:28:32 -05005342bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005343{
5344 if (index >= MAX_VERTEX_ATTRIBS)
5345 {
Jamie Madille0472f32018-11-27 16:32:45 -05005346 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005347 return false;
5348 }
5349
5350 return true;
5351}
5352
Jamie Madill5b772312018-03-08 20:28:32 -05005353bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005354{
5355 if (index >= MAX_VERTEX_ATTRIBS)
5356 {
Jamie Madille0472f32018-11-27 16:32:45 -05005357 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005358 return false;
5359 }
5360
5361 return true;
5362}
5363
Jamie Madill5b772312018-03-08 20:28:32 -05005364bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005365{
5366 return true;
5367}
5368
Jamie Madill5b772312018-03-08 20:28:32 -05005369bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005370{
5371 return true;
5372}
5373
Jamie Madill5b772312018-03-08 20:28:32 -05005374bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005375{
5376 switch (mode)
5377 {
5378 case GL_CW:
5379 case GL_CCW:
5380 break;
5381 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005382 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005383 return false;
5384 }
5385
5386 return true;
5387}
5388
Jamie Madill5b772312018-03-08 20:28:32 -05005389bool ValidateGetActiveAttrib(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005390 GLuint program,
5391 GLuint index,
5392 GLsizei bufsize,
5393 GLsizei *length,
5394 GLint *size,
5395 GLenum *type,
5396 GLchar *name)
5397{
5398 if (bufsize < 0)
5399 {
Jamie Madille0472f32018-11-27 16:32:45 -05005400 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005401 return false;
5402 }
5403
5404 Program *programObject = GetValidProgram(context, program);
5405
5406 if (!programObject)
5407 {
5408 return false;
5409 }
5410
5411 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5412 {
Jamie Madille0472f32018-11-27 16:32:45 -05005413 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005414 return false;
5415 }
5416
5417 return true;
5418}
5419
Jamie Madill5b772312018-03-08 20:28:32 -05005420bool ValidateGetActiveUniform(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005421 GLuint program,
5422 GLuint index,
5423 GLsizei bufsize,
5424 GLsizei *length,
5425 GLint *size,
5426 GLenum *type,
5427 GLchar *name)
5428{
5429 if (bufsize < 0)
5430 {
Jamie Madille0472f32018-11-27 16:32:45 -05005431 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005432 return false;
5433 }
5434
5435 Program *programObject = GetValidProgram(context, program);
5436
5437 if (!programObject)
5438 {
5439 return false;
5440 }
5441
5442 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5443 {
Jamie Madille0472f32018-11-27 16:32:45 -05005444 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005445 return false;
5446 }
5447
5448 return true;
5449}
5450
Jamie Madill5b772312018-03-08 20:28:32 -05005451bool ValidateGetAttachedShaders(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005452 GLuint program,
5453 GLsizei maxcount,
5454 GLsizei *count,
5455 GLuint *shaders)
5456{
5457 if (maxcount < 0)
5458 {
Jamie Madille0472f32018-11-27 16:32:45 -05005459 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005460 return false;
5461 }
5462
5463 Program *programObject = GetValidProgram(context, program);
5464
5465 if (!programObject)
5466 {
5467 return false;
5468 }
5469
5470 return true;
5471}
5472
Jamie Madill5b772312018-03-08 20:28:32 -05005473bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005474{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005475 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5476 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005477 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005478 {
Jamie Madille0472f32018-11-27 16:32:45 -05005479 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005480 return false;
5481 }
5482
Jamie Madillc1d770e2017-04-13 17:31:24 -04005483 Program *programObject = GetValidProgram(context, program);
5484
5485 if (!programObject)
5486 {
Jamie Madille0472f32018-11-27 16:32:45 -05005487 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005488 return false;
5489 }
5490
5491 if (!programObject->isLinked())
5492 {
Jamie Madille0472f32018-11-27 16:32:45 -05005493 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005494 return false;
5495 }
5496
5497 return true;
5498}
5499
Jamie Madill5b772312018-03-08 20:28:32 -05005500bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005501{
5502 GLenum nativeType;
5503 unsigned int numParams = 0;
5504 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5505}
5506
Jamie Madill5b772312018-03-08 20:28:32 -05005507bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005508{
5509 return true;
5510}
5511
Jamie Madill5b772312018-03-08 20:28:32 -05005512bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005513{
5514 GLenum nativeType;
5515 unsigned int numParams = 0;
5516 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5517}
5518
Jamie Madill5b772312018-03-08 20:28:32 -05005519bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005520{
5521 GLenum nativeType;
5522 unsigned int numParams = 0;
5523 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5524}
5525
Jamie Madill5b772312018-03-08 20:28:32 -05005526bool ValidateGetProgramInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005527 GLuint program,
5528 GLsizei bufsize,
5529 GLsizei *length,
5530 GLchar *infolog)
5531{
5532 if (bufsize < 0)
5533 {
Jamie Madille0472f32018-11-27 16:32:45 -05005534 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005535 return false;
5536 }
5537
5538 Program *programObject = GetValidProgram(context, program);
5539 if (!programObject)
5540 {
5541 return false;
5542 }
5543
5544 return true;
5545}
5546
Jamie Madill5b772312018-03-08 20:28:32 -05005547bool ValidateGetShaderInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005548 GLuint shader,
5549 GLsizei bufsize,
5550 GLsizei *length,
5551 GLchar *infolog)
5552{
5553 if (bufsize < 0)
5554 {
Jamie Madille0472f32018-11-27 16:32:45 -05005555 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005556 return false;
5557 }
5558
5559 Shader *shaderObject = GetValidShader(context, shader);
5560 if (!shaderObject)
5561 {
5562 return false;
5563 }
5564
5565 return true;
5566}
5567
Jamie Madill5b772312018-03-08 20:28:32 -05005568bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005569 GLenum shadertype,
5570 GLenum precisiontype,
5571 GLint *range,
5572 GLint *precision)
5573{
5574 switch (shadertype)
5575 {
5576 case GL_VERTEX_SHADER:
5577 case GL_FRAGMENT_SHADER:
5578 break;
5579 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005580 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005581 return false;
5582 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005583 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005584 return false;
5585 }
5586
5587 switch (precisiontype)
5588 {
5589 case GL_LOW_FLOAT:
5590 case GL_MEDIUM_FLOAT:
5591 case GL_HIGH_FLOAT:
5592 case GL_LOW_INT:
5593 case GL_MEDIUM_INT:
5594 case GL_HIGH_INT:
5595 break;
5596
5597 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005598 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005599 return false;
5600 }
5601
5602 return true;
5603}
5604
Jamie Madill5b772312018-03-08 20:28:32 -05005605bool ValidateGetShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005606 GLuint shader,
5607 GLsizei bufsize,
5608 GLsizei *length,
5609 GLchar *source)
5610{
5611 if (bufsize < 0)
5612 {
Jamie Madille0472f32018-11-27 16:32:45 -05005613 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005614 return false;
5615 }
5616
5617 Shader *shaderObject = GetValidShader(context, shader);
5618 if (!shaderObject)
5619 {
5620 return false;
5621 }
5622
5623 return true;
5624}
5625
Jamie Madill5b772312018-03-08 20:28:32 -05005626bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005627{
5628 if (strstr(name, "gl_") == name)
5629 {
5630 return false;
5631 }
5632
Geoff Langfc32e8b2017-05-31 14:16:59 -04005633 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5634 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005635 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005636 {
Jamie Madille0472f32018-11-27 16:32:45 -05005637 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005638 return false;
5639 }
5640
Jamie Madillc1d770e2017-04-13 17:31:24 -04005641 Program *programObject = GetValidProgram(context, program);
5642
5643 if (!programObject)
5644 {
5645 return false;
5646 }
5647
5648 if (!programObject->isLinked())
5649 {
Jamie Madille0472f32018-11-27 16:32:45 -05005650 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005651 return false;
5652 }
5653
5654 return true;
5655}
5656
Jamie Madill5b772312018-03-08 20:28:32 -05005657bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005658{
5659 switch (mode)
5660 {
5661 case GL_FASTEST:
5662 case GL_NICEST:
5663 case GL_DONT_CARE:
5664 break;
5665
5666 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005667 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005668 return false;
5669 }
5670
5671 switch (target)
5672 {
5673 case GL_GENERATE_MIPMAP_HINT:
5674 break;
5675
Geoff Lange7bd2182017-06-16 16:13:13 -04005676 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5677 if (context->getClientVersion() < ES_3_0 &&
5678 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005679 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005680 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005681 return false;
5682 }
5683 break;
5684
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005685 case GL_PERSPECTIVE_CORRECTION_HINT:
5686 case GL_POINT_SMOOTH_HINT:
5687 case GL_LINE_SMOOTH_HINT:
5688 case GL_FOG_HINT:
5689 if (context->getClientMajorVersion() >= 2)
5690 {
Jamie Madille0472f32018-11-27 16:32:45 -05005691 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005692 return false;
5693 }
5694 break;
5695
Jamie Madillc1d770e2017-04-13 17:31:24 -04005696 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005697 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005698 return false;
5699 }
5700
5701 return true;
5702}
5703
Jamie Madill5b772312018-03-08 20:28:32 -05005704bool ValidateIsBuffer(Context *context, GLuint buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005705{
5706 return true;
5707}
5708
Jamie Madill5b772312018-03-08 20:28:32 -05005709bool ValidateIsFramebuffer(Context *context, GLuint framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005710{
5711 return true;
5712}
5713
Jamie Madill5b772312018-03-08 20:28:32 -05005714bool ValidateIsProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005715{
5716 return true;
5717}
5718
Jamie Madill5b772312018-03-08 20:28:32 -05005719bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005720{
5721 return true;
5722}
5723
Jamie Madill5b772312018-03-08 20:28:32 -05005724bool ValidateIsShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005725{
5726 return true;
5727}
5728
Jamie Madill5b772312018-03-08 20:28:32 -05005729bool ValidateIsTexture(Context *context, GLuint texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005730{
5731 return true;
5732}
5733
Jamie Madill5b772312018-03-08 20:28:32 -05005734bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005735{
5736 if (context->getClientMajorVersion() < 3)
5737 {
5738 switch (pname)
5739 {
5740 case GL_UNPACK_IMAGE_HEIGHT:
5741 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005742 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743 return false;
5744
5745 case GL_UNPACK_ROW_LENGTH:
5746 case GL_UNPACK_SKIP_ROWS:
5747 case GL_UNPACK_SKIP_PIXELS:
5748 if (!context->getExtensions().unpackSubimage)
5749 {
Jamie Madille0472f32018-11-27 16:32:45 -05005750 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005751 return false;
5752 }
5753 break;
5754
5755 case GL_PACK_ROW_LENGTH:
5756 case GL_PACK_SKIP_ROWS:
5757 case GL_PACK_SKIP_PIXELS:
5758 if (!context->getExtensions().packSubimage)
5759 {
Jamie Madille0472f32018-11-27 16:32:45 -05005760 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005761 return false;
5762 }
5763 break;
5764 }
5765 }
5766
5767 if (param < 0)
5768 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005769 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005770 return false;
5771 }
5772
5773 switch (pname)
5774 {
5775 case GL_UNPACK_ALIGNMENT:
5776 if (param != 1 && param != 2 && param != 4 && param != 8)
5777 {
Jamie Madille0472f32018-11-27 16:32:45 -05005778 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005779 return false;
5780 }
5781 break;
5782
5783 case GL_PACK_ALIGNMENT:
5784 if (param != 1 && param != 2 && param != 4 && param != 8)
5785 {
Jamie Madille0472f32018-11-27 16:32:45 -05005786 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005787 return false;
5788 }
5789 break;
5790
5791 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005792 if (!context->getExtensions().packReverseRowOrder)
5793 {
Jamie Madille0472f32018-11-27 16:32:45 -05005794 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005795 }
5796 break;
5797
Jamie Madillc1d770e2017-04-13 17:31:24 -04005798 case GL_UNPACK_ROW_LENGTH:
5799 case GL_UNPACK_IMAGE_HEIGHT:
5800 case GL_UNPACK_SKIP_IMAGES:
5801 case GL_UNPACK_SKIP_ROWS:
5802 case GL_UNPACK_SKIP_PIXELS:
5803 case GL_PACK_ROW_LENGTH:
5804 case GL_PACK_SKIP_ROWS:
5805 case GL_PACK_SKIP_PIXELS:
5806 break;
5807
5808 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005809 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005810 return false;
5811 }
5812
5813 return true;
5814}
5815
Jamie Madill5b772312018-03-08 20:28:32 -05005816bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005817{
5818 return true;
5819}
5820
Jamie Madill5b772312018-03-08 20:28:32 -05005821bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005822{
5823 return true;
5824}
5825
Jamie Madill5b772312018-03-08 20:28:32 -05005826bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005827{
5828 return true;
5829}
5830
Jamie Madill5b772312018-03-08 20:28:32 -05005831bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005832{
5833 if (width < 0 || height < 0)
5834 {
Jamie Madille0472f32018-11-27 16:32:45 -05005835 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005836 return false;
5837 }
5838
5839 return true;
5840}
5841
Jamie Madill5b772312018-03-08 20:28:32 -05005842bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005843 GLsizei n,
5844 const GLuint *shaders,
5845 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005846 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005847 GLsizei length)
5848{
5849 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
5850 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
5851 shaderBinaryFormats.end())
5852 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005853 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005854 return false;
5855 }
5856
5857 return true;
5858}
5859
Jamie Madill5b772312018-03-08 20:28:32 -05005860bool ValidateShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005861 GLuint shader,
5862 GLsizei count,
5863 const GLchar *const *string,
5864 const GLint *length)
5865{
5866 if (count < 0)
5867 {
Jamie Madille0472f32018-11-27 16:32:45 -05005868 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005869 return false;
5870 }
5871
Geoff Langfc32e8b2017-05-31 14:16:59 -04005872 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5873 // shader-related entry points
5874 if (context->getExtensions().webglCompatibility)
5875 {
5876 for (GLsizei i = 0; i < count; i++)
5877 {
Geoff Langcab92ee2017-07-19 17:32:07 -04005878 size_t len =
5879 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04005880
5881 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04005882 if (!IsValidESSLShaderSourceString(string[i], len,
5883 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005884 {
Jamie Madille0472f32018-11-27 16:32:45 -05005885 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005886 return false;
5887 }
5888 }
5889 }
5890
Jamie Madillc1d770e2017-04-13 17:31:24 -04005891 Shader *shaderObject = GetValidShader(context, shader);
5892 if (!shaderObject)
5893 {
5894 return false;
5895 }
5896
5897 return true;
5898}
5899
Jamie Madill5b772312018-03-08 20:28:32 -05005900bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005901{
5902 if (!IsValidStencilFunc(func))
5903 {
Jamie Madille0472f32018-11-27 16:32:45 -05005904 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005905 return false;
5906 }
5907
5908 return true;
5909}
5910
Jamie Madill5b772312018-03-08 20:28:32 -05005911bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005912{
5913 if (!IsValidStencilFace(face))
5914 {
Jamie Madille0472f32018-11-27 16:32:45 -05005915 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005916 return false;
5917 }
5918
5919 if (!IsValidStencilFunc(func))
5920 {
Jamie Madille0472f32018-11-27 16:32:45 -05005921 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005922 return false;
5923 }
5924
5925 return true;
5926}
5927
Jamie Madill5b772312018-03-08 20:28:32 -05005928bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005929{
5930 return true;
5931}
5932
Jamie Madill5b772312018-03-08 20:28:32 -05005933bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005934{
5935 if (!IsValidStencilFace(face))
5936 {
Jamie Madille0472f32018-11-27 16:32:45 -05005937 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005938 return false;
5939 }
5940
5941 return true;
5942}
5943
Jamie Madill5b772312018-03-08 20:28:32 -05005944bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005945{
5946 if (!IsValidStencilOp(fail))
5947 {
Jamie Madille0472f32018-11-27 16:32:45 -05005948 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005949 return false;
5950 }
5951
5952 if (!IsValidStencilOp(zfail))
5953 {
Jamie Madille0472f32018-11-27 16:32:45 -05005954 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005955 return false;
5956 }
5957
5958 if (!IsValidStencilOp(zpass))
5959 {
Jamie Madille0472f32018-11-27 16:32:45 -05005960 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005961 return false;
5962 }
5963
5964 return true;
5965}
5966
Jamie Madill5b772312018-03-08 20:28:32 -05005967bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005968 GLenum face,
5969 GLenum fail,
5970 GLenum zfail,
5971 GLenum zpass)
5972{
5973 if (!IsValidStencilFace(face))
5974 {
Jamie Madille0472f32018-11-27 16:32:45 -05005975 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005976 return false;
5977 }
5978
5979 return ValidateStencilOp(context, fail, zfail, zpass);
5980}
5981
Jamie Madill5b772312018-03-08 20:28:32 -05005982bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005983{
5984 return ValidateUniform(context, GL_FLOAT, location, 1);
5985}
5986
Jamie Madill5b772312018-03-08 20:28:32 -05005987bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005988{
5989 return ValidateUniform(context, GL_FLOAT, location, count);
5990}
5991
Jamie Madill5b772312018-03-08 20:28:32 -05005992bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04005993{
5994 return ValidateUniform1iv(context, location, 1, &x);
5995}
5996
Jamie Madill5b772312018-03-08 20:28:32 -05005997bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005998{
5999 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
6000}
6001
Jamie Madill5b772312018-03-08 20:28:32 -05006002bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006003{
6004 return ValidateUniform(context, GL_INT_VEC2, location, 1);
6005}
6006
Jamie Madill5b772312018-03-08 20:28:32 -05006007bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006008{
6009 return ValidateUniform(context, GL_INT_VEC2, location, count);
6010}
6011
Jamie Madill5b772312018-03-08 20:28:32 -05006012bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006013{
6014 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
6015}
6016
Jamie Madill5b772312018-03-08 20:28:32 -05006017bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006018{
6019 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
6020}
6021
Jamie Madill5b772312018-03-08 20:28:32 -05006022bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006023{
6024 return ValidateUniform(context, GL_INT_VEC3, location, 1);
6025}
6026
Jamie Madill5b772312018-03-08 20:28:32 -05006027bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006028{
6029 return ValidateUniform(context, GL_INT_VEC3, location, count);
6030}
6031
Jamie Madill5b772312018-03-08 20:28:32 -05006032bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006033{
6034 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
6035}
6036
Jamie Madill5b772312018-03-08 20:28:32 -05006037bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006038{
6039 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
6040}
6041
Jamie Madill5b772312018-03-08 20:28:32 -05006042bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006043{
6044 return ValidateUniform(context, GL_INT_VEC4, location, 1);
6045}
6046
Jamie Madill5b772312018-03-08 20:28:32 -05006047bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006048{
6049 return ValidateUniform(context, GL_INT_VEC4, location, count);
6050}
6051
Jamie Madill5b772312018-03-08 20:28:32 -05006052bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006053 GLint location,
6054 GLsizei count,
6055 GLboolean transpose,
6056 const GLfloat *value)
6057{
6058 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
6059}
6060
Jamie Madill5b772312018-03-08 20:28:32 -05006061bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006062 GLint location,
6063 GLsizei count,
6064 GLboolean transpose,
6065 const GLfloat *value)
6066{
6067 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
6068}
6069
Jamie Madill5b772312018-03-08 20:28:32 -05006070bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006071 GLint location,
6072 GLsizei count,
6073 GLboolean transpose,
6074 const GLfloat *value)
6075{
6076 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
6077}
6078
Jamie Madill5b772312018-03-08 20:28:32 -05006079bool ValidateValidateProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006080{
6081 Program *programObject = GetValidProgram(context, program);
6082
6083 if (!programObject)
6084 {
6085 return false;
6086 }
6087
6088 return true;
6089}
6090
Jamie Madill5b772312018-03-08 20:28:32 -05006091bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006092{
6093 return ValidateVertexAttribIndex(context, index);
6094}
6095
Jamie Madill5b772312018-03-08 20:28:32 -05006096bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006097{
6098 return ValidateVertexAttribIndex(context, index);
6099}
6100
Jamie Madill5b772312018-03-08 20:28:32 -05006101bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006102{
6103 return ValidateVertexAttribIndex(context, index);
6104}
6105
Jamie Madill5b772312018-03-08 20:28:32 -05006106bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006107{
6108 return ValidateVertexAttribIndex(context, index);
6109}
6110
Jamie Madill5b772312018-03-08 20:28:32 -05006111bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006112{
6113 return ValidateVertexAttribIndex(context, index);
6114}
6115
Jamie Madill5b772312018-03-08 20:28:32 -05006116bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006117{
6118 return ValidateVertexAttribIndex(context, index);
6119}
6120
Jamie Madill5b772312018-03-08 20:28:32 -05006121bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006122 GLuint index,
6123 GLfloat x,
6124 GLfloat y,
6125 GLfloat z,
6126 GLfloat w)
6127{
6128 return ValidateVertexAttribIndex(context, index);
6129}
6130
Jamie Madill5b772312018-03-08 20:28:32 -05006131bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006132{
6133 return ValidateVertexAttribIndex(context, index);
6134}
6135
Jamie Madill5b772312018-03-08 20:28:32 -05006136bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006137{
6138 if (width < 0 || height < 0)
6139 {
Jamie Madille0472f32018-11-27 16:32:45 -05006140 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006141 return false;
6142 }
6143
6144 return true;
6145}
6146
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08006147bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006148 GLenum target,
6149 GLenum attachment,
6150 GLenum pname,
6151 GLint *params)
6152{
6153 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
6154 nullptr);
6155}
6156
Jamie Madill5b772312018-03-08 20:28:32 -05006157bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006158{
6159 return ValidateGetProgramivBase(context, program, pname, nullptr);
6160}
6161
Jamie Madill5b772312018-03-08 20:28:32 -05006162bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006163 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006164 GLint level,
6165 GLenum internalformat,
6166 GLint x,
6167 GLint y,
6168 GLsizei width,
6169 GLsizei height,
6170 GLint border)
6171{
6172 if (context->getClientMajorVersion() < 3)
6173 {
6174 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
6175 0, x, y, width, height, border);
6176 }
6177
6178 ASSERT(context->getClientMajorVersion() == 3);
6179 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
6180 0, x, y, width, height, border);
6181}
6182
6183bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006184 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006185 GLint level,
6186 GLint xoffset,
6187 GLint yoffset,
6188 GLint x,
6189 GLint y,
6190 GLsizei width,
6191 GLsizei height)
6192{
6193 if (context->getClientMajorVersion() < 3)
6194 {
6195 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
6196 yoffset, x, y, width, height, 0);
6197 }
6198
6199 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
6200 yoffset, 0, x, y, width, height, 0);
6201}
6202
Cody Northrop5faff912019-06-28 14:04:50 -06006203bool ValidateCopyTexSubImage3DOES(Context *context,
6204 TextureTarget target,
6205 GLint level,
6206 GLint xoffset,
6207 GLint yoffset,
6208 GLint zoffset,
6209 GLint x,
6210 GLint y,
6211 GLsizei width,
6212 GLsizei height)
6213{
6214 return ValidateCopyTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, x, y, width,
6215 height);
6216}
6217
Jamie Madillbe849e42017-05-02 15:49:00 -04006218bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *)
6219{
6220 return ValidateGenOrDelete(context, n);
6221}
6222
6223bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *)
6224{
6225 return ValidateGenOrDelete(context, n);
6226}
6227
6228bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *)
6229{
6230 return ValidateGenOrDelete(context, n);
6231}
6232
6233bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *)
6234{
6235 return ValidateGenOrDelete(context, n);
6236}
6237
6238bool ValidateDisable(Context *context, GLenum cap)
6239{
6240 if (!ValidCap(context, cap, false))
6241 {
Jamie Madille0472f32018-11-27 16:32:45 -05006242 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006243 return false;
6244 }
6245
6246 return true;
6247}
6248
6249bool ValidateEnable(Context *context, GLenum cap)
6250{
6251 if (!ValidCap(context, cap, false))
6252 {
Jamie Madille0472f32018-11-27 16:32:45 -05006253 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006254 return false;
6255 }
6256
6257 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6258 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6259 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006260 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006261
6262 // We also output an error message to the debugger window if tracing is active, so that
6263 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006264 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006265 return false;
6266 }
6267
6268 return true;
6269}
6270
6271bool ValidateFramebufferRenderbuffer(Context *context,
6272 GLenum target,
6273 GLenum attachment,
6274 GLenum renderbuffertarget,
6275 GLuint renderbuffer)
6276{
Geoff Lange8afa902017-09-27 15:00:43 -04006277 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006278 {
Jamie Madille0472f32018-11-27 16:32:45 -05006279 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006280 return false;
6281 }
6282
6283 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)
6284 {
Jamie Madille0472f32018-11-27 16:32:45 -05006285 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006286 return false;
6287 }
6288
6289 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6290 renderbuffertarget, renderbuffer);
6291}
6292
6293bool ValidateFramebufferTexture2D(Context *context,
6294 GLenum target,
6295 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006296 TextureTarget textarget,
Jamie Madillbe849e42017-05-02 15:49:00 -04006297 GLuint texture,
6298 GLint level)
6299{
6300 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6301 // extension
6302 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6303 level != 0)
6304 {
Jamie Madille0472f32018-11-27 16:32:45 -05006305 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006306 return false;
6307 }
6308
6309 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6310 {
6311 return false;
6312 }
6313
6314 if (texture != 0)
6315 {
6316 gl::Texture *tex = context->getTexture(texture);
6317 ASSERT(tex);
6318
6319 const gl::Caps &caps = context->getCaps();
6320
6321 switch (textarget)
6322 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006323 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006324 {
6325 if (level > gl::log2(caps.max2DTextureSize))
6326 {
Jamie Madille0472f32018-11-27 16:32:45 -05006327 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006328 return false;
6329 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006330 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006331 {
Jamie Madille0472f32018-11-27 16:32:45 -05006332 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006333 return false;
6334 }
6335 }
6336 break;
6337
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006338 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006339 {
6340 if (level != 0)
6341 {
Jamie Madille0472f32018-11-27 16:32:45 -05006342 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006343 return false;
6344 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006345 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006346 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006347 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006348 return false;
6349 }
6350 }
6351 break;
6352
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006353 case TextureTarget::CubeMapNegativeX:
6354 case TextureTarget::CubeMapNegativeY:
6355 case TextureTarget::CubeMapNegativeZ:
6356 case TextureTarget::CubeMapPositiveX:
6357 case TextureTarget::CubeMapPositiveY:
6358 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006359 {
6360 if (level > gl::log2(caps.maxCubeMapTextureSize))
6361 {
Jamie Madille0472f32018-11-27 16:32:45 -05006362 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006363 return false;
6364 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006365 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006366 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006367 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006368 return false;
6369 }
6370 }
6371 break;
6372
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006373 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006374 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006375 if (context->getClientVersion() < ES_3_1 &&
6376 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006377 {
Jamie Madill610640f2018-11-21 17:28:41 -05006378 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006379 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006380 return false;
6381 }
6382
6383 if (level != 0)
6384 {
Jamie Madille0472f32018-11-27 16:32:45 -05006385 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006386 return false;
6387 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006388 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006389 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006390 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006391 return false;
6392 }
6393 }
6394 break;
6395
6396 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006397 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006398 return false;
6399 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006400 }
6401
6402 return true;
6403}
6404
Cody Northrop5faff912019-06-28 14:04:50 -06006405bool ValidateFramebufferTexture3DOES(Context *context,
6406 GLenum target,
6407 GLenum attachment,
6408 TextureTarget textargetPacked,
6409 GLuint texture,
6410 GLint level,
6411 GLint zoffset)
6412{
6413 UNIMPLEMENTED();
6414 return false;
6415}
6416
Jamie Madillbe849e42017-05-02 15:49:00 -04006417bool ValidateGenBuffers(Context *context, GLint n, GLuint *)
6418{
6419 return ValidateGenOrDelete(context, n);
6420}
6421
6422bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *)
6423{
6424 return ValidateGenOrDelete(context, n);
6425}
6426
6427bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *)
6428{
6429 return ValidateGenOrDelete(context, n);
6430}
6431
6432bool ValidateGenTextures(Context *context, GLint n, GLuint *)
6433{
6434 return ValidateGenOrDelete(context, n);
6435}
6436
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006437bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006438{
6439 if (!ValidTextureTarget(context, target))
6440 {
Jamie Madille0472f32018-11-27 16:32:45 -05006441 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006442 return false;
6443 }
6444
Jamie Madillcfc73cc2019-04-08 16:26:51 -04006445 Texture *texture = context->getTextureByType(target);
Jamie Madillbe849e42017-05-02 15:49:00 -04006446
6447 if (texture == nullptr)
6448 {
Jamie Madille0472f32018-11-27 16:32:45 -05006449 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006450 return false;
6451 }
6452
6453 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6454
6455 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6456 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6457 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6458 {
Jamie Madille0472f32018-11-27 16:32:45 -05006459 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006460 return false;
6461 }
6462
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006463 TextureTarget baseTarget = (target == TextureType::CubeMap)
6464 ? TextureTarget::CubeMapPositiveX
6465 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006466 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6467 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6468 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006469 {
Jamie Madille0472f32018-11-27 16:32:45 -05006470 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006471 return false;
6472 }
6473
Geoff Lang536eca12017-09-13 11:23:35 -04006474 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6475 bool formatUnsized = !format.sized;
6476 bool formatColorRenderableAndFilterable =
6477 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006478 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006479 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006480 {
Jamie Madille0472f32018-11-27 16:32:45 -05006481 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006482 return false;
6483 }
6484
Geoff Lang536eca12017-09-13 11:23:35 -04006485 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6486 // generation
6487 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6488 {
Jamie Madille0472f32018-11-27 16:32:45 -05006489 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006490 return false;
6491 }
6492
Jiange2c00842018-07-13 16:50:49 +08006493 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6494 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6495 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006496 {
Jamie Madille0472f32018-11-27 16:32:45 -05006497 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006498 return false;
6499 }
6500
6501 // Non-power of 2 ES2 check
6502 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6503 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6504 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6505 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006506 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6507 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006508 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006509 return false;
6510 }
6511
6512 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006513 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006514 {
Jamie Madille0472f32018-11-27 16:32:45 -05006515 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006516 return false;
6517 }
6518
James Darpinian83b2f0e2018-11-27 15:56:01 -08006519 if (context->getExtensions().webglCompatibility &&
6520 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6521 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6522 {
6523 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6524 return false;
6525 }
6526
Jamie Madillbe849e42017-05-02 15:49:00 -04006527 return true;
6528}
6529
Jamie Madill5b772312018-03-08 20:28:32 -05006530bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006531 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006532 GLenum pname,
6533 GLint *params)
6534{
6535 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6536}
6537
6538bool ValidateGetRenderbufferParameteriv(Context *context,
6539 GLenum target,
6540 GLenum pname,
6541 GLint *params)
6542{
6543 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6544}
6545
6546bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params)
6547{
6548 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6549}
6550
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006551bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006552{
6553 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6554}
6555
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006556bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006557{
6558 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6559}
6560
Till Rathmannb8543632018-10-02 19:46:14 +02006561bool ValidateGetTexParameterIivOES(Context *context,
6562 TextureType target,
6563 GLenum pname,
6564 GLint *params)
6565{
6566 if (context->getClientMajorVersion() < 3)
6567 {
Jamie Madille0472f32018-11-27 16:32:45 -05006568 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006569 return false;
6570 }
6571 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6572}
6573
6574bool ValidateGetTexParameterIuivOES(Context *context,
6575 TextureType target,
6576 GLenum pname,
6577 GLuint *params)
6578{
6579 if (context->getClientMajorVersion() < 3)
6580 {
Jamie Madille0472f32018-11-27 16:32:45 -05006581 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006582 return false;
6583 }
6584 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6585}
6586
Jamie Madillbe849e42017-05-02 15:49:00 -04006587bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params)
6588{
6589 return ValidateGetUniformBase(context, program, location);
6590}
6591
6592bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params)
6593{
6594 return ValidateGetUniformBase(context, program, location);
6595}
6596
6597bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6598{
6599 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6600}
6601
6602bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6603{
6604 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6605}
6606
6607bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6608{
6609 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6610}
6611
6612bool ValidateIsEnabled(Context *context, GLenum cap)
6613{
6614 if (!ValidCap(context, cap, true))
6615 {
Jamie Madille0472f32018-11-27 16:32:45 -05006616 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006617 return false;
6618 }
6619
6620 return true;
6621}
6622
6623bool ValidateLinkProgram(Context *context, GLuint program)
6624{
6625 if (context->hasActiveTransformFeedback(program))
6626 {
6627 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006628 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006629 return false;
6630 }
6631
6632 Program *programObject = GetValidProgram(context, program);
6633 if (!programObject)
6634 {
6635 return false;
6636 }
6637
6638 return true;
6639}
6640
Jamie Madill4928b7c2017-06-20 12:57:39 -04006641bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006642 GLint x,
6643 GLint y,
6644 GLsizei width,
6645 GLsizei height,
6646 GLenum format,
6647 GLenum type,
6648 void *pixels)
6649{
6650 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6651 nullptr, pixels);
6652}
6653
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006654bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006655{
Till Rathmannb8543632018-10-02 19:46:14 +02006656 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006657}
6658
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006659bool ValidateTexParameterfv(Context *context,
6660 TextureType target,
6661 GLenum pname,
6662 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006663{
Till Rathmannb8543632018-10-02 19:46:14 +02006664 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006665}
6666
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006667bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006668{
Till Rathmannb8543632018-10-02 19:46:14 +02006669 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006670}
6671
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006672bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006673{
Till Rathmannb8543632018-10-02 19:46:14 +02006674 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6675}
6676
6677bool ValidateTexParameterIivOES(Context *context,
6678 TextureType target,
6679 GLenum pname,
6680 const GLint *params)
6681{
6682 if (context->getClientMajorVersion() < 3)
6683 {
Jamie Madille0472f32018-11-27 16:32:45 -05006684 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006685 return false;
6686 }
6687 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6688}
6689
6690bool ValidateTexParameterIuivOES(Context *context,
6691 TextureType target,
6692 GLenum pname,
6693 const GLuint *params)
6694{
6695 if (context->getClientMajorVersion() < 3)
6696 {
Jamie Madille0472f32018-11-27 16:32:45 -05006697 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006698 return false;
6699 }
6700 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006701}
6702
6703bool ValidateUseProgram(Context *context, GLuint program)
6704{
6705 if (program != 0)
6706 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006707 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006708 if (!programObject)
6709 {
6710 // ES 3.1.0 section 7.3 page 72
6711 if (context->getShader(program))
6712 {
Jamie Madille0472f32018-11-27 16:32:45 -05006713 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006714 return false;
6715 }
6716 else
6717 {
Jamie Madille0472f32018-11-27 16:32:45 -05006718 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006719 return false;
6720 }
6721 }
6722 if (!programObject->isLinked())
6723 {
Jamie Madille0472f32018-11-27 16:32:45 -05006724 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006725 return false;
6726 }
6727 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006728 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006729 {
6730 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006731 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006732 return false;
6733 }
6734
6735 return true;
6736}
6737
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006738bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences)
6739{
6740 if (!context->getExtensions().fence)
6741 {
Jamie Madille0472f32018-11-27 16:32:45 -05006742 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006743 return false;
6744 }
6745
6746 if (n < 0)
6747 {
Jamie Madille0472f32018-11-27 16:32:45 -05006748 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006749 return false;
6750 }
6751
6752 return true;
6753}
6754
6755bool ValidateFinishFenceNV(Context *context, GLuint fence)
6756{
6757 if (!context->getExtensions().fence)
6758 {
Jamie Madille0472f32018-11-27 16:32:45 -05006759 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006760 return false;
6761 }
6762
6763 FenceNV *fenceObject = context->getFenceNV(fence);
6764
6765 if (fenceObject == nullptr)
6766 {
Jamie Madille0472f32018-11-27 16:32:45 -05006767 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006768 return false;
6769 }
6770
6771 if (!fenceObject->isSet())
6772 {
Jamie Madille0472f32018-11-27 16:32:45 -05006773 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006774 return false;
6775 }
6776
6777 return true;
6778}
6779
6780bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences)
6781{
6782 if (!context->getExtensions().fence)
6783 {
Jamie Madille0472f32018-11-27 16:32:45 -05006784 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006785 return false;
6786 }
6787
6788 if (n < 0)
6789 {
Jamie Madille0472f32018-11-27 16:32:45 -05006790 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006791 return false;
6792 }
6793
6794 return true;
6795}
6796
6797bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params)
6798{
6799 if (!context->getExtensions().fence)
6800 {
Jamie Madille0472f32018-11-27 16:32:45 -05006801 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006802 return false;
6803 }
6804
6805 FenceNV *fenceObject = context->getFenceNV(fence);
6806
6807 if (fenceObject == nullptr)
6808 {
Jamie Madille0472f32018-11-27 16:32:45 -05006809 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006810 return false;
6811 }
6812
6813 if (!fenceObject->isSet())
6814 {
Jamie Madille0472f32018-11-27 16:32:45 -05006815 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006816 return false;
6817 }
6818
6819 switch (pname)
6820 {
6821 case GL_FENCE_STATUS_NV:
6822 case GL_FENCE_CONDITION_NV:
6823 break;
6824
6825 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006826 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006827 return false;
6828 }
6829
6830 return true;
6831}
6832
6833bool ValidateGetGraphicsResetStatusEXT(Context *context)
6834{
6835 if (!context->getExtensions().robustness)
6836 {
Jamie Madille0472f32018-11-27 16:32:45 -05006837 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006838 return false;
6839 }
6840
6841 return true;
6842}
6843
6844bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
6845 GLuint shader,
6846 GLsizei bufsize,
6847 GLsizei *length,
6848 GLchar *source)
6849{
6850 if (!context->getExtensions().translatedShaderSource)
6851 {
Jamie Madille0472f32018-11-27 16:32:45 -05006852 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006853 return false;
6854 }
6855
6856 if (bufsize < 0)
6857 {
Jamie Madille0472f32018-11-27 16:32:45 -05006858 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006859 return false;
6860 }
6861
6862 Shader *shaderObject = context->getShader(shader);
6863
6864 if (!shaderObject)
6865 {
Jamie Madille0472f32018-11-27 16:32:45 -05006866 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006867 return false;
6868 }
6869
6870 return true;
6871}
6872
6873bool ValidateIsFenceNV(Context *context, GLuint fence)
6874{
6875 if (!context->getExtensions().fence)
6876 {
Jamie Madille0472f32018-11-27 16:32:45 -05006877 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006878 return false;
6879 }
6880
6881 return true;
6882}
6883
Jamie Madill007530e2017-12-28 14:27:04 -05006884bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition)
6885{
6886 if (!context->getExtensions().fence)
6887 {
Jamie Madille0472f32018-11-27 16:32:45 -05006888 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006889 return false;
6890 }
6891
6892 if (condition != GL_ALL_COMPLETED_NV)
6893 {
Jamie Madille0472f32018-11-27 16:32:45 -05006894 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05006895 return false;
6896 }
6897
6898 FenceNV *fenceObject = context->getFenceNV(fence);
6899
6900 if (fenceObject == nullptr)
6901 {
Jamie Madille0472f32018-11-27 16:32:45 -05006902 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006903 return false;
6904 }
6905
6906 return true;
6907}
6908
6909bool ValidateTestFenceNV(Context *context, GLuint fence)
6910{
6911 if (!context->getExtensions().fence)
6912 {
Jamie Madille0472f32018-11-27 16:32:45 -05006913 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006914 return false;
6915 }
6916
6917 FenceNV *fenceObject = context->getFenceNV(fence);
6918
6919 if (fenceObject == nullptr)
6920 {
Jamie Madille0472f32018-11-27 16:32:45 -05006921 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006922 return false;
6923 }
6924
6925 if (fenceObject->isSet() != GL_TRUE)
6926 {
Jamie Madille0472f32018-11-27 16:32:45 -05006927 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05006928 return false;
6929 }
6930
6931 return true;
6932}
6933
6934bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006935 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05006936 GLsizei levels,
6937 GLenum internalformat,
6938 GLsizei width,
6939 GLsizei height)
6940{
6941 if (!context->getExtensions().textureStorage)
6942 {
Jamie Madille0472f32018-11-27 16:32:45 -05006943 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006944 return false;
6945 }
6946
6947 if (context->getClientMajorVersion() < 3)
6948 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006949 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05006950 height);
6951 }
6952
6953 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006954 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05006955 1);
6956}
6957
6958bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
6959{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006960 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05006961 {
Jamie Madille0472f32018-11-27 16:32:45 -05006962 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006963 return false;
6964 }
6965
6966 if (index >= MAX_VERTEX_ATTRIBS)
6967 {
Jamie Madille0472f32018-11-27 16:32:45 -05006968 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05006969 return false;
6970 }
6971
6972 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
6973 {
6974 if (index == 0 && divisor != 0)
6975 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006976 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05006977
6978 // We also output an error message to the debugger window if tracing is active, so
6979 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006980 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05006981 return false;
6982 }
6983 }
6984
6985 return true;
6986}
6987
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006988bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
6989{
6990 if (!context->getExtensions().instancedArraysEXT)
6991 {
6992 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6993 return false;
6994 }
6995
6996 if (index >= MAX_VERTEX_ATTRIBS)
6997 {
6998 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
6999 return false;
7000 }
7001
7002 return true;
7003}
7004
Jamie Madill007530e2017-12-28 14:27:04 -05007005bool ValidateTexImage3DOES(Context *context,
Cody Northrop5faff912019-06-28 14:04:50 -06007006 TextureTarget target,
Jamie Madill007530e2017-12-28 14:27:04 -05007007 GLint level,
7008 GLenum internalformat,
7009 GLsizei width,
7010 GLsizei height,
7011 GLsizei depth,
7012 GLint border,
7013 GLenum format,
7014 GLenum type,
7015 const void *pixels)
7016{
Cody Northrop5faff912019-06-28 14:04:50 -06007017 return ValidateTexImage3D(context, target, level, internalformat, width, height, depth, border,
7018 format, type, pixels);
Jamie Madill007530e2017-12-28 14:27:04 -05007019}
7020
7021bool ValidatePopGroupMarkerEXT(Context *context)
7022{
7023 if (!context->getExtensions().debugMarker)
7024 {
7025 // The debug marker calls should not set error state
7026 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05007027 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007028 return false;
7029 }
7030
7031 return true;
7032}
7033
Jamie Madillfa920eb2018-01-04 11:45:50 -05007034bool ValidateTexStorage1DEXT(Context *context,
7035 GLenum target,
7036 GLsizei levels,
7037 GLenum internalformat,
7038 GLsizei width)
7039{
7040 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05007041 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007042 return false;
7043}
7044
7045bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007046 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05007047 GLsizei levels,
7048 GLenum internalformat,
7049 GLsizei width,
7050 GLsizei height,
7051 GLsizei depth)
7052{
7053 if (!context->getExtensions().textureStorage)
7054 {
Jamie Madille0472f32018-11-27 16:32:45 -05007055 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007056 return false;
7057 }
7058
7059 if (context->getClientMajorVersion() < 3)
7060 {
Jamie Madille0472f32018-11-27 16:32:45 -05007061 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007062 return false;
7063 }
7064
7065 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
7066 depth);
7067}
7068
jchen1082af6202018-06-22 10:59:52 +08007069bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
7070{
7071 if (!context->getExtensions().parallelShaderCompile)
7072 {
Jamie Madille0472f32018-11-27 16:32:45 -05007073 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08007074 return false;
7075 }
7076 return true;
7077}
7078
Austin Eng1bf18ce2018-10-19 15:34:02 -07007079bool ValidateMultiDrawArraysANGLE(Context *context,
7080 PrimitiveMode mode,
7081 const GLint *firsts,
7082 const GLsizei *counts,
7083 GLsizei drawcount)
7084{
7085 if (!context->getExtensions().multiDraw)
7086 {
Jamie Madille0472f32018-11-27 16:32:45 -05007087 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007088 return false;
7089 }
7090 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7091 {
7092 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
7093 {
7094 return false;
7095 }
7096 }
7097 return true;
7098}
7099
7100bool ValidateMultiDrawElementsANGLE(Context *context,
7101 PrimitiveMode mode,
7102 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05007103 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08007104 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07007105 GLsizei drawcount)
7106{
7107 if (!context->getExtensions().multiDraw)
7108 {
Jamie Madille0472f32018-11-27 16:32:45 -05007109 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007110 return false;
7111 }
7112 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7113 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08007114 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07007115 {
7116 return false;
7117 }
7118 }
7119 return true;
7120}
7121
Jeff Gilbert465d6092019-01-02 16:21:18 -08007122bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked)
7123{
7124 if (!context->getExtensions().provokingVertex)
7125 {
7126 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7127 return false;
7128 }
7129
7130 switch (modePacked)
7131 {
7132 case ProvokingVertex::FirstVertexConvention:
7133 case ProvokingVertex::LastVertexConvention:
7134 break;
7135 default:
7136 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
7137 return false;
7138 }
7139
7140 return true;
7141}
7142
Jamie Madilla5410482019-01-31 19:55:55 -05007143void RecordBindTextureTypeError(Context *context, TextureType target)
7144{
7145 ASSERT(!context->getStateCache().isValidBindTextureType(target));
7146
7147 switch (target)
7148 {
7149 case TextureType::Rectangle:
7150 ASSERT(!context->getExtensions().textureRectangle);
7151 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
7152 break;
7153
7154 case TextureType::_3D:
7155 case TextureType::_2DArray:
7156 ASSERT(context->getClientMajorVersion() < 3);
7157 context->validationError(GL_INVALID_ENUM, kES3Required);
7158 break;
7159
7160 case TextureType::_2DMultisample:
7161 ASSERT(context->getClientVersion() < Version(3, 1) &&
7162 !context->getExtensions().textureMultisample);
7163 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
7164 break;
7165
7166 case TextureType::_2DMultisampleArray:
7167 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
7168 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
7169 break;
7170
7171 case TextureType::External:
7172 ASSERT(!context->getExtensions().eglImageExternal &&
7173 !context->getExtensions().eglStreamConsumerExternal);
7174 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
7175 break;
7176
7177 default:
7178 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
7179 }
7180}
7181
Jamie Madillc29968b2016-01-20 11:17:23 -05007182} // namespace gl