blob: 3b8eebdc70edda555b2f7da760cbf2f60d5db28b [file] [log] [blame]
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001//
Stuart Morgan9d737962019-08-14 12:25:12 -07002// Copyright 2013 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,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -060073 PathID pathBase)
Sami Väisänend59ca052016-06-21 16:10:00 +030074{
75 const auto *array = static_cast<const T *>(paths);
76
77 for (GLsizei i = 0; i < numPaths; ++i)
78 {
Jiacheng Lu7b5744f2019-08-22 16:26:35 -060079 const GLuint pathName = array[i] + pathBase.value;
80 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,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -060093 PathID pathBase,
Sami Väisänend59ca052016-06-21 16:10:00 +030094 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 =
Jamie Madill4e71b2b2019-07-08 13:23:38 -0400495 framebuffer->getReadColorAttachment()->getFormat().info->sizedInternalFormat;
Jamie Madillbe849e42017-05-02 15:49:00 -0400496 const auto &formatInfo = *textureFormat.info;
497
498 // [OpenGL ES 2.0.24] table 3.9
499 if (isSubImage)
500 {
501 switch (formatInfo.format)
502 {
503 case GL_ALPHA:
504 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400505 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
506 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400507 {
Jamie Madille0472f32018-11-27 16:32:45 -0500508 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400509 return false;
510 }
511 break;
512 case GL_LUMINANCE:
513 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
514 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
515 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400516 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT &&
517 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400518 {
Jamie Madille0472f32018-11-27 16:32:45 -0500519 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400520 return false;
521 }
522 break;
523 case GL_RED_EXT:
524 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
525 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
526 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
527 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F &&
528 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400529 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
530 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400531 {
Jamie Madille0472f32018-11-27 16:32:45 -0500532 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400533 return false;
534 }
535 break;
536 case GL_RG_EXT:
537 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
538 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
539 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES &&
540 colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400541 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
542 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400543 {
Jamie Madille0472f32018-11-27 16:32:45 -0500544 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400545 return false;
546 }
547 break;
548 case GL_RGB:
549 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
550 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
551 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400552 colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT &&
553 colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400554 {
Jamie Madille0472f32018-11-27 16:32:45 -0500555 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400556 return false;
557 }
558 break;
559 case GL_LUMINANCE_ALPHA:
560 case GL_RGBA:
561 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
Geoff Lang0c09e262017-05-03 09:43:13 -0400562 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F &&
563 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX)
Jamie Madillbe849e42017-05-02 15:49:00 -0400564 {
Jamie Madille0472f32018-11-27 16:32:45 -0500565 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400566 return false;
567 }
568 break;
569 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
570 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
571 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
572 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
573 case GL_ETC1_RGB8_OES:
574 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
575 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
576 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
577 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
578 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
Olli Etuahof2ed2992018-10-04 13:54:42 +0300579 case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT:
580 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:
581 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT:
582 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT:
Jamie Madille0472f32018-11-27 16:32:45 -0500583 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400584 return false;
585 case GL_DEPTH_COMPONENT:
586 case GL_DEPTH_STENCIL_OES:
Jamie Madille0472f32018-11-27 16:32:45 -0500587 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400588 return false;
589 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500590 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400591 return false;
592 }
593
594 if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat)
595 {
Jamie Madille0472f32018-11-27 16:32:45 -0500596 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400597 return false;
598 }
599 }
600 else
601 {
602 switch (internalformat)
603 {
604 case GL_ALPHA:
605 if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 &&
606 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
607 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
608 {
Jamie Madille0472f32018-11-27 16:32:45 -0500609 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400610 return false;
611 }
612 break;
613 case GL_LUMINANCE:
614 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
615 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
616 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
617 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
618 colorbufferFormat != GL_BGR5_A1_ANGLEX)
619 {
Jamie Madille0472f32018-11-27 16:32:45 -0500620 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400621 return false;
622 }
623 break;
624 case GL_RED_EXT:
625 if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT &&
626 colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
627 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
628 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
629 colorbufferFormat != GL_BGR5_A1_ANGLEX)
630 {
Jamie Madille0472f32018-11-27 16:32:45 -0500631 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400632 return false;
633 }
634 break;
635 case GL_RG_EXT:
636 if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 &&
637 colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 &&
638 colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT &&
639 colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX)
640 {
Jamie Madille0472f32018-11-27 16:32:45 -0500641 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400642 return false;
643 }
644 break;
645 case GL_RGB:
646 if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES &&
647 colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
648 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
649 colorbufferFormat != GL_BGR5_A1_ANGLEX)
650 {
Jamie Madille0472f32018-11-27 16:32:45 -0500651 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400652 return false;
653 }
654 break;
655 case GL_LUMINANCE_ALPHA:
656 case GL_RGBA:
657 if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 &&
658 colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES &&
659 colorbufferFormat != GL_BGR5_A1_ANGLEX)
660 {
Jamie Madille0472f32018-11-27 16:32:45 -0500661 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400662 return false;
663 }
664 break;
665 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
666 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
667 if (context->getExtensions().textureCompressionDXT1)
668 {
Jamie Madille0472f32018-11-27 16:32:45 -0500669 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400670 return false;
671 }
672 else
673 {
Jamie Madille0472f32018-11-27 16:32:45 -0500674 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400675 return false;
676 }
677 break;
678 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
679 if (context->getExtensions().textureCompressionDXT3)
680 {
Jamie Madille0472f32018-11-27 16:32:45 -0500681 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400682 return false;
683 }
684 else
685 {
Jamie Madille0472f32018-11-27 16:32:45 -0500686 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400687 return false;
688 }
689 break;
690 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
691 if (context->getExtensions().textureCompressionDXT5)
692 {
Jamie Madille0472f32018-11-27 16:32:45 -0500693 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400694 return false;
695 }
696 else
697 {
Jamie Madille0472f32018-11-27 16:32:45 -0500698 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400699 return false;
700 }
701 break;
702 case GL_ETC1_RGB8_OES:
703 if (context->getExtensions().compressedETC1RGB8Texture)
704 {
Jamie Madille0472f32018-11-27 16:32:45 -0500705 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400706 return false;
707 }
708 else
709 {
Jamie Madille0472f32018-11-27 16:32:45 -0500710 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400711 return false;
712 }
713 break;
714 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
715 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
716 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
717 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
718 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
719 if (context->getExtensions().lossyETCDecode)
720 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500721 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400722 return false;
723 }
724 else
725 {
Jamie Madillc3e37312018-11-30 15:25:39 -0500726 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400727 return false;
728 }
729 break;
730 case GL_DEPTH_COMPONENT:
731 case GL_DEPTH_COMPONENT16:
732 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600733 if (context->getExtensions().depthTextureAny())
Jamie Madillbe849e42017-05-02 15:49:00 -0400734 {
Jamie Madille0472f32018-11-27 16:32:45 -0500735 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400736 return false;
737 }
738 else
739 {
Jamie Madille0472f32018-11-27 16:32:45 -0500740 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400741 return false;
742 }
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600743 break;
744 case GL_DEPTH_STENCIL_OES:
745 case GL_DEPTH24_STENCIL8_OES:
746 if (context->getExtensions().depthTextureAny() ||
747 context->getExtensions().packedDepthStencil)
748 {
749 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
750 return false;
751 }
752 else
753 {
754 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
755 return false;
756 }
757 break;
Jamie Madillbe849e42017-05-02 15:49:00 -0400758 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500759 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400760 return false;
761 }
762 }
763
764 // If width or height is zero, it is a no-op. Return false without setting an error.
765 return (width > 0 && height > 0);
766}
767
768bool ValidCap(const Context *context, GLenum cap, bool queryOnly)
769{
770 switch (cap)
771 {
772 // EXT_multisample_compatibility
773 case GL_MULTISAMPLE_EXT:
774 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
775 return context->getExtensions().multisampleCompatibility;
776
777 case GL_CULL_FACE:
778 case GL_POLYGON_OFFSET_FILL:
779 case GL_SAMPLE_ALPHA_TO_COVERAGE:
780 case GL_SAMPLE_COVERAGE:
781 case GL_SCISSOR_TEST:
782 case GL_STENCIL_TEST:
783 case GL_DEPTH_TEST:
784 case GL_BLEND:
785 case GL_DITHER:
786 return true;
787
788 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
789 case GL_RASTERIZER_DISCARD:
790 return (context->getClientMajorVersion() >= 3);
791
792 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
793 case GL_DEBUG_OUTPUT:
794 return context->getExtensions().debug;
795
796 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
797 return queryOnly && context->getExtensions().bindGeneratesResource;
798
799 case GL_CLIENT_ARRAYS_ANGLE:
800 return queryOnly && context->getExtensions().clientArrays;
801
802 case GL_FRAMEBUFFER_SRGB_EXT:
803 return context->getExtensions().sRGBWriteControl;
804
805 case GL_SAMPLE_MASK:
806 return context->getClientVersion() >= Version(3, 1);
807
Geoff Langb433e872017-10-05 14:01:47 -0400808 case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
Jamie Madillbe849e42017-05-02 15:49:00 -0400809 return queryOnly && context->getExtensions().robustResourceInitialization;
810
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700811 // GLES1 emulation: GLES1-specific caps
812 case GL_ALPHA_TEST:
Lingfeng Yang01074432018-04-16 10:19:51 -0700813 case GL_VERTEX_ARRAY:
814 case GL_NORMAL_ARRAY:
815 case GL_COLOR_ARRAY:
816 case GL_TEXTURE_COORD_ARRAY:
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700817 case GL_TEXTURE_2D:
Lingfeng Yangd0febe72018-05-17 22:36:52 -0700818 case GL_LIGHTING:
819 case GL_LIGHT0:
820 case GL_LIGHT1:
821 case GL_LIGHT2:
822 case GL_LIGHT3:
823 case GL_LIGHT4:
824 case GL_LIGHT5:
825 case GL_LIGHT6:
826 case GL_LIGHT7:
827 case GL_NORMALIZE:
828 case GL_RESCALE_NORMAL:
829 case GL_COLOR_MATERIAL:
Lingfeng Yang060088a2018-05-30 20:40:57 -0700830 case GL_CLIP_PLANE0:
831 case GL_CLIP_PLANE1:
832 case GL_CLIP_PLANE2:
833 case GL_CLIP_PLANE3:
834 case GL_CLIP_PLANE4:
835 case GL_CLIP_PLANE5:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -0700836 case GL_FOG:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700837 case GL_POINT_SMOOTH:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -0700838 case GL_LINE_SMOOTH:
839 case GL_COLOR_LOGIC_OP:
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700840 return context->getClientVersion() < Version(2, 0);
Lingfeng Yang01074432018-04-16 10:19:51 -0700841 case GL_POINT_SIZE_ARRAY_OES:
842 return context->getClientVersion() < Version(2, 0) &&
843 context->getExtensions().pointSizeArray;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700844 case GL_TEXTURE_CUBE_MAP:
845 return context->getClientVersion() < Version(2, 0) &&
846 context->getExtensions().textureCubeMap;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700847 case GL_POINT_SPRITE_OES:
848 return context->getClientVersion() < Version(2, 0) &&
849 context->getExtensions().pointSprite;
Jamie Madillbe849e42017-05-02 15:49:00 -0400850 default:
851 return false;
852 }
853}
854
Geoff Langfc32e8b2017-05-31 14:16:59 -0400855// Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section
856// 3.1.
Geoff Langcab92ee2017-07-19 17:32:07 -0400857bool IsValidESSLCharacter(unsigned char c)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400858{
859 // Printing characters are valid except " $ ` @ \ ' DEL.
Geoff Langcab92ee2017-07-19 17:32:07 -0400860 if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' &&
861 c != '\'')
Geoff Langfc32e8b2017-05-31 14:16:59 -0400862 {
863 return true;
864 }
865
866 // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid.
867 if (c >= 9 && c <= 13)
868 {
869 return true;
870 }
871
872 return false;
873}
874
Geoff Langcab92ee2017-07-19 17:32:07 -0400875bool IsValidESSLString(const char *str, size_t len)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400876{
Geoff Langa71a98e2017-06-19 15:15:00 -0400877 for (size_t i = 0; i < len; i++)
878 {
Geoff Langcab92ee2017-07-19 17:32:07 -0400879 if (!IsValidESSLCharacter(str[i]))
Geoff Langa71a98e2017-06-19 15:15:00 -0400880 {
881 return false;
882 }
883 }
884
885 return true;
Geoff Langfc32e8b2017-05-31 14:16:59 -0400886}
887
Geoff Langcab92ee2017-07-19 17:32:07 -0400888bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed)
889{
890 enum class ParseState
891 {
892 // Have not seen an ASCII non-whitespace character yet on
893 // this line. Possible that we might see a preprocessor
894 // directive.
895 BEGINING_OF_LINE,
896
897 // Have seen at least one ASCII non-whitespace character
898 // on this line.
899 MIDDLE_OF_LINE,
900
901 // Handling a preprocessor directive. Passes through all
902 // characters up to the end of the line. Disables comment
903 // processing.
904 IN_PREPROCESSOR_DIRECTIVE,
905
906 // Handling a single-line comment. The comment text is
907 // replaced with a single space.
908 IN_SINGLE_LINE_COMMENT,
909
910 // Handling a multi-line comment. Newlines are passed
911 // through to preserve line numbers.
912 IN_MULTI_LINE_COMMENT
913 };
914
915 ParseState state = ParseState::BEGINING_OF_LINE;
916 size_t pos = 0;
917
918 while (pos < len)
919 {
920 char c = str[pos];
921 char next = pos + 1 < len ? str[pos + 1] : 0;
922
923 // Check for newlines
924 if (c == '\n' || c == '\r')
925 {
926 if (state != ParseState::IN_MULTI_LINE_COMMENT)
927 {
928 state = ParseState::BEGINING_OF_LINE;
929 }
930
931 pos++;
932 continue;
933 }
934
935 switch (state)
936 {
937 case ParseState::BEGINING_OF_LINE:
938 if (c == ' ')
939 {
940 // Maintain the BEGINING_OF_LINE state until a non-space is seen
941 pos++;
942 }
943 else if (c == '#')
944 {
945 state = ParseState::IN_PREPROCESSOR_DIRECTIVE;
946 pos++;
947 }
948 else
949 {
950 // Don't advance, re-process this character with the MIDDLE_OF_LINE state
951 state = ParseState::MIDDLE_OF_LINE;
952 }
953 break;
954
955 case ParseState::MIDDLE_OF_LINE:
956 if (c == '/' && next == '/')
957 {
958 state = ParseState::IN_SINGLE_LINE_COMMENT;
959 pos++;
960 }
961 else if (c == '/' && next == '*')
962 {
963 state = ParseState::IN_MULTI_LINE_COMMENT;
964 pos++;
965 }
966 else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r'))
967 {
968 // Skip line continuation characters
969 }
970 else if (!IsValidESSLCharacter(c))
971 {
972 return false;
973 }
974 pos++;
975 break;
976
977 case ParseState::IN_PREPROCESSOR_DIRECTIVE:
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -0700978 // Line-continuation characters may not be permitted.
979 // Otherwise, just pass it through. Do not parse comments in this state.
980 if (!lineContinuationAllowed && c == '\\')
981 {
982 return false;
983 }
Geoff Langcab92ee2017-07-19 17:32:07 -0400984 pos++;
985 break;
986
987 case ParseState::IN_SINGLE_LINE_COMMENT:
988 // Line-continuation characters are processed before comment processing.
989 // Advance string if a new line character is immediately behind
990 // line-continuation character.
991 if (c == '\\' && (next == '\n' || next == '\r'))
992 {
993 pos++;
994 }
995 pos++;
996 break;
997
998 case ParseState::IN_MULTI_LINE_COMMENT:
999 if (c == '*' && next == '/')
1000 {
1001 state = ParseState::MIDDLE_OF_LINE;
1002 pos++;
1003 }
1004 pos++;
1005 break;
1006 }
1007 }
1008
1009 return true;
1010}
1011
Jamie Madill5b772312018-03-08 20:28:32 -05001012bool ValidateWebGLNamePrefix(Context *context, const GLchar *name)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001013{
1014 ASSERT(context->isWebGL());
1015
1016 // WebGL 1.0 [Section 6.16] GLSL Constructs
1017 // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL.
1018 if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0)
1019 {
Jamie Madille0472f32018-11-27 16:32:45 -05001020 context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001021 return false;
1022 }
1023
1024 return true;
1025}
1026
Jamie Madill5b772312018-03-08 20:28:32 -05001027bool ValidateWebGLNameLength(Context *context, size_t length)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001028{
1029 ASSERT(context->isWebGL());
1030
1031 if (context->isWebGL1() && length > 256)
1032 {
1033 // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths
1034 // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute
1035 // locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001036 context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001037
1038 return false;
1039 }
1040 else if (length > 1024)
1041 {
1042 // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of
1043 // uniform and attribute locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001044 context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001045 return false;
1046 }
1047
1048 return true;
1049}
1050
Jamie Madill007530e2017-12-28 14:27:04 -05001051bool ValidateMatrixMode(Context *context, GLenum matrixMode)
1052{
1053 if (!context->getExtensions().pathRendering)
1054 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001055 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05001056 return false;
1057 }
1058
1059 if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM)
1060 {
Jamie Madille0472f32018-11-27 16:32:45 -05001061 context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode);
Jamie Madill007530e2017-12-28 14:27:04 -05001062 return false;
1063 }
1064 return true;
1065}
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001066
1067bool ValidBlendFunc(const Context *context, GLenum val)
1068{
1069 const gl::Extensions &ext = context->getExtensions();
1070
1071 // these are always valid for src and dst.
1072 switch (val)
1073 {
1074 case GL_ZERO:
1075 case GL_ONE:
1076 case GL_SRC_COLOR:
1077 case GL_ONE_MINUS_SRC_COLOR:
1078 case GL_DST_COLOR:
1079 case GL_ONE_MINUS_DST_COLOR:
1080 case GL_SRC_ALPHA:
1081 case GL_ONE_MINUS_SRC_ALPHA:
1082 case GL_DST_ALPHA:
1083 case GL_ONE_MINUS_DST_ALPHA:
1084 case GL_CONSTANT_COLOR:
1085 case GL_ONE_MINUS_CONSTANT_COLOR:
1086 case GL_CONSTANT_ALPHA:
1087 case GL_ONE_MINUS_CONSTANT_ALPHA:
1088 return true;
1089
1090 // EXT_blend_func_extended.
1091 case GL_SRC1_COLOR_EXT:
1092 case GL_SRC1_ALPHA_EXT:
1093 case GL_ONE_MINUS_SRC1_COLOR_EXT:
1094 case GL_ONE_MINUS_SRC1_ALPHA_EXT:
1095 case GL_SRC_ALPHA_SATURATE_EXT:
1096 return ext.blendFuncExtended;
1097
1098 default:
1099 return false;
1100 }
1101}
1102
1103bool ValidSrcBlendFunc(const Context *context, GLenum val)
1104{
1105 if (ValidBlendFunc(context, val))
1106 return true;
1107
1108 if (val == GL_SRC_ALPHA_SATURATE)
1109 return true;
1110
1111 return false;
1112}
1113
1114bool ValidDstBlendFunc(const Context *context, GLenum val)
1115{
1116 if (ValidBlendFunc(context, val))
1117 return true;
1118
1119 if (val == GL_SRC_ALPHA_SATURATE)
1120 {
1121 if (context->getClientMajorVersion() >= 3)
1122 return true;
1123 }
1124
1125 return false;
1126}
Michael Spangab6a59b2019-05-21 21:26:26 -04001127
1128bool IsValidImageLayout(ImageLayout layout)
1129{
1130 switch (layout)
1131 {
Michael Spang6c824a12019-06-18 15:43:33 -04001132 case ImageLayout::Undefined:
Michael Spangab6a59b2019-05-21 21:26:26 -04001133 case ImageLayout::General:
1134 case ImageLayout::ColorAttachment:
1135 case ImageLayout::DepthStencilAttachment:
1136 case ImageLayout::DepthStencilReadOnlyAttachment:
1137 case ImageLayout::ShaderReadOnly:
1138 case ImageLayout::TransferSrc:
1139 case ImageLayout::TransferDst:
1140 case ImageLayout::DepthReadOnlyStencilAttachment:
1141 case ImageLayout::DepthAttachmentStencilReadOnly:
1142 return true;
1143
1144 default:
1145 return false;
1146 }
1147}
1148
Geoff Langff5b2d52016-09-07 11:32:23 -04001149bool ValidateES2TexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001150 TextureTarget target,
Geoff Langff5b2d52016-09-07 11:32:23 -04001151 GLint level,
1152 GLenum internalformat,
1153 bool isCompressed,
1154 bool isSubImage,
1155 GLint xoffset,
1156 GLint yoffset,
1157 GLsizei width,
1158 GLsizei height,
1159 GLint border,
1160 GLenum format,
1161 GLenum type,
1162 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001163 const void *pixels)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001164{
Jamie Madill6f38f822014-06-06 17:12:20 -04001165 if (!ValidTexture2DDestinationTarget(context, target))
1166 {
Jamie Madille0472f32018-11-27 16:32:45 -05001167 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001168 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001169 }
1170
Geoff Lang857880e2019-05-27 13:39:15 -04001171 return ValidateES2TexImageParametersBase(context, target, level, internalformat, isCompressed,
1172 isSubImage, xoffset, yoffset, width, height, border,
1173 format, type, imageSize, pixels);
1174}
1175
1176} // anonymous namespace
1177
1178bool ValidateES2TexImageParametersBase(Context *context,
1179 TextureTarget target,
1180 GLint level,
1181 GLenum internalformat,
1182 bool isCompressed,
1183 bool isSubImage,
1184 GLint xoffset,
1185 GLint yoffset,
1186 GLsizei width,
1187 GLsizei height,
1188 GLint border,
1189 GLenum format,
1190 GLenum type,
1191 GLsizei imageSize,
1192 const void *pixels)
1193{
1194
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001195 TextureType texType = TextureTargetToType(target);
1196 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001197 {
Jamie Madill610640f2018-11-21 17:28:41 -05001198 // Error already handled.
Geoff Langb1196682014-07-23 13:47:29 -04001199 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001200 }
1201
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001202 if (!ValidMipLevel(context, texType, level))
Brandon Jones6cad5662017-06-14 13:25:13 -07001203 {
Jamie Madille0472f32018-11-27 16:32:45 -05001204 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Brandon Jones6cad5662017-06-14 13:25:13 -07001205 return false;
1206 }
1207
1208 if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width ||
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001209 std::numeric_limits<GLsizei>::max() - yoffset < height)
1210 {
Jamie Madille0472f32018-11-27 16:32:45 -05001211 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Geoff Langb1196682014-07-23 13:47:29 -04001212 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001213 }
1214
Geoff Langaae65a42014-05-26 12:43:44 -04001215 const gl::Caps &caps = context->getCaps();
1216
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001217 switch (texType)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001218 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001219 case TextureType::_2D:
Geoff Lang857880e2019-05-27 13:39:15 -04001220 case TextureType::External:
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001221 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
1222 static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
1223 {
Jamie Madille0472f32018-11-27 16:32:45 -05001224 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001225 return false;
1226 }
1227 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001228
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001229 case TextureType::Rectangle:
1230 ASSERT(level == 0);
1231 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1232 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1233 {
Jamie Madille0472f32018-11-27 16:32:45 -05001234 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001235 return false;
1236 }
1237 if (isCompressed)
1238 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001239 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001240 return false;
1241 }
1242 break;
1243
1244 case TextureType::CubeMap:
1245 if (!isSubImage && width != height)
1246 {
Jamie Madille0472f32018-11-27 16:32:45 -05001247 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001248 return false;
1249 }
1250
1251 if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) ||
1252 static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level))
1253 {
Jamie Madille0472f32018-11-27 16:32:45 -05001254 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001255 return false;
1256 }
1257 break;
1258
1259 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001260 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langa9be0dc2014-12-17 12:34:40 -05001261 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001262 }
1263
Jamie Madillcfc73cc2019-04-08 16:26:51 -04001264 gl::Texture *texture = context->getTextureByType(texType);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001265 if (!texture)
1266 {
Jamie Madille0472f32018-11-27 16:32:45 -05001267 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Geoff Langb1196682014-07-23 13:47:29 -04001268 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001269 }
1270
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001271 // Verify zero border
1272 if (border != 0)
1273 {
Jamie Madille0472f32018-11-27 16:32:45 -05001274 context->validationError(GL_INVALID_VALUE, kInvalidBorder);
Geoff Langb1196682014-07-23 13:47:29 -04001275 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001276 }
1277
Tim Van Patten208af3e2019-03-19 09:15:55 -06001278 bool nonEqualFormatsAllowed = false;
1279
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001280 if (isCompressed)
1281 {
tmartino0ccd5ae2015-10-01 14:33:14 -04001282 GLenum actualInternalFormat =
Geoff Langca271392017-04-05 12:30:00 -04001283 isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat
1284 : internalformat;
Geoff Lange88e4542018-05-03 15:05:57 -04001285
1286 const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat);
1287
1288 if (!internalFormatInfo.compressed)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001289 {
Jamie Madille0472f32018-11-27 16:32:45 -05001290 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001291 return false;
1292 }
1293
1294 if (!internalFormatInfo.textureSupport(context->getClientVersion(),
1295 context->getExtensions()))
1296 {
Jamie Madille0472f32018-11-27 16:32:45 -05001297 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001298 return false;
tmartino0ccd5ae2015-10-01 14:33:14 -04001299 }
Geoff Lang966c9402017-04-18 12:38:27 -04001300
1301 if (isSubImage)
tmartino0ccd5ae2015-10-01 14:33:14 -04001302 {
Geoff Lange88e4542018-05-03 15:05:57 -04001303 // From the OES_compressed_ETC1_RGB8_texture spec:
1304 // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or
1305 // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format
1306 // ETC1_RGB8_OES.
1307 if (actualInternalFormat == GL_ETC1_RGB8_OES)
1308 {
Jamie Madille0472f32018-11-27 16:32:45 -05001309 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001310 return false;
1311 }
1312
Geoff Langd9c17102019-07-10 14:56:26 -04001313 if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, 0,
1314 width, height, 1, texture->getWidth(target, level),
1315 texture->getHeight(target, level),
1316 texture->getDepth(target, level)))
Geoff Lang966c9402017-04-18 12:38:27 -04001317 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001318 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001319 return false;
1320 }
1321
1322 if (format != actualInternalFormat)
1323 {
Jamie Madille0472f32018-11-27 16:32:45 -05001324 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Geoff Lang966c9402017-04-18 12:38:27 -04001325 return false;
1326 }
1327 }
1328 else
1329 {
Geoff Langd9c17102019-07-10 14:56:26 -04001330 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height, 1))
Geoff Lang966c9402017-04-18 12:38:27 -04001331 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001332 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001333 return false;
1334 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001335 }
1336 }
1337 else
1338 {
1339 // validate <type> by itself (used as secondary key below)
1340 switch (type)
1341 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001342 case GL_UNSIGNED_BYTE:
1343 case GL_UNSIGNED_SHORT_5_6_5:
1344 case GL_UNSIGNED_SHORT_4_4_4_4:
1345 case GL_UNSIGNED_SHORT_5_5_5_1:
1346 case GL_UNSIGNED_SHORT:
1347 case GL_UNSIGNED_INT:
1348 case GL_UNSIGNED_INT_24_8_OES:
1349 case GL_HALF_FLOAT_OES:
1350 case GL_FLOAT:
1351 break;
Jaedon Lee3b468852019-07-30 16:50:36 +09001352 case GL_UNSIGNED_INT_2_10_10_10_REV_EXT:
1353 if (!context->getExtensions().textureFormat2101010REV)
1354 {
1355 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1356 return false;
1357 }
1358 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001359 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001360 context->validationError(GL_INVALID_ENUM, kInvalidType);
He Yunchaoced53ae2016-11-29 15:00:51 +08001361 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001362 }
1363
1364 // validate <format> + <type> combinations
1365 // - invalid <format> -> sets INVALID_ENUM
1366 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
1367 switch (format)
1368 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001369 case GL_ALPHA:
1370 case GL_LUMINANCE:
1371 case GL_LUMINANCE_ALPHA:
1372 switch (type)
1373 {
1374 case GL_UNSIGNED_BYTE:
1375 case GL_FLOAT:
1376 case GL_HALF_FLOAT_OES:
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 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001382 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001383 case GL_RED:
1384 case GL_RG:
1385 if (!context->getExtensions().textureRG)
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:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001393 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001394 case GL_FLOAT:
1395 case GL_HALF_FLOAT_OES:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001396 if (!context->getExtensions().textureFloat)
1397 {
Jamie Madille0472f32018-11-27 16:32:45 -05001398 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001399 return false;
1400 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001401 break;
1402 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001403 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001404 return false;
1405 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001406 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001407 case GL_RGB:
1408 switch (type)
1409 {
1410 case GL_UNSIGNED_BYTE:
1411 case GL_UNSIGNED_SHORT_5_6_5:
Jaedon Lee3b468852019-07-30 16:50:36 +09001412 case GL_UNSIGNED_INT_2_10_10_10_REV_EXT:
He Yunchaoced53ae2016-11-29 15:00:51 +08001413 case GL_FLOAT:
1414 case GL_HALF_FLOAT_OES:
1415 break;
1416 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001417 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001418 return false;
1419 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001420 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001421 case GL_RGBA:
1422 switch (type)
1423 {
1424 case GL_UNSIGNED_BYTE:
1425 case GL_UNSIGNED_SHORT_4_4_4_4:
1426 case GL_UNSIGNED_SHORT_5_5_5_1:
1427 case GL_FLOAT:
1428 case GL_HALF_FLOAT_OES:
Jaedon Lee3b468852019-07-30 16:50:36 +09001429 case GL_UNSIGNED_INT_2_10_10_10_REV_EXT:
He Yunchaoced53ae2016-11-29 15:00:51 +08001430 break;
1431 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001432 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001433 return false;
1434 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001435 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001436 case GL_BGRA_EXT:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001437 if (!context->getExtensions().textureFormatBGRA8888)
1438 {
Jamie Madille0472f32018-11-27 16:32:45 -05001439 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001440 return false;
1441 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001442 switch (type)
1443 {
1444 case GL_UNSIGNED_BYTE:
1445 break;
1446 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001447 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001448 return false;
1449 }
1450 break;
1451 case GL_SRGB_EXT:
1452 case GL_SRGB_ALPHA_EXT:
1453 if (!context->getExtensions().sRGB)
1454 {
Jamie Madille0472f32018-11-27 16:32:45 -05001455 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001456 return false;
1457 }
1458 switch (type)
1459 {
1460 case GL_UNSIGNED_BYTE:
1461 break;
1462 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001463 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001464 return false;
1465 }
1466 break;
1467 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are
1468 // handled below
1469 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1470 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1471 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1472 break;
1473 case GL_DEPTH_COMPONENT:
1474 switch (type)
1475 {
1476 case GL_UNSIGNED_SHORT:
1477 case GL_UNSIGNED_INT:
1478 break;
1479 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001480 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001481 return false;
1482 }
1483 break;
1484 case GL_DEPTH_STENCIL_OES:
1485 switch (type)
1486 {
1487 case GL_UNSIGNED_INT_24_8_OES:
1488 break;
1489 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001490 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001491 return false;
1492 }
1493 break;
1494 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001495 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001496 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001497 }
1498
1499 switch (format)
1500 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001501 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1502 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1503 if (context->getExtensions().textureCompressionDXT1)
1504 {
Jamie Madille0472f32018-11-27 16:32:45 -05001505 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001506 return false;
1507 }
1508 else
1509 {
Jamie Madille0472f32018-11-27 16:32:45 -05001510 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001511 return false;
1512 }
1513 break;
1514 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1515 if (context->getExtensions().textureCompressionDXT3)
1516 {
Jamie Madille0472f32018-11-27 16:32:45 -05001517 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001518 return false;
1519 }
1520 else
1521 {
Jamie Madille0472f32018-11-27 16:32:45 -05001522 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001523 return false;
1524 }
1525 break;
1526 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1527 if (context->getExtensions().textureCompressionDXT5)
1528 {
Jamie Madille0472f32018-11-27 16:32:45 -05001529 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001530 return false;
1531 }
1532 else
1533 {
Jamie Madille0472f32018-11-27 16:32:45 -05001534 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001535 return false;
1536 }
1537 break;
1538 case GL_ETC1_RGB8_OES:
1539 if (context->getExtensions().compressedETC1RGB8Texture)
1540 {
Jamie Madille0472f32018-11-27 16:32:45 -05001541 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001542 return false;
1543 }
1544 else
1545 {
Jamie Madille0472f32018-11-27 16:32:45 -05001546 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001547 return false;
1548 }
1549 break;
1550 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001551 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1552 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1553 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1554 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001555 if (context->getExtensions().lossyETCDecode)
1556 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001557 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001558 return false;
1559 }
1560 else
1561 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001562 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001563 return false;
1564 }
1565 break;
1566 case GL_DEPTH_COMPONENT:
1567 case GL_DEPTH_STENCIL_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001568 if (!context->getExtensions().depthTextureANGLE &&
1569 !(context->getExtensions().packedDepthStencil &&
1570 context->getExtensions().depthTextureOES))
He Yunchaoced53ae2016-11-29 15:00:51 +08001571 {
Jamie Madille0472f32018-11-27 16:32:45 -05001572 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001573 return false;
1574 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001575 if (target != TextureTarget::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001576 {
Jamie Madille0472f32018-11-27 16:32:45 -05001577 context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001578 return false;
1579 }
1580 // OES_depth_texture supports loading depth data and multiple levels,
1581 // but ANGLE_depth_texture does not
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001582 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001583 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001584 if (pixels != nullptr)
1585 {
1586 context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
1587 return false;
1588 }
1589 if (level != 0)
1590 {
1591 context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
1592 return false;
1593 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001594 }
1595 break;
1596 default:
1597 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001598 }
1599
Geoff Lang6e898aa2017-06-02 11:17:26 -04001600 if (!isSubImage)
1601 {
1602 switch (internalformat)
1603 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001604 // Core ES 2.0 formats
1605 case GL_ALPHA:
1606 case GL_LUMINANCE:
1607 case GL_LUMINANCE_ALPHA:
1608 case GL_RGB:
1609 case GL_RGBA:
1610 break;
1611
Geoff Lang6e898aa2017-06-02 11:17:26 -04001612 case GL_RGBA32F:
1613 if (!context->getExtensions().colorBufferFloatRGBA)
1614 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001615 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001616 return false;
1617 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001618
1619 nonEqualFormatsAllowed = true;
1620
Geoff Lang6e898aa2017-06-02 11:17:26 -04001621 if (type != GL_FLOAT)
1622 {
Jamie Madille0472f32018-11-27 16:32:45 -05001623 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001624 return false;
1625 }
1626 if (format != GL_RGBA)
1627 {
Jamie Madille0472f32018-11-27 16:32:45 -05001628 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001629 return false;
1630 }
1631 break;
1632
1633 case GL_RGB32F:
1634 if (!context->getExtensions().colorBufferFloatRGB)
1635 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001636 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001637 return false;
1638 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001639
1640 nonEqualFormatsAllowed = true;
1641
Geoff Lang6e898aa2017-06-02 11:17:26 -04001642 if (type != GL_FLOAT)
1643 {
Jamie Madille0472f32018-11-27 16:32:45 -05001644 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001645 return false;
1646 }
1647 if (format != GL_RGB)
1648 {
Jamie Madille0472f32018-11-27 16:32:45 -05001649 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001650 return false;
1651 }
1652 break;
1653
Tim Van Patten208af3e2019-03-19 09:15:55 -06001654 case GL_BGRA_EXT:
1655 if (!context->getExtensions().textureFormatBGRA8888)
1656 {
1657 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1658 return false;
1659 }
Geoff Lang6e898aa2017-06-02 11:17:26 -04001660 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001661
1662 case GL_DEPTH_COMPONENT:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001663 if (!(context->getExtensions().depthTextureAny()))
1664 {
1665 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1666 return false;
1667 }
1668 break;
1669
Tim Van Patten208af3e2019-03-19 09:15:55 -06001670 case GL_DEPTH_STENCIL:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001671 if (!(context->getExtensions().depthTextureANGLE ||
1672 context->getExtensions().packedDepthStencil))
Tim Van Patten208af3e2019-03-19 09:15:55 -06001673 {
1674 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1675 return false;
1676 }
1677 break;
1678
1679 case GL_RED:
1680 case GL_RG:
1681 if (!context->getExtensions().textureRG)
1682 {
1683 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1684 return false;
1685 }
1686 break;
1687
1688 case GL_SRGB_EXT:
1689 case GL_SRGB_ALPHA_EXT:
1690 if (!context->getExtensions().sRGB)
1691 {
1692 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1693 return false;
1694 }
1695 break;
1696
Jaedon Lee3b468852019-07-30 16:50:36 +09001697 case GL_RGB10_A2_EXT:
1698 if (!context->getExtensions().textureFormat2101010REV)
1699 {
1700 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1701 return false;
1702 }
1703
1704 if (type != GL_UNSIGNED_INT_2_10_10_10_REV_EXT || format != GL_RGBA)
1705 {
1706 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
1707 return false;
1708 }
1709
1710 nonEqualFormatsAllowed = true;
1711
1712 break;
1713
1714 case GL_RGB5_A1:
1715 if (context->getExtensions().textureFormat2101010REV &&
1716 type == GL_UNSIGNED_INT_2_10_10_10_REV_EXT && format == GL_RGBA)
1717 {
1718 nonEqualFormatsAllowed = true;
1719 }
1720
1721 break;
1722
Tim Van Patten208af3e2019-03-19 09:15:55 -06001723 default:
1724 context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat);
1725 return false;
Geoff Lang6e898aa2017-06-02 11:17:26 -04001726 }
1727 }
1728
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001729 if (type == GL_FLOAT)
1730 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001731 if (!context->getExtensions().textureFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001732 {
Jamie Madille0472f32018-11-27 16:32:45 -05001733 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001734 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001735 }
1736 }
1737 else if (type == GL_HALF_FLOAT_OES)
1738 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001739 if (!context->getExtensions().textureHalfFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001740 {
Jamie Madille0472f32018-11-27 16:32:45 -05001741 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001742 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001743 }
1744 }
1745 }
1746
Tim Van Patten208af3e2019-03-19 09:15:55 -06001747 if (isSubImage)
Geoff Langff5b2d52016-09-07 11:32:23 -04001748 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001749 const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info;
1750 if (textureInternalFormat.internalFormat == GL_NONE)
1751 {
1752 context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel);
1753 return false;
1754 }
1755
Tim Van Patten5f388c22019-03-14 09:54:23 -06001756 if (format != textureInternalFormat.format)
1757 {
1758 context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch);
1759 return false;
1760 }
1761
1762 if (context->getExtensions().webglCompatibility)
Tim Van Patten208af3e2019-03-19 09:15:55 -06001763 {
1764 if (GetInternalFormatInfo(format, type).sizedInternalFormat !=
1765 textureInternalFormat.sizedInternalFormat)
1766 {
Tim Van Patten5f388c22019-03-14 09:54:23 -06001767 context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch);
Tim Van Patten208af3e2019-03-19 09:15:55 -06001768 return false;
1769 }
1770 }
1771
1772 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
1773 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level))
1774 {
1775 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
1776 return false;
1777 }
1778
1779 if (width > 0 && height > 0 && pixels == nullptr &&
1780 context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr)
1781 {
1782 context->validationError(GL_INVALID_VALUE, kPixelDataNull);
1783 return false;
1784 }
1785 }
1786 else
1787 {
1788 if (texture->getImmutableFormat())
1789 {
1790 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
1791 return false;
1792 }
1793 }
1794
1795 // From GL_CHROMIUM_color_buffer_float_rgb[a]:
1796 // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
1797 // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
1798 // internalformat parameter and format parameter of TexImage2D must match is lifted for this
1799 // case.
1800 if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
1801 {
1802 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Langff5b2d52016-09-07 11:32:23 -04001803 return false;
1804 }
1805
Tim Van Patten208af3e2019-03-19 09:15:55 -06001806 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
1807 return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels,
1808 imageSize);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001809}
1810
He Yunchaoced53ae2016-11-29 15:00:51 +08001811bool ValidateES2TexStorageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001812 TextureType target,
He Yunchaoced53ae2016-11-29 15:00:51 +08001813 GLsizei levels,
1814 GLenum internalformat,
1815 GLsizei width,
1816 GLsizei height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001817{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001818 if (target != TextureType::_2D && target != TextureType::CubeMap &&
1819 target != TextureType::Rectangle)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001820 {
Jamie Madille0472f32018-11-27 16:32:45 -05001821 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001822 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001823 }
1824
1825 if (width < 1 || height < 1 || levels < 1)
1826 {
Jamie Madille0472f32018-11-27 16:32:45 -05001827 context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall);
Geoff Langb1196682014-07-23 13:47:29 -04001828 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001829 }
1830
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001831 if (target == TextureType::CubeMap && width != height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001832 {
Jamie Madille0472f32018-11-27 16:32:45 -05001833 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Langb1196682014-07-23 13:47:29 -04001834 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001835 }
1836
1837 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1838 {
Jamie Madille0472f32018-11-27 16:32:45 -05001839 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
Geoff Langb1196682014-07-23 13:47:29 -04001840 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001841 }
1842
Geoff Langca271392017-04-05 12:30:00 -04001843 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Lang5d601382014-07-22 15:14:06 -04001844 if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001845 {
Jamie Madille0472f32018-11-27 16:32:45 -05001846 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Langb1196682014-07-23 13:47:29 -04001847 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001848 }
1849
Geoff Langaae65a42014-05-26 12:43:44 -04001850 const gl::Caps &caps = context->getCaps();
1851
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001852 switch (target)
1853 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001854 case TextureType::_2D:
He Yunchaoced53ae2016-11-29 15:00:51 +08001855 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
1856 static_cast<GLuint>(height) > caps.max2DTextureSize)
1857 {
Jamie Madille0472f32018-11-27 16:32:45 -05001858 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001859 return false;
1860 }
1861 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001862 case TextureType::Rectangle:
Jamie Madill610640f2018-11-21 17:28:41 -05001863 if (levels != 1)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001864 {
Jamie Madille0472f32018-11-27 16:32:45 -05001865 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madill610640f2018-11-21 17:28:41 -05001866 return false;
1867 }
1868
1869 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1870 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1871 {
Jamie Madille0472f32018-11-27 16:32:45 -05001872 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001873 return false;
1874 }
1875 if (formatInfo.compressed)
1876 {
Jamie Madille0472f32018-11-27 16:32:45 -05001877 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001878 return false;
1879 }
1880 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001881 case TextureType::CubeMap:
He Yunchaoced53ae2016-11-29 15:00:51 +08001882 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize ||
1883 static_cast<GLuint>(height) > caps.maxCubeMapTextureSize)
1884 {
Jamie Madille0472f32018-11-27 16:32:45 -05001885 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001886 return false;
1887 }
1888 break;
1889 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001890 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001891 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001892 }
1893
Geoff Langc0b9ef42014-07-02 10:02:37 -04001894 if (levels != 1 && !context->getExtensions().textureNPOT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001895 {
1896 if (!gl::isPow2(width) || !gl::isPow2(height))
1897 {
Jamie Madille0472f32018-11-27 16:32:45 -05001898 context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2);
Geoff Langb1196682014-07-23 13:47:29 -04001899 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001900 }
1901 }
1902
1903 switch (internalformat)
1904 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001905 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1906 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1907 if (!context->getExtensions().textureCompressionDXT1)
1908 {
Jamie Madille0472f32018-11-27 16:32:45 -05001909 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001910 return false;
1911 }
1912 break;
1913 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1914 if (!context->getExtensions().textureCompressionDXT3)
1915 {
Jamie Madille0472f32018-11-27 16:32:45 -05001916 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001917 return false;
1918 }
1919 break;
1920 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1921 if (!context->getExtensions().textureCompressionDXT5)
1922 {
Jamie Madille0472f32018-11-27 16:32:45 -05001923 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001924 return false;
1925 }
1926 break;
1927 case GL_ETC1_RGB8_OES:
1928 if (!context->getExtensions().compressedETC1RGB8Texture)
1929 {
Jamie Madille0472f32018-11-27 16:32:45 -05001930 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001931 return false;
1932 }
1933 break;
1934 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001935 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1936 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1937 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1938 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001939 if (!context->getExtensions().lossyETCDecode)
1940 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001941 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001942 return false;
1943 }
1944 break;
1945 case GL_RGBA32F_EXT:
1946 case GL_RGB32F_EXT:
1947 case GL_ALPHA32F_EXT:
1948 case GL_LUMINANCE32F_EXT:
1949 case GL_LUMINANCE_ALPHA32F_EXT:
1950 if (!context->getExtensions().textureFloat)
1951 {
Jamie Madille0472f32018-11-27 16:32:45 -05001952 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001953 return false;
1954 }
1955 break;
1956 case GL_RGBA16F_EXT:
1957 case GL_RGB16F_EXT:
1958 case GL_ALPHA16F_EXT:
1959 case GL_LUMINANCE16F_EXT:
1960 case GL_LUMINANCE_ALPHA16F_EXT:
1961 if (!context->getExtensions().textureHalfFloat)
1962 {
Jamie Madille0472f32018-11-27 16:32:45 -05001963 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001964 return false;
1965 }
1966 break;
1967 case GL_R8_EXT:
1968 case GL_RG8_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001969 if (!context->getExtensions().textureRG)
1970 {
Jamie Madille0472f32018-11-27 16:32:45 -05001971 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001972 return false;
1973 }
1974 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001975 case GL_R16F_EXT:
1976 case GL_RG16F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001977 if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat)
1978 {
Jamie Madille0472f32018-11-27 16:32:45 -05001979 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04001980 return false;
1981 }
1982 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001983 case GL_R32F_EXT:
1984 case GL_RG32F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04001985 if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat)
He Yunchaoced53ae2016-11-29 15:00:51 +08001986 {
Jamie Madille0472f32018-11-27 16:32:45 -05001987 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001988 return false;
1989 }
1990 break;
1991 case GL_DEPTH_COMPONENT16:
1992 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001993 if (!(context->getExtensions().depthTextureAny()))
He Yunchaoced53ae2016-11-29 15:00:51 +08001994 {
Jamie Madille0472f32018-11-27 16:32:45 -05001995 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001996 return false;
1997 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001998 if (target != TextureType::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001999 {
Jamie Madille0472f32018-11-27 16:32:45 -05002000 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08002001 return false;
2002 }
2003 // ANGLE_depth_texture only supports 1-level textures
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06002004 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08002005 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06002006 if (levels != 1)
2007 {
2008 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
2009 return false;
2010 }
He Yunchaoced53ae2016-11-29 15:00:51 +08002011 }
2012 break;
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06002013 case GL_DEPTH24_STENCIL8_OES:
2014 if (!(context->getExtensions().depthTextureANGLE ||
2015 (context->getExtensions().packedDepthStencil &&
2016 context->getExtensions().textureStorage)))
2017 {
2018 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
2019 return false;
2020 }
2021 if (target != TextureType::_2D)
2022 {
2023 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
2024 return false;
2025 }
2026 if (!context->getExtensions().packedDepthStencil)
2027 {
2028 // ANGLE_depth_texture only supports 1-level textures
2029 if (levels != 1)
2030 {
2031 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
2032 return false;
2033 }
2034 }
2035 break;
2036
He Yunchaoced53ae2016-11-29 15:00:51 +08002037 default:
2038 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002039 }
2040
Jamie Madillcfc73cc2019-04-08 16:26:51 -04002041 gl::Texture *texture = context->getTextureByType(target);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002042 if (!texture || texture->id() == 0)
2043 {
Jamie Madille0472f32018-11-27 16:32:45 -05002044 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
Geoff Langb1196682014-07-23 13:47:29 -04002045 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002046 }
2047
Geoff Lang69cce582015-09-17 13:20:36 -04002048 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002049 {
Jamie Madille0472f32018-11-27 16:32:45 -05002050 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
Geoff Langb1196682014-07-23 13:47:29 -04002051 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002052 }
2053
2054 return true;
2055}
2056
He Yunchaoced53ae2016-11-29 15:00:51 +08002057bool ValidateDiscardFramebufferEXT(Context *context,
2058 GLenum target,
2059 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07002060 const GLenum *attachments)
2061{
Jamie Madillc29968b2016-01-20 11:17:23 -05002062 if (!context->getExtensions().discardFramebuffer)
2063 {
Jamie Madille0472f32018-11-27 16:32:45 -05002064 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002065 return false;
2066 }
2067
Austin Kinross08332632015-05-05 13:35:47 -07002068 bool defaultFramebuffer = false;
2069
2070 switch (target)
2071 {
He Yunchaoced53ae2016-11-29 15:00:51 +08002072 case GL_FRAMEBUFFER:
2073 defaultFramebuffer =
Tim Van Patten56ba54c2019-08-08 13:03:34 -06002074 (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->isDefault());
He Yunchaoced53ae2016-11-29 15:00:51 +08002075 break;
2076 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002077 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08002078 return false;
Austin Kinross08332632015-05-05 13:35:47 -07002079 }
2080
He Yunchaoced53ae2016-11-29 15:00:51 +08002081 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
2082 defaultFramebuffer);
Austin Kinross08332632015-05-05 13:35:47 -07002083}
2084
Jiacheng Lufeb85072019-09-03 13:22:04 -04002085bool ValidateBindVertexArrayOES(Context *context, VertexArrayID array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002086{
2087 if (!context->getExtensions().vertexArrayObject)
2088 {
Jamie Madille0472f32018-11-27 16:32:45 -05002089 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002090 return false;
2091 }
2092
2093 return ValidateBindVertexArrayBase(context, array);
2094}
2095
Jiacheng Lufeb85072019-09-03 13:22:04 -04002096bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const VertexArrayID *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002097{
2098 if (!context->getExtensions().vertexArrayObject)
2099 {
Jamie Madille0472f32018-11-27 16:32:45 -05002100 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002101 return false;
2102 }
2103
Olli Etuaho41997e72016-03-10 13:38:39 +02002104 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002105}
2106
Jiacheng Lufeb85072019-09-03 13:22:04 -04002107bool ValidateGenVertexArraysOES(Context *context, GLsizei n, VertexArrayID *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002108{
2109 if (!context->getExtensions().vertexArrayObject)
2110 {
Jamie Madille0472f32018-11-27 16:32:45 -05002111 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002112 return false;
2113 }
2114
Olli Etuaho41997e72016-03-10 13:38:39 +02002115 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002116}
2117
Jiacheng Lufeb85072019-09-03 13:22:04 -04002118bool ValidateIsVertexArrayOES(Context *context, VertexArrayID array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002119{
2120 if (!context->getExtensions().vertexArrayObject)
2121 {
Jamie Madille0472f32018-11-27 16:32:45 -05002122 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002123 return false;
2124 }
2125
2126 return true;
2127}
Geoff Langc5629752015-12-07 16:29:04 -05002128
2129bool ValidateProgramBinaryOES(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06002130 ShaderProgramID program,
Geoff Langc5629752015-12-07 16:29:04 -05002131 GLenum binaryFormat,
2132 const void *binary,
2133 GLint length)
2134{
2135 if (!context->getExtensions().getProgramBinary)
2136 {
Jamie Madille0472f32018-11-27 16:32:45 -05002137 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002138 return false;
2139 }
2140
2141 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
2142}
2143
2144bool ValidateGetProgramBinaryOES(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06002145 ShaderProgramID program,
Geoff Langc5629752015-12-07 16:29:04 -05002146 GLsizei bufSize,
2147 GLsizei *length,
2148 GLenum *binaryFormat,
2149 void *binary)
2150{
2151 if (!context->getExtensions().getProgramBinary)
2152 {
Jamie Madille0472f32018-11-27 16:32:45 -05002153 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002154 return false;
2155 }
2156
2157 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
2158}
Geoff Lange102fee2015-12-10 11:23:30 -05002159
Geoff Lang70d0f492015-12-10 17:45:46 -05002160static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication)
2161{
2162 switch (source)
2163 {
2164 case GL_DEBUG_SOURCE_API:
2165 case GL_DEBUG_SOURCE_SHADER_COMPILER:
2166 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
2167 case GL_DEBUG_SOURCE_OTHER:
2168 // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted
2169 return !mustBeThirdPartyOrApplication;
2170
2171 case GL_DEBUG_SOURCE_THIRD_PARTY:
2172 case GL_DEBUG_SOURCE_APPLICATION:
2173 return true;
2174
2175 default:
2176 return false;
2177 }
2178}
2179
2180static bool ValidDebugType(GLenum type)
2181{
2182 switch (type)
2183 {
2184 case GL_DEBUG_TYPE_ERROR:
2185 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
2186 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
2187 case GL_DEBUG_TYPE_PERFORMANCE:
2188 case GL_DEBUG_TYPE_PORTABILITY:
2189 case GL_DEBUG_TYPE_OTHER:
2190 case GL_DEBUG_TYPE_MARKER:
2191 case GL_DEBUG_TYPE_PUSH_GROUP:
2192 case GL_DEBUG_TYPE_POP_GROUP:
2193 return true;
2194
2195 default:
2196 return false;
2197 }
2198}
2199
2200static bool ValidDebugSeverity(GLenum severity)
2201{
2202 switch (severity)
2203 {
2204 case GL_DEBUG_SEVERITY_HIGH:
2205 case GL_DEBUG_SEVERITY_MEDIUM:
2206 case GL_DEBUG_SEVERITY_LOW:
2207 case GL_DEBUG_SEVERITY_NOTIFICATION:
2208 return true;
2209
2210 default:
2211 return false;
2212 }
2213}
2214
Geoff Lange102fee2015-12-10 11:23:30 -05002215bool ValidateDebugMessageControlKHR(Context *context,
2216 GLenum source,
2217 GLenum type,
2218 GLenum severity,
2219 GLsizei count,
2220 const GLuint *ids,
2221 GLboolean enabled)
2222{
2223 if (!context->getExtensions().debug)
2224 {
Jamie Madille0472f32018-11-27 16:32:45 -05002225 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002226 return false;
2227 }
2228
Geoff Lang70d0f492015-12-10 17:45:46 -05002229 if (!ValidDebugSource(source, false) && source != GL_DONT_CARE)
2230 {
Jamie Madille0472f32018-11-27 16:32:45 -05002231 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002232 return false;
2233 }
2234
2235 if (!ValidDebugType(type) && type != GL_DONT_CARE)
2236 {
Jamie Madille0472f32018-11-27 16:32:45 -05002237 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002238 return false;
2239 }
2240
2241 if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE)
2242 {
Jamie Madille0472f32018-11-27 16:32:45 -05002243 context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002244 return false;
2245 }
2246
2247 if (count > 0)
2248 {
2249 if (source == GL_DONT_CARE || type == GL_DONT_CARE)
2250 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002251 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002252 return false;
2253 }
2254
2255 if (severity != GL_DONT_CARE)
2256 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002257 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002258 return false;
2259 }
2260 }
2261
Geoff Lange102fee2015-12-10 11:23:30 -05002262 return true;
2263}
2264
2265bool ValidateDebugMessageInsertKHR(Context *context,
2266 GLenum source,
2267 GLenum type,
2268 GLuint id,
2269 GLenum severity,
2270 GLsizei length,
2271 const GLchar *buf)
2272{
2273 if (!context->getExtensions().debug)
2274 {
Jamie Madille0472f32018-11-27 16:32:45 -05002275 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002276 return false;
2277 }
2278
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002279 if (!context->getState().getDebug().isOutputEnabled())
Geoff Lang70d0f492015-12-10 17:45:46 -05002280 {
2281 // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do
2282 // not generate an error.
2283 return false;
2284 }
2285
2286 if (!ValidDebugSeverity(severity))
2287 {
Jamie Madille0472f32018-11-27 16:32:45 -05002288 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002289 return false;
2290 }
2291
2292 if (!ValidDebugType(type))
2293 {
Jamie Madille0472f32018-11-27 16:32:45 -05002294 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002295 return false;
2296 }
2297
2298 if (!ValidDebugSource(source, true))
2299 {
Jamie Madille0472f32018-11-27 16:32:45 -05002300 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002301 return false;
2302 }
2303
2304 size_t messageLength = (length < 0) ? strlen(buf) : length;
2305 if (messageLength > context->getExtensions().maxDebugMessageLength)
2306 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002307 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002308 return false;
2309 }
2310
Geoff Lange102fee2015-12-10 11:23:30 -05002311 return true;
2312}
2313
2314bool ValidateDebugMessageCallbackKHR(Context *context,
2315 GLDEBUGPROCKHR callback,
2316 const void *userParam)
2317{
2318 if (!context->getExtensions().debug)
2319 {
Jamie Madille0472f32018-11-27 16:32:45 -05002320 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002321 return false;
2322 }
2323
Geoff Lange102fee2015-12-10 11:23:30 -05002324 return true;
2325}
2326
2327bool ValidateGetDebugMessageLogKHR(Context *context,
2328 GLuint count,
2329 GLsizei bufSize,
2330 GLenum *sources,
2331 GLenum *types,
2332 GLuint *ids,
2333 GLenum *severities,
2334 GLsizei *lengths,
2335 GLchar *messageLog)
2336{
2337 if (!context->getExtensions().debug)
2338 {
Jamie Madille0472f32018-11-27 16:32:45 -05002339 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002340 return false;
2341 }
2342
Geoff Lang70d0f492015-12-10 17:45:46 -05002343 if (bufSize < 0 && messageLog != nullptr)
2344 {
Jamie Madille0472f32018-11-27 16:32:45 -05002345 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002346 return false;
2347 }
2348
Geoff Lange102fee2015-12-10 11:23:30 -05002349 return true;
2350}
2351
2352bool ValidatePushDebugGroupKHR(Context *context,
2353 GLenum source,
2354 GLuint id,
2355 GLsizei length,
2356 const GLchar *message)
2357{
2358 if (!context->getExtensions().debug)
2359 {
Jamie Madille0472f32018-11-27 16:32:45 -05002360 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002361 return false;
2362 }
2363
Geoff Lang70d0f492015-12-10 17:45:46 -05002364 if (!ValidDebugSource(source, true))
2365 {
Jamie Madille0472f32018-11-27 16:32:45 -05002366 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002367 return false;
2368 }
2369
2370 size_t messageLength = (length < 0) ? strlen(message) : length;
2371 if (messageLength > context->getExtensions().maxDebugMessageLength)
2372 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002373 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002374 return false;
2375 }
2376
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002377 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002378 if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth)
2379 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002380 context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth);
Geoff Lang70d0f492015-12-10 17:45:46 -05002381 return false;
2382 }
2383
Geoff Lange102fee2015-12-10 11:23:30 -05002384 return true;
2385}
2386
2387bool ValidatePopDebugGroupKHR(Context *context)
2388{
2389 if (!context->getExtensions().debug)
2390 {
Jamie Madille0472f32018-11-27 16:32:45 -05002391 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002392 return false;
2393 }
2394
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002395 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002396 if (currentStackSize <= 1)
2397 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002398 context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup);
Geoff Lang70d0f492015-12-10 17:45:46 -05002399 return false;
2400 }
2401
2402 return true;
2403}
2404
2405static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name)
2406{
2407 switch (identifier)
2408 {
2409 case GL_BUFFER:
Jamie Madill3b3fe832019-08-06 17:44:12 -04002410 if (context->getBuffer({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002411 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002412 context->validationError(GL_INVALID_VALUE, kInvalidBufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002413 return false;
2414 }
2415 return true;
2416
2417 case GL_SHADER:
Jiacheng Lu120b61d2019-08-21 12:51:58 -06002418 if (context->getShader({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002419 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002420 context->validationError(GL_INVALID_VALUE, kInvalidShaderName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002421 return false;
2422 }
2423 return true;
2424
2425 case GL_PROGRAM:
Jiacheng Lu120b61d2019-08-21 12:51:58 -06002426 if (context->getProgramNoResolveLink({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002427 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002428 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002429 return false;
2430 }
2431 return true;
2432
2433 case GL_VERTEX_ARRAY:
Jiacheng Lufeb85072019-09-03 13:22:04 -04002434 if (context->getVertexArray({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002435 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002436 context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002437 return false;
2438 }
2439 return true;
2440
2441 case GL_QUERY:
Jiacheng Lu814a0a12019-08-22 11:50:43 -06002442 if (context->getQuery({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002443 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002444 context->validationError(GL_INVALID_VALUE, kInvalidQueryName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002445 return false;
2446 }
2447 return true;
2448
2449 case GL_TRANSFORM_FEEDBACK:
Jiacheng Luc3f78732019-08-30 15:00:52 -06002450 if (context->getTransformFeedback({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002451 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002452 context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002453 return false;
2454 }
2455 return true;
2456
2457 case GL_SAMPLER:
Jiacheng Luee79e2f2019-08-20 11:28:36 -06002458 if (context->getSampler({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002459 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002460 context->validationError(GL_INVALID_VALUE, kInvalidSamplerName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002461 return false;
2462 }
2463 return true;
2464
2465 case GL_TEXTURE:
Jamie Madill2ab08ed2019-08-12 16:20:21 -04002466 if (context->getTexture({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002467 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002468 context->validationError(GL_INVALID_VALUE, kInvalidTextureName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002469 return false;
2470 }
2471 return true;
2472
2473 case GL_RENDERBUFFER:
Jamie Madill7c7dec02019-08-06 17:44:11 -04002474 if (!context->isRenderbuffer({name}))
Geoff Lang70d0f492015-12-10 17:45:46 -05002475 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002476 context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002477 return false;
2478 }
2479 return true;
2480
2481 case GL_FRAMEBUFFER:
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06002482 if (context->getFramebuffer({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002483 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002484 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002485 return false;
2486 }
2487 return true;
2488
2489 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05002490 context->validationError(GL_INVALID_ENUM, kInvalidIndentifier);
Geoff Lang70d0f492015-12-10 17:45:46 -05002491 return false;
2492 }
Geoff Lange102fee2015-12-10 11:23:30 -05002493}
2494
Martin Radev9d901792016-07-15 15:58:58 +03002495static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label)
2496{
2497 size_t labelLength = 0;
2498
2499 if (length < 0)
2500 {
2501 if (label != nullptr)
2502 {
2503 labelLength = strlen(label);
2504 }
2505 }
2506 else
2507 {
2508 labelLength = static_cast<size_t>(length);
2509 }
2510
2511 if (labelLength > context->getExtensions().maxLabelLength)
2512 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002513 context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength);
Martin Radev9d901792016-07-15 15:58:58 +03002514 return false;
2515 }
2516
2517 return true;
2518}
2519
Geoff Lange102fee2015-12-10 11:23:30 -05002520bool ValidateObjectLabelKHR(Context *context,
2521 GLenum identifier,
2522 GLuint name,
2523 GLsizei length,
2524 const GLchar *label)
2525{
2526 if (!context->getExtensions().debug)
2527 {
Jamie Madille0472f32018-11-27 16:32:45 -05002528 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002529 return false;
2530 }
2531
Geoff Lang70d0f492015-12-10 17:45:46 -05002532 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2533 {
2534 return false;
2535 }
2536
Martin Radev9d901792016-07-15 15:58:58 +03002537 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002538 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002539 return false;
2540 }
2541
Geoff Lange102fee2015-12-10 11:23:30 -05002542 return true;
2543}
2544
2545bool ValidateGetObjectLabelKHR(Context *context,
2546 GLenum identifier,
2547 GLuint name,
2548 GLsizei bufSize,
2549 GLsizei *length,
2550 GLchar *label)
2551{
2552 if (!context->getExtensions().debug)
2553 {
Jamie Madille0472f32018-11-27 16:32:45 -05002554 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002555 return false;
2556 }
2557
Geoff Lang70d0f492015-12-10 17:45:46 -05002558 if (bufSize < 0)
2559 {
Jamie Madille0472f32018-11-27 16:32:45 -05002560 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002561 return false;
2562 }
2563
2564 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2565 {
2566 return false;
2567 }
2568
Martin Radev9d901792016-07-15 15:58:58 +03002569 return true;
Geoff Lang70d0f492015-12-10 17:45:46 -05002570}
2571
2572static bool ValidateObjectPtrName(Context *context, const void *ptr)
2573{
Jamie Madill70b5bb02017-08-28 13:32:37 -04002574 if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002575 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002576 context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer);
Geoff Lang70d0f492015-12-10 17:45:46 -05002577 return false;
2578 }
2579
Geoff Lange102fee2015-12-10 11:23:30 -05002580 return true;
2581}
2582
2583bool ValidateObjectPtrLabelKHR(Context *context,
2584 const void *ptr,
2585 GLsizei length,
2586 const GLchar *label)
2587{
2588 if (!context->getExtensions().debug)
2589 {
Jamie Madille0472f32018-11-27 16:32:45 -05002590 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002591 return false;
2592 }
2593
Geoff Lang70d0f492015-12-10 17:45:46 -05002594 if (!ValidateObjectPtrName(context, ptr))
2595 {
2596 return false;
2597 }
2598
Martin Radev9d901792016-07-15 15:58:58 +03002599 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002600 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002601 return false;
2602 }
2603
Geoff Lange102fee2015-12-10 11:23:30 -05002604 return true;
2605}
2606
2607bool ValidateGetObjectPtrLabelKHR(Context *context,
2608 const void *ptr,
2609 GLsizei bufSize,
2610 GLsizei *length,
2611 GLchar *label)
2612{
2613 if (!context->getExtensions().debug)
2614 {
Jamie Madille0472f32018-11-27 16:32:45 -05002615 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002616 return false;
2617 }
2618
Geoff Lang70d0f492015-12-10 17:45:46 -05002619 if (bufSize < 0)
2620 {
Jamie Madille0472f32018-11-27 16:32:45 -05002621 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002622 return false;
2623 }
2624
2625 if (!ValidateObjectPtrName(context, ptr))
2626 {
2627 return false;
2628 }
2629
Martin Radev9d901792016-07-15 15:58:58 +03002630 return true;
Geoff Lange102fee2015-12-10 11:23:30 -05002631}
2632
2633bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params)
2634{
2635 if (!context->getExtensions().debug)
2636 {
Jamie Madille0472f32018-11-27 16:32:45 -05002637 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002638 return false;
2639 }
2640
Geoff Lang70d0f492015-12-10 17:45:46 -05002641 // TODO: represent this in Context::getQueryParameterInfo.
2642 switch (pname)
2643 {
2644 case GL_DEBUG_CALLBACK_FUNCTION:
2645 case GL_DEBUG_CALLBACK_USER_PARAM:
2646 break;
2647
2648 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002649 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang70d0f492015-12-10 17:45:46 -05002650 return false;
2651 }
2652
Geoff Lange102fee2015-12-10 11:23:30 -05002653 return true;
2654}
Jamie Madillc29968b2016-01-20 11:17:23 -05002655
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002656bool ValidateGetPointervRobustANGLERobustANGLE(Context *context,
2657 GLenum pname,
2658 GLsizei bufSize,
2659 GLsizei *length,
2660 void **params)
2661{
2662 UNIMPLEMENTED();
2663 return false;
2664}
2665
Jamie Madillc29968b2016-01-20 11:17:23 -05002666bool ValidateBlitFramebufferANGLE(Context *context,
2667 GLint srcX0,
2668 GLint srcY0,
2669 GLint srcX1,
2670 GLint srcY1,
2671 GLint dstX0,
2672 GLint dstY0,
2673 GLint dstX1,
2674 GLint dstY1,
2675 GLbitfield mask,
2676 GLenum filter)
2677{
2678 if (!context->getExtensions().framebufferBlit)
2679 {
Jamie Madille0472f32018-11-27 16:32:45 -05002680 context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable);
Jamie Madillc29968b2016-01-20 11:17:23 -05002681 return false;
2682 }
2683
2684 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
2685 {
2686 // TODO(jmadill): Determine if this should be available on other implementations.
Jamie Madille0472f32018-11-27 16:32:45 -05002687 context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip);
Jamie Madillc29968b2016-01-20 11:17:23 -05002688 return false;
2689 }
2690
2691 if (filter == GL_LINEAR)
2692 {
Jamie Madille0472f32018-11-27 16:32:45 -05002693 context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear);
Jamie Madillc29968b2016-01-20 11:17:23 -05002694 return false;
2695 }
2696
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002697 Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
2698 Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002699
2700 if (mask & GL_COLOR_BUFFER_BIT)
2701 {
Jamie Madill4e71b2b2019-07-08 13:23:38 -04002702 const FramebufferAttachment *readColorAttachment =
2703 readFramebuffer->getReadColorAttachment();
2704 const FramebufferAttachment *drawColorAttachment =
2705 drawFramebuffer->getFirstColorAttachment();
Jamie Madillc29968b2016-01-20 11:17:23 -05002706
2707 if (readColorAttachment && drawColorAttachment)
2708 {
2709 if (!(readColorAttachment->type() == GL_TEXTURE &&
Kenneth Russellcbdf8612019-07-09 20:30:45 -07002710 (readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D ||
2711 readColorAttachment->getTextureImageIndex().getType() ==
2712 TextureType::Rectangle)) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002713 readColorAttachment->type() != GL_RENDERBUFFER &&
2714 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2715 {
Jamie Madill610640f2018-11-21 17:28:41 -05002716 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002717 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002718 return false;
2719 }
2720
Geoff Langa15472a2015-08-11 11:48:03 -04002721 for (size_t drawbufferIdx = 0;
2722 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002723 {
Geoff Langa15472a2015-08-11 11:48:03 -04002724 const FramebufferAttachment *attachment =
2725 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2726 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002727 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002728 if (!(attachment->type() == GL_TEXTURE &&
Kenneth Russellcbdf8612019-07-09 20:30:45 -07002729 (attachment->getTextureImageIndex().getType() == TextureType::_2D ||
2730 attachment->getTextureImageIndex().getType() ==
2731 TextureType::Rectangle)) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002732 attachment->type() != GL_RENDERBUFFER &&
2733 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2734 {
Jamie Madill610640f2018-11-21 17:28:41 -05002735 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002736 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002737 return false;
2738 }
2739
2740 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002741 if (!Format::EquivalentForBlit(attachment->getFormat(),
2742 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002743 {
Jamie Madill610640f2018-11-21 17:28:41 -05002744 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002745 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002746 return false;
2747 }
2748 }
2749 }
2750
Jamie Madill427064d2018-04-13 16:20:34 -04002751 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002752 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002753 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2754 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2755 {
Jamie Madill610640f2018-11-21 17:28:41 -05002756 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002757 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002758 return false;
2759 }
2760 }
2761 }
2762
2763 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2764 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2765 for (size_t i = 0; i < 2; i++)
2766 {
2767 if (mask & masks[i])
2768 {
2769 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002770 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002771 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002772 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002773
2774 if (readBuffer && drawBuffer)
2775 {
2776 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2777 dstX0, dstY0, dstX1, dstY1))
2778 {
2779 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002780 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002781 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002782 return false;
2783 }
2784
2785 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2786 {
Jamie Madill610640f2018-11-21 17:28:41 -05002787 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002788 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002789 return false;
2790 }
2791 }
2792 }
2793 }
2794
2795 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2796 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002797}
Jamie Madillc29968b2016-01-20 11:17:23 -05002798
Jamie Madill5b772312018-03-08 20:28:32 -05002799bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002800{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002801 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002802 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002803
Jamie Madill427064d2018-04-13 16:20:34 -04002804 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002805 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002806 return false;
2807 }
2808
2809 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2810 {
Jamie Madille0472f32018-11-27 16:32:45 -05002811 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002812 return false;
2813 }
2814
Olli Etuaho94c91a92018-07-19 15:10:24 +03002815 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002816 {
2817 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2818 GL_SIGNED_NORMALIZED};
2819
Corentin Wallez59c41592017-07-11 13:19:54 -04002820 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002821 drawBufferIdx++)
2822 {
2823 if (!ValidateWebGLFramebufferAttachmentClearType(
2824 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2825 {
2826 return false;
2827 }
2828 }
2829 }
2830
Mingyu Huebab6702019-04-19 14:36:45 -07002831 if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery)
Olli Etuaho94c91a92018-07-19 15:10:24 +03002832 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002833 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002834 Framebuffer *framebuffer = state.getDrawFramebuffer();
2835 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2836 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002837 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002838 return false;
2839 }
2840 }
2841
Jamie Madillc29968b2016-01-20 11:17:23 -05002842 return true;
2843}
2844
Jamie Madill5b772312018-03-08 20:28:32 -05002845bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002846{
2847 if (!context->getExtensions().drawBuffers)
2848 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002849 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002850 return false;
2851 }
2852
2853 return ValidateDrawBuffersBase(context, n, bufs);
2854}
2855
Jamie Madill73a84962016-02-12 09:27:23 -05002856bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002857 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002858 GLint level,
2859 GLint internalformat,
2860 GLsizei width,
2861 GLsizei height,
2862 GLint border,
2863 GLenum format,
2864 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002865 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002866{
Martin Radev1be913c2016-07-11 17:59:16 +03002867 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002868 {
2869 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002870 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002871 }
2872
Martin Radev1be913c2016-07-11 17:59:16 +03002873 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002874 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002875 0, 0, width, height, 1, border, format, type, -1,
2876 pixels);
2877}
2878
Brandon Jones416aaf92018-04-10 08:10:16 -07002879bool ValidateTexImage2DRobustANGLE(Context *context,
2880 TextureTarget target,
2881 GLint level,
2882 GLint internalformat,
2883 GLsizei width,
2884 GLsizei height,
2885 GLint border,
2886 GLenum format,
2887 GLenum type,
2888 GLsizei bufSize,
2889 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04002890{
2891 if (!ValidateRobustEntryPoint(context, bufSize))
2892 {
2893 return false;
2894 }
2895
2896 if (context->getClientMajorVersion() < 3)
2897 {
2898 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
2899 0, 0, width, height, border, format, type, bufSize,
2900 pixels);
2901 }
2902
2903 ASSERT(context->getClientMajorVersion() >= 3);
2904 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
2905 0, 0, width, height, 1, border, format, type, bufSize,
2906 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002907}
2908
2909bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002910 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002911 GLint level,
2912 GLint xoffset,
2913 GLint yoffset,
2914 GLsizei width,
2915 GLsizei height,
2916 GLenum format,
2917 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002918 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002919{
2920
Martin Radev1be913c2016-07-11 17:59:16 +03002921 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002922 {
2923 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002924 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002925 }
2926
Martin Radev1be913c2016-07-11 17:59:16 +03002927 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002928 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04002929 yoffset, 0, width, height, 1, 0, format, type, -1,
2930 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002931}
2932
Geoff Langc52f6f12016-10-14 10:18:00 -04002933bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002934 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04002935 GLint level,
2936 GLint xoffset,
2937 GLint yoffset,
2938 GLsizei width,
2939 GLsizei height,
2940 GLenum format,
2941 GLenum type,
2942 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002943 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04002944{
2945 if (!ValidateRobustEntryPoint(context, bufSize))
2946 {
2947 return false;
2948 }
2949
2950 if (context->getClientMajorVersion() < 3)
2951 {
2952 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
2953 yoffset, width, height, 0, format, type, bufSize,
2954 pixels);
2955 }
2956
2957 ASSERT(context->getClientMajorVersion() >= 3);
2958 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
2959 yoffset, 0, width, height, 1, 0, format, type, bufSize,
2960 pixels);
2961}
2962
Cody Northrop5faff912019-06-28 14:04:50 -06002963bool ValidateTexSubImage3DOES(Context *context,
2964 TextureTarget target,
2965 GLint level,
2966 GLint xoffset,
2967 GLint yoffset,
2968 GLint zoffset,
2969 GLsizei width,
2970 GLsizei height,
2971 GLsizei depth,
2972 GLenum format,
2973 GLenum type,
2974 const void *pixels)
2975{
2976 return ValidateTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, height,
2977 depth, format, type, pixels);
2978}
2979
Jamie Madill73a84962016-02-12 09:27:23 -05002980bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002981 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002982 GLint level,
2983 GLenum internalformat,
2984 GLsizei width,
2985 GLsizei height,
2986 GLint border,
2987 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04002988 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05002989{
Martin Radev1be913c2016-07-11 17:59:16 +03002990 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002991 {
2992 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002993 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05002994 {
2995 return false;
2996 }
2997 }
2998 else
2999 {
Martin Radev1be913c2016-07-11 17:59:16 +03003000 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003001 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04003002 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05003003 data))
3004 {
3005 return false;
3006 }
3007 }
3008
Geoff Langca271392017-04-05 12:30:00 -04003009 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04003010
3011 GLuint blockSize = 0;
3012 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003013 {
Jamie Madille0472f32018-11-27 16:32:45 -05003014 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003015 return false;
3016 }
3017
Jamie Madillca2ff382018-07-11 09:01:17 -04003018 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003019 {
Jamie Madille0472f32018-11-27 16:32:45 -05003020 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05003021 return false;
3022 }
3023
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003024 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003025 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003026 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003027 return false;
3028 }
3029
Jamie Madill73a84962016-02-12 09:27:23 -05003030 return true;
3031}
3032
Corentin Wallezb2931602017-04-11 15:58:57 -04003033bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003034 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04003035 GLint level,
3036 GLenum internalformat,
3037 GLsizei width,
3038 GLsizei height,
3039 GLint border,
3040 GLsizei imageSize,
3041 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003042 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003043{
3044 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3045 {
3046 return false;
3047 }
3048
3049 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
3050 border, imageSize, data);
3051}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003052
Cody Northrop5faff912019-06-28 14:04:50 -06003053bool ValidateCompressedTexImage3DOES(Context *context,
3054 TextureTarget target,
3055 GLint level,
3056 GLenum internalformat,
3057 GLsizei width,
3058 GLsizei height,
3059 GLsizei depth,
3060 GLint border,
3061 GLsizei imageSize,
3062 const void *data)
3063{
3064 return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height,
3065 depth, border, imageSize, data);
3066}
3067
Corentin Wallezb2931602017-04-11 15:58:57 -04003068bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003069 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04003070 GLint level,
3071 GLint xoffset,
3072 GLint yoffset,
3073 GLsizei width,
3074 GLsizei height,
3075 GLenum format,
3076 GLsizei imageSize,
3077 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003078 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003079{
3080 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3081 {
3082 return false;
3083 }
3084
3085 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
3086 format, imageSize, data);
3087}
3088
Jamie Madill73a84962016-02-12 09:27:23 -05003089bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003090 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003091 GLint level,
3092 GLint xoffset,
3093 GLint yoffset,
3094 GLsizei width,
3095 GLsizei height,
3096 GLenum format,
3097 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003098 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003099{
Martin Radev1be913c2016-07-11 17:59:16 +03003100 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05003101 {
3102 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003103 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05003104 {
3105 return false;
3106 }
3107 }
3108 else
3109 {
Martin Radev1be913c2016-07-11 17:59:16 +03003110 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003111 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003112 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05003113 data))
3114 {
3115 return false;
3116 }
3117 }
3118
Geoff Langca271392017-04-05 12:30:00 -04003119 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04003120 GLuint blockSize = 0;
3121 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003122 {
Jamie Madille0472f32018-11-27 16:32:45 -05003123 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003124 return false;
3125 }
3126
Jamie Madillca2ff382018-07-11 09:01:17 -04003127 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003128 {
Jamie Madille0472f32018-11-27 16:32:45 -05003129 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05003130 return false;
3131 }
3132
3133 return true;
3134}
3135
Cody Northrop5faff912019-06-28 14:04:50 -06003136bool ValidateCompressedTexSubImage3DOES(Context *context,
3137 TextureTarget target,
3138 GLint level,
3139 GLint xoffset,
3140 GLint yoffset,
3141 GLint zoffset,
3142 GLsizei width,
3143 GLsizei height,
3144 GLsizei depth,
3145 GLenum format,
3146 GLsizei imageSize,
3147 const void *data)
3148{
3149 return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width,
3150 height, depth, format, imageSize, data);
3151}
3152
Corentin Wallez336129f2017-10-17 15:55:40 -04003153bool ValidateGetBufferPointervOES(Context *context,
3154 BufferBinding target,
3155 GLenum pname,
3156 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003157{
Jamie Madillc3e37312018-11-30 15:25:39 -05003158 if (!context->getExtensions().mapBuffer)
3159 {
3160 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3161 return false;
3162 }
3163
Geoff Lang496c02d2016-10-20 11:38:11 -07003164 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003165}
3166
Corentin Wallez336129f2017-10-17 15:55:40 -04003167bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003168{
3169 if (!context->getExtensions().mapBuffer)
3170 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003171 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003172 return false;
3173 }
3174
Corentin Walleze4477002017-12-01 14:39:58 -05003175 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03003176 {
Jamie Madille0472f32018-11-27 16:32:45 -05003177 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03003178 return false;
3179 }
3180
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003181 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003182
3183 if (buffer == nullptr)
3184 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003185 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03003186 return false;
3187 }
3188
3189 if (access != GL_WRITE_ONLY_OES)
3190 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003191 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03003192 return false;
3193 }
3194
3195 if (buffer->isMapped())
3196 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003197 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003198 return false;
3199 }
3200
Geoff Lang79f71042017-08-14 16:43:43 -04003201 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003202}
3203
Corentin Wallez336129f2017-10-17 15:55:40 -04003204bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003205{
3206 if (!context->getExtensions().mapBuffer)
3207 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003208 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003209 return false;
3210 }
3211
3212 return ValidateUnmapBufferBase(context, target);
3213}
3214
3215bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003216 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003217 GLintptr offset,
3218 GLsizeiptr length,
3219 GLbitfield access)
3220{
3221 if (!context->getExtensions().mapBufferRange)
3222 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003223 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003224 return false;
3225 }
3226
3227 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3228}
3229
Michael Spang7a8c3e52019-04-03 14:49:57 -04003230bool ValidateBufferStorageMemEXT(Context *context,
3231 TextureType target,
3232 GLsizeiptr size,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003233 MemoryObjectID memory,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003234 GLuint64 offset)
3235{
3236 if (!context->getExtensions().memoryObject)
3237 {
3238 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3239 return false;
3240 }
3241
3242 UNIMPLEMENTED();
3243 return false;
3244}
3245
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003246bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, MemoryObjectID *memoryObjects)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003247{
3248 if (!context->getExtensions().memoryObject)
3249 {
3250 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3251 return false;
3252 }
3253
Michael Spangfb201c52019-04-03 14:57:35 -04003254 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003255}
3256
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003257bool ValidateDeleteMemoryObjectsEXT(Context *context,
3258 GLsizei n,
3259 const MemoryObjectID *memoryObjects)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003260{
3261 if (!context->getExtensions().memoryObject)
3262 {
3263 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3264 return false;
3265 }
3266
Michael Spangfb201c52019-04-03 14:57:35 -04003267 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003268}
3269
3270bool ValidateGetMemoryObjectParameterivEXT(Context *context,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003271 MemoryObjectID memoryObject,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003272 GLenum pname,
3273 GLint *params)
3274{
3275 if (!context->getExtensions().memoryObject)
3276 {
3277 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3278 return false;
3279 }
3280
3281 UNIMPLEMENTED();
3282 return false;
3283}
3284
3285bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3286{
3287 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3288 {
3289 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3290 return false;
3291 }
3292
3293 UNIMPLEMENTED();
3294 return false;
3295}
3296
3297bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3298{
3299 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3300 {
3301 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3302 return false;
3303 }
3304
3305 UNIMPLEMENTED();
3306 return false;
3307}
3308
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003309bool ValidateIsMemoryObjectEXT(Context *context, MemoryObjectID memoryObject)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003310{
3311 if (!context->getExtensions().memoryObject)
3312 {
3313 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3314 return false;
3315 }
3316
Michael Spangfb201c52019-04-03 14:57:35 -04003317 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003318}
3319
3320bool ValidateMemoryObjectParameterivEXT(Context *context,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003321 MemoryObjectID memoryObject,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003322 GLenum pname,
3323 const GLint *params)
3324{
3325 if (!context->getExtensions().memoryObject)
3326 {
3327 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3328 return false;
3329 }
3330
3331 UNIMPLEMENTED();
3332 return false;
3333}
3334
3335bool ValidateTexStorageMem2DEXT(Context *context,
3336 TextureType target,
3337 GLsizei levels,
3338 GLenum internalFormat,
3339 GLsizei width,
3340 GLsizei height,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003341 MemoryObjectID memory,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003342 GLuint64 offset)
3343{
3344 if (!context->getExtensions().memoryObject)
3345 {
3346 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3347 return false;
3348 }
3349
Michael Spangf02a7672019-04-09 18:45:23 -04003350 if (context->getClientMajorVersion() < 3)
3351 {
3352 return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width,
3353 height);
3354 }
3355
3356 ASSERT(context->getClientMajorVersion() >= 3);
3357 return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height,
3358 1);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003359}
3360
3361bool ValidateTexStorageMem3DEXT(Context *context,
3362 TextureType target,
3363 GLsizei levels,
3364 GLenum internalFormat,
3365 GLsizei width,
3366 GLsizei height,
3367 GLsizei depth,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003368 MemoryObjectID memory,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003369 GLuint64 offset)
3370{
3371 if (!context->getExtensions().memoryObject)
3372 {
3373 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3374 return false;
3375 }
3376
3377 UNIMPLEMENTED();
3378 return false;
3379}
3380
Michael Spang9de3ddb2019-04-03 16:23:40 -04003381bool ValidateImportMemoryFdEXT(Context *context,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003382 MemoryObjectID memory,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003383 GLuint64 size,
Michael Spange0da9ce2019-04-16 14:34:51 -04003384 HandleType handleType,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003385 GLint fd)
3386{
3387 if (!context->getExtensions().memoryObjectFd)
3388 {
3389 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3390 return false;
3391 }
3392
Michael Spang3b2c6bf2019-04-16 17:19:50 -04003393 switch (handleType)
3394 {
3395 case HandleType::OpaqueFd:
3396 break;
3397 default:
3398 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3399 return false;
3400 }
3401
3402 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003403}
3404
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003405bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const SemaphoreID *semaphores)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003406{
3407 if (!context->getExtensions().semaphore)
3408 {
3409 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3410 return false;
3411 }
3412
Michael Spang5093ba62019-05-14 17:36:36 -04003413 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003414}
3415
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003416bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, SemaphoreID *semaphores)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003417{
3418 if (!context->getExtensions().semaphore)
3419 {
3420 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3421 return false;
3422 }
3423
Michael Spang5093ba62019-05-14 17:36:36 -04003424 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003425}
3426
3427bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003428 SemaphoreID semaphore,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003429 GLenum pname,
3430 GLuint64 *params)
3431{
3432 if (!context->getExtensions().semaphore)
3433 {
3434 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3435 return false;
3436 }
3437
3438 UNIMPLEMENTED();
3439 return false;
3440}
3441
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003442bool ValidateIsSemaphoreEXT(Context *context, SemaphoreID semaphore)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003443{
3444 if (!context->getExtensions().semaphore)
3445 {
3446 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3447 return false;
3448 }
3449
Michael Spang5093ba62019-05-14 17:36:36 -04003450 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003451}
3452
3453bool ValidateSemaphoreParameterui64vEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003454 SemaphoreID semaphore,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003455 GLenum pname,
3456 const GLuint64 *params)
3457{
3458 if (!context->getExtensions().semaphore)
3459 {
3460 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3461 return false;
3462 }
3463
3464 UNIMPLEMENTED();
3465 return false;
3466}
3467
3468bool ValidateSignalSemaphoreEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003469 SemaphoreID semaphore,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003470 GLuint numBufferBarriers,
Jamie Madill3b3fe832019-08-06 17:44:12 -04003471 const BufferID *buffers,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003472 GLuint numTextureBarriers,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04003473 const TextureID *textures,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003474 const GLenum *dstLayouts)
3475{
3476 if (!context->getExtensions().semaphore)
3477 {
3478 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3479 return false;
3480 }
3481
Michael Spangab6a59b2019-05-21 21:26:26 -04003482 for (GLuint i = 0; i < numTextureBarriers; ++i)
3483 {
3484 if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i])))
3485 {
3486 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3487 return false;
3488 }
3489 }
3490
3491 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003492}
3493
3494bool ValidateWaitSemaphoreEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003495 SemaphoreID semaphore,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003496 GLuint numBufferBarriers,
Jamie Madill3b3fe832019-08-06 17:44:12 -04003497 const BufferID *buffers,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003498 GLuint numTextureBarriers,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04003499 const TextureID *textures,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003500 const GLenum *srcLayouts)
3501{
3502 if (!context->getExtensions().semaphore)
3503 {
3504 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3505 return false;
3506 }
3507
Michael Spangab6a59b2019-05-21 21:26:26 -04003508 for (GLuint i = 0; i < numTextureBarriers; ++i)
3509 {
3510 if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i])))
3511 {
3512 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3513 return false;
3514 }
3515 }
3516
3517 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003518}
3519
Michael Spange0da9ce2019-04-16 14:34:51 -04003520bool ValidateImportSemaphoreFdEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003521 SemaphoreID semaphore,
Michael Spange0da9ce2019-04-16 14:34:51 -04003522 HandleType handleType,
3523 GLint fd)
Michael Spang9de3ddb2019-04-03 16:23:40 -04003524{
3525 if (!context->getExtensions().semaphoreFd)
3526 {
3527 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3528 return false;
3529 }
3530
Michael Spang6bb193c2019-05-22 16:32:21 -04003531 switch (handleType)
3532 {
3533 case HandleType::OpaqueFd:
3534 break;
3535 default:
3536 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3537 return false;
3538 }
3539
3540 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003541}
3542
Corentin Wallez336129f2017-10-17 15:55:40 -04003543bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003544{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003545 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003546 ASSERT(buffer != nullptr);
3547
3548 // Check if this buffer is currently being used as a transform feedback output buffer
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003549 if (context->getState().isTransformFeedbackActive())
Geoff Lang79f71042017-08-14 16:43:43 -04003550 {
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003551 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003552 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3553 {
3554 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3555 if (transformFeedbackBuffer.get() == buffer)
3556 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003557 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003558 return false;
3559 }
3560 }
3561 }
3562
James Darpiniane8a93c62018-01-04 18:02:24 -08003563 if (context->getExtensions().webglCompatibility &&
3564 buffer->isBoundForTransformFeedbackAndOtherUse())
3565 {
Jamie Madille0472f32018-11-27 16:32:45 -05003566 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003567 return false;
3568 }
3569
Geoff Lang79f71042017-08-14 16:43:43 -04003570 return true;
3571}
3572
Olli Etuaho4f667482016-03-30 15:56:35 +03003573bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003574 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003575 GLintptr offset,
3576 GLsizeiptr length)
3577{
3578 if (!context->getExtensions().mapBufferRange)
3579 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003580 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003581 return false;
3582 }
3583
3584 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3585}
3586
Geoff Langd8605522016-04-13 10:19:12 -04003587bool ValidateBindUniformLocationCHROMIUM(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06003588 ShaderProgramID program,
Geoff Langd8605522016-04-13 10:19:12 -04003589 GLint location,
3590 const GLchar *name)
3591{
3592 if (!context->getExtensions().bindUniformLocation)
3593 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003594 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003595 return false;
3596 }
3597
3598 Program *programObject = GetValidProgram(context, program);
3599 if (!programObject)
3600 {
3601 return false;
3602 }
3603
3604 if (location < 0)
3605 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003606 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003607 return false;
3608 }
3609
3610 const Caps &caps = context->getCaps();
3611 if (static_cast<size_t>(location) >=
3612 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3613 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003614 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003615 return false;
3616 }
3617
Geoff Langfc32e8b2017-05-31 14:16:59 -04003618 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3619 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003620 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003621 {
Jamie Madille0472f32018-11-27 16:32:45 -05003622 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003623 return false;
3624 }
3625
Geoff Langd8605522016-04-13 10:19:12 -04003626 if (strncmp(name, "gl_", 3) == 0)
3627 {
Jamie Madille0472f32018-11-27 16:32:45 -05003628 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003629 return false;
3630 }
3631
3632 return true;
3633}
3634
Jamie Madille2e406c2016-06-02 13:04:10 -04003635bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003636{
3637 if (!context->getExtensions().framebufferMixedSamples)
3638 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003639 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003640 return false;
3641 }
3642 switch (components)
3643 {
3644 case GL_RGB:
3645 case GL_RGBA:
3646 case GL_ALPHA:
3647 case GL_NONE:
3648 break;
3649 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003650 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003651 return false;
3652 }
3653
3654 return true;
3655}
3656
Sami Väisänene45e53b2016-05-25 10:36:04 +03003657// CHROMIUM_path_rendering
3658
Jamie Madill007530e2017-12-28 14:27:04 -05003659bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003660{
Jamie Madill007530e2017-12-28 14:27:04 -05003661 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003662 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003663 return false;
3664 }
Jamie Madill007530e2017-12-28 14:27:04 -05003665
Sami Väisänene45e53b2016-05-25 10:36:04 +03003666 if (matrix == nullptr)
3667 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003668 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003669 return false;
3670 }
Jamie Madill007530e2017-12-28 14:27:04 -05003671
Sami Väisänene45e53b2016-05-25 10:36:04 +03003672 return true;
3673}
3674
Jamie Madill007530e2017-12-28 14:27:04 -05003675bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003676{
Jamie Madill007530e2017-12-28 14:27:04 -05003677 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003678}
3679
Jamie Madill007530e2017-12-28 14:27:04 -05003680bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003681{
3682 if (!context->getExtensions().pathRendering)
3683 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003684 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003685 return false;
3686 }
3687
3688 // range = 0 is undefined in NV_path_rendering.
3689 // we add stricter semantic check here and require a non zero positive range.
3690 if (range <= 0)
3691 {
Jamie Madille0472f32018-11-27 16:32:45 -05003692 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003693 return false;
3694 }
3695
3696 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3697 {
Jamie Madille0472f32018-11-27 16:32:45 -05003698 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003699 return false;
3700 }
3701
3702 return true;
3703}
3704
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003705bool ValidateDeletePathsCHROMIUM(Context *context, PathID path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003706{
3707 if (!context->getExtensions().pathRendering)
3708 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003709 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003710 return false;
3711 }
3712
3713 // range = 0 is undefined in NV_path_rendering.
3714 // we add stricter semantic check here and require a non zero positive range.
3715 if (range <= 0)
3716 {
Jamie Madille0472f32018-11-27 16:32:45 -05003717 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003718 return false;
3719 }
3720
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003721 angle::CheckedNumeric<std::uint32_t> checkedRange(path.value);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003722 checkedRange += range;
3723
3724 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3725 {
Jamie Madille0472f32018-11-27 16:32:45 -05003726 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003727 return false;
3728 }
3729 return true;
3730}
3731
Jamie Madill007530e2017-12-28 14:27:04 -05003732bool ValidatePathCommandsCHROMIUM(Context *context,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003733 PathID path,
Jamie Madill007530e2017-12-28 14:27:04 -05003734 GLsizei numCommands,
3735 const GLubyte *commands,
3736 GLsizei numCoords,
3737 GLenum coordType,
3738 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003739{
3740 if (!context->getExtensions().pathRendering)
3741 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003742 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003743 return false;
3744 }
Brandon Jones59770802018-04-02 13:18:42 -07003745 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003746 {
Jamie Madille0472f32018-11-27 16:32:45 -05003747 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003748 return false;
3749 }
3750
3751 if (numCommands < 0)
3752 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003753 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003754 return false;
3755 }
3756 else if (numCommands > 0)
3757 {
3758 if (!commands)
3759 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003760 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003761 return false;
3762 }
3763 }
3764
3765 if (numCoords < 0)
3766 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003767 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003768 return false;
3769 }
3770 else if (numCoords > 0)
3771 {
3772 if (!coords)
3773 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003774 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003775 return false;
3776 }
3777 }
3778
3779 std::uint32_t coordTypeSize = 0;
3780 switch (coordType)
3781 {
3782 case GL_BYTE:
3783 coordTypeSize = sizeof(GLbyte);
3784 break;
3785
3786 case GL_UNSIGNED_BYTE:
3787 coordTypeSize = sizeof(GLubyte);
3788 break;
3789
3790 case GL_SHORT:
3791 coordTypeSize = sizeof(GLshort);
3792 break;
3793
3794 case GL_UNSIGNED_SHORT:
3795 coordTypeSize = sizeof(GLushort);
3796 break;
3797
3798 case GL_FLOAT:
3799 coordTypeSize = sizeof(GLfloat);
3800 break;
3801
3802 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003803 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003804 return false;
3805 }
3806
3807 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3808 checkedSize += (coordTypeSize * numCoords);
3809 if (!checkedSize.IsValid())
3810 {
Jamie Madille0472f32018-11-27 16:32:45 -05003811 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003812 return false;
3813 }
3814
3815 // early return skips command data validation when it doesn't exist.
3816 if (!commands)
3817 return true;
3818
3819 GLsizei expectedNumCoords = 0;
3820 for (GLsizei i = 0; i < numCommands; ++i)
3821 {
3822 switch (commands[i])
3823 {
3824 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3825 break;
3826 case GL_MOVE_TO_CHROMIUM:
3827 case GL_LINE_TO_CHROMIUM:
3828 expectedNumCoords += 2;
3829 break;
3830 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3831 expectedNumCoords += 4;
3832 break;
3833 case GL_CUBIC_CURVE_TO_CHROMIUM:
3834 expectedNumCoords += 6;
3835 break;
3836 case GL_CONIC_CURVE_TO_CHROMIUM:
3837 expectedNumCoords += 5;
3838 break;
3839 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003840 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003841 return false;
3842 }
3843 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003844
Sami Väisänene45e53b2016-05-25 10:36:04 +03003845 if (expectedNumCoords != numCoords)
3846 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003847 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003848 return false;
3849 }
3850
3851 return true;
3852}
3853
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003854bool ValidatePathParameterfCHROMIUM(Context *context, PathID path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003855{
3856 if (!context->getExtensions().pathRendering)
3857 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003858 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003859 return false;
3860 }
Brandon Jones59770802018-04-02 13:18:42 -07003861 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003862 {
Jamie Madille0472f32018-11-27 16:32:45 -05003863 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003864 return false;
3865 }
3866
3867 switch (pname)
3868 {
3869 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3870 if (value < 0.0f)
3871 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003872 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003873 return false;
3874 }
3875 break;
3876 case GL_PATH_END_CAPS_CHROMIUM:
3877 switch (static_cast<GLenum>(value))
3878 {
3879 case GL_FLAT_CHROMIUM:
3880 case GL_SQUARE_CHROMIUM:
3881 case GL_ROUND_CHROMIUM:
3882 break;
3883 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003884 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003885 return false;
3886 }
3887 break;
3888 case GL_PATH_JOIN_STYLE_CHROMIUM:
3889 switch (static_cast<GLenum>(value))
3890 {
3891 case GL_MITER_REVERT_CHROMIUM:
3892 case GL_BEVEL_CHROMIUM:
3893 case GL_ROUND_CHROMIUM:
3894 break;
3895 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003896 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003897 return false;
3898 }
Nico Weber41b072b2018-02-09 10:01:32 -05003899 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03003900 case GL_PATH_MITER_LIMIT_CHROMIUM:
3901 if (value < 0.0f)
3902 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003903 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003904 return false;
3905 }
3906 break;
3907
3908 case GL_PATH_STROKE_BOUND_CHROMIUM:
3909 // no errors, only clamping.
3910 break;
3911
3912 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003913 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003914 return false;
3915 }
3916 return true;
3917}
3918
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003919bool ValidatePathParameteriCHROMIUM(Context *context, PathID path, GLenum pname, GLint value)
Jamie Madill007530e2017-12-28 14:27:04 -05003920{
3921 // TODO(jmadill): Use proper clamping cast.
3922 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
3923}
3924
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003925bool ValidateGetPathParameterfvCHROMIUM(Context *context, PathID path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003926{
3927 if (!context->getExtensions().pathRendering)
3928 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003929 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003930 return false;
3931 }
3932
Brandon Jones59770802018-04-02 13:18:42 -07003933 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003934 {
Jamie Madille0472f32018-11-27 16:32:45 -05003935 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003936 return false;
3937 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003938
Sami Väisänene45e53b2016-05-25 10:36:04 +03003939 if (!value)
3940 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003941 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003942 return false;
3943 }
3944
3945 switch (pname)
3946 {
3947 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3948 case GL_PATH_END_CAPS_CHROMIUM:
3949 case GL_PATH_JOIN_STYLE_CHROMIUM:
3950 case GL_PATH_MITER_LIMIT_CHROMIUM:
3951 case GL_PATH_STROKE_BOUND_CHROMIUM:
3952 break;
3953
3954 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003955 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003956 return false;
3957 }
3958
3959 return true;
3960}
3961
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003962bool ValidateGetPathParameterivCHROMIUM(Context *context, PathID path, GLenum pname, GLint *value)
Jamie Madill007530e2017-12-28 14:27:04 -05003963{
3964 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
3965 reinterpret_cast<GLfloat *>(value));
3966}
3967
3968bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003969{
3970 if (!context->getExtensions().pathRendering)
3971 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003972 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003973 return false;
3974 }
3975
3976 switch (func)
3977 {
3978 case GL_NEVER:
3979 case GL_ALWAYS:
3980 case GL_LESS:
3981 case GL_LEQUAL:
3982 case GL_EQUAL:
3983 case GL_GEQUAL:
3984 case GL_GREATER:
3985 case GL_NOTEQUAL:
3986 break;
3987 default:
Jamie Madille0472f32018-11-27 16:32:45 -05003988 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003989 return false;
3990 }
3991
3992 return true;
3993}
3994
3995// Note that the spec specifies that for the path drawing commands
3996// if the path object is not an existing path object the command
3997// does nothing and no error is generated.
3998// However if the path object exists but has not been specified any
3999// commands then an error is generated.
4000
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004001bool ValidateStencilFillPathCHROMIUM(Context *context, PathID path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004002{
4003 if (!context->getExtensions().pathRendering)
4004 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004005 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004006 return false;
4007 }
Brandon Jones59770802018-04-02 13:18:42 -07004008 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004009 {
Jamie Madille0472f32018-11-27 16:32:45 -05004010 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004011 return false;
4012 }
4013
4014 switch (fillMode)
4015 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004016 case GL_INVERT:
Sami Väisänene45e53b2016-05-25 10:36:04 +03004017 case GL_COUNT_UP_CHROMIUM:
4018 case GL_COUNT_DOWN_CHROMIUM:
4019 break;
4020 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004021 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004022 return false;
4023 }
4024
4025 if (!isPow2(mask + 1))
4026 {
Jamie Madille0472f32018-11-27 16:32:45 -05004027 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004028 return false;
4029 }
4030
4031 return true;
4032}
4033
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004034bool ValidateStencilStrokePathCHROMIUM(Context *context, PathID path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004035{
4036 if (!context->getExtensions().pathRendering)
4037 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004038 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004039 return false;
4040 }
Jamie Madillc3e37312018-11-30 15:25:39 -05004041
Brandon Jones59770802018-04-02 13:18:42 -07004042 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004043 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004044 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004045 return false;
4046 }
4047
4048 return true;
4049}
4050
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004051bool ValidateCoverPathCHROMIUM(Context *context, PathID path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004052{
4053 if (!context->getExtensions().pathRendering)
4054 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004055 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004056 return false;
4057 }
Brandon Jones59770802018-04-02 13:18:42 -07004058 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004059 {
Jamie Madille0472f32018-11-27 16:32:45 -05004060 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004061 return false;
4062 }
4063
4064 switch (coverMode)
4065 {
4066 case GL_CONVEX_HULL_CHROMIUM:
4067 case GL_BOUNDING_BOX_CHROMIUM:
4068 break;
4069 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004070 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004071 return false;
4072 }
4073 return true;
4074}
4075
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004076bool ValidateCoverFillPathCHROMIUM(Context *context, PathID path, GLenum coverMode)
Jamie Madill778bf092018-11-14 09:54:36 -05004077{
4078 return ValidateCoverPathCHROMIUM(context, path, coverMode);
4079}
4080
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004081bool ValidateCoverStrokePathCHROMIUM(Context *context, PathID path, GLenum coverMode)
Jamie Madill778bf092018-11-14 09:54:36 -05004082{
4083 return ValidateCoverPathCHROMIUM(context, path, coverMode);
4084}
4085
Jamie Madill007530e2017-12-28 14:27:04 -05004086bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004087 PathID path,
Jamie Madill007530e2017-12-28 14:27:04 -05004088 GLenum fillMode,
4089 GLuint mask,
4090 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004091{
Jamie Madill007530e2017-12-28 14:27:04 -05004092 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
4093 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004094}
4095
Jamie Madill007530e2017-12-28 14:27:04 -05004096bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004097 PathID path,
Jamie Madill007530e2017-12-28 14:27:04 -05004098 GLint reference,
4099 GLuint mask,
4100 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004101{
Jamie Madill007530e2017-12-28 14:27:04 -05004102 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
4103 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004104}
4105
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004106bool ValidateIsPathCHROMIUM(Context *context, PathID path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004107{
4108 if (!context->getExtensions().pathRendering)
4109 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004110 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004111 return false;
4112 }
4113 return true;
4114}
4115
Jamie Madill007530e2017-12-28 14:27:04 -05004116bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
4117 GLsizei numPaths,
4118 GLenum pathNameType,
4119 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004120 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004121 GLenum coverMode,
4122 GLenum transformType,
4123 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004124{
4125 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4126 transformType, transformValues))
4127 return false;
4128
4129 switch (coverMode)
4130 {
4131 case GL_CONVEX_HULL_CHROMIUM:
4132 case GL_BOUNDING_BOX_CHROMIUM:
4133 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4134 break;
4135 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004136 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004137 return false;
4138 }
4139
4140 return true;
4141}
4142
Jamie Madill007530e2017-12-28 14:27:04 -05004143bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
4144 GLsizei numPaths,
4145 GLenum pathNameType,
4146 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004147 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004148 GLenum coverMode,
4149 GLenum transformType,
4150 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004151{
4152 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4153 transformType, transformValues))
4154 return false;
4155
4156 switch (coverMode)
4157 {
4158 case GL_CONVEX_HULL_CHROMIUM:
4159 case GL_BOUNDING_BOX_CHROMIUM:
4160 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4161 break;
4162 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004163 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004164 return false;
4165 }
4166
4167 return true;
4168}
4169
Jamie Madill007530e2017-12-28 14:27:04 -05004170bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
4171 GLsizei numPaths,
4172 GLenum pathNameType,
4173 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004174 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004175 GLenum fillMode,
4176 GLuint mask,
4177 GLenum transformType,
4178 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004179{
4180
4181 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4182 transformType, transformValues))
4183 return false;
4184
4185 switch (fillMode)
4186 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004187 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004188 case GL_COUNT_UP_CHROMIUM:
4189 case GL_COUNT_DOWN_CHROMIUM:
4190 break;
4191 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004192 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004193 return false;
4194 }
4195 if (!isPow2(mask + 1))
4196 {
Jamie Madille0472f32018-11-27 16:32:45 -05004197 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004198 return false;
4199 }
4200 return true;
4201}
4202
Jamie Madill007530e2017-12-28 14:27:04 -05004203bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
4204 GLsizei numPaths,
4205 GLenum pathNameType,
4206 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004207 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004208 GLint reference,
4209 GLuint mask,
4210 GLenum transformType,
4211 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004212{
4213 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4214 transformType, transformValues))
4215 return false;
4216
4217 // no more validation here.
4218
4219 return true;
4220}
4221
Jamie Madill007530e2017-12-28 14:27:04 -05004222bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
4223 GLsizei numPaths,
4224 GLenum pathNameType,
4225 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004226 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004227 GLenum fillMode,
4228 GLuint mask,
4229 GLenum coverMode,
4230 GLenum transformType,
4231 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004232{
4233 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4234 transformType, transformValues))
4235 return false;
4236
4237 switch (coverMode)
4238 {
4239 case GL_CONVEX_HULL_CHROMIUM:
4240 case GL_BOUNDING_BOX_CHROMIUM:
4241 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4242 break;
4243 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004244 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004245 return false;
4246 }
4247
4248 switch (fillMode)
4249 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004250 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004251 case GL_COUNT_UP_CHROMIUM:
4252 case GL_COUNT_DOWN_CHROMIUM:
4253 break;
4254 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004255 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004256 return false;
4257 }
4258 if (!isPow2(mask + 1))
4259 {
Jamie Madille0472f32018-11-27 16:32:45 -05004260 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004261 return false;
4262 }
4263
4264 return true;
4265}
4266
Jamie Madill007530e2017-12-28 14:27:04 -05004267bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4268 GLsizei numPaths,
4269 GLenum pathNameType,
4270 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004271 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004272 GLint reference,
4273 GLuint mask,
4274 GLenum coverMode,
4275 GLenum transformType,
4276 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004277{
4278 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4279 transformType, transformValues))
4280 return false;
4281
4282 switch (coverMode)
4283 {
4284 case GL_CONVEX_HULL_CHROMIUM:
4285 case GL_BOUNDING_BOX_CHROMIUM:
4286 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4287 break;
4288 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004289 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004290 return false;
4291 }
4292
4293 return true;
4294}
4295
Jamie Madill007530e2017-12-28 14:27:04 -05004296bool ValidateBindFragmentInputLocationCHROMIUM(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06004297 ShaderProgramID program,
Jamie Madill007530e2017-12-28 14:27:04 -05004298 GLint location,
4299 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004300{
4301 if (!context->getExtensions().pathRendering)
4302 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004303 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004304 return false;
4305 }
4306
4307 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4308 if (location >= MaxLocation)
4309 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004310 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004311 return false;
4312 }
4313
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004314 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004315 if (!programObject)
4316 {
Jamie Madille0472f32018-11-27 16:32:45 -05004317 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004318 return false;
4319 }
4320
4321 if (!name)
4322 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004323 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004324 return false;
4325 }
4326
4327 if (angle::BeginsWith(name, "gl_"))
4328 {
Jamie Madille0472f32018-11-27 16:32:45 -05004329 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004330 return false;
4331 }
4332
4333 return true;
4334}
4335
Jamie Madill007530e2017-12-28 14:27:04 -05004336bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06004337 ShaderProgramID program,
Jamie Madill007530e2017-12-28 14:27:04 -05004338 GLint location,
4339 GLenum genMode,
4340 GLint components,
4341 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004342{
4343 if (!context->getExtensions().pathRendering)
4344 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004345 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004346 return false;
4347 }
4348
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004349 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004350 if (!programObject || programObject->isFlaggedForDeletion())
4351 {
Jamie Madille0472f32018-11-27 16:32:45 -05004352 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004353 return false;
4354 }
4355
4356 if (!programObject->isLinked())
4357 {
Jamie Madille0472f32018-11-27 16:32:45 -05004358 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004359 return false;
4360 }
4361
4362 switch (genMode)
4363 {
4364 case GL_NONE:
4365 if (components != 0)
4366 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004367 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004368 return false;
4369 }
4370 break;
4371
4372 case GL_OBJECT_LINEAR_CHROMIUM:
4373 case GL_EYE_LINEAR_CHROMIUM:
4374 case GL_CONSTANT_CHROMIUM:
4375 if (components < 1 || components > 4)
4376 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004377 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004378 return false;
4379 }
4380 if (!coeffs)
4381 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004382 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004383 return false;
4384 }
4385 break;
4386
4387 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004388 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004389 return false;
4390 }
4391
4392 // If the location is -1 then the command is silently ignored
4393 // and no further validation is needed.
4394 if (location == -1)
4395 return true;
4396
jchen103fd614d2018-08-13 12:21:58 +08004397 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004398
4399 if (!binding.valid)
4400 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004401 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004402 return false;
4403 }
4404
4405 if (binding.type != GL_NONE)
4406 {
4407 GLint expectedComponents = 0;
4408 switch (binding.type)
4409 {
4410 case GL_FLOAT:
4411 expectedComponents = 1;
4412 break;
4413 case GL_FLOAT_VEC2:
4414 expectedComponents = 2;
4415 break;
4416 case GL_FLOAT_VEC3:
4417 expectedComponents = 3;
4418 break;
4419 case GL_FLOAT_VEC4:
4420 expectedComponents = 4;
4421 break;
4422 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004423 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004424 return false;
4425 }
4426 if (expectedComponents != components && genMode != GL_NONE)
4427 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004428 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004429 return false;
4430 }
4431 }
4432 return true;
4433}
4434
Geoff Lang97073d12016-04-20 10:42:34 -07004435bool ValidateCopyTextureCHROMIUM(Context *context,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004436 TextureID sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004437 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004438 TextureTarget destTarget,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004439 TextureID destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004440 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004441 GLint internalFormat,
4442 GLenum destType,
4443 GLboolean unpackFlipY,
4444 GLboolean unpackPremultiplyAlpha,
4445 GLboolean unpackUnmultiplyAlpha)
4446{
4447 if (!context->getExtensions().copyTexture)
4448 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004449 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004450 return false;
4451 }
4452
Geoff Lang4f0e0032017-05-01 16:04:35 -04004453 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004454 if (source == nullptr)
4455 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004456 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004457 return false;
4458 }
4459
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004460 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004461 {
Jamie Madille0472f32018-11-27 16:32:45 -05004462 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004463 return false;
4464 }
4465
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004466 TextureType sourceType = source->getType();
4467 ASSERT(sourceType != TextureType::CubeMap);
4468 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004469
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004470 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004471 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004472 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004473 return false;
4474 }
4475
Geoff Lang4f0e0032017-05-01 16:04:35 -04004476 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4477 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4478 if (sourceWidth == 0 || sourceHeight == 0)
4479 {
Jamie Madille0472f32018-11-27 16:32:45 -05004480 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004481 return false;
4482 }
4483
4484 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4485 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004486 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004487 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004488 return false;
4489 }
4490
Geoff Lang63458a32017-10-30 15:16:53 -04004491 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4492 {
Jamie Madille0472f32018-11-27 16:32:45 -05004493 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004494 return false;
4495 }
4496
Geoff Lang4f0e0032017-05-01 16:04:35 -04004497 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004498 if (dest == nullptr)
4499 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004500 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004501 return false;
4502 }
4503
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004504 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004505 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004506 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004507 return false;
4508 }
4509
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004510 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004511 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004512 {
Jamie Madille0472f32018-11-27 16:32:45 -05004513 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004514 return false;
4515 }
4516
Geoff Lang97073d12016-04-20 10:42:34 -07004517 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4518 {
Geoff Lang97073d12016-04-20 10:42:34 -07004519 return false;
4520 }
4521
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004522 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004523 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004524 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004525 return false;
4526 }
4527
Geoff Lang97073d12016-04-20 10:42:34 -07004528 if (dest->getImmutableFormat())
4529 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004530 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004531 return false;
4532 }
4533
4534 return true;
4535}
4536
4537bool ValidateCopySubTextureCHROMIUM(Context *context,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004538 TextureID sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004539 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004540 TextureTarget destTarget,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004541 TextureID destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004542 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004543 GLint xoffset,
4544 GLint yoffset,
4545 GLint x,
4546 GLint y,
4547 GLsizei width,
4548 GLsizei height,
4549 GLboolean unpackFlipY,
4550 GLboolean unpackPremultiplyAlpha,
4551 GLboolean unpackUnmultiplyAlpha)
4552{
4553 if (!context->getExtensions().copyTexture)
4554 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004555 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004556 return false;
4557 }
4558
Geoff Lang4f0e0032017-05-01 16:04:35 -04004559 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004560 if (source == nullptr)
4561 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004562 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004563 return false;
4564 }
4565
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004566 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004567 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004568 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004569 return false;
4570 }
4571
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004572 TextureType sourceType = source->getType();
4573 ASSERT(sourceType != TextureType::CubeMap);
4574 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004575
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004576 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004577 {
Jamie Madille0472f32018-11-27 16:32:45 -05004578 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004579 return false;
4580 }
4581
4582 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4583 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004584 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004585 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004586 return false;
4587 }
4588
4589 if (x < 0 || y < 0)
4590 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004591 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004592 return false;
4593 }
4594
4595 if (width < 0 || height < 0)
4596 {
Jamie Madille0472f32018-11-27 16:32:45 -05004597 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004598 return false;
4599 }
4600
Geoff Lang4f0e0032017-05-01 16:04:35 -04004601 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4602 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004603 {
Jamie Madille0472f32018-11-27 16:32:45 -05004604 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004605 return false;
4606 }
4607
Geoff Lang4f0e0032017-05-01 16:04:35 -04004608 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4609 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004610 {
Jamie Madille0472f32018-11-27 16:32:45 -05004611 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004612 return false;
4613 }
4614
Geoff Lang63458a32017-10-30 15:16:53 -04004615 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4616 {
Jamie Madille0472f32018-11-27 16:32:45 -05004617 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004618 return false;
4619 }
4620
Geoff Lang4f0e0032017-05-01 16:04:35 -04004621 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004622 if (dest == nullptr)
4623 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004624 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004625 return false;
4626 }
4627
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004628 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004629 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004630 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004631 return false;
4632 }
4633
Brandon Jones28783792018-03-05 09:37:32 -08004634 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4635 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004636 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004637 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004638 return false;
4639 }
4640
Geoff Lang4f0e0032017-05-01 16:04:35 -04004641 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4642 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004643 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004644 return false;
4645 }
4646
4647 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4648 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004649 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004650 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004651 return false;
4652 }
4653
4654 if (xoffset < 0 || yoffset < 0)
4655 {
Jamie Madille0472f32018-11-27 16:32:45 -05004656 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004657 return false;
4658 }
4659
Geoff Lang4f0e0032017-05-01 16:04:35 -04004660 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4661 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004662 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004663 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004664 return false;
4665 }
4666
4667 return true;
4668}
4669
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004670bool ValidateCompressedCopyTextureCHROMIUM(Context *context, TextureID sourceId, TextureID destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004671{
4672 if (!context->getExtensions().copyCompressedTexture)
4673 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004674 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004675 return false;
4676 }
4677
4678 const gl::Texture *source = context->getTexture(sourceId);
4679 if (source == nullptr)
4680 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004681 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004682 return false;
4683 }
4684
Corentin Wallez99d492c2018-02-27 15:17:10 -05004685 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004686 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004687 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004688 return false;
4689 }
4690
Corentin Wallez99d492c2018-02-27 15:17:10 -05004691 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4692 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004693 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004694 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004695 return false;
4696 }
4697
Corentin Wallez99d492c2018-02-27 15:17:10 -05004698 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004699 if (!sourceFormat.info->compressed)
4700 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004701 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004702 return false;
4703 }
4704
4705 const gl::Texture *dest = context->getTexture(destId);
4706 if (dest == nullptr)
4707 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004708 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004709 return false;
4710 }
4711
Corentin Wallez99d492c2018-02-27 15:17:10 -05004712 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004713 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004714 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004715 return false;
4716 }
4717
4718 if (dest->getImmutableFormat())
4719 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004720 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004721 return false;
4722 }
4723
4724 return true;
4725}
4726
Jiawei Shao385b3e02018-03-21 09:43:28 +08004727bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004728{
4729 switch (type)
4730 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004731 case ShaderType::Vertex:
4732 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004733 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004734
Jiawei Shao385b3e02018-03-21 09:43:28 +08004735 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004736 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004737 {
Jamie Madille0472f32018-11-27 16:32:45 -05004738 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004739 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004740 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004741 break;
4742
Jiawei Shao385b3e02018-03-21 09:43:28 +08004743 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004744 if (!context->getExtensions().geometryShader)
4745 {
Jamie Madille0472f32018-11-27 16:32:45 -05004746 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004747 return false;
4748 }
4749 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004750 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004751 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004752 return false;
4753 }
Jamie Madill29639852016-09-02 15:00:09 -04004754
4755 return true;
4756}
4757
Jamie Madill5b772312018-03-08 20:28:32 -05004758bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004759 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004760 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004761 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004762 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004763{
4764 if (size < 0)
4765 {
Jamie Madille0472f32018-11-27 16:32:45 -05004766 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004767 return false;
4768 }
4769
4770 switch (usage)
4771 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004772 case BufferUsage::StreamDraw:
4773 case BufferUsage::StaticDraw:
4774 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004775 break;
4776
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004777 case BufferUsage::StreamRead:
4778 case BufferUsage::StaticRead:
4779 case BufferUsage::DynamicRead:
4780 case BufferUsage::StreamCopy:
4781 case BufferUsage::StaticCopy:
4782 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004783 if (context->getClientMajorVersion() < 3)
4784 {
Jamie Madille0472f32018-11-27 16:32:45 -05004785 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004786 return false;
4787 }
4788 break;
4789
4790 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004791 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004792 return false;
4793 }
4794
Corentin Walleze4477002017-12-01 14:39:58 -05004795 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004796 {
Jamie Madille0472f32018-11-27 16:32:45 -05004797 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004798 return false;
4799 }
4800
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004801 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004802
4803 if (!buffer)
4804 {
Jamie Madille0472f32018-11-27 16:32:45 -05004805 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004806 return false;
4807 }
4808
James Darpiniane8a93c62018-01-04 18:02:24 -08004809 if (context->getExtensions().webglCompatibility &&
4810 buffer->isBoundForTransformFeedbackAndOtherUse())
4811 {
Jamie Madille0472f32018-11-27 16:32:45 -05004812 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004813 return false;
4814 }
4815
Jamie Madill29639852016-09-02 15:00:09 -04004816 return true;
4817}
4818
Jamie Madill5b772312018-03-08 20:28:32 -05004819bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004820 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004821 GLintptr offset,
4822 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004823 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004824{
Brandon Jones6cad5662017-06-14 13:25:13 -07004825 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004826 {
Jamie Madille0472f32018-11-27 16:32:45 -05004827 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004828 return false;
4829 }
4830
4831 if (offset < 0)
4832 {
Jamie Madille0472f32018-11-27 16:32:45 -05004833 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004834 return false;
4835 }
4836
Corentin Walleze4477002017-12-01 14:39:58 -05004837 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004838 {
Jamie Madille0472f32018-11-27 16:32:45 -05004839 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004840 return false;
4841 }
4842
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004843 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004844
4845 if (!buffer)
4846 {
Jamie Madille0472f32018-11-27 16:32:45 -05004847 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004848 return false;
4849 }
4850
4851 if (buffer->isMapped())
4852 {
Jamie Madille0472f32018-11-27 16:32:45 -05004853 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004854 return false;
4855 }
4856
James Darpiniane8a93c62018-01-04 18:02:24 -08004857 if (context->getExtensions().webglCompatibility &&
4858 buffer->isBoundForTransformFeedbackAndOtherUse())
4859 {
Jamie Madille0472f32018-11-27 16:32:45 -05004860 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004861 return false;
4862 }
4863
Jamie Madill29639852016-09-02 15:00:09 -04004864 // Check for possible overflow of size + offset
4865 angle::CheckedNumeric<size_t> checkedSize(size);
4866 checkedSize += offset;
4867 if (!checkedSize.IsValid())
4868 {
Jamie Madille0472f32018-11-27 16:32:45 -05004869 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004870 return false;
4871 }
4872
4873 if (size + offset > buffer->getSize())
4874 {
Jamie Madille0472f32018-11-27 16:32:45 -05004875 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004876 return false;
4877 }
4878
Martin Radev4c4c8e72016-08-04 12:25:34 +03004879 return true;
4880}
4881
Geoff Lang111a99e2017-10-17 10:58:41 -04004882bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04004883{
Geoff Langc339c4e2016-11-29 10:37:36 -05004884 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04004885 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004886 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04004887 return false;
4888 }
4889
Geoff Lang111a99e2017-10-17 10:58:41 -04004890 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04004891 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004892 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04004893 return false;
4894 }
4895
4896 return true;
4897}
4898
Jamie Madill5b772312018-03-08 20:28:32 -05004899bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04004900{
Lingfeng Yang038dd532018-03-29 17:31:52 -07004901 if (context->getClientMajorVersion() < 2)
4902 {
4903 return ValidateMultitextureUnit(context, texture);
4904 }
4905
Jamie Madillef300b12016-10-07 15:12:09 -04004906 if (texture < GL_TEXTURE0 ||
4907 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
4908 {
Jamie Madille0472f32018-11-27 16:32:45 -05004909 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04004910 return false;
4911 }
4912
4913 return true;
4914}
4915
Jiacheng Lu120b61d2019-08-21 12:51:58 -06004916bool ValidateAttachShader(Context *context, ShaderProgramID program, ShaderProgramID shader)
Jamie Madillef300b12016-10-07 15:12:09 -04004917{
4918 Program *programObject = GetValidProgram(context, program);
4919 if (!programObject)
4920 {
4921 return false;
4922 }
4923
4924 Shader *shaderObject = GetValidShader(context, shader);
4925 if (!shaderObject)
4926 {
4927 return false;
4928 }
4929
Jiawei Shao385b3e02018-03-21 09:43:28 +08004930 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04004931 {
Jamie Madille0472f32018-11-27 16:32:45 -05004932 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08004933 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04004934 }
4935
4936 return true;
4937}
4938
Jiacheng Lu120b61d2019-08-21 12:51:58 -06004939bool ValidateBindAttribLocation(Context *context,
4940 ShaderProgramID program,
4941 GLuint index,
4942 const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004943{
4944 if (index >= MAX_VERTEX_ATTRIBS)
4945 {
Jamie Madille0472f32018-11-27 16:32:45 -05004946 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004947 return false;
4948 }
4949
4950 if (strncmp(name, "gl_", 3) == 0)
4951 {
Jamie Madille0472f32018-11-27 16:32:45 -05004952 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004953 return false;
4954 }
4955
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004956 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04004957 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004958 const size_t length = strlen(name);
4959
4960 if (!IsValidESSLString(name, length))
4961 {
4962 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
4963 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05004964 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004965 return false;
4966 }
4967
4968 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
4969 {
4970 return false;
4971 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04004972 }
4973
Jamie Madill01a80ee2016-11-07 12:06:18 -05004974 return GetValidProgram(context, program) != nullptr;
4975}
4976
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06004977bool ValidateBindFramebuffer(Context *context, GLenum target, FramebufferID framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004978{
Geoff Lange8afa902017-09-27 15:00:43 -04004979 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05004980 {
Jamie Madille0472f32018-11-27 16:32:45 -05004981 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004982 return false;
4983 }
4984
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004985 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05004986 !context->isFramebufferGenerated(framebuffer))
4987 {
Jamie Madille0472f32018-11-27 16:32:45 -05004988 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004989 return false;
4990 }
4991
4992 return true;
4993}
4994
Jamie Madill7c7dec02019-08-06 17:44:11 -04004995bool ValidateBindRenderbuffer(Context *context, GLenum target, RenderbufferID renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004996{
4997 if (target != GL_RENDERBUFFER)
4998 {
Jamie Madille0472f32018-11-27 16:32:45 -05004999 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005000 return false;
5001 }
5002
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005003 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05005004 !context->isRenderbufferGenerated(renderbuffer))
5005 {
Jamie Madille0472f32018-11-27 16:32:45 -05005006 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005007 return false;
5008 }
5009
5010 return true;
5011}
5012
Jamie Madill5b772312018-03-08 20:28:32 -05005013static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005014{
5015 switch (mode)
5016 {
5017 case GL_FUNC_ADD:
5018 case GL_FUNC_SUBTRACT:
5019 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04005020 return true;
5021
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005022 case GL_MIN:
5023 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04005024 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005025
5026 default:
5027 return false;
5028 }
5029}
5030
Jamie Madill5b772312018-03-08 20:28:32 -05005031bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005032{
5033 return true;
5034}
5035
Jamie Madill5b772312018-03-08 20:28:32 -05005036bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005037{
Geoff Lang50cac572017-09-26 17:37:43 -04005038 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005039 {
Jamie Madille0472f32018-11-27 16:32:45 -05005040 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005041 return false;
5042 }
5043
5044 return true;
5045}
5046
Jamie Madill5b772312018-03-08 20:28:32 -05005047bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005048{
Geoff Lang50cac572017-09-26 17:37:43 -04005049 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005050 {
Jamie Madille0472f32018-11-27 16:32:45 -05005051 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005052 return false;
5053 }
5054
Geoff Lang50cac572017-09-26 17:37:43 -04005055 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005056 {
Jamie Madille0472f32018-11-27 16:32:45 -05005057 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005058 return false;
5059 }
5060
5061 return true;
5062}
5063
Jamie Madill5b772312018-03-08 20:28:32 -05005064bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005065{
5066 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
5067}
5068
Jamie Madill5b772312018-03-08 20:28:32 -05005069bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005070 GLenum srcRGB,
5071 GLenum dstRGB,
5072 GLenum srcAlpha,
5073 GLenum dstAlpha)
5074{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005075 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005076 {
Jamie Madille0472f32018-11-27 16:32:45 -05005077 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005078 return false;
5079 }
5080
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005081 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005082 {
Jamie Madille0472f32018-11-27 16:32:45 -05005083 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005084 return false;
5085 }
5086
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005087 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005088 {
Jamie Madille0472f32018-11-27 16:32:45 -05005089 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005090 return false;
5091 }
5092
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005093 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005094 {
Jamie Madille0472f32018-11-27 16:32:45 -05005095 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005096 return false;
5097 }
5098
Frank Henigman146e8a12017-03-02 23:22:37 -05005099 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
5100 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005101 {
5102 bool constantColorUsed =
5103 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
5104 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
5105
5106 bool constantAlphaUsed =
5107 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
5108 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
5109
5110 if (constantColorUsed && constantAlphaUsed)
5111 {
Frank Henigman146e8a12017-03-02 23:22:37 -05005112 if (context->getExtensions().webglCompatibility)
5113 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005114 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
5115 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05005116 }
Jamie Madillc3e37312018-11-30 15:25:39 -05005117
5118 WARN() << kConstantColorAlphaLimitation;
5119 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005120 return false;
5121 }
5122 }
5123
5124 return true;
5125}
5126
Geoff Langc339c4e2016-11-29 10:37:36 -05005127bool ValidateGetString(Context *context, GLenum name)
5128{
5129 switch (name)
5130 {
5131 case GL_VENDOR:
5132 case GL_RENDERER:
5133 case GL_VERSION:
5134 case GL_SHADING_LANGUAGE_VERSION:
5135 case GL_EXTENSIONS:
5136 break;
5137
5138 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
5139 if (!context->getExtensions().requestExtension)
5140 {
Jamie Madille0472f32018-11-27 16:32:45 -05005141 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005142 return false;
5143 }
5144 break;
5145
5146 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005147 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005148 return false;
5149 }
5150
5151 return true;
5152}
5153
Jamie Madill5b772312018-03-08 20:28:32 -05005154bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05005155{
5156 if (width <= 0.0f || isNaN(width))
5157 {
Jamie Madille0472f32018-11-27 16:32:45 -05005158 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05005159 return false;
5160 }
5161
5162 return true;
5163}
5164
Jamie Madill5b772312018-03-08 20:28:32 -05005165bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05005166{
5167 if (context->getExtensions().webglCompatibility && zNear > zFar)
5168 {
Jamie Madille0472f32018-11-27 16:32:45 -05005169 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05005170 return false;
5171 }
5172
5173 return true;
5174}
5175
Jamie Madill5b772312018-03-08 20:28:32 -05005176bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005177 GLenum target,
5178 GLenum internalformat,
5179 GLsizei width,
5180 GLsizei height)
5181{
5182 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
5183 height);
5184}
5185
Jamie Madill5b772312018-03-08 20:28:32 -05005186bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005187 GLenum target,
5188 GLsizei samples,
5189 GLenum internalformat,
5190 GLsizei width,
5191 GLsizei height)
5192{
5193 if (!context->getExtensions().framebufferMultisample)
5194 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005195 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05005196 return false;
5197 }
5198
5199 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05005200 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05005201 // generated.
5202 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
5203 {
Jamie Madille0472f32018-11-27 16:32:45 -05005204 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005205 return false;
5206 }
5207
5208 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
5209 // the specified storage. This is different than ES 3.0 in which a sample number higher
5210 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
5211 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
5212 if (context->getClientMajorVersion() >= 3)
5213 {
5214 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
5215 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
5216 {
Jamie Madille0472f32018-11-27 16:32:45 -05005217 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005218 return false;
5219 }
5220 }
5221
5222 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
5223 width, height);
5224}
5225
Jamie Madill5b772312018-03-08 20:28:32 -05005226bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005227{
Geoff Lange8afa902017-09-27 15:00:43 -04005228 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005229 {
Jamie Madille0472f32018-11-27 16:32:45 -05005230 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005231 return false;
5232 }
5233
5234 return true;
5235}
5236
Jamie Madill5b772312018-03-08 20:28:32 -05005237bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005238{
5239 return true;
5240}
5241
Jamie Madill5b772312018-03-08 20:28:32 -05005242bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005243{
5244 return true;
5245}
5246
Jamie Madill5b772312018-03-08 20:28:32 -05005247bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005248{
5249 return true;
5250}
5251
Jamie Madill5b772312018-03-08 20:28:32 -05005252bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005253 GLboolean red,
5254 GLboolean green,
5255 GLboolean blue,
5256 GLboolean alpha)
5257{
5258 return true;
5259}
5260
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005261bool ValidateCompileShader(Context *context, ShaderProgramID shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005262{
5263 return true;
5264}
5265
Jamie Madill5b772312018-03-08 20:28:32 -05005266bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005267{
5268 return true;
5269}
5270
Jamie Madill5b772312018-03-08 20:28:32 -05005271bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005272{
5273 switch (mode)
5274 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005275 case CullFaceMode::Front:
5276 case CullFaceMode::Back:
5277 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005278 break;
5279
5280 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005281 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005282 return false;
5283 }
5284
5285 return true;
5286}
5287
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005288bool ValidateDeleteProgram(Context *context, ShaderProgramID program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005289{
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005290 if (program.value == 0)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005291 {
5292 return false;
5293 }
5294
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005295 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005296 {
5297 if (context->getShader(program))
5298 {
Jamie Madille0472f32018-11-27 16:32:45 -05005299 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005300 return false;
5301 }
5302 else
5303 {
Jamie Madille0472f32018-11-27 16:32:45 -05005304 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005305 return false;
5306 }
5307 }
5308
5309 return true;
5310}
5311
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005312bool ValidateDeleteShader(Context *context, ShaderProgramID shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005313{
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005314 if (shader.value == 0)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005315 {
5316 return false;
5317 }
5318
5319 if (!context->getShader(shader))
5320 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005321 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005322 {
Jamie Madille0472f32018-11-27 16:32:45 -05005323 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005324 return false;
5325 }
5326 else
5327 {
Jamie Madille0472f32018-11-27 16:32:45 -05005328 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005329 return false;
5330 }
5331 }
5332
5333 return true;
5334}
5335
Jamie Madill5b772312018-03-08 20:28:32 -05005336bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005337{
5338 switch (func)
5339 {
5340 case GL_NEVER:
5341 case GL_ALWAYS:
5342 case GL_LESS:
5343 case GL_LEQUAL:
5344 case GL_EQUAL:
5345 case GL_GREATER:
5346 case GL_GEQUAL:
5347 case GL_NOTEQUAL:
5348 break;
5349
5350 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005351 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005352 return false;
5353 }
5354
5355 return true;
5356}
5357
Jamie Madill5b772312018-03-08 20:28:32 -05005358bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005359{
5360 return true;
5361}
5362
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005363bool ValidateDetachShader(Context *context, ShaderProgramID program, ShaderProgramID shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005364{
5365 Program *programObject = GetValidProgram(context, program);
5366 if (!programObject)
5367 {
5368 return false;
5369 }
5370
5371 Shader *shaderObject = GetValidShader(context, shader);
5372 if (!shaderObject)
5373 {
5374 return false;
5375 }
5376
Jiawei Shao385b3e02018-03-21 09:43:28 +08005377 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005378 if (attachedShader != shaderObject)
5379 {
Jamie Madille0472f32018-11-27 16:32:45 -05005380 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005381 return false;
5382 }
5383
5384 return true;
5385}
5386
Jamie Madill5b772312018-03-08 20:28:32 -05005387bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005388{
5389 if (index >= MAX_VERTEX_ATTRIBS)
5390 {
Jamie Madille0472f32018-11-27 16:32:45 -05005391 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005392 return false;
5393 }
5394
5395 return true;
5396}
5397
Jamie Madill5b772312018-03-08 20:28:32 -05005398bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005399{
5400 if (index >= MAX_VERTEX_ATTRIBS)
5401 {
Jamie Madille0472f32018-11-27 16:32:45 -05005402 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005403 return false;
5404 }
5405
5406 return true;
5407}
5408
Jamie Madill5b772312018-03-08 20:28:32 -05005409bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005410{
5411 return true;
5412}
5413
Jamie Madill5b772312018-03-08 20:28:32 -05005414bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005415{
5416 return true;
5417}
5418
Jamie Madill5b772312018-03-08 20:28:32 -05005419bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005420{
5421 switch (mode)
5422 {
5423 case GL_CW:
5424 case GL_CCW:
5425 break;
5426 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005427 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005428 return false;
5429 }
5430
5431 return true;
5432}
5433
Jamie Madill5b772312018-03-08 20:28:32 -05005434bool ValidateGetActiveAttrib(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005435 ShaderProgramID program,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005436 GLuint index,
5437 GLsizei bufsize,
5438 GLsizei *length,
5439 GLint *size,
5440 GLenum *type,
5441 GLchar *name)
5442{
5443 if (bufsize < 0)
5444 {
Jamie Madille0472f32018-11-27 16:32:45 -05005445 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005446 return false;
5447 }
5448
5449 Program *programObject = GetValidProgram(context, program);
5450
5451 if (!programObject)
5452 {
5453 return false;
5454 }
5455
5456 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5457 {
Jamie Madille0472f32018-11-27 16:32:45 -05005458 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459 return false;
5460 }
5461
5462 return true;
5463}
5464
Jamie Madill5b772312018-03-08 20:28:32 -05005465bool ValidateGetActiveUniform(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005466 ShaderProgramID program,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005467 GLuint index,
5468 GLsizei bufsize,
5469 GLsizei *length,
5470 GLint *size,
5471 GLenum *type,
5472 GLchar *name)
5473{
5474 if (bufsize < 0)
5475 {
Jamie Madille0472f32018-11-27 16:32:45 -05005476 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005477 return false;
5478 }
5479
5480 Program *programObject = GetValidProgram(context, program);
5481
5482 if (!programObject)
5483 {
5484 return false;
5485 }
5486
5487 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5488 {
Jamie Madille0472f32018-11-27 16:32:45 -05005489 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005490 return false;
5491 }
5492
5493 return true;
5494}
5495
Jamie Madill5b772312018-03-08 20:28:32 -05005496bool ValidateGetAttachedShaders(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005497 ShaderProgramID program,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005498 GLsizei maxcount,
5499 GLsizei *count,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005500 ShaderProgramID *shaders)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005501{
5502 if (maxcount < 0)
5503 {
Jamie Madille0472f32018-11-27 16:32:45 -05005504 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005505 return false;
5506 }
5507
5508 Program *programObject = GetValidProgram(context, program);
5509
5510 if (!programObject)
5511 {
5512 return false;
5513 }
5514
5515 return true;
5516}
5517
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005518bool ValidateGetAttribLocation(Context *context, ShaderProgramID program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005519{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005520 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5521 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005522 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005523 {
Jamie Madille0472f32018-11-27 16:32:45 -05005524 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005525 return false;
5526 }
5527
Jamie Madillc1d770e2017-04-13 17:31:24 -04005528 Program *programObject = GetValidProgram(context, program);
5529
5530 if (!programObject)
5531 {
Jamie Madille0472f32018-11-27 16:32:45 -05005532 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005533 return false;
5534 }
5535
5536 if (!programObject->isLinked())
5537 {
Jamie Madille0472f32018-11-27 16:32:45 -05005538 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005539 return false;
5540 }
5541
5542 return true;
5543}
5544
Jamie Madill5b772312018-03-08 20:28:32 -05005545bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005546{
5547 GLenum nativeType;
5548 unsigned int numParams = 0;
5549 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5550}
5551
Jamie Madill5b772312018-03-08 20:28:32 -05005552bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005553{
5554 return true;
5555}
5556
Jamie Madill5b772312018-03-08 20:28:32 -05005557bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005558{
5559 GLenum nativeType;
5560 unsigned int numParams = 0;
5561 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5562}
5563
Jamie Madill5b772312018-03-08 20:28:32 -05005564bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005565{
5566 GLenum nativeType;
5567 unsigned int numParams = 0;
5568 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5569}
5570
Jamie Madill5b772312018-03-08 20:28:32 -05005571bool ValidateGetProgramInfoLog(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005572 ShaderProgramID program,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005573 GLsizei bufsize,
5574 GLsizei *length,
5575 GLchar *infolog)
5576{
5577 if (bufsize < 0)
5578 {
Jamie Madille0472f32018-11-27 16:32:45 -05005579 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005580 return false;
5581 }
5582
5583 Program *programObject = GetValidProgram(context, program);
5584 if (!programObject)
5585 {
5586 return false;
5587 }
5588
5589 return true;
5590}
5591
Jamie Madill5b772312018-03-08 20:28:32 -05005592bool ValidateGetShaderInfoLog(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005593 ShaderProgramID shader,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005594 GLsizei bufsize,
5595 GLsizei *length,
5596 GLchar *infolog)
5597{
5598 if (bufsize < 0)
5599 {
Jamie Madille0472f32018-11-27 16:32:45 -05005600 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005601 return false;
5602 }
5603
5604 Shader *shaderObject = GetValidShader(context, shader);
5605 if (!shaderObject)
5606 {
5607 return false;
5608 }
5609
5610 return true;
5611}
5612
Jamie Madill5b772312018-03-08 20:28:32 -05005613bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005614 GLenum shadertype,
5615 GLenum precisiontype,
5616 GLint *range,
5617 GLint *precision)
5618{
5619 switch (shadertype)
5620 {
5621 case GL_VERTEX_SHADER:
5622 case GL_FRAGMENT_SHADER:
5623 break;
5624 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005625 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005626 return false;
5627 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005628 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005629 return false;
5630 }
5631
5632 switch (precisiontype)
5633 {
5634 case GL_LOW_FLOAT:
5635 case GL_MEDIUM_FLOAT:
5636 case GL_HIGH_FLOAT:
5637 case GL_LOW_INT:
5638 case GL_MEDIUM_INT:
5639 case GL_HIGH_INT:
5640 break;
5641
5642 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005643 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005644 return false;
5645 }
5646
5647 return true;
5648}
5649
Jamie Madill5b772312018-03-08 20:28:32 -05005650bool ValidateGetShaderSource(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005651 ShaderProgramID shader,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005652 GLsizei bufsize,
5653 GLsizei *length,
5654 GLchar *source)
5655{
5656 if (bufsize < 0)
5657 {
Jamie Madille0472f32018-11-27 16:32:45 -05005658 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005659 return false;
5660 }
5661
5662 Shader *shaderObject = GetValidShader(context, shader);
5663 if (!shaderObject)
5664 {
5665 return false;
5666 }
5667
5668 return true;
5669}
5670
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005671bool ValidateGetUniformLocation(Context *context, ShaderProgramID program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005672{
5673 if (strstr(name, "gl_") == name)
5674 {
5675 return false;
5676 }
5677
Geoff Langfc32e8b2017-05-31 14:16:59 -04005678 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5679 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005680 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005681 {
Jamie Madille0472f32018-11-27 16:32:45 -05005682 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005683 return false;
5684 }
5685
Jamie Madillc1d770e2017-04-13 17:31:24 -04005686 Program *programObject = GetValidProgram(context, program);
5687
5688 if (!programObject)
5689 {
5690 return false;
5691 }
5692
5693 if (!programObject->isLinked())
5694 {
Jamie Madille0472f32018-11-27 16:32:45 -05005695 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005696 return false;
5697 }
5698
5699 return true;
5700}
5701
Jamie Madill5b772312018-03-08 20:28:32 -05005702bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005703{
5704 switch (mode)
5705 {
5706 case GL_FASTEST:
5707 case GL_NICEST:
5708 case GL_DONT_CARE:
5709 break;
5710
5711 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005712 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005713 return false;
5714 }
5715
5716 switch (target)
5717 {
5718 case GL_GENERATE_MIPMAP_HINT:
5719 break;
5720
Geoff Lange7bd2182017-06-16 16:13:13 -04005721 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5722 if (context->getClientVersion() < ES_3_0 &&
5723 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005724 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005725 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005726 return false;
5727 }
5728 break;
5729
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005730 case GL_PERSPECTIVE_CORRECTION_HINT:
5731 case GL_POINT_SMOOTH_HINT:
5732 case GL_LINE_SMOOTH_HINT:
5733 case GL_FOG_HINT:
5734 if (context->getClientMajorVersion() >= 2)
5735 {
Jamie Madille0472f32018-11-27 16:32:45 -05005736 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005737 return false;
5738 }
5739 break;
5740
Jamie Madillc1d770e2017-04-13 17:31:24 -04005741 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005742 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743 return false;
5744 }
5745
5746 return true;
5747}
5748
Jamie Madill3b3fe832019-08-06 17:44:12 -04005749bool ValidateIsBuffer(Context *context, BufferID buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005750{
5751 return true;
5752}
5753
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06005754bool ValidateIsFramebuffer(Context *context, FramebufferID framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005755{
5756 return true;
5757}
5758
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005759bool ValidateIsProgram(Context *context, ShaderProgramID program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005760{
5761 return true;
5762}
5763
Jamie Madill7c7dec02019-08-06 17:44:11 -04005764bool ValidateIsRenderbuffer(Context *context, RenderbufferID renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005765{
5766 return true;
5767}
5768
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005769bool ValidateIsShader(Context *context, ShaderProgramID shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005770{
5771 return true;
5772}
5773
Jamie Madill2ab08ed2019-08-12 16:20:21 -04005774bool ValidateIsTexture(Context *context, TextureID texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005775{
5776 return true;
5777}
5778
Jamie Madill5b772312018-03-08 20:28:32 -05005779bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005780{
5781 if (context->getClientMajorVersion() < 3)
5782 {
5783 switch (pname)
5784 {
5785 case GL_UNPACK_IMAGE_HEIGHT:
5786 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005787 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005788 return false;
5789
5790 case GL_UNPACK_ROW_LENGTH:
5791 case GL_UNPACK_SKIP_ROWS:
5792 case GL_UNPACK_SKIP_PIXELS:
5793 if (!context->getExtensions().unpackSubimage)
5794 {
Jamie Madille0472f32018-11-27 16:32:45 -05005795 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005796 return false;
5797 }
5798 break;
5799
5800 case GL_PACK_ROW_LENGTH:
5801 case GL_PACK_SKIP_ROWS:
5802 case GL_PACK_SKIP_PIXELS:
5803 if (!context->getExtensions().packSubimage)
5804 {
Jamie Madille0472f32018-11-27 16:32:45 -05005805 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005806 return false;
5807 }
5808 break;
5809 }
5810 }
5811
5812 if (param < 0)
5813 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005814 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005815 return false;
5816 }
5817
5818 switch (pname)
5819 {
5820 case GL_UNPACK_ALIGNMENT:
5821 if (param != 1 && param != 2 && param != 4 && param != 8)
5822 {
Jamie Madille0472f32018-11-27 16:32:45 -05005823 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005824 return false;
5825 }
5826 break;
5827
5828 case GL_PACK_ALIGNMENT:
5829 if (param != 1 && param != 2 && param != 4 && param != 8)
5830 {
Jamie Madille0472f32018-11-27 16:32:45 -05005831 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005832 return false;
5833 }
5834 break;
5835
5836 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005837 if (!context->getExtensions().packReverseRowOrder)
5838 {
Jamie Madille0472f32018-11-27 16:32:45 -05005839 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005840 }
5841 break;
5842
Jamie Madillc1d770e2017-04-13 17:31:24 -04005843 case GL_UNPACK_ROW_LENGTH:
5844 case GL_UNPACK_IMAGE_HEIGHT:
5845 case GL_UNPACK_SKIP_IMAGES:
5846 case GL_UNPACK_SKIP_ROWS:
5847 case GL_UNPACK_SKIP_PIXELS:
5848 case GL_PACK_ROW_LENGTH:
5849 case GL_PACK_SKIP_ROWS:
5850 case GL_PACK_SKIP_PIXELS:
5851 break;
5852
5853 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005854 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005855 return false;
5856 }
5857
5858 return true;
5859}
5860
Jamie Madill5b772312018-03-08 20:28:32 -05005861bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005862{
5863 return true;
5864}
5865
Jamie Madill5b772312018-03-08 20:28:32 -05005866bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005867{
5868 return true;
5869}
5870
Jamie Madill5b772312018-03-08 20:28:32 -05005871bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005872{
5873 return true;
5874}
5875
Jamie Madill5b772312018-03-08 20:28:32 -05005876bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005877{
5878 if (width < 0 || height < 0)
5879 {
Jamie Madille0472f32018-11-27 16:32:45 -05005880 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005881 return false;
5882 }
5883
5884 return true;
5885}
5886
Jamie Madill5b772312018-03-08 20:28:32 -05005887bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005888 GLsizei n,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005889 const ShaderProgramID *shaders,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005890 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005891 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005892 GLsizei length)
5893{
5894 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
5895 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
5896 shaderBinaryFormats.end())
5897 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005898 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005899 return false;
5900 }
5901
5902 return true;
5903}
5904
Jamie Madill5b772312018-03-08 20:28:32 -05005905bool ValidateShaderSource(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005906 ShaderProgramID shader,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005907 GLsizei count,
5908 const GLchar *const *string,
5909 const GLint *length)
5910{
5911 if (count < 0)
5912 {
Jamie Madille0472f32018-11-27 16:32:45 -05005913 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005914 return false;
5915 }
5916
Geoff Langfc32e8b2017-05-31 14:16:59 -04005917 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5918 // shader-related entry points
5919 if (context->getExtensions().webglCompatibility)
5920 {
5921 for (GLsizei i = 0; i < count; i++)
5922 {
Geoff Langcab92ee2017-07-19 17:32:07 -04005923 size_t len =
5924 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04005925
5926 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04005927 if (!IsValidESSLShaderSourceString(string[i], len,
5928 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005929 {
Jamie Madille0472f32018-11-27 16:32:45 -05005930 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005931 return false;
5932 }
5933 }
5934 }
5935
Jamie Madillc1d770e2017-04-13 17:31:24 -04005936 Shader *shaderObject = GetValidShader(context, shader);
5937 if (!shaderObject)
5938 {
5939 return false;
5940 }
5941
5942 return true;
5943}
5944
Jamie Madill5b772312018-03-08 20:28:32 -05005945bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005946{
5947 if (!IsValidStencilFunc(func))
5948 {
Jamie Madille0472f32018-11-27 16:32:45 -05005949 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005950 return false;
5951 }
5952
5953 return true;
5954}
5955
Jamie Madill5b772312018-03-08 20:28:32 -05005956bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005957{
5958 if (!IsValidStencilFace(face))
5959 {
Jamie Madille0472f32018-11-27 16:32:45 -05005960 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005961 return false;
5962 }
5963
5964 if (!IsValidStencilFunc(func))
5965 {
Jamie Madille0472f32018-11-27 16:32:45 -05005966 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005967 return false;
5968 }
5969
5970 return true;
5971}
5972
Jamie Madill5b772312018-03-08 20:28:32 -05005973bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005974{
5975 return true;
5976}
5977
Jamie Madill5b772312018-03-08 20:28:32 -05005978bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005979{
5980 if (!IsValidStencilFace(face))
5981 {
Jamie Madille0472f32018-11-27 16:32:45 -05005982 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005983 return false;
5984 }
5985
5986 return true;
5987}
5988
Jamie Madill5b772312018-03-08 20:28:32 -05005989bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005990{
5991 if (!IsValidStencilOp(fail))
5992 {
Jamie Madille0472f32018-11-27 16:32:45 -05005993 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005994 return false;
5995 }
5996
5997 if (!IsValidStencilOp(zfail))
5998 {
Jamie Madille0472f32018-11-27 16:32:45 -05005999 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006000 return false;
6001 }
6002
6003 if (!IsValidStencilOp(zpass))
6004 {
Jamie Madille0472f32018-11-27 16:32:45 -05006005 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006006 return false;
6007 }
6008
6009 return true;
6010}
6011
Jamie Madill5b772312018-03-08 20:28:32 -05006012bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006013 GLenum face,
6014 GLenum fail,
6015 GLenum zfail,
6016 GLenum zpass)
6017{
6018 if (!IsValidStencilFace(face))
6019 {
Jamie Madille0472f32018-11-27 16:32:45 -05006020 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006021 return false;
6022 }
6023
6024 return ValidateStencilOp(context, fail, zfail, zpass);
6025}
6026
Jamie Madill5b772312018-03-08 20:28:32 -05006027bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006028{
6029 return ValidateUniform(context, GL_FLOAT, location, 1);
6030}
6031
Jamie Madill5b772312018-03-08 20:28:32 -05006032bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006033{
6034 return ValidateUniform(context, GL_FLOAT, location, count);
6035}
6036
Jamie Madill5b772312018-03-08 20:28:32 -05006037bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04006038{
6039 return ValidateUniform1iv(context, location, 1, &x);
6040}
6041
Jamie Madill5b772312018-03-08 20:28:32 -05006042bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006043{
6044 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
6045}
6046
Jamie Madill5b772312018-03-08 20:28:32 -05006047bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006048{
6049 return ValidateUniform(context, GL_INT_VEC2, location, 1);
6050}
6051
Jamie Madill5b772312018-03-08 20:28:32 -05006052bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006053{
6054 return ValidateUniform(context, GL_INT_VEC2, location, count);
6055}
6056
Jamie Madill5b772312018-03-08 20:28:32 -05006057bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006058{
6059 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
6060}
6061
Jamie Madill5b772312018-03-08 20:28:32 -05006062bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006063{
6064 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
6065}
6066
Jamie Madill5b772312018-03-08 20:28:32 -05006067bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006068{
6069 return ValidateUniform(context, GL_INT_VEC3, location, 1);
6070}
6071
Jamie Madill5b772312018-03-08 20:28:32 -05006072bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006073{
6074 return ValidateUniform(context, GL_INT_VEC3, location, count);
6075}
6076
Jamie Madill5b772312018-03-08 20:28:32 -05006077bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006078{
6079 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
6080}
6081
Jamie Madill5b772312018-03-08 20:28:32 -05006082bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006083{
6084 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
6085}
6086
Jamie Madill5b772312018-03-08 20:28:32 -05006087bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006088{
6089 return ValidateUniform(context, GL_INT_VEC4, location, 1);
6090}
6091
Jamie Madill5b772312018-03-08 20:28:32 -05006092bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006093{
6094 return ValidateUniform(context, GL_INT_VEC4, location, count);
6095}
6096
Jamie Madill5b772312018-03-08 20:28:32 -05006097bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006098 GLint location,
6099 GLsizei count,
6100 GLboolean transpose,
6101 const GLfloat *value)
6102{
6103 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
6104}
6105
Jamie Madill5b772312018-03-08 20:28:32 -05006106bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006107 GLint location,
6108 GLsizei count,
6109 GLboolean transpose,
6110 const GLfloat *value)
6111{
6112 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
6113}
6114
Jamie Madill5b772312018-03-08 20:28:32 -05006115bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006116 GLint location,
6117 GLsizei count,
6118 GLboolean transpose,
6119 const GLfloat *value)
6120{
6121 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
6122}
6123
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006124bool ValidateValidateProgram(Context *context, ShaderProgramID program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006125{
6126 Program *programObject = GetValidProgram(context, program);
6127
6128 if (!programObject)
6129 {
6130 return false;
6131 }
6132
6133 return true;
6134}
6135
Jamie Madill5b772312018-03-08 20:28:32 -05006136bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006137{
6138 return ValidateVertexAttribIndex(context, index);
6139}
6140
Jamie Madill5b772312018-03-08 20:28:32 -05006141bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006142{
6143 return ValidateVertexAttribIndex(context, index);
6144}
6145
Jamie Madill5b772312018-03-08 20:28:32 -05006146bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006147{
6148 return ValidateVertexAttribIndex(context, index);
6149}
6150
Jamie Madill5b772312018-03-08 20:28:32 -05006151bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006152{
6153 return ValidateVertexAttribIndex(context, index);
6154}
6155
Jamie Madill5b772312018-03-08 20:28:32 -05006156bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006157{
6158 return ValidateVertexAttribIndex(context, index);
6159}
6160
Jamie Madill5b772312018-03-08 20:28:32 -05006161bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006162{
6163 return ValidateVertexAttribIndex(context, index);
6164}
6165
Jamie Madill5b772312018-03-08 20:28:32 -05006166bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006167 GLuint index,
6168 GLfloat x,
6169 GLfloat y,
6170 GLfloat z,
6171 GLfloat w)
6172{
6173 return ValidateVertexAttribIndex(context, index);
6174}
6175
Jamie Madill5b772312018-03-08 20:28:32 -05006176bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006177{
6178 return ValidateVertexAttribIndex(context, index);
6179}
6180
Jamie Madill5b772312018-03-08 20:28:32 -05006181bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006182{
6183 if (width < 0 || height < 0)
6184 {
Jamie Madille0472f32018-11-27 16:32:45 -05006185 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006186 return false;
6187 }
6188
6189 return true;
6190}
6191
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08006192bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006193 GLenum target,
6194 GLenum attachment,
6195 GLenum pname,
6196 GLint *params)
6197{
6198 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
6199 nullptr);
6200}
6201
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006202bool ValidateGetProgramiv(Context *context, ShaderProgramID program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006203{
6204 return ValidateGetProgramivBase(context, program, pname, nullptr);
6205}
6206
Jamie Madill5b772312018-03-08 20:28:32 -05006207bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006208 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006209 GLint level,
6210 GLenum internalformat,
6211 GLint x,
6212 GLint y,
6213 GLsizei width,
6214 GLsizei height,
6215 GLint border)
6216{
6217 if (context->getClientMajorVersion() < 3)
6218 {
6219 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
6220 0, x, y, width, height, border);
6221 }
6222
6223 ASSERT(context->getClientMajorVersion() == 3);
6224 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
6225 0, x, y, width, height, border);
6226}
6227
6228bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006229 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006230 GLint level,
6231 GLint xoffset,
6232 GLint yoffset,
6233 GLint x,
6234 GLint y,
6235 GLsizei width,
6236 GLsizei height)
6237{
6238 if (context->getClientMajorVersion() < 3)
6239 {
6240 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
6241 yoffset, x, y, width, height, 0);
6242 }
6243
6244 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
6245 yoffset, 0, x, y, width, height, 0);
6246}
6247
Cody Northrop5faff912019-06-28 14:04:50 -06006248bool ValidateCopyTexSubImage3DOES(Context *context,
6249 TextureTarget target,
6250 GLint level,
6251 GLint xoffset,
6252 GLint yoffset,
6253 GLint zoffset,
6254 GLint x,
6255 GLint y,
6256 GLsizei width,
6257 GLsizei height)
6258{
6259 return ValidateCopyTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, x, y, width,
6260 height);
6261}
6262
Jamie Madill3b3fe832019-08-06 17:44:12 -04006263bool ValidateDeleteBuffers(Context *context, GLint n, const BufferID *buffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006264{
6265 return ValidateGenOrDelete(context, n);
6266}
6267
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06006268bool ValidateDeleteFramebuffers(Context *context, GLint n, const FramebufferID *framebuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006269{
6270 return ValidateGenOrDelete(context, n);
6271}
6272
Jamie Madill7c7dec02019-08-06 17:44:11 -04006273bool ValidateDeleteRenderbuffers(Context *context, GLint n, const RenderbufferID *renderbuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006274{
6275 return ValidateGenOrDelete(context, n);
6276}
6277
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006278bool ValidateDeleteTextures(Context *context, GLint n, const TextureID *textures)
Jamie Madillbe849e42017-05-02 15:49:00 -04006279{
6280 return ValidateGenOrDelete(context, n);
6281}
6282
6283bool ValidateDisable(Context *context, GLenum cap)
6284{
6285 if (!ValidCap(context, cap, false))
6286 {
Jamie Madille0472f32018-11-27 16:32:45 -05006287 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006288 return false;
6289 }
6290
6291 return true;
6292}
6293
6294bool ValidateEnable(Context *context, GLenum cap)
6295{
6296 if (!ValidCap(context, cap, false))
6297 {
Jamie Madille0472f32018-11-27 16:32:45 -05006298 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006299 return false;
6300 }
6301
6302 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6303 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6304 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006305 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006306
6307 // We also output an error message to the debugger window if tracing is active, so that
6308 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006309 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006310 return false;
6311 }
6312
6313 return true;
6314}
6315
6316bool ValidateFramebufferRenderbuffer(Context *context,
6317 GLenum target,
6318 GLenum attachment,
6319 GLenum renderbuffertarget,
Jamie Madill7c7dec02019-08-06 17:44:11 -04006320 RenderbufferID renderbuffer)
Jamie Madillbe849e42017-05-02 15:49:00 -04006321{
Geoff Lange8afa902017-09-27 15:00:43 -04006322 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006323 {
Jamie Madille0472f32018-11-27 16:32:45 -05006324 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006325 return false;
6326 }
6327
Jamie Madill7c7dec02019-08-06 17:44:11 -04006328 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer.value != 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006329 {
Jamie Madille0472f32018-11-27 16:32:45 -05006330 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006331 return false;
6332 }
6333
6334 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6335 renderbuffertarget, renderbuffer);
6336}
6337
6338bool ValidateFramebufferTexture2D(Context *context,
6339 GLenum target,
6340 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006341 TextureTarget textarget,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006342 TextureID texture,
Jamie Madillbe849e42017-05-02 15:49:00 -04006343 GLint level)
6344{
6345 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6346 // extension
6347 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6348 level != 0)
6349 {
Jamie Madille0472f32018-11-27 16:32:45 -05006350 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006351 return false;
6352 }
6353
6354 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6355 {
6356 return false;
6357 }
6358
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006359 if (texture.value != 0)
Jamie Madillbe849e42017-05-02 15:49:00 -04006360 {
6361 gl::Texture *tex = context->getTexture(texture);
6362 ASSERT(tex);
6363
6364 const gl::Caps &caps = context->getCaps();
6365
6366 switch (textarget)
6367 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006368 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006369 {
6370 if (level > gl::log2(caps.max2DTextureSize))
6371 {
Jamie Madille0472f32018-11-27 16:32:45 -05006372 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006373 return false;
6374 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006375 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006376 {
Jamie Madille0472f32018-11-27 16:32:45 -05006377 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006378 return false;
6379 }
6380 }
6381 break;
6382
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006383 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006384 {
6385 if (level != 0)
6386 {
Jamie Madille0472f32018-11-27 16:32:45 -05006387 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006388 return false;
6389 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006390 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006391 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006392 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006393 return false;
6394 }
6395 }
6396 break;
6397
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006398 case TextureTarget::CubeMapNegativeX:
6399 case TextureTarget::CubeMapNegativeY:
6400 case TextureTarget::CubeMapNegativeZ:
6401 case TextureTarget::CubeMapPositiveX:
6402 case TextureTarget::CubeMapPositiveY:
6403 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006404 {
6405 if (level > gl::log2(caps.maxCubeMapTextureSize))
6406 {
Jamie Madille0472f32018-11-27 16:32:45 -05006407 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006408 return false;
6409 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006410 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006411 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006412 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006413 return false;
6414 }
6415 }
6416 break;
6417
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006418 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006419 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006420 if (context->getClientVersion() < ES_3_1 &&
6421 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006422 {
Jamie Madill610640f2018-11-21 17:28:41 -05006423 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006424 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006425 return false;
6426 }
6427
6428 if (level != 0)
6429 {
Jamie Madille0472f32018-11-27 16:32:45 -05006430 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006431 return false;
6432 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006433 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006434 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006435 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006436 return false;
6437 }
6438 }
6439 break;
6440
6441 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006442 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006443 return false;
6444 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006445 }
6446
6447 return true;
6448}
6449
Cody Northrop5faff912019-06-28 14:04:50 -06006450bool ValidateFramebufferTexture3DOES(Context *context,
6451 GLenum target,
6452 GLenum attachment,
6453 TextureTarget textargetPacked,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006454 TextureID texture,
Cody Northrop5faff912019-06-28 14:04:50 -06006455 GLint level,
6456 GLint zoffset)
6457{
Cody Northrop90958e32019-08-07 16:26:14 -06006458 // We don't call into a base ValidateFramebufferTexture3D here because
6459 // it doesn't exist for OpenGL ES. This function is replaced by
6460 // FramebufferTextureLayer in ES 3.x, which has broader support.
6461 if (!context->getExtensions().texture3DOES)
6462 {
6463 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6464 return false;
6465 }
6466
6467 // Attachments are required to be bound to level 0 without ES3 or the
6468 // GL_OES_fbo_render_mipmap extension
6469 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6470 level != 0)
6471 {
6472 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
6473 return false;
6474 }
6475
6476 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6477 {
6478 return false;
6479 }
6480
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006481 if (texture.value != 0)
Cody Northrop90958e32019-08-07 16:26:14 -06006482 {
6483 gl::Texture *tex = context->getTexture(texture);
6484 ASSERT(tex);
6485
6486 const gl::Caps &caps = context->getCaps();
6487
6488 switch (textargetPacked)
6489 {
6490 case TextureTarget::_3D:
6491 {
6492 if (level > gl::log2(caps.max3DTextureSize))
6493 {
6494 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
6495 return false;
6496 }
6497 if (static_cast<size_t>(zoffset) >= caps.max3DTextureSize)
6498 {
6499 context->validationError(GL_INVALID_VALUE, kInvalidZOffset);
6500 return false;
6501 }
6502 if (tex->getType() != TextureType::_3D)
6503 {
6504 context->validationError(GL_INVALID_OPERATION, kInvalidTextureType);
6505 return false;
6506 }
6507 }
6508 break;
6509
6510 default:
6511 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
6512 return false;
6513 }
6514 }
6515
6516 return true;
Cody Northrop5faff912019-06-28 14:04:50 -06006517}
6518
Jamie Madill3b3fe832019-08-06 17:44:12 -04006519bool ValidateGenBuffers(Context *context, GLint n, BufferID *buffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006520{
6521 return ValidateGenOrDelete(context, n);
6522}
6523
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06006524bool ValidateGenFramebuffers(Context *context, GLint n, FramebufferID *framebuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006525{
6526 return ValidateGenOrDelete(context, n);
6527}
6528
Jamie Madill7c7dec02019-08-06 17:44:11 -04006529bool ValidateGenRenderbuffers(Context *context, GLint n, RenderbufferID *renderbuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006530{
6531 return ValidateGenOrDelete(context, n);
6532}
6533
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006534bool ValidateGenTextures(Context *context, GLint n, TextureID *textures)
Jamie Madillbe849e42017-05-02 15:49:00 -04006535{
6536 return ValidateGenOrDelete(context, n);
6537}
6538
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006539bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006540{
6541 if (!ValidTextureTarget(context, target))
6542 {
Jamie Madille0472f32018-11-27 16:32:45 -05006543 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006544 return false;
6545 }
6546
Jamie Madillcfc73cc2019-04-08 16:26:51 -04006547 Texture *texture = context->getTextureByType(target);
Jamie Madillbe849e42017-05-02 15:49:00 -04006548
6549 if (texture == nullptr)
6550 {
Jamie Madille0472f32018-11-27 16:32:45 -05006551 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006552 return false;
6553 }
6554
6555 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6556
6557 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6558 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6559 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6560 {
Jamie Madille0472f32018-11-27 16:32:45 -05006561 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006562 return false;
6563 }
6564
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006565 TextureTarget baseTarget = (target == TextureType::CubeMap)
6566 ? TextureTarget::CubeMapPositiveX
6567 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006568 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6569 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6570 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006571 {
Jamie Madille0472f32018-11-27 16:32:45 -05006572 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006573 return false;
6574 }
6575
Geoff Lang536eca12017-09-13 11:23:35 -04006576 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6577 bool formatUnsized = !format.sized;
6578 bool formatColorRenderableAndFilterable =
6579 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006580 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006581 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006582 {
Jamie Madille0472f32018-11-27 16:32:45 -05006583 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006584 return false;
6585 }
6586
Geoff Lang536eca12017-09-13 11:23:35 -04006587 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6588 // generation
6589 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6590 {
Jamie Madille0472f32018-11-27 16:32:45 -05006591 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006592 return false;
6593 }
6594
Jiange2c00842018-07-13 16:50:49 +08006595 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6596 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6597 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006598 {
Jamie Madille0472f32018-11-27 16:32:45 -05006599 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006600 return false;
6601 }
6602
6603 // Non-power of 2 ES2 check
6604 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6605 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6606 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6607 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006608 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6609 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006610 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006611 return false;
6612 }
6613
6614 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006615 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006616 {
Jamie Madille0472f32018-11-27 16:32:45 -05006617 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006618 return false;
6619 }
6620
James Darpinian83b2f0e2018-11-27 15:56:01 -08006621 if (context->getExtensions().webglCompatibility &&
6622 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6623 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6624 {
6625 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6626 return false;
6627 }
6628
Jamie Madillbe849e42017-05-02 15:49:00 -04006629 return true;
6630}
6631
Jamie Madill5b772312018-03-08 20:28:32 -05006632bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006633 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006634 GLenum pname,
6635 GLint *params)
6636{
6637 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6638}
6639
6640bool ValidateGetRenderbufferParameteriv(Context *context,
6641 GLenum target,
6642 GLenum pname,
6643 GLint *params)
6644{
6645 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6646}
6647
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006648bool ValidateGetShaderiv(Context *context, ShaderProgramID shader, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006649{
6650 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6651}
6652
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006653bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006654{
6655 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6656}
6657
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006658bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006659{
6660 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6661}
6662
Till Rathmannb8543632018-10-02 19:46:14 +02006663bool ValidateGetTexParameterIivOES(Context *context,
6664 TextureType target,
6665 GLenum pname,
6666 GLint *params)
6667{
6668 if (context->getClientMajorVersion() < 3)
6669 {
Jamie Madille0472f32018-11-27 16:32:45 -05006670 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006671 return false;
6672 }
6673 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6674}
6675
6676bool ValidateGetTexParameterIuivOES(Context *context,
6677 TextureType target,
6678 GLenum pname,
6679 GLuint *params)
6680{
6681 if (context->getClientMajorVersion() < 3)
6682 {
Jamie Madille0472f32018-11-27 16:32:45 -05006683 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006684 return false;
6685 }
6686 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6687}
6688
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006689bool ValidateGetUniformfv(Context *context,
6690 ShaderProgramID program,
6691 GLint location,
6692 GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006693{
6694 return ValidateGetUniformBase(context, program, location);
6695}
6696
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006697bool ValidateGetUniformiv(Context *context, ShaderProgramID program, GLint location, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006698{
6699 return ValidateGetUniformBase(context, program, location);
6700}
6701
6702bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6703{
6704 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6705}
6706
6707bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6708{
6709 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6710}
6711
6712bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6713{
6714 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6715}
6716
6717bool ValidateIsEnabled(Context *context, GLenum cap)
6718{
6719 if (!ValidCap(context, cap, true))
6720 {
Jamie Madille0472f32018-11-27 16:32:45 -05006721 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006722 return false;
6723 }
6724
6725 return true;
6726}
6727
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006728bool ValidateLinkProgram(Context *context, ShaderProgramID program)
Jamie Madillbe849e42017-05-02 15:49:00 -04006729{
6730 if (context->hasActiveTransformFeedback(program))
6731 {
6732 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006733 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006734 return false;
6735 }
6736
6737 Program *programObject = GetValidProgram(context, program);
6738 if (!programObject)
6739 {
6740 return false;
6741 }
6742
6743 return true;
6744}
6745
Jamie Madill4928b7c2017-06-20 12:57:39 -04006746bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006747 GLint x,
6748 GLint y,
6749 GLsizei width,
6750 GLsizei height,
6751 GLenum format,
6752 GLenum type,
6753 void *pixels)
6754{
6755 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6756 nullptr, pixels);
6757}
6758
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006759bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006760{
Till Rathmannb8543632018-10-02 19:46:14 +02006761 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006762}
6763
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006764bool ValidateTexParameterfv(Context *context,
6765 TextureType target,
6766 GLenum pname,
6767 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006768{
Till Rathmannb8543632018-10-02 19:46:14 +02006769 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006770}
6771
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006772bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006773{
Till Rathmannb8543632018-10-02 19:46:14 +02006774 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006775}
6776
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006777bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006778{
Till Rathmannb8543632018-10-02 19:46:14 +02006779 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6780}
6781
6782bool ValidateTexParameterIivOES(Context *context,
6783 TextureType target,
6784 GLenum pname,
6785 const GLint *params)
6786{
6787 if (context->getClientMajorVersion() < 3)
6788 {
Jamie Madille0472f32018-11-27 16:32:45 -05006789 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006790 return false;
6791 }
6792 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6793}
6794
6795bool ValidateTexParameterIuivOES(Context *context,
6796 TextureType target,
6797 GLenum pname,
6798 const GLuint *params)
6799{
6800 if (context->getClientMajorVersion() < 3)
6801 {
Jamie Madille0472f32018-11-27 16:32:45 -05006802 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006803 return false;
6804 }
6805 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006806}
6807
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006808bool ValidateUseProgram(Context *context, ShaderProgramID program)
Jamie Madillbe849e42017-05-02 15:49:00 -04006809{
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006810 if (program.value != 0)
Jamie Madillbe849e42017-05-02 15:49:00 -04006811 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006812 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006813 if (!programObject)
6814 {
6815 // ES 3.1.0 section 7.3 page 72
6816 if (context->getShader(program))
6817 {
Jamie Madille0472f32018-11-27 16:32:45 -05006818 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006819 return false;
6820 }
6821 else
6822 {
Jamie Madille0472f32018-11-27 16:32:45 -05006823 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006824 return false;
6825 }
6826 }
6827 if (!programObject->isLinked())
6828 {
Jamie Madille0472f32018-11-27 16:32:45 -05006829 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006830 return false;
6831 }
6832 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006833 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006834 {
6835 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006836 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006837 return false;
6838 }
6839
6840 return true;
6841}
6842
Jiacheng Lu962503e2019-08-21 13:18:30 -06006843bool ValidateDeleteFencesNV(Context *context, GLsizei n, const FenceNVID *fences)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006844{
6845 if (!context->getExtensions().fence)
6846 {
Jamie Madille0472f32018-11-27 16:32:45 -05006847 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006848 return false;
6849 }
6850
6851 if (n < 0)
6852 {
Jamie Madille0472f32018-11-27 16:32:45 -05006853 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006854 return false;
6855 }
6856
6857 return true;
6858}
6859
Jiacheng Lu962503e2019-08-21 13:18:30 -06006860bool ValidateFinishFenceNV(Context *context, FenceNVID fence)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006861{
6862 if (!context->getExtensions().fence)
6863 {
Jamie Madille0472f32018-11-27 16:32:45 -05006864 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006865 return false;
6866 }
6867
6868 FenceNV *fenceObject = context->getFenceNV(fence);
6869
6870 if (fenceObject == nullptr)
6871 {
Jamie Madille0472f32018-11-27 16:32:45 -05006872 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006873 return false;
6874 }
6875
6876 if (!fenceObject->isSet())
6877 {
Jamie Madille0472f32018-11-27 16:32:45 -05006878 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006879 return false;
6880 }
6881
6882 return true;
6883}
6884
Jiacheng Lu962503e2019-08-21 13:18:30 -06006885bool ValidateGenFencesNV(Context *context, GLsizei n, FenceNVID *fences)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006886{
6887 if (!context->getExtensions().fence)
6888 {
Jamie Madille0472f32018-11-27 16:32:45 -05006889 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006890 return false;
6891 }
6892
6893 if (n < 0)
6894 {
Jamie Madille0472f32018-11-27 16:32:45 -05006895 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006896 return false;
6897 }
6898
6899 return true;
6900}
6901
Jiacheng Lu962503e2019-08-21 13:18:30 -06006902bool ValidateGetFenceivNV(Context *context, FenceNVID fence, GLenum pname, GLint *params)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006903{
6904 if (!context->getExtensions().fence)
6905 {
Jamie Madille0472f32018-11-27 16:32:45 -05006906 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006907 return false;
6908 }
6909
6910 FenceNV *fenceObject = context->getFenceNV(fence);
6911
6912 if (fenceObject == nullptr)
6913 {
Jamie Madille0472f32018-11-27 16:32:45 -05006914 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006915 return false;
6916 }
6917
6918 if (!fenceObject->isSet())
6919 {
Jamie Madille0472f32018-11-27 16:32:45 -05006920 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006921 return false;
6922 }
6923
6924 switch (pname)
6925 {
6926 case GL_FENCE_STATUS_NV:
6927 case GL_FENCE_CONDITION_NV:
6928 break;
6929
6930 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006931 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006932 return false;
6933 }
6934
6935 return true;
6936}
6937
6938bool ValidateGetGraphicsResetStatusEXT(Context *context)
6939{
6940 if (!context->getExtensions().robustness)
6941 {
Jamie Madille0472f32018-11-27 16:32:45 -05006942 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006943 return false;
6944 }
6945
6946 return true;
6947}
6948
6949bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006950 ShaderProgramID shader,
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006951 GLsizei bufsize,
6952 GLsizei *length,
6953 GLchar *source)
6954{
6955 if (!context->getExtensions().translatedShaderSource)
6956 {
Jamie Madille0472f32018-11-27 16:32:45 -05006957 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006958 return false;
6959 }
6960
6961 if (bufsize < 0)
6962 {
Jamie Madille0472f32018-11-27 16:32:45 -05006963 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006964 return false;
6965 }
6966
6967 Shader *shaderObject = context->getShader(shader);
6968
6969 if (!shaderObject)
6970 {
Jamie Madille0472f32018-11-27 16:32:45 -05006971 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006972 return false;
6973 }
6974
6975 return true;
6976}
6977
Jiacheng Lu962503e2019-08-21 13:18:30 -06006978bool ValidateIsFenceNV(Context *context, FenceNVID fence)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006979{
6980 if (!context->getExtensions().fence)
6981 {
Jamie Madille0472f32018-11-27 16:32:45 -05006982 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006983 return false;
6984 }
6985
6986 return true;
6987}
6988
Jiacheng Lu962503e2019-08-21 13:18:30 -06006989bool ValidateSetFenceNV(Context *context, FenceNVID fence, GLenum condition)
Jamie Madill007530e2017-12-28 14:27:04 -05006990{
6991 if (!context->getExtensions().fence)
6992 {
Jamie Madille0472f32018-11-27 16:32:45 -05006993 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05006994 return false;
6995 }
6996
6997 if (condition != GL_ALL_COMPLETED_NV)
6998 {
Jamie Madille0472f32018-11-27 16:32:45 -05006999 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05007000 return false;
7001 }
7002
7003 FenceNV *fenceObject = context->getFenceNV(fence);
7004
7005 if (fenceObject == nullptr)
7006 {
Jamie Madille0472f32018-11-27 16:32:45 -05007007 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05007008 return false;
7009 }
7010
7011 return true;
7012}
7013
Jiacheng Lu962503e2019-08-21 13:18:30 -06007014bool ValidateTestFenceNV(Context *context, FenceNVID fence)
Jamie Madill007530e2017-12-28 14:27:04 -05007015{
7016 if (!context->getExtensions().fence)
7017 {
Jamie Madille0472f32018-11-27 16:32:45 -05007018 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05007019 return false;
7020 }
7021
7022 FenceNV *fenceObject = context->getFenceNV(fence);
7023
7024 if (fenceObject == nullptr)
7025 {
Jamie Madille0472f32018-11-27 16:32:45 -05007026 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05007027 return false;
7028 }
7029
7030 if (fenceObject->isSet() != GL_TRUE)
7031 {
Jamie Madille0472f32018-11-27 16:32:45 -05007032 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05007033 return false;
7034 }
7035
7036 return true;
7037}
7038
7039bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007040 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05007041 GLsizei levels,
7042 GLenum internalformat,
7043 GLsizei width,
7044 GLsizei height)
7045{
7046 if (!context->getExtensions().textureStorage)
7047 {
Jamie Madille0472f32018-11-27 16:32:45 -05007048 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007049 return false;
7050 }
7051
7052 if (context->getClientMajorVersion() < 3)
7053 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007054 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05007055 height);
7056 }
7057
7058 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007059 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05007060 1);
7061}
7062
7063bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
7064{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05007065 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05007066 {
Jamie Madille0472f32018-11-27 16:32:45 -05007067 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007068 return false;
7069 }
7070
7071 if (index >= MAX_VERTEX_ATTRIBS)
7072 {
Jamie Madille0472f32018-11-27 16:32:45 -05007073 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05007074 return false;
7075 }
7076
7077 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
7078 {
7079 if (index == 0 && divisor != 0)
7080 {
Jamie Madillc3e37312018-11-30 15:25:39 -05007081 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05007082
7083 // We also output an error message to the debugger window if tracing is active, so
7084 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05007085 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05007086 return false;
7087 }
7088 }
7089
7090 return true;
7091}
7092
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05007093bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
7094{
7095 if (!context->getExtensions().instancedArraysEXT)
7096 {
7097 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7098 return false;
7099 }
7100
7101 if (index >= MAX_VERTEX_ATTRIBS)
7102 {
7103 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
7104 return false;
7105 }
7106
7107 return true;
7108}
7109
Jamie Madill007530e2017-12-28 14:27:04 -05007110bool ValidateTexImage3DOES(Context *context,
Cody Northrop5faff912019-06-28 14:04:50 -06007111 TextureTarget target,
Jamie Madill007530e2017-12-28 14:27:04 -05007112 GLint level,
7113 GLenum internalformat,
7114 GLsizei width,
7115 GLsizei height,
7116 GLsizei depth,
7117 GLint border,
7118 GLenum format,
7119 GLenum type,
7120 const void *pixels)
7121{
Cody Northrop5faff912019-06-28 14:04:50 -06007122 return ValidateTexImage3D(context, target, level, internalformat, width, height, depth, border,
7123 format, type, pixels);
Jamie Madill007530e2017-12-28 14:27:04 -05007124}
7125
7126bool ValidatePopGroupMarkerEXT(Context *context)
7127{
7128 if (!context->getExtensions().debugMarker)
7129 {
7130 // The debug marker calls should not set error state
7131 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05007132 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007133 return false;
7134 }
7135
7136 return true;
7137}
7138
Jamie Madillfa920eb2018-01-04 11:45:50 -05007139bool ValidateTexStorage1DEXT(Context *context,
7140 GLenum target,
7141 GLsizei levels,
7142 GLenum internalformat,
7143 GLsizei width)
7144{
7145 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05007146 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007147 return false;
7148}
7149
7150bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007151 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05007152 GLsizei levels,
7153 GLenum internalformat,
7154 GLsizei width,
7155 GLsizei height,
7156 GLsizei depth)
7157{
7158 if (!context->getExtensions().textureStorage)
7159 {
Jamie Madille0472f32018-11-27 16:32:45 -05007160 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007161 return false;
7162 }
7163
7164 if (context->getClientMajorVersion() < 3)
7165 {
Jamie Madille0472f32018-11-27 16:32:45 -05007166 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007167 return false;
7168 }
7169
7170 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
7171 depth);
7172}
7173
jchen1082af6202018-06-22 10:59:52 +08007174bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
7175{
7176 if (!context->getExtensions().parallelShaderCompile)
7177 {
Jamie Madille0472f32018-11-27 16:32:45 -05007178 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08007179 return false;
7180 }
7181 return true;
7182}
7183
Austin Eng1bf18ce2018-10-19 15:34:02 -07007184bool ValidateMultiDrawArraysANGLE(Context *context,
7185 PrimitiveMode mode,
7186 const GLint *firsts,
7187 const GLsizei *counts,
7188 GLsizei drawcount)
7189{
7190 if (!context->getExtensions().multiDraw)
7191 {
Jamie Madille0472f32018-11-27 16:32:45 -05007192 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007193 return false;
7194 }
7195 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7196 {
7197 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
7198 {
7199 return false;
7200 }
7201 }
7202 return true;
7203}
7204
7205bool ValidateMultiDrawElementsANGLE(Context *context,
7206 PrimitiveMode mode,
7207 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05007208 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08007209 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07007210 GLsizei drawcount)
7211{
7212 if (!context->getExtensions().multiDraw)
7213 {
Jamie Madille0472f32018-11-27 16:32:45 -05007214 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007215 return false;
7216 }
7217 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7218 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08007219 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07007220 {
7221 return false;
7222 }
7223 }
7224 return true;
7225}
7226
Clemen Dengce330592019-07-16 10:02:21 -04007227bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertexConvention modePacked)
Jeff Gilbert465d6092019-01-02 16:21:18 -08007228{
7229 if (!context->getExtensions().provokingVertex)
7230 {
7231 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7232 return false;
7233 }
7234
7235 switch (modePacked)
7236 {
Clemen Dengce330592019-07-16 10:02:21 -04007237 case ProvokingVertexConvention::FirstVertexConvention:
7238 case ProvokingVertexConvention::LastVertexConvention:
Jeff Gilbert465d6092019-01-02 16:21:18 -08007239 break;
7240 default:
7241 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
7242 return false;
7243 }
7244
7245 return true;
7246}
7247
Mingyu Hu7e44ec22019-08-26 15:59:48 -07007248bool ValidateFramebufferTexture2DMultisampleEXT(Context *context,
7249 GLenum target,
7250 GLenum attachment,
7251 GLenum textarget,
7252 GLuint texture,
7253 GLint level,
7254 GLsizei samples)
7255{
7256 return true;
7257}
7258
7259bool ValidateRenderbufferStorageMultisampleEXT(Context *context,
7260 GLenum target,
7261 GLsizei samples,
7262 GLenum internalformat,
7263 GLsizei width,
7264 GLsizei height)
7265{
7266 return true;
7267}
7268
Jamie Madilla5410482019-01-31 19:55:55 -05007269void RecordBindTextureTypeError(Context *context, TextureType target)
7270{
7271 ASSERT(!context->getStateCache().isValidBindTextureType(target));
7272
7273 switch (target)
7274 {
7275 case TextureType::Rectangle:
7276 ASSERT(!context->getExtensions().textureRectangle);
7277 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
7278 break;
7279
7280 case TextureType::_3D:
7281 case TextureType::_2DArray:
7282 ASSERT(context->getClientMajorVersion() < 3);
7283 context->validationError(GL_INVALID_ENUM, kES3Required);
7284 break;
7285
7286 case TextureType::_2DMultisample:
7287 ASSERT(context->getClientVersion() < Version(3, 1) &&
7288 !context->getExtensions().textureMultisample);
7289 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
7290 break;
7291
7292 case TextureType::_2DMultisampleArray:
7293 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
7294 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
7295 break;
7296
7297 case TextureType::External:
7298 ASSERT(!context->getExtensions().eglImageExternal &&
7299 !context->getExtensions().eglStreamConsumerExternal);
7300 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
7301 break;
7302
7303 default:
7304 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
7305 }
7306}
7307
Jamie Madillc29968b2016-01-20 11:17:23 -05007308} // namespace gl