blob: 8e1047769d87717fa8a4569e69e058180de4c903 [file] [log] [blame]
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
Geoff Lange8ebe7f2013-08-05 15:03:13 -04003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// validationES2.cpp: Validation functions for OpenGL ES 2.0 entry point parameters
8
Jamie Madill778bf092018-11-14 09:54:36 -05009#include "libANGLE/validationES2_autogen.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030010
11#include <cstdint>
12
Geoff Lange8ebe7f2013-08-05 15:03:13 -040013#include "common/mathutil.h"
Sami Väisänen46eaa942016-06-29 10:26:37 +030014#include "common/string_utils.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040015#include "common/utilities.h"
Jamie Madillef300b12016-10-07 15:12:09 -040016#include "libANGLE/Context.h"
Brandon Jones6cad5662017-06-14 13:25:13 -070017#include "libANGLE/ErrorStrings.h"
Jamie Madill2b7bbc22017-12-21 17:30:38 -050018#include "libANGLE/Fence.h"
Jamie Madillef300b12016-10-07 15:12:09 -040019#include "libANGLE/Framebuffer.h"
20#include "libANGLE/FramebufferAttachment.h"
21#include "libANGLE/Renderbuffer.h"
22#include "libANGLE/Shader.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040023#include "libANGLE/Texture.h"
Jamie Madillef300b12016-10-07 15:12:09 -040024#include "libANGLE/Uniform.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040025#include "libANGLE/VertexArray.h"
Jamie Madillef300b12016-10-07 15:12:09 -040026#include "libANGLE/formatutils.h"
27#include "libANGLE/validationES.h"
Jamie Madill778bf092018-11-14 09:54:36 -050028#include "libANGLE/validationES2.h"
29#include "libANGLE/validationES3_autogen.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040030
31namespace gl
32{
Jamie Madille0472f32018-11-27 16:32:45 -050033using namespace err;
Geoff Lange8ebe7f2013-08-05 15:03:13 -040034
Jamie Madillc29968b2016-01-20 11:17:23 -050035namespace
36{
37
38bool IsPartialBlit(gl::Context *context,
39 const FramebufferAttachment *readBuffer,
40 const FramebufferAttachment *writeBuffer,
41 GLint srcX0,
42 GLint srcY0,
43 GLint srcX1,
44 GLint srcY1,
45 GLint dstX0,
46 GLint dstY0,
47 GLint dstX1,
48 GLint dstY1)
49{
50 const Extents &writeSize = writeBuffer->getSize();
51 const Extents &readSize = readBuffer->getSize();
52
53 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width ||
54 dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height)
55 {
56 return true;
57 }
58
Jamie Madillc3dc5d42018-12-30 12:12:04 -050059 if (context->getState().isScissorTestEnabled())
Jamie Madillc29968b2016-01-20 11:17:23 -050060 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -050061 const Rectangle &scissor = context->getState().getScissor();
Jamie Madillc29968b2016-01-20 11:17:23 -050062 return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width ||
63 scissor.height < writeSize.height;
64 }
65
66 return false;
67}
68
Sami Väisänend59ca052016-06-21 16:10:00 +030069template <typename T>
70bool ValidatePathInstances(gl::Context *context,
71 GLsizei numPaths,
72 const void *paths,
73 GLuint pathBase)
74{
75 const auto *array = static_cast<const T *>(paths);
76
77 for (GLsizei i = 0; i < numPaths; ++i)
78 {
79 const GLuint pathName = array[i] + pathBase;
Brandon Jones59770802018-04-02 13:18:42 -070080 if (context->isPathGenerated(pathName) && !context->isPath(pathName))
Sami Väisänend59ca052016-06-21 16:10:00 +030081 {
Jamie Madille0472f32018-11-27 16:32:45 -050082 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänend59ca052016-06-21 16:10:00 +030083 return false;
84 }
85 }
86 return true;
87}
88
89bool ValidateInstancedPathParameters(gl::Context *context,
90 GLsizei numPaths,
91 GLenum pathNameType,
92 const void *paths,
93 GLuint pathBase,
94 GLenum transformType,
95 const GLfloat *transformValues)
96{
97 if (!context->getExtensions().pathRendering)
98 {
Jamie Madillc3e37312018-11-30 15:25:39 -050099 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänend59ca052016-06-21 16:10:00 +0300100 return false;
101 }
102
103 if (paths == nullptr)
104 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500105 context->validationError(GL_INVALID_VALUE, kInvalidPathNameArray);
Sami Väisänend59ca052016-06-21 16:10:00 +0300106 return false;
107 }
108
109 if (numPaths < 0)
110 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500111 context->validationError(GL_INVALID_VALUE, kInvalidPathNumPaths);
Sami Väisänend59ca052016-06-21 16:10:00 +0300112 return false;
113 }
114
115 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths))
116 {
Jamie Madille0472f32018-11-27 16:32:45 -0500117 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänend59ca052016-06-21 16:10:00 +0300118 return false;
119 }
120
121 std::uint32_t pathNameTypeSize = 0;
122 std::uint32_t componentCount = 0;
123
124 switch (pathNameType)
125 {
126 case GL_UNSIGNED_BYTE:
127 pathNameTypeSize = sizeof(GLubyte);
128 if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase))
129 return false;
130 break;
131
132 case GL_BYTE:
133 pathNameTypeSize = sizeof(GLbyte);
134 if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase))
135 return false;
136 break;
137
138 case GL_UNSIGNED_SHORT:
139 pathNameTypeSize = sizeof(GLushort);
140 if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase))
141 return false;
142 break;
143
144 case GL_SHORT:
145 pathNameTypeSize = sizeof(GLshort);
146 if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase))
147 return false;
148 break;
149
150 case GL_UNSIGNED_INT:
151 pathNameTypeSize = sizeof(GLuint);
152 if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase))
153 return false;
154 break;
155
156 case GL_INT:
157 pathNameTypeSize = sizeof(GLint);
158 if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase))
159 return false;
160 break;
161
162 default:
Jamie Madillc3e37312018-11-30 15:25:39 -0500163 context->validationError(GL_INVALID_ENUM, kInvalidPathNameType);
Sami Väisänend59ca052016-06-21 16:10:00 +0300164 return false;
165 }
166
167 switch (transformType)
168 {
169 case GL_NONE:
170 componentCount = 0;
171 break;
172 case GL_TRANSLATE_X_CHROMIUM:
173 case GL_TRANSLATE_Y_CHROMIUM:
174 componentCount = 1;
175 break;
176 case GL_TRANSLATE_2D_CHROMIUM:
177 componentCount = 2;
178 break;
179 case GL_TRANSLATE_3D_CHROMIUM:
180 componentCount = 3;
181 break;
182 case GL_AFFINE_2D_CHROMIUM:
183 case GL_TRANSPOSE_AFFINE_2D_CHROMIUM:
184 componentCount = 6;
185 break;
186 case GL_AFFINE_3D_CHROMIUM:
187 case GL_TRANSPOSE_AFFINE_3D_CHROMIUM:
188 componentCount = 12;
189 break;
190 default:
Jamie Madillc3e37312018-11-30 15:25:39 -0500191 context->validationError(GL_INVALID_ENUM, kInvalidTransformation);
Sami Väisänend59ca052016-06-21 16:10:00 +0300192 return false;
193 }
194 if (componentCount != 0 && transformValues == nullptr)
195 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500196 context->validationError(GL_INVALID_VALUE, kNoTransformArray);
Sami Väisänend59ca052016-06-21 16:10:00 +0300197 return false;
198 }
199
200 angle::CheckedNumeric<std::uint32_t> checkedSize(0);
201 checkedSize += (numPaths * pathNameTypeSize);
202 checkedSize += (numPaths * sizeof(GLfloat) * componentCount);
203 if (!checkedSize.IsValid())
204 {
Jamie Madille0472f32018-11-27 16:32:45 -0500205 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänend59ca052016-06-21 16:10:00 +0300206 return false;
207 }
208
209 return true;
210}
211
Geoff Lang4f0e0032017-05-01 16:04:35 -0400212bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat)
Geoff Lang97073d12016-04-20 10:42:34 -0700213{
Geoff Lang4f0e0032017-05-01 16:04:35 -0400214 // Table 1.1 from the CHROMIUM_copy_texture spec
Geoff Langca271392017-04-05 12:30:00 -0400215 switch (GetUnsizedFormat(internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -0700216 {
Geoff Lang4f0e0032017-05-01 16:04:35 -0400217 case GL_RED:
Geoff Lang97073d12016-04-20 10:42:34 -0700218 case GL_ALPHA:
219 case GL_LUMINANCE:
220 case GL_LUMINANCE_ALPHA:
221 case GL_RGB:
222 case GL_RGBA:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400223 case GL_RGB8:
224 case GL_RGBA8:
225 case GL_BGRA_EXT:
226 case GL_BGRA8_EXT:
Geoff Lang97073d12016-04-20 10:42:34 -0700227 return true;
228
Geoff Lang4f0e0032017-05-01 16:04:35 -0400229 default:
230 return false;
231 }
232}
Geoff Lang97073d12016-04-20 10:42:34 -0700233
Geoff Lang4f0e0032017-05-01 16:04:35 -0400234bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat)
235{
236 return IsValidCopyTextureSourceInternalFormatEnum(internalFormat);
237}
238
Geoff Lang4f0e0032017-05-01 16:04:35 -0400239bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat)
240{
241 // Table 1.0 from the CHROMIUM_copy_texture spec
242 switch (internalFormat)
243 {
244 case GL_RGB:
245 case GL_RGBA:
246 case GL_RGB8:
247 case GL_RGBA8:
Geoff Lang97073d12016-04-20 10:42:34 -0700248 case GL_BGRA_EXT:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400249 case GL_BGRA8_EXT:
250 case GL_SRGB_EXT:
251 case GL_SRGB_ALPHA_EXT:
252 case GL_R8:
253 case GL_R8UI:
254 case GL_RG8:
255 case GL_RG8UI:
256 case GL_SRGB8:
257 case GL_RGB565:
258 case GL_RGB8UI:
Geoff Lang6be3d4c2017-06-16 15:54:15 -0400259 case GL_RGB10_A2:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400260 case GL_SRGB8_ALPHA8:
261 case GL_RGB5_A1:
262 case GL_RGBA4:
263 case GL_RGBA8UI:
264 case GL_RGB9_E5:
265 case GL_R16F:
266 case GL_R32F:
267 case GL_RG16F:
268 case GL_RG32F:
269 case GL_RGB16F:
270 case GL_RGB32F:
271 case GL_RGBA16F:
272 case GL_RGBA32F:
273 case GL_R11F_G11F_B10F:
Brandon Jones340b7b82017-06-26 13:02:31 -0700274 case GL_LUMINANCE:
275 case GL_LUMINANCE_ALPHA:
276 case GL_ALPHA:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400277 return true;
Geoff Lang97073d12016-04-20 10:42:34 -0700278
279 default:
280 return false;
281 }
282}
283
Geoff Lang6be3d4c2017-06-16 15:54:15 -0400284bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat)
285{
286 return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat);
287}
288
Geoff Lang97073d12016-04-20 10:42:34 -0700289bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type)
290{
Geoff Lang4f0e0032017-05-01 16:04:35 -0400291 if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -0700292 {
Jamie Madille0472f32018-11-27 16:32:45 -0500293 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400294 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700295 }
296
Geoff Langc0094ec2017-08-16 14:16:24 -0400297 if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat))
298 {
Jamie Madille0472f32018-11-27 16:32:45 -0500299 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Langc0094ec2017-08-16 14:16:24 -0400300 return false;
301 }
302
Geoff Lang4f0e0032017-05-01 16:04:35 -0400303 const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type);
304 if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Geoff Lang97073d12016-04-20 10:42:34 -0700305 {
Jamie Madille0472f32018-11-27 16:32:45 -0500306 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400307 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700308 }
309
310 return true;
311}
312
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800313bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target)
Geoff Lang97073d12016-04-20 10:42:34 -0700314{
315 switch (target)
316 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800317 case TextureTarget::_2D:
318 case TextureTarget::CubeMapNegativeX:
319 case TextureTarget::CubeMapNegativeY:
320 case TextureTarget::CubeMapNegativeZ:
321 case TextureTarget::CubeMapPositiveX:
322 case TextureTarget::CubeMapPositiveY:
323 case TextureTarget::CubeMapPositiveZ:
Geoff Lang63458a32017-10-30 15:16:53 -0400324 return true;
Geoff Lang97073d12016-04-20 10:42:34 -0700325
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 case TextureTarget::Rectangle:
Geoff Lang63458a32017-10-30 15:16:53 -0400327 return context->getExtensions().textureRectangle;
Geoff Lang97073d12016-04-20 10:42:34 -0700328
329 default:
330 return false;
331 }
332}
333
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334bool IsValidCopyTextureDestinationTarget(Context *context,
335 TextureType textureType,
336 TextureTarget target)
Geoff Lang63458a32017-10-30 15:16:53 -0400337{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800338 return TextureTargetToType(target) == textureType;
Geoff Lang63458a32017-10-30 15:16:53 -0400339}
340
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800341bool IsValidCopyTextureSourceTarget(Context *context, TextureType type)
Geoff Lang97073d12016-04-20 10:42:34 -0700342{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800343 switch (type)
Geoff Lang97073d12016-04-20 10:42:34 -0700344 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800345 case TextureType::_2D:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400346 return true;
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800347 case TextureType::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400348 return context->getExtensions().textureRectangle;
Geoff Langbe607ad2018-11-29 10:14:22 -0500349 case TextureType::External:
350 return context->getExtensions().eglImageExternal;
Geoff Lang4f0e0032017-05-01 16:04:35 -0400351 default:
352 return false;
353 }
354}
355
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800356bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400357{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 if (!ValidMipLevel(context, type, level))
Geoff Lang4f0e0032017-05-01 16:04:35 -0400359 {
360 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700361 }
362
Geoff Lang4f0e0032017-05-01 16:04:35 -0400363 if (level > 0 && context->getClientVersion() < ES_3_0)
364 {
365 return false;
366 }
Geoff Lang97073d12016-04-20 10:42:34 -0700367
Geoff Lang4f0e0032017-05-01 16:04:35 -0400368 return true;
369}
370
371bool IsValidCopyTextureDestinationLevel(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800372 TextureType type,
Geoff Lang4f0e0032017-05-01 16:04:35 -0400373 GLint level,
374 GLsizei width,
Brandon Jones28783792018-03-05 09:37:32 -0800375 GLsizei height,
376 bool isSubImage)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400377{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800378 if (!ValidMipLevel(context, type, level))
Geoff Lang4f0e0032017-05-01 16:04:35 -0400379 {
380 return false;
381 }
382
Brandon Jones28783792018-03-05 09:37:32 -0800383 if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage))
384 {
385 return false;
386 }
387
Geoff Lang4f0e0032017-05-01 16:04:35 -0400388 const Caps &caps = context->getCaps();
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800389 switch (type)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400390 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 case TextureType::_2D:
392 return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) &&
393 static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level);
394 case TextureType::Rectangle:
395 ASSERT(level == 0);
396 return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) &&
397 static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400398
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800399 case TextureType::CubeMap:
400 return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) &&
401 static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level);
402 default:
403 return true;
404 }
Geoff Lang97073d12016-04-20 10:42:34 -0700405}
406
Jamie Madillc1d770e2017-04-13 17:31:24 -0400407bool IsValidStencilFunc(GLenum func)
408{
409 switch (func)
410 {
411 case GL_NEVER:
412 case GL_ALWAYS:
413 case GL_LESS:
414 case GL_LEQUAL:
415 case GL_EQUAL:
416 case GL_GEQUAL:
417 case GL_GREATER:
418 case GL_NOTEQUAL:
419 return true;
420
421 default:
422 return false;
423 }
424}
425
426bool IsValidStencilFace(GLenum face)
427{
428 switch (face)
429 {
430 case GL_FRONT:
431 case GL_BACK:
432 case GL_FRONT_AND_BACK:
433 return true;
434
435 default:
436 return false;
437 }
438}
439
440bool IsValidStencilOp(GLenum op)
441{
442 switch (op)
443 {
444 case GL_ZERO:
445 case GL_KEEP:
446 case GL_REPLACE:
447 case GL_INCR:
448 case GL_DECR:
449 case GL_INVERT:
450 case GL_INCR_WRAP:
451 case GL_DECR_WRAP:
452 return true;
453
454 default:
455 return false;
456 }
457}
458
Jamie Madill5b772312018-03-08 20:28:32 -0500459bool ValidateES2CopyTexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800460 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -0400461 GLint level,
462 GLenum internalformat,
463 bool isSubImage,
464 GLint xoffset,
465 GLint yoffset,
466 GLint x,
467 GLint y,
468 GLsizei width,
469 GLsizei height,
470 GLint border)
471{
472 if (!ValidTexture2DDestinationTarget(context, target))
473 {
Jamie Madille0472f32018-11-27 16:32:45 -0500474 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -0400475 return false;
476 }
477
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800478 TextureType texType = TextureTargetToType(target);
479 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Jamie Madillbe849e42017-05-02 15:49:00 -0400480 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500481 // Error is already handled.
Jamie Madillbe849e42017-05-02 15:49:00 -0400482 return false;
483 }
484
485 Format textureFormat = Format::Invalid();
486 if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
487 xoffset, yoffset, 0, x, y, width, height, border,
488 &textureFormat))
489 {
490 return false;
491 }
492
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500493 const gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madillbe849e42017-05-02 15:49:00 -0400494 GLenum colorbufferFormat =
495 framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat;
496 const auto &formatInfo = *textureFormat.info;
497
498 // [OpenGL ES 2.0.24] table 3.9
499 if (isSubImage)
500 {
501 switch (formatInfo.format)
502 {
503 case GL_ALPHA:
504 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400505 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
506 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400507 {
Jamie Madille0472f32018-11-27 16:32:45 -0500508 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400509 return false;
510 }
511 break;
512 case GL_LUMINANCE:
513 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
514 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
515 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400516 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT &&
517 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400518 {
Jamie Madille0472f32018-11-27 16:32:45 -0500519 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400520 return false;
521 }
522 break;
523 case GL_RED_EXT:
524 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
525 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
526 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
527 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F &&
528 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400529 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
530 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400531 {
Jamie Madille0472f32018-11-27 16:32:45 -0500532 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400533 return false;
534 }
535 break;
536 case GL_RG_EXT:
537 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
538 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
539 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
540 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400541 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
542 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400543 {
Jamie Madille0472f32018-11-27 16:32:45 -0500544 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400545 return false;
546 }
547 break;
548 case GL_RGB:
549 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
550 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
551 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400552 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
553 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400554 {
Jamie Madille0472f32018-11-27 16:32:45 -0500555 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400556 return false;
557 }
558 break;
559 case GL_LUMINANCE_ALPHA:
560 case GL_RGBA:
561 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400562 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F &&
563 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400564 {
Jamie Madille0472f32018-11-27 16:32:45 -0500565 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400566 return false;
567 }
568 break;
569 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
570 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
571 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
572 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
573 case GL_ETC1_RGB8_OES:
574 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
575 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
576 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
577 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
578 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
Olli Etuahof2ed2992018-10-04 13:54:42 +0300579 case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT:
580 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:
581 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT:
582 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT:
Jamie Madille0472f32018-11-27 16:32:45 -0500583 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400584 return false;
585 case GL_DEPTH_COMPONENT:
586 case GL_DEPTH_STENCIL_OES:
Jamie Madille0472f32018-11-27 16:32:45 -0500587 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400588 return false;
589 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500590 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400591 return false;
592 }
593
594 if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat)
595 {
Jamie Madille0472f32018-11-27 16:32:45 -0500596 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400597 return false;
598 }
599 }
600 else
601 {
602 switch (internalformat)
603 {
604 case GL_ALPHA:
605 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
606 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
607 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
608 {
Jamie Madille0472f32018-11-27 16:32:45 -0500609 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400610 return false;
611 }
612 break;
613 case GL_LUMINANCE:
614 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
615 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
616 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
617 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
618 colorbufferFormat != GL_BGR5_A1_ANGLEX)
619 {
Jamie Madille0472f32018-11-27 16:32:45 -0500620 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400621 return false;
622 }
623 break;
624 case GL_RED_EXT:
625 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
626 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
627 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
628 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
629 colorbufferFormat != GL_BGR5_A1_ANGLEX)
630 {
Jamie Madille0472f32018-11-27 16:32:45 -0500631 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400632 return false;
633 }
634 break;
635 case GL_RG_EXT:
636 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
637 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
638 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
639 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
640 {
Jamie Madille0472f32018-11-27 16:32:45 -0500641 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400642 return false;
643 }
644 break;
645 case GL_RGB:
646 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
647 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
648 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
649 colorbufferFormat != GL_BGR5_A1_ANGLEX)
650 {
Jamie Madille0472f32018-11-27 16:32:45 -0500651 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400652 return false;
653 }
654 break;
655 case GL_LUMINANCE_ALPHA:
656 case GL_RGBA:
657 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
658 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
659 colorbufferFormat != GL_BGR5_A1_ANGLEX)
660 {
Jamie Madille0472f32018-11-27 16:32:45 -0500661 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400662 return false;
663 }
664 break;
665 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
666 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
667 if (context->getExtensions().textureCompressionDXT1)
668 {
Jamie Madille0472f32018-11-27 16:32:45 -0500669 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400670 return false;
671 }
672 else
673 {
Jamie Madille0472f32018-11-27 16:32:45 -0500674 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400675 return false;
676 }
677 break;
678 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
679 if (context->getExtensions().textureCompressionDXT3)
680 {
Jamie Madille0472f32018-11-27 16:32:45 -0500681 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400682 return false;
683 }
684 else
685 {
Jamie Madille0472f32018-11-27 16:32:45 -0500686 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400687 return false;
688 }
689 break;
690 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
691 if (context->getExtensions().textureCompressionDXT5)
692 {
Jamie Madille0472f32018-11-27 16:32:45 -0500693 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400694 return false;
695 }
696 else
697 {
Jamie Madille0472f32018-11-27 16:32:45 -0500698 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400699 return false;
700 }
701 break;
702 case GL_ETC1_RGB8_OES:
703 if (context->getExtensions().compressedETC1RGB8Texture)
704 {
Jamie Madille0472f32018-11-27 16:32:45 -0500705 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400706 return false;
707 }
708 else
709 {
Jamie Madille0472f32018-11-27 16:32:45 -0500710 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400711 return false;
712 }
713 break;
714 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
715 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
716 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
717 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
718 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
719 if (context->getExtensions().lossyETCDecode)
720 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500721 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400722 return false;
723 }
724 else
725 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500726 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400727 return false;
728 }
729 break;
730 case GL_DEPTH_COMPONENT:
731 case GL_DEPTH_COMPONENT16:
732 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600733 if (context->getExtensions().depthTextureAny())
Jamie Madillbe849e42017-05-02 15:49:00 -0400734 {
Jamie Madille0472f32018-11-27 16:32:45 -0500735 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400736 return false;
737 }
738 else
739 {
Jamie Madille0472f32018-11-27 16:32:45 -0500740 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400741 return false;
742 }
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600743 break;
744 case GL_DEPTH_STENCIL_OES:
745 case GL_DEPTH24_STENCIL8_OES:
746 if (context->getExtensions().depthTextureAny() ||
747 context->getExtensions().packedDepthStencil)
748 {
749 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
750 return false;
751 }
752 else
753 {
754 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
755 return false;
756 }
757 break;
Jamie Madillbe849e42017-05-02 15:49:00 -0400758 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500759 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400760 return false;
761 }
762 }
763
764 // If width or height is zero, it is a no-op. Return false without setting an error.
765 return (width > 0 && height > 0);
766}
767
768bool ValidCap(const Context *context, GLenum cap, bool queryOnly)
769{
770 switch (cap)
771 {
772 // EXT_multisample_compatibility
773 case GL_MULTISAMPLE_EXT:
774 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
775 return context->getExtensions().multisampleCompatibility;
776
777 case GL_CULL_FACE:
778 case GL_POLYGON_OFFSET_FILL:
779 case GL_SAMPLE_ALPHA_TO_COVERAGE:
780 case GL_SAMPLE_COVERAGE:
781 case GL_SCISSOR_TEST:
782 case GL_STENCIL_TEST:
783 case GL_DEPTH_TEST:
784 case GL_BLEND:
785 case GL_DITHER:
786 return true;
787
788 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
789 case GL_RASTERIZER_DISCARD:
790 return (context->getClientMajorVersion() >= 3);
791
792 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
793 case GL_DEBUG_OUTPUT:
794 return context->getExtensions().debug;
795
796 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
797 return queryOnly && context->getExtensions().bindGeneratesResource;
798
799 case GL_CLIENT_ARRAYS_ANGLE:
800 return queryOnly && context->getExtensions().clientArrays;
801
802 case GL_FRAMEBUFFER_SRGB_EXT:
803 return context->getExtensions().sRGBWriteControl;
804
805 case GL_SAMPLE_MASK:
806 return context->getClientVersion() >= Version(3, 1);
807
Geoff Langb433e872017-10-05 14:01:47 -0400808 case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
Jamie Madillbe849e42017-05-02 15:49:00 -0400809 return queryOnly && context->getExtensions().robustResourceInitialization;
810
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700811 // GLES1 emulation: GLES1-specific caps
812 case GL_ALPHA_TEST:
Lingfeng Yang01074432018-04-16 10:19:51 -0700813 case GL_VERTEX_ARRAY:
814 case GL_NORMAL_ARRAY:
815 case GL_COLOR_ARRAY:
816 case GL_TEXTURE_COORD_ARRAY:
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700817 case GL_TEXTURE_2D:
Lingfeng Yangd0febe72018-05-17 22:36:52 -0700818 case GL_LIGHTING:
819 case GL_LIGHT0:
820 case GL_LIGHT1:
821 case GL_LIGHT2:
822 case GL_LIGHT3:
823 case GL_LIGHT4:
824 case GL_LIGHT5:
825 case GL_LIGHT6:
826 case GL_LIGHT7:
827 case GL_NORMALIZE:
828 case GL_RESCALE_NORMAL:
829 case GL_COLOR_MATERIAL:
Lingfeng Yang060088a2018-05-30 20:40:57 -0700830 case GL_CLIP_PLANE0:
831 case GL_CLIP_PLANE1:
832 case GL_CLIP_PLANE2:
833 case GL_CLIP_PLANE3:
834 case GL_CLIP_PLANE4:
835 case GL_CLIP_PLANE5:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -0700836 case GL_FOG:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700837 case GL_POINT_SMOOTH:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -0700838 case GL_LINE_SMOOTH:
839 case GL_COLOR_LOGIC_OP:
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700840 return context->getClientVersion() < Version(2, 0);
Lingfeng Yang01074432018-04-16 10:19:51 -0700841 case GL_POINT_SIZE_ARRAY_OES:
842 return context->getClientVersion() < Version(2, 0) &&
843 context->getExtensions().pointSizeArray;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700844 case GL_TEXTURE_CUBE_MAP:
845 return context->getClientVersion() < Version(2, 0) &&
846 context->getExtensions().textureCubeMap;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700847 case GL_POINT_SPRITE_OES:
848 return context->getClientVersion() < Version(2, 0) &&
849 context->getExtensions().pointSprite;
Jamie Madillbe849e42017-05-02 15:49:00 -0400850 default:
851 return false;
852 }
853}
854
Geoff Langfc32e8b2017-05-31 14:16:59 -0400855// Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section
856// 3.1.
Geoff Langcab92ee2017-07-19 17:32:07 -0400857bool IsValidESSLCharacter(unsigned char c)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400858{
859 // Printing characters are valid except " $ ` @ \ ' DEL.
Geoff Langcab92ee2017-07-19 17:32:07 -0400860 if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' &&
861 c != '\'')
Geoff Langfc32e8b2017-05-31 14:16:59 -0400862 {
863 return true;
864 }
865
866 // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid.
867 if (c >= 9 && c <= 13)
868 {
869 return true;
870 }
871
872 return false;
873}
874
Geoff Langcab92ee2017-07-19 17:32:07 -0400875bool IsValidESSLString(const char *str, size_t len)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400876{
Geoff Langa71a98e2017-06-19 15:15:00 -0400877 for (size_t i = 0; i < len; i++)
878 {
Geoff Langcab92ee2017-07-19 17:32:07 -0400879 if (!IsValidESSLCharacter(str[i]))
Geoff Langa71a98e2017-06-19 15:15:00 -0400880 {
881 return false;
882 }
883 }
884
885 return true;
Geoff Langfc32e8b2017-05-31 14:16:59 -0400886}
887
Geoff Langcab92ee2017-07-19 17:32:07 -0400888bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed)
889{
890 enum class ParseState
891 {
892 // Have not seen an ASCII non-whitespace character yet on
893 // this line. Possible that we might see a preprocessor
894 // directive.
895 BEGINING_OF_LINE,
896
897 // Have seen at least one ASCII non-whitespace character
898 // on this line.
899 MIDDLE_OF_LINE,
900
901 // Handling a preprocessor directive. Passes through all
902 // characters up to the end of the line. Disables comment
903 // processing.
904 IN_PREPROCESSOR_DIRECTIVE,
905
906 // Handling a single-line comment. The comment text is
907 // replaced with a single space.
908 IN_SINGLE_LINE_COMMENT,
909
910 // Handling a multi-line comment. Newlines are passed
911 // through to preserve line numbers.
912 IN_MULTI_LINE_COMMENT
913 };
914
915 ParseState state = ParseState::BEGINING_OF_LINE;
916 size_t pos = 0;
917
918 while (pos < len)
919 {
920 char c = str[pos];
921 char next = pos + 1 < len ? str[pos + 1] : 0;
922
923 // Check for newlines
924 if (c == '\n' || c == '\r')
925 {
926 if (state != ParseState::IN_MULTI_LINE_COMMENT)
927 {
928 state = ParseState::BEGINING_OF_LINE;
929 }
930
931 pos++;
932 continue;
933 }
934
935 switch (state)
936 {
937 case ParseState::BEGINING_OF_LINE:
938 if (c == ' ')
939 {
940 // Maintain the BEGINING_OF_LINE state until a non-space is seen
941 pos++;
942 }
943 else if (c == '#')
944 {
945 state = ParseState::IN_PREPROCESSOR_DIRECTIVE;
946 pos++;
947 }
948 else
949 {
950 // Don't advance, re-process this character with the MIDDLE_OF_LINE state
951 state = ParseState::MIDDLE_OF_LINE;
952 }
953 break;
954
955 case ParseState::MIDDLE_OF_LINE:
956 if (c == '/' && next == '/')
957 {
958 state = ParseState::IN_SINGLE_LINE_COMMENT;
959 pos++;
960 }
961 else if (c == '/' && next == '*')
962 {
963 state = ParseState::IN_MULTI_LINE_COMMENT;
964 pos++;
965 }
966 else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r'))
967 {
968 // Skip line continuation characters
969 }
970 else if (!IsValidESSLCharacter(c))
971 {
972 return false;
973 }
974 pos++;
975 break;
976
977 case ParseState::IN_PREPROCESSOR_DIRECTIVE:
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -0700978 // Line-continuation characters may not be permitted.
979 // Otherwise, just pass it through. Do not parse comments in this state.
980 if (!lineContinuationAllowed && c == '\\')
981 {
982 return false;
983 }
Geoff Langcab92ee2017-07-19 17:32:07 -0400984 pos++;
985 break;
986
987 case ParseState::IN_SINGLE_LINE_COMMENT:
988 // Line-continuation characters are processed before comment processing.
989 // Advance string if a new line character is immediately behind
990 // line-continuation character.
991 if (c == '\\' && (next == '\n' || next == '\r'))
992 {
993 pos++;
994 }
995 pos++;
996 break;
997
998 case ParseState::IN_MULTI_LINE_COMMENT:
999 if (c == '*' && next == '/')
1000 {
1001 state = ParseState::MIDDLE_OF_LINE;
1002 pos++;
1003 }
1004 pos++;
1005 break;
1006 }
1007 }
1008
1009 return true;
1010}
1011
Jamie Madill5b772312018-03-08 20:28:32 -05001012bool ValidateWebGLNamePrefix(Context *context, const GLchar *name)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001013{
1014 ASSERT(context->isWebGL());
1015
1016 // WebGL 1.0 [Section 6.16] GLSL Constructs
1017 // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL.
1018 if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0)
1019 {
Jamie Madille0472f32018-11-27 16:32:45 -05001020 context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001021 return false;
1022 }
1023
1024 return true;
1025}
1026
Jamie Madill5b772312018-03-08 20:28:32 -05001027bool ValidateWebGLNameLength(Context *context, size_t length)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001028{
1029 ASSERT(context->isWebGL());
1030
1031 if (context->isWebGL1() && length > 256)
1032 {
1033 // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths
1034 // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute
1035 // locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001036 context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001037
1038 return false;
1039 }
1040 else if (length > 1024)
1041 {
1042 // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of
1043 // uniform and attribute locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001044 context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001045 return false;
1046 }
1047
1048 return true;
1049}
1050
Jamie Madill007530e2017-12-28 14:27:04 -05001051bool ValidateMatrixMode(Context *context, GLenum matrixMode)
1052{
1053 if (!context->getExtensions().pathRendering)
1054 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001055 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05001056 return false;
1057 }
1058
1059 if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM)
1060 {
Jamie Madille0472f32018-11-27 16:32:45 -05001061 context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode);
Jamie Madill007530e2017-12-28 14:27:04 -05001062 return false;
1063 }
1064 return true;
1065}
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001066
1067bool ValidBlendFunc(const Context *context, GLenum val)
1068{
1069 const gl::Extensions &ext = context->getExtensions();
1070
1071 // these are always valid for src and dst.
1072 switch (val)
1073 {
1074 case GL_ZERO:
1075 case GL_ONE:
1076 case GL_SRC_COLOR:
1077 case GL_ONE_MINUS_SRC_COLOR:
1078 case GL_DST_COLOR:
1079 case GL_ONE_MINUS_DST_COLOR:
1080 case GL_SRC_ALPHA:
1081 case GL_ONE_MINUS_SRC_ALPHA:
1082 case GL_DST_ALPHA:
1083 case GL_ONE_MINUS_DST_ALPHA:
1084 case GL_CONSTANT_COLOR:
1085 case GL_ONE_MINUS_CONSTANT_COLOR:
1086 case GL_CONSTANT_ALPHA:
1087 case GL_ONE_MINUS_CONSTANT_ALPHA:
1088 return true;
1089
1090 // EXT_blend_func_extended.
1091 case GL_SRC1_COLOR_EXT:
1092 case GL_SRC1_ALPHA_EXT:
1093 case GL_ONE_MINUS_SRC1_COLOR_EXT:
1094 case GL_ONE_MINUS_SRC1_ALPHA_EXT:
1095 case GL_SRC_ALPHA_SATURATE_EXT:
1096 return ext.blendFuncExtended;
1097
1098 default:
1099 return false;
1100 }
1101}
1102
1103bool ValidSrcBlendFunc(const Context *context, GLenum val)
1104{
1105 if (ValidBlendFunc(context, val))
1106 return true;
1107
1108 if (val == GL_SRC_ALPHA_SATURATE)
1109 return true;
1110
1111 return false;
1112}
1113
1114bool ValidDstBlendFunc(const Context *context, GLenum val)
1115{
1116 if (ValidBlendFunc(context, val))
1117 return true;
1118
1119 if (val == GL_SRC_ALPHA_SATURATE)
1120 {
1121 if (context->getClientMajorVersion() >= 3)
1122 return true;
1123 }
1124
1125 return false;
1126}
Michael Spangab6a59b2019-05-21 21:26:26 -04001127
1128bool IsValidImageLayout(ImageLayout layout)
1129{
1130 switch (layout)
1131 {
Michael Spang6c824a12019-06-18 15:43:33 -04001132 case ImageLayout::Undefined:
Michael Spangab6a59b2019-05-21 21:26:26 -04001133 case ImageLayout::General:
1134 case ImageLayout::ColorAttachment:
1135 case ImageLayout::DepthStencilAttachment:
1136 case ImageLayout::DepthStencilReadOnlyAttachment:
1137 case ImageLayout::ShaderReadOnly:
1138 case ImageLayout::TransferSrc:
1139 case ImageLayout::TransferDst:
1140 case ImageLayout::DepthReadOnlyStencilAttachment:
1141 case ImageLayout::DepthAttachmentStencilReadOnly:
1142 return true;
1143
1144 default:
1145 return false;
1146 }
1147}
1148
Geoff Langff5b2d52016-09-07 11:32:23 -04001149bool ValidateES2TexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001150 TextureTarget target,
Geoff Langff5b2d52016-09-07 11:32:23 -04001151 GLint level,
1152 GLenum internalformat,
1153 bool isCompressed,
1154 bool isSubImage,
1155 GLint xoffset,
1156 GLint yoffset,
1157 GLsizei width,
1158 GLsizei height,
1159 GLint border,
1160 GLenum format,
1161 GLenum type,
1162 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001163 const void *pixels)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001164{
Jamie Madill6f38f822014-06-06 17:12:20 -04001165 if (!ValidTexture2DDestinationTarget(context, target))
1166 {
Jamie Madille0472f32018-11-27 16:32:45 -05001167 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001168 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001169 }
1170
Geoff Lang857880e2019-05-27 13:39:15 -04001171 return ValidateES2TexImageParametersBase(context, target, level, internalformat, isCompressed,
1172 isSubImage, xoffset, yoffset, width, height, border,
1173 format, type, imageSize, pixels);
1174}
1175
1176} // anonymous namespace
1177
1178bool ValidateES2TexImageParametersBase(Context *context,
1179 TextureTarget target,
1180 GLint level,
1181 GLenum internalformat,
1182 bool isCompressed,
1183 bool isSubImage,
1184 GLint xoffset,
1185 GLint yoffset,
1186 GLsizei width,
1187 GLsizei height,
1188 GLint border,
1189 GLenum format,
1190 GLenum type,
1191 GLsizei imageSize,
1192 const void *pixels)
1193{
1194
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001195 TextureType texType = TextureTargetToType(target);
1196 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001197 {
Jamie Madill610640f2018-11-21 17:28:41 -05001198 // Error already handled.
Geoff Langb1196682014-07-23 13:47:29 -04001199 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001200 }
1201
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001202 if (!ValidMipLevel(context, texType, level))
Brandon Jones6cad5662017-06-14 13:25:13 -07001203 {
Jamie Madille0472f32018-11-27 16:32:45 -05001204 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Brandon Jones6cad5662017-06-14 13:25:13 -07001205 return false;
1206 }
1207
1208 if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width ||
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001209 std::numeric_limits<GLsizei>::max() - yoffset < height)
1210 {
Jamie Madille0472f32018-11-27 16:32:45 -05001211 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Geoff Langb1196682014-07-23 13:47:29 -04001212 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001213 }
1214
Geoff Langaae65a42014-05-26 12:43:44 -04001215 const gl::Caps &caps = context->getCaps();
1216
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001217 switch (texType)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001218 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001219 case TextureType::_2D:
Geoff Lang857880e2019-05-27 13:39:15 -04001220 case TextureType::External:
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001221 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
1222 static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
1223 {
Jamie Madille0472f32018-11-27 16:32:45 -05001224 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001225 return false;
1226 }
1227 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001228
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001229 case TextureType::Rectangle:
1230 ASSERT(level == 0);
1231 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1232 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1233 {
Jamie Madille0472f32018-11-27 16:32:45 -05001234 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001235 return false;
1236 }
1237 if (isCompressed)
1238 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001239 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001240 return false;
1241 }
1242 break;
1243
1244 case TextureType::CubeMap:
1245 if (!isSubImage && width != height)
1246 {
Jamie Madille0472f32018-11-27 16:32:45 -05001247 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001248 return false;
1249 }
1250
1251 if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) ||
1252 static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level))
1253 {
Jamie Madille0472f32018-11-27 16:32:45 -05001254 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001255 return false;
1256 }
1257 break;
1258
1259 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001260 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langa9be0dc2014-12-17 12:34:40 -05001261 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001262 }
1263
Jamie Madillcfc73cc2019-04-08 16:26:51 -04001264 gl::Texture *texture = context->getTextureByType(texType);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001265 if (!texture)
1266 {
Jamie Madille0472f32018-11-27 16:32:45 -05001267 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Geoff Langb1196682014-07-23 13:47:29 -04001268 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001269 }
1270
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001271 // Verify zero border
1272 if (border != 0)
1273 {
Jamie Madille0472f32018-11-27 16:32:45 -05001274 context->validationError(GL_INVALID_VALUE, kInvalidBorder);
Geoff Langb1196682014-07-23 13:47:29 -04001275 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001276 }
1277
Tim Van Patten208af3e2019-03-19 09:15:55 -06001278 bool nonEqualFormatsAllowed = false;
1279
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001280 if (isCompressed)
1281 {
tmartino0ccd5ae2015-10-01 14:33:14 -04001282 GLenum actualInternalFormat =
Geoff Langca271392017-04-05 12:30:00 -04001283 isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat
1284 : internalformat;
Geoff Lange88e4542018-05-03 15:05:57 -04001285
1286 const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat);
1287
1288 if (!internalFormatInfo.compressed)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001289 {
Jamie Madille0472f32018-11-27 16:32:45 -05001290 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001291 return false;
1292 }
1293
1294 if (!internalFormatInfo.textureSupport(context->getClientVersion(),
1295 context->getExtensions()))
1296 {
Jamie Madille0472f32018-11-27 16:32:45 -05001297 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001298 return false;
tmartino0ccd5ae2015-10-01 14:33:14 -04001299 }
Geoff Lang966c9402017-04-18 12:38:27 -04001300
1301 if (isSubImage)
tmartino0ccd5ae2015-10-01 14:33:14 -04001302 {
Geoff Lange88e4542018-05-03 15:05:57 -04001303 // From the OES_compressed_ETC1_RGB8_texture spec:
1304 // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or
1305 // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format
1306 // ETC1_RGB8_OES.
1307 if (actualInternalFormat == GL_ETC1_RGB8_OES)
1308 {
Jamie Madille0472f32018-11-27 16:32:45 -05001309 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001310 return false;
1311 }
1312
Geoff Lang966c9402017-04-18 12:38:27 -04001313 if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width,
1314 height, texture->getWidth(target, level),
1315 texture->getHeight(target, level)))
1316 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001317 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001318 return false;
1319 }
1320
1321 if (format != actualInternalFormat)
1322 {
Jamie Madille0472f32018-11-27 16:32:45 -05001323 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Geoff Lang966c9402017-04-18 12:38:27 -04001324 return false;
1325 }
1326 }
1327 else
1328 {
1329 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height))
1330 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001331 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001332 return false;
1333 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001334 }
1335 }
1336 else
1337 {
1338 // validate <type> by itself (used as secondary key below)
1339 switch (type)
1340 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001341 case GL_UNSIGNED_BYTE:
1342 case GL_UNSIGNED_SHORT_5_6_5:
1343 case GL_UNSIGNED_SHORT_4_4_4_4:
1344 case GL_UNSIGNED_SHORT_5_5_5_1:
1345 case GL_UNSIGNED_SHORT:
1346 case GL_UNSIGNED_INT:
1347 case GL_UNSIGNED_INT_24_8_OES:
1348 case GL_HALF_FLOAT_OES:
1349 case GL_FLOAT:
1350 break;
1351 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001352 context->validationError(GL_INVALID_ENUM, kInvalidType);
He Yunchaoced53ae2016-11-29 15:00:51 +08001353 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001354 }
1355
1356 // validate <format> + <type> combinations
1357 // - invalid <format> -> sets INVALID_ENUM
1358 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
1359 switch (format)
1360 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001361 case GL_ALPHA:
1362 case GL_LUMINANCE:
1363 case GL_LUMINANCE_ALPHA:
1364 switch (type)
1365 {
1366 case GL_UNSIGNED_BYTE:
1367 case GL_FLOAT:
1368 case GL_HALF_FLOAT_OES:
1369 break;
1370 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001371 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001372 return false;
1373 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001374 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001375 case GL_RED:
1376 case GL_RG:
1377 if (!context->getExtensions().textureRG)
1378 {
Jamie Madille0472f32018-11-27 16:32:45 -05001379 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001380 return false;
1381 }
1382 switch (type)
1383 {
1384 case GL_UNSIGNED_BYTE:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001385 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001386 case GL_FLOAT:
1387 case GL_HALF_FLOAT_OES:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001388 if (!context->getExtensions().textureFloat)
1389 {
Jamie Madille0472f32018-11-27 16:32:45 -05001390 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001391 return false;
1392 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001393 break;
1394 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001395 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001396 return false;
1397 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001398 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001399 case GL_RGB:
1400 switch (type)
1401 {
1402 case GL_UNSIGNED_BYTE:
1403 case GL_UNSIGNED_SHORT_5_6_5:
1404 case GL_FLOAT:
1405 case GL_HALF_FLOAT_OES:
1406 break;
1407 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001408 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001409 return false;
1410 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001411 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001412 case GL_RGBA:
1413 switch (type)
1414 {
1415 case GL_UNSIGNED_BYTE:
1416 case GL_UNSIGNED_SHORT_4_4_4_4:
1417 case GL_UNSIGNED_SHORT_5_5_5_1:
1418 case GL_FLOAT:
1419 case GL_HALF_FLOAT_OES:
1420 break;
1421 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001422 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001423 return false;
1424 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001425 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001426 case GL_BGRA_EXT:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001427 if (!context->getExtensions().textureFormatBGRA8888)
1428 {
Jamie Madille0472f32018-11-27 16:32:45 -05001429 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001430 return false;
1431 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001432 switch (type)
1433 {
1434 case GL_UNSIGNED_BYTE:
1435 break;
1436 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001437 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001438 return false;
1439 }
1440 break;
1441 case GL_SRGB_EXT:
1442 case GL_SRGB_ALPHA_EXT:
1443 if (!context->getExtensions().sRGB)
1444 {
Jamie Madille0472f32018-11-27 16:32:45 -05001445 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001446 return false;
1447 }
1448 switch (type)
1449 {
1450 case GL_UNSIGNED_BYTE:
1451 break;
1452 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001453 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001454 return false;
1455 }
1456 break;
1457 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are
1458 // handled below
1459 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1460 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1461 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1462 break;
1463 case GL_DEPTH_COMPONENT:
1464 switch (type)
1465 {
1466 case GL_UNSIGNED_SHORT:
1467 case GL_UNSIGNED_INT:
1468 break;
1469 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001470 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001471 return false;
1472 }
1473 break;
1474 case GL_DEPTH_STENCIL_OES:
1475 switch (type)
1476 {
1477 case GL_UNSIGNED_INT_24_8_OES:
1478 break;
1479 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001480 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001481 return false;
1482 }
1483 break;
1484 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001485 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001486 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001487 }
1488
1489 switch (format)
1490 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001491 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1492 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1493 if (context->getExtensions().textureCompressionDXT1)
1494 {
Jamie Madille0472f32018-11-27 16:32:45 -05001495 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001496 return false;
1497 }
1498 else
1499 {
Jamie Madille0472f32018-11-27 16:32:45 -05001500 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001501 return false;
1502 }
1503 break;
1504 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1505 if (context->getExtensions().textureCompressionDXT3)
1506 {
Jamie Madille0472f32018-11-27 16:32:45 -05001507 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001508 return false;
1509 }
1510 else
1511 {
Jamie Madille0472f32018-11-27 16:32:45 -05001512 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001513 return false;
1514 }
1515 break;
1516 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1517 if (context->getExtensions().textureCompressionDXT5)
1518 {
Jamie Madille0472f32018-11-27 16:32:45 -05001519 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001520 return false;
1521 }
1522 else
1523 {
Jamie Madille0472f32018-11-27 16:32:45 -05001524 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001525 return false;
1526 }
1527 break;
1528 case GL_ETC1_RGB8_OES:
1529 if (context->getExtensions().compressedETC1RGB8Texture)
1530 {
Jamie Madille0472f32018-11-27 16:32:45 -05001531 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001532 return false;
1533 }
1534 else
1535 {
Jamie Madille0472f32018-11-27 16:32:45 -05001536 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001537 return false;
1538 }
1539 break;
1540 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001541 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1542 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1543 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1544 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001545 if (context->getExtensions().lossyETCDecode)
1546 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001547 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001548 return false;
1549 }
1550 else
1551 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001552 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001553 return false;
1554 }
1555 break;
1556 case GL_DEPTH_COMPONENT:
1557 case GL_DEPTH_STENCIL_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001558 if (!context->getExtensions().depthTextureANGLE &&
1559 !(context->getExtensions().packedDepthStencil &&
1560 context->getExtensions().depthTextureOES))
He Yunchaoced53ae2016-11-29 15:00:51 +08001561 {
Jamie Madille0472f32018-11-27 16:32:45 -05001562 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001563 return false;
1564 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001565 if (target != TextureTarget::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001566 {
Jamie Madille0472f32018-11-27 16:32:45 -05001567 context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001568 return false;
1569 }
1570 // OES_depth_texture supports loading depth data and multiple levels,
1571 // but ANGLE_depth_texture does not
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001572 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001573 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001574 if (pixels != nullptr)
1575 {
1576 context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
1577 return false;
1578 }
1579 if (level != 0)
1580 {
1581 context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
1582 return false;
1583 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001584 }
1585 break;
1586 default:
1587 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001588 }
1589
Geoff Lang6e898aa2017-06-02 11:17:26 -04001590 if (!isSubImage)
1591 {
1592 switch (internalformat)
1593 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001594 // Core ES 2.0 formats
1595 case GL_ALPHA:
1596 case GL_LUMINANCE:
1597 case GL_LUMINANCE_ALPHA:
1598 case GL_RGB:
1599 case GL_RGBA:
1600 break;
1601
Geoff Lang6e898aa2017-06-02 11:17:26 -04001602 case GL_RGBA32F:
1603 if (!context->getExtensions().colorBufferFloatRGBA)
1604 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001605 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001606 return false;
1607 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001608
1609 nonEqualFormatsAllowed = true;
1610
Geoff Lang6e898aa2017-06-02 11:17:26 -04001611 if (type != GL_FLOAT)
1612 {
Jamie Madille0472f32018-11-27 16:32:45 -05001613 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001614 return false;
1615 }
1616 if (format != GL_RGBA)
1617 {
Jamie Madille0472f32018-11-27 16:32:45 -05001618 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001619 return false;
1620 }
1621 break;
1622
1623 case GL_RGB32F:
1624 if (!context->getExtensions().colorBufferFloatRGB)
1625 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001626 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001627 return false;
1628 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001629
1630 nonEqualFormatsAllowed = true;
1631
Geoff Lang6e898aa2017-06-02 11:17:26 -04001632 if (type != GL_FLOAT)
1633 {
Jamie Madille0472f32018-11-27 16:32:45 -05001634 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001635 return false;
1636 }
1637 if (format != GL_RGB)
1638 {
Jamie Madille0472f32018-11-27 16:32:45 -05001639 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001640 return false;
1641 }
1642 break;
1643
Tim Van Patten208af3e2019-03-19 09:15:55 -06001644 case GL_BGRA_EXT:
1645 if (!context->getExtensions().textureFormatBGRA8888)
1646 {
1647 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1648 return false;
1649 }
Geoff Lang6e898aa2017-06-02 11:17:26 -04001650 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001651
1652 case GL_DEPTH_COMPONENT:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001653 if (!(context->getExtensions().depthTextureAny()))
1654 {
1655 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1656 return false;
1657 }
1658 break;
1659
Tim Van Patten208af3e2019-03-19 09:15:55 -06001660 case GL_DEPTH_STENCIL:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001661 if (!(context->getExtensions().depthTextureANGLE ||
1662 context->getExtensions().packedDepthStencil))
Tim Van Patten208af3e2019-03-19 09:15:55 -06001663 {
1664 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1665 return false;
1666 }
1667 break;
1668
1669 case GL_RED:
1670 case GL_RG:
1671 if (!context->getExtensions().textureRG)
1672 {
1673 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1674 return false;
1675 }
1676 break;
1677
1678 case GL_SRGB_EXT:
1679 case GL_SRGB_ALPHA_EXT:
1680 if (!context->getExtensions().sRGB)
1681 {
1682 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1683 return false;
1684 }
1685 break;
1686
1687 default:
1688 context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat);
1689 return false;
Geoff Lang6e898aa2017-06-02 11:17:26 -04001690 }
1691 }
1692
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001693 if (type == GL_FLOAT)
1694 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001695 if (!context->getExtensions().textureFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001696 {
Jamie Madille0472f32018-11-27 16:32:45 -05001697 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001698 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001699 }
1700 }
1701 else if (type == GL_HALF_FLOAT_OES)
1702 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001703 if (!context->getExtensions().textureHalfFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001704 {
Jamie Madille0472f32018-11-27 16:32:45 -05001705 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001706 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001707 }
1708 }
1709 }
1710
Tim Van Patten208af3e2019-03-19 09:15:55 -06001711 if (isSubImage)
Geoff Langff5b2d52016-09-07 11:32:23 -04001712 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001713 const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info;
1714 if (textureInternalFormat.internalFormat == GL_NONE)
1715 {
1716 context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel);
1717 return false;
1718 }
1719
Tim Van Patten5f388c22019-03-14 09:54:23 -06001720 if (format != textureInternalFormat.format)
1721 {
1722 context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch);
1723 return false;
1724 }
1725
1726 if (context->getExtensions().webglCompatibility)
Tim Van Patten208af3e2019-03-19 09:15:55 -06001727 {
1728 if (GetInternalFormatInfo(format, type).sizedInternalFormat !=
1729 textureInternalFormat.sizedInternalFormat)
1730 {
Tim Van Patten5f388c22019-03-14 09:54:23 -06001731 context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch);
Tim Van Patten208af3e2019-03-19 09:15:55 -06001732 return false;
1733 }
1734 }
1735
1736 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
1737 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level))
1738 {
1739 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
1740 return false;
1741 }
1742
1743 if (width > 0 && height > 0 && pixels == nullptr &&
1744 context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr)
1745 {
1746 context->validationError(GL_INVALID_VALUE, kPixelDataNull);
1747 return false;
1748 }
1749 }
1750 else
1751 {
1752 if (texture->getImmutableFormat())
1753 {
1754 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
1755 return false;
1756 }
1757 }
1758
1759 // From GL_CHROMIUM_color_buffer_float_rgb[a]:
1760 // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
1761 // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
1762 // internalformat parameter and format parameter of TexImage2D must match is lifted for this
1763 // case.
1764 if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
1765 {
1766 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Langff5b2d52016-09-07 11:32:23 -04001767 return false;
1768 }
1769
Tim Van Patten208af3e2019-03-19 09:15:55 -06001770 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
1771 return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels,
1772 imageSize);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001773}
1774
He Yunchaoced53ae2016-11-29 15:00:51 +08001775bool ValidateES2TexStorageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001776 TextureType target,
He Yunchaoced53ae2016-11-29 15:00:51 +08001777 GLsizei levels,
1778 GLenum internalformat,
1779 GLsizei width,
1780 GLsizei height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001781{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001782 if (target != TextureType::_2D && target != TextureType::CubeMap &&
1783 target != TextureType::Rectangle)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001784 {
Jamie Madille0472f32018-11-27 16:32:45 -05001785 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001786 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001787 }
1788
1789 if (width < 1 || height < 1 || levels < 1)
1790 {
Jamie Madille0472f32018-11-27 16:32:45 -05001791 context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall);
Geoff Langb1196682014-07-23 13:47:29 -04001792 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001793 }
1794
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001795 if (target == TextureType::CubeMap && width != height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001796 {
Jamie Madille0472f32018-11-27 16:32:45 -05001797 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Langb1196682014-07-23 13:47:29 -04001798 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001799 }
1800
1801 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1802 {
Jamie Madille0472f32018-11-27 16:32:45 -05001803 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
Geoff Langb1196682014-07-23 13:47:29 -04001804 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001805 }
1806
Geoff Langca271392017-04-05 12:30:00 -04001807 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Lang5d601382014-07-22 15:14:06 -04001808 if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001809 {
Jamie Madille0472f32018-11-27 16:32:45 -05001810 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Langb1196682014-07-23 13:47:29 -04001811 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001812 }
1813
Geoff Langaae65a42014-05-26 12:43:44 -04001814 const gl::Caps &caps = context->getCaps();
1815
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001816 switch (target)
1817 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001818 case TextureType::_2D:
He Yunchaoced53ae2016-11-29 15:00:51 +08001819 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
1820 static_cast<GLuint>(height) > caps.max2DTextureSize)
1821 {
Jamie Madille0472f32018-11-27 16:32:45 -05001822 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001823 return false;
1824 }
1825 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001826 case TextureType::Rectangle:
Jamie Madill610640f2018-11-21 17:28:41 -05001827 if (levels != 1)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001828 {
Jamie Madille0472f32018-11-27 16:32:45 -05001829 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madill610640f2018-11-21 17:28:41 -05001830 return false;
1831 }
1832
1833 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1834 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1835 {
Jamie Madille0472f32018-11-27 16:32:45 -05001836 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001837 return false;
1838 }
1839 if (formatInfo.compressed)
1840 {
Jamie Madille0472f32018-11-27 16:32:45 -05001841 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001842 return false;
1843 }
1844 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001845 case TextureType::CubeMap:
He Yunchaoced53ae2016-11-29 15:00:51 +08001846 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize ||
1847 static_cast<GLuint>(height) > caps.maxCubeMapTextureSize)
1848 {
Jamie Madille0472f32018-11-27 16:32:45 -05001849 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001850 return false;
1851 }
1852 break;
1853 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001854 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001855 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001856 }
1857
Geoff Langc0b9ef42014-07-02 10:02:37 -04001858 if (levels != 1 && !context->getExtensions().textureNPOT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001859 {
1860 if (!gl::isPow2(width) || !gl::isPow2(height))
1861 {
Jamie Madille0472f32018-11-27 16:32:45 -05001862 context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2);
Geoff Langb1196682014-07-23 13:47:29 -04001863 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001864 }
1865 }
1866
1867 switch (internalformat)
1868 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001869 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1870 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1871 if (!context->getExtensions().textureCompressionDXT1)
1872 {
Jamie Madille0472f32018-11-27 16:32:45 -05001873 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001874 return false;
1875 }
1876 break;
1877 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1878 if (!context->getExtensions().textureCompressionDXT3)
1879 {
Jamie Madille0472f32018-11-27 16:32:45 -05001880 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001881 return false;
1882 }
1883 break;
1884 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1885 if (!context->getExtensions().textureCompressionDXT5)
1886 {
Jamie Madille0472f32018-11-27 16:32:45 -05001887 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001888 return false;
1889 }
1890 break;
1891 case GL_ETC1_RGB8_OES:
1892 if (!context->getExtensions().compressedETC1RGB8Texture)
1893 {
Jamie Madille0472f32018-11-27 16:32:45 -05001894 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001895 return false;
1896 }
1897 break;
1898 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001899 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1900 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1901 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1902 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001903 if (!context->getExtensions().lossyETCDecode)
1904 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001905 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001906 return false;
1907 }
1908 break;
1909 case GL_RGBA32F_EXT:
1910 case GL_RGB32F_EXT:
1911 case GL_ALPHA32F_EXT:
1912 case GL_LUMINANCE32F_EXT:
1913 case GL_LUMINANCE_ALPHA32F_EXT:
1914 if (!context->getExtensions().textureFloat)
1915 {
Jamie Madille0472f32018-11-27 16:32:45 -05001916 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001917 return false;
1918 }
1919 break;
1920 case GL_RGBA16F_EXT:
1921 case GL_RGB16F_EXT:
1922 case GL_ALPHA16F_EXT:
1923 case GL_LUMINANCE16F_EXT:
1924 case GL_LUMINANCE_ALPHA16F_EXT:
1925 if (!context->getExtensions().textureHalfFloat)
1926 {
Jamie Madille0472f32018-11-27 16:32:45 -05001927 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001928 return false;
1929 }
1930 break;
1931 case GL_R8_EXT:
1932 case GL_RG8_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001933 if (!context->getExtensions().textureRG)
1934 {
Jamie Madille0472f32018-11-27 16:32:45 -05001935 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001936 return false;
1937 }
1938 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001939 case GL_R16F_EXT:
1940 case GL_RG16F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001941 if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat)
1942 {
Jamie Madille0472f32018-11-27 16:32:45 -05001943 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001944 return false;
1945 }
1946 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001947 case GL_R32F_EXT:
1948 case GL_RG32F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001949 if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat)
He Yunchaoced53ae2016-11-29 15:00:51 +08001950 {
Jamie Madille0472f32018-11-27 16:32:45 -05001951 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001952 return false;
1953 }
1954 break;
1955 case GL_DEPTH_COMPONENT16:
1956 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001957 if (!(context->getExtensions().depthTextureAny()))
He Yunchaoced53ae2016-11-29 15:00:51 +08001958 {
Jamie Madille0472f32018-11-27 16:32:45 -05001959 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001960 return false;
1961 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001962 if (target != TextureType::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001963 {
Jamie Madille0472f32018-11-27 16:32:45 -05001964 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001965 return false;
1966 }
1967 // ANGLE_depth_texture only supports 1-level textures
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001968 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001969 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001970 if (levels != 1)
1971 {
1972 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1973 return false;
1974 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001975 }
1976 break;
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001977 case GL_DEPTH24_STENCIL8_OES:
1978 if (!(context->getExtensions().depthTextureANGLE ||
1979 (context->getExtensions().packedDepthStencil &&
1980 context->getExtensions().textureStorage)))
1981 {
1982 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1983 return false;
1984 }
1985 if (target != TextureType::_2D)
1986 {
1987 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
1988 return false;
1989 }
1990 if (!context->getExtensions().packedDepthStencil)
1991 {
1992 // ANGLE_depth_texture only supports 1-level textures
1993 if (levels != 1)
1994 {
1995 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1996 return false;
1997 }
1998 }
1999 break;
2000
He Yunchaoced53ae2016-11-29 15:00:51 +08002001 default:
2002 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002003 }
2004
Jamie Madillcfc73cc2019-04-08 16:26:51 -04002005 gl::Texture *texture = context->getTextureByType(target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002006 if (!texture || texture->id() == 0)
2007 {
Jamie Madille0472f32018-11-27 16:32:45 -05002008 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
Geoff Langb1196682014-07-23 13:47:29 -04002009 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002010 }
2011
Geoff Lang69cce582015-09-17 13:20:36 -04002012 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002013 {
Jamie Madille0472f32018-11-27 16:32:45 -05002014 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
Geoff Langb1196682014-07-23 13:47:29 -04002015 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002016 }
2017
2018 return true;
2019}
2020
He Yunchaoced53ae2016-11-29 15:00:51 +08002021bool ValidateDiscardFramebufferEXT(Context *context,
2022 GLenum target,
2023 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07002024 const GLenum *attachments)
2025{
Jamie Madillc29968b2016-01-20 11:17:23 -05002026 if (!context->getExtensions().discardFramebuffer)
2027 {
Jamie Madille0472f32018-11-27 16:32:45 -05002028 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002029 return false;
2030 }
2031
Austin Kinross08332632015-05-05 13:35:47 -07002032 bool defaultFramebuffer = false;
2033
2034 switch (target)
2035 {
He Yunchaoced53ae2016-11-29 15:00:51 +08002036 case GL_FRAMEBUFFER:
2037 defaultFramebuffer =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002038 (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0);
He Yunchaoced53ae2016-11-29 15:00:51 +08002039 break;
2040 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002041 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08002042 return false;
Austin Kinross08332632015-05-05 13:35:47 -07002043 }
2044
He Yunchaoced53ae2016-11-29 15:00:51 +08002045 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
2046 defaultFramebuffer);
Austin Kinross08332632015-05-05 13:35:47 -07002047}
2048
Austin Kinrossbc781f32015-10-26 09:27:38 -07002049bool ValidateBindVertexArrayOES(Context *context, GLuint array)
2050{
2051 if (!context->getExtensions().vertexArrayObject)
2052 {
Jamie Madille0472f32018-11-27 16:32:45 -05002053 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002054 return false;
2055 }
2056
2057 return ValidateBindVertexArrayBase(context, array);
2058}
2059
Jamie Madilld7576732017-08-26 18:49:50 -04002060bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002061{
2062 if (!context->getExtensions().vertexArrayObject)
2063 {
Jamie Madille0472f32018-11-27 16:32:45 -05002064 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002065 return false;
2066 }
2067
Olli Etuaho41997e72016-03-10 13:38:39 +02002068 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002069}
2070
Jamie Madilld7576732017-08-26 18:49:50 -04002071bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002072{
2073 if (!context->getExtensions().vertexArrayObject)
2074 {
Jamie Madille0472f32018-11-27 16:32:45 -05002075 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002076 return false;
2077 }
2078
Olli Etuaho41997e72016-03-10 13:38:39 +02002079 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002080}
2081
Jamie Madilld7576732017-08-26 18:49:50 -04002082bool ValidateIsVertexArrayOES(Context *context, GLuint array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002083{
2084 if (!context->getExtensions().vertexArrayObject)
2085 {
Jamie Madille0472f32018-11-27 16:32:45 -05002086 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002087 return false;
2088 }
2089
2090 return true;
2091}
Geoff Langc5629752015-12-07 16:29:04 -05002092
2093bool ValidateProgramBinaryOES(Context *context,
2094 GLuint program,
2095 GLenum binaryFormat,
2096 const void *binary,
2097 GLint length)
2098{
2099 if (!context->getExtensions().getProgramBinary)
2100 {
Jamie Madille0472f32018-11-27 16:32:45 -05002101 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002102 return false;
2103 }
2104
2105 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
2106}
2107
2108bool ValidateGetProgramBinaryOES(Context *context,
2109 GLuint program,
2110 GLsizei bufSize,
2111 GLsizei *length,
2112 GLenum *binaryFormat,
2113 void *binary)
2114{
2115 if (!context->getExtensions().getProgramBinary)
2116 {
Jamie Madille0472f32018-11-27 16:32:45 -05002117 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002118 return false;
2119 }
2120
2121 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
2122}
Geoff Lange102fee2015-12-10 11:23:30 -05002123
Geoff Lang70d0f492015-12-10 17:45:46 -05002124static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication)
2125{
2126 switch (source)
2127 {
2128 case GL_DEBUG_SOURCE_API:
2129 case GL_DEBUG_SOURCE_SHADER_COMPILER:
2130 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
2131 case GL_DEBUG_SOURCE_OTHER:
2132 // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted
2133 return !mustBeThirdPartyOrApplication;
2134
2135 case GL_DEBUG_SOURCE_THIRD_PARTY:
2136 case GL_DEBUG_SOURCE_APPLICATION:
2137 return true;
2138
2139 default:
2140 return false;
2141 }
2142}
2143
2144static bool ValidDebugType(GLenum type)
2145{
2146 switch (type)
2147 {
2148 case GL_DEBUG_TYPE_ERROR:
2149 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
2150 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
2151 case GL_DEBUG_TYPE_PERFORMANCE:
2152 case GL_DEBUG_TYPE_PORTABILITY:
2153 case GL_DEBUG_TYPE_OTHER:
2154 case GL_DEBUG_TYPE_MARKER:
2155 case GL_DEBUG_TYPE_PUSH_GROUP:
2156 case GL_DEBUG_TYPE_POP_GROUP:
2157 return true;
2158
2159 default:
2160 return false;
2161 }
2162}
2163
2164static bool ValidDebugSeverity(GLenum severity)
2165{
2166 switch (severity)
2167 {
2168 case GL_DEBUG_SEVERITY_HIGH:
2169 case GL_DEBUG_SEVERITY_MEDIUM:
2170 case GL_DEBUG_SEVERITY_LOW:
2171 case GL_DEBUG_SEVERITY_NOTIFICATION:
2172 return true;
2173
2174 default:
2175 return false;
2176 }
2177}
2178
Geoff Lange102fee2015-12-10 11:23:30 -05002179bool ValidateDebugMessageControlKHR(Context *context,
2180 GLenum source,
2181 GLenum type,
2182 GLenum severity,
2183 GLsizei count,
2184 const GLuint *ids,
2185 GLboolean enabled)
2186{
2187 if (!context->getExtensions().debug)
2188 {
Jamie Madille0472f32018-11-27 16:32:45 -05002189 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002190 return false;
2191 }
2192
Geoff Lang70d0f492015-12-10 17:45:46 -05002193 if (!ValidDebugSource(source, false) && source != GL_DONT_CARE)
2194 {
Jamie Madille0472f32018-11-27 16:32:45 -05002195 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002196 return false;
2197 }
2198
2199 if (!ValidDebugType(type) && type != GL_DONT_CARE)
2200 {
Jamie Madille0472f32018-11-27 16:32:45 -05002201 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002202 return false;
2203 }
2204
2205 if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE)
2206 {
Jamie Madille0472f32018-11-27 16:32:45 -05002207 context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002208 return false;
2209 }
2210
2211 if (count > 0)
2212 {
2213 if (source == GL_DONT_CARE || type == GL_DONT_CARE)
2214 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002215 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002216 return false;
2217 }
2218
2219 if (severity != GL_DONT_CARE)
2220 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002221 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002222 return false;
2223 }
2224 }
2225
Geoff Lange102fee2015-12-10 11:23:30 -05002226 return true;
2227}
2228
2229bool ValidateDebugMessageInsertKHR(Context *context,
2230 GLenum source,
2231 GLenum type,
2232 GLuint id,
2233 GLenum severity,
2234 GLsizei length,
2235 const GLchar *buf)
2236{
2237 if (!context->getExtensions().debug)
2238 {
Jamie Madille0472f32018-11-27 16:32:45 -05002239 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002240 return false;
2241 }
2242
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002243 if (!context->getState().getDebug().isOutputEnabled())
Geoff Lang70d0f492015-12-10 17:45:46 -05002244 {
2245 // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do
2246 // not generate an error.
2247 return false;
2248 }
2249
2250 if (!ValidDebugSeverity(severity))
2251 {
Jamie Madille0472f32018-11-27 16:32:45 -05002252 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002253 return false;
2254 }
2255
2256 if (!ValidDebugType(type))
2257 {
Jamie Madille0472f32018-11-27 16:32:45 -05002258 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002259 return false;
2260 }
2261
2262 if (!ValidDebugSource(source, true))
2263 {
Jamie Madille0472f32018-11-27 16:32:45 -05002264 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002265 return false;
2266 }
2267
2268 size_t messageLength = (length < 0) ? strlen(buf) : length;
2269 if (messageLength > context->getExtensions().maxDebugMessageLength)
2270 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002271 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002272 return false;
2273 }
2274
Geoff Lange102fee2015-12-10 11:23:30 -05002275 return true;
2276}
2277
2278bool ValidateDebugMessageCallbackKHR(Context *context,
2279 GLDEBUGPROCKHR callback,
2280 const void *userParam)
2281{
2282 if (!context->getExtensions().debug)
2283 {
Jamie Madille0472f32018-11-27 16:32:45 -05002284 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002285 return false;
2286 }
2287
Geoff Lange102fee2015-12-10 11:23:30 -05002288 return true;
2289}
2290
2291bool ValidateGetDebugMessageLogKHR(Context *context,
2292 GLuint count,
2293 GLsizei bufSize,
2294 GLenum *sources,
2295 GLenum *types,
2296 GLuint *ids,
2297 GLenum *severities,
2298 GLsizei *lengths,
2299 GLchar *messageLog)
2300{
2301 if (!context->getExtensions().debug)
2302 {
Jamie Madille0472f32018-11-27 16:32:45 -05002303 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002304 return false;
2305 }
2306
Geoff Lang70d0f492015-12-10 17:45:46 -05002307 if (bufSize < 0 && messageLog != nullptr)
2308 {
Jamie Madille0472f32018-11-27 16:32:45 -05002309 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002310 return false;
2311 }
2312
Geoff Lange102fee2015-12-10 11:23:30 -05002313 return true;
2314}
2315
2316bool ValidatePushDebugGroupKHR(Context *context,
2317 GLenum source,
2318 GLuint id,
2319 GLsizei length,
2320 const GLchar *message)
2321{
2322 if (!context->getExtensions().debug)
2323 {
Jamie Madille0472f32018-11-27 16:32:45 -05002324 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002325 return false;
2326 }
2327
Geoff Lang70d0f492015-12-10 17:45:46 -05002328 if (!ValidDebugSource(source, true))
2329 {
Jamie Madille0472f32018-11-27 16:32:45 -05002330 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002331 return false;
2332 }
2333
2334 size_t messageLength = (length < 0) ? strlen(message) : length;
2335 if (messageLength > context->getExtensions().maxDebugMessageLength)
2336 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002337 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002338 return false;
2339 }
2340
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002341 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002342 if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth)
2343 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002344 context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth);
Geoff Lang70d0f492015-12-10 17:45:46 -05002345 return false;
2346 }
2347
Geoff Lange102fee2015-12-10 11:23:30 -05002348 return true;
2349}
2350
2351bool ValidatePopDebugGroupKHR(Context *context)
2352{
2353 if (!context->getExtensions().debug)
2354 {
Jamie Madille0472f32018-11-27 16:32:45 -05002355 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002356 return false;
2357 }
2358
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002359 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002360 if (currentStackSize <= 1)
2361 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002362 context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup);
Geoff Lang70d0f492015-12-10 17:45:46 -05002363 return false;
2364 }
2365
2366 return true;
2367}
2368
2369static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name)
2370{
2371 switch (identifier)
2372 {
2373 case GL_BUFFER:
2374 if (context->getBuffer(name) == nullptr)
2375 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002376 context->validationError(GL_INVALID_VALUE, kInvalidBufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002377 return false;
2378 }
2379 return true;
2380
2381 case GL_SHADER:
2382 if (context->getShader(name) == nullptr)
2383 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002384 context->validationError(GL_INVALID_VALUE, kInvalidShaderName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002385 return false;
2386 }
2387 return true;
2388
2389 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002390 if (context->getProgramNoResolveLink(name) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002391 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002392 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002393 return false;
2394 }
2395 return true;
2396
2397 case GL_VERTEX_ARRAY:
2398 if (context->getVertexArray(name) == nullptr)
2399 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002400 context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002401 return false;
2402 }
2403 return true;
2404
2405 case GL_QUERY:
2406 if (context->getQuery(name) == nullptr)
2407 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002408 context->validationError(GL_INVALID_VALUE, kInvalidQueryName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002409 return false;
2410 }
2411 return true;
2412
2413 case GL_TRANSFORM_FEEDBACK:
2414 if (context->getTransformFeedback(name) == nullptr)
2415 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002416 context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002417 return false;
2418 }
2419 return true;
2420
2421 case GL_SAMPLER:
2422 if (context->getSampler(name) == nullptr)
2423 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002424 context->validationError(GL_INVALID_VALUE, kInvalidSamplerName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002425 return false;
2426 }
2427 return true;
2428
2429 case GL_TEXTURE:
2430 if (context->getTexture(name) == nullptr)
2431 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002432 context->validationError(GL_INVALID_VALUE, kInvalidTextureName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002433 return false;
2434 }
2435 return true;
2436
2437 case GL_RENDERBUFFER:
2438 if (context->getRenderbuffer(name) == nullptr)
2439 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002440 context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002441 return false;
2442 }
2443 return true;
2444
2445 case GL_FRAMEBUFFER:
2446 if (context->getFramebuffer(name) == nullptr)
2447 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002448 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002449 return false;
2450 }
2451 return true;
2452
2453 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05002454 context->validationError(GL_INVALID_ENUM, kInvalidIndentifier);
Geoff Lang70d0f492015-12-10 17:45:46 -05002455 return false;
2456 }
Geoff Lange102fee2015-12-10 11:23:30 -05002457}
2458
Martin Radev9d901792016-07-15 15:58:58 +03002459static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label)
2460{
2461 size_t labelLength = 0;
2462
2463 if (length < 0)
2464 {
2465 if (label != nullptr)
2466 {
2467 labelLength = strlen(label);
2468 }
2469 }
2470 else
2471 {
2472 labelLength = static_cast<size_t>(length);
2473 }
2474
2475 if (labelLength > context->getExtensions().maxLabelLength)
2476 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002477 context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength);
Martin Radev9d901792016-07-15 15:58:58 +03002478 return false;
2479 }
2480
2481 return true;
2482}
2483
Geoff Lange102fee2015-12-10 11:23:30 -05002484bool ValidateObjectLabelKHR(Context *context,
2485 GLenum identifier,
2486 GLuint name,
2487 GLsizei length,
2488 const GLchar *label)
2489{
2490 if (!context->getExtensions().debug)
2491 {
Jamie Madille0472f32018-11-27 16:32:45 -05002492 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002493 return false;
2494 }
2495
Geoff Lang70d0f492015-12-10 17:45:46 -05002496 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2497 {
2498 return false;
2499 }
2500
Martin Radev9d901792016-07-15 15:58:58 +03002501 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002502 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002503 return false;
2504 }
2505
Geoff Lange102fee2015-12-10 11:23:30 -05002506 return true;
2507}
2508
2509bool ValidateGetObjectLabelKHR(Context *context,
2510 GLenum identifier,
2511 GLuint name,
2512 GLsizei bufSize,
2513 GLsizei *length,
2514 GLchar *label)
2515{
2516 if (!context->getExtensions().debug)
2517 {
Jamie Madille0472f32018-11-27 16:32:45 -05002518 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002519 return false;
2520 }
2521
Geoff Lang70d0f492015-12-10 17:45:46 -05002522 if (bufSize < 0)
2523 {
Jamie Madille0472f32018-11-27 16:32:45 -05002524 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002525 return false;
2526 }
2527
2528 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2529 {
2530 return false;
2531 }
2532
Martin Radev9d901792016-07-15 15:58:58 +03002533 return true;
Geoff Lang70d0f492015-12-10 17:45:46 -05002534}
2535
2536static bool ValidateObjectPtrName(Context *context, const void *ptr)
2537{
Jamie Madill70b5bb02017-08-28 13:32:37 -04002538 if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002539 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002540 context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer);
Geoff Lang70d0f492015-12-10 17:45:46 -05002541 return false;
2542 }
2543
Geoff Lange102fee2015-12-10 11:23:30 -05002544 return true;
2545}
2546
2547bool ValidateObjectPtrLabelKHR(Context *context,
2548 const void *ptr,
2549 GLsizei length,
2550 const GLchar *label)
2551{
2552 if (!context->getExtensions().debug)
2553 {
Jamie Madille0472f32018-11-27 16:32:45 -05002554 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002555 return false;
2556 }
2557
Geoff Lang70d0f492015-12-10 17:45:46 -05002558 if (!ValidateObjectPtrName(context, ptr))
2559 {
2560 return false;
2561 }
2562
Martin Radev9d901792016-07-15 15:58:58 +03002563 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002564 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002565 return false;
2566 }
2567
Geoff Lange102fee2015-12-10 11:23:30 -05002568 return true;
2569}
2570
2571bool ValidateGetObjectPtrLabelKHR(Context *context,
2572 const void *ptr,
2573 GLsizei bufSize,
2574 GLsizei *length,
2575 GLchar *label)
2576{
2577 if (!context->getExtensions().debug)
2578 {
Jamie Madille0472f32018-11-27 16:32:45 -05002579 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002580 return false;
2581 }
2582
Geoff Lang70d0f492015-12-10 17:45:46 -05002583 if (bufSize < 0)
2584 {
Jamie Madille0472f32018-11-27 16:32:45 -05002585 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002586 return false;
2587 }
2588
2589 if (!ValidateObjectPtrName(context, ptr))
2590 {
2591 return false;
2592 }
2593
Martin Radev9d901792016-07-15 15:58:58 +03002594 return true;
Geoff Lange102fee2015-12-10 11:23:30 -05002595}
2596
2597bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params)
2598{
2599 if (!context->getExtensions().debug)
2600 {
Jamie Madille0472f32018-11-27 16:32:45 -05002601 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002602 return false;
2603 }
2604
Geoff Lang70d0f492015-12-10 17:45:46 -05002605 // TODO: represent this in Context::getQueryParameterInfo.
2606 switch (pname)
2607 {
2608 case GL_DEBUG_CALLBACK_FUNCTION:
2609 case GL_DEBUG_CALLBACK_USER_PARAM:
2610 break;
2611
2612 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002613 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang70d0f492015-12-10 17:45:46 -05002614 return false;
2615 }
2616
Geoff Lange102fee2015-12-10 11:23:30 -05002617 return true;
2618}
Jamie Madillc29968b2016-01-20 11:17:23 -05002619
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002620bool ValidateGetPointervRobustANGLERobustANGLE(Context *context,
2621 GLenum pname,
2622 GLsizei bufSize,
2623 GLsizei *length,
2624 void **params)
2625{
2626 UNIMPLEMENTED();
2627 return false;
2628}
2629
Jamie Madillc29968b2016-01-20 11:17:23 -05002630bool ValidateBlitFramebufferANGLE(Context *context,
2631 GLint srcX0,
2632 GLint srcY0,
2633 GLint srcX1,
2634 GLint srcY1,
2635 GLint dstX0,
2636 GLint dstY0,
2637 GLint dstX1,
2638 GLint dstY1,
2639 GLbitfield mask,
2640 GLenum filter)
2641{
2642 if (!context->getExtensions().framebufferBlit)
2643 {
Jamie Madille0472f32018-11-27 16:32:45 -05002644 context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable);
Jamie Madillc29968b2016-01-20 11:17:23 -05002645 return false;
2646 }
2647
2648 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
2649 {
2650 // TODO(jmadill): Determine if this should be available on other implementations.
Jamie Madille0472f32018-11-27 16:32:45 -05002651 context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip);
Jamie Madillc29968b2016-01-20 11:17:23 -05002652 return false;
2653 }
2654
2655 if (filter == GL_LINEAR)
2656 {
Jamie Madille0472f32018-11-27 16:32:45 -05002657 context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear);
Jamie Madillc29968b2016-01-20 11:17:23 -05002658 return false;
2659 }
2660
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002661 Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
2662 Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002663
2664 if (mask & GL_COLOR_BUFFER_BIT)
2665 {
2666 const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer();
2667 const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer();
2668
2669 if (readColorAttachment && drawColorAttachment)
2670 {
2671 if (!(readColorAttachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002672 readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002673 readColorAttachment->type() != GL_RENDERBUFFER &&
2674 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2675 {
Jamie Madill610640f2018-11-21 17:28:41 -05002676 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002677 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002678 return false;
2679 }
2680
Geoff Langa15472a2015-08-11 11:48:03 -04002681 for (size_t drawbufferIdx = 0;
2682 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002683 {
Geoff Langa15472a2015-08-11 11:48:03 -04002684 const FramebufferAttachment *attachment =
2685 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2686 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002687 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002688 if (!(attachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002689 attachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002690 attachment->type() != GL_RENDERBUFFER &&
2691 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2692 {
Jamie Madill610640f2018-11-21 17:28:41 -05002693 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002694 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002695 return false;
2696 }
2697
2698 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002699 if (!Format::EquivalentForBlit(attachment->getFormat(),
2700 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002701 {
Jamie Madill610640f2018-11-21 17:28:41 -05002702 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002703 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002704 return false;
2705 }
2706 }
2707 }
2708
Jamie Madill427064d2018-04-13 16:20:34 -04002709 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002710 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002711 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2712 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2713 {
Jamie Madill610640f2018-11-21 17:28:41 -05002714 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002715 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002716 return false;
2717 }
2718 }
2719 }
2720
2721 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2722 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2723 for (size_t i = 0; i < 2; i++)
2724 {
2725 if (mask & masks[i])
2726 {
2727 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002728 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002729 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002730 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002731
2732 if (readBuffer && drawBuffer)
2733 {
2734 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2735 dstX0, dstY0, dstX1, dstY1))
2736 {
2737 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002738 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002739 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002740 return false;
2741 }
2742
2743 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2744 {
Jamie Madill610640f2018-11-21 17:28:41 -05002745 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002746 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002747 return false;
2748 }
2749 }
2750 }
2751 }
2752
2753 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2754 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002755}
Jamie Madillc29968b2016-01-20 11:17:23 -05002756
Jamie Madill5b772312018-03-08 20:28:32 -05002757bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002758{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002759 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002760 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002761
Jamie Madill427064d2018-04-13 16:20:34 -04002762 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002763 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002764 return false;
2765 }
2766
2767 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2768 {
Jamie Madille0472f32018-11-27 16:32:45 -05002769 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002770 return false;
2771 }
2772
Olli Etuaho94c91a92018-07-19 15:10:24 +03002773 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002774 {
2775 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2776 GL_SIGNED_NORMALIZED};
2777
Corentin Wallez59c41592017-07-11 13:19:54 -04002778 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002779 drawBufferIdx++)
2780 {
2781 if (!ValidateWebGLFramebufferAttachmentClearType(
2782 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2783 {
2784 return false;
2785 }
2786 }
2787 }
2788
Mingyu Huebab6702019-04-19 14:36:45 -07002789 if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery)
Olli Etuaho94c91a92018-07-19 15:10:24 +03002790 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002791 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002792 Framebuffer *framebuffer = state.getDrawFramebuffer();
2793 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2794 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002795 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002796 return false;
2797 }
2798 }
2799
Jamie Madillc29968b2016-01-20 11:17:23 -05002800 return true;
2801}
2802
Jamie Madill5b772312018-03-08 20:28:32 -05002803bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002804{
2805 if (!context->getExtensions().drawBuffers)
2806 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002807 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002808 return false;
2809 }
2810
2811 return ValidateDrawBuffersBase(context, n, bufs);
2812}
2813
Jamie Madill73a84962016-02-12 09:27:23 -05002814bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002815 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002816 GLint level,
2817 GLint internalformat,
2818 GLsizei width,
2819 GLsizei height,
2820 GLint border,
2821 GLenum format,
2822 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002823 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002824{
Martin Radev1be913c2016-07-11 17:59:16 +03002825 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002826 {
2827 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002828 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002829 }
2830
Martin Radev1be913c2016-07-11 17:59:16 +03002831 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002832 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002833 0, 0, width, height, 1, border, format, type, -1,
2834 pixels);
2835}
2836
Brandon Jones416aaf92018-04-10 08:10:16 -07002837bool ValidateTexImage2DRobustANGLE(Context *context,
2838 TextureTarget target,
2839 GLint level,
2840 GLint internalformat,
2841 GLsizei width,
2842 GLsizei height,
2843 GLint border,
2844 GLenum format,
2845 GLenum type,
2846 GLsizei bufSize,
2847 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04002848{
2849 if (!ValidateRobustEntryPoint(context, bufSize))
2850 {
2851 return false;
2852 }
2853
2854 if (context->getClientMajorVersion() < 3)
2855 {
2856 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
2857 0, 0, width, height, border, format, type, bufSize,
2858 pixels);
2859 }
2860
2861 ASSERT(context->getClientMajorVersion() >= 3);
2862 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
2863 0, 0, width, height, 1, border, format, type, bufSize,
2864 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002865}
2866
2867bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002868 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002869 GLint level,
2870 GLint xoffset,
2871 GLint yoffset,
2872 GLsizei width,
2873 GLsizei height,
2874 GLenum format,
2875 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002876 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002877{
2878
Martin Radev1be913c2016-07-11 17:59:16 +03002879 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002880 {
2881 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002882 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002883 }
2884
Martin Radev1be913c2016-07-11 17:59:16 +03002885 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002886 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002887 yoffset, 0, width, height, 1, 0, format, type, -1,
2888 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002889}
2890
Geoff Langc52f6f12016-10-14 10:18:00 -04002891bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002892 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04002893 GLint level,
2894 GLint xoffset,
2895 GLint yoffset,
2896 GLsizei width,
2897 GLsizei height,
2898 GLenum format,
2899 GLenum type,
2900 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002901 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04002902{
2903 if (!ValidateRobustEntryPoint(context, bufSize))
2904 {
2905 return false;
2906 }
2907
2908 if (context->getClientMajorVersion() < 3)
2909 {
2910 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
2911 yoffset, width, height, 0, format, type, bufSize,
2912 pixels);
2913 }
2914
2915 ASSERT(context->getClientMajorVersion() >= 3);
2916 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
2917 yoffset, 0, width, height, 1, 0, format, type, bufSize,
2918 pixels);
2919}
2920
Jamie Madill73a84962016-02-12 09:27:23 -05002921bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002922 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002923 GLint level,
2924 GLenum internalformat,
2925 GLsizei width,
2926 GLsizei height,
2927 GLint border,
2928 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002929 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002930{
Martin Radev1be913c2016-07-11 17:59:16 +03002931 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002932 {
2933 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002934 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002935 {
2936 return false;
2937 }
2938 }
2939 else
2940 {
Martin Radev1be913c2016-07-11 17:59:16 +03002941 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002942 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002943 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002944 data))
2945 {
2946 return false;
2947 }
2948 }
2949
Geoff Langca271392017-04-05 12:30:00 -04002950 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04002951
2952 GLuint blockSize = 0;
2953 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002954 {
Jamie Madille0472f32018-11-27 16:32:45 -05002955 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002956 return false;
2957 }
2958
Jamie Madillca2ff382018-07-11 09:01:17 -04002959 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002960 {
Jamie Madille0472f32018-11-27 16:32:45 -05002961 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05002962 return false;
2963 }
2964
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002965 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002966 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002967 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002968 return false;
2969 }
2970
Jamie Madill73a84962016-02-12 09:27:23 -05002971 return true;
2972}
2973
Corentin Wallezb2931602017-04-11 15:58:57 -04002974bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002975 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002976 GLint level,
2977 GLenum internalformat,
2978 GLsizei width,
2979 GLsizei height,
2980 GLint border,
2981 GLsizei imageSize,
2982 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002983 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002984{
2985 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2986 {
2987 return false;
2988 }
2989
2990 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
2991 border, imageSize, data);
2992}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002993
Corentin Wallezb2931602017-04-11 15:58:57 -04002994bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002995 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002996 GLint level,
2997 GLint xoffset,
2998 GLint yoffset,
2999 GLsizei width,
3000 GLsizei height,
3001 GLenum format,
3002 GLsizei imageSize,
3003 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003004 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003005{
3006 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3007 {
3008 return false;
3009 }
3010
3011 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
3012 format, imageSize, data);
3013}
3014
Jamie Madill73a84962016-02-12 09:27:23 -05003015bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003016 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003017 GLint level,
3018 GLint xoffset,
3019 GLint yoffset,
3020 GLsizei width,
3021 GLsizei height,
3022 GLenum format,
3023 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003024 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003025{
Martin Radev1be913c2016-07-11 17:59:16 +03003026 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05003027 {
3028 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003029 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05003030 {
3031 return false;
3032 }
3033 }
3034 else
3035 {
Martin Radev1be913c2016-07-11 17:59:16 +03003036 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003037 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003038 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05003039 data))
3040 {
3041 return false;
3042 }
3043 }
3044
Geoff Langca271392017-04-05 12:30:00 -04003045 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04003046 GLuint blockSize = 0;
3047 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003048 {
Jamie Madille0472f32018-11-27 16:32:45 -05003049 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003050 return false;
3051 }
3052
Jamie Madillca2ff382018-07-11 09:01:17 -04003053 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003054 {
Jamie Madille0472f32018-11-27 16:32:45 -05003055 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05003056 return false;
3057 }
3058
3059 return true;
3060}
3061
Corentin Wallez336129f2017-10-17 15:55:40 -04003062bool ValidateGetBufferPointervOES(Context *context,
3063 BufferBinding target,
3064 GLenum pname,
3065 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003066{
Jamie Madillc3e37312018-11-30 15:25:39 -05003067 if (!context->getExtensions().mapBuffer)
3068 {
3069 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3070 return false;
3071 }
3072
Geoff Lang496c02d2016-10-20 11:38:11 -07003073 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003074}
3075
Corentin Wallez336129f2017-10-17 15:55:40 -04003076bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003077{
3078 if (!context->getExtensions().mapBuffer)
3079 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003080 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003081 return false;
3082 }
3083
Corentin Walleze4477002017-12-01 14:39:58 -05003084 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03003085 {
Jamie Madille0472f32018-11-27 16:32:45 -05003086 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03003087 return false;
3088 }
3089
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003090 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003091
3092 if (buffer == nullptr)
3093 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003094 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03003095 return false;
3096 }
3097
3098 if (access != GL_WRITE_ONLY_OES)
3099 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003100 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03003101 return false;
3102 }
3103
3104 if (buffer->isMapped())
3105 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003106 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003107 return false;
3108 }
3109
Geoff Lang79f71042017-08-14 16:43:43 -04003110 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003111}
3112
Corentin Wallez336129f2017-10-17 15:55:40 -04003113bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003114{
3115 if (!context->getExtensions().mapBuffer)
3116 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003117 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003118 return false;
3119 }
3120
3121 return ValidateUnmapBufferBase(context, target);
3122}
3123
3124bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003125 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003126 GLintptr offset,
3127 GLsizeiptr length,
3128 GLbitfield access)
3129{
3130 if (!context->getExtensions().mapBufferRange)
3131 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003132 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003133 return false;
3134 }
3135
3136 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3137}
3138
Michael Spang7a8c3e52019-04-03 14:49:57 -04003139bool ValidateBufferStorageMemEXT(Context *context,
3140 TextureType target,
3141 GLsizeiptr size,
3142 GLuint memory,
3143 GLuint64 offset)
3144{
3145 if (!context->getExtensions().memoryObject)
3146 {
3147 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3148 return false;
3149 }
3150
3151 UNIMPLEMENTED();
3152 return false;
3153}
3154
3155bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects)
3156{
3157 if (!context->getExtensions().memoryObject)
3158 {
3159 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3160 return false;
3161 }
3162
Michael Spangfb201c52019-04-03 14:57:35 -04003163 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003164}
3165
3166bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects)
3167{
3168 if (!context->getExtensions().memoryObject)
3169 {
3170 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3171 return false;
3172 }
3173
Michael Spangfb201c52019-04-03 14:57:35 -04003174 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003175}
3176
3177bool ValidateGetMemoryObjectParameterivEXT(Context *context,
3178 GLuint memoryObject,
3179 GLenum pname,
3180 GLint *params)
3181{
3182 if (!context->getExtensions().memoryObject)
3183 {
3184 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3185 return false;
3186 }
3187
3188 UNIMPLEMENTED();
3189 return false;
3190}
3191
3192bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3193{
3194 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3195 {
3196 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3197 return false;
3198 }
3199
3200 UNIMPLEMENTED();
3201 return false;
3202}
3203
3204bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3205{
3206 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3207 {
3208 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3209 return false;
3210 }
3211
3212 UNIMPLEMENTED();
3213 return false;
3214}
3215
3216bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject)
3217{
3218 if (!context->getExtensions().memoryObject)
3219 {
3220 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3221 return false;
3222 }
3223
Michael Spangfb201c52019-04-03 14:57:35 -04003224 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003225}
3226
3227bool ValidateMemoryObjectParameterivEXT(Context *context,
3228 GLuint memoryObject,
3229 GLenum pname,
3230 const GLint *params)
3231{
3232 if (!context->getExtensions().memoryObject)
3233 {
3234 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3235 return false;
3236 }
3237
3238 UNIMPLEMENTED();
3239 return false;
3240}
3241
3242bool ValidateTexStorageMem2DEXT(Context *context,
3243 TextureType target,
3244 GLsizei levels,
3245 GLenum internalFormat,
3246 GLsizei width,
3247 GLsizei height,
3248 GLuint memory,
3249 GLuint64 offset)
3250{
3251 if (!context->getExtensions().memoryObject)
3252 {
3253 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3254 return false;
3255 }
3256
Michael Spangf02a7672019-04-09 18:45:23 -04003257 if (context->getClientMajorVersion() < 3)
3258 {
3259 return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width,
3260 height);
3261 }
3262
3263 ASSERT(context->getClientMajorVersion() >= 3);
3264 return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height,
3265 1);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003266}
3267
3268bool ValidateTexStorageMem3DEXT(Context *context,
3269 TextureType target,
3270 GLsizei levels,
3271 GLenum internalFormat,
3272 GLsizei width,
3273 GLsizei height,
3274 GLsizei depth,
3275 GLuint memory,
3276 GLuint64 offset)
3277{
3278 if (!context->getExtensions().memoryObject)
3279 {
3280 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3281 return false;
3282 }
3283
3284 UNIMPLEMENTED();
3285 return false;
3286}
3287
Michael Spang9de3ddb2019-04-03 16:23:40 -04003288bool ValidateImportMemoryFdEXT(Context *context,
3289 GLuint memory,
3290 GLuint64 size,
Michael Spange0da9ce2019-04-16 14:34:51 -04003291 HandleType handleType,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003292 GLint fd)
3293{
3294 if (!context->getExtensions().memoryObjectFd)
3295 {
3296 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3297 return false;
3298 }
3299
Michael Spang3b2c6bf2019-04-16 17:19:50 -04003300 switch (handleType)
3301 {
3302 case HandleType::OpaqueFd:
3303 break;
3304 default:
3305 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3306 return false;
3307 }
3308
3309 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003310}
3311
Michael Spang7a8c3e52019-04-03 14:49:57 -04003312bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores)
3313{
3314 if (!context->getExtensions().semaphore)
3315 {
3316 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3317 return false;
3318 }
3319
Michael Spang5093ba62019-05-14 17:36:36 -04003320 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003321}
3322
3323bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores)
3324{
3325 if (!context->getExtensions().semaphore)
3326 {
3327 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3328 return false;
3329 }
3330
Michael Spang5093ba62019-05-14 17:36:36 -04003331 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003332}
3333
3334bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
3335 GLuint semaphore,
3336 GLenum pname,
3337 GLuint64 *params)
3338{
3339 if (!context->getExtensions().semaphore)
3340 {
3341 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3342 return false;
3343 }
3344
3345 UNIMPLEMENTED();
3346 return false;
3347}
3348
3349bool ValidateIsSemaphoreEXT(Context *context, GLuint semaphore)
3350{
3351 if (!context->getExtensions().semaphore)
3352 {
3353 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3354 return false;
3355 }
3356
Michael Spang5093ba62019-05-14 17:36:36 -04003357 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003358}
3359
3360bool ValidateSemaphoreParameterui64vEXT(Context *context,
3361 GLuint semaphore,
3362 GLenum pname,
3363 const GLuint64 *params)
3364{
3365 if (!context->getExtensions().semaphore)
3366 {
3367 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3368 return false;
3369 }
3370
3371 UNIMPLEMENTED();
3372 return false;
3373}
3374
3375bool ValidateSignalSemaphoreEXT(Context *context,
3376 GLuint semaphore,
3377 GLuint numBufferBarriers,
3378 const GLuint *buffers,
3379 GLuint numTextureBarriers,
3380 const GLuint *textures,
3381 const GLenum *dstLayouts)
3382{
3383 if (!context->getExtensions().semaphore)
3384 {
3385 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3386 return false;
3387 }
3388
Michael Spangab6a59b2019-05-21 21:26:26 -04003389 for (GLuint i = 0; i < numTextureBarriers; ++i)
3390 {
3391 if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i])))
3392 {
3393 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3394 return false;
3395 }
3396 }
3397
3398 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003399}
3400
3401bool ValidateWaitSemaphoreEXT(Context *context,
3402 GLuint semaphore,
3403 GLuint numBufferBarriers,
3404 const GLuint *buffers,
3405 GLuint numTextureBarriers,
3406 const GLuint *textures,
3407 const GLenum *srcLayouts)
3408{
3409 if (!context->getExtensions().semaphore)
3410 {
3411 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3412 return false;
3413 }
3414
Michael Spangab6a59b2019-05-21 21:26:26 -04003415 for (GLuint i = 0; i < numTextureBarriers; ++i)
3416 {
3417 if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i])))
3418 {
3419 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3420 return false;
3421 }
3422 }
3423
3424 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003425}
3426
Michael Spange0da9ce2019-04-16 14:34:51 -04003427bool ValidateImportSemaphoreFdEXT(Context *context,
3428 GLuint semaphore,
3429 HandleType handleType,
3430 GLint fd)
Michael Spang9de3ddb2019-04-03 16:23:40 -04003431{
3432 if (!context->getExtensions().semaphoreFd)
3433 {
3434 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3435 return false;
3436 }
3437
Michael Spang6bb193c2019-05-22 16:32:21 -04003438 switch (handleType)
3439 {
3440 case HandleType::OpaqueFd:
3441 break;
3442 default:
3443 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3444 return false;
3445 }
3446
3447 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003448}
3449
Corentin Wallez336129f2017-10-17 15:55:40 -04003450bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003451{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003452 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003453 ASSERT(buffer != nullptr);
3454
3455 // Check if this buffer is currently being used as a transform feedback output buffer
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003456 if (context->getState().isTransformFeedbackActive())
Geoff Lang79f71042017-08-14 16:43:43 -04003457 {
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003458 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003459 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3460 {
3461 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3462 if (transformFeedbackBuffer.get() == buffer)
3463 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003464 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003465 return false;
3466 }
3467 }
3468 }
3469
James Darpiniane8a93c62018-01-04 18:02:24 -08003470 if (context->getExtensions().webglCompatibility &&
3471 buffer->isBoundForTransformFeedbackAndOtherUse())
3472 {
Jamie Madille0472f32018-11-27 16:32:45 -05003473 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003474 return false;
3475 }
3476
Geoff Lang79f71042017-08-14 16:43:43 -04003477 return true;
3478}
3479
Olli Etuaho4f667482016-03-30 15:56:35 +03003480bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003481 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003482 GLintptr offset,
3483 GLsizeiptr length)
3484{
3485 if (!context->getExtensions().mapBufferRange)
3486 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003487 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003488 return false;
3489 }
3490
3491 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3492}
3493
Geoff Langd8605522016-04-13 10:19:12 -04003494bool ValidateBindUniformLocationCHROMIUM(Context *context,
3495 GLuint program,
3496 GLint location,
3497 const GLchar *name)
3498{
3499 if (!context->getExtensions().bindUniformLocation)
3500 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003501 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003502 return false;
3503 }
3504
3505 Program *programObject = GetValidProgram(context, program);
3506 if (!programObject)
3507 {
3508 return false;
3509 }
3510
3511 if (location < 0)
3512 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003513 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003514 return false;
3515 }
3516
3517 const Caps &caps = context->getCaps();
3518 if (static_cast<size_t>(location) >=
3519 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3520 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003521 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003522 return false;
3523 }
3524
Geoff Langfc32e8b2017-05-31 14:16:59 -04003525 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3526 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003527 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003528 {
Jamie Madille0472f32018-11-27 16:32:45 -05003529 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003530 return false;
3531 }
3532
Geoff Langd8605522016-04-13 10:19:12 -04003533 if (strncmp(name, "gl_", 3) == 0)
3534 {
Jamie Madille0472f32018-11-27 16:32:45 -05003535 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003536 return false;
3537 }
3538
3539 return true;
3540}
3541
Jamie Madille2e406c2016-06-02 13:04:10 -04003542bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003543{
3544 if (!context->getExtensions().framebufferMixedSamples)
3545 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003546 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003547 return false;
3548 }
3549 switch (components)
3550 {
3551 case GL_RGB:
3552 case GL_RGBA:
3553 case GL_ALPHA:
3554 case GL_NONE:
3555 break;
3556 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003557 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003558 return false;
3559 }
3560
3561 return true;
3562}
3563
Sami Väisänene45e53b2016-05-25 10:36:04 +03003564// CHROMIUM_path_rendering
3565
Jamie Madill007530e2017-12-28 14:27:04 -05003566bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003567{
Jamie Madill007530e2017-12-28 14:27:04 -05003568 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003569 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003570 return false;
3571 }
Jamie Madill007530e2017-12-28 14:27:04 -05003572
Sami Väisänene45e53b2016-05-25 10:36:04 +03003573 if (matrix == nullptr)
3574 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003575 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003576 return false;
3577 }
Jamie Madill007530e2017-12-28 14:27:04 -05003578
Sami Väisänene45e53b2016-05-25 10:36:04 +03003579 return true;
3580}
3581
Jamie Madill007530e2017-12-28 14:27:04 -05003582bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003583{
Jamie Madill007530e2017-12-28 14:27:04 -05003584 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003585}
3586
Jamie Madill007530e2017-12-28 14:27:04 -05003587bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003588{
3589 if (!context->getExtensions().pathRendering)
3590 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003591 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003592 return false;
3593 }
3594
3595 // range = 0 is undefined in NV_path_rendering.
3596 // we add stricter semantic check here and require a non zero positive range.
3597 if (range <= 0)
3598 {
Jamie Madille0472f32018-11-27 16:32:45 -05003599 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003600 return false;
3601 }
3602
3603 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3604 {
Jamie Madille0472f32018-11-27 16:32:45 -05003605 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003606 return false;
3607 }
3608
3609 return true;
3610}
3611
Jamie Madill007530e2017-12-28 14:27:04 -05003612bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003613{
3614 if (!context->getExtensions().pathRendering)
3615 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003616 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003617 return false;
3618 }
3619
3620 // range = 0 is undefined in NV_path_rendering.
3621 // we add stricter semantic check here and require a non zero positive range.
3622 if (range <= 0)
3623 {
Jamie Madille0472f32018-11-27 16:32:45 -05003624 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003625 return false;
3626 }
3627
3628 angle::CheckedNumeric<std::uint32_t> checkedRange(path);
3629 checkedRange += range;
3630
3631 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3632 {
Jamie Madille0472f32018-11-27 16:32:45 -05003633 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003634 return false;
3635 }
3636 return true;
3637}
3638
Jamie Madill007530e2017-12-28 14:27:04 -05003639bool ValidatePathCommandsCHROMIUM(Context *context,
3640 GLuint path,
3641 GLsizei numCommands,
3642 const GLubyte *commands,
3643 GLsizei numCoords,
3644 GLenum coordType,
3645 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003646{
3647 if (!context->getExtensions().pathRendering)
3648 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003649 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003650 return false;
3651 }
Brandon Jones59770802018-04-02 13:18:42 -07003652 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003653 {
Jamie Madille0472f32018-11-27 16:32:45 -05003654 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003655 return false;
3656 }
3657
3658 if (numCommands < 0)
3659 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003660 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003661 return false;
3662 }
3663 else if (numCommands > 0)
3664 {
3665 if (!commands)
3666 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003667 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003668 return false;
3669 }
3670 }
3671
3672 if (numCoords < 0)
3673 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003674 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003675 return false;
3676 }
3677 else if (numCoords > 0)
3678 {
3679 if (!coords)
3680 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003681 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003682 return false;
3683 }
3684 }
3685
3686 std::uint32_t coordTypeSize = 0;
3687 switch (coordType)
3688 {
3689 case GL_BYTE:
3690 coordTypeSize = sizeof(GLbyte);
3691 break;
3692
3693 case GL_UNSIGNED_BYTE:
3694 coordTypeSize = sizeof(GLubyte);
3695 break;
3696
3697 case GL_SHORT:
3698 coordTypeSize = sizeof(GLshort);
3699 break;
3700
3701 case GL_UNSIGNED_SHORT:
3702 coordTypeSize = sizeof(GLushort);
3703 break;
3704
3705 case GL_FLOAT:
3706 coordTypeSize = sizeof(GLfloat);
3707 break;
3708
3709 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003710 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003711 return false;
3712 }
3713
3714 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3715 checkedSize += (coordTypeSize * numCoords);
3716 if (!checkedSize.IsValid())
3717 {
Jamie Madille0472f32018-11-27 16:32:45 -05003718 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003719 return false;
3720 }
3721
3722 // early return skips command data validation when it doesn't exist.
3723 if (!commands)
3724 return true;
3725
3726 GLsizei expectedNumCoords = 0;
3727 for (GLsizei i = 0; i < numCommands; ++i)
3728 {
3729 switch (commands[i])
3730 {
3731 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3732 break;
3733 case GL_MOVE_TO_CHROMIUM:
3734 case GL_LINE_TO_CHROMIUM:
3735 expectedNumCoords += 2;
3736 break;
3737 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3738 expectedNumCoords += 4;
3739 break;
3740 case GL_CUBIC_CURVE_TO_CHROMIUM:
3741 expectedNumCoords += 6;
3742 break;
3743 case GL_CONIC_CURVE_TO_CHROMIUM:
3744 expectedNumCoords += 5;
3745 break;
3746 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003747 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003748 return false;
3749 }
3750 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003751
Sami Väisänene45e53b2016-05-25 10:36:04 +03003752 if (expectedNumCoords != numCoords)
3753 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003754 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003755 return false;
3756 }
3757
3758 return true;
3759}
3760
Jamie Madill007530e2017-12-28 14:27:04 -05003761bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003762{
3763 if (!context->getExtensions().pathRendering)
3764 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003765 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003766 return false;
3767 }
Brandon Jones59770802018-04-02 13:18:42 -07003768 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003769 {
Jamie Madille0472f32018-11-27 16:32:45 -05003770 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003771 return false;
3772 }
3773
3774 switch (pname)
3775 {
3776 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3777 if (value < 0.0f)
3778 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003779 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003780 return false;
3781 }
3782 break;
3783 case GL_PATH_END_CAPS_CHROMIUM:
3784 switch (static_cast<GLenum>(value))
3785 {
3786 case GL_FLAT_CHROMIUM:
3787 case GL_SQUARE_CHROMIUM:
3788 case GL_ROUND_CHROMIUM:
3789 break;
3790 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003791 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003792 return false;
3793 }
3794 break;
3795 case GL_PATH_JOIN_STYLE_CHROMIUM:
3796 switch (static_cast<GLenum>(value))
3797 {
3798 case GL_MITER_REVERT_CHROMIUM:
3799 case GL_BEVEL_CHROMIUM:
3800 case GL_ROUND_CHROMIUM:
3801 break;
3802 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003803 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003804 return false;
3805 }
Nico Weber41b072b2018-02-09 10:01:32 -05003806 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03003807 case GL_PATH_MITER_LIMIT_CHROMIUM:
3808 if (value < 0.0f)
3809 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003810 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003811 return false;
3812 }
3813 break;
3814
3815 case GL_PATH_STROKE_BOUND_CHROMIUM:
3816 // no errors, only clamping.
3817 break;
3818
3819 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003820 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003821 return false;
3822 }
3823 return true;
3824}
3825
Jamie Madill007530e2017-12-28 14:27:04 -05003826bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value)
3827{
3828 // TODO(jmadill): Use proper clamping cast.
3829 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
3830}
3831
3832bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003833{
3834 if (!context->getExtensions().pathRendering)
3835 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003836 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003837 return false;
3838 }
3839
Brandon Jones59770802018-04-02 13:18:42 -07003840 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003841 {
Jamie Madille0472f32018-11-27 16:32:45 -05003842 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003843 return false;
3844 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003845
Sami Väisänene45e53b2016-05-25 10:36:04 +03003846 if (!value)
3847 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003848 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003849 return false;
3850 }
3851
3852 switch (pname)
3853 {
3854 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3855 case GL_PATH_END_CAPS_CHROMIUM:
3856 case GL_PATH_JOIN_STYLE_CHROMIUM:
3857 case GL_PATH_MITER_LIMIT_CHROMIUM:
3858 case GL_PATH_STROKE_BOUND_CHROMIUM:
3859 break;
3860
3861 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003862 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003863 return false;
3864 }
3865
3866 return true;
3867}
3868
Jamie Madill007530e2017-12-28 14:27:04 -05003869bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value)
3870{
3871 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
3872 reinterpret_cast<GLfloat *>(value));
3873}
3874
3875bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003876{
3877 if (!context->getExtensions().pathRendering)
3878 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003879 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003880 return false;
3881 }
3882
3883 switch (func)
3884 {
3885 case GL_NEVER:
3886 case GL_ALWAYS:
3887 case GL_LESS:
3888 case GL_LEQUAL:
3889 case GL_EQUAL:
3890 case GL_GEQUAL:
3891 case GL_GREATER:
3892 case GL_NOTEQUAL:
3893 break;
3894 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003895 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003896 return false;
3897 }
3898
3899 return true;
3900}
3901
3902// Note that the spec specifies that for the path drawing commands
3903// if the path object is not an existing path object the command
3904// does nothing and no error is generated.
3905// However if the path object exists but has not been specified any
3906// commands then an error is generated.
3907
Jamie Madill007530e2017-12-28 14:27:04 -05003908bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003909{
3910 if (!context->getExtensions().pathRendering)
3911 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003912 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003913 return false;
3914 }
Brandon Jones59770802018-04-02 13:18:42 -07003915 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003916 {
Jamie Madille0472f32018-11-27 16:32:45 -05003917 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003918 return false;
3919 }
3920
3921 switch (fillMode)
3922 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06003923 case GL_INVERT:
Sami Väisänene45e53b2016-05-25 10:36:04 +03003924 case GL_COUNT_UP_CHROMIUM:
3925 case GL_COUNT_DOWN_CHROMIUM:
3926 break;
3927 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003928 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003929 return false;
3930 }
3931
3932 if (!isPow2(mask + 1))
3933 {
Jamie Madille0472f32018-11-27 16:32:45 -05003934 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003935 return false;
3936 }
3937
3938 return true;
3939}
3940
Jamie Madill007530e2017-12-28 14:27:04 -05003941bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003942{
3943 if (!context->getExtensions().pathRendering)
3944 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003945 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003946 return false;
3947 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003948
Brandon Jones59770802018-04-02 13:18:42 -07003949 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003950 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003951 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003952 return false;
3953 }
3954
3955 return true;
3956}
3957
Jamie Madill007530e2017-12-28 14:27:04 -05003958bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003959{
3960 if (!context->getExtensions().pathRendering)
3961 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003962 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003963 return false;
3964 }
Brandon Jones59770802018-04-02 13:18:42 -07003965 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003966 {
Jamie Madille0472f32018-11-27 16:32:45 -05003967 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003968 return false;
3969 }
3970
3971 switch (coverMode)
3972 {
3973 case GL_CONVEX_HULL_CHROMIUM:
3974 case GL_BOUNDING_BOX_CHROMIUM:
3975 break;
3976 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003977 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003978 return false;
3979 }
3980 return true;
3981}
3982
Jamie Madill778bf092018-11-14 09:54:36 -05003983bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3984{
3985 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3986}
3987
3988bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3989{
3990 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3991}
3992
Jamie Madill007530e2017-12-28 14:27:04 -05003993bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
3994 GLuint path,
3995 GLenum fillMode,
3996 GLuint mask,
3997 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003998{
Jamie Madill007530e2017-12-28 14:27:04 -05003999 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
4000 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004001}
4002
Jamie Madill007530e2017-12-28 14:27:04 -05004003bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
4004 GLuint path,
4005 GLint reference,
4006 GLuint mask,
4007 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004008{
Jamie Madill007530e2017-12-28 14:27:04 -05004009 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
4010 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004011}
4012
Brandon Jonesd1049182018-03-28 10:02:20 -07004013bool ValidateIsPathCHROMIUM(Context *context, GLuint path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004014{
4015 if (!context->getExtensions().pathRendering)
4016 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004017 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004018 return false;
4019 }
4020 return true;
4021}
4022
Jamie Madill007530e2017-12-28 14:27:04 -05004023bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
4024 GLsizei numPaths,
4025 GLenum pathNameType,
4026 const void *paths,
4027 GLuint pathBase,
4028 GLenum coverMode,
4029 GLenum transformType,
4030 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004031{
4032 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4033 transformType, transformValues))
4034 return false;
4035
4036 switch (coverMode)
4037 {
4038 case GL_CONVEX_HULL_CHROMIUM:
4039 case GL_BOUNDING_BOX_CHROMIUM:
4040 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4041 break;
4042 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004043 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004044 return false;
4045 }
4046
4047 return true;
4048}
4049
Jamie Madill007530e2017-12-28 14:27:04 -05004050bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
4051 GLsizei numPaths,
4052 GLenum pathNameType,
4053 const void *paths,
4054 GLuint pathBase,
4055 GLenum coverMode,
4056 GLenum transformType,
4057 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004058{
4059 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4060 transformType, transformValues))
4061 return false;
4062
4063 switch (coverMode)
4064 {
4065 case GL_CONVEX_HULL_CHROMIUM:
4066 case GL_BOUNDING_BOX_CHROMIUM:
4067 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4068 break;
4069 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004070 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004071 return false;
4072 }
4073
4074 return true;
4075}
4076
Jamie Madill007530e2017-12-28 14:27:04 -05004077bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
4078 GLsizei numPaths,
4079 GLenum pathNameType,
4080 const void *paths,
4081 GLuint pathBase,
4082 GLenum fillMode,
4083 GLuint mask,
4084 GLenum transformType,
4085 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004086{
4087
4088 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4089 transformType, transformValues))
4090 return false;
4091
4092 switch (fillMode)
4093 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004094 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004095 case GL_COUNT_UP_CHROMIUM:
4096 case GL_COUNT_DOWN_CHROMIUM:
4097 break;
4098 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004099 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004100 return false;
4101 }
4102 if (!isPow2(mask + 1))
4103 {
Jamie Madille0472f32018-11-27 16:32:45 -05004104 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004105 return false;
4106 }
4107 return true;
4108}
4109
Jamie Madill007530e2017-12-28 14:27:04 -05004110bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
4111 GLsizei numPaths,
4112 GLenum pathNameType,
4113 const void *paths,
4114 GLuint pathBase,
4115 GLint reference,
4116 GLuint mask,
4117 GLenum transformType,
4118 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004119{
4120 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4121 transformType, transformValues))
4122 return false;
4123
4124 // no more validation here.
4125
4126 return true;
4127}
4128
Jamie Madill007530e2017-12-28 14:27:04 -05004129bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
4130 GLsizei numPaths,
4131 GLenum pathNameType,
4132 const void *paths,
4133 GLuint pathBase,
4134 GLenum fillMode,
4135 GLuint mask,
4136 GLenum coverMode,
4137 GLenum transformType,
4138 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004139{
4140 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4141 transformType, transformValues))
4142 return false;
4143
4144 switch (coverMode)
4145 {
4146 case GL_CONVEX_HULL_CHROMIUM:
4147 case GL_BOUNDING_BOX_CHROMIUM:
4148 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4149 break;
4150 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004151 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004152 return false;
4153 }
4154
4155 switch (fillMode)
4156 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004157 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004158 case GL_COUNT_UP_CHROMIUM:
4159 case GL_COUNT_DOWN_CHROMIUM:
4160 break;
4161 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004162 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004163 return false;
4164 }
4165 if (!isPow2(mask + 1))
4166 {
Jamie Madille0472f32018-11-27 16:32:45 -05004167 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004168 return false;
4169 }
4170
4171 return true;
4172}
4173
Jamie Madill007530e2017-12-28 14:27:04 -05004174bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4175 GLsizei numPaths,
4176 GLenum pathNameType,
4177 const void *paths,
4178 GLuint pathBase,
4179 GLint reference,
4180 GLuint mask,
4181 GLenum coverMode,
4182 GLenum transformType,
4183 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004184{
4185 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4186 transformType, transformValues))
4187 return false;
4188
4189 switch (coverMode)
4190 {
4191 case GL_CONVEX_HULL_CHROMIUM:
4192 case GL_BOUNDING_BOX_CHROMIUM:
4193 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4194 break;
4195 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004196 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004197 return false;
4198 }
4199
4200 return true;
4201}
4202
Jamie Madill007530e2017-12-28 14:27:04 -05004203bool ValidateBindFragmentInputLocationCHROMIUM(Context *context,
4204 GLuint program,
4205 GLint location,
4206 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004207{
4208 if (!context->getExtensions().pathRendering)
4209 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004210 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004211 return false;
4212 }
4213
4214 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4215 if (location >= MaxLocation)
4216 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004217 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004218 return false;
4219 }
4220
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004221 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004222 if (!programObject)
4223 {
Jamie Madille0472f32018-11-27 16:32:45 -05004224 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004225 return false;
4226 }
4227
4228 if (!name)
4229 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004230 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004231 return false;
4232 }
4233
4234 if (angle::BeginsWith(name, "gl_"))
4235 {
Jamie Madille0472f32018-11-27 16:32:45 -05004236 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004237 return false;
4238 }
4239
4240 return true;
4241}
4242
Jamie Madill007530e2017-12-28 14:27:04 -05004243bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
4244 GLuint program,
4245 GLint location,
4246 GLenum genMode,
4247 GLint components,
4248 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004249{
4250 if (!context->getExtensions().pathRendering)
4251 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004252 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004253 return false;
4254 }
4255
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004256 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004257 if (!programObject || programObject->isFlaggedForDeletion())
4258 {
Jamie Madille0472f32018-11-27 16:32:45 -05004259 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004260 return false;
4261 }
4262
4263 if (!programObject->isLinked())
4264 {
Jamie Madille0472f32018-11-27 16:32:45 -05004265 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004266 return false;
4267 }
4268
4269 switch (genMode)
4270 {
4271 case GL_NONE:
4272 if (components != 0)
4273 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004274 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004275 return false;
4276 }
4277 break;
4278
4279 case GL_OBJECT_LINEAR_CHROMIUM:
4280 case GL_EYE_LINEAR_CHROMIUM:
4281 case GL_CONSTANT_CHROMIUM:
4282 if (components < 1 || components > 4)
4283 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004284 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004285 return false;
4286 }
4287 if (!coeffs)
4288 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004289 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004290 return false;
4291 }
4292 break;
4293
4294 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004295 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004296 return false;
4297 }
4298
4299 // If the location is -1 then the command is silently ignored
4300 // and no further validation is needed.
4301 if (location == -1)
4302 return true;
4303
jchen103fd614d2018-08-13 12:21:58 +08004304 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004305
4306 if (!binding.valid)
4307 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004308 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004309 return false;
4310 }
4311
4312 if (binding.type != GL_NONE)
4313 {
4314 GLint expectedComponents = 0;
4315 switch (binding.type)
4316 {
4317 case GL_FLOAT:
4318 expectedComponents = 1;
4319 break;
4320 case GL_FLOAT_VEC2:
4321 expectedComponents = 2;
4322 break;
4323 case GL_FLOAT_VEC3:
4324 expectedComponents = 3;
4325 break;
4326 case GL_FLOAT_VEC4:
4327 expectedComponents = 4;
4328 break;
4329 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004330 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004331 return false;
4332 }
4333 if (expectedComponents != components && genMode != GL_NONE)
4334 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004335 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004336 return false;
4337 }
4338 }
4339 return true;
4340}
4341
Geoff Lang97073d12016-04-20 10:42:34 -07004342bool ValidateCopyTextureCHROMIUM(Context *context,
4343 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004344 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004345 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004346 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004347 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004348 GLint internalFormat,
4349 GLenum destType,
4350 GLboolean unpackFlipY,
4351 GLboolean unpackPremultiplyAlpha,
4352 GLboolean unpackUnmultiplyAlpha)
4353{
4354 if (!context->getExtensions().copyTexture)
4355 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004356 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004357 return false;
4358 }
4359
Geoff Lang4f0e0032017-05-01 16:04:35 -04004360 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004361 if (source == nullptr)
4362 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004363 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004364 return false;
4365 }
4366
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004367 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004368 {
Jamie Madille0472f32018-11-27 16:32:45 -05004369 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004370 return false;
4371 }
4372
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004373 TextureType sourceType = source->getType();
4374 ASSERT(sourceType != TextureType::CubeMap);
4375 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004376
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004377 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004378 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004379 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004380 return false;
4381 }
4382
Geoff Lang4f0e0032017-05-01 16:04:35 -04004383 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4384 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4385 if (sourceWidth == 0 || sourceHeight == 0)
4386 {
Jamie Madille0472f32018-11-27 16:32:45 -05004387 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004388 return false;
4389 }
4390
4391 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4392 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004393 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004394 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004395 return false;
4396 }
4397
Geoff Lang63458a32017-10-30 15:16:53 -04004398 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4399 {
Jamie Madille0472f32018-11-27 16:32:45 -05004400 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004401 return false;
4402 }
4403
Geoff Lang4f0e0032017-05-01 16:04:35 -04004404 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004405 if (dest == nullptr)
4406 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004407 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004408 return false;
4409 }
4410
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004411 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004412 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004413 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004414 return false;
4415 }
4416
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004417 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004418 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004419 {
Jamie Madille0472f32018-11-27 16:32:45 -05004420 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004421 return false;
4422 }
4423
Geoff Lang97073d12016-04-20 10:42:34 -07004424 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4425 {
Geoff Lang97073d12016-04-20 10:42:34 -07004426 return false;
4427 }
4428
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004429 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004430 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004431 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004432 return false;
4433 }
4434
Geoff Lang97073d12016-04-20 10:42:34 -07004435 if (dest->getImmutableFormat())
4436 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004437 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004438 return false;
4439 }
4440
4441 return true;
4442}
4443
4444bool ValidateCopySubTextureCHROMIUM(Context *context,
4445 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004446 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004447 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004448 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004449 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004450 GLint xoffset,
4451 GLint yoffset,
4452 GLint x,
4453 GLint y,
4454 GLsizei width,
4455 GLsizei height,
4456 GLboolean unpackFlipY,
4457 GLboolean unpackPremultiplyAlpha,
4458 GLboolean unpackUnmultiplyAlpha)
4459{
4460 if (!context->getExtensions().copyTexture)
4461 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004462 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004463 return false;
4464 }
4465
Geoff Lang4f0e0032017-05-01 16:04:35 -04004466 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004467 if (source == nullptr)
4468 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004469 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004470 return false;
4471 }
4472
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004473 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004474 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004475 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004476 return false;
4477 }
4478
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004479 TextureType sourceType = source->getType();
4480 ASSERT(sourceType != TextureType::CubeMap);
4481 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004482
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004483 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004484 {
Jamie Madille0472f32018-11-27 16:32:45 -05004485 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004486 return false;
4487 }
4488
4489 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4490 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004491 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004492 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004493 return false;
4494 }
4495
4496 if (x < 0 || y < 0)
4497 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004498 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004499 return false;
4500 }
4501
4502 if (width < 0 || height < 0)
4503 {
Jamie Madille0472f32018-11-27 16:32:45 -05004504 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004505 return false;
4506 }
4507
Geoff Lang4f0e0032017-05-01 16:04:35 -04004508 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4509 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004510 {
Jamie Madille0472f32018-11-27 16:32:45 -05004511 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004512 return false;
4513 }
4514
Geoff Lang4f0e0032017-05-01 16:04:35 -04004515 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4516 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004517 {
Jamie Madille0472f32018-11-27 16:32:45 -05004518 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004519 return false;
4520 }
4521
Geoff Lang63458a32017-10-30 15:16:53 -04004522 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4523 {
Jamie Madille0472f32018-11-27 16:32:45 -05004524 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004525 return false;
4526 }
4527
Geoff Lang4f0e0032017-05-01 16:04:35 -04004528 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004529 if (dest == nullptr)
4530 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004531 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004532 return false;
4533 }
4534
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004535 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004536 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004537 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004538 return false;
4539 }
4540
Brandon Jones28783792018-03-05 09:37:32 -08004541 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4542 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004543 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004544 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004545 return false;
4546 }
4547
Geoff Lang4f0e0032017-05-01 16:04:35 -04004548 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4549 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004550 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004551 return false;
4552 }
4553
4554 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4555 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004556 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004557 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004558 return false;
4559 }
4560
4561 if (xoffset < 0 || yoffset < 0)
4562 {
Jamie Madille0472f32018-11-27 16:32:45 -05004563 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004564 return false;
4565 }
4566
Geoff Lang4f0e0032017-05-01 16:04:35 -04004567 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4568 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004569 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004570 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004571 return false;
4572 }
4573
4574 return true;
4575}
4576
Geoff Lang47110bf2016-04-20 11:13:22 -07004577bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId)
4578{
4579 if (!context->getExtensions().copyCompressedTexture)
4580 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004581 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004582 return false;
4583 }
4584
4585 const gl::Texture *source = context->getTexture(sourceId);
4586 if (source == nullptr)
4587 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004588 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004589 return false;
4590 }
4591
Corentin Wallez99d492c2018-02-27 15:17:10 -05004592 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004593 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004594 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004595 return false;
4596 }
4597
Corentin Wallez99d492c2018-02-27 15:17:10 -05004598 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4599 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004600 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004601 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004602 return false;
4603 }
4604
Corentin Wallez99d492c2018-02-27 15:17:10 -05004605 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004606 if (!sourceFormat.info->compressed)
4607 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004608 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004609 return false;
4610 }
4611
4612 const gl::Texture *dest = context->getTexture(destId);
4613 if (dest == nullptr)
4614 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004615 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004616 return false;
4617 }
4618
Corentin Wallez99d492c2018-02-27 15:17:10 -05004619 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004620 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004621 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004622 return false;
4623 }
4624
4625 if (dest->getImmutableFormat())
4626 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004627 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004628 return false;
4629 }
4630
4631 return true;
4632}
4633
Jiawei Shao385b3e02018-03-21 09:43:28 +08004634bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004635{
4636 switch (type)
4637 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004638 case ShaderType::Vertex:
4639 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004640 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004641
Jiawei Shao385b3e02018-03-21 09:43:28 +08004642 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004643 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004644 {
Jamie Madille0472f32018-11-27 16:32:45 -05004645 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004646 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004647 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004648 break;
4649
Jiawei Shao385b3e02018-03-21 09:43:28 +08004650 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004651 if (!context->getExtensions().geometryShader)
4652 {
Jamie Madille0472f32018-11-27 16:32:45 -05004653 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004654 return false;
4655 }
4656 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004657 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004658 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004659 return false;
4660 }
Jamie Madill29639852016-09-02 15:00:09 -04004661
4662 return true;
4663}
4664
Jamie Madill5b772312018-03-08 20:28:32 -05004665bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004666 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004667 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004668 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004669 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004670{
4671 if (size < 0)
4672 {
Jamie Madille0472f32018-11-27 16:32:45 -05004673 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004674 return false;
4675 }
4676
4677 switch (usage)
4678 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004679 case BufferUsage::StreamDraw:
4680 case BufferUsage::StaticDraw:
4681 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004682 break;
4683
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004684 case BufferUsage::StreamRead:
4685 case BufferUsage::StaticRead:
4686 case BufferUsage::DynamicRead:
4687 case BufferUsage::StreamCopy:
4688 case BufferUsage::StaticCopy:
4689 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004690 if (context->getClientMajorVersion() < 3)
4691 {
Jamie Madille0472f32018-11-27 16:32:45 -05004692 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004693 return false;
4694 }
4695 break;
4696
4697 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004698 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004699 return false;
4700 }
4701
Corentin Walleze4477002017-12-01 14:39:58 -05004702 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004703 {
Jamie Madille0472f32018-11-27 16:32:45 -05004704 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004705 return false;
4706 }
4707
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004708 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004709
4710 if (!buffer)
4711 {
Jamie Madille0472f32018-11-27 16:32:45 -05004712 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004713 return false;
4714 }
4715
James Darpiniane8a93c62018-01-04 18:02:24 -08004716 if (context->getExtensions().webglCompatibility &&
4717 buffer->isBoundForTransformFeedbackAndOtherUse())
4718 {
Jamie Madille0472f32018-11-27 16:32:45 -05004719 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004720 return false;
4721 }
4722
Jamie Madill29639852016-09-02 15:00:09 -04004723 return true;
4724}
4725
Jamie Madill5b772312018-03-08 20:28:32 -05004726bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004727 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004728 GLintptr offset,
4729 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004730 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004731{
Brandon Jones6cad5662017-06-14 13:25:13 -07004732 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004733 {
Jamie Madille0472f32018-11-27 16:32:45 -05004734 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004735 return false;
4736 }
4737
4738 if (offset < 0)
4739 {
Jamie Madille0472f32018-11-27 16:32:45 -05004740 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004741 return false;
4742 }
4743
Corentin Walleze4477002017-12-01 14:39:58 -05004744 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004745 {
Jamie Madille0472f32018-11-27 16:32:45 -05004746 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004747 return false;
4748 }
4749
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004750 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004751
4752 if (!buffer)
4753 {
Jamie Madille0472f32018-11-27 16:32:45 -05004754 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004755 return false;
4756 }
4757
4758 if (buffer->isMapped())
4759 {
Jamie Madille0472f32018-11-27 16:32:45 -05004760 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004761 return false;
4762 }
4763
James Darpiniane8a93c62018-01-04 18:02:24 -08004764 if (context->getExtensions().webglCompatibility &&
4765 buffer->isBoundForTransformFeedbackAndOtherUse())
4766 {
Jamie Madille0472f32018-11-27 16:32:45 -05004767 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004768 return false;
4769 }
4770
Jamie Madill29639852016-09-02 15:00:09 -04004771 // Check for possible overflow of size + offset
4772 angle::CheckedNumeric<size_t> checkedSize(size);
4773 checkedSize += offset;
4774 if (!checkedSize.IsValid())
4775 {
Jamie Madille0472f32018-11-27 16:32:45 -05004776 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004777 return false;
4778 }
4779
4780 if (size + offset > buffer->getSize())
4781 {
Jamie Madille0472f32018-11-27 16:32:45 -05004782 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004783 return false;
4784 }
4785
Martin Radev4c4c8e72016-08-04 12:25:34 +03004786 return true;
4787}
4788
Geoff Lang111a99e2017-10-17 10:58:41 -04004789bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04004790{
Geoff Langc339c4e2016-11-29 10:37:36 -05004791 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04004792 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004793 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04004794 return false;
4795 }
4796
Geoff Lang111a99e2017-10-17 10:58:41 -04004797 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04004798 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004799 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04004800 return false;
4801 }
4802
4803 return true;
4804}
4805
Jamie Madill5b772312018-03-08 20:28:32 -05004806bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04004807{
Lingfeng Yang038dd532018-03-29 17:31:52 -07004808 if (context->getClientMajorVersion() < 2)
4809 {
4810 return ValidateMultitextureUnit(context, texture);
4811 }
4812
Jamie Madillef300b12016-10-07 15:12:09 -04004813 if (texture < GL_TEXTURE0 ||
4814 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
4815 {
Jamie Madille0472f32018-11-27 16:32:45 -05004816 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04004817 return false;
4818 }
4819
4820 return true;
4821}
4822
Jamie Madill5b772312018-03-08 20:28:32 -05004823bool ValidateAttachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillef300b12016-10-07 15:12:09 -04004824{
4825 Program *programObject = GetValidProgram(context, program);
4826 if (!programObject)
4827 {
4828 return false;
4829 }
4830
4831 Shader *shaderObject = GetValidShader(context, shader);
4832 if (!shaderObject)
4833 {
4834 return false;
4835 }
4836
Jiawei Shao385b3e02018-03-21 09:43:28 +08004837 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04004838 {
Jamie Madille0472f32018-11-27 16:32:45 -05004839 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08004840 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04004841 }
4842
4843 return true;
4844}
4845
Jamie Madill5b772312018-03-08 20:28:32 -05004846bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004847{
4848 if (index >= MAX_VERTEX_ATTRIBS)
4849 {
Jamie Madille0472f32018-11-27 16:32:45 -05004850 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004851 return false;
4852 }
4853
4854 if (strncmp(name, "gl_", 3) == 0)
4855 {
Jamie Madille0472f32018-11-27 16:32:45 -05004856 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004857 return false;
4858 }
4859
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004860 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04004861 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004862 const size_t length = strlen(name);
4863
4864 if (!IsValidESSLString(name, length))
4865 {
4866 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
4867 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05004868 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004869 return false;
4870 }
4871
4872 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
4873 {
4874 return false;
4875 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04004876 }
4877
Jamie Madill01a80ee2016-11-07 12:06:18 -05004878 return GetValidProgram(context, program) != nullptr;
4879}
4880
Jamie Madill5b772312018-03-08 20:28:32 -05004881bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004882{
Geoff Lange8afa902017-09-27 15:00:43 -04004883 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05004884 {
Jamie Madille0472f32018-11-27 16:32:45 -05004885 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004886 return false;
4887 }
4888
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004889 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004890 !context->isFramebufferGenerated(framebuffer))
4891 {
Jamie Madille0472f32018-11-27 16:32:45 -05004892 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004893 return false;
4894 }
4895
4896 return true;
4897}
4898
Jamie Madill5b772312018-03-08 20:28:32 -05004899bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004900{
4901 if (target != GL_RENDERBUFFER)
4902 {
Jamie Madille0472f32018-11-27 16:32:45 -05004903 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004904 return false;
4905 }
4906
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004907 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004908 !context->isRenderbufferGenerated(renderbuffer))
4909 {
Jamie Madille0472f32018-11-27 16:32:45 -05004910 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004911 return false;
4912 }
4913
4914 return true;
4915}
4916
Jamie Madill5b772312018-03-08 20:28:32 -05004917static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004918{
4919 switch (mode)
4920 {
4921 case GL_FUNC_ADD:
4922 case GL_FUNC_SUBTRACT:
4923 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04004924 return true;
4925
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004926 case GL_MIN:
4927 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04004928 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004929
4930 default:
4931 return false;
4932 }
4933}
4934
Jamie Madill5b772312018-03-08 20:28:32 -05004935bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004936{
4937 return true;
4938}
4939
Jamie Madill5b772312018-03-08 20:28:32 -05004940bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004941{
Geoff Lang50cac572017-09-26 17:37:43 -04004942 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004943 {
Jamie Madille0472f32018-11-27 16:32:45 -05004944 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004945 return false;
4946 }
4947
4948 return true;
4949}
4950
Jamie Madill5b772312018-03-08 20:28:32 -05004951bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004952{
Geoff Lang50cac572017-09-26 17:37:43 -04004953 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004954 {
Jamie Madille0472f32018-11-27 16:32:45 -05004955 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004956 return false;
4957 }
4958
Geoff Lang50cac572017-09-26 17:37:43 -04004959 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004960 {
Jamie Madille0472f32018-11-27 16:32:45 -05004961 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004962 return false;
4963 }
4964
4965 return true;
4966}
4967
Jamie Madill5b772312018-03-08 20:28:32 -05004968bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004969{
4970 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
4971}
4972
Jamie Madill5b772312018-03-08 20:28:32 -05004973bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004974 GLenum srcRGB,
4975 GLenum dstRGB,
4976 GLenum srcAlpha,
4977 GLenum dstAlpha)
4978{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004979 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004980 {
Jamie Madille0472f32018-11-27 16:32:45 -05004981 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004982 return false;
4983 }
4984
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004985 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004986 {
Jamie Madille0472f32018-11-27 16:32:45 -05004987 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004988 return false;
4989 }
4990
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004991 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004992 {
Jamie Madille0472f32018-11-27 16:32:45 -05004993 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004994 return false;
4995 }
4996
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004997 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004998 {
Jamie Madille0472f32018-11-27 16:32:45 -05004999 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005000 return false;
5001 }
5002
Frank Henigman146e8a12017-03-02 23:22:37 -05005003 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
5004 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005005 {
5006 bool constantColorUsed =
5007 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
5008 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
5009
5010 bool constantAlphaUsed =
5011 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
5012 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
5013
5014 if (constantColorUsed && constantAlphaUsed)
5015 {
Frank Henigman146e8a12017-03-02 23:22:37 -05005016 if (context->getExtensions().webglCompatibility)
5017 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005018 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
5019 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05005020 }
Jamie Madillc3e37312018-11-30 15:25:39 -05005021
5022 WARN() << kConstantColorAlphaLimitation;
5023 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005024 return false;
5025 }
5026 }
5027
5028 return true;
5029}
5030
Geoff Langc339c4e2016-11-29 10:37:36 -05005031bool ValidateGetString(Context *context, GLenum name)
5032{
5033 switch (name)
5034 {
5035 case GL_VENDOR:
5036 case GL_RENDERER:
5037 case GL_VERSION:
5038 case GL_SHADING_LANGUAGE_VERSION:
5039 case GL_EXTENSIONS:
5040 break;
5041
5042 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
5043 if (!context->getExtensions().requestExtension)
5044 {
Jamie Madille0472f32018-11-27 16:32:45 -05005045 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005046 return false;
5047 }
5048 break;
5049
5050 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005051 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005052 return false;
5053 }
5054
5055 return true;
5056}
5057
Jamie Madill5b772312018-03-08 20:28:32 -05005058bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05005059{
5060 if (width <= 0.0f || isNaN(width))
5061 {
Jamie Madille0472f32018-11-27 16:32:45 -05005062 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05005063 return false;
5064 }
5065
5066 return true;
5067}
5068
Jamie Madill5b772312018-03-08 20:28:32 -05005069bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05005070{
5071 if (context->getExtensions().webglCompatibility && zNear > zFar)
5072 {
Jamie Madille0472f32018-11-27 16:32:45 -05005073 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05005074 return false;
5075 }
5076
5077 return true;
5078}
5079
Jamie Madill5b772312018-03-08 20:28:32 -05005080bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005081 GLenum target,
5082 GLenum internalformat,
5083 GLsizei width,
5084 GLsizei height)
5085{
5086 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
5087 height);
5088}
5089
Jamie Madill5b772312018-03-08 20:28:32 -05005090bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005091 GLenum target,
5092 GLsizei samples,
5093 GLenum internalformat,
5094 GLsizei width,
5095 GLsizei height)
5096{
5097 if (!context->getExtensions().framebufferMultisample)
5098 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005099 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05005100 return false;
5101 }
5102
5103 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05005104 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05005105 // generated.
5106 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
5107 {
Jamie Madille0472f32018-11-27 16:32:45 -05005108 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005109 return false;
5110 }
5111
5112 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
5113 // the specified storage. This is different than ES 3.0 in which a sample number higher
5114 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
5115 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
5116 if (context->getClientMajorVersion() >= 3)
5117 {
5118 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
5119 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
5120 {
Jamie Madille0472f32018-11-27 16:32:45 -05005121 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005122 return false;
5123 }
5124 }
5125
5126 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
5127 width, height);
5128}
5129
Jamie Madill5b772312018-03-08 20:28:32 -05005130bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005131{
Geoff Lange8afa902017-09-27 15:00:43 -04005132 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005133 {
Jamie Madille0472f32018-11-27 16:32:45 -05005134 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005135 return false;
5136 }
5137
5138 return true;
5139}
5140
Jamie Madill5b772312018-03-08 20:28:32 -05005141bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005142{
5143 return true;
5144}
5145
Jamie Madill5b772312018-03-08 20:28:32 -05005146bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005147{
5148 return true;
5149}
5150
Jamie Madill5b772312018-03-08 20:28:32 -05005151bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005152{
5153 return true;
5154}
5155
Jamie Madill5b772312018-03-08 20:28:32 -05005156bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005157 GLboolean red,
5158 GLboolean green,
5159 GLboolean blue,
5160 GLboolean alpha)
5161{
5162 return true;
5163}
5164
Jamie Madill5b772312018-03-08 20:28:32 -05005165bool ValidateCompileShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005166{
5167 return true;
5168}
5169
Jamie Madill5b772312018-03-08 20:28:32 -05005170bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005171{
5172 return true;
5173}
5174
Jamie Madill5b772312018-03-08 20:28:32 -05005175bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005176{
5177 switch (mode)
5178 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005179 case CullFaceMode::Front:
5180 case CullFaceMode::Back:
5181 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005182 break;
5183
5184 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005185 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005186 return false;
5187 }
5188
5189 return true;
5190}
5191
Jamie Madill5b772312018-03-08 20:28:32 -05005192bool ValidateDeleteProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005193{
5194 if (program == 0)
5195 {
5196 return false;
5197 }
5198
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005199 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005200 {
5201 if (context->getShader(program))
5202 {
Jamie Madille0472f32018-11-27 16:32:45 -05005203 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005204 return false;
5205 }
5206 else
5207 {
Jamie Madille0472f32018-11-27 16:32:45 -05005208 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005209 return false;
5210 }
5211 }
5212
5213 return true;
5214}
5215
Jamie Madill5b772312018-03-08 20:28:32 -05005216bool ValidateDeleteShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005217{
5218 if (shader == 0)
5219 {
5220 return false;
5221 }
5222
5223 if (!context->getShader(shader))
5224 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005225 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005226 {
Jamie Madille0472f32018-11-27 16:32:45 -05005227 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005228 return false;
5229 }
5230 else
5231 {
Jamie Madille0472f32018-11-27 16:32:45 -05005232 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005233 return false;
5234 }
5235 }
5236
5237 return true;
5238}
5239
Jamie Madill5b772312018-03-08 20:28:32 -05005240bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005241{
5242 switch (func)
5243 {
5244 case GL_NEVER:
5245 case GL_ALWAYS:
5246 case GL_LESS:
5247 case GL_LEQUAL:
5248 case GL_EQUAL:
5249 case GL_GREATER:
5250 case GL_GEQUAL:
5251 case GL_NOTEQUAL:
5252 break;
5253
5254 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005255 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005256 return false;
5257 }
5258
5259 return true;
5260}
5261
Jamie Madill5b772312018-03-08 20:28:32 -05005262bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005263{
5264 return true;
5265}
5266
Jamie Madill5b772312018-03-08 20:28:32 -05005267bool ValidateDetachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005268{
5269 Program *programObject = GetValidProgram(context, program);
5270 if (!programObject)
5271 {
5272 return false;
5273 }
5274
5275 Shader *shaderObject = GetValidShader(context, shader);
5276 if (!shaderObject)
5277 {
5278 return false;
5279 }
5280
Jiawei Shao385b3e02018-03-21 09:43:28 +08005281 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005282 if (attachedShader != shaderObject)
5283 {
Jamie Madille0472f32018-11-27 16:32:45 -05005284 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005285 return false;
5286 }
5287
5288 return true;
5289}
5290
Jamie Madill5b772312018-03-08 20:28:32 -05005291bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005292{
5293 if (index >= MAX_VERTEX_ATTRIBS)
5294 {
Jamie Madille0472f32018-11-27 16:32:45 -05005295 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005296 return false;
5297 }
5298
5299 return true;
5300}
5301
Jamie Madill5b772312018-03-08 20:28:32 -05005302bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005303{
5304 if (index >= MAX_VERTEX_ATTRIBS)
5305 {
Jamie Madille0472f32018-11-27 16:32:45 -05005306 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005307 return false;
5308 }
5309
5310 return true;
5311}
5312
Jamie Madill5b772312018-03-08 20:28:32 -05005313bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005314{
5315 return true;
5316}
5317
Jamie Madill5b772312018-03-08 20:28:32 -05005318bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005319{
5320 return true;
5321}
5322
Jamie Madill5b772312018-03-08 20:28:32 -05005323bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005324{
5325 switch (mode)
5326 {
5327 case GL_CW:
5328 case GL_CCW:
5329 break;
5330 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005331 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005332 return false;
5333 }
5334
5335 return true;
5336}
5337
Jamie Madill5b772312018-03-08 20:28:32 -05005338bool ValidateGetActiveAttrib(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005339 GLuint program,
5340 GLuint index,
5341 GLsizei bufsize,
5342 GLsizei *length,
5343 GLint *size,
5344 GLenum *type,
5345 GLchar *name)
5346{
5347 if (bufsize < 0)
5348 {
Jamie Madille0472f32018-11-27 16:32:45 -05005349 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005350 return false;
5351 }
5352
5353 Program *programObject = GetValidProgram(context, program);
5354
5355 if (!programObject)
5356 {
5357 return false;
5358 }
5359
5360 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5361 {
Jamie Madille0472f32018-11-27 16:32:45 -05005362 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005363 return false;
5364 }
5365
5366 return true;
5367}
5368
Jamie Madill5b772312018-03-08 20:28:32 -05005369bool ValidateGetActiveUniform(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005370 GLuint program,
5371 GLuint index,
5372 GLsizei bufsize,
5373 GLsizei *length,
5374 GLint *size,
5375 GLenum *type,
5376 GLchar *name)
5377{
5378 if (bufsize < 0)
5379 {
Jamie Madille0472f32018-11-27 16:32:45 -05005380 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005381 return false;
5382 }
5383
5384 Program *programObject = GetValidProgram(context, program);
5385
5386 if (!programObject)
5387 {
5388 return false;
5389 }
5390
5391 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5392 {
Jamie Madille0472f32018-11-27 16:32:45 -05005393 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005394 return false;
5395 }
5396
5397 return true;
5398}
5399
Jamie Madill5b772312018-03-08 20:28:32 -05005400bool ValidateGetAttachedShaders(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005401 GLuint program,
5402 GLsizei maxcount,
5403 GLsizei *count,
5404 GLuint *shaders)
5405{
5406 if (maxcount < 0)
5407 {
Jamie Madille0472f32018-11-27 16:32:45 -05005408 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005409 return false;
5410 }
5411
5412 Program *programObject = GetValidProgram(context, program);
5413
5414 if (!programObject)
5415 {
5416 return false;
5417 }
5418
5419 return true;
5420}
5421
Jamie Madill5b772312018-03-08 20:28:32 -05005422bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005423{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005424 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5425 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005426 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005427 {
Jamie Madille0472f32018-11-27 16:32:45 -05005428 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005429 return false;
5430 }
5431
Jamie Madillc1d770e2017-04-13 17:31:24 -04005432 Program *programObject = GetValidProgram(context, program);
5433
5434 if (!programObject)
5435 {
Jamie Madille0472f32018-11-27 16:32:45 -05005436 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005437 return false;
5438 }
5439
5440 if (!programObject->isLinked())
5441 {
Jamie Madille0472f32018-11-27 16:32:45 -05005442 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005443 return false;
5444 }
5445
5446 return true;
5447}
5448
Jamie Madill5b772312018-03-08 20:28:32 -05005449bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005450{
5451 GLenum nativeType;
5452 unsigned int numParams = 0;
5453 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5454}
5455
Jamie Madill5b772312018-03-08 20:28:32 -05005456bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005457{
5458 return true;
5459}
5460
Jamie Madill5b772312018-03-08 20:28:32 -05005461bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005462{
5463 GLenum nativeType;
5464 unsigned int numParams = 0;
5465 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5466}
5467
Jamie Madill5b772312018-03-08 20:28:32 -05005468bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005469{
5470 GLenum nativeType;
5471 unsigned int numParams = 0;
5472 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5473}
5474
Jamie Madill5b772312018-03-08 20:28:32 -05005475bool ValidateGetProgramInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005476 GLuint program,
5477 GLsizei bufsize,
5478 GLsizei *length,
5479 GLchar *infolog)
5480{
5481 if (bufsize < 0)
5482 {
Jamie Madille0472f32018-11-27 16:32:45 -05005483 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005484 return false;
5485 }
5486
5487 Program *programObject = GetValidProgram(context, program);
5488 if (!programObject)
5489 {
5490 return false;
5491 }
5492
5493 return true;
5494}
5495
Jamie Madill5b772312018-03-08 20:28:32 -05005496bool ValidateGetShaderInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005497 GLuint shader,
5498 GLsizei bufsize,
5499 GLsizei *length,
5500 GLchar *infolog)
5501{
5502 if (bufsize < 0)
5503 {
Jamie Madille0472f32018-11-27 16:32:45 -05005504 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005505 return false;
5506 }
5507
5508 Shader *shaderObject = GetValidShader(context, shader);
5509 if (!shaderObject)
5510 {
5511 return false;
5512 }
5513
5514 return true;
5515}
5516
Jamie Madill5b772312018-03-08 20:28:32 -05005517bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005518 GLenum shadertype,
5519 GLenum precisiontype,
5520 GLint *range,
5521 GLint *precision)
5522{
5523 switch (shadertype)
5524 {
5525 case GL_VERTEX_SHADER:
5526 case GL_FRAGMENT_SHADER:
5527 break;
5528 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005529 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005530 return false;
5531 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005532 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005533 return false;
5534 }
5535
5536 switch (precisiontype)
5537 {
5538 case GL_LOW_FLOAT:
5539 case GL_MEDIUM_FLOAT:
5540 case GL_HIGH_FLOAT:
5541 case GL_LOW_INT:
5542 case GL_MEDIUM_INT:
5543 case GL_HIGH_INT:
5544 break;
5545
5546 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005547 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005548 return false;
5549 }
5550
5551 return true;
5552}
5553
Jamie Madill5b772312018-03-08 20:28:32 -05005554bool ValidateGetShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005555 GLuint shader,
5556 GLsizei bufsize,
5557 GLsizei *length,
5558 GLchar *source)
5559{
5560 if (bufsize < 0)
5561 {
Jamie Madille0472f32018-11-27 16:32:45 -05005562 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005563 return false;
5564 }
5565
5566 Shader *shaderObject = GetValidShader(context, shader);
5567 if (!shaderObject)
5568 {
5569 return false;
5570 }
5571
5572 return true;
5573}
5574
Jamie Madill5b772312018-03-08 20:28:32 -05005575bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005576{
5577 if (strstr(name, "gl_") == name)
5578 {
5579 return false;
5580 }
5581
Geoff Langfc32e8b2017-05-31 14:16:59 -04005582 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5583 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005584 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005585 {
Jamie Madille0472f32018-11-27 16:32:45 -05005586 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005587 return false;
5588 }
5589
Jamie Madillc1d770e2017-04-13 17:31:24 -04005590 Program *programObject = GetValidProgram(context, program);
5591
5592 if (!programObject)
5593 {
5594 return false;
5595 }
5596
5597 if (!programObject->isLinked())
5598 {
Jamie Madille0472f32018-11-27 16:32:45 -05005599 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005600 return false;
5601 }
5602
5603 return true;
5604}
5605
Jamie Madill5b772312018-03-08 20:28:32 -05005606bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005607{
5608 switch (mode)
5609 {
5610 case GL_FASTEST:
5611 case GL_NICEST:
5612 case GL_DONT_CARE:
5613 break;
5614
5615 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005616 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005617 return false;
5618 }
5619
5620 switch (target)
5621 {
5622 case GL_GENERATE_MIPMAP_HINT:
5623 break;
5624
Geoff Lange7bd2182017-06-16 16:13:13 -04005625 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5626 if (context->getClientVersion() < ES_3_0 &&
5627 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005628 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005629 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005630 return false;
5631 }
5632 break;
5633
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005634 case GL_PERSPECTIVE_CORRECTION_HINT:
5635 case GL_POINT_SMOOTH_HINT:
5636 case GL_LINE_SMOOTH_HINT:
5637 case GL_FOG_HINT:
5638 if (context->getClientMajorVersion() >= 2)
5639 {
Jamie Madille0472f32018-11-27 16:32:45 -05005640 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005641 return false;
5642 }
5643 break;
5644
Jamie Madillc1d770e2017-04-13 17:31:24 -04005645 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005646 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005647 return false;
5648 }
5649
5650 return true;
5651}
5652
Jamie Madill5b772312018-03-08 20:28:32 -05005653bool ValidateIsBuffer(Context *context, GLuint buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005654{
5655 return true;
5656}
5657
Jamie Madill5b772312018-03-08 20:28:32 -05005658bool ValidateIsFramebuffer(Context *context, GLuint framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005659{
5660 return true;
5661}
5662
Jamie Madill5b772312018-03-08 20:28:32 -05005663bool ValidateIsProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005664{
5665 return true;
5666}
5667
Jamie Madill5b772312018-03-08 20:28:32 -05005668bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005669{
5670 return true;
5671}
5672
Jamie Madill5b772312018-03-08 20:28:32 -05005673bool ValidateIsShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005674{
5675 return true;
5676}
5677
Jamie Madill5b772312018-03-08 20:28:32 -05005678bool ValidateIsTexture(Context *context, GLuint texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005679{
5680 return true;
5681}
5682
Jamie Madill5b772312018-03-08 20:28:32 -05005683bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005684{
5685 if (context->getClientMajorVersion() < 3)
5686 {
5687 switch (pname)
5688 {
5689 case GL_UNPACK_IMAGE_HEIGHT:
5690 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005691 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005692 return false;
5693
5694 case GL_UNPACK_ROW_LENGTH:
5695 case GL_UNPACK_SKIP_ROWS:
5696 case GL_UNPACK_SKIP_PIXELS:
5697 if (!context->getExtensions().unpackSubimage)
5698 {
Jamie Madille0472f32018-11-27 16:32:45 -05005699 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005700 return false;
5701 }
5702 break;
5703
5704 case GL_PACK_ROW_LENGTH:
5705 case GL_PACK_SKIP_ROWS:
5706 case GL_PACK_SKIP_PIXELS:
5707 if (!context->getExtensions().packSubimage)
5708 {
Jamie Madille0472f32018-11-27 16:32:45 -05005709 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005710 return false;
5711 }
5712 break;
5713 }
5714 }
5715
5716 if (param < 0)
5717 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005718 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005719 return false;
5720 }
5721
5722 switch (pname)
5723 {
5724 case GL_UNPACK_ALIGNMENT:
5725 if (param != 1 && param != 2 && param != 4 && param != 8)
5726 {
Jamie Madille0472f32018-11-27 16:32:45 -05005727 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005728 return false;
5729 }
5730 break;
5731
5732 case GL_PACK_ALIGNMENT:
5733 if (param != 1 && param != 2 && param != 4 && param != 8)
5734 {
Jamie Madille0472f32018-11-27 16:32:45 -05005735 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005736 return false;
5737 }
5738 break;
5739
5740 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005741 if (!context->getExtensions().packReverseRowOrder)
5742 {
Jamie Madille0472f32018-11-27 16:32:45 -05005743 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005744 }
5745 break;
5746
Jamie Madillc1d770e2017-04-13 17:31:24 -04005747 case GL_UNPACK_ROW_LENGTH:
5748 case GL_UNPACK_IMAGE_HEIGHT:
5749 case GL_UNPACK_SKIP_IMAGES:
5750 case GL_UNPACK_SKIP_ROWS:
5751 case GL_UNPACK_SKIP_PIXELS:
5752 case GL_PACK_ROW_LENGTH:
5753 case GL_PACK_SKIP_ROWS:
5754 case GL_PACK_SKIP_PIXELS:
5755 break;
5756
5757 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005758 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005759 return false;
5760 }
5761
5762 return true;
5763}
5764
Jamie Madill5b772312018-03-08 20:28:32 -05005765bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005766{
5767 return true;
5768}
5769
Jamie Madill5b772312018-03-08 20:28:32 -05005770bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005771{
5772 return true;
5773}
5774
Jamie Madill5b772312018-03-08 20:28:32 -05005775bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005776{
5777 return true;
5778}
5779
Jamie Madill5b772312018-03-08 20:28:32 -05005780bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005781{
5782 if (width < 0 || height < 0)
5783 {
Jamie Madille0472f32018-11-27 16:32:45 -05005784 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005785 return false;
5786 }
5787
5788 return true;
5789}
5790
Jamie Madill5b772312018-03-08 20:28:32 -05005791bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005792 GLsizei n,
5793 const GLuint *shaders,
5794 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005795 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005796 GLsizei length)
5797{
5798 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
5799 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
5800 shaderBinaryFormats.end())
5801 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005802 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005803 return false;
5804 }
5805
5806 return true;
5807}
5808
Jamie Madill5b772312018-03-08 20:28:32 -05005809bool ValidateShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005810 GLuint shader,
5811 GLsizei count,
5812 const GLchar *const *string,
5813 const GLint *length)
5814{
5815 if (count < 0)
5816 {
Jamie Madille0472f32018-11-27 16:32:45 -05005817 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005818 return false;
5819 }
5820
Geoff Langfc32e8b2017-05-31 14:16:59 -04005821 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5822 // shader-related entry points
5823 if (context->getExtensions().webglCompatibility)
5824 {
5825 for (GLsizei i = 0; i < count; i++)
5826 {
Geoff Langcab92ee2017-07-19 17:32:07 -04005827 size_t len =
5828 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04005829
5830 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04005831 if (!IsValidESSLShaderSourceString(string[i], len,
5832 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005833 {
Jamie Madille0472f32018-11-27 16:32:45 -05005834 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005835 return false;
5836 }
5837 }
5838 }
5839
Jamie Madillc1d770e2017-04-13 17:31:24 -04005840 Shader *shaderObject = GetValidShader(context, shader);
5841 if (!shaderObject)
5842 {
5843 return false;
5844 }
5845
5846 return true;
5847}
5848
Jamie Madill5b772312018-03-08 20:28:32 -05005849bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005850{
5851 if (!IsValidStencilFunc(func))
5852 {
Jamie Madille0472f32018-11-27 16:32:45 -05005853 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005854 return false;
5855 }
5856
5857 return true;
5858}
5859
Jamie Madill5b772312018-03-08 20:28:32 -05005860bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005861{
5862 if (!IsValidStencilFace(face))
5863 {
Jamie Madille0472f32018-11-27 16:32:45 -05005864 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005865 return false;
5866 }
5867
5868 if (!IsValidStencilFunc(func))
5869 {
Jamie Madille0472f32018-11-27 16:32:45 -05005870 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005871 return false;
5872 }
5873
5874 return true;
5875}
5876
Jamie Madill5b772312018-03-08 20:28:32 -05005877bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005878{
5879 return true;
5880}
5881
Jamie Madill5b772312018-03-08 20:28:32 -05005882bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005883{
5884 if (!IsValidStencilFace(face))
5885 {
Jamie Madille0472f32018-11-27 16:32:45 -05005886 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005887 return false;
5888 }
5889
5890 return true;
5891}
5892
Jamie Madill5b772312018-03-08 20:28:32 -05005893bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005894{
5895 if (!IsValidStencilOp(fail))
5896 {
Jamie Madille0472f32018-11-27 16:32:45 -05005897 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005898 return false;
5899 }
5900
5901 if (!IsValidStencilOp(zfail))
5902 {
Jamie Madille0472f32018-11-27 16:32:45 -05005903 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005904 return false;
5905 }
5906
5907 if (!IsValidStencilOp(zpass))
5908 {
Jamie Madille0472f32018-11-27 16:32:45 -05005909 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005910 return false;
5911 }
5912
5913 return true;
5914}
5915
Jamie Madill5b772312018-03-08 20:28:32 -05005916bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005917 GLenum face,
5918 GLenum fail,
5919 GLenum zfail,
5920 GLenum zpass)
5921{
5922 if (!IsValidStencilFace(face))
5923 {
Jamie Madille0472f32018-11-27 16:32:45 -05005924 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005925 return false;
5926 }
5927
5928 return ValidateStencilOp(context, fail, zfail, zpass);
5929}
5930
Jamie Madill5b772312018-03-08 20:28:32 -05005931bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005932{
5933 return ValidateUniform(context, GL_FLOAT, location, 1);
5934}
5935
Jamie Madill5b772312018-03-08 20:28:32 -05005936bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005937{
5938 return ValidateUniform(context, GL_FLOAT, location, count);
5939}
5940
Jamie Madill5b772312018-03-08 20:28:32 -05005941bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04005942{
5943 return ValidateUniform1iv(context, location, 1, &x);
5944}
5945
Jamie Madill5b772312018-03-08 20:28:32 -05005946bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005947{
5948 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
5949}
5950
Jamie Madill5b772312018-03-08 20:28:32 -05005951bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005952{
5953 return ValidateUniform(context, GL_INT_VEC2, location, 1);
5954}
5955
Jamie Madill5b772312018-03-08 20:28:32 -05005956bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005957{
5958 return ValidateUniform(context, GL_INT_VEC2, location, count);
5959}
5960
Jamie Madill5b772312018-03-08 20:28:32 -05005961bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005962{
5963 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
5964}
5965
Jamie Madill5b772312018-03-08 20:28:32 -05005966bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005967{
5968 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
5969}
5970
Jamie Madill5b772312018-03-08 20:28:32 -05005971bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005972{
5973 return ValidateUniform(context, GL_INT_VEC3, location, 1);
5974}
5975
Jamie Madill5b772312018-03-08 20:28:32 -05005976bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005977{
5978 return ValidateUniform(context, GL_INT_VEC3, location, count);
5979}
5980
Jamie Madill5b772312018-03-08 20:28:32 -05005981bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005982{
5983 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
5984}
5985
Jamie Madill5b772312018-03-08 20:28:32 -05005986bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005987{
5988 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
5989}
5990
Jamie Madill5b772312018-03-08 20:28:32 -05005991bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005992{
5993 return ValidateUniform(context, GL_INT_VEC4, location, 1);
5994}
5995
Jamie Madill5b772312018-03-08 20:28:32 -05005996bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005997{
5998 return ValidateUniform(context, GL_INT_VEC4, location, count);
5999}
6000
Jamie Madill5b772312018-03-08 20:28:32 -05006001bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006002 GLint location,
6003 GLsizei count,
6004 GLboolean transpose,
6005 const GLfloat *value)
6006{
6007 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
6008}
6009
Jamie Madill5b772312018-03-08 20:28:32 -05006010bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006011 GLint location,
6012 GLsizei count,
6013 GLboolean transpose,
6014 const GLfloat *value)
6015{
6016 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
6017}
6018
Jamie Madill5b772312018-03-08 20:28:32 -05006019bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006020 GLint location,
6021 GLsizei count,
6022 GLboolean transpose,
6023 const GLfloat *value)
6024{
6025 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
6026}
6027
Jamie Madill5b772312018-03-08 20:28:32 -05006028bool ValidateValidateProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006029{
6030 Program *programObject = GetValidProgram(context, program);
6031
6032 if (!programObject)
6033 {
6034 return false;
6035 }
6036
6037 return true;
6038}
6039
Jamie Madill5b772312018-03-08 20:28:32 -05006040bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006041{
6042 return ValidateVertexAttribIndex(context, index);
6043}
6044
Jamie Madill5b772312018-03-08 20:28:32 -05006045bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006046{
6047 return ValidateVertexAttribIndex(context, index);
6048}
6049
Jamie Madill5b772312018-03-08 20:28:32 -05006050bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006051{
6052 return ValidateVertexAttribIndex(context, index);
6053}
6054
Jamie Madill5b772312018-03-08 20:28:32 -05006055bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006056{
6057 return ValidateVertexAttribIndex(context, index);
6058}
6059
Jamie Madill5b772312018-03-08 20:28:32 -05006060bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006061{
6062 return ValidateVertexAttribIndex(context, index);
6063}
6064
Jamie Madill5b772312018-03-08 20:28:32 -05006065bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006066{
6067 return ValidateVertexAttribIndex(context, index);
6068}
6069
Jamie Madill5b772312018-03-08 20:28:32 -05006070bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006071 GLuint index,
6072 GLfloat x,
6073 GLfloat y,
6074 GLfloat z,
6075 GLfloat w)
6076{
6077 return ValidateVertexAttribIndex(context, index);
6078}
6079
Jamie Madill5b772312018-03-08 20:28:32 -05006080bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006081{
6082 return ValidateVertexAttribIndex(context, index);
6083}
6084
Jamie Madill5b772312018-03-08 20:28:32 -05006085bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006086{
6087 if (width < 0 || height < 0)
6088 {
Jamie Madille0472f32018-11-27 16:32:45 -05006089 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006090 return false;
6091 }
6092
6093 return true;
6094}
6095
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08006096bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006097 GLenum target,
6098 GLenum attachment,
6099 GLenum pname,
6100 GLint *params)
6101{
6102 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
6103 nullptr);
6104}
6105
Jamie Madill5b772312018-03-08 20:28:32 -05006106bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006107{
6108 return ValidateGetProgramivBase(context, program, pname, nullptr);
6109}
6110
Jamie Madill5b772312018-03-08 20:28:32 -05006111bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006112 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006113 GLint level,
6114 GLenum internalformat,
6115 GLint x,
6116 GLint y,
6117 GLsizei width,
6118 GLsizei height,
6119 GLint border)
6120{
6121 if (context->getClientMajorVersion() < 3)
6122 {
6123 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
6124 0, x, y, width, height, border);
6125 }
6126
6127 ASSERT(context->getClientMajorVersion() == 3);
6128 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
6129 0, x, y, width, height, border);
6130}
6131
6132bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006133 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006134 GLint level,
6135 GLint xoffset,
6136 GLint yoffset,
6137 GLint x,
6138 GLint y,
6139 GLsizei width,
6140 GLsizei height)
6141{
6142 if (context->getClientMajorVersion() < 3)
6143 {
6144 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
6145 yoffset, x, y, width, height, 0);
6146 }
6147
6148 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
6149 yoffset, 0, x, y, width, height, 0);
6150}
6151
6152bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *)
6153{
6154 return ValidateGenOrDelete(context, n);
6155}
6156
6157bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *)
6158{
6159 return ValidateGenOrDelete(context, n);
6160}
6161
6162bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *)
6163{
6164 return ValidateGenOrDelete(context, n);
6165}
6166
6167bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *)
6168{
6169 return ValidateGenOrDelete(context, n);
6170}
6171
6172bool ValidateDisable(Context *context, GLenum cap)
6173{
6174 if (!ValidCap(context, cap, false))
6175 {
Jamie Madille0472f32018-11-27 16:32:45 -05006176 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006177 return false;
6178 }
6179
6180 return true;
6181}
6182
6183bool ValidateEnable(Context *context, GLenum cap)
6184{
6185 if (!ValidCap(context, cap, false))
6186 {
Jamie Madille0472f32018-11-27 16:32:45 -05006187 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006188 return false;
6189 }
6190
6191 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6192 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6193 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006194 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006195
6196 // We also output an error message to the debugger window if tracing is active, so that
6197 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006198 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006199 return false;
6200 }
6201
6202 return true;
6203}
6204
6205bool ValidateFramebufferRenderbuffer(Context *context,
6206 GLenum target,
6207 GLenum attachment,
6208 GLenum renderbuffertarget,
6209 GLuint renderbuffer)
6210{
Geoff Lange8afa902017-09-27 15:00:43 -04006211 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006212 {
Jamie Madille0472f32018-11-27 16:32:45 -05006213 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006214 return false;
6215 }
6216
6217 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)
6218 {
Jamie Madille0472f32018-11-27 16:32:45 -05006219 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006220 return false;
6221 }
6222
6223 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6224 renderbuffertarget, renderbuffer);
6225}
6226
6227bool ValidateFramebufferTexture2D(Context *context,
6228 GLenum target,
6229 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006230 TextureTarget textarget,
Jamie Madillbe849e42017-05-02 15:49:00 -04006231 GLuint texture,
6232 GLint level)
6233{
6234 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6235 // extension
6236 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6237 level != 0)
6238 {
Jamie Madille0472f32018-11-27 16:32:45 -05006239 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006240 return false;
6241 }
6242
6243 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6244 {
6245 return false;
6246 }
6247
6248 if (texture != 0)
6249 {
6250 gl::Texture *tex = context->getTexture(texture);
6251 ASSERT(tex);
6252
6253 const gl::Caps &caps = context->getCaps();
6254
6255 switch (textarget)
6256 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006257 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006258 {
6259 if (level > gl::log2(caps.max2DTextureSize))
6260 {
Jamie Madille0472f32018-11-27 16:32:45 -05006261 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006262 return false;
6263 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006264 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006265 {
Jamie Madille0472f32018-11-27 16:32:45 -05006266 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006267 return false;
6268 }
6269 }
6270 break;
6271
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006272 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006273 {
6274 if (level != 0)
6275 {
Jamie Madille0472f32018-11-27 16:32:45 -05006276 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006277 return false;
6278 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006279 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006280 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006281 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006282 return false;
6283 }
6284 }
6285 break;
6286
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006287 case TextureTarget::CubeMapNegativeX:
6288 case TextureTarget::CubeMapNegativeY:
6289 case TextureTarget::CubeMapNegativeZ:
6290 case TextureTarget::CubeMapPositiveX:
6291 case TextureTarget::CubeMapPositiveY:
6292 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006293 {
6294 if (level > gl::log2(caps.maxCubeMapTextureSize))
6295 {
Jamie Madille0472f32018-11-27 16:32:45 -05006296 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006297 return false;
6298 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006299 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006300 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006301 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006302 return false;
6303 }
6304 }
6305 break;
6306
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006307 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006308 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006309 if (context->getClientVersion() < ES_3_1 &&
6310 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006311 {
Jamie Madill610640f2018-11-21 17:28:41 -05006312 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006313 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006314 return false;
6315 }
6316
6317 if (level != 0)
6318 {
Jamie Madille0472f32018-11-27 16:32:45 -05006319 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006320 return false;
6321 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006322 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006323 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006324 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006325 return false;
6326 }
6327 }
6328 break;
6329
6330 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006331 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006332 return false;
6333 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006334 }
6335
6336 return true;
6337}
6338
6339bool ValidateGenBuffers(Context *context, GLint n, GLuint *)
6340{
6341 return ValidateGenOrDelete(context, n);
6342}
6343
6344bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *)
6345{
6346 return ValidateGenOrDelete(context, n);
6347}
6348
6349bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *)
6350{
6351 return ValidateGenOrDelete(context, n);
6352}
6353
6354bool ValidateGenTextures(Context *context, GLint n, GLuint *)
6355{
6356 return ValidateGenOrDelete(context, n);
6357}
6358
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006359bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006360{
6361 if (!ValidTextureTarget(context, target))
6362 {
Jamie Madille0472f32018-11-27 16:32:45 -05006363 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006364 return false;
6365 }
6366
Jamie Madillcfc73cc2019-04-08 16:26:51 -04006367 Texture *texture = context->getTextureByType(target);
Jamie Madillbe849e42017-05-02 15:49:00 -04006368
6369 if (texture == nullptr)
6370 {
Jamie Madille0472f32018-11-27 16:32:45 -05006371 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006372 return false;
6373 }
6374
6375 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6376
6377 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6378 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6379 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6380 {
Jamie Madille0472f32018-11-27 16:32:45 -05006381 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006382 return false;
6383 }
6384
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006385 TextureTarget baseTarget = (target == TextureType::CubeMap)
6386 ? TextureTarget::CubeMapPositiveX
6387 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006388 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6389 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6390 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006391 {
Jamie Madille0472f32018-11-27 16:32:45 -05006392 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006393 return false;
6394 }
6395
Geoff Lang536eca12017-09-13 11:23:35 -04006396 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6397 bool formatUnsized = !format.sized;
6398 bool formatColorRenderableAndFilterable =
6399 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006400 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006401 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006402 {
Jamie Madille0472f32018-11-27 16:32:45 -05006403 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006404 return false;
6405 }
6406
Geoff Lang536eca12017-09-13 11:23:35 -04006407 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6408 // generation
6409 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6410 {
Jamie Madille0472f32018-11-27 16:32:45 -05006411 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006412 return false;
6413 }
6414
Jiange2c00842018-07-13 16:50:49 +08006415 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6416 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6417 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006418 {
Jamie Madille0472f32018-11-27 16:32:45 -05006419 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006420 return false;
6421 }
6422
6423 // Non-power of 2 ES2 check
6424 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6425 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6426 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6427 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006428 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6429 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006430 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006431 return false;
6432 }
6433
6434 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006435 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006436 {
Jamie Madille0472f32018-11-27 16:32:45 -05006437 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006438 return false;
6439 }
6440
James Darpinian83b2f0e2018-11-27 15:56:01 -08006441 if (context->getExtensions().webglCompatibility &&
6442 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6443 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6444 {
6445 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6446 return false;
6447 }
6448
Jamie Madillbe849e42017-05-02 15:49:00 -04006449 return true;
6450}
6451
Jamie Madill5b772312018-03-08 20:28:32 -05006452bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006453 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006454 GLenum pname,
6455 GLint *params)
6456{
6457 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6458}
6459
6460bool ValidateGetRenderbufferParameteriv(Context *context,
6461 GLenum target,
6462 GLenum pname,
6463 GLint *params)
6464{
6465 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6466}
6467
6468bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params)
6469{
6470 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6471}
6472
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006473bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006474{
6475 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6476}
6477
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006478bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006479{
6480 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6481}
6482
Till Rathmannb8543632018-10-02 19:46:14 +02006483bool ValidateGetTexParameterIivOES(Context *context,
6484 TextureType target,
6485 GLenum pname,
6486 GLint *params)
6487{
6488 if (context->getClientMajorVersion() < 3)
6489 {
Jamie Madille0472f32018-11-27 16:32:45 -05006490 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006491 return false;
6492 }
6493 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6494}
6495
6496bool ValidateGetTexParameterIuivOES(Context *context,
6497 TextureType target,
6498 GLenum pname,
6499 GLuint *params)
6500{
6501 if (context->getClientMajorVersion() < 3)
6502 {
Jamie Madille0472f32018-11-27 16:32:45 -05006503 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006504 return false;
6505 }
6506 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6507}
6508
Jamie Madillbe849e42017-05-02 15:49:00 -04006509bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params)
6510{
6511 return ValidateGetUniformBase(context, program, location);
6512}
6513
6514bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params)
6515{
6516 return ValidateGetUniformBase(context, program, location);
6517}
6518
6519bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6520{
6521 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6522}
6523
6524bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6525{
6526 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6527}
6528
6529bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6530{
6531 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6532}
6533
6534bool ValidateIsEnabled(Context *context, GLenum cap)
6535{
6536 if (!ValidCap(context, cap, true))
6537 {
Jamie Madille0472f32018-11-27 16:32:45 -05006538 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006539 return false;
6540 }
6541
6542 return true;
6543}
6544
6545bool ValidateLinkProgram(Context *context, GLuint program)
6546{
6547 if (context->hasActiveTransformFeedback(program))
6548 {
6549 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006550 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006551 return false;
6552 }
6553
6554 Program *programObject = GetValidProgram(context, program);
6555 if (!programObject)
6556 {
6557 return false;
6558 }
6559
6560 return true;
6561}
6562
Jamie Madill4928b7c2017-06-20 12:57:39 -04006563bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006564 GLint x,
6565 GLint y,
6566 GLsizei width,
6567 GLsizei height,
6568 GLenum format,
6569 GLenum type,
6570 void *pixels)
6571{
6572 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6573 nullptr, pixels);
6574}
6575
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006576bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006577{
Till Rathmannb8543632018-10-02 19:46:14 +02006578 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006579}
6580
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006581bool ValidateTexParameterfv(Context *context,
6582 TextureType target,
6583 GLenum pname,
6584 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006585{
Till Rathmannb8543632018-10-02 19:46:14 +02006586 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006587}
6588
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006589bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006590{
Till Rathmannb8543632018-10-02 19:46:14 +02006591 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006592}
6593
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006594bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006595{
Till Rathmannb8543632018-10-02 19:46:14 +02006596 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6597}
6598
6599bool ValidateTexParameterIivOES(Context *context,
6600 TextureType target,
6601 GLenum pname,
6602 const GLint *params)
6603{
6604 if (context->getClientMajorVersion() < 3)
6605 {
Jamie Madille0472f32018-11-27 16:32:45 -05006606 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006607 return false;
6608 }
6609 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6610}
6611
6612bool ValidateTexParameterIuivOES(Context *context,
6613 TextureType target,
6614 GLenum pname,
6615 const GLuint *params)
6616{
6617 if (context->getClientMajorVersion() < 3)
6618 {
Jamie Madille0472f32018-11-27 16:32:45 -05006619 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006620 return false;
6621 }
6622 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006623}
6624
6625bool ValidateUseProgram(Context *context, GLuint program)
6626{
6627 if (program != 0)
6628 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006629 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006630 if (!programObject)
6631 {
6632 // ES 3.1.0 section 7.3 page 72
6633 if (context->getShader(program))
6634 {
Jamie Madille0472f32018-11-27 16:32:45 -05006635 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006636 return false;
6637 }
6638 else
6639 {
Jamie Madille0472f32018-11-27 16:32:45 -05006640 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006641 return false;
6642 }
6643 }
6644 if (!programObject->isLinked())
6645 {
Jamie Madille0472f32018-11-27 16:32:45 -05006646 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006647 return false;
6648 }
6649 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006650 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006651 {
6652 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006653 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006654 return false;
6655 }
6656
6657 return true;
6658}
6659
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006660bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences)
6661{
6662 if (!context->getExtensions().fence)
6663 {
Jamie Madille0472f32018-11-27 16:32:45 -05006664 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006665 return false;
6666 }
6667
6668 if (n < 0)
6669 {
Jamie Madille0472f32018-11-27 16:32:45 -05006670 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006671 return false;
6672 }
6673
6674 return true;
6675}
6676
6677bool ValidateFinishFenceNV(Context *context, GLuint fence)
6678{
6679 if (!context->getExtensions().fence)
6680 {
Jamie Madille0472f32018-11-27 16:32:45 -05006681 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006682 return false;
6683 }
6684
6685 FenceNV *fenceObject = context->getFenceNV(fence);
6686
6687 if (fenceObject == nullptr)
6688 {
Jamie Madille0472f32018-11-27 16:32:45 -05006689 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006690 return false;
6691 }
6692
6693 if (!fenceObject->isSet())
6694 {
Jamie Madille0472f32018-11-27 16:32:45 -05006695 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006696 return false;
6697 }
6698
6699 return true;
6700}
6701
6702bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences)
6703{
6704 if (!context->getExtensions().fence)
6705 {
Jamie Madille0472f32018-11-27 16:32:45 -05006706 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006707 return false;
6708 }
6709
6710 if (n < 0)
6711 {
Jamie Madille0472f32018-11-27 16:32:45 -05006712 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006713 return false;
6714 }
6715
6716 return true;
6717}
6718
6719bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params)
6720{
6721 if (!context->getExtensions().fence)
6722 {
Jamie Madille0472f32018-11-27 16:32:45 -05006723 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006724 return false;
6725 }
6726
6727 FenceNV *fenceObject = context->getFenceNV(fence);
6728
6729 if (fenceObject == nullptr)
6730 {
Jamie Madille0472f32018-11-27 16:32:45 -05006731 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006732 return false;
6733 }
6734
6735 if (!fenceObject->isSet())
6736 {
Jamie Madille0472f32018-11-27 16:32:45 -05006737 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006738 return false;
6739 }
6740
6741 switch (pname)
6742 {
6743 case GL_FENCE_STATUS_NV:
6744 case GL_FENCE_CONDITION_NV:
6745 break;
6746
6747 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006748 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006749 return false;
6750 }
6751
6752 return true;
6753}
6754
6755bool ValidateGetGraphicsResetStatusEXT(Context *context)
6756{
6757 if (!context->getExtensions().robustness)
6758 {
Jamie Madille0472f32018-11-27 16:32:45 -05006759 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006760 return false;
6761 }
6762
6763 return true;
6764}
6765
6766bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
6767 GLuint shader,
6768 GLsizei bufsize,
6769 GLsizei *length,
6770 GLchar *source)
6771{
6772 if (!context->getExtensions().translatedShaderSource)
6773 {
Jamie Madille0472f32018-11-27 16:32:45 -05006774 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006775 return false;
6776 }
6777
6778 if (bufsize < 0)
6779 {
Jamie Madille0472f32018-11-27 16:32:45 -05006780 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006781 return false;
6782 }
6783
6784 Shader *shaderObject = context->getShader(shader);
6785
6786 if (!shaderObject)
6787 {
Jamie Madille0472f32018-11-27 16:32:45 -05006788 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006789 return false;
6790 }
6791
6792 return true;
6793}
6794
6795bool ValidateIsFenceNV(Context *context, GLuint fence)
6796{
6797 if (!context->getExtensions().fence)
6798 {
Jamie Madille0472f32018-11-27 16:32:45 -05006799 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006800 return false;
6801 }
6802
6803 return true;
6804}
6805
Jamie Madill007530e2017-12-28 14:27:04 -05006806bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition)
6807{
6808 if (!context->getExtensions().fence)
6809 {
Jamie Madille0472f32018-11-27 16:32:45 -05006810 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006811 return false;
6812 }
6813
6814 if (condition != GL_ALL_COMPLETED_NV)
6815 {
Jamie Madille0472f32018-11-27 16:32:45 -05006816 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05006817 return false;
6818 }
6819
6820 FenceNV *fenceObject = context->getFenceNV(fence);
6821
6822 if (fenceObject == nullptr)
6823 {
Jamie Madille0472f32018-11-27 16:32:45 -05006824 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006825 return false;
6826 }
6827
6828 return true;
6829}
6830
6831bool ValidateTestFenceNV(Context *context, GLuint fence)
6832{
6833 if (!context->getExtensions().fence)
6834 {
Jamie Madille0472f32018-11-27 16:32:45 -05006835 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006836 return false;
6837 }
6838
6839 FenceNV *fenceObject = context->getFenceNV(fence);
6840
6841 if (fenceObject == nullptr)
6842 {
Jamie Madille0472f32018-11-27 16:32:45 -05006843 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006844 return false;
6845 }
6846
6847 if (fenceObject->isSet() != GL_TRUE)
6848 {
Jamie Madille0472f32018-11-27 16:32:45 -05006849 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05006850 return false;
6851 }
6852
6853 return true;
6854}
6855
6856bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006857 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05006858 GLsizei levels,
6859 GLenum internalformat,
6860 GLsizei width,
6861 GLsizei height)
6862{
6863 if (!context->getExtensions().textureStorage)
6864 {
Jamie Madille0472f32018-11-27 16:32:45 -05006865 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006866 return false;
6867 }
6868
6869 if (context->getClientMajorVersion() < 3)
6870 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006871 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05006872 height);
6873 }
6874
6875 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006876 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05006877 1);
6878}
6879
6880bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
6881{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006882 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05006883 {
Jamie Madille0472f32018-11-27 16:32:45 -05006884 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006885 return false;
6886 }
6887
6888 if (index >= MAX_VERTEX_ATTRIBS)
6889 {
Jamie Madille0472f32018-11-27 16:32:45 -05006890 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05006891 return false;
6892 }
6893
6894 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
6895 {
6896 if (index == 0 && divisor != 0)
6897 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006898 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05006899
6900 // We also output an error message to the debugger window if tracing is active, so
6901 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006902 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05006903 return false;
6904 }
6905 }
6906
6907 return true;
6908}
6909
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006910bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
6911{
6912 if (!context->getExtensions().instancedArraysEXT)
6913 {
6914 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6915 return false;
6916 }
6917
6918 if (index >= MAX_VERTEX_ATTRIBS)
6919 {
6920 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
6921 return false;
6922 }
6923
6924 return true;
6925}
6926
Jamie Madill007530e2017-12-28 14:27:04 -05006927bool ValidateTexImage3DOES(Context *context,
6928 GLenum target,
6929 GLint level,
6930 GLenum internalformat,
6931 GLsizei width,
6932 GLsizei height,
6933 GLsizei depth,
6934 GLint border,
6935 GLenum format,
6936 GLenum type,
6937 const void *pixels)
6938{
6939 UNIMPLEMENTED(); // FIXME
6940 return false;
6941}
6942
6943bool ValidatePopGroupMarkerEXT(Context *context)
6944{
6945 if (!context->getExtensions().debugMarker)
6946 {
6947 // The debug marker calls should not set error state
6948 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05006949 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006950 return false;
6951 }
6952
6953 return true;
6954}
6955
Jamie Madillfa920eb2018-01-04 11:45:50 -05006956bool ValidateTexStorage1DEXT(Context *context,
6957 GLenum target,
6958 GLsizei levels,
6959 GLenum internalformat,
6960 GLsizei width)
6961{
6962 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05006963 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006964 return false;
6965}
6966
6967bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006968 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05006969 GLsizei levels,
6970 GLenum internalformat,
6971 GLsizei width,
6972 GLsizei height,
6973 GLsizei depth)
6974{
6975 if (!context->getExtensions().textureStorage)
6976 {
Jamie Madille0472f32018-11-27 16:32:45 -05006977 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006978 return false;
6979 }
6980
6981 if (context->getClientMajorVersion() < 3)
6982 {
Jamie Madille0472f32018-11-27 16:32:45 -05006983 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006984 return false;
6985 }
6986
6987 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
6988 depth);
6989}
6990
jchen1082af6202018-06-22 10:59:52 +08006991bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
6992{
6993 if (!context->getExtensions().parallelShaderCompile)
6994 {
Jamie Madille0472f32018-11-27 16:32:45 -05006995 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08006996 return false;
6997 }
6998 return true;
6999}
7000
Austin Eng1bf18ce2018-10-19 15:34:02 -07007001bool ValidateMultiDrawArraysANGLE(Context *context,
7002 PrimitiveMode mode,
7003 const GLint *firsts,
7004 const GLsizei *counts,
7005 GLsizei drawcount)
7006{
7007 if (!context->getExtensions().multiDraw)
7008 {
Jamie Madille0472f32018-11-27 16:32:45 -05007009 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007010 return false;
7011 }
7012 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7013 {
7014 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
7015 {
7016 return false;
7017 }
7018 }
7019 return true;
7020}
7021
7022bool ValidateMultiDrawElementsANGLE(Context *context,
7023 PrimitiveMode mode,
7024 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05007025 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08007026 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07007027 GLsizei drawcount)
7028{
7029 if (!context->getExtensions().multiDraw)
7030 {
Jamie Madille0472f32018-11-27 16:32:45 -05007031 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007032 return false;
7033 }
7034 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7035 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08007036 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07007037 {
7038 return false;
7039 }
7040 }
7041 return true;
7042}
7043
Jeff Gilbert465d6092019-01-02 16:21:18 -08007044bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked)
7045{
7046 if (!context->getExtensions().provokingVertex)
7047 {
7048 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7049 return false;
7050 }
7051
7052 switch (modePacked)
7053 {
7054 case ProvokingVertex::FirstVertexConvention:
7055 case ProvokingVertex::LastVertexConvention:
7056 break;
7057 default:
7058 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
7059 return false;
7060 }
7061
7062 return true;
7063}
7064
Jamie Madilla5410482019-01-31 19:55:55 -05007065void RecordBindTextureTypeError(Context *context, TextureType target)
7066{
7067 ASSERT(!context->getStateCache().isValidBindTextureType(target));
7068
7069 switch (target)
7070 {
7071 case TextureType::Rectangle:
7072 ASSERT(!context->getExtensions().textureRectangle);
7073 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
7074 break;
7075
7076 case TextureType::_3D:
7077 case TextureType::_2DArray:
7078 ASSERT(context->getClientMajorVersion() < 3);
7079 context->validationError(GL_INVALID_ENUM, kES3Required);
7080 break;
7081
7082 case TextureType::_2DMultisample:
7083 ASSERT(context->getClientVersion() < Version(3, 1) &&
7084 !context->getExtensions().textureMultisample);
7085 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
7086 break;
7087
7088 case TextureType::_2DMultisampleArray:
7089 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
7090 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
7091 break;
7092
7093 case TextureType::External:
7094 ASSERT(!context->getExtensions().eglImageExternal &&
7095 !context->getExtensions().eglStreamConsumerExternal);
7096 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
7097 break;
7098
7099 default:
7100 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
7101 }
7102}
7103
Jamie Madillc29968b2016-01-20 11:17:23 -05007104} // namespace gl