blob: fc3a04037eeb2cdc64f982745a14b0f09c25ee98 [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 =
495 framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat;
496 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 {
2666 const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer();
2667 const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer();
2668
2669 if (readColorAttachment && drawColorAttachment)
2670 {
2671 if (!(readColorAttachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002672 readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002673 readColorAttachment->type() != GL_RENDERBUFFER &&
2674 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2675 {
Jamie Madill610640f2018-11-21 17:28:41 -05002676 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002677 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002678 return false;
2679 }
2680
Geoff Langa15472a2015-08-11 11:48:03 -04002681 for (size_t drawbufferIdx = 0;
2682 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002683 {
Geoff Langa15472a2015-08-11 11:48:03 -04002684 const FramebufferAttachment *attachment =
2685 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2686 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002687 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002688 if (!(attachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002689 attachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002690 attachment->type() != GL_RENDERBUFFER &&
2691 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2692 {
Jamie Madill610640f2018-11-21 17:28:41 -05002693 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002694 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002695 return false;
2696 }
2697
2698 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002699 if (!Format::EquivalentForBlit(attachment->getFormat(),
2700 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002701 {
Jamie Madill610640f2018-11-21 17:28:41 -05002702 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002703 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002704 return false;
2705 }
2706 }
2707 }
2708
Jamie Madill427064d2018-04-13 16:20:34 -04002709 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002710 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002711 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2712 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2713 {
Jamie Madill610640f2018-11-21 17:28:41 -05002714 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002715 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002716 return false;
2717 }
2718 }
2719 }
2720
2721 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2722 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2723 for (size_t i = 0; i < 2; i++)
2724 {
2725 if (mask & masks[i])
2726 {
2727 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002728 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002729 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002730 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002731
2732 if (readBuffer && drawBuffer)
2733 {
2734 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2735 dstX0, dstY0, dstX1, dstY1))
2736 {
2737 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002738 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002739 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002740 return false;
2741 }
2742
2743 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2744 {
Jamie Madill610640f2018-11-21 17:28:41 -05002745 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002746 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002747 return false;
2748 }
2749 }
2750 }
2751 }
2752
2753 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2754 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002755}
Jamie Madillc29968b2016-01-20 11:17:23 -05002756
Jamie Madill5b772312018-03-08 20:28:32 -05002757bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002758{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002759 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002760 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002761
Jamie Madill427064d2018-04-13 16:20:34 -04002762 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002763 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002764 return false;
2765 }
2766
2767 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2768 {
Jamie Madille0472f32018-11-27 16:32:45 -05002769 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002770 return false;
2771 }
2772
Olli Etuaho94c91a92018-07-19 15:10:24 +03002773 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002774 {
2775 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2776 GL_SIGNED_NORMALIZED};
2777
Corentin Wallez59c41592017-07-11 13:19:54 -04002778 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002779 drawBufferIdx++)
2780 {
2781 if (!ValidateWebGLFramebufferAttachmentClearType(
2782 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2783 {
2784 return false;
2785 }
2786 }
2787 }
2788
Mingyu Huebab6702019-04-19 14:36:45 -07002789 if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery)
Olli Etuaho94c91a92018-07-19 15:10:24 +03002790 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002791 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002792 Framebuffer *framebuffer = state.getDrawFramebuffer();
2793 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2794 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002795 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002796 return false;
2797 }
2798 }
2799
Jamie Madillc29968b2016-01-20 11:17:23 -05002800 return true;
2801}
2802
Jamie Madill5b772312018-03-08 20:28:32 -05002803bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002804{
2805 if (!context->getExtensions().drawBuffers)
2806 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002807 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002808 return false;
2809 }
2810
2811 return ValidateDrawBuffersBase(context, n, bufs);
2812}
2813
Jamie Madill73a84962016-02-12 09:27:23 -05002814bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002815 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002816 GLint level,
2817 GLint internalformat,
2818 GLsizei width,
2819 GLsizei height,
2820 GLint border,
2821 GLenum format,
2822 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002823 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002824{
Martin Radev1be913c2016-07-11 17:59:16 +03002825 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002826 {
2827 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002828 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002829 }
2830
Martin Radev1be913c2016-07-11 17:59:16 +03002831 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002832 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002833 0, 0, width, height, 1, border, format, type, -1,
2834 pixels);
2835}
2836
Brandon Jones416aaf92018-04-10 08:10:16 -07002837bool ValidateTexImage2DRobustANGLE(Context *context,
2838 TextureTarget target,
2839 GLint level,
2840 GLint internalformat,
2841 GLsizei width,
2842 GLsizei height,
2843 GLint border,
2844 GLenum format,
2845 GLenum type,
2846 GLsizei bufSize,
2847 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04002848{
2849 if (!ValidateRobustEntryPoint(context, bufSize))
2850 {
2851 return false;
2852 }
2853
2854 if (context->getClientMajorVersion() < 3)
2855 {
2856 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
2857 0, 0, width, height, border, format, type, bufSize,
2858 pixels);
2859 }
2860
2861 ASSERT(context->getClientMajorVersion() >= 3);
2862 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
2863 0, 0, width, height, 1, border, format, type, bufSize,
2864 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002865}
2866
2867bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002868 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002869 GLint level,
2870 GLint xoffset,
2871 GLint yoffset,
2872 GLsizei width,
2873 GLsizei height,
2874 GLenum format,
2875 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002876 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002877{
2878
Martin Radev1be913c2016-07-11 17:59:16 +03002879 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002880 {
2881 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002882 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002883 }
2884
Martin Radev1be913c2016-07-11 17:59:16 +03002885 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002886 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002887 yoffset, 0, width, height, 1, 0, format, type, -1,
2888 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002889}
2890
Geoff Langc52f6f12016-10-14 10:18:00 -04002891bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002892 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04002893 GLint level,
2894 GLint xoffset,
2895 GLint yoffset,
2896 GLsizei width,
2897 GLsizei height,
2898 GLenum format,
2899 GLenum type,
2900 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002901 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04002902{
2903 if (!ValidateRobustEntryPoint(context, bufSize))
2904 {
2905 return false;
2906 }
2907
2908 if (context->getClientMajorVersion() < 3)
2909 {
2910 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
2911 yoffset, width, height, 0, format, type, bufSize,
2912 pixels);
2913 }
2914
2915 ASSERT(context->getClientMajorVersion() >= 3);
2916 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
2917 yoffset, 0, width, height, 1, 0, format, type, bufSize,
2918 pixels);
2919}
2920
Jamie Madill73a84962016-02-12 09:27:23 -05002921bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002922 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002923 GLint level,
2924 GLenum internalformat,
2925 GLsizei width,
2926 GLsizei height,
2927 GLint border,
2928 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002929 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002930{
Martin Radev1be913c2016-07-11 17:59:16 +03002931 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002932 {
2933 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002934 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002935 {
2936 return false;
2937 }
2938 }
2939 else
2940 {
Martin Radev1be913c2016-07-11 17:59:16 +03002941 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002942 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002943 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002944 data))
2945 {
2946 return false;
2947 }
2948 }
2949
Geoff Langca271392017-04-05 12:30:00 -04002950 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04002951
2952 GLuint blockSize = 0;
2953 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002954 {
Jamie Madille0472f32018-11-27 16:32:45 -05002955 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002956 return false;
2957 }
2958
Jamie Madillca2ff382018-07-11 09:01:17 -04002959 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002960 {
Jamie Madille0472f32018-11-27 16:32:45 -05002961 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05002962 return false;
2963 }
2964
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002965 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002966 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002967 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002968 return false;
2969 }
2970
Jamie Madill73a84962016-02-12 09:27:23 -05002971 return true;
2972}
2973
Corentin Wallezb2931602017-04-11 15:58:57 -04002974bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002975 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002976 GLint level,
2977 GLenum internalformat,
2978 GLsizei width,
2979 GLsizei height,
2980 GLint border,
2981 GLsizei imageSize,
2982 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002983 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002984{
2985 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2986 {
2987 return false;
2988 }
2989
2990 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
2991 border, imageSize, data);
2992}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002993
Corentin Wallezb2931602017-04-11 15:58:57 -04002994bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002995 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002996 GLint level,
2997 GLint xoffset,
2998 GLint yoffset,
2999 GLsizei width,
3000 GLsizei height,
3001 GLenum format,
3002 GLsizei imageSize,
3003 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003004 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003005{
3006 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3007 {
3008 return false;
3009 }
3010
3011 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
3012 format, imageSize, data);
3013}
3014
Jamie Madill73a84962016-02-12 09:27:23 -05003015bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003016 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003017 GLint level,
3018 GLint xoffset,
3019 GLint yoffset,
3020 GLsizei width,
3021 GLsizei height,
3022 GLenum format,
3023 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003024 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003025{
Martin Radev1be913c2016-07-11 17:59:16 +03003026 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05003027 {
3028 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003029 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05003030 {
3031 return false;
3032 }
3033 }
3034 else
3035 {
Martin Radev1be913c2016-07-11 17:59:16 +03003036 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003037 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003038 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05003039 data))
3040 {
3041 return false;
3042 }
3043 }
3044
Geoff Langca271392017-04-05 12:30:00 -04003045 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04003046 GLuint blockSize = 0;
3047 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003048 {
Jamie Madille0472f32018-11-27 16:32:45 -05003049 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003050 return false;
3051 }
3052
Jamie Madillca2ff382018-07-11 09:01:17 -04003053 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003054 {
Jamie Madille0472f32018-11-27 16:32:45 -05003055 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05003056 return false;
3057 }
3058
3059 return true;
3060}
3061
Corentin Wallez336129f2017-10-17 15:55:40 -04003062bool ValidateGetBufferPointervOES(Context *context,
3063 BufferBinding target,
3064 GLenum pname,
3065 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003066{
Jamie Madillc3e37312018-11-30 15:25:39 -05003067 if (!context->getExtensions().mapBuffer)
3068 {
3069 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3070 return false;
3071 }
3072
Geoff Lang496c02d2016-10-20 11:38:11 -07003073 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003074}
3075
Corentin Wallez336129f2017-10-17 15:55:40 -04003076bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003077{
3078 if (!context->getExtensions().mapBuffer)
3079 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003080 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003081 return false;
3082 }
3083
Corentin Walleze4477002017-12-01 14:39:58 -05003084 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03003085 {
Jamie Madille0472f32018-11-27 16:32:45 -05003086 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03003087 return false;
3088 }
3089
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003090 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003091
3092 if (buffer == nullptr)
3093 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003094 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03003095 return false;
3096 }
3097
3098 if (access != GL_WRITE_ONLY_OES)
3099 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003100 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03003101 return false;
3102 }
3103
3104 if (buffer->isMapped())
3105 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003106 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003107 return false;
3108 }
3109
Geoff Lang79f71042017-08-14 16:43:43 -04003110 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003111}
3112
Corentin Wallez336129f2017-10-17 15:55:40 -04003113bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003114{
3115 if (!context->getExtensions().mapBuffer)
3116 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003117 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003118 return false;
3119 }
3120
3121 return ValidateUnmapBufferBase(context, target);
3122}
3123
3124bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003125 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003126 GLintptr offset,
3127 GLsizeiptr length,
3128 GLbitfield access)
3129{
3130 if (!context->getExtensions().mapBufferRange)
3131 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003132 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003133 return false;
3134 }
3135
3136 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3137}
3138
Michael Spang7a8c3e52019-04-03 14:49:57 -04003139bool ValidateBufferStorageMemEXT(Context *context,
3140 TextureType target,
3141 GLsizeiptr size,
3142 GLuint memory,
3143 GLuint64 offset)
3144{
3145 if (!context->getExtensions().memoryObject)
3146 {
3147 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3148 return false;
3149 }
3150
3151 UNIMPLEMENTED();
3152 return false;
3153}
3154
3155bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects)
3156{
3157 if (!context->getExtensions().memoryObject)
3158 {
3159 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3160 return false;
3161 }
3162
Michael Spangfb201c52019-04-03 14:57:35 -04003163 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003164}
3165
3166bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects)
3167{
3168 if (!context->getExtensions().memoryObject)
3169 {
3170 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3171 return false;
3172 }
3173
Michael Spangfb201c52019-04-03 14:57:35 -04003174 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003175}
3176
3177bool ValidateGetMemoryObjectParameterivEXT(Context *context,
3178 GLuint memoryObject,
3179 GLenum pname,
3180 GLint *params)
3181{
3182 if (!context->getExtensions().memoryObject)
3183 {
3184 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3185 return false;
3186 }
3187
3188 UNIMPLEMENTED();
3189 return false;
3190}
3191
3192bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3193{
3194 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3195 {
3196 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3197 return false;
3198 }
3199
3200 UNIMPLEMENTED();
3201 return false;
3202}
3203
3204bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3205{
3206 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3207 {
3208 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3209 return false;
3210 }
3211
3212 UNIMPLEMENTED();
3213 return false;
3214}
3215
3216bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject)
3217{
3218 if (!context->getExtensions().memoryObject)
3219 {
3220 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3221 return false;
3222 }
3223
Michael Spangfb201c52019-04-03 14:57:35 -04003224 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003225}
3226
3227bool ValidateMemoryObjectParameterivEXT(Context *context,
3228 GLuint memoryObject,
3229 GLenum pname,
3230 const GLint *params)
3231{
3232 if (!context->getExtensions().memoryObject)
3233 {
3234 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3235 return false;
3236 }
3237
3238 UNIMPLEMENTED();
3239 return false;
3240}
3241
3242bool ValidateTexStorageMem2DEXT(Context *context,
3243 TextureType target,
3244 GLsizei levels,
3245 GLenum internalFormat,
3246 GLsizei width,
3247 GLsizei height,
3248 GLuint memory,
3249 GLuint64 offset)
3250{
3251 if (!context->getExtensions().memoryObject)
3252 {
3253 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3254 return false;
3255 }
3256
Michael Spangf02a7672019-04-09 18:45:23 -04003257 if (context->getClientMajorVersion() < 3)
3258 {
3259 return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width,
3260 height);
3261 }
3262
3263 ASSERT(context->getClientMajorVersion() >= 3);
3264 return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height,
3265 1);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003266}
3267
3268bool ValidateTexStorageMem3DEXT(Context *context,
3269 TextureType target,
3270 GLsizei levels,
3271 GLenum internalFormat,
3272 GLsizei width,
3273 GLsizei height,
3274 GLsizei depth,
3275 GLuint memory,
3276 GLuint64 offset)
3277{
3278 if (!context->getExtensions().memoryObject)
3279 {
3280 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3281 return false;
3282 }
3283
3284 UNIMPLEMENTED();
3285 return false;
3286}
3287
Michael Spang9de3ddb2019-04-03 16:23:40 -04003288bool ValidateImportMemoryFdEXT(Context *context,
3289 GLuint memory,
3290 GLuint64 size,
Michael Spange0da9ce2019-04-16 14:34:51 -04003291 HandleType handleType,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003292 GLint fd)
3293{
3294 if (!context->getExtensions().memoryObjectFd)
3295 {
3296 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3297 return false;
3298 }
3299
Michael Spang3b2c6bf2019-04-16 17:19:50 -04003300 switch (handleType)
3301 {
3302 case HandleType::OpaqueFd:
3303 break;
3304 default:
3305 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3306 return false;
3307 }
3308
3309 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003310}
3311
Michael Spang7a8c3e52019-04-03 14:49:57 -04003312bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores)
3313{
3314 if (!context->getExtensions().semaphore)
3315 {
3316 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3317 return false;
3318 }
3319
Michael Spang5093ba62019-05-14 17:36:36 -04003320 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003321}
3322
3323bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores)
3324{
3325 if (!context->getExtensions().semaphore)
3326 {
3327 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3328 return false;
3329 }
3330
Michael Spang5093ba62019-05-14 17:36:36 -04003331 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003332}
3333
3334bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
3335 GLuint semaphore,
3336 GLenum pname,
3337 GLuint64 *params)
3338{
3339 if (!context->getExtensions().semaphore)
3340 {
3341 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3342 return false;
3343 }
3344
3345 UNIMPLEMENTED();
3346 return false;
3347}
3348
3349bool ValidateIsSemaphoreEXT(Context *context, GLuint semaphore)
3350{
3351 if (!context->getExtensions().semaphore)
3352 {
3353 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3354 return false;
3355 }
3356
Michael Spang5093ba62019-05-14 17:36:36 -04003357 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003358}
3359
3360bool ValidateSemaphoreParameterui64vEXT(Context *context,
3361 GLuint semaphore,
3362 GLenum pname,
3363 const GLuint64 *params)
3364{
3365 if (!context->getExtensions().semaphore)
3366 {
3367 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3368 return false;
3369 }
3370
3371 UNIMPLEMENTED();
3372 return false;
3373}
3374
3375bool ValidateSignalSemaphoreEXT(Context *context,
3376 GLuint semaphore,
3377 GLuint numBufferBarriers,
3378 const GLuint *buffers,
3379 GLuint numTextureBarriers,
3380 const GLuint *textures,
3381 const GLenum *dstLayouts)
3382{
3383 if (!context->getExtensions().semaphore)
3384 {
3385 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3386 return false;
3387 }
3388
Michael Spangab6a59b2019-05-21 21:26:26 -04003389 for (GLuint i = 0; i < numTextureBarriers; ++i)
3390 {
3391 if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i])))
3392 {
3393 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3394 return false;
3395 }
3396 }
3397
3398 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003399}
3400
3401bool ValidateWaitSemaphoreEXT(Context *context,
3402 GLuint semaphore,
3403 GLuint numBufferBarriers,
3404 const GLuint *buffers,
3405 GLuint numTextureBarriers,
3406 const GLuint *textures,
3407 const GLenum *srcLayouts)
3408{
3409 if (!context->getExtensions().semaphore)
3410 {
3411 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3412 return false;
3413 }
3414
Michael Spangab6a59b2019-05-21 21:26:26 -04003415 for (GLuint i = 0; i < numTextureBarriers; ++i)
3416 {
3417 if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i])))
3418 {
3419 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3420 return false;
3421 }
3422 }
3423
3424 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003425}
3426
Michael Spange0da9ce2019-04-16 14:34:51 -04003427bool ValidateImportSemaphoreFdEXT(Context *context,
3428 GLuint semaphore,
3429 HandleType handleType,
3430 GLint fd)
Michael Spang9de3ddb2019-04-03 16:23:40 -04003431{
3432 if (!context->getExtensions().semaphoreFd)
3433 {
3434 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3435 return false;
3436 }
3437
Michael Spang6bb193c2019-05-22 16:32:21 -04003438 switch (handleType)
3439 {
3440 case HandleType::OpaqueFd:
3441 break;
3442 default:
3443 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3444 return false;
3445 }
3446
3447 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003448}
3449
Corentin Wallez336129f2017-10-17 15:55:40 -04003450bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003451{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003452 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003453 ASSERT(buffer != nullptr);
3454
3455 // Check if this buffer is currently being used as a transform feedback output buffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003456 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003457 if (transformFeedback != nullptr && transformFeedback->isActive())
3458 {
3459 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3460 {
3461 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3462 if (transformFeedbackBuffer.get() == buffer)
3463 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003464 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003465 return false;
3466 }
3467 }
3468 }
3469
James Darpiniane8a93c62018-01-04 18:02:24 -08003470 if (context->getExtensions().webglCompatibility &&
3471 buffer->isBoundForTransformFeedbackAndOtherUse())
3472 {
Jamie Madille0472f32018-11-27 16:32:45 -05003473 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003474 return false;
3475 }
3476
Geoff Lang79f71042017-08-14 16:43:43 -04003477 return true;
3478}
3479
Olli Etuaho4f667482016-03-30 15:56:35 +03003480bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003481 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003482 GLintptr offset,
3483 GLsizeiptr length)
3484{
3485 if (!context->getExtensions().mapBufferRange)
3486 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003487 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003488 return false;
3489 }
3490
3491 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3492}
3493
Geoff Langd8605522016-04-13 10:19:12 -04003494bool ValidateBindUniformLocationCHROMIUM(Context *context,
3495 GLuint program,
3496 GLint location,
3497 const GLchar *name)
3498{
3499 if (!context->getExtensions().bindUniformLocation)
3500 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003501 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003502 return false;
3503 }
3504
3505 Program *programObject = GetValidProgram(context, program);
3506 if (!programObject)
3507 {
3508 return false;
3509 }
3510
3511 if (location < 0)
3512 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003513 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003514 return false;
3515 }
3516
3517 const Caps &caps = context->getCaps();
3518 if (static_cast<size_t>(location) >=
3519 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3520 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003521 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003522 return false;
3523 }
3524
Geoff Langfc32e8b2017-05-31 14:16:59 -04003525 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3526 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003527 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003528 {
Jamie Madille0472f32018-11-27 16:32:45 -05003529 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003530 return false;
3531 }
3532
Geoff Langd8605522016-04-13 10:19:12 -04003533 if (strncmp(name, "gl_", 3) == 0)
3534 {
Jamie Madille0472f32018-11-27 16:32:45 -05003535 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003536 return false;
3537 }
3538
3539 return true;
3540}
3541
Jamie Madille2e406c2016-06-02 13:04:10 -04003542bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003543{
3544 if (!context->getExtensions().framebufferMixedSamples)
3545 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003546 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003547 return false;
3548 }
3549 switch (components)
3550 {
3551 case GL_RGB:
3552 case GL_RGBA:
3553 case GL_ALPHA:
3554 case GL_NONE:
3555 break;
3556 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003557 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003558 return false;
3559 }
3560
3561 return true;
3562}
3563
Sami Väisänene45e53b2016-05-25 10:36:04 +03003564// CHROMIUM_path_rendering
3565
Jamie Madill007530e2017-12-28 14:27:04 -05003566bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003567{
Jamie Madill007530e2017-12-28 14:27:04 -05003568 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003569 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003570 return false;
3571 }
Jamie Madill007530e2017-12-28 14:27:04 -05003572
Sami Väisänene45e53b2016-05-25 10:36:04 +03003573 if (matrix == nullptr)
3574 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003575 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003576 return false;
3577 }
Jamie Madill007530e2017-12-28 14:27:04 -05003578
Sami Väisänene45e53b2016-05-25 10:36:04 +03003579 return true;
3580}
3581
Jamie Madill007530e2017-12-28 14:27:04 -05003582bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003583{
Jamie Madill007530e2017-12-28 14:27:04 -05003584 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003585}
3586
Jamie Madill007530e2017-12-28 14:27:04 -05003587bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003588{
3589 if (!context->getExtensions().pathRendering)
3590 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003591 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003592 return false;
3593 }
3594
3595 // range = 0 is undefined in NV_path_rendering.
3596 // we add stricter semantic check here and require a non zero positive range.
3597 if (range <= 0)
3598 {
Jamie Madille0472f32018-11-27 16:32:45 -05003599 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003600 return false;
3601 }
3602
3603 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3604 {
Jamie Madille0472f32018-11-27 16:32:45 -05003605 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003606 return false;
3607 }
3608
3609 return true;
3610}
3611
Jamie Madill007530e2017-12-28 14:27:04 -05003612bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003613{
3614 if (!context->getExtensions().pathRendering)
3615 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003616 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003617 return false;
3618 }
3619
3620 // range = 0 is undefined in NV_path_rendering.
3621 // we add stricter semantic check here and require a non zero positive range.
3622 if (range <= 0)
3623 {
Jamie Madille0472f32018-11-27 16:32:45 -05003624 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003625 return false;
3626 }
3627
3628 angle::CheckedNumeric<std::uint32_t> checkedRange(path);
3629 checkedRange += range;
3630
3631 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3632 {
Jamie Madille0472f32018-11-27 16:32:45 -05003633 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003634 return false;
3635 }
3636 return true;
3637}
3638
Jamie Madill007530e2017-12-28 14:27:04 -05003639bool ValidatePathCommandsCHROMIUM(Context *context,
3640 GLuint path,
3641 GLsizei numCommands,
3642 const GLubyte *commands,
3643 GLsizei numCoords,
3644 GLenum coordType,
3645 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003646{
3647 if (!context->getExtensions().pathRendering)
3648 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003649 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003650 return false;
3651 }
Brandon Jones59770802018-04-02 13:18:42 -07003652 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003653 {
Jamie Madille0472f32018-11-27 16:32:45 -05003654 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003655 return false;
3656 }
3657
3658 if (numCommands < 0)
3659 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003660 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003661 return false;
3662 }
3663 else if (numCommands > 0)
3664 {
3665 if (!commands)
3666 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003667 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003668 return false;
3669 }
3670 }
3671
3672 if (numCoords < 0)
3673 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003674 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003675 return false;
3676 }
3677 else if (numCoords > 0)
3678 {
3679 if (!coords)
3680 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003681 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003682 return false;
3683 }
3684 }
3685
3686 std::uint32_t coordTypeSize = 0;
3687 switch (coordType)
3688 {
3689 case GL_BYTE:
3690 coordTypeSize = sizeof(GLbyte);
3691 break;
3692
3693 case GL_UNSIGNED_BYTE:
3694 coordTypeSize = sizeof(GLubyte);
3695 break;
3696
3697 case GL_SHORT:
3698 coordTypeSize = sizeof(GLshort);
3699 break;
3700
3701 case GL_UNSIGNED_SHORT:
3702 coordTypeSize = sizeof(GLushort);
3703 break;
3704
3705 case GL_FLOAT:
3706 coordTypeSize = sizeof(GLfloat);
3707 break;
3708
3709 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003710 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003711 return false;
3712 }
3713
3714 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3715 checkedSize += (coordTypeSize * numCoords);
3716 if (!checkedSize.IsValid())
3717 {
Jamie Madille0472f32018-11-27 16:32:45 -05003718 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003719 return false;
3720 }
3721
3722 // early return skips command data validation when it doesn't exist.
3723 if (!commands)
3724 return true;
3725
3726 GLsizei expectedNumCoords = 0;
3727 for (GLsizei i = 0; i < numCommands; ++i)
3728 {
3729 switch (commands[i])
3730 {
3731 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3732 break;
3733 case GL_MOVE_TO_CHROMIUM:
3734 case GL_LINE_TO_CHROMIUM:
3735 expectedNumCoords += 2;
3736 break;
3737 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3738 expectedNumCoords += 4;
3739 break;
3740 case GL_CUBIC_CURVE_TO_CHROMIUM:
3741 expectedNumCoords += 6;
3742 break;
3743 case GL_CONIC_CURVE_TO_CHROMIUM:
3744 expectedNumCoords += 5;
3745 break;
3746 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003747 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003748 return false;
3749 }
3750 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003751
Sami Väisänene45e53b2016-05-25 10:36:04 +03003752 if (expectedNumCoords != numCoords)
3753 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003754 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003755 return false;
3756 }
3757
3758 return true;
3759}
3760
Jamie Madill007530e2017-12-28 14:27:04 -05003761bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003762{
3763 if (!context->getExtensions().pathRendering)
3764 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003765 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003766 return false;
3767 }
Brandon Jones59770802018-04-02 13:18:42 -07003768 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003769 {
Jamie Madille0472f32018-11-27 16:32:45 -05003770 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003771 return false;
3772 }
3773
3774 switch (pname)
3775 {
3776 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3777 if (value < 0.0f)
3778 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003779 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003780 return false;
3781 }
3782 break;
3783 case GL_PATH_END_CAPS_CHROMIUM:
3784 switch (static_cast<GLenum>(value))
3785 {
3786 case GL_FLAT_CHROMIUM:
3787 case GL_SQUARE_CHROMIUM:
3788 case GL_ROUND_CHROMIUM:
3789 break;
3790 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003791 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003792 return false;
3793 }
3794 break;
3795 case GL_PATH_JOIN_STYLE_CHROMIUM:
3796 switch (static_cast<GLenum>(value))
3797 {
3798 case GL_MITER_REVERT_CHROMIUM:
3799 case GL_BEVEL_CHROMIUM:
3800 case GL_ROUND_CHROMIUM:
3801 break;
3802 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003803 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003804 return false;
3805 }
Nico Weber41b072b2018-02-09 10:01:32 -05003806 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03003807 case GL_PATH_MITER_LIMIT_CHROMIUM:
3808 if (value < 0.0f)
3809 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003810 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003811 return false;
3812 }
3813 break;
3814
3815 case GL_PATH_STROKE_BOUND_CHROMIUM:
3816 // no errors, only clamping.
3817 break;
3818
3819 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003820 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003821 return false;
3822 }
3823 return true;
3824}
3825
Jamie Madill007530e2017-12-28 14:27:04 -05003826bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value)
3827{
3828 // TODO(jmadill): Use proper clamping cast.
3829 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
3830}
3831
3832bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003833{
3834 if (!context->getExtensions().pathRendering)
3835 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003836 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003837 return false;
3838 }
3839
Brandon Jones59770802018-04-02 13:18:42 -07003840 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003841 {
Jamie Madille0472f32018-11-27 16:32:45 -05003842 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003843 return false;
3844 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003845
Sami Väisänene45e53b2016-05-25 10:36:04 +03003846 if (!value)
3847 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003848 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003849 return false;
3850 }
3851
3852 switch (pname)
3853 {
3854 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3855 case GL_PATH_END_CAPS_CHROMIUM:
3856 case GL_PATH_JOIN_STYLE_CHROMIUM:
3857 case GL_PATH_MITER_LIMIT_CHROMIUM:
3858 case GL_PATH_STROKE_BOUND_CHROMIUM:
3859 break;
3860
3861 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003862 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003863 return false;
3864 }
3865
3866 return true;
3867}
3868
Jamie Madill007530e2017-12-28 14:27:04 -05003869bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value)
3870{
3871 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
3872 reinterpret_cast<GLfloat *>(value));
3873}
3874
3875bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003876{
3877 if (!context->getExtensions().pathRendering)
3878 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003879 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003880 return false;
3881 }
3882
3883 switch (func)
3884 {
3885 case GL_NEVER:
3886 case GL_ALWAYS:
3887 case GL_LESS:
3888 case GL_LEQUAL:
3889 case GL_EQUAL:
3890 case GL_GEQUAL:
3891 case GL_GREATER:
3892 case GL_NOTEQUAL:
3893 break;
3894 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003895 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003896 return false;
3897 }
3898
3899 return true;
3900}
3901
3902// Note that the spec specifies that for the path drawing commands
3903// if the path object is not an existing path object the command
3904// does nothing and no error is generated.
3905// However if the path object exists but has not been specified any
3906// commands then an error is generated.
3907
Jamie Madill007530e2017-12-28 14:27:04 -05003908bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003909{
3910 if (!context->getExtensions().pathRendering)
3911 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003912 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003913 return false;
3914 }
Brandon Jones59770802018-04-02 13:18:42 -07003915 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003916 {
Jamie Madille0472f32018-11-27 16:32:45 -05003917 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003918 return false;
3919 }
3920
3921 switch (fillMode)
3922 {
3923 case GL_COUNT_UP_CHROMIUM:
3924 case GL_COUNT_DOWN_CHROMIUM:
3925 break;
3926 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003927 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003928 return false;
3929 }
3930
3931 if (!isPow2(mask + 1))
3932 {
Jamie Madille0472f32018-11-27 16:32:45 -05003933 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003934 return false;
3935 }
3936
3937 return true;
3938}
3939
Jamie Madill007530e2017-12-28 14:27:04 -05003940bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003941{
3942 if (!context->getExtensions().pathRendering)
3943 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003944 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003945 return false;
3946 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003947
Brandon Jones59770802018-04-02 13:18:42 -07003948 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003949 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003950 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003951 return false;
3952 }
3953
3954 return true;
3955}
3956
Jamie Madill007530e2017-12-28 14:27:04 -05003957bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003958{
3959 if (!context->getExtensions().pathRendering)
3960 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003961 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003962 return false;
3963 }
Brandon Jones59770802018-04-02 13:18:42 -07003964 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003965 {
Jamie Madille0472f32018-11-27 16:32:45 -05003966 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003967 return false;
3968 }
3969
3970 switch (coverMode)
3971 {
3972 case GL_CONVEX_HULL_CHROMIUM:
3973 case GL_BOUNDING_BOX_CHROMIUM:
3974 break;
3975 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003976 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003977 return false;
3978 }
3979 return true;
3980}
3981
Jamie Madill778bf092018-11-14 09:54:36 -05003982bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3983{
3984 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3985}
3986
3987bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3988{
3989 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3990}
3991
Jamie Madill007530e2017-12-28 14:27:04 -05003992bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
3993 GLuint path,
3994 GLenum fillMode,
3995 GLuint mask,
3996 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003997{
Jamie Madill007530e2017-12-28 14:27:04 -05003998 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
3999 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004000}
4001
Jamie Madill007530e2017-12-28 14:27:04 -05004002bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
4003 GLuint path,
4004 GLint reference,
4005 GLuint mask,
4006 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004007{
Jamie Madill007530e2017-12-28 14:27:04 -05004008 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
4009 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004010}
4011
Brandon Jonesd1049182018-03-28 10:02:20 -07004012bool ValidateIsPathCHROMIUM(Context *context, GLuint path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004013{
4014 if (!context->getExtensions().pathRendering)
4015 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004016 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004017 return false;
4018 }
4019 return true;
4020}
4021
Jamie Madill007530e2017-12-28 14:27:04 -05004022bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
4023 GLsizei numPaths,
4024 GLenum pathNameType,
4025 const void *paths,
4026 GLuint pathBase,
4027 GLenum coverMode,
4028 GLenum transformType,
4029 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004030{
4031 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4032 transformType, transformValues))
4033 return false;
4034
4035 switch (coverMode)
4036 {
4037 case GL_CONVEX_HULL_CHROMIUM:
4038 case GL_BOUNDING_BOX_CHROMIUM:
4039 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4040 break;
4041 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004042 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004043 return false;
4044 }
4045
4046 return true;
4047}
4048
Jamie Madill007530e2017-12-28 14:27:04 -05004049bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
4050 GLsizei numPaths,
4051 GLenum pathNameType,
4052 const void *paths,
4053 GLuint pathBase,
4054 GLenum coverMode,
4055 GLenum transformType,
4056 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004057{
4058 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4059 transformType, transformValues))
4060 return false;
4061
4062 switch (coverMode)
4063 {
4064 case GL_CONVEX_HULL_CHROMIUM:
4065 case GL_BOUNDING_BOX_CHROMIUM:
4066 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4067 break;
4068 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004069 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004070 return false;
4071 }
4072
4073 return true;
4074}
4075
Jamie Madill007530e2017-12-28 14:27:04 -05004076bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
4077 GLsizei numPaths,
4078 GLenum pathNameType,
4079 const void *paths,
4080 GLuint pathBase,
4081 GLenum fillMode,
4082 GLuint mask,
4083 GLenum transformType,
4084 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004085{
4086
4087 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4088 transformType, transformValues))
4089 return false;
4090
4091 switch (fillMode)
4092 {
4093 case GL_COUNT_UP_CHROMIUM:
4094 case GL_COUNT_DOWN_CHROMIUM:
4095 break;
4096 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004097 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004098 return false;
4099 }
4100 if (!isPow2(mask + 1))
4101 {
Jamie Madille0472f32018-11-27 16:32:45 -05004102 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004103 return false;
4104 }
4105 return true;
4106}
4107
Jamie Madill007530e2017-12-28 14:27:04 -05004108bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
4109 GLsizei numPaths,
4110 GLenum pathNameType,
4111 const void *paths,
4112 GLuint pathBase,
4113 GLint reference,
4114 GLuint mask,
4115 GLenum transformType,
4116 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004117{
4118 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4119 transformType, transformValues))
4120 return false;
4121
4122 // no more validation here.
4123
4124 return true;
4125}
4126
Jamie Madill007530e2017-12-28 14:27:04 -05004127bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
4128 GLsizei numPaths,
4129 GLenum pathNameType,
4130 const void *paths,
4131 GLuint pathBase,
4132 GLenum fillMode,
4133 GLuint mask,
4134 GLenum coverMode,
4135 GLenum transformType,
4136 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004137{
4138 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4139 transformType, transformValues))
4140 return false;
4141
4142 switch (coverMode)
4143 {
4144 case GL_CONVEX_HULL_CHROMIUM:
4145 case GL_BOUNDING_BOX_CHROMIUM:
4146 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4147 break;
4148 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004149 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004150 return false;
4151 }
4152
4153 switch (fillMode)
4154 {
4155 case GL_COUNT_UP_CHROMIUM:
4156 case GL_COUNT_DOWN_CHROMIUM:
4157 break;
4158 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004159 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004160 return false;
4161 }
4162 if (!isPow2(mask + 1))
4163 {
Jamie Madille0472f32018-11-27 16:32:45 -05004164 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004165 return false;
4166 }
4167
4168 return true;
4169}
4170
Jamie Madill007530e2017-12-28 14:27:04 -05004171bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4172 GLsizei numPaths,
4173 GLenum pathNameType,
4174 const void *paths,
4175 GLuint pathBase,
4176 GLint reference,
4177 GLuint mask,
4178 GLenum coverMode,
4179 GLenum transformType,
4180 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004181{
4182 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4183 transformType, transformValues))
4184 return false;
4185
4186 switch (coverMode)
4187 {
4188 case GL_CONVEX_HULL_CHROMIUM:
4189 case GL_BOUNDING_BOX_CHROMIUM:
4190 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4191 break;
4192 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004193 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004194 return false;
4195 }
4196
4197 return true;
4198}
4199
Jamie Madill007530e2017-12-28 14:27:04 -05004200bool ValidateBindFragmentInputLocationCHROMIUM(Context *context,
4201 GLuint program,
4202 GLint location,
4203 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004204{
4205 if (!context->getExtensions().pathRendering)
4206 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004207 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004208 return false;
4209 }
4210
4211 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4212 if (location >= MaxLocation)
4213 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004214 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004215 return false;
4216 }
4217
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004218 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004219 if (!programObject)
4220 {
Jamie Madille0472f32018-11-27 16:32:45 -05004221 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004222 return false;
4223 }
4224
4225 if (!name)
4226 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004227 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004228 return false;
4229 }
4230
4231 if (angle::BeginsWith(name, "gl_"))
4232 {
Jamie Madille0472f32018-11-27 16:32:45 -05004233 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004234 return false;
4235 }
4236
4237 return true;
4238}
4239
Jamie Madill007530e2017-12-28 14:27:04 -05004240bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
4241 GLuint program,
4242 GLint location,
4243 GLenum genMode,
4244 GLint components,
4245 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004246{
4247 if (!context->getExtensions().pathRendering)
4248 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004249 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004250 return false;
4251 }
4252
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004253 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004254 if (!programObject || programObject->isFlaggedForDeletion())
4255 {
Jamie Madille0472f32018-11-27 16:32:45 -05004256 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004257 return false;
4258 }
4259
4260 if (!programObject->isLinked())
4261 {
Jamie Madille0472f32018-11-27 16:32:45 -05004262 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004263 return false;
4264 }
4265
4266 switch (genMode)
4267 {
4268 case GL_NONE:
4269 if (components != 0)
4270 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004271 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004272 return false;
4273 }
4274 break;
4275
4276 case GL_OBJECT_LINEAR_CHROMIUM:
4277 case GL_EYE_LINEAR_CHROMIUM:
4278 case GL_CONSTANT_CHROMIUM:
4279 if (components < 1 || components > 4)
4280 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004281 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004282 return false;
4283 }
4284 if (!coeffs)
4285 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004286 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004287 return false;
4288 }
4289 break;
4290
4291 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004292 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004293 return false;
4294 }
4295
4296 // If the location is -1 then the command is silently ignored
4297 // and no further validation is needed.
4298 if (location == -1)
4299 return true;
4300
jchen103fd614d2018-08-13 12:21:58 +08004301 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004302
4303 if (!binding.valid)
4304 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004305 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004306 return false;
4307 }
4308
4309 if (binding.type != GL_NONE)
4310 {
4311 GLint expectedComponents = 0;
4312 switch (binding.type)
4313 {
4314 case GL_FLOAT:
4315 expectedComponents = 1;
4316 break;
4317 case GL_FLOAT_VEC2:
4318 expectedComponents = 2;
4319 break;
4320 case GL_FLOAT_VEC3:
4321 expectedComponents = 3;
4322 break;
4323 case GL_FLOAT_VEC4:
4324 expectedComponents = 4;
4325 break;
4326 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004327 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004328 return false;
4329 }
4330 if (expectedComponents != components && genMode != GL_NONE)
4331 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004332 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004333 return false;
4334 }
4335 }
4336 return true;
4337}
4338
Geoff Lang97073d12016-04-20 10:42:34 -07004339bool ValidateCopyTextureCHROMIUM(Context *context,
4340 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004341 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004342 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004343 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004344 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004345 GLint internalFormat,
4346 GLenum destType,
4347 GLboolean unpackFlipY,
4348 GLboolean unpackPremultiplyAlpha,
4349 GLboolean unpackUnmultiplyAlpha)
4350{
4351 if (!context->getExtensions().copyTexture)
4352 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004353 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004354 return false;
4355 }
4356
Geoff Lang4f0e0032017-05-01 16:04:35 -04004357 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004358 if (source == nullptr)
4359 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004360 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004361 return false;
4362 }
4363
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004364 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004365 {
Jamie Madille0472f32018-11-27 16:32:45 -05004366 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004367 return false;
4368 }
4369
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004370 TextureType sourceType = source->getType();
4371 ASSERT(sourceType != TextureType::CubeMap);
4372 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004373
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004374 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004375 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004376 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004377 return false;
4378 }
4379
Geoff Lang4f0e0032017-05-01 16:04:35 -04004380 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4381 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4382 if (sourceWidth == 0 || sourceHeight == 0)
4383 {
Jamie Madille0472f32018-11-27 16:32:45 -05004384 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004385 return false;
4386 }
4387
4388 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4389 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004390 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004391 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004392 return false;
4393 }
4394
Geoff Lang63458a32017-10-30 15:16:53 -04004395 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4396 {
Jamie Madille0472f32018-11-27 16:32:45 -05004397 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004398 return false;
4399 }
4400
Geoff Lang4f0e0032017-05-01 16:04:35 -04004401 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004402 if (dest == nullptr)
4403 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004404 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004405 return false;
4406 }
4407
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004408 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004409 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004410 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004411 return false;
4412 }
4413
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004414 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004415 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004416 {
Jamie Madille0472f32018-11-27 16:32:45 -05004417 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004418 return false;
4419 }
4420
Geoff Lang97073d12016-04-20 10:42:34 -07004421 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4422 {
Geoff Lang97073d12016-04-20 10:42:34 -07004423 return false;
4424 }
4425
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004426 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004427 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004428 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004429 return false;
4430 }
4431
Geoff Lang97073d12016-04-20 10:42:34 -07004432 if (dest->getImmutableFormat())
4433 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004434 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004435 return false;
4436 }
4437
4438 return true;
4439}
4440
4441bool ValidateCopySubTextureCHROMIUM(Context *context,
4442 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004443 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004444 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004445 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004446 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004447 GLint xoffset,
4448 GLint yoffset,
4449 GLint x,
4450 GLint y,
4451 GLsizei width,
4452 GLsizei height,
4453 GLboolean unpackFlipY,
4454 GLboolean unpackPremultiplyAlpha,
4455 GLboolean unpackUnmultiplyAlpha)
4456{
4457 if (!context->getExtensions().copyTexture)
4458 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004459 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004460 return false;
4461 }
4462
Geoff Lang4f0e0032017-05-01 16:04:35 -04004463 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004464 if (source == nullptr)
4465 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004466 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004467 return false;
4468 }
4469
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004470 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004471 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004472 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004473 return false;
4474 }
4475
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004476 TextureType sourceType = source->getType();
4477 ASSERT(sourceType != TextureType::CubeMap);
4478 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004479
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004480 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004481 {
Jamie Madille0472f32018-11-27 16:32:45 -05004482 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004483 return false;
4484 }
4485
4486 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4487 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004488 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004489 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004490 return false;
4491 }
4492
4493 if (x < 0 || y < 0)
4494 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004495 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004496 return false;
4497 }
4498
4499 if (width < 0 || height < 0)
4500 {
Jamie Madille0472f32018-11-27 16:32:45 -05004501 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004502 return false;
4503 }
4504
Geoff Lang4f0e0032017-05-01 16:04:35 -04004505 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4506 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004507 {
Jamie Madille0472f32018-11-27 16:32:45 -05004508 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004509 return false;
4510 }
4511
Geoff Lang4f0e0032017-05-01 16:04:35 -04004512 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4513 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004514 {
Jamie Madille0472f32018-11-27 16:32:45 -05004515 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004516 return false;
4517 }
4518
Geoff Lang63458a32017-10-30 15:16:53 -04004519 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4520 {
Jamie Madille0472f32018-11-27 16:32:45 -05004521 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004522 return false;
4523 }
4524
Geoff Lang4f0e0032017-05-01 16:04:35 -04004525 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004526 if (dest == nullptr)
4527 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004528 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004529 return false;
4530 }
4531
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004532 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004533 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004534 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004535 return false;
4536 }
4537
Brandon Jones28783792018-03-05 09:37:32 -08004538 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4539 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004540 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004541 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004542 return false;
4543 }
4544
Geoff Lang4f0e0032017-05-01 16:04:35 -04004545 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4546 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004547 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004548 return false;
4549 }
4550
4551 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4552 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004553 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004554 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004555 return false;
4556 }
4557
4558 if (xoffset < 0 || yoffset < 0)
4559 {
Jamie Madille0472f32018-11-27 16:32:45 -05004560 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004561 return false;
4562 }
4563
Geoff Lang4f0e0032017-05-01 16:04:35 -04004564 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4565 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004566 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004567 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004568 return false;
4569 }
4570
4571 return true;
4572}
4573
Geoff Lang47110bf2016-04-20 11:13:22 -07004574bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId)
4575{
4576 if (!context->getExtensions().copyCompressedTexture)
4577 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004578 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004579 return false;
4580 }
4581
4582 const gl::Texture *source = context->getTexture(sourceId);
4583 if (source == nullptr)
4584 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004585 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004586 return false;
4587 }
4588
Corentin Wallez99d492c2018-02-27 15:17:10 -05004589 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004590 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004591 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004592 return false;
4593 }
4594
Corentin Wallez99d492c2018-02-27 15:17:10 -05004595 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4596 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004597 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004598 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004599 return false;
4600 }
4601
Corentin Wallez99d492c2018-02-27 15:17:10 -05004602 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004603 if (!sourceFormat.info->compressed)
4604 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004605 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004606 return false;
4607 }
4608
4609 const gl::Texture *dest = context->getTexture(destId);
4610 if (dest == nullptr)
4611 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004612 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004613 return false;
4614 }
4615
Corentin Wallez99d492c2018-02-27 15:17:10 -05004616 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004617 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004618 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004619 return false;
4620 }
4621
4622 if (dest->getImmutableFormat())
4623 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004624 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004625 return false;
4626 }
4627
4628 return true;
4629}
4630
Jiawei Shao385b3e02018-03-21 09:43:28 +08004631bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004632{
4633 switch (type)
4634 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004635 case ShaderType::Vertex:
4636 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004637 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004638
Jiawei Shao385b3e02018-03-21 09:43:28 +08004639 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004640 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004641 {
Jamie Madille0472f32018-11-27 16:32:45 -05004642 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004643 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004644 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004645 break;
4646
Jiawei Shao385b3e02018-03-21 09:43:28 +08004647 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004648 if (!context->getExtensions().geometryShader)
4649 {
Jamie Madille0472f32018-11-27 16:32:45 -05004650 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004651 return false;
4652 }
4653 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004654 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004655 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004656 return false;
4657 }
Jamie Madill29639852016-09-02 15:00:09 -04004658
4659 return true;
4660}
4661
Jamie Madill5b772312018-03-08 20:28:32 -05004662bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004663 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004664 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004665 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004666 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004667{
4668 if (size < 0)
4669 {
Jamie Madille0472f32018-11-27 16:32:45 -05004670 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004671 return false;
4672 }
4673
4674 switch (usage)
4675 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004676 case BufferUsage::StreamDraw:
4677 case BufferUsage::StaticDraw:
4678 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004679 break;
4680
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004681 case BufferUsage::StreamRead:
4682 case BufferUsage::StaticRead:
4683 case BufferUsage::DynamicRead:
4684 case BufferUsage::StreamCopy:
4685 case BufferUsage::StaticCopy:
4686 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004687 if (context->getClientMajorVersion() < 3)
4688 {
Jamie Madille0472f32018-11-27 16:32:45 -05004689 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004690 return false;
4691 }
4692 break;
4693
4694 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004695 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004696 return false;
4697 }
4698
Corentin Walleze4477002017-12-01 14:39:58 -05004699 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004700 {
Jamie Madille0472f32018-11-27 16:32:45 -05004701 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004702 return false;
4703 }
4704
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004705 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004706
4707 if (!buffer)
4708 {
Jamie Madille0472f32018-11-27 16:32:45 -05004709 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004710 return false;
4711 }
4712
James Darpiniane8a93c62018-01-04 18:02:24 -08004713 if (context->getExtensions().webglCompatibility &&
4714 buffer->isBoundForTransformFeedbackAndOtherUse())
4715 {
Jamie Madille0472f32018-11-27 16:32:45 -05004716 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004717 return false;
4718 }
4719
Jamie Madill29639852016-09-02 15:00:09 -04004720 return true;
4721}
4722
Jamie Madill5b772312018-03-08 20:28:32 -05004723bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004724 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004725 GLintptr offset,
4726 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004727 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004728{
Brandon Jones6cad5662017-06-14 13:25:13 -07004729 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004730 {
Jamie Madille0472f32018-11-27 16:32:45 -05004731 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004732 return false;
4733 }
4734
4735 if (offset < 0)
4736 {
Jamie Madille0472f32018-11-27 16:32:45 -05004737 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004738 return false;
4739 }
4740
Corentin Walleze4477002017-12-01 14:39:58 -05004741 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004742 {
Jamie Madille0472f32018-11-27 16:32:45 -05004743 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004744 return false;
4745 }
4746
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004747 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004748
4749 if (!buffer)
4750 {
Jamie Madille0472f32018-11-27 16:32:45 -05004751 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004752 return false;
4753 }
4754
4755 if (buffer->isMapped())
4756 {
Jamie Madille0472f32018-11-27 16:32:45 -05004757 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004758 return false;
4759 }
4760
James Darpiniane8a93c62018-01-04 18:02:24 -08004761 if (context->getExtensions().webglCompatibility &&
4762 buffer->isBoundForTransformFeedbackAndOtherUse())
4763 {
Jamie Madille0472f32018-11-27 16:32:45 -05004764 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004765 return false;
4766 }
4767
Jamie Madill29639852016-09-02 15:00:09 -04004768 // Check for possible overflow of size + offset
4769 angle::CheckedNumeric<size_t> checkedSize(size);
4770 checkedSize += offset;
4771 if (!checkedSize.IsValid())
4772 {
Jamie Madille0472f32018-11-27 16:32:45 -05004773 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004774 return false;
4775 }
4776
4777 if (size + offset > buffer->getSize())
4778 {
Jamie Madille0472f32018-11-27 16:32:45 -05004779 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004780 return false;
4781 }
4782
Martin Radev4c4c8e72016-08-04 12:25:34 +03004783 return true;
4784}
4785
Geoff Lang111a99e2017-10-17 10:58:41 -04004786bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04004787{
Geoff Langc339c4e2016-11-29 10:37:36 -05004788 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04004789 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004790 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04004791 return false;
4792 }
4793
Geoff Lang111a99e2017-10-17 10:58:41 -04004794 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04004795 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004796 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04004797 return false;
4798 }
4799
4800 return true;
4801}
4802
Jamie Madill5b772312018-03-08 20:28:32 -05004803bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04004804{
Lingfeng Yang038dd532018-03-29 17:31:52 -07004805 if (context->getClientMajorVersion() < 2)
4806 {
4807 return ValidateMultitextureUnit(context, texture);
4808 }
4809
Jamie Madillef300b12016-10-07 15:12:09 -04004810 if (texture < GL_TEXTURE0 ||
4811 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
4812 {
Jamie Madille0472f32018-11-27 16:32:45 -05004813 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04004814 return false;
4815 }
4816
4817 return true;
4818}
4819
Jamie Madill5b772312018-03-08 20:28:32 -05004820bool ValidateAttachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillef300b12016-10-07 15:12:09 -04004821{
4822 Program *programObject = GetValidProgram(context, program);
4823 if (!programObject)
4824 {
4825 return false;
4826 }
4827
4828 Shader *shaderObject = GetValidShader(context, shader);
4829 if (!shaderObject)
4830 {
4831 return false;
4832 }
4833
Jiawei Shao385b3e02018-03-21 09:43:28 +08004834 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04004835 {
Jamie Madille0472f32018-11-27 16:32:45 -05004836 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08004837 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04004838 }
4839
4840 return true;
4841}
4842
Jamie Madill5b772312018-03-08 20:28:32 -05004843bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004844{
4845 if (index >= MAX_VERTEX_ATTRIBS)
4846 {
Jamie Madille0472f32018-11-27 16:32:45 -05004847 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004848 return false;
4849 }
4850
4851 if (strncmp(name, "gl_", 3) == 0)
4852 {
Jamie Madille0472f32018-11-27 16:32:45 -05004853 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004854 return false;
4855 }
4856
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004857 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04004858 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004859 const size_t length = strlen(name);
4860
4861 if (!IsValidESSLString(name, length))
4862 {
4863 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
4864 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05004865 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004866 return false;
4867 }
4868
4869 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
4870 {
4871 return false;
4872 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04004873 }
4874
Jamie Madill01a80ee2016-11-07 12:06:18 -05004875 return GetValidProgram(context, program) != nullptr;
4876}
4877
Jamie Madill5b772312018-03-08 20:28:32 -05004878bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004879{
Geoff Lange8afa902017-09-27 15:00:43 -04004880 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05004881 {
Jamie Madille0472f32018-11-27 16:32:45 -05004882 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004883 return false;
4884 }
4885
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004886 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004887 !context->isFramebufferGenerated(framebuffer))
4888 {
Jamie Madille0472f32018-11-27 16:32:45 -05004889 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004890 return false;
4891 }
4892
4893 return true;
4894}
4895
Jamie Madill5b772312018-03-08 20:28:32 -05004896bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004897{
4898 if (target != GL_RENDERBUFFER)
4899 {
Jamie Madille0472f32018-11-27 16:32:45 -05004900 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004901 return false;
4902 }
4903
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004904 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004905 !context->isRenderbufferGenerated(renderbuffer))
4906 {
Jamie Madille0472f32018-11-27 16:32:45 -05004907 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004908 return false;
4909 }
4910
4911 return true;
4912}
4913
Jamie Madill5b772312018-03-08 20:28:32 -05004914static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004915{
4916 switch (mode)
4917 {
4918 case GL_FUNC_ADD:
4919 case GL_FUNC_SUBTRACT:
4920 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04004921 return true;
4922
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004923 case GL_MIN:
4924 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04004925 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004926
4927 default:
4928 return false;
4929 }
4930}
4931
Jamie Madill5b772312018-03-08 20:28:32 -05004932bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004933{
4934 return true;
4935}
4936
Jamie Madill5b772312018-03-08 20:28:32 -05004937bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004938{
Geoff Lang50cac572017-09-26 17:37:43 -04004939 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004940 {
Jamie Madille0472f32018-11-27 16:32:45 -05004941 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004942 return false;
4943 }
4944
4945 return true;
4946}
4947
Jamie Madill5b772312018-03-08 20:28:32 -05004948bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004949{
Geoff Lang50cac572017-09-26 17:37:43 -04004950 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004951 {
Jamie Madille0472f32018-11-27 16:32:45 -05004952 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004953 return false;
4954 }
4955
Geoff Lang50cac572017-09-26 17:37:43 -04004956 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004957 {
Jamie Madille0472f32018-11-27 16:32:45 -05004958 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004959 return false;
4960 }
4961
4962 return true;
4963}
4964
Jamie Madill5b772312018-03-08 20:28:32 -05004965bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004966{
4967 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
4968}
4969
Jamie Madill5b772312018-03-08 20:28:32 -05004970bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004971 GLenum srcRGB,
4972 GLenum dstRGB,
4973 GLenum srcAlpha,
4974 GLenum dstAlpha)
4975{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004976 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004977 {
Jamie Madille0472f32018-11-27 16:32:45 -05004978 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004979 return false;
4980 }
4981
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004982 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004983 {
Jamie Madille0472f32018-11-27 16:32:45 -05004984 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004985 return false;
4986 }
4987
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004988 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004989 {
Jamie Madille0472f32018-11-27 16:32:45 -05004990 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004991 return false;
4992 }
4993
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004994 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004995 {
Jamie Madille0472f32018-11-27 16:32:45 -05004996 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004997 return false;
4998 }
4999
Frank Henigman146e8a12017-03-02 23:22:37 -05005000 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
5001 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005002 {
5003 bool constantColorUsed =
5004 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
5005 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
5006
5007 bool constantAlphaUsed =
5008 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
5009 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
5010
5011 if (constantColorUsed && constantAlphaUsed)
5012 {
Frank Henigman146e8a12017-03-02 23:22:37 -05005013 if (context->getExtensions().webglCompatibility)
5014 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005015 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
5016 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05005017 }
Jamie Madillc3e37312018-11-30 15:25:39 -05005018
5019 WARN() << kConstantColorAlphaLimitation;
5020 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005021 return false;
5022 }
5023 }
5024
5025 return true;
5026}
5027
Geoff Langc339c4e2016-11-29 10:37:36 -05005028bool ValidateGetString(Context *context, GLenum name)
5029{
5030 switch (name)
5031 {
5032 case GL_VENDOR:
5033 case GL_RENDERER:
5034 case GL_VERSION:
5035 case GL_SHADING_LANGUAGE_VERSION:
5036 case GL_EXTENSIONS:
5037 break;
5038
5039 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
5040 if (!context->getExtensions().requestExtension)
5041 {
Jamie Madille0472f32018-11-27 16:32:45 -05005042 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005043 return false;
5044 }
5045 break;
5046
5047 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005048 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005049 return false;
5050 }
5051
5052 return true;
5053}
5054
Jamie Madill5b772312018-03-08 20:28:32 -05005055bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05005056{
5057 if (width <= 0.0f || isNaN(width))
5058 {
Jamie Madille0472f32018-11-27 16:32:45 -05005059 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05005060 return false;
5061 }
5062
5063 return true;
5064}
5065
Jamie Madill5b772312018-03-08 20:28:32 -05005066bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05005067{
5068 if (context->getExtensions().webglCompatibility && zNear > zFar)
5069 {
Jamie Madille0472f32018-11-27 16:32:45 -05005070 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05005071 return false;
5072 }
5073
5074 return true;
5075}
5076
Jamie Madill5b772312018-03-08 20:28:32 -05005077bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005078 GLenum target,
5079 GLenum internalformat,
5080 GLsizei width,
5081 GLsizei height)
5082{
5083 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
5084 height);
5085}
5086
Jamie Madill5b772312018-03-08 20:28:32 -05005087bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005088 GLenum target,
5089 GLsizei samples,
5090 GLenum internalformat,
5091 GLsizei width,
5092 GLsizei height)
5093{
5094 if (!context->getExtensions().framebufferMultisample)
5095 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005096 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05005097 return false;
5098 }
5099
5100 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05005101 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05005102 // generated.
5103 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
5104 {
Jamie Madille0472f32018-11-27 16:32:45 -05005105 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005106 return false;
5107 }
5108
5109 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
5110 // the specified storage. This is different than ES 3.0 in which a sample number higher
5111 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
5112 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
5113 if (context->getClientMajorVersion() >= 3)
5114 {
5115 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
5116 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
5117 {
Jamie Madille0472f32018-11-27 16:32:45 -05005118 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005119 return false;
5120 }
5121 }
5122
5123 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
5124 width, height);
5125}
5126
Jamie Madill5b772312018-03-08 20:28:32 -05005127bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005128{
Geoff Lange8afa902017-09-27 15:00:43 -04005129 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005130 {
Jamie Madille0472f32018-11-27 16:32:45 -05005131 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005132 return false;
5133 }
5134
5135 return true;
5136}
5137
Jamie Madill5b772312018-03-08 20:28:32 -05005138bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005139{
5140 return true;
5141}
5142
Jamie Madill5b772312018-03-08 20:28:32 -05005143bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005144{
5145 return true;
5146}
5147
Jamie Madill5b772312018-03-08 20:28:32 -05005148bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005149{
5150 return true;
5151}
5152
Jamie Madill5b772312018-03-08 20:28:32 -05005153bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005154 GLboolean red,
5155 GLboolean green,
5156 GLboolean blue,
5157 GLboolean alpha)
5158{
5159 return true;
5160}
5161
Jamie Madill5b772312018-03-08 20:28:32 -05005162bool ValidateCompileShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005163{
5164 return true;
5165}
5166
Jamie Madill5b772312018-03-08 20:28:32 -05005167bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005168{
5169 return true;
5170}
5171
Jamie Madill5b772312018-03-08 20:28:32 -05005172bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005173{
5174 switch (mode)
5175 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005176 case CullFaceMode::Front:
5177 case CullFaceMode::Back:
5178 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005179 break;
5180
5181 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005182 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005183 return false;
5184 }
5185
5186 return true;
5187}
5188
Jamie Madill5b772312018-03-08 20:28:32 -05005189bool ValidateDeleteProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005190{
5191 if (program == 0)
5192 {
5193 return false;
5194 }
5195
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005196 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005197 {
5198 if (context->getShader(program))
5199 {
Jamie Madille0472f32018-11-27 16:32:45 -05005200 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005201 return false;
5202 }
5203 else
5204 {
Jamie Madille0472f32018-11-27 16:32:45 -05005205 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005206 return false;
5207 }
5208 }
5209
5210 return true;
5211}
5212
Jamie Madill5b772312018-03-08 20:28:32 -05005213bool ValidateDeleteShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005214{
5215 if (shader == 0)
5216 {
5217 return false;
5218 }
5219
5220 if (!context->getShader(shader))
5221 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005222 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005223 {
Jamie Madille0472f32018-11-27 16:32:45 -05005224 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005225 return false;
5226 }
5227 else
5228 {
Jamie Madille0472f32018-11-27 16:32:45 -05005229 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005230 return false;
5231 }
5232 }
5233
5234 return true;
5235}
5236
Jamie Madill5b772312018-03-08 20:28:32 -05005237bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005238{
5239 switch (func)
5240 {
5241 case GL_NEVER:
5242 case GL_ALWAYS:
5243 case GL_LESS:
5244 case GL_LEQUAL:
5245 case GL_EQUAL:
5246 case GL_GREATER:
5247 case GL_GEQUAL:
5248 case GL_NOTEQUAL:
5249 break;
5250
5251 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005252 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005253 return false;
5254 }
5255
5256 return true;
5257}
5258
Jamie Madill5b772312018-03-08 20:28:32 -05005259bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005260{
5261 return true;
5262}
5263
Jamie Madill5b772312018-03-08 20:28:32 -05005264bool ValidateDetachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005265{
5266 Program *programObject = GetValidProgram(context, program);
5267 if (!programObject)
5268 {
5269 return false;
5270 }
5271
5272 Shader *shaderObject = GetValidShader(context, shader);
5273 if (!shaderObject)
5274 {
5275 return false;
5276 }
5277
Jiawei Shao385b3e02018-03-21 09:43:28 +08005278 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005279 if (attachedShader != shaderObject)
5280 {
Jamie Madille0472f32018-11-27 16:32:45 -05005281 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005282 return false;
5283 }
5284
5285 return true;
5286}
5287
Jamie Madill5b772312018-03-08 20:28:32 -05005288bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005289{
5290 if (index >= MAX_VERTEX_ATTRIBS)
5291 {
Jamie Madille0472f32018-11-27 16:32:45 -05005292 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005293 return false;
5294 }
5295
5296 return true;
5297}
5298
Jamie Madill5b772312018-03-08 20:28:32 -05005299bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005300{
5301 if (index >= MAX_VERTEX_ATTRIBS)
5302 {
Jamie Madille0472f32018-11-27 16:32:45 -05005303 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005304 return false;
5305 }
5306
5307 return true;
5308}
5309
Jamie Madill5b772312018-03-08 20:28:32 -05005310bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005311{
5312 return true;
5313}
5314
Jamie Madill5b772312018-03-08 20:28:32 -05005315bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005316{
5317 return true;
5318}
5319
Jamie Madill5b772312018-03-08 20:28:32 -05005320bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005321{
5322 switch (mode)
5323 {
5324 case GL_CW:
5325 case GL_CCW:
5326 break;
5327 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005328 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005329 return false;
5330 }
5331
5332 return true;
5333}
5334
Jamie Madill5b772312018-03-08 20:28:32 -05005335bool ValidateGetActiveAttrib(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005336 GLuint program,
5337 GLuint index,
5338 GLsizei bufsize,
5339 GLsizei *length,
5340 GLint *size,
5341 GLenum *type,
5342 GLchar *name)
5343{
5344 if (bufsize < 0)
5345 {
Jamie Madille0472f32018-11-27 16:32:45 -05005346 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005347 return false;
5348 }
5349
5350 Program *programObject = GetValidProgram(context, program);
5351
5352 if (!programObject)
5353 {
5354 return false;
5355 }
5356
5357 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5358 {
Jamie Madille0472f32018-11-27 16:32:45 -05005359 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005360 return false;
5361 }
5362
5363 return true;
5364}
5365
Jamie Madill5b772312018-03-08 20:28:32 -05005366bool ValidateGetActiveUniform(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005367 GLuint program,
5368 GLuint index,
5369 GLsizei bufsize,
5370 GLsizei *length,
5371 GLint *size,
5372 GLenum *type,
5373 GLchar *name)
5374{
5375 if (bufsize < 0)
5376 {
Jamie Madille0472f32018-11-27 16:32:45 -05005377 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005378 return false;
5379 }
5380
5381 Program *programObject = GetValidProgram(context, program);
5382
5383 if (!programObject)
5384 {
5385 return false;
5386 }
5387
5388 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5389 {
Jamie Madille0472f32018-11-27 16:32:45 -05005390 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005391 return false;
5392 }
5393
5394 return true;
5395}
5396
Jamie Madill5b772312018-03-08 20:28:32 -05005397bool ValidateGetAttachedShaders(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005398 GLuint program,
5399 GLsizei maxcount,
5400 GLsizei *count,
5401 GLuint *shaders)
5402{
5403 if (maxcount < 0)
5404 {
Jamie Madille0472f32018-11-27 16:32:45 -05005405 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005406 return false;
5407 }
5408
5409 Program *programObject = GetValidProgram(context, program);
5410
5411 if (!programObject)
5412 {
5413 return false;
5414 }
5415
5416 return true;
5417}
5418
Jamie Madill5b772312018-03-08 20:28:32 -05005419bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005420{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005421 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5422 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005423 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005424 {
Jamie Madille0472f32018-11-27 16:32:45 -05005425 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005426 return false;
5427 }
5428
Jamie Madillc1d770e2017-04-13 17:31:24 -04005429 Program *programObject = GetValidProgram(context, program);
5430
5431 if (!programObject)
5432 {
Jamie Madille0472f32018-11-27 16:32:45 -05005433 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005434 return false;
5435 }
5436
5437 if (!programObject->isLinked())
5438 {
Jamie Madille0472f32018-11-27 16:32:45 -05005439 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005440 return false;
5441 }
5442
5443 return true;
5444}
5445
Jamie Madill5b772312018-03-08 20:28:32 -05005446bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005447{
5448 GLenum nativeType;
5449 unsigned int numParams = 0;
5450 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5451}
5452
Jamie Madill5b772312018-03-08 20:28:32 -05005453bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005454{
5455 return true;
5456}
5457
Jamie Madill5b772312018-03-08 20:28:32 -05005458bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459{
5460 GLenum nativeType;
5461 unsigned int numParams = 0;
5462 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5463}
5464
Jamie Madill5b772312018-03-08 20:28:32 -05005465bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005466{
5467 GLenum nativeType;
5468 unsigned int numParams = 0;
5469 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5470}
5471
Jamie Madill5b772312018-03-08 20:28:32 -05005472bool ValidateGetProgramInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005473 GLuint program,
5474 GLsizei bufsize,
5475 GLsizei *length,
5476 GLchar *infolog)
5477{
5478 if (bufsize < 0)
5479 {
Jamie Madille0472f32018-11-27 16:32:45 -05005480 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005481 return false;
5482 }
5483
5484 Program *programObject = GetValidProgram(context, program);
5485 if (!programObject)
5486 {
5487 return false;
5488 }
5489
5490 return true;
5491}
5492
Jamie Madill5b772312018-03-08 20:28:32 -05005493bool ValidateGetShaderInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005494 GLuint shader,
5495 GLsizei bufsize,
5496 GLsizei *length,
5497 GLchar *infolog)
5498{
5499 if (bufsize < 0)
5500 {
Jamie Madille0472f32018-11-27 16:32:45 -05005501 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005502 return false;
5503 }
5504
5505 Shader *shaderObject = GetValidShader(context, shader);
5506 if (!shaderObject)
5507 {
5508 return false;
5509 }
5510
5511 return true;
5512}
5513
Jamie Madill5b772312018-03-08 20:28:32 -05005514bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005515 GLenum shadertype,
5516 GLenum precisiontype,
5517 GLint *range,
5518 GLint *precision)
5519{
5520 switch (shadertype)
5521 {
5522 case GL_VERTEX_SHADER:
5523 case GL_FRAGMENT_SHADER:
5524 break;
5525 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005526 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005527 return false;
5528 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005529 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005530 return false;
5531 }
5532
5533 switch (precisiontype)
5534 {
5535 case GL_LOW_FLOAT:
5536 case GL_MEDIUM_FLOAT:
5537 case GL_HIGH_FLOAT:
5538 case GL_LOW_INT:
5539 case GL_MEDIUM_INT:
5540 case GL_HIGH_INT:
5541 break;
5542
5543 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005544 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005545 return false;
5546 }
5547
5548 return true;
5549}
5550
Jamie Madill5b772312018-03-08 20:28:32 -05005551bool ValidateGetShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005552 GLuint shader,
5553 GLsizei bufsize,
5554 GLsizei *length,
5555 GLchar *source)
5556{
5557 if (bufsize < 0)
5558 {
Jamie Madille0472f32018-11-27 16:32:45 -05005559 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005560 return false;
5561 }
5562
5563 Shader *shaderObject = GetValidShader(context, shader);
5564 if (!shaderObject)
5565 {
5566 return false;
5567 }
5568
5569 return true;
5570}
5571
Jamie Madill5b772312018-03-08 20:28:32 -05005572bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005573{
5574 if (strstr(name, "gl_") == name)
5575 {
5576 return false;
5577 }
5578
Geoff Langfc32e8b2017-05-31 14:16:59 -04005579 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5580 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005581 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005582 {
Jamie Madille0472f32018-11-27 16:32:45 -05005583 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005584 return false;
5585 }
5586
Jamie Madillc1d770e2017-04-13 17:31:24 -04005587 Program *programObject = GetValidProgram(context, program);
5588
5589 if (!programObject)
5590 {
5591 return false;
5592 }
5593
5594 if (!programObject->isLinked())
5595 {
Jamie Madille0472f32018-11-27 16:32:45 -05005596 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005597 return false;
5598 }
5599
5600 return true;
5601}
5602
Jamie Madill5b772312018-03-08 20:28:32 -05005603bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005604{
5605 switch (mode)
5606 {
5607 case GL_FASTEST:
5608 case GL_NICEST:
5609 case GL_DONT_CARE:
5610 break;
5611
5612 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005613 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005614 return false;
5615 }
5616
5617 switch (target)
5618 {
5619 case GL_GENERATE_MIPMAP_HINT:
5620 break;
5621
Geoff Lange7bd2182017-06-16 16:13:13 -04005622 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5623 if (context->getClientVersion() < ES_3_0 &&
5624 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005625 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005626 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005627 return false;
5628 }
5629 break;
5630
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005631 case GL_PERSPECTIVE_CORRECTION_HINT:
5632 case GL_POINT_SMOOTH_HINT:
5633 case GL_LINE_SMOOTH_HINT:
5634 case GL_FOG_HINT:
5635 if (context->getClientMajorVersion() >= 2)
5636 {
Jamie Madille0472f32018-11-27 16:32:45 -05005637 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005638 return false;
5639 }
5640 break;
5641
Jamie Madillc1d770e2017-04-13 17:31:24 -04005642 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005643 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005644 return false;
5645 }
5646
5647 return true;
5648}
5649
Jamie Madill5b772312018-03-08 20:28:32 -05005650bool ValidateIsBuffer(Context *context, GLuint buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005651{
5652 return true;
5653}
5654
Jamie Madill5b772312018-03-08 20:28:32 -05005655bool ValidateIsFramebuffer(Context *context, GLuint framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005656{
5657 return true;
5658}
5659
Jamie Madill5b772312018-03-08 20:28:32 -05005660bool ValidateIsProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005661{
5662 return true;
5663}
5664
Jamie Madill5b772312018-03-08 20:28:32 -05005665bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005666{
5667 return true;
5668}
5669
Jamie Madill5b772312018-03-08 20:28:32 -05005670bool ValidateIsShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005671{
5672 return true;
5673}
5674
Jamie Madill5b772312018-03-08 20:28:32 -05005675bool ValidateIsTexture(Context *context, GLuint texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005676{
5677 return true;
5678}
5679
Jamie Madill5b772312018-03-08 20:28:32 -05005680bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005681{
5682 if (context->getClientMajorVersion() < 3)
5683 {
5684 switch (pname)
5685 {
5686 case GL_UNPACK_IMAGE_HEIGHT:
5687 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005688 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005689 return false;
5690
5691 case GL_UNPACK_ROW_LENGTH:
5692 case GL_UNPACK_SKIP_ROWS:
5693 case GL_UNPACK_SKIP_PIXELS:
5694 if (!context->getExtensions().unpackSubimage)
5695 {
Jamie Madille0472f32018-11-27 16:32:45 -05005696 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005697 return false;
5698 }
5699 break;
5700
5701 case GL_PACK_ROW_LENGTH:
5702 case GL_PACK_SKIP_ROWS:
5703 case GL_PACK_SKIP_PIXELS:
5704 if (!context->getExtensions().packSubimage)
5705 {
Jamie Madille0472f32018-11-27 16:32:45 -05005706 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005707 return false;
5708 }
5709 break;
5710 }
5711 }
5712
5713 if (param < 0)
5714 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005715 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005716 return false;
5717 }
5718
5719 switch (pname)
5720 {
5721 case GL_UNPACK_ALIGNMENT:
5722 if (param != 1 && param != 2 && param != 4 && param != 8)
5723 {
Jamie Madille0472f32018-11-27 16:32:45 -05005724 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005725 return false;
5726 }
5727 break;
5728
5729 case GL_PACK_ALIGNMENT:
5730 if (param != 1 && param != 2 && param != 4 && param != 8)
5731 {
Jamie Madille0472f32018-11-27 16:32:45 -05005732 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005733 return false;
5734 }
5735 break;
5736
5737 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005738 if (!context->getExtensions().packReverseRowOrder)
5739 {
Jamie Madille0472f32018-11-27 16:32:45 -05005740 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005741 }
5742 break;
5743
Jamie Madillc1d770e2017-04-13 17:31:24 -04005744 case GL_UNPACK_ROW_LENGTH:
5745 case GL_UNPACK_IMAGE_HEIGHT:
5746 case GL_UNPACK_SKIP_IMAGES:
5747 case GL_UNPACK_SKIP_ROWS:
5748 case GL_UNPACK_SKIP_PIXELS:
5749 case GL_PACK_ROW_LENGTH:
5750 case GL_PACK_SKIP_ROWS:
5751 case GL_PACK_SKIP_PIXELS:
5752 break;
5753
5754 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005755 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005756 return false;
5757 }
5758
5759 return true;
5760}
5761
Jamie Madill5b772312018-03-08 20:28:32 -05005762bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005763{
5764 return true;
5765}
5766
Jamie Madill5b772312018-03-08 20:28:32 -05005767bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005768{
5769 return true;
5770}
5771
Jamie Madill5b772312018-03-08 20:28:32 -05005772bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005773{
5774 return true;
5775}
5776
Jamie Madill5b772312018-03-08 20:28:32 -05005777bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005778{
5779 if (width < 0 || height < 0)
5780 {
Jamie Madille0472f32018-11-27 16:32:45 -05005781 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005782 return false;
5783 }
5784
5785 return true;
5786}
5787
Jamie Madill5b772312018-03-08 20:28:32 -05005788bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005789 GLsizei n,
5790 const GLuint *shaders,
5791 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005792 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005793 GLsizei length)
5794{
5795 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
5796 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
5797 shaderBinaryFormats.end())
5798 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005799 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005800 return false;
5801 }
5802
5803 return true;
5804}
5805
Jamie Madill5b772312018-03-08 20:28:32 -05005806bool ValidateShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005807 GLuint shader,
5808 GLsizei count,
5809 const GLchar *const *string,
5810 const GLint *length)
5811{
5812 if (count < 0)
5813 {
Jamie Madille0472f32018-11-27 16:32:45 -05005814 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005815 return false;
5816 }
5817
Geoff Langfc32e8b2017-05-31 14:16:59 -04005818 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5819 // shader-related entry points
5820 if (context->getExtensions().webglCompatibility)
5821 {
5822 for (GLsizei i = 0; i < count; i++)
5823 {
Geoff Langcab92ee2017-07-19 17:32:07 -04005824 size_t len =
5825 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04005826
5827 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04005828 if (!IsValidESSLShaderSourceString(string[i], len,
5829 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005830 {
Jamie Madille0472f32018-11-27 16:32:45 -05005831 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005832 return false;
5833 }
5834 }
5835 }
5836
Jamie Madillc1d770e2017-04-13 17:31:24 -04005837 Shader *shaderObject = GetValidShader(context, shader);
5838 if (!shaderObject)
5839 {
5840 return false;
5841 }
5842
5843 return true;
5844}
5845
Jamie Madill5b772312018-03-08 20:28:32 -05005846bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005847{
5848 if (!IsValidStencilFunc(func))
5849 {
Jamie Madille0472f32018-11-27 16:32:45 -05005850 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005851 return false;
5852 }
5853
5854 return true;
5855}
5856
Jamie Madill5b772312018-03-08 20:28:32 -05005857bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005858{
5859 if (!IsValidStencilFace(face))
5860 {
Jamie Madille0472f32018-11-27 16:32:45 -05005861 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005862 return false;
5863 }
5864
5865 if (!IsValidStencilFunc(func))
5866 {
Jamie Madille0472f32018-11-27 16:32:45 -05005867 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005868 return false;
5869 }
5870
5871 return true;
5872}
5873
Jamie Madill5b772312018-03-08 20:28:32 -05005874bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005875{
5876 return true;
5877}
5878
Jamie Madill5b772312018-03-08 20:28:32 -05005879bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005880{
5881 if (!IsValidStencilFace(face))
5882 {
Jamie Madille0472f32018-11-27 16:32:45 -05005883 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005884 return false;
5885 }
5886
5887 return true;
5888}
5889
Jamie Madill5b772312018-03-08 20:28:32 -05005890bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005891{
5892 if (!IsValidStencilOp(fail))
5893 {
Jamie Madille0472f32018-11-27 16:32:45 -05005894 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005895 return false;
5896 }
5897
5898 if (!IsValidStencilOp(zfail))
5899 {
Jamie Madille0472f32018-11-27 16:32:45 -05005900 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005901 return false;
5902 }
5903
5904 if (!IsValidStencilOp(zpass))
5905 {
Jamie Madille0472f32018-11-27 16:32:45 -05005906 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005907 return false;
5908 }
5909
5910 return true;
5911}
5912
Jamie Madill5b772312018-03-08 20:28:32 -05005913bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005914 GLenum face,
5915 GLenum fail,
5916 GLenum zfail,
5917 GLenum zpass)
5918{
5919 if (!IsValidStencilFace(face))
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 ValidateStencilOp(context, fail, zfail, zpass);
5926}
5927
Jamie Madill5b772312018-03-08 20:28:32 -05005928bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005929{
5930 return ValidateUniform(context, GL_FLOAT, location, 1);
5931}
5932
Jamie Madill5b772312018-03-08 20:28:32 -05005933bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005934{
5935 return ValidateUniform(context, GL_FLOAT, location, count);
5936}
5937
Jamie Madill5b772312018-03-08 20:28:32 -05005938bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04005939{
5940 return ValidateUniform1iv(context, location, 1, &x);
5941}
5942
Jamie Madill5b772312018-03-08 20:28:32 -05005943bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005944{
5945 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
5946}
5947
Jamie Madill5b772312018-03-08 20:28:32 -05005948bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005949{
5950 return ValidateUniform(context, GL_INT_VEC2, location, 1);
5951}
5952
Jamie Madill5b772312018-03-08 20:28:32 -05005953bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005954{
5955 return ValidateUniform(context, GL_INT_VEC2, location, count);
5956}
5957
Jamie Madill5b772312018-03-08 20:28:32 -05005958bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005959{
5960 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
5961}
5962
Jamie Madill5b772312018-03-08 20:28:32 -05005963bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005964{
5965 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
5966}
5967
Jamie Madill5b772312018-03-08 20:28:32 -05005968bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005969{
5970 return ValidateUniform(context, GL_INT_VEC3, location, 1);
5971}
5972
Jamie Madill5b772312018-03-08 20:28:32 -05005973bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005974{
5975 return ValidateUniform(context, GL_INT_VEC3, location, count);
5976}
5977
Jamie Madill5b772312018-03-08 20:28:32 -05005978bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005979{
5980 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
5981}
5982
Jamie Madill5b772312018-03-08 20:28:32 -05005983bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005984{
5985 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
5986}
5987
Jamie Madill5b772312018-03-08 20:28:32 -05005988bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005989{
5990 return ValidateUniform(context, GL_INT_VEC4, location, 1);
5991}
5992
Jamie Madill5b772312018-03-08 20:28:32 -05005993bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005994{
5995 return ValidateUniform(context, GL_INT_VEC4, location, count);
5996}
5997
Jamie Madill5b772312018-03-08 20:28:32 -05005998bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005999 GLint location,
6000 GLsizei count,
6001 GLboolean transpose,
6002 const GLfloat *value)
6003{
6004 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
6005}
6006
Jamie Madill5b772312018-03-08 20:28:32 -05006007bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006008 GLint location,
6009 GLsizei count,
6010 GLboolean transpose,
6011 const GLfloat *value)
6012{
6013 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
6014}
6015
Jamie Madill5b772312018-03-08 20:28:32 -05006016bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006017 GLint location,
6018 GLsizei count,
6019 GLboolean transpose,
6020 const GLfloat *value)
6021{
6022 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
6023}
6024
Jamie Madill5b772312018-03-08 20:28:32 -05006025bool ValidateValidateProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006026{
6027 Program *programObject = GetValidProgram(context, program);
6028
6029 if (!programObject)
6030 {
6031 return false;
6032 }
6033
6034 return true;
6035}
6036
Jamie Madill5b772312018-03-08 20:28:32 -05006037bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006038{
6039 return ValidateVertexAttribIndex(context, index);
6040}
6041
Jamie Madill5b772312018-03-08 20:28:32 -05006042bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006043{
6044 return ValidateVertexAttribIndex(context, index);
6045}
6046
Jamie Madill5b772312018-03-08 20:28:32 -05006047bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006048{
6049 return ValidateVertexAttribIndex(context, index);
6050}
6051
Jamie Madill5b772312018-03-08 20:28:32 -05006052bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006053{
6054 return ValidateVertexAttribIndex(context, index);
6055}
6056
Jamie Madill5b772312018-03-08 20:28:32 -05006057bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006058{
6059 return ValidateVertexAttribIndex(context, index);
6060}
6061
Jamie Madill5b772312018-03-08 20:28:32 -05006062bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006063{
6064 return ValidateVertexAttribIndex(context, index);
6065}
6066
Jamie Madill5b772312018-03-08 20:28:32 -05006067bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006068 GLuint index,
6069 GLfloat x,
6070 GLfloat y,
6071 GLfloat z,
6072 GLfloat w)
6073{
6074 return ValidateVertexAttribIndex(context, index);
6075}
6076
Jamie Madill5b772312018-03-08 20:28:32 -05006077bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006078{
6079 return ValidateVertexAttribIndex(context, index);
6080}
6081
Jamie Madill5b772312018-03-08 20:28:32 -05006082bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006083{
6084 if (width < 0 || height < 0)
6085 {
Jamie Madille0472f32018-11-27 16:32:45 -05006086 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006087 return false;
6088 }
6089
6090 return true;
6091}
6092
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08006093bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006094 GLenum target,
6095 GLenum attachment,
6096 GLenum pname,
6097 GLint *params)
6098{
6099 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
6100 nullptr);
6101}
6102
Jamie Madill5b772312018-03-08 20:28:32 -05006103bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006104{
6105 return ValidateGetProgramivBase(context, program, pname, nullptr);
6106}
6107
Jamie Madill5b772312018-03-08 20:28:32 -05006108bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006109 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006110 GLint level,
6111 GLenum internalformat,
6112 GLint x,
6113 GLint y,
6114 GLsizei width,
6115 GLsizei height,
6116 GLint border)
6117{
6118 if (context->getClientMajorVersion() < 3)
6119 {
6120 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
6121 0, x, y, width, height, border);
6122 }
6123
6124 ASSERT(context->getClientMajorVersion() == 3);
6125 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
6126 0, x, y, width, height, border);
6127}
6128
6129bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006130 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006131 GLint level,
6132 GLint xoffset,
6133 GLint yoffset,
6134 GLint x,
6135 GLint y,
6136 GLsizei width,
6137 GLsizei height)
6138{
6139 if (context->getClientMajorVersion() < 3)
6140 {
6141 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
6142 yoffset, x, y, width, height, 0);
6143 }
6144
6145 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
6146 yoffset, 0, x, y, width, height, 0);
6147}
6148
6149bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *)
6150{
6151 return ValidateGenOrDelete(context, n);
6152}
6153
6154bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *)
6155{
6156 return ValidateGenOrDelete(context, n);
6157}
6158
6159bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *)
6160{
6161 return ValidateGenOrDelete(context, n);
6162}
6163
6164bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *)
6165{
6166 return ValidateGenOrDelete(context, n);
6167}
6168
6169bool ValidateDisable(Context *context, GLenum cap)
6170{
6171 if (!ValidCap(context, cap, false))
6172 {
Jamie Madille0472f32018-11-27 16:32:45 -05006173 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006174 return false;
6175 }
6176
6177 return true;
6178}
6179
6180bool ValidateEnable(Context *context, GLenum cap)
6181{
6182 if (!ValidCap(context, cap, false))
6183 {
Jamie Madille0472f32018-11-27 16:32:45 -05006184 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006185 return false;
6186 }
6187
6188 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6189 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6190 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006191 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006192
6193 // We also output an error message to the debugger window if tracing is active, so that
6194 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006195 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006196 return false;
6197 }
6198
6199 return true;
6200}
6201
6202bool ValidateFramebufferRenderbuffer(Context *context,
6203 GLenum target,
6204 GLenum attachment,
6205 GLenum renderbuffertarget,
6206 GLuint renderbuffer)
6207{
Geoff Lange8afa902017-09-27 15:00:43 -04006208 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006209 {
Jamie Madille0472f32018-11-27 16:32:45 -05006210 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006211 return false;
6212 }
6213
6214 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)
6215 {
Jamie Madille0472f32018-11-27 16:32:45 -05006216 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006217 return false;
6218 }
6219
6220 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6221 renderbuffertarget, renderbuffer);
6222}
6223
6224bool ValidateFramebufferTexture2D(Context *context,
6225 GLenum target,
6226 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006227 TextureTarget textarget,
Jamie Madillbe849e42017-05-02 15:49:00 -04006228 GLuint texture,
6229 GLint level)
6230{
6231 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6232 // extension
6233 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6234 level != 0)
6235 {
Jamie Madille0472f32018-11-27 16:32:45 -05006236 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006237 return false;
6238 }
6239
6240 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6241 {
6242 return false;
6243 }
6244
6245 if (texture != 0)
6246 {
6247 gl::Texture *tex = context->getTexture(texture);
6248 ASSERT(tex);
6249
6250 const gl::Caps &caps = context->getCaps();
6251
6252 switch (textarget)
6253 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006254 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006255 {
6256 if (level > gl::log2(caps.max2DTextureSize))
6257 {
Jamie Madille0472f32018-11-27 16:32:45 -05006258 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006259 return false;
6260 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006261 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006262 {
Jamie Madille0472f32018-11-27 16:32:45 -05006263 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006264 return false;
6265 }
6266 }
6267 break;
6268
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006269 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006270 {
6271 if (level != 0)
6272 {
Jamie Madille0472f32018-11-27 16:32:45 -05006273 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006274 return false;
6275 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006276 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006277 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006278 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006279 return false;
6280 }
6281 }
6282 break;
6283
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006284 case TextureTarget::CubeMapNegativeX:
6285 case TextureTarget::CubeMapNegativeY:
6286 case TextureTarget::CubeMapNegativeZ:
6287 case TextureTarget::CubeMapPositiveX:
6288 case TextureTarget::CubeMapPositiveY:
6289 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006290 {
6291 if (level > gl::log2(caps.maxCubeMapTextureSize))
6292 {
Jamie Madille0472f32018-11-27 16:32:45 -05006293 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006294 return false;
6295 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006296 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006297 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006298 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006299 return false;
6300 }
6301 }
6302 break;
6303
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006304 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006305 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006306 if (context->getClientVersion() < ES_3_1 &&
6307 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006308 {
Jamie Madill610640f2018-11-21 17:28:41 -05006309 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006310 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006311 return false;
6312 }
6313
6314 if (level != 0)
6315 {
Jamie Madille0472f32018-11-27 16:32:45 -05006316 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006317 return false;
6318 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006319 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006320 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006321 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006322 return false;
6323 }
6324 }
6325 break;
6326
6327 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006328 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006329 return false;
6330 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006331 }
6332
6333 return true;
6334}
6335
6336bool ValidateGenBuffers(Context *context, GLint n, GLuint *)
6337{
6338 return ValidateGenOrDelete(context, n);
6339}
6340
6341bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *)
6342{
6343 return ValidateGenOrDelete(context, n);
6344}
6345
6346bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *)
6347{
6348 return ValidateGenOrDelete(context, n);
6349}
6350
6351bool ValidateGenTextures(Context *context, GLint n, GLuint *)
6352{
6353 return ValidateGenOrDelete(context, n);
6354}
6355
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006356bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006357{
6358 if (!ValidTextureTarget(context, target))
6359 {
Jamie Madille0472f32018-11-27 16:32:45 -05006360 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006361 return false;
6362 }
6363
Jamie Madillcfc73cc2019-04-08 16:26:51 -04006364 Texture *texture = context->getTextureByType(target);
Jamie Madillbe849e42017-05-02 15:49:00 -04006365
6366 if (texture == nullptr)
6367 {
Jamie Madille0472f32018-11-27 16:32:45 -05006368 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006369 return false;
6370 }
6371
6372 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6373
6374 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6375 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6376 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6377 {
Jamie Madille0472f32018-11-27 16:32:45 -05006378 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006379 return false;
6380 }
6381
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006382 TextureTarget baseTarget = (target == TextureType::CubeMap)
6383 ? TextureTarget::CubeMapPositiveX
6384 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006385 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6386 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6387 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006388 {
Jamie Madille0472f32018-11-27 16:32:45 -05006389 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006390 return false;
6391 }
6392
Geoff Lang536eca12017-09-13 11:23:35 -04006393 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6394 bool formatUnsized = !format.sized;
6395 bool formatColorRenderableAndFilterable =
6396 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006397 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006398 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006399 {
Jamie Madille0472f32018-11-27 16:32:45 -05006400 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006401 return false;
6402 }
6403
Geoff Lang536eca12017-09-13 11:23:35 -04006404 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6405 // generation
6406 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6407 {
Jamie Madille0472f32018-11-27 16:32:45 -05006408 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006409 return false;
6410 }
6411
Jiange2c00842018-07-13 16:50:49 +08006412 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6413 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6414 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006415 {
Jamie Madille0472f32018-11-27 16:32:45 -05006416 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006417 return false;
6418 }
6419
6420 // Non-power of 2 ES2 check
6421 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6422 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6423 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6424 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006425 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6426 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006427 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006428 return false;
6429 }
6430
6431 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006432 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006433 {
Jamie Madille0472f32018-11-27 16:32:45 -05006434 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006435 return false;
6436 }
6437
James Darpinian83b2f0e2018-11-27 15:56:01 -08006438 if (context->getExtensions().webglCompatibility &&
6439 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6440 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6441 {
6442 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6443 return false;
6444 }
6445
Jamie Madillbe849e42017-05-02 15:49:00 -04006446 return true;
6447}
6448
Jamie Madill5b772312018-03-08 20:28:32 -05006449bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006450 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006451 GLenum pname,
6452 GLint *params)
6453{
6454 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6455}
6456
6457bool ValidateGetRenderbufferParameteriv(Context *context,
6458 GLenum target,
6459 GLenum pname,
6460 GLint *params)
6461{
6462 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6463}
6464
6465bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params)
6466{
6467 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6468}
6469
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006470bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006471{
6472 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6473}
6474
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006475bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006476{
6477 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6478}
6479
Till Rathmannb8543632018-10-02 19:46:14 +02006480bool ValidateGetTexParameterIivOES(Context *context,
6481 TextureType target,
6482 GLenum pname,
6483 GLint *params)
6484{
6485 if (context->getClientMajorVersion() < 3)
6486 {
Jamie Madille0472f32018-11-27 16:32:45 -05006487 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006488 return false;
6489 }
6490 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6491}
6492
6493bool ValidateGetTexParameterIuivOES(Context *context,
6494 TextureType target,
6495 GLenum pname,
6496 GLuint *params)
6497{
6498 if (context->getClientMajorVersion() < 3)
6499 {
Jamie Madille0472f32018-11-27 16:32:45 -05006500 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006501 return false;
6502 }
6503 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6504}
6505
Jamie Madillbe849e42017-05-02 15:49:00 -04006506bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params)
6507{
6508 return ValidateGetUniformBase(context, program, location);
6509}
6510
6511bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params)
6512{
6513 return ValidateGetUniformBase(context, program, location);
6514}
6515
6516bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6517{
6518 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6519}
6520
6521bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6522{
6523 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6524}
6525
6526bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6527{
6528 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6529}
6530
6531bool ValidateIsEnabled(Context *context, GLenum cap)
6532{
6533 if (!ValidCap(context, cap, true))
6534 {
Jamie Madille0472f32018-11-27 16:32:45 -05006535 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006536 return false;
6537 }
6538
6539 return true;
6540}
6541
6542bool ValidateLinkProgram(Context *context, GLuint program)
6543{
6544 if (context->hasActiveTransformFeedback(program))
6545 {
6546 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006547 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006548 return false;
6549 }
6550
6551 Program *programObject = GetValidProgram(context, program);
6552 if (!programObject)
6553 {
6554 return false;
6555 }
6556
6557 return true;
6558}
6559
Jamie Madill4928b7c2017-06-20 12:57:39 -04006560bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006561 GLint x,
6562 GLint y,
6563 GLsizei width,
6564 GLsizei height,
6565 GLenum format,
6566 GLenum type,
6567 void *pixels)
6568{
6569 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6570 nullptr, pixels);
6571}
6572
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006573bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006574{
Till Rathmannb8543632018-10-02 19:46:14 +02006575 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006576}
6577
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006578bool ValidateTexParameterfv(Context *context,
6579 TextureType target,
6580 GLenum pname,
6581 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006582{
Till Rathmannb8543632018-10-02 19:46:14 +02006583 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006584}
6585
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006586bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006587{
Till Rathmannb8543632018-10-02 19:46:14 +02006588 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006589}
6590
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006591bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006592{
Till Rathmannb8543632018-10-02 19:46:14 +02006593 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6594}
6595
6596bool ValidateTexParameterIivOES(Context *context,
6597 TextureType target,
6598 GLenum pname,
6599 const GLint *params)
6600{
6601 if (context->getClientMajorVersion() < 3)
6602 {
Jamie Madille0472f32018-11-27 16:32:45 -05006603 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006604 return false;
6605 }
6606 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6607}
6608
6609bool ValidateTexParameterIuivOES(Context *context,
6610 TextureType target,
6611 GLenum pname,
6612 const GLuint *params)
6613{
6614 if (context->getClientMajorVersion() < 3)
6615 {
Jamie Madille0472f32018-11-27 16:32:45 -05006616 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006617 return false;
6618 }
6619 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006620}
6621
6622bool ValidateUseProgram(Context *context, GLuint program)
6623{
6624 if (program != 0)
6625 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006626 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006627 if (!programObject)
6628 {
6629 // ES 3.1.0 section 7.3 page 72
6630 if (context->getShader(program))
6631 {
Jamie Madille0472f32018-11-27 16:32:45 -05006632 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006633 return false;
6634 }
6635 else
6636 {
Jamie Madille0472f32018-11-27 16:32:45 -05006637 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006638 return false;
6639 }
6640 }
6641 if (!programObject->isLinked())
6642 {
Jamie Madille0472f32018-11-27 16:32:45 -05006643 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006644 return false;
6645 }
6646 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006647 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006648 {
6649 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006650 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006651 return false;
6652 }
6653
6654 return true;
6655}
6656
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006657bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences)
6658{
6659 if (!context->getExtensions().fence)
6660 {
Jamie Madille0472f32018-11-27 16:32:45 -05006661 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006662 return false;
6663 }
6664
6665 if (n < 0)
6666 {
Jamie Madille0472f32018-11-27 16:32:45 -05006667 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006668 return false;
6669 }
6670
6671 return true;
6672}
6673
6674bool ValidateFinishFenceNV(Context *context, GLuint fence)
6675{
6676 if (!context->getExtensions().fence)
6677 {
Jamie Madille0472f32018-11-27 16:32:45 -05006678 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006679 return false;
6680 }
6681
6682 FenceNV *fenceObject = context->getFenceNV(fence);
6683
6684 if (fenceObject == nullptr)
6685 {
Jamie Madille0472f32018-11-27 16:32:45 -05006686 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006687 return false;
6688 }
6689
6690 if (!fenceObject->isSet())
6691 {
Jamie Madille0472f32018-11-27 16:32:45 -05006692 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006693 return false;
6694 }
6695
6696 return true;
6697}
6698
6699bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences)
6700{
6701 if (!context->getExtensions().fence)
6702 {
Jamie Madille0472f32018-11-27 16:32:45 -05006703 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006704 return false;
6705 }
6706
6707 if (n < 0)
6708 {
Jamie Madille0472f32018-11-27 16:32:45 -05006709 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006710 return false;
6711 }
6712
6713 return true;
6714}
6715
6716bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params)
6717{
6718 if (!context->getExtensions().fence)
6719 {
Jamie Madille0472f32018-11-27 16:32:45 -05006720 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006721 return false;
6722 }
6723
6724 FenceNV *fenceObject = context->getFenceNV(fence);
6725
6726 if (fenceObject == nullptr)
6727 {
Jamie Madille0472f32018-11-27 16:32:45 -05006728 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006729 return false;
6730 }
6731
6732 if (!fenceObject->isSet())
6733 {
Jamie Madille0472f32018-11-27 16:32:45 -05006734 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006735 return false;
6736 }
6737
6738 switch (pname)
6739 {
6740 case GL_FENCE_STATUS_NV:
6741 case GL_FENCE_CONDITION_NV:
6742 break;
6743
6744 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006745 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006746 return false;
6747 }
6748
6749 return true;
6750}
6751
6752bool ValidateGetGraphicsResetStatusEXT(Context *context)
6753{
6754 if (!context->getExtensions().robustness)
6755 {
Jamie Madille0472f32018-11-27 16:32:45 -05006756 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006757 return false;
6758 }
6759
6760 return true;
6761}
6762
6763bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
6764 GLuint shader,
6765 GLsizei bufsize,
6766 GLsizei *length,
6767 GLchar *source)
6768{
6769 if (!context->getExtensions().translatedShaderSource)
6770 {
Jamie Madille0472f32018-11-27 16:32:45 -05006771 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006772 return false;
6773 }
6774
6775 if (bufsize < 0)
6776 {
Jamie Madille0472f32018-11-27 16:32:45 -05006777 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006778 return false;
6779 }
6780
6781 Shader *shaderObject = context->getShader(shader);
6782
6783 if (!shaderObject)
6784 {
Jamie Madille0472f32018-11-27 16:32:45 -05006785 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006786 return false;
6787 }
6788
6789 return true;
6790}
6791
6792bool ValidateIsFenceNV(Context *context, GLuint fence)
6793{
6794 if (!context->getExtensions().fence)
6795 {
Jamie Madille0472f32018-11-27 16:32:45 -05006796 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006797 return false;
6798 }
6799
6800 return true;
6801}
6802
Jamie Madill007530e2017-12-28 14:27:04 -05006803bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition)
6804{
6805 if (!context->getExtensions().fence)
6806 {
Jamie Madille0472f32018-11-27 16:32:45 -05006807 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006808 return false;
6809 }
6810
6811 if (condition != GL_ALL_COMPLETED_NV)
6812 {
Jamie Madille0472f32018-11-27 16:32:45 -05006813 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05006814 return false;
6815 }
6816
6817 FenceNV *fenceObject = context->getFenceNV(fence);
6818
6819 if (fenceObject == nullptr)
6820 {
Jamie Madille0472f32018-11-27 16:32:45 -05006821 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006822 return false;
6823 }
6824
6825 return true;
6826}
6827
6828bool ValidateTestFenceNV(Context *context, GLuint fence)
6829{
6830 if (!context->getExtensions().fence)
6831 {
Jamie Madille0472f32018-11-27 16:32:45 -05006832 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006833 return false;
6834 }
6835
6836 FenceNV *fenceObject = context->getFenceNV(fence);
6837
6838 if (fenceObject == nullptr)
6839 {
Jamie Madille0472f32018-11-27 16:32:45 -05006840 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006841 return false;
6842 }
6843
6844 if (fenceObject->isSet() != GL_TRUE)
6845 {
Jamie Madille0472f32018-11-27 16:32:45 -05006846 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05006847 return false;
6848 }
6849
6850 return true;
6851}
6852
6853bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006854 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05006855 GLsizei levels,
6856 GLenum internalformat,
6857 GLsizei width,
6858 GLsizei height)
6859{
6860 if (!context->getExtensions().textureStorage)
6861 {
Jamie Madille0472f32018-11-27 16:32:45 -05006862 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006863 return false;
6864 }
6865
6866 if (context->getClientMajorVersion() < 3)
6867 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006868 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05006869 height);
6870 }
6871
6872 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006873 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05006874 1);
6875}
6876
6877bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
6878{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006879 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05006880 {
Jamie Madille0472f32018-11-27 16:32:45 -05006881 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006882 return false;
6883 }
6884
6885 if (index >= MAX_VERTEX_ATTRIBS)
6886 {
Jamie Madille0472f32018-11-27 16:32:45 -05006887 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05006888 return false;
6889 }
6890
6891 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
6892 {
6893 if (index == 0 && divisor != 0)
6894 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006895 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05006896
6897 // We also output an error message to the debugger window if tracing is active, so
6898 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006899 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05006900 return false;
6901 }
6902 }
6903
6904 return true;
6905}
6906
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006907bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
6908{
6909 if (!context->getExtensions().instancedArraysEXT)
6910 {
6911 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6912 return false;
6913 }
6914
6915 if (index >= MAX_VERTEX_ATTRIBS)
6916 {
6917 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
6918 return false;
6919 }
6920
6921 return true;
6922}
6923
Jamie Madill007530e2017-12-28 14:27:04 -05006924bool ValidateTexImage3DOES(Context *context,
6925 GLenum target,
6926 GLint level,
6927 GLenum internalformat,
6928 GLsizei width,
6929 GLsizei height,
6930 GLsizei depth,
6931 GLint border,
6932 GLenum format,
6933 GLenum type,
6934 const void *pixels)
6935{
6936 UNIMPLEMENTED(); // FIXME
6937 return false;
6938}
6939
6940bool ValidatePopGroupMarkerEXT(Context *context)
6941{
6942 if (!context->getExtensions().debugMarker)
6943 {
6944 // The debug marker calls should not set error state
6945 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05006946 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006947 return false;
6948 }
6949
6950 return true;
6951}
6952
Jamie Madillfa920eb2018-01-04 11:45:50 -05006953bool ValidateTexStorage1DEXT(Context *context,
6954 GLenum target,
6955 GLsizei levels,
6956 GLenum internalformat,
6957 GLsizei width)
6958{
6959 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05006960 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006961 return false;
6962}
6963
6964bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006965 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05006966 GLsizei levels,
6967 GLenum internalformat,
6968 GLsizei width,
6969 GLsizei height,
6970 GLsizei depth)
6971{
6972 if (!context->getExtensions().textureStorage)
6973 {
Jamie Madille0472f32018-11-27 16:32:45 -05006974 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006975 return false;
6976 }
6977
6978 if (context->getClientMajorVersion() < 3)
6979 {
Jamie Madille0472f32018-11-27 16:32:45 -05006980 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006981 return false;
6982 }
6983
6984 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
6985 depth);
6986}
6987
jchen1082af6202018-06-22 10:59:52 +08006988bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
6989{
6990 if (!context->getExtensions().parallelShaderCompile)
6991 {
Jamie Madille0472f32018-11-27 16:32:45 -05006992 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08006993 return false;
6994 }
6995 return true;
6996}
6997
Austin Eng1bf18ce2018-10-19 15:34:02 -07006998bool ValidateMultiDrawArraysANGLE(Context *context,
6999 PrimitiveMode mode,
7000 const GLint *firsts,
7001 const GLsizei *counts,
7002 GLsizei drawcount)
7003{
7004 if (!context->getExtensions().multiDraw)
7005 {
Jamie Madille0472f32018-11-27 16:32:45 -05007006 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007007 return false;
7008 }
7009 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7010 {
7011 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
7012 {
7013 return false;
7014 }
7015 }
7016 return true;
7017}
7018
7019bool ValidateMultiDrawElementsANGLE(Context *context,
7020 PrimitiveMode mode,
7021 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05007022 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08007023 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07007024 GLsizei drawcount)
7025{
7026 if (!context->getExtensions().multiDraw)
7027 {
Jamie Madille0472f32018-11-27 16:32:45 -05007028 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007029 return false;
7030 }
7031 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7032 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08007033 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07007034 {
7035 return false;
7036 }
7037 }
7038 return true;
7039}
7040
Jeff Gilbert465d6092019-01-02 16:21:18 -08007041bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked)
7042{
7043 if (!context->getExtensions().provokingVertex)
7044 {
7045 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7046 return false;
7047 }
7048
7049 switch (modePacked)
7050 {
7051 case ProvokingVertex::FirstVertexConvention:
7052 case ProvokingVertex::LastVertexConvention:
7053 break;
7054 default:
7055 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
7056 return false;
7057 }
7058
7059 return true;
7060}
7061
Jamie Madilla5410482019-01-31 19:55:55 -05007062void RecordBindTextureTypeError(Context *context, TextureType target)
7063{
7064 ASSERT(!context->getStateCache().isValidBindTextureType(target));
7065
7066 switch (target)
7067 {
7068 case TextureType::Rectangle:
7069 ASSERT(!context->getExtensions().textureRectangle);
7070 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
7071 break;
7072
7073 case TextureType::_3D:
7074 case TextureType::_2DArray:
7075 ASSERT(context->getClientMajorVersion() < 3);
7076 context->validationError(GL_INVALID_ENUM, kES3Required);
7077 break;
7078
7079 case TextureType::_2DMultisample:
7080 ASSERT(context->getClientVersion() < Version(3, 1) &&
7081 !context->getExtensions().textureMultisample);
7082 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
7083 break;
7084
7085 case TextureType::_2DMultisampleArray:
7086 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
7087 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
7088 break;
7089
7090 case TextureType::External:
7091 ASSERT(!context->getExtensions().eglImageExternal &&
7092 !context->getExtensions().eglStreamConsumerExternal);
7093 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
7094 break;
7095
7096 default:
7097 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
7098 }
7099}
7100
Jamie Madillc29968b2016-01-20 11:17:23 -05007101} // namespace gl