blob: 2f2b4478e85dcecd4efca1e8b6eeb085ed02818e [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:
733 case GL_DEPTH_STENCIL_OES:
734 case GL_DEPTH24_STENCIL8_OES:
735 if (context->getExtensions().depthTextures)
736 {
Jamie Madille0472f32018-11-27 16:32:45 -0500737 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400738 return false;
739 }
740 else
741 {
Jamie Madille0472f32018-11-27 16:32:45 -0500742 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400743 return false;
744 }
745 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500746 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400747 return false;
748 }
749 }
750
751 // If width or height is zero, it is a no-op. Return false without setting an error.
752 return (width > 0 && height > 0);
753}
754
755bool ValidCap(const Context *context, GLenum cap, bool queryOnly)
756{
757 switch (cap)
758 {
759 // EXT_multisample_compatibility
760 case GL_MULTISAMPLE_EXT:
761 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
762 return context->getExtensions().multisampleCompatibility;
763
764 case GL_CULL_FACE:
765 case GL_POLYGON_OFFSET_FILL:
766 case GL_SAMPLE_ALPHA_TO_COVERAGE:
767 case GL_SAMPLE_COVERAGE:
768 case GL_SCISSOR_TEST:
769 case GL_STENCIL_TEST:
770 case GL_DEPTH_TEST:
771 case GL_BLEND:
772 case GL_DITHER:
773 return true;
774
775 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
776 case GL_RASTERIZER_DISCARD:
777 return (context->getClientMajorVersion() >= 3);
778
779 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
780 case GL_DEBUG_OUTPUT:
781 return context->getExtensions().debug;
782
783 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
784 return queryOnly && context->getExtensions().bindGeneratesResource;
785
786 case GL_CLIENT_ARRAYS_ANGLE:
787 return queryOnly && context->getExtensions().clientArrays;
788
789 case GL_FRAMEBUFFER_SRGB_EXT:
790 return context->getExtensions().sRGBWriteControl;
791
792 case GL_SAMPLE_MASK:
793 return context->getClientVersion() >= Version(3, 1);
794
Geoff Langb433e872017-10-05 14:01:47 -0400795 case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
Jamie Madillbe849e42017-05-02 15:49:00 -0400796 return queryOnly && context->getExtensions().robustResourceInitialization;
797
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700798 // GLES1 emulation: GLES1-specific caps
799 case GL_ALPHA_TEST:
Lingfeng Yang01074432018-04-16 10:19:51 -0700800 case GL_VERTEX_ARRAY:
801 case GL_NORMAL_ARRAY:
802 case GL_COLOR_ARRAY:
803 case GL_TEXTURE_COORD_ARRAY:
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700804 case GL_TEXTURE_2D:
Lingfeng Yangd0febe72018-05-17 22:36:52 -0700805 case GL_LIGHTING:
806 case GL_LIGHT0:
807 case GL_LIGHT1:
808 case GL_LIGHT2:
809 case GL_LIGHT3:
810 case GL_LIGHT4:
811 case GL_LIGHT5:
812 case GL_LIGHT6:
813 case GL_LIGHT7:
814 case GL_NORMALIZE:
815 case GL_RESCALE_NORMAL:
816 case GL_COLOR_MATERIAL:
Lingfeng Yang060088a2018-05-30 20:40:57 -0700817 case GL_CLIP_PLANE0:
818 case GL_CLIP_PLANE1:
819 case GL_CLIP_PLANE2:
820 case GL_CLIP_PLANE3:
821 case GL_CLIP_PLANE4:
822 case GL_CLIP_PLANE5:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -0700823 case GL_FOG:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700824 case GL_POINT_SMOOTH:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -0700825 case GL_LINE_SMOOTH:
826 case GL_COLOR_LOGIC_OP:
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700827 return context->getClientVersion() < Version(2, 0);
Lingfeng Yang01074432018-04-16 10:19:51 -0700828 case GL_POINT_SIZE_ARRAY_OES:
829 return context->getClientVersion() < Version(2, 0) &&
830 context->getExtensions().pointSizeArray;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700831 case GL_TEXTURE_CUBE_MAP:
832 return context->getClientVersion() < Version(2, 0) &&
833 context->getExtensions().textureCubeMap;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700834 case GL_POINT_SPRITE_OES:
835 return context->getClientVersion() < Version(2, 0) &&
836 context->getExtensions().pointSprite;
Jamie Madillbe849e42017-05-02 15:49:00 -0400837 default:
838 return false;
839 }
840}
841
Geoff Langfc32e8b2017-05-31 14:16:59 -0400842// Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section
843// 3.1.
Geoff Langcab92ee2017-07-19 17:32:07 -0400844bool IsValidESSLCharacter(unsigned char c)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400845{
846 // Printing characters are valid except " $ ` @ \ ' DEL.
Geoff Langcab92ee2017-07-19 17:32:07 -0400847 if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' &&
848 c != '\'')
Geoff Langfc32e8b2017-05-31 14:16:59 -0400849 {
850 return true;
851 }
852
853 // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid.
854 if (c >= 9 && c <= 13)
855 {
856 return true;
857 }
858
859 return false;
860}
861
Geoff Langcab92ee2017-07-19 17:32:07 -0400862bool IsValidESSLString(const char *str, size_t len)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400863{
Geoff Langa71a98e2017-06-19 15:15:00 -0400864 for (size_t i = 0; i < len; i++)
865 {
Geoff Langcab92ee2017-07-19 17:32:07 -0400866 if (!IsValidESSLCharacter(str[i]))
Geoff Langa71a98e2017-06-19 15:15:00 -0400867 {
868 return false;
869 }
870 }
871
872 return true;
Geoff Langfc32e8b2017-05-31 14:16:59 -0400873}
874
Geoff Langcab92ee2017-07-19 17:32:07 -0400875bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed)
876{
877 enum class ParseState
878 {
879 // Have not seen an ASCII non-whitespace character yet on
880 // this line. Possible that we might see a preprocessor
881 // directive.
882 BEGINING_OF_LINE,
883
884 // Have seen at least one ASCII non-whitespace character
885 // on this line.
886 MIDDLE_OF_LINE,
887
888 // Handling a preprocessor directive. Passes through all
889 // characters up to the end of the line. Disables comment
890 // processing.
891 IN_PREPROCESSOR_DIRECTIVE,
892
893 // Handling a single-line comment. The comment text is
894 // replaced with a single space.
895 IN_SINGLE_LINE_COMMENT,
896
897 // Handling a multi-line comment. Newlines are passed
898 // through to preserve line numbers.
899 IN_MULTI_LINE_COMMENT
900 };
901
902 ParseState state = ParseState::BEGINING_OF_LINE;
903 size_t pos = 0;
904
905 while (pos < len)
906 {
907 char c = str[pos];
908 char next = pos + 1 < len ? str[pos + 1] : 0;
909
910 // Check for newlines
911 if (c == '\n' || c == '\r')
912 {
913 if (state != ParseState::IN_MULTI_LINE_COMMENT)
914 {
915 state = ParseState::BEGINING_OF_LINE;
916 }
917
918 pos++;
919 continue;
920 }
921
922 switch (state)
923 {
924 case ParseState::BEGINING_OF_LINE:
925 if (c == ' ')
926 {
927 // Maintain the BEGINING_OF_LINE state until a non-space is seen
928 pos++;
929 }
930 else if (c == '#')
931 {
932 state = ParseState::IN_PREPROCESSOR_DIRECTIVE;
933 pos++;
934 }
935 else
936 {
937 // Don't advance, re-process this character with the MIDDLE_OF_LINE state
938 state = ParseState::MIDDLE_OF_LINE;
939 }
940 break;
941
942 case ParseState::MIDDLE_OF_LINE:
943 if (c == '/' && next == '/')
944 {
945 state = ParseState::IN_SINGLE_LINE_COMMENT;
946 pos++;
947 }
948 else if (c == '/' && next == '*')
949 {
950 state = ParseState::IN_MULTI_LINE_COMMENT;
951 pos++;
952 }
953 else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r'))
954 {
955 // Skip line continuation characters
956 }
957 else if (!IsValidESSLCharacter(c))
958 {
959 return false;
960 }
961 pos++;
962 break;
963
964 case ParseState::IN_PREPROCESSOR_DIRECTIVE:
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -0700965 // Line-continuation characters may not be permitted.
966 // Otherwise, just pass it through. Do not parse comments in this state.
967 if (!lineContinuationAllowed && c == '\\')
968 {
969 return false;
970 }
Geoff Langcab92ee2017-07-19 17:32:07 -0400971 pos++;
972 break;
973
974 case ParseState::IN_SINGLE_LINE_COMMENT:
975 // Line-continuation characters are processed before comment processing.
976 // Advance string if a new line character is immediately behind
977 // line-continuation character.
978 if (c == '\\' && (next == '\n' || next == '\r'))
979 {
980 pos++;
981 }
982 pos++;
983 break;
984
985 case ParseState::IN_MULTI_LINE_COMMENT:
986 if (c == '*' && next == '/')
987 {
988 state = ParseState::MIDDLE_OF_LINE;
989 pos++;
990 }
991 pos++;
992 break;
993 }
994 }
995
996 return true;
997}
998
Jamie Madill5b772312018-03-08 20:28:32 -0500999bool ValidateWebGLNamePrefix(Context *context, const GLchar *name)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001000{
1001 ASSERT(context->isWebGL());
1002
1003 // WebGL 1.0 [Section 6.16] GLSL Constructs
1004 // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL.
1005 if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0)
1006 {
Jamie Madille0472f32018-11-27 16:32:45 -05001007 context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001008 return false;
1009 }
1010
1011 return true;
1012}
1013
Jamie Madill5b772312018-03-08 20:28:32 -05001014bool ValidateWebGLNameLength(Context *context, size_t length)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001015{
1016 ASSERT(context->isWebGL());
1017
1018 if (context->isWebGL1() && length > 256)
1019 {
1020 // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths
1021 // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute
1022 // locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001023 context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001024
1025 return false;
1026 }
1027 else if (length > 1024)
1028 {
1029 // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of
1030 // uniform and attribute locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001031 context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001032 return false;
1033 }
1034
1035 return true;
1036}
1037
Jamie Madill007530e2017-12-28 14:27:04 -05001038bool ValidateMatrixMode(Context *context, GLenum matrixMode)
1039{
1040 if (!context->getExtensions().pathRendering)
1041 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001042 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05001043 return false;
1044 }
1045
1046 if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM)
1047 {
Jamie Madille0472f32018-11-27 16:32:45 -05001048 context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode);
Jamie Madill007530e2017-12-28 14:27:04 -05001049 return false;
1050 }
1051 return true;
1052}
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001053
1054bool ValidBlendFunc(const Context *context, GLenum val)
1055{
1056 const gl::Extensions &ext = context->getExtensions();
1057
1058 // these are always valid for src and dst.
1059 switch (val)
1060 {
1061 case GL_ZERO:
1062 case GL_ONE:
1063 case GL_SRC_COLOR:
1064 case GL_ONE_MINUS_SRC_COLOR:
1065 case GL_DST_COLOR:
1066 case GL_ONE_MINUS_DST_COLOR:
1067 case GL_SRC_ALPHA:
1068 case GL_ONE_MINUS_SRC_ALPHA:
1069 case GL_DST_ALPHA:
1070 case GL_ONE_MINUS_DST_ALPHA:
1071 case GL_CONSTANT_COLOR:
1072 case GL_ONE_MINUS_CONSTANT_COLOR:
1073 case GL_CONSTANT_ALPHA:
1074 case GL_ONE_MINUS_CONSTANT_ALPHA:
1075 return true;
1076
1077 // EXT_blend_func_extended.
1078 case GL_SRC1_COLOR_EXT:
1079 case GL_SRC1_ALPHA_EXT:
1080 case GL_ONE_MINUS_SRC1_COLOR_EXT:
1081 case GL_ONE_MINUS_SRC1_ALPHA_EXT:
1082 case GL_SRC_ALPHA_SATURATE_EXT:
1083 return ext.blendFuncExtended;
1084
1085 default:
1086 return false;
1087 }
1088}
1089
1090bool ValidSrcBlendFunc(const Context *context, GLenum val)
1091{
1092 if (ValidBlendFunc(context, val))
1093 return true;
1094
1095 if (val == GL_SRC_ALPHA_SATURATE)
1096 return true;
1097
1098 return false;
1099}
1100
1101bool ValidDstBlendFunc(const Context *context, GLenum val)
1102{
1103 if (ValidBlendFunc(context, val))
1104 return true;
1105
1106 if (val == GL_SRC_ALPHA_SATURATE)
1107 {
1108 if (context->getClientMajorVersion() >= 3)
1109 return true;
1110 }
1111
1112 return false;
1113}
Jamie Madillc29968b2016-01-20 11:17:23 -05001114} // anonymous namespace
1115
Geoff Langff5b2d52016-09-07 11:32:23 -04001116bool ValidateES2TexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001117 TextureTarget target,
Geoff Langff5b2d52016-09-07 11:32:23 -04001118 GLint level,
1119 GLenum internalformat,
1120 bool isCompressed,
1121 bool isSubImage,
1122 GLint xoffset,
1123 GLint yoffset,
1124 GLsizei width,
1125 GLsizei height,
1126 GLint border,
1127 GLenum format,
1128 GLenum type,
1129 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001130 const void *pixels)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001131{
Jamie Madill6f38f822014-06-06 17:12:20 -04001132 if (!ValidTexture2DDestinationTarget(context, target))
1133 {
Jamie Madille0472f32018-11-27 16:32:45 -05001134 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001135 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001136 }
1137
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001138 TextureType texType = TextureTargetToType(target);
1139 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001140 {
Jamie Madill610640f2018-11-21 17:28:41 -05001141 // Error already handled.
Geoff Langb1196682014-07-23 13:47:29 -04001142 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001143 }
1144
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001145 if (!ValidMipLevel(context, texType, level))
Brandon Jones6cad5662017-06-14 13:25:13 -07001146 {
Jamie Madille0472f32018-11-27 16:32:45 -05001147 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Brandon Jones6cad5662017-06-14 13:25:13 -07001148 return false;
1149 }
1150
1151 if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width ||
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001152 std::numeric_limits<GLsizei>::max() - yoffset < height)
1153 {
Jamie Madille0472f32018-11-27 16:32:45 -05001154 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Geoff Langb1196682014-07-23 13:47:29 -04001155 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001156 }
1157
Geoff Langaae65a42014-05-26 12:43:44 -04001158 const gl::Caps &caps = context->getCaps();
1159
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001160 switch (texType)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001161 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001162 case TextureType::_2D:
1163 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
1164 static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
1165 {
Jamie Madille0472f32018-11-27 16:32:45 -05001166 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001167 return false;
1168 }
1169 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001170
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001171 case TextureType::Rectangle:
1172 ASSERT(level == 0);
1173 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1174 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1175 {
Jamie Madille0472f32018-11-27 16:32:45 -05001176 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001177 return false;
1178 }
1179 if (isCompressed)
1180 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001181 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001182 return false;
1183 }
1184 break;
1185
1186 case TextureType::CubeMap:
1187 if (!isSubImage && width != height)
1188 {
Jamie Madille0472f32018-11-27 16:32:45 -05001189 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001190 return false;
1191 }
1192
1193 if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) ||
1194 static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level))
1195 {
Jamie Madille0472f32018-11-27 16:32:45 -05001196 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001197 return false;
1198 }
1199 break;
1200
1201 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001202 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langa9be0dc2014-12-17 12:34:40 -05001203 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001204 }
1205
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001206 gl::Texture *texture = context->getTargetTexture(texType);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001207 if (!texture)
1208 {
Jamie Madille0472f32018-11-27 16:32:45 -05001209 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Geoff Langb1196682014-07-23 13:47:29 -04001210 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001211 }
1212
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001213 // Verify zero border
1214 if (border != 0)
1215 {
Jamie Madille0472f32018-11-27 16:32:45 -05001216 context->validationError(GL_INVALID_VALUE, kInvalidBorder);
Geoff Langb1196682014-07-23 13:47:29 -04001217 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001218 }
1219
Tim Van Patten208af3e2019-03-19 09:15:55 -06001220 bool nonEqualFormatsAllowed = false;
1221
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001222 if (isCompressed)
1223 {
tmartino0ccd5ae2015-10-01 14:33:14 -04001224 GLenum actualInternalFormat =
Geoff Langca271392017-04-05 12:30:00 -04001225 isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat
1226 : internalformat;
Geoff Lange88e4542018-05-03 15:05:57 -04001227
1228 const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat);
1229
1230 if (!internalFormatInfo.compressed)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001231 {
Jamie Madille0472f32018-11-27 16:32:45 -05001232 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001233 return false;
1234 }
1235
1236 if (!internalFormatInfo.textureSupport(context->getClientVersion(),
1237 context->getExtensions()))
1238 {
Jamie Madille0472f32018-11-27 16:32:45 -05001239 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001240 return false;
tmartino0ccd5ae2015-10-01 14:33:14 -04001241 }
Geoff Lang966c9402017-04-18 12:38:27 -04001242
1243 if (isSubImage)
tmartino0ccd5ae2015-10-01 14:33:14 -04001244 {
Geoff Lange88e4542018-05-03 15:05:57 -04001245 // From the OES_compressed_ETC1_RGB8_texture spec:
1246 // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or
1247 // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format
1248 // ETC1_RGB8_OES.
1249 if (actualInternalFormat == GL_ETC1_RGB8_OES)
1250 {
Jamie Madille0472f32018-11-27 16:32:45 -05001251 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001252 return false;
1253 }
1254
Geoff Lang966c9402017-04-18 12:38:27 -04001255 if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width,
1256 height, texture->getWidth(target, level),
1257 texture->getHeight(target, level)))
1258 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001259 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001260 return false;
1261 }
1262
1263 if (format != actualInternalFormat)
1264 {
Jamie Madille0472f32018-11-27 16:32:45 -05001265 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Geoff Lang966c9402017-04-18 12:38:27 -04001266 return false;
1267 }
1268 }
1269 else
1270 {
1271 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height))
1272 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001273 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001274 return false;
1275 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001276 }
1277 }
1278 else
1279 {
1280 // validate <type> by itself (used as secondary key below)
1281 switch (type)
1282 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001283 case GL_UNSIGNED_BYTE:
1284 case GL_UNSIGNED_SHORT_5_6_5:
1285 case GL_UNSIGNED_SHORT_4_4_4_4:
1286 case GL_UNSIGNED_SHORT_5_5_5_1:
1287 case GL_UNSIGNED_SHORT:
1288 case GL_UNSIGNED_INT:
1289 case GL_UNSIGNED_INT_24_8_OES:
1290 case GL_HALF_FLOAT_OES:
1291 case GL_FLOAT:
1292 break;
1293 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001294 context->validationError(GL_INVALID_ENUM, kInvalidType);
He Yunchaoced53ae2016-11-29 15:00:51 +08001295 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001296 }
1297
1298 // validate <format> + <type> combinations
1299 // - invalid <format> -> sets INVALID_ENUM
1300 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
1301 switch (format)
1302 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001303 case GL_ALPHA:
1304 case GL_LUMINANCE:
1305 case GL_LUMINANCE_ALPHA:
1306 switch (type)
1307 {
1308 case GL_UNSIGNED_BYTE:
1309 case GL_FLOAT:
1310 case GL_HALF_FLOAT_OES:
1311 break;
1312 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001313 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001314 return false;
1315 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001316 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001317 case GL_RED:
1318 case GL_RG:
1319 if (!context->getExtensions().textureRG)
1320 {
Jamie Madille0472f32018-11-27 16:32:45 -05001321 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001322 return false;
1323 }
1324 switch (type)
1325 {
1326 case GL_UNSIGNED_BYTE:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001327 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001328 case GL_FLOAT:
1329 case GL_HALF_FLOAT_OES:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001330 if (!context->getExtensions().textureFloat)
1331 {
Jamie Madille0472f32018-11-27 16:32:45 -05001332 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001333 return false;
1334 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001335 break;
1336 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001337 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001338 return false;
1339 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001340 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001341 case GL_RGB:
1342 switch (type)
1343 {
1344 case GL_UNSIGNED_BYTE:
1345 case GL_UNSIGNED_SHORT_5_6_5:
1346 case GL_FLOAT:
1347 case GL_HALF_FLOAT_OES:
1348 break;
1349 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001350 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001351 return false;
1352 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001353 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001354 case GL_RGBA:
1355 switch (type)
1356 {
1357 case GL_UNSIGNED_BYTE:
1358 case GL_UNSIGNED_SHORT_4_4_4_4:
1359 case GL_UNSIGNED_SHORT_5_5_5_1:
1360 case GL_FLOAT:
1361 case GL_HALF_FLOAT_OES:
1362 break;
1363 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001364 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001365 return false;
1366 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001367 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001368 case GL_BGRA_EXT:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001369 if (!context->getExtensions().textureFormatBGRA8888)
1370 {
Jamie Madille0472f32018-11-27 16:32:45 -05001371 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001372 return false;
1373 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001374 switch (type)
1375 {
1376 case GL_UNSIGNED_BYTE:
1377 break;
1378 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001379 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001380 return false;
1381 }
1382 break;
1383 case GL_SRGB_EXT:
1384 case GL_SRGB_ALPHA_EXT:
1385 if (!context->getExtensions().sRGB)
1386 {
Jamie Madille0472f32018-11-27 16:32:45 -05001387 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001388 return false;
1389 }
1390 switch (type)
1391 {
1392 case GL_UNSIGNED_BYTE:
1393 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 }
1398 break;
1399 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are
1400 // handled below
1401 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1402 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1403 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1404 break;
1405 case GL_DEPTH_COMPONENT:
1406 switch (type)
1407 {
1408 case GL_UNSIGNED_SHORT:
1409 case GL_UNSIGNED_INT:
1410 break;
1411 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001412 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001413 return false;
1414 }
1415 break;
1416 case GL_DEPTH_STENCIL_OES:
1417 switch (type)
1418 {
1419 case GL_UNSIGNED_INT_24_8_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 }
1425 break;
1426 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001427 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001428 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001429 }
1430
1431 switch (format)
1432 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001433 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1434 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1435 if (context->getExtensions().textureCompressionDXT1)
1436 {
Jamie Madille0472f32018-11-27 16:32:45 -05001437 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001438 return false;
1439 }
1440 else
1441 {
Jamie Madille0472f32018-11-27 16:32:45 -05001442 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001443 return false;
1444 }
1445 break;
1446 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1447 if (context->getExtensions().textureCompressionDXT3)
1448 {
Jamie Madille0472f32018-11-27 16:32:45 -05001449 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001450 return false;
1451 }
1452 else
1453 {
Jamie Madille0472f32018-11-27 16:32:45 -05001454 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001455 return false;
1456 }
1457 break;
1458 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1459 if (context->getExtensions().textureCompressionDXT5)
1460 {
Jamie Madille0472f32018-11-27 16:32:45 -05001461 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001462 return false;
1463 }
1464 else
1465 {
Jamie Madille0472f32018-11-27 16:32:45 -05001466 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001467 return false;
1468 }
1469 break;
1470 case GL_ETC1_RGB8_OES:
1471 if (context->getExtensions().compressedETC1RGB8Texture)
1472 {
Jamie Madille0472f32018-11-27 16:32:45 -05001473 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001474 return false;
1475 }
1476 else
1477 {
Jamie Madille0472f32018-11-27 16:32:45 -05001478 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001479 return false;
1480 }
1481 break;
1482 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001483 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1484 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1485 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1486 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001487 if (context->getExtensions().lossyETCDecode)
1488 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001489 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001490 return false;
1491 }
1492 else
1493 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001494 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001495 return false;
1496 }
1497 break;
1498 case GL_DEPTH_COMPONENT:
1499 case GL_DEPTH_STENCIL_OES:
1500 if (!context->getExtensions().depthTextures)
1501 {
Jamie Madille0472f32018-11-27 16:32:45 -05001502 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001503 return false;
1504 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001505 if (target != TextureTarget::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001506 {
Jamie Madille0472f32018-11-27 16:32:45 -05001507 context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001508 return false;
1509 }
1510 // OES_depth_texture supports loading depth data and multiple levels,
1511 // but ANGLE_depth_texture does not
Brandon Jonesafa75152017-07-21 13:11:29 -07001512 if (pixels != nullptr)
He Yunchaoced53ae2016-11-29 15:00:51 +08001513 {
Jamie Madille0472f32018-11-27 16:32:45 -05001514 context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
Brandon Jonesafa75152017-07-21 13:11:29 -07001515 return false;
1516 }
1517 if (level != 0)
1518 {
Jamie Madille0472f32018-11-27 16:32:45 -05001519 context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
He Yunchaoced53ae2016-11-29 15:00:51 +08001520 return false;
1521 }
1522 break;
1523 default:
1524 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001525 }
1526
Geoff Lang6e898aa2017-06-02 11:17:26 -04001527 if (!isSubImage)
1528 {
1529 switch (internalformat)
1530 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001531 // Core ES 2.0 formats
1532 case GL_ALPHA:
1533 case GL_LUMINANCE:
1534 case GL_LUMINANCE_ALPHA:
1535 case GL_RGB:
1536 case GL_RGBA:
1537 break;
1538
Geoff Lang6e898aa2017-06-02 11:17:26 -04001539 case GL_RGBA32F:
1540 if (!context->getExtensions().colorBufferFloatRGBA)
1541 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001542 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001543 return false;
1544 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001545
1546 nonEqualFormatsAllowed = true;
1547
Geoff Lang6e898aa2017-06-02 11:17:26 -04001548 if (type != GL_FLOAT)
1549 {
Jamie Madille0472f32018-11-27 16:32:45 -05001550 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001551 return false;
1552 }
1553 if (format != GL_RGBA)
1554 {
Jamie Madille0472f32018-11-27 16:32:45 -05001555 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001556 return false;
1557 }
1558 break;
1559
1560 case GL_RGB32F:
1561 if (!context->getExtensions().colorBufferFloatRGB)
1562 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001563 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001564 return false;
1565 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001566
1567 nonEqualFormatsAllowed = true;
1568
Geoff Lang6e898aa2017-06-02 11:17:26 -04001569 if (type != GL_FLOAT)
1570 {
Jamie Madille0472f32018-11-27 16:32:45 -05001571 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001572 return false;
1573 }
1574 if (format != GL_RGB)
1575 {
Jamie Madille0472f32018-11-27 16:32:45 -05001576 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001577 return false;
1578 }
1579 break;
1580
Tim Van Patten208af3e2019-03-19 09:15:55 -06001581 case GL_BGRA_EXT:
1582 if (!context->getExtensions().textureFormatBGRA8888)
1583 {
1584 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1585 return false;
1586 }
Geoff Lang6e898aa2017-06-02 11:17:26 -04001587 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001588
1589 case GL_DEPTH_COMPONENT:
1590 case GL_DEPTH_STENCIL:
1591 if (!context->getExtensions().depthTextures)
1592 {
1593 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1594 return false;
1595 }
1596 break;
1597
1598 case GL_RED:
1599 case GL_RG:
1600 if (!context->getExtensions().textureRG)
1601 {
1602 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1603 return false;
1604 }
1605 break;
1606
1607 case GL_SRGB_EXT:
1608 case GL_SRGB_ALPHA_EXT:
1609 if (!context->getExtensions().sRGB)
1610 {
1611 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1612 return false;
1613 }
1614 break;
1615
1616 default:
1617 context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat);
1618 return false;
Geoff Lang6e898aa2017-06-02 11:17:26 -04001619 }
1620 }
1621
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001622 if (type == GL_FLOAT)
1623 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001624 if (!context->getExtensions().textureFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001625 {
Jamie Madille0472f32018-11-27 16:32:45 -05001626 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001627 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001628 }
1629 }
1630 else if (type == GL_HALF_FLOAT_OES)
1631 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001632 if (!context->getExtensions().textureHalfFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001633 {
Jamie Madille0472f32018-11-27 16:32:45 -05001634 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001635 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001636 }
1637 }
1638 }
1639
Tim Van Patten208af3e2019-03-19 09:15:55 -06001640 if (isSubImage)
Geoff Langff5b2d52016-09-07 11:32:23 -04001641 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001642 const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info;
1643 if (textureInternalFormat.internalFormat == GL_NONE)
1644 {
1645 context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel);
1646 return false;
1647 }
1648
1649 if (format != GL_NONE)
1650 {
1651 if (GetInternalFormatInfo(format, type).sizedInternalFormat !=
1652 textureInternalFormat.sizedInternalFormat)
1653 {
1654 context->validationError(GL_INVALID_OPERATION, kTypeMismatch);
1655 return false;
1656 }
1657 }
1658
1659 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
1660 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level))
1661 {
1662 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
1663 return false;
1664 }
1665
1666 if (width > 0 && height > 0 && pixels == nullptr &&
1667 context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr)
1668 {
1669 context->validationError(GL_INVALID_VALUE, kPixelDataNull);
1670 return false;
1671 }
1672 }
1673 else
1674 {
1675 if (texture->getImmutableFormat())
1676 {
1677 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
1678 return false;
1679 }
1680 }
1681
1682 // From GL_CHROMIUM_color_buffer_float_rgb[a]:
1683 // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
1684 // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
1685 // internalformat parameter and format parameter of TexImage2D must match is lifted for this
1686 // case.
1687 if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
1688 {
1689 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Langff5b2d52016-09-07 11:32:23 -04001690 return false;
1691 }
1692
Tim Van Patten208af3e2019-03-19 09:15:55 -06001693 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
1694 return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels,
1695 imageSize);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001696}
1697
He Yunchaoced53ae2016-11-29 15:00:51 +08001698bool ValidateES2TexStorageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001699 TextureType target,
He Yunchaoced53ae2016-11-29 15:00:51 +08001700 GLsizei levels,
1701 GLenum internalformat,
1702 GLsizei width,
1703 GLsizei height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001704{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001705 if (target != TextureType::_2D && target != TextureType::CubeMap &&
1706 target != TextureType::Rectangle)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001707 {
Jamie Madille0472f32018-11-27 16:32:45 -05001708 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001709 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001710 }
1711
1712 if (width < 1 || height < 1 || levels < 1)
1713 {
Jamie Madille0472f32018-11-27 16:32:45 -05001714 context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall);
Geoff Langb1196682014-07-23 13:47:29 -04001715 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001716 }
1717
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001718 if (target == TextureType::CubeMap && width != height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001719 {
Jamie Madille0472f32018-11-27 16:32:45 -05001720 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Langb1196682014-07-23 13:47:29 -04001721 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001722 }
1723
1724 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1725 {
Jamie Madille0472f32018-11-27 16:32:45 -05001726 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
Geoff Langb1196682014-07-23 13:47:29 -04001727 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001728 }
1729
Geoff Langca271392017-04-05 12:30:00 -04001730 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Lang5d601382014-07-22 15:14:06 -04001731 if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001732 {
Jamie Madille0472f32018-11-27 16:32:45 -05001733 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Langb1196682014-07-23 13:47:29 -04001734 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001735 }
1736
Geoff Langaae65a42014-05-26 12:43:44 -04001737 const gl::Caps &caps = context->getCaps();
1738
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001739 switch (target)
1740 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001741 case TextureType::_2D:
He Yunchaoced53ae2016-11-29 15:00:51 +08001742 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
1743 static_cast<GLuint>(height) > caps.max2DTextureSize)
1744 {
Jamie Madille0472f32018-11-27 16:32:45 -05001745 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001746 return false;
1747 }
1748 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001749 case TextureType::Rectangle:
Jamie Madill610640f2018-11-21 17:28:41 -05001750 if (levels != 1)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001751 {
Jamie Madille0472f32018-11-27 16:32:45 -05001752 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madill610640f2018-11-21 17:28:41 -05001753 return false;
1754 }
1755
1756 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1757 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1758 {
Jamie Madille0472f32018-11-27 16:32:45 -05001759 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001760 return false;
1761 }
1762 if (formatInfo.compressed)
1763 {
Jamie Madille0472f32018-11-27 16:32:45 -05001764 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001765 return false;
1766 }
1767 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001768 case TextureType::CubeMap:
He Yunchaoced53ae2016-11-29 15:00:51 +08001769 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize ||
1770 static_cast<GLuint>(height) > caps.maxCubeMapTextureSize)
1771 {
Jamie Madille0472f32018-11-27 16:32:45 -05001772 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001773 return false;
1774 }
1775 break;
1776 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001777 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001778 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001779 }
1780
Geoff Langc0b9ef42014-07-02 10:02:37 -04001781 if (levels != 1 && !context->getExtensions().textureNPOT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001782 {
1783 if (!gl::isPow2(width) || !gl::isPow2(height))
1784 {
Jamie Madille0472f32018-11-27 16:32:45 -05001785 context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2);
Geoff Langb1196682014-07-23 13:47:29 -04001786 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001787 }
1788 }
1789
1790 switch (internalformat)
1791 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001792 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1793 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1794 if (!context->getExtensions().textureCompressionDXT1)
1795 {
Jamie Madille0472f32018-11-27 16:32:45 -05001796 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001797 return false;
1798 }
1799 break;
1800 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1801 if (!context->getExtensions().textureCompressionDXT3)
1802 {
Jamie Madille0472f32018-11-27 16:32:45 -05001803 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001804 return false;
1805 }
1806 break;
1807 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1808 if (!context->getExtensions().textureCompressionDXT5)
1809 {
Jamie Madille0472f32018-11-27 16:32:45 -05001810 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001811 return false;
1812 }
1813 break;
1814 case GL_ETC1_RGB8_OES:
1815 if (!context->getExtensions().compressedETC1RGB8Texture)
1816 {
Jamie Madille0472f32018-11-27 16:32:45 -05001817 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001818 return false;
1819 }
1820 break;
1821 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001822 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1823 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1824 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1825 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001826 if (!context->getExtensions().lossyETCDecode)
1827 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001828 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001829 return false;
1830 }
1831 break;
1832 case GL_RGBA32F_EXT:
1833 case GL_RGB32F_EXT:
1834 case GL_ALPHA32F_EXT:
1835 case GL_LUMINANCE32F_EXT:
1836 case GL_LUMINANCE_ALPHA32F_EXT:
1837 if (!context->getExtensions().textureFloat)
1838 {
Jamie Madille0472f32018-11-27 16:32:45 -05001839 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001840 return false;
1841 }
1842 break;
1843 case GL_RGBA16F_EXT:
1844 case GL_RGB16F_EXT:
1845 case GL_ALPHA16F_EXT:
1846 case GL_LUMINANCE16F_EXT:
1847 case GL_LUMINANCE_ALPHA16F_EXT:
1848 if (!context->getExtensions().textureHalfFloat)
1849 {
Jamie Madille0472f32018-11-27 16:32:45 -05001850 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001851 return false;
1852 }
1853 break;
1854 case GL_R8_EXT:
1855 case GL_RG8_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001856 if (!context->getExtensions().textureRG)
1857 {
Jamie Madille0472f32018-11-27 16:32:45 -05001858 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001859 return false;
1860 }
1861 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001862 case GL_R16F_EXT:
1863 case GL_RG16F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001864 if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat)
1865 {
Jamie Madille0472f32018-11-27 16:32:45 -05001866 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001867 return false;
1868 }
1869 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001870 case GL_R32F_EXT:
1871 case GL_RG32F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001872 if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat)
He Yunchaoced53ae2016-11-29 15:00:51 +08001873 {
Jamie Madille0472f32018-11-27 16:32:45 -05001874 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001875 return false;
1876 }
1877 break;
1878 case GL_DEPTH_COMPONENT16:
1879 case GL_DEPTH_COMPONENT32_OES:
1880 case GL_DEPTH24_STENCIL8_OES:
1881 if (!context->getExtensions().depthTextures)
1882 {
Jamie Madille0472f32018-11-27 16:32:45 -05001883 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001884 return false;
1885 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001886 if (target != TextureType::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001887 {
Jamie Madille0472f32018-11-27 16:32:45 -05001888 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001889 return false;
1890 }
1891 // ANGLE_depth_texture only supports 1-level textures
1892 if (levels != 1)
1893 {
Jamie Madille0472f32018-11-27 16:32:45 -05001894 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
He Yunchaoced53ae2016-11-29 15:00:51 +08001895 return false;
1896 }
1897 break;
1898 default:
1899 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001900 }
1901
Geoff Lang691e58c2014-12-19 17:03:25 -05001902 gl::Texture *texture = context->getTargetTexture(target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001903 if (!texture || texture->id() == 0)
1904 {
Jamie Madille0472f32018-11-27 16:32:45 -05001905 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
Geoff Langb1196682014-07-23 13:47:29 -04001906 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001907 }
1908
Geoff Lang69cce582015-09-17 13:20:36 -04001909 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001910 {
Jamie Madille0472f32018-11-27 16:32:45 -05001911 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
Geoff Langb1196682014-07-23 13:47:29 -04001912 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001913 }
1914
1915 return true;
1916}
1917
He Yunchaoced53ae2016-11-29 15:00:51 +08001918bool ValidateDiscardFramebufferEXT(Context *context,
1919 GLenum target,
1920 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07001921 const GLenum *attachments)
1922{
Jamie Madillc29968b2016-01-20 11:17:23 -05001923 if (!context->getExtensions().discardFramebuffer)
1924 {
Jamie Madille0472f32018-11-27 16:32:45 -05001925 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05001926 return false;
1927 }
1928
Austin Kinross08332632015-05-05 13:35:47 -07001929 bool defaultFramebuffer = false;
1930
1931 switch (target)
1932 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001933 case GL_FRAMEBUFFER:
1934 defaultFramebuffer =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001935 (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0);
He Yunchaoced53ae2016-11-29 15:00:51 +08001936 break;
1937 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001938 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001939 return false;
Austin Kinross08332632015-05-05 13:35:47 -07001940 }
1941
He Yunchaoced53ae2016-11-29 15:00:51 +08001942 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
1943 defaultFramebuffer);
Austin Kinross08332632015-05-05 13:35:47 -07001944}
1945
Austin Kinrossbc781f32015-10-26 09:27:38 -07001946bool ValidateBindVertexArrayOES(Context *context, GLuint array)
1947{
1948 if (!context->getExtensions().vertexArrayObject)
1949 {
Jamie Madille0472f32018-11-27 16:32:45 -05001950 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001951 return false;
1952 }
1953
1954 return ValidateBindVertexArrayBase(context, array);
1955}
1956
Jamie Madilld7576732017-08-26 18:49:50 -04001957bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07001958{
1959 if (!context->getExtensions().vertexArrayObject)
1960 {
Jamie Madille0472f32018-11-27 16:32:45 -05001961 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001962 return false;
1963 }
1964
Olli Etuaho41997e72016-03-10 13:38:39 +02001965 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001966}
1967
Jamie Madilld7576732017-08-26 18:49:50 -04001968bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07001969{
1970 if (!context->getExtensions().vertexArrayObject)
1971 {
Jamie Madille0472f32018-11-27 16:32:45 -05001972 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001973 return false;
1974 }
1975
Olli Etuaho41997e72016-03-10 13:38:39 +02001976 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001977}
1978
Jamie Madilld7576732017-08-26 18:49:50 -04001979bool ValidateIsVertexArrayOES(Context *context, GLuint array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07001980{
1981 if (!context->getExtensions().vertexArrayObject)
1982 {
Jamie Madille0472f32018-11-27 16:32:45 -05001983 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001984 return false;
1985 }
1986
1987 return true;
1988}
Geoff Langc5629752015-12-07 16:29:04 -05001989
1990bool ValidateProgramBinaryOES(Context *context,
1991 GLuint program,
1992 GLenum binaryFormat,
1993 const void *binary,
1994 GLint length)
1995{
1996 if (!context->getExtensions().getProgramBinary)
1997 {
Jamie Madille0472f32018-11-27 16:32:45 -05001998 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05001999 return false;
2000 }
2001
2002 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
2003}
2004
2005bool ValidateGetProgramBinaryOES(Context *context,
2006 GLuint program,
2007 GLsizei bufSize,
2008 GLsizei *length,
2009 GLenum *binaryFormat,
2010 void *binary)
2011{
2012 if (!context->getExtensions().getProgramBinary)
2013 {
Jamie Madille0472f32018-11-27 16:32:45 -05002014 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002015 return false;
2016 }
2017
2018 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
2019}
Geoff Lange102fee2015-12-10 11:23:30 -05002020
Geoff Lang70d0f492015-12-10 17:45:46 -05002021static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication)
2022{
2023 switch (source)
2024 {
2025 case GL_DEBUG_SOURCE_API:
2026 case GL_DEBUG_SOURCE_SHADER_COMPILER:
2027 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
2028 case GL_DEBUG_SOURCE_OTHER:
2029 // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted
2030 return !mustBeThirdPartyOrApplication;
2031
2032 case GL_DEBUG_SOURCE_THIRD_PARTY:
2033 case GL_DEBUG_SOURCE_APPLICATION:
2034 return true;
2035
2036 default:
2037 return false;
2038 }
2039}
2040
2041static bool ValidDebugType(GLenum type)
2042{
2043 switch (type)
2044 {
2045 case GL_DEBUG_TYPE_ERROR:
2046 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
2047 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
2048 case GL_DEBUG_TYPE_PERFORMANCE:
2049 case GL_DEBUG_TYPE_PORTABILITY:
2050 case GL_DEBUG_TYPE_OTHER:
2051 case GL_DEBUG_TYPE_MARKER:
2052 case GL_DEBUG_TYPE_PUSH_GROUP:
2053 case GL_DEBUG_TYPE_POP_GROUP:
2054 return true;
2055
2056 default:
2057 return false;
2058 }
2059}
2060
2061static bool ValidDebugSeverity(GLenum severity)
2062{
2063 switch (severity)
2064 {
2065 case GL_DEBUG_SEVERITY_HIGH:
2066 case GL_DEBUG_SEVERITY_MEDIUM:
2067 case GL_DEBUG_SEVERITY_LOW:
2068 case GL_DEBUG_SEVERITY_NOTIFICATION:
2069 return true;
2070
2071 default:
2072 return false;
2073 }
2074}
2075
Geoff Lange102fee2015-12-10 11:23:30 -05002076bool ValidateDebugMessageControlKHR(Context *context,
2077 GLenum source,
2078 GLenum type,
2079 GLenum severity,
2080 GLsizei count,
2081 const GLuint *ids,
2082 GLboolean enabled)
2083{
2084 if (!context->getExtensions().debug)
2085 {
Jamie Madille0472f32018-11-27 16:32:45 -05002086 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002087 return false;
2088 }
2089
Geoff Lang70d0f492015-12-10 17:45:46 -05002090 if (!ValidDebugSource(source, false) && source != GL_DONT_CARE)
2091 {
Jamie Madille0472f32018-11-27 16:32:45 -05002092 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002093 return false;
2094 }
2095
2096 if (!ValidDebugType(type) && type != GL_DONT_CARE)
2097 {
Jamie Madille0472f32018-11-27 16:32:45 -05002098 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002099 return false;
2100 }
2101
2102 if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE)
2103 {
Jamie Madille0472f32018-11-27 16:32:45 -05002104 context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002105 return false;
2106 }
2107
2108 if (count > 0)
2109 {
2110 if (source == GL_DONT_CARE || type == GL_DONT_CARE)
2111 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002112 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002113 return false;
2114 }
2115
2116 if (severity != GL_DONT_CARE)
2117 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002118 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002119 return false;
2120 }
2121 }
2122
Geoff Lange102fee2015-12-10 11:23:30 -05002123 return true;
2124}
2125
2126bool ValidateDebugMessageInsertKHR(Context *context,
2127 GLenum source,
2128 GLenum type,
2129 GLuint id,
2130 GLenum severity,
2131 GLsizei length,
2132 const GLchar *buf)
2133{
2134 if (!context->getExtensions().debug)
2135 {
Jamie Madille0472f32018-11-27 16:32:45 -05002136 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002137 return false;
2138 }
2139
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002140 if (!context->getState().getDebug().isOutputEnabled())
Geoff Lang70d0f492015-12-10 17:45:46 -05002141 {
2142 // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do
2143 // not generate an error.
2144 return false;
2145 }
2146
2147 if (!ValidDebugSeverity(severity))
2148 {
Jamie Madille0472f32018-11-27 16:32:45 -05002149 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002150 return false;
2151 }
2152
2153 if (!ValidDebugType(type))
2154 {
Jamie Madille0472f32018-11-27 16:32:45 -05002155 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002156 return false;
2157 }
2158
2159 if (!ValidDebugSource(source, true))
2160 {
Jamie Madille0472f32018-11-27 16:32:45 -05002161 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002162 return false;
2163 }
2164
2165 size_t messageLength = (length < 0) ? strlen(buf) : length;
2166 if (messageLength > context->getExtensions().maxDebugMessageLength)
2167 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002168 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002169 return false;
2170 }
2171
Geoff Lange102fee2015-12-10 11:23:30 -05002172 return true;
2173}
2174
2175bool ValidateDebugMessageCallbackKHR(Context *context,
2176 GLDEBUGPROCKHR callback,
2177 const void *userParam)
2178{
2179 if (!context->getExtensions().debug)
2180 {
Jamie Madille0472f32018-11-27 16:32:45 -05002181 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002182 return false;
2183 }
2184
Geoff Lange102fee2015-12-10 11:23:30 -05002185 return true;
2186}
2187
2188bool ValidateGetDebugMessageLogKHR(Context *context,
2189 GLuint count,
2190 GLsizei bufSize,
2191 GLenum *sources,
2192 GLenum *types,
2193 GLuint *ids,
2194 GLenum *severities,
2195 GLsizei *lengths,
2196 GLchar *messageLog)
2197{
2198 if (!context->getExtensions().debug)
2199 {
Jamie Madille0472f32018-11-27 16:32:45 -05002200 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002201 return false;
2202 }
2203
Geoff Lang70d0f492015-12-10 17:45:46 -05002204 if (bufSize < 0 && messageLog != nullptr)
2205 {
Jamie Madille0472f32018-11-27 16:32:45 -05002206 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002207 return false;
2208 }
2209
Geoff Lange102fee2015-12-10 11:23:30 -05002210 return true;
2211}
2212
2213bool ValidatePushDebugGroupKHR(Context *context,
2214 GLenum source,
2215 GLuint id,
2216 GLsizei length,
2217 const GLchar *message)
2218{
2219 if (!context->getExtensions().debug)
2220 {
Jamie Madille0472f32018-11-27 16:32:45 -05002221 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002222 return false;
2223 }
2224
Geoff Lang70d0f492015-12-10 17:45:46 -05002225 if (!ValidDebugSource(source, true))
2226 {
Jamie Madille0472f32018-11-27 16:32:45 -05002227 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002228 return false;
2229 }
2230
2231 size_t messageLength = (length < 0) ? strlen(message) : length;
2232 if (messageLength > context->getExtensions().maxDebugMessageLength)
2233 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002234 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002235 return false;
2236 }
2237
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002238 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002239 if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth)
2240 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002241 context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth);
Geoff Lang70d0f492015-12-10 17:45:46 -05002242 return false;
2243 }
2244
Geoff Lange102fee2015-12-10 11:23:30 -05002245 return true;
2246}
2247
2248bool ValidatePopDebugGroupKHR(Context *context)
2249{
2250 if (!context->getExtensions().debug)
2251 {
Jamie Madille0472f32018-11-27 16:32:45 -05002252 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002253 return false;
2254 }
2255
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002256 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002257 if (currentStackSize <= 1)
2258 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002259 context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup);
Geoff Lang70d0f492015-12-10 17:45:46 -05002260 return false;
2261 }
2262
2263 return true;
2264}
2265
2266static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name)
2267{
2268 switch (identifier)
2269 {
2270 case GL_BUFFER:
2271 if (context->getBuffer(name) == nullptr)
2272 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002273 context->validationError(GL_INVALID_VALUE, kInvalidBufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002274 return false;
2275 }
2276 return true;
2277
2278 case GL_SHADER:
2279 if (context->getShader(name) == nullptr)
2280 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002281 context->validationError(GL_INVALID_VALUE, kInvalidShaderName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002282 return false;
2283 }
2284 return true;
2285
2286 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002287 if (context->getProgramNoResolveLink(name) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002288 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002289 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002290 return false;
2291 }
2292 return true;
2293
2294 case GL_VERTEX_ARRAY:
2295 if (context->getVertexArray(name) == nullptr)
2296 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002297 context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002298 return false;
2299 }
2300 return true;
2301
2302 case GL_QUERY:
2303 if (context->getQuery(name) == nullptr)
2304 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002305 context->validationError(GL_INVALID_VALUE, kInvalidQueryName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002306 return false;
2307 }
2308 return true;
2309
2310 case GL_TRANSFORM_FEEDBACK:
2311 if (context->getTransformFeedback(name) == nullptr)
2312 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002313 context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002314 return false;
2315 }
2316 return true;
2317
2318 case GL_SAMPLER:
2319 if (context->getSampler(name) == nullptr)
2320 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002321 context->validationError(GL_INVALID_VALUE, kInvalidSamplerName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002322 return false;
2323 }
2324 return true;
2325
2326 case GL_TEXTURE:
2327 if (context->getTexture(name) == nullptr)
2328 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002329 context->validationError(GL_INVALID_VALUE, kInvalidTextureName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002330 return false;
2331 }
2332 return true;
2333
2334 case GL_RENDERBUFFER:
2335 if (context->getRenderbuffer(name) == nullptr)
2336 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002337 context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002338 return false;
2339 }
2340 return true;
2341
2342 case GL_FRAMEBUFFER:
2343 if (context->getFramebuffer(name) == nullptr)
2344 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002345 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002346 return false;
2347 }
2348 return true;
2349
2350 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05002351 context->validationError(GL_INVALID_ENUM, kInvalidIndentifier);
Geoff Lang70d0f492015-12-10 17:45:46 -05002352 return false;
2353 }
Geoff Lange102fee2015-12-10 11:23:30 -05002354}
2355
Martin Radev9d901792016-07-15 15:58:58 +03002356static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label)
2357{
2358 size_t labelLength = 0;
2359
2360 if (length < 0)
2361 {
2362 if (label != nullptr)
2363 {
2364 labelLength = strlen(label);
2365 }
2366 }
2367 else
2368 {
2369 labelLength = static_cast<size_t>(length);
2370 }
2371
2372 if (labelLength > context->getExtensions().maxLabelLength)
2373 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002374 context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength);
Martin Radev9d901792016-07-15 15:58:58 +03002375 return false;
2376 }
2377
2378 return true;
2379}
2380
Geoff Lange102fee2015-12-10 11:23:30 -05002381bool ValidateObjectLabelKHR(Context *context,
2382 GLenum identifier,
2383 GLuint name,
2384 GLsizei length,
2385 const GLchar *label)
2386{
2387 if (!context->getExtensions().debug)
2388 {
Jamie Madille0472f32018-11-27 16:32:45 -05002389 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002390 return false;
2391 }
2392
Geoff Lang70d0f492015-12-10 17:45:46 -05002393 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2394 {
2395 return false;
2396 }
2397
Martin Radev9d901792016-07-15 15:58:58 +03002398 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002399 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002400 return false;
2401 }
2402
Geoff Lange102fee2015-12-10 11:23:30 -05002403 return true;
2404}
2405
2406bool ValidateGetObjectLabelKHR(Context *context,
2407 GLenum identifier,
2408 GLuint name,
2409 GLsizei bufSize,
2410 GLsizei *length,
2411 GLchar *label)
2412{
2413 if (!context->getExtensions().debug)
2414 {
Jamie Madille0472f32018-11-27 16:32:45 -05002415 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002416 return false;
2417 }
2418
Geoff Lang70d0f492015-12-10 17:45:46 -05002419 if (bufSize < 0)
2420 {
Jamie Madille0472f32018-11-27 16:32:45 -05002421 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002422 return false;
2423 }
2424
2425 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2426 {
2427 return false;
2428 }
2429
Martin Radev9d901792016-07-15 15:58:58 +03002430 return true;
Geoff Lang70d0f492015-12-10 17:45:46 -05002431}
2432
2433static bool ValidateObjectPtrName(Context *context, const void *ptr)
2434{
Jamie Madill70b5bb02017-08-28 13:32:37 -04002435 if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002436 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002437 context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer);
Geoff Lang70d0f492015-12-10 17:45:46 -05002438 return false;
2439 }
2440
Geoff Lange102fee2015-12-10 11:23:30 -05002441 return true;
2442}
2443
2444bool ValidateObjectPtrLabelKHR(Context *context,
2445 const void *ptr,
2446 GLsizei length,
2447 const GLchar *label)
2448{
2449 if (!context->getExtensions().debug)
2450 {
Jamie Madille0472f32018-11-27 16:32:45 -05002451 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002452 return false;
2453 }
2454
Geoff Lang70d0f492015-12-10 17:45:46 -05002455 if (!ValidateObjectPtrName(context, ptr))
2456 {
2457 return false;
2458 }
2459
Martin Radev9d901792016-07-15 15:58:58 +03002460 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002461 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002462 return false;
2463 }
2464
Geoff Lange102fee2015-12-10 11:23:30 -05002465 return true;
2466}
2467
2468bool ValidateGetObjectPtrLabelKHR(Context *context,
2469 const void *ptr,
2470 GLsizei bufSize,
2471 GLsizei *length,
2472 GLchar *label)
2473{
2474 if (!context->getExtensions().debug)
2475 {
Jamie Madille0472f32018-11-27 16:32:45 -05002476 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002477 return false;
2478 }
2479
Geoff Lang70d0f492015-12-10 17:45:46 -05002480 if (bufSize < 0)
2481 {
Jamie Madille0472f32018-11-27 16:32:45 -05002482 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002483 return false;
2484 }
2485
2486 if (!ValidateObjectPtrName(context, ptr))
2487 {
2488 return false;
2489 }
2490
Martin Radev9d901792016-07-15 15:58:58 +03002491 return true;
Geoff Lange102fee2015-12-10 11:23:30 -05002492}
2493
2494bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params)
2495{
2496 if (!context->getExtensions().debug)
2497 {
Jamie Madille0472f32018-11-27 16:32:45 -05002498 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002499 return false;
2500 }
2501
Geoff Lang70d0f492015-12-10 17:45:46 -05002502 // TODO: represent this in Context::getQueryParameterInfo.
2503 switch (pname)
2504 {
2505 case GL_DEBUG_CALLBACK_FUNCTION:
2506 case GL_DEBUG_CALLBACK_USER_PARAM:
2507 break;
2508
2509 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002510 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang70d0f492015-12-10 17:45:46 -05002511 return false;
2512 }
2513
Geoff Lange102fee2015-12-10 11:23:30 -05002514 return true;
2515}
Jamie Madillc29968b2016-01-20 11:17:23 -05002516
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002517bool ValidateGetPointervRobustANGLERobustANGLE(Context *context,
2518 GLenum pname,
2519 GLsizei bufSize,
2520 GLsizei *length,
2521 void **params)
2522{
2523 UNIMPLEMENTED();
2524 return false;
2525}
2526
Jamie Madillc29968b2016-01-20 11:17:23 -05002527bool ValidateBlitFramebufferANGLE(Context *context,
2528 GLint srcX0,
2529 GLint srcY0,
2530 GLint srcX1,
2531 GLint srcY1,
2532 GLint dstX0,
2533 GLint dstY0,
2534 GLint dstX1,
2535 GLint dstY1,
2536 GLbitfield mask,
2537 GLenum filter)
2538{
2539 if (!context->getExtensions().framebufferBlit)
2540 {
Jamie Madille0472f32018-11-27 16:32:45 -05002541 context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable);
Jamie Madillc29968b2016-01-20 11:17:23 -05002542 return false;
2543 }
2544
2545 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
2546 {
2547 // TODO(jmadill): Determine if this should be available on other implementations.
Jamie Madille0472f32018-11-27 16:32:45 -05002548 context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip);
Jamie Madillc29968b2016-01-20 11:17:23 -05002549 return false;
2550 }
2551
2552 if (filter == GL_LINEAR)
2553 {
Jamie Madille0472f32018-11-27 16:32:45 -05002554 context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear);
Jamie Madillc29968b2016-01-20 11:17:23 -05002555 return false;
2556 }
2557
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002558 Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
2559 Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002560
2561 if (mask & GL_COLOR_BUFFER_BIT)
2562 {
2563 const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer();
2564 const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer();
2565
2566 if (readColorAttachment && drawColorAttachment)
2567 {
2568 if (!(readColorAttachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002569 readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002570 readColorAttachment->type() != GL_RENDERBUFFER &&
2571 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2572 {
Jamie Madill610640f2018-11-21 17:28:41 -05002573 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002574 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002575 return false;
2576 }
2577
Geoff Langa15472a2015-08-11 11:48:03 -04002578 for (size_t drawbufferIdx = 0;
2579 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002580 {
Geoff Langa15472a2015-08-11 11:48:03 -04002581 const FramebufferAttachment *attachment =
2582 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2583 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002584 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002585 if (!(attachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002586 attachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002587 attachment->type() != GL_RENDERBUFFER &&
2588 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2589 {
Jamie Madill610640f2018-11-21 17:28:41 -05002590 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002591 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002592 return false;
2593 }
2594
2595 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002596 if (!Format::EquivalentForBlit(attachment->getFormat(),
2597 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002598 {
Jamie Madill610640f2018-11-21 17:28:41 -05002599 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002600 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002601 return false;
2602 }
2603 }
2604 }
2605
Jamie Madill427064d2018-04-13 16:20:34 -04002606 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002607 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002608 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2609 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2610 {
Jamie Madill610640f2018-11-21 17:28:41 -05002611 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002612 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002613 return false;
2614 }
2615 }
2616 }
2617
2618 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2619 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2620 for (size_t i = 0; i < 2; i++)
2621 {
2622 if (mask & masks[i])
2623 {
2624 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002625 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002626 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002627 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002628
2629 if (readBuffer && drawBuffer)
2630 {
2631 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2632 dstX0, dstY0, dstX1, dstY1))
2633 {
2634 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002635 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002636 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002637 return false;
2638 }
2639
2640 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2641 {
Jamie Madill610640f2018-11-21 17:28:41 -05002642 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002643 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002644 return false;
2645 }
2646 }
2647 }
2648 }
2649
2650 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2651 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002652}
Jamie Madillc29968b2016-01-20 11:17:23 -05002653
Jamie Madill5b772312018-03-08 20:28:32 -05002654bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002655{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002656 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002657 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002658
Jamie Madill427064d2018-04-13 16:20:34 -04002659 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002660 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002661 return false;
2662 }
2663
2664 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2665 {
Jamie Madille0472f32018-11-27 16:32:45 -05002666 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002667 return false;
2668 }
2669
Olli Etuaho94c91a92018-07-19 15:10:24 +03002670 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002671 {
2672 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2673 GL_SIGNED_NORMALIZED};
2674
Corentin Wallez59c41592017-07-11 13:19:54 -04002675 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002676 drawBufferIdx++)
2677 {
2678 if (!ValidateWebGLFramebufferAttachmentClearType(
2679 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2680 {
2681 return false;
2682 }
2683 }
2684 }
2685
Olli Etuaho94c91a92018-07-19 15:10:24 +03002686 if (extensions.multiview && extensions.disjointTimerQuery)
2687 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002688 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002689 Framebuffer *framebuffer = state.getDrawFramebuffer();
2690 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2691 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002692 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002693 return false;
2694 }
2695 }
2696
Jamie Madillc29968b2016-01-20 11:17:23 -05002697 return true;
2698}
2699
Jamie Madill5b772312018-03-08 20:28:32 -05002700bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002701{
2702 if (!context->getExtensions().drawBuffers)
2703 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002704 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002705 return false;
2706 }
2707
2708 return ValidateDrawBuffersBase(context, n, bufs);
2709}
2710
Jamie Madill73a84962016-02-12 09:27:23 -05002711bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002712 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002713 GLint level,
2714 GLint internalformat,
2715 GLsizei width,
2716 GLsizei height,
2717 GLint border,
2718 GLenum format,
2719 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002720 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002721{
Martin Radev1be913c2016-07-11 17:59:16 +03002722 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002723 {
2724 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002725 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002726 }
2727
Martin Radev1be913c2016-07-11 17:59:16 +03002728 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002729 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002730 0, 0, width, height, 1, border, format, type, -1,
2731 pixels);
2732}
2733
Brandon Jones416aaf92018-04-10 08:10:16 -07002734bool ValidateTexImage2DRobustANGLE(Context *context,
2735 TextureTarget target,
2736 GLint level,
2737 GLint internalformat,
2738 GLsizei width,
2739 GLsizei height,
2740 GLint border,
2741 GLenum format,
2742 GLenum type,
2743 GLsizei bufSize,
2744 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04002745{
2746 if (!ValidateRobustEntryPoint(context, bufSize))
2747 {
2748 return false;
2749 }
2750
2751 if (context->getClientMajorVersion() < 3)
2752 {
2753 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
2754 0, 0, width, height, border, format, type, bufSize,
2755 pixels);
2756 }
2757
2758 ASSERT(context->getClientMajorVersion() >= 3);
2759 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
2760 0, 0, width, height, 1, border, format, type, bufSize,
2761 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002762}
2763
2764bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002765 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002766 GLint level,
2767 GLint xoffset,
2768 GLint yoffset,
2769 GLsizei width,
2770 GLsizei height,
2771 GLenum format,
2772 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002773 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002774{
2775
Martin Radev1be913c2016-07-11 17:59:16 +03002776 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002777 {
2778 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002779 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002780 }
2781
Martin Radev1be913c2016-07-11 17:59:16 +03002782 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002783 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002784 yoffset, 0, width, height, 1, 0, format, type, -1,
2785 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002786}
2787
Geoff Langc52f6f12016-10-14 10:18:00 -04002788bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002789 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04002790 GLint level,
2791 GLint xoffset,
2792 GLint yoffset,
2793 GLsizei width,
2794 GLsizei height,
2795 GLenum format,
2796 GLenum type,
2797 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002798 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04002799{
2800 if (!ValidateRobustEntryPoint(context, bufSize))
2801 {
2802 return false;
2803 }
2804
2805 if (context->getClientMajorVersion() < 3)
2806 {
2807 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
2808 yoffset, width, height, 0, format, type, bufSize,
2809 pixels);
2810 }
2811
2812 ASSERT(context->getClientMajorVersion() >= 3);
2813 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
2814 yoffset, 0, width, height, 1, 0, format, type, bufSize,
2815 pixels);
2816}
2817
Jamie Madill73a84962016-02-12 09:27:23 -05002818bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002819 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002820 GLint level,
2821 GLenum internalformat,
2822 GLsizei width,
2823 GLsizei height,
2824 GLint border,
2825 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002826 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002827{
Martin Radev1be913c2016-07-11 17:59:16 +03002828 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002829 {
2830 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002831 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002832 {
2833 return false;
2834 }
2835 }
2836 else
2837 {
Martin Radev1be913c2016-07-11 17:59:16 +03002838 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002839 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002840 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002841 data))
2842 {
2843 return false;
2844 }
2845 }
2846
Geoff Langca271392017-04-05 12:30:00 -04002847 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04002848
2849 GLuint blockSize = 0;
2850 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002851 {
Jamie Madille0472f32018-11-27 16:32:45 -05002852 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002853 return false;
2854 }
2855
Jamie Madillca2ff382018-07-11 09:01:17 -04002856 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002857 {
Jamie Madille0472f32018-11-27 16:32:45 -05002858 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05002859 return false;
2860 }
2861
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002862 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002863 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002864 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002865 return false;
2866 }
2867
Jamie Madill73a84962016-02-12 09:27:23 -05002868 return true;
2869}
2870
Corentin Wallezb2931602017-04-11 15:58:57 -04002871bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002872 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002873 GLint level,
2874 GLenum internalformat,
2875 GLsizei width,
2876 GLsizei height,
2877 GLint border,
2878 GLsizei imageSize,
2879 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002880 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002881{
2882 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2883 {
2884 return false;
2885 }
2886
2887 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
2888 border, imageSize, data);
2889}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002890
Corentin Wallezb2931602017-04-11 15:58:57 -04002891bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002892 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002893 GLint level,
2894 GLint xoffset,
2895 GLint yoffset,
2896 GLsizei width,
2897 GLsizei height,
2898 GLenum format,
2899 GLsizei imageSize,
2900 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002901 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002902{
2903 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2904 {
2905 return false;
2906 }
2907
2908 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
2909 format, imageSize, data);
2910}
2911
Jamie Madill73a84962016-02-12 09:27:23 -05002912bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002913 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002914 GLint level,
2915 GLint xoffset,
2916 GLint yoffset,
2917 GLsizei width,
2918 GLsizei height,
2919 GLenum format,
2920 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002921 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002922{
Martin Radev1be913c2016-07-11 17:59:16 +03002923 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002924 {
2925 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04002926 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002927 {
2928 return false;
2929 }
2930 }
2931 else
2932 {
Martin Radev1be913c2016-07-11 17:59:16 +03002933 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002934 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04002935 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002936 data))
2937 {
2938 return false;
2939 }
2940 }
2941
Geoff Langca271392017-04-05 12:30:00 -04002942 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04002943 GLuint blockSize = 0;
2944 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002945 {
Jamie Madille0472f32018-11-27 16:32:45 -05002946 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002947 return false;
2948 }
2949
Jamie Madillca2ff382018-07-11 09:01:17 -04002950 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002951 {
Jamie Madille0472f32018-11-27 16:32:45 -05002952 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05002953 return false;
2954 }
2955
2956 return true;
2957}
2958
Corentin Wallez336129f2017-10-17 15:55:40 -04002959bool ValidateGetBufferPointervOES(Context *context,
2960 BufferBinding target,
2961 GLenum pname,
2962 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03002963{
Jamie Madillc3e37312018-11-30 15:25:39 -05002964 if (!context->getExtensions().mapBuffer)
2965 {
2966 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
2967 return false;
2968 }
2969
Geoff Lang496c02d2016-10-20 11:38:11 -07002970 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03002971}
2972
Corentin Wallez336129f2017-10-17 15:55:40 -04002973bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03002974{
2975 if (!context->getExtensions().mapBuffer)
2976 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002977 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03002978 return false;
2979 }
2980
Corentin Walleze4477002017-12-01 14:39:58 -05002981 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03002982 {
Jamie Madille0472f32018-11-27 16:32:45 -05002983 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03002984 return false;
2985 }
2986
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002987 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03002988
2989 if (buffer == nullptr)
2990 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002991 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03002992 return false;
2993 }
2994
2995 if (access != GL_WRITE_ONLY_OES)
2996 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002997 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03002998 return false;
2999 }
3000
3001 if (buffer->isMapped())
3002 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003003 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003004 return false;
3005 }
3006
Geoff Lang79f71042017-08-14 16:43:43 -04003007 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003008}
3009
Corentin Wallez336129f2017-10-17 15:55:40 -04003010bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003011{
3012 if (!context->getExtensions().mapBuffer)
3013 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003014 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003015 return false;
3016 }
3017
3018 return ValidateUnmapBufferBase(context, target);
3019}
3020
3021bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003022 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003023 GLintptr offset,
3024 GLsizeiptr length,
3025 GLbitfield access)
3026{
3027 if (!context->getExtensions().mapBufferRange)
3028 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003029 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003030 return false;
3031 }
3032
3033 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3034}
3035
Michael Spang7a8c3e52019-04-03 14:49:57 -04003036bool ValidateBufferStorageMemEXT(Context *context,
3037 TextureType target,
3038 GLsizeiptr size,
3039 GLuint memory,
3040 GLuint64 offset)
3041{
3042 if (!context->getExtensions().memoryObject)
3043 {
3044 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3045 return false;
3046 }
3047
3048 UNIMPLEMENTED();
3049 return false;
3050}
3051
3052bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects)
3053{
3054 if (!context->getExtensions().memoryObject)
3055 {
3056 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3057 return false;
3058 }
3059
Michael Spangfb201c52019-04-03 14:57:35 -04003060 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003061}
3062
3063bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects)
3064{
3065 if (!context->getExtensions().memoryObject)
3066 {
3067 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3068 return false;
3069 }
3070
Michael Spangfb201c52019-04-03 14:57:35 -04003071 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003072}
3073
3074bool ValidateGetMemoryObjectParameterivEXT(Context *context,
3075 GLuint memoryObject,
3076 GLenum pname,
3077 GLint *params)
3078{
3079 if (!context->getExtensions().memoryObject)
3080 {
3081 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3082 return false;
3083 }
3084
3085 UNIMPLEMENTED();
3086 return false;
3087}
3088
3089bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3090{
3091 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3092 {
3093 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3094 return false;
3095 }
3096
3097 UNIMPLEMENTED();
3098 return false;
3099}
3100
3101bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3102{
3103 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3104 {
3105 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3106 return false;
3107 }
3108
3109 UNIMPLEMENTED();
3110 return false;
3111}
3112
3113bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject)
3114{
3115 if (!context->getExtensions().memoryObject)
3116 {
3117 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3118 return false;
3119 }
3120
Michael Spangfb201c52019-04-03 14:57:35 -04003121 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003122}
3123
3124bool ValidateMemoryObjectParameterivEXT(Context *context,
3125 GLuint memoryObject,
3126 GLenum pname,
3127 const GLint *params)
3128{
3129 if (!context->getExtensions().memoryObject)
3130 {
3131 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3132 return false;
3133 }
3134
3135 UNIMPLEMENTED();
3136 return false;
3137}
3138
3139bool ValidateTexStorageMem2DEXT(Context *context,
3140 TextureType target,
3141 GLsizei levels,
3142 GLenum internalFormat,
3143 GLsizei width,
3144 GLsizei height,
3145 GLuint memory,
3146 GLuint64 offset)
3147{
3148 if (!context->getExtensions().memoryObject)
3149 {
3150 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3151 return false;
3152 }
3153
3154 UNIMPLEMENTED();
3155 return false;
3156}
3157
3158bool ValidateTexStorageMem3DEXT(Context *context,
3159 TextureType target,
3160 GLsizei levels,
3161 GLenum internalFormat,
3162 GLsizei width,
3163 GLsizei height,
3164 GLsizei depth,
3165 GLuint memory,
3166 GLuint64 offset)
3167{
3168 if (!context->getExtensions().memoryObject)
3169 {
3170 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3171 return false;
3172 }
3173
3174 UNIMPLEMENTED();
3175 return false;
3176}
3177
3178bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores)
3179{
3180 if (!context->getExtensions().semaphore)
3181 {
3182 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3183 return false;
3184 }
3185
3186 UNIMPLEMENTED();
3187 return false;
3188}
3189
3190bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores)
3191{
3192 if (!context->getExtensions().semaphore)
3193 {
3194 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3195 return false;
3196 }
3197
3198 UNIMPLEMENTED();
3199 return false;
3200}
3201
3202bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
3203 GLuint semaphore,
3204 GLenum pname,
3205 GLuint64 *params)
3206{
3207 if (!context->getExtensions().semaphore)
3208 {
3209 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3210 return false;
3211 }
3212
3213 UNIMPLEMENTED();
3214 return false;
3215}
3216
3217bool ValidateIsSemaphoreEXT(Context *context, GLuint semaphore)
3218{
3219 if (!context->getExtensions().semaphore)
3220 {
3221 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3222 return false;
3223 }
3224
3225 UNIMPLEMENTED();
3226 return false;
3227}
3228
3229bool ValidateSemaphoreParameterui64vEXT(Context *context,
3230 GLuint semaphore,
3231 GLenum pname,
3232 const GLuint64 *params)
3233{
3234 if (!context->getExtensions().semaphore)
3235 {
3236 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3237 return false;
3238 }
3239
3240 UNIMPLEMENTED();
3241 return false;
3242}
3243
3244bool ValidateSignalSemaphoreEXT(Context *context,
3245 GLuint semaphore,
3246 GLuint numBufferBarriers,
3247 const GLuint *buffers,
3248 GLuint numTextureBarriers,
3249 const GLuint *textures,
3250 const GLenum *dstLayouts)
3251{
3252 if (!context->getExtensions().semaphore)
3253 {
3254 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3255 return false;
3256 }
3257
3258 UNIMPLEMENTED();
3259 return false;
3260}
3261
3262bool ValidateWaitSemaphoreEXT(Context *context,
3263 GLuint semaphore,
3264 GLuint numBufferBarriers,
3265 const GLuint *buffers,
3266 GLuint numTextureBarriers,
3267 const GLuint *textures,
3268 const GLenum *srcLayouts)
3269{
3270 if (!context->getExtensions().semaphore)
3271 {
3272 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3273 return false;
3274 }
3275
3276 UNIMPLEMENTED();
3277 return false;
3278}
3279
Corentin Wallez336129f2017-10-17 15:55:40 -04003280bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003281{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003282 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003283 ASSERT(buffer != nullptr);
3284
3285 // Check if this buffer is currently being used as a transform feedback output buffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003286 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003287 if (transformFeedback != nullptr && transformFeedback->isActive())
3288 {
3289 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3290 {
3291 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3292 if (transformFeedbackBuffer.get() == buffer)
3293 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003294 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003295 return false;
3296 }
3297 }
3298 }
3299
James Darpiniane8a93c62018-01-04 18:02:24 -08003300 if (context->getExtensions().webglCompatibility &&
3301 buffer->isBoundForTransformFeedbackAndOtherUse())
3302 {
Jamie Madille0472f32018-11-27 16:32:45 -05003303 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003304 return false;
3305 }
3306
Geoff Lang79f71042017-08-14 16:43:43 -04003307 return true;
3308}
3309
Olli Etuaho4f667482016-03-30 15:56:35 +03003310bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003311 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003312 GLintptr offset,
3313 GLsizeiptr length)
3314{
3315 if (!context->getExtensions().mapBufferRange)
3316 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003317 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003318 return false;
3319 }
3320
3321 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3322}
3323
Geoff Langd8605522016-04-13 10:19:12 -04003324bool ValidateBindUniformLocationCHROMIUM(Context *context,
3325 GLuint program,
3326 GLint location,
3327 const GLchar *name)
3328{
3329 if (!context->getExtensions().bindUniformLocation)
3330 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003331 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003332 return false;
3333 }
3334
3335 Program *programObject = GetValidProgram(context, program);
3336 if (!programObject)
3337 {
3338 return false;
3339 }
3340
3341 if (location < 0)
3342 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003343 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003344 return false;
3345 }
3346
3347 const Caps &caps = context->getCaps();
3348 if (static_cast<size_t>(location) >=
3349 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3350 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003351 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003352 return false;
3353 }
3354
Geoff Langfc32e8b2017-05-31 14:16:59 -04003355 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3356 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003357 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003358 {
Jamie Madille0472f32018-11-27 16:32:45 -05003359 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003360 return false;
3361 }
3362
Geoff Langd8605522016-04-13 10:19:12 -04003363 if (strncmp(name, "gl_", 3) == 0)
3364 {
Jamie Madille0472f32018-11-27 16:32:45 -05003365 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003366 return false;
3367 }
3368
3369 return true;
3370}
3371
Jamie Madille2e406c2016-06-02 13:04:10 -04003372bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003373{
3374 if (!context->getExtensions().framebufferMixedSamples)
3375 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003376 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003377 return false;
3378 }
3379 switch (components)
3380 {
3381 case GL_RGB:
3382 case GL_RGBA:
3383 case GL_ALPHA:
3384 case GL_NONE:
3385 break;
3386 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003387 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003388 return false;
3389 }
3390
3391 return true;
3392}
3393
Sami Väisänene45e53b2016-05-25 10:36:04 +03003394// CHROMIUM_path_rendering
3395
Jamie Madill007530e2017-12-28 14:27:04 -05003396bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003397{
Jamie Madill007530e2017-12-28 14:27:04 -05003398 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003399 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003400 return false;
3401 }
Jamie Madill007530e2017-12-28 14:27:04 -05003402
Sami Väisänene45e53b2016-05-25 10:36:04 +03003403 if (matrix == nullptr)
3404 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003405 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003406 return false;
3407 }
Jamie Madill007530e2017-12-28 14:27:04 -05003408
Sami Väisänene45e53b2016-05-25 10:36:04 +03003409 return true;
3410}
3411
Jamie Madill007530e2017-12-28 14:27:04 -05003412bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003413{
Jamie Madill007530e2017-12-28 14:27:04 -05003414 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003415}
3416
Jamie Madill007530e2017-12-28 14:27:04 -05003417bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003418{
3419 if (!context->getExtensions().pathRendering)
3420 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003421 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003422 return false;
3423 }
3424
3425 // range = 0 is undefined in NV_path_rendering.
3426 // we add stricter semantic check here and require a non zero positive range.
3427 if (range <= 0)
3428 {
Jamie Madille0472f32018-11-27 16:32:45 -05003429 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003430 return false;
3431 }
3432
3433 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3434 {
Jamie Madille0472f32018-11-27 16:32:45 -05003435 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003436 return false;
3437 }
3438
3439 return true;
3440}
3441
Jamie Madill007530e2017-12-28 14:27:04 -05003442bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003443{
3444 if (!context->getExtensions().pathRendering)
3445 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003446 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003447 return false;
3448 }
3449
3450 // range = 0 is undefined in NV_path_rendering.
3451 // we add stricter semantic check here and require a non zero positive range.
3452 if (range <= 0)
3453 {
Jamie Madille0472f32018-11-27 16:32:45 -05003454 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003455 return false;
3456 }
3457
3458 angle::CheckedNumeric<std::uint32_t> checkedRange(path);
3459 checkedRange += range;
3460
3461 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3462 {
Jamie Madille0472f32018-11-27 16:32:45 -05003463 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003464 return false;
3465 }
3466 return true;
3467}
3468
Jamie Madill007530e2017-12-28 14:27:04 -05003469bool ValidatePathCommandsCHROMIUM(Context *context,
3470 GLuint path,
3471 GLsizei numCommands,
3472 const GLubyte *commands,
3473 GLsizei numCoords,
3474 GLenum coordType,
3475 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003476{
3477 if (!context->getExtensions().pathRendering)
3478 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003479 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003480 return false;
3481 }
Brandon Jones59770802018-04-02 13:18:42 -07003482 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003483 {
Jamie Madille0472f32018-11-27 16:32:45 -05003484 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003485 return false;
3486 }
3487
3488 if (numCommands < 0)
3489 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003490 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003491 return false;
3492 }
3493 else if (numCommands > 0)
3494 {
3495 if (!commands)
3496 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003497 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003498 return false;
3499 }
3500 }
3501
3502 if (numCoords < 0)
3503 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003504 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003505 return false;
3506 }
3507 else if (numCoords > 0)
3508 {
3509 if (!coords)
3510 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003511 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003512 return false;
3513 }
3514 }
3515
3516 std::uint32_t coordTypeSize = 0;
3517 switch (coordType)
3518 {
3519 case GL_BYTE:
3520 coordTypeSize = sizeof(GLbyte);
3521 break;
3522
3523 case GL_UNSIGNED_BYTE:
3524 coordTypeSize = sizeof(GLubyte);
3525 break;
3526
3527 case GL_SHORT:
3528 coordTypeSize = sizeof(GLshort);
3529 break;
3530
3531 case GL_UNSIGNED_SHORT:
3532 coordTypeSize = sizeof(GLushort);
3533 break;
3534
3535 case GL_FLOAT:
3536 coordTypeSize = sizeof(GLfloat);
3537 break;
3538
3539 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003540 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003541 return false;
3542 }
3543
3544 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3545 checkedSize += (coordTypeSize * numCoords);
3546 if (!checkedSize.IsValid())
3547 {
Jamie Madille0472f32018-11-27 16:32:45 -05003548 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003549 return false;
3550 }
3551
3552 // early return skips command data validation when it doesn't exist.
3553 if (!commands)
3554 return true;
3555
3556 GLsizei expectedNumCoords = 0;
3557 for (GLsizei i = 0; i < numCommands; ++i)
3558 {
3559 switch (commands[i])
3560 {
3561 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3562 break;
3563 case GL_MOVE_TO_CHROMIUM:
3564 case GL_LINE_TO_CHROMIUM:
3565 expectedNumCoords += 2;
3566 break;
3567 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3568 expectedNumCoords += 4;
3569 break;
3570 case GL_CUBIC_CURVE_TO_CHROMIUM:
3571 expectedNumCoords += 6;
3572 break;
3573 case GL_CONIC_CURVE_TO_CHROMIUM:
3574 expectedNumCoords += 5;
3575 break;
3576 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003577 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003578 return false;
3579 }
3580 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003581
Sami Väisänene45e53b2016-05-25 10:36:04 +03003582 if (expectedNumCoords != numCoords)
3583 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003584 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003585 return false;
3586 }
3587
3588 return true;
3589}
3590
Jamie Madill007530e2017-12-28 14:27:04 -05003591bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003592{
3593 if (!context->getExtensions().pathRendering)
3594 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003595 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003596 return false;
3597 }
Brandon Jones59770802018-04-02 13:18:42 -07003598 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003599 {
Jamie Madille0472f32018-11-27 16:32:45 -05003600 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003601 return false;
3602 }
3603
3604 switch (pname)
3605 {
3606 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3607 if (value < 0.0f)
3608 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003609 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003610 return false;
3611 }
3612 break;
3613 case GL_PATH_END_CAPS_CHROMIUM:
3614 switch (static_cast<GLenum>(value))
3615 {
3616 case GL_FLAT_CHROMIUM:
3617 case GL_SQUARE_CHROMIUM:
3618 case GL_ROUND_CHROMIUM:
3619 break;
3620 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003621 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003622 return false;
3623 }
3624 break;
3625 case GL_PATH_JOIN_STYLE_CHROMIUM:
3626 switch (static_cast<GLenum>(value))
3627 {
3628 case GL_MITER_REVERT_CHROMIUM:
3629 case GL_BEVEL_CHROMIUM:
3630 case GL_ROUND_CHROMIUM:
3631 break;
3632 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003633 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003634 return false;
3635 }
Nico Weber41b072b2018-02-09 10:01:32 -05003636 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03003637 case GL_PATH_MITER_LIMIT_CHROMIUM:
3638 if (value < 0.0f)
3639 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003640 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003641 return false;
3642 }
3643 break;
3644
3645 case GL_PATH_STROKE_BOUND_CHROMIUM:
3646 // no errors, only clamping.
3647 break;
3648
3649 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003650 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003651 return false;
3652 }
3653 return true;
3654}
3655
Jamie Madill007530e2017-12-28 14:27:04 -05003656bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value)
3657{
3658 // TODO(jmadill): Use proper clamping cast.
3659 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
3660}
3661
3662bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003663{
3664 if (!context->getExtensions().pathRendering)
3665 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003666 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003667 return false;
3668 }
3669
Brandon Jones59770802018-04-02 13:18:42 -07003670 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003671 {
Jamie Madille0472f32018-11-27 16:32:45 -05003672 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003673 return false;
3674 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003675
Sami Väisänene45e53b2016-05-25 10:36:04 +03003676 if (!value)
3677 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003678 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003679 return false;
3680 }
3681
3682 switch (pname)
3683 {
3684 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3685 case GL_PATH_END_CAPS_CHROMIUM:
3686 case GL_PATH_JOIN_STYLE_CHROMIUM:
3687 case GL_PATH_MITER_LIMIT_CHROMIUM:
3688 case GL_PATH_STROKE_BOUND_CHROMIUM:
3689 break;
3690
3691 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003692 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003693 return false;
3694 }
3695
3696 return true;
3697}
3698
Jamie Madill007530e2017-12-28 14:27:04 -05003699bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value)
3700{
3701 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
3702 reinterpret_cast<GLfloat *>(value));
3703}
3704
3705bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003706{
3707 if (!context->getExtensions().pathRendering)
3708 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003709 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003710 return false;
3711 }
3712
3713 switch (func)
3714 {
3715 case GL_NEVER:
3716 case GL_ALWAYS:
3717 case GL_LESS:
3718 case GL_LEQUAL:
3719 case GL_EQUAL:
3720 case GL_GEQUAL:
3721 case GL_GREATER:
3722 case GL_NOTEQUAL:
3723 break;
3724 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003725 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003726 return false;
3727 }
3728
3729 return true;
3730}
3731
3732// Note that the spec specifies that for the path drawing commands
3733// if the path object is not an existing path object the command
3734// does nothing and no error is generated.
3735// However if the path object exists but has not been specified any
3736// commands then an error is generated.
3737
Jamie Madill007530e2017-12-28 14:27:04 -05003738bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003739{
3740 if (!context->getExtensions().pathRendering)
3741 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003742 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003743 return false;
3744 }
Brandon Jones59770802018-04-02 13:18:42 -07003745 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003746 {
Jamie Madille0472f32018-11-27 16:32:45 -05003747 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003748 return false;
3749 }
3750
3751 switch (fillMode)
3752 {
3753 case GL_COUNT_UP_CHROMIUM:
3754 case GL_COUNT_DOWN_CHROMIUM:
3755 break;
3756 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003757 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003758 return false;
3759 }
3760
3761 if (!isPow2(mask + 1))
3762 {
Jamie Madille0472f32018-11-27 16:32:45 -05003763 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003764 return false;
3765 }
3766
3767 return true;
3768}
3769
Jamie Madill007530e2017-12-28 14:27:04 -05003770bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003771{
3772 if (!context->getExtensions().pathRendering)
3773 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003774 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003775 return false;
3776 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003777
Brandon Jones59770802018-04-02 13:18:42 -07003778 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003779 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003780 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003781 return false;
3782 }
3783
3784 return true;
3785}
3786
Jamie Madill007530e2017-12-28 14:27:04 -05003787bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003788{
3789 if (!context->getExtensions().pathRendering)
3790 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003791 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003792 return false;
3793 }
Brandon Jones59770802018-04-02 13:18:42 -07003794 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003795 {
Jamie Madille0472f32018-11-27 16:32:45 -05003796 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003797 return false;
3798 }
3799
3800 switch (coverMode)
3801 {
3802 case GL_CONVEX_HULL_CHROMIUM:
3803 case GL_BOUNDING_BOX_CHROMIUM:
3804 break;
3805 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003806 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003807 return false;
3808 }
3809 return true;
3810}
3811
Jamie Madill778bf092018-11-14 09:54:36 -05003812bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3813{
3814 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3815}
3816
3817bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3818{
3819 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3820}
3821
Jamie Madill007530e2017-12-28 14:27:04 -05003822bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
3823 GLuint path,
3824 GLenum fillMode,
3825 GLuint mask,
3826 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003827{
Jamie Madill007530e2017-12-28 14:27:04 -05003828 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
3829 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003830}
3831
Jamie Madill007530e2017-12-28 14:27:04 -05003832bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
3833 GLuint path,
3834 GLint reference,
3835 GLuint mask,
3836 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003837{
Jamie Madill007530e2017-12-28 14:27:04 -05003838 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
3839 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003840}
3841
Brandon Jonesd1049182018-03-28 10:02:20 -07003842bool ValidateIsPathCHROMIUM(Context *context, GLuint path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003843{
3844 if (!context->getExtensions().pathRendering)
3845 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003846 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003847 return false;
3848 }
3849 return true;
3850}
3851
Jamie Madill007530e2017-12-28 14:27:04 -05003852bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
3853 GLsizei numPaths,
3854 GLenum pathNameType,
3855 const void *paths,
3856 GLuint pathBase,
3857 GLenum coverMode,
3858 GLenum transformType,
3859 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003860{
3861 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3862 transformType, transformValues))
3863 return false;
3864
3865 switch (coverMode)
3866 {
3867 case GL_CONVEX_HULL_CHROMIUM:
3868 case GL_BOUNDING_BOX_CHROMIUM:
3869 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
3870 break;
3871 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003872 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03003873 return false;
3874 }
3875
3876 return true;
3877}
3878
Jamie Madill007530e2017-12-28 14:27:04 -05003879bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
3880 GLsizei numPaths,
3881 GLenum pathNameType,
3882 const void *paths,
3883 GLuint pathBase,
3884 GLenum coverMode,
3885 GLenum transformType,
3886 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003887{
3888 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3889 transformType, transformValues))
3890 return false;
3891
3892 switch (coverMode)
3893 {
3894 case GL_CONVEX_HULL_CHROMIUM:
3895 case GL_BOUNDING_BOX_CHROMIUM:
3896 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
3897 break;
3898 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003899 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03003900 return false;
3901 }
3902
3903 return true;
3904}
3905
Jamie Madill007530e2017-12-28 14:27:04 -05003906bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
3907 GLsizei numPaths,
3908 GLenum pathNameType,
3909 const void *paths,
3910 GLuint pathBase,
3911 GLenum fillMode,
3912 GLuint mask,
3913 GLenum transformType,
3914 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003915{
3916
3917 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3918 transformType, transformValues))
3919 return false;
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änend59ca052016-06-21 16:10:00 +03003928 return false;
3929 }
3930 if (!isPow2(mask + 1))
3931 {
Jamie Madille0472f32018-11-27 16:32:45 -05003932 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03003933 return false;
3934 }
3935 return true;
3936}
3937
Jamie Madill007530e2017-12-28 14:27:04 -05003938bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
3939 GLsizei numPaths,
3940 GLenum pathNameType,
3941 const void *paths,
3942 GLuint pathBase,
3943 GLint reference,
3944 GLuint mask,
3945 GLenum transformType,
3946 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003947{
3948 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3949 transformType, transformValues))
3950 return false;
3951
3952 // no more validation here.
3953
3954 return true;
3955}
3956
Jamie Madill007530e2017-12-28 14:27:04 -05003957bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
3958 GLsizei numPaths,
3959 GLenum pathNameType,
3960 const void *paths,
3961 GLuint pathBase,
3962 GLenum fillMode,
3963 GLuint mask,
3964 GLenum coverMode,
3965 GLenum transformType,
3966 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003967{
3968 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3969 transformType, transformValues))
3970 return false;
3971
3972 switch (coverMode)
3973 {
3974 case GL_CONVEX_HULL_CHROMIUM:
3975 case GL_BOUNDING_BOX_CHROMIUM:
3976 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
3977 break;
3978 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003979 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03003980 return false;
3981 }
3982
3983 switch (fillMode)
3984 {
3985 case GL_COUNT_UP_CHROMIUM:
3986 case GL_COUNT_DOWN_CHROMIUM:
3987 break;
3988 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003989 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03003990 return false;
3991 }
3992 if (!isPow2(mask + 1))
3993 {
Jamie Madille0472f32018-11-27 16:32:45 -05003994 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03003995 return false;
3996 }
3997
3998 return true;
3999}
4000
Jamie Madill007530e2017-12-28 14:27:04 -05004001bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4002 GLsizei numPaths,
4003 GLenum pathNameType,
4004 const void *paths,
4005 GLuint pathBase,
4006 GLint reference,
4007 GLuint mask,
4008 GLenum coverMode,
4009 GLenum transformType,
4010 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004011{
4012 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4013 transformType, transformValues))
4014 return false;
4015
4016 switch (coverMode)
4017 {
4018 case GL_CONVEX_HULL_CHROMIUM:
4019 case GL_BOUNDING_BOX_CHROMIUM:
4020 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4021 break;
4022 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004023 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004024 return false;
4025 }
4026
4027 return true;
4028}
4029
Jamie Madill007530e2017-12-28 14:27:04 -05004030bool ValidateBindFragmentInputLocationCHROMIUM(Context *context,
4031 GLuint program,
4032 GLint location,
4033 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004034{
4035 if (!context->getExtensions().pathRendering)
4036 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004037 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004038 return false;
4039 }
4040
4041 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4042 if (location >= MaxLocation)
4043 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004044 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004045 return false;
4046 }
4047
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004048 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004049 if (!programObject)
4050 {
Jamie Madille0472f32018-11-27 16:32:45 -05004051 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004052 return false;
4053 }
4054
4055 if (!name)
4056 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004057 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004058 return false;
4059 }
4060
4061 if (angle::BeginsWith(name, "gl_"))
4062 {
Jamie Madille0472f32018-11-27 16:32:45 -05004063 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004064 return false;
4065 }
4066
4067 return true;
4068}
4069
Jamie Madill007530e2017-12-28 14:27:04 -05004070bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
4071 GLuint program,
4072 GLint location,
4073 GLenum genMode,
4074 GLint components,
4075 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004076{
4077 if (!context->getExtensions().pathRendering)
4078 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004079 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004080 return false;
4081 }
4082
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004083 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004084 if (!programObject || programObject->isFlaggedForDeletion())
4085 {
Jamie Madille0472f32018-11-27 16:32:45 -05004086 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004087 return false;
4088 }
4089
4090 if (!programObject->isLinked())
4091 {
Jamie Madille0472f32018-11-27 16:32:45 -05004092 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004093 return false;
4094 }
4095
4096 switch (genMode)
4097 {
4098 case GL_NONE:
4099 if (components != 0)
4100 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004101 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004102 return false;
4103 }
4104 break;
4105
4106 case GL_OBJECT_LINEAR_CHROMIUM:
4107 case GL_EYE_LINEAR_CHROMIUM:
4108 case GL_CONSTANT_CHROMIUM:
4109 if (components < 1 || components > 4)
4110 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004111 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004112 return false;
4113 }
4114 if (!coeffs)
4115 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004116 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004117 return false;
4118 }
4119 break;
4120
4121 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004122 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004123 return false;
4124 }
4125
4126 // If the location is -1 then the command is silently ignored
4127 // and no further validation is needed.
4128 if (location == -1)
4129 return true;
4130
jchen103fd614d2018-08-13 12:21:58 +08004131 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004132
4133 if (!binding.valid)
4134 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004135 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004136 return false;
4137 }
4138
4139 if (binding.type != GL_NONE)
4140 {
4141 GLint expectedComponents = 0;
4142 switch (binding.type)
4143 {
4144 case GL_FLOAT:
4145 expectedComponents = 1;
4146 break;
4147 case GL_FLOAT_VEC2:
4148 expectedComponents = 2;
4149 break;
4150 case GL_FLOAT_VEC3:
4151 expectedComponents = 3;
4152 break;
4153 case GL_FLOAT_VEC4:
4154 expectedComponents = 4;
4155 break;
4156 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004157 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004158 return false;
4159 }
4160 if (expectedComponents != components && genMode != GL_NONE)
4161 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004162 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004163 return false;
4164 }
4165 }
4166 return true;
4167}
4168
Geoff Lang97073d12016-04-20 10:42:34 -07004169bool ValidateCopyTextureCHROMIUM(Context *context,
4170 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004171 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004172 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004173 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004174 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004175 GLint internalFormat,
4176 GLenum destType,
4177 GLboolean unpackFlipY,
4178 GLboolean unpackPremultiplyAlpha,
4179 GLboolean unpackUnmultiplyAlpha)
4180{
4181 if (!context->getExtensions().copyTexture)
4182 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004183 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004184 return false;
4185 }
4186
Geoff Lang4f0e0032017-05-01 16:04:35 -04004187 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004188 if (source == nullptr)
4189 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004190 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004191 return false;
4192 }
4193
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004194 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004195 {
Jamie Madille0472f32018-11-27 16:32:45 -05004196 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004197 return false;
4198 }
4199
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004200 TextureType sourceType = source->getType();
4201 ASSERT(sourceType != TextureType::CubeMap);
4202 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004203
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004204 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004205 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004206 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004207 return false;
4208 }
4209
Geoff Lang4f0e0032017-05-01 16:04:35 -04004210 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4211 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4212 if (sourceWidth == 0 || sourceHeight == 0)
4213 {
Jamie Madille0472f32018-11-27 16:32:45 -05004214 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004215 return false;
4216 }
4217
4218 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4219 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004220 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004221 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004222 return false;
4223 }
4224
Geoff Lang63458a32017-10-30 15:16:53 -04004225 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4226 {
Jamie Madille0472f32018-11-27 16:32:45 -05004227 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004228 return false;
4229 }
4230
Geoff Lang4f0e0032017-05-01 16:04:35 -04004231 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004232 if (dest == nullptr)
4233 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004234 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004235 return false;
4236 }
4237
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004238 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004239 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004240 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004241 return false;
4242 }
4243
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004244 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004245 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004246 {
Jamie Madille0472f32018-11-27 16:32:45 -05004247 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004248 return false;
4249 }
4250
Geoff Lang97073d12016-04-20 10:42:34 -07004251 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4252 {
Geoff Lang97073d12016-04-20 10:42:34 -07004253 return false;
4254 }
4255
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004256 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004257 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004258 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004259 return false;
4260 }
4261
Geoff Lang97073d12016-04-20 10:42:34 -07004262 if (dest->getImmutableFormat())
4263 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004264 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004265 return false;
4266 }
4267
4268 return true;
4269}
4270
4271bool ValidateCopySubTextureCHROMIUM(Context *context,
4272 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004273 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004274 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004275 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004276 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004277 GLint xoffset,
4278 GLint yoffset,
4279 GLint x,
4280 GLint y,
4281 GLsizei width,
4282 GLsizei height,
4283 GLboolean unpackFlipY,
4284 GLboolean unpackPremultiplyAlpha,
4285 GLboolean unpackUnmultiplyAlpha)
4286{
4287 if (!context->getExtensions().copyTexture)
4288 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004289 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004290 return false;
4291 }
4292
Geoff Lang4f0e0032017-05-01 16:04:35 -04004293 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004294 if (source == nullptr)
4295 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004296 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004297 return false;
4298 }
4299
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004300 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004301 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004302 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004303 return false;
4304 }
4305
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004306 TextureType sourceType = source->getType();
4307 ASSERT(sourceType != TextureType::CubeMap);
4308 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004309
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004310 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004311 {
Jamie Madille0472f32018-11-27 16:32:45 -05004312 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004313 return false;
4314 }
4315
4316 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4317 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004318 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004319 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004320 return false;
4321 }
4322
4323 if (x < 0 || y < 0)
4324 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004325 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004326 return false;
4327 }
4328
4329 if (width < 0 || height < 0)
4330 {
Jamie Madille0472f32018-11-27 16:32:45 -05004331 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004332 return false;
4333 }
4334
Geoff Lang4f0e0032017-05-01 16:04:35 -04004335 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4336 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004337 {
Jamie Madille0472f32018-11-27 16:32:45 -05004338 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004339 return false;
4340 }
4341
Geoff Lang4f0e0032017-05-01 16:04:35 -04004342 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4343 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004344 {
Jamie Madille0472f32018-11-27 16:32:45 -05004345 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004346 return false;
4347 }
4348
Geoff Lang63458a32017-10-30 15:16:53 -04004349 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4350 {
Jamie Madille0472f32018-11-27 16:32:45 -05004351 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004352 return false;
4353 }
4354
Geoff Lang4f0e0032017-05-01 16:04:35 -04004355 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004356 if (dest == nullptr)
4357 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004358 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004359 return false;
4360 }
4361
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004362 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004363 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004364 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004365 return false;
4366 }
4367
Brandon Jones28783792018-03-05 09:37:32 -08004368 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4369 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004370 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004371 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004372 return false;
4373 }
4374
Geoff Lang4f0e0032017-05-01 16:04:35 -04004375 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4376 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004377 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004378 return false;
4379 }
4380
4381 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4382 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004383 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004384 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004385 return false;
4386 }
4387
4388 if (xoffset < 0 || yoffset < 0)
4389 {
Jamie Madille0472f32018-11-27 16:32:45 -05004390 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004391 return false;
4392 }
4393
Geoff Lang4f0e0032017-05-01 16:04:35 -04004394 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4395 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004396 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004397 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004398 return false;
4399 }
4400
4401 return true;
4402}
4403
Geoff Lang47110bf2016-04-20 11:13:22 -07004404bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId)
4405{
4406 if (!context->getExtensions().copyCompressedTexture)
4407 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004408 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004409 return false;
4410 }
4411
4412 const gl::Texture *source = context->getTexture(sourceId);
4413 if (source == nullptr)
4414 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004415 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004416 return false;
4417 }
4418
Corentin Wallez99d492c2018-02-27 15:17:10 -05004419 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004420 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004421 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004422 return false;
4423 }
4424
Corentin Wallez99d492c2018-02-27 15:17:10 -05004425 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4426 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004427 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004428 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004429 return false;
4430 }
4431
Corentin Wallez99d492c2018-02-27 15:17:10 -05004432 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004433 if (!sourceFormat.info->compressed)
4434 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004435 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004436 return false;
4437 }
4438
4439 const gl::Texture *dest = context->getTexture(destId);
4440 if (dest == nullptr)
4441 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004442 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004443 return false;
4444 }
4445
Corentin Wallez99d492c2018-02-27 15:17:10 -05004446 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004447 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004448 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004449 return false;
4450 }
4451
4452 if (dest->getImmutableFormat())
4453 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004454 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004455 return false;
4456 }
4457
4458 return true;
4459}
4460
Jiawei Shao385b3e02018-03-21 09:43:28 +08004461bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004462{
4463 switch (type)
4464 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004465 case ShaderType::Vertex:
4466 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004467 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004468
Jiawei Shao385b3e02018-03-21 09:43:28 +08004469 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004470 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004471 {
Jamie Madille0472f32018-11-27 16:32:45 -05004472 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004473 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004474 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004475 break;
4476
Jiawei Shao385b3e02018-03-21 09:43:28 +08004477 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004478 if (!context->getExtensions().geometryShader)
4479 {
Jamie Madille0472f32018-11-27 16:32:45 -05004480 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004481 return false;
4482 }
4483 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004484 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004485 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004486 return false;
4487 }
Jamie Madill29639852016-09-02 15:00:09 -04004488
4489 return true;
4490}
4491
Jamie Madill5b772312018-03-08 20:28:32 -05004492bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004493 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004494 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004495 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004496 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004497{
4498 if (size < 0)
4499 {
Jamie Madille0472f32018-11-27 16:32:45 -05004500 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004501 return false;
4502 }
4503
4504 switch (usage)
4505 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004506 case BufferUsage::StreamDraw:
4507 case BufferUsage::StaticDraw:
4508 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004509 break;
4510
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004511 case BufferUsage::StreamRead:
4512 case BufferUsage::StaticRead:
4513 case BufferUsage::DynamicRead:
4514 case BufferUsage::StreamCopy:
4515 case BufferUsage::StaticCopy:
4516 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004517 if (context->getClientMajorVersion() < 3)
4518 {
Jamie Madille0472f32018-11-27 16:32:45 -05004519 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004520 return false;
4521 }
4522 break;
4523
4524 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004525 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004526 return false;
4527 }
4528
Corentin Walleze4477002017-12-01 14:39:58 -05004529 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004530 {
Jamie Madille0472f32018-11-27 16:32:45 -05004531 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004532 return false;
4533 }
4534
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004535 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004536
4537 if (!buffer)
4538 {
Jamie Madille0472f32018-11-27 16:32:45 -05004539 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004540 return false;
4541 }
4542
James Darpiniane8a93c62018-01-04 18:02:24 -08004543 if (context->getExtensions().webglCompatibility &&
4544 buffer->isBoundForTransformFeedbackAndOtherUse())
4545 {
Jamie Madille0472f32018-11-27 16:32:45 -05004546 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004547 return false;
4548 }
4549
Jamie Madill29639852016-09-02 15:00:09 -04004550 return true;
4551}
4552
Jamie Madill5b772312018-03-08 20:28:32 -05004553bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004554 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004555 GLintptr offset,
4556 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004557 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004558{
Brandon Jones6cad5662017-06-14 13:25:13 -07004559 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004560 {
Jamie Madille0472f32018-11-27 16:32:45 -05004561 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004562 return false;
4563 }
4564
4565 if (offset < 0)
4566 {
Jamie Madille0472f32018-11-27 16:32:45 -05004567 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004568 return false;
4569 }
4570
Corentin Walleze4477002017-12-01 14:39:58 -05004571 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004572 {
Jamie Madille0472f32018-11-27 16:32:45 -05004573 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004574 return false;
4575 }
4576
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004577 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004578
4579 if (!buffer)
4580 {
Jamie Madille0472f32018-11-27 16:32:45 -05004581 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004582 return false;
4583 }
4584
4585 if (buffer->isMapped())
4586 {
Jamie Madille0472f32018-11-27 16:32:45 -05004587 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004588 return false;
4589 }
4590
James Darpiniane8a93c62018-01-04 18:02:24 -08004591 if (context->getExtensions().webglCompatibility &&
4592 buffer->isBoundForTransformFeedbackAndOtherUse())
4593 {
Jamie Madille0472f32018-11-27 16:32:45 -05004594 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004595 return false;
4596 }
4597
Jamie Madill29639852016-09-02 15:00:09 -04004598 // Check for possible overflow of size + offset
4599 angle::CheckedNumeric<size_t> checkedSize(size);
4600 checkedSize += offset;
4601 if (!checkedSize.IsValid())
4602 {
Jamie Madille0472f32018-11-27 16:32:45 -05004603 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004604 return false;
4605 }
4606
4607 if (size + offset > buffer->getSize())
4608 {
Jamie Madille0472f32018-11-27 16:32:45 -05004609 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004610 return false;
4611 }
4612
Martin Radev4c4c8e72016-08-04 12:25:34 +03004613 return true;
4614}
4615
Geoff Lang111a99e2017-10-17 10:58:41 -04004616bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04004617{
Geoff Langc339c4e2016-11-29 10:37:36 -05004618 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04004619 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004620 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04004621 return false;
4622 }
4623
Geoff Lang111a99e2017-10-17 10:58:41 -04004624 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04004625 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004626 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04004627 return false;
4628 }
4629
4630 return true;
4631}
4632
Jamie Madill5b772312018-03-08 20:28:32 -05004633bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04004634{
Lingfeng Yang038dd532018-03-29 17:31:52 -07004635 if (context->getClientMajorVersion() < 2)
4636 {
4637 return ValidateMultitextureUnit(context, texture);
4638 }
4639
Jamie Madillef300b12016-10-07 15:12:09 -04004640 if (texture < GL_TEXTURE0 ||
4641 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
4642 {
Jamie Madille0472f32018-11-27 16:32:45 -05004643 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04004644 return false;
4645 }
4646
4647 return true;
4648}
4649
Jamie Madill5b772312018-03-08 20:28:32 -05004650bool ValidateAttachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillef300b12016-10-07 15:12:09 -04004651{
4652 Program *programObject = GetValidProgram(context, program);
4653 if (!programObject)
4654 {
4655 return false;
4656 }
4657
4658 Shader *shaderObject = GetValidShader(context, shader);
4659 if (!shaderObject)
4660 {
4661 return false;
4662 }
4663
Jiawei Shao385b3e02018-03-21 09:43:28 +08004664 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04004665 {
Jamie Madille0472f32018-11-27 16:32:45 -05004666 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08004667 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04004668 }
4669
4670 return true;
4671}
4672
Jamie Madill5b772312018-03-08 20:28:32 -05004673bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004674{
4675 if (index >= MAX_VERTEX_ATTRIBS)
4676 {
Jamie Madille0472f32018-11-27 16:32:45 -05004677 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004678 return false;
4679 }
4680
4681 if (strncmp(name, "gl_", 3) == 0)
4682 {
Jamie Madille0472f32018-11-27 16:32:45 -05004683 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004684 return false;
4685 }
4686
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004687 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04004688 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004689 const size_t length = strlen(name);
4690
4691 if (!IsValidESSLString(name, length))
4692 {
4693 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
4694 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05004695 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004696 return false;
4697 }
4698
4699 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
4700 {
4701 return false;
4702 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04004703 }
4704
Jamie Madill01a80ee2016-11-07 12:06:18 -05004705 return GetValidProgram(context, program) != nullptr;
4706}
4707
Jamie Madill5b772312018-03-08 20:28:32 -05004708bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004709{
Geoff Lange8afa902017-09-27 15:00:43 -04004710 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05004711 {
Jamie Madille0472f32018-11-27 16:32:45 -05004712 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004713 return false;
4714 }
4715
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004716 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004717 !context->isFramebufferGenerated(framebuffer))
4718 {
Jamie Madille0472f32018-11-27 16:32:45 -05004719 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004720 return false;
4721 }
4722
4723 return true;
4724}
4725
Jamie Madill5b772312018-03-08 20:28:32 -05004726bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004727{
4728 if (target != GL_RENDERBUFFER)
4729 {
Jamie Madille0472f32018-11-27 16:32:45 -05004730 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004731 return false;
4732 }
4733
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004734 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004735 !context->isRenderbufferGenerated(renderbuffer))
4736 {
Jamie Madille0472f32018-11-27 16:32:45 -05004737 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004738 return false;
4739 }
4740
4741 return true;
4742}
4743
Jamie Madill5b772312018-03-08 20:28:32 -05004744static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004745{
4746 switch (mode)
4747 {
4748 case GL_FUNC_ADD:
4749 case GL_FUNC_SUBTRACT:
4750 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04004751 return true;
4752
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004753 case GL_MIN:
4754 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04004755 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004756
4757 default:
4758 return false;
4759 }
4760}
4761
Jamie Madill5b772312018-03-08 20:28:32 -05004762bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004763{
4764 return true;
4765}
4766
Jamie Madill5b772312018-03-08 20:28:32 -05004767bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004768{
Geoff Lang50cac572017-09-26 17:37:43 -04004769 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004770 {
Jamie Madille0472f32018-11-27 16:32:45 -05004771 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004772 return false;
4773 }
4774
4775 return true;
4776}
4777
Jamie Madill5b772312018-03-08 20:28:32 -05004778bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004779{
Geoff Lang50cac572017-09-26 17:37:43 -04004780 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004781 {
Jamie Madille0472f32018-11-27 16:32:45 -05004782 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004783 return false;
4784 }
4785
Geoff Lang50cac572017-09-26 17:37:43 -04004786 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004787 {
Jamie Madille0472f32018-11-27 16:32:45 -05004788 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004789 return false;
4790 }
4791
4792 return true;
4793}
4794
Jamie Madill5b772312018-03-08 20:28:32 -05004795bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004796{
4797 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
4798}
4799
Jamie Madill5b772312018-03-08 20:28:32 -05004800bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004801 GLenum srcRGB,
4802 GLenum dstRGB,
4803 GLenum srcAlpha,
4804 GLenum dstAlpha)
4805{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004806 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004807 {
Jamie Madille0472f32018-11-27 16:32:45 -05004808 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004809 return false;
4810 }
4811
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004812 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004813 {
Jamie Madille0472f32018-11-27 16:32:45 -05004814 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004815 return false;
4816 }
4817
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004818 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004819 {
Jamie Madille0472f32018-11-27 16:32:45 -05004820 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004821 return false;
4822 }
4823
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004824 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004825 {
Jamie Madille0472f32018-11-27 16:32:45 -05004826 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004827 return false;
4828 }
4829
Frank Henigman146e8a12017-03-02 23:22:37 -05004830 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
4831 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004832 {
4833 bool constantColorUsed =
4834 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
4835 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
4836
4837 bool constantAlphaUsed =
4838 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
4839 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
4840
4841 if (constantColorUsed && constantAlphaUsed)
4842 {
Frank Henigman146e8a12017-03-02 23:22:37 -05004843 if (context->getExtensions().webglCompatibility)
4844 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004845 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
4846 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05004847 }
Jamie Madillc3e37312018-11-30 15:25:39 -05004848
4849 WARN() << kConstantColorAlphaLimitation;
4850 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004851 return false;
4852 }
4853 }
4854
4855 return true;
4856}
4857
Geoff Langc339c4e2016-11-29 10:37:36 -05004858bool ValidateGetString(Context *context, GLenum name)
4859{
4860 switch (name)
4861 {
4862 case GL_VENDOR:
4863 case GL_RENDERER:
4864 case GL_VERSION:
4865 case GL_SHADING_LANGUAGE_VERSION:
4866 case GL_EXTENSIONS:
4867 break;
4868
4869 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
4870 if (!context->getExtensions().requestExtension)
4871 {
Jamie Madille0472f32018-11-27 16:32:45 -05004872 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05004873 return false;
4874 }
4875 break;
4876
4877 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004878 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05004879 return false;
4880 }
4881
4882 return true;
4883}
4884
Jamie Madill5b772312018-03-08 20:28:32 -05004885bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05004886{
4887 if (width <= 0.0f || isNaN(width))
4888 {
Jamie Madille0472f32018-11-27 16:32:45 -05004889 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05004890 return false;
4891 }
4892
4893 return true;
4894}
4895
Jamie Madill5b772312018-03-08 20:28:32 -05004896bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05004897{
4898 if (context->getExtensions().webglCompatibility && zNear > zFar)
4899 {
Jamie Madille0472f32018-11-27 16:32:45 -05004900 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05004901 return false;
4902 }
4903
4904 return true;
4905}
4906
Jamie Madill5b772312018-03-08 20:28:32 -05004907bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05004908 GLenum target,
4909 GLenum internalformat,
4910 GLsizei width,
4911 GLsizei height)
4912{
4913 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
4914 height);
4915}
4916
Jamie Madill5b772312018-03-08 20:28:32 -05004917bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05004918 GLenum target,
4919 GLsizei samples,
4920 GLenum internalformat,
4921 GLsizei width,
4922 GLsizei height)
4923{
4924 if (!context->getExtensions().framebufferMultisample)
4925 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004926 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05004927 return false;
4928 }
4929
4930 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05004931 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05004932 // generated.
4933 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
4934 {
Jamie Madille0472f32018-11-27 16:32:45 -05004935 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05004936 return false;
4937 }
4938
4939 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
4940 // the specified storage. This is different than ES 3.0 in which a sample number higher
4941 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
4942 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
4943 if (context->getClientMajorVersion() >= 3)
4944 {
4945 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
4946 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
4947 {
Jamie Madille0472f32018-11-27 16:32:45 -05004948 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05004949 return false;
4950 }
4951 }
4952
4953 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
4954 width, height);
4955}
4956
Jamie Madill5b772312018-03-08 20:28:32 -05004957bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004958{
Geoff Lange8afa902017-09-27 15:00:43 -04004959 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04004960 {
Jamie Madille0472f32018-11-27 16:32:45 -05004961 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004962 return false;
4963 }
4964
4965 return true;
4966}
4967
Jamie Madill5b772312018-03-08 20:28:32 -05004968bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004969{
4970 return true;
4971}
4972
Jamie Madill5b772312018-03-08 20:28:32 -05004973bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004974{
4975 return true;
4976}
4977
Jamie Madill5b772312018-03-08 20:28:32 -05004978bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004979{
4980 return true;
4981}
4982
Jamie Madill5b772312018-03-08 20:28:32 -05004983bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004984 GLboolean red,
4985 GLboolean green,
4986 GLboolean blue,
4987 GLboolean alpha)
4988{
4989 return true;
4990}
4991
Jamie Madill5b772312018-03-08 20:28:32 -05004992bool ValidateCompileShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004993{
4994 return true;
4995}
4996
Jamie Madill5b772312018-03-08 20:28:32 -05004997bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004998{
4999 return true;
5000}
5001
Jamie Madill5b772312018-03-08 20:28:32 -05005002bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005003{
5004 switch (mode)
5005 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005006 case CullFaceMode::Front:
5007 case CullFaceMode::Back:
5008 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005009 break;
5010
5011 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005012 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005013 return false;
5014 }
5015
5016 return true;
5017}
5018
Jamie Madill5b772312018-03-08 20:28:32 -05005019bool ValidateDeleteProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005020{
5021 if (program == 0)
5022 {
5023 return false;
5024 }
5025
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005026 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005027 {
5028 if (context->getShader(program))
5029 {
Jamie Madille0472f32018-11-27 16:32:45 -05005030 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005031 return false;
5032 }
5033 else
5034 {
Jamie Madille0472f32018-11-27 16:32:45 -05005035 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005036 return false;
5037 }
5038 }
5039
5040 return true;
5041}
5042
Jamie Madill5b772312018-03-08 20:28:32 -05005043bool ValidateDeleteShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005044{
5045 if (shader == 0)
5046 {
5047 return false;
5048 }
5049
5050 if (!context->getShader(shader))
5051 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005052 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005053 {
Jamie Madille0472f32018-11-27 16:32:45 -05005054 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005055 return false;
5056 }
5057 else
5058 {
Jamie Madille0472f32018-11-27 16:32:45 -05005059 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005060 return false;
5061 }
5062 }
5063
5064 return true;
5065}
5066
Jamie Madill5b772312018-03-08 20:28:32 -05005067bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005068{
5069 switch (func)
5070 {
5071 case GL_NEVER:
5072 case GL_ALWAYS:
5073 case GL_LESS:
5074 case GL_LEQUAL:
5075 case GL_EQUAL:
5076 case GL_GREATER:
5077 case GL_GEQUAL:
5078 case GL_NOTEQUAL:
5079 break;
5080
5081 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005082 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005083 return false;
5084 }
5085
5086 return true;
5087}
5088
Jamie Madill5b772312018-03-08 20:28:32 -05005089bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005090{
5091 return true;
5092}
5093
Jamie Madill5b772312018-03-08 20:28:32 -05005094bool ValidateDetachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005095{
5096 Program *programObject = GetValidProgram(context, program);
5097 if (!programObject)
5098 {
5099 return false;
5100 }
5101
5102 Shader *shaderObject = GetValidShader(context, shader);
5103 if (!shaderObject)
5104 {
5105 return false;
5106 }
5107
Jiawei Shao385b3e02018-03-21 09:43:28 +08005108 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005109 if (attachedShader != shaderObject)
5110 {
Jamie Madille0472f32018-11-27 16:32:45 -05005111 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005112 return false;
5113 }
5114
5115 return true;
5116}
5117
Jamie Madill5b772312018-03-08 20:28:32 -05005118bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005119{
5120 if (index >= MAX_VERTEX_ATTRIBS)
5121 {
Jamie Madille0472f32018-11-27 16:32:45 -05005122 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005123 return false;
5124 }
5125
5126 return true;
5127}
5128
Jamie Madill5b772312018-03-08 20:28:32 -05005129bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005130{
5131 if (index >= MAX_VERTEX_ATTRIBS)
5132 {
Jamie Madille0472f32018-11-27 16:32:45 -05005133 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005134 return false;
5135 }
5136
5137 return true;
5138}
5139
Jamie Madill5b772312018-03-08 20:28:32 -05005140bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005141{
5142 return true;
5143}
5144
Jamie Madill5b772312018-03-08 20:28:32 -05005145bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005146{
5147 return true;
5148}
5149
Jamie Madill5b772312018-03-08 20:28:32 -05005150bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005151{
5152 switch (mode)
5153 {
5154 case GL_CW:
5155 case GL_CCW:
5156 break;
5157 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005158 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005159 return false;
5160 }
5161
5162 return true;
5163}
5164
Jamie Madill5b772312018-03-08 20:28:32 -05005165bool ValidateGetActiveAttrib(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005166 GLuint program,
5167 GLuint index,
5168 GLsizei bufsize,
5169 GLsizei *length,
5170 GLint *size,
5171 GLenum *type,
5172 GLchar *name)
5173{
5174 if (bufsize < 0)
5175 {
Jamie Madille0472f32018-11-27 16:32:45 -05005176 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005177 return false;
5178 }
5179
5180 Program *programObject = GetValidProgram(context, program);
5181
5182 if (!programObject)
5183 {
5184 return false;
5185 }
5186
5187 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5188 {
Jamie Madille0472f32018-11-27 16:32:45 -05005189 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005190 return false;
5191 }
5192
5193 return true;
5194}
5195
Jamie Madill5b772312018-03-08 20:28:32 -05005196bool ValidateGetActiveUniform(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005197 GLuint program,
5198 GLuint index,
5199 GLsizei bufsize,
5200 GLsizei *length,
5201 GLint *size,
5202 GLenum *type,
5203 GLchar *name)
5204{
5205 if (bufsize < 0)
5206 {
Jamie Madille0472f32018-11-27 16:32:45 -05005207 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005208 return false;
5209 }
5210
5211 Program *programObject = GetValidProgram(context, program);
5212
5213 if (!programObject)
5214 {
5215 return false;
5216 }
5217
5218 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5219 {
Jamie Madille0472f32018-11-27 16:32:45 -05005220 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005221 return false;
5222 }
5223
5224 return true;
5225}
5226
Jamie Madill5b772312018-03-08 20:28:32 -05005227bool ValidateGetAttachedShaders(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005228 GLuint program,
5229 GLsizei maxcount,
5230 GLsizei *count,
5231 GLuint *shaders)
5232{
5233 if (maxcount < 0)
5234 {
Jamie Madille0472f32018-11-27 16:32:45 -05005235 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005236 return false;
5237 }
5238
5239 Program *programObject = GetValidProgram(context, program);
5240
5241 if (!programObject)
5242 {
5243 return false;
5244 }
5245
5246 return true;
5247}
5248
Jamie Madill5b772312018-03-08 20:28:32 -05005249bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005250{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005251 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5252 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005253 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005254 {
Jamie Madille0472f32018-11-27 16:32:45 -05005255 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005256 return false;
5257 }
5258
Jamie Madillc1d770e2017-04-13 17:31:24 -04005259 Program *programObject = GetValidProgram(context, program);
5260
5261 if (!programObject)
5262 {
Jamie Madille0472f32018-11-27 16:32:45 -05005263 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005264 return false;
5265 }
5266
5267 if (!programObject->isLinked())
5268 {
Jamie Madille0472f32018-11-27 16:32:45 -05005269 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005270 return false;
5271 }
5272
5273 return true;
5274}
5275
Jamie Madill5b772312018-03-08 20:28:32 -05005276bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005277{
5278 GLenum nativeType;
5279 unsigned int numParams = 0;
5280 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5281}
5282
Jamie Madill5b772312018-03-08 20:28:32 -05005283bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005284{
5285 return true;
5286}
5287
Jamie Madill5b772312018-03-08 20:28:32 -05005288bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005289{
5290 GLenum nativeType;
5291 unsigned int numParams = 0;
5292 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5293}
5294
Jamie Madill5b772312018-03-08 20:28:32 -05005295bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005296{
5297 GLenum nativeType;
5298 unsigned int numParams = 0;
5299 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5300}
5301
Jamie Madill5b772312018-03-08 20:28:32 -05005302bool ValidateGetProgramInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005303 GLuint program,
5304 GLsizei bufsize,
5305 GLsizei *length,
5306 GLchar *infolog)
5307{
5308 if (bufsize < 0)
5309 {
Jamie Madille0472f32018-11-27 16:32:45 -05005310 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005311 return false;
5312 }
5313
5314 Program *programObject = GetValidProgram(context, program);
5315 if (!programObject)
5316 {
5317 return false;
5318 }
5319
5320 return true;
5321}
5322
Jamie Madill5b772312018-03-08 20:28:32 -05005323bool ValidateGetShaderInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005324 GLuint shader,
5325 GLsizei bufsize,
5326 GLsizei *length,
5327 GLchar *infolog)
5328{
5329 if (bufsize < 0)
5330 {
Jamie Madille0472f32018-11-27 16:32:45 -05005331 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005332 return false;
5333 }
5334
5335 Shader *shaderObject = GetValidShader(context, shader);
5336 if (!shaderObject)
5337 {
5338 return false;
5339 }
5340
5341 return true;
5342}
5343
Jamie Madill5b772312018-03-08 20:28:32 -05005344bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005345 GLenum shadertype,
5346 GLenum precisiontype,
5347 GLint *range,
5348 GLint *precision)
5349{
5350 switch (shadertype)
5351 {
5352 case GL_VERTEX_SHADER:
5353 case GL_FRAGMENT_SHADER:
5354 break;
5355 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005356 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005357 return false;
5358 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005359 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005360 return false;
5361 }
5362
5363 switch (precisiontype)
5364 {
5365 case GL_LOW_FLOAT:
5366 case GL_MEDIUM_FLOAT:
5367 case GL_HIGH_FLOAT:
5368 case GL_LOW_INT:
5369 case GL_MEDIUM_INT:
5370 case GL_HIGH_INT:
5371 break;
5372
5373 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005374 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005375 return false;
5376 }
5377
5378 return true;
5379}
5380
Jamie Madill5b772312018-03-08 20:28:32 -05005381bool ValidateGetShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005382 GLuint shader,
5383 GLsizei bufsize,
5384 GLsizei *length,
5385 GLchar *source)
5386{
5387 if (bufsize < 0)
5388 {
Jamie Madille0472f32018-11-27 16:32:45 -05005389 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005390 return false;
5391 }
5392
5393 Shader *shaderObject = GetValidShader(context, shader);
5394 if (!shaderObject)
5395 {
5396 return false;
5397 }
5398
5399 return true;
5400}
5401
Jamie Madill5b772312018-03-08 20:28:32 -05005402bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005403{
5404 if (strstr(name, "gl_") == name)
5405 {
5406 return false;
5407 }
5408
Geoff Langfc32e8b2017-05-31 14:16:59 -04005409 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5410 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005411 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005412 {
Jamie Madille0472f32018-11-27 16:32:45 -05005413 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005414 return false;
5415 }
5416
Jamie Madillc1d770e2017-04-13 17:31:24 -04005417 Program *programObject = GetValidProgram(context, program);
5418
5419 if (!programObject)
5420 {
5421 return false;
5422 }
5423
5424 if (!programObject->isLinked())
5425 {
Jamie Madille0472f32018-11-27 16:32:45 -05005426 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005427 return false;
5428 }
5429
5430 return true;
5431}
5432
Jamie Madill5b772312018-03-08 20:28:32 -05005433bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005434{
5435 switch (mode)
5436 {
5437 case GL_FASTEST:
5438 case GL_NICEST:
5439 case GL_DONT_CARE:
5440 break;
5441
5442 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005443 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005444 return false;
5445 }
5446
5447 switch (target)
5448 {
5449 case GL_GENERATE_MIPMAP_HINT:
5450 break;
5451
Geoff Lange7bd2182017-06-16 16:13:13 -04005452 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5453 if (context->getClientVersion() < ES_3_0 &&
5454 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005455 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005456 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005457 return false;
5458 }
5459 break;
5460
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005461 case GL_PERSPECTIVE_CORRECTION_HINT:
5462 case GL_POINT_SMOOTH_HINT:
5463 case GL_LINE_SMOOTH_HINT:
5464 case GL_FOG_HINT:
5465 if (context->getClientMajorVersion() >= 2)
5466 {
Jamie Madille0472f32018-11-27 16:32:45 -05005467 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005468 return false;
5469 }
5470 break;
5471
Jamie Madillc1d770e2017-04-13 17:31:24 -04005472 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005473 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005474 return false;
5475 }
5476
5477 return true;
5478}
5479
Jamie Madill5b772312018-03-08 20:28:32 -05005480bool ValidateIsBuffer(Context *context, GLuint buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005481{
5482 return true;
5483}
5484
Jamie Madill5b772312018-03-08 20:28:32 -05005485bool ValidateIsFramebuffer(Context *context, GLuint framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005486{
5487 return true;
5488}
5489
Jamie Madill5b772312018-03-08 20:28:32 -05005490bool ValidateIsProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005491{
5492 return true;
5493}
5494
Jamie Madill5b772312018-03-08 20:28:32 -05005495bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005496{
5497 return true;
5498}
5499
Jamie Madill5b772312018-03-08 20:28:32 -05005500bool ValidateIsShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005501{
5502 return true;
5503}
5504
Jamie Madill5b772312018-03-08 20:28:32 -05005505bool ValidateIsTexture(Context *context, GLuint texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005506{
5507 return true;
5508}
5509
Jamie Madill5b772312018-03-08 20:28:32 -05005510bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005511{
5512 if (context->getClientMajorVersion() < 3)
5513 {
5514 switch (pname)
5515 {
5516 case GL_UNPACK_IMAGE_HEIGHT:
5517 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005518 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005519 return false;
5520
5521 case GL_UNPACK_ROW_LENGTH:
5522 case GL_UNPACK_SKIP_ROWS:
5523 case GL_UNPACK_SKIP_PIXELS:
5524 if (!context->getExtensions().unpackSubimage)
5525 {
Jamie Madille0472f32018-11-27 16:32:45 -05005526 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005527 return false;
5528 }
5529 break;
5530
5531 case GL_PACK_ROW_LENGTH:
5532 case GL_PACK_SKIP_ROWS:
5533 case GL_PACK_SKIP_PIXELS:
5534 if (!context->getExtensions().packSubimage)
5535 {
Jamie Madille0472f32018-11-27 16:32:45 -05005536 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005537 return false;
5538 }
5539 break;
5540 }
5541 }
5542
5543 if (param < 0)
5544 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005545 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005546 return false;
5547 }
5548
5549 switch (pname)
5550 {
5551 case GL_UNPACK_ALIGNMENT:
5552 if (param != 1 && param != 2 && param != 4 && param != 8)
5553 {
Jamie Madille0472f32018-11-27 16:32:45 -05005554 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005555 return false;
5556 }
5557 break;
5558
5559 case GL_PACK_ALIGNMENT:
5560 if (param != 1 && param != 2 && param != 4 && param != 8)
5561 {
Jamie Madille0472f32018-11-27 16:32:45 -05005562 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005563 return false;
5564 }
5565 break;
5566
5567 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005568 if (!context->getExtensions().packReverseRowOrder)
5569 {
Jamie Madille0472f32018-11-27 16:32:45 -05005570 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005571 }
5572 break;
5573
Jamie Madillc1d770e2017-04-13 17:31:24 -04005574 case GL_UNPACK_ROW_LENGTH:
5575 case GL_UNPACK_IMAGE_HEIGHT:
5576 case GL_UNPACK_SKIP_IMAGES:
5577 case GL_UNPACK_SKIP_ROWS:
5578 case GL_UNPACK_SKIP_PIXELS:
5579 case GL_PACK_ROW_LENGTH:
5580 case GL_PACK_SKIP_ROWS:
5581 case GL_PACK_SKIP_PIXELS:
5582 break;
5583
5584 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005585 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005586 return false;
5587 }
5588
5589 return true;
5590}
5591
Jamie Madill5b772312018-03-08 20:28:32 -05005592bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005593{
5594 return true;
5595}
5596
Jamie Madill5b772312018-03-08 20:28:32 -05005597bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005598{
5599 return true;
5600}
5601
Jamie Madill5b772312018-03-08 20:28:32 -05005602bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005603{
5604 return true;
5605}
5606
Jamie Madill5b772312018-03-08 20:28:32 -05005607bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005608{
5609 if (width < 0 || height < 0)
5610 {
Jamie Madille0472f32018-11-27 16:32:45 -05005611 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005612 return false;
5613 }
5614
5615 return true;
5616}
5617
Jamie Madill5b772312018-03-08 20:28:32 -05005618bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005619 GLsizei n,
5620 const GLuint *shaders,
5621 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005622 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005623 GLsizei length)
5624{
5625 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
5626 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
5627 shaderBinaryFormats.end())
5628 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005629 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005630 return false;
5631 }
5632
5633 return true;
5634}
5635
Jamie Madill5b772312018-03-08 20:28:32 -05005636bool ValidateShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005637 GLuint shader,
5638 GLsizei count,
5639 const GLchar *const *string,
5640 const GLint *length)
5641{
5642 if (count < 0)
5643 {
Jamie Madille0472f32018-11-27 16:32:45 -05005644 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005645 return false;
5646 }
5647
Geoff Langfc32e8b2017-05-31 14:16:59 -04005648 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5649 // shader-related entry points
5650 if (context->getExtensions().webglCompatibility)
5651 {
5652 for (GLsizei i = 0; i < count; i++)
5653 {
Geoff Langcab92ee2017-07-19 17:32:07 -04005654 size_t len =
5655 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04005656
5657 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04005658 if (!IsValidESSLShaderSourceString(string[i], len,
5659 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005660 {
Jamie Madille0472f32018-11-27 16:32:45 -05005661 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005662 return false;
5663 }
5664 }
5665 }
5666
Jamie Madillc1d770e2017-04-13 17:31:24 -04005667 Shader *shaderObject = GetValidShader(context, shader);
5668 if (!shaderObject)
5669 {
5670 return false;
5671 }
5672
5673 return true;
5674}
5675
Jamie Madill5b772312018-03-08 20:28:32 -05005676bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005677{
5678 if (!IsValidStencilFunc(func))
5679 {
Jamie Madille0472f32018-11-27 16:32:45 -05005680 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005681 return false;
5682 }
5683
5684 return true;
5685}
5686
Jamie Madill5b772312018-03-08 20:28:32 -05005687bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005688{
5689 if (!IsValidStencilFace(face))
5690 {
Jamie Madille0472f32018-11-27 16:32:45 -05005691 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005692 return false;
5693 }
5694
5695 if (!IsValidStencilFunc(func))
5696 {
Jamie Madille0472f32018-11-27 16:32:45 -05005697 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005698 return false;
5699 }
5700
5701 return true;
5702}
5703
Jamie Madill5b772312018-03-08 20:28:32 -05005704bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005705{
5706 return true;
5707}
5708
Jamie Madill5b772312018-03-08 20:28:32 -05005709bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005710{
5711 if (!IsValidStencilFace(face))
5712 {
Jamie Madille0472f32018-11-27 16:32:45 -05005713 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005714 return false;
5715 }
5716
5717 return true;
5718}
5719
Jamie Madill5b772312018-03-08 20:28:32 -05005720bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005721{
5722 if (!IsValidStencilOp(fail))
5723 {
Jamie Madille0472f32018-11-27 16:32:45 -05005724 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005725 return false;
5726 }
5727
5728 if (!IsValidStencilOp(zfail))
5729 {
Jamie Madille0472f32018-11-27 16:32:45 -05005730 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005731 return false;
5732 }
5733
5734 if (!IsValidStencilOp(zpass))
5735 {
Jamie Madille0472f32018-11-27 16:32:45 -05005736 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005737 return false;
5738 }
5739
5740 return true;
5741}
5742
Jamie Madill5b772312018-03-08 20:28:32 -05005743bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005744 GLenum face,
5745 GLenum fail,
5746 GLenum zfail,
5747 GLenum zpass)
5748{
5749 if (!IsValidStencilFace(face))
5750 {
Jamie Madille0472f32018-11-27 16:32:45 -05005751 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005752 return false;
5753 }
5754
5755 return ValidateStencilOp(context, fail, zfail, zpass);
5756}
5757
Jamie Madill5b772312018-03-08 20:28:32 -05005758bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005759{
5760 return ValidateUniform(context, GL_FLOAT, location, 1);
5761}
5762
Jamie Madill5b772312018-03-08 20:28:32 -05005763bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005764{
5765 return ValidateUniform(context, GL_FLOAT, location, count);
5766}
5767
Jamie Madill5b772312018-03-08 20:28:32 -05005768bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04005769{
5770 return ValidateUniform1iv(context, location, 1, &x);
5771}
5772
Jamie Madill5b772312018-03-08 20:28:32 -05005773bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005774{
5775 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
5776}
5777
Jamie Madill5b772312018-03-08 20:28:32 -05005778bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005779{
5780 return ValidateUniform(context, GL_INT_VEC2, location, 1);
5781}
5782
Jamie Madill5b772312018-03-08 20:28:32 -05005783bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005784{
5785 return ValidateUniform(context, GL_INT_VEC2, location, count);
5786}
5787
Jamie Madill5b772312018-03-08 20:28:32 -05005788bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005789{
5790 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
5791}
5792
Jamie Madill5b772312018-03-08 20:28:32 -05005793bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005794{
5795 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
5796}
5797
Jamie Madill5b772312018-03-08 20:28:32 -05005798bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005799{
5800 return ValidateUniform(context, GL_INT_VEC3, location, 1);
5801}
5802
Jamie Madill5b772312018-03-08 20:28:32 -05005803bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005804{
5805 return ValidateUniform(context, GL_INT_VEC3, location, count);
5806}
5807
Jamie Madill5b772312018-03-08 20:28:32 -05005808bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005809{
5810 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
5811}
5812
Jamie Madill5b772312018-03-08 20:28:32 -05005813bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005814{
5815 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
5816}
5817
Jamie Madill5b772312018-03-08 20:28:32 -05005818bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005819{
5820 return ValidateUniform(context, GL_INT_VEC4, location, 1);
5821}
5822
Jamie Madill5b772312018-03-08 20:28:32 -05005823bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005824{
5825 return ValidateUniform(context, GL_INT_VEC4, location, count);
5826}
5827
Jamie Madill5b772312018-03-08 20:28:32 -05005828bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005829 GLint location,
5830 GLsizei count,
5831 GLboolean transpose,
5832 const GLfloat *value)
5833{
5834 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
5835}
5836
Jamie Madill5b772312018-03-08 20:28:32 -05005837bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005838 GLint location,
5839 GLsizei count,
5840 GLboolean transpose,
5841 const GLfloat *value)
5842{
5843 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
5844}
5845
Jamie Madill5b772312018-03-08 20:28:32 -05005846bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005847 GLint location,
5848 GLsizei count,
5849 GLboolean transpose,
5850 const GLfloat *value)
5851{
5852 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
5853}
5854
Jamie Madill5b772312018-03-08 20:28:32 -05005855bool ValidateValidateProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005856{
5857 Program *programObject = GetValidProgram(context, program);
5858
5859 if (!programObject)
5860 {
5861 return false;
5862 }
5863
5864 return true;
5865}
5866
Jamie Madill5b772312018-03-08 20:28:32 -05005867bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005868{
5869 return ValidateVertexAttribIndex(context, index);
5870}
5871
Jamie Madill5b772312018-03-08 20:28:32 -05005872bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005873{
5874 return ValidateVertexAttribIndex(context, index);
5875}
5876
Jamie Madill5b772312018-03-08 20:28:32 -05005877bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005878{
5879 return ValidateVertexAttribIndex(context, index);
5880}
5881
Jamie Madill5b772312018-03-08 20:28:32 -05005882bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005883{
5884 return ValidateVertexAttribIndex(context, index);
5885}
5886
Jamie Madill5b772312018-03-08 20:28:32 -05005887bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005888{
5889 return ValidateVertexAttribIndex(context, index);
5890}
5891
Jamie Madill5b772312018-03-08 20:28:32 -05005892bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005893{
5894 return ValidateVertexAttribIndex(context, index);
5895}
5896
Jamie Madill5b772312018-03-08 20:28:32 -05005897bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005898 GLuint index,
5899 GLfloat x,
5900 GLfloat y,
5901 GLfloat z,
5902 GLfloat w)
5903{
5904 return ValidateVertexAttribIndex(context, index);
5905}
5906
Jamie Madill5b772312018-03-08 20:28:32 -05005907bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005908{
5909 return ValidateVertexAttribIndex(context, index);
5910}
5911
Jamie Madill5b772312018-03-08 20:28:32 -05005912bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005913{
5914 if (width < 0 || height < 0)
5915 {
Jamie Madille0472f32018-11-27 16:32:45 -05005916 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005917 return false;
5918 }
5919
5920 return true;
5921}
5922
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08005923bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04005924 GLenum target,
5925 GLenum attachment,
5926 GLenum pname,
5927 GLint *params)
5928{
5929 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
5930 nullptr);
5931}
5932
Jamie Madill5b772312018-03-08 20:28:32 -05005933bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04005934{
5935 return ValidateGetProgramivBase(context, program, pname, nullptr);
5936}
5937
Jamie Madill5b772312018-03-08 20:28:32 -05005938bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005939 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04005940 GLint level,
5941 GLenum internalformat,
5942 GLint x,
5943 GLint y,
5944 GLsizei width,
5945 GLsizei height,
5946 GLint border)
5947{
5948 if (context->getClientMajorVersion() < 3)
5949 {
5950 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
5951 0, x, y, width, height, border);
5952 }
5953
5954 ASSERT(context->getClientMajorVersion() == 3);
5955 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
5956 0, x, y, width, height, border);
5957}
5958
5959bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005960 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04005961 GLint level,
5962 GLint xoffset,
5963 GLint yoffset,
5964 GLint x,
5965 GLint y,
5966 GLsizei width,
5967 GLsizei height)
5968{
5969 if (context->getClientMajorVersion() < 3)
5970 {
5971 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
5972 yoffset, x, y, width, height, 0);
5973 }
5974
5975 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
5976 yoffset, 0, x, y, width, height, 0);
5977}
5978
5979bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *)
5980{
5981 return ValidateGenOrDelete(context, n);
5982}
5983
5984bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *)
5985{
5986 return ValidateGenOrDelete(context, n);
5987}
5988
5989bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *)
5990{
5991 return ValidateGenOrDelete(context, n);
5992}
5993
5994bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *)
5995{
5996 return ValidateGenOrDelete(context, n);
5997}
5998
5999bool ValidateDisable(Context *context, GLenum cap)
6000{
6001 if (!ValidCap(context, cap, false))
6002 {
Jamie Madille0472f32018-11-27 16:32:45 -05006003 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006004 return false;
6005 }
6006
6007 return true;
6008}
6009
6010bool ValidateEnable(Context *context, GLenum cap)
6011{
6012 if (!ValidCap(context, cap, false))
6013 {
Jamie Madille0472f32018-11-27 16:32:45 -05006014 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006015 return false;
6016 }
6017
6018 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6019 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6020 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006021 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006022
6023 // We also output an error message to the debugger window if tracing is active, so that
6024 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006025 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006026 return false;
6027 }
6028
6029 return true;
6030}
6031
6032bool ValidateFramebufferRenderbuffer(Context *context,
6033 GLenum target,
6034 GLenum attachment,
6035 GLenum renderbuffertarget,
6036 GLuint renderbuffer)
6037{
Geoff Lange8afa902017-09-27 15:00:43 -04006038 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006039 {
Jamie Madille0472f32018-11-27 16:32:45 -05006040 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006041 return false;
6042 }
6043
6044 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)
6045 {
Jamie Madille0472f32018-11-27 16:32:45 -05006046 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006047 return false;
6048 }
6049
6050 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6051 renderbuffertarget, renderbuffer);
6052}
6053
6054bool ValidateFramebufferTexture2D(Context *context,
6055 GLenum target,
6056 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006057 TextureTarget textarget,
Jamie Madillbe849e42017-05-02 15:49:00 -04006058 GLuint texture,
6059 GLint level)
6060{
6061 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6062 // extension
6063 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6064 level != 0)
6065 {
Jamie Madille0472f32018-11-27 16:32:45 -05006066 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006067 return false;
6068 }
6069
6070 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6071 {
6072 return false;
6073 }
6074
6075 if (texture != 0)
6076 {
6077 gl::Texture *tex = context->getTexture(texture);
6078 ASSERT(tex);
6079
6080 const gl::Caps &caps = context->getCaps();
6081
6082 switch (textarget)
6083 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006084 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006085 {
6086 if (level > gl::log2(caps.max2DTextureSize))
6087 {
Jamie Madille0472f32018-11-27 16:32:45 -05006088 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006089 return false;
6090 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006091 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006092 {
Jamie Madille0472f32018-11-27 16:32:45 -05006093 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006094 return false;
6095 }
6096 }
6097 break;
6098
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006099 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006100 {
6101 if (level != 0)
6102 {
Jamie Madille0472f32018-11-27 16:32:45 -05006103 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006104 return false;
6105 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006106 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006107 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006108 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006109 return false;
6110 }
6111 }
6112 break;
6113
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006114 case TextureTarget::CubeMapNegativeX:
6115 case TextureTarget::CubeMapNegativeY:
6116 case TextureTarget::CubeMapNegativeZ:
6117 case TextureTarget::CubeMapPositiveX:
6118 case TextureTarget::CubeMapPositiveY:
6119 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006120 {
6121 if (level > gl::log2(caps.maxCubeMapTextureSize))
6122 {
Jamie Madille0472f32018-11-27 16:32:45 -05006123 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006124 return false;
6125 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006126 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006127 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006128 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006129 return false;
6130 }
6131 }
6132 break;
6133
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006134 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006135 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006136 if (context->getClientVersion() < ES_3_1 &&
6137 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006138 {
Jamie Madill610640f2018-11-21 17:28:41 -05006139 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006140 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006141 return false;
6142 }
6143
6144 if (level != 0)
6145 {
Jamie Madille0472f32018-11-27 16:32:45 -05006146 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006147 return false;
6148 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006149 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006150 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006151 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006152 return false;
6153 }
6154 }
6155 break;
6156
6157 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006158 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006159 return false;
6160 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006161 }
6162
6163 return true;
6164}
6165
6166bool ValidateGenBuffers(Context *context, GLint n, GLuint *)
6167{
6168 return ValidateGenOrDelete(context, n);
6169}
6170
6171bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *)
6172{
6173 return ValidateGenOrDelete(context, n);
6174}
6175
6176bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *)
6177{
6178 return ValidateGenOrDelete(context, n);
6179}
6180
6181bool ValidateGenTextures(Context *context, GLint n, GLuint *)
6182{
6183 return ValidateGenOrDelete(context, n);
6184}
6185
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006186bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006187{
6188 if (!ValidTextureTarget(context, target))
6189 {
Jamie Madille0472f32018-11-27 16:32:45 -05006190 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006191 return false;
6192 }
6193
6194 Texture *texture = context->getTargetTexture(target);
6195
6196 if (texture == nullptr)
6197 {
Jamie Madille0472f32018-11-27 16:32:45 -05006198 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006199 return false;
6200 }
6201
6202 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6203
6204 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6205 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6206 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6207 {
Jamie Madille0472f32018-11-27 16:32:45 -05006208 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006209 return false;
6210 }
6211
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006212 TextureTarget baseTarget = (target == TextureType::CubeMap)
6213 ? TextureTarget::CubeMapPositiveX
6214 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006215 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6216 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6217 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006218 {
Jamie Madille0472f32018-11-27 16:32:45 -05006219 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006220 return false;
6221 }
6222
Geoff Lang536eca12017-09-13 11:23:35 -04006223 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6224 bool formatUnsized = !format.sized;
6225 bool formatColorRenderableAndFilterable =
6226 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006227 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006228 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006229 {
Jamie Madille0472f32018-11-27 16:32:45 -05006230 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006231 return false;
6232 }
6233
Geoff Lang536eca12017-09-13 11:23:35 -04006234 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6235 // generation
6236 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6237 {
Jamie Madille0472f32018-11-27 16:32:45 -05006238 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006239 return false;
6240 }
6241
Jiange2c00842018-07-13 16:50:49 +08006242 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6243 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6244 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006245 {
Jamie Madille0472f32018-11-27 16:32:45 -05006246 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006247 return false;
6248 }
6249
6250 // Non-power of 2 ES2 check
6251 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6252 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6253 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6254 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006255 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6256 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006257 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006258 return false;
6259 }
6260
6261 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006262 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006263 {
Jamie Madille0472f32018-11-27 16:32:45 -05006264 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006265 return false;
6266 }
6267
James Darpinian83b2f0e2018-11-27 15:56:01 -08006268 if (context->getExtensions().webglCompatibility &&
6269 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6270 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6271 {
6272 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6273 return false;
6274 }
6275
Jamie Madillbe849e42017-05-02 15:49:00 -04006276 return true;
6277}
6278
Jamie Madill5b772312018-03-08 20:28:32 -05006279bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006280 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006281 GLenum pname,
6282 GLint *params)
6283{
6284 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6285}
6286
6287bool ValidateGetRenderbufferParameteriv(Context *context,
6288 GLenum target,
6289 GLenum pname,
6290 GLint *params)
6291{
6292 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6293}
6294
6295bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params)
6296{
6297 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6298}
6299
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006300bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006301{
6302 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6303}
6304
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006305bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006306{
6307 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6308}
6309
Till Rathmannb8543632018-10-02 19:46:14 +02006310bool ValidateGetTexParameterIivOES(Context *context,
6311 TextureType target,
6312 GLenum pname,
6313 GLint *params)
6314{
6315 if (context->getClientMajorVersion() < 3)
6316 {
Jamie Madille0472f32018-11-27 16:32:45 -05006317 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006318 return false;
6319 }
6320 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6321}
6322
6323bool ValidateGetTexParameterIuivOES(Context *context,
6324 TextureType target,
6325 GLenum pname,
6326 GLuint *params)
6327{
6328 if (context->getClientMajorVersion() < 3)
6329 {
Jamie Madille0472f32018-11-27 16:32:45 -05006330 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006331 return false;
6332 }
6333 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6334}
6335
Jamie Madillbe849e42017-05-02 15:49:00 -04006336bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params)
6337{
6338 return ValidateGetUniformBase(context, program, location);
6339}
6340
6341bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params)
6342{
6343 return ValidateGetUniformBase(context, program, location);
6344}
6345
6346bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6347{
6348 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6349}
6350
6351bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6352{
6353 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6354}
6355
6356bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6357{
6358 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6359}
6360
6361bool ValidateIsEnabled(Context *context, GLenum cap)
6362{
6363 if (!ValidCap(context, cap, true))
6364 {
Jamie Madille0472f32018-11-27 16:32:45 -05006365 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006366 return false;
6367 }
6368
6369 return true;
6370}
6371
6372bool ValidateLinkProgram(Context *context, GLuint program)
6373{
6374 if (context->hasActiveTransformFeedback(program))
6375 {
6376 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006377 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006378 return false;
6379 }
6380
6381 Program *programObject = GetValidProgram(context, program);
6382 if (!programObject)
6383 {
6384 return false;
6385 }
6386
6387 return true;
6388}
6389
Jamie Madill4928b7c2017-06-20 12:57:39 -04006390bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006391 GLint x,
6392 GLint y,
6393 GLsizei width,
6394 GLsizei height,
6395 GLenum format,
6396 GLenum type,
6397 void *pixels)
6398{
6399 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6400 nullptr, pixels);
6401}
6402
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006403bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006404{
Till Rathmannb8543632018-10-02 19:46:14 +02006405 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006406}
6407
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006408bool ValidateTexParameterfv(Context *context,
6409 TextureType target,
6410 GLenum pname,
6411 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006412{
Till Rathmannb8543632018-10-02 19:46:14 +02006413 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006414}
6415
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006416bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006417{
Till Rathmannb8543632018-10-02 19:46:14 +02006418 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006419}
6420
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006421bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006422{
Till Rathmannb8543632018-10-02 19:46:14 +02006423 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6424}
6425
6426bool ValidateTexParameterIivOES(Context *context,
6427 TextureType target,
6428 GLenum pname,
6429 const GLint *params)
6430{
6431 if (context->getClientMajorVersion() < 3)
6432 {
Jamie Madille0472f32018-11-27 16:32:45 -05006433 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006434 return false;
6435 }
6436 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6437}
6438
6439bool ValidateTexParameterIuivOES(Context *context,
6440 TextureType target,
6441 GLenum pname,
6442 const GLuint *params)
6443{
6444 if (context->getClientMajorVersion() < 3)
6445 {
Jamie Madille0472f32018-11-27 16:32:45 -05006446 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006447 return false;
6448 }
6449 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006450}
6451
6452bool ValidateUseProgram(Context *context, GLuint program)
6453{
6454 if (program != 0)
6455 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006456 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006457 if (!programObject)
6458 {
6459 // ES 3.1.0 section 7.3 page 72
6460 if (context->getShader(program))
6461 {
Jamie Madille0472f32018-11-27 16:32:45 -05006462 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006463 return false;
6464 }
6465 else
6466 {
Jamie Madille0472f32018-11-27 16:32:45 -05006467 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006468 return false;
6469 }
6470 }
6471 if (!programObject->isLinked())
6472 {
Jamie Madille0472f32018-11-27 16:32:45 -05006473 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006474 return false;
6475 }
6476 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006477 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006478 {
6479 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006480 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006481 return false;
6482 }
6483
6484 return true;
6485}
6486
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006487bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences)
6488{
6489 if (!context->getExtensions().fence)
6490 {
Jamie Madille0472f32018-11-27 16:32:45 -05006491 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006492 return false;
6493 }
6494
6495 if (n < 0)
6496 {
Jamie Madille0472f32018-11-27 16:32:45 -05006497 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006498 return false;
6499 }
6500
6501 return true;
6502}
6503
6504bool ValidateFinishFenceNV(Context *context, GLuint fence)
6505{
6506 if (!context->getExtensions().fence)
6507 {
Jamie Madille0472f32018-11-27 16:32:45 -05006508 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006509 return false;
6510 }
6511
6512 FenceNV *fenceObject = context->getFenceNV(fence);
6513
6514 if (fenceObject == nullptr)
6515 {
Jamie Madille0472f32018-11-27 16:32:45 -05006516 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006517 return false;
6518 }
6519
6520 if (!fenceObject->isSet())
6521 {
Jamie Madille0472f32018-11-27 16:32:45 -05006522 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006523 return false;
6524 }
6525
6526 return true;
6527}
6528
6529bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences)
6530{
6531 if (!context->getExtensions().fence)
6532 {
Jamie Madille0472f32018-11-27 16:32:45 -05006533 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006534 return false;
6535 }
6536
6537 if (n < 0)
6538 {
Jamie Madille0472f32018-11-27 16:32:45 -05006539 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006540 return false;
6541 }
6542
6543 return true;
6544}
6545
6546bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params)
6547{
6548 if (!context->getExtensions().fence)
6549 {
Jamie Madille0472f32018-11-27 16:32:45 -05006550 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006551 return false;
6552 }
6553
6554 FenceNV *fenceObject = context->getFenceNV(fence);
6555
6556 if (fenceObject == nullptr)
6557 {
Jamie Madille0472f32018-11-27 16:32:45 -05006558 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006559 return false;
6560 }
6561
6562 if (!fenceObject->isSet())
6563 {
Jamie Madille0472f32018-11-27 16:32:45 -05006564 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006565 return false;
6566 }
6567
6568 switch (pname)
6569 {
6570 case GL_FENCE_STATUS_NV:
6571 case GL_FENCE_CONDITION_NV:
6572 break;
6573
6574 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006575 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006576 return false;
6577 }
6578
6579 return true;
6580}
6581
6582bool ValidateGetGraphicsResetStatusEXT(Context *context)
6583{
6584 if (!context->getExtensions().robustness)
6585 {
Jamie Madille0472f32018-11-27 16:32:45 -05006586 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006587 return false;
6588 }
6589
6590 return true;
6591}
6592
6593bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
6594 GLuint shader,
6595 GLsizei bufsize,
6596 GLsizei *length,
6597 GLchar *source)
6598{
6599 if (!context->getExtensions().translatedShaderSource)
6600 {
Jamie Madille0472f32018-11-27 16:32:45 -05006601 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006602 return false;
6603 }
6604
6605 if (bufsize < 0)
6606 {
Jamie Madille0472f32018-11-27 16:32:45 -05006607 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006608 return false;
6609 }
6610
6611 Shader *shaderObject = context->getShader(shader);
6612
6613 if (!shaderObject)
6614 {
Jamie Madille0472f32018-11-27 16:32:45 -05006615 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006616 return false;
6617 }
6618
6619 return true;
6620}
6621
6622bool ValidateIsFenceNV(Context *context, GLuint fence)
6623{
6624 if (!context->getExtensions().fence)
6625 {
Jamie Madille0472f32018-11-27 16:32:45 -05006626 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006627 return false;
6628 }
6629
6630 return true;
6631}
6632
Jamie Madill007530e2017-12-28 14:27:04 -05006633bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition)
6634{
6635 if (!context->getExtensions().fence)
6636 {
Jamie Madille0472f32018-11-27 16:32:45 -05006637 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006638 return false;
6639 }
6640
6641 if (condition != GL_ALL_COMPLETED_NV)
6642 {
Jamie Madille0472f32018-11-27 16:32:45 -05006643 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05006644 return false;
6645 }
6646
6647 FenceNV *fenceObject = context->getFenceNV(fence);
6648
6649 if (fenceObject == nullptr)
6650 {
Jamie Madille0472f32018-11-27 16:32:45 -05006651 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006652 return false;
6653 }
6654
6655 return true;
6656}
6657
6658bool ValidateTestFenceNV(Context *context, GLuint fence)
6659{
6660 if (!context->getExtensions().fence)
6661 {
Jamie Madille0472f32018-11-27 16:32:45 -05006662 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006663 return false;
6664 }
6665
6666 FenceNV *fenceObject = context->getFenceNV(fence);
6667
6668 if (fenceObject == nullptr)
6669 {
Jamie Madille0472f32018-11-27 16:32:45 -05006670 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006671 return false;
6672 }
6673
6674 if (fenceObject->isSet() != GL_TRUE)
6675 {
Jamie Madille0472f32018-11-27 16:32:45 -05006676 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05006677 return false;
6678 }
6679
6680 return true;
6681}
6682
6683bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006684 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05006685 GLsizei levels,
6686 GLenum internalformat,
6687 GLsizei width,
6688 GLsizei height)
6689{
6690 if (!context->getExtensions().textureStorage)
6691 {
Jamie Madille0472f32018-11-27 16:32:45 -05006692 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006693 return false;
6694 }
6695
6696 if (context->getClientMajorVersion() < 3)
6697 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006698 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05006699 height);
6700 }
6701
6702 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006703 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05006704 1);
6705}
6706
6707bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
6708{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006709 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05006710 {
Jamie Madille0472f32018-11-27 16:32:45 -05006711 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006712 return false;
6713 }
6714
6715 if (index >= MAX_VERTEX_ATTRIBS)
6716 {
Jamie Madille0472f32018-11-27 16:32:45 -05006717 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05006718 return false;
6719 }
6720
6721 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
6722 {
6723 if (index == 0 && divisor != 0)
6724 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006725 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05006726
6727 // We also output an error message to the debugger window if tracing is active, so
6728 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006729 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05006730 return false;
6731 }
6732 }
6733
6734 return true;
6735}
6736
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006737bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
6738{
6739 if (!context->getExtensions().instancedArraysEXT)
6740 {
6741 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6742 return false;
6743 }
6744
6745 if (index >= MAX_VERTEX_ATTRIBS)
6746 {
6747 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
6748 return false;
6749 }
6750
6751 return true;
6752}
6753
Jamie Madill007530e2017-12-28 14:27:04 -05006754bool ValidateTexImage3DOES(Context *context,
6755 GLenum target,
6756 GLint level,
6757 GLenum internalformat,
6758 GLsizei width,
6759 GLsizei height,
6760 GLsizei depth,
6761 GLint border,
6762 GLenum format,
6763 GLenum type,
6764 const void *pixels)
6765{
6766 UNIMPLEMENTED(); // FIXME
6767 return false;
6768}
6769
6770bool ValidatePopGroupMarkerEXT(Context *context)
6771{
6772 if (!context->getExtensions().debugMarker)
6773 {
6774 // The debug marker calls should not set error state
6775 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05006776 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006777 return false;
6778 }
6779
6780 return true;
6781}
6782
Jamie Madillfa920eb2018-01-04 11:45:50 -05006783bool ValidateTexStorage1DEXT(Context *context,
6784 GLenum target,
6785 GLsizei levels,
6786 GLenum internalformat,
6787 GLsizei width)
6788{
6789 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05006790 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006791 return false;
6792}
6793
6794bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006795 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05006796 GLsizei levels,
6797 GLenum internalformat,
6798 GLsizei width,
6799 GLsizei height,
6800 GLsizei depth)
6801{
6802 if (!context->getExtensions().textureStorage)
6803 {
Jamie Madille0472f32018-11-27 16:32:45 -05006804 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006805 return false;
6806 }
6807
6808 if (context->getClientMajorVersion() < 3)
6809 {
Jamie Madille0472f32018-11-27 16:32:45 -05006810 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006811 return false;
6812 }
6813
6814 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
6815 depth);
6816}
6817
jchen1082af6202018-06-22 10:59:52 +08006818bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
6819{
6820 if (!context->getExtensions().parallelShaderCompile)
6821 {
Jamie Madille0472f32018-11-27 16:32:45 -05006822 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08006823 return false;
6824 }
6825 return true;
6826}
6827
Austin Eng1bf18ce2018-10-19 15:34:02 -07006828bool ValidateMultiDrawArraysANGLE(Context *context,
6829 PrimitiveMode mode,
6830 const GLint *firsts,
6831 const GLsizei *counts,
6832 GLsizei drawcount)
6833{
6834 if (!context->getExtensions().multiDraw)
6835 {
Jamie Madille0472f32018-11-27 16:32:45 -05006836 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07006837 return false;
6838 }
6839 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
6840 {
6841 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
6842 {
6843 return false;
6844 }
6845 }
6846 return true;
6847}
6848
6849bool ValidateMultiDrawElementsANGLE(Context *context,
6850 PrimitiveMode mode,
6851 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05006852 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08006853 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07006854 GLsizei drawcount)
6855{
6856 if (!context->getExtensions().multiDraw)
6857 {
Jamie Madille0472f32018-11-27 16:32:45 -05006858 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07006859 return false;
6860 }
6861 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
6862 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08006863 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07006864 {
6865 return false;
6866 }
6867 }
6868 return true;
6869}
6870
Jeff Gilbert465d6092019-01-02 16:21:18 -08006871bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked)
6872{
6873 if (!context->getExtensions().provokingVertex)
6874 {
6875 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6876 return false;
6877 }
6878
6879 switch (modePacked)
6880 {
6881 case ProvokingVertex::FirstVertexConvention:
6882 case ProvokingVertex::LastVertexConvention:
6883 break;
6884 default:
6885 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
6886 return false;
6887 }
6888
6889 return true;
6890}
6891
Jamie Madilla5410482019-01-31 19:55:55 -05006892void RecordBindTextureTypeError(Context *context, TextureType target)
6893{
6894 ASSERT(!context->getStateCache().isValidBindTextureType(target));
6895
6896 switch (target)
6897 {
6898 case TextureType::Rectangle:
6899 ASSERT(!context->getExtensions().textureRectangle);
6900 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
6901 break;
6902
6903 case TextureType::_3D:
6904 case TextureType::_2DArray:
6905 ASSERT(context->getClientMajorVersion() < 3);
6906 context->validationError(GL_INVALID_ENUM, kES3Required);
6907 break;
6908
6909 case TextureType::_2DMultisample:
6910 ASSERT(context->getClientVersion() < Version(3, 1) &&
6911 !context->getExtensions().textureMultisample);
6912 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
6913 break;
6914
6915 case TextureType::_2DMultisampleArray:
6916 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
6917 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
6918 break;
6919
6920 case TextureType::External:
6921 ASSERT(!context->getExtensions().eglImageExternal &&
6922 !context->getExtensions().eglStreamConsumerExternal);
6923 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
6924 break;
6925
6926 default:
6927 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
6928 }
6929}
6930
Jamie Madillc29968b2016-01-20 11:17:23 -05006931} // namespace gl