blob: 8951a5995ecbeb81057a70626eb65969de7cf6d8 [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;
Le Quyen6e653982019-10-09 15:19:02 +0800730 case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
731 case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
732 case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
733 case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
734 if (context->getExtensions().compressedTexturePVRTC)
735 {
736 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
737 return false;
738 }
739 else
740 {
741 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
742 return false;
743 }
744 break;
745 case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:
746 case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:
747 case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:
748 case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:
749 if (context->getExtensions().compressedTexturePVRTCsRGB)
750 {
751 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
752 return false;
753 }
754 else
755 {
756 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
757 return false;
758 }
759 break;
Jamie Madillbe849e42017-05-02 15:49:00 -0400760 case GL_DEPTH_COMPONENT:
761 case GL_DEPTH_COMPONENT16:
762 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600763 if (context->getExtensions().depthTextureAny())
Jamie Madillbe849e42017-05-02 15:49:00 -0400764 {
Jamie Madille0472f32018-11-27 16:32:45 -0500765 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Jamie Madillbe849e42017-05-02 15:49:00 -0400766 return false;
767 }
768 else
769 {
Jamie Madille0472f32018-11-27 16:32:45 -0500770 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400771 return false;
772 }
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600773 break;
774 case GL_DEPTH_STENCIL_OES:
775 case GL_DEPTH24_STENCIL8_OES:
776 if (context->getExtensions().depthTextureAny() ||
777 context->getExtensions().packedDepthStencil)
778 {
779 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
780 return false;
781 }
782 else
783 {
784 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
785 return false;
786 }
787 break;
Jamie Madillbe849e42017-05-02 15:49:00 -0400788 default:
Jamie Madille0472f32018-11-27 16:32:45 -0500789 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -0400790 return false;
791 }
792 }
793
794 // If width or height is zero, it is a no-op. Return false without setting an error.
795 return (width > 0 && height > 0);
796}
797
798bool ValidCap(const Context *context, GLenum cap, bool queryOnly)
799{
800 switch (cap)
801 {
802 // EXT_multisample_compatibility
803 case GL_MULTISAMPLE_EXT:
804 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
805 return context->getExtensions().multisampleCompatibility;
806
807 case GL_CULL_FACE:
808 case GL_POLYGON_OFFSET_FILL:
809 case GL_SAMPLE_ALPHA_TO_COVERAGE:
810 case GL_SAMPLE_COVERAGE:
811 case GL_SCISSOR_TEST:
812 case GL_STENCIL_TEST:
813 case GL_DEPTH_TEST:
814 case GL_BLEND:
815 case GL_DITHER:
816 return true;
817
818 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
819 case GL_RASTERIZER_DISCARD:
820 return (context->getClientMajorVersion() >= 3);
821
822 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
823 case GL_DEBUG_OUTPUT:
824 return context->getExtensions().debug;
825
826 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
827 return queryOnly && context->getExtensions().bindGeneratesResource;
828
829 case GL_CLIENT_ARRAYS_ANGLE:
830 return queryOnly && context->getExtensions().clientArrays;
831
832 case GL_FRAMEBUFFER_SRGB_EXT:
833 return context->getExtensions().sRGBWriteControl;
834
835 case GL_SAMPLE_MASK:
836 return context->getClientVersion() >= Version(3, 1);
837
Geoff Langb433e872017-10-05 14:01:47 -0400838 case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
Jamie Madillbe849e42017-05-02 15:49:00 -0400839 return queryOnly && context->getExtensions().robustResourceInitialization;
840
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700841 // GLES1 emulation: GLES1-specific caps
842 case GL_ALPHA_TEST:
Lingfeng Yang01074432018-04-16 10:19:51 -0700843 case GL_VERTEX_ARRAY:
844 case GL_NORMAL_ARRAY:
845 case GL_COLOR_ARRAY:
846 case GL_TEXTURE_COORD_ARRAY:
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700847 case GL_TEXTURE_2D:
Lingfeng Yangd0febe72018-05-17 22:36:52 -0700848 case GL_LIGHTING:
849 case GL_LIGHT0:
850 case GL_LIGHT1:
851 case GL_LIGHT2:
852 case GL_LIGHT3:
853 case GL_LIGHT4:
854 case GL_LIGHT5:
855 case GL_LIGHT6:
856 case GL_LIGHT7:
857 case GL_NORMALIZE:
858 case GL_RESCALE_NORMAL:
859 case GL_COLOR_MATERIAL:
Lingfeng Yang060088a2018-05-30 20:40:57 -0700860 case GL_CLIP_PLANE0:
861 case GL_CLIP_PLANE1:
862 case GL_CLIP_PLANE2:
863 case GL_CLIP_PLANE3:
864 case GL_CLIP_PLANE4:
865 case GL_CLIP_PLANE5:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -0700866 case GL_FOG:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700867 case GL_POINT_SMOOTH:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -0700868 case GL_LINE_SMOOTH:
869 case GL_COLOR_LOGIC_OP:
Lingfeng Yang13b708f2018-03-21 12:14:10 -0700870 return context->getClientVersion() < Version(2, 0);
Lingfeng Yang01074432018-04-16 10:19:51 -0700871 case GL_POINT_SIZE_ARRAY_OES:
872 return context->getClientVersion() < Version(2, 0) &&
873 context->getExtensions().pointSizeArray;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -0700874 case GL_TEXTURE_CUBE_MAP:
875 return context->getClientVersion() < Version(2, 0) &&
876 context->getExtensions().textureCubeMap;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -0700877 case GL_POINT_SPRITE_OES:
878 return context->getClientVersion() < Version(2, 0) &&
879 context->getExtensions().pointSprite;
Jamie Madillbe849e42017-05-02 15:49:00 -0400880 default:
881 return false;
882 }
883}
884
Geoff Langfc32e8b2017-05-31 14:16:59 -0400885// Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section
886// 3.1.
Geoff Langcab92ee2017-07-19 17:32:07 -0400887bool IsValidESSLCharacter(unsigned char c)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400888{
889 // Printing characters are valid except " $ ` @ \ ' DEL.
Geoff Langcab92ee2017-07-19 17:32:07 -0400890 if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' &&
891 c != '\'')
Geoff Langfc32e8b2017-05-31 14:16:59 -0400892 {
893 return true;
894 }
895
896 // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid.
897 if (c >= 9 && c <= 13)
898 {
899 return true;
900 }
901
902 return false;
903}
904
Geoff Langcab92ee2017-07-19 17:32:07 -0400905bool IsValidESSLString(const char *str, size_t len)
Geoff Langfc32e8b2017-05-31 14:16:59 -0400906{
Geoff Langa71a98e2017-06-19 15:15:00 -0400907 for (size_t i = 0; i < len; i++)
908 {
Geoff Langcab92ee2017-07-19 17:32:07 -0400909 if (!IsValidESSLCharacter(str[i]))
Geoff Langa71a98e2017-06-19 15:15:00 -0400910 {
911 return false;
912 }
913 }
914
915 return true;
Geoff Langfc32e8b2017-05-31 14:16:59 -0400916}
917
Geoff Langcab92ee2017-07-19 17:32:07 -0400918bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed)
919{
920 enum class ParseState
921 {
922 // Have not seen an ASCII non-whitespace character yet on
923 // this line. Possible that we might see a preprocessor
924 // directive.
925 BEGINING_OF_LINE,
926
927 // Have seen at least one ASCII non-whitespace character
928 // on this line.
929 MIDDLE_OF_LINE,
930
931 // Handling a preprocessor directive. Passes through all
932 // characters up to the end of the line. Disables comment
933 // processing.
934 IN_PREPROCESSOR_DIRECTIVE,
935
936 // Handling a single-line comment. The comment text is
937 // replaced with a single space.
938 IN_SINGLE_LINE_COMMENT,
939
940 // Handling a multi-line comment. Newlines are passed
941 // through to preserve line numbers.
942 IN_MULTI_LINE_COMMENT
943 };
944
945 ParseState state = ParseState::BEGINING_OF_LINE;
946 size_t pos = 0;
947
948 while (pos < len)
949 {
950 char c = str[pos];
951 char next = pos + 1 < len ? str[pos + 1] : 0;
952
953 // Check for newlines
954 if (c == '\n' || c == '\r')
955 {
956 if (state != ParseState::IN_MULTI_LINE_COMMENT)
957 {
958 state = ParseState::BEGINING_OF_LINE;
959 }
960
961 pos++;
962 continue;
963 }
964
965 switch (state)
966 {
967 case ParseState::BEGINING_OF_LINE:
968 if (c == ' ')
969 {
970 // Maintain the BEGINING_OF_LINE state until a non-space is seen
971 pos++;
972 }
973 else if (c == '#')
974 {
975 state = ParseState::IN_PREPROCESSOR_DIRECTIVE;
976 pos++;
977 }
978 else
979 {
980 // Don't advance, re-process this character with the MIDDLE_OF_LINE state
981 state = ParseState::MIDDLE_OF_LINE;
982 }
983 break;
984
985 case ParseState::MIDDLE_OF_LINE:
986 if (c == '/' && next == '/')
987 {
988 state = ParseState::IN_SINGLE_LINE_COMMENT;
989 pos++;
990 }
991 else if (c == '/' && next == '*')
992 {
993 state = ParseState::IN_MULTI_LINE_COMMENT;
994 pos++;
995 }
996 else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r'))
997 {
998 // Skip line continuation characters
999 }
1000 else if (!IsValidESSLCharacter(c))
1001 {
1002 return false;
1003 }
1004 pos++;
1005 break;
1006
1007 case ParseState::IN_PREPROCESSOR_DIRECTIVE:
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -07001008 // Line-continuation characters may not be permitted.
1009 // Otherwise, just pass it through. Do not parse comments in this state.
1010 if (!lineContinuationAllowed && c == '\\')
1011 {
1012 return false;
1013 }
Geoff Langcab92ee2017-07-19 17:32:07 -04001014 pos++;
1015 break;
1016
1017 case ParseState::IN_SINGLE_LINE_COMMENT:
1018 // Line-continuation characters are processed before comment processing.
1019 // Advance string if a new line character is immediately behind
1020 // line-continuation character.
1021 if (c == '\\' && (next == '\n' || next == '\r'))
1022 {
1023 pos++;
1024 }
1025 pos++;
1026 break;
1027
1028 case ParseState::IN_MULTI_LINE_COMMENT:
1029 if (c == '*' && next == '/')
1030 {
1031 state = ParseState::MIDDLE_OF_LINE;
1032 pos++;
1033 }
1034 pos++;
1035 break;
1036 }
1037 }
1038
1039 return true;
1040}
1041
Jamie Madill5b772312018-03-08 20:28:32 -05001042bool ValidateWebGLNamePrefix(Context *context, const GLchar *name)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001043{
1044 ASSERT(context->isWebGL());
1045
1046 // WebGL 1.0 [Section 6.16] GLSL Constructs
1047 // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL.
1048 if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0)
1049 {
Jamie Madille0472f32018-11-27 16:32:45 -05001050 context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001051 return false;
1052 }
1053
1054 return true;
1055}
1056
Jamie Madill5b772312018-03-08 20:28:32 -05001057bool ValidateWebGLNameLength(Context *context, size_t length)
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001058{
1059 ASSERT(context->isWebGL());
1060
1061 if (context->isWebGL1() && length > 256)
1062 {
1063 // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths
1064 // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute
1065 // locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001066 context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001067
1068 return false;
1069 }
1070 else if (length > 1024)
1071 {
1072 // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of
1073 // uniform and attribute locations.
Jamie Madille0472f32018-11-27 16:32:45 -05001074 context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001075 return false;
1076 }
1077
1078 return true;
1079}
1080
Jamie Madill007530e2017-12-28 14:27:04 -05001081bool ValidateMatrixMode(Context *context, GLenum matrixMode)
1082{
1083 if (!context->getExtensions().pathRendering)
1084 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001085 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05001086 return false;
1087 }
1088
1089 if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM)
1090 {
Jamie Madille0472f32018-11-27 16:32:45 -05001091 context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode);
Jamie Madill007530e2017-12-28 14:27:04 -05001092 return false;
1093 }
1094 return true;
1095}
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001096
1097bool ValidBlendFunc(const Context *context, GLenum val)
1098{
1099 const gl::Extensions &ext = context->getExtensions();
1100
1101 // these are always valid for src and dst.
1102 switch (val)
1103 {
1104 case GL_ZERO:
1105 case GL_ONE:
1106 case GL_SRC_COLOR:
1107 case GL_ONE_MINUS_SRC_COLOR:
1108 case GL_DST_COLOR:
1109 case GL_ONE_MINUS_DST_COLOR:
1110 case GL_SRC_ALPHA:
1111 case GL_ONE_MINUS_SRC_ALPHA:
1112 case GL_DST_ALPHA:
1113 case GL_ONE_MINUS_DST_ALPHA:
1114 case GL_CONSTANT_COLOR:
1115 case GL_ONE_MINUS_CONSTANT_COLOR:
1116 case GL_CONSTANT_ALPHA:
1117 case GL_ONE_MINUS_CONSTANT_ALPHA:
1118 return true;
1119
1120 // EXT_blend_func_extended.
1121 case GL_SRC1_COLOR_EXT:
1122 case GL_SRC1_ALPHA_EXT:
1123 case GL_ONE_MINUS_SRC1_COLOR_EXT:
1124 case GL_ONE_MINUS_SRC1_ALPHA_EXT:
1125 case GL_SRC_ALPHA_SATURATE_EXT:
1126 return ext.blendFuncExtended;
1127
1128 default:
1129 return false;
1130 }
1131}
1132
1133bool ValidSrcBlendFunc(const Context *context, GLenum val)
1134{
1135 if (ValidBlendFunc(context, val))
1136 return true;
1137
1138 if (val == GL_SRC_ALPHA_SATURATE)
1139 return true;
1140
1141 return false;
1142}
1143
1144bool ValidDstBlendFunc(const Context *context, GLenum val)
1145{
1146 if (ValidBlendFunc(context, val))
1147 return true;
1148
1149 if (val == GL_SRC_ALPHA_SATURATE)
1150 {
1151 if (context->getClientMajorVersion() >= 3)
1152 return true;
1153 }
1154
1155 return false;
1156}
Michael Spangab6a59b2019-05-21 21:26:26 -04001157
1158bool IsValidImageLayout(ImageLayout layout)
1159{
1160 switch (layout)
1161 {
Michael Spang6c824a12019-06-18 15:43:33 -04001162 case ImageLayout::Undefined:
Michael Spangab6a59b2019-05-21 21:26:26 -04001163 case ImageLayout::General:
1164 case ImageLayout::ColorAttachment:
1165 case ImageLayout::DepthStencilAttachment:
1166 case ImageLayout::DepthStencilReadOnlyAttachment:
1167 case ImageLayout::ShaderReadOnly:
1168 case ImageLayout::TransferSrc:
1169 case ImageLayout::TransferDst:
1170 case ImageLayout::DepthReadOnlyStencilAttachment:
1171 case ImageLayout::DepthAttachmentStencilReadOnly:
1172 return true;
1173
1174 default:
1175 return false;
1176 }
1177}
1178
Geoff Langff5b2d52016-09-07 11:32:23 -04001179bool ValidateES2TexImageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001180 TextureTarget target,
Geoff Langff5b2d52016-09-07 11:32:23 -04001181 GLint level,
1182 GLenum internalformat,
1183 bool isCompressed,
1184 bool isSubImage,
1185 GLint xoffset,
1186 GLint yoffset,
1187 GLsizei width,
1188 GLsizei height,
1189 GLint border,
1190 GLenum format,
1191 GLenum type,
1192 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04001193 const void *pixels)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001194{
Jamie Madill6f38f822014-06-06 17:12:20 -04001195 if (!ValidTexture2DDestinationTarget(context, target))
1196 {
Jamie Madille0472f32018-11-27 16:32:45 -05001197 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001198 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001199 }
1200
Geoff Lang857880e2019-05-27 13:39:15 -04001201 return ValidateES2TexImageParametersBase(context, target, level, internalformat, isCompressed,
1202 isSubImage, xoffset, yoffset, width, height, border,
1203 format, type, imageSize, pixels);
1204}
1205
1206} // anonymous namespace
1207
1208bool ValidateES2TexImageParametersBase(Context *context,
1209 TextureTarget target,
1210 GLint level,
1211 GLenum internalformat,
1212 bool isCompressed,
1213 bool isSubImage,
1214 GLint xoffset,
1215 GLint yoffset,
1216 GLsizei width,
1217 GLsizei height,
1218 GLint border,
1219 GLenum format,
1220 GLenum type,
1221 GLsizei imageSize,
1222 const void *pixels)
1223{
1224
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001225 TextureType texType = TextureTargetToType(target);
1226 if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage))
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001227 {
Jamie Madill610640f2018-11-21 17:28:41 -05001228 // Error already handled.
Geoff Langb1196682014-07-23 13:47:29 -04001229 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001230 }
1231
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001232 if (!ValidMipLevel(context, texType, level))
Brandon Jones6cad5662017-06-14 13:25:13 -07001233 {
Jamie Madille0472f32018-11-27 16:32:45 -05001234 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Brandon Jones6cad5662017-06-14 13:25:13 -07001235 return false;
1236 }
1237
1238 if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width ||
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001239 std::numeric_limits<GLsizei>::max() - yoffset < height)
1240 {
Jamie Madille0472f32018-11-27 16:32:45 -05001241 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Geoff Langb1196682014-07-23 13:47:29 -04001242 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001243 }
1244
Geoff Langaae65a42014-05-26 12:43:44 -04001245 const gl::Caps &caps = context->getCaps();
1246
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001247 switch (texType)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001248 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001249 case TextureType::_2D:
Geoff Lang857880e2019-05-27 13:39:15 -04001250 case TextureType::External:
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001251 if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
1252 static_cast<GLuint>(height) > (caps.max2DTextureSize >> 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;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001258
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001259 case TextureType::Rectangle:
1260 ASSERT(level == 0);
1261 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1262 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1263 {
Jamie Madille0472f32018-11-27 16:32:45 -05001264 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001265 return false;
1266 }
1267 if (isCompressed)
1268 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001269 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001270 return false;
1271 }
1272 break;
1273
1274 case TextureType::CubeMap:
1275 if (!isSubImage && width != height)
1276 {
Jamie Madille0472f32018-11-27 16:32:45 -05001277 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001278 return false;
1279 }
1280
1281 if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) ||
1282 static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level))
1283 {
Jamie Madille0472f32018-11-27 16:32:45 -05001284 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001285 return false;
1286 }
1287 break;
1288
1289 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001290 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langa9be0dc2014-12-17 12:34:40 -05001291 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001292 }
1293
Jamie Madillcfc73cc2019-04-08 16:26:51 -04001294 gl::Texture *texture = context->getTextureByType(texType);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001295 if (!texture)
1296 {
Jamie Madille0472f32018-11-27 16:32:45 -05001297 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Geoff Langb1196682014-07-23 13:47:29 -04001298 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001299 }
1300
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001301 // Verify zero border
1302 if (border != 0)
1303 {
Jamie Madille0472f32018-11-27 16:32:45 -05001304 context->validationError(GL_INVALID_VALUE, kInvalidBorder);
Geoff Langb1196682014-07-23 13:47:29 -04001305 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001306 }
1307
Tim Van Patten208af3e2019-03-19 09:15:55 -06001308 bool nonEqualFormatsAllowed = false;
1309
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001310 if (isCompressed)
1311 {
tmartino0ccd5ae2015-10-01 14:33:14 -04001312 GLenum actualInternalFormat =
Geoff Langca271392017-04-05 12:30:00 -04001313 isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat
1314 : internalformat;
Geoff Lange88e4542018-05-03 15:05:57 -04001315
1316 const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat);
1317
1318 if (!internalFormatInfo.compressed)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001319 {
Jamie Madille0472f32018-11-27 16:32:45 -05001320 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001321 return false;
1322 }
1323
1324 if (!internalFormatInfo.textureSupport(context->getClientVersion(),
1325 context->getExtensions()))
1326 {
Jamie Madille0472f32018-11-27 16:32:45 -05001327 context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001328 return false;
tmartino0ccd5ae2015-10-01 14:33:14 -04001329 }
Geoff Lang966c9402017-04-18 12:38:27 -04001330
1331 if (isSubImage)
tmartino0ccd5ae2015-10-01 14:33:14 -04001332 {
Geoff Lange88e4542018-05-03 15:05:57 -04001333 // From the OES_compressed_ETC1_RGB8_texture spec:
1334 // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or
1335 // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format
1336 // ETC1_RGB8_OES.
1337 if (actualInternalFormat == GL_ETC1_RGB8_OES)
1338 {
Jamie Madille0472f32018-11-27 16:32:45 -05001339 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lange88e4542018-05-03 15:05:57 -04001340 return false;
1341 }
1342
Geoff Langd9c17102019-07-10 14:56:26 -04001343 if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, 0,
1344 width, height, 1, texture->getWidth(target, level),
1345 texture->getHeight(target, level),
1346 texture->getDepth(target, level)))
Geoff Lang966c9402017-04-18 12:38:27 -04001347 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001348 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001349 return false;
1350 }
1351
1352 if (format != actualInternalFormat)
1353 {
Jamie Madille0472f32018-11-27 16:32:45 -05001354 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
Geoff Lang966c9402017-04-18 12:38:27 -04001355 return false;
1356 }
1357 }
1358 else
1359 {
Geoff Langd9c17102019-07-10 14:56:26 -04001360 if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height, 1))
Geoff Lang966c9402017-04-18 12:38:27 -04001361 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001362 context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize);
Geoff Lang966c9402017-04-18 12:38:27 -04001363 return false;
1364 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001365 }
1366 }
1367 else
1368 {
1369 // validate <type> by itself (used as secondary key below)
1370 switch (type)
1371 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001372 case GL_UNSIGNED_BYTE:
1373 case GL_UNSIGNED_SHORT_5_6_5:
1374 case GL_UNSIGNED_SHORT_4_4_4_4:
1375 case GL_UNSIGNED_SHORT_5_5_5_1:
1376 case GL_UNSIGNED_SHORT:
1377 case GL_UNSIGNED_INT:
1378 case GL_UNSIGNED_INT_24_8_OES:
1379 case GL_HALF_FLOAT_OES:
1380 case GL_FLOAT:
1381 break;
Jaedon Lee3b468852019-07-30 16:50:36 +09001382 case GL_UNSIGNED_INT_2_10_10_10_REV_EXT:
1383 if (!context->getExtensions().textureFormat2101010REV)
1384 {
1385 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1386 return false;
1387 }
1388 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001389 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001390 context->validationError(GL_INVALID_ENUM, kInvalidType);
He Yunchaoced53ae2016-11-29 15:00:51 +08001391 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001392 }
1393
1394 // validate <format> + <type> combinations
1395 // - invalid <format> -> sets INVALID_ENUM
1396 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
1397 switch (format)
1398 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001399 case GL_ALPHA:
1400 case GL_LUMINANCE:
1401 case GL_LUMINANCE_ALPHA:
1402 switch (type)
1403 {
1404 case GL_UNSIGNED_BYTE:
1405 case GL_FLOAT:
1406 case GL_HALF_FLOAT_OES:
1407 break;
1408 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001409 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001410 return false;
1411 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001412 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001413 case GL_RED:
1414 case GL_RG:
1415 if (!context->getExtensions().textureRG)
1416 {
Jamie Madille0472f32018-11-27 16:32:45 -05001417 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001418 return false;
1419 }
1420 switch (type)
1421 {
1422 case GL_UNSIGNED_BYTE:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001423 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001424 case GL_FLOAT:
1425 case GL_HALF_FLOAT_OES:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001426 if (!context->getExtensions().textureFloat)
1427 {
Jamie Madille0472f32018-11-27 16:32:45 -05001428 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001429 return false;
1430 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001431 break;
shrekshaoe33c1582019-11-06 16:55:29 -08001432 case GL_SHORT:
1433 case GL_UNSIGNED_SHORT:
1434 if (!context->getExtensions().textureNorm16)
1435 {
1436 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1437 return false;
1438 }
1439 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001440 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001441 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001442 return false;
1443 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001444 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001445 case GL_RGB:
1446 switch (type)
1447 {
1448 case GL_UNSIGNED_BYTE:
1449 case GL_UNSIGNED_SHORT_5_6_5:
Jaedon Lee3b468852019-07-30 16:50:36 +09001450 case GL_UNSIGNED_INT_2_10_10_10_REV_EXT:
He Yunchaoced53ae2016-11-29 15:00:51 +08001451 case GL_FLOAT:
1452 case GL_HALF_FLOAT_OES:
1453 break;
shrekshaoe33c1582019-11-06 16:55:29 -08001454 case GL_SHORT:
1455 case GL_UNSIGNED_SHORT:
1456 if (!context->getExtensions().textureNorm16)
1457 {
1458 context->validationError(GL_INVALID_OPERATION,
1459 kMismatchedTypeAndFormat);
1460 return false;
1461 }
1462 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001463 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001464 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001465 return false;
1466 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001467 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001468 case GL_RGBA:
1469 switch (type)
1470 {
1471 case GL_UNSIGNED_BYTE:
1472 case GL_UNSIGNED_SHORT_4_4_4_4:
1473 case GL_UNSIGNED_SHORT_5_5_5_1:
1474 case GL_FLOAT:
1475 case GL_HALF_FLOAT_OES:
Jaedon Lee3b468852019-07-30 16:50:36 +09001476 case GL_UNSIGNED_INT_2_10_10_10_REV_EXT:
He Yunchaoced53ae2016-11-29 15:00:51 +08001477 break;
shrekshaoe33c1582019-11-06 16:55:29 -08001478 case GL_SHORT:
1479 case GL_UNSIGNED_SHORT:
1480 if (!context->getExtensions().textureNorm16)
1481 {
1482 context->validationError(GL_INVALID_OPERATION,
1483 kMismatchedTypeAndFormat);
1484 return false;
1485 }
1486 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001487 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001488 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001489 return false;
1490 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001491 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001492 case GL_BGRA_EXT:
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001493 if (!context->getExtensions().textureFormatBGRA8888)
1494 {
Jamie Madille0472f32018-11-27 16:32:45 -05001495 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07001496 return false;
1497 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001498 switch (type)
1499 {
1500 case GL_UNSIGNED_BYTE:
1501 break;
1502 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001503 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001504 return false;
1505 }
1506 break;
1507 case GL_SRGB_EXT:
1508 case GL_SRGB_ALPHA_EXT:
1509 if (!context->getExtensions().sRGB)
1510 {
Jamie Madille0472f32018-11-27 16:32:45 -05001511 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001512 return false;
1513 }
1514 switch (type)
1515 {
1516 case GL_UNSIGNED_BYTE:
1517 break;
1518 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001519 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001520 return false;
1521 }
1522 break;
1523 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are
1524 // handled below
1525 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1526 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1527 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1528 break;
1529 case GL_DEPTH_COMPONENT:
1530 switch (type)
1531 {
1532 case GL_UNSIGNED_SHORT:
1533 case GL_UNSIGNED_INT:
1534 break;
1535 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001536 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001537 return false;
1538 }
1539 break;
1540 case GL_DEPTH_STENCIL_OES:
1541 switch (type)
1542 {
1543 case GL_UNSIGNED_INT_24_8_OES:
1544 break;
1545 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001546 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001547 return false;
1548 }
1549 break;
1550 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001551 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001552 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001553 }
1554
1555 switch (format)
1556 {
He Yunchaoced53ae2016-11-29 15:00:51 +08001557 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1558 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1559 if (context->getExtensions().textureCompressionDXT1)
1560 {
Jamie Madille0472f32018-11-27 16:32:45 -05001561 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001562 return false;
1563 }
1564 else
1565 {
Jamie Madille0472f32018-11-27 16:32:45 -05001566 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001567 return false;
1568 }
1569 break;
1570 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1571 if (context->getExtensions().textureCompressionDXT3)
1572 {
Jamie Madille0472f32018-11-27 16:32:45 -05001573 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001574 return false;
1575 }
1576 else
1577 {
Jamie Madille0472f32018-11-27 16:32:45 -05001578 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001579 return false;
1580 }
1581 break;
1582 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1583 if (context->getExtensions().textureCompressionDXT5)
1584 {
Jamie Madille0472f32018-11-27 16:32:45 -05001585 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001586 return false;
1587 }
1588 else
1589 {
Jamie Madille0472f32018-11-27 16:32:45 -05001590 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001591 return false;
1592 }
1593 break;
1594 case GL_ETC1_RGB8_OES:
1595 if (context->getExtensions().compressedETC1RGB8Texture)
1596 {
Jamie Madille0472f32018-11-27 16:32:45 -05001597 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001598 return false;
1599 }
1600 else
1601 {
Jamie Madille0472f32018-11-27 16:32:45 -05001602 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001603 return false;
1604 }
1605 break;
1606 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08001607 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
1608 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
1609 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
1610 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08001611 if (context->getExtensions().lossyETCDecode)
1612 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001613 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001614 return false;
1615 }
1616 else
1617 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001618 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001619 return false;
1620 }
1621 break;
Le Quyen6e653982019-10-09 15:19:02 +08001622 case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
1623 case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
1624 case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
1625 case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
1626 if (context->getExtensions().compressedTexturePVRTC)
1627 {
1628 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
1629 return false;
1630 }
1631 else
1632 {
1633 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1634 return false;
1635 }
1636 break;
1637 case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:
1638 case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:
1639 case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:
1640 case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:
1641 if (context->getExtensions().compressedTexturePVRTCsRGB)
1642 {
1643 context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
1644 return false;
1645 }
1646 else
1647 {
1648 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1649 return false;
1650 }
1651 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08001652 case GL_DEPTH_COMPONENT:
1653 case GL_DEPTH_STENCIL_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001654 if (!context->getExtensions().depthTextureANGLE &&
1655 !(context->getExtensions().packedDepthStencil &&
1656 context->getExtensions().depthTextureOES))
He Yunchaoced53ae2016-11-29 15:00:51 +08001657 {
Jamie Madille0472f32018-11-27 16:32:45 -05001658 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08001659 return false;
1660 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001661 if (target != TextureTarget::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08001662 {
Jamie Madille0472f32018-11-27 16:32:45 -05001663 context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat);
He Yunchaoced53ae2016-11-29 15:00:51 +08001664 return false;
1665 }
1666 // OES_depth_texture supports loading depth data and multiple levels,
1667 // but ANGLE_depth_texture does not
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001668 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08001669 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001670 if (pixels != nullptr)
1671 {
1672 context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
1673 return false;
1674 }
1675 if (level != 0)
1676 {
1677 context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
1678 return false;
1679 }
He Yunchaoced53ae2016-11-29 15:00:51 +08001680 }
1681 break;
1682 default:
1683 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001684 }
1685
Geoff Lang6e898aa2017-06-02 11:17:26 -04001686 if (!isSubImage)
1687 {
1688 switch (internalformat)
1689 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001690 // Core ES 2.0 formats
1691 case GL_ALPHA:
1692 case GL_LUMINANCE:
1693 case GL_LUMINANCE_ALPHA:
1694 case GL_RGB:
1695 case GL_RGBA:
1696 break;
1697
Geoff Lang6e898aa2017-06-02 11:17:26 -04001698 case GL_RGBA32F:
1699 if (!context->getExtensions().colorBufferFloatRGBA)
1700 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001701 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001702 return false;
1703 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001704
1705 nonEqualFormatsAllowed = true;
1706
Geoff Lang6e898aa2017-06-02 11:17:26 -04001707 if (type != GL_FLOAT)
1708 {
Jamie Madille0472f32018-11-27 16:32:45 -05001709 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001710 return false;
1711 }
1712 if (format != GL_RGBA)
1713 {
Jamie Madille0472f32018-11-27 16:32:45 -05001714 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001715 return false;
1716 }
1717 break;
1718
1719 case GL_RGB32F:
1720 if (!context->getExtensions().colorBufferFloatRGB)
1721 {
Jamie Madillc3e37312018-11-30 15:25:39 -05001722 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001723 return false;
1724 }
Tim Van Patten208af3e2019-03-19 09:15:55 -06001725
1726 nonEqualFormatsAllowed = true;
1727
Geoff Lang6e898aa2017-06-02 11:17:26 -04001728 if (type != GL_FLOAT)
1729 {
Jamie Madille0472f32018-11-27 16:32:45 -05001730 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001731 return false;
1732 }
1733 if (format != GL_RGB)
1734 {
Jamie Madille0472f32018-11-27 16:32:45 -05001735 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
Geoff Lang6e898aa2017-06-02 11:17:26 -04001736 return false;
1737 }
1738 break;
1739
Tim Van Patten208af3e2019-03-19 09:15:55 -06001740 case GL_BGRA_EXT:
1741 if (!context->getExtensions().textureFormatBGRA8888)
1742 {
1743 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1744 return false;
1745 }
Geoff Lang6e898aa2017-06-02 11:17:26 -04001746 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001747
1748 case GL_DEPTH_COMPONENT:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001749 if (!(context->getExtensions().depthTextureAny()))
1750 {
1751 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1752 return false;
1753 }
1754 break;
1755
Tim Van Patten208af3e2019-03-19 09:15:55 -06001756 case GL_DEPTH_STENCIL:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06001757 if (!(context->getExtensions().depthTextureANGLE ||
1758 context->getExtensions().packedDepthStencil))
Tim Van Patten208af3e2019-03-19 09:15:55 -06001759 {
1760 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1761 return false;
1762 }
1763 break;
1764
1765 case GL_RED:
1766 case GL_RG:
1767 if (!context->getExtensions().textureRG)
1768 {
1769 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
1770 return false;
1771 }
1772 break;
1773
1774 case GL_SRGB_EXT:
1775 case GL_SRGB_ALPHA_EXT:
1776 if (!context->getExtensions().sRGB)
1777 {
1778 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1779 return false;
1780 }
1781 break;
1782
Jaedon Lee3b468852019-07-30 16:50:36 +09001783 case GL_RGB10_A2_EXT:
1784 if (!context->getExtensions().textureFormat2101010REV)
1785 {
1786 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1787 return false;
1788 }
1789
1790 if (type != GL_UNSIGNED_INT_2_10_10_10_REV_EXT || format != GL_RGBA)
1791 {
1792 context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat);
1793 return false;
1794 }
1795
1796 nonEqualFormatsAllowed = true;
1797
1798 break;
1799
1800 case GL_RGB5_A1:
1801 if (context->getExtensions().textureFormat2101010REV &&
1802 type == GL_UNSIGNED_INT_2_10_10_10_REV_EXT && format == GL_RGBA)
1803 {
1804 nonEqualFormatsAllowed = true;
1805 }
1806
1807 break;
1808
shrekshaoe33c1582019-11-06 16:55:29 -08001809 case GL_R16_EXT:
1810 case GL_RG16_EXT:
1811 case GL_RGB16_EXT:
1812 case GL_RGBA16_EXT:
1813 case GL_R16_SNORM_EXT:
1814 case GL_RG16_SNORM_EXT:
1815 case GL_RGB16_SNORM_EXT:
1816 case GL_RGBA16_SNORM_EXT:
1817 if (!context->getExtensions().textureNorm16)
1818 {
1819 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
1820 return false;
1821 }
1822 break;
Tim Van Patten208af3e2019-03-19 09:15:55 -06001823 default:
1824 context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat);
1825 return false;
Geoff Lang6e898aa2017-06-02 11:17:26 -04001826 }
1827 }
1828
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001829 if (type == GL_FLOAT)
1830 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001831 if (!context->getExtensions().textureFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001832 {
Jamie Madille0472f32018-11-27 16:32:45 -05001833 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001834 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001835 }
1836 }
1837 else if (type == GL_HALF_FLOAT_OES)
1838 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001839 if (!context->getExtensions().textureHalfFloat)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001840 {
Jamie Madille0472f32018-11-27 16:32:45 -05001841 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001842 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001843 }
1844 }
1845 }
1846
Tim Van Patten208af3e2019-03-19 09:15:55 -06001847 if (isSubImage)
Geoff Langff5b2d52016-09-07 11:32:23 -04001848 {
Tim Van Patten208af3e2019-03-19 09:15:55 -06001849 const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info;
1850 if (textureInternalFormat.internalFormat == GL_NONE)
1851 {
1852 context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel);
1853 return false;
1854 }
1855
Tim Van Patten5f388c22019-03-14 09:54:23 -06001856 if (format != textureInternalFormat.format)
1857 {
1858 context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch);
1859 return false;
1860 }
1861
1862 if (context->getExtensions().webglCompatibility)
Tim Van Patten208af3e2019-03-19 09:15:55 -06001863 {
1864 if (GetInternalFormatInfo(format, type).sizedInternalFormat !=
1865 textureInternalFormat.sizedInternalFormat)
1866 {
Tim Van Patten5f388c22019-03-14 09:54:23 -06001867 context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch);
Tim Van Patten208af3e2019-03-19 09:15:55 -06001868 return false;
1869 }
1870 }
1871
1872 if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
1873 static_cast<size_t>(yoffset + height) > texture->getHeight(target, level))
1874 {
1875 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
1876 return false;
1877 }
1878
1879 if (width > 0 && height > 0 && pixels == nullptr &&
1880 context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr)
1881 {
1882 context->validationError(GL_INVALID_VALUE, kPixelDataNull);
1883 return false;
1884 }
1885 }
1886 else
1887 {
1888 if (texture->getImmutableFormat())
1889 {
1890 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
1891 return false;
1892 }
1893 }
1894
1895 // From GL_CHROMIUM_color_buffer_float_rgb[a]:
1896 // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
1897 // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
1898 // internalformat parameter and format parameter of TexImage2D must match is lifted for this
1899 // case.
1900 if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
1901 {
1902 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Langff5b2d52016-09-07 11:32:23 -04001903 return false;
1904 }
1905
Tim Van Patten208af3e2019-03-19 09:15:55 -06001906 GLenum sizeCheckFormat = isSubImage ? format : internalformat;
1907 return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels,
1908 imageSize);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001909}
1910
He Yunchaoced53ae2016-11-29 15:00:51 +08001911bool ValidateES2TexStorageParameters(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001912 TextureType target,
He Yunchaoced53ae2016-11-29 15:00:51 +08001913 GLsizei levels,
1914 GLenum internalformat,
1915 GLsizei width,
1916 GLsizei height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001917{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001918 if (target != TextureType::_2D && target != TextureType::CubeMap &&
1919 target != TextureType::Rectangle)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001920 {
Jamie Madille0472f32018-11-27 16:32:45 -05001921 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Langb1196682014-07-23 13:47:29 -04001922 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001923 }
1924
1925 if (width < 1 || height < 1 || levels < 1)
1926 {
Jamie Madille0472f32018-11-27 16:32:45 -05001927 context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall);
Geoff Langb1196682014-07-23 13:47:29 -04001928 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001929 }
1930
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001931 if (target == TextureType::CubeMap && width != height)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001932 {
Jamie Madille0472f32018-11-27 16:32:45 -05001933 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Langb1196682014-07-23 13:47:29 -04001934 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001935 }
1936
1937 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
1938 {
Jamie Madille0472f32018-11-27 16:32:45 -05001939 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
Geoff Langb1196682014-07-23 13:47:29 -04001940 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001941 }
1942
Geoff Langca271392017-04-05 12:30:00 -04001943 const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat);
Geoff Lang5d601382014-07-22 15:14:06 -04001944 if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001945 {
Jamie Madille0472f32018-11-27 16:32:45 -05001946 context->validationError(GL_INVALID_ENUM, kInvalidFormat);
Geoff Langb1196682014-07-23 13:47:29 -04001947 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001948 }
1949
Geoff Langaae65a42014-05-26 12:43:44 -04001950 const gl::Caps &caps = context->getCaps();
1951
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001952 switch (target)
1953 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001954 case TextureType::_2D:
He Yunchaoced53ae2016-11-29 15:00:51 +08001955 if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
1956 static_cast<GLuint>(height) > caps.max2DTextureSize)
1957 {
Jamie Madille0472f32018-11-27 16:32:45 -05001958 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001959 return false;
1960 }
1961 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001962 case TextureType::Rectangle:
Jamie Madill610640f2018-11-21 17:28:41 -05001963 if (levels != 1)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001964 {
Jamie Madille0472f32018-11-27 16:32:45 -05001965 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madill610640f2018-11-21 17:28:41 -05001966 return false;
1967 }
1968
1969 if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
1970 static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
1971 {
Jamie Madille0472f32018-11-27 16:32:45 -05001972 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001973 return false;
1974 }
1975 if (formatInfo.compressed)
1976 {
Jamie Madille0472f32018-11-27 16:32:45 -05001977 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001978 return false;
1979 }
1980 break;
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001981 case TextureType::CubeMap:
He Yunchaoced53ae2016-11-29 15:00:51 +08001982 if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize ||
1983 static_cast<GLuint>(height) > caps.maxCubeMapTextureSize)
1984 {
Jamie Madille0472f32018-11-27 16:32:45 -05001985 context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize);
He Yunchaoced53ae2016-11-29 15:00:51 +08001986 return false;
1987 }
1988 break;
1989 default:
Jamie Madille0472f32018-11-27 16:32:45 -05001990 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Langb1196682014-07-23 13:47:29 -04001991 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001992 }
1993
Geoff Langc0b9ef42014-07-02 10:02:37 -04001994 if (levels != 1 && !context->getExtensions().textureNPOT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001995 {
1996 if (!gl::isPow2(width) || !gl::isPow2(height))
1997 {
Jamie Madille0472f32018-11-27 16:32:45 -05001998 context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2);
Geoff Langb1196682014-07-23 13:47:29 -04001999 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002000 }
2001 }
2002
2003 switch (internalformat)
2004 {
He Yunchaoced53ae2016-11-29 15:00:51 +08002005 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
2006 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
2007 if (!context->getExtensions().textureCompressionDXT1)
2008 {
Jamie Madille0472f32018-11-27 16:32:45 -05002009 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08002010 return false;
2011 }
2012 break;
2013 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
2014 if (!context->getExtensions().textureCompressionDXT3)
2015 {
Jamie Madille0472f32018-11-27 16:32:45 -05002016 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08002017 return false;
2018 }
2019 break;
2020 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
2021 if (!context->getExtensions().textureCompressionDXT5)
2022 {
Jamie Madille0472f32018-11-27 16:32:45 -05002023 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08002024 return false;
2025 }
2026 break;
2027 case GL_ETC1_RGB8_OES:
2028 if (!context->getExtensions().compressedETC1RGB8Texture)
2029 {
Jamie Madille0472f32018-11-27 16:32:45 -05002030 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08002031 return false;
2032 }
2033 break;
2034 case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
Minmin Gong390208b2017-02-28 18:03:06 -08002035 case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
2036 case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
2037 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
2038 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
He Yunchaoced53ae2016-11-29 15:00:51 +08002039 if (!context->getExtensions().lossyETCDecode)
2040 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002041 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08002042 return false;
2043 }
2044 break;
Le Quyen6e653982019-10-09 15:19:02 +08002045 case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
2046 case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
2047 case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
2048 case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
2049 if (!context->getExtensions().compressedTexturePVRTC)
2050 {
2051 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
2052 return false;
2053 }
2054 break;
2055 case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:
2056 case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:
2057 case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:
2058 case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:
2059 if (!context->getExtensions().compressedTexturePVRTCsRGB)
2060 {
2061 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
2062 return false;
2063 }
2064 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08002065 case GL_RGBA32F_EXT:
2066 case GL_RGB32F_EXT:
2067 case GL_ALPHA32F_EXT:
2068 case GL_LUMINANCE32F_EXT:
2069 case GL_LUMINANCE_ALPHA32F_EXT:
2070 if (!context->getExtensions().textureFloat)
2071 {
Jamie Madille0472f32018-11-27 16:32:45 -05002072 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08002073 return false;
2074 }
2075 break;
2076 case GL_RGBA16F_EXT:
2077 case GL_RGB16F_EXT:
2078 case GL_ALPHA16F_EXT:
2079 case GL_LUMINANCE16F_EXT:
2080 case GL_LUMINANCE_ALPHA16F_EXT:
2081 if (!context->getExtensions().textureHalfFloat)
2082 {
Jamie Madille0472f32018-11-27 16:32:45 -05002083 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08002084 return false;
2085 }
2086 break;
2087 case GL_R8_EXT:
2088 case GL_RG8_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04002089 if (!context->getExtensions().textureRG)
2090 {
Jamie Madille0472f32018-11-27 16:32:45 -05002091 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04002092 return false;
2093 }
2094 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08002095 case GL_R16F_EXT:
2096 case GL_RG16F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04002097 if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat)
2098 {
Jamie Madille0472f32018-11-27 16:32:45 -05002099 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang677bb6f2017-04-05 12:40:40 -04002100 return false;
2101 }
2102 break;
He Yunchaoced53ae2016-11-29 15:00:51 +08002103 case GL_R32F_EXT:
2104 case GL_RG32F_EXT:
Geoff Lang677bb6f2017-04-05 12:40:40 -04002105 if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat)
He Yunchaoced53ae2016-11-29 15:00:51 +08002106 {
Jamie Madille0472f32018-11-27 16:32:45 -05002107 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08002108 return false;
2109 }
2110 break;
2111 case GL_DEPTH_COMPONENT16:
2112 case GL_DEPTH_COMPONENT32_OES:
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06002113 if (!(context->getExtensions().depthTextureAny()))
He Yunchaoced53ae2016-11-29 15:00:51 +08002114 {
Jamie Madille0472f32018-11-27 16:32:45 -05002115 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
He Yunchaoced53ae2016-11-29 15:00:51 +08002116 return false;
2117 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002118 if (target != TextureType::_2D)
He Yunchaoced53ae2016-11-29 15:00:51 +08002119 {
Jamie Madille0472f32018-11-27 16:32:45 -05002120 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08002121 return false;
2122 }
2123 // ANGLE_depth_texture only supports 1-level textures
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06002124 if (!context->getExtensions().depthTextureOES)
He Yunchaoced53ae2016-11-29 15:00:51 +08002125 {
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06002126 if (levels != 1)
2127 {
2128 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
2129 return false;
2130 }
He Yunchaoced53ae2016-11-29 15:00:51 +08002131 }
2132 break;
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -06002133 case GL_DEPTH24_STENCIL8_OES:
2134 if (!(context->getExtensions().depthTextureANGLE ||
2135 (context->getExtensions().packedDepthStencil &&
2136 context->getExtensions().textureStorage)))
2137 {
2138 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
2139 return false;
2140 }
2141 if (target != TextureType::_2D)
2142 {
2143 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
2144 return false;
2145 }
2146 if (!context->getExtensions().packedDepthStencil)
2147 {
2148 // ANGLE_depth_texture only supports 1-level textures
2149 if (levels != 1)
2150 {
2151 context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
2152 return false;
2153 }
2154 }
2155 break;
2156
He Yunchaoced53ae2016-11-29 15:00:51 +08002157 default:
2158 break;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002159 }
2160
Jamie Madillcfc73cc2019-04-08 16:26:51 -04002161 gl::Texture *texture = context->getTextureByType(target);
Jamie Madillf7034432019-09-21 14:10:35 -04002162 if (!texture || texture->id().value == 0)
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002163 {
Jamie Madille0472f32018-11-27 16:32:45 -05002164 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
Geoff Langb1196682014-07-23 13:47:29 -04002165 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002166 }
2167
Geoff Lang69cce582015-09-17 13:20:36 -04002168 if (texture->getImmutableFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002169 {
Jamie Madille0472f32018-11-27 16:32:45 -05002170 context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable);
Geoff Langb1196682014-07-23 13:47:29 -04002171 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002172 }
2173
2174 return true;
2175}
2176
He Yunchaoced53ae2016-11-29 15:00:51 +08002177bool ValidateDiscardFramebufferEXT(Context *context,
2178 GLenum target,
2179 GLsizei numAttachments,
Austin Kinross08332632015-05-05 13:35:47 -07002180 const GLenum *attachments)
2181{
Jamie Madillc29968b2016-01-20 11:17:23 -05002182 if (!context->getExtensions().discardFramebuffer)
2183 {
Jamie Madille0472f32018-11-27 16:32:45 -05002184 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002185 return false;
2186 }
2187
Austin Kinross08332632015-05-05 13:35:47 -07002188 bool defaultFramebuffer = false;
2189
2190 switch (target)
2191 {
He Yunchaoced53ae2016-11-29 15:00:51 +08002192 case GL_FRAMEBUFFER:
2193 defaultFramebuffer =
Tim Van Patten56ba54c2019-08-08 13:03:34 -06002194 (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->isDefault());
He Yunchaoced53ae2016-11-29 15:00:51 +08002195 break;
2196 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002197 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
He Yunchaoced53ae2016-11-29 15:00:51 +08002198 return false;
Austin Kinross08332632015-05-05 13:35:47 -07002199 }
2200
He Yunchaoced53ae2016-11-29 15:00:51 +08002201 return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments,
2202 defaultFramebuffer);
Austin Kinross08332632015-05-05 13:35:47 -07002203}
2204
Jiacheng Lufeb85072019-09-03 13:22:04 -04002205bool ValidateBindVertexArrayOES(Context *context, VertexArrayID array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002206{
2207 if (!context->getExtensions().vertexArrayObject)
2208 {
Jamie Madille0472f32018-11-27 16:32:45 -05002209 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002210 return false;
2211 }
2212
2213 return ValidateBindVertexArrayBase(context, array);
2214}
2215
Jiacheng Lufeb85072019-09-03 13:22:04 -04002216bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const VertexArrayID *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002217{
2218 if (!context->getExtensions().vertexArrayObject)
2219 {
Jamie Madille0472f32018-11-27 16:32:45 -05002220 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002221 return false;
2222 }
2223
Olli Etuaho41997e72016-03-10 13:38:39 +02002224 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002225}
2226
Jiacheng Lufeb85072019-09-03 13:22:04 -04002227bool ValidateGenVertexArraysOES(Context *context, GLsizei n, VertexArrayID *arrays)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002228{
2229 if (!context->getExtensions().vertexArrayObject)
2230 {
Jamie Madille0472f32018-11-27 16:32:45 -05002231 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002232 return false;
2233 }
2234
Olli Etuaho41997e72016-03-10 13:38:39 +02002235 return ValidateGenOrDelete(context, n);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002236}
2237
Jiacheng Lufeb85072019-09-03 13:22:04 -04002238bool ValidateIsVertexArrayOES(Context *context, VertexArrayID array)
Austin Kinrossbc781f32015-10-26 09:27:38 -07002239{
2240 if (!context->getExtensions().vertexArrayObject)
2241 {
Jamie Madille0472f32018-11-27 16:32:45 -05002242 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Kinrossbc781f32015-10-26 09:27:38 -07002243 return false;
2244 }
2245
2246 return true;
2247}
Geoff Langc5629752015-12-07 16:29:04 -05002248
2249bool ValidateProgramBinaryOES(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06002250 ShaderProgramID program,
Geoff Langc5629752015-12-07 16:29:04 -05002251 GLenum binaryFormat,
2252 const void *binary,
2253 GLint length)
2254{
2255 if (!context->getExtensions().getProgramBinary)
2256 {
Jamie Madille0472f32018-11-27 16:32:45 -05002257 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002258 return false;
2259 }
2260
2261 return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length);
2262}
2263
2264bool ValidateGetProgramBinaryOES(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06002265 ShaderProgramID program,
Geoff Langc5629752015-12-07 16:29:04 -05002266 GLsizei bufSize,
2267 GLsizei *length,
2268 GLenum *binaryFormat,
2269 void *binary)
2270{
2271 if (!context->getExtensions().getProgramBinary)
2272 {
Jamie Madille0472f32018-11-27 16:32:45 -05002273 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc5629752015-12-07 16:29:04 -05002274 return false;
2275 }
2276
2277 return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary);
2278}
Geoff Lange102fee2015-12-10 11:23:30 -05002279
Geoff Lang70d0f492015-12-10 17:45:46 -05002280static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication)
2281{
2282 switch (source)
2283 {
2284 case GL_DEBUG_SOURCE_API:
2285 case GL_DEBUG_SOURCE_SHADER_COMPILER:
2286 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
2287 case GL_DEBUG_SOURCE_OTHER:
2288 // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted
2289 return !mustBeThirdPartyOrApplication;
2290
2291 case GL_DEBUG_SOURCE_THIRD_PARTY:
2292 case GL_DEBUG_SOURCE_APPLICATION:
2293 return true;
2294
2295 default:
2296 return false;
2297 }
2298}
2299
2300static bool ValidDebugType(GLenum type)
2301{
2302 switch (type)
2303 {
2304 case GL_DEBUG_TYPE_ERROR:
2305 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
2306 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
2307 case GL_DEBUG_TYPE_PERFORMANCE:
2308 case GL_DEBUG_TYPE_PORTABILITY:
2309 case GL_DEBUG_TYPE_OTHER:
2310 case GL_DEBUG_TYPE_MARKER:
2311 case GL_DEBUG_TYPE_PUSH_GROUP:
2312 case GL_DEBUG_TYPE_POP_GROUP:
2313 return true;
2314
2315 default:
2316 return false;
2317 }
2318}
2319
2320static bool ValidDebugSeverity(GLenum severity)
2321{
2322 switch (severity)
2323 {
2324 case GL_DEBUG_SEVERITY_HIGH:
2325 case GL_DEBUG_SEVERITY_MEDIUM:
2326 case GL_DEBUG_SEVERITY_LOW:
2327 case GL_DEBUG_SEVERITY_NOTIFICATION:
2328 return true;
2329
2330 default:
2331 return false;
2332 }
2333}
2334
Geoff Lange102fee2015-12-10 11:23:30 -05002335bool ValidateDebugMessageControlKHR(Context *context,
2336 GLenum source,
2337 GLenum type,
2338 GLenum severity,
2339 GLsizei count,
2340 const GLuint *ids,
2341 GLboolean enabled)
2342{
2343 if (!context->getExtensions().debug)
2344 {
Jamie Madille0472f32018-11-27 16:32:45 -05002345 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002346 return false;
2347 }
2348
Geoff Lang70d0f492015-12-10 17:45:46 -05002349 if (!ValidDebugSource(source, false) && source != GL_DONT_CARE)
2350 {
Jamie Madille0472f32018-11-27 16:32:45 -05002351 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002352 return false;
2353 }
2354
2355 if (!ValidDebugType(type) && type != GL_DONT_CARE)
2356 {
Jamie Madille0472f32018-11-27 16:32:45 -05002357 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002358 return false;
2359 }
2360
2361 if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE)
2362 {
Jamie Madille0472f32018-11-27 16:32:45 -05002363 context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002364 return false;
2365 }
2366
2367 if (count > 0)
2368 {
2369 if (source == GL_DONT_CARE || type == GL_DONT_CARE)
2370 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002371 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002372 return false;
2373 }
2374
2375 if (severity != GL_DONT_CARE)
2376 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002377 context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity);
Geoff Lang70d0f492015-12-10 17:45:46 -05002378 return false;
2379 }
2380 }
2381
Geoff Lange102fee2015-12-10 11:23:30 -05002382 return true;
2383}
2384
2385bool ValidateDebugMessageInsertKHR(Context *context,
2386 GLenum source,
2387 GLenum type,
2388 GLuint id,
2389 GLenum severity,
2390 GLsizei length,
2391 const GLchar *buf)
2392{
2393 if (!context->getExtensions().debug)
2394 {
Jamie Madille0472f32018-11-27 16:32:45 -05002395 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002396 return false;
2397 }
2398
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002399 if (!context->getState().getDebug().isOutputEnabled())
Geoff Lang70d0f492015-12-10 17:45:46 -05002400 {
2401 // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do
2402 // not generate an error.
2403 return false;
2404 }
2405
2406 if (!ValidDebugSeverity(severity))
2407 {
Jamie Madille0472f32018-11-27 16:32:45 -05002408 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002409 return false;
2410 }
2411
2412 if (!ValidDebugType(type))
2413 {
Jamie Madille0472f32018-11-27 16:32:45 -05002414 context->validationError(GL_INVALID_ENUM, kInvalidDebugType);
Geoff Lang70d0f492015-12-10 17:45:46 -05002415 return false;
2416 }
2417
2418 if (!ValidDebugSource(source, true))
2419 {
Jamie Madille0472f32018-11-27 16:32:45 -05002420 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002421 return false;
2422 }
2423
2424 size_t messageLength = (length < 0) ? strlen(buf) : length;
2425 if (messageLength > context->getExtensions().maxDebugMessageLength)
2426 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002427 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002428 return false;
2429 }
2430
Geoff Lange102fee2015-12-10 11:23:30 -05002431 return true;
2432}
2433
2434bool ValidateDebugMessageCallbackKHR(Context *context,
2435 GLDEBUGPROCKHR callback,
2436 const void *userParam)
2437{
2438 if (!context->getExtensions().debug)
2439 {
Jamie Madille0472f32018-11-27 16:32:45 -05002440 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002441 return false;
2442 }
2443
Geoff Lange102fee2015-12-10 11:23:30 -05002444 return true;
2445}
2446
2447bool ValidateGetDebugMessageLogKHR(Context *context,
2448 GLuint count,
2449 GLsizei bufSize,
2450 GLenum *sources,
2451 GLenum *types,
2452 GLuint *ids,
2453 GLenum *severities,
2454 GLsizei *lengths,
2455 GLchar *messageLog)
2456{
2457 if (!context->getExtensions().debug)
2458 {
Jamie Madille0472f32018-11-27 16:32:45 -05002459 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002460 return false;
2461 }
2462
Geoff Lang70d0f492015-12-10 17:45:46 -05002463 if (bufSize < 0 && messageLog != nullptr)
2464 {
Jamie Madille0472f32018-11-27 16:32:45 -05002465 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002466 return false;
2467 }
2468
Geoff Lange102fee2015-12-10 11:23:30 -05002469 return true;
2470}
2471
2472bool ValidatePushDebugGroupKHR(Context *context,
2473 GLenum source,
2474 GLuint id,
2475 GLsizei length,
2476 const GLchar *message)
2477{
2478 if (!context->getExtensions().debug)
2479 {
Jamie Madille0472f32018-11-27 16:32:45 -05002480 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002481 return false;
2482 }
2483
Geoff Lang70d0f492015-12-10 17:45:46 -05002484 if (!ValidDebugSource(source, true))
2485 {
Jamie Madille0472f32018-11-27 16:32:45 -05002486 context->validationError(GL_INVALID_ENUM, kInvalidDebugSource);
Geoff Lang70d0f492015-12-10 17:45:46 -05002487 return false;
2488 }
2489
2490 size_t messageLength = (length < 0) ? strlen(message) : length;
2491 if (messageLength > context->getExtensions().maxDebugMessageLength)
2492 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002493 context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength);
Geoff Lang70d0f492015-12-10 17:45:46 -05002494 return false;
2495 }
2496
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002497 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002498 if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth)
2499 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002500 context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth);
Geoff Lang70d0f492015-12-10 17:45:46 -05002501 return false;
2502 }
2503
Geoff Lange102fee2015-12-10 11:23:30 -05002504 return true;
2505}
2506
2507bool ValidatePopDebugGroupKHR(Context *context)
2508{
2509 if (!context->getExtensions().debug)
2510 {
Jamie Madille0472f32018-11-27 16:32:45 -05002511 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002512 return false;
2513 }
2514
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002515 size_t currentStackSize = context->getState().getDebug().getGroupStackDepth();
Geoff Lang70d0f492015-12-10 17:45:46 -05002516 if (currentStackSize <= 1)
2517 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002518 context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup);
Geoff Lang70d0f492015-12-10 17:45:46 -05002519 return false;
2520 }
2521
2522 return true;
2523}
2524
2525static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name)
2526{
2527 switch (identifier)
2528 {
2529 case GL_BUFFER:
Jamie Madill3b3fe832019-08-06 17:44:12 -04002530 if (context->getBuffer({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002531 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002532 context->validationError(GL_INVALID_VALUE, kInvalidBufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002533 return false;
2534 }
2535 return true;
2536
2537 case GL_SHADER:
Jiacheng Lu120b61d2019-08-21 12:51:58 -06002538 if (context->getShader({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002539 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002540 context->validationError(GL_INVALID_VALUE, kInvalidShaderName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002541 return false;
2542 }
2543 return true;
2544
2545 case GL_PROGRAM:
Jiacheng Lu120b61d2019-08-21 12:51:58 -06002546 if (context->getProgramNoResolveLink({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002547 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002548 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002549 return false;
2550 }
2551 return true;
2552
2553 case GL_VERTEX_ARRAY:
Jiacheng Lufeb85072019-09-03 13:22:04 -04002554 if (context->getVertexArray({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002555 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002556 context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002557 return false;
2558 }
2559 return true;
2560
2561 case GL_QUERY:
Jiacheng Lu814a0a12019-08-22 11:50:43 -06002562 if (context->getQuery({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002563 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002564 context->validationError(GL_INVALID_VALUE, kInvalidQueryName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002565 return false;
2566 }
2567 return true;
2568
2569 case GL_TRANSFORM_FEEDBACK:
Jiacheng Luc3f78732019-08-30 15:00:52 -06002570 if (context->getTransformFeedback({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002571 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002572 context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002573 return false;
2574 }
2575 return true;
2576
2577 case GL_SAMPLER:
Jiacheng Luee79e2f2019-08-20 11:28:36 -06002578 if (context->getSampler({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002579 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002580 context->validationError(GL_INVALID_VALUE, kInvalidSamplerName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002581 return false;
2582 }
2583 return true;
2584
2585 case GL_TEXTURE:
Jamie Madill2ab08ed2019-08-12 16:20:21 -04002586 if (context->getTexture({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002587 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002588 context->validationError(GL_INVALID_VALUE, kInvalidTextureName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002589 return false;
2590 }
2591 return true;
2592
2593 case GL_RENDERBUFFER:
Jamie Madill7c7dec02019-08-06 17:44:11 -04002594 if (!context->isRenderbuffer({name}))
Geoff Lang70d0f492015-12-10 17:45:46 -05002595 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002596 context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002597 return false;
2598 }
2599 return true;
2600
2601 case GL_FRAMEBUFFER:
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06002602 if (context->getFramebuffer({name}) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002603 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002604 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName);
Geoff Lang70d0f492015-12-10 17:45:46 -05002605 return false;
2606 }
2607 return true;
2608
2609 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05002610 context->validationError(GL_INVALID_ENUM, kInvalidIndentifier);
Geoff Lang70d0f492015-12-10 17:45:46 -05002611 return false;
2612 }
Geoff Lange102fee2015-12-10 11:23:30 -05002613}
2614
Martin Radev9d901792016-07-15 15:58:58 +03002615static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label)
2616{
2617 size_t labelLength = 0;
2618
2619 if (length < 0)
2620 {
2621 if (label != nullptr)
2622 {
2623 labelLength = strlen(label);
2624 }
2625 }
2626 else
2627 {
2628 labelLength = static_cast<size_t>(length);
2629 }
2630
2631 if (labelLength > context->getExtensions().maxLabelLength)
2632 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002633 context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength);
Martin Radev9d901792016-07-15 15:58:58 +03002634 return false;
2635 }
2636
2637 return true;
2638}
2639
Geoff Lange102fee2015-12-10 11:23:30 -05002640bool ValidateObjectLabelKHR(Context *context,
2641 GLenum identifier,
2642 GLuint name,
2643 GLsizei length,
2644 const GLchar *label)
2645{
2646 if (!context->getExtensions().debug)
2647 {
Jamie Madille0472f32018-11-27 16:32:45 -05002648 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002649 return false;
2650 }
2651
Geoff Lang70d0f492015-12-10 17:45:46 -05002652 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2653 {
2654 return false;
2655 }
2656
Martin Radev9d901792016-07-15 15:58:58 +03002657 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002658 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002659 return false;
2660 }
2661
Geoff Lange102fee2015-12-10 11:23:30 -05002662 return true;
2663}
2664
2665bool ValidateGetObjectLabelKHR(Context *context,
2666 GLenum identifier,
2667 GLuint name,
2668 GLsizei bufSize,
2669 GLsizei *length,
2670 GLchar *label)
2671{
2672 if (!context->getExtensions().debug)
2673 {
Jamie Madille0472f32018-11-27 16:32:45 -05002674 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002675 return false;
2676 }
2677
Geoff Lang70d0f492015-12-10 17:45:46 -05002678 if (bufSize < 0)
2679 {
Jamie Madille0472f32018-11-27 16:32:45 -05002680 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002681 return false;
2682 }
2683
2684 if (!ValidateObjectIdentifierAndName(context, identifier, name))
2685 {
2686 return false;
2687 }
2688
Martin Radev9d901792016-07-15 15:58:58 +03002689 return true;
Geoff Lang70d0f492015-12-10 17:45:46 -05002690}
2691
2692static bool ValidateObjectPtrName(Context *context, const void *ptr)
2693{
Jamie Madill70b5bb02017-08-28 13:32:37 -04002694 if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr)
Geoff Lang70d0f492015-12-10 17:45:46 -05002695 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002696 context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer);
Geoff Lang70d0f492015-12-10 17:45:46 -05002697 return false;
2698 }
2699
Geoff Lange102fee2015-12-10 11:23:30 -05002700 return true;
2701}
2702
2703bool ValidateObjectPtrLabelKHR(Context *context,
2704 const void *ptr,
2705 GLsizei length,
2706 const GLchar *label)
2707{
2708 if (!context->getExtensions().debug)
2709 {
Jamie Madille0472f32018-11-27 16:32:45 -05002710 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002711 return false;
2712 }
2713
Geoff Lang70d0f492015-12-10 17:45:46 -05002714 if (!ValidateObjectPtrName(context, ptr))
2715 {
2716 return false;
2717 }
2718
Martin Radev9d901792016-07-15 15:58:58 +03002719 if (!ValidateLabelLength(context, length, label))
Geoff Lang70d0f492015-12-10 17:45:46 -05002720 {
Geoff Lang70d0f492015-12-10 17:45:46 -05002721 return false;
2722 }
2723
Geoff Lange102fee2015-12-10 11:23:30 -05002724 return true;
2725}
2726
2727bool ValidateGetObjectPtrLabelKHR(Context *context,
2728 const void *ptr,
2729 GLsizei bufSize,
2730 GLsizei *length,
2731 GLchar *label)
2732{
2733 if (!context->getExtensions().debug)
2734 {
Jamie Madille0472f32018-11-27 16:32:45 -05002735 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002736 return false;
2737 }
2738
Geoff Lang70d0f492015-12-10 17:45:46 -05002739 if (bufSize < 0)
2740 {
Jamie Madille0472f32018-11-27 16:32:45 -05002741 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Geoff Lang70d0f492015-12-10 17:45:46 -05002742 return false;
2743 }
2744
2745 if (!ValidateObjectPtrName(context, ptr))
2746 {
2747 return false;
2748 }
2749
Martin Radev9d901792016-07-15 15:58:58 +03002750 return true;
Geoff Lange102fee2015-12-10 11:23:30 -05002751}
2752
2753bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params)
2754{
2755 if (!context->getExtensions().debug)
2756 {
Jamie Madille0472f32018-11-27 16:32:45 -05002757 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lange102fee2015-12-10 11:23:30 -05002758 return false;
2759 }
2760
Geoff Lang70d0f492015-12-10 17:45:46 -05002761 // TODO: represent this in Context::getQueryParameterInfo.
2762 switch (pname)
2763 {
2764 case GL_DEBUG_CALLBACK_FUNCTION:
2765 case GL_DEBUG_CALLBACK_USER_PARAM:
2766 break;
2767
2768 default:
Jamie Madille0472f32018-11-27 16:32:45 -05002769 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang70d0f492015-12-10 17:45:46 -05002770 return false;
2771 }
2772
Geoff Lange102fee2015-12-10 11:23:30 -05002773 return true;
2774}
Jamie Madillc29968b2016-01-20 11:17:23 -05002775
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002776bool ValidateGetPointervRobustANGLERobustANGLE(Context *context,
2777 GLenum pname,
2778 GLsizei bufSize,
2779 GLsizei *length,
2780 void **params)
2781{
2782 UNIMPLEMENTED();
2783 return false;
2784}
2785
Jamie Madillc29968b2016-01-20 11:17:23 -05002786bool ValidateBlitFramebufferANGLE(Context *context,
2787 GLint srcX0,
2788 GLint srcY0,
2789 GLint srcX1,
2790 GLint srcY1,
2791 GLint dstX0,
2792 GLint dstY0,
2793 GLint dstX1,
2794 GLint dstY1,
2795 GLbitfield mask,
2796 GLenum filter)
2797{
2798 if (!context->getExtensions().framebufferBlit)
2799 {
Jamie Madille0472f32018-11-27 16:32:45 -05002800 context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable);
Jamie Madillc29968b2016-01-20 11:17:23 -05002801 return false;
2802 }
2803
2804 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
2805 {
2806 // TODO(jmadill): Determine if this should be available on other implementations.
Jamie Madille0472f32018-11-27 16:32:45 -05002807 context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip);
Jamie Madillc29968b2016-01-20 11:17:23 -05002808 return false;
2809 }
2810
2811 if (filter == GL_LINEAR)
2812 {
Jamie Madille0472f32018-11-27 16:32:45 -05002813 context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear);
Jamie Madillc29968b2016-01-20 11:17:23 -05002814 return false;
2815 }
2816
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002817 Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
2818 Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002819
2820 if (mask & GL_COLOR_BUFFER_BIT)
2821 {
Jamie Madill4e71b2b2019-07-08 13:23:38 -04002822 const FramebufferAttachment *readColorAttachment =
2823 readFramebuffer->getReadColorAttachment();
2824 const FramebufferAttachment *drawColorAttachment =
2825 drawFramebuffer->getFirstColorAttachment();
Jamie Madillc29968b2016-01-20 11:17:23 -05002826
2827 if (readColorAttachment && drawColorAttachment)
2828 {
2829 if (!(readColorAttachment->type() == GL_TEXTURE &&
Kenneth Russellcbdf8612019-07-09 20:30:45 -07002830 (readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D ||
2831 readColorAttachment->getTextureImageIndex().getType() ==
2832 TextureType::Rectangle)) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002833 readColorAttachment->type() != GL_RENDERBUFFER &&
2834 readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)
2835 {
Jamie Madill610640f2018-11-21 17:28:41 -05002836 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002837 kBlitExtensionFromInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002838 return false;
2839 }
2840
Geoff Langa15472a2015-08-11 11:48:03 -04002841 for (size_t drawbufferIdx = 0;
2842 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
Jamie Madillc29968b2016-01-20 11:17:23 -05002843 {
Geoff Langa15472a2015-08-11 11:48:03 -04002844 const FramebufferAttachment *attachment =
2845 drawFramebuffer->getDrawBuffer(drawbufferIdx);
2846 if (attachment)
Jamie Madillc29968b2016-01-20 11:17:23 -05002847 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002848 if (!(attachment->type() == GL_TEXTURE &&
Kenneth Russellcbdf8612019-07-09 20:30:45 -07002849 (attachment->getTextureImageIndex().getType() == TextureType::_2D ||
2850 attachment->getTextureImageIndex().getType() ==
2851 TextureType::Rectangle)) &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002852 attachment->type() != GL_RENDERBUFFER &&
2853 attachment->type() != GL_FRAMEBUFFER_DEFAULT)
2854 {
Jamie Madill610640f2018-11-21 17:28:41 -05002855 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002856 kBlitExtensionToInvalidAttachmentType);
Jamie Madillc29968b2016-01-20 11:17:23 -05002857 return false;
2858 }
2859
2860 // Return an error if the destination formats do not match
Kenneth Russell69382852017-07-21 16:38:44 -04002861 if (!Format::EquivalentForBlit(attachment->getFormat(),
2862 readColorAttachment->getFormat()))
Jamie Madillc29968b2016-01-20 11:17:23 -05002863 {
Jamie Madill610640f2018-11-21 17:28:41 -05002864 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002865 kBlitExtensionFormatMismatch);
Jamie Madillc29968b2016-01-20 11:17:23 -05002866 return false;
2867 }
2868 }
2869 }
2870
Jamie Madill427064d2018-04-13 16:20:34 -04002871 GLint samples = readFramebuffer->getSamples(context);
Jamie Madille98b1b52018-03-08 09:47:23 -05002872 if (samples != 0 &&
Jamie Madillc29968b2016-01-20 11:17:23 -05002873 IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0,
2874 srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
2875 {
Jamie Madill610640f2018-11-21 17:28:41 -05002876 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002877 kBlitExtensionMultisampledWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002878 return false;
2879 }
2880 }
2881 }
2882
2883 GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
2884 GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
2885 for (size_t i = 0; i < 2; i++)
2886 {
2887 if (mask & masks[i])
2888 {
2889 const FramebufferAttachment *readBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002890 readFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002891 const FramebufferAttachment *drawBuffer =
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002892 drawFramebuffer->getAttachment(context, attachments[i]);
Jamie Madillc29968b2016-01-20 11:17:23 -05002893
2894 if (readBuffer && drawBuffer)
2895 {
2896 if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1,
2897 dstX0, dstY0, dstX1, dstY1))
2898 {
2899 // only whole-buffer copies are permitted
Jamie Madill610640f2018-11-21 17:28:41 -05002900 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002901 kBlitExtensionDepthStencilWholeBufferBlit);
Jamie Madillc29968b2016-01-20 11:17:23 -05002902 return false;
2903 }
2904
2905 if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0)
2906 {
Jamie Madill610640f2018-11-21 17:28:41 -05002907 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05002908 kBlitExtensionMultisampledDepthOrStencil);
Jamie Madillc29968b2016-01-20 11:17:23 -05002909 return false;
2910 }
2911 }
2912 }
2913 }
2914
2915 return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
2916 dstX1, dstY1, mask, filter);
Geoff Lange8ebe7f2013-08-05 15:03:13 -04002917}
Jamie Madillc29968b2016-01-20 11:17:23 -05002918
Jamie Madill5b772312018-03-08 20:28:32 -05002919bool ValidateClear(Context *context, GLbitfield mask)
Jamie Madillc29968b2016-01-20 11:17:23 -05002920{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002921 Framebuffer *fbo = context->getState().getDrawFramebuffer();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002922 const Extensions &extensions = context->getExtensions();
Jamie Madille98b1b52018-03-08 09:47:23 -05002923
Jamie Madill427064d2018-04-13 16:20:34 -04002924 if (!ValidateFramebufferComplete(context, fbo))
Jamie Madillc29968b2016-01-20 11:17:23 -05002925 {
Jamie Madillc29968b2016-01-20 11:17:23 -05002926 return false;
2927 }
2928
2929 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
2930 {
Jamie Madille0472f32018-11-27 16:32:45 -05002931 context->validationError(GL_INVALID_VALUE, kInvalidClearMask);
Jamie Madillc29968b2016-01-20 11:17:23 -05002932 return false;
2933 }
2934
Olli Etuaho94c91a92018-07-19 15:10:24 +03002935 if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0)
Geoff Lang76e65652017-03-27 14:58:02 -04002936 {
2937 constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED,
2938 GL_SIGNED_NORMALIZED};
2939
Corentin Wallez59c41592017-07-11 13:19:54 -04002940 for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount();
Geoff Lang76e65652017-03-27 14:58:02 -04002941 drawBufferIdx++)
2942 {
2943 if (!ValidateWebGLFramebufferAttachmentClearType(
2944 context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes)))
2945 {
2946 return false;
2947 }
2948 }
2949 }
2950
Mingyu Huebab6702019-04-19 14:36:45 -07002951 if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery)
Olli Etuaho94c91a92018-07-19 15:10:24 +03002952 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002953 const State &state = context->getState();
Olli Etuaho94c91a92018-07-19 15:10:24 +03002954 Framebuffer *framebuffer = state.getDrawFramebuffer();
2955 if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed))
2956 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002957 context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery);
Olli Etuaho94c91a92018-07-19 15:10:24 +03002958 return false;
2959 }
2960 }
2961
Jamie Madillc29968b2016-01-20 11:17:23 -05002962 return true;
2963}
2964
Jamie Madill5b772312018-03-08 20:28:32 -05002965bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs)
Jamie Madillc29968b2016-01-20 11:17:23 -05002966{
2967 if (!context->getExtensions().drawBuffers)
2968 {
Jamie Madillc3e37312018-11-30 15:25:39 -05002969 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillc29968b2016-01-20 11:17:23 -05002970 return false;
2971 }
2972
2973 return ValidateDrawBuffersBase(context, n, bufs);
2974}
2975
Jamie Madill73a84962016-02-12 09:27:23 -05002976bool ValidateTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002977 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05002978 GLint level,
2979 GLint internalformat,
2980 GLsizei width,
2981 GLsizei height,
2982 GLint border,
2983 GLenum format,
2984 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002985 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05002986{
Martin Radev1be913c2016-07-11 17:59:16 +03002987 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05002988 {
2989 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
Geoff Langff5b2d52016-09-07 11:32:23 -04002990 0, 0, width, height, border, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05002991 }
2992
Martin Radev1be913c2016-07-11 17:59:16 +03002993 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05002994 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04002995 0, 0, width, height, 1, border, format, type, -1,
2996 pixels);
2997}
2998
Brandon Jones416aaf92018-04-10 08:10:16 -07002999bool ValidateTexImage2DRobustANGLE(Context *context,
3000 TextureTarget target,
3001 GLint level,
3002 GLint internalformat,
3003 GLsizei width,
3004 GLsizei height,
3005 GLint border,
3006 GLenum format,
3007 GLenum type,
3008 GLsizei bufSize,
3009 const void *pixels)
Geoff Langff5b2d52016-09-07 11:32:23 -04003010{
3011 if (!ValidateRobustEntryPoint(context, bufSize))
3012 {
3013 return false;
3014 }
3015
3016 if (context->getClientMajorVersion() < 3)
3017 {
3018 return ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
3019 0, 0, width, height, border, format, type, bufSize,
3020 pixels);
3021 }
3022
3023 ASSERT(context->getClientMajorVersion() >= 3);
3024 return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0,
3025 0, 0, width, height, 1, border, format, type, bufSize,
3026 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05003027}
3028
3029bool ValidateTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003030 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003031 GLint level,
3032 GLint xoffset,
3033 GLint yoffset,
3034 GLsizei width,
3035 GLsizei height,
3036 GLenum format,
3037 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003038 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003039{
3040
Martin Radev1be913c2016-07-11 17:59:16 +03003041 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05003042 {
3043 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04003044 yoffset, width, height, 0, format, type, -1, pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05003045 }
3046
Martin Radev1be913c2016-07-11 17:59:16 +03003047 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003048 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
Geoff Langff5b2d52016-09-07 11:32:23 -04003049 yoffset, 0, width, height, 1, 0, format, type, -1,
3050 pixels);
Jamie Madill73a84962016-02-12 09:27:23 -05003051}
3052
Geoff Langc52f6f12016-10-14 10:18:00 -04003053bool ValidateTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003054 TextureTarget target,
Geoff Langc52f6f12016-10-14 10:18:00 -04003055 GLint level,
3056 GLint xoffset,
3057 GLint yoffset,
3058 GLsizei width,
3059 GLsizei height,
3060 GLenum format,
3061 GLenum type,
3062 GLsizei bufSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003063 const void *pixels)
Geoff Langc52f6f12016-10-14 10:18:00 -04003064{
3065 if (!ValidateRobustEntryPoint(context, bufSize))
3066 {
3067 return false;
3068 }
3069
3070 if (context->getClientMajorVersion() < 3)
3071 {
3072 return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset,
3073 yoffset, width, height, 0, format, type, bufSize,
3074 pixels);
3075 }
3076
3077 ASSERT(context->getClientMajorVersion() >= 3);
3078 return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset,
3079 yoffset, 0, width, height, 1, 0, format, type, bufSize,
3080 pixels);
3081}
3082
Cody Northrop5faff912019-06-28 14:04:50 -06003083bool ValidateTexSubImage3DOES(Context *context,
3084 TextureTarget target,
3085 GLint level,
3086 GLint xoffset,
3087 GLint yoffset,
3088 GLint zoffset,
3089 GLsizei width,
3090 GLsizei height,
3091 GLsizei depth,
3092 GLenum format,
3093 GLenum type,
3094 const void *pixels)
3095{
3096 return ValidateTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, height,
3097 depth, format, type, pixels);
3098}
3099
Jamie Madill73a84962016-02-12 09:27:23 -05003100bool ValidateCompressedTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003101 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003102 GLint level,
3103 GLenum internalformat,
3104 GLsizei width,
3105 GLsizei height,
3106 GLint border,
3107 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003108 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003109{
Martin Radev1be913c2016-07-11 17:59:16 +03003110 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05003111 {
3112 if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04003113 0, width, height, border, GL_NONE, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05003114 {
3115 return false;
3116 }
3117 }
3118 else
3119 {
Martin Radev1be913c2016-07-11 17:59:16 +03003120 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003121 if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0,
Geoff Langff5b2d52016-09-07 11:32:23 -04003122 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05003123 data))
3124 {
3125 return false;
3126 }
3127 }
3128
Geoff Langca271392017-04-05 12:30:00 -04003129 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat);
Jamie Madillca2ff382018-07-11 09:01:17 -04003130
3131 GLuint blockSize = 0;
3132 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003133 {
Jamie Madille0472f32018-11-27 16:32:45 -05003134 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003135 return false;
3136 }
3137
Jamie Madillca2ff382018-07-11 09:01:17 -04003138 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003139 {
Jamie Madille0472f32018-11-27 16:32:45 -05003140 context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData);
Jamie Madill73a84962016-02-12 09:27:23 -05003141 return false;
3142 }
3143
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003144 if (target == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003145 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003146 context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003147 return false;
3148 }
3149
Jamie Madill73a84962016-02-12 09:27:23 -05003150 return true;
3151}
3152
Corentin Wallezb2931602017-04-11 15:58:57 -04003153bool ValidateCompressedTexImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003154 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04003155 GLint level,
3156 GLenum internalformat,
3157 GLsizei width,
3158 GLsizei height,
3159 GLint border,
3160 GLsizei imageSize,
3161 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003162 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003163{
3164 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3165 {
3166 return false;
3167 }
3168
3169 return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height,
3170 border, imageSize, data);
3171}
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003172
Cody Northrop5faff912019-06-28 14:04:50 -06003173bool ValidateCompressedTexImage3DOES(Context *context,
3174 TextureTarget target,
3175 GLint level,
3176 GLenum internalformat,
3177 GLsizei width,
3178 GLsizei height,
3179 GLsizei depth,
3180 GLint border,
3181 GLsizei imageSize,
3182 const void *data)
3183{
3184 return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height,
3185 depth, border, imageSize, data);
3186}
3187
Corentin Wallezb2931602017-04-11 15:58:57 -04003188bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003189 TextureTarget target,
Corentin Wallezb2931602017-04-11 15:58:57 -04003190 GLint level,
3191 GLint xoffset,
3192 GLint yoffset,
3193 GLsizei width,
3194 GLsizei height,
3195 GLenum format,
3196 GLsizei imageSize,
3197 GLsizei dataSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003198 const void *data)
Corentin Wallezb2931602017-04-11 15:58:57 -04003199{
3200 if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize))
3201 {
3202 return false;
3203 }
3204
3205 return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height,
3206 format, imageSize, data);
3207}
3208
Jamie Madill73a84962016-02-12 09:27:23 -05003209bool ValidateCompressedTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003210 TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003211 GLint level,
3212 GLint xoffset,
3213 GLint yoffset,
3214 GLsizei width,
3215 GLsizei height,
3216 GLenum format,
3217 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003218 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003219{
Martin Radev1be913c2016-07-11 17:59:16 +03003220 if (context->getClientMajorVersion() < 3)
Jamie Madill73a84962016-02-12 09:27:23 -05003221 {
3222 if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003223 yoffset, width, height, 0, format, GL_NONE, -1, data))
Jamie Madill73a84962016-02-12 09:27:23 -05003224 {
3225 return false;
3226 }
3227 }
3228 else
3229 {
Martin Radev1be913c2016-07-11 17:59:16 +03003230 ASSERT(context->getClientMajorVersion() >= 3);
Jamie Madill73a84962016-02-12 09:27:23 -05003231 if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset,
Geoff Lang966c9402017-04-18 12:38:27 -04003232 yoffset, 0, width, height, 1, 0, format, GL_NONE, -1,
Jamie Madill73a84962016-02-12 09:27:23 -05003233 data))
3234 {
3235 return false;
3236 }
3237 }
3238
Geoff Langca271392017-04-05 12:30:00 -04003239 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format);
Jamie Madillca2ff382018-07-11 09:01:17 -04003240 GLuint blockSize = 0;
3241 if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize))
Jamie Madille2e406c2016-06-02 13:04:10 -04003242 {
Jamie Madille0472f32018-11-27 16:32:45 -05003243 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Jamie Madille2e406c2016-06-02 13:04:10 -04003244 return false;
3245 }
3246
Jamie Madillca2ff382018-07-11 09:01:17 -04003247 if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize)
Jamie Madill73a84962016-02-12 09:27:23 -05003248 {
Jamie Madille0472f32018-11-27 16:32:45 -05003249 context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize);
Jamie Madill73a84962016-02-12 09:27:23 -05003250 return false;
3251 }
3252
3253 return true;
3254}
3255
Cody Northrop5faff912019-06-28 14:04:50 -06003256bool ValidateCompressedTexSubImage3DOES(Context *context,
3257 TextureTarget target,
3258 GLint level,
3259 GLint xoffset,
3260 GLint yoffset,
3261 GLint zoffset,
3262 GLsizei width,
3263 GLsizei height,
3264 GLsizei depth,
3265 GLenum format,
3266 GLsizei imageSize,
3267 const void *data)
3268{
3269 return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width,
3270 height, depth, format, imageSize, data);
3271}
3272
Corentin Wallez336129f2017-10-17 15:55:40 -04003273bool ValidateGetBufferPointervOES(Context *context,
3274 BufferBinding target,
3275 GLenum pname,
3276 void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003277{
Jamie Madillc3e37312018-11-30 15:25:39 -05003278 if (!context->getExtensions().mapBuffer)
3279 {
3280 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3281 return false;
3282 }
3283
Geoff Lang496c02d2016-10-20 11:38:11 -07003284 return ValidateGetBufferPointervBase(context, target, pname, nullptr, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003285}
3286
Corentin Wallez336129f2017-10-17 15:55:40 -04003287bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003288{
3289 if (!context->getExtensions().mapBuffer)
3290 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003291 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003292 return false;
3293 }
3294
Corentin Walleze4477002017-12-01 14:39:58 -05003295 if (!context->isValidBufferBinding(target))
Olli Etuaho4f667482016-03-30 15:56:35 +03003296 {
Jamie Madille0472f32018-11-27 16:32:45 -05003297 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Olli Etuaho4f667482016-03-30 15:56:35 +03003298 return false;
3299 }
3300
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003301 Buffer *buffer = context->getState().getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003302
3303 if (buffer == nullptr)
3304 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003305 context->validationError(GL_INVALID_OPERATION, kBufferNotMappable);
Olli Etuaho4f667482016-03-30 15:56:35 +03003306 return false;
3307 }
3308
3309 if (access != GL_WRITE_ONLY_OES)
3310 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003311 context->validationError(GL_INVALID_ENUM, kInvalidAccessBits);
Olli Etuaho4f667482016-03-30 15:56:35 +03003312 return false;
3313 }
3314
3315 if (buffer->isMapped())
3316 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003317 context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped);
Olli Etuaho4f667482016-03-30 15:56:35 +03003318 return false;
3319 }
3320
Geoff Lang79f71042017-08-14 16:43:43 -04003321 return ValidateMapBufferBase(context, target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003322}
3323
Corentin Wallez336129f2017-10-17 15:55:40 -04003324bool ValidateUnmapBufferOES(Context *context, BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003325{
3326 if (!context->getExtensions().mapBuffer)
3327 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003328 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003329 return false;
3330 }
3331
3332 return ValidateUnmapBufferBase(context, target);
3333}
3334
3335bool ValidateMapBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003336 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003337 GLintptr offset,
3338 GLsizeiptr length,
3339 GLbitfield access)
3340{
3341 if (!context->getExtensions().mapBufferRange)
3342 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003343 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003344 return false;
3345 }
3346
3347 return ValidateMapBufferRangeBase(context, target, offset, length, access);
3348}
3349
Michael Spang7a8c3e52019-04-03 14:49:57 -04003350bool ValidateBufferStorageMemEXT(Context *context,
3351 TextureType target,
3352 GLsizeiptr size,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003353 MemoryObjectID memory,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003354 GLuint64 offset)
3355{
3356 if (!context->getExtensions().memoryObject)
3357 {
3358 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3359 return false;
3360 }
3361
3362 UNIMPLEMENTED();
3363 return false;
3364}
3365
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003366bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, MemoryObjectID *memoryObjects)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003367{
3368 if (!context->getExtensions().memoryObject)
3369 {
3370 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3371 return false;
3372 }
3373
Michael Spangfb201c52019-04-03 14:57:35 -04003374 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003375}
3376
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003377bool ValidateDeleteMemoryObjectsEXT(Context *context,
3378 GLsizei n,
3379 const MemoryObjectID *memoryObjects)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003380{
3381 if (!context->getExtensions().memoryObject)
3382 {
3383 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3384 return false;
3385 }
3386
Michael Spangfb201c52019-04-03 14:57:35 -04003387 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003388}
3389
3390bool ValidateGetMemoryObjectParameterivEXT(Context *context,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003391 MemoryObjectID memoryObject,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003392 GLenum pname,
3393 GLint *params)
3394{
3395 if (!context->getExtensions().memoryObject)
3396 {
3397 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3398 return false;
3399 }
3400
3401 UNIMPLEMENTED();
3402 return false;
3403}
3404
3405bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data)
3406{
3407 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3408 {
3409 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3410 return false;
3411 }
3412
3413 UNIMPLEMENTED();
3414 return false;
3415}
3416
3417bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data)
3418{
3419 if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
3420 {
3421 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3422 return false;
3423 }
3424
3425 UNIMPLEMENTED();
3426 return false;
3427}
3428
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003429bool ValidateIsMemoryObjectEXT(Context *context, MemoryObjectID memoryObject)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003430{
3431 if (!context->getExtensions().memoryObject)
3432 {
3433 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3434 return false;
3435 }
3436
Michael Spangfb201c52019-04-03 14:57:35 -04003437 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003438}
3439
3440bool ValidateMemoryObjectParameterivEXT(Context *context,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003441 MemoryObjectID memoryObject,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003442 GLenum pname,
3443 const GLint *params)
3444{
3445 if (!context->getExtensions().memoryObject)
3446 {
3447 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3448 return false;
3449 }
3450
3451 UNIMPLEMENTED();
3452 return false;
3453}
3454
3455bool ValidateTexStorageMem2DEXT(Context *context,
3456 TextureType target,
3457 GLsizei levels,
3458 GLenum internalFormat,
3459 GLsizei width,
3460 GLsizei height,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003461 MemoryObjectID memory,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003462 GLuint64 offset)
3463{
3464 if (!context->getExtensions().memoryObject)
3465 {
3466 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3467 return false;
3468 }
3469
Michael Spangf02a7672019-04-09 18:45:23 -04003470 if (context->getClientMajorVersion() < 3)
3471 {
3472 return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width,
3473 height);
3474 }
3475
3476 ASSERT(context->getClientMajorVersion() >= 3);
3477 return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height,
3478 1);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003479}
3480
3481bool ValidateTexStorageMem3DEXT(Context *context,
3482 TextureType target,
3483 GLsizei levels,
3484 GLenum internalFormat,
3485 GLsizei width,
3486 GLsizei height,
3487 GLsizei depth,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003488 MemoryObjectID memory,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003489 GLuint64 offset)
3490{
3491 if (!context->getExtensions().memoryObject)
3492 {
3493 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3494 return false;
3495 }
3496
3497 UNIMPLEMENTED();
3498 return false;
3499}
3500
Michael Spang9de3ddb2019-04-03 16:23:40 -04003501bool ValidateImportMemoryFdEXT(Context *context,
Jiacheng Lu9deb3bf2019-08-23 15:57:50 -06003502 MemoryObjectID memory,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003503 GLuint64 size,
Michael Spange0da9ce2019-04-16 14:34:51 -04003504 HandleType handleType,
Michael Spang9de3ddb2019-04-03 16:23:40 -04003505 GLint fd)
3506{
3507 if (!context->getExtensions().memoryObjectFd)
3508 {
3509 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3510 return false;
3511 }
3512
Michael Spang3b2c6bf2019-04-16 17:19:50 -04003513 switch (handleType)
3514 {
3515 case HandleType::OpaqueFd:
3516 break;
3517 default:
3518 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3519 return false;
3520 }
3521
3522 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003523}
3524
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003525bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const SemaphoreID *semaphores)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003526{
3527 if (!context->getExtensions().semaphore)
3528 {
3529 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3530 return false;
3531 }
3532
Michael Spang5093ba62019-05-14 17:36:36 -04003533 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003534}
3535
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003536bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, SemaphoreID *semaphores)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003537{
3538 if (!context->getExtensions().semaphore)
3539 {
3540 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3541 return false;
3542 }
3543
Michael Spang5093ba62019-05-14 17:36:36 -04003544 return ValidateGenOrDelete(context, n);
Michael Spang7a8c3e52019-04-03 14:49:57 -04003545}
3546
3547bool ValidateGetSemaphoreParameterui64vEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003548 SemaphoreID semaphore,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003549 GLenum pname,
3550 GLuint64 *params)
3551{
3552 if (!context->getExtensions().semaphore)
3553 {
3554 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3555 return false;
3556 }
3557
3558 UNIMPLEMENTED();
3559 return false;
3560}
3561
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003562bool ValidateIsSemaphoreEXT(Context *context, SemaphoreID semaphore)
Michael Spang7a8c3e52019-04-03 14:49:57 -04003563{
3564 if (!context->getExtensions().semaphore)
3565 {
3566 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3567 return false;
3568 }
3569
Michael Spang5093ba62019-05-14 17:36:36 -04003570 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003571}
3572
3573bool ValidateSemaphoreParameterui64vEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003574 SemaphoreID semaphore,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003575 GLenum pname,
3576 const GLuint64 *params)
3577{
3578 if (!context->getExtensions().semaphore)
3579 {
3580 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3581 return false;
3582 }
3583
3584 UNIMPLEMENTED();
3585 return false;
3586}
3587
3588bool ValidateSignalSemaphoreEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003589 SemaphoreID semaphore,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003590 GLuint numBufferBarriers,
Jamie Madill3b3fe832019-08-06 17:44:12 -04003591 const BufferID *buffers,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003592 GLuint numTextureBarriers,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04003593 const TextureID *textures,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003594 const GLenum *dstLayouts)
3595{
3596 if (!context->getExtensions().semaphore)
3597 {
3598 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3599 return false;
3600 }
3601
Michael Spangab6a59b2019-05-21 21:26:26 -04003602 for (GLuint i = 0; i < numTextureBarriers; ++i)
3603 {
3604 if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i])))
3605 {
3606 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3607 return false;
3608 }
3609 }
3610
3611 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003612}
3613
3614bool ValidateWaitSemaphoreEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003615 SemaphoreID semaphore,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003616 GLuint numBufferBarriers,
Jamie Madill3b3fe832019-08-06 17:44:12 -04003617 const BufferID *buffers,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003618 GLuint numTextureBarriers,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04003619 const TextureID *textures,
Michael Spang7a8c3e52019-04-03 14:49:57 -04003620 const GLenum *srcLayouts)
3621{
3622 if (!context->getExtensions().semaphore)
3623 {
3624 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3625 return false;
3626 }
3627
Michael Spangab6a59b2019-05-21 21:26:26 -04003628 for (GLuint i = 0; i < numTextureBarriers; ++i)
3629 {
3630 if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i])))
3631 {
3632 context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
3633 return false;
3634 }
3635 }
3636
3637 return true;
Michael Spang7a8c3e52019-04-03 14:49:57 -04003638}
3639
Michael Spange0da9ce2019-04-16 14:34:51 -04003640bool ValidateImportSemaphoreFdEXT(Context *context,
Jiacheng Luf0640bc2019-08-23 10:26:25 -06003641 SemaphoreID semaphore,
Michael Spange0da9ce2019-04-16 14:34:51 -04003642 HandleType handleType,
3643 GLint fd)
Michael Spang9de3ddb2019-04-03 16:23:40 -04003644{
3645 if (!context->getExtensions().semaphoreFd)
3646 {
3647 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
3648 return false;
3649 }
3650
Michael Spang6bb193c2019-05-22 16:32:21 -04003651 switch (handleType)
3652 {
3653 case HandleType::OpaqueFd:
3654 break;
3655 default:
3656 context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
3657 return false;
3658 }
3659
3660 return true;
Michael Spang9de3ddb2019-04-03 16:23:40 -04003661}
3662
Corentin Wallez336129f2017-10-17 15:55:40 -04003663bool ValidateMapBufferBase(Context *context, BufferBinding target)
Geoff Lang79f71042017-08-14 16:43:43 -04003664{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003665 Buffer *buffer = context->getState().getTargetBuffer(target);
Geoff Lang79f71042017-08-14 16:43:43 -04003666 ASSERT(buffer != nullptr);
3667
3668 // Check if this buffer is currently being used as a transform feedback output buffer
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003669 if (context->getState().isTransformFeedbackActive())
Geoff Lang79f71042017-08-14 16:43:43 -04003670 {
Shahbaz Youssefi8af6c6f2019-06-18 15:43:44 -04003671 TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
Geoff Lang79f71042017-08-14 16:43:43 -04003672 for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++)
3673 {
3674 const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i);
3675 if (transformFeedbackBuffer.get() == buffer)
3676 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003677 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
Geoff Lang79f71042017-08-14 16:43:43 -04003678 return false;
3679 }
3680 }
3681 }
3682
James Darpiniane8a93c62018-01-04 18:02:24 -08003683 if (context->getExtensions().webglCompatibility &&
3684 buffer->isBoundForTransformFeedbackAndOtherUse())
3685 {
Jamie Madille0472f32018-11-27 16:32:45 -05003686 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08003687 return false;
3688 }
3689
Geoff Lang79f71042017-08-14 16:43:43 -04003690 return true;
3691}
3692
Olli Etuaho4f667482016-03-30 15:56:35 +03003693bool ValidateFlushMappedBufferRangeEXT(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04003694 BufferBinding target,
Olli Etuaho4f667482016-03-30 15:56:35 +03003695 GLintptr offset,
3696 GLsizeiptr length)
3697{
3698 if (!context->getExtensions().mapBufferRange)
3699 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003700 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Olli Etuaho4f667482016-03-30 15:56:35 +03003701 return false;
3702 }
3703
3704 return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
3705}
3706
Geoff Langd8605522016-04-13 10:19:12 -04003707bool ValidateBindUniformLocationCHROMIUM(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06003708 ShaderProgramID program,
Geoff Langd8605522016-04-13 10:19:12 -04003709 GLint location,
3710 const GLchar *name)
3711{
3712 if (!context->getExtensions().bindUniformLocation)
3713 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003714 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langd8605522016-04-13 10:19:12 -04003715 return false;
3716 }
3717
3718 Program *programObject = GetValidProgram(context, program);
3719 if (!programObject)
3720 {
3721 return false;
3722 }
3723
3724 if (location < 0)
3725 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003726 context->validationError(GL_INVALID_VALUE, kNegativeLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003727 return false;
3728 }
3729
3730 const Caps &caps = context->getCaps();
3731 if (static_cast<size_t>(location) >=
3732 (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4)
3733 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003734 context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation);
Geoff Langd8605522016-04-13 10:19:12 -04003735 return false;
3736 }
3737
Geoff Langfc32e8b2017-05-31 14:16:59 -04003738 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
3739 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04003740 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04003741 {
Jamie Madille0472f32018-11-27 16:32:45 -05003742 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04003743 return false;
3744 }
3745
Geoff Langd8605522016-04-13 10:19:12 -04003746 if (strncmp(name, "gl_", 3) == 0)
3747 {
Jamie Madille0472f32018-11-27 16:32:45 -05003748 context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL);
Geoff Langd8605522016-04-13 10:19:12 -04003749 return false;
3750 }
3751
3752 return true;
3753}
3754
Jamie Madille2e406c2016-06-02 13:04:10 -04003755bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03003756{
3757 if (!context->getExtensions().framebufferMixedSamples)
3758 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003759 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänena797e062016-05-12 15:23:40 +03003760 return false;
3761 }
3762 switch (components)
3763 {
3764 case GL_RGB:
3765 case GL_RGBA:
3766 case GL_ALPHA:
3767 case GL_NONE:
3768 break;
3769 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003770 context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents);
Sami Väisänena797e062016-05-12 15:23:40 +03003771 return false;
3772 }
3773
3774 return true;
3775}
3776
Sami Väisänene45e53b2016-05-25 10:36:04 +03003777// CHROMIUM_path_rendering
3778
Jamie Madill007530e2017-12-28 14:27:04 -05003779bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003780{
Jamie Madill007530e2017-12-28 14:27:04 -05003781 if (!ValidateMatrixMode(context, matrixMode))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003782 {
Sami Väisänene45e53b2016-05-25 10:36:04 +03003783 return false;
3784 }
Jamie Madill007530e2017-12-28 14:27:04 -05003785
Sami Väisänene45e53b2016-05-25 10:36:04 +03003786 if (matrix == nullptr)
3787 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003788 context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003789 return false;
3790 }
Jamie Madill007530e2017-12-28 14:27:04 -05003791
Sami Väisänene45e53b2016-05-25 10:36:04 +03003792 return true;
3793}
3794
Jamie Madill007530e2017-12-28 14:27:04 -05003795bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003796{
Jamie Madill007530e2017-12-28 14:27:04 -05003797 return ValidateMatrixMode(context, matrixMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003798}
3799
Jamie Madill007530e2017-12-28 14:27:04 -05003800bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003801{
3802 if (!context->getExtensions().pathRendering)
3803 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003804 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003805 return false;
3806 }
3807
3808 // range = 0 is undefined in NV_path_rendering.
3809 // we add stricter semantic check here and require a non zero positive range.
3810 if (range <= 0)
3811 {
Jamie Madille0472f32018-11-27 16:32:45 -05003812 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003813 return false;
3814 }
3815
3816 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range))
3817 {
Jamie Madille0472f32018-11-27 16:32:45 -05003818 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003819 return false;
3820 }
3821
3822 return true;
3823}
3824
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003825bool ValidateDeletePathsCHROMIUM(Context *context, PathID path, GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003826{
3827 if (!context->getExtensions().pathRendering)
3828 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003829 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003830 return false;
3831 }
3832
3833 // range = 0 is undefined in NV_path_rendering.
3834 // we add stricter semantic check here and require a non zero positive range.
3835 if (range <= 0)
3836 {
Jamie Madille0472f32018-11-27 16:32:45 -05003837 context->validationError(GL_INVALID_VALUE, kInvalidRange);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003838 return false;
3839 }
3840
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003841 angle::CheckedNumeric<std::uint32_t> checkedRange(path.value);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003842 checkedRange += range;
3843
3844 if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid())
3845 {
Jamie Madille0472f32018-11-27 16:32:45 -05003846 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003847 return false;
3848 }
3849 return true;
3850}
3851
Jamie Madill007530e2017-12-28 14:27:04 -05003852bool ValidatePathCommandsCHROMIUM(Context *context,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003853 PathID path,
Jamie Madill007530e2017-12-28 14:27:04 -05003854 GLsizei numCommands,
3855 const GLubyte *commands,
3856 GLsizei numCoords,
3857 GLenum coordType,
3858 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003859{
3860 if (!context->getExtensions().pathRendering)
3861 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003862 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003863 return false;
3864 }
Brandon Jones59770802018-04-02 13:18:42 -07003865 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003866 {
Jamie Madille0472f32018-11-27 16:32:45 -05003867 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003868 return false;
3869 }
3870
3871 if (numCommands < 0)
3872 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003873 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003874 return false;
3875 }
3876 else if (numCommands > 0)
3877 {
3878 if (!commands)
3879 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003880 context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003881 return false;
3882 }
3883 }
3884
3885 if (numCoords < 0)
3886 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003887 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003888 return false;
3889 }
3890 else if (numCoords > 0)
3891 {
3892 if (!coords)
3893 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003894 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003895 return false;
3896 }
3897 }
3898
3899 std::uint32_t coordTypeSize = 0;
3900 switch (coordType)
3901 {
3902 case GL_BYTE:
3903 coordTypeSize = sizeof(GLbyte);
3904 break;
3905
3906 case GL_UNSIGNED_BYTE:
3907 coordTypeSize = sizeof(GLubyte);
3908 break;
3909
3910 case GL_SHORT:
3911 coordTypeSize = sizeof(GLshort);
3912 break;
3913
3914 case GL_UNSIGNED_SHORT:
3915 coordTypeSize = sizeof(GLushort);
3916 break;
3917
3918 case GL_FLOAT:
3919 coordTypeSize = sizeof(GLfloat);
3920 break;
3921
3922 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003923 context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003924 return false;
3925 }
3926
3927 angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands);
3928 checkedSize += (coordTypeSize * numCoords);
3929 if (!checkedSize.IsValid())
3930 {
Jamie Madille0472f32018-11-27 16:32:45 -05003931 context->validationError(GL_INVALID_OPERATION, kIntegerOverflow);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003932 return false;
3933 }
3934
3935 // early return skips command data validation when it doesn't exist.
3936 if (!commands)
3937 return true;
3938
3939 GLsizei expectedNumCoords = 0;
3940 for (GLsizei i = 0; i < numCommands; ++i)
3941 {
3942 switch (commands[i])
3943 {
3944 case GL_CLOSE_PATH_CHROMIUM: // no coordinates.
3945 break;
3946 case GL_MOVE_TO_CHROMIUM:
3947 case GL_LINE_TO_CHROMIUM:
3948 expectedNumCoords += 2;
3949 break;
3950 case GL_QUADRATIC_CURVE_TO_CHROMIUM:
3951 expectedNumCoords += 4;
3952 break;
3953 case GL_CUBIC_CURVE_TO_CHROMIUM:
3954 expectedNumCoords += 6;
3955 break;
3956 case GL_CONIC_CURVE_TO_CHROMIUM:
3957 expectedNumCoords += 5;
3958 break;
3959 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05003960 context->validationError(GL_INVALID_ENUM, kInvalidPathCommand);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003961 return false;
3962 }
3963 }
Jamie Madillc3e37312018-11-30 15:25:39 -05003964
Sami Väisänene45e53b2016-05-25 10:36:04 +03003965 if (expectedNumCoords != numCoords)
3966 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003967 context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003968 return false;
3969 }
3970
3971 return true;
3972}
3973
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06003974bool ValidatePathParameterfCHROMIUM(Context *context, PathID path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03003975{
3976 if (!context->getExtensions().pathRendering)
3977 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003978 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003979 return false;
3980 }
Brandon Jones59770802018-04-02 13:18:42 -07003981 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03003982 {
Jamie Madille0472f32018-11-27 16:32:45 -05003983 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003984 return false;
3985 }
3986
3987 switch (pname)
3988 {
3989 case GL_PATH_STROKE_WIDTH_CHROMIUM:
3990 if (value < 0.0f)
3991 {
Jamie Madillc3e37312018-11-30 15:25:39 -05003992 context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth);
Sami Väisänene45e53b2016-05-25 10:36:04 +03003993 return false;
3994 }
3995 break;
3996 case GL_PATH_END_CAPS_CHROMIUM:
3997 switch (static_cast<GLenum>(value))
3998 {
3999 case GL_FLAT_CHROMIUM:
4000 case GL_SQUARE_CHROMIUM:
4001 case GL_ROUND_CHROMIUM:
4002 break;
4003 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004004 context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004005 return false;
4006 }
4007 break;
4008 case GL_PATH_JOIN_STYLE_CHROMIUM:
4009 switch (static_cast<GLenum>(value))
4010 {
4011 case GL_MITER_REVERT_CHROMIUM:
4012 case GL_BEVEL_CHROMIUM:
4013 case GL_ROUND_CHROMIUM:
4014 break;
4015 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004016 context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004017 return false;
4018 }
Nico Weber41b072b2018-02-09 10:01:32 -05004019 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03004020 case GL_PATH_MITER_LIMIT_CHROMIUM:
4021 if (value < 0.0f)
4022 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004023 context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004024 return false;
4025 }
4026 break;
4027
4028 case GL_PATH_STROKE_BOUND_CHROMIUM:
4029 // no errors, only clamping.
4030 break;
4031
4032 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004033 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004034 return false;
4035 }
4036 return true;
4037}
4038
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004039bool ValidatePathParameteriCHROMIUM(Context *context, PathID path, GLenum pname, GLint value)
Jamie Madill007530e2017-12-28 14:27:04 -05004040{
4041 // TODO(jmadill): Use proper clamping cast.
4042 return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value));
4043}
4044
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004045bool ValidateGetPathParameterfvCHROMIUM(Context *context, PathID path, GLenum pname, GLfloat *value)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004046{
4047 if (!context->getExtensions().pathRendering)
4048 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004049 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004050 return false;
4051 }
4052
Brandon Jones59770802018-04-02 13:18:42 -07004053 if (!context->isPathGenerated(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004054 {
Jamie Madille0472f32018-11-27 16:32:45 -05004055 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004056 return false;
4057 }
Jamie Madillc3e37312018-11-30 15:25:39 -05004058
Sami Väisänene45e53b2016-05-25 10:36:04 +03004059 if (!value)
4060 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004061 context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004062 return false;
4063 }
4064
4065 switch (pname)
4066 {
4067 case GL_PATH_STROKE_WIDTH_CHROMIUM:
4068 case GL_PATH_END_CAPS_CHROMIUM:
4069 case GL_PATH_JOIN_STYLE_CHROMIUM:
4070 case GL_PATH_MITER_LIMIT_CHROMIUM:
4071 case GL_PATH_STROKE_BOUND_CHROMIUM:
4072 break;
4073
4074 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004075 context->validationError(GL_INVALID_ENUM, kInvalidPathParameter);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004076 return false;
4077 }
4078
4079 return true;
4080}
4081
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004082bool ValidateGetPathParameterivCHROMIUM(Context *context, PathID path, GLenum pname, GLint *value)
Jamie Madill007530e2017-12-28 14:27:04 -05004083{
4084 return ValidateGetPathParameterfvCHROMIUM(context, path, pname,
4085 reinterpret_cast<GLfloat *>(value));
4086}
4087
4088bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004089{
4090 if (!context->getExtensions().pathRendering)
4091 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004092 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004093 return false;
4094 }
4095
4096 switch (func)
4097 {
4098 case GL_NEVER:
4099 case GL_ALWAYS:
4100 case GL_LESS:
4101 case GL_LEQUAL:
4102 case GL_EQUAL:
4103 case GL_GEQUAL:
4104 case GL_GREATER:
4105 case GL_NOTEQUAL:
4106 break;
4107 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004108 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004109 return false;
4110 }
4111
4112 return true;
4113}
4114
4115// Note that the spec specifies that for the path drawing commands
4116// if the path object is not an existing path object the command
4117// does nothing and no error is generated.
4118// However if the path object exists but has not been specified any
4119// commands then an error is generated.
4120
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004121bool ValidateStencilFillPathCHROMIUM(Context *context, PathID path, GLenum fillMode, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004122{
4123 if (!context->getExtensions().pathRendering)
4124 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004125 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004126 return false;
4127 }
Brandon Jones59770802018-04-02 13:18:42 -07004128 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004129 {
Jamie Madille0472f32018-11-27 16:32:45 -05004130 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004131 return false;
4132 }
4133
4134 switch (fillMode)
4135 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004136 case GL_INVERT:
Sami Väisänene45e53b2016-05-25 10:36:04 +03004137 case GL_COUNT_UP_CHROMIUM:
4138 case GL_COUNT_DOWN_CHROMIUM:
4139 break;
4140 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004141 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004142 return false;
4143 }
4144
4145 if (!isPow2(mask + 1))
4146 {
Jamie Madille0472f32018-11-27 16:32:45 -05004147 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004148 return false;
4149 }
4150
4151 return true;
4152}
4153
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004154bool ValidateStencilStrokePathCHROMIUM(Context *context, PathID path, GLint reference, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004155{
4156 if (!context->getExtensions().pathRendering)
4157 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004158 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004159 return false;
4160 }
Jamie Madillc3e37312018-11-30 15:25:39 -05004161
Brandon Jones59770802018-04-02 13:18:42 -07004162 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004163 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004164 context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004165 return false;
4166 }
4167
4168 return true;
4169}
4170
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004171bool ValidateCoverPathCHROMIUM(Context *context, PathID path, GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004172{
4173 if (!context->getExtensions().pathRendering)
4174 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004175 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004176 return false;
4177 }
Brandon Jones59770802018-04-02 13:18:42 -07004178 if (context->isPathGenerated(path) && !context->isPath(path))
Sami Väisänene45e53b2016-05-25 10:36:04 +03004179 {
Jamie Madille0472f32018-11-27 16:32:45 -05004180 context->validationError(GL_INVALID_OPERATION, kNoSuchPath);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004181 return false;
4182 }
4183
4184 switch (coverMode)
4185 {
4186 case GL_CONVEX_HULL_CHROMIUM:
4187 case GL_BOUNDING_BOX_CHROMIUM:
4188 break;
4189 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004190 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004191 return false;
4192 }
4193 return true;
4194}
4195
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004196bool ValidateCoverFillPathCHROMIUM(Context *context, PathID path, GLenum coverMode)
Jamie Madill778bf092018-11-14 09:54:36 -05004197{
4198 return ValidateCoverPathCHROMIUM(context, path, coverMode);
4199}
4200
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004201bool ValidateCoverStrokePathCHROMIUM(Context *context, PathID path, GLenum coverMode)
Jamie Madill778bf092018-11-14 09:54:36 -05004202{
4203 return ValidateCoverPathCHROMIUM(context, path, coverMode);
4204}
4205
Jamie Madill007530e2017-12-28 14:27:04 -05004206bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004207 PathID path,
Jamie Madill007530e2017-12-28 14:27:04 -05004208 GLenum fillMode,
4209 GLuint mask,
4210 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004211{
Jamie Madill007530e2017-12-28 14:27:04 -05004212 return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) &&
4213 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004214}
4215
Jamie Madill007530e2017-12-28 14:27:04 -05004216bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004217 PathID path,
Jamie Madill007530e2017-12-28 14:27:04 -05004218 GLint reference,
4219 GLuint mask,
4220 GLenum coverMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004221{
Jamie Madill007530e2017-12-28 14:27:04 -05004222 return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) &&
4223 ValidateCoverPathCHROMIUM(context, path, coverMode);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004224}
4225
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004226bool ValidateIsPathCHROMIUM(Context *context, PathID path)
Sami Väisänene45e53b2016-05-25 10:36:04 +03004227{
4228 if (!context->getExtensions().pathRendering)
4229 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004230 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänene45e53b2016-05-25 10:36:04 +03004231 return false;
4232 }
4233 return true;
4234}
4235
Jamie Madill007530e2017-12-28 14:27:04 -05004236bool ValidateCoverFillPathInstancedCHROMIUM(Context *context,
4237 GLsizei numPaths,
4238 GLenum pathNameType,
4239 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004240 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004241 GLenum coverMode,
4242 GLenum transformType,
4243 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004244{
4245 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4246 transformType, transformValues))
4247 return false;
4248
4249 switch (coverMode)
4250 {
4251 case GL_CONVEX_HULL_CHROMIUM:
4252 case GL_BOUNDING_BOX_CHROMIUM:
4253 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4254 break;
4255 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004256 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004257 return false;
4258 }
4259
4260 return true;
4261}
4262
Jamie Madill007530e2017-12-28 14:27:04 -05004263bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context,
4264 GLsizei numPaths,
4265 GLenum pathNameType,
4266 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004267 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004268 GLenum coverMode,
4269 GLenum transformType,
4270 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004271{
4272 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4273 transformType, transformValues))
4274 return false;
4275
4276 switch (coverMode)
4277 {
4278 case GL_CONVEX_HULL_CHROMIUM:
4279 case GL_BOUNDING_BOX_CHROMIUM:
4280 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4281 break;
4282 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004283 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004284 return false;
4285 }
4286
4287 return true;
4288}
4289
Jamie Madill007530e2017-12-28 14:27:04 -05004290bool ValidateStencilFillPathInstancedCHROMIUM(Context *context,
4291 GLsizei numPaths,
4292 GLenum pathNameType,
4293 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004294 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004295 GLenum fillMode,
4296 GLuint mask,
4297 GLenum transformType,
4298 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004299{
4300
4301 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4302 transformType, transformValues))
4303 return false;
4304
4305 switch (fillMode)
4306 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004307 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004308 case GL_COUNT_UP_CHROMIUM:
4309 case GL_COUNT_DOWN_CHROMIUM:
4310 break;
4311 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004312 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004313 return false;
4314 }
4315 if (!isPow2(mask + 1))
4316 {
Jamie Madille0472f32018-11-27 16:32:45 -05004317 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004318 return false;
4319 }
4320 return true;
4321}
4322
Jamie Madill007530e2017-12-28 14:27:04 -05004323bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context,
4324 GLsizei numPaths,
4325 GLenum pathNameType,
4326 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004327 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004328 GLint reference,
4329 GLuint mask,
4330 GLenum transformType,
4331 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004332{
4333 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4334 transformType, transformValues))
4335 return false;
4336
4337 // no more validation here.
4338
4339 return true;
4340}
4341
Jamie Madill007530e2017-12-28 14:27:04 -05004342bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context,
4343 GLsizei numPaths,
4344 GLenum pathNameType,
4345 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004346 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004347 GLenum fillMode,
4348 GLuint mask,
4349 GLenum coverMode,
4350 GLenum transformType,
4351 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004352{
4353 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4354 transformType, transformValues))
4355 return false;
4356
4357 switch (coverMode)
4358 {
4359 case GL_CONVEX_HULL_CHROMIUM:
4360 case GL_BOUNDING_BOX_CHROMIUM:
4361 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4362 break;
4363 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004364 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004365 return false;
4366 }
4367
4368 switch (fillMode)
4369 {
Chris Daltona9dfb3b2019-06-26 18:36:10 -06004370 case GL_INVERT:
Sami Väisänend59ca052016-06-21 16:10:00 +03004371 case GL_COUNT_UP_CHROMIUM:
4372 case GL_COUNT_DOWN_CHROMIUM:
4373 break;
4374 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004375 context->validationError(GL_INVALID_ENUM, kInvalidFillMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004376 return false;
4377 }
4378 if (!isPow2(mask + 1))
4379 {
Jamie Madille0472f32018-11-27 16:32:45 -05004380 context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask);
Sami Väisänend59ca052016-06-21 16:10:00 +03004381 return false;
4382 }
4383
4384 return true;
4385}
4386
Jamie Madill007530e2017-12-28 14:27:04 -05004387bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context,
4388 GLsizei numPaths,
4389 GLenum pathNameType,
4390 const void *paths,
Jiacheng Lu7b5744f2019-08-22 16:26:35 -06004391 PathID pathBase,
Jamie Madill007530e2017-12-28 14:27:04 -05004392 GLint reference,
4393 GLuint mask,
4394 GLenum coverMode,
4395 GLenum transformType,
4396 const GLfloat *transformValues)
Sami Väisänend59ca052016-06-21 16:10:00 +03004397{
4398 if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase,
4399 transformType, transformValues))
4400 return false;
4401
4402 switch (coverMode)
4403 {
4404 case GL_CONVEX_HULL_CHROMIUM:
4405 case GL_BOUNDING_BOX_CHROMIUM:
4406 case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM:
4407 break;
4408 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004409 context->validationError(GL_INVALID_ENUM, kInvalidCoverMode);
Sami Väisänend59ca052016-06-21 16:10:00 +03004410 return false;
4411 }
4412
4413 return true;
4414}
4415
Jamie Madill007530e2017-12-28 14:27:04 -05004416bool ValidateBindFragmentInputLocationCHROMIUM(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06004417 ShaderProgramID program,
Jamie Madill007530e2017-12-28 14:27:04 -05004418 GLint location,
4419 const GLchar *name)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004420{
4421 if (!context->getExtensions().pathRendering)
4422 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004423 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004424 return false;
4425 }
4426
4427 const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4;
4428 if (location >= MaxLocation)
4429 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004430 context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004431 return false;
4432 }
4433
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004434 const auto *programObject = context->getProgramNoResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004435 if (!programObject)
4436 {
Jamie Madille0472f32018-11-27 16:32:45 -05004437 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004438 return false;
4439 }
4440
4441 if (!name)
4442 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004443 context->validationError(GL_INVALID_VALUE, kMissingName);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004444 return false;
4445 }
4446
4447 if (angle::BeginsWith(name, "gl_"))
4448 {
Jamie Madille0472f32018-11-27 16:32:45 -05004449 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004450 return false;
4451 }
4452
4453 return true;
4454}
4455
Jamie Madill007530e2017-12-28 14:27:04 -05004456bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06004457 ShaderProgramID program,
Jamie Madill007530e2017-12-28 14:27:04 -05004458 GLint location,
4459 GLenum genMode,
4460 GLint components,
4461 const GLfloat *coeffs)
Sami Väisänen46eaa942016-06-29 10:26:37 +03004462{
4463 if (!context->getExtensions().pathRendering)
4464 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004465 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004466 return false;
4467 }
4468
Jamie Madill44a6fbf2018-10-02 13:38:56 -04004469 const auto *programObject = context->getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004470 if (!programObject || programObject->isFlaggedForDeletion())
4471 {
Jamie Madille0472f32018-11-27 16:32:45 -05004472 context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004473 return false;
4474 }
4475
4476 if (!programObject->isLinked())
4477 {
Jamie Madille0472f32018-11-27 16:32:45 -05004478 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004479 return false;
4480 }
4481
4482 switch (genMode)
4483 {
4484 case GL_NONE:
4485 if (components != 0)
4486 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004487 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004488 return false;
4489 }
4490 break;
4491
4492 case GL_OBJECT_LINEAR_CHROMIUM:
4493 case GL_EYE_LINEAR_CHROMIUM:
4494 case GL_CONSTANT_CHROMIUM:
4495 if (components < 1 || components > 4)
4496 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004497 context->validationError(GL_INVALID_VALUE, kInvalidComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004498 return false;
4499 }
4500 if (!coeffs)
4501 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004502 context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004503 return false;
4504 }
4505 break;
4506
4507 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004508 context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004509 return false;
4510 }
4511
4512 // If the location is -1 then the command is silently ignored
4513 // and no further validation is needed.
4514 if (location == -1)
4515 return true;
4516
jchen103fd614d2018-08-13 12:21:58 +08004517 const auto &binding = programObject->getFragmentInputBindingInfo(location);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004518
4519 if (!binding.valid)
4520 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004521 context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004522 return false;
4523 }
4524
4525 if (binding.type != GL_NONE)
4526 {
4527 GLint expectedComponents = 0;
4528 switch (binding.type)
4529 {
4530 case GL_FLOAT:
4531 expectedComponents = 1;
4532 break;
4533 case GL_FLOAT_VEC2:
4534 expectedComponents = 2;
4535 break;
4536 case GL_FLOAT_VEC3:
4537 expectedComponents = 3;
4538 break;
4539 case GL_FLOAT_VEC4:
4540 expectedComponents = 4;
4541 break;
4542 default:
Jamie Madillc3e37312018-11-30 15:25:39 -05004543 context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004544 return false;
4545 }
4546 if (expectedComponents != components && genMode != GL_NONE)
4547 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004548 context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents);
Sami Väisänen46eaa942016-06-29 10:26:37 +03004549 return false;
4550 }
4551 }
4552 return true;
4553}
4554
Geoff Lang97073d12016-04-20 10:42:34 -07004555bool ValidateCopyTextureCHROMIUM(Context *context,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004556 TextureID sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004557 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004558 TextureTarget destTarget,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004559 TextureID destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004560 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004561 GLint internalFormat,
4562 GLenum destType,
4563 GLboolean unpackFlipY,
4564 GLboolean unpackPremultiplyAlpha,
4565 GLboolean unpackUnmultiplyAlpha)
4566{
4567 if (!context->getExtensions().copyTexture)
4568 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004569 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004570 return false;
4571 }
4572
Geoff Lang4f0e0032017-05-01 16:04:35 -04004573 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004574 if (source == nullptr)
4575 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004576 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004577 return false;
4578 }
4579
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004580 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004581 {
Jamie Madille0472f32018-11-27 16:32:45 -05004582 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004583 return false;
4584 }
4585
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004586 TextureType sourceType = source->getType();
4587 ASSERT(sourceType != TextureType::CubeMap);
4588 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004589
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004590 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004591 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004592 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004593 return false;
4594 }
4595
Geoff Lang4f0e0032017-05-01 16:04:35 -04004596 GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel));
4597 GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel));
4598 if (sourceWidth == 0 || sourceHeight == 0)
4599 {
Jamie Madille0472f32018-11-27 16:32:45 -05004600 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004601 return false;
4602 }
4603
4604 const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info;
4605 if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004606 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004607 context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004608 return false;
4609 }
4610
Geoff Lang63458a32017-10-30 15:16:53 -04004611 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4612 {
Jamie Madille0472f32018-11-27 16:32:45 -05004613 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004614 return false;
4615 }
4616
Geoff Lang4f0e0032017-05-01 16:04:35 -04004617 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004618 if (dest == nullptr)
4619 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004620 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004621 return false;
4622 }
4623
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004624 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004625 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004626 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004627 return false;
4628 }
4629
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004630 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth,
Brandon Jones28783792018-03-05 09:37:32 -08004631 sourceHeight, false))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004632 {
Jamie Madille0472f32018-11-27 16:32:45 -05004633 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004634 return false;
4635 }
4636
Geoff Lang97073d12016-04-20 10:42:34 -07004637 if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType))
4638 {
Geoff Lang97073d12016-04-20 10:42:34 -07004639 return false;
4640 }
4641
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004642 if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight)
Geoff Lang4f0e0032017-05-01 16:04:35 -04004643 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004644 context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004645 return false;
4646 }
4647
Geoff Lang97073d12016-04-20 10:42:34 -07004648 if (dest->getImmutableFormat())
4649 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004650 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang97073d12016-04-20 10:42:34 -07004651 return false;
4652 }
4653
4654 return true;
4655}
4656
4657bool ValidateCopySubTextureCHROMIUM(Context *context,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004658 TextureID sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04004659 GLint sourceLevel,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004660 TextureTarget destTarget,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004661 TextureID destId,
Geoff Langfc72a072017-03-24 14:52:39 -04004662 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07004663 GLint xoffset,
4664 GLint yoffset,
4665 GLint x,
4666 GLint y,
4667 GLsizei width,
4668 GLsizei height,
4669 GLboolean unpackFlipY,
4670 GLboolean unpackPremultiplyAlpha,
4671 GLboolean unpackUnmultiplyAlpha)
4672{
4673 if (!context->getExtensions().copyTexture)
4674 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004675 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang97073d12016-04-20 10:42:34 -07004676 return false;
4677 }
4678
Geoff Lang4f0e0032017-05-01 16:04:35 -04004679 const Texture *source = context->getTexture(sourceId);
Geoff Lang97073d12016-04-20 10:42:34 -07004680 if (source == nullptr)
4681 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004682 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004683 return false;
4684 }
4685
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004686 if (!IsValidCopyTextureSourceTarget(context, source->getType()))
Geoff Lang97073d12016-04-20 10:42:34 -07004687 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004688 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004689 return false;
4690 }
4691
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004692 TextureType sourceType = source->getType();
4693 ASSERT(sourceType != TextureType::CubeMap);
4694 TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004695
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004696 if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel))
Geoff Lang4f0e0032017-05-01 16:04:35 -04004697 {
Jamie Madille0472f32018-11-27 16:32:45 -05004698 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004699 return false;
4700 }
4701
4702 if (source->getWidth(sourceTarget, sourceLevel) == 0 ||
4703 source->getHeight(sourceTarget, sourceLevel) == 0)
Geoff Lang97073d12016-04-20 10:42:34 -07004704 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004705 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004706 return false;
4707 }
4708
4709 if (x < 0 || y < 0)
4710 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004711 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004712 return false;
4713 }
4714
4715 if (width < 0 || height < 0)
4716 {
Jamie Madille0472f32018-11-27 16:32:45 -05004717 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Geoff Lang97073d12016-04-20 10:42:34 -07004718 return false;
4719 }
4720
Geoff Lang4f0e0032017-05-01 16:04:35 -04004721 if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) ||
4722 static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004723 {
Jamie Madille0472f32018-11-27 16:32:45 -05004724 context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall);
Geoff Lang97073d12016-04-20 10:42:34 -07004725 return false;
4726 }
4727
Geoff Lang4f0e0032017-05-01 16:04:35 -04004728 const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel);
4729 if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004730 {
Jamie Madille0472f32018-11-27 16:32:45 -05004731 context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat);
Geoff Lang97073d12016-04-20 10:42:34 -07004732 return false;
4733 }
4734
Geoff Lang63458a32017-10-30 15:16:53 -04004735 if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget))
4736 {
Jamie Madille0472f32018-11-27 16:32:45 -05004737 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Geoff Lang63458a32017-10-30 15:16:53 -04004738 return false;
4739 }
4740
Geoff Lang4f0e0032017-05-01 16:04:35 -04004741 const Texture *dest = context->getTexture(destId);
Geoff Lang97073d12016-04-20 10:42:34 -07004742 if (dest == nullptr)
4743 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004744 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang97073d12016-04-20 10:42:34 -07004745 return false;
4746 }
4747
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004748 if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget))
Geoff Lang97073d12016-04-20 10:42:34 -07004749 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004750 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang97073d12016-04-20 10:42:34 -07004751 return false;
4752 }
4753
Brandon Jones28783792018-03-05 09:37:32 -08004754 if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height,
4755 true))
Geoff Lang97073d12016-04-20 10:42:34 -07004756 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004757 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Geoff Lang97073d12016-04-20 10:42:34 -07004758 return false;
4759 }
4760
Geoff Lang4f0e0032017-05-01 16:04:35 -04004761 if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0)
4762 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004763 context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined);
Geoff Lang4f0e0032017-05-01 16:04:35 -04004764 return false;
4765 }
4766
4767 const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info;
4768 if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat))
Geoff Lang97073d12016-04-20 10:42:34 -07004769 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004770 context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination);
Geoff Lang97073d12016-04-20 10:42:34 -07004771 return false;
4772 }
4773
4774 if (xoffset < 0 || yoffset < 0)
4775 {
Jamie Madille0472f32018-11-27 16:32:45 -05004776 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Geoff Lang97073d12016-04-20 10:42:34 -07004777 return false;
4778 }
4779
Geoff Lang4f0e0032017-05-01 16:04:35 -04004780 if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) ||
4781 static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel))
Geoff Lang97073d12016-04-20 10:42:34 -07004782 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004783 context->validationError(GL_INVALID_VALUE, kOffsetOverflow);
Geoff Lang97073d12016-04-20 10:42:34 -07004784 return false;
4785 }
4786
4787 return true;
4788}
4789
Jamie Madill2ab08ed2019-08-12 16:20:21 -04004790bool ValidateCompressedCopyTextureCHROMIUM(Context *context, TextureID sourceId, TextureID destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004791{
4792 if (!context->getExtensions().copyCompressedTexture)
4793 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004794 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Lang47110bf2016-04-20 11:13:22 -07004795 return false;
4796 }
4797
4798 const gl::Texture *source = context->getTexture(sourceId);
4799 if (source == nullptr)
4800 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004801 context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004802 return false;
4803 }
4804
Corentin Wallez99d492c2018-02-27 15:17:10 -05004805 if (source->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004806 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004807 context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004808 return false;
4809 }
4810
Corentin Wallez99d492c2018-02-27 15:17:10 -05004811 if (source->getWidth(TextureTarget::_2D, 0) == 0 ||
4812 source->getHeight(TextureTarget::_2D, 0) == 0)
Geoff Lang47110bf2016-04-20 11:13:22 -07004813 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004814 context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined);
Geoff Lang47110bf2016-04-20 11:13:22 -07004815 return false;
4816 }
4817
Corentin Wallez99d492c2018-02-27 15:17:10 -05004818 const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0);
Geoff Lang47110bf2016-04-20 11:13:22 -07004819 if (!sourceFormat.info->compressed)
4820 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004821 context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed);
Geoff Lang47110bf2016-04-20 11:13:22 -07004822 return false;
4823 }
4824
4825 const gl::Texture *dest = context->getTexture(destId);
4826 if (dest == nullptr)
4827 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004828 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture);
Geoff Lang47110bf2016-04-20 11:13:22 -07004829 return false;
4830 }
4831
Corentin Wallez99d492c2018-02-27 15:17:10 -05004832 if (dest->getType() != TextureType::_2D)
Geoff Lang47110bf2016-04-20 11:13:22 -07004833 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004834 context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType);
Geoff Lang47110bf2016-04-20 11:13:22 -07004835 return false;
4836 }
4837
4838 if (dest->getImmutableFormat())
4839 {
Jamie Madillc3e37312018-11-30 15:25:39 -05004840 context->validationError(GL_INVALID_OPERATION, kDestinationImmutable);
Geoff Lang47110bf2016-04-20 11:13:22 -07004841 return false;
4842 }
4843
4844 return true;
4845}
4846
Jiawei Shao385b3e02018-03-21 09:43:28 +08004847bool ValidateCreateShader(Context *context, ShaderType type)
Martin Radev4c4c8e72016-08-04 12:25:34 +03004848{
4849 switch (type)
4850 {
Jiawei Shao385b3e02018-03-21 09:43:28 +08004851 case ShaderType::Vertex:
4852 case ShaderType::Fragment:
Martin Radev4c4c8e72016-08-04 12:25:34 +03004853 break;
Geoff Langeb66a6e2016-10-31 13:06:12 -04004854
Jiawei Shao385b3e02018-03-21 09:43:28 +08004855 case ShaderType::Compute:
Geoff Langeb66a6e2016-10-31 13:06:12 -04004856 if (context->getClientVersion() < Version(3, 1))
Martin Radev4c4c8e72016-08-04 12:25:34 +03004857 {
Jamie Madille0472f32018-11-27 16:32:45 -05004858 context->validationError(GL_INVALID_ENUM, kES31Required);
Geoff Langeb66a6e2016-10-31 13:06:12 -04004859 return false;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004860 }
Geoff Langeb66a6e2016-10-31 13:06:12 -04004861 break;
4862
Jiawei Shao385b3e02018-03-21 09:43:28 +08004863 case ShaderType::Geometry:
Jiawei Shao89be29a2017-11-06 14:36:45 +08004864 if (!context->getExtensions().geometryShader)
4865 {
Jamie Madille0472f32018-11-27 16:32:45 -05004866 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jiawei Shao89be29a2017-11-06 14:36:45 +08004867 return false;
4868 }
4869 break;
Martin Radev4c4c8e72016-08-04 12:25:34 +03004870 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004871 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Martin Radev4c4c8e72016-08-04 12:25:34 +03004872 return false;
4873 }
Jamie Madill29639852016-09-02 15:00:09 -04004874
4875 return true;
4876}
4877
Jamie Madill5b772312018-03-08 20:28:32 -05004878bool ValidateBufferData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004879 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004880 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004881 const void *data,
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004882 BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004883{
4884 if (size < 0)
4885 {
Jamie Madille0472f32018-11-27 16:32:45 -05004886 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madill29639852016-09-02 15:00:09 -04004887 return false;
4888 }
4889
4890 switch (usage)
4891 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004892 case BufferUsage::StreamDraw:
4893 case BufferUsage::StaticDraw:
4894 case BufferUsage::DynamicDraw:
Jamie Madill29639852016-09-02 15:00:09 -04004895 break;
4896
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004897 case BufferUsage::StreamRead:
4898 case BufferUsage::StaticRead:
4899 case BufferUsage::DynamicRead:
4900 case BufferUsage::StreamCopy:
4901 case BufferUsage::StaticCopy:
4902 case BufferUsage::DynamicCopy:
Jamie Madill29639852016-09-02 15:00:09 -04004903 if (context->getClientMajorVersion() < 3)
4904 {
Jamie Madille0472f32018-11-27 16:32:45 -05004905 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004906 return false;
4907 }
4908 break;
4909
4910 default:
Jamie Madille0472f32018-11-27 16:32:45 -05004911 context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage);
Jamie Madill29639852016-09-02 15:00:09 -04004912 return false;
4913 }
4914
Corentin Walleze4477002017-12-01 14:39:58 -05004915 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004916 {
Jamie Madille0472f32018-11-27 16:32:45 -05004917 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004918 return false;
4919 }
4920
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004921 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004922
4923 if (!buffer)
4924 {
Jamie Madille0472f32018-11-27 16:32:45 -05004925 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004926 return false;
4927 }
4928
James Darpiniane8a93c62018-01-04 18:02:24 -08004929 if (context->getExtensions().webglCompatibility &&
4930 buffer->isBoundForTransformFeedbackAndOtherUse())
4931 {
Jamie Madille0472f32018-11-27 16:32:45 -05004932 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004933 return false;
4934 }
4935
Jamie Madill29639852016-09-02 15:00:09 -04004936 return true;
4937}
4938
Jamie Madill5b772312018-03-08 20:28:32 -05004939bool ValidateBufferSubData(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04004940 BufferBinding target,
Jamie Madill29639852016-09-02 15:00:09 -04004941 GLintptr offset,
4942 GLsizeiptr size,
Jamie Madill876429b2017-04-20 15:46:24 -04004943 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004944{
Brandon Jones6cad5662017-06-14 13:25:13 -07004945 if (size < 0)
Jamie Madill29639852016-09-02 15:00:09 -04004946 {
Jamie Madille0472f32018-11-27 16:32:45 -05004947 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Brandon Jones6cad5662017-06-14 13:25:13 -07004948 return false;
4949 }
4950
4951 if (offset < 0)
4952 {
Jamie Madille0472f32018-11-27 16:32:45 -05004953 context->validationError(GL_INVALID_VALUE, kNegativeOffset);
Jamie Madill29639852016-09-02 15:00:09 -04004954 return false;
4955 }
4956
Corentin Walleze4477002017-12-01 14:39:58 -05004957 if (!context->isValidBufferBinding(target))
Jamie Madill29639852016-09-02 15:00:09 -04004958 {
Jamie Madille0472f32018-11-27 16:32:45 -05004959 context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
Jamie Madill29639852016-09-02 15:00:09 -04004960 return false;
4961 }
4962
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004963 Buffer *buffer = context->getState().getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04004964
4965 if (!buffer)
4966 {
Jamie Madille0472f32018-11-27 16:32:45 -05004967 context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
Jamie Madill29639852016-09-02 15:00:09 -04004968 return false;
4969 }
4970
4971 if (buffer->isMapped())
4972 {
Jamie Madille0472f32018-11-27 16:32:45 -05004973 context->validationError(GL_INVALID_OPERATION, kBufferMapped);
Jamie Madill29639852016-09-02 15:00:09 -04004974 return false;
4975 }
4976
James Darpiniane8a93c62018-01-04 18:02:24 -08004977 if (context->getExtensions().webglCompatibility &&
4978 buffer->isBoundForTransformFeedbackAndOtherUse())
4979 {
Jamie Madille0472f32018-11-27 16:32:45 -05004980 context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback);
James Darpiniane8a93c62018-01-04 18:02:24 -08004981 return false;
4982 }
4983
Jamie Madill29639852016-09-02 15:00:09 -04004984 // Check for possible overflow of size + offset
4985 angle::CheckedNumeric<size_t> checkedSize(size);
4986 checkedSize += offset;
4987 if (!checkedSize.IsValid())
4988 {
Jamie Madille0472f32018-11-27 16:32:45 -05004989 context->validationError(GL_INVALID_VALUE, kParamOverflow);
Jamie Madill29639852016-09-02 15:00:09 -04004990 return false;
4991 }
4992
4993 if (size + offset > buffer->getSize())
4994 {
Jamie Madille0472f32018-11-27 16:32:45 -05004995 context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize);
Jamie Madill29639852016-09-02 15:00:09 -04004996 return false;
4997 }
4998
Martin Radev4c4c8e72016-08-04 12:25:34 +03004999 return true;
5000}
5001
Geoff Lang111a99e2017-10-17 10:58:41 -04005002bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name)
Geoff Langc287ea62016-09-16 14:46:51 -04005003{
Geoff Langc339c4e2016-11-29 10:37:36 -05005004 if (!context->getExtensions().requestExtension)
Geoff Langc287ea62016-09-16 14:46:51 -04005005 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005006 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Geoff Langc287ea62016-09-16 14:46:51 -04005007 return false;
5008 }
5009
Geoff Lang111a99e2017-10-17 10:58:41 -04005010 if (!context->isExtensionRequestable(name))
Geoff Langc287ea62016-09-16 14:46:51 -04005011 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005012 context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable);
Geoff Langc287ea62016-09-16 14:46:51 -04005013 return false;
5014 }
5015
5016 return true;
5017}
5018
James Darpinianc42da4e2019-10-03 13:46:28 -07005019bool ValidateDisableExtensionANGLE(Context *context, const GLchar *name)
5020{
5021 if (!context->getExtensions().requestExtension)
5022 {
5023 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
5024 return false;
5025 }
5026
5027 if (!context->isExtensionDisablable(name))
5028 {
5029 context->validationError(GL_INVALID_OPERATION, kExtensionNotDisablable);
5030 return false;
5031 }
5032
5033 return true;
5034}
5035
Jamie Madill5b772312018-03-08 20:28:32 -05005036bool ValidateActiveTexture(Context *context, GLenum texture)
Jamie Madillef300b12016-10-07 15:12:09 -04005037{
Lingfeng Yang038dd532018-03-29 17:31:52 -07005038 if (context->getClientMajorVersion() < 2)
5039 {
5040 return ValidateMultitextureUnit(context, texture);
5041 }
5042
Jamie Madillef300b12016-10-07 15:12:09 -04005043 if (texture < GL_TEXTURE0 ||
5044 texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
5045 {
Jamie Madille0472f32018-11-27 16:32:45 -05005046 context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit);
Jamie Madillef300b12016-10-07 15:12:09 -04005047 return false;
5048 }
5049
5050 return true;
5051}
5052
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005053bool ValidateAttachShader(Context *context, ShaderProgramID program, ShaderProgramID shader)
Jamie Madillef300b12016-10-07 15:12:09 -04005054{
5055 Program *programObject = GetValidProgram(context, program);
5056 if (!programObject)
5057 {
5058 return false;
5059 }
5060
5061 Shader *shaderObject = GetValidShader(context, shader);
5062 if (!shaderObject)
5063 {
5064 return false;
5065 }
5066
Jiawei Shao385b3e02018-03-21 09:43:28 +08005067 if (programObject->getAttachedShader(shaderObject->getType()))
Jamie Madillef300b12016-10-07 15:12:09 -04005068 {
Jamie Madille0472f32018-11-27 16:32:45 -05005069 context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader);
Jiawei Shao385b3e02018-03-21 09:43:28 +08005070 return false;
Jamie Madillef300b12016-10-07 15:12:09 -04005071 }
5072
5073 return true;
5074}
5075
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005076bool ValidateBindAttribLocation(Context *context,
5077 ShaderProgramID program,
5078 GLuint index,
5079 const GLchar *name)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005080{
5081 if (index >= MAX_VERTEX_ATTRIBS)
5082 {
Jamie Madille0472f32018-11-27 16:32:45 -05005083 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005084 return false;
5085 }
5086
5087 if (strncmp(name, "gl_", 3) == 0)
5088 {
Jamie Madille0472f32018-11-27 16:32:45 -05005089 context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005090 return false;
5091 }
5092
Brandon Jonesed5b46f2017-07-21 08:39:17 -07005093 if (context->isWebGL())
Geoff Langfc32e8b2017-05-31 14:16:59 -04005094 {
Brandon Jonesed5b46f2017-07-21 08:39:17 -07005095 const size_t length = strlen(name);
5096
5097 if (!IsValidESSLString(name, length))
5098 {
5099 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters
5100 // for shader-related entry points
Jamie Madille0472f32018-11-27 16:32:45 -05005101 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Brandon Jonesed5b46f2017-07-21 08:39:17 -07005102 return false;
5103 }
5104
5105 if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name))
5106 {
5107 return false;
5108 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04005109 }
5110
Jamie Madill01a80ee2016-11-07 12:06:18 -05005111 return GetValidProgram(context, program) != nullptr;
5112}
5113
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06005114bool ValidateBindFramebuffer(Context *context, GLenum target, FramebufferID framebuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005115{
Geoff Lange8afa902017-09-27 15:00:43 -04005116 if (!ValidFramebufferTarget(context, target))
Jamie Madill01a80ee2016-11-07 12:06:18 -05005117 {
Jamie Madille0472f32018-11-27 16:32:45 -05005118 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005119 return false;
5120 }
5121
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005122 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05005123 !context->isFramebufferGenerated(framebuffer))
5124 {
Jamie Madille0472f32018-11-27 16:32:45 -05005125 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005126 return false;
5127 }
5128
5129 return true;
5130}
5131
Jamie Madill7c7dec02019-08-06 17:44:11 -04005132bool ValidateBindRenderbuffer(Context *context, GLenum target, RenderbufferID renderbuffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005133{
5134 if (target != GL_RENDERBUFFER)
5135 {
Jamie Madille0472f32018-11-27 16:32:45 -05005136 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005137 return false;
5138 }
5139
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005140 if (!context->getState().isBindGeneratesResourceEnabled() &&
Jamie Madill01a80ee2016-11-07 12:06:18 -05005141 !context->isRenderbufferGenerated(renderbuffer))
5142 {
Jamie Madille0472f32018-11-27 16:32:45 -05005143 context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005144 return false;
5145 }
5146
5147 return true;
5148}
5149
Jamie Madill5b772312018-03-08 20:28:32 -05005150static bool ValidBlendEquationMode(const Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005151{
5152 switch (mode)
5153 {
5154 case GL_FUNC_ADD:
5155 case GL_FUNC_SUBTRACT:
5156 case GL_FUNC_REVERSE_SUBTRACT:
Geoff Lang50cac572017-09-26 17:37:43 -04005157 return true;
5158
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005159 case GL_MIN:
5160 case GL_MAX:
Geoff Lang50cac572017-09-26 17:37:43 -04005161 return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax;
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005162
5163 default:
5164 return false;
5165 }
5166}
5167
Jamie Madill5b772312018-03-08 20:28:32 -05005168bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005169{
5170 return true;
5171}
5172
Jamie Madill5b772312018-03-08 20:28:32 -05005173bool ValidateBlendEquation(Context *context, GLenum mode)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005174{
Geoff Lang50cac572017-09-26 17:37:43 -04005175 if (!ValidBlendEquationMode(context, mode))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005176 {
Jamie Madille0472f32018-11-27 16:32:45 -05005177 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005178 return false;
5179 }
5180
5181 return true;
5182}
5183
Jamie Madill5b772312018-03-08 20:28:32 -05005184bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005185{
Geoff Lang50cac572017-09-26 17:37:43 -04005186 if (!ValidBlendEquationMode(context, modeRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005187 {
Jamie Madille0472f32018-11-27 16:32:45 -05005188 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005189 return false;
5190 }
5191
Geoff Lang50cac572017-09-26 17:37:43 -04005192 if (!ValidBlendEquationMode(context, modeAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005193 {
Jamie Madille0472f32018-11-27 16:32:45 -05005194 context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005195 return false;
5196 }
5197
5198 return true;
5199}
5200
Jamie Madill5b772312018-03-08 20:28:32 -05005201bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005202{
5203 return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor);
5204}
5205
Jamie Madill5b772312018-03-08 20:28:32 -05005206bool ValidateBlendFuncSeparate(Context *context,
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005207 GLenum srcRGB,
5208 GLenum dstRGB,
5209 GLenum srcAlpha,
5210 GLenum dstAlpha)
5211{
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005212 if (!ValidSrcBlendFunc(context, srcRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005213 {
Jamie Madille0472f32018-11-27 16:32:45 -05005214 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005215 return false;
5216 }
5217
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005218 if (!ValidDstBlendFunc(context, dstRGB))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005219 {
Jamie Madille0472f32018-11-27 16:32:45 -05005220 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005221 return false;
5222 }
5223
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005224 if (!ValidSrcBlendFunc(context, srcAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005225 {
Jamie Madille0472f32018-11-27 16:32:45 -05005226 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005227 return false;
5228 }
5229
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03005230 if (!ValidDstBlendFunc(context, dstAlpha))
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005231 {
Jamie Madille0472f32018-11-27 16:32:45 -05005232 context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005233 return false;
5234 }
5235
Frank Henigman146e8a12017-03-02 23:22:37 -05005236 if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
5237 context->getExtensions().webglCompatibility)
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005238 {
5239 bool constantColorUsed =
5240 (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
5241 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
5242
5243 bool constantAlphaUsed =
5244 (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
5245 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
5246
5247 if (constantColorUsed && constantAlphaUsed)
5248 {
Frank Henigman146e8a12017-03-02 23:22:37 -05005249 if (context->getExtensions().webglCompatibility)
5250 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005251 context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor);
5252 return false;
Frank Henigman146e8a12017-03-02 23:22:37 -05005253 }
Jamie Madillc3e37312018-11-30 15:25:39 -05005254
5255 WARN() << kConstantColorAlphaLimitation;
5256 context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05005257 return false;
5258 }
5259 }
5260
5261 return true;
5262}
5263
Geoff Langc339c4e2016-11-29 10:37:36 -05005264bool ValidateGetString(Context *context, GLenum name)
5265{
5266 switch (name)
5267 {
5268 case GL_VENDOR:
5269 case GL_RENDERER:
5270 case GL_VERSION:
5271 case GL_SHADING_LANGUAGE_VERSION:
5272 case GL_EXTENSIONS:
5273 break;
5274
5275 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
5276 if (!context->getExtensions().requestExtension)
5277 {
Jamie Madille0472f32018-11-27 16:32:45 -05005278 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005279 return false;
5280 }
5281 break;
5282
5283 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005284 context->validationError(GL_INVALID_ENUM, kInvalidName);
Geoff Langc339c4e2016-11-29 10:37:36 -05005285 return false;
5286 }
5287
5288 return true;
5289}
5290
Jamie Madill5b772312018-03-08 20:28:32 -05005291bool ValidateLineWidth(Context *context, GLfloat width)
Geoff Lang47c48082016-12-07 15:38:13 -05005292{
5293 if (width <= 0.0f || isNaN(width))
5294 {
Jamie Madille0472f32018-11-27 16:32:45 -05005295 context->validationError(GL_INVALID_VALUE, kInvalidWidth);
Geoff Lang47c48082016-12-07 15:38:13 -05005296 return false;
5297 }
5298
5299 return true;
5300}
5301
Jamie Madill5b772312018-03-08 20:28:32 -05005302bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
Frank Henigman6137ddc2017-02-10 18:55:07 -05005303{
5304 if (context->getExtensions().webglCompatibility && zNear > zFar)
5305 {
Jamie Madille0472f32018-11-27 16:32:45 -05005306 context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange);
Frank Henigman6137ddc2017-02-10 18:55:07 -05005307 return false;
5308 }
5309
5310 return true;
5311}
5312
Jamie Madill5b772312018-03-08 20:28:32 -05005313bool ValidateRenderbufferStorage(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005314 GLenum target,
5315 GLenum internalformat,
5316 GLsizei width,
5317 GLsizei height)
5318{
5319 return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width,
5320 height);
5321}
5322
Jamie Madill5b772312018-03-08 20:28:32 -05005323bool ValidateRenderbufferStorageMultisampleANGLE(Context *context,
Jamie Madille8fb6402017-02-14 17:56:40 -05005324 GLenum target,
5325 GLsizei samples,
5326 GLenum internalformat,
5327 GLsizei width,
5328 GLsizei height)
5329{
5330 if (!context->getExtensions().framebufferMultisample)
5331 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005332 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madille8fb6402017-02-14 17:56:40 -05005333 return false;
5334 }
5335
5336 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
Jamie Madill610640f2018-11-21 17:28:41 -05005337 // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is
Jamie Madille8fb6402017-02-14 17:56:40 -05005338 // generated.
5339 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
5340 {
Jamie Madille0472f32018-11-27 16:32:45 -05005341 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005342 return false;
5343 }
5344
5345 // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create
5346 // the specified storage. This is different than ES 3.0 in which a sample number higher
5347 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
5348 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
5349 if (context->getClientMajorVersion() >= 3)
5350 {
5351 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
5352 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
5353 {
Jamie Madille0472f32018-11-27 16:32:45 -05005354 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
Jamie Madille8fb6402017-02-14 17:56:40 -05005355 return false;
5356 }
5357 }
5358
5359 return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat,
5360 width, height);
5361}
5362
Jamie Madill5b772312018-03-08 20:28:32 -05005363bool ValidateCheckFramebufferStatus(Context *context, GLenum target)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005364{
Geoff Lange8afa902017-09-27 15:00:43 -04005365 if (!ValidFramebufferTarget(context, target))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005366 {
Jamie Madille0472f32018-11-27 16:32:45 -05005367 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005368 return false;
5369 }
5370
5371 return true;
5372}
5373
Jamie Madill5b772312018-03-08 20:28:32 -05005374bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005375{
5376 return true;
5377}
5378
Jamie Madill5b772312018-03-08 20:28:32 -05005379bool ValidateClearDepthf(Context *context, GLfloat depth)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005380{
5381 return true;
5382}
5383
Jamie Madill5b772312018-03-08 20:28:32 -05005384bool ValidateClearStencil(Context *context, GLint s)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005385{
5386 return true;
5387}
5388
Jamie Madill5b772312018-03-08 20:28:32 -05005389bool ValidateColorMask(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005390 GLboolean red,
5391 GLboolean green,
5392 GLboolean blue,
5393 GLboolean alpha)
5394{
5395 return true;
5396}
5397
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005398bool ValidateCompileShader(Context *context, ShaderProgramID shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005399{
5400 return true;
5401}
5402
Jamie Madill5b772312018-03-08 20:28:32 -05005403bool ValidateCreateProgram(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005404{
5405 return true;
5406}
5407
Jamie Madill5b772312018-03-08 20:28:32 -05005408bool ValidateCullFace(Context *context, CullFaceMode mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005409{
5410 switch (mode)
5411 {
Corentin Wallez2e568cf2017-09-18 17:05:22 -04005412 case CullFaceMode::Front:
5413 case CullFaceMode::Back:
5414 case CullFaceMode::FrontAndBack:
Jamie Madillc1d770e2017-04-13 17:31:24 -04005415 break;
5416
5417 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005418 context->validationError(GL_INVALID_ENUM, kInvalidCullMode);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005419 return false;
5420 }
5421
5422 return true;
5423}
5424
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005425bool ValidateDeleteProgram(Context *context, ShaderProgramID program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005426{
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005427 if (program.value == 0)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005428 {
5429 return false;
5430 }
5431
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005432 if (!context->getProgramResolveLink(program))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005433 {
5434 if (context->getShader(program))
5435 {
Jamie Madille0472f32018-11-27 16:32:45 -05005436 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005437 return false;
5438 }
5439 else
5440 {
Jamie Madille0472f32018-11-27 16:32:45 -05005441 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005442 return false;
5443 }
5444 }
5445
5446 return true;
5447}
5448
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005449bool ValidateDeleteShader(Context *context, ShaderProgramID shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005450{
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005451 if (shader.value == 0)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005452 {
5453 return false;
5454 }
5455
5456 if (!context->getShader(shader))
5457 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005458 if (context->getProgramResolveLink(shader))
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459 {
Jamie Madille0472f32018-11-27 16:32:45 -05005460 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005461 return false;
5462 }
5463 else
5464 {
Jamie Madille0472f32018-11-27 16:32:45 -05005465 context->validationError(GL_INVALID_VALUE, kExpectedShaderName);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005466 return false;
5467 }
5468 }
5469
5470 return true;
5471}
5472
Jamie Madill5b772312018-03-08 20:28:32 -05005473bool ValidateDepthFunc(Context *context, GLenum func)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005474{
5475 switch (func)
5476 {
5477 case GL_NEVER:
5478 case GL_ALWAYS:
5479 case GL_LESS:
5480 case GL_LEQUAL:
5481 case GL_EQUAL:
5482 case GL_GREATER:
5483 case GL_GEQUAL:
5484 case GL_NOTEQUAL:
5485 break;
5486
5487 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005488 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005489 return false;
5490 }
5491
5492 return true;
5493}
5494
Jamie Madill5b772312018-03-08 20:28:32 -05005495bool ValidateDepthMask(Context *context, GLboolean flag)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005496{
5497 return true;
5498}
5499
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005500bool ValidateDetachShader(Context *context, ShaderProgramID program, ShaderProgramID shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005501{
5502 Program *programObject = GetValidProgram(context, program);
5503 if (!programObject)
5504 {
5505 return false;
5506 }
5507
5508 Shader *shaderObject = GetValidShader(context, shader);
5509 if (!shaderObject)
5510 {
5511 return false;
5512 }
5513
Jiawei Shao385b3e02018-03-21 09:43:28 +08005514 const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType());
Jamie Madillc1d770e2017-04-13 17:31:24 -04005515 if (attachedShader != shaderObject)
5516 {
Jamie Madille0472f32018-11-27 16:32:45 -05005517 context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005518 return false;
5519 }
5520
5521 return true;
5522}
5523
Jamie Madill5b772312018-03-08 20:28:32 -05005524bool ValidateDisableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005525{
5526 if (index >= MAX_VERTEX_ATTRIBS)
5527 {
Jamie Madille0472f32018-11-27 16:32:45 -05005528 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005529 return false;
5530 }
5531
5532 return true;
5533}
5534
Jamie Madill5b772312018-03-08 20:28:32 -05005535bool ValidateEnableVertexAttribArray(Context *context, GLuint index)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005536{
5537 if (index >= MAX_VERTEX_ATTRIBS)
5538 {
Jamie Madille0472f32018-11-27 16:32:45 -05005539 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005540 return false;
5541 }
5542
5543 return true;
5544}
5545
Jamie Madill5b772312018-03-08 20:28:32 -05005546bool ValidateFinish(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005547{
5548 return true;
5549}
5550
Jamie Madill5b772312018-03-08 20:28:32 -05005551bool ValidateFlush(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005552{
5553 return true;
5554}
5555
Jamie Madill5b772312018-03-08 20:28:32 -05005556bool ValidateFrontFace(Context *context, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005557{
5558 switch (mode)
5559 {
5560 case GL_CW:
5561 case GL_CCW:
5562 break;
5563 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005564 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005565 return false;
5566 }
5567
5568 return true;
5569}
5570
Jamie Madill5b772312018-03-08 20:28:32 -05005571bool ValidateGetActiveAttrib(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005572 ShaderProgramID program,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005573 GLuint index,
5574 GLsizei bufsize,
5575 GLsizei *length,
5576 GLint *size,
5577 GLenum *type,
5578 GLchar *name)
5579{
5580 if (bufsize < 0)
5581 {
Jamie Madille0472f32018-11-27 16:32:45 -05005582 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005583 return false;
5584 }
5585
5586 Program *programObject = GetValidProgram(context, program);
5587
5588 if (!programObject)
5589 {
5590 return false;
5591 }
5592
5593 if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount()))
5594 {
Jamie Madille0472f32018-11-27 16:32:45 -05005595 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005596 return false;
5597 }
5598
5599 return true;
5600}
5601
Jamie Madill5b772312018-03-08 20:28:32 -05005602bool ValidateGetActiveUniform(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005603 ShaderProgramID program,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005604 GLuint index,
5605 GLsizei bufsize,
5606 GLsizei *length,
5607 GLint *size,
5608 GLenum *type,
5609 GLchar *name)
5610{
5611 if (bufsize < 0)
5612 {
Jamie Madille0472f32018-11-27 16:32:45 -05005613 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005614 return false;
5615 }
5616
5617 Program *programObject = GetValidProgram(context, program);
5618
5619 if (!programObject)
5620 {
5621 return false;
5622 }
5623
5624 if (index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
5625 {
Jamie Madille0472f32018-11-27 16:32:45 -05005626 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005627 return false;
5628 }
5629
5630 return true;
5631}
5632
Jamie Madill5b772312018-03-08 20:28:32 -05005633bool ValidateGetAttachedShaders(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005634 ShaderProgramID program,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005635 GLsizei maxcount,
5636 GLsizei *count,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005637 ShaderProgramID *shaders)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005638{
5639 if (maxcount < 0)
5640 {
Jamie Madille0472f32018-11-27 16:32:45 -05005641 context->validationError(GL_INVALID_VALUE, kNegativeMaxCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005642 return false;
5643 }
5644
5645 Program *programObject = GetValidProgram(context, program);
5646
5647 if (!programObject)
5648 {
5649 return false;
5650 }
5651
5652 return true;
5653}
5654
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005655bool ValidateGetAttribLocation(Context *context, ShaderProgramID program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005656{
Geoff Langfc32e8b2017-05-31 14:16:59 -04005657 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5658 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005659 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005660 {
Jamie Madille0472f32018-11-27 16:32:45 -05005661 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005662 return false;
5663 }
5664
Jamie Madillc1d770e2017-04-13 17:31:24 -04005665 Program *programObject = GetValidProgram(context, program);
5666
5667 if (!programObject)
5668 {
Jamie Madille0472f32018-11-27 16:32:45 -05005669 context->validationError(GL_INVALID_OPERATION, kProgramNotBound);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005670 return false;
5671 }
5672
5673 if (!programObject->isLinked())
5674 {
Jamie Madille0472f32018-11-27 16:32:45 -05005675 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005676 return false;
5677 }
5678
5679 return true;
5680}
5681
Jamie Madill5b772312018-03-08 20:28:32 -05005682bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005683{
5684 GLenum nativeType;
5685 unsigned int numParams = 0;
5686 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5687}
5688
Jamie Madill5b772312018-03-08 20:28:32 -05005689bool ValidateGetError(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005690{
5691 return true;
5692}
5693
Jamie Madill5b772312018-03-08 20:28:32 -05005694bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005695{
5696 GLenum nativeType;
5697 unsigned int numParams = 0;
5698 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5699}
5700
Jamie Madill5b772312018-03-08 20:28:32 -05005701bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005702{
5703 GLenum nativeType;
5704 unsigned int numParams = 0;
5705 return ValidateStateQuery(context, pname, &nativeType, &numParams);
5706}
5707
Jamie Madill5b772312018-03-08 20:28:32 -05005708bool ValidateGetProgramInfoLog(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005709 ShaderProgramID program,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005710 GLsizei bufsize,
5711 GLsizei *length,
5712 GLchar *infolog)
5713{
5714 if (bufsize < 0)
5715 {
Jamie Madille0472f32018-11-27 16:32:45 -05005716 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005717 return false;
5718 }
5719
5720 Program *programObject = GetValidProgram(context, program);
5721 if (!programObject)
5722 {
5723 return false;
5724 }
5725
5726 return true;
5727}
5728
Jamie Madill5b772312018-03-08 20:28:32 -05005729bool ValidateGetShaderInfoLog(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005730 ShaderProgramID shader,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005731 GLsizei bufsize,
5732 GLsizei *length,
5733 GLchar *infolog)
5734{
5735 if (bufsize < 0)
5736 {
Jamie Madille0472f32018-11-27 16:32:45 -05005737 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005738 return false;
5739 }
5740
5741 Shader *shaderObject = GetValidShader(context, shader);
5742 if (!shaderObject)
5743 {
5744 return false;
5745 }
5746
5747 return true;
5748}
5749
Jamie Madill5b772312018-03-08 20:28:32 -05005750bool ValidateGetShaderPrecisionFormat(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005751 GLenum shadertype,
5752 GLenum precisiontype,
5753 GLint *range,
5754 GLint *precision)
5755{
5756 switch (shadertype)
5757 {
5758 case GL_VERTEX_SHADER:
5759 case GL_FRAGMENT_SHADER:
5760 break;
5761 case GL_COMPUTE_SHADER:
Jamie Madillc3e37312018-11-30 15:25:39 -05005762 context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005763 return false;
5764 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005765 context->validationError(GL_INVALID_ENUM, kInvalidShaderType);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005766 return false;
5767 }
5768
5769 switch (precisiontype)
5770 {
5771 case GL_LOW_FLOAT:
5772 case GL_MEDIUM_FLOAT:
5773 case GL_HIGH_FLOAT:
5774 case GL_LOW_INT:
5775 case GL_MEDIUM_INT:
5776 case GL_HIGH_INT:
5777 break;
5778
5779 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005780 context->validationError(GL_INVALID_ENUM, kInvalidPrecision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005781 return false;
5782 }
5783
5784 return true;
5785}
5786
Jamie Madill5b772312018-03-08 20:28:32 -05005787bool ValidateGetShaderSource(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005788 ShaderProgramID shader,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005789 GLsizei bufsize,
5790 GLsizei *length,
5791 GLchar *source)
5792{
5793 if (bufsize < 0)
5794 {
Jamie Madille0472f32018-11-27 16:32:45 -05005795 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005796 return false;
5797 }
5798
5799 Shader *shaderObject = GetValidShader(context, shader);
5800 if (!shaderObject)
5801 {
5802 return false;
5803 }
5804
5805 return true;
5806}
5807
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005808bool ValidateGetUniformLocation(Context *context, ShaderProgramID program, const GLchar *name)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005809{
5810 if (strstr(name, "gl_") == name)
5811 {
5812 return false;
5813 }
5814
Geoff Langfc32e8b2017-05-31 14:16:59 -04005815 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
5816 // shader-related entry points
Geoff Langcab92ee2017-07-19 17:32:07 -04005817 if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name)))
Geoff Langfc32e8b2017-05-31 14:16:59 -04005818 {
Jamie Madille0472f32018-11-27 16:32:45 -05005819 context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04005820 return false;
5821 }
5822
Jamie Madillc1d770e2017-04-13 17:31:24 -04005823 Program *programObject = GetValidProgram(context, program);
5824
5825 if (!programObject)
5826 {
5827 return false;
5828 }
5829
5830 if (!programObject->isLinked())
5831 {
Jamie Madille0472f32018-11-27 16:32:45 -05005832 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005833 return false;
5834 }
5835
5836 return true;
5837}
5838
Jamie Madill5b772312018-03-08 20:28:32 -05005839bool ValidateHint(Context *context, GLenum target, GLenum mode)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005840{
5841 switch (mode)
5842 {
5843 case GL_FASTEST:
5844 case GL_NICEST:
5845 case GL_DONT_CARE:
5846 break;
5847
5848 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005849 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005850 return false;
5851 }
5852
5853 switch (target)
5854 {
5855 case GL_GENERATE_MIPMAP_HINT:
5856 break;
5857
Geoff Lange7bd2182017-06-16 16:13:13 -04005858 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
5859 if (context->getClientVersion() < ES_3_0 &&
5860 !context->getExtensions().standardDerivatives)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005861 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005862 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005863 return false;
5864 }
5865 break;
5866
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005867 case GL_PERSPECTIVE_CORRECTION_HINT:
5868 case GL_POINT_SMOOTH_HINT:
5869 case GL_LINE_SMOOTH_HINT:
5870 case GL_FOG_HINT:
5871 if (context->getClientMajorVersion() >= 2)
5872 {
Jamie Madille0472f32018-11-27 16:32:45 -05005873 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07005874 return false;
5875 }
5876 break;
5877
Jamie Madillc1d770e2017-04-13 17:31:24 -04005878 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005879 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005880 return false;
5881 }
5882
5883 return true;
5884}
5885
Jamie Madill3b3fe832019-08-06 17:44:12 -04005886bool ValidateIsBuffer(Context *context, BufferID buffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005887{
5888 return true;
5889}
5890
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06005891bool ValidateIsFramebuffer(Context *context, FramebufferID framebuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005892{
5893 return true;
5894}
5895
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005896bool ValidateIsProgram(Context *context, ShaderProgramID program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005897{
5898 return true;
5899}
5900
Jamie Madill7c7dec02019-08-06 17:44:11 -04005901bool ValidateIsRenderbuffer(Context *context, RenderbufferID renderbuffer)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005902{
5903 return true;
5904}
5905
Jiacheng Lu120b61d2019-08-21 12:51:58 -06005906bool ValidateIsShader(Context *context, ShaderProgramID shader)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005907{
5908 return true;
5909}
5910
Jamie Madill2ab08ed2019-08-12 16:20:21 -04005911bool ValidateIsTexture(Context *context, TextureID texture)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005912{
5913 return true;
5914}
5915
Jamie Madill5b772312018-03-08 20:28:32 -05005916bool ValidatePixelStorei(Context *context, GLenum pname, GLint param)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005917{
5918 if (context->getClientMajorVersion() < 3)
5919 {
5920 switch (pname)
5921 {
5922 case GL_UNPACK_IMAGE_HEIGHT:
5923 case GL_UNPACK_SKIP_IMAGES:
Jamie Madille0472f32018-11-27 16:32:45 -05005924 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005925 return false;
5926
5927 case GL_UNPACK_ROW_LENGTH:
5928 case GL_UNPACK_SKIP_ROWS:
5929 case GL_UNPACK_SKIP_PIXELS:
5930 if (!context->getExtensions().unpackSubimage)
5931 {
Jamie Madille0472f32018-11-27 16:32:45 -05005932 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005933 return false;
5934 }
5935 break;
5936
5937 case GL_PACK_ROW_LENGTH:
5938 case GL_PACK_SKIP_ROWS:
5939 case GL_PACK_SKIP_PIXELS:
5940 if (!context->getExtensions().packSubimage)
5941 {
Jamie Madille0472f32018-11-27 16:32:45 -05005942 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005943 return false;
5944 }
5945 break;
5946 }
5947 }
5948
5949 if (param < 0)
5950 {
Jamie Madillc3e37312018-11-30 15:25:39 -05005951 context->validationError(GL_INVALID_VALUE, kNegativeParam);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005952 return false;
5953 }
5954
5955 switch (pname)
5956 {
5957 case GL_UNPACK_ALIGNMENT:
5958 if (param != 1 && param != 2 && param != 4 && param != 8)
5959 {
Jamie Madille0472f32018-11-27 16:32:45 -05005960 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005961 return false;
5962 }
5963 break;
5964
5965 case GL_PACK_ALIGNMENT:
5966 if (param != 1 && param != 2 && param != 4 && param != 8)
5967 {
Jamie Madille0472f32018-11-27 16:32:45 -05005968 context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005969 return false;
5970 }
5971 break;
5972
5973 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Geoff Lang000dab82017-09-27 14:27:07 -04005974 if (!context->getExtensions().packReverseRowOrder)
5975 {
Jamie Madille0472f32018-11-27 16:32:45 -05005976 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Geoff Lang000dab82017-09-27 14:27:07 -04005977 }
5978 break;
5979
Jamie Madillc1d770e2017-04-13 17:31:24 -04005980 case GL_UNPACK_ROW_LENGTH:
5981 case GL_UNPACK_IMAGE_HEIGHT:
5982 case GL_UNPACK_SKIP_IMAGES:
5983 case GL_UNPACK_SKIP_ROWS:
5984 case GL_UNPACK_SKIP_PIXELS:
5985 case GL_PACK_ROW_LENGTH:
5986 case GL_PACK_SKIP_ROWS:
5987 case GL_PACK_SKIP_PIXELS:
5988 break;
5989
5990 default:
Jamie Madille0472f32018-11-27 16:32:45 -05005991 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005992 return false;
5993 }
5994
5995 return true;
5996}
5997
Jamie Madill5b772312018-03-08 20:28:32 -05005998bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005999{
6000 return true;
6001}
6002
Jamie Madill5b772312018-03-08 20:28:32 -05006003bool ValidateReleaseShaderCompiler(Context *context)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006004{
6005 return true;
6006}
6007
Jamie Madill5b772312018-03-08 20:28:32 -05006008bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006009{
6010 return true;
6011}
6012
Jamie Madill5b772312018-03-08 20:28:32 -05006013bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006014{
6015 if (width < 0 || height < 0)
6016 {
Jamie Madille0472f32018-11-27 16:32:45 -05006017 context->validationError(GL_INVALID_VALUE, kNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006018 return false;
6019 }
6020
6021 return true;
6022}
6023
Jamie Madill5b772312018-03-08 20:28:32 -05006024bool ValidateShaderBinary(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006025 GLsizei n,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006026 const ShaderProgramID *shaders,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006027 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04006028 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006029 GLsizei length)
6030{
6031 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
6032 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) ==
6033 shaderBinaryFormats.end())
6034 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006035 context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006036 return false;
6037 }
6038
6039 return true;
6040}
6041
Jamie Madill5b772312018-03-08 20:28:32 -05006042bool ValidateShaderSource(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006043 ShaderProgramID shader,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006044 GLsizei count,
6045 const GLchar *const *string,
6046 const GLint *length)
6047{
6048 if (count < 0)
6049 {
Jamie Madille0472f32018-11-27 16:32:45 -05006050 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006051 return false;
6052 }
6053
Geoff Langfc32e8b2017-05-31 14:16:59 -04006054 // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for
6055 // shader-related entry points
6056 if (context->getExtensions().webglCompatibility)
6057 {
6058 for (GLsizei i = 0; i < count; i++)
6059 {
Geoff Langcab92ee2017-07-19 17:32:07 -04006060 size_t len =
6061 (length && length[i] >= 0) ? static_cast<size_t>(length[i]) : strlen(string[i]);
Geoff Langa71a98e2017-06-19 15:15:00 -04006062
6063 // Backslash as line-continuation is allowed in WebGL 2.0.
Geoff Langcab92ee2017-07-19 17:32:07 -04006064 if (!IsValidESSLShaderSourceString(string[i], len,
6065 context->getClientVersion() >= ES_3_0))
Geoff Langfc32e8b2017-05-31 14:16:59 -04006066 {
Jamie Madille0472f32018-11-27 16:32:45 -05006067 context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters);
Geoff Langfc32e8b2017-05-31 14:16:59 -04006068 return false;
6069 }
6070 }
6071 }
6072
Jamie Madillc1d770e2017-04-13 17:31:24 -04006073 Shader *shaderObject = GetValidShader(context, shader);
6074 if (!shaderObject)
6075 {
6076 return false;
6077 }
6078
6079 return true;
6080}
6081
Jamie Madill5b772312018-03-08 20:28:32 -05006082bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006083{
6084 if (!IsValidStencilFunc(func))
6085 {
Jamie Madille0472f32018-11-27 16:32:45 -05006086 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006087 return false;
6088 }
6089
6090 return true;
6091}
6092
Jamie Madill5b772312018-03-08 20:28:32 -05006093bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006094{
6095 if (!IsValidStencilFace(face))
6096 {
Jamie Madille0472f32018-11-27 16:32:45 -05006097 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006098 return false;
6099 }
6100
6101 if (!IsValidStencilFunc(func))
6102 {
Jamie Madille0472f32018-11-27 16:32:45 -05006103 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006104 return false;
6105 }
6106
6107 return true;
6108}
6109
Jamie Madill5b772312018-03-08 20:28:32 -05006110bool ValidateStencilMask(Context *context, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006111{
6112 return true;
6113}
6114
Jamie Madill5b772312018-03-08 20:28:32 -05006115bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006116{
6117 if (!IsValidStencilFace(face))
6118 {
Jamie Madille0472f32018-11-27 16:32:45 -05006119 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006120 return false;
6121 }
6122
6123 return true;
6124}
6125
Jamie Madill5b772312018-03-08 20:28:32 -05006126bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006127{
6128 if (!IsValidStencilOp(fail))
6129 {
Jamie Madille0472f32018-11-27 16:32:45 -05006130 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006131 return false;
6132 }
6133
6134 if (!IsValidStencilOp(zfail))
6135 {
Jamie Madille0472f32018-11-27 16:32:45 -05006136 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006137 return false;
6138 }
6139
6140 if (!IsValidStencilOp(zpass))
6141 {
Jamie Madille0472f32018-11-27 16:32:45 -05006142 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006143 return false;
6144 }
6145
6146 return true;
6147}
6148
Jamie Madill5b772312018-03-08 20:28:32 -05006149bool ValidateStencilOpSeparate(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006150 GLenum face,
6151 GLenum fail,
6152 GLenum zfail,
6153 GLenum zpass)
6154{
6155 if (!IsValidStencilFace(face))
6156 {
Jamie Madille0472f32018-11-27 16:32:45 -05006157 context->validationError(GL_INVALID_ENUM, kInvalidStencil);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006158 return false;
6159 }
6160
6161 return ValidateStencilOp(context, fail, zfail, zpass);
6162}
6163
Jamie Madill5b772312018-03-08 20:28:32 -05006164bool ValidateUniform1f(Context *context, GLint location, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006165{
6166 return ValidateUniform(context, GL_FLOAT, location, 1);
6167}
6168
Jamie Madill5b772312018-03-08 20:28:32 -05006169bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006170{
6171 return ValidateUniform(context, GL_FLOAT, location, count);
6172}
6173
Jamie Madill5b772312018-03-08 20:28:32 -05006174bool ValidateUniform1i(Context *context, GLint location, GLint x)
Jamie Madillbe849e42017-05-02 15:49:00 -04006175{
6176 return ValidateUniform1iv(context, location, 1, &x);
6177}
6178
Jamie Madill5b772312018-03-08 20:28:32 -05006179bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006180{
6181 return ValidateUniform(context, GL_FLOAT_VEC2, location, count);
6182}
6183
Jamie Madill5b772312018-03-08 20:28:32 -05006184bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006185{
6186 return ValidateUniform(context, GL_INT_VEC2, location, 1);
6187}
6188
Jamie Madill5b772312018-03-08 20:28:32 -05006189bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006190{
6191 return ValidateUniform(context, GL_INT_VEC2, location, count);
6192}
6193
Jamie Madill5b772312018-03-08 20:28:32 -05006194bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006195{
6196 return ValidateUniform(context, GL_FLOAT_VEC3, location, 1);
6197}
6198
Jamie Madill5b772312018-03-08 20:28:32 -05006199bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006200{
6201 return ValidateUniform(context, GL_FLOAT_VEC3, location, count);
6202}
6203
Jamie Madill5b772312018-03-08 20:28:32 -05006204bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006205{
6206 return ValidateUniform(context, GL_INT_VEC3, location, 1);
6207}
6208
Jamie Madill5b772312018-03-08 20:28:32 -05006209bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006210{
6211 return ValidateUniform(context, GL_INT_VEC3, location, count);
6212}
6213
Jamie Madill5b772312018-03-08 20:28:32 -05006214bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006215{
6216 return ValidateUniform(context, GL_FLOAT_VEC4, location, 1);
6217}
6218
Jamie Madill5b772312018-03-08 20:28:32 -05006219bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006220{
6221 return ValidateUniform(context, GL_FLOAT_VEC4, location, count);
6222}
6223
Jamie Madill5b772312018-03-08 20:28:32 -05006224bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006225{
6226 return ValidateUniform(context, GL_INT_VEC4, location, 1);
6227}
6228
Jamie Madill5b772312018-03-08 20:28:32 -05006229bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006230{
6231 return ValidateUniform(context, GL_INT_VEC4, location, count);
6232}
6233
Jamie Madill5b772312018-03-08 20:28:32 -05006234bool ValidateUniformMatrix2fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006235 GLint location,
6236 GLsizei count,
6237 GLboolean transpose,
6238 const GLfloat *value)
6239{
6240 return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose);
6241}
6242
Jamie Madill5b772312018-03-08 20:28:32 -05006243bool ValidateUniformMatrix3fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006244 GLint location,
6245 GLsizei count,
6246 GLboolean transpose,
6247 const GLfloat *value)
6248{
6249 return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose);
6250}
6251
Jamie Madill5b772312018-03-08 20:28:32 -05006252bool ValidateUniformMatrix4fv(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006253 GLint location,
6254 GLsizei count,
6255 GLboolean transpose,
6256 const GLfloat *value)
6257{
6258 return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose);
6259}
6260
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006261bool ValidateValidateProgram(Context *context, ShaderProgramID program)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006262{
6263 Program *programObject = GetValidProgram(context, program);
6264
6265 if (!programObject)
6266 {
6267 return false;
6268 }
6269
6270 return true;
6271}
6272
Jamie Madill5b772312018-03-08 20:28:32 -05006273bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006274{
6275 return ValidateVertexAttribIndex(context, index);
6276}
6277
Jamie Madill5b772312018-03-08 20:28:32 -05006278bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006279{
6280 return ValidateVertexAttribIndex(context, index);
6281}
6282
Jamie Madill5b772312018-03-08 20:28:32 -05006283bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006284{
6285 return ValidateVertexAttribIndex(context, index);
6286}
6287
Jamie Madill5b772312018-03-08 20:28:32 -05006288bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006289{
6290 return ValidateVertexAttribIndex(context, index);
6291}
6292
Jamie Madill5b772312018-03-08 20:28:32 -05006293bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006294{
6295 return ValidateVertexAttribIndex(context, index);
6296}
6297
Jamie Madill5b772312018-03-08 20:28:32 -05006298bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006299{
6300 return ValidateVertexAttribIndex(context, index);
6301}
6302
Jamie Madill5b772312018-03-08 20:28:32 -05006303bool ValidateVertexAttrib4f(Context *context,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006304 GLuint index,
6305 GLfloat x,
6306 GLfloat y,
6307 GLfloat z,
6308 GLfloat w)
6309{
6310 return ValidateVertexAttribIndex(context, index);
6311}
6312
Jamie Madill5b772312018-03-08 20:28:32 -05006313bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006314{
6315 return ValidateVertexAttribIndex(context, index);
6316}
6317
Jamie Madill5b772312018-03-08 20:28:32 -05006318bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006319{
6320 if (width < 0 || height < 0)
6321 {
Jamie Madille0472f32018-11-27 16:32:45 -05006322 context->validationError(GL_INVALID_VALUE, kViewportNegativeSize);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006323 return false;
6324 }
6325
6326 return true;
6327}
6328
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08006329bool ValidateGetFramebufferAttachmentParameteriv(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006330 GLenum target,
6331 GLenum attachment,
6332 GLenum pname,
6333 GLint *params)
6334{
6335 return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname,
6336 nullptr);
6337}
6338
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006339bool ValidateGetProgramiv(Context *context, ShaderProgramID program, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006340{
6341 return ValidateGetProgramivBase(context, program, pname, nullptr);
6342}
6343
Jamie Madill5b772312018-03-08 20:28:32 -05006344bool ValidateCopyTexImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006345 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006346 GLint level,
6347 GLenum internalformat,
6348 GLint x,
6349 GLint y,
6350 GLsizei width,
6351 GLsizei height,
6352 GLint border)
6353{
6354 if (context->getClientMajorVersion() < 3)
6355 {
6356 return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0,
6357 0, x, y, width, height, border);
6358 }
6359
6360 ASSERT(context->getClientMajorVersion() == 3);
6361 return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
6362 0, x, y, width, height, border);
6363}
6364
6365bool ValidateCopyTexSubImage2D(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006366 TextureTarget target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006367 GLint level,
6368 GLint xoffset,
6369 GLint yoffset,
6370 GLint x,
6371 GLint y,
6372 GLsizei width,
6373 GLsizei height)
6374{
6375 if (context->getClientMajorVersion() < 3)
6376 {
6377 return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
6378 yoffset, x, y, width, height, 0);
6379 }
6380
6381 return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
6382 yoffset, 0, x, y, width, height, 0);
6383}
6384
Cody Northrop5faff912019-06-28 14:04:50 -06006385bool ValidateCopyTexSubImage3DOES(Context *context,
6386 TextureTarget target,
6387 GLint level,
6388 GLint xoffset,
6389 GLint yoffset,
6390 GLint zoffset,
6391 GLint x,
6392 GLint y,
6393 GLsizei width,
6394 GLsizei height)
6395{
6396 return ValidateCopyTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, x, y, width,
6397 height);
6398}
6399
Jamie Madill3b3fe832019-08-06 17:44:12 -04006400bool ValidateDeleteBuffers(Context *context, GLint n, const BufferID *buffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006401{
6402 return ValidateGenOrDelete(context, n);
6403}
6404
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06006405bool ValidateDeleteFramebuffers(Context *context, GLint n, const FramebufferID *framebuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006406{
6407 return ValidateGenOrDelete(context, n);
6408}
6409
Jamie Madill7c7dec02019-08-06 17:44:11 -04006410bool ValidateDeleteRenderbuffers(Context *context, GLint n, const RenderbufferID *renderbuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006411{
6412 return ValidateGenOrDelete(context, n);
6413}
6414
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006415bool ValidateDeleteTextures(Context *context, GLint n, const TextureID *textures)
Jamie Madillbe849e42017-05-02 15:49:00 -04006416{
6417 return ValidateGenOrDelete(context, n);
6418}
6419
6420bool ValidateDisable(Context *context, GLenum cap)
6421{
6422 if (!ValidCap(context, cap, false))
6423 {
Jamie Madille0472f32018-11-27 16:32:45 -05006424 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006425 return false;
6426 }
6427
6428 return true;
6429}
6430
6431bool ValidateEnable(Context *context, GLenum cap)
6432{
6433 if (!ValidCap(context, cap, false))
6434 {
Jamie Madille0472f32018-11-27 16:32:45 -05006435 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006436 return false;
6437 }
6438
6439 if (context->getLimitations().noSampleAlphaToCoverageSupport &&
6440 cap == GL_SAMPLE_ALPHA_TO_COVERAGE)
6441 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006442 context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation);
Jamie Madillbe849e42017-05-02 15:49:00 -04006443
6444 // We also output an error message to the debugger window if tracing is active, so that
6445 // developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05006446 ERR() << kNoSampleAlphaToCoveragesLimitation;
Jamie Madillbe849e42017-05-02 15:49:00 -04006447 return false;
6448 }
6449
6450 return true;
6451}
6452
6453bool ValidateFramebufferRenderbuffer(Context *context,
6454 GLenum target,
6455 GLenum attachment,
6456 GLenum renderbuffertarget,
Jamie Madill7c7dec02019-08-06 17:44:11 -04006457 RenderbufferID renderbuffer)
Jamie Madillbe849e42017-05-02 15:49:00 -04006458{
Geoff Lange8afa902017-09-27 15:00:43 -04006459 if (!ValidFramebufferTarget(context, target))
Jamie Madillbe849e42017-05-02 15:49:00 -04006460 {
Jamie Madille0472f32018-11-27 16:32:45 -05006461 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
Brandon Jones6cad5662017-06-14 13:25:13 -07006462 return false;
6463 }
6464
Jamie Madill7c7dec02019-08-06 17:44:11 -04006465 if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer.value != 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006466 {
Jamie Madille0472f32018-11-27 16:32:45 -05006467 context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006468 return false;
6469 }
6470
6471 return ValidateFramebufferRenderbufferParameters(context, target, attachment,
6472 renderbuffertarget, renderbuffer);
6473}
6474
6475bool ValidateFramebufferTexture2D(Context *context,
6476 GLenum target,
6477 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006478 TextureTarget textarget,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006479 TextureID texture,
Jamie Madillbe849e42017-05-02 15:49:00 -04006480 GLint level)
6481{
6482 // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap
6483 // extension
6484 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6485 level != 0)
6486 {
Jamie Madille0472f32018-11-27 16:32:45 -05006487 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006488 return false;
6489 }
6490
6491 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6492 {
6493 return false;
6494 }
6495
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006496 if (texture.value != 0)
Jamie Madillbe849e42017-05-02 15:49:00 -04006497 {
6498 gl::Texture *tex = context->getTexture(texture);
6499 ASSERT(tex);
6500
6501 const gl::Caps &caps = context->getCaps();
6502
6503 switch (textarget)
6504 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006505 case TextureTarget::_2D:
Jamie Madillbe849e42017-05-02 15:49:00 -04006506 {
6507 if (level > gl::log2(caps.max2DTextureSize))
6508 {
Jamie Madille0472f32018-11-27 16:32:45 -05006509 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006510 return false;
6511 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006512 if (tex->getType() != TextureType::_2D)
Jamie Madillbe849e42017-05-02 15:49:00 -04006513 {
Jamie Madille0472f32018-11-27 16:32:45 -05006514 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006515 return false;
6516 }
6517 }
6518 break;
6519
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006520 case TextureTarget::Rectangle:
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006521 {
6522 if (level != 0)
6523 {
Jamie Madille0472f32018-11-27 16:32:45 -05006524 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006525 return false;
6526 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006527 if (tex->getType() != TextureType::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006528 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006529 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Corentin Wallez13c0dd42017-07-04 18:27:01 -04006530 return false;
6531 }
6532 }
6533 break;
6534
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006535 case TextureTarget::CubeMapNegativeX:
6536 case TextureTarget::CubeMapNegativeY:
6537 case TextureTarget::CubeMapNegativeZ:
6538 case TextureTarget::CubeMapPositiveX:
6539 case TextureTarget::CubeMapPositiveY:
6540 case TextureTarget::CubeMapPositiveZ:
Jamie Madillbe849e42017-05-02 15:49:00 -04006541 {
6542 if (level > gl::log2(caps.maxCubeMapTextureSize))
6543 {
Jamie Madille0472f32018-11-27 16:32:45 -05006544 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
Jamie Madillbe849e42017-05-02 15:49:00 -04006545 return false;
6546 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006547 if (tex->getType() != TextureType::CubeMap)
Jamie Madillbe849e42017-05-02 15:49:00 -04006548 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006549 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006550 return false;
6551 }
6552 }
6553 break;
6554
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006555 case TextureTarget::_2DMultisample:
Jamie Madillbe849e42017-05-02 15:49:00 -04006556 {
Yizhou Jiang7818a852018-09-06 15:02:04 +08006557 if (context->getClientVersion() < ES_3_1 &&
6558 !context->getExtensions().textureMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006559 {
Jamie Madill610640f2018-11-21 17:28:41 -05006560 context->validationError(GL_INVALID_OPERATION,
Jamie Madille0472f32018-11-27 16:32:45 -05006561 kMultisampleTextureExtensionOrES31Required);
Jamie Madillbe849e42017-05-02 15:49:00 -04006562 return false;
6563 }
6564
6565 if (level != 0)
6566 {
Jamie Madille0472f32018-11-27 16:32:45 -05006567 context->validationError(GL_INVALID_VALUE, kLevelNotZero);
Jamie Madillbe849e42017-05-02 15:49:00 -04006568 return false;
6569 }
Corentin Wallez99d492c2018-02-27 15:17:10 -05006570 if (tex->getType() != TextureType::_2DMultisample)
Jamie Madillbe849e42017-05-02 15:49:00 -04006571 {
Jamie Madillc3e37312018-11-30 15:25:39 -05006572 context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch);
Jamie Madillbe849e42017-05-02 15:49:00 -04006573 return false;
6574 }
6575 }
6576 break;
6577
6578 default:
Jamie Madille0472f32018-11-27 16:32:45 -05006579 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006580 return false;
6581 }
Jamie Madillbe849e42017-05-02 15:49:00 -04006582 }
6583
6584 return true;
6585}
6586
Cody Northrop5faff912019-06-28 14:04:50 -06006587bool ValidateFramebufferTexture3DOES(Context *context,
6588 GLenum target,
6589 GLenum attachment,
6590 TextureTarget textargetPacked,
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006591 TextureID texture,
Cody Northrop5faff912019-06-28 14:04:50 -06006592 GLint level,
6593 GLint zoffset)
6594{
Cody Northrop90958e32019-08-07 16:26:14 -06006595 // We don't call into a base ValidateFramebufferTexture3D here because
6596 // it doesn't exist for OpenGL ES. This function is replaced by
6597 // FramebufferTextureLayer in ES 3.x, which has broader support.
6598 if (!context->getExtensions().texture3DOES)
6599 {
6600 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
6601 return false;
6602 }
6603
6604 // Attachments are required to be bound to level 0 without ES3 or the
6605 // GL_OES_fbo_render_mipmap extension
6606 if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap &&
6607 level != 0)
6608 {
6609 context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel);
6610 return false;
6611 }
6612
6613 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
6614 {
6615 return false;
6616 }
6617
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006618 if (texture.value != 0)
Cody Northrop90958e32019-08-07 16:26:14 -06006619 {
6620 gl::Texture *tex = context->getTexture(texture);
6621 ASSERT(tex);
6622
6623 const gl::Caps &caps = context->getCaps();
6624
6625 switch (textargetPacked)
6626 {
6627 case TextureTarget::_3D:
6628 {
6629 if (level > gl::log2(caps.max3DTextureSize))
6630 {
6631 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
6632 return false;
6633 }
6634 if (static_cast<size_t>(zoffset) >= caps.max3DTextureSize)
6635 {
6636 context->validationError(GL_INVALID_VALUE, kInvalidZOffset);
6637 return false;
6638 }
6639 if (tex->getType() != TextureType::_3D)
6640 {
6641 context->validationError(GL_INVALID_OPERATION, kInvalidTextureType);
6642 return false;
6643 }
6644 }
6645 break;
6646
6647 default:
6648 context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
6649 return false;
6650 }
6651 }
6652
6653 return true;
Cody Northrop5faff912019-06-28 14:04:50 -06006654}
6655
Jamie Madill3b3fe832019-08-06 17:44:12 -04006656bool ValidateGenBuffers(Context *context, GLint n, BufferID *buffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006657{
6658 return ValidateGenOrDelete(context, n);
6659}
6660
Jiacheng Lu2c5d48a2019-08-23 09:28:35 -06006661bool ValidateGenFramebuffers(Context *context, GLint n, FramebufferID *framebuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006662{
6663 return ValidateGenOrDelete(context, n);
6664}
6665
Jamie Madill7c7dec02019-08-06 17:44:11 -04006666bool ValidateGenRenderbuffers(Context *context, GLint n, RenderbufferID *renderbuffers)
Jamie Madillbe849e42017-05-02 15:49:00 -04006667{
6668 return ValidateGenOrDelete(context, n);
6669}
6670
Jamie Madill2ab08ed2019-08-12 16:20:21 -04006671bool ValidateGenTextures(Context *context, GLint n, TextureID *textures)
Jamie Madillbe849e42017-05-02 15:49:00 -04006672{
6673 return ValidateGenOrDelete(context, n);
6674}
6675
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006676bool ValidateGenerateMipmap(Context *context, TextureType target)
Jamie Madillbe849e42017-05-02 15:49:00 -04006677{
6678 if (!ValidTextureTarget(context, target))
6679 {
Jamie Madille0472f32018-11-27 16:32:45 -05006680 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
Jamie Madillbe849e42017-05-02 15:49:00 -04006681 return false;
6682 }
6683
Jamie Madillcfc73cc2019-04-08 16:26:51 -04006684 Texture *texture = context->getTextureByType(target);
Jamie Madillbe849e42017-05-02 15:49:00 -04006685
6686 if (texture == nullptr)
6687 {
Jamie Madille0472f32018-11-27 16:32:45 -05006688 context->validationError(GL_INVALID_OPERATION, kTextureNotBound);
Jamie Madillbe849e42017-05-02 15:49:00 -04006689 return false;
6690 }
6691
6692 const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel();
6693
6694 // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so
6695 // that out-of-range base level has a non-color-renderable / non-texture-filterable format.
6696 if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
6697 {
Jamie Madille0472f32018-11-27 16:32:45 -05006698 context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange);
Jamie Madillbe849e42017-05-02 15:49:00 -04006699 return false;
6700 }
6701
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006702 TextureTarget baseTarget = (target == TextureType::CubeMap)
6703 ? TextureTarget::CubeMapPositiveX
6704 : NonCubeTextureTypeToTarget(target);
Geoff Lang536eca12017-09-13 11:23:35 -04006705 const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
6706 if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
6707 format.stencilBits > 0)
Brandon Jones6cad5662017-06-14 13:25:13 -07006708 {
Jamie Madille0472f32018-11-27 16:32:45 -05006709 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Brandon Jones6cad5662017-06-14 13:25:13 -07006710 return false;
6711 }
6712
Geoff Lang536eca12017-09-13 11:23:35 -04006713 // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
6714 bool formatUnsized = !format.sized;
6715 bool formatColorRenderableAndFilterable =
6716 format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
Yuly Novikovf15f8862018-06-04 18:59:41 -04006717 format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions());
Geoff Lang536eca12017-09-13 11:23:35 -04006718 if (!formatUnsized && !formatColorRenderableAndFilterable)
Jamie Madillbe849e42017-05-02 15:49:00 -04006719 {
Jamie Madille0472f32018-11-27 16:32:45 -05006720 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006721 return false;
6722 }
6723
Geoff Lang536eca12017-09-13 11:23:35 -04006724 // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
6725 // generation
6726 if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
6727 {
Jamie Madille0472f32018-11-27 16:32:45 -05006728 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Geoff Lang536eca12017-09-13 11:23:35 -04006729 return false;
6730 }
6731
Jiange2c00842018-07-13 16:50:49 +08006732 // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and
6733 // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT.
6734 if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB)
Jamie Madillbe849e42017-05-02 15:49:00 -04006735 {
Jamie Madille0472f32018-11-27 16:32:45 -05006736 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed);
Jamie Madillbe849e42017-05-02 15:49:00 -04006737 return false;
6738 }
6739
6740 // Non-power of 2 ES2 check
6741 if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT &&
6742 (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) ||
6743 !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0)))))
6744 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006745 ASSERT(target == TextureType::_2D || target == TextureType::Rectangle ||
6746 target == TextureType::CubeMap);
Jamie Madille0472f32018-11-27 16:32:45 -05006747 context->validationError(GL_INVALID_OPERATION, kTextureNotPow2);
Jamie Madillbe849e42017-05-02 15:49:00 -04006748 return false;
6749 }
6750
6751 // Cube completeness check
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006752 if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete())
Jamie Madillbe849e42017-05-02 15:49:00 -04006753 {
Jamie Madille0472f32018-11-27 16:32:45 -05006754 context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete);
Jamie Madillbe849e42017-05-02 15:49:00 -04006755 return false;
6756 }
6757
James Darpinian83b2f0e2018-11-27 15:56:01 -08006758 if (context->getExtensions().webglCompatibility &&
6759 (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 ||
6760 texture->getHeight(baseTarget, effectiveBaseLevel) == 0))
6761 {
6762 context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize);
6763 return false;
6764 }
6765
Jamie Madillbe849e42017-05-02 15:49:00 -04006766 return true;
6767}
6768
Jamie Madill5b772312018-03-08 20:28:32 -05006769bool ValidateGetBufferParameteriv(Context *context,
Corentin Wallez336129f2017-10-17 15:55:40 -04006770 BufferBinding target,
Jamie Madillbe849e42017-05-02 15:49:00 -04006771 GLenum pname,
6772 GLint *params)
6773{
6774 return ValidateGetBufferParameterBase(context, target, pname, false, nullptr);
6775}
6776
6777bool ValidateGetRenderbufferParameteriv(Context *context,
6778 GLenum target,
6779 GLenum pname,
6780 GLint *params)
6781{
6782 return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr);
6783}
6784
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006785bool ValidateGetShaderiv(Context *context, ShaderProgramID shader, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006786{
6787 return ValidateGetShaderivBase(context, shader, pname, nullptr);
6788}
6789
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006790bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006791{
6792 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6793}
6794
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006795bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006796{
6797 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6798}
6799
Till Rathmannb8543632018-10-02 19:46:14 +02006800bool ValidateGetTexParameterIivOES(Context *context,
6801 TextureType target,
6802 GLenum pname,
6803 GLint *params)
6804{
6805 if (context->getClientMajorVersion() < 3)
6806 {
Jamie Madille0472f32018-11-27 16:32:45 -05006807 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006808 return false;
6809 }
6810 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6811}
6812
6813bool ValidateGetTexParameterIuivOES(Context *context,
6814 TextureType target,
6815 GLenum pname,
6816 GLuint *params)
6817{
6818 if (context->getClientMajorVersion() < 3)
6819 {
Jamie Madille0472f32018-11-27 16:32:45 -05006820 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006821 return false;
6822 }
6823 return ValidateGetTexParameterBase(context, target, pname, nullptr);
6824}
6825
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006826bool ValidateGetUniformfv(Context *context,
6827 ShaderProgramID program,
6828 GLint location,
6829 GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006830{
6831 return ValidateGetUniformBase(context, program, location);
6832}
6833
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006834bool ValidateGetUniformiv(Context *context, ShaderProgramID program, GLint location, GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006835{
6836 return ValidateGetUniformBase(context, program, location);
6837}
6838
6839bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params)
6840{
6841 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6842}
6843
6844bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params)
6845{
6846 return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false);
6847}
6848
6849bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer)
6850{
6851 return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false);
6852}
6853
6854bool ValidateIsEnabled(Context *context, GLenum cap)
6855{
6856 if (!ValidCap(context, cap, true))
6857 {
Jamie Madille0472f32018-11-27 16:32:45 -05006858 context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
Jamie Madillbe849e42017-05-02 15:49:00 -04006859 return false;
6860 }
6861
6862 return true;
6863}
6864
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006865bool ValidateLinkProgram(Context *context, ShaderProgramID program)
Jamie Madillbe849e42017-05-02 15:49:00 -04006866{
6867 if (context->hasActiveTransformFeedback(program))
6868 {
6869 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006870 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink);
Jamie Madillbe849e42017-05-02 15:49:00 -04006871 return false;
6872 }
6873
6874 Program *programObject = GetValidProgram(context, program);
6875 if (!programObject)
6876 {
6877 return false;
6878 }
6879
6880 return true;
6881}
6882
Jamie Madill4928b7c2017-06-20 12:57:39 -04006883bool ValidateReadPixels(Context *context,
Jamie Madillbe849e42017-05-02 15:49:00 -04006884 GLint x,
6885 GLint y,
6886 GLsizei width,
6887 GLsizei height,
6888 GLenum format,
6889 GLenum type,
6890 void *pixels)
6891{
6892 return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr,
6893 nullptr, pixels);
6894}
6895
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006896bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006897{
Till Rathmannb8543632018-10-02 19:46:14 +02006898 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006899}
6900
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006901bool ValidateTexParameterfv(Context *context,
6902 TextureType target,
6903 GLenum pname,
6904 const GLfloat *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006905{
Till Rathmannb8543632018-10-02 19:46:14 +02006906 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006907}
6908
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006909bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
Jamie Madillbe849e42017-05-02 15:49:00 -04006910{
Till Rathmannb8543632018-10-02 19:46:14 +02006911 return ValidateTexParameterBase(context, target, pname, -1, false, &param);
Jamie Madillbe849e42017-05-02 15:49:00 -04006912}
6913
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006914bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
Jamie Madillbe849e42017-05-02 15:49:00 -04006915{
Till Rathmannb8543632018-10-02 19:46:14 +02006916 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6917}
6918
6919bool ValidateTexParameterIivOES(Context *context,
6920 TextureType target,
6921 GLenum pname,
6922 const GLint *params)
6923{
6924 if (context->getClientMajorVersion() < 3)
6925 {
Jamie Madille0472f32018-11-27 16:32:45 -05006926 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006927 return false;
6928 }
6929 return ValidateTexParameterBase(context, target, pname, -1, true, params);
6930}
6931
6932bool ValidateTexParameterIuivOES(Context *context,
6933 TextureType target,
6934 GLenum pname,
6935 const GLuint *params)
6936{
6937 if (context->getClientMajorVersion() < 3)
6938 {
Jamie Madille0472f32018-11-27 16:32:45 -05006939 context->validationError(GL_INVALID_OPERATION, kES3Required);
Till Rathmannb8543632018-10-02 19:46:14 +02006940 return false;
6941 }
6942 return ValidateTexParameterBase(context, target, pname, -1, true, params);
Jamie Madillbe849e42017-05-02 15:49:00 -04006943}
6944
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006945bool ValidateUseProgram(Context *context, ShaderProgramID program)
Jamie Madillbe849e42017-05-02 15:49:00 -04006946{
Jiacheng Lu120b61d2019-08-21 12:51:58 -06006947 if (program.value != 0)
Jamie Madillbe849e42017-05-02 15:49:00 -04006948 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006949 Program *programObject = context->getProgramResolveLink(program);
Jamie Madillbe849e42017-05-02 15:49:00 -04006950 if (!programObject)
6951 {
6952 // ES 3.1.0 section 7.3 page 72
6953 if (context->getShader(program))
6954 {
Jamie Madille0472f32018-11-27 16:32:45 -05006955 context->validationError(GL_INVALID_OPERATION, kExpectedProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006956 return false;
6957 }
6958 else
6959 {
Jamie Madille0472f32018-11-27 16:32:45 -05006960 context->validationError(GL_INVALID_VALUE, kInvalidProgramName);
Jamie Madillbe849e42017-05-02 15:49:00 -04006961 return false;
6962 }
6963 }
6964 if (!programObject->isLinked())
6965 {
Jamie Madille0472f32018-11-27 16:32:45 -05006966 context->validationError(GL_INVALID_OPERATION, kProgramNotLinked);
Jamie Madillbe849e42017-05-02 15:49:00 -04006967 return false;
6968 }
6969 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006970 if (context->getState().isTransformFeedbackActiveUnpaused())
Jamie Madillbe849e42017-05-02 15:49:00 -04006971 {
6972 // ES 3.0.4 section 2.15 page 91
Jamie Madillc3e37312018-11-30 15:25:39 -05006973 context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram);
Jamie Madillbe849e42017-05-02 15:49:00 -04006974 return false;
6975 }
6976
6977 return true;
6978}
6979
Jiacheng Lu962503e2019-08-21 13:18:30 -06006980bool ValidateDeleteFencesNV(Context *context, GLsizei n, const FenceNVID *fences)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006981{
6982 if (!context->getExtensions().fence)
6983 {
Jamie Madille0472f32018-11-27 16:32:45 -05006984 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006985 return false;
6986 }
6987
6988 if (n < 0)
6989 {
Jamie Madille0472f32018-11-27 16:32:45 -05006990 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006991 return false;
6992 }
6993
6994 return true;
6995}
6996
Jiacheng Lu962503e2019-08-21 13:18:30 -06006997bool ValidateFinishFenceNV(Context *context, FenceNVID fence)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006998{
6999 if (!context->getExtensions().fence)
7000 {
Jamie Madille0472f32018-11-27 16:32:45 -05007001 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007002 return false;
7003 }
7004
7005 FenceNV *fenceObject = context->getFenceNV(fence);
7006
7007 if (fenceObject == nullptr)
7008 {
Jamie Madille0472f32018-11-27 16:32:45 -05007009 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007010 return false;
7011 }
7012
7013 if (!fenceObject->isSet())
7014 {
Jamie Madille0472f32018-11-27 16:32:45 -05007015 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007016 return false;
7017 }
7018
7019 return true;
7020}
7021
Jiacheng Lu962503e2019-08-21 13:18:30 -06007022bool ValidateGenFencesNV(Context *context, GLsizei n, FenceNVID *fences)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007023{
7024 if (!context->getExtensions().fence)
7025 {
Jamie Madille0472f32018-11-27 16:32:45 -05007026 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007027 return false;
7028 }
7029
7030 if (n < 0)
7031 {
Jamie Madille0472f32018-11-27 16:32:45 -05007032 context->validationError(GL_INVALID_VALUE, kNegativeCount);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007033 return false;
7034 }
7035
7036 return true;
7037}
7038
Jiacheng Lu962503e2019-08-21 13:18:30 -06007039bool ValidateGetFenceivNV(Context *context, FenceNVID fence, GLenum pname, GLint *params)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007040{
7041 if (!context->getExtensions().fence)
7042 {
Jamie Madille0472f32018-11-27 16:32:45 -05007043 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007044 return false;
7045 }
7046
7047 FenceNV *fenceObject = context->getFenceNV(fence);
7048
7049 if (fenceObject == nullptr)
7050 {
Jamie Madille0472f32018-11-27 16:32:45 -05007051 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007052 return false;
7053 }
7054
7055 if (!fenceObject->isSet())
7056 {
Jamie Madille0472f32018-11-27 16:32:45 -05007057 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007058 return false;
7059 }
7060
7061 switch (pname)
7062 {
7063 case GL_FENCE_STATUS_NV:
7064 case GL_FENCE_CONDITION_NV:
7065 break;
7066
7067 default:
Jamie Madille0472f32018-11-27 16:32:45 -05007068 context->validationError(GL_INVALID_ENUM, kInvalidPname);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007069 return false;
7070 }
7071
7072 return true;
7073}
7074
7075bool ValidateGetGraphicsResetStatusEXT(Context *context)
7076{
7077 if (!context->getExtensions().robustness)
7078 {
Jamie Madille0472f32018-11-27 16:32:45 -05007079 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007080 return false;
7081 }
7082
7083 return true;
7084}
7085
7086bool ValidateGetTranslatedShaderSourceANGLE(Context *context,
Jiacheng Lu120b61d2019-08-21 12:51:58 -06007087 ShaderProgramID shader,
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007088 GLsizei bufsize,
7089 GLsizei *length,
7090 GLchar *source)
7091{
7092 if (!context->getExtensions().translatedShaderSource)
7093 {
Jamie Madille0472f32018-11-27 16:32:45 -05007094 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007095 return false;
7096 }
7097
7098 if (bufsize < 0)
7099 {
Jamie Madille0472f32018-11-27 16:32:45 -05007100 context->validationError(GL_INVALID_VALUE, kNegativeBufferSize);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007101 return false;
7102 }
7103
7104 Shader *shaderObject = context->getShader(shader);
7105
7106 if (!shaderObject)
7107 {
Jamie Madille0472f32018-11-27 16:32:45 -05007108 context->validationError(GL_INVALID_OPERATION, kInvalidShaderName);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007109 return false;
7110 }
7111
7112 return true;
7113}
7114
Jiacheng Lu962503e2019-08-21 13:18:30 -06007115bool ValidateIsFenceNV(Context *context, FenceNVID fence)
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007116{
7117 if (!context->getExtensions().fence)
7118 {
Jamie Madille0472f32018-11-27 16:32:45 -05007119 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007120 return false;
7121 }
7122
7123 return true;
7124}
7125
Jiacheng Lu962503e2019-08-21 13:18:30 -06007126bool ValidateSetFenceNV(Context *context, FenceNVID fence, GLenum condition)
Jamie Madill007530e2017-12-28 14:27:04 -05007127{
7128 if (!context->getExtensions().fence)
7129 {
Jamie Madille0472f32018-11-27 16:32:45 -05007130 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05007131 return false;
7132 }
7133
7134 if (condition != GL_ALL_COMPLETED_NV)
7135 {
Jamie Madille0472f32018-11-27 16:32:45 -05007136 context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition);
Jamie Madill007530e2017-12-28 14:27:04 -05007137 return false;
7138 }
7139
7140 FenceNV *fenceObject = context->getFenceNV(fence);
7141
7142 if (fenceObject == nullptr)
7143 {
Jamie Madille0472f32018-11-27 16:32:45 -05007144 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05007145 return false;
7146 }
7147
7148 return true;
7149}
7150
Jiacheng Lu962503e2019-08-21 13:18:30 -06007151bool ValidateTestFenceNV(Context *context, FenceNVID fence)
Jamie Madill007530e2017-12-28 14:27:04 -05007152{
7153 if (!context->getExtensions().fence)
7154 {
Jamie Madille0472f32018-11-27 16:32:45 -05007155 context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported);
Jamie Madill007530e2017-12-28 14:27:04 -05007156 return false;
7157 }
7158
7159 FenceNV *fenceObject = context->getFenceNV(fence);
7160
7161 if (fenceObject == nullptr)
7162 {
Jamie Madille0472f32018-11-27 16:32:45 -05007163 context->validationError(GL_INVALID_OPERATION, kInvalidFence);
Jamie Madill007530e2017-12-28 14:27:04 -05007164 return false;
7165 }
7166
7167 if (fenceObject->isSet() != GL_TRUE)
7168 {
Jamie Madille0472f32018-11-27 16:32:45 -05007169 context->validationError(GL_INVALID_OPERATION, kInvalidFenceState);
Jamie Madill007530e2017-12-28 14:27:04 -05007170 return false;
7171 }
7172
7173 return true;
7174}
7175
7176bool ValidateTexStorage2DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007177 TextureType type,
Jamie Madill007530e2017-12-28 14:27:04 -05007178 GLsizei levels,
7179 GLenum internalformat,
7180 GLsizei width,
7181 GLsizei height)
7182{
7183 if (!context->getExtensions().textureStorage)
7184 {
Jamie Madille0472f32018-11-27 16:32:45 -05007185 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007186 return false;
7187 }
7188
7189 if (context->getClientMajorVersion() < 3)
7190 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007191 return ValidateES2TexStorageParameters(context, type, levels, internalformat, width,
Jamie Madill007530e2017-12-28 14:27:04 -05007192 height);
7193 }
7194
7195 ASSERT(context->getClientMajorVersion() >= 3);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007196 return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height,
Jamie Madill007530e2017-12-28 14:27:04 -05007197 1);
7198}
7199
7200bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor)
7201{
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05007202 if (!context->getExtensions().instancedArraysANGLE)
Jamie Madill007530e2017-12-28 14:27:04 -05007203 {
Jamie Madille0472f32018-11-27 16:32:45 -05007204 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007205 return false;
7206 }
7207
7208 if (index >= MAX_VERTEX_ATTRIBS)
7209 {
Jamie Madille0472f32018-11-27 16:32:45 -05007210 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
Jamie Madill007530e2017-12-28 14:27:04 -05007211 return false;
7212 }
7213
7214 if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT)
7215 {
7216 if (index == 0 && divisor != 0)
7217 {
Jamie Madillc3e37312018-11-30 15:25:39 -05007218 context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation);
Jamie Madill007530e2017-12-28 14:27:04 -05007219
7220 // We also output an error message to the debugger window if tracing is active, so
7221 // that developers can see the error message.
Jamie Madillc3e37312018-11-30 15:25:39 -05007222 ERR() << kAttributeZeroRequiresDivisorLimitation;
Jamie Madill007530e2017-12-28 14:27:04 -05007223 return false;
7224 }
7225 }
7226
7227 return true;
7228}
7229
Jonah Ryan-Davis2b0553c2019-02-08 10:07:21 -05007230bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor)
7231{
7232 if (!context->getExtensions().instancedArraysEXT)
7233 {
7234 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7235 return false;
7236 }
7237
7238 if (index >= MAX_VERTEX_ATTRIBS)
7239 {
7240 context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute);
7241 return false;
7242 }
7243
7244 return true;
7245}
7246
Jamie Madill007530e2017-12-28 14:27:04 -05007247bool ValidateTexImage3DOES(Context *context,
Cody Northrop5faff912019-06-28 14:04:50 -06007248 TextureTarget target,
Jamie Madill007530e2017-12-28 14:27:04 -05007249 GLint level,
7250 GLenum internalformat,
7251 GLsizei width,
7252 GLsizei height,
7253 GLsizei depth,
7254 GLint border,
7255 GLenum format,
7256 GLenum type,
7257 const void *pixels)
7258{
Cody Northrop5faff912019-06-28 14:04:50 -06007259 return ValidateTexImage3D(context, target, level, internalformat, width, height, depth, border,
7260 format, type, pixels);
Jamie Madill007530e2017-12-28 14:27:04 -05007261}
7262
7263bool ValidatePopGroupMarkerEXT(Context *context)
7264{
7265 if (!context->getExtensions().debugMarker)
7266 {
7267 // The debug marker calls should not set error state
7268 // However, it seems reasonable to set an error state if the extension is not enabled
Jamie Madille0472f32018-11-27 16:32:45 -05007269 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madill007530e2017-12-28 14:27:04 -05007270 return false;
7271 }
7272
7273 return true;
7274}
7275
Jamie Madillfa920eb2018-01-04 11:45:50 -05007276bool ValidateTexStorage1DEXT(Context *context,
7277 GLenum target,
7278 GLsizei levels,
7279 GLenum internalformat,
7280 GLsizei width)
7281{
7282 UNIMPLEMENTED();
Jamie Madille0472f32018-11-27 16:32:45 -05007283 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007284 return false;
7285}
7286
7287bool ValidateTexStorage3DEXT(Context *context,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007288 TextureType target,
Jamie Madillfa920eb2018-01-04 11:45:50 -05007289 GLsizei levels,
7290 GLenum internalformat,
7291 GLsizei width,
7292 GLsizei height,
7293 GLsizei depth)
7294{
7295 if (!context->getExtensions().textureStorage)
7296 {
Jamie Madille0472f32018-11-27 16:32:45 -05007297 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007298 return false;
7299 }
7300
7301 if (context->getClientMajorVersion() < 3)
7302 {
Jamie Madille0472f32018-11-27 16:32:45 -05007303 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Jamie Madillfa920eb2018-01-04 11:45:50 -05007304 return false;
7305 }
7306
7307 return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height,
7308 depth);
7309}
7310
jchen1082af6202018-06-22 10:59:52 +08007311bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count)
7312{
7313 if (!context->getExtensions().parallelShaderCompile)
7314 {
Jamie Madille0472f32018-11-27 16:32:45 -05007315 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
jchen1082af6202018-06-22 10:59:52 +08007316 return false;
7317 }
7318 return true;
7319}
7320
Austin Eng1bf18ce2018-10-19 15:34:02 -07007321bool ValidateMultiDrawArraysANGLE(Context *context,
7322 PrimitiveMode mode,
7323 const GLint *firsts,
7324 const GLsizei *counts,
7325 GLsizei drawcount)
7326{
7327 if (!context->getExtensions().multiDraw)
7328 {
Jamie Madille0472f32018-11-27 16:32:45 -05007329 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007330 return false;
7331 }
7332 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7333 {
7334 if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID]))
7335 {
7336 return false;
7337 }
7338 }
7339 return true;
7340}
7341
7342bool ValidateMultiDrawElementsANGLE(Context *context,
7343 PrimitiveMode mode,
7344 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05007345 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08007346 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07007347 GLsizei drawcount)
7348{
7349 if (!context->getExtensions().multiDraw)
7350 {
Jamie Madille0472f32018-11-27 16:32:45 -05007351 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
Austin Eng1bf18ce2018-10-19 15:34:02 -07007352 return false;
7353 }
7354 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
7355 {
Austin Eng3b7c9d02018-11-21 18:09:05 -08007356 if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID]))
Austin Eng1bf18ce2018-10-19 15:34:02 -07007357 {
7358 return false;
7359 }
7360 }
7361 return true;
7362}
7363
Clemen Dengce330592019-07-16 10:02:21 -04007364bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertexConvention modePacked)
Jeff Gilbert465d6092019-01-02 16:21:18 -08007365{
7366 if (!context->getExtensions().provokingVertex)
7367 {
7368 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7369 return false;
7370 }
7371
7372 switch (modePacked)
7373 {
Clemen Dengce330592019-07-16 10:02:21 -04007374 case ProvokingVertexConvention::FirstVertexConvention:
7375 case ProvokingVertexConvention::LastVertexConvention:
Jeff Gilbert465d6092019-01-02 16:21:18 -08007376 break;
7377 default:
7378 context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex);
7379 return false;
7380 }
7381
7382 return true;
7383}
7384
Mingyu Hu7e44ec22019-08-26 15:59:48 -07007385bool ValidateFramebufferTexture2DMultisampleEXT(Context *context,
7386 GLenum target,
7387 GLenum attachment,
7388 GLenum textarget,
7389 GLuint texture,
7390 GLint level,
7391 GLsizei samples)
7392{
Mingyu Hu2d0e5b52019-08-27 13:49:07 -07007393 if (!context->getExtensions().multisampledRenderToTexture)
7394 {
7395 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7396 return false;
7397 }
7398
7399 if (samples < 0)
7400 {
7401 return false;
7402 }
7403
7404 // EXT_multisampled_render_to_texture states that the value of samples
7405 // must be less than or equal to MAX_SAMPLES_EXT (Context::getCaps().maxSamples)
7406 // otherwise GL_INVALID_VALUE is generated.
7407 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
7408 {
7409 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
7410 return false;
7411 }
7412
7413 if (!ValidFramebufferTarget(context, target))
7414 {
7415 context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget);
7416 return false;
7417 }
7418
7419 if (attachment != GL_COLOR_ATTACHMENT0)
7420 {
7421 context->validationError(GL_INVALID_ENUM, kInvalidAttachment);
7422 return false;
7423 }
7424
7425 TextureTarget textargetPacked = FromGLenum<TextureTarget>(textarget);
7426 if (!ValidTexture2DDestinationTarget(context, textargetPacked))
7427 {
7428 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
7429 return false;
7430 }
7431
7432 if (texture != 0)
7433 {
7434 TextureID texturePacked = FromGL<TextureID>(texture);
7435 Texture *tex = context->getTexture(texturePacked);
7436
7437 if (tex == nullptr)
7438 {
7439 context->validationError(GL_INVALID_OPERATION, kMissingTexture);
7440 return false;
7441 }
7442
7443 if (level < 0)
7444 {
7445 context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
7446 return false;
7447 }
7448
7449 // EXT_multisampled_render_to_texture returns INVALID_OPERATION when a sample number higher
7450 // than the maximum sample number supported by this format is passed.
7451 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is
7452 // ES3.
7453 if (context->getClientMajorVersion() >= 3)
7454 {
7455 GLenum internalformat = tex->getFormat(textargetPacked, level).info->internalFormat;
7456 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7457 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
7458 {
7459 context->validationError(GL_INVALID_OPERATION, kSamplesOutOfRange);
7460 return false;
7461 }
7462 }
7463 }
7464
Mingyu Hu7e44ec22019-08-26 15:59:48 -07007465 return true;
7466}
7467
7468bool ValidateRenderbufferStorageMultisampleEXT(Context *context,
7469 GLenum target,
7470 GLsizei samples,
7471 GLenum internalformat,
7472 GLsizei width,
7473 GLsizei height)
7474{
Mingyu Hu2d0e5b52019-08-27 13:49:07 -07007475 if (!context->getExtensions().multisampledRenderToTexture)
7476 {
7477 context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
7478 return false;
7479 }
7480 if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width,
7481 height))
7482 {
7483 return false;
7484 }
7485
7486 // EXT_multisampled_render_to_texture states that the value of samples
7487 // must be less than or equal to MAX_SAMPLES_EXT (Context::getCaps().maxSamples)
7488 // otherwise GL_INVALID_VALUE is generated.
7489 if (static_cast<GLuint>(samples) > context->getCaps().maxSamples)
7490 {
7491 context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange);
7492 return false;
7493 }
7494
7495 // EXT_multisampled_render_to_texture returns GL_OUT_OF_MEMORY on failure to create
7496 // the specified storage. This is different than ES 3.0 in which a sample number higher
7497 // than the maximum sample number supported by this format generates a GL_INVALID_VALUE.
7498 // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3.
7499 if (context->getClientMajorVersion() >= 3)
7500 {
7501 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
7502 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
7503 {
7504 context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange);
7505 return false;
7506 }
7507 }
7508
Mingyu Hu7e44ec22019-08-26 15:59:48 -07007509 return true;
7510}
7511
Jamie Madilla5410482019-01-31 19:55:55 -05007512void RecordBindTextureTypeError(Context *context, TextureType target)
7513{
7514 ASSERT(!context->getStateCache().isValidBindTextureType(target));
7515
7516 switch (target)
7517 {
7518 case TextureType::Rectangle:
7519 ASSERT(!context->getExtensions().textureRectangle);
7520 context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported);
7521 break;
7522
7523 case TextureType::_3D:
7524 case TextureType::_2DArray:
7525 ASSERT(context->getClientMajorVersion() < 3);
7526 context->validationError(GL_INVALID_ENUM, kES3Required);
7527 break;
7528
7529 case TextureType::_2DMultisample:
7530 ASSERT(context->getClientVersion() < Version(3, 1) &&
7531 !context->getExtensions().textureMultisample);
7532 context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required);
7533 break;
7534
7535 case TextureType::_2DMultisampleArray:
7536 ASSERT(!context->getExtensions().textureStorageMultisample2DArray);
7537 context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired);
7538 break;
7539
7540 case TextureType::External:
7541 ASSERT(!context->getExtensions().eglImageExternal &&
7542 !context->getExtensions().eglStreamConsumerExternal);
7543 context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported);
7544 break;
7545
7546 default:
7547 context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
7548 }
7549}
7550
Jamie Madillc29968b2016-01-20 11:17:23 -05007551} // namespace gl