blob: 0a2f9c7db92b7f5108305e28303e0091a98af902 [file] [log] [blame]
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
Geoff Lange8ebe7f2013-08-05 15:03:13 -04003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// validationES2.cpp: Validation functions for OpenGL ES 2.0 entry point parameters
8
Jamie Madill778bf092018-11-14 09:54:36 -05009#include "libANGLE/validationES2_autogen.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030010
11#include <cstdint>
12
Geoff Lange8ebe7f2013-08-05 15:03:13 -040013#include "common/mathutil.h"
Sami Väisänen46eaa942016-06-29 10:26:37 +030014#include "common/string_utils.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040015#include "common/utilities.h"
Jamie Madillef300b12016-10-07 15:12:09 -040016#include "libANGLE/Context.h"
Brandon Jones6cad5662017-06-14 13:25:13 -070017#include "libANGLE/ErrorStrings.h"
Jamie Madill2b7bbc22017-12-21 17:30:38 -050018#include "libANGLE/Fence.h"
Jamie Madillef300b12016-10-07 15:12:09 -040019#include "libANGLE/Framebuffer.h"
20#include "libANGLE/FramebufferAttachment.h"
21#include "libANGLE/Renderbuffer.h"
22#include "libANGLE/Shader.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040023#include "libANGLE/Texture.h"
Jamie Madillef300b12016-10-07 15:12:09 -040024#include "libANGLE/Uniform.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040025#include "libANGLE/VertexArray.h"
Jamie Madillef300b12016-10-07 15:12:09 -040026#include "libANGLE/formatutils.h"
27#include "libANGLE/validationES.h"
Jamie Madill778bf092018-11-14 09:54:36 -050028#include "libANGLE/validationES2.h"
29#include "libANGLE/validationES3_autogen.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040030
31namespace gl
32{
Jamie Madille0472f32018-11-27 16:32:45 -050033using namespace err;
Geoff Lange8ebe7f2013-08-05 15:03:13 -040034
Jamie Madillc29968b2016-01-20 11:17:23 -050035namespace
36{
37
38bool IsPartialBlit(gl::Context *context,
39 const FramebufferAttachment *readBuffer,
40 const FramebufferAttachment *writeBuffer,
41 GLint srcX0,
42 GLint srcY0,
43 GLint srcX1,
44 GLint srcY1,
45 GLint dstX0,
46 GLint dstY0,
47 GLint dstX1,
48 GLint dstY1)
49{
50 const Extents &writeSize = writeBuffer->getSize();
51 const Extents &readSize = readBuffer->getSize();
52
53 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width ||
54 dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height)
55 {
56 return true;
57 }
58
Jamie Madillc3dc5d42018-12-30 12:12:04 -050059 if (context->getState().isScissorTestEnabled())
Jamie Madillc29968b2016-01-20 11:17:23 -050060 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -050061 const Rectangle &scissor = context->getState().getScissor();
Jamie Madillc29968b2016-01-20 11:17:23 -050062 return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width ||
63 scissor.height < writeSize.height;
64 }
65
66 return false;
67}
68
Sami Väisänend59ca052016-06-21 16:10:00 +030069template <typename T>
70bool ValidatePathInstances(gl::Context *context,
71 GLsizei numPaths,
72 const void *paths,
73 GLuint pathBase)
74{
75 const auto *array = static_cast<const T *>(paths);
76
77 for (GLsizei i = 0; i < numPaths; ++i)
78 {
79 const GLuint pathName = array[i] + pathBase;
Brandon Jones59770802018-04-02 13:18:42 -070080 if (context->isPathGenerated(pathName) && !context->isPath(pathName))
Sami Väisänend59ca052016-06-21 16:10:00 +030081 {
Jamie Madille0472f32018-11-27 16:32:45 -050082 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänend59ca052016-06-21 16:10:00 +030083 return false;
84 }
85 }
86 return true;
87}
88
89bool ValidateInstancedPathParameters(gl::Context *context,
90 GLsizei numPaths,
91 GLenum pathNameType,
92 const void *paths,
93 GLuint pathBase,
94 GLenum transformType,
95 const GLfloat *transformValues)
96{
97 if (!context->getExtensions().pathRendering)
98 {
Jamie Madillc3e37312018-11-30 15:25:39 -050099 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänend59ca052016-06-21 16:10:00 +0300100 return false;
101 }
102
103 if (paths == nullptr)
104 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500105 context->validationError(GL_INVALID_VALUE, kInvalidPathNameArray);
Sami Väisänend59ca052016-06-21 16:10:00 +0300106 return false;
107 }
108
109 if (numPaths < 0)
110 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500111 context->validationError(GL_INVALID_VALUE, kInvalidPathNumPaths);
Sami Väisänend59ca052016-06-21 16:10:00 +0300112 return false;
113 }
114
115 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths))
116 {
Jamie Madille0472f32018-11-27 16:32:45 -0500117 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänend59ca052016-06-21 16:10:00 +0300118 return false;
119 }
120
121 std::uint32_t pathNameTypeSize = 0;
122 std::uint32_t componentCount = 0;
123
124 switch (pathNameType)
125 {
126 case GL_UNSIGNED_BYTE:
127 pathNameTypeSize = sizeof(GLubyte);
128 if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase))
129 return false;
130 break;
131
132 case GL_BYTE:
133 pathNameTypeSize = sizeof(GLbyte);
134 if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase))
135 return false;
136 break;
137
138 case GL_UNSIGNED_SHORT:
139 pathNameTypeSize = sizeof(GLushort);
140 if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase))
141 return false;
142 break;
143
144 case GL_SHORT:
145 pathNameTypeSize = sizeof(GLshort);
146 if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase))
147 return false;
148 break;
149
150 case GL_UNSIGNED_INT:
151 pathNameTypeSize = sizeof(GLuint);
152 if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase))
153 return false;
154 break;
155
156 case GL_INT:
157 pathNameTypeSize = sizeof(GLint);
158 if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase))
159 return false;
160 break;
161
162 default:
Jamie Madillc3e37312018-11-30 15:25:39 -0500163 context->validationError(GL_INVALID_ENUM, kInvalidPathNameType);
Sami Väisänend59ca052016-06-21 16:10:00 +0300164 return false;
165 }
166
167 switch (transformType)
168 {
169 case GL_NONE:
170 componentCount = 0;
171 break;
172 case GL_TRANSLATE_X_CHROMIUM:
173 case GL_TRANSLATE_Y_CHROMIUM:
174 componentCount = 1;
175 break;
176 case GL_TRANSLATE_2D_CHROMIUM:
177 componentCount = 2;
178 break;
179 case GL_TRANSLATE_3D_CHROMIUM:
180 componentCount = 3;
181 break;
182 case GL_AFFINE_2D_CHROMIUM:
183 case GL_TRANSPOSE_AFFINE_2D_CHROMIUM:
184 componentCount = 6;
185 break;
186 case GL_AFFINE_3D_CHROMIUM:
187 case GL_TRANSPOSE_AFFINE_3D_CHROMIUM:
188 componentCount = 12;
189 break;
190 default:
Jamie Madillc3e37312018-11-30 15:25:39 -0500191 context->validationError(GL_INVALID_ENUM, kInvalidTransformation);
Sami Väisänend59ca052016-06-21 16:10:00 +0300192 return false;
193 }
194 if (componentCount != 0 && transformValues == nullptr)
195 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500196 context->validationError(GL_INVALID_VALUE, kNoTransformArray);
Sami Väisänend59ca052016-06-21 16:10:00 +0300197 return false;
198 }
199
200 angle::CheckedNumeric<std::uint32_t> checkedSize(0);
201 checkedSize += (numPaths * pathNameTypeSize);
202 checkedSize += (numPaths * sizeof(GLfloat) * componentCount);
203 if (!checkedSize.IsValid())
204 {
Jamie Madille0472f32018-11-27 16:32:45 -0500205 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänend59ca052016-06-21 16:10:00 +0300206 return false;
207 }
208
209 return true;
210}
211
Geoff Lang4f0e0032017-05-01 16:04:35 -0400212bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat)
Geoff Lang97073d12016-04-20 10:42:34 -0700213{
Geoff Lang4f0e0032017-05-01 16:04:35 -0400214 // Table 1.1 from the CHROMIUM_copy_texture spec
Geoff Langca271392017-04-05 12:30:00 -0400215 switch (GetUnsizedFormat(internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -0700216 {
Geoff Lang4f0e0032017-05-01 16:04:35 -0400217 case GL_RED:
Geoff Lang97073d12016-04-20 10:42:34 -0700218 case GL_ALPHA:
219 case GL_LUMINANCE:
220 case GL_LUMINANCE_ALPHA:
221 case GL_RGB:
222 case GL_RGBA:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400223 case GL_RGB8:
224 case GL_RGBA8:
225 case GL_BGRA_EXT:
226 case GL_BGRA8_EXT:
Geoff Lang97073d12016-04-20 10:42:34 -0700227 return true;
228
Geoff Lang4f0e0032017-05-01 16:04:35 -0400229 default:
230 return false;
231 }
232}
Geoff Lang97073d12016-04-20 10:42:34 -0700233
Geoff Lang4f0e0032017-05-01 16:04:35 -0400234bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat)
235{
236 return IsValidCopyTextureSourceInternalFormatEnum(internalFormat);
237}
238
Geoff Lang4f0e0032017-05-01 16:04:35 -0400239bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat)
240{
241 // Table 1.0 from the CHROMIUM_copy_texture spec
242 switch (internalFormat)
243 {
244 case GL_RGB:
245 case GL_RGBA:
246 case GL_RGB8:
247 case GL_RGBA8:
Geoff Lang97073d12016-04-20 10:42:34 -0700248 case GL_BGRA_EXT:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400249 case GL_BGRA8_EXT:
250 case GL_SRGB_EXT:
251 case GL_SRGB_ALPHA_EXT:
252 case GL_R8:
253 case GL_R8UI:
254 case GL_RG8:
255 case GL_RG8UI:
256 case GL_SRGB8:
257 case GL_RGB565:
258 case GL_RGB8UI:
Geoff Lang6be3d4c2017-06-16 15:54:15 -0400259 case GL_RGB10_A2:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400260 case GL_SRGB8_ALPHA8:
261 case GL_RGB5_A1:
262 case GL_RGBA4:
263 case GL_RGBA8UI:
264 case GL_RGB9_E5:
265 case GL_R16F:
266 case GL_R32F:
267 case GL_RG16F:
268 case GL_RG32F:
269 case GL_RGB16F:
270 case GL_RGB32F:
271 case GL_RGBA16F:
272 case GL_RGBA32F:
273 case GL_R11F_G11F_B10F:
Brandon Jones340b7b82017-06-26 13:02:31 -0700274 case GL_LUMINANCE:
275 case GL_LUMINANCE_ALPHA:
276 case GL_ALPHA:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400277 return true;
Geoff Lang97073d12016-04-20 10:42:34 -0700278
279 default:
280 return false;
281 }
282}
283
Geoff Lang6be3d4c2017-06-16 15:54:15 -0400284bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat)
285{
286 return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat);
287}
288
Geoff Lang97073d12016-04-20 10:42:34 -0700289bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type)
290{
Geoff Lang4f0e0032017-05-01 16:04:35 -0400291 if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -0700292 {
Jamie Madille0472f32018-11-27 16:32:45 -0500293 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400294 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700295 }
296
Geoff Langc0094ec2017-08-16 14:16:24 -0400297 if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat))
298 {
Jamie Madille0472f32018-11-27 16:32:45 -0500299 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Langc0094ec2017-08-16 14:16:24 -0400300 return false;
301 }
302
Geoff Lang4f0e0032017-05-01 16:04:35 -0400303 const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type);
304 if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Geoff Lang97073d12016-04-20 10:42:34 -0700305 {
Jamie Madille0472f32018-11-27 16:32:45 -0500306 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400307 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700308 }
309
310 return true;
311}
312
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800313bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target)
Geoff Lang97073d12016-04-20 10:42:34 -0700314{
315 switch (target)
316 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800317 case TextureTarget::_2D:
318 case TextureTarget::CubeMapNegativeX:
319 case TextureTarget::CubeMapNegativeY:
320 case TextureTarget::CubeMapNegativeZ:
321 case TextureTarget::CubeMapPositiveX:
322 case TextureTarget::CubeMapPositiveY:
323 case TextureTarget::CubeMapPositiveZ:
Geoff Lang63458a32017-10-30 15:16:53 -0400324 return true;
Geoff Lang97073d12016-04-20 10:42:34 -0700325
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 case TextureTarget::Rectangle:
Geoff Lang63458a32017-10-30 15:16:53 -0400327 return context->getExtensions().textureRectangle;
Geoff Lang97073d12016-04-20 10:42:34 -0700328
329 default:
330 return false;
331 }
332}
333
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334bool IsValidCopyTextureDestinationTarget(Context *context,
335 TextureType textureType,
336 TextureTarget target)
Geoff Lang63458a32017-10-30 15:16:53 -0400337{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800338 return TextureTargetToType(target) == textureType;
Geoff Lang63458a32017-10-30 15:16:53 -0400339}
340
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800341bool IsValidCopyTextureSourceTarget(Context *context, TextureType type)
Geoff Lang97073d12016-04-20 10:42:34 -0700342{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800343 switch (type)
Geoff Lang97073d12016-04-20 10:42:34 -0700344 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800345 case TextureType::_2D:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400346 return true;
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800347 case TextureType::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400348 return context->getExtensions().textureRectangle;
Geoff Langbe607ad2018-11-29 10:14:22 -0500349 case TextureType::External:
350 return context->getExtensions().eglImageExternal;
Geoff Lang4f0e0032017-05-01 16:04:35 -0400351 default:
352 return false;
353 }
354}
355
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800356bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400357{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 if (!ValidMipLevel(context, type, level))
Geoff Lang4f0e0032017-05-01 16:04:35 -0400359 {
360 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700361 }
362
Geoff Lang4f0e0032017-05-01 16:04:35 -0400363 if (level > 0 && context->getClientVersion() < ES_3_0)
364 {
365 return false;
366 }
Geoff Lang97073d12016-04-20 10:42:34 -0700367
Geoff Lang4f0e0032017-05-01 16:04:35 -0400368 return true;
369}
370
371bool IsValidCopyTextureDestinationLevel(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800372 TextureType type,
Geoff Lang4f0e0032017-05-01 16:04:35 -0400373 GLint level,
374 GLsizei width,
Brandon Jones28783792018-03-05 09:37:32 -0800375 GLsizei height,
376 bool isSubImage)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400377{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800378 if (!ValidMipLevel(context, type, level))
Geoff Lang4f0e0032017-05-01 16:04:35 -0400379 {
380 return false;
381 }
382
Brandon Jones28783792018-03-05 09:37:32 -0800383 if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage))
384 {
385 return false;
386 }
387
Geoff Lang4f0e0032017-05-01 16:04:35 -0400388 const Caps &caps = context->getCaps();
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800389 switch (type)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400390 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 case TextureType::_2D:
392 return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) &&
393 static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level);
394 case TextureType::Rectangle:
395 ASSERT(level == 0);
396 return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) &&
397 static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400398
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800399 case TextureType::CubeMap:
400 return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) &&
401 static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level);
402 default:
403 return true;
404 }
Geoff Lang97073d12016-04-20 10:42:34 -0700405}
406
Jamie Madillc1d770e2017-04-13 17:31:24 -0400407bool IsValidStencilFunc(GLenum func)
408{
409 switch (func)
410 {
411 case GL_NEVER:
412 case GL_ALWAYS:
413 case GL_LESS:
414 case GL_LEQUAL:
415 case GL_EQUAL:
416 case GL_GEQUAL:
417 case GL_GREATER:
418 case GL_NOTEQUAL:
419 return true;
420
421 default:
422 return false;
423 }
424}
425
426bool IsValidStencilFace(GLenum face)
427{
428 switch (face)
429 {
430 case GL_FRONT:
431 case GL_BACK:
432 case GL_FRONT_AND_BACK:
433 return true;
434
435 default:
436 return false;
437 }
438}
439
440bool IsValidStencilOp(GLenum op)
441{
442 switch (op)
443 {
444 case GL_ZERO:
445 case GL_KEEP:
446 case GL_REPLACE:
447 case GL_INCR:
448 case GL_DECR:
449 case GL_INVERT:
450 case GL_INCR_WRAP:
451 case GL_DECR_WRAP:
452 return true;
453
454 default:
455 return false;
456 }
457}
458
Jamie Madill5b772312018-03-08 20:28:32 -0500459bool ValidateES2CopyTexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800460 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -0400461 GLint level,
462 GLenum internalformat,
463 bool isSubImage,
464 GLint xoffset,
465 GLint yoffset,
466 GLint x,
467 GLint y,
468 GLsizei width,
469 GLsizei height,
470 GLint border)
471{
472 if (!ValidTexture2DDestinationTarget(context, target))
473 {
Jamie Madille0472f32018-11-27 16:32:45 -0500474 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -0400475 return false;
476 }
477
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800478 TextureType texType = TextureTargetToType(target);
479 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Jamie Madillbe849e42017-05-02 15:49:00 -0400480 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500481 // Error is already handled.
Jamie Madillbe849e42017-05-02 15:49:00 -0400482 return false;
483 }
484
485 Format textureFormat = Format::Invalid();
486 if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
487 xoffset, yoffset, 0, x, y, width, height, border,
488 &textureFormat))
489 {
490 return false;
491 }
492
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500493 const gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madillbe849e42017-05-02 15:49:00 -0400494 GLenum colorbufferFormat =
495 framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat;
496 const auto &formatInfo = *textureFormat.info;
497
498 // [OpenGL ES 2.0.24] table 3.9
499 if (isSubImage)
500 {
501 switch (formatInfo.format)
502 {
503 case GL_ALPHA:
504 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400505 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
506 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400507 {
Jamie Madille0472f32018-11-27 16:32:45 -0500508 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400509 return false;
510 }
511 break;
512 case GL_LUMINANCE:
513 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
514 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
515 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400516 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT &&
517 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400518 {
Jamie Madille0472f32018-11-27 16:32:45 -0500519 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400520 return false;
521 }
522 break;
523 case GL_RED_EXT:
524 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
525 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
526 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
527 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F &&
528 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400529 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
530 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400531 {
Jamie Madille0472f32018-11-27 16:32:45 -0500532 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400533 return false;
534 }
535 break;
536 case GL_RG_EXT:
537 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
538 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
539 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
540 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400541 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
542 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400543 {
Jamie Madille0472f32018-11-27 16:32:45 -0500544 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400545 return false;
546 }
547 break;
548 case GL_RGB:
549 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
550 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
551 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400552 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
553 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400554 {
Jamie Madille0472f32018-11-27 16:32:45 -0500555 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400556 return false;
557 }
558 break;
559 case GL_LUMINANCE_ALPHA:
560 case GL_RGBA:
561 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400562 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F &&
563 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400564 {
Jamie Madille0472f32018-11-27 16:32:45 -0500565 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400566 return false;
567 }
568 break;
569 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
570 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
571 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
572 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
573 case GL_ETC1_RGB8_OES:
574 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
575 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
576 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
577 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
578 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
Olli Etuahof2ed2992018-10-04 13:54:42 +0300579 case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT:
580 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:
581 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT:
582 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT:
Jamie Madille0472f32018-11-27 16:32:45 -0500583 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400584 return false;
585 case GL_DEPTH_COMPONENT:
586 case GL_DEPTH_STENCIL_OES:
Jamie Madille0472f32018-11-27 16:32:45 -0500587 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400588 return false;
589 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500590 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400591 return false;
592 }
593
594 if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat)
595 {
Jamie Madille0472f32018-11-27 16:32:45 -0500596 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400597 return false;
598 }
599 }
600 else
601 {
602 switch (internalformat)
603 {
604 case GL_ALPHA:
605 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
606 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
607 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
608 {
Jamie Madille0472f32018-11-27 16:32:45 -0500609 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400610 return false;
611 }
612 break;
613 case GL_LUMINANCE:
614 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
615 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
616 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
617 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
618 colorbufferFormat != GL_BGR5_A1_ANGLEX)
619 {
Jamie Madille0472f32018-11-27 16:32:45 -0500620 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400621 return false;
622 }
623 break;
624 case GL_RED_EXT:
625 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
626 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
627 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
628 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
629 colorbufferFormat != GL_BGR5_A1_ANGLEX)
630 {
Jamie Madille0472f32018-11-27 16:32:45 -0500631 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400632 return false;
633 }
634 break;
635 case GL_RG_EXT:
636 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
637 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
638 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
639 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
640 {
Jamie Madille0472f32018-11-27 16:32:45 -0500641 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400642 return false;
643 }
644 break;
645 case GL_RGB:
646 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
647 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
648 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
649 colorbufferFormat != GL_BGR5_A1_ANGLEX)
650 {
Jamie Madille0472f32018-11-27 16:32:45 -0500651 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400652 return false;
653 }
654 break;
655 case GL_LUMINANCE_ALPHA:
656 case GL_RGBA:
657 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
658 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
659 colorbufferFormat != GL_BGR5_A1_ANGLEX)
660 {
Jamie Madille0472f32018-11-27 16:32:45 -0500661 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400662 return false;
663 }
664 break;
665 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
666 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
667 if (context->getExtensions().textureCompressionDXT1)
668 {
Jamie Madille0472f32018-11-27 16:32:45 -0500669 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400670 return false;
671 }
672 else
673 {
Jamie Madille0472f32018-11-27 16:32:45 -0500674 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400675 return false;
676 }
677 break;
678 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
679 if (context->getExtensions().textureCompressionDXT3)
680 {
Jamie Madille0472f32018-11-27 16:32:45 -0500681 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400682 return false;
683 }
684 else
685 {
Jamie Madille0472f32018-11-27 16:32:45 -0500686 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400687 return false;
688 }
689 break;
690 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
691 if (context->getExtensions().textureCompressionDXT5)
692 {
Jamie Madille0472f32018-11-27 16:32:45 -0500693 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400694 return false;
695 }
696 else
697 {
Jamie Madille0472f32018-11-27 16:32:45 -0500698 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400699 return false;
700 }
701 break;
702 case GL_ETC1_RGB8_OES:
703 if (context->getExtensions().compressedETC1RGB8Texture)
704 {
Jamie Madille0472f32018-11-27 16:32:45 -0500705 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400706 return false;
707 }
708 else
709 {
Jamie Madille0472f32018-11-27 16:32:45 -0500710 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400711 return false;
712 }
713 break;
714 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
715 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
716 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
717 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
718 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
719 if (context->getExtensions().lossyETCDecode)
720 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500721 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400722 return false;
723 }
724 else
725 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500726 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400727 return false;
728 }
729 break;
730 case GL_DEPTH_COMPONENT:
731 case GL_DEPTH_COMPONENT16:
732 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600733 if (context->getExtensions().depthTextureAny())
Jamie Madillbe849e42017-05-02 15:49:00 -0400734 {
Jamie Madille0472f32018-11-27 16:32:45 -0500735 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400736 return false;
737 }
738 else
739 {
Jamie Madille0472f32018-11-27 16:32:45 -0500740 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400741 return false;
742 }
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600743 break;
744 case GL_DEPTH_STENCIL_OES:
745 case GL_DEPTH24_STENCIL8_OES:
746 if (context->getExtensions().depthTextureAny() ||
747 context->getExtensions().packedDepthStencil)
748 {
749 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
750 return false;
751 }
752 else
753 {
754 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
755 return false;
756 }
757 break;
Jamie Madillbe849e42017-05-02 15:49:00 -0400758 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500759 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400760 return false;
761 }
762 }
763
764 // If width or height is zero, it is a no-op. Return false without setting an error.
765 return (width > 0 && height > 0);
766}
767
768bool ValidCap(const Context *context, GLenum cap, bool queryOnly)
769{
770 switch (cap)
771 {
772 // EXT_multisample_compatibility
773 case GL_MULTISAMPLE_EXT:
774 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
775 return context->getExtensions().multisampleCompatibility;
776
777 case GL_CULL_FACE:
778 case GL_POLYGON_OFFSET_FILL:
779 case GL_SAMPLE_ALPHA_TO_COVERAGE:
780 case GL_SAMPLE_COVERAGE:
781 case GL_SCISSOR_TEST:
782 case GL_STENCIL_TEST:
783 case GL_DEPTH_TEST:
784 case GL_BLEND:
785 case GL_DITHER:
786 return true;
787
788 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
789 case GL_RASTERIZER_DISCARD:
790 return (context->getClientMajorVersion() >= 3);
791
792 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
793 case GL_DEBUG_OUTPUT:
794 return context->getExtensions().debug;
795
796 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
797 return queryOnly && context->getExtensions().bindGeneratesResource;
798
799 case GL_CLIENT_ARRAYS_ANGLE:
800 return queryOnly && context->getExtensions().clientArrays;
801
802 case GL_FRAMEBUFFER_SRGB_EXT:
803 return context->getExtensions().sRGBWriteControl;
804
805 case GL_SAMPLE_MASK:
806 return context->getClientVersion() >= Version(3, 1);
807
Geoff Langb433e872017-10-05 14:01:47 -0400808 case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
Jamie Madillbe849e42017-05-02 15:49:00 -0400809 return queryOnly && context->getExtensions().robustResourceInitialization;
810
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700811 // GLES1 emulation: GLES1-specific caps
812 case GL_ALPHA_TEST:
Lingfeng Yang01074432018-04-16 10:19:51 -0700813 case GL_VERTEX_ARRAY:
814 case GL_NORMAL_ARRAY:
815 case GL_COLOR_ARRAY:
816 case GL_TEXTURE_COORD_ARRAY:
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700817 case GL_TEXTURE_2D:
Lingfeng Yangd0febe72018-05-17 22:36:52 -0700818 case GL_LIGHTING:
819 case GL_LIGHT0:
820 case GL_LIGHT1:
821 case GL_LIGHT2:
822 case GL_LIGHT3:
823 case GL_LIGHT4:
824 case GL_LIGHT5:
825 case GL_LIGHT6:
826 case GL_LIGHT7:
827 case GL_NORMALIZE:
828 case GL_RESCALE_NORMAL:
829 case GL_COLOR_MATERIAL:
Lingfeng Yang060088a2018-05-30 20:40:57 -0700830 case GL_CLIP_PLANE0:
831 case GL_CLIP_PLANE1:
832 case GL_CLIP_PLANE2:
833 case GL_CLIP_PLANE3:
834 case GL_CLIP_PLANE4:
835 case GL_CLIP_PLANE5:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -0700836 case GL_FOG:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700837 case GL_POINT_SMOOTH:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -0700838 case GL_LINE_SMOOTH:
839 case GL_COLOR_LOGIC_OP:
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700840 return context->getClientVersion() < Version(2, 0);
Lingfeng Yang01074432018-04-16 10:19:51 -0700841 case GL_POINT_SIZE_ARRAY_OES:
842 return context->getClientVersion() < Version(2, 0) &&
843 context->getExtensions().pointSizeArray;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700844 case GL_TEXTURE_CUBE_MAP:
845 return context->getClientVersion() < Version(2, 0) &&
846 context->getExtensions().textureCubeMap;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700847 case GL_POINT_SPRITE_OES:
848 return context->getClientVersion() < Version(2, 0) &&
849 context->getExtensions().pointSprite;
Jamie Madillbe849e42017-05-02 15:49:00 -0400850 default:
851 return false;
852 }
853}
854
Geoff Langfc32e8b2017-05-31 14:16:59 -0400855// Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section
856// 3.1.
Geoff Langcab92ee2017-07-19 17:32:07 -0400857bool IsValidESSLCharacter(unsigned char c)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400858{
859 // Printing characters are valid except " $ ` @ \ ' DEL.
Geoff Langcab92ee2017-07-19 17:32:07 -0400860 if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' &&
861 c != '\'')
Geoff Langfc32e8b2017-05-31 14:16:59 -0400862 {
863 return true;
864 }
865
866 // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid.
867 if (c >= 9 && c <= 13)
868 {
869 return true;
870 }
871
872 return false;
873}
874
Geoff Langcab92ee2017-07-19 17:32:07 -0400875bool IsValidESSLString(const char *str, size_t len)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400876{
Geoff Langa71a98e2017-06-19 15:15:00 -0400877 for (size_t i = 0; i < len; i++)
878 {
Geoff Langcab92ee2017-07-19 17:32:07 -0400879 if (!IsValidESSLCharacter(str[i]))
Geoff Langa71a98e2017-06-19 15:15:00 -0400880 {
881 return false;
882 }
883 }
884
885 return true;
Geoff Langfc32e8b2017-05-31 14:16:59 -0400886}
887
Geoff Langcab92ee2017-07-19 17:32:07 -0400888bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed)
889{
890 enum class ParseState
891 {
892 // Have not seen an ASCII non-whitespace character yet on
893 // this line. Possible that we might see a preprocessor
894 // directive.
895 BEGINING_OF_LINE,
896
897 // Have seen at least one ASCII non-whitespace character
898 // on this line.
899 MIDDLE_OF_LINE,
900
901 // Handling a preprocessor directive. Passes through all
902 // characters up to the end of the line. Disables comment
903 // processing.
904 IN_PREPROCESSOR_DIRECTIVE,
905
906 // Handling a single-line comment. The comment text is
907 // replaced with a single space.
908 IN_SINGLE_LINE_COMMENT,
909
910 // Handling a multi-line comment. Newlines are passed
911 // through to preserve line numbers.
912 IN_MULTI_LINE_COMMENT
913 };
914
915 ParseState state = ParseState::BEGINING_OF_LINE;
916 size_t pos = 0;
917
918 while (pos < len)
919 {
920 char c = str[pos];
921 char next = pos + 1 < len ? str[pos + 1] : 0;
922
923 // Check for newlines
924 if (c == '\n' || c == '\r')
925 {
926 if (state != ParseState::IN_MULTI_LINE_COMMENT)
927 {
928 state = ParseState::BEGINING_OF_LINE;
929 }
930
931 pos++;
932 continue;
933 }
934
935 switch (state)
936 {
937 case ParseState::BEGINING_OF_LINE:
938 if (c == ' ')
939 {
940 // Maintain the BEGINING_OF_LINE state until a non-space is seen
941 pos++;
942 }
943 else if (c == '#')
944 {
945 state = ParseState::IN_PREPROCESSOR_DIRECTIVE;
946 pos++;
947 }
948 else
949 {
950 // Don't advance, re-process this character with the MIDDLE_OF_LINE state
951 state = ParseState::MIDDLE_OF_LINE;
952 }
953 break;
954
955 case ParseState::MIDDLE_OF_LINE:
956 if (c == '/' && next == '/')
957 {
958 state = ParseState::IN_SINGLE_LINE_COMMENT;
959 pos++;
960 }
961 else if (c == '/' && next == '*')
962 {
963 state = ParseState::IN_MULTI_LINE_COMMENT;
964 pos++;
965 }
966 else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r'))
967 {
968 // Skip line continuation characters
969 }
970 else if (!IsValidESSLCharacter(c))
971 {
972 return false;
973 }
974 pos++;
975 break;
976
977 case ParseState::IN_PREPROCESSOR_DIRECTIVE:
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -0700978 // Line-continuation characters may not be permitted.
979 // Otherwise, just pass it through. Do not parse comments in this state.
980 if (!lineContinuationAllowed && c == '\\')
981 {
982 return false;
983 }
Geoff Langcab92ee2017-07-19 17:32:07 -0400984 pos++;
985 break;
986
987 case ParseState::IN_SINGLE_LINE_COMMENT:
988 // Line-continuation characters are processed before comment processing.
989 // Advance string if a new line character is immediately behind
990 // line-continuation character.
991 if (c == '\\' && (next == '\n' || next == '\r'))
992 {
993 pos++;
994 }
995 pos++;
996 break;
997
998 case ParseState::IN_MULTI_LINE_COMMENT:
999 if (c == '*' && next == '/')
1000 {
1001 state = ParseState::MIDDLE_OF_LINE;
1002 pos++;
1003 }
1004 pos++;
1005 break;
1006 }
1007 }
1008
1009 return true;
1010}
1011
Jamie Madill5b772312018-03-08 20:28:32 -05001012bool ValidateWebGLNamePrefix(Context *context, const GLchar *name)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001013{
1014 ASSERT(context->isWebGL());
1015
1016 // WebGL 1.0 [Section 6.16] GLSL Constructs
1017 // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL.
1018 if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0)
1019 {
Jamie Madille0472f32018-11-27 16:32:45 -05001020 context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001021 return false;
1022 }
1023
1024 return true;
1025}
1026
Jamie Madill5b772312018-03-08 20:28:32 -05001027bool ValidateWebGLNameLength(Context *context, size_t length)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001028{
1029 ASSERT(context->isWebGL());
1030
1031 if (context->isWebGL1() && length > 256)
1032 {
1033 // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths
1034 // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute
1035 // locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001036 context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001037
1038 return false;
1039 }
1040 else if (length > 1024)
1041 {
1042 // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of
1043 // uniform and attribute locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001044 context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001045 return false;
1046 }
1047
1048 return true;
1049}
1050
Jamie Madill007530e2017-12-28 14:27:04 -05001051bool ValidateMatrixMode(Context *context, GLenum matrixMode)
1052{
1053 if (!context->getExtensions().pathRendering)
1054 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001055 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05001056 return false;
1057 }
1058
1059 if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM)
1060 {
Jamie Madille0472f32018-11-27 16:32:45 -05001061 context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode);
Jamie Madill007530e2017-12-28 14:27:04 -05001062 return false;
1063 }
1064 return true;
1065}
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001066
1067bool ValidBlendFunc(const Context *context, GLenum val)
1068{
1069 const gl::Extensions &ext = context->getExtensions();
1070
1071 // these are always valid for src and dst.
1072 switch (val)
1073 {
1074 case GL_ZERO:
1075 case GL_ONE:
1076 case GL_SRC_COLOR:
1077 case GL_ONE_MINUS_SRC_COLOR:
1078 case GL_DST_COLOR:
1079 case GL_ONE_MINUS_DST_COLOR:
1080 case GL_SRC_ALPHA:
1081 case GL_ONE_MINUS_SRC_ALPHA:
1082 case GL_DST_ALPHA:
1083 case GL_ONE_MINUS_DST_ALPHA:
1084 case GL_CONSTANT_COLOR:
1085 case GL_ONE_MINUS_CONSTANT_COLOR:
1086 case GL_CONSTANT_ALPHA:
1087 case GL_ONE_MINUS_CONSTANT_ALPHA:
1088 return true;
1089
1090 // EXT_blend_func_extended.
1091 case GL_SRC1_COLOR_EXT:
1092 case GL_SRC1_ALPHA_EXT:
1093 case GL_ONE_MINUS_SRC1_COLOR_EXT:
1094 case GL_ONE_MINUS_SRC1_ALPHA_EXT:
1095 case GL_SRC_ALPHA_SATURATE_EXT:
1096 return ext.blendFuncExtended;
1097
1098 default:
1099 return false;
1100 }
1101}
1102
1103bool ValidSrcBlendFunc(const Context *context, GLenum val)
1104{
1105 if (ValidBlendFunc(context, val))
1106 return true;
1107
1108 if (val == GL_SRC_ALPHA_SATURATE)
1109 return true;
1110
1111 return false;
1112}
1113
1114bool ValidDstBlendFunc(const Context *context, GLenum val)
1115{
1116 if (ValidBlendFunc(context, val))
1117 return true;
1118
1119 if (val == GL_SRC_ALPHA_SATURATE)
1120 {
1121 if (context->getClientMajorVersion() >= 3)
1122 return true;
1123 }
1124
1125 return false;
1126}
Michael Spangab6a59b2019-05-21 21:26:26 -04001127
1128bool IsValidImageLayout(ImageLayout layout)
1129{
1130 switch (layout)
1131 {
1132 case ImageLayout::General:
1133 case ImageLayout::ColorAttachment:
1134 case ImageLayout::DepthStencilAttachment:
1135 case ImageLayout::DepthStencilReadOnlyAttachment:
1136 case ImageLayout::ShaderReadOnly:
1137 case ImageLayout::TransferSrc:
1138 case ImageLayout::TransferDst:
1139 case ImageLayout::DepthReadOnlyStencilAttachment:
1140 case ImageLayout::DepthAttachmentStencilReadOnly:
1141 return true;
1142
1143 default:
1144 return false;
1145 }
1146}
1147
Geoff Langff5b2d52016-09-07 11:32:23 -04001148bool ValidateES2TexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001149 TextureTarget target,
Geoff Langff5b2d52016-09-07 11:32:23 -04001150 GLint level,
1151 GLenum internalformat,
1152 bool isCompressed,
1153 bool isSubImage,
1154 GLint xoffset,
1155 GLint yoffset,
1156 GLsizei width,
1157 GLsizei height,
1158 GLint border,
1159 GLenum format,
1160 GLenum type,
1161 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001162 const void *pixels)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001163{
Jamie Madill6f38f822014-06-06 17:12:20 -04001164 if (!ValidTexture2DDestinationTarget(context, target))
1165 {
Jamie Madille0472f32018-11-27 16:32:45 -05001166 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001167 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001168 }
1169
Geoff Lang857880e2019-05-27 13:39:15 -04001170 return ValidateES2TexImageParametersBase(context, target, level, internalformat, isCompressed,
1171 isSubImage, xoffset, yoffset, width, height, border,
1172 format, type, imageSize, pixels);
1173}
1174
1175} // anonymous namespace
1176
1177bool ValidateES2TexImageParametersBase(Context *context,
1178 TextureTarget target,
1179 GLint level,
1180 GLenum internalformat,
1181 bool isCompressed,
1182 bool isSubImage,
1183 GLint xoffset,
1184 GLint yoffset,
1185 GLsizei width,
1186 GLsizei height,
1187 GLint border,
1188 GLenum format,
1189 GLenum type,
1190 GLsizei imageSize,
1191 const void *pixels)
1192{
1193
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001194 TextureType texType = TextureTargetToType(target);
1195 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001196 {
Jamie Madill610640f2018-11-21 17:28:41 -05001197 // Error already handled.
Geoff Langb1196682014-07-23 13:47:29 -04001198 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001199 }
1200
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001201 if (!ValidMipLevel(context, texType, level))
Brandon Jones6cad5662017-06-14 13:25:13 -07001202 {
Jamie Madille0472f32018-11-27 16:32:45 -05001203 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Brandon Jones6cad5662017-06-14 13:25:13 -07001204 return false;
1205 }
1206
1207 if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width ||
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001208 std::numeric_limits<GLsizei>::max() - yoffset < height)
1209 {
Jamie Madille0472f32018-11-27 16:32:45 -05001210 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Geoff Langb1196682014-07-23 13:47:29 -04001211 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001212 }
1213
Geoff Langaae65a42014-05-26 12:43:44 -04001214 const gl::Caps &caps = context->getCaps();
1215
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001216 switch (texType)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001217 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001218 case TextureType::_2D:
Geoff Lang857880e2019-05-27 13:39:15 -04001219 case TextureType::External:
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001220 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
1221 static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
1222 {
Jamie Madille0472f32018-11-27 16:32:45 -05001223 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001224 return false;
1225 }
1226 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001227
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001228 case TextureType::Rectangle:
1229 ASSERT(level == 0);
1230 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1231 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1232 {
Jamie Madille0472f32018-11-27 16:32:45 -05001233 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001234 return false;
1235 }
1236 if (isCompressed)
1237 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001238 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001239 return false;
1240 }
1241 break;
1242
1243 case TextureType::CubeMap:
1244 if (!isSubImage && width != height)
1245 {
Jamie Madille0472f32018-11-27 16:32:45 -05001246 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001247 return false;
1248 }
1249
1250 if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) ||
1251 static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level))
1252 {
Jamie Madille0472f32018-11-27 16:32:45 -05001253 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001254 return false;
1255 }
1256 break;
1257
1258 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001259 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langa9be0dc2014-12-17 12:34:40 -05001260 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001261 }
1262
Jamie Madillcfc73cc2019-04-08 16:26:51 -04001263 gl::Texture *texture = context->getTextureByType(texType);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001264 if (!texture)
1265 {
Jamie Madille0472f32018-11-27 16:32:45 -05001266 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Geoff Langb1196682014-07-23 13:47:29 -04001267 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001268 }
1269
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001270 // Verify zero border
1271 if (border != 0)
1272 {
Jamie Madille0472f32018-11-27 16:32:45 -05001273 context->validationError(GL_INVALID_VALUE, kInvalidBorder);
Geoff Langb1196682014-07-23 13:47:29 -04001274 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001275 }
1276
Tim Van Patten208af3e2019-03-19 09:15:55 -06001277 bool nonEqualFormatsAllowed = false;
1278
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001279 if (isCompressed)
1280 {
tmartino0ccd5ae2015-10-01 14:33:14 -04001281 GLenum actualInternalFormat =
Geoff Langca271392017-04-05 12:30:00 -04001282 isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat
1283 : internalformat;
Geoff Lange88e4542018-05-03 15:05:57 -04001284
1285 const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat);
1286
1287 if (!internalFormatInfo.compressed)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001288 {
Jamie Madille0472f32018-11-27 16:32:45 -05001289 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001290 return false;
1291 }
1292
1293 if (!internalFormatInfo.textureSupport(context->getClientVersion(),
1294 context->getExtensions()))
1295 {
Jamie Madille0472f32018-11-27 16:32:45 -05001296 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001297 return false;
tmartino0ccd5ae2015-10-01 14:33:14 -04001298 }
Geoff Lang966c9402017-04-18 12:38:27 -04001299
1300 if (isSubImage)
tmartino0ccd5ae2015-10-01 14:33:14 -04001301 {
Geoff Lange88e4542018-05-03 15:05:57 -04001302 // From the OES_compressed_ETC1_RGB8_texture spec:
1303 // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or
1304 // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format
1305 // ETC1_RGB8_OES.
1306 if (actualInternalFormat == GL_ETC1_RGB8_OES)
1307 {
Jamie Madille0472f32018-11-27 16:32:45 -05001308 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001309 return false;
1310 }
1311
Geoff Lang966c9402017-04-18 12:38:27 -04001312 if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width,
1313 height, texture->getWidth(target, level),
1314 texture->getHeight(target, level)))
1315 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001316 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001317 return false;
1318 }
1319
1320 if (format != actualInternalFormat)
1321 {
Jamie Madille0472f32018-11-27 16:32:45 -05001322 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Geoff Lang966c9402017-04-18 12:38:27 -04001323 return false;
1324 }
1325 }
1326 else
1327 {
1328 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height))
1329 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001330 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001331 return false;
1332 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001333 }
1334 }
1335 else
1336 {
1337 // validate <type> by itself (used as secondary key below)
1338 switch (type)
1339 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001340 case GL_UNSIGNED_BYTE:
1341 case GL_UNSIGNED_SHORT_5_6_5:
1342 case GL_UNSIGNED_SHORT_4_4_4_4:
1343 case GL_UNSIGNED_SHORT_5_5_5_1:
1344 case GL_UNSIGNED_SHORT:
1345 case GL_UNSIGNED_INT:
1346 case GL_UNSIGNED_INT_24_8_OES:
1347 case GL_HALF_FLOAT_OES:
1348 case GL_FLOAT:
1349 break;
1350 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001351 context->validationError(GL_INVALID_ENUM, kInvalidType);
He Yunchaoced53ae2016-11-29 15:00:51 +08001352 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001353 }
1354
1355 // validate <format> + <type> combinations
1356 // - invalid <format> -> sets INVALID_ENUM
1357 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
1358 switch (format)
1359 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001360 case GL_ALPHA:
1361 case GL_LUMINANCE:
1362 case GL_LUMINANCE_ALPHA:
1363 switch (type)
1364 {
1365 case GL_UNSIGNED_BYTE:
1366 case GL_FLOAT:
1367 case GL_HALF_FLOAT_OES:
1368 break;
1369 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001370 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001371 return false;
1372 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001373 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001374 case GL_RED:
1375 case GL_RG:
1376 if (!context->getExtensions().textureRG)
1377 {
Jamie Madille0472f32018-11-27 16:32:45 -05001378 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001379 return false;
1380 }
1381 switch (type)
1382 {
1383 case GL_UNSIGNED_BYTE:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001384 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001385 case GL_FLOAT:
1386 case GL_HALF_FLOAT_OES:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001387 if (!context->getExtensions().textureFloat)
1388 {
Jamie Madille0472f32018-11-27 16:32:45 -05001389 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001390 return false;
1391 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001392 break;
1393 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001394 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001395 return false;
1396 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001397 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001398 case GL_RGB:
1399 switch (type)
1400 {
1401 case GL_UNSIGNED_BYTE:
1402 case GL_UNSIGNED_SHORT_5_6_5:
1403 case GL_FLOAT:
1404 case GL_HALF_FLOAT_OES:
1405 break;
1406 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001407 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001408 return false;
1409 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001410 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001411 case GL_RGBA:
1412 switch (type)
1413 {
1414 case GL_UNSIGNED_BYTE:
1415 case GL_UNSIGNED_SHORT_4_4_4_4:
1416 case GL_UNSIGNED_SHORT_5_5_5_1:
1417 case GL_FLOAT:
1418 case GL_HALF_FLOAT_OES:
1419 break;
1420 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001421 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001422 return false;
1423 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001424 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001425 case GL_BGRA_EXT:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001426 if (!context->getExtensions().textureFormatBGRA8888)
1427 {
Jamie Madille0472f32018-11-27 16:32:45 -05001428 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001429 return false;
1430 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001431 switch (type)
1432 {
1433 case GL_UNSIGNED_BYTE:
1434 break;
1435 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001436 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001437 return false;
1438 }
1439 break;
1440 case GL_SRGB_EXT:
1441 case GL_SRGB_ALPHA_EXT:
1442 if (!context->getExtensions().sRGB)
1443 {
Jamie Madille0472f32018-11-27 16:32:45 -05001444 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001445 return false;
1446 }
1447 switch (type)
1448 {
1449 case GL_UNSIGNED_BYTE:
1450 break;
1451 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001452 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001453 return false;
1454 }
1455 break;
1456 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are
1457 // handled below
1458 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1459 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1460 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1461 break;
1462 case GL_DEPTH_COMPONENT:
1463 switch (type)
1464 {
1465 case GL_UNSIGNED_SHORT:
1466 case GL_UNSIGNED_INT:
1467 break;
1468 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001469 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001470 return false;
1471 }
1472 break;
1473 case GL_DEPTH_STENCIL_OES:
1474 switch (type)
1475 {
1476 case GL_UNSIGNED_INT_24_8_OES:
1477 break;
1478 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001479 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001480 return false;
1481 }
1482 break;
1483 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001484 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001485 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001486 }
1487
1488 switch (format)
1489 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001490 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1491 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1492 if (context->getExtensions().textureCompressionDXT1)
1493 {
Jamie Madille0472f32018-11-27 16:32:45 -05001494 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001495 return false;
1496 }
1497 else
1498 {
Jamie Madille0472f32018-11-27 16:32:45 -05001499 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001500 return false;
1501 }
1502 break;
1503 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1504 if (context->getExtensions().textureCompressionDXT3)
1505 {
Jamie Madille0472f32018-11-27 16:32:45 -05001506 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001507 return false;
1508 }
1509 else
1510 {
Jamie Madille0472f32018-11-27 16:32:45 -05001511 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001512 return false;
1513 }
1514 break;
1515 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1516 if (context->getExtensions().textureCompressionDXT5)
1517 {
Jamie Madille0472f32018-11-27 16:32:45 -05001518 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001519 return false;
1520 }
1521 else
1522 {
Jamie Madille0472f32018-11-27 16:32:45 -05001523 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001524 return false;
1525 }
1526 break;
1527 case GL_ETC1_RGB8_OES:
1528 if (context->getExtensions().compressedETC1RGB8Texture)
1529 {
Jamie Madille0472f32018-11-27 16:32:45 -05001530 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001531 return false;
1532 }
1533 else
1534 {
Jamie Madille0472f32018-11-27 16:32:45 -05001535 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001536 return false;
1537 }
1538 break;
1539 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001540 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1541 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1542 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1543 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001544 if (context->getExtensions().lossyETCDecode)
1545 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001546 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001547 return false;
1548 }
1549 else
1550 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001551 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001552 return false;
1553 }
1554 break;
1555 case GL_DEPTH_COMPONENT:
1556 case GL_DEPTH_STENCIL_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001557 if (!context->getExtensions().depthTextureANGLE &&
1558 !(context->getExtensions().packedDepthStencil &&
1559 context->getExtensions().depthTextureOES))
He Yunchaoced53ae2016-11-29 15:00:51 +08001560 {
Jamie Madille0472f32018-11-27 16:32:45 -05001561 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001562 return false;
1563 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001564 if (target != TextureTarget::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001565 {
Jamie Madille0472f32018-11-27 16:32:45 -05001566 context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001567 return false;
1568 }
1569 // OES_depth_texture supports loading depth data and multiple levels,
1570 // but ANGLE_depth_texture does not
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001571 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001572 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001573 if (pixels != nullptr)
1574 {
1575 context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
1576 return false;
1577 }
1578 if (level != 0)
1579 {
1580 context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
1581 return false;
1582 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001583 }
1584 break;
1585 default:
1586 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001587 }
1588
Geoff Lang6e898aa2017-06-02 11:17:26 -04001589 if (!isSubImage)
1590 {
1591 switch (internalformat)
1592 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001593 // Core ES 2.0 formats
1594 case GL_ALPHA:
1595 case GL_LUMINANCE:
1596 case GL_LUMINANCE_ALPHA:
1597 case GL_RGB:
1598 case GL_RGBA:
1599 break;
1600
Geoff Lang6e898aa2017-06-02 11:17:26 -04001601 case GL_RGBA32F:
1602 if (!context->getExtensions().colorBufferFloatRGBA)
1603 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001604 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001605 return false;
1606 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001607
1608 nonEqualFormatsAllowed = true;
1609
Geoff Lang6e898aa2017-06-02 11:17:26 -04001610 if (type != GL_FLOAT)
1611 {
Jamie Madille0472f32018-11-27 16:32:45 -05001612 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001613 return false;
1614 }
1615 if (format != GL_RGBA)
1616 {
Jamie Madille0472f32018-11-27 16:32:45 -05001617 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001618 return false;
1619 }
1620 break;
1621
1622 case GL_RGB32F:
1623 if (!context->getExtensions().colorBufferFloatRGB)
1624 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001625 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001626 return false;
1627 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001628
1629 nonEqualFormatsAllowed = true;
1630
Geoff Lang6e898aa2017-06-02 11:17:26 -04001631 if (type != GL_FLOAT)
1632 {
Jamie Madille0472f32018-11-27 16:32:45 -05001633 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001634 return false;
1635 }
1636 if (format != GL_RGB)
1637 {
Jamie Madille0472f32018-11-27 16:32:45 -05001638 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001639 return false;
1640 }
1641 break;
1642
Tim Van Patten208af3e2019-03-19 09:15:55 -06001643 case GL_BGRA_EXT:
1644 if (!context->getExtensions().textureFormatBGRA8888)
1645 {
1646 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1647 return false;
1648 }
Geoff Lang6e898aa2017-06-02 11:17:26 -04001649 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001650
1651 case GL_DEPTH_COMPONENT:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001652 if (!(context->getExtensions().depthTextureAny()))
1653 {
1654 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1655 return false;
1656 }
1657 break;
1658
Tim Van Patten208af3e2019-03-19 09:15:55 -06001659 case GL_DEPTH_STENCIL:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001660 if (!(context->getExtensions().depthTextureANGLE ||
1661 context->getExtensions().packedDepthStencil))
Tim Van Patten208af3e2019-03-19 09:15:55 -06001662 {
1663 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1664 return false;
1665 }
1666 break;
1667
1668 case GL_RED:
1669 case GL_RG:
1670 if (!context->getExtensions().textureRG)
1671 {
1672 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1673 return false;
1674 }
1675 break;
1676
1677 case GL_SRGB_EXT:
1678 case GL_SRGB_ALPHA_EXT:
1679 if (!context->getExtensions().sRGB)
1680 {
1681 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1682 return false;
1683 }
1684 break;
1685
1686 default:
1687 context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat);
1688 return false;
Geoff Lang6e898aa2017-06-02 11:17:26 -04001689 }
1690 }
1691
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001692 if (type == GL_FLOAT)
1693 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001694 if (!context->getExtensions().textureFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001695 {
Jamie Madille0472f32018-11-27 16:32:45 -05001696 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001697 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001698 }
1699 }
1700 else if (type == GL_HALF_FLOAT_OES)
1701 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001702 if (!context->getExtensions().textureHalfFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001703 {
Jamie Madille0472f32018-11-27 16:32:45 -05001704 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001705 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001706 }
1707 }
1708 }
1709
Tim Van Patten208af3e2019-03-19 09:15:55 -06001710 if (isSubImage)
Geoff Langff5b2d52016-09-07 11:32:23 -04001711 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001712 const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info;
1713 if (textureInternalFormat.internalFormat == GL_NONE)
1714 {
1715 context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel);
1716 return false;
1717 }
1718
Tim Van Patten5f388c22019-03-14 09:54:23 -06001719 if (format != textureInternalFormat.format)
1720 {
1721 context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch);
1722 return false;
1723 }
1724
1725 if (context->getExtensions().webglCompatibility)
Tim Van Patten208af3e2019-03-19 09:15:55 -06001726 {
1727 if (GetInternalFormatInfo(format, type).sizedInternalFormat !=
1728 textureInternalFormat.sizedInternalFormat)
1729 {
Tim Van Patten5f388c22019-03-14 09:54:23 -06001730 context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch);
Tim Van Patten208af3e2019-03-19 09:15:55 -06001731 return false;
1732 }
1733 }
1734
1735 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
1736 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level))
1737 {
1738 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
1739 return false;
1740 }
1741
1742 if (width > 0 && height > 0 && pixels == nullptr &&
1743 context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr)
1744 {
1745 context->validationError(GL_INVALID_VALUE, kPixelDataNull);
1746 return false;
1747 }
1748 }
1749 else
1750 {
1751 if (texture->getImmutableFormat())
1752 {
1753 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
1754 return false;
1755 }
1756 }
1757
1758 // From GL_CHROMIUM_color_buffer_float_rgb[a]:
1759 // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
1760 // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
1761 // internalformat parameter and format parameter of TexImage2D must match is lifted for this
1762 // case.
1763 if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
1764 {
1765 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Langff5b2d52016-09-07 11:32:23 -04001766 return false;
1767 }
1768
Tim Van Patten208af3e2019-03-19 09:15:55 -06001769 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
1770 return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels,
1771 imageSize);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001772}
1773
He Yunchaoced53ae2016-11-29 15:00:51 +08001774bool ValidateES2TexStorageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001775 TextureType target,
He Yunchaoced53ae2016-11-29 15:00:51 +08001776 GLsizei levels,
1777 GLenum internalformat,
1778 GLsizei width,
1779 GLsizei height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001780{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001781 if (target != TextureType::_2D && target != TextureType::CubeMap &&
1782 target != TextureType::Rectangle)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001783 {
Jamie Madille0472f32018-11-27 16:32:45 -05001784 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001785 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001786 }
1787
1788 if (width < 1 || height < 1 || levels < 1)
1789 {
Jamie Madille0472f32018-11-27 16:32:45 -05001790 context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall);
Geoff Langb1196682014-07-23 13:47:29 -04001791 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001792 }
1793
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001794 if (target == TextureType::CubeMap && width != height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001795 {
Jamie Madille0472f32018-11-27 16:32:45 -05001796 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Langb1196682014-07-23 13:47:29 -04001797 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001798 }
1799
1800 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1801 {
Jamie Madille0472f32018-11-27 16:32:45 -05001802 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
Geoff Langb1196682014-07-23 13:47:29 -04001803 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001804 }
1805
Geoff Langca271392017-04-05 12:30:00 -04001806 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Lang5d601382014-07-22 15:14:06 -04001807 if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001808 {
Jamie Madille0472f32018-11-27 16:32:45 -05001809 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Langb1196682014-07-23 13:47:29 -04001810 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001811 }
1812
Geoff Langaae65a42014-05-26 12:43:44 -04001813 const gl::Caps &caps = context->getCaps();
1814
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001815 switch (target)
1816 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001817 case TextureType::_2D:
He Yunchaoced53ae2016-11-29 15:00:51 +08001818 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
1819 static_cast<GLuint>(height) > caps.max2DTextureSize)
1820 {
Jamie Madille0472f32018-11-27 16:32:45 -05001821 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001822 return false;
1823 }
1824 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001825 case TextureType::Rectangle:
Jamie Madill610640f2018-11-21 17:28:41 -05001826 if (levels != 1)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001827 {
Jamie Madille0472f32018-11-27 16:32:45 -05001828 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madill610640f2018-11-21 17:28:41 -05001829 return false;
1830 }
1831
1832 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1833 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1834 {
Jamie Madille0472f32018-11-27 16:32:45 -05001835 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001836 return false;
1837 }
1838 if (formatInfo.compressed)
1839 {
Jamie Madille0472f32018-11-27 16:32:45 -05001840 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001841 return false;
1842 }
1843 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001844 case TextureType::CubeMap:
He Yunchaoced53ae2016-11-29 15:00:51 +08001845 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize ||
1846 static_cast<GLuint>(height) > caps.maxCubeMapTextureSize)
1847 {
Jamie Madille0472f32018-11-27 16:32:45 -05001848 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001849 return false;
1850 }
1851 break;
1852 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001853 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001854 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001855 }
1856
Geoff Langc0b9ef42014-07-02 10:02:37 -04001857 if (levels != 1 && !context->getExtensions().textureNPOT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001858 {
1859 if (!gl::isPow2(width) || !gl::isPow2(height))
1860 {
Jamie Madille0472f32018-11-27 16:32:45 -05001861 context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2);
Geoff Langb1196682014-07-23 13:47:29 -04001862 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001863 }
1864 }
1865
1866 switch (internalformat)
1867 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001868 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1869 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1870 if (!context->getExtensions().textureCompressionDXT1)
1871 {
Jamie Madille0472f32018-11-27 16:32:45 -05001872 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001873 return false;
1874 }
1875 break;
1876 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1877 if (!context->getExtensions().textureCompressionDXT3)
1878 {
Jamie Madille0472f32018-11-27 16:32:45 -05001879 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001880 return false;
1881 }
1882 break;
1883 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1884 if (!context->getExtensions().textureCompressionDXT5)
1885 {
Jamie Madille0472f32018-11-27 16:32:45 -05001886 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001887 return false;
1888 }
1889 break;
1890 case GL_ETC1_RGB8_OES:
1891 if (!context->getExtensions().compressedETC1RGB8Texture)
1892 {
Jamie Madille0472f32018-11-27 16:32:45 -05001893 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001894 return false;
1895 }
1896 break;
1897 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001898 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1899 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1900 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1901 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001902 if (!context->getExtensions().lossyETCDecode)
1903 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001904 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001905 return false;
1906 }
1907 break;
1908 case GL_RGBA32F_EXT:
1909 case GL_RGB32F_EXT:
1910 case GL_ALPHA32F_EXT:
1911 case GL_LUMINANCE32F_EXT:
1912 case GL_LUMINANCE_ALPHA32F_EXT:
1913 if (!context->getExtensions().textureFloat)
1914 {
Jamie Madille0472f32018-11-27 16:32:45 -05001915 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001916 return false;
1917 }
1918 break;
1919 case GL_RGBA16F_EXT:
1920 case GL_RGB16F_EXT:
1921 case GL_ALPHA16F_EXT:
1922 case GL_LUMINANCE16F_EXT:
1923 case GL_LUMINANCE_ALPHA16F_EXT:
1924 if (!context->getExtensions().textureHalfFloat)
1925 {
Jamie Madille0472f32018-11-27 16:32:45 -05001926 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001927 return false;
1928 }
1929 break;
1930 case GL_R8_EXT:
1931 case GL_RG8_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001932 if (!context->getExtensions().textureRG)
1933 {
Jamie Madille0472f32018-11-27 16:32:45 -05001934 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001935 return false;
1936 }
1937 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001938 case GL_R16F_EXT:
1939 case GL_RG16F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001940 if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat)
1941 {
Jamie Madille0472f32018-11-27 16:32:45 -05001942 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001943 return false;
1944 }
1945 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001946 case GL_R32F_EXT:
1947 case GL_RG32F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001948 if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat)
He Yunchaoced53ae2016-11-29 15:00:51 +08001949 {
Jamie Madille0472f32018-11-27 16:32:45 -05001950 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001951 return false;
1952 }
1953 break;
1954 case GL_DEPTH_COMPONENT16:
1955 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001956 if (!(context->getExtensions().depthTextureAny()))
He Yunchaoced53ae2016-11-29 15:00:51 +08001957 {
Jamie Madille0472f32018-11-27 16:32:45 -05001958 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001959 return false;
1960 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001961 if (target != TextureType::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001962 {
Jamie Madille0472f32018-11-27 16:32:45 -05001963 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001964 return false;
1965 }
1966 // ANGLE_depth_texture only supports 1-level textures
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001967 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001968 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001969 if (levels != 1)
1970 {
1971 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1972 return false;
1973 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001974 }
1975 break;
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001976 case GL_DEPTH24_STENCIL8_OES:
1977 if (!(context->getExtensions().depthTextureANGLE ||
1978 (context->getExtensions().packedDepthStencil &&
1979 context->getExtensions().textureStorage)))
1980 {
1981 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1982 return false;
1983 }
1984 if (target != TextureType::_2D)
1985 {
1986 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
1987 return false;
1988 }
1989 if (!context->getExtensions().packedDepthStencil)
1990 {
1991 // ANGLE_depth_texture only supports 1-level textures
1992 if (levels != 1)
1993 {
1994 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
1995 return false;
1996 }
1997 }
1998 break;
1999
He Yunchaoced53ae2016-11-29 15:00:51 +08002000 default:
2001 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002002 }
2003
Jamie Madillcfc73cc2019-04-08 16:26:51 -04002004 gl::Texture *texture = context->getTextureByType(target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002005 if (!texture || texture->id() == 0)
2006 {
Jamie Madille0472f32018-11-27 16:32:45 -05002007 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
Geoff Langb1196682014-07-23 13:47:29 -04002008 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002009 }
2010
Geoff Lang69cce582015-09-17 13:20:36 -04002011 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002012 {
Jamie Madille0472f32018-11-27 16:32:45 -05002013 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
Geoff Langb1196682014-07-23 13:47:29 -04002014 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002015 }
2016
2017 return true;
2018}
2019
He Yunchaoced53ae2016-11-29 15:00:51 +08002020bool ValidateDiscardFramebufferEXT(Context *context,
2021 GLenum target,
2022 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07002023 const GLenum *attachments)
2024{
Jamie Madillc29968b2016-01-20 11:17:23 -05002025 if (!context->getExtensions().discardFramebuffer)
2026 {
Jamie Madille0472f32018-11-27 16:32:45 -05002027 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002028 return false;
2029 }
2030
Austin Kinross08332632015-05-05 13:35:47 -07002031 bool defaultFramebuffer = false;
2032
2033 switch (target)
2034 {
He Yunchaoced53ae2016-11-29 15:00:51 +08002035 case GL_FRAMEBUFFER:
2036 defaultFramebuffer =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002037 (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0);
He Yunchaoced53ae2016-11-29 15:00:51 +08002038 break;
2039 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002040 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08002041 return false;
Austin Kinross08332632015-05-05 13:35:47 -07002042 }
2043
He Yunchaoced53ae2016-11-29 15:00:51 +08002044 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
2045 defaultFramebuffer);
Austin Kinross08332632015-05-05 13:35:47 -07002046}
2047
Austin Kinrossbc781f32015-10-26 09:27:38 -07002048bool ValidateBindVertexArrayOES(Context *context, GLuint array)
2049{
2050 if (!context->getExtensions().vertexArrayObject)
2051 {
Jamie Madille0472f32018-11-27 16:32:45 -05002052 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002053 return false;
2054 }
2055
2056 return ValidateBindVertexArrayBase(context, array);
2057}
2058
Jamie Madilld7576732017-08-26 18:49:50 -04002059bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002060{
2061 if (!context->getExtensions().vertexArrayObject)
2062 {
Jamie Madille0472f32018-11-27 16:32:45 -05002063 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002064 return false;
2065 }
2066
Olli Etuaho41997e72016-03-10 13:38:39 +02002067 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002068}
2069
Jamie Madilld7576732017-08-26 18:49:50 -04002070bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002071{
2072 if (!context->getExtensions().vertexArrayObject)
2073 {
Jamie Madille0472f32018-11-27 16:32:45 -05002074 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002075 return false;
2076 }
2077
Olli Etuaho41997e72016-03-10 13:38:39 +02002078 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002079}
2080
Jamie Madilld7576732017-08-26 18:49:50 -04002081bool ValidateIsVertexArrayOES(Context *context, GLuint array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002082{
2083 if (!context->getExtensions().vertexArrayObject)
2084 {
Jamie Madille0472f32018-11-27 16:32:45 -05002085 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002086 return false;
2087 }
2088
2089 return true;
2090}
Geoff Langc5629752015-12-07 16:29:04 -05002091
2092bool ValidateProgramBinaryOES(Context *context,
2093 GLuint program,
2094 GLenum binaryFormat,
2095 const void *binary,
2096 GLint length)
2097{
2098 if (!context->getExtensions().getProgramBinary)
2099 {
Jamie Madille0472f32018-11-27 16:32:45 -05002100 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002101 return false;
2102 }
2103
2104 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
2105}
2106
2107bool ValidateGetProgramBinaryOES(Context *context,
2108 GLuint program,
2109 GLsizei bufSize,
2110 GLsizei *length,
2111 GLenum *binaryFormat,
2112 void *binary)
2113{
2114 if (!context->getExtensions().getProgramBinary)
2115 {
Jamie Madille0472f32018-11-27 16:32:45 -05002116 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002117 return false;
2118 }
2119
2120 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
2121}
Geoff Lange102fee2015-12-10 11:23:30 -05002122
Geoff Lang70d0f492015-12-10 17:45:46 -05002123static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication)
2124{
2125 switch (source)
2126 {
2127 case GL_DEBUG_SOURCE_API:
2128 case GL_DEBUG_SOURCE_SHADER_COMPILER:
2129 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
2130 case GL_DEBUG_SOURCE_OTHER:
2131 // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted
2132 return !mustBeThirdPartyOrApplication;
2133
2134 case GL_DEBUG_SOURCE_THIRD_PARTY:
2135 case GL_DEBUG_SOURCE_APPLICATION:
2136 return true;
2137
2138 default:
2139 return false;
2140 }
2141}
2142
2143static bool ValidDebugType(GLenum type)
2144{
2145 switch (type)
2146 {
2147 case GL_DEBUG_TYPE_ERROR:
2148 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
2149 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
2150 case GL_DEBUG_TYPE_PERFORMANCE:
2151 case GL_DEBUG_TYPE_PORTABILITY:
2152 case GL_DEBUG_TYPE_OTHER:
2153 case GL_DEBUG_TYPE_MARKER:
2154 case GL_DEBUG_TYPE_PUSH_GROUP:
2155 case GL_DEBUG_TYPE_POP_GROUP:
2156 return true;
2157
2158 default:
2159 return false;
2160 }
2161}
2162
2163static bool ValidDebugSeverity(GLenum severity)
2164{
2165 switch (severity)
2166 {
2167 case GL_DEBUG_SEVERITY_HIGH:
2168 case GL_DEBUG_SEVERITY_MEDIUM:
2169 case GL_DEBUG_SEVERITY_LOW:
2170 case GL_DEBUG_SEVERITY_NOTIFICATION:
2171 return true;
2172
2173 default:
2174 return false;
2175 }
2176}
2177
Geoff Lange102fee2015-12-10 11:23:30 -05002178bool ValidateDebugMessageControlKHR(Context *context,
2179 GLenum source,
2180 GLenum type,
2181 GLenum severity,
2182 GLsizei count,
2183 const GLuint *ids,
2184 GLboolean enabled)
2185{
2186 if (!context->getExtensions().debug)
2187 {
Jamie Madille0472f32018-11-27 16:32:45 -05002188 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002189 return false;
2190 }
2191
Geoff Lang70d0f492015-12-10 17:45:46 -05002192 if (!ValidDebugSource(source, false) && source != GL_DONT_CARE)
2193 {
Jamie Madille0472f32018-11-27 16:32:45 -05002194 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002195 return false;
2196 }
2197
2198 if (!ValidDebugType(type) && type != GL_DONT_CARE)
2199 {
Jamie Madille0472f32018-11-27 16:32:45 -05002200 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002201 return false;
2202 }
2203
2204 if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE)
2205 {
Jamie Madille0472f32018-11-27 16:32:45 -05002206 context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002207 return false;
2208 }
2209
2210 if (count > 0)
2211 {
2212 if (source == GL_DONT_CARE || type == GL_DONT_CARE)
2213 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002214 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002215 return false;
2216 }
2217
2218 if (severity != GL_DONT_CARE)
2219 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002220 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002221 return false;
2222 }
2223 }
2224
Geoff Lange102fee2015-12-10 11:23:30 -05002225 return true;
2226}
2227
2228bool ValidateDebugMessageInsertKHR(Context *context,
2229 GLenum source,
2230 GLenum type,
2231 GLuint id,
2232 GLenum severity,
2233 GLsizei length,
2234 const GLchar *buf)
2235{
2236 if (!context->getExtensions().debug)
2237 {
Jamie Madille0472f32018-11-27 16:32:45 -05002238 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002239 return false;
2240 }
2241
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002242 if (!context->getState().getDebug().isOutputEnabled())
Geoff Lang70d0f492015-12-10 17:45:46 -05002243 {
2244 // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do
2245 // not generate an error.
2246 return false;
2247 }
2248
2249 if (!ValidDebugSeverity(severity))
2250 {
Jamie Madille0472f32018-11-27 16:32:45 -05002251 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002252 return false;
2253 }
2254
2255 if (!ValidDebugType(type))
2256 {
Jamie Madille0472f32018-11-27 16:32:45 -05002257 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002258 return false;
2259 }
2260
2261 if (!ValidDebugSource(source, true))
2262 {
Jamie Madille0472f32018-11-27 16:32:45 -05002263 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002264 return false;
2265 }
2266
2267 size_t messageLength = (length < 0) ? strlen(buf) : length;
2268 if (messageLength > context->getExtensions().maxDebugMessageLength)
2269 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002270 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002271 return false;
2272 }
2273
Geoff Lange102fee2015-12-10 11:23:30 -05002274 return true;
2275}
2276
2277bool ValidateDebugMessageCallbackKHR(Context *context,
2278 GLDEBUGPROCKHR callback,
2279 const void *userParam)
2280{
2281 if (!context->getExtensions().debug)
2282 {
Jamie Madille0472f32018-11-27 16:32:45 -05002283 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002284 return false;
2285 }
2286
Geoff Lange102fee2015-12-10 11:23:30 -05002287 return true;
2288}
2289
2290bool ValidateGetDebugMessageLogKHR(Context *context,
2291 GLuint count,
2292 GLsizei bufSize,
2293 GLenum *sources,
2294 GLenum *types,
2295 GLuint *ids,
2296 GLenum *severities,
2297 GLsizei *lengths,
2298 GLchar *messageLog)
2299{
2300 if (!context->getExtensions().debug)
2301 {
Jamie Madille0472f32018-11-27 16:32:45 -05002302 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002303 return false;
2304 }
2305
Geoff Lang70d0f492015-12-10 17:45:46 -05002306 if (bufSize < 0 && messageLog != nullptr)
2307 {
Jamie Madille0472f32018-11-27 16:32:45 -05002308 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002309 return false;
2310 }
2311
Geoff Lange102fee2015-12-10 11:23:30 -05002312 return true;
2313}
2314
2315bool ValidatePushDebugGroupKHR(Context *context,
2316 GLenum source,
2317 GLuint id,
2318 GLsizei length,
2319 const GLchar *message)
2320{
2321 if (!context->getExtensions().debug)
2322 {
Jamie Madille0472f32018-11-27 16:32:45 -05002323 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002324 return false;
2325 }
2326
Geoff Lang70d0f492015-12-10 17:45:46 -05002327 if (!ValidDebugSource(source, true))
2328 {
Jamie Madille0472f32018-11-27 16:32:45 -05002329 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002330 return false;
2331 }
2332
2333 size_t messageLength = (length < 0) ? strlen(message) : length;
2334 if (messageLength > context->getExtensions().maxDebugMessageLength)
2335 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002336 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002337 return false;
2338 }
2339
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002340 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002341 if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth)
2342 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002343 context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth);
Geoff Lang70d0f492015-12-10 17:45:46 -05002344 return false;
2345 }
2346
Geoff Lange102fee2015-12-10 11:23:30 -05002347 return true;
2348}
2349
2350bool ValidatePopDebugGroupKHR(Context *context)
2351{
2352 if (!context->getExtensions().debug)
2353 {
Jamie Madille0472f32018-11-27 16:32:45 -05002354 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002355 return false;
2356 }
2357
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002358 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002359 if (currentStackSize <= 1)
2360 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002361 context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup);
Geoff Lang70d0f492015-12-10 17:45:46 -05002362 return false;
2363 }
2364
2365 return true;
2366}
2367
2368static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name)
2369{
2370 switch (identifier)
2371 {
2372 case GL_BUFFER:
2373 if (context->getBuffer(name) == nullptr)
2374 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002375 context->validationError(GL_INVALID_VALUE, kInvalidBufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002376 return false;
2377 }
2378 return true;
2379
2380 case GL_SHADER:
2381 if (context->getShader(name) == nullptr)
2382 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002383 context->validationError(GL_INVALID_VALUE, kInvalidShaderName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002384 return false;
2385 }
2386 return true;
2387
2388 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002389 if (context->getProgramNoResolveLink(name) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002390 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002391 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002392 return false;
2393 }
2394 return true;
2395
2396 case GL_VERTEX_ARRAY:
2397 if (context->getVertexArray(name) == nullptr)
2398 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002399 context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002400 return false;
2401 }
2402 return true;
2403
2404 case GL_QUERY:
2405 if (context->getQuery(name) == nullptr)
2406 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002407 context->validationError(GL_INVALID_VALUE, kInvalidQueryName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002408 return false;
2409 }
2410 return true;
2411
2412 case GL_TRANSFORM_FEEDBACK:
2413 if (context->getTransformFeedback(name) == nullptr)
2414 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002415 context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002416 return false;
2417 }
2418 return true;
2419
2420 case GL_SAMPLER:
2421 if (context->getSampler(name) == nullptr)
2422 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002423 context->validationError(GL_INVALID_VALUE, kInvalidSamplerName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002424 return false;
2425 }
2426 return true;
2427
2428 case GL_TEXTURE:
2429 if (context->getTexture(name) == nullptr)
2430 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002431 context->validationError(GL_INVALID_VALUE, kInvalidTextureName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002432 return false;
2433 }
2434 return true;
2435
2436 case GL_RENDERBUFFER:
2437 if (context->getRenderbuffer(name) == nullptr)
2438 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002439 context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002440 return false;
2441 }
2442 return true;
2443
2444 case GL_FRAMEBUFFER:
2445 if (context->getFramebuffer(name) == nullptr)
2446 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002447 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002448 return false;
2449 }
2450 return true;
2451
2452 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05002453 context->validationError(GL_INVALID_ENUM, kInvalidIndentifier);
Geoff Lang70d0f492015-12-10 17:45:46 -05002454 return false;
2455 }
Geoff Lange102fee2015-12-10 11:23:30 -05002456}
2457
Martin Radev9d901792016-07-15 15:58:58 +03002458static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label)
2459{
2460 size_t labelLength = 0;
2461
2462 if (length < 0)
2463 {
2464 if (label != nullptr)
2465 {
2466 labelLength = strlen(label);
2467 }
2468 }
2469 else
2470 {
2471 labelLength = static_cast<size_t>(length);
2472 }
2473
2474 if (labelLength > context->getExtensions().maxLabelLength)
2475 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002476 context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength);
Martin Radev9d901792016-07-15 15:58:58 +03002477 return false;
2478 }
2479
2480 return true;
2481}
2482
Geoff Lange102fee2015-12-10 11:23:30 -05002483bool ValidateObjectLabelKHR(Context *context,
2484 GLenum identifier,
2485 GLuint name,
2486 GLsizei length,
2487 const GLchar *label)
2488{
2489 if (!context->getExtensions().debug)
2490 {
Jamie Madille0472f32018-11-27 16:32:45 -05002491 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002492 return false;
2493 }
2494
Geoff Lang70d0f492015-12-10 17:45:46 -05002495 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2496 {
2497 return false;
2498 }
2499
Martin Radev9d901792016-07-15 15:58:58 +03002500 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002501 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002502 return false;
2503 }
2504
Geoff Lange102fee2015-12-10 11:23:30 -05002505 return true;
2506}
2507
2508bool ValidateGetObjectLabelKHR(Context *context,
2509 GLenum identifier,
2510 GLuint name,
2511 GLsizei bufSize,
2512 GLsizei *length,
2513 GLchar *label)
2514{
2515 if (!context->getExtensions().debug)
2516 {
Jamie Madille0472f32018-11-27 16:32:45 -05002517 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002518 return false;
2519 }
2520
Geoff Lang70d0f492015-12-10 17:45:46 -05002521 if (bufSize < 0)
2522 {
Jamie Madille0472f32018-11-27 16:32:45 -05002523 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002524 return false;
2525 }
2526
2527 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2528 {
2529 return false;
2530 }
2531
Martin Radev9d901792016-07-15 15:58:58 +03002532 return true;
Geoff Lang70d0f492015-12-10 17:45:46 -05002533}
2534
2535static bool ValidateObjectPtrName(Context *context, const void *ptr)
2536{
Jamie Madill70b5bb02017-08-28 13:32:37 -04002537 if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002538 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002539 context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer);
Geoff Lang70d0f492015-12-10 17:45:46 -05002540 return false;
2541 }
2542
Geoff Lange102fee2015-12-10 11:23:30 -05002543 return true;
2544}
2545
2546bool ValidateObjectPtrLabelKHR(Context *context,
2547 const void *ptr,
2548 GLsizei length,
2549 const GLchar *label)
2550{
2551 if (!context->getExtensions().debug)
2552 {
Jamie Madille0472f32018-11-27 16:32:45 -05002553 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002554 return false;
2555 }
2556
Geoff Lang70d0f492015-12-10 17:45:46 -05002557 if (!ValidateObjectPtrName(context, ptr))
2558 {
2559 return false;
2560 }
2561
Martin Radev9d901792016-07-15 15:58:58 +03002562 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002563 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002564 return false;
2565 }
2566
Geoff Lange102fee2015-12-10 11:23:30 -05002567 return true;
2568}
2569
2570bool ValidateGetObjectPtrLabelKHR(Context *context,
2571 const void *ptr,
2572 GLsizei bufSize,
2573 GLsizei *length,
2574 GLchar *label)
2575{
2576 if (!context->getExtensions().debug)
2577 {
Jamie Madille0472f32018-11-27 16:32:45 -05002578 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002579 return false;
2580 }
2581
Geoff Lang70d0f492015-12-10 17:45:46 -05002582 if (bufSize < 0)
2583 {
Jamie Madille0472f32018-11-27 16:32:45 -05002584 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002585 return false;
2586 }
2587
2588 if (!ValidateObjectPtrName(context, ptr))
2589 {
2590 return false;
2591 }
2592
Martin Radev9d901792016-07-15 15:58:58 +03002593 return true;
Geoff Lange102fee2015-12-10 11:23:30 -05002594}
2595
2596bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params)
2597{
2598 if (!context->getExtensions().debug)
2599 {
Jamie Madille0472f32018-11-27 16:32:45 -05002600 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002601 return false;
2602 }
2603
Geoff Lang70d0f492015-12-10 17:45:46 -05002604 // TODO: represent this in Context::getQueryParameterInfo.
2605 switch (pname)
2606 {
2607 case GL_DEBUG_CALLBACK_FUNCTION:
2608 case GL_DEBUG_CALLBACK_USER_PARAM:
2609 break;
2610
2611 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002612 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang70d0f492015-12-10 17:45:46 -05002613 return false;
2614 }
2615
Geoff Lange102fee2015-12-10 11:23:30 -05002616 return true;
2617}
Jamie Madillc29968b2016-01-20 11:17:23 -05002618
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002619bool ValidateGetPointervRobustANGLERobustANGLE(Context *context,
2620 GLenum pname,
2621 GLsizei bufSize,
2622 GLsizei *length,
2623 void **params)
2624{
2625 UNIMPLEMENTED();
2626 return false;
2627}
2628
Jamie Madillc29968b2016-01-20 11:17:23 -05002629bool ValidateBlitFramebufferANGLE(Context *context,
2630 GLint srcX0,
2631 GLint srcY0,
2632 GLint srcX1,
2633 GLint srcY1,
2634 GLint dstX0,
2635 GLint dstY0,
2636 GLint dstX1,
2637 GLint dstY1,
2638 GLbitfield mask,
2639 GLenum filter)
2640{
2641 if (!context->getExtensions().framebufferBlit)
2642 {
Jamie Madille0472f32018-11-27 16:32:45 -05002643 context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable);
Jamie Madillc29968b2016-01-20 11:17:23 -05002644 return false;
2645 }
2646
2647 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
2648 {
2649 // TODO(jmadill): Determine if this should be available on other implementations.
Jamie Madille0472f32018-11-27 16:32:45 -05002650 context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip);
Jamie Madillc29968b2016-01-20 11:17:23 -05002651 return false;
2652 }
2653
2654 if (filter == GL_LINEAR)
2655 {
Jamie Madille0472f32018-11-27 16:32:45 -05002656 context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear);
Jamie Madillc29968b2016-01-20 11:17:23 -05002657 return false;
2658 }
2659
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002660 Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
2661 Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002662
2663 if (mask & GL_COLOR_BUFFER_BIT)
2664 {
2665 const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer();
2666 const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer();
2667
2668 if (readColorAttachment && drawColorAttachment)
2669 {
2670 if (!(readColorAttachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002671 readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002672 readColorAttachment->type() != GL_RENDERBUFFER &&
2673 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2674 {
Jamie Madill610640f2018-11-21 17:28:41 -05002675 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002676 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002677 return false;
2678 }
2679
Geoff Langa15472a2015-08-11 11:48:03 -04002680 for (size_t drawbufferIdx = 0;
2681 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002682 {
Geoff Langa15472a2015-08-11 11:48:03 -04002683 const FramebufferAttachment *attachment =
2684 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2685 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002686 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002687 if (!(attachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002688 attachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002689 attachment->type() != GL_RENDERBUFFER &&
2690 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2691 {
Jamie Madill610640f2018-11-21 17:28:41 -05002692 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002693 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002694 return false;
2695 }
2696
2697 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002698 if (!Format::EquivalentForBlit(attachment->getFormat(),
2699 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002700 {
Jamie Madill610640f2018-11-21 17:28:41 -05002701 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002702 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002703 return false;
2704 }
2705 }
2706 }
2707
Jamie Madill427064d2018-04-13 16:20:34 -04002708 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002709 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002710 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2711 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2712 {
Jamie Madill610640f2018-11-21 17:28:41 -05002713 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002714 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002715 return false;
2716 }
2717 }
2718 }
2719
2720 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2721 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2722 for (size_t i = 0; i < 2; i++)
2723 {
2724 if (mask & masks[i])
2725 {
2726 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002727 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002728 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002729 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002730
2731 if (readBuffer && drawBuffer)
2732 {
2733 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2734 dstX0, dstY0, dstX1, dstY1))
2735 {
2736 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002737 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002738 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002739 return false;
2740 }
2741
2742 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2743 {
Jamie Madill610640f2018-11-21 17:28:41 -05002744 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002745 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002746 return false;
2747 }
2748 }
2749 }
2750 }
2751
2752 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2753 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002754}
Jamie Madillc29968b2016-01-20 11:17:23 -05002755
Jamie Madill5b772312018-03-08 20:28:32 -05002756bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002757{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002758 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002759 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002760
Jamie Madill427064d2018-04-13 16:20:34 -04002761 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002762 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002763 return false;
2764 }
2765
2766 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2767 {
Jamie Madille0472f32018-11-27 16:32:45 -05002768 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002769 return false;
2770 }
2771
Olli Etuaho94c91a92018-07-19 15:10:24 +03002772 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002773 {
2774 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2775 GL_SIGNED_NORMALIZED};
2776
Corentin Wallez59c41592017-07-11 13:19:54 -04002777 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002778 drawBufferIdx++)
2779 {
2780 if (!ValidateWebGLFramebufferAttachmentClearType(
2781 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2782 {
2783 return false;
2784 }
2785 }
2786 }
2787
Mingyu Huebab6702019-04-19 14:36:45 -07002788 if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery)
Olli Etuaho94c91a92018-07-19 15:10:24 +03002789 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002790 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002791 Framebuffer *framebuffer = state.getDrawFramebuffer();
2792 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2793 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002794 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002795 return false;
2796 }
2797 }
2798
Jamie Madillc29968b2016-01-20 11:17:23 -05002799 return true;
2800}
2801
Jamie Madill5b772312018-03-08 20:28:32 -05002802bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002803{
2804 if (!context->getExtensions().drawBuffers)
2805 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002806 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002807 return false;
2808 }
2809
2810 return ValidateDrawBuffersBase(context, n, bufs);
2811}
2812
Jamie Madill73a84962016-02-12 09:27:23 -05002813bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002814 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002815 GLint level,
2816 GLint internalformat,
2817 GLsizei width,
2818 GLsizei height,
2819 GLint border,
2820 GLenum format,
2821 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002822 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002823{
Martin Radev1be913c2016-07-11 17:59:16 +03002824 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002825 {
2826 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002827 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002828 }
2829
Martin Radev1be913c2016-07-11 17:59:16 +03002830 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002831 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002832 0, 0, width, height, 1, border, format, type, -1,
2833 pixels);
2834}
2835
Brandon Jones416aaf92018-04-10 08:10:16 -07002836bool ValidateTexImage2DRobustANGLE(Context *context,
2837 TextureTarget target,
2838 GLint level,
2839 GLint internalformat,
2840 GLsizei width,
2841 GLsizei height,
2842 GLint border,
2843 GLenum format,
2844 GLenum type,
2845 GLsizei bufSize,
2846 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04002847{
2848 if (!ValidateRobustEntryPoint(context, bufSize))
2849 {
2850 return false;
2851 }
2852
2853 if (context->getClientMajorVersion() < 3)
2854 {
2855 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
2856 0, 0, width, height, border, format, type, bufSize,
2857 pixels);
2858 }
2859
2860 ASSERT(context->getClientMajorVersion() >= 3);
2861 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
2862 0, 0, width, height, 1, border, format, type, bufSize,
2863 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002864}
2865
2866bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002867 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002868 GLint level,
2869 GLint xoffset,
2870 GLint yoffset,
2871 GLsizei width,
2872 GLsizei height,
2873 GLenum format,
2874 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002875 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002876{
2877
Martin Radev1be913c2016-07-11 17:59:16 +03002878 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002879 {
2880 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002881 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002882 }
2883
Martin Radev1be913c2016-07-11 17:59:16 +03002884 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002885 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002886 yoffset, 0, width, height, 1, 0, format, type, -1,
2887 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002888}
2889
Geoff Langc52f6f12016-10-14 10:18:00 -04002890bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002891 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04002892 GLint level,
2893 GLint xoffset,
2894 GLint yoffset,
2895 GLsizei width,
2896 GLsizei height,
2897 GLenum format,
2898 GLenum type,
2899 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002900 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04002901{
2902 if (!ValidateRobustEntryPoint(context, bufSize))
2903 {
2904 return false;
2905 }
2906
2907 if (context->getClientMajorVersion() < 3)
2908 {
2909 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
2910 yoffset, width, height, 0, format, type, bufSize,
2911 pixels);
2912 }
2913
2914 ASSERT(context->getClientMajorVersion() >= 3);
2915 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
2916 yoffset, 0, width, height, 1, 0, format, type, bufSize,
2917 pixels);
2918}
2919
Jamie Madill73a84962016-02-12 09:27:23 -05002920bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002921 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002922 GLint level,
2923 GLenum internalformat,
2924 GLsizei width,
2925 GLsizei height,
2926 GLint border,
2927 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002928 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002929{
Martin Radev1be913c2016-07-11 17:59:16 +03002930 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002931 {
2932 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002933 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002934 {
2935 return false;
2936 }
2937 }
2938 else
2939 {
Martin Radev1be913c2016-07-11 17:59:16 +03002940 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002941 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002942 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002943 data))
2944 {
2945 return false;
2946 }
2947 }
2948
Geoff Langca271392017-04-05 12:30:00 -04002949 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04002950
2951 GLuint blockSize = 0;
2952 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002953 {
Jamie Madille0472f32018-11-27 16:32:45 -05002954 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002955 return false;
2956 }
2957
Jamie Madillca2ff382018-07-11 09:01:17 -04002958 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002959 {
Jamie Madille0472f32018-11-27 16:32:45 -05002960 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05002961 return false;
2962 }
2963
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002964 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002965 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002966 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002967 return false;
2968 }
2969
Jamie Madill73a84962016-02-12 09:27:23 -05002970 return true;
2971}
2972
Corentin Wallezb2931602017-04-11 15:58:57 -04002973bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002974 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002975 GLint level,
2976 GLenum internalformat,
2977 GLsizei width,
2978 GLsizei height,
2979 GLint border,
2980 GLsizei imageSize,
2981 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002982 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002983{
2984 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2985 {
2986 return false;
2987 }
2988
2989 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
2990 border, imageSize, data);
2991}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002992
Corentin Wallezb2931602017-04-11 15:58:57 -04002993bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002994 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002995 GLint level,
2996 GLint xoffset,
2997 GLint yoffset,
2998 GLsizei width,
2999 GLsizei height,
3000 GLenum format,
3001 GLsizei imageSize,
3002 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003003 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003004{
3005 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3006 {
3007 return false;
3008 }
3009
3010 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
3011 format, imageSize, data);
3012}
3013
Jamie Madill73a84962016-02-12 09:27:23 -05003014bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003015 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003016 GLint level,
3017 GLint xoffset,
3018 GLint yoffset,
3019 GLsizei width,
3020 GLsizei height,
3021 GLenum format,
3022 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003023 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003024{
Martin Radev1be913c2016-07-11 17:59:16 +03003025 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05003026 {
3027 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003028 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05003029 {
3030 return false;
3031 }
3032 }
3033 else
3034 {
Martin Radev1be913c2016-07-11 17:59:16 +03003035 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003036 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003037 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05003038 data))
3039 {
3040 return false;
3041 }
3042 }
3043
Geoff Langca271392017-04-05 12:30:00 -04003044 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04003045 GLuint blockSize = 0;
3046 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003047 {
Jamie Madille0472f32018-11-27 16:32:45 -05003048 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003049 return false;
3050 }
3051
Jamie Madillca2ff382018-07-11 09:01:17 -04003052 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003053 {
Jamie Madille0472f32018-11-27 16:32:45 -05003054 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05003055 return false;
3056 }
3057
3058 return true;
3059}
3060
Corentin Wallez336129f2017-10-17 15:55:40 -04003061bool ValidateGetBufferPointervOES(Context *context,
3062 BufferBinding target,
3063 GLenum pname,
3064 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003065{
Jamie Madillc3e37312018-11-30 15:25:39 -05003066 if (!context->getExtensions().mapBuffer)
3067 {
3068 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3069 return false;
3070 }
3071
Geoff Lang496c02d2016-10-20 11:38:11 -07003072 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003073}
3074
Corentin Wallez336129f2017-10-17 15:55:40 -04003075bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003076{
3077 if (!context->getExtensions().mapBuffer)
3078 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003079 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003080 return false;
3081 }
3082
Corentin Walleze4477002017-12-01 14:39:58 -05003083 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03003084 {
Jamie Madille0472f32018-11-27 16:32:45 -05003085 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03003086 return false;
3087 }
3088
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003089 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003090
3091 if (buffer == nullptr)
3092 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003093 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03003094 return false;
3095 }
3096
3097 if (access != GL_WRITE_ONLY_OES)
3098 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003099 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03003100 return false;
3101 }
3102
3103 if (buffer->isMapped())
3104 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003105 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003106 return false;
3107 }
3108
Geoff Lang79f71042017-08-14 16:43:43 -04003109 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003110}
3111
Corentin Wallez336129f2017-10-17 15:55:40 -04003112bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003113{
3114 if (!context->getExtensions().mapBuffer)
3115 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003116 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003117 return false;
3118 }
3119
3120 return ValidateUnmapBufferBase(context, target);
3121}
3122
3123bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003124 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003125 GLintptr offset,
3126 GLsizeiptr length,
3127 GLbitfield access)
3128{
3129 if (!context->getExtensions().mapBufferRange)
3130 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003131 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003132 return false;
3133 }
3134
3135 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3136}
3137
Michael Spang7a8c3e52019-04-03 14:49:57 -04003138bool ValidateBufferStorageMemEXT(Context *context,
3139 TextureType target,
3140 GLsizeiptr size,
3141 GLuint memory,
3142 GLuint64 offset)
3143{
3144 if (!context->getExtensions().memoryObject)
3145 {
3146 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3147 return false;
3148 }
3149
3150 UNIMPLEMENTED();
3151 return false;
3152}
3153
3154bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects)
3155{
3156 if (!context->getExtensions().memoryObject)
3157 {
3158 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3159 return false;
3160 }
3161
Michael Spangfb201c52019-04-03 14:57:35 -04003162 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003163}
3164
3165bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects)
3166{
3167 if (!context->getExtensions().memoryObject)
3168 {
3169 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3170 return false;
3171 }
3172
Michael Spangfb201c52019-04-03 14:57:35 -04003173 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003174}
3175
3176bool ValidateGetMemoryObjectParameterivEXT(Context *context,
3177 GLuint memoryObject,
3178 GLenum pname,
3179 GLint *params)
3180{
3181 if (!context->getExtensions().memoryObject)
3182 {
3183 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3184 return false;
3185 }
3186
3187 UNIMPLEMENTED();
3188 return false;
3189}
3190
3191bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3192{
3193 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3194 {
3195 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3196 return false;
3197 }
3198
3199 UNIMPLEMENTED();
3200 return false;
3201}
3202
3203bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3204{
3205 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3206 {
3207 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3208 return false;
3209 }
3210
3211 UNIMPLEMENTED();
3212 return false;
3213}
3214
3215bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject)
3216{
3217 if (!context->getExtensions().memoryObject)
3218 {
3219 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3220 return false;
3221 }
3222
Michael Spangfb201c52019-04-03 14:57:35 -04003223 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003224}
3225
3226bool ValidateMemoryObjectParameterivEXT(Context *context,
3227 GLuint memoryObject,
3228 GLenum pname,
3229 const GLint *params)
3230{
3231 if (!context->getExtensions().memoryObject)
3232 {
3233 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3234 return false;
3235 }
3236
3237 UNIMPLEMENTED();
3238 return false;
3239}
3240
3241bool ValidateTexStorageMem2DEXT(Context *context,
3242 TextureType target,
3243 GLsizei levels,
3244 GLenum internalFormat,
3245 GLsizei width,
3246 GLsizei height,
3247 GLuint memory,
3248 GLuint64 offset)
3249{
3250 if (!context->getExtensions().memoryObject)
3251 {
3252 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3253 return false;
3254 }
3255
Michael Spangf02a7672019-04-09 18:45:23 -04003256 if (context->getClientMajorVersion() < 3)
3257 {
3258 return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width,
3259 height);
3260 }
3261
3262 ASSERT(context->getClientMajorVersion() >= 3);
3263 return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height,
3264 1);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003265}
3266
3267bool ValidateTexStorageMem3DEXT(Context *context,
3268 TextureType target,
3269 GLsizei levels,
3270 GLenum internalFormat,
3271 GLsizei width,
3272 GLsizei height,
3273 GLsizei depth,
3274 GLuint memory,
3275 GLuint64 offset)
3276{
3277 if (!context->getExtensions().memoryObject)
3278 {
3279 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3280 return false;
3281 }
3282
3283 UNIMPLEMENTED();
3284 return false;
3285}
3286
Michael Spang9de3ddb2019-04-03 16:23:40 -04003287bool ValidateImportMemoryFdEXT(Context *context,
3288 GLuint memory,
3289 GLuint64 size,
Michael Spange0da9ce2019-04-16 14:34:51 -04003290 HandleType handleType,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003291 GLint fd)
3292{
3293 if (!context->getExtensions().memoryObjectFd)
3294 {
3295 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3296 return false;
3297 }
3298
Michael Spang3b2c6bf2019-04-16 17:19:50 -04003299 switch (handleType)
3300 {
3301 case HandleType::OpaqueFd:
3302 break;
3303 default:
3304 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3305 return false;
3306 }
3307
3308 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003309}
3310
Michael Spang7a8c3e52019-04-03 14:49:57 -04003311bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores)
3312{
3313 if (!context->getExtensions().semaphore)
3314 {
3315 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3316 return false;
3317 }
3318
Michael Spang5093ba62019-05-14 17:36:36 -04003319 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003320}
3321
3322bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores)
3323{
3324 if (!context->getExtensions().semaphore)
3325 {
3326 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3327 return false;
3328 }
3329
Michael Spang5093ba62019-05-14 17:36:36 -04003330 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003331}
3332
3333bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
3334 GLuint semaphore,
3335 GLenum pname,
3336 GLuint64 *params)
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 ValidateIsSemaphoreEXT(Context *context, GLuint semaphore)
3349{
3350 if (!context->getExtensions().semaphore)
3351 {
3352 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3353 return false;
3354 }
3355
Michael Spang5093ba62019-05-14 17:36:36 -04003356 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003357}
3358
3359bool ValidateSemaphoreParameterui64vEXT(Context *context,
3360 GLuint semaphore,
3361 GLenum pname,
3362 const GLuint64 *params)
3363{
3364 if (!context->getExtensions().semaphore)
3365 {
3366 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3367 return false;
3368 }
3369
3370 UNIMPLEMENTED();
3371 return false;
3372}
3373
3374bool ValidateSignalSemaphoreEXT(Context *context,
3375 GLuint semaphore,
3376 GLuint numBufferBarriers,
3377 const GLuint *buffers,
3378 GLuint numTextureBarriers,
3379 const GLuint *textures,
3380 const GLenum *dstLayouts)
3381{
3382 if (!context->getExtensions().semaphore)
3383 {
3384 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3385 return false;
3386 }
3387
Michael Spangab6a59b2019-05-21 21:26:26 -04003388 for (GLuint i = 0; i < numTextureBarriers; ++i)
3389 {
3390 if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i])))
3391 {
3392 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3393 return false;
3394 }
3395 }
3396
3397 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003398}
3399
3400bool ValidateWaitSemaphoreEXT(Context *context,
3401 GLuint semaphore,
3402 GLuint numBufferBarriers,
3403 const GLuint *buffers,
3404 GLuint numTextureBarriers,
3405 const GLuint *textures,
3406 const GLenum *srcLayouts)
3407{
3408 if (!context->getExtensions().semaphore)
3409 {
3410 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3411 return false;
3412 }
3413
Michael Spangab6a59b2019-05-21 21:26:26 -04003414 for (GLuint i = 0; i < numTextureBarriers; ++i)
3415 {
3416 if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i])))
3417 {
3418 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3419 return false;
3420 }
3421 }
3422
3423 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003424}
3425
Michael Spange0da9ce2019-04-16 14:34:51 -04003426bool ValidateImportSemaphoreFdEXT(Context *context,
3427 GLuint semaphore,
3428 HandleType handleType,
3429 GLint fd)
Michael Spang9de3ddb2019-04-03 16:23:40 -04003430{
3431 if (!context->getExtensions().semaphoreFd)
3432 {
3433 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3434 return false;
3435 }
3436
Michael Spang6bb193c2019-05-22 16:32:21 -04003437 switch (handleType)
3438 {
3439 case HandleType::OpaqueFd:
3440 break;
3441 default:
3442 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3443 return false;
3444 }
3445
3446 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003447}
3448
Corentin Wallez336129f2017-10-17 15:55:40 -04003449bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003450{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003451 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003452 ASSERT(buffer != nullptr);
3453
3454 // Check if this buffer is currently being used as a transform feedback output buffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003455 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003456 if (transformFeedback != nullptr && transformFeedback->isActive())
3457 {
3458 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3459 {
3460 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3461 if (transformFeedbackBuffer.get() == buffer)
3462 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003463 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003464 return false;
3465 }
3466 }
3467 }
3468
James Darpiniane8a93c62018-01-04 18:02:24 -08003469 if (context->getExtensions().webglCompatibility &&
3470 buffer->isBoundForTransformFeedbackAndOtherUse())
3471 {
Jamie Madille0472f32018-11-27 16:32:45 -05003472 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003473 return false;
3474 }
3475
Geoff Lang79f71042017-08-14 16:43:43 -04003476 return true;
3477}
3478
Olli Etuaho4f667482016-03-30 15:56:35 +03003479bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003480 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003481 GLintptr offset,
3482 GLsizeiptr length)
3483{
3484 if (!context->getExtensions().mapBufferRange)
3485 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003486 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003487 return false;
3488 }
3489
3490 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3491}
3492
Geoff Langd8605522016-04-13 10:19:12 -04003493bool ValidateBindUniformLocationCHROMIUM(Context *context,
3494 GLuint program,
3495 GLint location,
3496 const GLchar *name)
3497{
3498 if (!context->getExtensions().bindUniformLocation)
3499 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003500 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003501 return false;
3502 }
3503
3504 Program *programObject = GetValidProgram(context, program);
3505 if (!programObject)
3506 {
3507 return false;
3508 }
3509
3510 if (location < 0)
3511 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003512 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003513 return false;
3514 }
3515
3516 const Caps &caps = context->getCaps();
3517 if (static_cast<size_t>(location) >=
3518 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3519 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003520 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003521 return false;
3522 }
3523
Geoff Langfc32e8b2017-05-31 14:16:59 -04003524 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3525 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003526 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003527 {
Jamie Madille0472f32018-11-27 16:32:45 -05003528 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003529 return false;
3530 }
3531
Geoff Langd8605522016-04-13 10:19:12 -04003532 if (strncmp(name, "gl_", 3) == 0)
3533 {
Jamie Madille0472f32018-11-27 16:32:45 -05003534 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003535 return false;
3536 }
3537
3538 return true;
3539}
3540
Jamie Madille2e406c2016-06-02 13:04:10 -04003541bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003542{
3543 if (!context->getExtensions().framebufferMixedSamples)
3544 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003545 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003546 return false;
3547 }
3548 switch (components)
3549 {
3550 case GL_RGB:
3551 case GL_RGBA:
3552 case GL_ALPHA:
3553 case GL_NONE:
3554 break;
3555 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003556 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003557 return false;
3558 }
3559
3560 return true;
3561}
3562
Sami Väisänene45e53b2016-05-25 10:36:04 +03003563// CHROMIUM_path_rendering
3564
Jamie Madill007530e2017-12-28 14:27:04 -05003565bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003566{
Jamie Madill007530e2017-12-28 14:27:04 -05003567 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003568 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003569 return false;
3570 }
Jamie Madill007530e2017-12-28 14:27:04 -05003571
Sami Väisänene45e53b2016-05-25 10:36:04 +03003572 if (matrix == nullptr)
3573 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003574 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003575 return false;
3576 }
Jamie Madill007530e2017-12-28 14:27:04 -05003577
Sami Väisänene45e53b2016-05-25 10:36:04 +03003578 return true;
3579}
3580
Jamie Madill007530e2017-12-28 14:27:04 -05003581bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003582{
Jamie Madill007530e2017-12-28 14:27:04 -05003583 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003584}
3585
Jamie Madill007530e2017-12-28 14:27:04 -05003586bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003587{
3588 if (!context->getExtensions().pathRendering)
3589 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003590 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003591 return false;
3592 }
3593
3594 // range = 0 is undefined in NV_path_rendering.
3595 // we add stricter semantic check here and require a non zero positive range.
3596 if (range <= 0)
3597 {
Jamie Madille0472f32018-11-27 16:32:45 -05003598 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003599 return false;
3600 }
3601
3602 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3603 {
Jamie Madille0472f32018-11-27 16:32:45 -05003604 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003605 return false;
3606 }
3607
3608 return true;
3609}
3610
Jamie Madill007530e2017-12-28 14:27:04 -05003611bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003612{
3613 if (!context->getExtensions().pathRendering)
3614 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003615 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003616 return false;
3617 }
3618
3619 // range = 0 is undefined in NV_path_rendering.
3620 // we add stricter semantic check here and require a non zero positive range.
3621 if (range <= 0)
3622 {
Jamie Madille0472f32018-11-27 16:32:45 -05003623 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003624 return false;
3625 }
3626
3627 angle::CheckedNumeric<std::uint32_t> checkedRange(path);
3628 checkedRange += range;
3629
3630 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3631 {
Jamie Madille0472f32018-11-27 16:32:45 -05003632 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003633 return false;
3634 }
3635 return true;
3636}
3637
Jamie Madill007530e2017-12-28 14:27:04 -05003638bool ValidatePathCommandsCHROMIUM(Context *context,
3639 GLuint path,
3640 GLsizei numCommands,
3641 const GLubyte *commands,
3642 GLsizei numCoords,
3643 GLenum coordType,
3644 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003645{
3646 if (!context->getExtensions().pathRendering)
3647 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003648 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003649 return false;
3650 }
Brandon Jones59770802018-04-02 13:18:42 -07003651 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003652 {
Jamie Madille0472f32018-11-27 16:32:45 -05003653 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003654 return false;
3655 }
3656
3657 if (numCommands < 0)
3658 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003659 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003660 return false;
3661 }
3662 else if (numCommands > 0)
3663 {
3664 if (!commands)
3665 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003666 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003667 return false;
3668 }
3669 }
3670
3671 if (numCoords < 0)
3672 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003673 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003674 return false;
3675 }
3676 else if (numCoords > 0)
3677 {
3678 if (!coords)
3679 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003680 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003681 return false;
3682 }
3683 }
3684
3685 std::uint32_t coordTypeSize = 0;
3686 switch (coordType)
3687 {
3688 case GL_BYTE:
3689 coordTypeSize = sizeof(GLbyte);
3690 break;
3691
3692 case GL_UNSIGNED_BYTE:
3693 coordTypeSize = sizeof(GLubyte);
3694 break;
3695
3696 case GL_SHORT:
3697 coordTypeSize = sizeof(GLshort);
3698 break;
3699
3700 case GL_UNSIGNED_SHORT:
3701 coordTypeSize = sizeof(GLushort);
3702 break;
3703
3704 case GL_FLOAT:
3705 coordTypeSize = sizeof(GLfloat);
3706 break;
3707
3708 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003709 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003710 return false;
3711 }
3712
3713 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3714 checkedSize += (coordTypeSize * numCoords);
3715 if (!checkedSize.IsValid())
3716 {
Jamie Madille0472f32018-11-27 16:32:45 -05003717 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003718 return false;
3719 }
3720
3721 // early return skips command data validation when it doesn't exist.
3722 if (!commands)
3723 return true;
3724
3725 GLsizei expectedNumCoords = 0;
3726 for (GLsizei i = 0; i < numCommands; ++i)
3727 {
3728 switch (commands[i])
3729 {
3730 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3731 break;
3732 case GL_MOVE_TO_CHROMIUM:
3733 case GL_LINE_TO_CHROMIUM:
3734 expectedNumCoords += 2;
3735 break;
3736 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3737 expectedNumCoords += 4;
3738 break;
3739 case GL_CUBIC_CURVE_TO_CHROMIUM:
3740 expectedNumCoords += 6;
3741 break;
3742 case GL_CONIC_CURVE_TO_CHROMIUM:
3743 expectedNumCoords += 5;
3744 break;
3745 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003746 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003747 return false;
3748 }
3749 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003750
Sami Väisänene45e53b2016-05-25 10:36:04 +03003751 if (expectedNumCoords != numCoords)
3752 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003753 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003754 return false;
3755 }
3756
3757 return true;
3758}
3759
Jamie Madill007530e2017-12-28 14:27:04 -05003760bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003761{
3762 if (!context->getExtensions().pathRendering)
3763 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003764 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003765 return false;
3766 }
Brandon Jones59770802018-04-02 13:18:42 -07003767 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003768 {
Jamie Madille0472f32018-11-27 16:32:45 -05003769 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003770 return false;
3771 }
3772
3773 switch (pname)
3774 {
3775 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3776 if (value < 0.0f)
3777 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003778 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003779 return false;
3780 }
3781 break;
3782 case GL_PATH_END_CAPS_CHROMIUM:
3783 switch (static_cast<GLenum>(value))
3784 {
3785 case GL_FLAT_CHROMIUM:
3786 case GL_SQUARE_CHROMIUM:
3787 case GL_ROUND_CHROMIUM:
3788 break;
3789 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003790 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003791 return false;
3792 }
3793 break;
3794 case GL_PATH_JOIN_STYLE_CHROMIUM:
3795 switch (static_cast<GLenum>(value))
3796 {
3797 case GL_MITER_REVERT_CHROMIUM:
3798 case GL_BEVEL_CHROMIUM:
3799 case GL_ROUND_CHROMIUM:
3800 break;
3801 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003802 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003803 return false;
3804 }
Nico Weber41b072b2018-02-09 10:01:32 -05003805 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03003806 case GL_PATH_MITER_LIMIT_CHROMIUM:
3807 if (value < 0.0f)
3808 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003809 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003810 return false;
3811 }
3812 break;
3813
3814 case GL_PATH_STROKE_BOUND_CHROMIUM:
3815 // no errors, only clamping.
3816 break;
3817
3818 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003819 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003820 return false;
3821 }
3822 return true;
3823}
3824
Jamie Madill007530e2017-12-28 14:27:04 -05003825bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value)
3826{
3827 // TODO(jmadill): Use proper clamping cast.
3828 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
3829}
3830
3831bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003832{
3833 if (!context->getExtensions().pathRendering)
3834 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003835 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003836 return false;
3837 }
3838
Brandon Jones59770802018-04-02 13:18:42 -07003839 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003840 {
Jamie Madille0472f32018-11-27 16:32:45 -05003841 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003842 return false;
3843 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003844
Sami Väisänene45e53b2016-05-25 10:36:04 +03003845 if (!value)
3846 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003847 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003848 return false;
3849 }
3850
3851 switch (pname)
3852 {
3853 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3854 case GL_PATH_END_CAPS_CHROMIUM:
3855 case GL_PATH_JOIN_STYLE_CHROMIUM:
3856 case GL_PATH_MITER_LIMIT_CHROMIUM:
3857 case GL_PATH_STROKE_BOUND_CHROMIUM:
3858 break;
3859
3860 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003861 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003862 return false;
3863 }
3864
3865 return true;
3866}
3867
Jamie Madill007530e2017-12-28 14:27:04 -05003868bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value)
3869{
3870 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
3871 reinterpret_cast<GLfloat *>(value));
3872}
3873
3874bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003875{
3876 if (!context->getExtensions().pathRendering)
3877 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003878 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003879 return false;
3880 }
3881
3882 switch (func)
3883 {
3884 case GL_NEVER:
3885 case GL_ALWAYS:
3886 case GL_LESS:
3887 case GL_LEQUAL:
3888 case GL_EQUAL:
3889 case GL_GEQUAL:
3890 case GL_GREATER:
3891 case GL_NOTEQUAL:
3892 break;
3893 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003894 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003895 return false;
3896 }
3897
3898 return true;
3899}
3900
3901// Note that the spec specifies that for the path drawing commands
3902// if the path object is not an existing path object the command
3903// does nothing and no error is generated.
3904// However if the path object exists but has not been specified any
3905// commands then an error is generated.
3906
Jamie Madill007530e2017-12-28 14:27:04 -05003907bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003908{
3909 if (!context->getExtensions().pathRendering)
3910 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003911 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003912 return false;
3913 }
Brandon Jones59770802018-04-02 13:18:42 -07003914 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003915 {
Jamie Madille0472f32018-11-27 16:32:45 -05003916 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003917 return false;
3918 }
3919
3920 switch (fillMode)
3921 {
3922 case GL_COUNT_UP_CHROMIUM:
3923 case GL_COUNT_DOWN_CHROMIUM:
3924 break;
3925 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003926 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003927 return false;
3928 }
3929
3930 if (!isPow2(mask + 1))
3931 {
Jamie Madille0472f32018-11-27 16:32:45 -05003932 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003933 return false;
3934 }
3935
3936 return true;
3937}
3938
Jamie Madill007530e2017-12-28 14:27:04 -05003939bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003940{
3941 if (!context->getExtensions().pathRendering)
3942 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003943 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003944 return false;
3945 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003946
Brandon Jones59770802018-04-02 13:18:42 -07003947 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003948 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003949 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003950 return false;
3951 }
3952
3953 return true;
3954}
3955
Jamie Madill007530e2017-12-28 14:27:04 -05003956bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003957{
3958 if (!context->getExtensions().pathRendering)
3959 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003960 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003961 return false;
3962 }
Brandon Jones59770802018-04-02 13:18:42 -07003963 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003964 {
Jamie Madille0472f32018-11-27 16:32:45 -05003965 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003966 return false;
3967 }
3968
3969 switch (coverMode)
3970 {
3971 case GL_CONVEX_HULL_CHROMIUM:
3972 case GL_BOUNDING_BOX_CHROMIUM:
3973 break;
3974 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003975 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003976 return false;
3977 }
3978 return true;
3979}
3980
Jamie Madill778bf092018-11-14 09:54:36 -05003981bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3982{
3983 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3984}
3985
3986bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3987{
3988 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3989}
3990
Jamie Madill007530e2017-12-28 14:27:04 -05003991bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
3992 GLuint path,
3993 GLenum fillMode,
3994 GLuint mask,
3995 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003996{
Jamie Madill007530e2017-12-28 14:27:04 -05003997 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
3998 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003999}
4000
Jamie Madill007530e2017-12-28 14:27:04 -05004001bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
4002 GLuint path,
4003 GLint reference,
4004 GLuint mask,
4005 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004006{
Jamie Madill007530e2017-12-28 14:27:04 -05004007 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
4008 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004009}
4010
Brandon Jonesd1049182018-03-28 10:02:20 -07004011bool ValidateIsPathCHROMIUM(Context *context, GLuint path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004012{
4013 if (!context->getExtensions().pathRendering)
4014 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004015 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004016 return false;
4017 }
4018 return true;
4019}
4020
Jamie Madill007530e2017-12-28 14:27:04 -05004021bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
4022 GLsizei numPaths,
4023 GLenum pathNameType,
4024 const void *paths,
4025 GLuint pathBase,
4026 GLenum coverMode,
4027 GLenum transformType,
4028 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004029{
4030 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4031 transformType, transformValues))
4032 return false;
4033
4034 switch (coverMode)
4035 {
4036 case GL_CONVEX_HULL_CHROMIUM:
4037 case GL_BOUNDING_BOX_CHROMIUM:
4038 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4039 break;
4040 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004041 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004042 return false;
4043 }
4044
4045 return true;
4046}
4047
Jamie Madill007530e2017-12-28 14:27:04 -05004048bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
4049 GLsizei numPaths,
4050 GLenum pathNameType,
4051 const void *paths,
4052 GLuint pathBase,
4053 GLenum coverMode,
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 switch (coverMode)
4062 {
4063 case GL_CONVEX_HULL_CHROMIUM:
4064 case GL_BOUNDING_BOX_CHROMIUM:
4065 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4066 break;
4067 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004068 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004069 return false;
4070 }
4071
4072 return true;
4073}
4074
Jamie Madill007530e2017-12-28 14:27:04 -05004075bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
4076 GLsizei numPaths,
4077 GLenum pathNameType,
4078 const void *paths,
4079 GLuint pathBase,
4080 GLenum fillMode,
4081 GLuint mask,
4082 GLenum transformType,
4083 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004084{
4085
4086 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4087 transformType, transformValues))
4088 return false;
4089
4090 switch (fillMode)
4091 {
4092 case GL_COUNT_UP_CHROMIUM:
4093 case GL_COUNT_DOWN_CHROMIUM:
4094 break;
4095 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004096 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004097 return false;
4098 }
4099 if (!isPow2(mask + 1))
4100 {
Jamie Madille0472f32018-11-27 16:32:45 -05004101 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004102 return false;
4103 }
4104 return true;
4105}
4106
Jamie Madill007530e2017-12-28 14:27:04 -05004107bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
4108 GLsizei numPaths,
4109 GLenum pathNameType,
4110 const void *paths,
4111 GLuint pathBase,
4112 GLint reference,
4113 GLuint mask,
4114 GLenum transformType,
4115 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004116{
4117 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4118 transformType, transformValues))
4119 return false;
4120
4121 // no more validation here.
4122
4123 return true;
4124}
4125
Jamie Madill007530e2017-12-28 14:27:04 -05004126bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
4127 GLsizei numPaths,
4128 GLenum pathNameType,
4129 const void *paths,
4130 GLuint pathBase,
4131 GLenum fillMode,
4132 GLuint mask,
4133 GLenum coverMode,
4134 GLenum transformType,
4135 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004136{
4137 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4138 transformType, transformValues))
4139 return false;
4140
4141 switch (coverMode)
4142 {
4143 case GL_CONVEX_HULL_CHROMIUM:
4144 case GL_BOUNDING_BOX_CHROMIUM:
4145 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4146 break;
4147 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004148 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004149 return false;
4150 }
4151
4152 switch (fillMode)
4153 {
4154 case GL_COUNT_UP_CHROMIUM:
4155 case GL_COUNT_DOWN_CHROMIUM:
4156 break;
4157 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004158 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004159 return false;
4160 }
4161 if (!isPow2(mask + 1))
4162 {
Jamie Madille0472f32018-11-27 16:32:45 -05004163 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004164 return false;
4165 }
4166
4167 return true;
4168}
4169
Jamie Madill007530e2017-12-28 14:27:04 -05004170bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4171 GLsizei numPaths,
4172 GLenum pathNameType,
4173 const void *paths,
4174 GLuint pathBase,
4175 GLint reference,
4176 GLuint mask,
4177 GLenum coverMode,
4178 GLenum transformType,
4179 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004180{
4181 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4182 transformType, transformValues))
4183 return false;
4184
4185 switch (coverMode)
4186 {
4187 case GL_CONVEX_HULL_CHROMIUM:
4188 case GL_BOUNDING_BOX_CHROMIUM:
4189 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4190 break;
4191 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004192 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004193 return false;
4194 }
4195
4196 return true;
4197}
4198
Jamie Madill007530e2017-12-28 14:27:04 -05004199bool ValidateBindFragmentInputLocationCHROMIUM(Context *context,
4200 GLuint program,
4201 GLint location,
4202 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004203{
4204 if (!context->getExtensions().pathRendering)
4205 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004206 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004207 return false;
4208 }
4209
4210 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4211 if (location >= MaxLocation)
4212 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004213 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004214 return false;
4215 }
4216
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004217 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004218 if (!programObject)
4219 {
Jamie Madille0472f32018-11-27 16:32:45 -05004220 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004221 return false;
4222 }
4223
4224 if (!name)
4225 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004226 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004227 return false;
4228 }
4229
4230 if (angle::BeginsWith(name, "gl_"))
4231 {
Jamie Madille0472f32018-11-27 16:32:45 -05004232 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004233 return false;
4234 }
4235
4236 return true;
4237}
4238
Jamie Madill007530e2017-12-28 14:27:04 -05004239bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
4240 GLuint program,
4241 GLint location,
4242 GLenum genMode,
4243 GLint components,
4244 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004245{
4246 if (!context->getExtensions().pathRendering)
4247 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004248 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004249 return false;
4250 }
4251
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004252 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004253 if (!programObject || programObject->isFlaggedForDeletion())
4254 {
Jamie Madille0472f32018-11-27 16:32:45 -05004255 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004256 return false;
4257 }
4258
4259 if (!programObject->isLinked())
4260 {
Jamie Madille0472f32018-11-27 16:32:45 -05004261 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004262 return false;
4263 }
4264
4265 switch (genMode)
4266 {
4267 case GL_NONE:
4268 if (components != 0)
4269 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004270 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004271 return false;
4272 }
4273 break;
4274
4275 case GL_OBJECT_LINEAR_CHROMIUM:
4276 case GL_EYE_LINEAR_CHROMIUM:
4277 case GL_CONSTANT_CHROMIUM:
4278 if (components < 1 || components > 4)
4279 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004280 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004281 return false;
4282 }
4283 if (!coeffs)
4284 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004285 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004286 return false;
4287 }
4288 break;
4289
4290 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004291 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004292 return false;
4293 }
4294
4295 // If the location is -1 then the command is silently ignored
4296 // and no further validation is needed.
4297 if (location == -1)
4298 return true;
4299
jchen103fd614d2018-08-13 12:21:58 +08004300 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004301
4302 if (!binding.valid)
4303 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004304 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004305 return false;
4306 }
4307
4308 if (binding.type != GL_NONE)
4309 {
4310 GLint expectedComponents = 0;
4311 switch (binding.type)
4312 {
4313 case GL_FLOAT:
4314 expectedComponents = 1;
4315 break;
4316 case GL_FLOAT_VEC2:
4317 expectedComponents = 2;
4318 break;
4319 case GL_FLOAT_VEC3:
4320 expectedComponents = 3;
4321 break;
4322 case GL_FLOAT_VEC4:
4323 expectedComponents = 4;
4324 break;
4325 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004326 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004327 return false;
4328 }
4329 if (expectedComponents != components && genMode != GL_NONE)
4330 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004331 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004332 return false;
4333 }
4334 }
4335 return true;
4336}
4337
Geoff Lang97073d12016-04-20 10:42:34 -07004338bool ValidateCopyTextureCHROMIUM(Context *context,
4339 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004340 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004341 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004342 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004343 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004344 GLint internalFormat,
4345 GLenum destType,
4346 GLboolean unpackFlipY,
4347 GLboolean unpackPremultiplyAlpha,
4348 GLboolean unpackUnmultiplyAlpha)
4349{
4350 if (!context->getExtensions().copyTexture)
4351 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004352 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004353 return false;
4354 }
4355
Geoff Lang4f0e0032017-05-01 16:04:35 -04004356 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004357 if (source == nullptr)
4358 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004359 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004360 return false;
4361 }
4362
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004363 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004364 {
Jamie Madille0472f32018-11-27 16:32:45 -05004365 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004366 return false;
4367 }
4368
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004369 TextureType sourceType = source->getType();
4370 ASSERT(sourceType != TextureType::CubeMap);
4371 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004372
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004373 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004374 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004375 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004376 return false;
4377 }
4378
Geoff Lang4f0e0032017-05-01 16:04:35 -04004379 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4380 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4381 if (sourceWidth == 0 || sourceHeight == 0)
4382 {
Jamie Madille0472f32018-11-27 16:32:45 -05004383 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004384 return false;
4385 }
4386
4387 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4388 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004389 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004390 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004391 return false;
4392 }
4393
Geoff Lang63458a32017-10-30 15:16:53 -04004394 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4395 {
Jamie Madille0472f32018-11-27 16:32:45 -05004396 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004397 return false;
4398 }
4399
Geoff Lang4f0e0032017-05-01 16:04:35 -04004400 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004401 if (dest == nullptr)
4402 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004403 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004404 return false;
4405 }
4406
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004407 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004408 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004409 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004410 return false;
4411 }
4412
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004413 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004414 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004415 {
Jamie Madille0472f32018-11-27 16:32:45 -05004416 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004417 return false;
4418 }
4419
Geoff Lang97073d12016-04-20 10:42:34 -07004420 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4421 {
Geoff Lang97073d12016-04-20 10:42:34 -07004422 return false;
4423 }
4424
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004425 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004426 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004427 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004428 return false;
4429 }
4430
Geoff Lang97073d12016-04-20 10:42:34 -07004431 if (dest->getImmutableFormat())
4432 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004433 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004434 return false;
4435 }
4436
4437 return true;
4438}
4439
4440bool ValidateCopySubTextureCHROMIUM(Context *context,
4441 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004442 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004443 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004444 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004445 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004446 GLint xoffset,
4447 GLint yoffset,
4448 GLint x,
4449 GLint y,
4450 GLsizei width,
4451 GLsizei height,
4452 GLboolean unpackFlipY,
4453 GLboolean unpackPremultiplyAlpha,
4454 GLboolean unpackUnmultiplyAlpha)
4455{
4456 if (!context->getExtensions().copyTexture)
4457 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004458 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004459 return false;
4460 }
4461
Geoff Lang4f0e0032017-05-01 16:04:35 -04004462 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004463 if (source == nullptr)
4464 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004465 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004466 return false;
4467 }
4468
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004469 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004470 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004471 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004472 return false;
4473 }
4474
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004475 TextureType sourceType = source->getType();
4476 ASSERT(sourceType != TextureType::CubeMap);
4477 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004478
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004479 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004480 {
Jamie Madille0472f32018-11-27 16:32:45 -05004481 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004482 return false;
4483 }
4484
4485 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4486 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004487 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004488 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004489 return false;
4490 }
4491
4492 if (x < 0 || y < 0)
4493 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004494 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004495 return false;
4496 }
4497
4498 if (width < 0 || height < 0)
4499 {
Jamie Madille0472f32018-11-27 16:32:45 -05004500 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004501 return false;
4502 }
4503
Geoff Lang4f0e0032017-05-01 16:04:35 -04004504 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4505 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004506 {
Jamie Madille0472f32018-11-27 16:32:45 -05004507 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004508 return false;
4509 }
4510
Geoff Lang4f0e0032017-05-01 16:04:35 -04004511 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4512 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004513 {
Jamie Madille0472f32018-11-27 16:32:45 -05004514 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004515 return false;
4516 }
4517
Geoff Lang63458a32017-10-30 15:16:53 -04004518 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4519 {
Jamie Madille0472f32018-11-27 16:32:45 -05004520 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004521 return false;
4522 }
4523
Geoff Lang4f0e0032017-05-01 16:04:35 -04004524 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004525 if (dest == nullptr)
4526 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004527 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004528 return false;
4529 }
4530
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004531 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004532 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004533 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004534 return false;
4535 }
4536
Brandon Jones28783792018-03-05 09:37:32 -08004537 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4538 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004539 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004540 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004541 return false;
4542 }
4543
Geoff Lang4f0e0032017-05-01 16:04:35 -04004544 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4545 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004546 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004547 return false;
4548 }
4549
4550 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4551 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004552 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004553 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004554 return false;
4555 }
4556
4557 if (xoffset < 0 || yoffset < 0)
4558 {
Jamie Madille0472f32018-11-27 16:32:45 -05004559 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004560 return false;
4561 }
4562
Geoff Lang4f0e0032017-05-01 16:04:35 -04004563 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4564 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004565 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004566 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004567 return false;
4568 }
4569
4570 return true;
4571}
4572
Geoff Lang47110bf2016-04-20 11:13:22 -07004573bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId)
4574{
4575 if (!context->getExtensions().copyCompressedTexture)
4576 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004577 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004578 return false;
4579 }
4580
4581 const gl::Texture *source = context->getTexture(sourceId);
4582 if (source == nullptr)
4583 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004584 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004585 return false;
4586 }
4587
Corentin Wallez99d492c2018-02-27 15:17:10 -05004588 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004589 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004590 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004591 return false;
4592 }
4593
Corentin Wallez99d492c2018-02-27 15:17:10 -05004594 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4595 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004596 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004597 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004598 return false;
4599 }
4600
Corentin Wallez99d492c2018-02-27 15:17:10 -05004601 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004602 if (!sourceFormat.info->compressed)
4603 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004604 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004605 return false;
4606 }
4607
4608 const gl::Texture *dest = context->getTexture(destId);
4609 if (dest == nullptr)
4610 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004611 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004612 return false;
4613 }
4614
Corentin Wallez99d492c2018-02-27 15:17:10 -05004615 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004616 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004617 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004618 return false;
4619 }
4620
4621 if (dest->getImmutableFormat())
4622 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004623 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004624 return false;
4625 }
4626
4627 return true;
4628}
4629
Jiawei Shao385b3e02018-03-21 09:43:28 +08004630bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004631{
4632 switch (type)
4633 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004634 case ShaderType::Vertex:
4635 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004636 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004637
Jiawei Shao385b3e02018-03-21 09:43:28 +08004638 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004639 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004640 {
Jamie Madille0472f32018-11-27 16:32:45 -05004641 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004642 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004643 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004644 break;
4645
Jiawei Shao385b3e02018-03-21 09:43:28 +08004646 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004647 if (!context->getExtensions().geometryShader)
4648 {
Jamie Madille0472f32018-11-27 16:32:45 -05004649 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004650 return false;
4651 }
4652 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004653 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004654 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004655 return false;
4656 }
Jamie Madill29639852016-09-02 15:00:09 -04004657
4658 return true;
4659}
4660
Jamie Madill5b772312018-03-08 20:28:32 -05004661bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004662 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004663 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004664 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004665 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004666{
4667 if (size < 0)
4668 {
Jamie Madille0472f32018-11-27 16:32:45 -05004669 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004670 return false;
4671 }
4672
4673 switch (usage)
4674 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004675 case BufferUsage::StreamDraw:
4676 case BufferUsage::StaticDraw:
4677 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004678 break;
4679
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004680 case BufferUsage::StreamRead:
4681 case BufferUsage::StaticRead:
4682 case BufferUsage::DynamicRead:
4683 case BufferUsage::StreamCopy:
4684 case BufferUsage::StaticCopy:
4685 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004686 if (context->getClientMajorVersion() < 3)
4687 {
Jamie Madille0472f32018-11-27 16:32:45 -05004688 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004689 return false;
4690 }
4691 break;
4692
4693 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004694 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004695 return false;
4696 }
4697
Corentin Walleze4477002017-12-01 14:39:58 -05004698 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004699 {
Jamie Madille0472f32018-11-27 16:32:45 -05004700 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004701 return false;
4702 }
4703
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004704 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004705
4706 if (!buffer)
4707 {
Jamie Madille0472f32018-11-27 16:32:45 -05004708 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004709 return false;
4710 }
4711
James Darpiniane8a93c62018-01-04 18:02:24 -08004712 if (context->getExtensions().webglCompatibility &&
4713 buffer->isBoundForTransformFeedbackAndOtherUse())
4714 {
Jamie Madille0472f32018-11-27 16:32:45 -05004715 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004716 return false;
4717 }
4718
Jamie Madill29639852016-09-02 15:00:09 -04004719 return true;
4720}
4721
Jamie Madill5b772312018-03-08 20:28:32 -05004722bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004723 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004724 GLintptr offset,
4725 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004726 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004727{
Brandon Jones6cad5662017-06-14 13:25:13 -07004728 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004729 {
Jamie Madille0472f32018-11-27 16:32:45 -05004730 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004731 return false;
4732 }
4733
4734 if (offset < 0)
4735 {
Jamie Madille0472f32018-11-27 16:32:45 -05004736 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004737 return false;
4738 }
4739
Corentin Walleze4477002017-12-01 14:39:58 -05004740 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004741 {
Jamie Madille0472f32018-11-27 16:32:45 -05004742 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004743 return false;
4744 }
4745
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004746 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004747
4748 if (!buffer)
4749 {
Jamie Madille0472f32018-11-27 16:32:45 -05004750 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004751 return false;
4752 }
4753
4754 if (buffer->isMapped())
4755 {
Jamie Madille0472f32018-11-27 16:32:45 -05004756 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004757 return false;
4758 }
4759
James Darpiniane8a93c62018-01-04 18:02:24 -08004760 if (context->getExtensions().webglCompatibility &&
4761 buffer->isBoundForTransformFeedbackAndOtherUse())
4762 {
Jamie Madille0472f32018-11-27 16:32:45 -05004763 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004764 return false;
4765 }
4766
Jamie Madill29639852016-09-02 15:00:09 -04004767 // Check for possible overflow of size + offset
4768 angle::CheckedNumeric<size_t> checkedSize(size);
4769 checkedSize += offset;
4770 if (!checkedSize.IsValid())
4771 {
Jamie Madille0472f32018-11-27 16:32:45 -05004772 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004773 return false;
4774 }
4775
4776 if (size + offset > buffer->getSize())
4777 {
Jamie Madille0472f32018-11-27 16:32:45 -05004778 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004779 return false;
4780 }
4781
Martin Radev4c4c8e72016-08-04 12:25:34 +03004782 return true;
4783}
4784
Geoff Lang111a99e2017-10-17 10:58:41 -04004785bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04004786{
Geoff Langc339c4e2016-11-29 10:37:36 -05004787 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04004788 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004789 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04004790 return false;
4791 }
4792
Geoff Lang111a99e2017-10-17 10:58:41 -04004793 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04004794 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004795 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04004796 return false;
4797 }
4798
4799 return true;
4800}
4801
Jamie Madill5b772312018-03-08 20:28:32 -05004802bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04004803{
Lingfeng Yang038dd532018-03-29 17:31:52 -07004804 if (context->getClientMajorVersion() < 2)
4805 {
4806 return ValidateMultitextureUnit(context, texture);
4807 }
4808
Jamie Madillef300b12016-10-07 15:12:09 -04004809 if (texture < GL_TEXTURE0 ||
4810 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
4811 {
Jamie Madille0472f32018-11-27 16:32:45 -05004812 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04004813 return false;
4814 }
4815
4816 return true;
4817}
4818
Jamie Madill5b772312018-03-08 20:28:32 -05004819bool ValidateAttachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillef300b12016-10-07 15:12:09 -04004820{
4821 Program *programObject = GetValidProgram(context, program);
4822 if (!programObject)
4823 {
4824 return false;
4825 }
4826
4827 Shader *shaderObject = GetValidShader(context, shader);
4828 if (!shaderObject)
4829 {
4830 return false;
4831 }
4832
Jiawei Shao385b3e02018-03-21 09:43:28 +08004833 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04004834 {
Jamie Madille0472f32018-11-27 16:32:45 -05004835 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08004836 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04004837 }
4838
4839 return true;
4840}
4841
Jamie Madill5b772312018-03-08 20:28:32 -05004842bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004843{
4844 if (index >= MAX_VERTEX_ATTRIBS)
4845 {
Jamie Madille0472f32018-11-27 16:32:45 -05004846 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004847 return false;
4848 }
4849
4850 if (strncmp(name, "gl_", 3) == 0)
4851 {
Jamie Madille0472f32018-11-27 16:32:45 -05004852 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004853 return false;
4854 }
4855
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004856 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04004857 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004858 const size_t length = strlen(name);
4859
4860 if (!IsValidESSLString(name, length))
4861 {
4862 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
4863 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05004864 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004865 return false;
4866 }
4867
4868 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
4869 {
4870 return false;
4871 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04004872 }
4873
Jamie Madill01a80ee2016-11-07 12:06:18 -05004874 return GetValidProgram(context, program) != nullptr;
4875}
4876
Jamie Madill5b772312018-03-08 20:28:32 -05004877bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004878{
Geoff Lange8afa902017-09-27 15:00:43 -04004879 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05004880 {
Jamie Madille0472f32018-11-27 16:32:45 -05004881 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004882 return false;
4883 }
4884
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004885 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004886 !context->isFramebufferGenerated(framebuffer))
4887 {
Jamie Madille0472f32018-11-27 16:32:45 -05004888 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004889 return false;
4890 }
4891
4892 return true;
4893}
4894
Jamie Madill5b772312018-03-08 20:28:32 -05004895bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004896{
4897 if (target != GL_RENDERBUFFER)
4898 {
Jamie Madille0472f32018-11-27 16:32:45 -05004899 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004900 return false;
4901 }
4902
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004903 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004904 !context->isRenderbufferGenerated(renderbuffer))
4905 {
Jamie Madille0472f32018-11-27 16:32:45 -05004906 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004907 return false;
4908 }
4909
4910 return true;
4911}
4912
Jamie Madill5b772312018-03-08 20:28:32 -05004913static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004914{
4915 switch (mode)
4916 {
4917 case GL_FUNC_ADD:
4918 case GL_FUNC_SUBTRACT:
4919 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04004920 return true;
4921
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004922 case GL_MIN:
4923 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04004924 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004925
4926 default:
4927 return false;
4928 }
4929}
4930
Jamie Madill5b772312018-03-08 20:28:32 -05004931bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004932{
4933 return true;
4934}
4935
Jamie Madill5b772312018-03-08 20:28:32 -05004936bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004937{
Geoff Lang50cac572017-09-26 17:37:43 -04004938 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004939 {
Jamie Madille0472f32018-11-27 16:32:45 -05004940 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004941 return false;
4942 }
4943
4944 return true;
4945}
4946
Jamie Madill5b772312018-03-08 20:28:32 -05004947bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004948{
Geoff Lang50cac572017-09-26 17:37:43 -04004949 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004950 {
Jamie Madille0472f32018-11-27 16:32:45 -05004951 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004952 return false;
4953 }
4954
Geoff Lang50cac572017-09-26 17:37:43 -04004955 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004956 {
Jamie Madille0472f32018-11-27 16:32:45 -05004957 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004958 return false;
4959 }
4960
4961 return true;
4962}
4963
Jamie Madill5b772312018-03-08 20:28:32 -05004964bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004965{
4966 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
4967}
4968
Jamie Madill5b772312018-03-08 20:28:32 -05004969bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004970 GLenum srcRGB,
4971 GLenum dstRGB,
4972 GLenum srcAlpha,
4973 GLenum dstAlpha)
4974{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004975 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004976 {
Jamie Madille0472f32018-11-27 16:32:45 -05004977 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004978 return false;
4979 }
4980
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004981 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004982 {
Jamie Madille0472f32018-11-27 16:32:45 -05004983 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004984 return false;
4985 }
4986
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004987 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004988 {
Jamie Madille0472f32018-11-27 16:32:45 -05004989 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004990 return false;
4991 }
4992
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004993 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004994 {
Jamie Madille0472f32018-11-27 16:32:45 -05004995 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004996 return false;
4997 }
4998
Frank Henigman146e8a12017-03-02 23:22:37 -05004999 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
5000 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005001 {
5002 bool constantColorUsed =
5003 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
5004 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
5005
5006 bool constantAlphaUsed =
5007 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
5008 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
5009
5010 if (constantColorUsed && constantAlphaUsed)
5011 {
Frank Henigman146e8a12017-03-02 23:22:37 -05005012 if (context->getExtensions().webglCompatibility)
5013 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005014 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
5015 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05005016 }
Jamie Madillc3e37312018-11-30 15:25:39 -05005017
5018 WARN() << kConstantColorAlphaLimitation;
5019 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005020 return false;
5021 }
5022 }
5023
5024 return true;
5025}
5026
Geoff Langc339c4e2016-11-29 10:37:36 -05005027bool ValidateGetString(Context *context, GLenum name)
5028{
5029 switch (name)
5030 {
5031 case GL_VENDOR:
5032 case GL_RENDERER:
5033 case GL_VERSION:
5034 case GL_SHADING_LANGUAGE_VERSION:
5035 case GL_EXTENSIONS:
5036 break;
5037
5038 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
5039 if (!context->getExtensions().requestExtension)
5040 {
Jamie Madille0472f32018-11-27 16:32:45 -05005041 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005042 return false;
5043 }
5044 break;
5045
5046 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005047 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005048 return false;
5049 }
5050
5051 return true;
5052}
5053
Jamie Madill5b772312018-03-08 20:28:32 -05005054bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05005055{
5056 if (width <= 0.0f || isNaN(width))
5057 {
Jamie Madille0472f32018-11-27 16:32:45 -05005058 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05005059 return false;
5060 }
5061
5062 return true;
5063}
5064
Jamie Madill5b772312018-03-08 20:28:32 -05005065bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05005066{
5067 if (context->getExtensions().webglCompatibility && zNear > zFar)
5068 {
Jamie Madille0472f32018-11-27 16:32:45 -05005069 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05005070 return false;
5071 }
5072
5073 return true;
5074}
5075
Jamie Madill5b772312018-03-08 20:28:32 -05005076bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005077 GLenum target,
5078 GLenum internalformat,
5079 GLsizei width,
5080 GLsizei height)
5081{
5082 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
5083 height);
5084}
5085
Jamie Madill5b772312018-03-08 20:28:32 -05005086bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005087 GLenum target,
5088 GLsizei samples,
5089 GLenum internalformat,
5090 GLsizei width,
5091 GLsizei height)
5092{
5093 if (!context->getExtensions().framebufferMultisample)
5094 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005095 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05005096 return false;
5097 }
5098
5099 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05005100 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05005101 // generated.
5102 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
5103 {
Jamie Madille0472f32018-11-27 16:32:45 -05005104 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005105 return false;
5106 }
5107
5108 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
5109 // the specified storage. This is different than ES 3.0 in which a sample number higher
5110 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
5111 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
5112 if (context->getClientMajorVersion() >= 3)
5113 {
5114 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
5115 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
5116 {
Jamie Madille0472f32018-11-27 16:32:45 -05005117 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005118 return false;
5119 }
5120 }
5121
5122 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
5123 width, height);
5124}
5125
Jamie Madill5b772312018-03-08 20:28:32 -05005126bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005127{
Geoff Lange8afa902017-09-27 15:00:43 -04005128 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005129 {
Jamie Madille0472f32018-11-27 16:32:45 -05005130 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005131 return false;
5132 }
5133
5134 return true;
5135}
5136
Jamie Madill5b772312018-03-08 20:28:32 -05005137bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005138{
5139 return true;
5140}
5141
Jamie Madill5b772312018-03-08 20:28:32 -05005142bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005143{
5144 return true;
5145}
5146
Jamie Madill5b772312018-03-08 20:28:32 -05005147bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005148{
5149 return true;
5150}
5151
Jamie Madill5b772312018-03-08 20:28:32 -05005152bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005153 GLboolean red,
5154 GLboolean green,
5155 GLboolean blue,
5156 GLboolean alpha)
5157{
5158 return true;
5159}
5160
Jamie Madill5b772312018-03-08 20:28:32 -05005161bool ValidateCompileShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005162{
5163 return true;
5164}
5165
Jamie Madill5b772312018-03-08 20:28:32 -05005166bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005167{
5168 return true;
5169}
5170
Jamie Madill5b772312018-03-08 20:28:32 -05005171bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005172{
5173 switch (mode)
5174 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005175 case CullFaceMode::Front:
5176 case CullFaceMode::Back:
5177 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005178 break;
5179
5180 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005181 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005182 return false;
5183 }
5184
5185 return true;
5186}
5187
Jamie Madill5b772312018-03-08 20:28:32 -05005188bool ValidateDeleteProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005189{
5190 if (program == 0)
5191 {
5192 return false;
5193 }
5194
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005195 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005196 {
5197 if (context->getShader(program))
5198 {
Jamie Madille0472f32018-11-27 16:32:45 -05005199 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005200 return false;
5201 }
5202 else
5203 {
Jamie Madille0472f32018-11-27 16:32:45 -05005204 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005205 return false;
5206 }
5207 }
5208
5209 return true;
5210}
5211
Jamie Madill5b772312018-03-08 20:28:32 -05005212bool ValidateDeleteShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005213{
5214 if (shader == 0)
5215 {
5216 return false;
5217 }
5218
5219 if (!context->getShader(shader))
5220 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005221 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005222 {
Jamie Madille0472f32018-11-27 16:32:45 -05005223 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005224 return false;
5225 }
5226 else
5227 {
Jamie Madille0472f32018-11-27 16:32:45 -05005228 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005229 return false;
5230 }
5231 }
5232
5233 return true;
5234}
5235
Jamie Madill5b772312018-03-08 20:28:32 -05005236bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005237{
5238 switch (func)
5239 {
5240 case GL_NEVER:
5241 case GL_ALWAYS:
5242 case GL_LESS:
5243 case GL_LEQUAL:
5244 case GL_EQUAL:
5245 case GL_GREATER:
5246 case GL_GEQUAL:
5247 case GL_NOTEQUAL:
5248 break;
5249
5250 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005251 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005252 return false;
5253 }
5254
5255 return true;
5256}
5257
Jamie Madill5b772312018-03-08 20:28:32 -05005258bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005259{
5260 return true;
5261}
5262
Jamie Madill5b772312018-03-08 20:28:32 -05005263bool ValidateDetachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005264{
5265 Program *programObject = GetValidProgram(context, program);
5266 if (!programObject)
5267 {
5268 return false;
5269 }
5270
5271 Shader *shaderObject = GetValidShader(context, shader);
5272 if (!shaderObject)
5273 {
5274 return false;
5275 }
5276
Jiawei Shao385b3e02018-03-21 09:43:28 +08005277 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005278 if (attachedShader != shaderObject)
5279 {
Jamie Madille0472f32018-11-27 16:32:45 -05005280 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005281 return false;
5282 }
5283
5284 return true;
5285}
5286
Jamie Madill5b772312018-03-08 20:28:32 -05005287bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005288{
5289 if (index >= MAX_VERTEX_ATTRIBS)
5290 {
Jamie Madille0472f32018-11-27 16:32:45 -05005291 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005292 return false;
5293 }
5294
5295 return true;
5296}
5297
Jamie Madill5b772312018-03-08 20:28:32 -05005298bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005299{
5300 if (index >= MAX_VERTEX_ATTRIBS)
5301 {
Jamie Madille0472f32018-11-27 16:32:45 -05005302 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005303 return false;
5304 }
5305
5306 return true;
5307}
5308
Jamie Madill5b772312018-03-08 20:28:32 -05005309bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005310{
5311 return true;
5312}
5313
Jamie Madill5b772312018-03-08 20:28:32 -05005314bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005315{
5316 return true;
5317}
5318
Jamie Madill5b772312018-03-08 20:28:32 -05005319bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005320{
5321 switch (mode)
5322 {
5323 case GL_CW:
5324 case GL_CCW:
5325 break;
5326 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005327 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005328 return false;
5329 }
5330
5331 return true;
5332}
5333
Jamie Madill5b772312018-03-08 20:28:32 -05005334bool ValidateGetActiveAttrib(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005335 GLuint program,
5336 GLuint index,
5337 GLsizei bufsize,
5338 GLsizei *length,
5339 GLint *size,
5340 GLenum *type,
5341 GLchar *name)
5342{
5343 if (bufsize < 0)
5344 {
Jamie Madille0472f32018-11-27 16:32:45 -05005345 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005346 return false;
5347 }
5348
5349 Program *programObject = GetValidProgram(context, program);
5350
5351 if (!programObject)
5352 {
5353 return false;
5354 }
5355
5356 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5357 {
Jamie Madille0472f32018-11-27 16:32:45 -05005358 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005359 return false;
5360 }
5361
5362 return true;
5363}
5364
Jamie Madill5b772312018-03-08 20:28:32 -05005365bool ValidateGetActiveUniform(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005366 GLuint program,
5367 GLuint index,
5368 GLsizei bufsize,
5369 GLsizei *length,
5370 GLint *size,
5371 GLenum *type,
5372 GLchar *name)
5373{
5374 if (bufsize < 0)
5375 {
Jamie Madille0472f32018-11-27 16:32:45 -05005376 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005377 return false;
5378 }
5379
5380 Program *programObject = GetValidProgram(context, program);
5381
5382 if (!programObject)
5383 {
5384 return false;
5385 }
5386
5387 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5388 {
Jamie Madille0472f32018-11-27 16:32:45 -05005389 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005390 return false;
5391 }
5392
5393 return true;
5394}
5395
Jamie Madill5b772312018-03-08 20:28:32 -05005396bool ValidateGetAttachedShaders(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005397 GLuint program,
5398 GLsizei maxcount,
5399 GLsizei *count,
5400 GLuint *shaders)
5401{
5402 if (maxcount < 0)
5403 {
Jamie Madille0472f32018-11-27 16:32:45 -05005404 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005405 return false;
5406 }
5407
5408 Program *programObject = GetValidProgram(context, program);
5409
5410 if (!programObject)
5411 {
5412 return false;
5413 }
5414
5415 return true;
5416}
5417
Jamie Madill5b772312018-03-08 20:28:32 -05005418bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005419{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005420 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5421 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005422 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005423 {
Jamie Madille0472f32018-11-27 16:32:45 -05005424 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005425 return false;
5426 }
5427
Jamie Madillc1d770e2017-04-13 17:31:24 -04005428 Program *programObject = GetValidProgram(context, program);
5429
5430 if (!programObject)
5431 {
Jamie Madille0472f32018-11-27 16:32:45 -05005432 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005433 return false;
5434 }
5435
5436 if (!programObject->isLinked())
5437 {
Jamie Madille0472f32018-11-27 16:32:45 -05005438 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005439 return false;
5440 }
5441
5442 return true;
5443}
5444
Jamie Madill5b772312018-03-08 20:28:32 -05005445bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005446{
5447 GLenum nativeType;
5448 unsigned int numParams = 0;
5449 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5450}
5451
Jamie Madill5b772312018-03-08 20:28:32 -05005452bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005453{
5454 return true;
5455}
5456
Jamie Madill5b772312018-03-08 20:28:32 -05005457bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005458{
5459 GLenum nativeType;
5460 unsigned int numParams = 0;
5461 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5462}
5463
Jamie Madill5b772312018-03-08 20:28:32 -05005464bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005465{
5466 GLenum nativeType;
5467 unsigned int numParams = 0;
5468 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5469}
5470
Jamie Madill5b772312018-03-08 20:28:32 -05005471bool ValidateGetProgramInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005472 GLuint program,
5473 GLsizei bufsize,
5474 GLsizei *length,
5475 GLchar *infolog)
5476{
5477 if (bufsize < 0)
5478 {
Jamie Madille0472f32018-11-27 16:32:45 -05005479 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005480 return false;
5481 }
5482
5483 Program *programObject = GetValidProgram(context, program);
5484 if (!programObject)
5485 {
5486 return false;
5487 }
5488
5489 return true;
5490}
5491
Jamie Madill5b772312018-03-08 20:28:32 -05005492bool ValidateGetShaderInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005493 GLuint shader,
5494 GLsizei bufsize,
5495 GLsizei *length,
5496 GLchar *infolog)
5497{
5498 if (bufsize < 0)
5499 {
Jamie Madille0472f32018-11-27 16:32:45 -05005500 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005501 return false;
5502 }
5503
5504 Shader *shaderObject = GetValidShader(context, shader);
5505 if (!shaderObject)
5506 {
5507 return false;
5508 }
5509
5510 return true;
5511}
5512
Jamie Madill5b772312018-03-08 20:28:32 -05005513bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005514 GLenum shadertype,
5515 GLenum precisiontype,
5516 GLint *range,
5517 GLint *precision)
5518{
5519 switch (shadertype)
5520 {
5521 case GL_VERTEX_SHADER:
5522 case GL_FRAGMENT_SHADER:
5523 break;
5524 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005525 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005526 return false;
5527 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005528 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005529 return false;
5530 }
5531
5532 switch (precisiontype)
5533 {
5534 case GL_LOW_FLOAT:
5535 case GL_MEDIUM_FLOAT:
5536 case GL_HIGH_FLOAT:
5537 case GL_LOW_INT:
5538 case GL_MEDIUM_INT:
5539 case GL_HIGH_INT:
5540 break;
5541
5542 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005543 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005544 return false;
5545 }
5546
5547 return true;
5548}
5549
Jamie Madill5b772312018-03-08 20:28:32 -05005550bool ValidateGetShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005551 GLuint shader,
5552 GLsizei bufsize,
5553 GLsizei *length,
5554 GLchar *source)
5555{
5556 if (bufsize < 0)
5557 {
Jamie Madille0472f32018-11-27 16:32:45 -05005558 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005559 return false;
5560 }
5561
5562 Shader *shaderObject = GetValidShader(context, shader);
5563 if (!shaderObject)
5564 {
5565 return false;
5566 }
5567
5568 return true;
5569}
5570
Jamie Madill5b772312018-03-08 20:28:32 -05005571bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005572{
5573 if (strstr(name, "gl_") == name)
5574 {
5575 return false;
5576 }
5577
Geoff Langfc32e8b2017-05-31 14:16:59 -04005578 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5579 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005580 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005581 {
Jamie Madille0472f32018-11-27 16:32:45 -05005582 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005583 return false;
5584 }
5585
Jamie Madillc1d770e2017-04-13 17:31:24 -04005586 Program *programObject = GetValidProgram(context, program);
5587
5588 if (!programObject)
5589 {
5590 return false;
5591 }
5592
5593 if (!programObject->isLinked())
5594 {
Jamie Madille0472f32018-11-27 16:32:45 -05005595 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005596 return false;
5597 }
5598
5599 return true;
5600}
5601
Jamie Madill5b772312018-03-08 20:28:32 -05005602bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005603{
5604 switch (mode)
5605 {
5606 case GL_FASTEST:
5607 case GL_NICEST:
5608 case GL_DONT_CARE:
5609 break;
5610
5611 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005612 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005613 return false;
5614 }
5615
5616 switch (target)
5617 {
5618 case GL_GENERATE_MIPMAP_HINT:
5619 break;
5620
Geoff Lange7bd2182017-06-16 16:13:13 -04005621 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5622 if (context->getClientVersion() < ES_3_0 &&
5623 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005624 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005625 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005626 return false;
5627 }
5628 break;
5629
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005630 case GL_PERSPECTIVE_CORRECTION_HINT:
5631 case GL_POINT_SMOOTH_HINT:
5632 case GL_LINE_SMOOTH_HINT:
5633 case GL_FOG_HINT:
5634 if (context->getClientMajorVersion() >= 2)
5635 {
Jamie Madille0472f32018-11-27 16:32:45 -05005636 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005637 return false;
5638 }
5639 break;
5640
Jamie Madillc1d770e2017-04-13 17:31:24 -04005641 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005642 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005643 return false;
5644 }
5645
5646 return true;
5647}
5648
Jamie Madill5b772312018-03-08 20:28:32 -05005649bool ValidateIsBuffer(Context *context, GLuint buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005650{
5651 return true;
5652}
5653
Jamie Madill5b772312018-03-08 20:28:32 -05005654bool ValidateIsFramebuffer(Context *context, GLuint framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005655{
5656 return true;
5657}
5658
Jamie Madill5b772312018-03-08 20:28:32 -05005659bool ValidateIsProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005660{
5661 return true;
5662}
5663
Jamie Madill5b772312018-03-08 20:28:32 -05005664bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005665{
5666 return true;
5667}
5668
Jamie Madill5b772312018-03-08 20:28:32 -05005669bool ValidateIsShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005670{
5671 return true;
5672}
5673
Jamie Madill5b772312018-03-08 20:28:32 -05005674bool ValidateIsTexture(Context *context, GLuint texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005675{
5676 return true;
5677}
5678
Jamie Madill5b772312018-03-08 20:28:32 -05005679bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005680{
5681 if (context->getClientMajorVersion() < 3)
5682 {
5683 switch (pname)
5684 {
5685 case GL_UNPACK_IMAGE_HEIGHT:
5686 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005687 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005688 return false;
5689
5690 case GL_UNPACK_ROW_LENGTH:
5691 case GL_UNPACK_SKIP_ROWS:
5692 case GL_UNPACK_SKIP_PIXELS:
5693 if (!context->getExtensions().unpackSubimage)
5694 {
Jamie Madille0472f32018-11-27 16:32:45 -05005695 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005696 return false;
5697 }
5698 break;
5699
5700 case GL_PACK_ROW_LENGTH:
5701 case GL_PACK_SKIP_ROWS:
5702 case GL_PACK_SKIP_PIXELS:
5703 if (!context->getExtensions().packSubimage)
5704 {
Jamie Madille0472f32018-11-27 16:32:45 -05005705 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005706 return false;
5707 }
5708 break;
5709 }
5710 }
5711
5712 if (param < 0)
5713 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005714 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005715 return false;
5716 }
5717
5718 switch (pname)
5719 {
5720 case GL_UNPACK_ALIGNMENT:
5721 if (param != 1 && param != 2 && param != 4 && param != 8)
5722 {
Jamie Madille0472f32018-11-27 16:32:45 -05005723 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005724 return false;
5725 }
5726 break;
5727
5728 case GL_PACK_ALIGNMENT:
5729 if (param != 1 && param != 2 && param != 4 && param != 8)
5730 {
Jamie Madille0472f32018-11-27 16:32:45 -05005731 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005732 return false;
5733 }
5734 break;
5735
5736 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005737 if (!context->getExtensions().packReverseRowOrder)
5738 {
Jamie Madille0472f32018-11-27 16:32:45 -05005739 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005740 }
5741 break;
5742
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743 case GL_UNPACK_ROW_LENGTH:
5744 case GL_UNPACK_IMAGE_HEIGHT:
5745 case GL_UNPACK_SKIP_IMAGES:
5746 case GL_UNPACK_SKIP_ROWS:
5747 case GL_UNPACK_SKIP_PIXELS:
5748 case GL_PACK_ROW_LENGTH:
5749 case GL_PACK_SKIP_ROWS:
5750 case GL_PACK_SKIP_PIXELS:
5751 break;
5752
5753 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005754 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005755 return false;
5756 }
5757
5758 return true;
5759}
5760
Jamie Madill5b772312018-03-08 20:28:32 -05005761bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005762{
5763 return true;
5764}
5765
Jamie Madill5b772312018-03-08 20:28:32 -05005766bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005767{
5768 return true;
5769}
5770
Jamie Madill5b772312018-03-08 20:28:32 -05005771bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005772{
5773 return true;
5774}
5775
Jamie Madill5b772312018-03-08 20:28:32 -05005776bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005777{
5778 if (width < 0 || height < 0)
5779 {
Jamie Madille0472f32018-11-27 16:32:45 -05005780 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005781 return false;
5782 }
5783
5784 return true;
5785}
5786
Jamie Madill5b772312018-03-08 20:28:32 -05005787bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005788 GLsizei n,
5789 const GLuint *shaders,
5790 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005791 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005792 GLsizei length)
5793{
5794 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
5795 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
5796 shaderBinaryFormats.end())
5797 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005798 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005799 return false;
5800 }
5801
5802 return true;
5803}
5804
Jamie Madill5b772312018-03-08 20:28:32 -05005805bool ValidateShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005806 GLuint shader,
5807 GLsizei count,
5808 const GLchar *const *string,
5809 const GLint *length)
5810{
5811 if (count < 0)
5812 {
Jamie Madille0472f32018-11-27 16:32:45 -05005813 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005814 return false;
5815 }
5816
Geoff Langfc32e8b2017-05-31 14:16:59 -04005817 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5818 // shader-related entry points
5819 if (context->getExtensions().webglCompatibility)
5820 {
5821 for (GLsizei i = 0; i < count; i++)
5822 {
Geoff Langcab92ee2017-07-19 17:32:07 -04005823 size_t len =
5824 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04005825
5826 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04005827 if (!IsValidESSLShaderSourceString(string[i], len,
5828 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005829 {
Jamie Madille0472f32018-11-27 16:32:45 -05005830 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005831 return false;
5832 }
5833 }
5834 }
5835
Jamie Madillc1d770e2017-04-13 17:31:24 -04005836 Shader *shaderObject = GetValidShader(context, shader);
5837 if (!shaderObject)
5838 {
5839 return false;
5840 }
5841
5842 return true;
5843}
5844
Jamie Madill5b772312018-03-08 20:28:32 -05005845bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005846{
5847 if (!IsValidStencilFunc(func))
5848 {
Jamie Madille0472f32018-11-27 16:32:45 -05005849 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005850 return false;
5851 }
5852
5853 return true;
5854}
5855
Jamie Madill5b772312018-03-08 20:28:32 -05005856bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005857{
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 if (!IsValidStencilFunc(func))
5865 {
Jamie Madille0472f32018-11-27 16:32:45 -05005866 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005867 return false;
5868 }
5869
5870 return true;
5871}
5872
Jamie Madill5b772312018-03-08 20:28:32 -05005873bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005874{
5875 return true;
5876}
5877
Jamie Madill5b772312018-03-08 20:28:32 -05005878bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005879{
5880 if (!IsValidStencilFace(face))
5881 {
Jamie Madille0472f32018-11-27 16:32:45 -05005882 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005883 return false;
5884 }
5885
5886 return true;
5887}
5888
Jamie Madill5b772312018-03-08 20:28:32 -05005889bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005890{
5891 if (!IsValidStencilOp(fail))
5892 {
Jamie Madille0472f32018-11-27 16:32:45 -05005893 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005894 return false;
5895 }
5896
5897 if (!IsValidStencilOp(zfail))
5898 {
Jamie Madille0472f32018-11-27 16:32:45 -05005899 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005900 return false;
5901 }
5902
5903 if (!IsValidStencilOp(zpass))
5904 {
Jamie Madille0472f32018-11-27 16:32:45 -05005905 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005906 return false;
5907 }
5908
5909 return true;
5910}
5911
Jamie Madill5b772312018-03-08 20:28:32 -05005912bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005913 GLenum face,
5914 GLenum fail,
5915 GLenum zfail,
5916 GLenum zpass)
5917{
5918 if (!IsValidStencilFace(face))
5919 {
Jamie Madille0472f32018-11-27 16:32:45 -05005920 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005921 return false;
5922 }
5923
5924 return ValidateStencilOp(context, fail, zfail, zpass);
5925}
5926
Jamie Madill5b772312018-03-08 20:28:32 -05005927bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005928{
5929 return ValidateUniform(context, GL_FLOAT, location, 1);
5930}
5931
Jamie Madill5b772312018-03-08 20:28:32 -05005932bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005933{
5934 return ValidateUniform(context, GL_FLOAT, location, count);
5935}
5936
Jamie Madill5b772312018-03-08 20:28:32 -05005937bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04005938{
5939 return ValidateUniform1iv(context, location, 1, &x);
5940}
5941
Jamie Madill5b772312018-03-08 20:28:32 -05005942bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005943{
5944 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
5945}
5946
Jamie Madill5b772312018-03-08 20:28:32 -05005947bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005948{
5949 return ValidateUniform(context, GL_INT_VEC2, location, 1);
5950}
5951
Jamie Madill5b772312018-03-08 20:28:32 -05005952bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005953{
5954 return ValidateUniform(context, GL_INT_VEC2, location, count);
5955}
5956
Jamie Madill5b772312018-03-08 20:28:32 -05005957bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005958{
5959 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
5960}
5961
Jamie Madill5b772312018-03-08 20:28:32 -05005962bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005963{
5964 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
5965}
5966
Jamie Madill5b772312018-03-08 20:28:32 -05005967bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005968{
5969 return ValidateUniform(context, GL_INT_VEC3, location, 1);
5970}
5971
Jamie Madill5b772312018-03-08 20:28:32 -05005972bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005973{
5974 return ValidateUniform(context, GL_INT_VEC3, location, count);
5975}
5976
Jamie Madill5b772312018-03-08 20:28:32 -05005977bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005978{
5979 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
5980}
5981
Jamie Madill5b772312018-03-08 20:28:32 -05005982bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005983{
5984 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
5985}
5986
Jamie Madill5b772312018-03-08 20:28:32 -05005987bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005988{
5989 return ValidateUniform(context, GL_INT_VEC4, location, 1);
5990}
5991
Jamie Madill5b772312018-03-08 20:28:32 -05005992bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005993{
5994 return ValidateUniform(context, GL_INT_VEC4, location, count);
5995}
5996
Jamie Madill5b772312018-03-08 20:28:32 -05005997bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005998 GLint location,
5999 GLsizei count,
6000 GLboolean transpose,
6001 const GLfloat *value)
6002{
6003 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
6004}
6005
Jamie Madill5b772312018-03-08 20:28:32 -05006006bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006007 GLint location,
6008 GLsizei count,
6009 GLboolean transpose,
6010 const GLfloat *value)
6011{
6012 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
6013}
6014
Jamie Madill5b772312018-03-08 20:28:32 -05006015bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006016 GLint location,
6017 GLsizei count,
6018 GLboolean transpose,
6019 const GLfloat *value)
6020{
6021 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
6022}
6023
Jamie Madill5b772312018-03-08 20:28:32 -05006024bool ValidateValidateProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006025{
6026 Program *programObject = GetValidProgram(context, program);
6027
6028 if (!programObject)
6029 {
6030 return false;
6031 }
6032
6033 return true;
6034}
6035
Jamie Madill5b772312018-03-08 20:28:32 -05006036bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006037{
6038 return ValidateVertexAttribIndex(context, index);
6039}
6040
Jamie Madill5b772312018-03-08 20:28:32 -05006041bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006042{
6043 return ValidateVertexAttribIndex(context, index);
6044}
6045
Jamie Madill5b772312018-03-08 20:28:32 -05006046bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006047{
6048 return ValidateVertexAttribIndex(context, index);
6049}
6050
Jamie Madill5b772312018-03-08 20:28:32 -05006051bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006052{
6053 return ValidateVertexAttribIndex(context, index);
6054}
6055
Jamie Madill5b772312018-03-08 20:28:32 -05006056bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006057{
6058 return ValidateVertexAttribIndex(context, index);
6059}
6060
Jamie Madill5b772312018-03-08 20:28:32 -05006061bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006062{
6063 return ValidateVertexAttribIndex(context, index);
6064}
6065
Jamie Madill5b772312018-03-08 20:28:32 -05006066bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006067 GLuint index,
6068 GLfloat x,
6069 GLfloat y,
6070 GLfloat z,
6071 GLfloat w)
6072{
6073 return ValidateVertexAttribIndex(context, index);
6074}
6075
Jamie Madill5b772312018-03-08 20:28:32 -05006076bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006077{
6078 return ValidateVertexAttribIndex(context, index);
6079}
6080
Jamie Madill5b772312018-03-08 20:28:32 -05006081bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006082{
6083 if (width < 0 || height < 0)
6084 {
Jamie Madille0472f32018-11-27 16:32:45 -05006085 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006086 return false;
6087 }
6088
6089 return true;
6090}
6091
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08006092bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006093 GLenum target,
6094 GLenum attachment,
6095 GLenum pname,
6096 GLint *params)
6097{
6098 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
6099 nullptr);
6100}
6101
Jamie Madill5b772312018-03-08 20:28:32 -05006102bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006103{
6104 return ValidateGetProgramivBase(context, program, pname, nullptr);
6105}
6106
Jamie Madill5b772312018-03-08 20:28:32 -05006107bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006108 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006109 GLint level,
6110 GLenum internalformat,
6111 GLint x,
6112 GLint y,
6113 GLsizei width,
6114 GLsizei height,
6115 GLint border)
6116{
6117 if (context->getClientMajorVersion() < 3)
6118 {
6119 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
6120 0, x, y, width, height, border);
6121 }
6122
6123 ASSERT(context->getClientMajorVersion() == 3);
6124 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
6125 0, x, y, width, height, border);
6126}
6127
6128bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006129 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006130 GLint level,
6131 GLint xoffset,
6132 GLint yoffset,
6133 GLint x,
6134 GLint y,
6135 GLsizei width,
6136 GLsizei height)
6137{
6138 if (context->getClientMajorVersion() < 3)
6139 {
6140 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
6141 yoffset, x, y, width, height, 0);
6142 }
6143
6144 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
6145 yoffset, 0, x, y, width, height, 0);
6146}
6147
6148bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *)
6149{
6150 return ValidateGenOrDelete(context, n);
6151}
6152
6153bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *)
6154{
6155 return ValidateGenOrDelete(context, n);
6156}
6157
6158bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *)
6159{
6160 return ValidateGenOrDelete(context, n);
6161}
6162
6163bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *)
6164{
6165 return ValidateGenOrDelete(context, n);
6166}
6167
6168bool ValidateDisable(Context *context, GLenum cap)
6169{
6170 if (!ValidCap(context, cap, false))
6171 {
Jamie Madille0472f32018-11-27 16:32:45 -05006172 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006173 return false;
6174 }
6175
6176 return true;
6177}
6178
6179bool ValidateEnable(Context *context, GLenum cap)
6180{
6181 if (!ValidCap(context, cap, false))
6182 {
Jamie Madille0472f32018-11-27 16:32:45 -05006183 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006184 return false;
6185 }
6186
6187 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6188 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6189 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006190 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006191
6192 // We also output an error message to the debugger window if tracing is active, so that
6193 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006194 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006195 return false;
6196 }
6197
6198 return true;
6199}
6200
6201bool ValidateFramebufferRenderbuffer(Context *context,
6202 GLenum target,
6203 GLenum attachment,
6204 GLenum renderbuffertarget,
6205 GLuint renderbuffer)
6206{
Geoff Lange8afa902017-09-27 15:00:43 -04006207 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006208 {
Jamie Madille0472f32018-11-27 16:32:45 -05006209 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006210 return false;
6211 }
6212
6213 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)
6214 {
Jamie Madille0472f32018-11-27 16:32:45 -05006215 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006216 return false;
6217 }
6218
6219 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6220 renderbuffertarget, renderbuffer);
6221}
6222
6223bool ValidateFramebufferTexture2D(Context *context,
6224 GLenum target,
6225 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006226 TextureTarget textarget,
Jamie Madillbe849e42017-05-02 15:49:00 -04006227 GLuint texture,
6228 GLint level)
6229{
6230 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6231 // extension
6232 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6233 level != 0)
6234 {
Jamie Madille0472f32018-11-27 16:32:45 -05006235 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006236 return false;
6237 }
6238
6239 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6240 {
6241 return false;
6242 }
6243
6244 if (texture != 0)
6245 {
6246 gl::Texture *tex = context->getTexture(texture);
6247 ASSERT(tex);
6248
6249 const gl::Caps &caps = context->getCaps();
6250
6251 switch (textarget)
6252 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006253 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006254 {
6255 if (level > gl::log2(caps.max2DTextureSize))
6256 {
Jamie Madille0472f32018-11-27 16:32:45 -05006257 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006258 return false;
6259 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006260 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006261 {
Jamie Madille0472f32018-11-27 16:32:45 -05006262 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006263 return false;
6264 }
6265 }
6266 break;
6267
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006268 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006269 {
6270 if (level != 0)
6271 {
Jamie Madille0472f32018-11-27 16:32:45 -05006272 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006273 return false;
6274 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006275 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006276 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006277 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006278 return false;
6279 }
6280 }
6281 break;
6282
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006283 case TextureTarget::CubeMapNegativeX:
6284 case TextureTarget::CubeMapNegativeY:
6285 case TextureTarget::CubeMapNegativeZ:
6286 case TextureTarget::CubeMapPositiveX:
6287 case TextureTarget::CubeMapPositiveY:
6288 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006289 {
6290 if (level > gl::log2(caps.maxCubeMapTextureSize))
6291 {
Jamie Madille0472f32018-11-27 16:32:45 -05006292 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006293 return false;
6294 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006295 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006296 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006297 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006298 return false;
6299 }
6300 }
6301 break;
6302
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006303 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006304 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006305 if (context->getClientVersion() < ES_3_1 &&
6306 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006307 {
Jamie Madill610640f2018-11-21 17:28:41 -05006308 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006309 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006310 return false;
6311 }
6312
6313 if (level != 0)
6314 {
Jamie Madille0472f32018-11-27 16:32:45 -05006315 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006316 return false;
6317 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006318 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006319 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006320 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006321 return false;
6322 }
6323 }
6324 break;
6325
6326 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006327 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006328 return false;
6329 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006330 }
6331
6332 return true;
6333}
6334
6335bool ValidateGenBuffers(Context *context, GLint n, GLuint *)
6336{
6337 return ValidateGenOrDelete(context, n);
6338}
6339
6340bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *)
6341{
6342 return ValidateGenOrDelete(context, n);
6343}
6344
6345bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *)
6346{
6347 return ValidateGenOrDelete(context, n);
6348}
6349
6350bool ValidateGenTextures(Context *context, GLint n, GLuint *)
6351{
6352 return ValidateGenOrDelete(context, n);
6353}
6354
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006355bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006356{
6357 if (!ValidTextureTarget(context, target))
6358 {
Jamie Madille0472f32018-11-27 16:32:45 -05006359 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006360 return false;
6361 }
6362
Jamie Madillcfc73cc2019-04-08 16:26:51 -04006363 Texture *texture = context->getTextureByType(target);
Jamie Madillbe849e42017-05-02 15:49:00 -04006364
6365 if (texture == nullptr)
6366 {
Jamie Madille0472f32018-11-27 16:32:45 -05006367 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006368 return false;
6369 }
6370
6371 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6372
6373 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6374 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6375 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6376 {
Jamie Madille0472f32018-11-27 16:32:45 -05006377 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006378 return false;
6379 }
6380
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006381 TextureTarget baseTarget = (target == TextureType::CubeMap)
6382 ? TextureTarget::CubeMapPositiveX
6383 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006384 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6385 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6386 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006387 {
Jamie Madille0472f32018-11-27 16:32:45 -05006388 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006389 return false;
6390 }
6391
Geoff Lang536eca12017-09-13 11:23:35 -04006392 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6393 bool formatUnsized = !format.sized;
6394 bool formatColorRenderableAndFilterable =
6395 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006396 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006397 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006398 {
Jamie Madille0472f32018-11-27 16:32:45 -05006399 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006400 return false;
6401 }
6402
Geoff Lang536eca12017-09-13 11:23:35 -04006403 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6404 // generation
6405 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6406 {
Jamie Madille0472f32018-11-27 16:32:45 -05006407 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006408 return false;
6409 }
6410
Jiange2c00842018-07-13 16:50:49 +08006411 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6412 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6413 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006414 {
Jamie Madille0472f32018-11-27 16:32:45 -05006415 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006416 return false;
6417 }
6418
6419 // Non-power of 2 ES2 check
6420 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6421 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6422 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6423 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006424 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6425 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006426 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006427 return false;
6428 }
6429
6430 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006431 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006432 {
Jamie Madille0472f32018-11-27 16:32:45 -05006433 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006434 return false;
6435 }
6436
James Darpinian83b2f0e2018-11-27 15:56:01 -08006437 if (context->getExtensions().webglCompatibility &&
6438 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6439 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6440 {
6441 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6442 return false;
6443 }
6444
Jamie Madillbe849e42017-05-02 15:49:00 -04006445 return true;
6446}
6447
Jamie Madill5b772312018-03-08 20:28:32 -05006448bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006449 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006450 GLenum pname,
6451 GLint *params)
6452{
6453 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6454}
6455
6456bool ValidateGetRenderbufferParameteriv(Context *context,
6457 GLenum target,
6458 GLenum pname,
6459 GLint *params)
6460{
6461 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6462}
6463
6464bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params)
6465{
6466 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6467}
6468
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006469bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006470{
6471 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6472}
6473
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006474bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006475{
6476 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6477}
6478
Till Rathmannb8543632018-10-02 19:46:14 +02006479bool ValidateGetTexParameterIivOES(Context *context,
6480 TextureType target,
6481 GLenum pname,
6482 GLint *params)
6483{
6484 if (context->getClientMajorVersion() < 3)
6485 {
Jamie Madille0472f32018-11-27 16:32:45 -05006486 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006487 return false;
6488 }
6489 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6490}
6491
6492bool ValidateGetTexParameterIuivOES(Context *context,
6493 TextureType target,
6494 GLenum pname,
6495 GLuint *params)
6496{
6497 if (context->getClientMajorVersion() < 3)
6498 {
Jamie Madille0472f32018-11-27 16:32:45 -05006499 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006500 return false;
6501 }
6502 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6503}
6504
Jamie Madillbe849e42017-05-02 15:49:00 -04006505bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params)
6506{
6507 return ValidateGetUniformBase(context, program, location);
6508}
6509
6510bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params)
6511{
6512 return ValidateGetUniformBase(context, program, location);
6513}
6514
6515bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6516{
6517 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6518}
6519
6520bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6521{
6522 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6523}
6524
6525bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6526{
6527 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6528}
6529
6530bool ValidateIsEnabled(Context *context, GLenum cap)
6531{
6532 if (!ValidCap(context, cap, true))
6533 {
Jamie Madille0472f32018-11-27 16:32:45 -05006534 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006535 return false;
6536 }
6537
6538 return true;
6539}
6540
6541bool ValidateLinkProgram(Context *context, GLuint program)
6542{
6543 if (context->hasActiveTransformFeedback(program))
6544 {
6545 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006546 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006547 return false;
6548 }
6549
6550 Program *programObject = GetValidProgram(context, program);
6551 if (!programObject)
6552 {
6553 return false;
6554 }
6555
6556 return true;
6557}
6558
Jamie Madill4928b7c2017-06-20 12:57:39 -04006559bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006560 GLint x,
6561 GLint y,
6562 GLsizei width,
6563 GLsizei height,
6564 GLenum format,
6565 GLenum type,
6566 void *pixels)
6567{
6568 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6569 nullptr, pixels);
6570}
6571
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006572bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006573{
Till Rathmannb8543632018-10-02 19:46:14 +02006574 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006575}
6576
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006577bool ValidateTexParameterfv(Context *context,
6578 TextureType target,
6579 GLenum pname,
6580 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006581{
Till Rathmannb8543632018-10-02 19:46:14 +02006582 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006583}
6584
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006585bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006586{
Till Rathmannb8543632018-10-02 19:46:14 +02006587 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006588}
6589
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006590bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006591{
Till Rathmannb8543632018-10-02 19:46:14 +02006592 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6593}
6594
6595bool ValidateTexParameterIivOES(Context *context,
6596 TextureType target,
6597 GLenum pname,
6598 const GLint *params)
6599{
6600 if (context->getClientMajorVersion() < 3)
6601 {
Jamie Madille0472f32018-11-27 16:32:45 -05006602 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006603 return false;
6604 }
6605 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6606}
6607
6608bool ValidateTexParameterIuivOES(Context *context,
6609 TextureType target,
6610 GLenum pname,
6611 const GLuint *params)
6612{
6613 if (context->getClientMajorVersion() < 3)
6614 {
Jamie Madille0472f32018-11-27 16:32:45 -05006615 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006616 return false;
6617 }
6618 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006619}
6620
6621bool ValidateUseProgram(Context *context, GLuint program)
6622{
6623 if (program != 0)
6624 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006625 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006626 if (!programObject)
6627 {
6628 // ES 3.1.0 section 7.3 page 72
6629 if (context->getShader(program))
6630 {
Jamie Madille0472f32018-11-27 16:32:45 -05006631 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006632 return false;
6633 }
6634 else
6635 {
Jamie Madille0472f32018-11-27 16:32:45 -05006636 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006637 return false;
6638 }
6639 }
6640 if (!programObject->isLinked())
6641 {
Jamie Madille0472f32018-11-27 16:32:45 -05006642 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006643 return false;
6644 }
6645 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006646 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006647 {
6648 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006649 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006650 return false;
6651 }
6652
6653 return true;
6654}
6655
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006656bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences)
6657{
6658 if (!context->getExtensions().fence)
6659 {
Jamie Madille0472f32018-11-27 16:32:45 -05006660 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006661 return false;
6662 }
6663
6664 if (n < 0)
6665 {
Jamie Madille0472f32018-11-27 16:32:45 -05006666 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006667 return false;
6668 }
6669
6670 return true;
6671}
6672
6673bool ValidateFinishFenceNV(Context *context, GLuint fence)
6674{
6675 if (!context->getExtensions().fence)
6676 {
Jamie Madille0472f32018-11-27 16:32:45 -05006677 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006678 return false;
6679 }
6680
6681 FenceNV *fenceObject = context->getFenceNV(fence);
6682
6683 if (fenceObject == nullptr)
6684 {
Jamie Madille0472f32018-11-27 16:32:45 -05006685 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006686 return false;
6687 }
6688
6689 if (!fenceObject->isSet())
6690 {
Jamie Madille0472f32018-11-27 16:32:45 -05006691 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006692 return false;
6693 }
6694
6695 return true;
6696}
6697
6698bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences)
6699{
6700 if (!context->getExtensions().fence)
6701 {
Jamie Madille0472f32018-11-27 16:32:45 -05006702 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006703 return false;
6704 }
6705
6706 if (n < 0)
6707 {
Jamie Madille0472f32018-11-27 16:32:45 -05006708 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006709 return false;
6710 }
6711
6712 return true;
6713}
6714
6715bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params)
6716{
6717 if (!context->getExtensions().fence)
6718 {
Jamie Madille0472f32018-11-27 16:32:45 -05006719 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006720 return false;
6721 }
6722
6723 FenceNV *fenceObject = context->getFenceNV(fence);
6724
6725 if (fenceObject == nullptr)
6726 {
Jamie Madille0472f32018-11-27 16:32:45 -05006727 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006728 return false;
6729 }
6730
6731 if (!fenceObject->isSet())
6732 {
Jamie Madille0472f32018-11-27 16:32:45 -05006733 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006734 return false;
6735 }
6736
6737 switch (pname)
6738 {
6739 case GL_FENCE_STATUS_NV:
6740 case GL_FENCE_CONDITION_NV:
6741 break;
6742
6743 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006744 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006745 return false;
6746 }
6747
6748 return true;
6749}
6750
6751bool ValidateGetGraphicsResetStatusEXT(Context *context)
6752{
6753 if (!context->getExtensions().robustness)
6754 {
Jamie Madille0472f32018-11-27 16:32:45 -05006755 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006756 return false;
6757 }
6758
6759 return true;
6760}
6761
6762bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
6763 GLuint shader,
6764 GLsizei bufsize,
6765 GLsizei *length,
6766 GLchar *source)
6767{
6768 if (!context->getExtensions().translatedShaderSource)
6769 {
Jamie Madille0472f32018-11-27 16:32:45 -05006770 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006771 return false;
6772 }
6773
6774 if (bufsize < 0)
6775 {
Jamie Madille0472f32018-11-27 16:32:45 -05006776 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006777 return false;
6778 }
6779
6780 Shader *shaderObject = context->getShader(shader);
6781
6782 if (!shaderObject)
6783 {
Jamie Madille0472f32018-11-27 16:32:45 -05006784 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006785 return false;
6786 }
6787
6788 return true;
6789}
6790
6791bool ValidateIsFenceNV(Context *context, GLuint fence)
6792{
6793 if (!context->getExtensions().fence)
6794 {
Jamie Madille0472f32018-11-27 16:32:45 -05006795 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006796 return false;
6797 }
6798
6799 return true;
6800}
6801
Jamie Madill007530e2017-12-28 14:27:04 -05006802bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition)
6803{
6804 if (!context->getExtensions().fence)
6805 {
Jamie Madille0472f32018-11-27 16:32:45 -05006806 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006807 return false;
6808 }
6809
6810 if (condition != GL_ALL_COMPLETED_NV)
6811 {
Jamie Madille0472f32018-11-27 16:32:45 -05006812 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05006813 return false;
6814 }
6815
6816 FenceNV *fenceObject = context->getFenceNV(fence);
6817
6818 if (fenceObject == nullptr)
6819 {
Jamie Madille0472f32018-11-27 16:32:45 -05006820 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006821 return false;
6822 }
6823
6824 return true;
6825}
6826
6827bool ValidateTestFenceNV(Context *context, GLuint fence)
6828{
6829 if (!context->getExtensions().fence)
6830 {
Jamie Madille0472f32018-11-27 16:32:45 -05006831 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006832 return false;
6833 }
6834
6835 FenceNV *fenceObject = context->getFenceNV(fence);
6836
6837 if (fenceObject == nullptr)
6838 {
Jamie Madille0472f32018-11-27 16:32:45 -05006839 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006840 return false;
6841 }
6842
6843 if (fenceObject->isSet() != GL_TRUE)
6844 {
Jamie Madille0472f32018-11-27 16:32:45 -05006845 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05006846 return false;
6847 }
6848
6849 return true;
6850}
6851
6852bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006853 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05006854 GLsizei levels,
6855 GLenum internalformat,
6856 GLsizei width,
6857 GLsizei height)
6858{
6859 if (!context->getExtensions().textureStorage)
6860 {
Jamie Madille0472f32018-11-27 16:32:45 -05006861 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006862 return false;
6863 }
6864
6865 if (context->getClientMajorVersion() < 3)
6866 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006867 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05006868 height);
6869 }
6870
6871 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006872 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05006873 1);
6874}
6875
6876bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
6877{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006878 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05006879 {
Jamie Madille0472f32018-11-27 16:32:45 -05006880 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006881 return false;
6882 }
6883
6884 if (index >= MAX_VERTEX_ATTRIBS)
6885 {
Jamie Madille0472f32018-11-27 16:32:45 -05006886 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05006887 return false;
6888 }
6889
6890 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
6891 {
6892 if (index == 0 && divisor != 0)
6893 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006894 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05006895
6896 // We also output an error message to the debugger window if tracing is active, so
6897 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006898 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05006899 return false;
6900 }
6901 }
6902
6903 return true;
6904}
6905
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006906bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
6907{
6908 if (!context->getExtensions().instancedArraysEXT)
6909 {
6910 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6911 return false;
6912 }
6913
6914 if (index >= MAX_VERTEX_ATTRIBS)
6915 {
6916 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
6917 return false;
6918 }
6919
6920 return true;
6921}
6922
Jamie Madill007530e2017-12-28 14:27:04 -05006923bool ValidateTexImage3DOES(Context *context,
6924 GLenum target,
6925 GLint level,
6926 GLenum internalformat,
6927 GLsizei width,
6928 GLsizei height,
6929 GLsizei depth,
6930 GLint border,
6931 GLenum format,
6932 GLenum type,
6933 const void *pixels)
6934{
6935 UNIMPLEMENTED(); // FIXME
6936 return false;
6937}
6938
6939bool ValidatePopGroupMarkerEXT(Context *context)
6940{
6941 if (!context->getExtensions().debugMarker)
6942 {
6943 // The debug marker calls should not set error state
6944 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05006945 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006946 return false;
6947 }
6948
6949 return true;
6950}
6951
Jamie Madillfa920eb2018-01-04 11:45:50 -05006952bool ValidateTexStorage1DEXT(Context *context,
6953 GLenum target,
6954 GLsizei levels,
6955 GLenum internalformat,
6956 GLsizei width)
6957{
6958 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05006959 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006960 return false;
6961}
6962
6963bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006964 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05006965 GLsizei levels,
6966 GLenum internalformat,
6967 GLsizei width,
6968 GLsizei height,
6969 GLsizei depth)
6970{
6971 if (!context->getExtensions().textureStorage)
6972 {
Jamie Madille0472f32018-11-27 16:32:45 -05006973 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006974 return false;
6975 }
6976
6977 if (context->getClientMajorVersion() < 3)
6978 {
Jamie Madille0472f32018-11-27 16:32:45 -05006979 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006980 return false;
6981 }
6982
6983 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
6984 depth);
6985}
6986
jchen1082af6202018-06-22 10:59:52 +08006987bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
6988{
6989 if (!context->getExtensions().parallelShaderCompile)
6990 {
Jamie Madille0472f32018-11-27 16:32:45 -05006991 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08006992 return false;
6993 }
6994 return true;
6995}
6996
Austin Eng1bf18ce2018-10-19 15:34:02 -07006997bool ValidateMultiDrawArraysANGLE(Context *context,
6998 PrimitiveMode mode,
6999 const GLint *firsts,
7000 const GLsizei *counts,
7001 GLsizei drawcount)
7002{
7003 if (!context->getExtensions().multiDraw)
7004 {
Jamie Madille0472f32018-11-27 16:32:45 -05007005 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007006 return false;
7007 }
7008 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7009 {
7010 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
7011 {
7012 return false;
7013 }
7014 }
7015 return true;
7016}
7017
7018bool ValidateMultiDrawElementsANGLE(Context *context,
7019 PrimitiveMode mode,
7020 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05007021 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08007022 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07007023 GLsizei drawcount)
7024{
7025 if (!context->getExtensions().multiDraw)
7026 {
Jamie Madille0472f32018-11-27 16:32:45 -05007027 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007028 return false;
7029 }
7030 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7031 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08007032 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07007033 {
7034 return false;
7035 }
7036 }
7037 return true;
7038}
7039
Jeff Gilbert465d6092019-01-02 16:21:18 -08007040bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked)
7041{
7042 if (!context->getExtensions().provokingVertex)
7043 {
7044 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7045 return false;
7046 }
7047
7048 switch (modePacked)
7049 {
7050 case ProvokingVertex::FirstVertexConvention:
7051 case ProvokingVertex::LastVertexConvention:
7052 break;
7053 default:
7054 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
7055 return false;
7056 }
7057
7058 return true;
7059}
7060
Jamie Madilla5410482019-01-31 19:55:55 -05007061void RecordBindTextureTypeError(Context *context, TextureType target)
7062{
7063 ASSERT(!context->getStateCache().isValidBindTextureType(target));
7064
7065 switch (target)
7066 {
7067 case TextureType::Rectangle:
7068 ASSERT(!context->getExtensions().textureRectangle);
7069 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
7070 break;
7071
7072 case TextureType::_3D:
7073 case TextureType::_2DArray:
7074 ASSERT(context->getClientMajorVersion() < 3);
7075 context->validationError(GL_INVALID_ENUM, kES3Required);
7076 break;
7077
7078 case TextureType::_2DMultisample:
7079 ASSERT(context->getClientVersion() < Version(3, 1) &&
7080 !context->getExtensions().textureMultisample);
7081 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
7082 break;
7083
7084 case TextureType::_2DMultisampleArray:
7085 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
7086 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
7087 break;
7088
7089 case TextureType::External:
7090 ASSERT(!context->getExtensions().eglImageExternal &&
7091 !context->getExtensions().eglStreamConsumerExternal);
7092 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
7093 break;
7094
7095 default:
7096 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
7097 }
7098}
7099
Jamie Madillc29968b2016-01-20 11:17:23 -05007100} // namespace gl