blob: b98de662fa3ae1954cf0ec8d97031a7e6312a879 [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}
Jamie Madillc29968b2016-01-20 11:17:23 -05001127} // anonymous namespace
1128
Geoff Langff5b2d52016-09-07 11:32:23 -04001129bool ValidateES2TexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001130 TextureTarget target,
Geoff Langff5b2d52016-09-07 11:32:23 -04001131 GLint level,
1132 GLenum internalformat,
1133 bool isCompressed,
1134 bool isSubImage,
1135 GLint xoffset,
1136 GLint yoffset,
1137 GLsizei width,
1138 GLsizei height,
1139 GLint border,
1140 GLenum format,
1141 GLenum type,
1142 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001143 const void *pixels)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001144{
Jamie Madill6f38f822014-06-06 17:12:20 -04001145 if (!ValidTexture2DDestinationTarget(context, target))
1146 {
Jamie Madille0472f32018-11-27 16:32:45 -05001147 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001148 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001149 }
1150
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001151 TextureType texType = TextureTargetToType(target);
1152 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001153 {
Jamie Madill610640f2018-11-21 17:28:41 -05001154 // Error already handled.
Geoff Langb1196682014-07-23 13:47:29 -04001155 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001156 }
1157
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001158 if (!ValidMipLevel(context, texType, level))
Brandon Jones6cad5662017-06-14 13:25:13 -07001159 {
Jamie Madille0472f32018-11-27 16:32:45 -05001160 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Brandon Jones6cad5662017-06-14 13:25:13 -07001161 return false;
1162 }
1163
1164 if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width ||
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001165 std::numeric_limits<GLsizei>::max() - yoffset < height)
1166 {
Jamie Madille0472f32018-11-27 16:32:45 -05001167 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Geoff Langb1196682014-07-23 13:47:29 -04001168 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001169 }
1170
Geoff Langaae65a42014-05-26 12:43:44 -04001171 const gl::Caps &caps = context->getCaps();
1172
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001173 switch (texType)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001174 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001175 case TextureType::_2D:
1176 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
1177 static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
1178 {
Jamie Madille0472f32018-11-27 16:32:45 -05001179 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001180 return false;
1181 }
1182 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001183
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001184 case TextureType::Rectangle:
1185 ASSERT(level == 0);
1186 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1187 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1188 {
Jamie Madille0472f32018-11-27 16:32:45 -05001189 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001190 return false;
1191 }
1192 if (isCompressed)
1193 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001194 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001195 return false;
1196 }
1197 break;
1198
1199 case TextureType::CubeMap:
1200 if (!isSubImage && width != height)
1201 {
Jamie Madille0472f32018-11-27 16:32:45 -05001202 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001203 return false;
1204 }
1205
1206 if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) ||
1207 static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level))
1208 {
Jamie Madille0472f32018-11-27 16:32:45 -05001209 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001210 return false;
1211 }
1212 break;
1213
1214 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001215 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langa9be0dc2014-12-17 12:34:40 -05001216 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001217 }
1218
Jamie Madillcfc73cc2019-04-08 16:26:51 -04001219 gl::Texture *texture = context->getTextureByType(texType);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001220 if (!texture)
1221 {
Jamie Madille0472f32018-11-27 16:32:45 -05001222 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Geoff Langb1196682014-07-23 13:47:29 -04001223 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001224 }
1225
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001226 // Verify zero border
1227 if (border != 0)
1228 {
Jamie Madille0472f32018-11-27 16:32:45 -05001229 context->validationError(GL_INVALID_VALUE, kInvalidBorder);
Geoff Langb1196682014-07-23 13:47:29 -04001230 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001231 }
1232
Tim Van Patten208af3e2019-03-19 09:15:55 -06001233 bool nonEqualFormatsAllowed = false;
1234
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001235 if (isCompressed)
1236 {
tmartino0ccd5ae2015-10-01 14:33:14 -04001237 GLenum actualInternalFormat =
Geoff Langca271392017-04-05 12:30:00 -04001238 isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat
1239 : internalformat;
Geoff Lange88e4542018-05-03 15:05:57 -04001240
1241 const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat);
1242
1243 if (!internalFormatInfo.compressed)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001244 {
Jamie Madille0472f32018-11-27 16:32:45 -05001245 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001246 return false;
1247 }
1248
1249 if (!internalFormatInfo.textureSupport(context->getClientVersion(),
1250 context->getExtensions()))
1251 {
Jamie Madille0472f32018-11-27 16:32:45 -05001252 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001253 return false;
tmartino0ccd5ae2015-10-01 14:33:14 -04001254 }
Geoff Lang966c9402017-04-18 12:38:27 -04001255
1256 if (isSubImage)
tmartino0ccd5ae2015-10-01 14:33:14 -04001257 {
Geoff Lange88e4542018-05-03 15:05:57 -04001258 // From the OES_compressed_ETC1_RGB8_texture spec:
1259 // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or
1260 // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format
1261 // ETC1_RGB8_OES.
1262 if (actualInternalFormat == GL_ETC1_RGB8_OES)
1263 {
Jamie Madille0472f32018-11-27 16:32:45 -05001264 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001265 return false;
1266 }
1267
Geoff Lang966c9402017-04-18 12:38:27 -04001268 if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width,
1269 height, texture->getWidth(target, level),
1270 texture->getHeight(target, level)))
1271 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001272 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001273 return false;
1274 }
1275
1276 if (format != actualInternalFormat)
1277 {
Jamie Madille0472f32018-11-27 16:32:45 -05001278 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Geoff Lang966c9402017-04-18 12:38:27 -04001279 return false;
1280 }
1281 }
1282 else
1283 {
1284 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height))
1285 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001286 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001287 return false;
1288 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001289 }
1290 }
1291 else
1292 {
1293 // validate <type> by itself (used as secondary key below)
1294 switch (type)
1295 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001296 case GL_UNSIGNED_BYTE:
1297 case GL_UNSIGNED_SHORT_5_6_5:
1298 case GL_UNSIGNED_SHORT_4_4_4_4:
1299 case GL_UNSIGNED_SHORT_5_5_5_1:
1300 case GL_UNSIGNED_SHORT:
1301 case GL_UNSIGNED_INT:
1302 case GL_UNSIGNED_INT_24_8_OES:
1303 case GL_HALF_FLOAT_OES:
1304 case GL_FLOAT:
1305 break;
1306 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001307 context->validationError(GL_INVALID_ENUM, kInvalidType);
He Yunchaoced53ae2016-11-29 15:00:51 +08001308 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001309 }
1310
1311 // validate <format> + <type> combinations
1312 // - invalid <format> -> sets INVALID_ENUM
1313 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
1314 switch (format)
1315 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001316 case GL_ALPHA:
1317 case GL_LUMINANCE:
1318 case GL_LUMINANCE_ALPHA:
1319 switch (type)
1320 {
1321 case GL_UNSIGNED_BYTE:
1322 case GL_FLOAT:
1323 case GL_HALF_FLOAT_OES:
1324 break;
1325 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001326 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001327 return false;
1328 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001329 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001330 case GL_RED:
1331 case GL_RG:
1332 if (!context->getExtensions().textureRG)
1333 {
Jamie Madille0472f32018-11-27 16:32:45 -05001334 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001335 return false;
1336 }
1337 switch (type)
1338 {
1339 case GL_UNSIGNED_BYTE:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001340 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001341 case GL_FLOAT:
1342 case GL_HALF_FLOAT_OES:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001343 if (!context->getExtensions().textureFloat)
1344 {
Jamie Madille0472f32018-11-27 16:32:45 -05001345 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001346 return false;
1347 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001348 break;
1349 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001350 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001351 return false;
1352 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001353 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001354 case GL_RGB:
1355 switch (type)
1356 {
1357 case GL_UNSIGNED_BYTE:
1358 case GL_UNSIGNED_SHORT_5_6_5:
1359 case GL_FLOAT:
1360 case GL_HALF_FLOAT_OES:
1361 break;
1362 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001363 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001364 return false;
1365 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001366 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001367 case GL_RGBA:
1368 switch (type)
1369 {
1370 case GL_UNSIGNED_BYTE:
1371 case GL_UNSIGNED_SHORT_4_4_4_4:
1372 case GL_UNSIGNED_SHORT_5_5_5_1:
1373 case GL_FLOAT:
1374 case GL_HALF_FLOAT_OES:
1375 break;
1376 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001377 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001378 return false;
1379 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001380 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001381 case GL_BGRA_EXT:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001382 if (!context->getExtensions().textureFormatBGRA8888)
1383 {
Jamie Madille0472f32018-11-27 16:32:45 -05001384 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001385 return false;
1386 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001387 switch (type)
1388 {
1389 case GL_UNSIGNED_BYTE:
1390 break;
1391 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001392 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001393 return false;
1394 }
1395 break;
1396 case GL_SRGB_EXT:
1397 case GL_SRGB_ALPHA_EXT:
1398 if (!context->getExtensions().sRGB)
1399 {
Jamie Madille0472f32018-11-27 16:32:45 -05001400 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001401 return false;
1402 }
1403 switch (type)
1404 {
1405 case GL_UNSIGNED_BYTE:
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 }
1411 break;
1412 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are
1413 // handled below
1414 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1415 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1416 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1417 break;
1418 case GL_DEPTH_COMPONENT:
1419 switch (type)
1420 {
1421 case GL_UNSIGNED_SHORT:
1422 case GL_UNSIGNED_INT:
1423 break;
1424 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001425 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001426 return false;
1427 }
1428 break;
1429 case GL_DEPTH_STENCIL_OES:
1430 switch (type)
1431 {
1432 case GL_UNSIGNED_INT_24_8_OES:
1433 break;
1434 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001435 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001436 return false;
1437 }
1438 break;
1439 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001440 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001441 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001442 }
1443
1444 switch (format)
1445 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001446 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1447 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1448 if (context->getExtensions().textureCompressionDXT1)
1449 {
Jamie Madille0472f32018-11-27 16:32:45 -05001450 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001451 return false;
1452 }
1453 else
1454 {
Jamie Madille0472f32018-11-27 16:32:45 -05001455 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001456 return false;
1457 }
1458 break;
1459 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1460 if (context->getExtensions().textureCompressionDXT3)
1461 {
Jamie Madille0472f32018-11-27 16:32:45 -05001462 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001463 return false;
1464 }
1465 else
1466 {
Jamie Madille0472f32018-11-27 16:32:45 -05001467 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001468 return false;
1469 }
1470 break;
1471 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1472 if (context->getExtensions().textureCompressionDXT5)
1473 {
Jamie Madille0472f32018-11-27 16:32:45 -05001474 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001475 return false;
1476 }
1477 else
1478 {
Jamie Madille0472f32018-11-27 16:32:45 -05001479 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001480 return false;
1481 }
1482 break;
1483 case GL_ETC1_RGB8_OES:
1484 if (context->getExtensions().compressedETC1RGB8Texture)
1485 {
Jamie Madille0472f32018-11-27 16:32:45 -05001486 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001487 return false;
1488 }
1489 else
1490 {
Jamie Madille0472f32018-11-27 16:32:45 -05001491 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001492 return false;
1493 }
1494 break;
1495 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001496 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1497 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1498 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1499 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001500 if (context->getExtensions().lossyETCDecode)
1501 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001502 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001503 return false;
1504 }
1505 else
1506 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001507 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001508 return false;
1509 }
1510 break;
1511 case GL_DEPTH_COMPONENT:
1512 case GL_DEPTH_STENCIL_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001513 if (!context->getExtensions().depthTextureANGLE &&
1514 !(context->getExtensions().packedDepthStencil &&
1515 context->getExtensions().depthTextureOES))
He Yunchaoced53ae2016-11-29 15:00:51 +08001516 {
Jamie Madille0472f32018-11-27 16:32:45 -05001517 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001518 return false;
1519 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001520 if (target != TextureTarget::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001521 {
Jamie Madille0472f32018-11-27 16:32:45 -05001522 context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001523 return false;
1524 }
1525 // OES_depth_texture supports loading depth data and multiple levels,
1526 // but ANGLE_depth_texture does not
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001527 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001528 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001529 if (pixels != nullptr)
1530 {
1531 context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
1532 return false;
1533 }
1534 if (level != 0)
1535 {
1536 context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
1537 return false;
1538 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001539 }
1540 break;
1541 default:
1542 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001543 }
1544
Geoff Lang6e898aa2017-06-02 11:17:26 -04001545 if (!isSubImage)
1546 {
1547 switch (internalformat)
1548 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001549 // Core ES 2.0 formats
1550 case GL_ALPHA:
1551 case GL_LUMINANCE:
1552 case GL_LUMINANCE_ALPHA:
1553 case GL_RGB:
1554 case GL_RGBA:
1555 break;
1556
Geoff Lang6e898aa2017-06-02 11:17:26 -04001557 case GL_RGBA32F:
1558 if (!context->getExtensions().colorBufferFloatRGBA)
1559 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001560 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001561 return false;
1562 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001563
1564 nonEqualFormatsAllowed = true;
1565
Geoff Lang6e898aa2017-06-02 11:17:26 -04001566 if (type != GL_FLOAT)
1567 {
Jamie Madille0472f32018-11-27 16:32:45 -05001568 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001569 return false;
1570 }
1571 if (format != GL_RGBA)
1572 {
Jamie Madille0472f32018-11-27 16:32:45 -05001573 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001574 return false;
1575 }
1576 break;
1577
1578 case GL_RGB32F:
1579 if (!context->getExtensions().colorBufferFloatRGB)
1580 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001581 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001582 return false;
1583 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001584
1585 nonEqualFormatsAllowed = true;
1586
Geoff Lang6e898aa2017-06-02 11:17:26 -04001587 if (type != GL_FLOAT)
1588 {
Jamie Madille0472f32018-11-27 16:32:45 -05001589 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001590 return false;
1591 }
1592 if (format != GL_RGB)
1593 {
Jamie Madille0472f32018-11-27 16:32:45 -05001594 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001595 return false;
1596 }
1597 break;
1598
Tim Van Patten208af3e2019-03-19 09:15:55 -06001599 case GL_BGRA_EXT:
1600 if (!context->getExtensions().textureFormatBGRA8888)
1601 {
1602 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1603 return false;
1604 }
Geoff Lang6e898aa2017-06-02 11:17:26 -04001605 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001606
1607 case GL_DEPTH_COMPONENT:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001608 if (!(context->getExtensions().depthTextureAny()))
1609 {
1610 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1611 return false;
1612 }
1613 break;
1614
Tim Van Patten208af3e2019-03-19 09:15:55 -06001615 case GL_DEPTH_STENCIL:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001616 if (!(context->getExtensions().depthTextureANGLE ||
1617 context->getExtensions().packedDepthStencil))
Tim Van Patten208af3e2019-03-19 09:15:55 -06001618 {
1619 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1620 return false;
1621 }
1622 break;
1623
1624 case GL_RED:
1625 case GL_RG:
1626 if (!context->getExtensions().textureRG)
1627 {
1628 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1629 return false;
1630 }
1631 break;
1632
1633 case GL_SRGB_EXT:
1634 case GL_SRGB_ALPHA_EXT:
1635 if (!context->getExtensions().sRGB)
1636 {
1637 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1638 return false;
1639 }
1640 break;
1641
1642 default:
1643 context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat);
1644 return false;
Geoff Lang6e898aa2017-06-02 11:17:26 -04001645 }
1646 }
1647
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001648 if (type == GL_FLOAT)
1649 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001650 if (!context->getExtensions().textureFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001651 {
Jamie Madille0472f32018-11-27 16:32:45 -05001652 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001653 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001654 }
1655 }
1656 else if (type == GL_HALF_FLOAT_OES)
1657 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001658 if (!context->getExtensions().textureHalfFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001659 {
Jamie Madille0472f32018-11-27 16:32:45 -05001660 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001661 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001662 }
1663 }
1664 }
1665
Tim Van Patten208af3e2019-03-19 09:15:55 -06001666 if (isSubImage)
Geoff Langff5b2d52016-09-07 11:32:23 -04001667 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001668 const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info;
1669 if (textureInternalFormat.internalFormat == GL_NONE)
1670 {
1671 context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel);
1672 return false;
1673 }
1674
Tim Van Patten5f388c22019-03-14 09:54:23 -06001675 if (format != textureInternalFormat.format)
1676 {
1677 context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch);
1678 return false;
1679 }
1680
1681 if (context->getExtensions().webglCompatibility)
Tim Van Patten208af3e2019-03-19 09:15:55 -06001682 {
1683 if (GetInternalFormatInfo(format, type).sizedInternalFormat !=
1684 textureInternalFormat.sizedInternalFormat)
1685 {
Tim Van Patten5f388c22019-03-14 09:54:23 -06001686 context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch);
Tim Van Patten208af3e2019-03-19 09:15:55 -06001687 return false;
1688 }
1689 }
1690
1691 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
1692 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level))
1693 {
1694 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
1695 return false;
1696 }
1697
1698 if (width > 0 && height > 0 && pixels == nullptr &&
1699 context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr)
1700 {
1701 context->validationError(GL_INVALID_VALUE, kPixelDataNull);
1702 return false;
1703 }
1704 }
1705 else
1706 {
1707 if (texture->getImmutableFormat())
1708 {
1709 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
1710 return false;
1711 }
1712 }
1713
1714 // From GL_CHROMIUM_color_buffer_float_rgb[a]:
1715 // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
1716 // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
1717 // internalformat parameter and format parameter of TexImage2D must match is lifted for this
1718 // case.
1719 if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
1720 {
1721 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Langff5b2d52016-09-07 11:32:23 -04001722 return false;
1723 }
1724
Tim Van Patten208af3e2019-03-19 09:15:55 -06001725 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
1726 return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels,
1727 imageSize);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001728}
1729
He Yunchaoced53ae2016-11-29 15:00:51 +08001730bool ValidateES2TexStorageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001731 TextureType target,
He Yunchaoced53ae2016-11-29 15:00:51 +08001732 GLsizei levels,
1733 GLenum internalformat,
1734 GLsizei width,
1735 GLsizei height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001736{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001737 if (target != TextureType::_2D && target != TextureType::CubeMap &&
1738 target != TextureType::Rectangle)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001739 {
Jamie Madille0472f32018-11-27 16:32:45 -05001740 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001741 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001742 }
1743
1744 if (width < 1 || height < 1 || levels < 1)
1745 {
Jamie Madille0472f32018-11-27 16:32:45 -05001746 context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall);
Geoff Langb1196682014-07-23 13:47:29 -04001747 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001748 }
1749
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001750 if (target == TextureType::CubeMap && width != height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001751 {
Jamie Madille0472f32018-11-27 16:32:45 -05001752 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Langb1196682014-07-23 13:47:29 -04001753 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001754 }
1755
1756 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1757 {
Jamie Madille0472f32018-11-27 16:32:45 -05001758 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
Geoff Langb1196682014-07-23 13:47:29 -04001759 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001760 }
1761
Geoff Langca271392017-04-05 12:30:00 -04001762 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Lang5d601382014-07-22 15:14:06 -04001763 if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001764 {
Jamie Madille0472f32018-11-27 16:32:45 -05001765 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Langb1196682014-07-23 13:47:29 -04001766 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001767 }
1768
Geoff Langaae65a42014-05-26 12:43:44 -04001769 const gl::Caps &caps = context->getCaps();
1770
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001771 switch (target)
1772 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001773 case TextureType::_2D:
He Yunchaoced53ae2016-11-29 15:00:51 +08001774 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
1775 static_cast<GLuint>(height) > caps.max2DTextureSize)
1776 {
Jamie Madille0472f32018-11-27 16:32:45 -05001777 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001778 return false;
1779 }
1780 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001781 case TextureType::Rectangle:
Jamie Madill610640f2018-11-21 17:28:41 -05001782 if (levels != 1)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001783 {
Jamie Madille0472f32018-11-27 16:32:45 -05001784 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madill610640f2018-11-21 17:28:41 -05001785 return false;
1786 }
1787
1788 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1789 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1790 {
Jamie Madille0472f32018-11-27 16:32:45 -05001791 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001792 return false;
1793 }
1794 if (formatInfo.compressed)
1795 {
Jamie Madille0472f32018-11-27 16:32:45 -05001796 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001797 return false;
1798 }
1799 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001800 case TextureType::CubeMap:
He Yunchaoced53ae2016-11-29 15:00:51 +08001801 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize ||
1802 static_cast<GLuint>(height) > caps.maxCubeMapTextureSize)
1803 {
Jamie Madille0472f32018-11-27 16:32:45 -05001804 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001805 return false;
1806 }
1807 break;
1808 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001809 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001810 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001811 }
1812
Geoff Langc0b9ef42014-07-02 10:02:37 -04001813 if (levels != 1 && !context->getExtensions().textureNPOT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001814 {
1815 if (!gl::isPow2(width) || !gl::isPow2(height))
1816 {
Jamie Madille0472f32018-11-27 16:32:45 -05001817 context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2);
Geoff Langb1196682014-07-23 13:47:29 -04001818 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001819 }
1820 }
1821
1822 switch (internalformat)
1823 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001824 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1825 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1826 if (!context->getExtensions().textureCompressionDXT1)
1827 {
Jamie Madille0472f32018-11-27 16:32:45 -05001828 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001829 return false;
1830 }
1831 break;
1832 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1833 if (!context->getExtensions().textureCompressionDXT3)
1834 {
Jamie Madille0472f32018-11-27 16:32:45 -05001835 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001836 return false;
1837 }
1838 break;
1839 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1840 if (!context->getExtensions().textureCompressionDXT5)
1841 {
Jamie Madille0472f32018-11-27 16:32:45 -05001842 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001843 return false;
1844 }
1845 break;
1846 case GL_ETC1_RGB8_OES:
1847 if (!context->getExtensions().compressedETC1RGB8Texture)
1848 {
Jamie Madille0472f32018-11-27 16:32:45 -05001849 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001850 return false;
1851 }
1852 break;
1853 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001854 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1855 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1856 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1857 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001858 if (!context->getExtensions().lossyETCDecode)
1859 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001860 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001861 return false;
1862 }
1863 break;
1864 case GL_RGBA32F_EXT:
1865 case GL_RGB32F_EXT:
1866 case GL_ALPHA32F_EXT:
1867 case GL_LUMINANCE32F_EXT:
1868 case GL_LUMINANCE_ALPHA32F_EXT:
1869 if (!context->getExtensions().textureFloat)
1870 {
Jamie Madille0472f32018-11-27 16:32:45 -05001871 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001872 return false;
1873 }
1874 break;
1875 case GL_RGBA16F_EXT:
1876 case GL_RGB16F_EXT:
1877 case GL_ALPHA16F_EXT:
1878 case GL_LUMINANCE16F_EXT:
1879 case GL_LUMINANCE_ALPHA16F_EXT:
1880 if (!context->getExtensions().textureHalfFloat)
1881 {
Jamie Madille0472f32018-11-27 16:32:45 -05001882 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001883 return false;
1884 }
1885 break;
1886 case GL_R8_EXT:
1887 case GL_RG8_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001888 if (!context->getExtensions().textureRG)
1889 {
Jamie Madille0472f32018-11-27 16:32:45 -05001890 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001891 return false;
1892 }
1893 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001894 case GL_R16F_EXT:
1895 case GL_RG16F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001896 if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat)
1897 {
Jamie Madille0472f32018-11-27 16:32:45 -05001898 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001899 return false;
1900 }
1901 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001902 case GL_R32F_EXT:
1903 case GL_RG32F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001904 if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat)
He Yunchaoced53ae2016-11-29 15:00:51 +08001905 {
Jamie Madille0472f32018-11-27 16:32:45 -05001906 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001907 return false;
1908 }
1909 break;
1910 case GL_DEPTH_COMPONENT16:
1911 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001912 if (!(context->getExtensions().depthTextureAny()))
He Yunchaoced53ae2016-11-29 15:00:51 +08001913 {
Jamie Madille0472f32018-11-27 16:32:45 -05001914 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001915 return false;
1916 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001917 if (target != TextureType::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001918 {
Jamie Madille0472f32018-11-27 16:32:45 -05001919 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001920 return false;
1921 }
1922 // ANGLE_depth_texture only supports 1-level textures
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001923 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001924 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001925 if (levels != 1)
1926 {
1927 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1928 return false;
1929 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001930 }
1931 break;
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001932 case GL_DEPTH24_STENCIL8_OES:
1933 if (!(context->getExtensions().depthTextureANGLE ||
1934 (context->getExtensions().packedDepthStencil &&
1935 context->getExtensions().textureStorage)))
1936 {
1937 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1938 return false;
1939 }
1940 if (target != TextureType::_2D)
1941 {
1942 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
1943 return false;
1944 }
1945 if (!context->getExtensions().packedDepthStencil)
1946 {
1947 // ANGLE_depth_texture only supports 1-level textures
1948 if (levels != 1)
1949 {
1950 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1951 return false;
1952 }
1953 }
1954 break;
1955
He Yunchaoced53ae2016-11-29 15:00:51 +08001956 default:
1957 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001958 }
1959
Jamie Madillcfc73cc2019-04-08 16:26:51 -04001960 gl::Texture *texture = context->getTextureByType(target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001961 if (!texture || texture->id() == 0)
1962 {
Jamie Madille0472f32018-11-27 16:32:45 -05001963 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
Geoff Langb1196682014-07-23 13:47:29 -04001964 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001965 }
1966
Geoff Lang69cce582015-09-17 13:20:36 -04001967 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001968 {
Jamie Madille0472f32018-11-27 16:32:45 -05001969 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
Geoff Langb1196682014-07-23 13:47:29 -04001970 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001971 }
1972
1973 return true;
1974}
1975
He Yunchaoced53ae2016-11-29 15:00:51 +08001976bool ValidateDiscardFramebufferEXT(Context *context,
1977 GLenum target,
1978 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07001979 const GLenum *attachments)
1980{
Jamie Madillc29968b2016-01-20 11:17:23 -05001981 if (!context->getExtensions().discardFramebuffer)
1982 {
Jamie Madille0472f32018-11-27 16:32:45 -05001983 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05001984 return false;
1985 }
1986
Austin Kinross08332632015-05-05 13:35:47 -07001987 bool defaultFramebuffer = false;
1988
1989 switch (target)
1990 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001991 case GL_FRAMEBUFFER:
1992 defaultFramebuffer =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001993 (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0);
He Yunchaoced53ae2016-11-29 15:00:51 +08001994 break;
1995 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001996 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001997 return false;
Austin Kinross08332632015-05-05 13:35:47 -07001998 }
1999
He Yunchaoced53ae2016-11-29 15:00:51 +08002000 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
2001 defaultFramebuffer);
Austin Kinross08332632015-05-05 13:35:47 -07002002}
2003
Austin Kinrossbc781f32015-10-26 09:27:38 -07002004bool ValidateBindVertexArrayOES(Context *context, GLuint array)
2005{
2006 if (!context->getExtensions().vertexArrayObject)
2007 {
Jamie Madille0472f32018-11-27 16:32:45 -05002008 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002009 return false;
2010 }
2011
2012 return ValidateBindVertexArrayBase(context, array);
2013}
2014
Jamie Madilld7576732017-08-26 18:49:50 -04002015bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002016{
2017 if (!context->getExtensions().vertexArrayObject)
2018 {
Jamie Madille0472f32018-11-27 16:32:45 -05002019 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002020 return false;
2021 }
2022
Olli Etuaho41997e72016-03-10 13:38:39 +02002023 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002024}
2025
Jamie Madilld7576732017-08-26 18:49:50 -04002026bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002027{
2028 if (!context->getExtensions().vertexArrayObject)
2029 {
Jamie Madille0472f32018-11-27 16:32:45 -05002030 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002031 return false;
2032 }
2033
Olli Etuaho41997e72016-03-10 13:38:39 +02002034 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002035}
2036
Jamie Madilld7576732017-08-26 18:49:50 -04002037bool ValidateIsVertexArrayOES(Context *context, GLuint array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002038{
2039 if (!context->getExtensions().vertexArrayObject)
2040 {
Jamie Madille0472f32018-11-27 16:32:45 -05002041 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002042 return false;
2043 }
2044
2045 return true;
2046}
Geoff Langc5629752015-12-07 16:29:04 -05002047
2048bool ValidateProgramBinaryOES(Context *context,
2049 GLuint program,
2050 GLenum binaryFormat,
2051 const void *binary,
2052 GLint length)
2053{
2054 if (!context->getExtensions().getProgramBinary)
2055 {
Jamie Madille0472f32018-11-27 16:32:45 -05002056 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002057 return false;
2058 }
2059
2060 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
2061}
2062
2063bool ValidateGetProgramBinaryOES(Context *context,
2064 GLuint program,
2065 GLsizei bufSize,
2066 GLsizei *length,
2067 GLenum *binaryFormat,
2068 void *binary)
2069{
2070 if (!context->getExtensions().getProgramBinary)
2071 {
Jamie Madille0472f32018-11-27 16:32:45 -05002072 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002073 return false;
2074 }
2075
2076 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
2077}
Geoff Lange102fee2015-12-10 11:23:30 -05002078
Geoff Lang70d0f492015-12-10 17:45:46 -05002079static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication)
2080{
2081 switch (source)
2082 {
2083 case GL_DEBUG_SOURCE_API:
2084 case GL_DEBUG_SOURCE_SHADER_COMPILER:
2085 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
2086 case GL_DEBUG_SOURCE_OTHER:
2087 // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted
2088 return !mustBeThirdPartyOrApplication;
2089
2090 case GL_DEBUG_SOURCE_THIRD_PARTY:
2091 case GL_DEBUG_SOURCE_APPLICATION:
2092 return true;
2093
2094 default:
2095 return false;
2096 }
2097}
2098
2099static bool ValidDebugType(GLenum type)
2100{
2101 switch (type)
2102 {
2103 case GL_DEBUG_TYPE_ERROR:
2104 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
2105 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
2106 case GL_DEBUG_TYPE_PERFORMANCE:
2107 case GL_DEBUG_TYPE_PORTABILITY:
2108 case GL_DEBUG_TYPE_OTHER:
2109 case GL_DEBUG_TYPE_MARKER:
2110 case GL_DEBUG_TYPE_PUSH_GROUP:
2111 case GL_DEBUG_TYPE_POP_GROUP:
2112 return true;
2113
2114 default:
2115 return false;
2116 }
2117}
2118
2119static bool ValidDebugSeverity(GLenum severity)
2120{
2121 switch (severity)
2122 {
2123 case GL_DEBUG_SEVERITY_HIGH:
2124 case GL_DEBUG_SEVERITY_MEDIUM:
2125 case GL_DEBUG_SEVERITY_LOW:
2126 case GL_DEBUG_SEVERITY_NOTIFICATION:
2127 return true;
2128
2129 default:
2130 return false;
2131 }
2132}
2133
Geoff Lange102fee2015-12-10 11:23:30 -05002134bool ValidateDebugMessageControlKHR(Context *context,
2135 GLenum source,
2136 GLenum type,
2137 GLenum severity,
2138 GLsizei count,
2139 const GLuint *ids,
2140 GLboolean enabled)
2141{
2142 if (!context->getExtensions().debug)
2143 {
Jamie Madille0472f32018-11-27 16:32:45 -05002144 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002145 return false;
2146 }
2147
Geoff Lang70d0f492015-12-10 17:45:46 -05002148 if (!ValidDebugSource(source, false) && source != GL_DONT_CARE)
2149 {
Jamie Madille0472f32018-11-27 16:32:45 -05002150 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002151 return false;
2152 }
2153
2154 if (!ValidDebugType(type) && type != GL_DONT_CARE)
2155 {
Jamie Madille0472f32018-11-27 16:32:45 -05002156 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002157 return false;
2158 }
2159
2160 if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE)
2161 {
Jamie Madille0472f32018-11-27 16:32:45 -05002162 context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002163 return false;
2164 }
2165
2166 if (count > 0)
2167 {
2168 if (source == GL_DONT_CARE || type == GL_DONT_CARE)
2169 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002170 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002171 return false;
2172 }
2173
2174 if (severity != GL_DONT_CARE)
2175 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002176 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002177 return false;
2178 }
2179 }
2180
Geoff Lange102fee2015-12-10 11:23:30 -05002181 return true;
2182}
2183
2184bool ValidateDebugMessageInsertKHR(Context *context,
2185 GLenum source,
2186 GLenum type,
2187 GLuint id,
2188 GLenum severity,
2189 GLsizei length,
2190 const GLchar *buf)
2191{
2192 if (!context->getExtensions().debug)
2193 {
Jamie Madille0472f32018-11-27 16:32:45 -05002194 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002195 return false;
2196 }
2197
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002198 if (!context->getState().getDebug().isOutputEnabled())
Geoff Lang70d0f492015-12-10 17:45:46 -05002199 {
2200 // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do
2201 // not generate an error.
2202 return false;
2203 }
2204
2205 if (!ValidDebugSeverity(severity))
2206 {
Jamie Madille0472f32018-11-27 16:32:45 -05002207 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002208 return false;
2209 }
2210
2211 if (!ValidDebugType(type))
2212 {
Jamie Madille0472f32018-11-27 16:32:45 -05002213 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002214 return false;
2215 }
2216
2217 if (!ValidDebugSource(source, true))
2218 {
Jamie Madille0472f32018-11-27 16:32:45 -05002219 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002220 return false;
2221 }
2222
2223 size_t messageLength = (length < 0) ? strlen(buf) : length;
2224 if (messageLength > context->getExtensions().maxDebugMessageLength)
2225 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002226 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002227 return false;
2228 }
2229
Geoff Lange102fee2015-12-10 11:23:30 -05002230 return true;
2231}
2232
2233bool ValidateDebugMessageCallbackKHR(Context *context,
2234 GLDEBUGPROCKHR callback,
2235 const void *userParam)
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
Geoff Lange102fee2015-12-10 11:23:30 -05002243 return true;
2244}
2245
2246bool ValidateGetDebugMessageLogKHR(Context *context,
2247 GLuint count,
2248 GLsizei bufSize,
2249 GLenum *sources,
2250 GLenum *types,
2251 GLuint *ids,
2252 GLenum *severities,
2253 GLsizei *lengths,
2254 GLchar *messageLog)
2255{
2256 if (!context->getExtensions().debug)
2257 {
Jamie Madille0472f32018-11-27 16:32:45 -05002258 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002259 return false;
2260 }
2261
Geoff Lang70d0f492015-12-10 17:45:46 -05002262 if (bufSize < 0 && messageLog != nullptr)
2263 {
Jamie Madille0472f32018-11-27 16:32:45 -05002264 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002265 return false;
2266 }
2267
Geoff Lange102fee2015-12-10 11:23:30 -05002268 return true;
2269}
2270
2271bool ValidatePushDebugGroupKHR(Context *context,
2272 GLenum source,
2273 GLuint id,
2274 GLsizei length,
2275 const GLchar *message)
2276{
2277 if (!context->getExtensions().debug)
2278 {
Jamie Madille0472f32018-11-27 16:32:45 -05002279 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002280 return false;
2281 }
2282
Geoff Lang70d0f492015-12-10 17:45:46 -05002283 if (!ValidDebugSource(source, true))
2284 {
Jamie Madille0472f32018-11-27 16:32:45 -05002285 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002286 return false;
2287 }
2288
2289 size_t messageLength = (length < 0) ? strlen(message) : length;
2290 if (messageLength > context->getExtensions().maxDebugMessageLength)
2291 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002292 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002293 return false;
2294 }
2295
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002296 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002297 if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth)
2298 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002299 context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth);
Geoff Lang70d0f492015-12-10 17:45:46 -05002300 return false;
2301 }
2302
Geoff Lange102fee2015-12-10 11:23:30 -05002303 return true;
2304}
2305
2306bool ValidatePopDebugGroupKHR(Context *context)
2307{
2308 if (!context->getExtensions().debug)
2309 {
Jamie Madille0472f32018-11-27 16:32:45 -05002310 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002311 return false;
2312 }
2313
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002314 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002315 if (currentStackSize <= 1)
2316 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002317 context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup);
Geoff Lang70d0f492015-12-10 17:45:46 -05002318 return false;
2319 }
2320
2321 return true;
2322}
2323
2324static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name)
2325{
2326 switch (identifier)
2327 {
2328 case GL_BUFFER:
2329 if (context->getBuffer(name) == nullptr)
2330 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002331 context->validationError(GL_INVALID_VALUE, kInvalidBufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002332 return false;
2333 }
2334 return true;
2335
2336 case GL_SHADER:
2337 if (context->getShader(name) == nullptr)
2338 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002339 context->validationError(GL_INVALID_VALUE, kInvalidShaderName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002340 return false;
2341 }
2342 return true;
2343
2344 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002345 if (context->getProgramNoResolveLink(name) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002346 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002347 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002348 return false;
2349 }
2350 return true;
2351
2352 case GL_VERTEX_ARRAY:
2353 if (context->getVertexArray(name) == nullptr)
2354 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002355 context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002356 return false;
2357 }
2358 return true;
2359
2360 case GL_QUERY:
2361 if (context->getQuery(name) == nullptr)
2362 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002363 context->validationError(GL_INVALID_VALUE, kInvalidQueryName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002364 return false;
2365 }
2366 return true;
2367
2368 case GL_TRANSFORM_FEEDBACK:
2369 if (context->getTransformFeedback(name) == nullptr)
2370 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002371 context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002372 return false;
2373 }
2374 return true;
2375
2376 case GL_SAMPLER:
2377 if (context->getSampler(name) == nullptr)
2378 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002379 context->validationError(GL_INVALID_VALUE, kInvalidSamplerName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002380 return false;
2381 }
2382 return true;
2383
2384 case GL_TEXTURE:
2385 if (context->getTexture(name) == nullptr)
2386 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002387 context->validationError(GL_INVALID_VALUE, kInvalidTextureName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002388 return false;
2389 }
2390 return true;
2391
2392 case GL_RENDERBUFFER:
2393 if (context->getRenderbuffer(name) == nullptr)
2394 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002395 context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002396 return false;
2397 }
2398 return true;
2399
2400 case GL_FRAMEBUFFER:
2401 if (context->getFramebuffer(name) == nullptr)
2402 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002403 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002404 return false;
2405 }
2406 return true;
2407
2408 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05002409 context->validationError(GL_INVALID_ENUM, kInvalidIndentifier);
Geoff Lang70d0f492015-12-10 17:45:46 -05002410 return false;
2411 }
Geoff Lange102fee2015-12-10 11:23:30 -05002412}
2413
Martin Radev9d901792016-07-15 15:58:58 +03002414static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label)
2415{
2416 size_t labelLength = 0;
2417
2418 if (length < 0)
2419 {
2420 if (label != nullptr)
2421 {
2422 labelLength = strlen(label);
2423 }
2424 }
2425 else
2426 {
2427 labelLength = static_cast<size_t>(length);
2428 }
2429
2430 if (labelLength > context->getExtensions().maxLabelLength)
2431 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002432 context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength);
Martin Radev9d901792016-07-15 15:58:58 +03002433 return false;
2434 }
2435
2436 return true;
2437}
2438
Geoff Lange102fee2015-12-10 11:23:30 -05002439bool ValidateObjectLabelKHR(Context *context,
2440 GLenum identifier,
2441 GLuint name,
2442 GLsizei length,
2443 const GLchar *label)
2444{
2445 if (!context->getExtensions().debug)
2446 {
Jamie Madille0472f32018-11-27 16:32:45 -05002447 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002448 return false;
2449 }
2450
Geoff Lang70d0f492015-12-10 17:45:46 -05002451 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2452 {
2453 return false;
2454 }
2455
Martin Radev9d901792016-07-15 15:58:58 +03002456 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002457 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002458 return false;
2459 }
2460
Geoff Lange102fee2015-12-10 11:23:30 -05002461 return true;
2462}
2463
2464bool ValidateGetObjectLabelKHR(Context *context,
2465 GLenum identifier,
2466 GLuint name,
2467 GLsizei bufSize,
2468 GLsizei *length,
2469 GLchar *label)
2470{
2471 if (!context->getExtensions().debug)
2472 {
Jamie Madille0472f32018-11-27 16:32:45 -05002473 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002474 return false;
2475 }
2476
Geoff Lang70d0f492015-12-10 17:45:46 -05002477 if (bufSize < 0)
2478 {
Jamie Madille0472f32018-11-27 16:32:45 -05002479 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002480 return false;
2481 }
2482
2483 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2484 {
2485 return false;
2486 }
2487
Martin Radev9d901792016-07-15 15:58:58 +03002488 return true;
Geoff Lang70d0f492015-12-10 17:45:46 -05002489}
2490
2491static bool ValidateObjectPtrName(Context *context, const void *ptr)
2492{
Jamie Madill70b5bb02017-08-28 13:32:37 -04002493 if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002494 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002495 context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer);
Geoff Lang70d0f492015-12-10 17:45:46 -05002496 return false;
2497 }
2498
Geoff Lange102fee2015-12-10 11:23:30 -05002499 return true;
2500}
2501
2502bool ValidateObjectPtrLabelKHR(Context *context,
2503 const void *ptr,
2504 GLsizei length,
2505 const GLchar *label)
2506{
2507 if (!context->getExtensions().debug)
2508 {
Jamie Madille0472f32018-11-27 16:32:45 -05002509 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002510 return false;
2511 }
2512
Geoff Lang70d0f492015-12-10 17:45:46 -05002513 if (!ValidateObjectPtrName(context, ptr))
2514 {
2515 return false;
2516 }
2517
Martin Radev9d901792016-07-15 15:58:58 +03002518 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002519 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002520 return false;
2521 }
2522
Geoff Lange102fee2015-12-10 11:23:30 -05002523 return true;
2524}
2525
2526bool ValidateGetObjectPtrLabelKHR(Context *context,
2527 const void *ptr,
2528 GLsizei bufSize,
2529 GLsizei *length,
2530 GLchar *label)
2531{
2532 if (!context->getExtensions().debug)
2533 {
Jamie Madille0472f32018-11-27 16:32:45 -05002534 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002535 return false;
2536 }
2537
Geoff Lang70d0f492015-12-10 17:45:46 -05002538 if (bufSize < 0)
2539 {
Jamie Madille0472f32018-11-27 16:32:45 -05002540 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002541 return false;
2542 }
2543
2544 if (!ValidateObjectPtrName(context, ptr))
2545 {
2546 return false;
2547 }
2548
Martin Radev9d901792016-07-15 15:58:58 +03002549 return true;
Geoff Lange102fee2015-12-10 11:23:30 -05002550}
2551
2552bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params)
2553{
2554 if (!context->getExtensions().debug)
2555 {
Jamie Madille0472f32018-11-27 16:32:45 -05002556 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002557 return false;
2558 }
2559
Geoff Lang70d0f492015-12-10 17:45:46 -05002560 // TODO: represent this in Context::getQueryParameterInfo.
2561 switch (pname)
2562 {
2563 case GL_DEBUG_CALLBACK_FUNCTION:
2564 case GL_DEBUG_CALLBACK_USER_PARAM:
2565 break;
2566
2567 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002568 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang70d0f492015-12-10 17:45:46 -05002569 return false;
2570 }
2571
Geoff Lange102fee2015-12-10 11:23:30 -05002572 return true;
2573}
Jamie Madillc29968b2016-01-20 11:17:23 -05002574
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002575bool ValidateGetPointervRobustANGLERobustANGLE(Context *context,
2576 GLenum pname,
2577 GLsizei bufSize,
2578 GLsizei *length,
2579 void **params)
2580{
2581 UNIMPLEMENTED();
2582 return false;
2583}
2584
Jamie Madillc29968b2016-01-20 11:17:23 -05002585bool ValidateBlitFramebufferANGLE(Context *context,
2586 GLint srcX0,
2587 GLint srcY0,
2588 GLint srcX1,
2589 GLint srcY1,
2590 GLint dstX0,
2591 GLint dstY0,
2592 GLint dstX1,
2593 GLint dstY1,
2594 GLbitfield mask,
2595 GLenum filter)
2596{
2597 if (!context->getExtensions().framebufferBlit)
2598 {
Jamie Madille0472f32018-11-27 16:32:45 -05002599 context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable);
Jamie Madillc29968b2016-01-20 11:17:23 -05002600 return false;
2601 }
2602
2603 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
2604 {
2605 // TODO(jmadill): Determine if this should be available on other implementations.
Jamie Madille0472f32018-11-27 16:32:45 -05002606 context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip);
Jamie Madillc29968b2016-01-20 11:17:23 -05002607 return false;
2608 }
2609
2610 if (filter == GL_LINEAR)
2611 {
Jamie Madille0472f32018-11-27 16:32:45 -05002612 context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear);
Jamie Madillc29968b2016-01-20 11:17:23 -05002613 return false;
2614 }
2615
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002616 Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
2617 Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002618
2619 if (mask & GL_COLOR_BUFFER_BIT)
2620 {
2621 const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer();
2622 const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer();
2623
2624 if (readColorAttachment && drawColorAttachment)
2625 {
2626 if (!(readColorAttachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002627 readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002628 readColorAttachment->type() != GL_RENDERBUFFER &&
2629 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2630 {
Jamie Madill610640f2018-11-21 17:28:41 -05002631 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002632 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002633 return false;
2634 }
2635
Geoff Langa15472a2015-08-11 11:48:03 -04002636 for (size_t drawbufferIdx = 0;
2637 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002638 {
Geoff Langa15472a2015-08-11 11:48:03 -04002639 const FramebufferAttachment *attachment =
2640 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2641 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002642 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002643 if (!(attachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002644 attachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002645 attachment->type() != GL_RENDERBUFFER &&
2646 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2647 {
Jamie Madill610640f2018-11-21 17:28:41 -05002648 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002649 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002650 return false;
2651 }
2652
2653 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002654 if (!Format::EquivalentForBlit(attachment->getFormat(),
2655 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002656 {
Jamie Madill610640f2018-11-21 17:28:41 -05002657 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002658 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002659 return false;
2660 }
2661 }
2662 }
2663
Jamie Madill427064d2018-04-13 16:20:34 -04002664 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002665 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002666 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2667 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2668 {
Jamie Madill610640f2018-11-21 17:28:41 -05002669 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002670 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002671 return false;
2672 }
2673 }
2674 }
2675
2676 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2677 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2678 for (size_t i = 0; i < 2; i++)
2679 {
2680 if (mask & masks[i])
2681 {
2682 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002683 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002684 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002685 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002686
2687 if (readBuffer && drawBuffer)
2688 {
2689 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2690 dstX0, dstY0, dstX1, dstY1))
2691 {
2692 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002693 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002694 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002695 return false;
2696 }
2697
2698 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2699 {
Jamie Madill610640f2018-11-21 17:28:41 -05002700 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002701 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002702 return false;
2703 }
2704 }
2705 }
2706 }
2707
2708 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2709 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002710}
Jamie Madillc29968b2016-01-20 11:17:23 -05002711
Jamie Madill5b772312018-03-08 20:28:32 -05002712bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002713{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002714 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002715 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002716
Jamie Madill427064d2018-04-13 16:20:34 -04002717 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002718 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002719 return false;
2720 }
2721
2722 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2723 {
Jamie Madille0472f32018-11-27 16:32:45 -05002724 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002725 return false;
2726 }
2727
Olli Etuaho94c91a92018-07-19 15:10:24 +03002728 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002729 {
2730 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2731 GL_SIGNED_NORMALIZED};
2732
Corentin Wallez59c41592017-07-11 13:19:54 -04002733 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002734 drawBufferIdx++)
2735 {
2736 if (!ValidateWebGLFramebufferAttachmentClearType(
2737 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2738 {
2739 return false;
2740 }
2741 }
2742 }
2743
Mingyu Huebab6702019-04-19 14:36:45 -07002744 if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery)
Olli Etuaho94c91a92018-07-19 15:10:24 +03002745 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002746 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002747 Framebuffer *framebuffer = state.getDrawFramebuffer();
2748 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2749 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002750 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002751 return false;
2752 }
2753 }
2754
Jamie Madillc29968b2016-01-20 11:17:23 -05002755 return true;
2756}
2757
Jamie Madill5b772312018-03-08 20:28:32 -05002758bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002759{
2760 if (!context->getExtensions().drawBuffers)
2761 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002762 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002763 return false;
2764 }
2765
2766 return ValidateDrawBuffersBase(context, n, bufs);
2767}
2768
Jamie Madill73a84962016-02-12 09:27:23 -05002769bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002770 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002771 GLint level,
2772 GLint internalformat,
2773 GLsizei width,
2774 GLsizei height,
2775 GLint border,
2776 GLenum format,
2777 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002778 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002779{
Martin Radev1be913c2016-07-11 17:59:16 +03002780 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002781 {
2782 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002783 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002784 }
2785
Martin Radev1be913c2016-07-11 17:59:16 +03002786 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002787 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002788 0, 0, width, height, 1, border, format, type, -1,
2789 pixels);
2790}
2791
Brandon Jones416aaf92018-04-10 08:10:16 -07002792bool ValidateTexImage2DRobustANGLE(Context *context,
2793 TextureTarget target,
2794 GLint level,
2795 GLint internalformat,
2796 GLsizei width,
2797 GLsizei height,
2798 GLint border,
2799 GLenum format,
2800 GLenum type,
2801 GLsizei bufSize,
2802 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04002803{
2804 if (!ValidateRobustEntryPoint(context, bufSize))
2805 {
2806 return false;
2807 }
2808
2809 if (context->getClientMajorVersion() < 3)
2810 {
2811 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
2812 0, 0, width, height, border, format, type, bufSize,
2813 pixels);
2814 }
2815
2816 ASSERT(context->getClientMajorVersion() >= 3);
2817 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
2818 0, 0, width, height, 1, border, format, type, bufSize,
2819 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002820}
2821
2822bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002823 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002824 GLint level,
2825 GLint xoffset,
2826 GLint yoffset,
2827 GLsizei width,
2828 GLsizei height,
2829 GLenum format,
2830 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002831 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002832{
2833
Martin Radev1be913c2016-07-11 17:59:16 +03002834 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002835 {
2836 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002837 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002838 }
2839
Martin Radev1be913c2016-07-11 17:59:16 +03002840 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002841 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002842 yoffset, 0, width, height, 1, 0, format, type, -1,
2843 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002844}
2845
Geoff Langc52f6f12016-10-14 10:18:00 -04002846bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002847 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04002848 GLint level,
2849 GLint xoffset,
2850 GLint yoffset,
2851 GLsizei width,
2852 GLsizei height,
2853 GLenum format,
2854 GLenum type,
2855 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002856 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04002857{
2858 if (!ValidateRobustEntryPoint(context, bufSize))
2859 {
2860 return false;
2861 }
2862
2863 if (context->getClientMajorVersion() < 3)
2864 {
2865 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
2866 yoffset, width, height, 0, format, type, bufSize,
2867 pixels);
2868 }
2869
2870 ASSERT(context->getClientMajorVersion() >= 3);
2871 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
2872 yoffset, 0, width, height, 1, 0, format, type, bufSize,
2873 pixels);
2874}
2875
Jamie Madill73a84962016-02-12 09:27:23 -05002876bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002877 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002878 GLint level,
2879 GLenum internalformat,
2880 GLsizei width,
2881 GLsizei height,
2882 GLint border,
2883 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002884 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002885{
Martin Radev1be913c2016-07-11 17:59:16 +03002886 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002887 {
2888 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002889 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002890 {
2891 return false;
2892 }
2893 }
2894 else
2895 {
Martin Radev1be913c2016-07-11 17:59:16 +03002896 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002897 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002898 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002899 data))
2900 {
2901 return false;
2902 }
2903 }
2904
Geoff Langca271392017-04-05 12:30:00 -04002905 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04002906
2907 GLuint blockSize = 0;
2908 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002909 {
Jamie Madille0472f32018-11-27 16:32:45 -05002910 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002911 return false;
2912 }
2913
Jamie Madillca2ff382018-07-11 09:01:17 -04002914 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002915 {
Jamie Madille0472f32018-11-27 16:32:45 -05002916 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05002917 return false;
2918 }
2919
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002920 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002921 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002922 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002923 return false;
2924 }
2925
Jamie Madill73a84962016-02-12 09:27:23 -05002926 return true;
2927}
2928
Corentin Wallezb2931602017-04-11 15:58:57 -04002929bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002930 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002931 GLint level,
2932 GLenum internalformat,
2933 GLsizei width,
2934 GLsizei height,
2935 GLint border,
2936 GLsizei imageSize,
2937 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002938 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002939{
2940 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2941 {
2942 return false;
2943 }
2944
2945 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
2946 border, imageSize, data);
2947}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002948
Corentin Wallezb2931602017-04-11 15:58:57 -04002949bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002950 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002951 GLint level,
2952 GLint xoffset,
2953 GLint yoffset,
2954 GLsizei width,
2955 GLsizei height,
2956 GLenum format,
2957 GLsizei imageSize,
2958 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002959 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002960{
2961 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2962 {
2963 return false;
2964 }
2965
2966 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
2967 format, imageSize, data);
2968}
2969
Jamie Madill73a84962016-02-12 09:27:23 -05002970bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002971 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002972 GLint level,
2973 GLint xoffset,
2974 GLint yoffset,
2975 GLsizei width,
2976 GLsizei height,
2977 GLenum format,
2978 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002979 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002980{
Martin Radev1be913c2016-07-11 17:59:16 +03002981 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002982 {
2983 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04002984 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002985 {
2986 return false;
2987 }
2988 }
2989 else
2990 {
Martin Radev1be913c2016-07-11 17:59:16 +03002991 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002992 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04002993 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002994 data))
2995 {
2996 return false;
2997 }
2998 }
2999
Geoff Langca271392017-04-05 12:30:00 -04003000 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04003001 GLuint blockSize = 0;
3002 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003003 {
Jamie Madille0472f32018-11-27 16:32:45 -05003004 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003005 return false;
3006 }
3007
Jamie Madillca2ff382018-07-11 09:01:17 -04003008 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003009 {
Jamie Madille0472f32018-11-27 16:32:45 -05003010 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05003011 return false;
3012 }
3013
3014 return true;
3015}
3016
Corentin Wallez336129f2017-10-17 15:55:40 -04003017bool ValidateGetBufferPointervOES(Context *context,
3018 BufferBinding target,
3019 GLenum pname,
3020 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003021{
Jamie Madillc3e37312018-11-30 15:25:39 -05003022 if (!context->getExtensions().mapBuffer)
3023 {
3024 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3025 return false;
3026 }
3027
Geoff Lang496c02d2016-10-20 11:38:11 -07003028 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003029}
3030
Corentin Wallez336129f2017-10-17 15:55:40 -04003031bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003032{
3033 if (!context->getExtensions().mapBuffer)
3034 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003035 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003036 return false;
3037 }
3038
Corentin Walleze4477002017-12-01 14:39:58 -05003039 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03003040 {
Jamie Madille0472f32018-11-27 16:32:45 -05003041 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03003042 return false;
3043 }
3044
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003045 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003046
3047 if (buffer == nullptr)
3048 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003049 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03003050 return false;
3051 }
3052
3053 if (access != GL_WRITE_ONLY_OES)
3054 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003055 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03003056 return false;
3057 }
3058
3059 if (buffer->isMapped())
3060 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003061 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003062 return false;
3063 }
3064
Geoff Lang79f71042017-08-14 16:43:43 -04003065 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003066}
3067
Corentin Wallez336129f2017-10-17 15:55:40 -04003068bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003069{
3070 if (!context->getExtensions().mapBuffer)
3071 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003072 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003073 return false;
3074 }
3075
3076 return ValidateUnmapBufferBase(context, target);
3077}
3078
3079bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003080 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003081 GLintptr offset,
3082 GLsizeiptr length,
3083 GLbitfield access)
3084{
3085 if (!context->getExtensions().mapBufferRange)
3086 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003087 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003088 return false;
3089 }
3090
3091 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3092}
3093
Michael Spang7a8c3e52019-04-03 14:49:57 -04003094bool ValidateBufferStorageMemEXT(Context *context,
3095 TextureType target,
3096 GLsizeiptr size,
3097 GLuint memory,
3098 GLuint64 offset)
3099{
3100 if (!context->getExtensions().memoryObject)
3101 {
3102 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3103 return false;
3104 }
3105
3106 UNIMPLEMENTED();
3107 return false;
3108}
3109
3110bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects)
3111{
3112 if (!context->getExtensions().memoryObject)
3113 {
3114 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3115 return false;
3116 }
3117
Michael Spangfb201c52019-04-03 14:57:35 -04003118 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003119}
3120
3121bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects)
3122{
3123 if (!context->getExtensions().memoryObject)
3124 {
3125 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3126 return false;
3127 }
3128
Michael Spangfb201c52019-04-03 14:57:35 -04003129 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003130}
3131
3132bool ValidateGetMemoryObjectParameterivEXT(Context *context,
3133 GLuint memoryObject,
3134 GLenum pname,
3135 GLint *params)
3136{
3137 if (!context->getExtensions().memoryObject)
3138 {
3139 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3140 return false;
3141 }
3142
3143 UNIMPLEMENTED();
3144 return false;
3145}
3146
3147bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3148{
3149 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3150 {
3151 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3152 return false;
3153 }
3154
3155 UNIMPLEMENTED();
3156 return false;
3157}
3158
3159bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3160{
3161 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3162 {
3163 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3164 return false;
3165 }
3166
3167 UNIMPLEMENTED();
3168 return false;
3169}
3170
3171bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject)
3172{
3173 if (!context->getExtensions().memoryObject)
3174 {
3175 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3176 return false;
3177 }
3178
Michael Spangfb201c52019-04-03 14:57:35 -04003179 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003180}
3181
3182bool ValidateMemoryObjectParameterivEXT(Context *context,
3183 GLuint memoryObject,
3184 GLenum pname,
3185 const GLint *params)
3186{
3187 if (!context->getExtensions().memoryObject)
3188 {
3189 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3190 return false;
3191 }
3192
3193 UNIMPLEMENTED();
3194 return false;
3195}
3196
3197bool ValidateTexStorageMem2DEXT(Context *context,
3198 TextureType target,
3199 GLsizei levels,
3200 GLenum internalFormat,
3201 GLsizei width,
3202 GLsizei height,
3203 GLuint memory,
3204 GLuint64 offset)
3205{
3206 if (!context->getExtensions().memoryObject)
3207 {
3208 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3209 return false;
3210 }
3211
Michael Spangf02a7672019-04-09 18:45:23 -04003212 if (context->getClientMajorVersion() < 3)
3213 {
3214 return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width,
3215 height);
3216 }
3217
3218 ASSERT(context->getClientMajorVersion() >= 3);
3219 return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height,
3220 1);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003221}
3222
3223bool ValidateTexStorageMem3DEXT(Context *context,
3224 TextureType target,
3225 GLsizei levels,
3226 GLenum internalFormat,
3227 GLsizei width,
3228 GLsizei height,
3229 GLsizei depth,
3230 GLuint memory,
3231 GLuint64 offset)
3232{
3233 if (!context->getExtensions().memoryObject)
3234 {
3235 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3236 return false;
3237 }
3238
3239 UNIMPLEMENTED();
3240 return false;
3241}
3242
Michael Spang9de3ddb2019-04-03 16:23:40 -04003243bool ValidateImportMemoryFdEXT(Context *context,
3244 GLuint memory,
3245 GLuint64 size,
Michael Spange0da9ce2019-04-16 14:34:51 -04003246 HandleType handleType,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003247 GLint fd)
3248{
3249 if (!context->getExtensions().memoryObjectFd)
3250 {
3251 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3252 return false;
3253 }
3254
Michael Spang3b2c6bf2019-04-16 17:19:50 -04003255 switch (handleType)
3256 {
3257 case HandleType::OpaqueFd:
3258 break;
3259 default:
3260 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3261 return false;
3262 }
3263
3264 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003265}
3266
Michael Spang7a8c3e52019-04-03 14:49:57 -04003267bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores)
3268{
3269 if (!context->getExtensions().semaphore)
3270 {
3271 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3272 return false;
3273 }
3274
Michael Spang5093ba62019-05-14 17:36:36 -04003275 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003276}
3277
3278bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores)
3279{
3280 if (!context->getExtensions().semaphore)
3281 {
3282 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3283 return false;
3284 }
3285
Michael Spang5093ba62019-05-14 17:36:36 -04003286 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003287}
3288
3289bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
3290 GLuint semaphore,
3291 GLenum pname,
3292 GLuint64 *params)
3293{
3294 if (!context->getExtensions().semaphore)
3295 {
3296 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3297 return false;
3298 }
3299
3300 UNIMPLEMENTED();
3301 return false;
3302}
3303
3304bool ValidateIsSemaphoreEXT(Context *context, GLuint semaphore)
3305{
3306 if (!context->getExtensions().semaphore)
3307 {
3308 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3309 return false;
3310 }
3311
Michael Spang5093ba62019-05-14 17:36:36 -04003312 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003313}
3314
3315bool ValidateSemaphoreParameterui64vEXT(Context *context,
3316 GLuint semaphore,
3317 GLenum pname,
3318 const GLuint64 *params)
3319{
3320 if (!context->getExtensions().semaphore)
3321 {
3322 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3323 return false;
3324 }
3325
3326 UNIMPLEMENTED();
3327 return false;
3328}
3329
3330bool ValidateSignalSemaphoreEXT(Context *context,
3331 GLuint semaphore,
3332 GLuint numBufferBarriers,
3333 const GLuint *buffers,
3334 GLuint numTextureBarriers,
3335 const GLuint *textures,
3336 const GLenum *dstLayouts)
3337{
3338 if (!context->getExtensions().semaphore)
3339 {
3340 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3341 return false;
3342 }
3343
3344 UNIMPLEMENTED();
3345 return false;
3346}
3347
3348bool ValidateWaitSemaphoreEXT(Context *context,
3349 GLuint semaphore,
3350 GLuint numBufferBarriers,
3351 const GLuint *buffers,
3352 GLuint numTextureBarriers,
3353 const GLuint *textures,
3354 const GLenum *srcLayouts)
3355{
3356 if (!context->getExtensions().semaphore)
3357 {
3358 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3359 return false;
3360 }
3361
3362 UNIMPLEMENTED();
3363 return false;
3364}
3365
Michael Spange0da9ce2019-04-16 14:34:51 -04003366bool ValidateImportSemaphoreFdEXT(Context *context,
3367 GLuint semaphore,
3368 HandleType handleType,
3369 GLint fd)
Michael Spang9de3ddb2019-04-03 16:23:40 -04003370{
3371 if (!context->getExtensions().semaphoreFd)
3372 {
3373 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3374 return false;
3375 }
3376
Michael Spang6bb193c2019-05-22 16:32:21 -04003377 switch (handleType)
3378 {
3379 case HandleType::OpaqueFd:
3380 break;
3381 default:
3382 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3383 return false;
3384 }
3385
3386 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003387}
3388
Corentin Wallez336129f2017-10-17 15:55:40 -04003389bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003390{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003391 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003392 ASSERT(buffer != nullptr);
3393
3394 // Check if this buffer is currently being used as a transform feedback output buffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003395 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003396 if (transformFeedback != nullptr && transformFeedback->isActive())
3397 {
3398 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3399 {
3400 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3401 if (transformFeedbackBuffer.get() == buffer)
3402 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003403 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003404 return false;
3405 }
3406 }
3407 }
3408
James Darpiniane8a93c62018-01-04 18:02:24 -08003409 if (context->getExtensions().webglCompatibility &&
3410 buffer->isBoundForTransformFeedbackAndOtherUse())
3411 {
Jamie Madille0472f32018-11-27 16:32:45 -05003412 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003413 return false;
3414 }
3415
Geoff Lang79f71042017-08-14 16:43:43 -04003416 return true;
3417}
3418
Olli Etuaho4f667482016-03-30 15:56:35 +03003419bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003420 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003421 GLintptr offset,
3422 GLsizeiptr length)
3423{
3424 if (!context->getExtensions().mapBufferRange)
3425 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003426 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003427 return false;
3428 }
3429
3430 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3431}
3432
Geoff Langd8605522016-04-13 10:19:12 -04003433bool ValidateBindUniformLocationCHROMIUM(Context *context,
3434 GLuint program,
3435 GLint location,
3436 const GLchar *name)
3437{
3438 if (!context->getExtensions().bindUniformLocation)
3439 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003440 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003441 return false;
3442 }
3443
3444 Program *programObject = GetValidProgram(context, program);
3445 if (!programObject)
3446 {
3447 return false;
3448 }
3449
3450 if (location < 0)
3451 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003452 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003453 return false;
3454 }
3455
3456 const Caps &caps = context->getCaps();
3457 if (static_cast<size_t>(location) >=
3458 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3459 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003460 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003461 return false;
3462 }
3463
Geoff Langfc32e8b2017-05-31 14:16:59 -04003464 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3465 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003466 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003467 {
Jamie Madille0472f32018-11-27 16:32:45 -05003468 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003469 return false;
3470 }
3471
Geoff Langd8605522016-04-13 10:19:12 -04003472 if (strncmp(name, "gl_", 3) == 0)
3473 {
Jamie Madille0472f32018-11-27 16:32:45 -05003474 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003475 return false;
3476 }
3477
3478 return true;
3479}
3480
Jamie Madille2e406c2016-06-02 13:04:10 -04003481bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003482{
3483 if (!context->getExtensions().framebufferMixedSamples)
3484 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003485 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003486 return false;
3487 }
3488 switch (components)
3489 {
3490 case GL_RGB:
3491 case GL_RGBA:
3492 case GL_ALPHA:
3493 case GL_NONE:
3494 break;
3495 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003496 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003497 return false;
3498 }
3499
3500 return true;
3501}
3502
Sami Väisänene45e53b2016-05-25 10:36:04 +03003503// CHROMIUM_path_rendering
3504
Jamie Madill007530e2017-12-28 14:27:04 -05003505bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003506{
Jamie Madill007530e2017-12-28 14:27:04 -05003507 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003508 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003509 return false;
3510 }
Jamie Madill007530e2017-12-28 14:27:04 -05003511
Sami Väisänene45e53b2016-05-25 10:36:04 +03003512 if (matrix == nullptr)
3513 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003514 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003515 return false;
3516 }
Jamie Madill007530e2017-12-28 14:27:04 -05003517
Sami Väisänene45e53b2016-05-25 10:36:04 +03003518 return true;
3519}
3520
Jamie Madill007530e2017-12-28 14:27:04 -05003521bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003522{
Jamie Madill007530e2017-12-28 14:27:04 -05003523 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003524}
3525
Jamie Madill007530e2017-12-28 14:27:04 -05003526bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003527{
3528 if (!context->getExtensions().pathRendering)
3529 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003530 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003531 return false;
3532 }
3533
3534 // range = 0 is undefined in NV_path_rendering.
3535 // we add stricter semantic check here and require a non zero positive range.
3536 if (range <= 0)
3537 {
Jamie Madille0472f32018-11-27 16:32:45 -05003538 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003539 return false;
3540 }
3541
3542 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3543 {
Jamie Madille0472f32018-11-27 16:32:45 -05003544 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003545 return false;
3546 }
3547
3548 return true;
3549}
3550
Jamie Madill007530e2017-12-28 14:27:04 -05003551bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003552{
3553 if (!context->getExtensions().pathRendering)
3554 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003555 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003556 return false;
3557 }
3558
3559 // range = 0 is undefined in NV_path_rendering.
3560 // we add stricter semantic check here and require a non zero positive range.
3561 if (range <= 0)
3562 {
Jamie Madille0472f32018-11-27 16:32:45 -05003563 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003564 return false;
3565 }
3566
3567 angle::CheckedNumeric<std::uint32_t> checkedRange(path);
3568 checkedRange += range;
3569
3570 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3571 {
Jamie Madille0472f32018-11-27 16:32:45 -05003572 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003573 return false;
3574 }
3575 return true;
3576}
3577
Jamie Madill007530e2017-12-28 14:27:04 -05003578bool ValidatePathCommandsCHROMIUM(Context *context,
3579 GLuint path,
3580 GLsizei numCommands,
3581 const GLubyte *commands,
3582 GLsizei numCoords,
3583 GLenum coordType,
3584 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003585{
3586 if (!context->getExtensions().pathRendering)
3587 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003588 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003589 return false;
3590 }
Brandon Jones59770802018-04-02 13:18:42 -07003591 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003592 {
Jamie Madille0472f32018-11-27 16:32:45 -05003593 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003594 return false;
3595 }
3596
3597 if (numCommands < 0)
3598 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003599 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003600 return false;
3601 }
3602 else if (numCommands > 0)
3603 {
3604 if (!commands)
3605 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003606 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003607 return false;
3608 }
3609 }
3610
3611 if (numCoords < 0)
3612 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003613 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003614 return false;
3615 }
3616 else if (numCoords > 0)
3617 {
3618 if (!coords)
3619 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003620 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003621 return false;
3622 }
3623 }
3624
3625 std::uint32_t coordTypeSize = 0;
3626 switch (coordType)
3627 {
3628 case GL_BYTE:
3629 coordTypeSize = sizeof(GLbyte);
3630 break;
3631
3632 case GL_UNSIGNED_BYTE:
3633 coordTypeSize = sizeof(GLubyte);
3634 break;
3635
3636 case GL_SHORT:
3637 coordTypeSize = sizeof(GLshort);
3638 break;
3639
3640 case GL_UNSIGNED_SHORT:
3641 coordTypeSize = sizeof(GLushort);
3642 break;
3643
3644 case GL_FLOAT:
3645 coordTypeSize = sizeof(GLfloat);
3646 break;
3647
3648 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003649 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003650 return false;
3651 }
3652
3653 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3654 checkedSize += (coordTypeSize * numCoords);
3655 if (!checkedSize.IsValid())
3656 {
Jamie Madille0472f32018-11-27 16:32:45 -05003657 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003658 return false;
3659 }
3660
3661 // early return skips command data validation when it doesn't exist.
3662 if (!commands)
3663 return true;
3664
3665 GLsizei expectedNumCoords = 0;
3666 for (GLsizei i = 0; i < numCommands; ++i)
3667 {
3668 switch (commands[i])
3669 {
3670 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3671 break;
3672 case GL_MOVE_TO_CHROMIUM:
3673 case GL_LINE_TO_CHROMIUM:
3674 expectedNumCoords += 2;
3675 break;
3676 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3677 expectedNumCoords += 4;
3678 break;
3679 case GL_CUBIC_CURVE_TO_CHROMIUM:
3680 expectedNumCoords += 6;
3681 break;
3682 case GL_CONIC_CURVE_TO_CHROMIUM:
3683 expectedNumCoords += 5;
3684 break;
3685 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003686 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003687 return false;
3688 }
3689 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003690
Sami Väisänene45e53b2016-05-25 10:36:04 +03003691 if (expectedNumCoords != numCoords)
3692 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003693 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003694 return false;
3695 }
3696
3697 return true;
3698}
3699
Jamie Madill007530e2017-12-28 14:27:04 -05003700bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003701{
3702 if (!context->getExtensions().pathRendering)
3703 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003704 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003705 return false;
3706 }
Brandon Jones59770802018-04-02 13:18:42 -07003707 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003708 {
Jamie Madille0472f32018-11-27 16:32:45 -05003709 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003710 return false;
3711 }
3712
3713 switch (pname)
3714 {
3715 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3716 if (value < 0.0f)
3717 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003718 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003719 return false;
3720 }
3721 break;
3722 case GL_PATH_END_CAPS_CHROMIUM:
3723 switch (static_cast<GLenum>(value))
3724 {
3725 case GL_FLAT_CHROMIUM:
3726 case GL_SQUARE_CHROMIUM:
3727 case GL_ROUND_CHROMIUM:
3728 break;
3729 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003730 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003731 return false;
3732 }
3733 break;
3734 case GL_PATH_JOIN_STYLE_CHROMIUM:
3735 switch (static_cast<GLenum>(value))
3736 {
3737 case GL_MITER_REVERT_CHROMIUM:
3738 case GL_BEVEL_CHROMIUM:
3739 case GL_ROUND_CHROMIUM:
3740 break;
3741 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003742 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003743 return false;
3744 }
Nico Weber41b072b2018-02-09 10:01:32 -05003745 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03003746 case GL_PATH_MITER_LIMIT_CHROMIUM:
3747 if (value < 0.0f)
3748 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003749 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003750 return false;
3751 }
3752 break;
3753
3754 case GL_PATH_STROKE_BOUND_CHROMIUM:
3755 // no errors, only clamping.
3756 break;
3757
3758 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003759 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003760 return false;
3761 }
3762 return true;
3763}
3764
Jamie Madill007530e2017-12-28 14:27:04 -05003765bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value)
3766{
3767 // TODO(jmadill): Use proper clamping cast.
3768 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
3769}
3770
3771bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003772{
3773 if (!context->getExtensions().pathRendering)
3774 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003775 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003776 return false;
3777 }
3778
Brandon Jones59770802018-04-02 13:18:42 -07003779 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003780 {
Jamie Madille0472f32018-11-27 16:32:45 -05003781 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003782 return false;
3783 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003784
Sami Väisänene45e53b2016-05-25 10:36:04 +03003785 if (!value)
3786 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003787 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003788 return false;
3789 }
3790
3791 switch (pname)
3792 {
3793 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3794 case GL_PATH_END_CAPS_CHROMIUM:
3795 case GL_PATH_JOIN_STYLE_CHROMIUM:
3796 case GL_PATH_MITER_LIMIT_CHROMIUM:
3797 case GL_PATH_STROKE_BOUND_CHROMIUM:
3798 break;
3799
3800 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003801 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003802 return false;
3803 }
3804
3805 return true;
3806}
3807
Jamie Madill007530e2017-12-28 14:27:04 -05003808bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value)
3809{
3810 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
3811 reinterpret_cast<GLfloat *>(value));
3812}
3813
3814bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003815{
3816 if (!context->getExtensions().pathRendering)
3817 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003818 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003819 return false;
3820 }
3821
3822 switch (func)
3823 {
3824 case GL_NEVER:
3825 case GL_ALWAYS:
3826 case GL_LESS:
3827 case GL_LEQUAL:
3828 case GL_EQUAL:
3829 case GL_GEQUAL:
3830 case GL_GREATER:
3831 case GL_NOTEQUAL:
3832 break;
3833 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003834 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003835 return false;
3836 }
3837
3838 return true;
3839}
3840
3841// Note that the spec specifies that for the path drawing commands
3842// if the path object is not an existing path object the command
3843// does nothing and no error is generated.
3844// However if the path object exists but has not been specified any
3845// commands then an error is generated.
3846
Jamie Madill007530e2017-12-28 14:27:04 -05003847bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003848{
3849 if (!context->getExtensions().pathRendering)
3850 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003851 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003852 return false;
3853 }
Brandon Jones59770802018-04-02 13:18:42 -07003854 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003855 {
Jamie Madille0472f32018-11-27 16:32:45 -05003856 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003857 return false;
3858 }
3859
3860 switch (fillMode)
3861 {
3862 case GL_COUNT_UP_CHROMIUM:
3863 case GL_COUNT_DOWN_CHROMIUM:
3864 break;
3865 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003866 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003867 return false;
3868 }
3869
3870 if (!isPow2(mask + 1))
3871 {
Jamie Madille0472f32018-11-27 16:32:45 -05003872 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003873 return false;
3874 }
3875
3876 return true;
3877}
3878
Jamie Madill007530e2017-12-28 14:27:04 -05003879bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003880{
3881 if (!context->getExtensions().pathRendering)
3882 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003883 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003884 return false;
3885 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003886
Brandon Jones59770802018-04-02 13:18:42 -07003887 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003888 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003889 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003890 return false;
3891 }
3892
3893 return true;
3894}
3895
Jamie Madill007530e2017-12-28 14:27:04 -05003896bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003897{
3898 if (!context->getExtensions().pathRendering)
3899 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003900 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003901 return false;
3902 }
Brandon Jones59770802018-04-02 13:18:42 -07003903 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003904 {
Jamie Madille0472f32018-11-27 16:32:45 -05003905 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003906 return false;
3907 }
3908
3909 switch (coverMode)
3910 {
3911 case GL_CONVEX_HULL_CHROMIUM:
3912 case GL_BOUNDING_BOX_CHROMIUM:
3913 break;
3914 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003915 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003916 return false;
3917 }
3918 return true;
3919}
3920
Jamie Madill778bf092018-11-14 09:54:36 -05003921bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3922{
3923 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3924}
3925
3926bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3927{
3928 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3929}
3930
Jamie Madill007530e2017-12-28 14:27:04 -05003931bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
3932 GLuint path,
3933 GLenum fillMode,
3934 GLuint mask,
3935 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003936{
Jamie Madill007530e2017-12-28 14:27:04 -05003937 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
3938 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003939}
3940
Jamie Madill007530e2017-12-28 14:27:04 -05003941bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
3942 GLuint path,
3943 GLint reference,
3944 GLuint mask,
3945 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003946{
Jamie Madill007530e2017-12-28 14:27:04 -05003947 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
3948 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003949}
3950
Brandon Jonesd1049182018-03-28 10:02:20 -07003951bool ValidateIsPathCHROMIUM(Context *context, GLuint path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003952{
3953 if (!context->getExtensions().pathRendering)
3954 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003955 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003956 return false;
3957 }
3958 return true;
3959}
3960
Jamie Madill007530e2017-12-28 14:27:04 -05003961bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
3962 GLsizei numPaths,
3963 GLenum pathNameType,
3964 const void *paths,
3965 GLuint pathBase,
3966 GLenum coverMode,
3967 GLenum transformType,
3968 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003969{
3970 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3971 transformType, transformValues))
3972 return false;
3973
3974 switch (coverMode)
3975 {
3976 case GL_CONVEX_HULL_CHROMIUM:
3977 case GL_BOUNDING_BOX_CHROMIUM:
3978 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
3979 break;
3980 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003981 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03003982 return false;
3983 }
3984
3985 return true;
3986}
3987
Jamie Madill007530e2017-12-28 14:27:04 -05003988bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
3989 GLsizei numPaths,
3990 GLenum pathNameType,
3991 const void *paths,
3992 GLuint pathBase,
3993 GLenum coverMode,
3994 GLenum transformType,
3995 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003996{
3997 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3998 transformType, transformValues))
3999 return false;
4000
4001 switch (coverMode)
4002 {
4003 case GL_CONVEX_HULL_CHROMIUM:
4004 case GL_BOUNDING_BOX_CHROMIUM:
4005 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4006 break;
4007 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004008 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004009 return false;
4010 }
4011
4012 return true;
4013}
4014
Jamie Madill007530e2017-12-28 14:27:04 -05004015bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
4016 GLsizei numPaths,
4017 GLenum pathNameType,
4018 const void *paths,
4019 GLuint pathBase,
4020 GLenum fillMode,
4021 GLuint mask,
4022 GLenum transformType,
4023 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004024{
4025
4026 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4027 transformType, transformValues))
4028 return false;
4029
4030 switch (fillMode)
4031 {
4032 case GL_COUNT_UP_CHROMIUM:
4033 case GL_COUNT_DOWN_CHROMIUM:
4034 break;
4035 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004036 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004037 return false;
4038 }
4039 if (!isPow2(mask + 1))
4040 {
Jamie Madille0472f32018-11-27 16:32:45 -05004041 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004042 return false;
4043 }
4044 return true;
4045}
4046
Jamie Madill007530e2017-12-28 14:27:04 -05004047bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
4048 GLsizei numPaths,
4049 GLenum pathNameType,
4050 const void *paths,
4051 GLuint pathBase,
4052 GLint reference,
4053 GLuint mask,
4054 GLenum transformType,
4055 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004056{
4057 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4058 transformType, transformValues))
4059 return false;
4060
4061 // no more validation here.
4062
4063 return true;
4064}
4065
Jamie Madill007530e2017-12-28 14:27:04 -05004066bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
4067 GLsizei numPaths,
4068 GLenum pathNameType,
4069 const void *paths,
4070 GLuint pathBase,
4071 GLenum fillMode,
4072 GLuint mask,
4073 GLenum coverMode,
4074 GLenum transformType,
4075 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004076{
4077 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4078 transformType, transformValues))
4079 return false;
4080
4081 switch (coverMode)
4082 {
4083 case GL_CONVEX_HULL_CHROMIUM:
4084 case GL_BOUNDING_BOX_CHROMIUM:
4085 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4086 break;
4087 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004088 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004089 return false;
4090 }
4091
4092 switch (fillMode)
4093 {
4094 case GL_COUNT_UP_CHROMIUM:
4095 case GL_COUNT_DOWN_CHROMIUM:
4096 break;
4097 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004098 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004099 return false;
4100 }
4101 if (!isPow2(mask + 1))
4102 {
Jamie Madille0472f32018-11-27 16:32:45 -05004103 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004104 return false;
4105 }
4106
4107 return true;
4108}
4109
Jamie Madill007530e2017-12-28 14:27:04 -05004110bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4111 GLsizei numPaths,
4112 GLenum pathNameType,
4113 const void *paths,
4114 GLuint pathBase,
4115 GLint reference,
4116 GLuint mask,
4117 GLenum coverMode,
4118 GLenum transformType,
4119 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004120{
4121 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4122 transformType, transformValues))
4123 return false;
4124
4125 switch (coverMode)
4126 {
4127 case GL_CONVEX_HULL_CHROMIUM:
4128 case GL_BOUNDING_BOX_CHROMIUM:
4129 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4130 break;
4131 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004132 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004133 return false;
4134 }
4135
4136 return true;
4137}
4138
Jamie Madill007530e2017-12-28 14:27:04 -05004139bool ValidateBindFragmentInputLocationCHROMIUM(Context *context,
4140 GLuint program,
4141 GLint location,
4142 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004143{
4144 if (!context->getExtensions().pathRendering)
4145 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004146 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004147 return false;
4148 }
4149
4150 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4151 if (location >= MaxLocation)
4152 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004153 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004154 return false;
4155 }
4156
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004157 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004158 if (!programObject)
4159 {
Jamie Madille0472f32018-11-27 16:32:45 -05004160 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004161 return false;
4162 }
4163
4164 if (!name)
4165 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004166 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004167 return false;
4168 }
4169
4170 if (angle::BeginsWith(name, "gl_"))
4171 {
Jamie Madille0472f32018-11-27 16:32:45 -05004172 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004173 return false;
4174 }
4175
4176 return true;
4177}
4178
Jamie Madill007530e2017-12-28 14:27:04 -05004179bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
4180 GLuint program,
4181 GLint location,
4182 GLenum genMode,
4183 GLint components,
4184 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004185{
4186 if (!context->getExtensions().pathRendering)
4187 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004188 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004189 return false;
4190 }
4191
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004192 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004193 if (!programObject || programObject->isFlaggedForDeletion())
4194 {
Jamie Madille0472f32018-11-27 16:32:45 -05004195 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004196 return false;
4197 }
4198
4199 if (!programObject->isLinked())
4200 {
Jamie Madille0472f32018-11-27 16:32:45 -05004201 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004202 return false;
4203 }
4204
4205 switch (genMode)
4206 {
4207 case GL_NONE:
4208 if (components != 0)
4209 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004210 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004211 return false;
4212 }
4213 break;
4214
4215 case GL_OBJECT_LINEAR_CHROMIUM:
4216 case GL_EYE_LINEAR_CHROMIUM:
4217 case GL_CONSTANT_CHROMIUM:
4218 if (components < 1 || components > 4)
4219 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004220 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004221 return false;
4222 }
4223 if (!coeffs)
4224 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004225 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004226 return false;
4227 }
4228 break;
4229
4230 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004231 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004232 return false;
4233 }
4234
4235 // If the location is -1 then the command is silently ignored
4236 // and no further validation is needed.
4237 if (location == -1)
4238 return true;
4239
jchen103fd614d2018-08-13 12:21:58 +08004240 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004241
4242 if (!binding.valid)
4243 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004244 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004245 return false;
4246 }
4247
4248 if (binding.type != GL_NONE)
4249 {
4250 GLint expectedComponents = 0;
4251 switch (binding.type)
4252 {
4253 case GL_FLOAT:
4254 expectedComponents = 1;
4255 break;
4256 case GL_FLOAT_VEC2:
4257 expectedComponents = 2;
4258 break;
4259 case GL_FLOAT_VEC3:
4260 expectedComponents = 3;
4261 break;
4262 case GL_FLOAT_VEC4:
4263 expectedComponents = 4;
4264 break;
4265 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004266 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004267 return false;
4268 }
4269 if (expectedComponents != components && genMode != GL_NONE)
4270 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004271 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004272 return false;
4273 }
4274 }
4275 return true;
4276}
4277
Geoff Lang97073d12016-04-20 10:42:34 -07004278bool ValidateCopyTextureCHROMIUM(Context *context,
4279 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004280 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004281 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004282 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004283 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004284 GLint internalFormat,
4285 GLenum destType,
4286 GLboolean unpackFlipY,
4287 GLboolean unpackPremultiplyAlpha,
4288 GLboolean unpackUnmultiplyAlpha)
4289{
4290 if (!context->getExtensions().copyTexture)
4291 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004292 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004293 return false;
4294 }
4295
Geoff Lang4f0e0032017-05-01 16:04:35 -04004296 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004297 if (source == nullptr)
4298 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004299 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004300 return false;
4301 }
4302
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004303 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004304 {
Jamie Madille0472f32018-11-27 16:32:45 -05004305 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004306 return false;
4307 }
4308
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004309 TextureType sourceType = source->getType();
4310 ASSERT(sourceType != TextureType::CubeMap);
4311 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004312
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004313 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004314 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004315 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004316 return false;
4317 }
4318
Geoff Lang4f0e0032017-05-01 16:04:35 -04004319 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4320 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4321 if (sourceWidth == 0 || sourceHeight == 0)
4322 {
Jamie Madille0472f32018-11-27 16:32:45 -05004323 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004324 return false;
4325 }
4326
4327 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4328 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004329 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004330 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004331 return false;
4332 }
4333
Geoff Lang63458a32017-10-30 15:16:53 -04004334 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4335 {
Jamie Madille0472f32018-11-27 16:32:45 -05004336 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004337 return false;
4338 }
4339
Geoff Lang4f0e0032017-05-01 16:04:35 -04004340 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004341 if (dest == nullptr)
4342 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004343 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004344 return false;
4345 }
4346
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004347 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004348 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004349 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004350 return false;
4351 }
4352
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004353 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004354 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004355 {
Jamie Madille0472f32018-11-27 16:32:45 -05004356 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004357 return false;
4358 }
4359
Geoff Lang97073d12016-04-20 10:42:34 -07004360 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4361 {
Geoff Lang97073d12016-04-20 10:42:34 -07004362 return false;
4363 }
4364
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004365 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004366 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004367 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004368 return false;
4369 }
4370
Geoff Lang97073d12016-04-20 10:42:34 -07004371 if (dest->getImmutableFormat())
4372 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004373 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004374 return false;
4375 }
4376
4377 return true;
4378}
4379
4380bool ValidateCopySubTextureCHROMIUM(Context *context,
4381 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004382 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004383 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004384 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004385 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004386 GLint xoffset,
4387 GLint yoffset,
4388 GLint x,
4389 GLint y,
4390 GLsizei width,
4391 GLsizei height,
4392 GLboolean unpackFlipY,
4393 GLboolean unpackPremultiplyAlpha,
4394 GLboolean unpackUnmultiplyAlpha)
4395{
4396 if (!context->getExtensions().copyTexture)
4397 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004398 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004399 return false;
4400 }
4401
Geoff Lang4f0e0032017-05-01 16:04:35 -04004402 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004403 if (source == nullptr)
4404 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004405 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004406 return false;
4407 }
4408
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004409 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004410 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004411 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004412 return false;
4413 }
4414
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004415 TextureType sourceType = source->getType();
4416 ASSERT(sourceType != TextureType::CubeMap);
4417 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004418
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004419 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004420 {
Jamie Madille0472f32018-11-27 16:32:45 -05004421 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004422 return false;
4423 }
4424
4425 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4426 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004427 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004428 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004429 return false;
4430 }
4431
4432 if (x < 0 || y < 0)
4433 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004434 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004435 return false;
4436 }
4437
4438 if (width < 0 || height < 0)
4439 {
Jamie Madille0472f32018-11-27 16:32:45 -05004440 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004441 return false;
4442 }
4443
Geoff Lang4f0e0032017-05-01 16:04:35 -04004444 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4445 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004446 {
Jamie Madille0472f32018-11-27 16:32:45 -05004447 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004448 return false;
4449 }
4450
Geoff Lang4f0e0032017-05-01 16:04:35 -04004451 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4452 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004453 {
Jamie Madille0472f32018-11-27 16:32:45 -05004454 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004455 return false;
4456 }
4457
Geoff Lang63458a32017-10-30 15:16:53 -04004458 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4459 {
Jamie Madille0472f32018-11-27 16:32:45 -05004460 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004461 return false;
4462 }
4463
Geoff Lang4f0e0032017-05-01 16:04:35 -04004464 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004465 if (dest == nullptr)
4466 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004467 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004468 return false;
4469 }
4470
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004471 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004472 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004473 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004474 return false;
4475 }
4476
Brandon Jones28783792018-03-05 09:37:32 -08004477 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4478 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004479 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004480 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004481 return false;
4482 }
4483
Geoff Lang4f0e0032017-05-01 16:04:35 -04004484 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4485 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004486 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004487 return false;
4488 }
4489
4490 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4491 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004492 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004493 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004494 return false;
4495 }
4496
4497 if (xoffset < 0 || yoffset < 0)
4498 {
Jamie Madille0472f32018-11-27 16:32:45 -05004499 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004500 return false;
4501 }
4502
Geoff Lang4f0e0032017-05-01 16:04:35 -04004503 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4504 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004505 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004506 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004507 return false;
4508 }
4509
4510 return true;
4511}
4512
Geoff Lang47110bf2016-04-20 11:13:22 -07004513bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId)
4514{
4515 if (!context->getExtensions().copyCompressedTexture)
4516 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004517 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004518 return false;
4519 }
4520
4521 const gl::Texture *source = context->getTexture(sourceId);
4522 if (source == nullptr)
4523 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004524 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004525 return false;
4526 }
4527
Corentin Wallez99d492c2018-02-27 15:17:10 -05004528 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004529 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004530 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004531 return false;
4532 }
4533
Corentin Wallez99d492c2018-02-27 15:17:10 -05004534 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4535 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004536 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004537 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004538 return false;
4539 }
4540
Corentin Wallez99d492c2018-02-27 15:17:10 -05004541 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004542 if (!sourceFormat.info->compressed)
4543 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004544 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004545 return false;
4546 }
4547
4548 const gl::Texture *dest = context->getTexture(destId);
4549 if (dest == nullptr)
4550 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004551 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004552 return false;
4553 }
4554
Corentin Wallez99d492c2018-02-27 15:17:10 -05004555 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004556 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004557 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004558 return false;
4559 }
4560
4561 if (dest->getImmutableFormat())
4562 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004563 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004564 return false;
4565 }
4566
4567 return true;
4568}
4569
Jiawei Shao385b3e02018-03-21 09:43:28 +08004570bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004571{
4572 switch (type)
4573 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004574 case ShaderType::Vertex:
4575 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004576 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004577
Jiawei Shao385b3e02018-03-21 09:43:28 +08004578 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004579 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004580 {
Jamie Madille0472f32018-11-27 16:32:45 -05004581 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004582 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004583 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004584 break;
4585
Jiawei Shao385b3e02018-03-21 09:43:28 +08004586 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004587 if (!context->getExtensions().geometryShader)
4588 {
Jamie Madille0472f32018-11-27 16:32:45 -05004589 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004590 return false;
4591 }
4592 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004593 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004594 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004595 return false;
4596 }
Jamie Madill29639852016-09-02 15:00:09 -04004597
4598 return true;
4599}
4600
Jamie Madill5b772312018-03-08 20:28:32 -05004601bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004602 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004603 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004604 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004605 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004606{
4607 if (size < 0)
4608 {
Jamie Madille0472f32018-11-27 16:32:45 -05004609 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004610 return false;
4611 }
4612
4613 switch (usage)
4614 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004615 case BufferUsage::StreamDraw:
4616 case BufferUsage::StaticDraw:
4617 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004618 break;
4619
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004620 case BufferUsage::StreamRead:
4621 case BufferUsage::StaticRead:
4622 case BufferUsage::DynamicRead:
4623 case BufferUsage::StreamCopy:
4624 case BufferUsage::StaticCopy:
4625 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004626 if (context->getClientMajorVersion() < 3)
4627 {
Jamie Madille0472f32018-11-27 16:32:45 -05004628 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004629 return false;
4630 }
4631 break;
4632
4633 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004634 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004635 return false;
4636 }
4637
Corentin Walleze4477002017-12-01 14:39:58 -05004638 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004639 {
Jamie Madille0472f32018-11-27 16:32:45 -05004640 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004641 return false;
4642 }
4643
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004644 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004645
4646 if (!buffer)
4647 {
Jamie Madille0472f32018-11-27 16:32:45 -05004648 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004649 return false;
4650 }
4651
James Darpiniane8a93c62018-01-04 18:02:24 -08004652 if (context->getExtensions().webglCompatibility &&
4653 buffer->isBoundForTransformFeedbackAndOtherUse())
4654 {
Jamie Madille0472f32018-11-27 16:32:45 -05004655 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004656 return false;
4657 }
4658
Jamie Madill29639852016-09-02 15:00:09 -04004659 return true;
4660}
4661
Jamie Madill5b772312018-03-08 20:28:32 -05004662bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004663 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004664 GLintptr offset,
4665 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004666 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004667{
Brandon Jones6cad5662017-06-14 13:25:13 -07004668 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004669 {
Jamie Madille0472f32018-11-27 16:32:45 -05004670 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004671 return false;
4672 }
4673
4674 if (offset < 0)
4675 {
Jamie Madille0472f32018-11-27 16:32:45 -05004676 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004677 return false;
4678 }
4679
Corentin Walleze4477002017-12-01 14:39:58 -05004680 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004681 {
Jamie Madille0472f32018-11-27 16:32:45 -05004682 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004683 return false;
4684 }
4685
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004686 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004687
4688 if (!buffer)
4689 {
Jamie Madille0472f32018-11-27 16:32:45 -05004690 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004691 return false;
4692 }
4693
4694 if (buffer->isMapped())
4695 {
Jamie Madille0472f32018-11-27 16:32:45 -05004696 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004697 return false;
4698 }
4699
James Darpiniane8a93c62018-01-04 18:02:24 -08004700 if (context->getExtensions().webglCompatibility &&
4701 buffer->isBoundForTransformFeedbackAndOtherUse())
4702 {
Jamie Madille0472f32018-11-27 16:32:45 -05004703 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004704 return false;
4705 }
4706
Jamie Madill29639852016-09-02 15:00:09 -04004707 // Check for possible overflow of size + offset
4708 angle::CheckedNumeric<size_t> checkedSize(size);
4709 checkedSize += offset;
4710 if (!checkedSize.IsValid())
4711 {
Jamie Madille0472f32018-11-27 16:32:45 -05004712 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004713 return false;
4714 }
4715
4716 if (size + offset > buffer->getSize())
4717 {
Jamie Madille0472f32018-11-27 16:32:45 -05004718 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004719 return false;
4720 }
4721
Martin Radev4c4c8e72016-08-04 12:25:34 +03004722 return true;
4723}
4724
Geoff Lang111a99e2017-10-17 10:58:41 -04004725bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04004726{
Geoff Langc339c4e2016-11-29 10:37:36 -05004727 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04004728 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004729 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04004730 return false;
4731 }
4732
Geoff Lang111a99e2017-10-17 10:58:41 -04004733 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04004734 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004735 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04004736 return false;
4737 }
4738
4739 return true;
4740}
4741
Jamie Madill5b772312018-03-08 20:28:32 -05004742bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04004743{
Lingfeng Yang038dd532018-03-29 17:31:52 -07004744 if (context->getClientMajorVersion() < 2)
4745 {
4746 return ValidateMultitextureUnit(context, texture);
4747 }
4748
Jamie Madillef300b12016-10-07 15:12:09 -04004749 if (texture < GL_TEXTURE0 ||
4750 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
4751 {
Jamie Madille0472f32018-11-27 16:32:45 -05004752 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04004753 return false;
4754 }
4755
4756 return true;
4757}
4758
Jamie Madill5b772312018-03-08 20:28:32 -05004759bool ValidateAttachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillef300b12016-10-07 15:12:09 -04004760{
4761 Program *programObject = GetValidProgram(context, program);
4762 if (!programObject)
4763 {
4764 return false;
4765 }
4766
4767 Shader *shaderObject = GetValidShader(context, shader);
4768 if (!shaderObject)
4769 {
4770 return false;
4771 }
4772
Jiawei Shao385b3e02018-03-21 09:43:28 +08004773 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04004774 {
Jamie Madille0472f32018-11-27 16:32:45 -05004775 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08004776 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04004777 }
4778
4779 return true;
4780}
4781
Jamie Madill5b772312018-03-08 20:28:32 -05004782bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004783{
4784 if (index >= MAX_VERTEX_ATTRIBS)
4785 {
Jamie Madille0472f32018-11-27 16:32:45 -05004786 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004787 return false;
4788 }
4789
4790 if (strncmp(name, "gl_", 3) == 0)
4791 {
Jamie Madille0472f32018-11-27 16:32:45 -05004792 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004793 return false;
4794 }
4795
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004796 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04004797 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004798 const size_t length = strlen(name);
4799
4800 if (!IsValidESSLString(name, length))
4801 {
4802 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
4803 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05004804 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004805 return false;
4806 }
4807
4808 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
4809 {
4810 return false;
4811 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04004812 }
4813
Jamie Madill01a80ee2016-11-07 12:06:18 -05004814 return GetValidProgram(context, program) != nullptr;
4815}
4816
Jamie Madill5b772312018-03-08 20:28:32 -05004817bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004818{
Geoff Lange8afa902017-09-27 15:00:43 -04004819 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05004820 {
Jamie Madille0472f32018-11-27 16:32:45 -05004821 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004822 return false;
4823 }
4824
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004825 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004826 !context->isFramebufferGenerated(framebuffer))
4827 {
Jamie Madille0472f32018-11-27 16:32:45 -05004828 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004829 return false;
4830 }
4831
4832 return true;
4833}
4834
Jamie Madill5b772312018-03-08 20:28:32 -05004835bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004836{
4837 if (target != GL_RENDERBUFFER)
4838 {
Jamie Madille0472f32018-11-27 16:32:45 -05004839 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004840 return false;
4841 }
4842
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004843 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004844 !context->isRenderbufferGenerated(renderbuffer))
4845 {
Jamie Madille0472f32018-11-27 16:32:45 -05004846 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004847 return false;
4848 }
4849
4850 return true;
4851}
4852
Jamie Madill5b772312018-03-08 20:28:32 -05004853static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004854{
4855 switch (mode)
4856 {
4857 case GL_FUNC_ADD:
4858 case GL_FUNC_SUBTRACT:
4859 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04004860 return true;
4861
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004862 case GL_MIN:
4863 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04004864 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004865
4866 default:
4867 return false;
4868 }
4869}
4870
Jamie Madill5b772312018-03-08 20:28:32 -05004871bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004872{
4873 return true;
4874}
4875
Jamie Madill5b772312018-03-08 20:28:32 -05004876bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004877{
Geoff Lang50cac572017-09-26 17:37:43 -04004878 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004879 {
Jamie Madille0472f32018-11-27 16:32:45 -05004880 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004881 return false;
4882 }
4883
4884 return true;
4885}
4886
Jamie Madill5b772312018-03-08 20:28:32 -05004887bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004888{
Geoff Lang50cac572017-09-26 17:37:43 -04004889 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004890 {
Jamie Madille0472f32018-11-27 16:32:45 -05004891 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004892 return false;
4893 }
4894
Geoff Lang50cac572017-09-26 17:37:43 -04004895 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004896 {
Jamie Madille0472f32018-11-27 16:32:45 -05004897 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004898 return false;
4899 }
4900
4901 return true;
4902}
4903
Jamie Madill5b772312018-03-08 20:28:32 -05004904bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004905{
4906 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
4907}
4908
Jamie Madill5b772312018-03-08 20:28:32 -05004909bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004910 GLenum srcRGB,
4911 GLenum dstRGB,
4912 GLenum srcAlpha,
4913 GLenum dstAlpha)
4914{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004915 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004916 {
Jamie Madille0472f32018-11-27 16:32:45 -05004917 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004918 return false;
4919 }
4920
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004921 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004922 {
Jamie Madille0472f32018-11-27 16:32:45 -05004923 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004924 return false;
4925 }
4926
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004927 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004928 {
Jamie Madille0472f32018-11-27 16:32:45 -05004929 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004930 return false;
4931 }
4932
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004933 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004934 {
Jamie Madille0472f32018-11-27 16:32:45 -05004935 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004936 return false;
4937 }
4938
Frank Henigman146e8a12017-03-02 23:22:37 -05004939 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
4940 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004941 {
4942 bool constantColorUsed =
4943 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
4944 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
4945
4946 bool constantAlphaUsed =
4947 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
4948 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
4949
4950 if (constantColorUsed && constantAlphaUsed)
4951 {
Frank Henigman146e8a12017-03-02 23:22:37 -05004952 if (context->getExtensions().webglCompatibility)
4953 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004954 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
4955 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05004956 }
Jamie Madillc3e37312018-11-30 15:25:39 -05004957
4958 WARN() << kConstantColorAlphaLimitation;
4959 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004960 return false;
4961 }
4962 }
4963
4964 return true;
4965}
4966
Geoff Langc339c4e2016-11-29 10:37:36 -05004967bool ValidateGetString(Context *context, GLenum name)
4968{
4969 switch (name)
4970 {
4971 case GL_VENDOR:
4972 case GL_RENDERER:
4973 case GL_VERSION:
4974 case GL_SHADING_LANGUAGE_VERSION:
4975 case GL_EXTENSIONS:
4976 break;
4977
4978 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
4979 if (!context->getExtensions().requestExtension)
4980 {
Jamie Madille0472f32018-11-27 16:32:45 -05004981 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05004982 return false;
4983 }
4984 break;
4985
4986 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004987 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05004988 return false;
4989 }
4990
4991 return true;
4992}
4993
Jamie Madill5b772312018-03-08 20:28:32 -05004994bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05004995{
4996 if (width <= 0.0f || isNaN(width))
4997 {
Jamie Madille0472f32018-11-27 16:32:45 -05004998 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05004999 return false;
5000 }
5001
5002 return true;
5003}
5004
Jamie Madill5b772312018-03-08 20:28:32 -05005005bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05005006{
5007 if (context->getExtensions().webglCompatibility && zNear > zFar)
5008 {
Jamie Madille0472f32018-11-27 16:32:45 -05005009 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05005010 return false;
5011 }
5012
5013 return true;
5014}
5015
Jamie Madill5b772312018-03-08 20:28:32 -05005016bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005017 GLenum target,
5018 GLenum internalformat,
5019 GLsizei width,
5020 GLsizei height)
5021{
5022 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
5023 height);
5024}
5025
Jamie Madill5b772312018-03-08 20:28:32 -05005026bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005027 GLenum target,
5028 GLsizei samples,
5029 GLenum internalformat,
5030 GLsizei width,
5031 GLsizei height)
5032{
5033 if (!context->getExtensions().framebufferMultisample)
5034 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005035 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05005036 return false;
5037 }
5038
5039 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05005040 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05005041 // generated.
5042 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
5043 {
Jamie Madille0472f32018-11-27 16:32:45 -05005044 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005045 return false;
5046 }
5047
5048 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
5049 // the specified storage. This is different than ES 3.0 in which a sample number higher
5050 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
5051 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
5052 if (context->getClientMajorVersion() >= 3)
5053 {
5054 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
5055 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
5056 {
Jamie Madille0472f32018-11-27 16:32:45 -05005057 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005058 return false;
5059 }
5060 }
5061
5062 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
5063 width, height);
5064}
5065
Jamie Madill5b772312018-03-08 20:28:32 -05005066bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005067{
Geoff Lange8afa902017-09-27 15:00:43 -04005068 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005069 {
Jamie Madille0472f32018-11-27 16:32:45 -05005070 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005071 return false;
5072 }
5073
5074 return true;
5075}
5076
Jamie Madill5b772312018-03-08 20:28:32 -05005077bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005078{
5079 return true;
5080}
5081
Jamie Madill5b772312018-03-08 20:28:32 -05005082bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005083{
5084 return true;
5085}
5086
Jamie Madill5b772312018-03-08 20:28:32 -05005087bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005088{
5089 return true;
5090}
5091
Jamie Madill5b772312018-03-08 20:28:32 -05005092bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005093 GLboolean red,
5094 GLboolean green,
5095 GLboolean blue,
5096 GLboolean alpha)
5097{
5098 return true;
5099}
5100
Jamie Madill5b772312018-03-08 20:28:32 -05005101bool ValidateCompileShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005102{
5103 return true;
5104}
5105
Jamie Madill5b772312018-03-08 20:28:32 -05005106bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005107{
5108 return true;
5109}
5110
Jamie Madill5b772312018-03-08 20:28:32 -05005111bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005112{
5113 switch (mode)
5114 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005115 case CullFaceMode::Front:
5116 case CullFaceMode::Back:
5117 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005118 break;
5119
5120 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005121 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005122 return false;
5123 }
5124
5125 return true;
5126}
5127
Jamie Madill5b772312018-03-08 20:28:32 -05005128bool ValidateDeleteProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005129{
5130 if (program == 0)
5131 {
5132 return false;
5133 }
5134
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005135 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005136 {
5137 if (context->getShader(program))
5138 {
Jamie Madille0472f32018-11-27 16:32:45 -05005139 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005140 return false;
5141 }
5142 else
5143 {
Jamie Madille0472f32018-11-27 16:32:45 -05005144 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005145 return false;
5146 }
5147 }
5148
5149 return true;
5150}
5151
Jamie Madill5b772312018-03-08 20:28:32 -05005152bool ValidateDeleteShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005153{
5154 if (shader == 0)
5155 {
5156 return false;
5157 }
5158
5159 if (!context->getShader(shader))
5160 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005161 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005162 {
Jamie Madille0472f32018-11-27 16:32:45 -05005163 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005164 return false;
5165 }
5166 else
5167 {
Jamie Madille0472f32018-11-27 16:32:45 -05005168 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005169 return false;
5170 }
5171 }
5172
5173 return true;
5174}
5175
Jamie Madill5b772312018-03-08 20:28:32 -05005176bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005177{
5178 switch (func)
5179 {
5180 case GL_NEVER:
5181 case GL_ALWAYS:
5182 case GL_LESS:
5183 case GL_LEQUAL:
5184 case GL_EQUAL:
5185 case GL_GREATER:
5186 case GL_GEQUAL:
5187 case GL_NOTEQUAL:
5188 break;
5189
5190 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005191 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005192 return false;
5193 }
5194
5195 return true;
5196}
5197
Jamie Madill5b772312018-03-08 20:28:32 -05005198bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005199{
5200 return true;
5201}
5202
Jamie Madill5b772312018-03-08 20:28:32 -05005203bool ValidateDetachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005204{
5205 Program *programObject = GetValidProgram(context, program);
5206 if (!programObject)
5207 {
5208 return false;
5209 }
5210
5211 Shader *shaderObject = GetValidShader(context, shader);
5212 if (!shaderObject)
5213 {
5214 return false;
5215 }
5216
Jiawei Shao385b3e02018-03-21 09:43:28 +08005217 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005218 if (attachedShader != shaderObject)
5219 {
Jamie Madille0472f32018-11-27 16:32:45 -05005220 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005221 return false;
5222 }
5223
5224 return true;
5225}
5226
Jamie Madill5b772312018-03-08 20:28:32 -05005227bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005228{
5229 if (index >= MAX_VERTEX_ATTRIBS)
5230 {
Jamie Madille0472f32018-11-27 16:32:45 -05005231 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005232 return false;
5233 }
5234
5235 return true;
5236}
5237
Jamie Madill5b772312018-03-08 20:28:32 -05005238bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005239{
5240 if (index >= MAX_VERTEX_ATTRIBS)
5241 {
Jamie Madille0472f32018-11-27 16:32:45 -05005242 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005243 return false;
5244 }
5245
5246 return true;
5247}
5248
Jamie Madill5b772312018-03-08 20:28:32 -05005249bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005250{
5251 return true;
5252}
5253
Jamie Madill5b772312018-03-08 20:28:32 -05005254bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005255{
5256 return true;
5257}
5258
Jamie Madill5b772312018-03-08 20:28:32 -05005259bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005260{
5261 switch (mode)
5262 {
5263 case GL_CW:
5264 case GL_CCW:
5265 break;
5266 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005267 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005268 return false;
5269 }
5270
5271 return true;
5272}
5273
Jamie Madill5b772312018-03-08 20:28:32 -05005274bool ValidateGetActiveAttrib(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005275 GLuint program,
5276 GLuint index,
5277 GLsizei bufsize,
5278 GLsizei *length,
5279 GLint *size,
5280 GLenum *type,
5281 GLchar *name)
5282{
5283 if (bufsize < 0)
5284 {
Jamie Madille0472f32018-11-27 16:32:45 -05005285 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005286 return false;
5287 }
5288
5289 Program *programObject = GetValidProgram(context, program);
5290
5291 if (!programObject)
5292 {
5293 return false;
5294 }
5295
5296 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5297 {
Jamie Madille0472f32018-11-27 16:32:45 -05005298 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005299 return false;
5300 }
5301
5302 return true;
5303}
5304
Jamie Madill5b772312018-03-08 20:28:32 -05005305bool ValidateGetActiveUniform(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005306 GLuint program,
5307 GLuint index,
5308 GLsizei bufsize,
5309 GLsizei *length,
5310 GLint *size,
5311 GLenum *type,
5312 GLchar *name)
5313{
5314 if (bufsize < 0)
5315 {
Jamie Madille0472f32018-11-27 16:32:45 -05005316 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005317 return false;
5318 }
5319
5320 Program *programObject = GetValidProgram(context, program);
5321
5322 if (!programObject)
5323 {
5324 return false;
5325 }
5326
5327 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5328 {
Jamie Madille0472f32018-11-27 16:32:45 -05005329 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005330 return false;
5331 }
5332
5333 return true;
5334}
5335
Jamie Madill5b772312018-03-08 20:28:32 -05005336bool ValidateGetAttachedShaders(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005337 GLuint program,
5338 GLsizei maxcount,
5339 GLsizei *count,
5340 GLuint *shaders)
5341{
5342 if (maxcount < 0)
5343 {
Jamie Madille0472f32018-11-27 16:32:45 -05005344 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005345 return false;
5346 }
5347
5348 Program *programObject = GetValidProgram(context, program);
5349
5350 if (!programObject)
5351 {
5352 return false;
5353 }
5354
5355 return true;
5356}
5357
Jamie Madill5b772312018-03-08 20:28:32 -05005358bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005359{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005360 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5361 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005362 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005363 {
Jamie Madille0472f32018-11-27 16:32:45 -05005364 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005365 return false;
5366 }
5367
Jamie Madillc1d770e2017-04-13 17:31:24 -04005368 Program *programObject = GetValidProgram(context, program);
5369
5370 if (!programObject)
5371 {
Jamie Madille0472f32018-11-27 16:32:45 -05005372 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005373 return false;
5374 }
5375
5376 if (!programObject->isLinked())
5377 {
Jamie Madille0472f32018-11-27 16:32:45 -05005378 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005379 return false;
5380 }
5381
5382 return true;
5383}
5384
Jamie Madill5b772312018-03-08 20:28:32 -05005385bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005386{
5387 GLenum nativeType;
5388 unsigned int numParams = 0;
5389 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5390}
5391
Jamie Madill5b772312018-03-08 20:28:32 -05005392bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005393{
5394 return true;
5395}
5396
Jamie Madill5b772312018-03-08 20:28:32 -05005397bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005398{
5399 GLenum nativeType;
5400 unsigned int numParams = 0;
5401 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5402}
5403
Jamie Madill5b772312018-03-08 20:28:32 -05005404bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005405{
5406 GLenum nativeType;
5407 unsigned int numParams = 0;
5408 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5409}
5410
Jamie Madill5b772312018-03-08 20:28:32 -05005411bool ValidateGetProgramInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005412 GLuint program,
5413 GLsizei bufsize,
5414 GLsizei *length,
5415 GLchar *infolog)
5416{
5417 if (bufsize < 0)
5418 {
Jamie Madille0472f32018-11-27 16:32:45 -05005419 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005420 return false;
5421 }
5422
5423 Program *programObject = GetValidProgram(context, program);
5424 if (!programObject)
5425 {
5426 return false;
5427 }
5428
5429 return true;
5430}
5431
Jamie Madill5b772312018-03-08 20:28:32 -05005432bool ValidateGetShaderInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005433 GLuint shader,
5434 GLsizei bufsize,
5435 GLsizei *length,
5436 GLchar *infolog)
5437{
5438 if (bufsize < 0)
5439 {
Jamie Madille0472f32018-11-27 16:32:45 -05005440 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005441 return false;
5442 }
5443
5444 Shader *shaderObject = GetValidShader(context, shader);
5445 if (!shaderObject)
5446 {
5447 return false;
5448 }
5449
5450 return true;
5451}
5452
Jamie Madill5b772312018-03-08 20:28:32 -05005453bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005454 GLenum shadertype,
5455 GLenum precisiontype,
5456 GLint *range,
5457 GLint *precision)
5458{
5459 switch (shadertype)
5460 {
5461 case GL_VERTEX_SHADER:
5462 case GL_FRAGMENT_SHADER:
5463 break;
5464 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005465 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005466 return false;
5467 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005468 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005469 return false;
5470 }
5471
5472 switch (precisiontype)
5473 {
5474 case GL_LOW_FLOAT:
5475 case GL_MEDIUM_FLOAT:
5476 case GL_HIGH_FLOAT:
5477 case GL_LOW_INT:
5478 case GL_MEDIUM_INT:
5479 case GL_HIGH_INT:
5480 break;
5481
5482 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005483 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005484 return false;
5485 }
5486
5487 return true;
5488}
5489
Jamie Madill5b772312018-03-08 20:28:32 -05005490bool ValidateGetShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005491 GLuint shader,
5492 GLsizei bufsize,
5493 GLsizei *length,
5494 GLchar *source)
5495{
5496 if (bufsize < 0)
5497 {
Jamie Madille0472f32018-11-27 16:32:45 -05005498 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005499 return false;
5500 }
5501
5502 Shader *shaderObject = GetValidShader(context, shader);
5503 if (!shaderObject)
5504 {
5505 return false;
5506 }
5507
5508 return true;
5509}
5510
Jamie Madill5b772312018-03-08 20:28:32 -05005511bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005512{
5513 if (strstr(name, "gl_") == name)
5514 {
5515 return false;
5516 }
5517
Geoff Langfc32e8b2017-05-31 14:16:59 -04005518 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5519 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005520 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005521 {
Jamie Madille0472f32018-11-27 16:32:45 -05005522 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005523 return false;
5524 }
5525
Jamie Madillc1d770e2017-04-13 17:31:24 -04005526 Program *programObject = GetValidProgram(context, program);
5527
5528 if (!programObject)
5529 {
5530 return false;
5531 }
5532
5533 if (!programObject->isLinked())
5534 {
Jamie Madille0472f32018-11-27 16:32:45 -05005535 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005536 return false;
5537 }
5538
5539 return true;
5540}
5541
Jamie Madill5b772312018-03-08 20:28:32 -05005542bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005543{
5544 switch (mode)
5545 {
5546 case GL_FASTEST:
5547 case GL_NICEST:
5548 case GL_DONT_CARE:
5549 break;
5550
5551 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005552 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005553 return false;
5554 }
5555
5556 switch (target)
5557 {
5558 case GL_GENERATE_MIPMAP_HINT:
5559 break;
5560
Geoff Lange7bd2182017-06-16 16:13:13 -04005561 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5562 if (context->getClientVersion() < ES_3_0 &&
5563 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005564 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005565 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005566 return false;
5567 }
5568 break;
5569
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005570 case GL_PERSPECTIVE_CORRECTION_HINT:
5571 case GL_POINT_SMOOTH_HINT:
5572 case GL_LINE_SMOOTH_HINT:
5573 case GL_FOG_HINT:
5574 if (context->getClientMajorVersion() >= 2)
5575 {
Jamie Madille0472f32018-11-27 16:32:45 -05005576 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005577 return false;
5578 }
5579 break;
5580
Jamie Madillc1d770e2017-04-13 17:31:24 -04005581 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005582 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005583 return false;
5584 }
5585
5586 return true;
5587}
5588
Jamie Madill5b772312018-03-08 20:28:32 -05005589bool ValidateIsBuffer(Context *context, GLuint buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005590{
5591 return true;
5592}
5593
Jamie Madill5b772312018-03-08 20:28:32 -05005594bool ValidateIsFramebuffer(Context *context, GLuint framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005595{
5596 return true;
5597}
5598
Jamie Madill5b772312018-03-08 20:28:32 -05005599bool ValidateIsProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005600{
5601 return true;
5602}
5603
Jamie Madill5b772312018-03-08 20:28:32 -05005604bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005605{
5606 return true;
5607}
5608
Jamie Madill5b772312018-03-08 20:28:32 -05005609bool ValidateIsShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005610{
5611 return true;
5612}
5613
Jamie Madill5b772312018-03-08 20:28:32 -05005614bool ValidateIsTexture(Context *context, GLuint texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005615{
5616 return true;
5617}
5618
Jamie Madill5b772312018-03-08 20:28:32 -05005619bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005620{
5621 if (context->getClientMajorVersion() < 3)
5622 {
5623 switch (pname)
5624 {
5625 case GL_UNPACK_IMAGE_HEIGHT:
5626 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005627 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005628 return false;
5629
5630 case GL_UNPACK_ROW_LENGTH:
5631 case GL_UNPACK_SKIP_ROWS:
5632 case GL_UNPACK_SKIP_PIXELS:
5633 if (!context->getExtensions().unpackSubimage)
5634 {
Jamie Madille0472f32018-11-27 16:32:45 -05005635 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005636 return false;
5637 }
5638 break;
5639
5640 case GL_PACK_ROW_LENGTH:
5641 case GL_PACK_SKIP_ROWS:
5642 case GL_PACK_SKIP_PIXELS:
5643 if (!context->getExtensions().packSubimage)
5644 {
Jamie Madille0472f32018-11-27 16:32:45 -05005645 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005646 return false;
5647 }
5648 break;
5649 }
5650 }
5651
5652 if (param < 0)
5653 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005654 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005655 return false;
5656 }
5657
5658 switch (pname)
5659 {
5660 case GL_UNPACK_ALIGNMENT:
5661 if (param != 1 && param != 2 && param != 4 && param != 8)
5662 {
Jamie Madille0472f32018-11-27 16:32:45 -05005663 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005664 return false;
5665 }
5666 break;
5667
5668 case GL_PACK_ALIGNMENT:
5669 if (param != 1 && param != 2 && param != 4 && param != 8)
5670 {
Jamie Madille0472f32018-11-27 16:32:45 -05005671 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005672 return false;
5673 }
5674 break;
5675
5676 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005677 if (!context->getExtensions().packReverseRowOrder)
5678 {
Jamie Madille0472f32018-11-27 16:32:45 -05005679 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005680 }
5681 break;
5682
Jamie Madillc1d770e2017-04-13 17:31:24 -04005683 case GL_UNPACK_ROW_LENGTH:
5684 case GL_UNPACK_IMAGE_HEIGHT:
5685 case GL_UNPACK_SKIP_IMAGES:
5686 case GL_UNPACK_SKIP_ROWS:
5687 case GL_UNPACK_SKIP_PIXELS:
5688 case GL_PACK_ROW_LENGTH:
5689 case GL_PACK_SKIP_ROWS:
5690 case GL_PACK_SKIP_PIXELS:
5691 break;
5692
5693 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005694 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005695 return false;
5696 }
5697
5698 return true;
5699}
5700
Jamie Madill5b772312018-03-08 20:28:32 -05005701bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005702{
5703 return true;
5704}
5705
Jamie Madill5b772312018-03-08 20:28:32 -05005706bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005707{
5708 return true;
5709}
5710
Jamie Madill5b772312018-03-08 20:28:32 -05005711bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005712{
5713 return true;
5714}
5715
Jamie Madill5b772312018-03-08 20:28:32 -05005716bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005717{
5718 if (width < 0 || height < 0)
5719 {
Jamie Madille0472f32018-11-27 16:32:45 -05005720 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005721 return false;
5722 }
5723
5724 return true;
5725}
5726
Jamie Madill5b772312018-03-08 20:28:32 -05005727bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005728 GLsizei n,
5729 const GLuint *shaders,
5730 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005731 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005732 GLsizei length)
5733{
5734 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
5735 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
5736 shaderBinaryFormats.end())
5737 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005738 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005739 return false;
5740 }
5741
5742 return true;
5743}
5744
Jamie Madill5b772312018-03-08 20:28:32 -05005745bool ValidateShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005746 GLuint shader,
5747 GLsizei count,
5748 const GLchar *const *string,
5749 const GLint *length)
5750{
5751 if (count < 0)
5752 {
Jamie Madille0472f32018-11-27 16:32:45 -05005753 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005754 return false;
5755 }
5756
Geoff Langfc32e8b2017-05-31 14:16:59 -04005757 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5758 // shader-related entry points
5759 if (context->getExtensions().webglCompatibility)
5760 {
5761 for (GLsizei i = 0; i < count; i++)
5762 {
Geoff Langcab92ee2017-07-19 17:32:07 -04005763 size_t len =
5764 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04005765
5766 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04005767 if (!IsValidESSLShaderSourceString(string[i], len,
5768 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005769 {
Jamie Madille0472f32018-11-27 16:32:45 -05005770 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005771 return false;
5772 }
5773 }
5774 }
5775
Jamie Madillc1d770e2017-04-13 17:31:24 -04005776 Shader *shaderObject = GetValidShader(context, shader);
5777 if (!shaderObject)
5778 {
5779 return false;
5780 }
5781
5782 return true;
5783}
5784
Jamie Madill5b772312018-03-08 20:28:32 -05005785bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005786{
5787 if (!IsValidStencilFunc(func))
5788 {
Jamie Madille0472f32018-11-27 16:32:45 -05005789 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005790 return false;
5791 }
5792
5793 return true;
5794}
5795
Jamie Madill5b772312018-03-08 20:28:32 -05005796bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005797{
5798 if (!IsValidStencilFace(face))
5799 {
Jamie Madille0472f32018-11-27 16:32:45 -05005800 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005801 return false;
5802 }
5803
5804 if (!IsValidStencilFunc(func))
5805 {
Jamie Madille0472f32018-11-27 16:32:45 -05005806 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005807 return false;
5808 }
5809
5810 return true;
5811}
5812
Jamie Madill5b772312018-03-08 20:28:32 -05005813bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005814{
5815 return true;
5816}
5817
Jamie Madill5b772312018-03-08 20:28:32 -05005818bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005819{
5820 if (!IsValidStencilFace(face))
5821 {
Jamie Madille0472f32018-11-27 16:32:45 -05005822 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005823 return false;
5824 }
5825
5826 return true;
5827}
5828
Jamie Madill5b772312018-03-08 20:28:32 -05005829bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005830{
5831 if (!IsValidStencilOp(fail))
5832 {
Jamie Madille0472f32018-11-27 16:32:45 -05005833 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005834 return false;
5835 }
5836
5837 if (!IsValidStencilOp(zfail))
5838 {
Jamie Madille0472f32018-11-27 16:32:45 -05005839 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005840 return false;
5841 }
5842
5843 if (!IsValidStencilOp(zpass))
5844 {
Jamie Madille0472f32018-11-27 16:32:45 -05005845 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005846 return false;
5847 }
5848
5849 return true;
5850}
5851
Jamie Madill5b772312018-03-08 20:28:32 -05005852bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005853 GLenum face,
5854 GLenum fail,
5855 GLenum zfail,
5856 GLenum zpass)
5857{
5858 if (!IsValidStencilFace(face))
5859 {
Jamie Madille0472f32018-11-27 16:32:45 -05005860 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005861 return false;
5862 }
5863
5864 return ValidateStencilOp(context, fail, zfail, zpass);
5865}
5866
Jamie Madill5b772312018-03-08 20:28:32 -05005867bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005868{
5869 return ValidateUniform(context, GL_FLOAT, location, 1);
5870}
5871
Jamie Madill5b772312018-03-08 20:28:32 -05005872bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005873{
5874 return ValidateUniform(context, GL_FLOAT, location, count);
5875}
5876
Jamie Madill5b772312018-03-08 20:28:32 -05005877bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04005878{
5879 return ValidateUniform1iv(context, location, 1, &x);
5880}
5881
Jamie Madill5b772312018-03-08 20:28:32 -05005882bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005883{
5884 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
5885}
5886
Jamie Madill5b772312018-03-08 20:28:32 -05005887bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005888{
5889 return ValidateUniform(context, GL_INT_VEC2, location, 1);
5890}
5891
Jamie Madill5b772312018-03-08 20:28:32 -05005892bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005893{
5894 return ValidateUniform(context, GL_INT_VEC2, location, count);
5895}
5896
Jamie Madill5b772312018-03-08 20:28:32 -05005897bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005898{
5899 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
5900}
5901
Jamie Madill5b772312018-03-08 20:28:32 -05005902bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005903{
5904 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
5905}
5906
Jamie Madill5b772312018-03-08 20:28:32 -05005907bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005908{
5909 return ValidateUniform(context, GL_INT_VEC3, location, 1);
5910}
5911
Jamie Madill5b772312018-03-08 20:28:32 -05005912bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005913{
5914 return ValidateUniform(context, GL_INT_VEC3, location, count);
5915}
5916
Jamie Madill5b772312018-03-08 20:28:32 -05005917bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005918{
5919 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
5920}
5921
Jamie Madill5b772312018-03-08 20:28:32 -05005922bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005923{
5924 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
5925}
5926
Jamie Madill5b772312018-03-08 20:28:32 -05005927bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005928{
5929 return ValidateUniform(context, GL_INT_VEC4, location, 1);
5930}
5931
Jamie Madill5b772312018-03-08 20:28:32 -05005932bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005933{
5934 return ValidateUniform(context, GL_INT_VEC4, location, count);
5935}
5936
Jamie Madill5b772312018-03-08 20:28:32 -05005937bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005938 GLint location,
5939 GLsizei count,
5940 GLboolean transpose,
5941 const GLfloat *value)
5942{
5943 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
5944}
5945
Jamie Madill5b772312018-03-08 20:28:32 -05005946bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005947 GLint location,
5948 GLsizei count,
5949 GLboolean transpose,
5950 const GLfloat *value)
5951{
5952 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
5953}
5954
Jamie Madill5b772312018-03-08 20:28:32 -05005955bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005956 GLint location,
5957 GLsizei count,
5958 GLboolean transpose,
5959 const GLfloat *value)
5960{
5961 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
5962}
5963
Jamie Madill5b772312018-03-08 20:28:32 -05005964bool ValidateValidateProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005965{
5966 Program *programObject = GetValidProgram(context, program);
5967
5968 if (!programObject)
5969 {
5970 return false;
5971 }
5972
5973 return true;
5974}
5975
Jamie Madill5b772312018-03-08 20:28:32 -05005976bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005977{
5978 return ValidateVertexAttribIndex(context, index);
5979}
5980
Jamie Madill5b772312018-03-08 20:28:32 -05005981bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005982{
5983 return ValidateVertexAttribIndex(context, index);
5984}
5985
Jamie Madill5b772312018-03-08 20:28:32 -05005986bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005987{
5988 return ValidateVertexAttribIndex(context, index);
5989}
5990
Jamie Madill5b772312018-03-08 20:28:32 -05005991bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005992{
5993 return ValidateVertexAttribIndex(context, index);
5994}
5995
Jamie Madill5b772312018-03-08 20:28:32 -05005996bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005997{
5998 return ValidateVertexAttribIndex(context, index);
5999}
6000
Jamie Madill5b772312018-03-08 20:28:32 -05006001bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006002{
6003 return ValidateVertexAttribIndex(context, index);
6004}
6005
Jamie Madill5b772312018-03-08 20:28:32 -05006006bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006007 GLuint index,
6008 GLfloat x,
6009 GLfloat y,
6010 GLfloat z,
6011 GLfloat w)
6012{
6013 return ValidateVertexAttribIndex(context, index);
6014}
6015
Jamie Madill5b772312018-03-08 20:28:32 -05006016bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006017{
6018 return ValidateVertexAttribIndex(context, index);
6019}
6020
Jamie Madill5b772312018-03-08 20:28:32 -05006021bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006022{
6023 if (width < 0 || height < 0)
6024 {
Jamie Madille0472f32018-11-27 16:32:45 -05006025 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006026 return false;
6027 }
6028
6029 return true;
6030}
6031
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08006032bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006033 GLenum target,
6034 GLenum attachment,
6035 GLenum pname,
6036 GLint *params)
6037{
6038 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
6039 nullptr);
6040}
6041
Jamie Madill5b772312018-03-08 20:28:32 -05006042bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006043{
6044 return ValidateGetProgramivBase(context, program, pname, nullptr);
6045}
6046
Jamie Madill5b772312018-03-08 20:28:32 -05006047bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006048 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006049 GLint level,
6050 GLenum internalformat,
6051 GLint x,
6052 GLint y,
6053 GLsizei width,
6054 GLsizei height,
6055 GLint border)
6056{
6057 if (context->getClientMajorVersion() < 3)
6058 {
6059 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
6060 0, x, y, width, height, border);
6061 }
6062
6063 ASSERT(context->getClientMajorVersion() == 3);
6064 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
6065 0, x, y, width, height, border);
6066}
6067
6068bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006069 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006070 GLint level,
6071 GLint xoffset,
6072 GLint yoffset,
6073 GLint x,
6074 GLint y,
6075 GLsizei width,
6076 GLsizei height)
6077{
6078 if (context->getClientMajorVersion() < 3)
6079 {
6080 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
6081 yoffset, x, y, width, height, 0);
6082 }
6083
6084 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
6085 yoffset, 0, x, y, width, height, 0);
6086}
6087
6088bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *)
6089{
6090 return ValidateGenOrDelete(context, n);
6091}
6092
6093bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *)
6094{
6095 return ValidateGenOrDelete(context, n);
6096}
6097
6098bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *)
6099{
6100 return ValidateGenOrDelete(context, n);
6101}
6102
6103bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *)
6104{
6105 return ValidateGenOrDelete(context, n);
6106}
6107
6108bool ValidateDisable(Context *context, GLenum cap)
6109{
6110 if (!ValidCap(context, cap, false))
6111 {
Jamie Madille0472f32018-11-27 16:32:45 -05006112 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006113 return false;
6114 }
6115
6116 return true;
6117}
6118
6119bool ValidateEnable(Context *context, GLenum cap)
6120{
6121 if (!ValidCap(context, cap, false))
6122 {
Jamie Madille0472f32018-11-27 16:32:45 -05006123 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006124 return false;
6125 }
6126
6127 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6128 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6129 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006130 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006131
6132 // We also output an error message to the debugger window if tracing is active, so that
6133 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006134 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006135 return false;
6136 }
6137
6138 return true;
6139}
6140
6141bool ValidateFramebufferRenderbuffer(Context *context,
6142 GLenum target,
6143 GLenum attachment,
6144 GLenum renderbuffertarget,
6145 GLuint renderbuffer)
6146{
Geoff Lange8afa902017-09-27 15:00:43 -04006147 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006148 {
Jamie Madille0472f32018-11-27 16:32:45 -05006149 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006150 return false;
6151 }
6152
6153 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)
6154 {
Jamie Madille0472f32018-11-27 16:32:45 -05006155 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006156 return false;
6157 }
6158
6159 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6160 renderbuffertarget, renderbuffer);
6161}
6162
6163bool ValidateFramebufferTexture2D(Context *context,
6164 GLenum target,
6165 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006166 TextureTarget textarget,
Jamie Madillbe849e42017-05-02 15:49:00 -04006167 GLuint texture,
6168 GLint level)
6169{
6170 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6171 // extension
6172 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6173 level != 0)
6174 {
Jamie Madille0472f32018-11-27 16:32:45 -05006175 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006176 return false;
6177 }
6178
6179 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6180 {
6181 return false;
6182 }
6183
6184 if (texture != 0)
6185 {
6186 gl::Texture *tex = context->getTexture(texture);
6187 ASSERT(tex);
6188
6189 const gl::Caps &caps = context->getCaps();
6190
6191 switch (textarget)
6192 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006193 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006194 {
6195 if (level > gl::log2(caps.max2DTextureSize))
6196 {
Jamie Madille0472f32018-11-27 16:32:45 -05006197 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006198 return false;
6199 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006200 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006201 {
Jamie Madille0472f32018-11-27 16:32:45 -05006202 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006203 return false;
6204 }
6205 }
6206 break;
6207
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006208 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006209 {
6210 if (level != 0)
6211 {
Jamie Madille0472f32018-11-27 16:32:45 -05006212 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006213 return false;
6214 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006215 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006216 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006217 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006218 return false;
6219 }
6220 }
6221 break;
6222
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006223 case TextureTarget::CubeMapNegativeX:
6224 case TextureTarget::CubeMapNegativeY:
6225 case TextureTarget::CubeMapNegativeZ:
6226 case TextureTarget::CubeMapPositiveX:
6227 case TextureTarget::CubeMapPositiveY:
6228 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006229 {
6230 if (level > gl::log2(caps.maxCubeMapTextureSize))
6231 {
Jamie Madille0472f32018-11-27 16:32:45 -05006232 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006233 return false;
6234 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006235 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006236 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006237 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006238 return false;
6239 }
6240 }
6241 break;
6242
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006243 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006244 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006245 if (context->getClientVersion() < ES_3_1 &&
6246 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006247 {
Jamie Madill610640f2018-11-21 17:28:41 -05006248 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006249 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006250 return false;
6251 }
6252
6253 if (level != 0)
6254 {
Jamie Madille0472f32018-11-27 16:32:45 -05006255 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006256 return false;
6257 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006258 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006259 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006260 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006261 return false;
6262 }
6263 }
6264 break;
6265
6266 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006267 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006268 return false;
6269 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006270 }
6271
6272 return true;
6273}
6274
6275bool ValidateGenBuffers(Context *context, GLint n, GLuint *)
6276{
6277 return ValidateGenOrDelete(context, n);
6278}
6279
6280bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *)
6281{
6282 return ValidateGenOrDelete(context, n);
6283}
6284
6285bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *)
6286{
6287 return ValidateGenOrDelete(context, n);
6288}
6289
6290bool ValidateGenTextures(Context *context, GLint n, GLuint *)
6291{
6292 return ValidateGenOrDelete(context, n);
6293}
6294
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006295bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006296{
6297 if (!ValidTextureTarget(context, target))
6298 {
Jamie Madille0472f32018-11-27 16:32:45 -05006299 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006300 return false;
6301 }
6302
Jamie Madillcfc73cc2019-04-08 16:26:51 -04006303 Texture *texture = context->getTextureByType(target);
Jamie Madillbe849e42017-05-02 15:49:00 -04006304
6305 if (texture == nullptr)
6306 {
Jamie Madille0472f32018-11-27 16:32:45 -05006307 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006308 return false;
6309 }
6310
6311 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6312
6313 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6314 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6315 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6316 {
Jamie Madille0472f32018-11-27 16:32:45 -05006317 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006318 return false;
6319 }
6320
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006321 TextureTarget baseTarget = (target == TextureType::CubeMap)
6322 ? TextureTarget::CubeMapPositiveX
6323 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006324 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6325 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6326 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006327 {
Jamie Madille0472f32018-11-27 16:32:45 -05006328 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006329 return false;
6330 }
6331
Geoff Lang536eca12017-09-13 11:23:35 -04006332 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6333 bool formatUnsized = !format.sized;
6334 bool formatColorRenderableAndFilterable =
6335 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006336 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006337 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006338 {
Jamie Madille0472f32018-11-27 16:32:45 -05006339 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006340 return false;
6341 }
6342
Geoff Lang536eca12017-09-13 11:23:35 -04006343 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6344 // generation
6345 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6346 {
Jamie Madille0472f32018-11-27 16:32:45 -05006347 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006348 return false;
6349 }
6350
Jiange2c00842018-07-13 16:50:49 +08006351 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6352 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6353 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006354 {
Jamie Madille0472f32018-11-27 16:32:45 -05006355 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006356 return false;
6357 }
6358
6359 // Non-power of 2 ES2 check
6360 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6361 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6362 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6363 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006364 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6365 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006366 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006367 return false;
6368 }
6369
6370 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006371 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006372 {
Jamie Madille0472f32018-11-27 16:32:45 -05006373 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006374 return false;
6375 }
6376
James Darpinian83b2f0e2018-11-27 15:56:01 -08006377 if (context->getExtensions().webglCompatibility &&
6378 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6379 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6380 {
6381 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6382 return false;
6383 }
6384
Jamie Madillbe849e42017-05-02 15:49:00 -04006385 return true;
6386}
6387
Jamie Madill5b772312018-03-08 20:28:32 -05006388bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006389 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006390 GLenum pname,
6391 GLint *params)
6392{
6393 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6394}
6395
6396bool ValidateGetRenderbufferParameteriv(Context *context,
6397 GLenum target,
6398 GLenum pname,
6399 GLint *params)
6400{
6401 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6402}
6403
6404bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params)
6405{
6406 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6407}
6408
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006409bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006410{
6411 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6412}
6413
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006414bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006415{
6416 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6417}
6418
Till Rathmannb8543632018-10-02 19:46:14 +02006419bool ValidateGetTexParameterIivOES(Context *context,
6420 TextureType target,
6421 GLenum pname,
6422 GLint *params)
6423{
6424 if (context->getClientMajorVersion() < 3)
6425 {
Jamie Madille0472f32018-11-27 16:32:45 -05006426 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006427 return false;
6428 }
6429 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6430}
6431
6432bool ValidateGetTexParameterIuivOES(Context *context,
6433 TextureType target,
6434 GLenum pname,
6435 GLuint *params)
6436{
6437 if (context->getClientMajorVersion() < 3)
6438 {
Jamie Madille0472f32018-11-27 16:32:45 -05006439 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006440 return false;
6441 }
6442 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6443}
6444
Jamie Madillbe849e42017-05-02 15:49:00 -04006445bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params)
6446{
6447 return ValidateGetUniformBase(context, program, location);
6448}
6449
6450bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params)
6451{
6452 return ValidateGetUniformBase(context, program, location);
6453}
6454
6455bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6456{
6457 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6458}
6459
6460bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6461{
6462 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6463}
6464
6465bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6466{
6467 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6468}
6469
6470bool ValidateIsEnabled(Context *context, GLenum cap)
6471{
6472 if (!ValidCap(context, cap, true))
6473 {
Jamie Madille0472f32018-11-27 16:32:45 -05006474 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006475 return false;
6476 }
6477
6478 return true;
6479}
6480
6481bool ValidateLinkProgram(Context *context, GLuint program)
6482{
6483 if (context->hasActiveTransformFeedback(program))
6484 {
6485 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006486 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006487 return false;
6488 }
6489
6490 Program *programObject = GetValidProgram(context, program);
6491 if (!programObject)
6492 {
6493 return false;
6494 }
6495
6496 return true;
6497}
6498
Jamie Madill4928b7c2017-06-20 12:57:39 -04006499bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006500 GLint x,
6501 GLint y,
6502 GLsizei width,
6503 GLsizei height,
6504 GLenum format,
6505 GLenum type,
6506 void *pixels)
6507{
6508 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6509 nullptr, pixels);
6510}
6511
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006512bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006513{
Till Rathmannb8543632018-10-02 19:46:14 +02006514 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006515}
6516
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006517bool ValidateTexParameterfv(Context *context,
6518 TextureType target,
6519 GLenum pname,
6520 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006521{
Till Rathmannb8543632018-10-02 19:46:14 +02006522 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006523}
6524
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006525bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006526{
Till Rathmannb8543632018-10-02 19:46:14 +02006527 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006528}
6529
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006530bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006531{
Till Rathmannb8543632018-10-02 19:46:14 +02006532 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6533}
6534
6535bool ValidateTexParameterIivOES(Context *context,
6536 TextureType target,
6537 GLenum pname,
6538 const GLint *params)
6539{
6540 if (context->getClientMajorVersion() < 3)
6541 {
Jamie Madille0472f32018-11-27 16:32:45 -05006542 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006543 return false;
6544 }
6545 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6546}
6547
6548bool ValidateTexParameterIuivOES(Context *context,
6549 TextureType target,
6550 GLenum pname,
6551 const GLuint *params)
6552{
6553 if (context->getClientMajorVersion() < 3)
6554 {
Jamie Madille0472f32018-11-27 16:32:45 -05006555 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006556 return false;
6557 }
6558 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006559}
6560
6561bool ValidateUseProgram(Context *context, GLuint program)
6562{
6563 if (program != 0)
6564 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006565 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006566 if (!programObject)
6567 {
6568 // ES 3.1.0 section 7.3 page 72
6569 if (context->getShader(program))
6570 {
Jamie Madille0472f32018-11-27 16:32:45 -05006571 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006572 return false;
6573 }
6574 else
6575 {
Jamie Madille0472f32018-11-27 16:32:45 -05006576 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006577 return false;
6578 }
6579 }
6580 if (!programObject->isLinked())
6581 {
Jamie Madille0472f32018-11-27 16:32:45 -05006582 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006583 return false;
6584 }
6585 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006586 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006587 {
6588 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006589 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006590 return false;
6591 }
6592
6593 return true;
6594}
6595
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006596bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences)
6597{
6598 if (!context->getExtensions().fence)
6599 {
Jamie Madille0472f32018-11-27 16:32:45 -05006600 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006601 return false;
6602 }
6603
6604 if (n < 0)
6605 {
Jamie Madille0472f32018-11-27 16:32:45 -05006606 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006607 return false;
6608 }
6609
6610 return true;
6611}
6612
6613bool ValidateFinishFenceNV(Context *context, GLuint fence)
6614{
6615 if (!context->getExtensions().fence)
6616 {
Jamie Madille0472f32018-11-27 16:32:45 -05006617 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006618 return false;
6619 }
6620
6621 FenceNV *fenceObject = context->getFenceNV(fence);
6622
6623 if (fenceObject == nullptr)
6624 {
Jamie Madille0472f32018-11-27 16:32:45 -05006625 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006626 return false;
6627 }
6628
6629 if (!fenceObject->isSet())
6630 {
Jamie Madille0472f32018-11-27 16:32:45 -05006631 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006632 return false;
6633 }
6634
6635 return true;
6636}
6637
6638bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences)
6639{
6640 if (!context->getExtensions().fence)
6641 {
Jamie Madille0472f32018-11-27 16:32:45 -05006642 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006643 return false;
6644 }
6645
6646 if (n < 0)
6647 {
Jamie Madille0472f32018-11-27 16:32:45 -05006648 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006649 return false;
6650 }
6651
6652 return true;
6653}
6654
6655bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params)
6656{
6657 if (!context->getExtensions().fence)
6658 {
Jamie Madille0472f32018-11-27 16:32:45 -05006659 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006660 return false;
6661 }
6662
6663 FenceNV *fenceObject = context->getFenceNV(fence);
6664
6665 if (fenceObject == nullptr)
6666 {
Jamie Madille0472f32018-11-27 16:32:45 -05006667 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006668 return false;
6669 }
6670
6671 if (!fenceObject->isSet())
6672 {
Jamie Madille0472f32018-11-27 16:32:45 -05006673 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006674 return false;
6675 }
6676
6677 switch (pname)
6678 {
6679 case GL_FENCE_STATUS_NV:
6680 case GL_FENCE_CONDITION_NV:
6681 break;
6682
6683 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006684 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006685 return false;
6686 }
6687
6688 return true;
6689}
6690
6691bool ValidateGetGraphicsResetStatusEXT(Context *context)
6692{
6693 if (!context->getExtensions().robustness)
6694 {
Jamie Madille0472f32018-11-27 16:32:45 -05006695 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006696 return false;
6697 }
6698
6699 return true;
6700}
6701
6702bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
6703 GLuint shader,
6704 GLsizei bufsize,
6705 GLsizei *length,
6706 GLchar *source)
6707{
6708 if (!context->getExtensions().translatedShaderSource)
6709 {
Jamie Madille0472f32018-11-27 16:32:45 -05006710 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006711 return false;
6712 }
6713
6714 if (bufsize < 0)
6715 {
Jamie Madille0472f32018-11-27 16:32:45 -05006716 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006717 return false;
6718 }
6719
6720 Shader *shaderObject = context->getShader(shader);
6721
6722 if (!shaderObject)
6723 {
Jamie Madille0472f32018-11-27 16:32:45 -05006724 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006725 return false;
6726 }
6727
6728 return true;
6729}
6730
6731bool ValidateIsFenceNV(Context *context, GLuint fence)
6732{
6733 if (!context->getExtensions().fence)
6734 {
Jamie Madille0472f32018-11-27 16:32:45 -05006735 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006736 return false;
6737 }
6738
6739 return true;
6740}
6741
Jamie Madill007530e2017-12-28 14:27:04 -05006742bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition)
6743{
6744 if (!context->getExtensions().fence)
6745 {
Jamie Madille0472f32018-11-27 16:32:45 -05006746 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006747 return false;
6748 }
6749
6750 if (condition != GL_ALL_COMPLETED_NV)
6751 {
Jamie Madille0472f32018-11-27 16:32:45 -05006752 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05006753 return false;
6754 }
6755
6756 FenceNV *fenceObject = context->getFenceNV(fence);
6757
6758 if (fenceObject == nullptr)
6759 {
Jamie Madille0472f32018-11-27 16:32:45 -05006760 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006761 return false;
6762 }
6763
6764 return true;
6765}
6766
6767bool ValidateTestFenceNV(Context *context, GLuint fence)
6768{
6769 if (!context->getExtensions().fence)
6770 {
Jamie Madille0472f32018-11-27 16:32:45 -05006771 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006772 return false;
6773 }
6774
6775 FenceNV *fenceObject = context->getFenceNV(fence);
6776
6777 if (fenceObject == nullptr)
6778 {
Jamie Madille0472f32018-11-27 16:32:45 -05006779 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006780 return false;
6781 }
6782
6783 if (fenceObject->isSet() != GL_TRUE)
6784 {
Jamie Madille0472f32018-11-27 16:32:45 -05006785 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05006786 return false;
6787 }
6788
6789 return true;
6790}
6791
6792bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006793 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05006794 GLsizei levels,
6795 GLenum internalformat,
6796 GLsizei width,
6797 GLsizei height)
6798{
6799 if (!context->getExtensions().textureStorage)
6800 {
Jamie Madille0472f32018-11-27 16:32:45 -05006801 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006802 return false;
6803 }
6804
6805 if (context->getClientMajorVersion() < 3)
6806 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006807 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05006808 height);
6809 }
6810
6811 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006812 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05006813 1);
6814}
6815
6816bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
6817{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006818 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05006819 {
Jamie Madille0472f32018-11-27 16:32:45 -05006820 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006821 return false;
6822 }
6823
6824 if (index >= MAX_VERTEX_ATTRIBS)
6825 {
Jamie Madille0472f32018-11-27 16:32:45 -05006826 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05006827 return false;
6828 }
6829
6830 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
6831 {
6832 if (index == 0 && divisor != 0)
6833 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006834 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05006835
6836 // We also output an error message to the debugger window if tracing is active, so
6837 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006838 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05006839 return false;
6840 }
6841 }
6842
6843 return true;
6844}
6845
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006846bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
6847{
6848 if (!context->getExtensions().instancedArraysEXT)
6849 {
6850 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6851 return false;
6852 }
6853
6854 if (index >= MAX_VERTEX_ATTRIBS)
6855 {
6856 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
6857 return false;
6858 }
6859
6860 return true;
6861}
6862
Jamie Madill007530e2017-12-28 14:27:04 -05006863bool ValidateTexImage3DOES(Context *context,
6864 GLenum target,
6865 GLint level,
6866 GLenum internalformat,
6867 GLsizei width,
6868 GLsizei height,
6869 GLsizei depth,
6870 GLint border,
6871 GLenum format,
6872 GLenum type,
6873 const void *pixels)
6874{
6875 UNIMPLEMENTED(); // FIXME
6876 return false;
6877}
6878
6879bool ValidatePopGroupMarkerEXT(Context *context)
6880{
6881 if (!context->getExtensions().debugMarker)
6882 {
6883 // The debug marker calls should not set error state
6884 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05006885 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006886 return false;
6887 }
6888
6889 return true;
6890}
6891
Jamie Madillfa920eb2018-01-04 11:45:50 -05006892bool ValidateTexStorage1DEXT(Context *context,
6893 GLenum target,
6894 GLsizei levels,
6895 GLenum internalformat,
6896 GLsizei width)
6897{
6898 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05006899 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006900 return false;
6901}
6902
6903bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006904 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05006905 GLsizei levels,
6906 GLenum internalformat,
6907 GLsizei width,
6908 GLsizei height,
6909 GLsizei depth)
6910{
6911 if (!context->getExtensions().textureStorage)
6912 {
Jamie Madille0472f32018-11-27 16:32:45 -05006913 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006914 return false;
6915 }
6916
6917 if (context->getClientMajorVersion() < 3)
6918 {
Jamie Madille0472f32018-11-27 16:32:45 -05006919 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006920 return false;
6921 }
6922
6923 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
6924 depth);
6925}
6926
jchen1082af6202018-06-22 10:59:52 +08006927bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
6928{
6929 if (!context->getExtensions().parallelShaderCompile)
6930 {
Jamie Madille0472f32018-11-27 16:32:45 -05006931 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08006932 return false;
6933 }
6934 return true;
6935}
6936
Austin Eng1bf18ce2018-10-19 15:34:02 -07006937bool ValidateMultiDrawArraysANGLE(Context *context,
6938 PrimitiveMode mode,
6939 const GLint *firsts,
6940 const GLsizei *counts,
6941 GLsizei drawcount)
6942{
6943 if (!context->getExtensions().multiDraw)
6944 {
Jamie Madille0472f32018-11-27 16:32:45 -05006945 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07006946 return false;
6947 }
6948 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
6949 {
6950 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
6951 {
6952 return false;
6953 }
6954 }
6955 return true;
6956}
6957
6958bool ValidateMultiDrawElementsANGLE(Context *context,
6959 PrimitiveMode mode,
6960 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05006961 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08006962 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07006963 GLsizei drawcount)
6964{
6965 if (!context->getExtensions().multiDraw)
6966 {
Jamie Madille0472f32018-11-27 16:32:45 -05006967 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07006968 return false;
6969 }
6970 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
6971 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08006972 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07006973 {
6974 return false;
6975 }
6976 }
6977 return true;
6978}
6979
Jeff Gilbert465d6092019-01-02 16:21:18 -08006980bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked)
6981{
6982 if (!context->getExtensions().provokingVertex)
6983 {
6984 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6985 return false;
6986 }
6987
6988 switch (modePacked)
6989 {
6990 case ProvokingVertex::FirstVertexConvention:
6991 case ProvokingVertex::LastVertexConvention:
6992 break;
6993 default:
6994 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
6995 return false;
6996 }
6997
6998 return true;
6999}
7000
Jamie Madilla5410482019-01-31 19:55:55 -05007001void RecordBindTextureTypeError(Context *context, TextureType target)
7002{
7003 ASSERT(!context->getStateCache().isValidBindTextureType(target));
7004
7005 switch (target)
7006 {
7007 case TextureType::Rectangle:
7008 ASSERT(!context->getExtensions().textureRectangle);
7009 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
7010 break;
7011
7012 case TextureType::_3D:
7013 case TextureType::_2DArray:
7014 ASSERT(context->getClientMajorVersion() < 3);
7015 context->validationError(GL_INVALID_ENUM, kES3Required);
7016 break;
7017
7018 case TextureType::_2DMultisample:
7019 ASSERT(context->getClientVersion() < Version(3, 1) &&
7020 !context->getExtensions().textureMultisample);
7021 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
7022 break;
7023
7024 case TextureType::_2DMultisampleArray:
7025 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
7026 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
7027 break;
7028
7029 case TextureType::External:
7030 ASSERT(!context->getExtensions().eglImageExternal &&
7031 !context->getExtensions().eglStreamConsumerExternal);
7032 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
7033 break;
7034
7035 default:
7036 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
7037 }
7038}
7039
Jamie Madillc29968b2016-01-20 11:17:23 -05007040} // namespace gl