blob: 5604249266f8d00ee60b212aab56141dc4a198dc [file] [log] [blame]
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
Geoff Lange8ebe7f2013-08-05 15:03:13 -04003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// validationES2.cpp: Validation functions for OpenGL ES 2.0 entry point parameters
8
Jamie Madill778bf092018-11-14 09:54:36 -05009#include "libANGLE/validationES2_autogen.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030010
11#include <cstdint>
12
Geoff Lange8ebe7f2013-08-05 15:03:13 -040013#include "common/mathutil.h"
Sami Väisänen46eaa942016-06-29 10:26:37 +030014#include "common/string_utils.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040015#include "common/utilities.h"
Jamie Madillef300b12016-10-07 15:12:09 -040016#include "libANGLE/Context.h"
Brandon Jones6cad5662017-06-14 13:25:13 -070017#include "libANGLE/ErrorStrings.h"
Jamie Madill2b7bbc22017-12-21 17:30:38 -050018#include "libANGLE/Fence.h"
Jamie Madillef300b12016-10-07 15:12:09 -040019#include "libANGLE/Framebuffer.h"
20#include "libANGLE/FramebufferAttachment.h"
21#include "libANGLE/Renderbuffer.h"
22#include "libANGLE/Shader.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040023#include "libANGLE/Texture.h"
Jamie Madillef300b12016-10-07 15:12:09 -040024#include "libANGLE/Uniform.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040025#include "libANGLE/VertexArray.h"
Jamie Madillef300b12016-10-07 15:12:09 -040026#include "libANGLE/formatutils.h"
27#include "libANGLE/validationES.h"
Jamie Madill778bf092018-11-14 09:54:36 -050028#include "libANGLE/validationES2.h"
29#include "libANGLE/validationES3_autogen.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040030
31namespace gl
32{
Jamie Madille0472f32018-11-27 16:32:45 -050033using namespace err;
Geoff Lange8ebe7f2013-08-05 15:03:13 -040034
Jamie Madillc29968b2016-01-20 11:17:23 -050035namespace
36{
37
38bool IsPartialBlit(gl::Context *context,
39 const FramebufferAttachment *readBuffer,
40 const FramebufferAttachment *writeBuffer,
41 GLint srcX0,
42 GLint srcY0,
43 GLint srcX1,
44 GLint srcY1,
45 GLint dstX0,
46 GLint dstY0,
47 GLint dstX1,
48 GLint dstY1)
49{
50 const Extents &writeSize = writeBuffer->getSize();
51 const Extents &readSize = readBuffer->getSize();
52
53 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width ||
54 dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height)
55 {
56 return true;
57 }
58
Jamie Madillc3dc5d42018-12-30 12:12:04 -050059 if (context->getState().isScissorTestEnabled())
Jamie Madillc29968b2016-01-20 11:17:23 -050060 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -050061 const Rectangle &scissor = context->getState().getScissor();
Jamie Madillc29968b2016-01-20 11:17:23 -050062 return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width ||
63 scissor.height < writeSize.height;
64 }
65
66 return false;
67}
68
Sami Väisänend59ca052016-06-21 16:10:00 +030069template <typename T>
70bool ValidatePathInstances(gl::Context *context,
71 GLsizei numPaths,
72 const void *paths,
73 GLuint pathBase)
74{
75 const auto *array = static_cast<const T *>(paths);
76
77 for (GLsizei i = 0; i < numPaths; ++i)
78 {
79 const GLuint pathName = array[i] + pathBase;
Brandon Jones59770802018-04-02 13:18:42 -070080 if (context->isPathGenerated(pathName) && !context->isPath(pathName))
Sami Väisänend59ca052016-06-21 16:10:00 +030081 {
Jamie Madille0472f32018-11-27 16:32:45 -050082 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänend59ca052016-06-21 16:10:00 +030083 return false;
84 }
85 }
86 return true;
87}
88
89bool ValidateInstancedPathParameters(gl::Context *context,
90 GLsizei numPaths,
91 GLenum pathNameType,
92 const void *paths,
93 GLuint pathBase,
94 GLenum transformType,
95 const GLfloat *transformValues)
96{
97 if (!context->getExtensions().pathRendering)
98 {
Jamie Madillc3e37312018-11-30 15:25:39 -050099 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänend59ca052016-06-21 16:10:00 +0300100 return false;
101 }
102
103 if (paths == nullptr)
104 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500105 context->validationError(GL_INVALID_VALUE, kInvalidPathNameArray);
Sami Väisänend59ca052016-06-21 16:10:00 +0300106 return false;
107 }
108
109 if (numPaths < 0)
110 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500111 context->validationError(GL_INVALID_VALUE, kInvalidPathNumPaths);
Sami Väisänend59ca052016-06-21 16:10:00 +0300112 return false;
113 }
114
115 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths))
116 {
Jamie Madille0472f32018-11-27 16:32:45 -0500117 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänend59ca052016-06-21 16:10:00 +0300118 return false;
119 }
120
121 std::uint32_t pathNameTypeSize = 0;
122 std::uint32_t componentCount = 0;
123
124 switch (pathNameType)
125 {
126 case GL_UNSIGNED_BYTE:
127 pathNameTypeSize = sizeof(GLubyte);
128 if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase))
129 return false;
130 break;
131
132 case GL_BYTE:
133 pathNameTypeSize = sizeof(GLbyte);
134 if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase))
135 return false;
136 break;
137
138 case GL_UNSIGNED_SHORT:
139 pathNameTypeSize = sizeof(GLushort);
140 if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase))
141 return false;
142 break;
143
144 case GL_SHORT:
145 pathNameTypeSize = sizeof(GLshort);
146 if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase))
147 return false;
148 break;
149
150 case GL_UNSIGNED_INT:
151 pathNameTypeSize = sizeof(GLuint);
152 if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase))
153 return false;
154 break;
155
156 case GL_INT:
157 pathNameTypeSize = sizeof(GLint);
158 if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase))
159 return false;
160 break;
161
162 default:
Jamie Madillc3e37312018-11-30 15:25:39 -0500163 context->validationError(GL_INVALID_ENUM, kInvalidPathNameType);
Sami Väisänend59ca052016-06-21 16:10:00 +0300164 return false;
165 }
166
167 switch (transformType)
168 {
169 case GL_NONE:
170 componentCount = 0;
171 break;
172 case GL_TRANSLATE_X_CHROMIUM:
173 case GL_TRANSLATE_Y_CHROMIUM:
174 componentCount = 1;
175 break;
176 case GL_TRANSLATE_2D_CHROMIUM:
177 componentCount = 2;
178 break;
179 case GL_TRANSLATE_3D_CHROMIUM:
180 componentCount = 3;
181 break;
182 case GL_AFFINE_2D_CHROMIUM:
183 case GL_TRANSPOSE_AFFINE_2D_CHROMIUM:
184 componentCount = 6;
185 break;
186 case GL_AFFINE_3D_CHROMIUM:
187 case GL_TRANSPOSE_AFFINE_3D_CHROMIUM:
188 componentCount = 12;
189 break;
190 default:
Jamie Madillc3e37312018-11-30 15:25:39 -0500191 context->validationError(GL_INVALID_ENUM, kInvalidTransformation);
Sami Väisänend59ca052016-06-21 16:10:00 +0300192 return false;
193 }
194 if (componentCount != 0 && transformValues == nullptr)
195 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500196 context->validationError(GL_INVALID_VALUE, kNoTransformArray);
Sami Väisänend59ca052016-06-21 16:10:00 +0300197 return false;
198 }
199
200 angle::CheckedNumeric<std::uint32_t> checkedSize(0);
201 checkedSize += (numPaths * pathNameTypeSize);
202 checkedSize += (numPaths * sizeof(GLfloat) * componentCount);
203 if (!checkedSize.IsValid())
204 {
Jamie Madille0472f32018-11-27 16:32:45 -0500205 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänend59ca052016-06-21 16:10:00 +0300206 return false;
207 }
208
209 return true;
210}
211
Geoff Lang4f0e0032017-05-01 16:04:35 -0400212bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat)
Geoff Lang97073d12016-04-20 10:42:34 -0700213{
Geoff Lang4f0e0032017-05-01 16:04:35 -0400214 // Table 1.1 from the CHROMIUM_copy_texture spec
Geoff Langca271392017-04-05 12:30:00 -0400215 switch (GetUnsizedFormat(internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -0700216 {
Geoff Lang4f0e0032017-05-01 16:04:35 -0400217 case GL_RED:
Geoff Lang97073d12016-04-20 10:42:34 -0700218 case GL_ALPHA:
219 case GL_LUMINANCE:
220 case GL_LUMINANCE_ALPHA:
221 case GL_RGB:
222 case GL_RGBA:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400223 case GL_RGB8:
224 case GL_RGBA8:
225 case GL_BGRA_EXT:
226 case GL_BGRA8_EXT:
Geoff Lang97073d12016-04-20 10:42:34 -0700227 return true;
228
Geoff Lang4f0e0032017-05-01 16:04:35 -0400229 default:
230 return false;
231 }
232}
Geoff Lang97073d12016-04-20 10:42:34 -0700233
Geoff Lang4f0e0032017-05-01 16:04:35 -0400234bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat)
235{
236 return IsValidCopyTextureSourceInternalFormatEnum(internalFormat);
237}
238
Geoff Lang4f0e0032017-05-01 16:04:35 -0400239bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat)
240{
241 // Table 1.0 from the CHROMIUM_copy_texture spec
242 switch (internalFormat)
243 {
244 case GL_RGB:
245 case GL_RGBA:
246 case GL_RGB8:
247 case GL_RGBA8:
Geoff Lang97073d12016-04-20 10:42:34 -0700248 case GL_BGRA_EXT:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400249 case GL_BGRA8_EXT:
250 case GL_SRGB_EXT:
251 case GL_SRGB_ALPHA_EXT:
252 case GL_R8:
253 case GL_R8UI:
254 case GL_RG8:
255 case GL_RG8UI:
256 case GL_SRGB8:
257 case GL_RGB565:
258 case GL_RGB8UI:
Geoff Lang6be3d4c2017-06-16 15:54:15 -0400259 case GL_RGB10_A2:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400260 case GL_SRGB8_ALPHA8:
261 case GL_RGB5_A1:
262 case GL_RGBA4:
263 case GL_RGBA8UI:
264 case GL_RGB9_E5:
265 case GL_R16F:
266 case GL_R32F:
267 case GL_RG16F:
268 case GL_RG32F:
269 case GL_RGB16F:
270 case GL_RGB32F:
271 case GL_RGBA16F:
272 case GL_RGBA32F:
273 case GL_R11F_G11F_B10F:
Brandon Jones340b7b82017-06-26 13:02:31 -0700274 case GL_LUMINANCE:
275 case GL_LUMINANCE_ALPHA:
276 case GL_ALPHA:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400277 return true;
Geoff Lang97073d12016-04-20 10:42:34 -0700278
279 default:
280 return false;
281 }
282}
283
Geoff Lang6be3d4c2017-06-16 15:54:15 -0400284bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat)
285{
286 return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat);
287}
288
Geoff Lang97073d12016-04-20 10:42:34 -0700289bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type)
290{
Geoff Lang4f0e0032017-05-01 16:04:35 -0400291 if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -0700292 {
Jamie Madille0472f32018-11-27 16:32:45 -0500293 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400294 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700295 }
296
Geoff Langc0094ec2017-08-16 14:16:24 -0400297 if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat))
298 {
Jamie Madille0472f32018-11-27 16:32:45 -0500299 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Langc0094ec2017-08-16 14:16:24 -0400300 return false;
301 }
302
Geoff Lang4f0e0032017-05-01 16:04:35 -0400303 const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type);
304 if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Geoff Lang97073d12016-04-20 10:42:34 -0700305 {
Jamie Madille0472f32018-11-27 16:32:45 -0500306 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400307 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700308 }
309
310 return true;
311}
312
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800313bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target)
Geoff Lang97073d12016-04-20 10:42:34 -0700314{
315 switch (target)
316 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800317 case TextureTarget::_2D:
318 case TextureTarget::CubeMapNegativeX:
319 case TextureTarget::CubeMapNegativeY:
320 case TextureTarget::CubeMapNegativeZ:
321 case TextureTarget::CubeMapPositiveX:
322 case TextureTarget::CubeMapPositiveY:
323 case TextureTarget::CubeMapPositiveZ:
Geoff Lang63458a32017-10-30 15:16:53 -0400324 return true;
Geoff Lang97073d12016-04-20 10:42:34 -0700325
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 case TextureTarget::Rectangle:
Geoff Lang63458a32017-10-30 15:16:53 -0400327 return context->getExtensions().textureRectangle;
Geoff Lang97073d12016-04-20 10:42:34 -0700328
329 default:
330 return false;
331 }
332}
333
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334bool IsValidCopyTextureDestinationTarget(Context *context,
335 TextureType textureType,
336 TextureTarget target)
Geoff Lang63458a32017-10-30 15:16:53 -0400337{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800338 return TextureTargetToType(target) == textureType;
Geoff Lang63458a32017-10-30 15:16:53 -0400339}
340
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800341bool IsValidCopyTextureSourceTarget(Context *context, TextureType type)
Geoff Lang97073d12016-04-20 10:42:34 -0700342{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800343 switch (type)
Geoff Lang97073d12016-04-20 10:42:34 -0700344 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800345 case TextureType::_2D:
Geoff Lang4f0e0032017-05-01 16:04:35 -0400346 return true;
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800347 case TextureType::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400348 return context->getExtensions().textureRectangle;
Geoff Langbe607ad2018-11-29 10:14:22 -0500349 case TextureType::External:
350 return context->getExtensions().eglImageExternal;
Geoff Lang4f0e0032017-05-01 16:04:35 -0400351 default:
352 return false;
353 }
354}
355
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800356bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400357{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 if (!ValidMipLevel(context, type, level))
Geoff Lang4f0e0032017-05-01 16:04:35 -0400359 {
360 return false;
Geoff Lang97073d12016-04-20 10:42:34 -0700361 }
362
Geoff Lang4f0e0032017-05-01 16:04:35 -0400363 if (level > 0 && context->getClientVersion() < ES_3_0)
364 {
365 return false;
366 }
Geoff Lang97073d12016-04-20 10:42:34 -0700367
Geoff Lang4f0e0032017-05-01 16:04:35 -0400368 return true;
369}
370
371bool IsValidCopyTextureDestinationLevel(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800372 TextureType type,
Geoff Lang4f0e0032017-05-01 16:04:35 -0400373 GLint level,
374 GLsizei width,
Brandon Jones28783792018-03-05 09:37:32 -0800375 GLsizei height,
376 bool isSubImage)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400377{
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800378 if (!ValidMipLevel(context, type, level))
Geoff Lang4f0e0032017-05-01 16:04:35 -0400379 {
380 return false;
381 }
382
Brandon Jones28783792018-03-05 09:37:32 -0800383 if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage))
384 {
385 return false;
386 }
387
Geoff Lang4f0e0032017-05-01 16:04:35 -0400388 const Caps &caps = context->getCaps();
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800389 switch (type)
Geoff Lang4f0e0032017-05-01 16:04:35 -0400390 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 case TextureType::_2D:
392 return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) &&
393 static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level);
394 case TextureType::Rectangle:
395 ASSERT(level == 0);
396 return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) &&
397 static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level);
Geoff Lang4f0e0032017-05-01 16:04:35 -0400398
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800399 case TextureType::CubeMap:
400 return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) &&
401 static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level);
402 default:
403 return true;
404 }
Geoff Lang97073d12016-04-20 10:42:34 -0700405}
406
Jamie Madillc1d770e2017-04-13 17:31:24 -0400407bool IsValidStencilFunc(GLenum func)
408{
409 switch (func)
410 {
411 case GL_NEVER:
412 case GL_ALWAYS:
413 case GL_LESS:
414 case GL_LEQUAL:
415 case GL_EQUAL:
416 case GL_GEQUAL:
417 case GL_GREATER:
418 case GL_NOTEQUAL:
419 return true;
420
421 default:
422 return false;
423 }
424}
425
426bool IsValidStencilFace(GLenum face)
427{
428 switch (face)
429 {
430 case GL_FRONT:
431 case GL_BACK:
432 case GL_FRONT_AND_BACK:
433 return true;
434
435 default:
436 return false;
437 }
438}
439
440bool IsValidStencilOp(GLenum op)
441{
442 switch (op)
443 {
444 case GL_ZERO:
445 case GL_KEEP:
446 case GL_REPLACE:
447 case GL_INCR:
448 case GL_DECR:
449 case GL_INVERT:
450 case GL_INCR_WRAP:
451 case GL_DECR_WRAP:
452 return true;
453
454 default:
455 return false;
456 }
457}
458
Jamie Madill5b772312018-03-08 20:28:32 -0500459bool ValidateES2CopyTexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800460 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -0400461 GLint level,
462 GLenum internalformat,
463 bool isSubImage,
464 GLint xoffset,
465 GLint yoffset,
466 GLint x,
467 GLint y,
468 GLsizei width,
469 GLsizei height,
470 GLint border)
471{
472 if (!ValidTexture2DDestinationTarget(context, target))
473 {
Jamie Madille0472f32018-11-27 16:32:45 -0500474 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -0400475 return false;
476 }
477
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800478 TextureType texType = TextureTargetToType(target);
479 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Jamie Madillbe849e42017-05-02 15:49:00 -0400480 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500481 // Error is already handled.
Jamie Madillbe849e42017-05-02 15:49:00 -0400482 return false;
483 }
484
485 Format textureFormat = Format::Invalid();
486 if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
487 xoffset, yoffset, 0, x, y, width, height, border,
488 &textureFormat))
489 {
490 return false;
491 }
492
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500493 const gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madillbe849e42017-05-02 15:49:00 -0400494 GLenum colorbufferFormat =
495 framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat;
496 const auto &formatInfo = *textureFormat.info;
497
498 // [OpenGL ES 2.0.24] table 3.9
499 if (isSubImage)
500 {
501 switch (formatInfo.format)
502 {
503 case GL_ALPHA:
504 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400505 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
506 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400507 {
Jamie Madille0472f32018-11-27 16:32:45 -0500508 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400509 return false;
510 }
511 break;
512 case GL_LUMINANCE:
513 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
514 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
515 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400516 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT &&
517 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400518 {
Jamie Madille0472f32018-11-27 16:32:45 -0500519 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400520 return false;
521 }
522 break;
523 case GL_RED_EXT:
524 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
525 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
526 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
527 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F &&
528 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400529 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
530 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400531 {
Jamie Madille0472f32018-11-27 16:32:45 -0500532 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400533 return false;
534 }
535 break;
536 case GL_RG_EXT:
537 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
538 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
539 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
540 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400541 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
542 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400543 {
Jamie Madille0472f32018-11-27 16:32:45 -0500544 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400545 return false;
546 }
547 break;
548 case GL_RGB:
549 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
550 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
551 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400552 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
553 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400554 {
Jamie Madille0472f32018-11-27 16:32:45 -0500555 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400556 return false;
557 }
558 break;
559 case GL_LUMINANCE_ALPHA:
560 case GL_RGBA:
561 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400562 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F &&
563 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400564 {
Jamie Madille0472f32018-11-27 16:32:45 -0500565 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400566 return false;
567 }
568 break;
569 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
570 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
571 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
572 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
573 case GL_ETC1_RGB8_OES:
574 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
575 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
576 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
577 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
578 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
Olli Etuahof2ed2992018-10-04 13:54:42 +0300579 case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT:
580 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:
581 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT:
582 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT:
Jamie Madille0472f32018-11-27 16:32:45 -0500583 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400584 return false;
585 case GL_DEPTH_COMPONENT:
586 case GL_DEPTH_STENCIL_OES:
Jamie Madille0472f32018-11-27 16:32:45 -0500587 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400588 return false;
589 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500590 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400591 return false;
592 }
593
594 if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat)
595 {
Jamie Madille0472f32018-11-27 16:32:45 -0500596 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400597 return false;
598 }
599 }
600 else
601 {
602 switch (internalformat)
603 {
604 case GL_ALPHA:
605 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
606 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
607 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
608 {
Jamie Madille0472f32018-11-27 16:32:45 -0500609 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400610 return false;
611 }
612 break;
613 case GL_LUMINANCE:
614 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
615 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
616 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
617 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
618 colorbufferFormat != GL_BGR5_A1_ANGLEX)
619 {
Jamie Madille0472f32018-11-27 16:32:45 -0500620 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400621 return false;
622 }
623 break;
624 case GL_RED_EXT:
625 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
626 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
627 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
628 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
629 colorbufferFormat != GL_BGR5_A1_ANGLEX)
630 {
Jamie Madille0472f32018-11-27 16:32:45 -0500631 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400632 return false;
633 }
634 break;
635 case GL_RG_EXT:
636 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
637 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
638 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
639 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
640 {
Jamie Madille0472f32018-11-27 16:32:45 -0500641 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400642 return false;
643 }
644 break;
645 case GL_RGB:
646 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
647 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
648 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
649 colorbufferFormat != GL_BGR5_A1_ANGLEX)
650 {
Jamie Madille0472f32018-11-27 16:32:45 -0500651 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400652 return false;
653 }
654 break;
655 case GL_LUMINANCE_ALPHA:
656 case GL_RGBA:
657 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
658 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
659 colorbufferFormat != GL_BGR5_A1_ANGLEX)
660 {
Jamie Madille0472f32018-11-27 16:32:45 -0500661 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400662 return false;
663 }
664 break;
665 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
666 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
667 if (context->getExtensions().textureCompressionDXT1)
668 {
Jamie Madille0472f32018-11-27 16:32:45 -0500669 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400670 return false;
671 }
672 else
673 {
Jamie Madille0472f32018-11-27 16:32:45 -0500674 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400675 return false;
676 }
677 break;
678 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
679 if (context->getExtensions().textureCompressionDXT3)
680 {
Jamie Madille0472f32018-11-27 16:32:45 -0500681 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400682 return false;
683 }
684 else
685 {
Jamie Madille0472f32018-11-27 16:32:45 -0500686 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400687 return false;
688 }
689 break;
690 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
691 if (context->getExtensions().textureCompressionDXT5)
692 {
Jamie Madille0472f32018-11-27 16:32:45 -0500693 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400694 return false;
695 }
696 else
697 {
Jamie Madille0472f32018-11-27 16:32:45 -0500698 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400699 return false;
700 }
701 break;
702 case GL_ETC1_RGB8_OES:
703 if (context->getExtensions().compressedETC1RGB8Texture)
704 {
Jamie Madille0472f32018-11-27 16:32:45 -0500705 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400706 return false;
707 }
708 else
709 {
Jamie Madille0472f32018-11-27 16:32:45 -0500710 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400711 return false;
712 }
713 break;
714 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
715 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
716 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
717 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
718 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
719 if (context->getExtensions().lossyETCDecode)
720 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500721 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400722 return false;
723 }
724 else
725 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500726 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400727 return false;
728 }
729 break;
730 case GL_DEPTH_COMPONENT:
731 case GL_DEPTH_COMPONENT16:
732 case GL_DEPTH_COMPONENT32_OES:
733 case GL_DEPTH_STENCIL_OES:
734 case GL_DEPTH24_STENCIL8_OES:
735 if (context->getExtensions().depthTextures)
736 {
Jamie Madille0472f32018-11-27 16:32:45 -0500737 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400738 return false;
739 }
740 else
741 {
Jamie Madille0472f32018-11-27 16:32:45 -0500742 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400743 return false;
744 }
745 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500746 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400747 return false;
748 }
749 }
750
751 // If width or height is zero, it is a no-op. Return false without setting an error.
752 return (width > 0 && height > 0);
753}
754
755bool ValidCap(const Context *context, GLenum cap, bool queryOnly)
756{
757 switch (cap)
758 {
759 // EXT_multisample_compatibility
760 case GL_MULTISAMPLE_EXT:
761 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
762 return context->getExtensions().multisampleCompatibility;
763
764 case GL_CULL_FACE:
765 case GL_POLYGON_OFFSET_FILL:
766 case GL_SAMPLE_ALPHA_TO_COVERAGE:
767 case GL_SAMPLE_COVERAGE:
768 case GL_SCISSOR_TEST:
769 case GL_STENCIL_TEST:
770 case GL_DEPTH_TEST:
771 case GL_BLEND:
772 case GL_DITHER:
773 return true;
774
775 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
776 case GL_RASTERIZER_DISCARD:
777 return (context->getClientMajorVersion() >= 3);
778
779 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
780 case GL_DEBUG_OUTPUT:
781 return context->getExtensions().debug;
782
783 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
784 return queryOnly && context->getExtensions().bindGeneratesResource;
785
786 case GL_CLIENT_ARRAYS_ANGLE:
787 return queryOnly && context->getExtensions().clientArrays;
788
789 case GL_FRAMEBUFFER_SRGB_EXT:
790 return context->getExtensions().sRGBWriteControl;
791
792 case GL_SAMPLE_MASK:
793 return context->getClientVersion() >= Version(3, 1);
794
Geoff Langb433e872017-10-05 14:01:47 -0400795 case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
Jamie Madillbe849e42017-05-02 15:49:00 -0400796 return queryOnly && context->getExtensions().robustResourceInitialization;
797
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700798 // GLES1 emulation: GLES1-specific caps
799 case GL_ALPHA_TEST:
Lingfeng Yang01074432018-04-16 10:19:51 -0700800 case GL_VERTEX_ARRAY:
801 case GL_NORMAL_ARRAY:
802 case GL_COLOR_ARRAY:
803 case GL_TEXTURE_COORD_ARRAY:
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700804 case GL_TEXTURE_2D:
Lingfeng Yangd0febe72018-05-17 22:36:52 -0700805 case GL_LIGHTING:
806 case GL_LIGHT0:
807 case GL_LIGHT1:
808 case GL_LIGHT2:
809 case GL_LIGHT3:
810 case GL_LIGHT4:
811 case GL_LIGHT5:
812 case GL_LIGHT6:
813 case GL_LIGHT7:
814 case GL_NORMALIZE:
815 case GL_RESCALE_NORMAL:
816 case GL_COLOR_MATERIAL:
Lingfeng Yang060088a2018-05-30 20:40:57 -0700817 case GL_CLIP_PLANE0:
818 case GL_CLIP_PLANE1:
819 case GL_CLIP_PLANE2:
820 case GL_CLIP_PLANE3:
821 case GL_CLIP_PLANE4:
822 case GL_CLIP_PLANE5:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -0700823 case GL_FOG:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700824 case GL_POINT_SMOOTH:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -0700825 case GL_LINE_SMOOTH:
826 case GL_COLOR_LOGIC_OP:
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700827 return context->getClientVersion() < Version(2, 0);
Lingfeng Yang01074432018-04-16 10:19:51 -0700828 case GL_POINT_SIZE_ARRAY_OES:
829 return context->getClientVersion() < Version(2, 0) &&
830 context->getExtensions().pointSizeArray;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700831 case GL_TEXTURE_CUBE_MAP:
832 return context->getClientVersion() < Version(2, 0) &&
833 context->getExtensions().textureCubeMap;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700834 case GL_POINT_SPRITE_OES:
835 return context->getClientVersion() < Version(2, 0) &&
836 context->getExtensions().pointSprite;
Jamie Madillbe849e42017-05-02 15:49:00 -0400837 default:
838 return false;
839 }
840}
841
Geoff Langfc32e8b2017-05-31 14:16:59 -0400842// Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section
843// 3.1.
Geoff Langcab92ee2017-07-19 17:32:07 -0400844bool IsValidESSLCharacter(unsigned char c)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400845{
846 // Printing characters are valid except " $ ` @ \ ' DEL.
Geoff Langcab92ee2017-07-19 17:32:07 -0400847 if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' &&
848 c != '\'')
Geoff Langfc32e8b2017-05-31 14:16:59 -0400849 {
850 return true;
851 }
852
853 // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid.
854 if (c >= 9 && c <= 13)
855 {
856 return true;
857 }
858
859 return false;
860}
861
Geoff Langcab92ee2017-07-19 17:32:07 -0400862bool IsValidESSLString(const char *str, size_t len)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400863{
Geoff Langa71a98e2017-06-19 15:15:00 -0400864 for (size_t i = 0; i < len; i++)
865 {
Geoff Langcab92ee2017-07-19 17:32:07 -0400866 if (!IsValidESSLCharacter(str[i]))
Geoff Langa71a98e2017-06-19 15:15:00 -0400867 {
868 return false;
869 }
870 }
871
872 return true;
Geoff Langfc32e8b2017-05-31 14:16:59 -0400873}
874
Geoff Langcab92ee2017-07-19 17:32:07 -0400875bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed)
876{
877 enum class ParseState
878 {
879 // Have not seen an ASCII non-whitespace character yet on
880 // this line. Possible that we might see a preprocessor
881 // directive.
882 BEGINING_OF_LINE,
883
884 // Have seen at least one ASCII non-whitespace character
885 // on this line.
886 MIDDLE_OF_LINE,
887
888 // Handling a preprocessor directive. Passes through all
889 // characters up to the end of the line. Disables comment
890 // processing.
891 IN_PREPROCESSOR_DIRECTIVE,
892
893 // Handling a single-line comment. The comment text is
894 // replaced with a single space.
895 IN_SINGLE_LINE_COMMENT,
896
897 // Handling a multi-line comment. Newlines are passed
898 // through to preserve line numbers.
899 IN_MULTI_LINE_COMMENT
900 };
901
902 ParseState state = ParseState::BEGINING_OF_LINE;
903 size_t pos = 0;
904
905 while (pos < len)
906 {
907 char c = str[pos];
908 char next = pos + 1 < len ? str[pos + 1] : 0;
909
910 // Check for newlines
911 if (c == '\n' || c == '\r')
912 {
913 if (state != ParseState::IN_MULTI_LINE_COMMENT)
914 {
915 state = ParseState::BEGINING_OF_LINE;
916 }
917
918 pos++;
919 continue;
920 }
921
922 switch (state)
923 {
924 case ParseState::BEGINING_OF_LINE:
925 if (c == ' ')
926 {
927 // Maintain the BEGINING_OF_LINE state until a non-space is seen
928 pos++;
929 }
930 else if (c == '#')
931 {
932 state = ParseState::IN_PREPROCESSOR_DIRECTIVE;
933 pos++;
934 }
935 else
936 {
937 // Don't advance, re-process this character with the MIDDLE_OF_LINE state
938 state = ParseState::MIDDLE_OF_LINE;
939 }
940 break;
941
942 case ParseState::MIDDLE_OF_LINE:
943 if (c == '/' && next == '/')
944 {
945 state = ParseState::IN_SINGLE_LINE_COMMENT;
946 pos++;
947 }
948 else if (c == '/' && next == '*')
949 {
950 state = ParseState::IN_MULTI_LINE_COMMENT;
951 pos++;
952 }
953 else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r'))
954 {
955 // Skip line continuation characters
956 }
957 else if (!IsValidESSLCharacter(c))
958 {
959 return false;
960 }
961 pos++;
962 break;
963
964 case ParseState::IN_PREPROCESSOR_DIRECTIVE:
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -0700965 // Line-continuation characters may not be permitted.
966 // Otherwise, just pass it through. Do not parse comments in this state.
967 if (!lineContinuationAllowed && c == '\\')
968 {
969 return false;
970 }
Geoff Langcab92ee2017-07-19 17:32:07 -0400971 pos++;
972 break;
973
974 case ParseState::IN_SINGLE_LINE_COMMENT:
975 // Line-continuation characters are processed before comment processing.
976 // Advance string if a new line character is immediately behind
977 // line-continuation character.
978 if (c == '\\' && (next == '\n' || next == '\r'))
979 {
980 pos++;
981 }
982 pos++;
983 break;
984
985 case ParseState::IN_MULTI_LINE_COMMENT:
986 if (c == '*' && next == '/')
987 {
988 state = ParseState::MIDDLE_OF_LINE;
989 pos++;
990 }
991 pos++;
992 break;
993 }
994 }
995
996 return true;
997}
998
Jamie Madill5b772312018-03-08 20:28:32 -0500999bool ValidateWebGLNamePrefix(Context *context, const GLchar *name)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001000{
1001 ASSERT(context->isWebGL());
1002
1003 // WebGL 1.0 [Section 6.16] GLSL Constructs
1004 // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL.
1005 if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0)
1006 {
Jamie Madille0472f32018-11-27 16:32:45 -05001007 context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001008 return false;
1009 }
1010
1011 return true;
1012}
1013
Jamie Madill5b772312018-03-08 20:28:32 -05001014bool ValidateWebGLNameLength(Context *context, size_t length)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001015{
1016 ASSERT(context->isWebGL());
1017
1018 if (context->isWebGL1() && length > 256)
1019 {
1020 // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths
1021 // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute
1022 // locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001023 context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001024
1025 return false;
1026 }
1027 else if (length > 1024)
1028 {
1029 // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of
1030 // uniform and attribute locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001031 context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001032 return false;
1033 }
1034
1035 return true;
1036}
1037
Jamie Madill007530e2017-12-28 14:27:04 -05001038bool ValidateMatrixMode(Context *context, GLenum matrixMode)
1039{
1040 if (!context->getExtensions().pathRendering)
1041 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001042 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05001043 return false;
1044 }
1045
1046 if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM)
1047 {
Jamie Madille0472f32018-11-27 16:32:45 -05001048 context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode);
Jamie Madill007530e2017-12-28 14:27:04 -05001049 return false;
1050 }
1051 return true;
1052}
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001053
1054bool ValidBlendFunc(const Context *context, GLenum val)
1055{
1056 const gl::Extensions &ext = context->getExtensions();
1057
1058 // these are always valid for src and dst.
1059 switch (val)
1060 {
1061 case GL_ZERO:
1062 case GL_ONE:
1063 case GL_SRC_COLOR:
1064 case GL_ONE_MINUS_SRC_COLOR:
1065 case GL_DST_COLOR:
1066 case GL_ONE_MINUS_DST_COLOR:
1067 case GL_SRC_ALPHA:
1068 case GL_ONE_MINUS_SRC_ALPHA:
1069 case GL_DST_ALPHA:
1070 case GL_ONE_MINUS_DST_ALPHA:
1071 case GL_CONSTANT_COLOR:
1072 case GL_ONE_MINUS_CONSTANT_COLOR:
1073 case GL_CONSTANT_ALPHA:
1074 case GL_ONE_MINUS_CONSTANT_ALPHA:
1075 return true;
1076
1077 // EXT_blend_func_extended.
1078 case GL_SRC1_COLOR_EXT:
1079 case GL_SRC1_ALPHA_EXT:
1080 case GL_ONE_MINUS_SRC1_COLOR_EXT:
1081 case GL_ONE_MINUS_SRC1_ALPHA_EXT:
1082 case GL_SRC_ALPHA_SATURATE_EXT:
1083 return ext.blendFuncExtended;
1084
1085 default:
1086 return false;
1087 }
1088}
1089
1090bool ValidSrcBlendFunc(const Context *context, GLenum val)
1091{
1092 if (ValidBlendFunc(context, val))
1093 return true;
1094
1095 if (val == GL_SRC_ALPHA_SATURATE)
1096 return true;
1097
1098 return false;
1099}
1100
1101bool ValidDstBlendFunc(const Context *context, GLenum val)
1102{
1103 if (ValidBlendFunc(context, val))
1104 return true;
1105
1106 if (val == GL_SRC_ALPHA_SATURATE)
1107 {
1108 if (context->getClientMajorVersion() >= 3)
1109 return true;
1110 }
1111
1112 return false;
1113}
Jamie Madillc29968b2016-01-20 11:17:23 -05001114} // anonymous namespace
1115
Geoff Langff5b2d52016-09-07 11:32:23 -04001116bool ValidateES2TexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001117 TextureTarget target,
Geoff Langff5b2d52016-09-07 11:32:23 -04001118 GLint level,
1119 GLenum internalformat,
1120 bool isCompressed,
1121 bool isSubImage,
1122 GLint xoffset,
1123 GLint yoffset,
1124 GLsizei width,
1125 GLsizei height,
1126 GLint border,
1127 GLenum format,
1128 GLenum type,
1129 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001130 const void *pixels)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001131{
Jamie Madill6f38f822014-06-06 17:12:20 -04001132 if (!ValidTexture2DDestinationTarget(context, target))
1133 {
Jamie Madille0472f32018-11-27 16:32:45 -05001134 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001135 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001136 }
1137
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001138 TextureType texType = TextureTargetToType(target);
1139 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001140 {
Jamie Madill610640f2018-11-21 17:28:41 -05001141 // Error already handled.
Geoff Langb1196682014-07-23 13:47:29 -04001142 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001143 }
1144
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001145 if (!ValidMipLevel(context, texType, level))
Brandon Jones6cad5662017-06-14 13:25:13 -07001146 {
Jamie Madille0472f32018-11-27 16:32:45 -05001147 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Brandon Jones6cad5662017-06-14 13:25:13 -07001148 return false;
1149 }
1150
1151 if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width ||
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001152 std::numeric_limits<GLsizei>::max() - yoffset < height)
1153 {
Jamie Madille0472f32018-11-27 16:32:45 -05001154 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Geoff Langb1196682014-07-23 13:47:29 -04001155 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001156 }
1157
Geoff Langaae65a42014-05-26 12:43:44 -04001158 const gl::Caps &caps = context->getCaps();
1159
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001160 switch (texType)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001161 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001162 case TextureType::_2D:
1163 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
1164 static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
1165 {
Jamie Madille0472f32018-11-27 16:32:45 -05001166 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001167 return false;
1168 }
1169 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001170
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001171 case TextureType::Rectangle:
1172 ASSERT(level == 0);
1173 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1174 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1175 {
Jamie Madille0472f32018-11-27 16:32:45 -05001176 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001177 return false;
1178 }
1179 if (isCompressed)
1180 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001181 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001182 return false;
1183 }
1184 break;
1185
1186 case TextureType::CubeMap:
1187 if (!isSubImage && width != height)
1188 {
Jamie Madille0472f32018-11-27 16:32:45 -05001189 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001190 return false;
1191 }
1192
1193 if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) ||
1194 static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level))
1195 {
Jamie Madille0472f32018-11-27 16:32:45 -05001196 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001197 return false;
1198 }
1199 break;
1200
1201 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001202 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langa9be0dc2014-12-17 12:34:40 -05001203 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001204 }
1205
Jamie Madillcfc73cc2019-04-08 16:26:51 -04001206 gl::Texture *texture = context->getTextureByType(texType);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001207 if (!texture)
1208 {
Jamie Madille0472f32018-11-27 16:32:45 -05001209 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Geoff Langb1196682014-07-23 13:47:29 -04001210 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001211 }
1212
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001213 // Verify zero border
1214 if (border != 0)
1215 {
Jamie Madille0472f32018-11-27 16:32:45 -05001216 context->validationError(GL_INVALID_VALUE, kInvalidBorder);
Geoff Langb1196682014-07-23 13:47:29 -04001217 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001218 }
1219
Tim Van Patten208af3e2019-03-19 09:15:55 -06001220 bool nonEqualFormatsAllowed = false;
1221
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001222 if (isCompressed)
1223 {
tmartino0ccd5ae2015-10-01 14:33:14 -04001224 GLenum actualInternalFormat =
Geoff Langca271392017-04-05 12:30:00 -04001225 isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat
1226 : internalformat;
Geoff Lange88e4542018-05-03 15:05:57 -04001227
1228 const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat);
1229
1230 if (!internalFormatInfo.compressed)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001231 {
Jamie Madille0472f32018-11-27 16:32:45 -05001232 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001233 return false;
1234 }
1235
1236 if (!internalFormatInfo.textureSupport(context->getClientVersion(),
1237 context->getExtensions()))
1238 {
Jamie Madille0472f32018-11-27 16:32:45 -05001239 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001240 return false;
tmartino0ccd5ae2015-10-01 14:33:14 -04001241 }
Geoff Lang966c9402017-04-18 12:38:27 -04001242
1243 if (isSubImage)
tmartino0ccd5ae2015-10-01 14:33:14 -04001244 {
Geoff Lange88e4542018-05-03 15:05:57 -04001245 // From the OES_compressed_ETC1_RGB8_texture spec:
1246 // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or
1247 // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format
1248 // ETC1_RGB8_OES.
1249 if (actualInternalFormat == GL_ETC1_RGB8_OES)
1250 {
Jamie Madille0472f32018-11-27 16:32:45 -05001251 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001252 return false;
1253 }
1254
Geoff Lang966c9402017-04-18 12:38:27 -04001255 if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width,
1256 height, texture->getWidth(target, level),
1257 texture->getHeight(target, level)))
1258 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001259 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001260 return false;
1261 }
1262
1263 if (format != actualInternalFormat)
1264 {
Jamie Madille0472f32018-11-27 16:32:45 -05001265 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Geoff Lang966c9402017-04-18 12:38:27 -04001266 return false;
1267 }
1268 }
1269 else
1270 {
1271 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height))
1272 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001273 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001274 return false;
1275 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001276 }
1277 }
1278 else
1279 {
1280 // validate <type> by itself (used as secondary key below)
1281 switch (type)
1282 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001283 case GL_UNSIGNED_BYTE:
1284 case GL_UNSIGNED_SHORT_5_6_5:
1285 case GL_UNSIGNED_SHORT_4_4_4_4:
1286 case GL_UNSIGNED_SHORT_5_5_5_1:
1287 case GL_UNSIGNED_SHORT:
1288 case GL_UNSIGNED_INT:
1289 case GL_UNSIGNED_INT_24_8_OES:
1290 case GL_HALF_FLOAT_OES:
1291 case GL_FLOAT:
1292 break;
1293 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001294 context->validationError(GL_INVALID_ENUM, kInvalidType);
He Yunchaoced53ae2016-11-29 15:00:51 +08001295 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001296 }
1297
1298 // validate <format> + <type> combinations
1299 // - invalid <format> -> sets INVALID_ENUM
1300 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
1301 switch (format)
1302 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001303 case GL_ALPHA:
1304 case GL_LUMINANCE:
1305 case GL_LUMINANCE_ALPHA:
1306 switch (type)
1307 {
1308 case GL_UNSIGNED_BYTE:
1309 case GL_FLOAT:
1310 case GL_HALF_FLOAT_OES:
1311 break;
1312 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001313 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001314 return false;
1315 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001316 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001317 case GL_RED:
1318 case GL_RG:
1319 if (!context->getExtensions().textureRG)
1320 {
Jamie Madille0472f32018-11-27 16:32:45 -05001321 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001322 return false;
1323 }
1324 switch (type)
1325 {
1326 case GL_UNSIGNED_BYTE:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001327 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001328 case GL_FLOAT:
1329 case GL_HALF_FLOAT_OES:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001330 if (!context->getExtensions().textureFloat)
1331 {
Jamie Madille0472f32018-11-27 16:32:45 -05001332 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001333 return false;
1334 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001335 break;
1336 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001337 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001338 return false;
1339 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001340 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001341 case GL_RGB:
1342 switch (type)
1343 {
1344 case GL_UNSIGNED_BYTE:
1345 case GL_UNSIGNED_SHORT_5_6_5:
1346 case GL_FLOAT:
1347 case GL_HALF_FLOAT_OES:
1348 break;
1349 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001350 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001351 return false;
1352 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001353 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001354 case GL_RGBA:
1355 switch (type)
1356 {
1357 case GL_UNSIGNED_BYTE:
1358 case GL_UNSIGNED_SHORT_4_4_4_4:
1359 case GL_UNSIGNED_SHORT_5_5_5_1:
1360 case GL_FLOAT:
1361 case GL_HALF_FLOAT_OES:
1362 break;
1363 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001364 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001365 return false;
1366 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001367 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001368 case GL_BGRA_EXT:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001369 if (!context->getExtensions().textureFormatBGRA8888)
1370 {
Jamie Madille0472f32018-11-27 16:32:45 -05001371 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001372 return false;
1373 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001374 switch (type)
1375 {
1376 case GL_UNSIGNED_BYTE:
1377 break;
1378 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001379 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001380 return false;
1381 }
1382 break;
1383 case GL_SRGB_EXT:
1384 case GL_SRGB_ALPHA_EXT:
1385 if (!context->getExtensions().sRGB)
1386 {
Jamie Madille0472f32018-11-27 16:32:45 -05001387 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001388 return false;
1389 }
1390 switch (type)
1391 {
1392 case GL_UNSIGNED_BYTE:
1393 break;
1394 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001395 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001396 return false;
1397 }
1398 break;
1399 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are
1400 // handled below
1401 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1402 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1403 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1404 break;
1405 case GL_DEPTH_COMPONENT:
1406 switch (type)
1407 {
1408 case GL_UNSIGNED_SHORT:
1409 case GL_UNSIGNED_INT:
1410 break;
1411 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001412 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001413 return false;
1414 }
1415 break;
1416 case GL_DEPTH_STENCIL_OES:
1417 switch (type)
1418 {
1419 case GL_UNSIGNED_INT_24_8_OES:
1420 break;
1421 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001422 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001423 return false;
1424 }
1425 break;
1426 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001427 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001428 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001429 }
1430
1431 switch (format)
1432 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001433 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1434 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1435 if (context->getExtensions().textureCompressionDXT1)
1436 {
Jamie Madille0472f32018-11-27 16:32:45 -05001437 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001438 return false;
1439 }
1440 else
1441 {
Jamie Madille0472f32018-11-27 16:32:45 -05001442 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001443 return false;
1444 }
1445 break;
1446 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1447 if (context->getExtensions().textureCompressionDXT3)
1448 {
Jamie Madille0472f32018-11-27 16:32:45 -05001449 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001450 return false;
1451 }
1452 else
1453 {
Jamie Madille0472f32018-11-27 16:32:45 -05001454 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001455 return false;
1456 }
1457 break;
1458 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1459 if (context->getExtensions().textureCompressionDXT5)
1460 {
Jamie Madille0472f32018-11-27 16:32:45 -05001461 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001462 return false;
1463 }
1464 else
1465 {
Jamie Madille0472f32018-11-27 16:32:45 -05001466 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001467 return false;
1468 }
1469 break;
1470 case GL_ETC1_RGB8_OES:
1471 if (context->getExtensions().compressedETC1RGB8Texture)
1472 {
Jamie Madille0472f32018-11-27 16:32:45 -05001473 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001474 return false;
1475 }
1476 else
1477 {
Jamie Madille0472f32018-11-27 16:32:45 -05001478 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001479 return false;
1480 }
1481 break;
1482 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001483 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1484 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1485 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1486 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001487 if (context->getExtensions().lossyETCDecode)
1488 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001489 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001490 return false;
1491 }
1492 else
1493 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001494 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001495 return false;
1496 }
1497 break;
1498 case GL_DEPTH_COMPONENT:
1499 case GL_DEPTH_STENCIL_OES:
1500 if (!context->getExtensions().depthTextures)
1501 {
Jamie Madille0472f32018-11-27 16:32:45 -05001502 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001503 return false;
1504 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001505 if (target != TextureTarget::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001506 {
Jamie Madille0472f32018-11-27 16:32:45 -05001507 context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001508 return false;
1509 }
1510 // OES_depth_texture supports loading depth data and multiple levels,
1511 // but ANGLE_depth_texture does not
Brandon Jonesafa75152017-07-21 13:11:29 -07001512 if (pixels != nullptr)
He Yunchaoced53ae2016-11-29 15:00:51 +08001513 {
Jamie Madille0472f32018-11-27 16:32:45 -05001514 context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
Brandon Jonesafa75152017-07-21 13:11:29 -07001515 return false;
1516 }
1517 if (level != 0)
1518 {
Jamie Madille0472f32018-11-27 16:32:45 -05001519 context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
He Yunchaoced53ae2016-11-29 15:00:51 +08001520 return false;
1521 }
1522 break;
1523 default:
1524 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001525 }
1526
Geoff Lang6e898aa2017-06-02 11:17:26 -04001527 if (!isSubImage)
1528 {
1529 switch (internalformat)
1530 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001531 // Core ES 2.0 formats
1532 case GL_ALPHA:
1533 case GL_LUMINANCE:
1534 case GL_LUMINANCE_ALPHA:
1535 case GL_RGB:
1536 case GL_RGBA:
1537 break;
1538
Geoff Lang6e898aa2017-06-02 11:17:26 -04001539 case GL_RGBA32F:
1540 if (!context->getExtensions().colorBufferFloatRGBA)
1541 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001542 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001543 return false;
1544 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001545
1546 nonEqualFormatsAllowed = true;
1547
Geoff Lang6e898aa2017-06-02 11:17:26 -04001548 if (type != GL_FLOAT)
1549 {
Jamie Madille0472f32018-11-27 16:32:45 -05001550 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001551 return false;
1552 }
1553 if (format != GL_RGBA)
1554 {
Jamie Madille0472f32018-11-27 16:32:45 -05001555 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001556 return false;
1557 }
1558 break;
1559
1560 case GL_RGB32F:
1561 if (!context->getExtensions().colorBufferFloatRGB)
1562 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001563 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001564 return false;
1565 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001566
1567 nonEqualFormatsAllowed = true;
1568
Geoff Lang6e898aa2017-06-02 11:17:26 -04001569 if (type != GL_FLOAT)
1570 {
Jamie Madille0472f32018-11-27 16:32:45 -05001571 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001572 return false;
1573 }
1574 if (format != GL_RGB)
1575 {
Jamie Madille0472f32018-11-27 16:32:45 -05001576 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001577 return false;
1578 }
1579 break;
1580
Tim Van Patten208af3e2019-03-19 09:15:55 -06001581 case GL_BGRA_EXT:
1582 if (!context->getExtensions().textureFormatBGRA8888)
1583 {
1584 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1585 return false;
1586 }
Geoff Lang6e898aa2017-06-02 11:17:26 -04001587 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001588
1589 case GL_DEPTH_COMPONENT:
1590 case GL_DEPTH_STENCIL:
1591 if (!context->getExtensions().depthTextures)
1592 {
1593 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1594 return false;
1595 }
1596 break;
1597
1598 case GL_RED:
1599 case GL_RG:
1600 if (!context->getExtensions().textureRG)
1601 {
1602 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1603 return false;
1604 }
1605 break;
1606
1607 case GL_SRGB_EXT:
1608 case GL_SRGB_ALPHA_EXT:
1609 if (!context->getExtensions().sRGB)
1610 {
1611 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1612 return false;
1613 }
1614 break;
1615
1616 default:
1617 context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat);
1618 return false;
Geoff Lang6e898aa2017-06-02 11:17:26 -04001619 }
1620 }
1621
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001622 if (type == GL_FLOAT)
1623 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001624 if (!context->getExtensions().textureFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001625 {
Jamie Madille0472f32018-11-27 16:32:45 -05001626 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001627 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001628 }
1629 }
1630 else if (type == GL_HALF_FLOAT_OES)
1631 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001632 if (!context->getExtensions().textureHalfFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001633 {
Jamie Madille0472f32018-11-27 16:32:45 -05001634 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001635 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001636 }
1637 }
1638 }
1639
Tim Van Patten208af3e2019-03-19 09:15:55 -06001640 if (isSubImage)
Geoff Langff5b2d52016-09-07 11:32:23 -04001641 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001642 const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info;
1643 if (textureInternalFormat.internalFormat == GL_NONE)
1644 {
1645 context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel);
1646 return false;
1647 }
1648
Tim Van Patten5f388c22019-03-14 09:54:23 -06001649 if (format != textureInternalFormat.format)
1650 {
1651 context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch);
1652 return false;
1653 }
1654
1655 if (context->getExtensions().webglCompatibility)
Tim Van Patten208af3e2019-03-19 09:15:55 -06001656 {
1657 if (GetInternalFormatInfo(format, type).sizedInternalFormat !=
1658 textureInternalFormat.sizedInternalFormat)
1659 {
Tim Van Patten5f388c22019-03-14 09:54:23 -06001660 context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch);
Tim Van Patten208af3e2019-03-19 09:15:55 -06001661 return false;
1662 }
1663 }
1664
1665 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
1666 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level))
1667 {
1668 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
1669 return false;
1670 }
1671
1672 if (width > 0 && height > 0 && pixels == nullptr &&
1673 context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr)
1674 {
1675 context->validationError(GL_INVALID_VALUE, kPixelDataNull);
1676 return false;
1677 }
1678 }
1679 else
1680 {
1681 if (texture->getImmutableFormat())
1682 {
1683 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
1684 return false;
1685 }
1686 }
1687
1688 // From GL_CHROMIUM_color_buffer_float_rgb[a]:
1689 // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
1690 // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
1691 // internalformat parameter and format parameter of TexImage2D must match is lifted for this
1692 // case.
1693 if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
1694 {
1695 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Langff5b2d52016-09-07 11:32:23 -04001696 return false;
1697 }
1698
Tim Van Patten208af3e2019-03-19 09:15:55 -06001699 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
1700 return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels,
1701 imageSize);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001702}
1703
He Yunchaoced53ae2016-11-29 15:00:51 +08001704bool ValidateES2TexStorageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001705 TextureType target,
He Yunchaoced53ae2016-11-29 15:00:51 +08001706 GLsizei levels,
1707 GLenum internalformat,
1708 GLsizei width,
1709 GLsizei height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001710{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001711 if (target != TextureType::_2D && target != TextureType::CubeMap &&
1712 target != TextureType::Rectangle)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001713 {
Jamie Madille0472f32018-11-27 16:32:45 -05001714 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001715 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001716 }
1717
1718 if (width < 1 || height < 1 || levels < 1)
1719 {
Jamie Madille0472f32018-11-27 16:32:45 -05001720 context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall);
Geoff Langb1196682014-07-23 13:47:29 -04001721 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001722 }
1723
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001724 if (target == TextureType::CubeMap && width != height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001725 {
Jamie Madille0472f32018-11-27 16:32:45 -05001726 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Langb1196682014-07-23 13:47:29 -04001727 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001728 }
1729
1730 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1731 {
Jamie Madille0472f32018-11-27 16:32:45 -05001732 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
Geoff Langb1196682014-07-23 13:47:29 -04001733 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001734 }
1735
Geoff Langca271392017-04-05 12:30:00 -04001736 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Lang5d601382014-07-22 15:14:06 -04001737 if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001738 {
Jamie Madille0472f32018-11-27 16:32:45 -05001739 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Langb1196682014-07-23 13:47:29 -04001740 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001741 }
1742
Geoff Langaae65a42014-05-26 12:43:44 -04001743 const gl::Caps &caps = context->getCaps();
1744
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001745 switch (target)
1746 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001747 case TextureType::_2D:
He Yunchaoced53ae2016-11-29 15:00:51 +08001748 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
1749 static_cast<GLuint>(height) > caps.max2DTextureSize)
1750 {
Jamie Madille0472f32018-11-27 16:32:45 -05001751 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001752 return false;
1753 }
1754 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001755 case TextureType::Rectangle:
Jamie Madill610640f2018-11-21 17:28:41 -05001756 if (levels != 1)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001757 {
Jamie Madille0472f32018-11-27 16:32:45 -05001758 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madill610640f2018-11-21 17:28:41 -05001759 return false;
1760 }
1761
1762 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1763 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1764 {
Jamie Madille0472f32018-11-27 16:32:45 -05001765 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001766 return false;
1767 }
1768 if (formatInfo.compressed)
1769 {
Jamie Madille0472f32018-11-27 16:32:45 -05001770 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001771 return false;
1772 }
1773 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001774 case TextureType::CubeMap:
He Yunchaoced53ae2016-11-29 15:00:51 +08001775 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize ||
1776 static_cast<GLuint>(height) > caps.maxCubeMapTextureSize)
1777 {
Jamie Madille0472f32018-11-27 16:32:45 -05001778 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001779 return false;
1780 }
1781 break;
1782 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001783 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001784 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001785 }
1786
Geoff Langc0b9ef42014-07-02 10:02:37 -04001787 if (levels != 1 && !context->getExtensions().textureNPOT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001788 {
1789 if (!gl::isPow2(width) || !gl::isPow2(height))
1790 {
Jamie Madille0472f32018-11-27 16:32:45 -05001791 context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2);
Geoff Langb1196682014-07-23 13:47:29 -04001792 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001793 }
1794 }
1795
1796 switch (internalformat)
1797 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001798 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1799 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1800 if (!context->getExtensions().textureCompressionDXT1)
1801 {
Jamie Madille0472f32018-11-27 16:32:45 -05001802 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001803 return false;
1804 }
1805 break;
1806 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1807 if (!context->getExtensions().textureCompressionDXT3)
1808 {
Jamie Madille0472f32018-11-27 16:32:45 -05001809 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001810 return false;
1811 }
1812 break;
1813 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1814 if (!context->getExtensions().textureCompressionDXT5)
1815 {
Jamie Madille0472f32018-11-27 16:32:45 -05001816 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001817 return false;
1818 }
1819 break;
1820 case GL_ETC1_RGB8_OES:
1821 if (!context->getExtensions().compressedETC1RGB8Texture)
1822 {
Jamie Madille0472f32018-11-27 16:32:45 -05001823 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001824 return false;
1825 }
1826 break;
1827 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001828 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1829 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1830 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1831 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001832 if (!context->getExtensions().lossyETCDecode)
1833 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001834 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001835 return false;
1836 }
1837 break;
1838 case GL_RGBA32F_EXT:
1839 case GL_RGB32F_EXT:
1840 case GL_ALPHA32F_EXT:
1841 case GL_LUMINANCE32F_EXT:
1842 case GL_LUMINANCE_ALPHA32F_EXT:
1843 if (!context->getExtensions().textureFloat)
1844 {
Jamie Madille0472f32018-11-27 16:32:45 -05001845 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001846 return false;
1847 }
1848 break;
1849 case GL_RGBA16F_EXT:
1850 case GL_RGB16F_EXT:
1851 case GL_ALPHA16F_EXT:
1852 case GL_LUMINANCE16F_EXT:
1853 case GL_LUMINANCE_ALPHA16F_EXT:
1854 if (!context->getExtensions().textureHalfFloat)
1855 {
Jamie Madille0472f32018-11-27 16:32:45 -05001856 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001857 return false;
1858 }
1859 break;
1860 case GL_R8_EXT:
1861 case GL_RG8_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001862 if (!context->getExtensions().textureRG)
1863 {
Jamie Madille0472f32018-11-27 16:32:45 -05001864 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001865 return false;
1866 }
1867 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001868 case GL_R16F_EXT:
1869 case GL_RG16F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001870 if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat)
1871 {
Jamie Madille0472f32018-11-27 16:32:45 -05001872 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001873 return false;
1874 }
1875 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001876 case GL_R32F_EXT:
1877 case GL_RG32F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001878 if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat)
He Yunchaoced53ae2016-11-29 15:00:51 +08001879 {
Jamie Madille0472f32018-11-27 16:32:45 -05001880 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001881 return false;
1882 }
1883 break;
1884 case GL_DEPTH_COMPONENT16:
1885 case GL_DEPTH_COMPONENT32_OES:
1886 case GL_DEPTH24_STENCIL8_OES:
1887 if (!context->getExtensions().depthTextures)
1888 {
Jamie Madille0472f32018-11-27 16:32:45 -05001889 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001890 return false;
1891 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001892 if (target != TextureType::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001893 {
Jamie Madille0472f32018-11-27 16:32:45 -05001894 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001895 return false;
1896 }
1897 // ANGLE_depth_texture only supports 1-level textures
1898 if (levels != 1)
1899 {
Jamie Madille0472f32018-11-27 16:32:45 -05001900 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
He Yunchaoced53ae2016-11-29 15:00:51 +08001901 return false;
1902 }
1903 break;
1904 default:
1905 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001906 }
1907
Jamie Madillcfc73cc2019-04-08 16:26:51 -04001908 gl::Texture *texture = context->getTextureByType(target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001909 if (!texture || texture->id() == 0)
1910 {
Jamie Madille0472f32018-11-27 16:32:45 -05001911 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
Geoff Langb1196682014-07-23 13:47:29 -04001912 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001913 }
1914
Geoff Lang69cce582015-09-17 13:20:36 -04001915 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001916 {
Jamie Madille0472f32018-11-27 16:32:45 -05001917 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
Geoff Langb1196682014-07-23 13:47:29 -04001918 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001919 }
1920
1921 return true;
1922}
1923
He Yunchaoced53ae2016-11-29 15:00:51 +08001924bool ValidateDiscardFramebufferEXT(Context *context,
1925 GLenum target,
1926 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07001927 const GLenum *attachments)
1928{
Jamie Madillc29968b2016-01-20 11:17:23 -05001929 if (!context->getExtensions().discardFramebuffer)
1930 {
Jamie Madille0472f32018-11-27 16:32:45 -05001931 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05001932 return false;
1933 }
1934
Austin Kinross08332632015-05-05 13:35:47 -07001935 bool defaultFramebuffer = false;
1936
1937 switch (target)
1938 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001939 case GL_FRAMEBUFFER:
1940 defaultFramebuffer =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001941 (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0);
He Yunchaoced53ae2016-11-29 15:00:51 +08001942 break;
1943 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001944 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08001945 return false;
Austin Kinross08332632015-05-05 13:35:47 -07001946 }
1947
He Yunchaoced53ae2016-11-29 15:00:51 +08001948 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
1949 defaultFramebuffer);
Austin Kinross08332632015-05-05 13:35:47 -07001950}
1951
Austin Kinrossbc781f32015-10-26 09:27:38 -07001952bool ValidateBindVertexArrayOES(Context *context, GLuint array)
1953{
1954 if (!context->getExtensions().vertexArrayObject)
1955 {
Jamie Madille0472f32018-11-27 16:32:45 -05001956 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001957 return false;
1958 }
1959
1960 return ValidateBindVertexArrayBase(context, array);
1961}
1962
Jamie Madilld7576732017-08-26 18:49:50 -04001963bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07001964{
1965 if (!context->getExtensions().vertexArrayObject)
1966 {
Jamie Madille0472f32018-11-27 16:32:45 -05001967 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001968 return false;
1969 }
1970
Olli Etuaho41997e72016-03-10 13:38:39 +02001971 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001972}
1973
Jamie Madilld7576732017-08-26 18:49:50 -04001974bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07001975{
1976 if (!context->getExtensions().vertexArrayObject)
1977 {
Jamie Madille0472f32018-11-27 16:32:45 -05001978 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001979 return false;
1980 }
1981
Olli Etuaho41997e72016-03-10 13:38:39 +02001982 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001983}
1984
Jamie Madilld7576732017-08-26 18:49:50 -04001985bool ValidateIsVertexArrayOES(Context *context, GLuint array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07001986{
1987 if (!context->getExtensions().vertexArrayObject)
1988 {
Jamie Madille0472f32018-11-27 16:32:45 -05001989 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07001990 return false;
1991 }
1992
1993 return true;
1994}
Geoff Langc5629752015-12-07 16:29:04 -05001995
1996bool ValidateProgramBinaryOES(Context *context,
1997 GLuint program,
1998 GLenum binaryFormat,
1999 const void *binary,
2000 GLint length)
2001{
2002 if (!context->getExtensions().getProgramBinary)
2003 {
Jamie Madille0472f32018-11-27 16:32:45 -05002004 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002005 return false;
2006 }
2007
2008 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
2009}
2010
2011bool ValidateGetProgramBinaryOES(Context *context,
2012 GLuint program,
2013 GLsizei bufSize,
2014 GLsizei *length,
2015 GLenum *binaryFormat,
2016 void *binary)
2017{
2018 if (!context->getExtensions().getProgramBinary)
2019 {
Jamie Madille0472f32018-11-27 16:32:45 -05002020 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002021 return false;
2022 }
2023
2024 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
2025}
Geoff Lange102fee2015-12-10 11:23:30 -05002026
Geoff Lang70d0f492015-12-10 17:45:46 -05002027static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication)
2028{
2029 switch (source)
2030 {
2031 case GL_DEBUG_SOURCE_API:
2032 case GL_DEBUG_SOURCE_SHADER_COMPILER:
2033 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
2034 case GL_DEBUG_SOURCE_OTHER:
2035 // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted
2036 return !mustBeThirdPartyOrApplication;
2037
2038 case GL_DEBUG_SOURCE_THIRD_PARTY:
2039 case GL_DEBUG_SOURCE_APPLICATION:
2040 return true;
2041
2042 default:
2043 return false;
2044 }
2045}
2046
2047static bool ValidDebugType(GLenum type)
2048{
2049 switch (type)
2050 {
2051 case GL_DEBUG_TYPE_ERROR:
2052 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
2053 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
2054 case GL_DEBUG_TYPE_PERFORMANCE:
2055 case GL_DEBUG_TYPE_PORTABILITY:
2056 case GL_DEBUG_TYPE_OTHER:
2057 case GL_DEBUG_TYPE_MARKER:
2058 case GL_DEBUG_TYPE_PUSH_GROUP:
2059 case GL_DEBUG_TYPE_POP_GROUP:
2060 return true;
2061
2062 default:
2063 return false;
2064 }
2065}
2066
2067static bool ValidDebugSeverity(GLenum severity)
2068{
2069 switch (severity)
2070 {
2071 case GL_DEBUG_SEVERITY_HIGH:
2072 case GL_DEBUG_SEVERITY_MEDIUM:
2073 case GL_DEBUG_SEVERITY_LOW:
2074 case GL_DEBUG_SEVERITY_NOTIFICATION:
2075 return true;
2076
2077 default:
2078 return false;
2079 }
2080}
2081
Geoff Lange102fee2015-12-10 11:23:30 -05002082bool ValidateDebugMessageControlKHR(Context *context,
2083 GLenum source,
2084 GLenum type,
2085 GLenum severity,
2086 GLsizei count,
2087 const GLuint *ids,
2088 GLboolean enabled)
2089{
2090 if (!context->getExtensions().debug)
2091 {
Jamie Madille0472f32018-11-27 16:32:45 -05002092 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002093 return false;
2094 }
2095
Geoff Lang70d0f492015-12-10 17:45:46 -05002096 if (!ValidDebugSource(source, false) && source != GL_DONT_CARE)
2097 {
Jamie Madille0472f32018-11-27 16:32:45 -05002098 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002099 return false;
2100 }
2101
2102 if (!ValidDebugType(type) && type != GL_DONT_CARE)
2103 {
Jamie Madille0472f32018-11-27 16:32:45 -05002104 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002105 return false;
2106 }
2107
2108 if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE)
2109 {
Jamie Madille0472f32018-11-27 16:32:45 -05002110 context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002111 return false;
2112 }
2113
2114 if (count > 0)
2115 {
2116 if (source == GL_DONT_CARE || type == GL_DONT_CARE)
2117 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002118 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002119 return false;
2120 }
2121
2122 if (severity != GL_DONT_CARE)
2123 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002124 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002125 return false;
2126 }
2127 }
2128
Geoff Lange102fee2015-12-10 11:23:30 -05002129 return true;
2130}
2131
2132bool ValidateDebugMessageInsertKHR(Context *context,
2133 GLenum source,
2134 GLenum type,
2135 GLuint id,
2136 GLenum severity,
2137 GLsizei length,
2138 const GLchar *buf)
2139{
2140 if (!context->getExtensions().debug)
2141 {
Jamie Madille0472f32018-11-27 16:32:45 -05002142 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002143 return false;
2144 }
2145
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002146 if (!context->getState().getDebug().isOutputEnabled())
Geoff Lang70d0f492015-12-10 17:45:46 -05002147 {
2148 // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do
2149 // not generate an error.
2150 return false;
2151 }
2152
2153 if (!ValidDebugSeverity(severity))
2154 {
Jamie Madille0472f32018-11-27 16:32:45 -05002155 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002156 return false;
2157 }
2158
2159 if (!ValidDebugType(type))
2160 {
Jamie Madille0472f32018-11-27 16:32:45 -05002161 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002162 return false;
2163 }
2164
2165 if (!ValidDebugSource(source, true))
2166 {
Jamie Madille0472f32018-11-27 16:32:45 -05002167 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002168 return false;
2169 }
2170
2171 size_t messageLength = (length < 0) ? strlen(buf) : length;
2172 if (messageLength > context->getExtensions().maxDebugMessageLength)
2173 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002174 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002175 return false;
2176 }
2177
Geoff Lange102fee2015-12-10 11:23:30 -05002178 return true;
2179}
2180
2181bool ValidateDebugMessageCallbackKHR(Context *context,
2182 GLDEBUGPROCKHR callback,
2183 const void *userParam)
2184{
2185 if (!context->getExtensions().debug)
2186 {
Jamie Madille0472f32018-11-27 16:32:45 -05002187 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002188 return false;
2189 }
2190
Geoff Lange102fee2015-12-10 11:23:30 -05002191 return true;
2192}
2193
2194bool ValidateGetDebugMessageLogKHR(Context *context,
2195 GLuint count,
2196 GLsizei bufSize,
2197 GLenum *sources,
2198 GLenum *types,
2199 GLuint *ids,
2200 GLenum *severities,
2201 GLsizei *lengths,
2202 GLchar *messageLog)
2203{
2204 if (!context->getExtensions().debug)
2205 {
Jamie Madille0472f32018-11-27 16:32:45 -05002206 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002207 return false;
2208 }
2209
Geoff Lang70d0f492015-12-10 17:45:46 -05002210 if (bufSize < 0 && messageLog != nullptr)
2211 {
Jamie Madille0472f32018-11-27 16:32:45 -05002212 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002213 return false;
2214 }
2215
Geoff Lange102fee2015-12-10 11:23:30 -05002216 return true;
2217}
2218
2219bool ValidatePushDebugGroupKHR(Context *context,
2220 GLenum source,
2221 GLuint id,
2222 GLsizei length,
2223 const GLchar *message)
2224{
2225 if (!context->getExtensions().debug)
2226 {
Jamie Madille0472f32018-11-27 16:32:45 -05002227 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002228 return false;
2229 }
2230
Geoff Lang70d0f492015-12-10 17:45:46 -05002231 if (!ValidDebugSource(source, true))
2232 {
Jamie Madille0472f32018-11-27 16:32:45 -05002233 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002234 return false;
2235 }
2236
2237 size_t messageLength = (length < 0) ? strlen(message) : length;
2238 if (messageLength > context->getExtensions().maxDebugMessageLength)
2239 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002240 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002241 return false;
2242 }
2243
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002244 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002245 if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth)
2246 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002247 context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth);
Geoff Lang70d0f492015-12-10 17:45:46 -05002248 return false;
2249 }
2250
Geoff Lange102fee2015-12-10 11:23:30 -05002251 return true;
2252}
2253
2254bool ValidatePopDebugGroupKHR(Context *context)
2255{
2256 if (!context->getExtensions().debug)
2257 {
Jamie Madille0472f32018-11-27 16:32:45 -05002258 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002259 return false;
2260 }
2261
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002262 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002263 if (currentStackSize <= 1)
2264 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002265 context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup);
Geoff Lang70d0f492015-12-10 17:45:46 -05002266 return false;
2267 }
2268
2269 return true;
2270}
2271
2272static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name)
2273{
2274 switch (identifier)
2275 {
2276 case GL_BUFFER:
2277 if (context->getBuffer(name) == nullptr)
2278 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002279 context->validationError(GL_INVALID_VALUE, kInvalidBufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002280 return false;
2281 }
2282 return true;
2283
2284 case GL_SHADER:
2285 if (context->getShader(name) == nullptr)
2286 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002287 context->validationError(GL_INVALID_VALUE, kInvalidShaderName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002288 return false;
2289 }
2290 return true;
2291
2292 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002293 if (context->getProgramNoResolveLink(name) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002294 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002295 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002296 return false;
2297 }
2298 return true;
2299
2300 case GL_VERTEX_ARRAY:
2301 if (context->getVertexArray(name) == nullptr)
2302 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002303 context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002304 return false;
2305 }
2306 return true;
2307
2308 case GL_QUERY:
2309 if (context->getQuery(name) == nullptr)
2310 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002311 context->validationError(GL_INVALID_VALUE, kInvalidQueryName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002312 return false;
2313 }
2314 return true;
2315
2316 case GL_TRANSFORM_FEEDBACK:
2317 if (context->getTransformFeedback(name) == nullptr)
2318 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002319 context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002320 return false;
2321 }
2322 return true;
2323
2324 case GL_SAMPLER:
2325 if (context->getSampler(name) == nullptr)
2326 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002327 context->validationError(GL_INVALID_VALUE, kInvalidSamplerName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002328 return false;
2329 }
2330 return true;
2331
2332 case GL_TEXTURE:
2333 if (context->getTexture(name) == nullptr)
2334 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002335 context->validationError(GL_INVALID_VALUE, kInvalidTextureName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002336 return false;
2337 }
2338 return true;
2339
2340 case GL_RENDERBUFFER:
2341 if (context->getRenderbuffer(name) == nullptr)
2342 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002343 context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002344 return false;
2345 }
2346 return true;
2347
2348 case GL_FRAMEBUFFER:
2349 if (context->getFramebuffer(name) == nullptr)
2350 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002351 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002352 return false;
2353 }
2354 return true;
2355
2356 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05002357 context->validationError(GL_INVALID_ENUM, kInvalidIndentifier);
Geoff Lang70d0f492015-12-10 17:45:46 -05002358 return false;
2359 }
Geoff Lange102fee2015-12-10 11:23:30 -05002360}
2361
Martin Radev9d901792016-07-15 15:58:58 +03002362static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label)
2363{
2364 size_t labelLength = 0;
2365
2366 if (length < 0)
2367 {
2368 if (label != nullptr)
2369 {
2370 labelLength = strlen(label);
2371 }
2372 }
2373 else
2374 {
2375 labelLength = static_cast<size_t>(length);
2376 }
2377
2378 if (labelLength > context->getExtensions().maxLabelLength)
2379 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002380 context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength);
Martin Radev9d901792016-07-15 15:58:58 +03002381 return false;
2382 }
2383
2384 return true;
2385}
2386
Geoff Lange102fee2015-12-10 11:23:30 -05002387bool ValidateObjectLabelKHR(Context *context,
2388 GLenum identifier,
2389 GLuint name,
2390 GLsizei length,
2391 const GLchar *label)
2392{
2393 if (!context->getExtensions().debug)
2394 {
Jamie Madille0472f32018-11-27 16:32:45 -05002395 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002396 return false;
2397 }
2398
Geoff Lang70d0f492015-12-10 17:45:46 -05002399 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2400 {
2401 return false;
2402 }
2403
Martin Radev9d901792016-07-15 15:58:58 +03002404 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002405 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002406 return false;
2407 }
2408
Geoff Lange102fee2015-12-10 11:23:30 -05002409 return true;
2410}
2411
2412bool ValidateGetObjectLabelKHR(Context *context,
2413 GLenum identifier,
2414 GLuint name,
2415 GLsizei bufSize,
2416 GLsizei *length,
2417 GLchar *label)
2418{
2419 if (!context->getExtensions().debug)
2420 {
Jamie Madille0472f32018-11-27 16:32:45 -05002421 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002422 return false;
2423 }
2424
Geoff Lang70d0f492015-12-10 17:45:46 -05002425 if (bufSize < 0)
2426 {
Jamie Madille0472f32018-11-27 16:32:45 -05002427 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002428 return false;
2429 }
2430
2431 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2432 {
2433 return false;
2434 }
2435
Martin Radev9d901792016-07-15 15:58:58 +03002436 return true;
Geoff Lang70d0f492015-12-10 17:45:46 -05002437}
2438
2439static bool ValidateObjectPtrName(Context *context, const void *ptr)
2440{
Jamie Madill70b5bb02017-08-28 13:32:37 -04002441 if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002442 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002443 context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer);
Geoff Lang70d0f492015-12-10 17:45:46 -05002444 return false;
2445 }
2446
Geoff Lange102fee2015-12-10 11:23:30 -05002447 return true;
2448}
2449
2450bool ValidateObjectPtrLabelKHR(Context *context,
2451 const void *ptr,
2452 GLsizei length,
2453 const GLchar *label)
2454{
2455 if (!context->getExtensions().debug)
2456 {
Jamie Madille0472f32018-11-27 16:32:45 -05002457 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002458 return false;
2459 }
2460
Geoff Lang70d0f492015-12-10 17:45:46 -05002461 if (!ValidateObjectPtrName(context, ptr))
2462 {
2463 return false;
2464 }
2465
Martin Radev9d901792016-07-15 15:58:58 +03002466 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002467 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002468 return false;
2469 }
2470
Geoff Lange102fee2015-12-10 11:23:30 -05002471 return true;
2472}
2473
2474bool ValidateGetObjectPtrLabelKHR(Context *context,
2475 const void *ptr,
2476 GLsizei bufSize,
2477 GLsizei *length,
2478 GLchar *label)
2479{
2480 if (!context->getExtensions().debug)
2481 {
Jamie Madille0472f32018-11-27 16:32:45 -05002482 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002483 return false;
2484 }
2485
Geoff Lang70d0f492015-12-10 17:45:46 -05002486 if (bufSize < 0)
2487 {
Jamie Madille0472f32018-11-27 16:32:45 -05002488 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002489 return false;
2490 }
2491
2492 if (!ValidateObjectPtrName(context, ptr))
2493 {
2494 return false;
2495 }
2496
Martin Radev9d901792016-07-15 15:58:58 +03002497 return true;
Geoff Lange102fee2015-12-10 11:23:30 -05002498}
2499
2500bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params)
2501{
2502 if (!context->getExtensions().debug)
2503 {
Jamie Madille0472f32018-11-27 16:32:45 -05002504 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002505 return false;
2506 }
2507
Geoff Lang70d0f492015-12-10 17:45:46 -05002508 // TODO: represent this in Context::getQueryParameterInfo.
2509 switch (pname)
2510 {
2511 case GL_DEBUG_CALLBACK_FUNCTION:
2512 case GL_DEBUG_CALLBACK_USER_PARAM:
2513 break;
2514
2515 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002516 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang70d0f492015-12-10 17:45:46 -05002517 return false;
2518 }
2519
Geoff Lange102fee2015-12-10 11:23:30 -05002520 return true;
2521}
Jamie Madillc29968b2016-01-20 11:17:23 -05002522
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002523bool ValidateGetPointervRobustANGLERobustANGLE(Context *context,
2524 GLenum pname,
2525 GLsizei bufSize,
2526 GLsizei *length,
2527 void **params)
2528{
2529 UNIMPLEMENTED();
2530 return false;
2531}
2532
Jamie Madillc29968b2016-01-20 11:17:23 -05002533bool ValidateBlitFramebufferANGLE(Context *context,
2534 GLint srcX0,
2535 GLint srcY0,
2536 GLint srcX1,
2537 GLint srcY1,
2538 GLint dstX0,
2539 GLint dstY0,
2540 GLint dstX1,
2541 GLint dstY1,
2542 GLbitfield mask,
2543 GLenum filter)
2544{
2545 if (!context->getExtensions().framebufferBlit)
2546 {
Jamie Madille0472f32018-11-27 16:32:45 -05002547 context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable);
Jamie Madillc29968b2016-01-20 11:17:23 -05002548 return false;
2549 }
2550
2551 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
2552 {
2553 // TODO(jmadill): Determine if this should be available on other implementations.
Jamie Madille0472f32018-11-27 16:32:45 -05002554 context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip);
Jamie Madillc29968b2016-01-20 11:17:23 -05002555 return false;
2556 }
2557
2558 if (filter == GL_LINEAR)
2559 {
Jamie Madille0472f32018-11-27 16:32:45 -05002560 context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear);
Jamie Madillc29968b2016-01-20 11:17:23 -05002561 return false;
2562 }
2563
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002564 Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
2565 Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002566
2567 if (mask & GL_COLOR_BUFFER_BIT)
2568 {
2569 const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer();
2570 const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer();
2571
2572 if (readColorAttachment && drawColorAttachment)
2573 {
2574 if (!(readColorAttachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002575 readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002576 readColorAttachment->type() != GL_RENDERBUFFER &&
2577 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2578 {
Jamie Madill610640f2018-11-21 17:28:41 -05002579 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002580 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002581 return false;
2582 }
2583
Geoff Langa15472a2015-08-11 11:48:03 -04002584 for (size_t drawbufferIdx = 0;
2585 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002586 {
Geoff Langa15472a2015-08-11 11:48:03 -04002587 const FramebufferAttachment *attachment =
2588 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2589 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002590 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002591 if (!(attachment->type() == GL_TEXTURE &&
Jamie Madillcc129372018-04-12 09:13:18 -04002592 attachment->getTextureImageIndex().getType() == TextureType::_2D) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002593 attachment->type() != GL_RENDERBUFFER &&
2594 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2595 {
Jamie Madill610640f2018-11-21 17:28:41 -05002596 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002597 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002598 return false;
2599 }
2600
2601 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002602 if (!Format::EquivalentForBlit(attachment->getFormat(),
2603 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002604 {
Jamie Madill610640f2018-11-21 17:28:41 -05002605 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002606 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002607 return false;
2608 }
2609 }
2610 }
2611
Jamie Madill427064d2018-04-13 16:20:34 -04002612 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002613 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002614 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2615 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2616 {
Jamie Madill610640f2018-11-21 17:28:41 -05002617 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002618 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002619 return false;
2620 }
2621 }
2622 }
2623
2624 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2625 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2626 for (size_t i = 0; i < 2; i++)
2627 {
2628 if (mask & masks[i])
2629 {
2630 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002631 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002632 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002633 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002634
2635 if (readBuffer && drawBuffer)
2636 {
2637 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2638 dstX0, dstY0, dstX1, dstY1))
2639 {
2640 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002641 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002642 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002643 return false;
2644 }
2645
2646 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2647 {
Jamie Madill610640f2018-11-21 17:28:41 -05002648 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002649 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002650 return false;
2651 }
2652 }
2653 }
2654 }
2655
2656 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2657 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002658}
Jamie Madillc29968b2016-01-20 11:17:23 -05002659
Jamie Madill5b772312018-03-08 20:28:32 -05002660bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002661{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002662 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002663 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002664
Jamie Madill427064d2018-04-13 16:20:34 -04002665 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002666 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002667 return false;
2668 }
2669
2670 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2671 {
Jamie Madille0472f32018-11-27 16:32:45 -05002672 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002673 return false;
2674 }
2675
Olli Etuaho94c91a92018-07-19 15:10:24 +03002676 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002677 {
2678 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2679 GL_SIGNED_NORMALIZED};
2680
Corentin Wallez59c41592017-07-11 13:19:54 -04002681 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002682 drawBufferIdx++)
2683 {
2684 if (!ValidateWebGLFramebufferAttachmentClearType(
2685 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2686 {
2687 return false;
2688 }
2689 }
2690 }
2691
Mingyu Hu7d64c482019-03-12 14:27:40 -07002692 if (extensions.multiview2 && extensions.disjointTimerQuery)
Olli Etuaho94c91a92018-07-19 15:10:24 +03002693 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002694 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002695 Framebuffer *framebuffer = state.getDrawFramebuffer();
2696 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2697 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002698 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002699 return false;
2700 }
2701 }
2702
Jamie Madillc29968b2016-01-20 11:17:23 -05002703 return true;
2704}
2705
Jamie Madill5b772312018-03-08 20:28:32 -05002706bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002707{
2708 if (!context->getExtensions().drawBuffers)
2709 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002710 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002711 return false;
2712 }
2713
2714 return ValidateDrawBuffersBase(context, n, bufs);
2715}
2716
Jamie Madill73a84962016-02-12 09:27:23 -05002717bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002718 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002719 GLint level,
2720 GLint internalformat,
2721 GLsizei width,
2722 GLsizei height,
2723 GLint border,
2724 GLenum format,
2725 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002726 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002727{
Martin Radev1be913c2016-07-11 17:59:16 +03002728 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002729 {
2730 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002731 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002732 }
2733
Martin Radev1be913c2016-07-11 17:59:16 +03002734 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002735 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002736 0, 0, width, height, 1, border, format, type, -1,
2737 pixels);
2738}
2739
Brandon Jones416aaf92018-04-10 08:10:16 -07002740bool ValidateTexImage2DRobustANGLE(Context *context,
2741 TextureTarget target,
2742 GLint level,
2743 GLint internalformat,
2744 GLsizei width,
2745 GLsizei height,
2746 GLint border,
2747 GLenum format,
2748 GLenum type,
2749 GLsizei bufSize,
2750 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04002751{
2752 if (!ValidateRobustEntryPoint(context, bufSize))
2753 {
2754 return false;
2755 }
2756
2757 if (context->getClientMajorVersion() < 3)
2758 {
2759 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
2760 0, 0, width, height, border, format, type, bufSize,
2761 pixels);
2762 }
2763
2764 ASSERT(context->getClientMajorVersion() >= 3);
2765 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
2766 0, 0, width, height, 1, border, format, type, bufSize,
2767 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002768}
2769
2770bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002771 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002772 GLint level,
2773 GLint xoffset,
2774 GLint yoffset,
2775 GLsizei width,
2776 GLsizei height,
2777 GLenum format,
2778 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002779 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002780{
2781
Martin Radev1be913c2016-07-11 17:59:16 +03002782 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002783 {
2784 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002785 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002786 }
2787
Martin Radev1be913c2016-07-11 17:59:16 +03002788 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002789 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002790 yoffset, 0, width, height, 1, 0, format, type, -1,
2791 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002792}
2793
Geoff Langc52f6f12016-10-14 10:18:00 -04002794bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002795 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04002796 GLint level,
2797 GLint xoffset,
2798 GLint yoffset,
2799 GLsizei width,
2800 GLsizei height,
2801 GLenum format,
2802 GLenum type,
2803 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002804 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04002805{
2806 if (!ValidateRobustEntryPoint(context, bufSize))
2807 {
2808 return false;
2809 }
2810
2811 if (context->getClientMajorVersion() < 3)
2812 {
2813 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
2814 yoffset, width, height, 0, format, type, bufSize,
2815 pixels);
2816 }
2817
2818 ASSERT(context->getClientMajorVersion() >= 3);
2819 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
2820 yoffset, 0, width, height, 1, 0, format, type, bufSize,
2821 pixels);
2822}
2823
Jamie Madill73a84962016-02-12 09:27:23 -05002824bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002825 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002826 GLint level,
2827 GLenum internalformat,
2828 GLsizei width,
2829 GLsizei height,
2830 GLint border,
2831 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002832 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002833{
Martin Radev1be913c2016-07-11 17:59:16 +03002834 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002835 {
2836 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002837 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002838 {
2839 return false;
2840 }
2841 }
2842 else
2843 {
Martin Radev1be913c2016-07-11 17:59:16 +03002844 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002845 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002846 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002847 data))
2848 {
2849 return false;
2850 }
2851 }
2852
Geoff Langca271392017-04-05 12:30:00 -04002853 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04002854
2855 GLuint blockSize = 0;
2856 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002857 {
Jamie Madille0472f32018-11-27 16:32:45 -05002858 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002859 return false;
2860 }
2861
Jamie Madillca2ff382018-07-11 09:01:17 -04002862 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002863 {
Jamie Madille0472f32018-11-27 16:32:45 -05002864 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05002865 return false;
2866 }
2867
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002868 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002869 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002870 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002871 return false;
2872 }
2873
Jamie Madill73a84962016-02-12 09:27:23 -05002874 return true;
2875}
2876
Corentin Wallezb2931602017-04-11 15:58:57 -04002877bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002878 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002879 GLint level,
2880 GLenum internalformat,
2881 GLsizei width,
2882 GLsizei height,
2883 GLint border,
2884 GLsizei imageSize,
2885 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002886 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002887{
2888 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2889 {
2890 return false;
2891 }
2892
2893 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
2894 border, imageSize, data);
2895}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002896
Corentin Wallezb2931602017-04-11 15:58:57 -04002897bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002898 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04002899 GLint level,
2900 GLint xoffset,
2901 GLint yoffset,
2902 GLsizei width,
2903 GLsizei height,
2904 GLenum format,
2905 GLsizei imageSize,
2906 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002907 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04002908{
2909 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
2910 {
2911 return false;
2912 }
2913
2914 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
2915 format, imageSize, data);
2916}
2917
Jamie Madill73a84962016-02-12 09:27:23 -05002918bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002919 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002920 GLint level,
2921 GLint xoffset,
2922 GLint yoffset,
2923 GLsizei width,
2924 GLsizei height,
2925 GLenum format,
2926 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002927 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002928{
Martin Radev1be913c2016-07-11 17:59:16 +03002929 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002930 {
2931 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04002932 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002933 {
2934 return false;
2935 }
2936 }
2937 else
2938 {
Martin Radev1be913c2016-07-11 17:59:16 +03002939 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002940 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04002941 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05002942 data))
2943 {
2944 return false;
2945 }
2946 }
2947
Geoff Langca271392017-04-05 12:30:00 -04002948 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04002949 GLuint blockSize = 0;
2950 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04002951 {
Jamie Madille0472f32018-11-27 16:32:45 -05002952 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04002953 return false;
2954 }
2955
Jamie Madillca2ff382018-07-11 09:01:17 -04002956 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05002957 {
Jamie Madille0472f32018-11-27 16:32:45 -05002958 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05002959 return false;
2960 }
2961
2962 return true;
2963}
2964
Corentin Wallez336129f2017-10-17 15:55:40 -04002965bool ValidateGetBufferPointervOES(Context *context,
2966 BufferBinding target,
2967 GLenum pname,
2968 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03002969{
Jamie Madillc3e37312018-11-30 15:25:39 -05002970 if (!context->getExtensions().mapBuffer)
2971 {
2972 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
2973 return false;
2974 }
2975
Geoff Lang496c02d2016-10-20 11:38:11 -07002976 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03002977}
2978
Corentin Wallez336129f2017-10-17 15:55:40 -04002979bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03002980{
2981 if (!context->getExtensions().mapBuffer)
2982 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002983 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03002984 return false;
2985 }
2986
Corentin Walleze4477002017-12-01 14:39:58 -05002987 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03002988 {
Jamie Madille0472f32018-11-27 16:32:45 -05002989 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03002990 return false;
2991 }
2992
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002993 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03002994
2995 if (buffer == nullptr)
2996 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002997 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03002998 return false;
2999 }
3000
3001 if (access != GL_WRITE_ONLY_OES)
3002 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003003 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03003004 return false;
3005 }
3006
3007 if (buffer->isMapped())
3008 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003009 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003010 return false;
3011 }
3012
Geoff Lang79f71042017-08-14 16:43:43 -04003013 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003014}
3015
Corentin Wallez336129f2017-10-17 15:55:40 -04003016bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003017{
3018 if (!context->getExtensions().mapBuffer)
3019 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003020 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003021 return false;
3022 }
3023
3024 return ValidateUnmapBufferBase(context, target);
3025}
3026
3027bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003028 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003029 GLintptr offset,
3030 GLsizeiptr length,
3031 GLbitfield access)
3032{
3033 if (!context->getExtensions().mapBufferRange)
3034 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003035 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003036 return false;
3037 }
3038
3039 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3040}
3041
Michael Spang7a8c3e52019-04-03 14:49:57 -04003042bool ValidateBufferStorageMemEXT(Context *context,
3043 TextureType target,
3044 GLsizeiptr size,
3045 GLuint memory,
3046 GLuint64 offset)
3047{
3048 if (!context->getExtensions().memoryObject)
3049 {
3050 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3051 return false;
3052 }
3053
3054 UNIMPLEMENTED();
3055 return false;
3056}
3057
3058bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects)
3059{
3060 if (!context->getExtensions().memoryObject)
3061 {
3062 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3063 return false;
3064 }
3065
Michael Spangfb201c52019-04-03 14:57:35 -04003066 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003067}
3068
3069bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects)
3070{
3071 if (!context->getExtensions().memoryObject)
3072 {
3073 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3074 return false;
3075 }
3076
Michael Spangfb201c52019-04-03 14:57:35 -04003077 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003078}
3079
3080bool ValidateGetMemoryObjectParameterivEXT(Context *context,
3081 GLuint memoryObject,
3082 GLenum pname,
3083 GLint *params)
3084{
3085 if (!context->getExtensions().memoryObject)
3086 {
3087 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3088 return false;
3089 }
3090
3091 UNIMPLEMENTED();
3092 return false;
3093}
3094
3095bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3096{
3097 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3098 {
3099 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3100 return false;
3101 }
3102
3103 UNIMPLEMENTED();
3104 return false;
3105}
3106
3107bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3108{
3109 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3110 {
3111 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3112 return false;
3113 }
3114
3115 UNIMPLEMENTED();
3116 return false;
3117}
3118
3119bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject)
3120{
3121 if (!context->getExtensions().memoryObject)
3122 {
3123 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3124 return false;
3125 }
3126
Michael Spangfb201c52019-04-03 14:57:35 -04003127 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003128}
3129
3130bool ValidateMemoryObjectParameterivEXT(Context *context,
3131 GLuint memoryObject,
3132 GLenum pname,
3133 const GLint *params)
3134{
3135 if (!context->getExtensions().memoryObject)
3136 {
3137 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3138 return false;
3139 }
3140
3141 UNIMPLEMENTED();
3142 return false;
3143}
3144
3145bool ValidateTexStorageMem2DEXT(Context *context,
3146 TextureType target,
3147 GLsizei levels,
3148 GLenum internalFormat,
3149 GLsizei width,
3150 GLsizei height,
3151 GLuint memory,
3152 GLuint64 offset)
3153{
3154 if (!context->getExtensions().memoryObject)
3155 {
3156 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3157 return false;
3158 }
3159
3160 UNIMPLEMENTED();
3161 return false;
3162}
3163
3164bool ValidateTexStorageMem3DEXT(Context *context,
3165 TextureType target,
3166 GLsizei levels,
3167 GLenum internalFormat,
3168 GLsizei width,
3169 GLsizei height,
3170 GLsizei depth,
3171 GLuint memory,
3172 GLuint64 offset)
3173{
3174 if (!context->getExtensions().memoryObject)
3175 {
3176 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3177 return false;
3178 }
3179
3180 UNIMPLEMENTED();
3181 return false;
3182}
3183
Michael Spang9de3ddb2019-04-03 16:23:40 -04003184bool ValidateImportMemoryFdEXT(Context *context,
3185 GLuint memory,
3186 GLuint64 size,
Michael Spange0da9ce2019-04-16 14:34:51 -04003187 HandleType handleType,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003188 GLint fd)
3189{
3190 if (!context->getExtensions().memoryObjectFd)
3191 {
3192 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3193 return false;
3194 }
3195
Michael Spang3b2c6bf2019-04-16 17:19:50 -04003196 switch (handleType)
3197 {
3198 case HandleType::OpaqueFd:
3199 break;
3200 default:
3201 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3202 return false;
3203 }
3204
3205 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003206}
3207
Michael Spang7a8c3e52019-04-03 14:49:57 -04003208bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores)
3209{
3210 if (!context->getExtensions().semaphore)
3211 {
3212 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3213 return false;
3214 }
3215
3216 UNIMPLEMENTED();
3217 return false;
3218}
3219
3220bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores)
3221{
3222 if (!context->getExtensions().semaphore)
3223 {
3224 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3225 return false;
3226 }
3227
3228 UNIMPLEMENTED();
3229 return false;
3230}
3231
3232bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
3233 GLuint semaphore,
3234 GLenum pname,
3235 GLuint64 *params)
3236{
3237 if (!context->getExtensions().semaphore)
3238 {
3239 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3240 return false;
3241 }
3242
3243 UNIMPLEMENTED();
3244 return false;
3245}
3246
3247bool ValidateIsSemaphoreEXT(Context *context, GLuint semaphore)
3248{
3249 if (!context->getExtensions().semaphore)
3250 {
3251 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3252 return false;
3253 }
3254
3255 UNIMPLEMENTED();
3256 return false;
3257}
3258
3259bool ValidateSemaphoreParameterui64vEXT(Context *context,
3260 GLuint semaphore,
3261 GLenum pname,
3262 const GLuint64 *params)
3263{
3264 if (!context->getExtensions().semaphore)
3265 {
3266 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3267 return false;
3268 }
3269
3270 UNIMPLEMENTED();
3271 return false;
3272}
3273
3274bool ValidateSignalSemaphoreEXT(Context *context,
3275 GLuint semaphore,
3276 GLuint numBufferBarriers,
3277 const GLuint *buffers,
3278 GLuint numTextureBarriers,
3279 const GLuint *textures,
3280 const GLenum *dstLayouts)
3281{
3282 if (!context->getExtensions().semaphore)
3283 {
3284 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3285 return false;
3286 }
3287
3288 UNIMPLEMENTED();
3289 return false;
3290}
3291
3292bool ValidateWaitSemaphoreEXT(Context *context,
3293 GLuint semaphore,
3294 GLuint numBufferBarriers,
3295 const GLuint *buffers,
3296 GLuint numTextureBarriers,
3297 const GLuint *textures,
3298 const GLenum *srcLayouts)
3299{
3300 if (!context->getExtensions().semaphore)
3301 {
3302 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3303 return false;
3304 }
3305
3306 UNIMPLEMENTED();
3307 return false;
3308}
3309
Michael Spange0da9ce2019-04-16 14:34:51 -04003310bool ValidateImportSemaphoreFdEXT(Context *context,
3311 GLuint semaphore,
3312 HandleType handleType,
3313 GLint fd)
Michael Spang9de3ddb2019-04-03 16:23:40 -04003314{
3315 if (!context->getExtensions().semaphoreFd)
3316 {
3317 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3318 return false;
3319 }
3320
3321 UNIMPLEMENTED();
3322 return false;
3323}
3324
Corentin Wallez336129f2017-10-17 15:55:40 -04003325bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003326{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003327 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003328 ASSERT(buffer != nullptr);
3329
3330 // Check if this buffer is currently being used as a transform feedback output buffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003331 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003332 if (transformFeedback != nullptr && transformFeedback->isActive())
3333 {
3334 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3335 {
3336 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3337 if (transformFeedbackBuffer.get() == buffer)
3338 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003339 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003340 return false;
3341 }
3342 }
3343 }
3344
James Darpiniane8a93c62018-01-04 18:02:24 -08003345 if (context->getExtensions().webglCompatibility &&
3346 buffer->isBoundForTransformFeedbackAndOtherUse())
3347 {
Jamie Madille0472f32018-11-27 16:32:45 -05003348 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003349 return false;
3350 }
3351
Geoff Lang79f71042017-08-14 16:43:43 -04003352 return true;
3353}
3354
Olli Etuaho4f667482016-03-30 15:56:35 +03003355bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003356 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003357 GLintptr offset,
3358 GLsizeiptr length)
3359{
3360 if (!context->getExtensions().mapBufferRange)
3361 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003362 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003363 return false;
3364 }
3365
3366 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3367}
3368
Geoff Langd8605522016-04-13 10:19:12 -04003369bool ValidateBindUniformLocationCHROMIUM(Context *context,
3370 GLuint program,
3371 GLint location,
3372 const GLchar *name)
3373{
3374 if (!context->getExtensions().bindUniformLocation)
3375 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003376 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003377 return false;
3378 }
3379
3380 Program *programObject = GetValidProgram(context, program);
3381 if (!programObject)
3382 {
3383 return false;
3384 }
3385
3386 if (location < 0)
3387 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003388 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003389 return false;
3390 }
3391
3392 const Caps &caps = context->getCaps();
3393 if (static_cast<size_t>(location) >=
3394 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3395 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003396 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003397 return false;
3398 }
3399
Geoff Langfc32e8b2017-05-31 14:16:59 -04003400 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3401 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003402 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003403 {
Jamie Madille0472f32018-11-27 16:32:45 -05003404 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003405 return false;
3406 }
3407
Geoff Langd8605522016-04-13 10:19:12 -04003408 if (strncmp(name, "gl_", 3) == 0)
3409 {
Jamie Madille0472f32018-11-27 16:32:45 -05003410 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003411 return false;
3412 }
3413
3414 return true;
3415}
3416
Jamie Madille2e406c2016-06-02 13:04:10 -04003417bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003418{
3419 if (!context->getExtensions().framebufferMixedSamples)
3420 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003421 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003422 return false;
3423 }
3424 switch (components)
3425 {
3426 case GL_RGB:
3427 case GL_RGBA:
3428 case GL_ALPHA:
3429 case GL_NONE:
3430 break;
3431 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003432 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003433 return false;
3434 }
3435
3436 return true;
3437}
3438
Sami Väisänene45e53b2016-05-25 10:36:04 +03003439// CHROMIUM_path_rendering
3440
Jamie Madill007530e2017-12-28 14:27:04 -05003441bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003442{
Jamie Madill007530e2017-12-28 14:27:04 -05003443 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003444 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003445 return false;
3446 }
Jamie Madill007530e2017-12-28 14:27:04 -05003447
Sami Väisänene45e53b2016-05-25 10:36:04 +03003448 if (matrix == nullptr)
3449 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003450 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003451 return false;
3452 }
Jamie Madill007530e2017-12-28 14:27:04 -05003453
Sami Väisänene45e53b2016-05-25 10:36:04 +03003454 return true;
3455}
3456
Jamie Madill007530e2017-12-28 14:27:04 -05003457bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003458{
Jamie Madill007530e2017-12-28 14:27:04 -05003459 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003460}
3461
Jamie Madill007530e2017-12-28 14:27:04 -05003462bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003463{
3464 if (!context->getExtensions().pathRendering)
3465 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003466 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003467 return false;
3468 }
3469
3470 // range = 0 is undefined in NV_path_rendering.
3471 // we add stricter semantic check here and require a non zero positive range.
3472 if (range <= 0)
3473 {
Jamie Madille0472f32018-11-27 16:32:45 -05003474 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003475 return false;
3476 }
3477
3478 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3479 {
Jamie Madille0472f32018-11-27 16:32:45 -05003480 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003481 return false;
3482 }
3483
3484 return true;
3485}
3486
Jamie Madill007530e2017-12-28 14:27:04 -05003487bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003488{
3489 if (!context->getExtensions().pathRendering)
3490 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003491 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003492 return false;
3493 }
3494
3495 // range = 0 is undefined in NV_path_rendering.
3496 // we add stricter semantic check here and require a non zero positive range.
3497 if (range <= 0)
3498 {
Jamie Madille0472f32018-11-27 16:32:45 -05003499 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003500 return false;
3501 }
3502
3503 angle::CheckedNumeric<std::uint32_t> checkedRange(path);
3504 checkedRange += range;
3505
3506 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3507 {
Jamie Madille0472f32018-11-27 16:32:45 -05003508 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003509 return false;
3510 }
3511 return true;
3512}
3513
Jamie Madill007530e2017-12-28 14:27:04 -05003514bool ValidatePathCommandsCHROMIUM(Context *context,
3515 GLuint path,
3516 GLsizei numCommands,
3517 const GLubyte *commands,
3518 GLsizei numCoords,
3519 GLenum coordType,
3520 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003521{
3522 if (!context->getExtensions().pathRendering)
3523 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003524 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003525 return false;
3526 }
Brandon Jones59770802018-04-02 13:18:42 -07003527 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003528 {
Jamie Madille0472f32018-11-27 16:32:45 -05003529 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003530 return false;
3531 }
3532
3533 if (numCommands < 0)
3534 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003535 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003536 return false;
3537 }
3538 else if (numCommands > 0)
3539 {
3540 if (!commands)
3541 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003542 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003543 return false;
3544 }
3545 }
3546
3547 if (numCoords < 0)
3548 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003549 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003550 return false;
3551 }
3552 else if (numCoords > 0)
3553 {
3554 if (!coords)
3555 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003556 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003557 return false;
3558 }
3559 }
3560
3561 std::uint32_t coordTypeSize = 0;
3562 switch (coordType)
3563 {
3564 case GL_BYTE:
3565 coordTypeSize = sizeof(GLbyte);
3566 break;
3567
3568 case GL_UNSIGNED_BYTE:
3569 coordTypeSize = sizeof(GLubyte);
3570 break;
3571
3572 case GL_SHORT:
3573 coordTypeSize = sizeof(GLshort);
3574 break;
3575
3576 case GL_UNSIGNED_SHORT:
3577 coordTypeSize = sizeof(GLushort);
3578 break;
3579
3580 case GL_FLOAT:
3581 coordTypeSize = sizeof(GLfloat);
3582 break;
3583
3584 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003585 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003586 return false;
3587 }
3588
3589 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3590 checkedSize += (coordTypeSize * numCoords);
3591 if (!checkedSize.IsValid())
3592 {
Jamie Madille0472f32018-11-27 16:32:45 -05003593 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003594 return false;
3595 }
3596
3597 // early return skips command data validation when it doesn't exist.
3598 if (!commands)
3599 return true;
3600
3601 GLsizei expectedNumCoords = 0;
3602 for (GLsizei i = 0; i < numCommands; ++i)
3603 {
3604 switch (commands[i])
3605 {
3606 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3607 break;
3608 case GL_MOVE_TO_CHROMIUM:
3609 case GL_LINE_TO_CHROMIUM:
3610 expectedNumCoords += 2;
3611 break;
3612 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3613 expectedNumCoords += 4;
3614 break;
3615 case GL_CUBIC_CURVE_TO_CHROMIUM:
3616 expectedNumCoords += 6;
3617 break;
3618 case GL_CONIC_CURVE_TO_CHROMIUM:
3619 expectedNumCoords += 5;
3620 break;
3621 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003622 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003623 return false;
3624 }
3625 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003626
Sami Väisänene45e53b2016-05-25 10:36:04 +03003627 if (expectedNumCoords != numCoords)
3628 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003629 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003630 return false;
3631 }
3632
3633 return true;
3634}
3635
Jamie Madill007530e2017-12-28 14:27:04 -05003636bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003637{
3638 if (!context->getExtensions().pathRendering)
3639 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003640 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003641 return false;
3642 }
Brandon Jones59770802018-04-02 13:18:42 -07003643 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003644 {
Jamie Madille0472f32018-11-27 16:32:45 -05003645 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003646 return false;
3647 }
3648
3649 switch (pname)
3650 {
3651 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3652 if (value < 0.0f)
3653 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003654 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003655 return false;
3656 }
3657 break;
3658 case GL_PATH_END_CAPS_CHROMIUM:
3659 switch (static_cast<GLenum>(value))
3660 {
3661 case GL_FLAT_CHROMIUM:
3662 case GL_SQUARE_CHROMIUM:
3663 case GL_ROUND_CHROMIUM:
3664 break;
3665 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003666 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003667 return false;
3668 }
3669 break;
3670 case GL_PATH_JOIN_STYLE_CHROMIUM:
3671 switch (static_cast<GLenum>(value))
3672 {
3673 case GL_MITER_REVERT_CHROMIUM:
3674 case GL_BEVEL_CHROMIUM:
3675 case GL_ROUND_CHROMIUM:
3676 break;
3677 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003678 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003679 return false;
3680 }
Nico Weber41b072b2018-02-09 10:01:32 -05003681 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03003682 case GL_PATH_MITER_LIMIT_CHROMIUM:
3683 if (value < 0.0f)
3684 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003685 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003686 return false;
3687 }
3688 break;
3689
3690 case GL_PATH_STROKE_BOUND_CHROMIUM:
3691 // no errors, only clamping.
3692 break;
3693
3694 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003695 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003696 return false;
3697 }
3698 return true;
3699}
3700
Jamie Madill007530e2017-12-28 14:27:04 -05003701bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value)
3702{
3703 // TODO(jmadill): Use proper clamping cast.
3704 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
3705}
3706
3707bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003708{
3709 if (!context->getExtensions().pathRendering)
3710 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003711 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003712 return false;
3713 }
3714
Brandon Jones59770802018-04-02 13:18:42 -07003715 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003716 {
Jamie Madille0472f32018-11-27 16:32:45 -05003717 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003718 return false;
3719 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003720
Sami Väisänene45e53b2016-05-25 10:36:04 +03003721 if (!value)
3722 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003723 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003724 return false;
3725 }
3726
3727 switch (pname)
3728 {
3729 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3730 case GL_PATH_END_CAPS_CHROMIUM:
3731 case GL_PATH_JOIN_STYLE_CHROMIUM:
3732 case GL_PATH_MITER_LIMIT_CHROMIUM:
3733 case GL_PATH_STROKE_BOUND_CHROMIUM:
3734 break;
3735
3736 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003737 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003738 return false;
3739 }
3740
3741 return true;
3742}
3743
Jamie Madill007530e2017-12-28 14:27:04 -05003744bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value)
3745{
3746 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
3747 reinterpret_cast<GLfloat *>(value));
3748}
3749
3750bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003751{
3752 if (!context->getExtensions().pathRendering)
3753 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003754 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003755 return false;
3756 }
3757
3758 switch (func)
3759 {
3760 case GL_NEVER:
3761 case GL_ALWAYS:
3762 case GL_LESS:
3763 case GL_LEQUAL:
3764 case GL_EQUAL:
3765 case GL_GEQUAL:
3766 case GL_GREATER:
3767 case GL_NOTEQUAL:
3768 break;
3769 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003770 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003771 return false;
3772 }
3773
3774 return true;
3775}
3776
3777// Note that the spec specifies that for the path drawing commands
3778// if the path object is not an existing path object the command
3779// does nothing and no error is generated.
3780// However if the path object exists but has not been specified any
3781// commands then an error is generated.
3782
Jamie Madill007530e2017-12-28 14:27:04 -05003783bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003784{
3785 if (!context->getExtensions().pathRendering)
3786 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003787 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003788 return false;
3789 }
Brandon Jones59770802018-04-02 13:18:42 -07003790 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003791 {
Jamie Madille0472f32018-11-27 16:32:45 -05003792 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003793 return false;
3794 }
3795
3796 switch (fillMode)
3797 {
3798 case GL_COUNT_UP_CHROMIUM:
3799 case GL_COUNT_DOWN_CHROMIUM:
3800 break;
3801 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003802 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003803 return false;
3804 }
3805
3806 if (!isPow2(mask + 1))
3807 {
Jamie Madille0472f32018-11-27 16:32:45 -05003808 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003809 return false;
3810 }
3811
3812 return true;
3813}
3814
Jamie Madill007530e2017-12-28 14:27:04 -05003815bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003816{
3817 if (!context->getExtensions().pathRendering)
3818 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003819 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003820 return false;
3821 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003822
Brandon Jones59770802018-04-02 13:18:42 -07003823 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003824 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003825 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003826 return false;
3827 }
3828
3829 return true;
3830}
3831
Jamie Madill007530e2017-12-28 14:27:04 -05003832bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003833{
3834 if (!context->getExtensions().pathRendering)
3835 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003836 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003837 return false;
3838 }
Brandon Jones59770802018-04-02 13:18:42 -07003839 if (context->isPathGenerated(path) && !context->isPath(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 }
3844
3845 switch (coverMode)
3846 {
3847 case GL_CONVEX_HULL_CHROMIUM:
3848 case GL_BOUNDING_BOX_CHROMIUM:
3849 break;
3850 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003851 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003852 return false;
3853 }
3854 return true;
3855}
3856
Jamie Madill778bf092018-11-14 09:54:36 -05003857bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3858{
3859 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3860}
3861
3862bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode)
3863{
3864 return ValidateCoverPathCHROMIUM(context, path, coverMode);
3865}
3866
Jamie Madill007530e2017-12-28 14:27:04 -05003867bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
3868 GLuint path,
3869 GLenum fillMode,
3870 GLuint mask,
3871 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003872{
Jamie Madill007530e2017-12-28 14:27:04 -05003873 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
3874 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003875}
3876
Jamie Madill007530e2017-12-28 14:27:04 -05003877bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
3878 GLuint path,
3879 GLint reference,
3880 GLuint mask,
3881 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003882{
Jamie Madill007530e2017-12-28 14:27:04 -05003883 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
3884 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003885}
3886
Brandon Jonesd1049182018-03-28 10:02:20 -07003887bool ValidateIsPathCHROMIUM(Context *context, GLuint path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003888{
3889 if (!context->getExtensions().pathRendering)
3890 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003891 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003892 return false;
3893 }
3894 return true;
3895}
3896
Jamie Madill007530e2017-12-28 14:27:04 -05003897bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
3898 GLsizei numPaths,
3899 GLenum pathNameType,
3900 const void *paths,
3901 GLuint pathBase,
3902 GLenum coverMode,
3903 GLenum transformType,
3904 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003905{
3906 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3907 transformType, transformValues))
3908 return false;
3909
3910 switch (coverMode)
3911 {
3912 case GL_CONVEX_HULL_CHROMIUM:
3913 case GL_BOUNDING_BOX_CHROMIUM:
3914 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
3915 break;
3916 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003917 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03003918 return false;
3919 }
3920
3921 return true;
3922}
3923
Jamie Madill007530e2017-12-28 14:27:04 -05003924bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
3925 GLsizei numPaths,
3926 GLenum pathNameType,
3927 const void *paths,
3928 GLuint pathBase,
3929 GLenum coverMode,
3930 GLenum transformType,
3931 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003932{
3933 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3934 transformType, transformValues))
3935 return false;
3936
3937 switch (coverMode)
3938 {
3939 case GL_CONVEX_HULL_CHROMIUM:
3940 case GL_BOUNDING_BOX_CHROMIUM:
3941 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
3942 break;
3943 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003944 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03003945 return false;
3946 }
3947
3948 return true;
3949}
3950
Jamie Madill007530e2017-12-28 14:27:04 -05003951bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
3952 GLsizei numPaths,
3953 GLenum pathNameType,
3954 const void *paths,
3955 GLuint pathBase,
3956 GLenum fillMode,
3957 GLuint mask,
3958 GLenum transformType,
3959 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003960{
3961
3962 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3963 transformType, transformValues))
3964 return false;
3965
3966 switch (fillMode)
3967 {
3968 case GL_COUNT_UP_CHROMIUM:
3969 case GL_COUNT_DOWN_CHROMIUM:
3970 break;
3971 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003972 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03003973 return false;
3974 }
3975 if (!isPow2(mask + 1))
3976 {
Jamie Madille0472f32018-11-27 16:32:45 -05003977 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03003978 return false;
3979 }
3980 return true;
3981}
3982
Jamie Madill007530e2017-12-28 14:27:04 -05003983bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
3984 GLsizei numPaths,
3985 GLenum pathNameType,
3986 const void *paths,
3987 GLuint pathBase,
3988 GLint reference,
3989 GLuint mask,
3990 GLenum transformType,
3991 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03003992{
3993 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
3994 transformType, transformValues))
3995 return false;
3996
3997 // no more validation here.
3998
3999 return true;
4000}
4001
Jamie Madill007530e2017-12-28 14:27:04 -05004002bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
4003 GLsizei numPaths,
4004 GLenum pathNameType,
4005 const void *paths,
4006 GLuint pathBase,
4007 GLenum fillMode,
4008 GLuint mask,
4009 GLenum coverMode,
4010 GLenum transformType,
4011 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004012{
4013 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4014 transformType, transformValues))
4015 return false;
4016
4017 switch (coverMode)
4018 {
4019 case GL_CONVEX_HULL_CHROMIUM:
4020 case GL_BOUNDING_BOX_CHROMIUM:
4021 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4022 break;
4023 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004024 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004025 return false;
4026 }
4027
4028 switch (fillMode)
4029 {
4030 case GL_COUNT_UP_CHROMIUM:
4031 case GL_COUNT_DOWN_CHROMIUM:
4032 break;
4033 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004034 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004035 return false;
4036 }
4037 if (!isPow2(mask + 1))
4038 {
Jamie Madille0472f32018-11-27 16:32:45 -05004039 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004040 return false;
4041 }
4042
4043 return true;
4044}
4045
Jamie Madill007530e2017-12-28 14:27:04 -05004046bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4047 GLsizei numPaths,
4048 GLenum pathNameType,
4049 const void *paths,
4050 GLuint pathBase,
4051 GLint reference,
4052 GLuint mask,
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 ValidateBindFragmentInputLocationCHROMIUM(Context *context,
4076 GLuint program,
4077 GLint location,
4078 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004079{
4080 if (!context->getExtensions().pathRendering)
4081 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004082 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004083 return false;
4084 }
4085
4086 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4087 if (location >= MaxLocation)
4088 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004089 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004090 return false;
4091 }
4092
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004093 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004094 if (!programObject)
4095 {
Jamie Madille0472f32018-11-27 16:32:45 -05004096 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004097 return false;
4098 }
4099
4100 if (!name)
4101 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004102 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004103 return false;
4104 }
4105
4106 if (angle::BeginsWith(name, "gl_"))
4107 {
Jamie Madille0472f32018-11-27 16:32:45 -05004108 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004109 return false;
4110 }
4111
4112 return true;
4113}
4114
Jamie Madill007530e2017-12-28 14:27:04 -05004115bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
4116 GLuint program,
4117 GLint location,
4118 GLenum genMode,
4119 GLint components,
4120 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004121{
4122 if (!context->getExtensions().pathRendering)
4123 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004124 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004125 return false;
4126 }
4127
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004128 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004129 if (!programObject || programObject->isFlaggedForDeletion())
4130 {
Jamie Madille0472f32018-11-27 16:32:45 -05004131 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004132 return false;
4133 }
4134
4135 if (!programObject->isLinked())
4136 {
Jamie Madille0472f32018-11-27 16:32:45 -05004137 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004138 return false;
4139 }
4140
4141 switch (genMode)
4142 {
4143 case GL_NONE:
4144 if (components != 0)
4145 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004146 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004147 return false;
4148 }
4149 break;
4150
4151 case GL_OBJECT_LINEAR_CHROMIUM:
4152 case GL_EYE_LINEAR_CHROMIUM:
4153 case GL_CONSTANT_CHROMIUM:
4154 if (components < 1 || components > 4)
4155 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004156 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004157 return false;
4158 }
4159 if (!coeffs)
4160 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004161 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004162 return false;
4163 }
4164 break;
4165
4166 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004167 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004168 return false;
4169 }
4170
4171 // If the location is -1 then the command is silently ignored
4172 // and no further validation is needed.
4173 if (location == -1)
4174 return true;
4175
jchen103fd614d2018-08-13 12:21:58 +08004176 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004177
4178 if (!binding.valid)
4179 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004180 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004181 return false;
4182 }
4183
4184 if (binding.type != GL_NONE)
4185 {
4186 GLint expectedComponents = 0;
4187 switch (binding.type)
4188 {
4189 case GL_FLOAT:
4190 expectedComponents = 1;
4191 break;
4192 case GL_FLOAT_VEC2:
4193 expectedComponents = 2;
4194 break;
4195 case GL_FLOAT_VEC3:
4196 expectedComponents = 3;
4197 break;
4198 case GL_FLOAT_VEC4:
4199 expectedComponents = 4;
4200 break;
4201 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004202 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004203 return false;
4204 }
4205 if (expectedComponents != components && genMode != GL_NONE)
4206 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004207 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004208 return false;
4209 }
4210 }
4211 return true;
4212}
4213
Geoff Lang97073d12016-04-20 10:42:34 -07004214bool ValidateCopyTextureCHROMIUM(Context *context,
4215 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004216 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004217 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004218 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004219 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004220 GLint internalFormat,
4221 GLenum destType,
4222 GLboolean unpackFlipY,
4223 GLboolean unpackPremultiplyAlpha,
4224 GLboolean unpackUnmultiplyAlpha)
4225{
4226 if (!context->getExtensions().copyTexture)
4227 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004228 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004229 return false;
4230 }
4231
Geoff Lang4f0e0032017-05-01 16:04:35 -04004232 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004233 if (source == nullptr)
4234 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004235 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004236 return false;
4237 }
4238
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004239 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004240 {
Jamie Madille0472f32018-11-27 16:32:45 -05004241 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004242 return false;
4243 }
4244
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004245 TextureType sourceType = source->getType();
4246 ASSERT(sourceType != TextureType::CubeMap);
4247 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004248
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004249 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004250 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004251 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004252 return false;
4253 }
4254
Geoff Lang4f0e0032017-05-01 16:04:35 -04004255 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4256 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4257 if (sourceWidth == 0 || sourceHeight == 0)
4258 {
Jamie Madille0472f32018-11-27 16:32:45 -05004259 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004260 return false;
4261 }
4262
4263 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4264 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004265 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004266 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004267 return false;
4268 }
4269
Geoff Lang63458a32017-10-30 15:16:53 -04004270 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4271 {
Jamie Madille0472f32018-11-27 16:32:45 -05004272 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004273 return false;
4274 }
4275
Geoff Lang4f0e0032017-05-01 16:04:35 -04004276 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004277 if (dest == nullptr)
4278 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004279 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004280 return false;
4281 }
4282
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004283 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004284 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004285 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004286 return false;
4287 }
4288
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004289 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004290 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004291 {
Jamie Madille0472f32018-11-27 16:32:45 -05004292 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004293 return false;
4294 }
4295
Geoff Lang97073d12016-04-20 10:42:34 -07004296 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4297 {
Geoff Lang97073d12016-04-20 10:42:34 -07004298 return false;
4299 }
4300
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004301 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004302 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004303 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004304 return false;
4305 }
4306
Geoff Lang97073d12016-04-20 10:42:34 -07004307 if (dest->getImmutableFormat())
4308 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004309 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004310 return false;
4311 }
4312
4313 return true;
4314}
4315
4316bool ValidateCopySubTextureCHROMIUM(Context *context,
4317 GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004318 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004319 TextureTarget destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07004320 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004321 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004322 GLint xoffset,
4323 GLint yoffset,
4324 GLint x,
4325 GLint y,
4326 GLsizei width,
4327 GLsizei height,
4328 GLboolean unpackFlipY,
4329 GLboolean unpackPremultiplyAlpha,
4330 GLboolean unpackUnmultiplyAlpha)
4331{
4332 if (!context->getExtensions().copyTexture)
4333 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004334 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004335 return false;
4336 }
4337
Geoff Lang4f0e0032017-05-01 16:04:35 -04004338 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004339 if (source == nullptr)
4340 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004341 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004342 return false;
4343 }
4344
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004345 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004346 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004347 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004348 return false;
4349 }
4350
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004351 TextureType sourceType = source->getType();
4352 ASSERT(sourceType != TextureType::CubeMap);
4353 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004354
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004355 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004356 {
Jamie Madille0472f32018-11-27 16:32:45 -05004357 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004358 return false;
4359 }
4360
4361 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4362 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004363 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004364 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004365 return false;
4366 }
4367
4368 if (x < 0 || y < 0)
4369 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004370 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004371 return false;
4372 }
4373
4374 if (width < 0 || height < 0)
4375 {
Jamie Madille0472f32018-11-27 16:32:45 -05004376 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004377 return false;
4378 }
4379
Geoff Lang4f0e0032017-05-01 16:04:35 -04004380 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4381 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004382 {
Jamie Madille0472f32018-11-27 16:32:45 -05004383 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004384 return false;
4385 }
4386
Geoff Lang4f0e0032017-05-01 16:04:35 -04004387 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4388 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004389 {
Jamie Madille0472f32018-11-27 16:32:45 -05004390 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
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
Brandon Jones28783792018-03-05 09:37:32 -08004413 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4414 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004415 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004416 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004417 return false;
4418 }
4419
Geoff Lang4f0e0032017-05-01 16:04:35 -04004420 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4421 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004422 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004423 return false;
4424 }
4425
4426 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4427 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004428 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004429 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004430 return false;
4431 }
4432
4433 if (xoffset < 0 || yoffset < 0)
4434 {
Jamie Madille0472f32018-11-27 16:32:45 -05004435 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004436 return false;
4437 }
4438
Geoff Lang4f0e0032017-05-01 16:04:35 -04004439 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4440 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004441 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004442 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004443 return false;
4444 }
4445
4446 return true;
4447}
4448
Geoff Lang47110bf2016-04-20 11:13:22 -07004449bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId)
4450{
4451 if (!context->getExtensions().copyCompressedTexture)
4452 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004453 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004454 return false;
4455 }
4456
4457 const gl::Texture *source = context->getTexture(sourceId);
4458 if (source == nullptr)
4459 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004460 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004461 return false;
4462 }
4463
Corentin Wallez99d492c2018-02-27 15:17:10 -05004464 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004465 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004466 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004467 return false;
4468 }
4469
Corentin Wallez99d492c2018-02-27 15:17:10 -05004470 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4471 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004472 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004473 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004474 return false;
4475 }
4476
Corentin Wallez99d492c2018-02-27 15:17:10 -05004477 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004478 if (!sourceFormat.info->compressed)
4479 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004480 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004481 return false;
4482 }
4483
4484 const gl::Texture *dest = context->getTexture(destId);
4485 if (dest == nullptr)
4486 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004487 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004488 return false;
4489 }
4490
Corentin Wallez99d492c2018-02-27 15:17:10 -05004491 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004492 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004493 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004494 return false;
4495 }
4496
4497 if (dest->getImmutableFormat())
4498 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004499 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004500 return false;
4501 }
4502
4503 return true;
4504}
4505
Jiawei Shao385b3e02018-03-21 09:43:28 +08004506bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004507{
4508 switch (type)
4509 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004510 case ShaderType::Vertex:
4511 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004512 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004513
Jiawei Shao385b3e02018-03-21 09:43:28 +08004514 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004515 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004516 {
Jamie Madille0472f32018-11-27 16:32:45 -05004517 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004518 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004519 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004520 break;
4521
Jiawei Shao385b3e02018-03-21 09:43:28 +08004522 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004523 if (!context->getExtensions().geometryShader)
4524 {
Jamie Madille0472f32018-11-27 16:32:45 -05004525 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004526 return false;
4527 }
4528 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004529 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004530 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004531 return false;
4532 }
Jamie Madill29639852016-09-02 15:00:09 -04004533
4534 return true;
4535}
4536
Jamie Madill5b772312018-03-08 20:28:32 -05004537bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004538 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004539 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004540 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004541 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004542{
4543 if (size < 0)
4544 {
Jamie Madille0472f32018-11-27 16:32:45 -05004545 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004546 return false;
4547 }
4548
4549 switch (usage)
4550 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004551 case BufferUsage::StreamDraw:
4552 case BufferUsage::StaticDraw:
4553 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004554 break;
4555
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004556 case BufferUsage::StreamRead:
4557 case BufferUsage::StaticRead:
4558 case BufferUsage::DynamicRead:
4559 case BufferUsage::StreamCopy:
4560 case BufferUsage::StaticCopy:
4561 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004562 if (context->getClientMajorVersion() < 3)
4563 {
Jamie Madille0472f32018-11-27 16:32:45 -05004564 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004565 return false;
4566 }
4567 break;
4568
4569 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004570 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004571 return false;
4572 }
4573
Corentin Walleze4477002017-12-01 14:39:58 -05004574 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004575 {
Jamie Madille0472f32018-11-27 16:32:45 -05004576 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004577 return false;
4578 }
4579
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004580 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004581
4582 if (!buffer)
4583 {
Jamie Madille0472f32018-11-27 16:32:45 -05004584 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004585 return false;
4586 }
4587
James Darpiniane8a93c62018-01-04 18:02:24 -08004588 if (context->getExtensions().webglCompatibility &&
4589 buffer->isBoundForTransformFeedbackAndOtherUse())
4590 {
Jamie Madille0472f32018-11-27 16:32:45 -05004591 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004592 return false;
4593 }
4594
Jamie Madill29639852016-09-02 15:00:09 -04004595 return true;
4596}
4597
Jamie Madill5b772312018-03-08 20:28:32 -05004598bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004599 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004600 GLintptr offset,
4601 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004602 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004603{
Brandon Jones6cad5662017-06-14 13:25:13 -07004604 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004605 {
Jamie Madille0472f32018-11-27 16:32:45 -05004606 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004607 return false;
4608 }
4609
4610 if (offset < 0)
4611 {
Jamie Madille0472f32018-11-27 16:32:45 -05004612 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004613 return false;
4614 }
4615
Corentin Walleze4477002017-12-01 14:39:58 -05004616 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004617 {
Jamie Madille0472f32018-11-27 16:32:45 -05004618 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004619 return false;
4620 }
4621
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004622 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004623
4624 if (!buffer)
4625 {
Jamie Madille0472f32018-11-27 16:32:45 -05004626 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004627 return false;
4628 }
4629
4630 if (buffer->isMapped())
4631 {
Jamie Madille0472f32018-11-27 16:32:45 -05004632 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004633 return false;
4634 }
4635
James Darpiniane8a93c62018-01-04 18:02:24 -08004636 if (context->getExtensions().webglCompatibility &&
4637 buffer->isBoundForTransformFeedbackAndOtherUse())
4638 {
Jamie Madille0472f32018-11-27 16:32:45 -05004639 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004640 return false;
4641 }
4642
Jamie Madill29639852016-09-02 15:00:09 -04004643 // Check for possible overflow of size + offset
4644 angle::CheckedNumeric<size_t> checkedSize(size);
4645 checkedSize += offset;
4646 if (!checkedSize.IsValid())
4647 {
Jamie Madille0472f32018-11-27 16:32:45 -05004648 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004649 return false;
4650 }
4651
4652 if (size + offset > buffer->getSize())
4653 {
Jamie Madille0472f32018-11-27 16:32:45 -05004654 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004655 return false;
4656 }
4657
Martin Radev4c4c8e72016-08-04 12:25:34 +03004658 return true;
4659}
4660
Geoff Lang111a99e2017-10-17 10:58:41 -04004661bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04004662{
Geoff Langc339c4e2016-11-29 10:37:36 -05004663 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04004664 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004665 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04004666 return false;
4667 }
4668
Geoff Lang111a99e2017-10-17 10:58:41 -04004669 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04004670 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004671 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04004672 return false;
4673 }
4674
4675 return true;
4676}
4677
Jamie Madill5b772312018-03-08 20:28:32 -05004678bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04004679{
Lingfeng Yang038dd532018-03-29 17:31:52 -07004680 if (context->getClientMajorVersion() < 2)
4681 {
4682 return ValidateMultitextureUnit(context, texture);
4683 }
4684
Jamie Madillef300b12016-10-07 15:12:09 -04004685 if (texture < GL_TEXTURE0 ||
4686 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
4687 {
Jamie Madille0472f32018-11-27 16:32:45 -05004688 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04004689 return false;
4690 }
4691
4692 return true;
4693}
4694
Jamie Madill5b772312018-03-08 20:28:32 -05004695bool ValidateAttachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillef300b12016-10-07 15:12:09 -04004696{
4697 Program *programObject = GetValidProgram(context, program);
4698 if (!programObject)
4699 {
4700 return false;
4701 }
4702
4703 Shader *shaderObject = GetValidShader(context, shader);
4704 if (!shaderObject)
4705 {
4706 return false;
4707 }
4708
Jiawei Shao385b3e02018-03-21 09:43:28 +08004709 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04004710 {
Jamie Madille0472f32018-11-27 16:32:45 -05004711 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08004712 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04004713 }
4714
4715 return true;
4716}
4717
Jamie Madill5b772312018-03-08 20:28:32 -05004718bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004719{
4720 if (index >= MAX_VERTEX_ATTRIBS)
4721 {
Jamie Madille0472f32018-11-27 16:32:45 -05004722 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004723 return false;
4724 }
4725
4726 if (strncmp(name, "gl_", 3) == 0)
4727 {
Jamie Madille0472f32018-11-27 16:32:45 -05004728 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004729 return false;
4730 }
4731
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004732 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04004733 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004734 const size_t length = strlen(name);
4735
4736 if (!IsValidESSLString(name, length))
4737 {
4738 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
4739 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05004740 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004741 return false;
4742 }
4743
4744 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
4745 {
4746 return false;
4747 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04004748 }
4749
Jamie Madill01a80ee2016-11-07 12:06:18 -05004750 return GetValidProgram(context, program) != nullptr;
4751}
4752
Jamie Madill5b772312018-03-08 20:28:32 -05004753bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004754{
Geoff Lange8afa902017-09-27 15:00:43 -04004755 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05004756 {
Jamie Madille0472f32018-11-27 16:32:45 -05004757 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004758 return false;
4759 }
4760
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004761 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004762 !context->isFramebufferGenerated(framebuffer))
4763 {
Jamie Madille0472f32018-11-27 16:32:45 -05004764 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004765 return false;
4766 }
4767
4768 return true;
4769}
4770
Jamie Madill5b772312018-03-08 20:28:32 -05004771bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004772{
4773 if (target != GL_RENDERBUFFER)
4774 {
Jamie Madille0472f32018-11-27 16:32:45 -05004775 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004776 return false;
4777 }
4778
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004779 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004780 !context->isRenderbufferGenerated(renderbuffer))
4781 {
Jamie Madille0472f32018-11-27 16:32:45 -05004782 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004783 return false;
4784 }
4785
4786 return true;
4787}
4788
Jamie Madill5b772312018-03-08 20:28:32 -05004789static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004790{
4791 switch (mode)
4792 {
4793 case GL_FUNC_ADD:
4794 case GL_FUNC_SUBTRACT:
4795 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04004796 return true;
4797
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004798 case GL_MIN:
4799 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04004800 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004801
4802 default:
4803 return false;
4804 }
4805}
4806
Jamie Madill5b772312018-03-08 20:28:32 -05004807bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004808{
4809 return true;
4810}
4811
Jamie Madill5b772312018-03-08 20:28:32 -05004812bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004813{
Geoff Lang50cac572017-09-26 17:37:43 -04004814 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004815 {
Jamie Madille0472f32018-11-27 16:32:45 -05004816 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004817 return false;
4818 }
4819
4820 return true;
4821}
4822
Jamie Madill5b772312018-03-08 20:28:32 -05004823bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004824{
Geoff Lang50cac572017-09-26 17:37:43 -04004825 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004826 {
Jamie Madille0472f32018-11-27 16:32:45 -05004827 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004828 return false;
4829 }
4830
Geoff Lang50cac572017-09-26 17:37:43 -04004831 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004832 {
Jamie Madille0472f32018-11-27 16:32:45 -05004833 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004834 return false;
4835 }
4836
4837 return true;
4838}
4839
Jamie Madill5b772312018-03-08 20:28:32 -05004840bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004841{
4842 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
4843}
4844
Jamie Madill5b772312018-03-08 20:28:32 -05004845bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004846 GLenum srcRGB,
4847 GLenum dstRGB,
4848 GLenum srcAlpha,
4849 GLenum dstAlpha)
4850{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004851 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004852 {
Jamie Madille0472f32018-11-27 16:32:45 -05004853 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004854 return false;
4855 }
4856
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004857 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004858 {
Jamie Madille0472f32018-11-27 16:32:45 -05004859 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004860 return false;
4861 }
4862
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004863 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004864 {
Jamie Madille0472f32018-11-27 16:32:45 -05004865 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004866 return false;
4867 }
4868
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03004869 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004870 {
Jamie Madille0472f32018-11-27 16:32:45 -05004871 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004872 return false;
4873 }
4874
Frank Henigman146e8a12017-03-02 23:22:37 -05004875 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
4876 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004877 {
4878 bool constantColorUsed =
4879 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
4880 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
4881
4882 bool constantAlphaUsed =
4883 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
4884 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
4885
4886 if (constantColorUsed && constantAlphaUsed)
4887 {
Frank Henigman146e8a12017-03-02 23:22:37 -05004888 if (context->getExtensions().webglCompatibility)
4889 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004890 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
4891 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05004892 }
Jamie Madillc3e37312018-11-30 15:25:39 -05004893
4894 WARN() << kConstantColorAlphaLimitation;
4895 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004896 return false;
4897 }
4898 }
4899
4900 return true;
4901}
4902
Geoff Langc339c4e2016-11-29 10:37:36 -05004903bool ValidateGetString(Context *context, GLenum name)
4904{
4905 switch (name)
4906 {
4907 case GL_VENDOR:
4908 case GL_RENDERER:
4909 case GL_VERSION:
4910 case GL_SHADING_LANGUAGE_VERSION:
4911 case GL_EXTENSIONS:
4912 break;
4913
4914 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
4915 if (!context->getExtensions().requestExtension)
4916 {
Jamie Madille0472f32018-11-27 16:32:45 -05004917 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05004918 return false;
4919 }
4920 break;
4921
4922 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004923 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05004924 return false;
4925 }
4926
4927 return true;
4928}
4929
Jamie Madill5b772312018-03-08 20:28:32 -05004930bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05004931{
4932 if (width <= 0.0f || isNaN(width))
4933 {
Jamie Madille0472f32018-11-27 16:32:45 -05004934 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05004935 return false;
4936 }
4937
4938 return true;
4939}
4940
Jamie Madill5b772312018-03-08 20:28:32 -05004941bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05004942{
4943 if (context->getExtensions().webglCompatibility && zNear > zFar)
4944 {
Jamie Madille0472f32018-11-27 16:32:45 -05004945 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05004946 return false;
4947 }
4948
4949 return true;
4950}
4951
Jamie Madill5b772312018-03-08 20:28:32 -05004952bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05004953 GLenum target,
4954 GLenum internalformat,
4955 GLsizei width,
4956 GLsizei height)
4957{
4958 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
4959 height);
4960}
4961
Jamie Madill5b772312018-03-08 20:28:32 -05004962bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05004963 GLenum target,
4964 GLsizei samples,
4965 GLenum internalformat,
4966 GLsizei width,
4967 GLsizei height)
4968{
4969 if (!context->getExtensions().framebufferMultisample)
4970 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004971 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05004972 return false;
4973 }
4974
4975 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05004976 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05004977 // generated.
4978 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
4979 {
Jamie Madille0472f32018-11-27 16:32:45 -05004980 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05004981 return false;
4982 }
4983
4984 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
4985 // the specified storage. This is different than ES 3.0 in which a sample number higher
4986 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
4987 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
4988 if (context->getClientMajorVersion() >= 3)
4989 {
4990 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
4991 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
4992 {
Jamie Madille0472f32018-11-27 16:32:45 -05004993 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05004994 return false;
4995 }
4996 }
4997
4998 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
4999 width, height);
5000}
5001
Jamie Madill5b772312018-03-08 20:28:32 -05005002bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005003{
Geoff Lange8afa902017-09-27 15:00:43 -04005004 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005005 {
Jamie Madille0472f32018-11-27 16:32:45 -05005006 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005007 return false;
5008 }
5009
5010 return true;
5011}
5012
Jamie Madill5b772312018-03-08 20:28:32 -05005013bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005014{
5015 return true;
5016}
5017
Jamie Madill5b772312018-03-08 20:28:32 -05005018bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005019{
5020 return true;
5021}
5022
Jamie Madill5b772312018-03-08 20:28:32 -05005023bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005024{
5025 return true;
5026}
5027
Jamie Madill5b772312018-03-08 20:28:32 -05005028bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005029 GLboolean red,
5030 GLboolean green,
5031 GLboolean blue,
5032 GLboolean alpha)
5033{
5034 return true;
5035}
5036
Jamie Madill5b772312018-03-08 20:28:32 -05005037bool ValidateCompileShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005038{
5039 return true;
5040}
5041
Jamie Madill5b772312018-03-08 20:28:32 -05005042bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005043{
5044 return true;
5045}
5046
Jamie Madill5b772312018-03-08 20:28:32 -05005047bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005048{
5049 switch (mode)
5050 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005051 case CullFaceMode::Front:
5052 case CullFaceMode::Back:
5053 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005054 break;
5055
5056 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005057 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005058 return false;
5059 }
5060
5061 return true;
5062}
5063
Jamie Madill5b772312018-03-08 20:28:32 -05005064bool ValidateDeleteProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005065{
5066 if (program == 0)
5067 {
5068 return false;
5069 }
5070
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005071 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005072 {
5073 if (context->getShader(program))
5074 {
Jamie Madille0472f32018-11-27 16:32:45 -05005075 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005076 return false;
5077 }
5078 else
5079 {
Jamie Madille0472f32018-11-27 16:32:45 -05005080 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005081 return false;
5082 }
5083 }
5084
5085 return true;
5086}
5087
Jamie Madill5b772312018-03-08 20:28:32 -05005088bool ValidateDeleteShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005089{
5090 if (shader == 0)
5091 {
5092 return false;
5093 }
5094
5095 if (!context->getShader(shader))
5096 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005097 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005098 {
Jamie Madille0472f32018-11-27 16:32:45 -05005099 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005100 return false;
5101 }
5102 else
5103 {
Jamie Madille0472f32018-11-27 16:32:45 -05005104 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005105 return false;
5106 }
5107 }
5108
5109 return true;
5110}
5111
Jamie Madill5b772312018-03-08 20:28:32 -05005112bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005113{
5114 switch (func)
5115 {
5116 case GL_NEVER:
5117 case GL_ALWAYS:
5118 case GL_LESS:
5119 case GL_LEQUAL:
5120 case GL_EQUAL:
5121 case GL_GREATER:
5122 case GL_GEQUAL:
5123 case GL_NOTEQUAL:
5124 break;
5125
5126 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005127 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005128 return false;
5129 }
5130
5131 return true;
5132}
5133
Jamie Madill5b772312018-03-08 20:28:32 -05005134bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005135{
5136 return true;
5137}
5138
Jamie Madill5b772312018-03-08 20:28:32 -05005139bool ValidateDetachShader(Context *context, GLuint program, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005140{
5141 Program *programObject = GetValidProgram(context, program);
5142 if (!programObject)
5143 {
5144 return false;
5145 }
5146
5147 Shader *shaderObject = GetValidShader(context, shader);
5148 if (!shaderObject)
5149 {
5150 return false;
5151 }
5152
Jiawei Shao385b3e02018-03-21 09:43:28 +08005153 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005154 if (attachedShader != shaderObject)
5155 {
Jamie Madille0472f32018-11-27 16:32:45 -05005156 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005157 return false;
5158 }
5159
5160 return true;
5161}
5162
Jamie Madill5b772312018-03-08 20:28:32 -05005163bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005164{
5165 if (index >= MAX_VERTEX_ATTRIBS)
5166 {
Jamie Madille0472f32018-11-27 16:32:45 -05005167 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005168 return false;
5169 }
5170
5171 return true;
5172}
5173
Jamie Madill5b772312018-03-08 20:28:32 -05005174bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005175{
5176 if (index >= MAX_VERTEX_ATTRIBS)
5177 {
Jamie Madille0472f32018-11-27 16:32:45 -05005178 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005179 return false;
5180 }
5181
5182 return true;
5183}
5184
Jamie Madill5b772312018-03-08 20:28:32 -05005185bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005186{
5187 return true;
5188}
5189
Jamie Madill5b772312018-03-08 20:28:32 -05005190bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005191{
5192 return true;
5193}
5194
Jamie Madill5b772312018-03-08 20:28:32 -05005195bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005196{
5197 switch (mode)
5198 {
5199 case GL_CW:
5200 case GL_CCW:
5201 break;
5202 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005203 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005204 return false;
5205 }
5206
5207 return true;
5208}
5209
Jamie Madill5b772312018-03-08 20:28:32 -05005210bool ValidateGetActiveAttrib(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005211 GLuint program,
5212 GLuint index,
5213 GLsizei bufsize,
5214 GLsizei *length,
5215 GLint *size,
5216 GLenum *type,
5217 GLchar *name)
5218{
5219 if (bufsize < 0)
5220 {
Jamie Madille0472f32018-11-27 16:32:45 -05005221 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005222 return false;
5223 }
5224
5225 Program *programObject = GetValidProgram(context, program);
5226
5227 if (!programObject)
5228 {
5229 return false;
5230 }
5231
5232 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5233 {
Jamie Madille0472f32018-11-27 16:32:45 -05005234 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005235 return false;
5236 }
5237
5238 return true;
5239}
5240
Jamie Madill5b772312018-03-08 20:28:32 -05005241bool ValidateGetActiveUniform(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005242 GLuint program,
5243 GLuint index,
5244 GLsizei bufsize,
5245 GLsizei *length,
5246 GLint *size,
5247 GLenum *type,
5248 GLchar *name)
5249{
5250 if (bufsize < 0)
5251 {
Jamie Madille0472f32018-11-27 16:32:45 -05005252 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005253 return false;
5254 }
5255
5256 Program *programObject = GetValidProgram(context, program);
5257
5258 if (!programObject)
5259 {
5260 return false;
5261 }
5262
5263 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5264 {
Jamie Madille0472f32018-11-27 16:32:45 -05005265 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005266 return false;
5267 }
5268
5269 return true;
5270}
5271
Jamie Madill5b772312018-03-08 20:28:32 -05005272bool ValidateGetAttachedShaders(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005273 GLuint program,
5274 GLsizei maxcount,
5275 GLsizei *count,
5276 GLuint *shaders)
5277{
5278 if (maxcount < 0)
5279 {
Jamie Madille0472f32018-11-27 16:32:45 -05005280 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005281 return false;
5282 }
5283
5284 Program *programObject = GetValidProgram(context, program);
5285
5286 if (!programObject)
5287 {
5288 return false;
5289 }
5290
5291 return true;
5292}
5293
Jamie Madill5b772312018-03-08 20:28:32 -05005294bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005295{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005296 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5297 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005298 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005299 {
Jamie Madille0472f32018-11-27 16:32:45 -05005300 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005301 return false;
5302 }
5303
Jamie Madillc1d770e2017-04-13 17:31:24 -04005304 Program *programObject = GetValidProgram(context, program);
5305
5306 if (!programObject)
5307 {
Jamie Madille0472f32018-11-27 16:32:45 -05005308 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005309 return false;
5310 }
5311
5312 if (!programObject->isLinked())
5313 {
Jamie Madille0472f32018-11-27 16:32:45 -05005314 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005315 return false;
5316 }
5317
5318 return true;
5319}
5320
Jamie Madill5b772312018-03-08 20:28:32 -05005321bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005322{
5323 GLenum nativeType;
5324 unsigned int numParams = 0;
5325 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5326}
5327
Jamie Madill5b772312018-03-08 20:28:32 -05005328bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005329{
5330 return true;
5331}
5332
Jamie Madill5b772312018-03-08 20:28:32 -05005333bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005334{
5335 GLenum nativeType;
5336 unsigned int numParams = 0;
5337 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5338}
5339
Jamie Madill5b772312018-03-08 20:28:32 -05005340bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005341{
5342 GLenum nativeType;
5343 unsigned int numParams = 0;
5344 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5345}
5346
Jamie Madill5b772312018-03-08 20:28:32 -05005347bool ValidateGetProgramInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005348 GLuint program,
5349 GLsizei bufsize,
5350 GLsizei *length,
5351 GLchar *infolog)
5352{
5353 if (bufsize < 0)
5354 {
Jamie Madille0472f32018-11-27 16:32:45 -05005355 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005356 return false;
5357 }
5358
5359 Program *programObject = GetValidProgram(context, program);
5360 if (!programObject)
5361 {
5362 return false;
5363 }
5364
5365 return true;
5366}
5367
Jamie Madill5b772312018-03-08 20:28:32 -05005368bool ValidateGetShaderInfoLog(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005369 GLuint shader,
5370 GLsizei bufsize,
5371 GLsizei *length,
5372 GLchar *infolog)
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 Shader *shaderObject = GetValidShader(context, shader);
5381 if (!shaderObject)
5382 {
5383 return false;
5384 }
5385
5386 return true;
5387}
5388
Jamie Madill5b772312018-03-08 20:28:32 -05005389bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005390 GLenum shadertype,
5391 GLenum precisiontype,
5392 GLint *range,
5393 GLint *precision)
5394{
5395 switch (shadertype)
5396 {
5397 case GL_VERTEX_SHADER:
5398 case GL_FRAGMENT_SHADER:
5399 break;
5400 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005401 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005402 return false;
5403 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005404 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005405 return false;
5406 }
5407
5408 switch (precisiontype)
5409 {
5410 case GL_LOW_FLOAT:
5411 case GL_MEDIUM_FLOAT:
5412 case GL_HIGH_FLOAT:
5413 case GL_LOW_INT:
5414 case GL_MEDIUM_INT:
5415 case GL_HIGH_INT:
5416 break;
5417
5418 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005419 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005420 return false;
5421 }
5422
5423 return true;
5424}
5425
Jamie Madill5b772312018-03-08 20:28:32 -05005426bool ValidateGetShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005427 GLuint shader,
5428 GLsizei bufsize,
5429 GLsizei *length,
5430 GLchar *source)
5431{
5432 if (bufsize < 0)
5433 {
Jamie Madille0472f32018-11-27 16:32:45 -05005434 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005435 return false;
5436 }
5437
5438 Shader *shaderObject = GetValidShader(context, shader);
5439 if (!shaderObject)
5440 {
5441 return false;
5442 }
5443
5444 return true;
5445}
5446
Jamie Madill5b772312018-03-08 20:28:32 -05005447bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005448{
5449 if (strstr(name, "gl_") == name)
5450 {
5451 return false;
5452 }
5453
Geoff Langfc32e8b2017-05-31 14:16:59 -04005454 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5455 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005456 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005457 {
Jamie Madille0472f32018-11-27 16:32:45 -05005458 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005459 return false;
5460 }
5461
Jamie Madillc1d770e2017-04-13 17:31:24 -04005462 Program *programObject = GetValidProgram(context, program);
5463
5464 if (!programObject)
5465 {
5466 return false;
5467 }
5468
5469 if (!programObject->isLinked())
5470 {
Jamie Madille0472f32018-11-27 16:32:45 -05005471 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005472 return false;
5473 }
5474
5475 return true;
5476}
5477
Jamie Madill5b772312018-03-08 20:28:32 -05005478bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005479{
5480 switch (mode)
5481 {
5482 case GL_FASTEST:
5483 case GL_NICEST:
5484 case GL_DONT_CARE:
5485 break;
5486
5487 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005488 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005489 return false;
5490 }
5491
5492 switch (target)
5493 {
5494 case GL_GENERATE_MIPMAP_HINT:
5495 break;
5496
Geoff Lange7bd2182017-06-16 16:13:13 -04005497 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5498 if (context->getClientVersion() < ES_3_0 &&
5499 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005500 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005501 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005502 return false;
5503 }
5504 break;
5505
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005506 case GL_PERSPECTIVE_CORRECTION_HINT:
5507 case GL_POINT_SMOOTH_HINT:
5508 case GL_LINE_SMOOTH_HINT:
5509 case GL_FOG_HINT:
5510 if (context->getClientMajorVersion() >= 2)
5511 {
Jamie Madille0472f32018-11-27 16:32:45 -05005512 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005513 return false;
5514 }
5515 break;
5516
Jamie Madillc1d770e2017-04-13 17:31:24 -04005517 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005518 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005519 return false;
5520 }
5521
5522 return true;
5523}
5524
Jamie Madill5b772312018-03-08 20:28:32 -05005525bool ValidateIsBuffer(Context *context, GLuint buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005526{
5527 return true;
5528}
5529
Jamie Madill5b772312018-03-08 20:28:32 -05005530bool ValidateIsFramebuffer(Context *context, GLuint framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005531{
5532 return true;
5533}
5534
Jamie Madill5b772312018-03-08 20:28:32 -05005535bool ValidateIsProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005536{
5537 return true;
5538}
5539
Jamie Madill5b772312018-03-08 20:28:32 -05005540bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005541{
5542 return true;
5543}
5544
Jamie Madill5b772312018-03-08 20:28:32 -05005545bool ValidateIsShader(Context *context, GLuint shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005546{
5547 return true;
5548}
5549
Jamie Madill5b772312018-03-08 20:28:32 -05005550bool ValidateIsTexture(Context *context, GLuint texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005551{
5552 return true;
5553}
5554
Jamie Madill5b772312018-03-08 20:28:32 -05005555bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005556{
5557 if (context->getClientMajorVersion() < 3)
5558 {
5559 switch (pname)
5560 {
5561 case GL_UNPACK_IMAGE_HEIGHT:
5562 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005563 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005564 return false;
5565
5566 case GL_UNPACK_ROW_LENGTH:
5567 case GL_UNPACK_SKIP_ROWS:
5568 case GL_UNPACK_SKIP_PIXELS:
5569 if (!context->getExtensions().unpackSubimage)
5570 {
Jamie Madille0472f32018-11-27 16:32:45 -05005571 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005572 return false;
5573 }
5574 break;
5575
5576 case GL_PACK_ROW_LENGTH:
5577 case GL_PACK_SKIP_ROWS:
5578 case GL_PACK_SKIP_PIXELS:
5579 if (!context->getExtensions().packSubimage)
5580 {
Jamie Madille0472f32018-11-27 16:32:45 -05005581 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005582 return false;
5583 }
5584 break;
5585 }
5586 }
5587
5588 if (param < 0)
5589 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005590 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005591 return false;
5592 }
5593
5594 switch (pname)
5595 {
5596 case GL_UNPACK_ALIGNMENT:
5597 if (param != 1 && param != 2 && param != 4 && param != 8)
5598 {
Jamie Madille0472f32018-11-27 16:32:45 -05005599 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005600 return false;
5601 }
5602 break;
5603
5604 case GL_PACK_ALIGNMENT:
5605 if (param != 1 && param != 2 && param != 4 && param != 8)
5606 {
Jamie Madille0472f32018-11-27 16:32:45 -05005607 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005608 return false;
5609 }
5610 break;
5611
5612 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005613 if (!context->getExtensions().packReverseRowOrder)
5614 {
Jamie Madille0472f32018-11-27 16:32:45 -05005615 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005616 }
5617 break;
5618
Jamie Madillc1d770e2017-04-13 17:31:24 -04005619 case GL_UNPACK_ROW_LENGTH:
5620 case GL_UNPACK_IMAGE_HEIGHT:
5621 case GL_UNPACK_SKIP_IMAGES:
5622 case GL_UNPACK_SKIP_ROWS:
5623 case GL_UNPACK_SKIP_PIXELS:
5624 case GL_PACK_ROW_LENGTH:
5625 case GL_PACK_SKIP_ROWS:
5626 case GL_PACK_SKIP_PIXELS:
5627 break;
5628
5629 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005630 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005631 return false;
5632 }
5633
5634 return true;
5635}
5636
Jamie Madill5b772312018-03-08 20:28:32 -05005637bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005638{
5639 return true;
5640}
5641
Jamie Madill5b772312018-03-08 20:28:32 -05005642bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005643{
5644 return true;
5645}
5646
Jamie Madill5b772312018-03-08 20:28:32 -05005647bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005648{
5649 return true;
5650}
5651
Jamie Madill5b772312018-03-08 20:28:32 -05005652bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005653{
5654 if (width < 0 || height < 0)
5655 {
Jamie Madille0472f32018-11-27 16:32:45 -05005656 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005657 return false;
5658 }
5659
5660 return true;
5661}
5662
Jamie Madill5b772312018-03-08 20:28:32 -05005663bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005664 GLsizei n,
5665 const GLuint *shaders,
5666 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005667 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005668 GLsizei length)
5669{
5670 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
5671 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
5672 shaderBinaryFormats.end())
5673 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005674 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005675 return false;
5676 }
5677
5678 return true;
5679}
5680
Jamie Madill5b772312018-03-08 20:28:32 -05005681bool ValidateShaderSource(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005682 GLuint shader,
5683 GLsizei count,
5684 const GLchar *const *string,
5685 const GLint *length)
5686{
5687 if (count < 0)
5688 {
Jamie Madille0472f32018-11-27 16:32:45 -05005689 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005690 return false;
5691 }
5692
Geoff Langfc32e8b2017-05-31 14:16:59 -04005693 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5694 // shader-related entry points
5695 if (context->getExtensions().webglCompatibility)
5696 {
5697 for (GLsizei i = 0; i < count; i++)
5698 {
Geoff Langcab92ee2017-07-19 17:32:07 -04005699 size_t len =
5700 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04005701
5702 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04005703 if (!IsValidESSLShaderSourceString(string[i], len,
5704 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005705 {
Jamie Madille0472f32018-11-27 16:32:45 -05005706 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005707 return false;
5708 }
5709 }
5710 }
5711
Jamie Madillc1d770e2017-04-13 17:31:24 -04005712 Shader *shaderObject = GetValidShader(context, shader);
5713 if (!shaderObject)
5714 {
5715 return false;
5716 }
5717
5718 return true;
5719}
5720
Jamie Madill5b772312018-03-08 20:28:32 -05005721bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005722{
5723 if (!IsValidStencilFunc(func))
5724 {
Jamie Madille0472f32018-11-27 16:32:45 -05005725 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005726 return false;
5727 }
5728
5729 return true;
5730}
5731
Jamie Madill5b772312018-03-08 20:28:32 -05005732bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005733{
5734 if (!IsValidStencilFace(face))
5735 {
Jamie Madille0472f32018-11-27 16:32:45 -05005736 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005737 return false;
5738 }
5739
5740 if (!IsValidStencilFunc(func))
5741 {
Jamie Madille0472f32018-11-27 16:32:45 -05005742 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743 return false;
5744 }
5745
5746 return true;
5747}
5748
Jamie Madill5b772312018-03-08 20:28:32 -05005749bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005750{
5751 return true;
5752}
5753
Jamie Madill5b772312018-03-08 20:28:32 -05005754bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005755{
5756 if (!IsValidStencilFace(face))
5757 {
Jamie Madille0472f32018-11-27 16:32:45 -05005758 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005759 return false;
5760 }
5761
5762 return true;
5763}
5764
Jamie Madill5b772312018-03-08 20:28:32 -05005765bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005766{
5767 if (!IsValidStencilOp(fail))
5768 {
Jamie Madille0472f32018-11-27 16:32:45 -05005769 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005770 return false;
5771 }
5772
5773 if (!IsValidStencilOp(zfail))
5774 {
Jamie Madille0472f32018-11-27 16:32:45 -05005775 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005776 return false;
5777 }
5778
5779 if (!IsValidStencilOp(zpass))
5780 {
Jamie Madille0472f32018-11-27 16:32:45 -05005781 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005782 return false;
5783 }
5784
5785 return true;
5786}
5787
Jamie Madill5b772312018-03-08 20:28:32 -05005788bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005789 GLenum face,
5790 GLenum fail,
5791 GLenum zfail,
5792 GLenum zpass)
5793{
5794 if (!IsValidStencilFace(face))
5795 {
Jamie Madille0472f32018-11-27 16:32:45 -05005796 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005797 return false;
5798 }
5799
5800 return ValidateStencilOp(context, fail, zfail, zpass);
5801}
5802
Jamie Madill5b772312018-03-08 20:28:32 -05005803bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005804{
5805 return ValidateUniform(context, GL_FLOAT, location, 1);
5806}
5807
Jamie Madill5b772312018-03-08 20:28:32 -05005808bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005809{
5810 return ValidateUniform(context, GL_FLOAT, location, count);
5811}
5812
Jamie Madill5b772312018-03-08 20:28:32 -05005813bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04005814{
5815 return ValidateUniform1iv(context, location, 1, &x);
5816}
5817
Jamie Madill5b772312018-03-08 20:28:32 -05005818bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005819{
5820 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
5821}
5822
Jamie Madill5b772312018-03-08 20:28:32 -05005823bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005824{
5825 return ValidateUniform(context, GL_INT_VEC2, location, 1);
5826}
5827
Jamie Madill5b772312018-03-08 20:28:32 -05005828bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005829{
5830 return ValidateUniform(context, GL_INT_VEC2, location, count);
5831}
5832
Jamie Madill5b772312018-03-08 20:28:32 -05005833bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005834{
5835 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
5836}
5837
Jamie Madill5b772312018-03-08 20:28:32 -05005838bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005839{
5840 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
5841}
5842
Jamie Madill5b772312018-03-08 20:28:32 -05005843bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005844{
5845 return ValidateUniform(context, GL_INT_VEC3, location, 1);
5846}
5847
Jamie Madill5b772312018-03-08 20:28:32 -05005848bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005849{
5850 return ValidateUniform(context, GL_INT_VEC3, location, count);
5851}
5852
Jamie Madill5b772312018-03-08 20:28:32 -05005853bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005854{
5855 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
5856}
5857
Jamie Madill5b772312018-03-08 20:28:32 -05005858bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005859{
5860 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
5861}
5862
Jamie Madill5b772312018-03-08 20:28:32 -05005863bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005864{
5865 return ValidateUniform(context, GL_INT_VEC4, location, 1);
5866}
5867
Jamie Madill5b772312018-03-08 20:28:32 -05005868bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005869{
5870 return ValidateUniform(context, GL_INT_VEC4, location, count);
5871}
5872
Jamie Madill5b772312018-03-08 20:28:32 -05005873bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005874 GLint location,
5875 GLsizei count,
5876 GLboolean transpose,
5877 const GLfloat *value)
5878{
5879 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
5880}
5881
Jamie Madill5b772312018-03-08 20:28:32 -05005882bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005883 GLint location,
5884 GLsizei count,
5885 GLboolean transpose,
5886 const GLfloat *value)
5887{
5888 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
5889}
5890
Jamie Madill5b772312018-03-08 20:28:32 -05005891bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005892 GLint location,
5893 GLsizei count,
5894 GLboolean transpose,
5895 const GLfloat *value)
5896{
5897 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
5898}
5899
Jamie Madill5b772312018-03-08 20:28:32 -05005900bool ValidateValidateProgram(Context *context, GLuint program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005901{
5902 Program *programObject = GetValidProgram(context, program);
5903
5904 if (!programObject)
5905 {
5906 return false;
5907 }
5908
5909 return true;
5910}
5911
Jamie Madill5b772312018-03-08 20:28:32 -05005912bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005913{
5914 return ValidateVertexAttribIndex(context, index);
5915}
5916
Jamie Madill5b772312018-03-08 20:28:32 -05005917bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005918{
5919 return ValidateVertexAttribIndex(context, index);
5920}
5921
Jamie Madill5b772312018-03-08 20:28:32 -05005922bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005923{
5924 return ValidateVertexAttribIndex(context, index);
5925}
5926
Jamie Madill5b772312018-03-08 20:28:32 -05005927bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005928{
5929 return ValidateVertexAttribIndex(context, index);
5930}
5931
Jamie Madill5b772312018-03-08 20:28:32 -05005932bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005933{
5934 return ValidateVertexAttribIndex(context, index);
5935}
5936
Jamie Madill5b772312018-03-08 20:28:32 -05005937bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005938{
5939 return ValidateVertexAttribIndex(context, index);
5940}
5941
Jamie Madill5b772312018-03-08 20:28:32 -05005942bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005943 GLuint index,
5944 GLfloat x,
5945 GLfloat y,
5946 GLfloat z,
5947 GLfloat w)
5948{
5949 return ValidateVertexAttribIndex(context, index);
5950}
5951
Jamie Madill5b772312018-03-08 20:28:32 -05005952bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005953{
5954 return ValidateVertexAttribIndex(context, index);
5955}
5956
Jamie Madill5b772312018-03-08 20:28:32 -05005957bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005958{
5959 if (width < 0 || height < 0)
5960 {
Jamie Madille0472f32018-11-27 16:32:45 -05005961 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005962 return false;
5963 }
5964
5965 return true;
5966}
5967
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08005968bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04005969 GLenum target,
5970 GLenum attachment,
5971 GLenum pname,
5972 GLint *params)
5973{
5974 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
5975 nullptr);
5976}
5977
Jamie Madill5b772312018-03-08 20:28:32 -05005978bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04005979{
5980 return ValidateGetProgramivBase(context, program, pname, nullptr);
5981}
5982
Jamie Madill5b772312018-03-08 20:28:32 -05005983bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005984 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04005985 GLint level,
5986 GLenum internalformat,
5987 GLint x,
5988 GLint y,
5989 GLsizei width,
5990 GLsizei height,
5991 GLint border)
5992{
5993 if (context->getClientMajorVersion() < 3)
5994 {
5995 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
5996 0, x, y, width, height, border);
5997 }
5998
5999 ASSERT(context->getClientMajorVersion() == 3);
6000 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
6001 0, x, y, width, height, border);
6002}
6003
6004bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006005 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006006 GLint level,
6007 GLint xoffset,
6008 GLint yoffset,
6009 GLint x,
6010 GLint y,
6011 GLsizei width,
6012 GLsizei height)
6013{
6014 if (context->getClientMajorVersion() < 3)
6015 {
6016 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
6017 yoffset, x, y, width, height, 0);
6018 }
6019
6020 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
6021 yoffset, 0, x, y, width, height, 0);
6022}
6023
6024bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *)
6025{
6026 return ValidateGenOrDelete(context, n);
6027}
6028
6029bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *)
6030{
6031 return ValidateGenOrDelete(context, n);
6032}
6033
6034bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *)
6035{
6036 return ValidateGenOrDelete(context, n);
6037}
6038
6039bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *)
6040{
6041 return ValidateGenOrDelete(context, n);
6042}
6043
6044bool ValidateDisable(Context *context, GLenum cap)
6045{
6046 if (!ValidCap(context, cap, false))
6047 {
Jamie Madille0472f32018-11-27 16:32:45 -05006048 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006049 return false;
6050 }
6051
6052 return true;
6053}
6054
6055bool ValidateEnable(Context *context, GLenum cap)
6056{
6057 if (!ValidCap(context, cap, false))
6058 {
Jamie Madille0472f32018-11-27 16:32:45 -05006059 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006060 return false;
6061 }
6062
6063 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6064 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6065 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006066 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006067
6068 // We also output an error message to the debugger window if tracing is active, so that
6069 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006070 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006071 return false;
6072 }
6073
6074 return true;
6075}
6076
6077bool ValidateFramebufferRenderbuffer(Context *context,
6078 GLenum target,
6079 GLenum attachment,
6080 GLenum renderbuffertarget,
6081 GLuint renderbuffer)
6082{
Geoff Lange8afa902017-09-27 15:00:43 -04006083 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006084 {
Jamie Madille0472f32018-11-27 16:32:45 -05006085 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006086 return false;
6087 }
6088
6089 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)
6090 {
Jamie Madille0472f32018-11-27 16:32:45 -05006091 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006092 return false;
6093 }
6094
6095 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6096 renderbuffertarget, renderbuffer);
6097}
6098
6099bool ValidateFramebufferTexture2D(Context *context,
6100 GLenum target,
6101 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006102 TextureTarget textarget,
Jamie Madillbe849e42017-05-02 15:49:00 -04006103 GLuint texture,
6104 GLint level)
6105{
6106 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6107 // extension
6108 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6109 level != 0)
6110 {
Jamie Madille0472f32018-11-27 16:32:45 -05006111 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006112 return false;
6113 }
6114
6115 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6116 {
6117 return false;
6118 }
6119
6120 if (texture != 0)
6121 {
6122 gl::Texture *tex = context->getTexture(texture);
6123 ASSERT(tex);
6124
6125 const gl::Caps &caps = context->getCaps();
6126
6127 switch (textarget)
6128 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006129 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006130 {
6131 if (level > gl::log2(caps.max2DTextureSize))
6132 {
Jamie Madille0472f32018-11-27 16:32:45 -05006133 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006134 return false;
6135 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006136 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006137 {
Jamie Madille0472f32018-11-27 16:32:45 -05006138 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006139 return false;
6140 }
6141 }
6142 break;
6143
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006144 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006145 {
6146 if (level != 0)
6147 {
Jamie Madille0472f32018-11-27 16:32:45 -05006148 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006149 return false;
6150 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006151 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006152 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006153 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006154 return false;
6155 }
6156 }
6157 break;
6158
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006159 case TextureTarget::CubeMapNegativeX:
6160 case TextureTarget::CubeMapNegativeY:
6161 case TextureTarget::CubeMapNegativeZ:
6162 case TextureTarget::CubeMapPositiveX:
6163 case TextureTarget::CubeMapPositiveY:
6164 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006165 {
6166 if (level > gl::log2(caps.maxCubeMapTextureSize))
6167 {
Jamie Madille0472f32018-11-27 16:32:45 -05006168 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006169 return false;
6170 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006171 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006172 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006173 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006174 return false;
6175 }
6176 }
6177 break;
6178
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006179 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006180 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006181 if (context->getClientVersion() < ES_3_1 &&
6182 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006183 {
Jamie Madill610640f2018-11-21 17:28:41 -05006184 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006185 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006186 return false;
6187 }
6188
6189 if (level != 0)
6190 {
Jamie Madille0472f32018-11-27 16:32:45 -05006191 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006192 return false;
6193 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006194 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006195 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006196 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006197 return false;
6198 }
6199 }
6200 break;
6201
6202 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006203 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006204 return false;
6205 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006206 }
6207
6208 return true;
6209}
6210
6211bool ValidateGenBuffers(Context *context, GLint n, GLuint *)
6212{
6213 return ValidateGenOrDelete(context, n);
6214}
6215
6216bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *)
6217{
6218 return ValidateGenOrDelete(context, n);
6219}
6220
6221bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *)
6222{
6223 return ValidateGenOrDelete(context, n);
6224}
6225
6226bool ValidateGenTextures(Context *context, GLint n, GLuint *)
6227{
6228 return ValidateGenOrDelete(context, n);
6229}
6230
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006231bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006232{
6233 if (!ValidTextureTarget(context, target))
6234 {
Jamie Madille0472f32018-11-27 16:32:45 -05006235 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006236 return false;
6237 }
6238
Jamie Madillcfc73cc2019-04-08 16:26:51 -04006239 Texture *texture = context->getTextureByType(target);
Jamie Madillbe849e42017-05-02 15:49:00 -04006240
6241 if (texture == nullptr)
6242 {
Jamie Madille0472f32018-11-27 16:32:45 -05006243 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006244 return false;
6245 }
6246
6247 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6248
6249 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6250 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6251 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6252 {
Jamie Madille0472f32018-11-27 16:32:45 -05006253 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006254 return false;
6255 }
6256
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006257 TextureTarget baseTarget = (target == TextureType::CubeMap)
6258 ? TextureTarget::CubeMapPositiveX
6259 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006260 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6261 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6262 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006263 {
Jamie Madille0472f32018-11-27 16:32:45 -05006264 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006265 return false;
6266 }
6267
Geoff Lang536eca12017-09-13 11:23:35 -04006268 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6269 bool formatUnsized = !format.sized;
6270 bool formatColorRenderableAndFilterable =
6271 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006272 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006273 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006274 {
Jamie Madille0472f32018-11-27 16:32:45 -05006275 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006276 return false;
6277 }
6278
Geoff Lang536eca12017-09-13 11:23:35 -04006279 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6280 // generation
6281 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6282 {
Jamie Madille0472f32018-11-27 16:32:45 -05006283 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006284 return false;
6285 }
6286
Jiange2c00842018-07-13 16:50:49 +08006287 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6288 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6289 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006290 {
Jamie Madille0472f32018-11-27 16:32:45 -05006291 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006292 return false;
6293 }
6294
6295 // Non-power of 2 ES2 check
6296 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6297 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6298 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6299 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006300 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6301 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006302 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006303 return false;
6304 }
6305
6306 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006307 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006308 {
Jamie Madille0472f32018-11-27 16:32:45 -05006309 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006310 return false;
6311 }
6312
James Darpinian83b2f0e2018-11-27 15:56:01 -08006313 if (context->getExtensions().webglCompatibility &&
6314 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6315 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6316 {
6317 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6318 return false;
6319 }
6320
Jamie Madillbe849e42017-05-02 15:49:00 -04006321 return true;
6322}
6323
Jamie Madill5b772312018-03-08 20:28:32 -05006324bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006325 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006326 GLenum pname,
6327 GLint *params)
6328{
6329 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6330}
6331
6332bool ValidateGetRenderbufferParameteriv(Context *context,
6333 GLenum target,
6334 GLenum pname,
6335 GLint *params)
6336{
6337 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6338}
6339
6340bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params)
6341{
6342 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6343}
6344
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006345bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006346{
6347 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6348}
6349
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006350bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006351{
6352 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6353}
6354
Till Rathmannb8543632018-10-02 19:46:14 +02006355bool ValidateGetTexParameterIivOES(Context *context,
6356 TextureType target,
6357 GLenum pname,
6358 GLint *params)
6359{
6360 if (context->getClientMajorVersion() < 3)
6361 {
Jamie Madille0472f32018-11-27 16:32:45 -05006362 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006363 return false;
6364 }
6365 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6366}
6367
6368bool ValidateGetTexParameterIuivOES(Context *context,
6369 TextureType target,
6370 GLenum pname,
6371 GLuint *params)
6372{
6373 if (context->getClientMajorVersion() < 3)
6374 {
Jamie Madille0472f32018-11-27 16:32:45 -05006375 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006376 return false;
6377 }
6378 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6379}
6380
Jamie Madillbe849e42017-05-02 15:49:00 -04006381bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params)
6382{
6383 return ValidateGetUniformBase(context, program, location);
6384}
6385
6386bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params)
6387{
6388 return ValidateGetUniformBase(context, program, location);
6389}
6390
6391bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6392{
6393 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6394}
6395
6396bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6397{
6398 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6399}
6400
6401bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6402{
6403 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6404}
6405
6406bool ValidateIsEnabled(Context *context, GLenum cap)
6407{
6408 if (!ValidCap(context, cap, true))
6409 {
Jamie Madille0472f32018-11-27 16:32:45 -05006410 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006411 return false;
6412 }
6413
6414 return true;
6415}
6416
6417bool ValidateLinkProgram(Context *context, GLuint program)
6418{
6419 if (context->hasActiveTransformFeedback(program))
6420 {
6421 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006422 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006423 return false;
6424 }
6425
6426 Program *programObject = GetValidProgram(context, program);
6427 if (!programObject)
6428 {
6429 return false;
6430 }
6431
6432 return true;
6433}
6434
Jamie Madill4928b7c2017-06-20 12:57:39 -04006435bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006436 GLint x,
6437 GLint y,
6438 GLsizei width,
6439 GLsizei height,
6440 GLenum format,
6441 GLenum type,
6442 void *pixels)
6443{
6444 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6445 nullptr, pixels);
6446}
6447
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006448bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006449{
Till Rathmannb8543632018-10-02 19:46:14 +02006450 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006451}
6452
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006453bool ValidateTexParameterfv(Context *context,
6454 TextureType target,
6455 GLenum pname,
6456 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006457{
Till Rathmannb8543632018-10-02 19:46:14 +02006458 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006459}
6460
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006461bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006462{
Till Rathmannb8543632018-10-02 19:46:14 +02006463 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006464}
6465
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006466bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006467{
Till Rathmannb8543632018-10-02 19:46:14 +02006468 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6469}
6470
6471bool ValidateTexParameterIivOES(Context *context,
6472 TextureType target,
6473 GLenum pname,
6474 const GLint *params)
6475{
6476 if (context->getClientMajorVersion() < 3)
6477 {
Jamie Madille0472f32018-11-27 16:32:45 -05006478 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006479 return false;
6480 }
6481 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6482}
6483
6484bool ValidateTexParameterIuivOES(Context *context,
6485 TextureType target,
6486 GLenum pname,
6487 const GLuint *params)
6488{
6489 if (context->getClientMajorVersion() < 3)
6490 {
Jamie Madille0472f32018-11-27 16:32:45 -05006491 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006492 return false;
6493 }
6494 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006495}
6496
6497bool ValidateUseProgram(Context *context, GLuint program)
6498{
6499 if (program != 0)
6500 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006501 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006502 if (!programObject)
6503 {
6504 // ES 3.1.0 section 7.3 page 72
6505 if (context->getShader(program))
6506 {
Jamie Madille0472f32018-11-27 16:32:45 -05006507 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006508 return false;
6509 }
6510 else
6511 {
Jamie Madille0472f32018-11-27 16:32:45 -05006512 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006513 return false;
6514 }
6515 }
6516 if (!programObject->isLinked())
6517 {
Jamie Madille0472f32018-11-27 16:32:45 -05006518 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006519 return false;
6520 }
6521 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006522 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006523 {
6524 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006525 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006526 return false;
6527 }
6528
6529 return true;
6530}
6531
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006532bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences)
6533{
6534 if (!context->getExtensions().fence)
6535 {
Jamie Madille0472f32018-11-27 16:32:45 -05006536 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006537 return false;
6538 }
6539
6540 if (n < 0)
6541 {
Jamie Madille0472f32018-11-27 16:32:45 -05006542 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006543 return false;
6544 }
6545
6546 return true;
6547}
6548
6549bool ValidateFinishFenceNV(Context *context, GLuint fence)
6550{
6551 if (!context->getExtensions().fence)
6552 {
Jamie Madille0472f32018-11-27 16:32:45 -05006553 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006554 return false;
6555 }
6556
6557 FenceNV *fenceObject = context->getFenceNV(fence);
6558
6559 if (fenceObject == nullptr)
6560 {
Jamie Madille0472f32018-11-27 16:32:45 -05006561 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006562 return false;
6563 }
6564
6565 if (!fenceObject->isSet())
6566 {
Jamie Madille0472f32018-11-27 16:32:45 -05006567 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006568 return false;
6569 }
6570
6571 return true;
6572}
6573
6574bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences)
6575{
6576 if (!context->getExtensions().fence)
6577 {
Jamie Madille0472f32018-11-27 16:32:45 -05006578 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006579 return false;
6580 }
6581
6582 if (n < 0)
6583 {
Jamie Madille0472f32018-11-27 16:32:45 -05006584 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006585 return false;
6586 }
6587
6588 return true;
6589}
6590
6591bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params)
6592{
6593 if (!context->getExtensions().fence)
6594 {
Jamie Madille0472f32018-11-27 16:32:45 -05006595 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006596 return false;
6597 }
6598
6599 FenceNV *fenceObject = context->getFenceNV(fence);
6600
6601 if (fenceObject == nullptr)
6602 {
Jamie Madille0472f32018-11-27 16:32:45 -05006603 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006604 return false;
6605 }
6606
6607 if (!fenceObject->isSet())
6608 {
Jamie Madille0472f32018-11-27 16:32:45 -05006609 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006610 return false;
6611 }
6612
6613 switch (pname)
6614 {
6615 case GL_FENCE_STATUS_NV:
6616 case GL_FENCE_CONDITION_NV:
6617 break;
6618
6619 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006620 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006621 return false;
6622 }
6623
6624 return true;
6625}
6626
6627bool ValidateGetGraphicsResetStatusEXT(Context *context)
6628{
6629 if (!context->getExtensions().robustness)
6630 {
Jamie Madille0472f32018-11-27 16:32:45 -05006631 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006632 return false;
6633 }
6634
6635 return true;
6636}
6637
6638bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
6639 GLuint shader,
6640 GLsizei bufsize,
6641 GLsizei *length,
6642 GLchar *source)
6643{
6644 if (!context->getExtensions().translatedShaderSource)
6645 {
Jamie Madille0472f32018-11-27 16:32:45 -05006646 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006647 return false;
6648 }
6649
6650 if (bufsize < 0)
6651 {
Jamie Madille0472f32018-11-27 16:32:45 -05006652 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006653 return false;
6654 }
6655
6656 Shader *shaderObject = context->getShader(shader);
6657
6658 if (!shaderObject)
6659 {
Jamie Madille0472f32018-11-27 16:32:45 -05006660 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006661 return false;
6662 }
6663
6664 return true;
6665}
6666
6667bool ValidateIsFenceNV(Context *context, GLuint fence)
6668{
6669 if (!context->getExtensions().fence)
6670 {
Jamie Madille0472f32018-11-27 16:32:45 -05006671 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006672 return false;
6673 }
6674
6675 return true;
6676}
6677
Jamie Madill007530e2017-12-28 14:27:04 -05006678bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition)
6679{
6680 if (!context->getExtensions().fence)
6681 {
Jamie Madille0472f32018-11-27 16:32:45 -05006682 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006683 return false;
6684 }
6685
6686 if (condition != GL_ALL_COMPLETED_NV)
6687 {
Jamie Madille0472f32018-11-27 16:32:45 -05006688 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05006689 return false;
6690 }
6691
6692 FenceNV *fenceObject = context->getFenceNV(fence);
6693
6694 if (fenceObject == nullptr)
6695 {
Jamie Madille0472f32018-11-27 16:32:45 -05006696 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006697 return false;
6698 }
6699
6700 return true;
6701}
6702
6703bool ValidateTestFenceNV(Context *context, GLuint fence)
6704{
6705 if (!context->getExtensions().fence)
6706 {
Jamie Madille0472f32018-11-27 16:32:45 -05006707 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006708 return false;
6709 }
6710
6711 FenceNV *fenceObject = context->getFenceNV(fence);
6712
6713 if (fenceObject == nullptr)
6714 {
Jamie Madille0472f32018-11-27 16:32:45 -05006715 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05006716 return false;
6717 }
6718
6719 if (fenceObject->isSet() != GL_TRUE)
6720 {
Jamie Madille0472f32018-11-27 16:32:45 -05006721 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05006722 return false;
6723 }
6724
6725 return true;
6726}
6727
6728bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006729 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05006730 GLsizei levels,
6731 GLenum internalformat,
6732 GLsizei width,
6733 GLsizei height)
6734{
6735 if (!context->getExtensions().textureStorage)
6736 {
Jamie Madille0472f32018-11-27 16:32:45 -05006737 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006738 return false;
6739 }
6740
6741 if (context->getClientMajorVersion() < 3)
6742 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006743 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05006744 height);
6745 }
6746
6747 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006748 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05006749 1);
6750}
6751
6752bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
6753{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006754 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05006755 {
Jamie Madille0472f32018-11-27 16:32:45 -05006756 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006757 return false;
6758 }
6759
6760 if (index >= MAX_VERTEX_ATTRIBS)
6761 {
Jamie Madille0472f32018-11-27 16:32:45 -05006762 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05006763 return false;
6764 }
6765
6766 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
6767 {
6768 if (index == 0 && divisor != 0)
6769 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006770 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05006771
6772 // We also output an error message to the debugger window if tracing is active, so
6773 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006774 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05006775 return false;
6776 }
6777 }
6778
6779 return true;
6780}
6781
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05006782bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
6783{
6784 if (!context->getExtensions().instancedArraysEXT)
6785 {
6786 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6787 return false;
6788 }
6789
6790 if (index >= MAX_VERTEX_ATTRIBS)
6791 {
6792 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
6793 return false;
6794 }
6795
6796 return true;
6797}
6798
Jamie Madill007530e2017-12-28 14:27:04 -05006799bool ValidateTexImage3DOES(Context *context,
6800 GLenum target,
6801 GLint level,
6802 GLenum internalformat,
6803 GLsizei width,
6804 GLsizei height,
6805 GLsizei depth,
6806 GLint border,
6807 GLenum format,
6808 GLenum type,
6809 const void *pixels)
6810{
6811 UNIMPLEMENTED(); // FIXME
6812 return false;
6813}
6814
6815bool ValidatePopGroupMarkerEXT(Context *context)
6816{
6817 if (!context->getExtensions().debugMarker)
6818 {
6819 // The debug marker calls should not set error state
6820 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05006821 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05006822 return false;
6823 }
6824
6825 return true;
6826}
6827
Jamie Madillfa920eb2018-01-04 11:45:50 -05006828bool ValidateTexStorage1DEXT(Context *context,
6829 GLenum target,
6830 GLsizei levels,
6831 GLenum internalformat,
6832 GLsizei width)
6833{
6834 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05006835 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006836 return false;
6837}
6838
6839bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006840 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05006841 GLsizei levels,
6842 GLenum internalformat,
6843 GLsizei width,
6844 GLsizei height,
6845 GLsizei depth)
6846{
6847 if (!context->getExtensions().textureStorage)
6848 {
Jamie Madille0472f32018-11-27 16:32:45 -05006849 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006850 return false;
6851 }
6852
6853 if (context->getClientMajorVersion() < 3)
6854 {
Jamie Madille0472f32018-11-27 16:32:45 -05006855 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05006856 return false;
6857 }
6858
6859 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
6860 depth);
6861}
6862
jchen1082af6202018-06-22 10:59:52 +08006863bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
6864{
6865 if (!context->getExtensions().parallelShaderCompile)
6866 {
Jamie Madille0472f32018-11-27 16:32:45 -05006867 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08006868 return false;
6869 }
6870 return true;
6871}
6872
Austin Eng1bf18ce2018-10-19 15:34:02 -07006873bool ValidateMultiDrawArraysANGLE(Context *context,
6874 PrimitiveMode mode,
6875 const GLint *firsts,
6876 const GLsizei *counts,
6877 GLsizei drawcount)
6878{
6879 if (!context->getExtensions().multiDraw)
6880 {
Jamie Madille0472f32018-11-27 16:32:45 -05006881 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07006882 return false;
6883 }
6884 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
6885 {
6886 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
6887 {
6888 return false;
6889 }
6890 }
6891 return true;
6892}
6893
6894bool ValidateMultiDrawElementsANGLE(Context *context,
6895 PrimitiveMode mode,
6896 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05006897 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08006898 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07006899 GLsizei drawcount)
6900{
6901 if (!context->getExtensions().multiDraw)
6902 {
Jamie Madille0472f32018-11-27 16:32:45 -05006903 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07006904 return false;
6905 }
6906 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
6907 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08006908 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07006909 {
6910 return false;
6911 }
6912 }
6913 return true;
6914}
6915
Jeff Gilbert465d6092019-01-02 16:21:18 -08006916bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked)
6917{
6918 if (!context->getExtensions().provokingVertex)
6919 {
6920 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6921 return false;
6922 }
6923
6924 switch (modePacked)
6925 {
6926 case ProvokingVertex::FirstVertexConvention:
6927 case ProvokingVertex::LastVertexConvention:
6928 break;
6929 default:
6930 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
6931 return false;
6932 }
6933
6934 return true;
6935}
6936
Jamie Madilla5410482019-01-31 19:55:55 -05006937void RecordBindTextureTypeError(Context *context, TextureType target)
6938{
6939 ASSERT(!context->getStateCache().isValidBindTextureType(target));
6940
6941 switch (target)
6942 {
6943 case TextureType::Rectangle:
6944 ASSERT(!context->getExtensions().textureRectangle);
6945 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
6946 break;
6947
6948 case TextureType::_3D:
6949 case TextureType::_2DArray:
6950 ASSERT(context->getClientMajorVersion() < 3);
6951 context->validationError(GL_INVALID_ENUM, kES3Required);
6952 break;
6953
6954 case TextureType::_2DMultisample:
6955 ASSERT(context->getClientVersion() < Version(3, 1) &&
6956 !context->getExtensions().textureMultisample);
6957 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
6958 break;
6959
6960 case TextureType::_2DMultisampleArray:
6961 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
6962 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
6963 break;
6964
6965 case TextureType::External:
6966 ASSERT(!context->getExtensions().eglImageExternal &&
6967 !context->getExtensions().eglStreamConsumerExternal);
6968 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
6969 break;
6970
6971 default:
6972 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
6973 }
6974}
6975
Jamie Madillc29968b2016-01-20 11:17:23 -05006976} // namespace gl