Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // 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 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES2.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 10 | |
| 11 | #include <cstdint> |
| 12 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 13 | #include "common/mathutil.h" |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 14 | #include "common/string_utils.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 15 | #include "common/utilities.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 16 | #include "libANGLE/Context.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 17 | #include "libANGLE/Framebuffer.h" |
| 18 | #include "libANGLE/FramebufferAttachment.h" |
| 19 | #include "libANGLE/Renderbuffer.h" |
| 20 | #include "libANGLE/Shader.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 21 | #include "libANGLE/Texture.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 22 | #include "libANGLE/Uniform.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 23 | #include "libANGLE/VertexArray.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 24 | #include "libANGLE/formatutils.h" |
| 25 | #include "libANGLE/validationES.h" |
| 26 | #include "libANGLE/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 27 | |
| 28 | namespace gl |
| 29 | { |
| 30 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 31 | namespace |
| 32 | { |
| 33 | |
| 34 | bool IsPartialBlit(gl::Context *context, |
| 35 | const FramebufferAttachment *readBuffer, |
| 36 | const FramebufferAttachment *writeBuffer, |
| 37 | GLint srcX0, |
| 38 | GLint srcY0, |
| 39 | GLint srcX1, |
| 40 | GLint srcY1, |
| 41 | GLint dstX0, |
| 42 | GLint dstY0, |
| 43 | GLint dstX1, |
| 44 | GLint dstY1) |
| 45 | { |
| 46 | const Extents &writeSize = writeBuffer->getSize(); |
| 47 | const Extents &readSize = readBuffer->getSize(); |
| 48 | |
| 49 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width || |
| 50 | dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height) |
| 51 | { |
| 52 | return true; |
| 53 | } |
| 54 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 55 | if (context->getGLState().isScissorTestEnabled()) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 56 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 57 | const Rectangle &scissor = context->getGLState().getScissor(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 58 | return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width || |
| 59 | scissor.height < writeSize.height; |
| 60 | } |
| 61 | |
| 62 | return false; |
| 63 | } |
| 64 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 65 | template <typename T> |
| 66 | bool ValidatePathInstances(gl::Context *context, |
| 67 | GLsizei numPaths, |
| 68 | const void *paths, |
| 69 | GLuint pathBase) |
| 70 | { |
| 71 | const auto *array = static_cast<const T *>(paths); |
| 72 | |
| 73 | for (GLsizei i = 0; i < numPaths; ++i) |
| 74 | { |
| 75 | const GLuint pathName = array[i] + pathBase; |
| 76 | if (context->hasPath(pathName) && !context->hasPathData(pathName)) |
| 77 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 78 | context->handleError(InvalidOperation() << "No such path object."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 79 | return false; |
| 80 | } |
| 81 | } |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | bool ValidateInstancedPathParameters(gl::Context *context, |
| 86 | GLsizei numPaths, |
| 87 | GLenum pathNameType, |
| 88 | const void *paths, |
| 89 | GLuint pathBase, |
| 90 | GLenum transformType, |
| 91 | const GLfloat *transformValues) |
| 92 | { |
| 93 | if (!context->getExtensions().pathRendering) |
| 94 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 95 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 96 | return false; |
| 97 | } |
| 98 | |
| 99 | if (paths == nullptr) |
| 100 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 101 | context->handleError(InvalidValue() << "No path name array."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 102 | return false; |
| 103 | } |
| 104 | |
| 105 | if (numPaths < 0) |
| 106 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 107 | context->handleError(InvalidValue() << "Invalid (negative) numPaths."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 108 | return false; |
| 109 | } |
| 110 | |
| 111 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths)) |
| 112 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 113 | context->handleError(InvalidOperation() << "Overflow in numPaths."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 114 | return false; |
| 115 | } |
| 116 | |
| 117 | std::uint32_t pathNameTypeSize = 0; |
| 118 | std::uint32_t componentCount = 0; |
| 119 | |
| 120 | switch (pathNameType) |
| 121 | { |
| 122 | case GL_UNSIGNED_BYTE: |
| 123 | pathNameTypeSize = sizeof(GLubyte); |
| 124 | if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase)) |
| 125 | return false; |
| 126 | break; |
| 127 | |
| 128 | case GL_BYTE: |
| 129 | pathNameTypeSize = sizeof(GLbyte); |
| 130 | if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase)) |
| 131 | return false; |
| 132 | break; |
| 133 | |
| 134 | case GL_UNSIGNED_SHORT: |
| 135 | pathNameTypeSize = sizeof(GLushort); |
| 136 | if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase)) |
| 137 | return false; |
| 138 | break; |
| 139 | |
| 140 | case GL_SHORT: |
| 141 | pathNameTypeSize = sizeof(GLshort); |
| 142 | if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase)) |
| 143 | return false; |
| 144 | break; |
| 145 | |
| 146 | case GL_UNSIGNED_INT: |
| 147 | pathNameTypeSize = sizeof(GLuint); |
| 148 | if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase)) |
| 149 | return false; |
| 150 | break; |
| 151 | |
| 152 | case GL_INT: |
| 153 | pathNameTypeSize = sizeof(GLint); |
| 154 | if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase)) |
| 155 | return false; |
| 156 | break; |
| 157 | |
| 158 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 159 | context->handleError(InvalidEnum() << "Invalid path name type."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 160 | return false; |
| 161 | } |
| 162 | |
| 163 | switch (transformType) |
| 164 | { |
| 165 | case GL_NONE: |
| 166 | componentCount = 0; |
| 167 | break; |
| 168 | case GL_TRANSLATE_X_CHROMIUM: |
| 169 | case GL_TRANSLATE_Y_CHROMIUM: |
| 170 | componentCount = 1; |
| 171 | break; |
| 172 | case GL_TRANSLATE_2D_CHROMIUM: |
| 173 | componentCount = 2; |
| 174 | break; |
| 175 | case GL_TRANSLATE_3D_CHROMIUM: |
| 176 | componentCount = 3; |
| 177 | break; |
| 178 | case GL_AFFINE_2D_CHROMIUM: |
| 179 | case GL_TRANSPOSE_AFFINE_2D_CHROMIUM: |
| 180 | componentCount = 6; |
| 181 | break; |
| 182 | case GL_AFFINE_3D_CHROMIUM: |
| 183 | case GL_TRANSPOSE_AFFINE_3D_CHROMIUM: |
| 184 | componentCount = 12; |
| 185 | break; |
| 186 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 187 | context->handleError(InvalidEnum() << "Invalid transformation."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 188 | return false; |
| 189 | } |
| 190 | if (componentCount != 0 && transformValues == nullptr) |
| 191 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 192 | context->handleError(InvalidValue() << "No transform array given."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 193 | return false; |
| 194 | } |
| 195 | |
| 196 | angle::CheckedNumeric<std::uint32_t> checkedSize(0); |
| 197 | checkedSize += (numPaths * pathNameTypeSize); |
| 198 | checkedSize += (numPaths * sizeof(GLfloat) * componentCount); |
| 199 | if (!checkedSize.IsValid()) |
| 200 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 201 | context->handleError(InvalidOperation() << "Overflow in num paths."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 202 | return false; |
| 203 | } |
| 204 | |
| 205 | return true; |
| 206 | } |
| 207 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 208 | bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 209 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 210 | // Table 1.1 from the CHROMIUM_copy_texture spec |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 211 | switch (GetUnsizedFormat(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 212 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 213 | case GL_RED: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 214 | case GL_ALPHA: |
| 215 | case GL_LUMINANCE: |
| 216 | case GL_LUMINANCE_ALPHA: |
| 217 | case GL_RGB: |
| 218 | case GL_RGBA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 219 | case GL_RGB8: |
| 220 | case GL_RGBA8: |
| 221 | case GL_BGRA_EXT: |
| 222 | case GL_BGRA8_EXT: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 223 | return true; |
| 224 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 225 | default: |
| 226 | return false; |
| 227 | } |
| 228 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 229 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 230 | bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat) |
| 231 | { |
| 232 | return IsValidCopyTextureSourceInternalFormatEnum(internalFormat); |
| 233 | } |
| 234 | |
| 235 | bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat) |
| 236 | { |
| 237 | return IsValidCopyTextureSourceInternalFormatEnum(internalFormat); |
| 238 | } |
| 239 | |
| 240 | bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat) |
| 241 | { |
| 242 | // Table 1.0 from the CHROMIUM_copy_texture spec |
| 243 | switch (internalFormat) |
| 244 | { |
| 245 | case GL_RGB: |
| 246 | case GL_RGBA: |
| 247 | case GL_RGB8: |
| 248 | case GL_RGBA8: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 249 | case GL_BGRA_EXT: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 250 | case GL_BGRA8_EXT: |
| 251 | case GL_SRGB_EXT: |
| 252 | case GL_SRGB_ALPHA_EXT: |
| 253 | case GL_R8: |
| 254 | case GL_R8UI: |
| 255 | case GL_RG8: |
| 256 | case GL_RG8UI: |
| 257 | case GL_SRGB8: |
| 258 | case GL_RGB565: |
| 259 | case GL_RGB8UI: |
| 260 | 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: |
| 274 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 275 | |
| 276 | default: |
| 277 | return false; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type) |
| 282 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 283 | if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 284 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 285 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 288 | const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type); |
| 289 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 290 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 291 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | return true; |
| 295 | } |
| 296 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 297 | bool IsValidCopyTextureDestinationTarget(Context *context, GLenum textureType, GLenum target) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 298 | { |
| 299 | switch (target) |
| 300 | { |
| 301 | case GL_TEXTURE_2D: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 302 | return textureType == GL_TEXTURE_2D; |
| 303 | |
| 304 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 305 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 306 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 307 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 308 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 309 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 310 | return textureType == GL_TEXTURE_CUBE_MAP; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 311 | |
| 312 | // TODO(geofflang): accept GL_TEXTURE_RECTANGLE_ARB if the texture_rectangle extension is |
| 313 | // supported |
| 314 | |
| 315 | default: |
| 316 | return false; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | bool IsValidCopyTextureSourceTarget(Context *context, GLenum target) |
| 321 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 322 | switch (target) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 323 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 324 | case GL_TEXTURE_2D: |
| 325 | return true; |
| 326 | |
| 327 | // TODO(geofflang): accept GL_TEXTURE_RECTANGLE_ARB if the texture_rectangle extension is |
| 328 | // supported |
| 329 | |
| 330 | // TODO(geofflang): accept GL_TEXTURE_EXTERNAL_OES if the texture_external extension is |
| 331 | // supported |
| 332 | |
| 333 | default: |
| 334 | return false; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | bool IsValidCopyTextureSourceLevel(Context *context, GLenum target, GLint level) |
| 339 | { |
| 340 | if (level < 0) |
| 341 | { |
| 342 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 345 | if (level > 0 && context->getClientVersion() < ES_3_0) |
| 346 | { |
| 347 | return false; |
| 348 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 349 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 350 | return true; |
| 351 | } |
| 352 | |
| 353 | bool IsValidCopyTextureDestinationLevel(Context *context, |
| 354 | GLenum target, |
| 355 | GLint level, |
| 356 | GLsizei width, |
| 357 | GLsizei height) |
| 358 | { |
| 359 | if (level < 0) |
| 360 | { |
| 361 | return false; |
| 362 | } |
| 363 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 364 | const Caps &caps = context->getCaps(); |
| 365 | if (target == GL_TEXTURE_2D) |
| 366 | { |
| 367 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 368 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 369 | { |
| 370 | return false; |
| 371 | } |
| 372 | } |
| 373 | else if (IsCubeMapTextureTarget(target)) |
| 374 | { |
| 375 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 376 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 377 | { |
| 378 | return false; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 385 | bool IsValidStencilFunc(GLenum func) |
| 386 | { |
| 387 | switch (func) |
| 388 | { |
| 389 | case GL_NEVER: |
| 390 | case GL_ALWAYS: |
| 391 | case GL_LESS: |
| 392 | case GL_LEQUAL: |
| 393 | case GL_EQUAL: |
| 394 | case GL_GEQUAL: |
| 395 | case GL_GREATER: |
| 396 | case GL_NOTEQUAL: |
| 397 | return true; |
| 398 | |
| 399 | default: |
| 400 | return false; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | bool IsValidStencilFace(GLenum face) |
| 405 | { |
| 406 | switch (face) |
| 407 | { |
| 408 | case GL_FRONT: |
| 409 | case GL_BACK: |
| 410 | case GL_FRONT_AND_BACK: |
| 411 | return true; |
| 412 | |
| 413 | default: |
| 414 | return false; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | bool IsValidStencilOp(GLenum op) |
| 419 | { |
| 420 | switch (op) |
| 421 | { |
| 422 | case GL_ZERO: |
| 423 | case GL_KEEP: |
| 424 | case GL_REPLACE: |
| 425 | case GL_INCR: |
| 426 | case GL_DECR: |
| 427 | case GL_INVERT: |
| 428 | case GL_INCR_WRAP: |
| 429 | case GL_DECR_WRAP: |
| 430 | return true; |
| 431 | |
| 432 | default: |
| 433 | return false; |
| 434 | } |
| 435 | } |
| 436 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 437 | bool ValidateES2CopyTexImageParameters(ValidationContext *context, |
| 438 | GLenum target, |
| 439 | GLint level, |
| 440 | GLenum internalformat, |
| 441 | bool isSubImage, |
| 442 | GLint xoffset, |
| 443 | GLint yoffset, |
| 444 | GLint x, |
| 445 | GLint y, |
| 446 | GLsizei width, |
| 447 | GLsizei height, |
| 448 | GLint border) |
| 449 | { |
| 450 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 451 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 452 | context->handleError(InvalidEnum() << "Invalid texture target"); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 453 | return false; |
| 454 | } |
| 455 | |
| 456 | if (!ValidImageSizeParameters(context, target, level, width, height, 1, isSubImage)) |
| 457 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 458 | context->handleError(InvalidValue() << "Invalid texture dimensions."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 459 | return false; |
| 460 | } |
| 461 | |
| 462 | Format textureFormat = Format::Invalid(); |
| 463 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 464 | xoffset, yoffset, 0, x, y, width, height, border, |
| 465 | &textureFormat)) |
| 466 | { |
| 467 | return false; |
| 468 | } |
| 469 | |
| 470 | const gl::Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
| 471 | GLenum colorbufferFormat = |
| 472 | framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat; |
| 473 | const auto &formatInfo = *textureFormat.info; |
| 474 | |
| 475 | // [OpenGL ES 2.0.24] table 3.9 |
| 476 | if (isSubImage) |
| 477 | { |
| 478 | switch (formatInfo.format) |
| 479 | { |
| 480 | case GL_ALPHA: |
| 481 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 482 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 483 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 484 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 485 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 486 | return false; |
| 487 | } |
| 488 | break; |
| 489 | case GL_LUMINANCE: |
| 490 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 491 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 492 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 493 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT && |
| 494 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 495 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 496 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 497 | return false; |
| 498 | } |
| 499 | break; |
| 500 | case GL_RED_EXT: |
| 501 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 502 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 503 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 504 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F && |
| 505 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 506 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 507 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 508 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 509 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 510 | return false; |
| 511 | } |
| 512 | break; |
| 513 | case GL_RG_EXT: |
| 514 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 515 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 516 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 517 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 518 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 519 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 520 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 521 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 522 | return false; |
| 523 | } |
| 524 | break; |
| 525 | case GL_RGB: |
| 526 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 527 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 528 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 529 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 530 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 531 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 532 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 533 | return false; |
| 534 | } |
| 535 | break; |
| 536 | case GL_LUMINANCE_ALPHA: |
| 537 | case GL_RGBA: |
| 538 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 539 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F && |
| 540 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 541 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 542 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 543 | return false; |
| 544 | } |
| 545 | break; |
| 546 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 547 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 548 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 549 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 550 | case GL_ETC1_RGB8_OES: |
| 551 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 552 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 553 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 554 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 555 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 556 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 557 | return false; |
| 558 | case GL_DEPTH_COMPONENT: |
| 559 | case GL_DEPTH_STENCIL_OES: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 560 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 561 | return false; |
| 562 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 563 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 564 | return false; |
| 565 | } |
| 566 | |
| 567 | if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat) |
| 568 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 569 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 570 | return false; |
| 571 | } |
| 572 | } |
| 573 | else |
| 574 | { |
| 575 | switch (internalformat) |
| 576 | { |
| 577 | case GL_ALPHA: |
| 578 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
| 579 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 580 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 581 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 582 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 583 | return false; |
| 584 | } |
| 585 | break; |
| 586 | case GL_LUMINANCE: |
| 587 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 588 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 589 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 590 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 591 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 592 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 593 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 594 | return false; |
| 595 | } |
| 596 | break; |
| 597 | case GL_RED_EXT: |
| 598 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 599 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 600 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 601 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 602 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 603 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 604 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 605 | return false; |
| 606 | } |
| 607 | break; |
| 608 | case GL_RG_EXT: |
| 609 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 610 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 611 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 612 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 613 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 614 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 615 | return false; |
| 616 | } |
| 617 | break; |
| 618 | case GL_RGB: |
| 619 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 620 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 621 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 622 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 623 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 624 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 625 | return false; |
| 626 | } |
| 627 | break; |
| 628 | case GL_LUMINANCE_ALPHA: |
| 629 | case GL_RGBA: |
| 630 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 631 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 632 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 633 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 634 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 635 | return false; |
| 636 | } |
| 637 | break; |
| 638 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 639 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 640 | if (context->getExtensions().textureCompressionDXT1) |
| 641 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 642 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 643 | return false; |
| 644 | } |
| 645 | else |
| 646 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 647 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 648 | return false; |
| 649 | } |
| 650 | break; |
| 651 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 652 | if (context->getExtensions().textureCompressionDXT3) |
| 653 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 654 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 655 | return false; |
| 656 | } |
| 657 | else |
| 658 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 659 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 660 | return false; |
| 661 | } |
| 662 | break; |
| 663 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 664 | if (context->getExtensions().textureCompressionDXT5) |
| 665 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 666 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 667 | return false; |
| 668 | } |
| 669 | else |
| 670 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 671 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 672 | return false; |
| 673 | } |
| 674 | break; |
| 675 | case GL_ETC1_RGB8_OES: |
| 676 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 677 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 678 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 679 | return false; |
| 680 | } |
| 681 | else |
| 682 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 683 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 684 | return false; |
| 685 | } |
| 686 | break; |
| 687 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 688 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 689 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 690 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 691 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 692 | if (context->getExtensions().lossyETCDecode) |
| 693 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 694 | context->handleError(InvalidOperation() |
| 695 | << "ETC lossy decode formats can't be copied to."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 696 | return false; |
| 697 | } |
| 698 | else |
| 699 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 700 | context->handleError(InvalidEnum() |
| 701 | << "ANGLE_lossy_etc_decode extension is not supported."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 702 | return false; |
| 703 | } |
| 704 | break; |
| 705 | case GL_DEPTH_COMPONENT: |
| 706 | case GL_DEPTH_COMPONENT16: |
| 707 | case GL_DEPTH_COMPONENT32_OES: |
| 708 | case GL_DEPTH_STENCIL_OES: |
| 709 | case GL_DEPTH24_STENCIL8_OES: |
| 710 | if (context->getExtensions().depthTextures) |
| 711 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 712 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 713 | return false; |
| 714 | } |
| 715 | else |
| 716 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 717 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 718 | return false; |
| 719 | } |
| 720 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 721 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 722 | return false; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 727 | return (width > 0 && height > 0); |
| 728 | } |
| 729 | |
| 730 | bool ValidCap(const Context *context, GLenum cap, bool queryOnly) |
| 731 | { |
| 732 | switch (cap) |
| 733 | { |
| 734 | // EXT_multisample_compatibility |
| 735 | case GL_MULTISAMPLE_EXT: |
| 736 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 737 | return context->getExtensions().multisampleCompatibility; |
| 738 | |
| 739 | case GL_CULL_FACE: |
| 740 | case GL_POLYGON_OFFSET_FILL: |
| 741 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 742 | case GL_SAMPLE_COVERAGE: |
| 743 | case GL_SCISSOR_TEST: |
| 744 | case GL_STENCIL_TEST: |
| 745 | case GL_DEPTH_TEST: |
| 746 | case GL_BLEND: |
| 747 | case GL_DITHER: |
| 748 | return true; |
| 749 | |
| 750 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 751 | case GL_RASTERIZER_DISCARD: |
| 752 | return (context->getClientMajorVersion() >= 3); |
| 753 | |
| 754 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 755 | case GL_DEBUG_OUTPUT: |
| 756 | return context->getExtensions().debug; |
| 757 | |
| 758 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 759 | return queryOnly && context->getExtensions().bindGeneratesResource; |
| 760 | |
| 761 | case GL_CLIENT_ARRAYS_ANGLE: |
| 762 | return queryOnly && context->getExtensions().clientArrays; |
| 763 | |
| 764 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 765 | return context->getExtensions().sRGBWriteControl; |
| 766 | |
| 767 | case GL_SAMPLE_MASK: |
| 768 | return context->getClientVersion() >= Version(3, 1); |
| 769 | |
| 770 | case GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
| 771 | return queryOnly && context->getExtensions().robustResourceInitialization; |
| 772 | |
| 773 | default: |
| 774 | return false; |
| 775 | } |
| 776 | } |
| 777 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 778 | // Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section |
| 779 | // 3.1. |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 780 | bool IsValidESSLCharacter(unsigned char c, bool allowBackslash) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 781 | { |
| 782 | // Printing characters are valid except " $ ` @ \ ' DEL. |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 783 | if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && |
| 784 | (allowBackslash || c != '\\') && c != '\'') |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 785 | { |
| 786 | return true; |
| 787 | } |
| 788 | |
| 789 | // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid. |
| 790 | if (c >= 9 && c <= 13) |
| 791 | { |
| 792 | return true; |
| 793 | } |
| 794 | |
| 795 | return false; |
| 796 | } |
| 797 | |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 798 | bool IsValidESSLString(const char *str, size_t len, bool allowBackslash) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 799 | { |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 800 | for (size_t i = 0; i < len; i++) |
| 801 | { |
| 802 | if (!IsValidESSLCharacter(str[i], allowBackslash)) |
| 803 | { |
| 804 | return false; |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | return true; |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 809 | } |
| 810 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 811 | } // anonymous namespace |
| 812 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 813 | bool ValidateES2TexImageParameters(Context *context, |
| 814 | GLenum target, |
| 815 | GLint level, |
| 816 | GLenum internalformat, |
| 817 | bool isCompressed, |
| 818 | bool isSubImage, |
| 819 | GLint xoffset, |
| 820 | GLint yoffset, |
| 821 | GLsizei width, |
| 822 | GLsizei height, |
| 823 | GLint border, |
| 824 | GLenum format, |
| 825 | GLenum type, |
| 826 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 827 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 828 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 829 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 830 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 831 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 832 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 833 | } |
| 834 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 835 | if (!ValidImageSizeParameters(context, target, level, width, height, 1, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 836 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 837 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 838 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 839 | } |
| 840 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 841 | if (level < 0 || xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width || |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 842 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 843 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 844 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 845 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 846 | } |
| 847 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 848 | // From GL_CHROMIUM_color_buffer_float_rgb[a]: |
| 849 | // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for |
| 850 | // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the |
| 851 | // internalformat parameter and format parameter of TexImage2D must match is lifted for this |
| 852 | // case. |
| 853 | bool nonEqualFormatsAllowed = |
| 854 | (internalformat == GL_RGB32F && context->getExtensions().colorBufferFloatRGB) || |
| 855 | (internalformat == GL_RGBA32F && context->getExtensions().colorBufferFloatRGBA); |
| 856 | |
| 857 | if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 858 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 859 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 860 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 861 | } |
| 862 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 863 | const gl::Caps &caps = context->getCaps(); |
| 864 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 865 | if (target == GL_TEXTURE_2D) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 866 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 867 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 868 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 869 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 870 | context->handleError(InvalidValue()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 871 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 872 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 873 | } |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 874 | else if (IsCubeMapTextureTarget(target)) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 875 | { |
| 876 | if (!isSubImage && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 877 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 878 | context->handleError(InvalidValue()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 879 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 880 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 881 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 882 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 883 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 884 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 885 | context->handleError(InvalidValue()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 886 | return false; |
| 887 | } |
| 888 | } |
| 889 | else |
| 890 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 891 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 892 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 893 | } |
| 894 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 895 | gl::Texture *texture = |
| 896 | context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 897 | if (!texture) |
| 898 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 899 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 900 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 901 | } |
| 902 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 903 | if (isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 904 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 905 | const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info; |
| 906 | if (textureInternalFormat.internalFormat == GL_NONE) |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 907 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 908 | context->handleError(InvalidOperation() << "Texture level does not exist."); |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 909 | return false; |
| 910 | } |
| 911 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 912 | if (format != GL_NONE) |
| 913 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 914 | if (GetInternalFormatInfo(format, type).sizedInternalFormat != |
| 915 | textureInternalFormat.sizedInternalFormat) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 916 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 917 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 918 | return false; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 923 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 924 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 925 | context->handleError(InvalidValue()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 926 | return false; |
| 927 | } |
| 928 | } |
| 929 | else |
| 930 | { |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 931 | if (texture->getImmutableFormat()) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 932 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 933 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 934 | return false; |
| 935 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | // Verify zero border |
| 939 | if (border != 0) |
| 940 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 941 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 942 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 943 | } |
| 944 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 945 | if (isCompressed) |
| 946 | { |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 947 | GLenum actualInternalFormat = |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 948 | isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat |
| 949 | : internalformat; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 950 | switch (actualInternalFormat) |
| 951 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 952 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 953 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 954 | if (!context->getExtensions().textureCompressionDXT1) |
| 955 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 956 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 957 | return false; |
| 958 | } |
| 959 | break; |
| 960 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 961 | if (!context->getExtensions().textureCompressionDXT1) |
| 962 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 963 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 964 | return false; |
| 965 | } |
| 966 | break; |
| 967 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 968 | if (!context->getExtensions().textureCompressionDXT5) |
| 969 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 970 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 971 | return false; |
| 972 | } |
| 973 | break; |
Kai Ninomiya | 02f075c | 2016-12-22 14:55:46 -0800 | [diff] [blame] | 974 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 975 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 976 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 977 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 978 | if (!context->getExtensions().textureCompressionS3TCsRGB) |
| 979 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 980 | context->handleError(InvalidEnum()); |
Kai Ninomiya | 02f075c | 2016-12-22 14:55:46 -0800 | [diff] [blame] | 981 | return false; |
| 982 | } |
| 983 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 984 | case GL_ETC1_RGB8_OES: |
| 985 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 986 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 987 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 988 | return false; |
| 989 | } |
| 990 | break; |
| 991 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 992 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 993 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 994 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 995 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 996 | if (!context->getExtensions().lossyETCDecode) |
| 997 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 998 | context->handleError(InvalidEnum() |
| 999 | << "ANGLE_lossy_etc_decode extension is not supported"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1000 | return false; |
| 1001 | } |
| 1002 | break; |
| 1003 | default: |
| 1004 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1005 | InvalidEnum() |
| 1006 | << "internalformat is not a supported compressed internal format"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1007 | return false; |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1008 | } |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1009 | |
| 1010 | if (isSubImage) |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1011 | { |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1012 | if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width, |
| 1013 | height, texture->getWidth(target, level), |
| 1014 | texture->getHeight(target, level))) |
| 1015 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1016 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1017 | return false; |
| 1018 | } |
| 1019 | |
| 1020 | if (format != actualInternalFormat) |
| 1021 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1022 | context->handleError(InvalidOperation() |
| 1023 | << "Format must match the internal format of the texture."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1024 | return false; |
| 1025 | } |
| 1026 | } |
| 1027 | else |
| 1028 | { |
| 1029 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 1030 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1031 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | else |
| 1037 | { |
| 1038 | // validate <type> by itself (used as secondary key below) |
| 1039 | switch (type) |
| 1040 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1041 | case GL_UNSIGNED_BYTE: |
| 1042 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1043 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1044 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1045 | case GL_UNSIGNED_SHORT: |
| 1046 | case GL_UNSIGNED_INT: |
| 1047 | case GL_UNSIGNED_INT_24_8_OES: |
| 1048 | case GL_HALF_FLOAT_OES: |
| 1049 | case GL_FLOAT: |
| 1050 | break; |
| 1051 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1052 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1053 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | // validate <format> + <type> combinations |
| 1057 | // - invalid <format> -> sets INVALID_ENUM |
| 1058 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 1059 | switch (format) |
| 1060 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1061 | case GL_ALPHA: |
| 1062 | case GL_LUMINANCE: |
| 1063 | case GL_LUMINANCE_ALPHA: |
| 1064 | switch (type) |
| 1065 | { |
| 1066 | case GL_UNSIGNED_BYTE: |
| 1067 | case GL_FLOAT: |
| 1068 | case GL_HALF_FLOAT_OES: |
| 1069 | break; |
| 1070 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1071 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1072 | return false; |
| 1073 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1074 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1075 | case GL_RED: |
| 1076 | case GL_RG: |
| 1077 | if (!context->getExtensions().textureRG) |
| 1078 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1079 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1080 | return false; |
| 1081 | } |
| 1082 | switch (type) |
| 1083 | { |
| 1084 | case GL_UNSIGNED_BYTE: |
| 1085 | case GL_FLOAT: |
| 1086 | case GL_HALF_FLOAT_OES: |
| 1087 | break; |
| 1088 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1089 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1090 | return false; |
| 1091 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1092 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1093 | case GL_RGB: |
| 1094 | switch (type) |
| 1095 | { |
| 1096 | case GL_UNSIGNED_BYTE: |
| 1097 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1098 | case GL_FLOAT: |
| 1099 | case GL_HALF_FLOAT_OES: |
| 1100 | break; |
| 1101 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1102 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1103 | return false; |
| 1104 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1105 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1106 | case GL_RGBA: |
| 1107 | switch (type) |
| 1108 | { |
| 1109 | case GL_UNSIGNED_BYTE: |
| 1110 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1111 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1112 | case GL_FLOAT: |
| 1113 | case GL_HALF_FLOAT_OES: |
| 1114 | break; |
| 1115 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1116 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1117 | return false; |
| 1118 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1119 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1120 | case GL_BGRA_EXT: |
| 1121 | switch (type) |
| 1122 | { |
| 1123 | case GL_UNSIGNED_BYTE: |
| 1124 | break; |
| 1125 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1126 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1127 | return false; |
| 1128 | } |
| 1129 | break; |
| 1130 | case GL_SRGB_EXT: |
| 1131 | case GL_SRGB_ALPHA_EXT: |
| 1132 | if (!context->getExtensions().sRGB) |
| 1133 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1134 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1135 | return false; |
| 1136 | } |
| 1137 | switch (type) |
| 1138 | { |
| 1139 | case GL_UNSIGNED_BYTE: |
| 1140 | break; |
| 1141 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1142 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1143 | return false; |
| 1144 | } |
| 1145 | break; |
| 1146 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1147 | // handled below |
| 1148 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1149 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1150 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1151 | break; |
| 1152 | case GL_DEPTH_COMPONENT: |
| 1153 | switch (type) |
| 1154 | { |
| 1155 | case GL_UNSIGNED_SHORT: |
| 1156 | case GL_UNSIGNED_INT: |
| 1157 | break; |
| 1158 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1159 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1160 | return false; |
| 1161 | } |
| 1162 | break; |
| 1163 | case GL_DEPTH_STENCIL_OES: |
| 1164 | switch (type) |
| 1165 | { |
| 1166 | case GL_UNSIGNED_INT_24_8_OES: |
| 1167 | break; |
| 1168 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1169 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1170 | return false; |
| 1171 | } |
| 1172 | break; |
| 1173 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1174 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1175 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | switch (format) |
| 1179 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1180 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1181 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1182 | if (context->getExtensions().textureCompressionDXT1) |
| 1183 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1184 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1185 | return false; |
| 1186 | } |
| 1187 | else |
| 1188 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1189 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1190 | return false; |
| 1191 | } |
| 1192 | break; |
| 1193 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1194 | if (context->getExtensions().textureCompressionDXT3) |
| 1195 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1196 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1197 | return false; |
| 1198 | } |
| 1199 | else |
| 1200 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1201 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1202 | return false; |
| 1203 | } |
| 1204 | break; |
| 1205 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1206 | if (context->getExtensions().textureCompressionDXT5) |
| 1207 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1208 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1209 | return false; |
| 1210 | } |
| 1211 | else |
| 1212 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1213 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1214 | return false; |
| 1215 | } |
| 1216 | break; |
| 1217 | case GL_ETC1_RGB8_OES: |
| 1218 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1219 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1220 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1221 | return false; |
| 1222 | } |
| 1223 | else |
| 1224 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1225 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1226 | return false; |
| 1227 | } |
| 1228 | break; |
| 1229 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1230 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1231 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1232 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1233 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1234 | if (context->getExtensions().lossyETCDecode) |
| 1235 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1236 | context->handleError(InvalidOperation() |
| 1237 | << "ETC lossy decode formats can't work with this type."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1238 | return false; |
| 1239 | } |
| 1240 | else |
| 1241 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1242 | context->handleError(InvalidEnum() |
| 1243 | << "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1244 | return false; |
| 1245 | } |
| 1246 | break; |
| 1247 | case GL_DEPTH_COMPONENT: |
| 1248 | case GL_DEPTH_STENCIL_OES: |
| 1249 | if (!context->getExtensions().depthTextures) |
| 1250 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1251 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1252 | return false; |
| 1253 | } |
| 1254 | if (target != GL_TEXTURE_2D) |
| 1255 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1256 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1257 | return false; |
| 1258 | } |
| 1259 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1260 | // but ANGLE_depth_texture does not |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 1261 | if (pixels != nullptr || level != 0) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1262 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1263 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1264 | return false; |
| 1265 | } |
| 1266 | break; |
| 1267 | default: |
| 1268 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1269 | } |
| 1270 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1271 | if (!isSubImage) |
| 1272 | { |
| 1273 | switch (internalformat) |
| 1274 | { |
| 1275 | case GL_RGBA32F: |
| 1276 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1277 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1278 | context->handleError(InvalidValue() |
| 1279 | << "Sized GL_RGBA32F internal format requires " |
| 1280 | "GL_CHROMIUM_color_buffer_float_rgba"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1281 | return false; |
| 1282 | } |
| 1283 | if (type != GL_FLOAT) |
| 1284 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1285 | context->handleError(InvalidOperation() |
| 1286 | << "Invalid internal format/type combination"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1287 | return false; |
| 1288 | } |
| 1289 | if (format != GL_RGBA) |
| 1290 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1291 | context->handleError(InvalidOperation() |
| 1292 | << "Invalid internal format/format combination"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1293 | return false; |
| 1294 | } |
| 1295 | break; |
| 1296 | |
| 1297 | case GL_RGB32F: |
| 1298 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1299 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1300 | context->handleError(InvalidValue() |
| 1301 | << "Sized GL_RGB32F internal format requires " |
| 1302 | "GL_CHROMIUM_color_buffer_float_rgb"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1303 | return false; |
| 1304 | } |
| 1305 | if (type != GL_FLOAT) |
| 1306 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1307 | context->handleError(InvalidOperation() |
| 1308 | << "Invalid internal format/type combination"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1309 | return false; |
| 1310 | } |
| 1311 | if (format != GL_RGB) |
| 1312 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1313 | context->handleError(InvalidOperation() |
| 1314 | << "Invalid internal format/format combination"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1315 | return false; |
| 1316 | } |
| 1317 | break; |
| 1318 | |
| 1319 | default: |
| 1320 | break; |
| 1321 | } |
| 1322 | } |
| 1323 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1324 | if (type == GL_FLOAT) |
| 1325 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1326 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1327 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1328 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1329 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | else if (type == GL_HALF_FLOAT_OES) |
| 1333 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1334 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1335 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1336 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1337 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | } |
| 1341 | |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 1342 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
| 1343 | if (!ValidImageDataSize(context, target, width, height, 1, sizeCheckFormat, type, pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1344 | imageSize)) |
| 1345 | { |
| 1346 | return false; |
| 1347 | } |
| 1348 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1349 | return true; |
| 1350 | } |
| 1351 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1352 | bool ValidateES2TexStorageParameters(Context *context, |
| 1353 | GLenum target, |
| 1354 | GLsizei levels, |
| 1355 | GLenum internalformat, |
| 1356 | GLsizei width, |
| 1357 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1358 | { |
| 1359 | if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP) |
| 1360 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1361 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1362 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | if (width < 1 || height < 1 || levels < 1) |
| 1366 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1367 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1368 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | if (target == GL_TEXTURE_CUBE_MAP && width != height) |
| 1372 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1373 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1374 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1378 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1379 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1380 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1381 | } |
| 1382 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1383 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1384 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1385 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1386 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1387 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1388 | } |
| 1389 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1390 | const gl::Caps &caps = context->getCaps(); |
| 1391 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1392 | switch (target) |
| 1393 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1394 | case GL_TEXTURE_2D: |
| 1395 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1396 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1397 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1398 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1399 | return false; |
| 1400 | } |
| 1401 | break; |
| 1402 | case GL_TEXTURE_CUBE_MAP: |
| 1403 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1404 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1405 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1406 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1407 | return false; |
| 1408 | } |
| 1409 | break; |
| 1410 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1411 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1412 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1415 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1416 | { |
| 1417 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1418 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1419 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1420 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | switch (internalformat) |
| 1425 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1426 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1427 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1428 | if (!context->getExtensions().textureCompressionDXT1) |
| 1429 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1430 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1431 | return false; |
| 1432 | } |
| 1433 | break; |
| 1434 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1435 | if (!context->getExtensions().textureCompressionDXT3) |
| 1436 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1437 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1438 | return false; |
| 1439 | } |
| 1440 | break; |
| 1441 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1442 | if (!context->getExtensions().textureCompressionDXT5) |
| 1443 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1444 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1445 | return false; |
| 1446 | } |
| 1447 | break; |
| 1448 | case GL_ETC1_RGB8_OES: |
| 1449 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1450 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1451 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1452 | return false; |
| 1453 | } |
| 1454 | break; |
| 1455 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1456 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1457 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1458 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1459 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1460 | if (!context->getExtensions().lossyETCDecode) |
| 1461 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1462 | context->handleError(InvalidEnum() |
| 1463 | << "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1464 | return false; |
| 1465 | } |
| 1466 | break; |
| 1467 | case GL_RGBA32F_EXT: |
| 1468 | case GL_RGB32F_EXT: |
| 1469 | case GL_ALPHA32F_EXT: |
| 1470 | case GL_LUMINANCE32F_EXT: |
| 1471 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 1472 | if (!context->getExtensions().textureFloat) |
| 1473 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1474 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1475 | return false; |
| 1476 | } |
| 1477 | break; |
| 1478 | case GL_RGBA16F_EXT: |
| 1479 | case GL_RGB16F_EXT: |
| 1480 | case GL_ALPHA16F_EXT: |
| 1481 | case GL_LUMINANCE16F_EXT: |
| 1482 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 1483 | if (!context->getExtensions().textureHalfFloat) |
| 1484 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1485 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1486 | return false; |
| 1487 | } |
| 1488 | break; |
| 1489 | case GL_R8_EXT: |
| 1490 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1491 | if (!context->getExtensions().textureRG) |
| 1492 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1493 | context->handleError(InvalidEnum()); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1494 | return false; |
| 1495 | } |
| 1496 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1497 | case GL_R16F_EXT: |
| 1498 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1499 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 1500 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1501 | context->handleError(InvalidEnum()); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1502 | return false; |
| 1503 | } |
| 1504 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1505 | case GL_R32F_EXT: |
| 1506 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1507 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1508 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1509 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1510 | return false; |
| 1511 | } |
| 1512 | break; |
| 1513 | case GL_DEPTH_COMPONENT16: |
| 1514 | case GL_DEPTH_COMPONENT32_OES: |
| 1515 | case GL_DEPTH24_STENCIL8_OES: |
| 1516 | if (!context->getExtensions().depthTextures) |
| 1517 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1518 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1519 | return false; |
| 1520 | } |
| 1521 | if (target != GL_TEXTURE_2D) |
| 1522 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1523 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1524 | return false; |
| 1525 | } |
| 1526 | // ANGLE_depth_texture only supports 1-level textures |
| 1527 | if (levels != 1) |
| 1528 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1529 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1530 | return false; |
| 1531 | } |
| 1532 | break; |
| 1533 | default: |
| 1534 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1535 | } |
| 1536 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1537 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1538 | if (!texture || texture->id() == 0) |
| 1539 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1540 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1541 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1542 | } |
| 1543 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1544 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1545 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1546 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1547 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | return true; |
| 1551 | } |
| 1552 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1553 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 1554 | GLenum target, |
| 1555 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1556 | const GLenum *attachments) |
| 1557 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1558 | if (!context->getExtensions().discardFramebuffer) |
| 1559 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1560 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1561 | return false; |
| 1562 | } |
| 1563 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1564 | bool defaultFramebuffer = false; |
| 1565 | |
| 1566 | switch (target) |
| 1567 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1568 | case GL_FRAMEBUFFER: |
| 1569 | defaultFramebuffer = |
| 1570 | (context->getGLState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
| 1571 | break; |
| 1572 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1573 | context->handleError(InvalidEnum() << "Invalid framebuffer target"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1574 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1577 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1578 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1581 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 1582 | { |
| 1583 | if (!context->getExtensions().vertexArrayObject) |
| 1584 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1585 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1586 | return false; |
| 1587 | } |
| 1588 | |
| 1589 | return ValidateBindVertexArrayBase(context, array); |
| 1590 | } |
| 1591 | |
| 1592 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n) |
| 1593 | { |
| 1594 | if (!context->getExtensions().vertexArrayObject) |
| 1595 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1596 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1597 | return false; |
| 1598 | } |
| 1599 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1600 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n) |
| 1604 | { |
| 1605 | if (!context->getExtensions().vertexArrayObject) |
| 1606 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1607 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1608 | return false; |
| 1609 | } |
| 1610 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1611 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | bool ValidateIsVertexArrayOES(Context *context) |
| 1615 | { |
| 1616 | if (!context->getExtensions().vertexArrayObject) |
| 1617 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1618 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1619 | return false; |
| 1620 | } |
| 1621 | |
| 1622 | return true; |
| 1623 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1624 | |
| 1625 | bool ValidateProgramBinaryOES(Context *context, |
| 1626 | GLuint program, |
| 1627 | GLenum binaryFormat, |
| 1628 | const void *binary, |
| 1629 | GLint length) |
| 1630 | { |
| 1631 | if (!context->getExtensions().getProgramBinary) |
| 1632 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1633 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1634 | return false; |
| 1635 | } |
| 1636 | |
| 1637 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1638 | } |
| 1639 | |
| 1640 | bool ValidateGetProgramBinaryOES(Context *context, |
| 1641 | GLuint program, |
| 1642 | GLsizei bufSize, |
| 1643 | GLsizei *length, |
| 1644 | GLenum *binaryFormat, |
| 1645 | void *binary) |
| 1646 | { |
| 1647 | if (!context->getExtensions().getProgramBinary) |
| 1648 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1649 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1650 | return false; |
| 1651 | } |
| 1652 | |
| 1653 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1654 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1655 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1656 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 1657 | { |
| 1658 | switch (source) |
| 1659 | { |
| 1660 | case GL_DEBUG_SOURCE_API: |
| 1661 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 1662 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 1663 | case GL_DEBUG_SOURCE_OTHER: |
| 1664 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 1665 | return !mustBeThirdPartyOrApplication; |
| 1666 | |
| 1667 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 1668 | case GL_DEBUG_SOURCE_APPLICATION: |
| 1669 | return true; |
| 1670 | |
| 1671 | default: |
| 1672 | return false; |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | static bool ValidDebugType(GLenum type) |
| 1677 | { |
| 1678 | switch (type) |
| 1679 | { |
| 1680 | case GL_DEBUG_TYPE_ERROR: |
| 1681 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 1682 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 1683 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 1684 | case GL_DEBUG_TYPE_PORTABILITY: |
| 1685 | case GL_DEBUG_TYPE_OTHER: |
| 1686 | case GL_DEBUG_TYPE_MARKER: |
| 1687 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 1688 | case GL_DEBUG_TYPE_POP_GROUP: |
| 1689 | return true; |
| 1690 | |
| 1691 | default: |
| 1692 | return false; |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | static bool ValidDebugSeverity(GLenum severity) |
| 1697 | { |
| 1698 | switch (severity) |
| 1699 | { |
| 1700 | case GL_DEBUG_SEVERITY_HIGH: |
| 1701 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 1702 | case GL_DEBUG_SEVERITY_LOW: |
| 1703 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 1704 | return true; |
| 1705 | |
| 1706 | default: |
| 1707 | return false; |
| 1708 | } |
| 1709 | } |
| 1710 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1711 | bool ValidateDebugMessageControlKHR(Context *context, |
| 1712 | GLenum source, |
| 1713 | GLenum type, |
| 1714 | GLenum severity, |
| 1715 | GLsizei count, |
| 1716 | const GLuint *ids, |
| 1717 | GLboolean enabled) |
| 1718 | { |
| 1719 | if (!context->getExtensions().debug) |
| 1720 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1721 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1722 | return false; |
| 1723 | } |
| 1724 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1725 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 1726 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1727 | context->handleError(InvalidEnum() << "Invalid debug source."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1728 | return false; |
| 1729 | } |
| 1730 | |
| 1731 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 1732 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1733 | context->handleError(InvalidEnum() << "Invalid debug type."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1734 | return false; |
| 1735 | } |
| 1736 | |
| 1737 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 1738 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1739 | context->handleError(InvalidEnum() << "Invalid debug severity."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1740 | return false; |
| 1741 | } |
| 1742 | |
| 1743 | if (count > 0) |
| 1744 | { |
| 1745 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 1746 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1747 | context->handleError( |
| 1748 | InvalidOperation() |
| 1749 | << "If count is greater than zero, source and severity cannot be GL_DONT_CARE."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1750 | return false; |
| 1751 | } |
| 1752 | |
| 1753 | if (severity != GL_DONT_CARE) |
| 1754 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1755 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1756 | InvalidOperation() |
| 1757 | << "If count is greater than zero, severity must be GL_DONT_CARE."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1758 | return false; |
| 1759 | } |
| 1760 | } |
| 1761 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1762 | return true; |
| 1763 | } |
| 1764 | |
| 1765 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 1766 | GLenum source, |
| 1767 | GLenum type, |
| 1768 | GLuint id, |
| 1769 | GLenum severity, |
| 1770 | GLsizei length, |
| 1771 | const GLchar *buf) |
| 1772 | { |
| 1773 | if (!context->getExtensions().debug) |
| 1774 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1775 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1776 | return false; |
| 1777 | } |
| 1778 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1779 | if (!context->getGLState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1780 | { |
| 1781 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 1782 | // not generate an error. |
| 1783 | return false; |
| 1784 | } |
| 1785 | |
| 1786 | if (!ValidDebugSeverity(severity)) |
| 1787 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1788 | context->handleError(InvalidEnum() << "Invalid debug severity."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1789 | return false; |
| 1790 | } |
| 1791 | |
| 1792 | if (!ValidDebugType(type)) |
| 1793 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1794 | context->handleError(InvalidEnum() << "Invalid debug type."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1795 | return false; |
| 1796 | } |
| 1797 | |
| 1798 | if (!ValidDebugSource(source, true)) |
| 1799 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1800 | context->handleError(InvalidEnum() << "Invalid debug source."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1801 | return false; |
| 1802 | } |
| 1803 | |
| 1804 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 1805 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 1806 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1807 | context->handleError(InvalidValue() |
| 1808 | << "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1809 | return false; |
| 1810 | } |
| 1811 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1812 | return true; |
| 1813 | } |
| 1814 | |
| 1815 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 1816 | GLDEBUGPROCKHR callback, |
| 1817 | const void *userParam) |
| 1818 | { |
| 1819 | if (!context->getExtensions().debug) |
| 1820 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1821 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1822 | return false; |
| 1823 | } |
| 1824 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1825 | return true; |
| 1826 | } |
| 1827 | |
| 1828 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 1829 | GLuint count, |
| 1830 | GLsizei bufSize, |
| 1831 | GLenum *sources, |
| 1832 | GLenum *types, |
| 1833 | GLuint *ids, |
| 1834 | GLenum *severities, |
| 1835 | GLsizei *lengths, |
| 1836 | GLchar *messageLog) |
| 1837 | { |
| 1838 | if (!context->getExtensions().debug) |
| 1839 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1840 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1841 | return false; |
| 1842 | } |
| 1843 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1844 | if (bufSize < 0 && messageLog != nullptr) |
| 1845 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1846 | context->handleError(InvalidValue() |
| 1847 | << "bufSize must be positive if messageLog is not null."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1848 | return false; |
| 1849 | } |
| 1850 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1851 | return true; |
| 1852 | } |
| 1853 | |
| 1854 | bool ValidatePushDebugGroupKHR(Context *context, |
| 1855 | GLenum source, |
| 1856 | GLuint id, |
| 1857 | GLsizei length, |
| 1858 | const GLchar *message) |
| 1859 | { |
| 1860 | if (!context->getExtensions().debug) |
| 1861 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1862 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1863 | return false; |
| 1864 | } |
| 1865 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1866 | if (!ValidDebugSource(source, true)) |
| 1867 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1868 | context->handleError(InvalidEnum() << "Invalid debug source."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1869 | return false; |
| 1870 | } |
| 1871 | |
| 1872 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 1873 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 1874 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1875 | context->handleError(InvalidValue() |
| 1876 | << "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1877 | return false; |
| 1878 | } |
| 1879 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1880 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1881 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 1882 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1883 | context |
| 1884 | ->handleError(StackOverflow() |
| 1885 | << "Cannot push more than GL_MAX_DEBUG_GROUP_STACK_DEPTH debug groups."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1886 | return false; |
| 1887 | } |
| 1888 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1889 | return true; |
| 1890 | } |
| 1891 | |
| 1892 | bool ValidatePopDebugGroupKHR(Context *context) |
| 1893 | { |
| 1894 | if (!context->getExtensions().debug) |
| 1895 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1896 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1897 | return false; |
| 1898 | } |
| 1899 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1900 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1901 | if (currentStackSize <= 1) |
| 1902 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1903 | context->handleError(StackUnderflow() << "Cannot pop the default debug group."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1904 | return false; |
| 1905 | } |
| 1906 | |
| 1907 | return true; |
| 1908 | } |
| 1909 | |
| 1910 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 1911 | { |
| 1912 | switch (identifier) |
| 1913 | { |
| 1914 | case GL_BUFFER: |
| 1915 | if (context->getBuffer(name) == nullptr) |
| 1916 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1917 | context->handleError(InvalidValue() << "name is not a valid buffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1918 | return false; |
| 1919 | } |
| 1920 | return true; |
| 1921 | |
| 1922 | case GL_SHADER: |
| 1923 | if (context->getShader(name) == nullptr) |
| 1924 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1925 | context->handleError(InvalidValue() << "name is not a valid shader."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1926 | return false; |
| 1927 | } |
| 1928 | return true; |
| 1929 | |
| 1930 | case GL_PROGRAM: |
| 1931 | if (context->getProgram(name) == nullptr) |
| 1932 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1933 | context->handleError(InvalidValue() << "name is not a valid program."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1934 | return false; |
| 1935 | } |
| 1936 | return true; |
| 1937 | |
| 1938 | case GL_VERTEX_ARRAY: |
| 1939 | if (context->getVertexArray(name) == nullptr) |
| 1940 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1941 | context->handleError(InvalidValue() << "name is not a valid vertex array."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1942 | return false; |
| 1943 | } |
| 1944 | return true; |
| 1945 | |
| 1946 | case GL_QUERY: |
| 1947 | if (context->getQuery(name) == nullptr) |
| 1948 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1949 | context->handleError(InvalidValue() << "name is not a valid query."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1950 | return false; |
| 1951 | } |
| 1952 | return true; |
| 1953 | |
| 1954 | case GL_TRANSFORM_FEEDBACK: |
| 1955 | if (context->getTransformFeedback(name) == nullptr) |
| 1956 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1957 | context->handleError(InvalidValue() << "name is not a valid transform feedback."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1958 | return false; |
| 1959 | } |
| 1960 | return true; |
| 1961 | |
| 1962 | case GL_SAMPLER: |
| 1963 | if (context->getSampler(name) == nullptr) |
| 1964 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1965 | context->handleError(InvalidValue() << "name is not a valid sampler."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1966 | return false; |
| 1967 | } |
| 1968 | return true; |
| 1969 | |
| 1970 | case GL_TEXTURE: |
| 1971 | if (context->getTexture(name) == nullptr) |
| 1972 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1973 | context->handleError(InvalidValue() << "name is not a valid texture."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1974 | return false; |
| 1975 | } |
| 1976 | return true; |
| 1977 | |
| 1978 | case GL_RENDERBUFFER: |
| 1979 | if (context->getRenderbuffer(name) == nullptr) |
| 1980 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1981 | context->handleError(InvalidValue() << "name is not a valid renderbuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1982 | return false; |
| 1983 | } |
| 1984 | return true; |
| 1985 | |
| 1986 | case GL_FRAMEBUFFER: |
| 1987 | if (context->getFramebuffer(name) == nullptr) |
| 1988 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1989 | context->handleError(InvalidValue() << "name is not a valid framebuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1990 | return false; |
| 1991 | } |
| 1992 | return true; |
| 1993 | |
| 1994 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1995 | context->handleError(InvalidEnum() << "Invalid identifier."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1996 | return false; |
| 1997 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1998 | } |
| 1999 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2000 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2001 | { |
| 2002 | size_t labelLength = 0; |
| 2003 | |
| 2004 | if (length < 0) |
| 2005 | { |
| 2006 | if (label != nullptr) |
| 2007 | { |
| 2008 | labelLength = strlen(label); |
| 2009 | } |
| 2010 | } |
| 2011 | else |
| 2012 | { |
| 2013 | labelLength = static_cast<size_t>(length); |
| 2014 | } |
| 2015 | |
| 2016 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2017 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2018 | context->handleError(InvalidValue() << "Label length is larger than GL_MAX_LABEL_LENGTH."); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2019 | return false; |
| 2020 | } |
| 2021 | |
| 2022 | return true; |
| 2023 | } |
| 2024 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2025 | bool ValidateObjectLabelKHR(Context *context, |
| 2026 | GLenum identifier, |
| 2027 | GLuint name, |
| 2028 | GLsizei length, |
| 2029 | const GLchar *label) |
| 2030 | { |
| 2031 | if (!context->getExtensions().debug) |
| 2032 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2033 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2034 | return false; |
| 2035 | } |
| 2036 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2037 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2038 | { |
| 2039 | return false; |
| 2040 | } |
| 2041 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2042 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2043 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2044 | return false; |
| 2045 | } |
| 2046 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2047 | return true; |
| 2048 | } |
| 2049 | |
| 2050 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2051 | GLenum identifier, |
| 2052 | GLuint name, |
| 2053 | GLsizei bufSize, |
| 2054 | GLsizei *length, |
| 2055 | GLchar *label) |
| 2056 | { |
| 2057 | if (!context->getExtensions().debug) |
| 2058 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2059 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2060 | return false; |
| 2061 | } |
| 2062 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2063 | if (bufSize < 0) |
| 2064 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2065 | context->handleError(InvalidValue() << "bufSize cannot be negative."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2066 | return false; |
| 2067 | } |
| 2068 | |
| 2069 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2070 | { |
| 2071 | return false; |
| 2072 | } |
| 2073 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2074 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2078 | { |
| 2079 | if (context->getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
| 2080 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2081 | context->handleError(InvalidValue() << "name is not a valid sync."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2082 | return false; |
| 2083 | } |
| 2084 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2085 | return true; |
| 2086 | } |
| 2087 | |
| 2088 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2089 | const void *ptr, |
| 2090 | GLsizei length, |
| 2091 | const GLchar *label) |
| 2092 | { |
| 2093 | if (!context->getExtensions().debug) |
| 2094 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2095 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2096 | return false; |
| 2097 | } |
| 2098 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2099 | if (!ValidateObjectPtrName(context, ptr)) |
| 2100 | { |
| 2101 | return false; |
| 2102 | } |
| 2103 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2104 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2105 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2106 | return false; |
| 2107 | } |
| 2108 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2109 | return true; |
| 2110 | } |
| 2111 | |
| 2112 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2113 | const void *ptr, |
| 2114 | GLsizei bufSize, |
| 2115 | GLsizei *length, |
| 2116 | GLchar *label) |
| 2117 | { |
| 2118 | if (!context->getExtensions().debug) |
| 2119 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2120 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2121 | return false; |
| 2122 | } |
| 2123 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2124 | if (bufSize < 0) |
| 2125 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2126 | context->handleError(InvalidValue() << "bufSize cannot be negative."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2127 | return false; |
| 2128 | } |
| 2129 | |
| 2130 | if (!ValidateObjectPtrName(context, ptr)) |
| 2131 | { |
| 2132 | return false; |
| 2133 | } |
| 2134 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2135 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2139 | { |
| 2140 | if (!context->getExtensions().debug) |
| 2141 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2142 | context->handleError(InvalidOperation() << "Extension not enabled"); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2143 | return false; |
| 2144 | } |
| 2145 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2146 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2147 | switch (pname) |
| 2148 | { |
| 2149 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2150 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2151 | break; |
| 2152 | |
| 2153 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2154 | context->handleError(InvalidEnum() << "Invalid pname."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2155 | return false; |
| 2156 | } |
| 2157 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2158 | return true; |
| 2159 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2160 | |
| 2161 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2162 | GLint srcX0, |
| 2163 | GLint srcY0, |
| 2164 | GLint srcX1, |
| 2165 | GLint srcY1, |
| 2166 | GLint dstX0, |
| 2167 | GLint dstY0, |
| 2168 | GLint dstX1, |
| 2169 | GLint dstY1, |
| 2170 | GLbitfield mask, |
| 2171 | GLenum filter) |
| 2172 | { |
| 2173 | if (!context->getExtensions().framebufferBlit) |
| 2174 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2175 | context->handleError(InvalidOperation() << "Blit extension not available."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2176 | return false; |
| 2177 | } |
| 2178 | |
| 2179 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2180 | { |
| 2181 | // TODO(jmadill): Determine if this should be available on other implementations. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2182 | context->handleError(InvalidOperation() << "Scaling and flipping in " |
| 2183 | "BlitFramebufferANGLE not supported by this " |
| 2184 | "implementation."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2185 | return false; |
| 2186 | } |
| 2187 | |
| 2188 | if (filter == GL_LINEAR) |
| 2189 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2190 | context->handleError(InvalidEnum() << "Linear blit not supported in this extension"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2191 | return false; |
| 2192 | } |
| 2193 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2194 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2195 | Framebuffer *drawFramebuffer = context->getGLState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2196 | |
| 2197 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2198 | { |
| 2199 | const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 2200 | const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer(); |
| 2201 | |
| 2202 | if (readColorAttachment && drawColorAttachment) |
| 2203 | { |
| 2204 | if (!(readColorAttachment->type() == GL_TEXTURE && |
| 2205 | readColorAttachment->getTextureImageIndex().type == GL_TEXTURE_2D) && |
| 2206 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2207 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2208 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2209 | context->handleError(InvalidOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2210 | return false; |
| 2211 | } |
| 2212 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2213 | for (size_t drawbufferIdx = 0; |
| 2214 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2215 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2216 | const FramebufferAttachment *attachment = |
| 2217 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2218 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2219 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2220 | if (!(attachment->type() == GL_TEXTURE && |
| 2221 | attachment->getTextureImageIndex().type == GL_TEXTURE_2D) && |
| 2222 | attachment->type() != GL_RENDERBUFFER && |
| 2223 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2224 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2225 | context->handleError(InvalidOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2226 | return false; |
| 2227 | } |
| 2228 | |
| 2229 | // Return an error if the destination formats do not match |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 2230 | if (!Format::SameSized(attachment->getFormat(), |
| 2231 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2232 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2233 | context->handleError(InvalidOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2234 | return false; |
| 2235 | } |
| 2236 | } |
| 2237 | } |
| 2238 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2239 | if (readFramebuffer->getSamples(context) != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2240 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2241 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2242 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2243 | context->handleError(InvalidOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2244 | return false; |
| 2245 | } |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2250 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2251 | for (size_t i = 0; i < 2; i++) |
| 2252 | { |
| 2253 | if (mask & masks[i]) |
| 2254 | { |
| 2255 | const FramebufferAttachment *readBuffer = |
| 2256 | readFramebuffer->getAttachment(attachments[i]); |
| 2257 | const FramebufferAttachment *drawBuffer = |
| 2258 | drawFramebuffer->getAttachment(attachments[i]); |
| 2259 | |
| 2260 | if (readBuffer && drawBuffer) |
| 2261 | { |
| 2262 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2263 | dstX0, dstY0, dstX1, dstY1)) |
| 2264 | { |
| 2265 | // only whole-buffer copies are permitted |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2266 | context->handleError(InvalidOperation() << "Only whole-buffer depth and " |
| 2267 | "stencil blits are supported by " |
| 2268 | "this extension."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2269 | return false; |
| 2270 | } |
| 2271 | |
| 2272 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2273 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2274 | context->handleError(InvalidOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2275 | return false; |
| 2276 | } |
| 2277 | } |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2282 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2283 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2284 | |
| 2285 | bool ValidateClear(ValidationContext *context, GLbitfield mask) |
| 2286 | { |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2287 | auto fbo = context->getGLState().getDrawFramebuffer(); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2288 | if (fbo->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2289 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2290 | context->handleError(InvalidFramebufferOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2291 | return false; |
| 2292 | } |
| 2293 | |
| 2294 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2295 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2296 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2297 | return false; |
| 2298 | } |
| 2299 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2300 | if (context->getExtensions().webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
| 2301 | { |
| 2302 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2303 | GL_SIGNED_NORMALIZED}; |
| 2304 | |
| 2305 | for (GLuint drawBufferIdx = 0; drawBufferIdx < context->getCaps().maxDrawBuffers; |
| 2306 | drawBufferIdx++) |
| 2307 | { |
| 2308 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2309 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2310 | { |
| 2311 | return false; |
| 2312 | } |
| 2313 | } |
| 2314 | } |
| 2315 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2316 | return true; |
| 2317 | } |
| 2318 | |
| 2319 | bool ValidateDrawBuffersEXT(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 2320 | { |
| 2321 | if (!context->getExtensions().drawBuffers) |
| 2322 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2323 | context->handleError(InvalidOperation() << "Extension not supported."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2324 | return false; |
| 2325 | } |
| 2326 | |
| 2327 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2328 | } |
| 2329 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2330 | bool ValidateTexImage2D(Context *context, |
| 2331 | GLenum target, |
| 2332 | GLint level, |
| 2333 | GLint internalformat, |
| 2334 | GLsizei width, |
| 2335 | GLsizei height, |
| 2336 | GLint border, |
| 2337 | GLenum format, |
| 2338 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2339 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2340 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2341 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2342 | { |
| 2343 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2344 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2345 | } |
| 2346 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2347 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2348 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2349 | 0, 0, width, height, 1, border, format, type, -1, |
| 2350 | pixels); |
| 2351 | } |
| 2352 | |
| 2353 | bool ValidateTexImage2DRobust(Context *context, |
| 2354 | GLenum target, |
| 2355 | GLint level, |
| 2356 | GLint internalformat, |
| 2357 | GLsizei width, |
| 2358 | GLsizei height, |
| 2359 | GLint border, |
| 2360 | GLenum format, |
| 2361 | GLenum type, |
| 2362 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2363 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2364 | { |
| 2365 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2366 | { |
| 2367 | return false; |
| 2368 | } |
| 2369 | |
| 2370 | if (context->getClientMajorVersion() < 3) |
| 2371 | { |
| 2372 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2373 | 0, 0, width, height, border, format, type, bufSize, |
| 2374 | pixels); |
| 2375 | } |
| 2376 | |
| 2377 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2378 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2379 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2380 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | bool ValidateTexSubImage2D(Context *context, |
| 2384 | GLenum target, |
| 2385 | GLint level, |
| 2386 | GLint xoffset, |
| 2387 | GLint yoffset, |
| 2388 | GLsizei width, |
| 2389 | GLsizei height, |
| 2390 | GLenum format, |
| 2391 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2392 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2393 | { |
| 2394 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2395 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2396 | { |
| 2397 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2398 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2399 | } |
| 2400 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2401 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2402 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2403 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 2404 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2405 | } |
| 2406 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2407 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
| 2408 | GLenum target, |
| 2409 | GLint level, |
| 2410 | GLint xoffset, |
| 2411 | GLint yoffset, |
| 2412 | GLsizei width, |
| 2413 | GLsizei height, |
| 2414 | GLenum format, |
| 2415 | GLenum type, |
| 2416 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2417 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2418 | { |
| 2419 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2420 | { |
| 2421 | return false; |
| 2422 | } |
| 2423 | |
| 2424 | if (context->getClientMajorVersion() < 3) |
| 2425 | { |
| 2426 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2427 | yoffset, width, height, 0, format, type, bufSize, |
| 2428 | pixels); |
| 2429 | } |
| 2430 | |
| 2431 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2432 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2433 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 2434 | pixels); |
| 2435 | } |
| 2436 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2437 | bool ValidateCompressedTexImage2D(Context *context, |
| 2438 | GLenum target, |
| 2439 | GLint level, |
| 2440 | GLenum internalformat, |
| 2441 | GLsizei width, |
| 2442 | GLsizei height, |
| 2443 | GLint border, |
| 2444 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2445 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2446 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2447 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2448 | { |
| 2449 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2450 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2451 | { |
| 2452 | return false; |
| 2453 | } |
| 2454 | } |
| 2455 | else |
| 2456 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2457 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2458 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2459 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2460 | data)) |
| 2461 | { |
| 2462 | return false; |
| 2463 | } |
| 2464 | } |
| 2465 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2466 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 2467 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 2468 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, 1)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2469 | if (blockSizeOrErr.isError()) |
| 2470 | { |
| 2471 | context->handleError(blockSizeOrErr.getError()); |
| 2472 | return false; |
| 2473 | } |
| 2474 | |
| 2475 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2476 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2477 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2478 | return false; |
| 2479 | } |
| 2480 | |
| 2481 | return true; |
| 2482 | } |
| 2483 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2484 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
| 2485 | GLenum target, |
| 2486 | GLint level, |
| 2487 | GLenum internalformat, |
| 2488 | GLsizei width, |
| 2489 | GLsizei height, |
| 2490 | GLint border, |
| 2491 | GLsizei imageSize, |
| 2492 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2493 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2494 | { |
| 2495 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2496 | { |
| 2497 | return false; |
| 2498 | } |
| 2499 | |
| 2500 | return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 2501 | border, imageSize, data); |
| 2502 | } |
| 2503 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
| 2504 | GLenum target, |
| 2505 | GLint level, |
| 2506 | GLint xoffset, |
| 2507 | GLint yoffset, |
| 2508 | GLsizei width, |
| 2509 | GLsizei height, |
| 2510 | GLenum format, |
| 2511 | GLsizei imageSize, |
| 2512 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2513 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2514 | { |
| 2515 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2516 | { |
| 2517 | return false; |
| 2518 | } |
| 2519 | |
| 2520 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 2521 | format, imageSize, data); |
| 2522 | } |
| 2523 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2524 | bool ValidateCompressedTexSubImage2D(Context *context, |
| 2525 | GLenum target, |
| 2526 | GLint level, |
| 2527 | GLint xoffset, |
| 2528 | GLint yoffset, |
| 2529 | GLsizei width, |
| 2530 | GLsizei height, |
| 2531 | GLenum format, |
| 2532 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2533 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2534 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2535 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2536 | { |
| 2537 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2538 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2539 | { |
| 2540 | return false; |
| 2541 | } |
| 2542 | } |
| 2543 | else |
| 2544 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2545 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2546 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2547 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2548 | data)) |
| 2549 | { |
| 2550 | return false; |
| 2551 | } |
| 2552 | } |
| 2553 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2554 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 2555 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 2556 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, 1)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2557 | if (blockSizeOrErr.isError()) |
| 2558 | { |
| 2559 | context->handleError(blockSizeOrErr.getError()); |
| 2560 | return false; |
| 2561 | } |
| 2562 | |
| 2563 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2564 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2565 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2566 | return false; |
| 2567 | } |
| 2568 | |
| 2569 | return true; |
| 2570 | } |
| 2571 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2572 | bool ValidateGetBufferPointervOES(Context *context, GLenum target, GLenum pname, void **params) |
| 2573 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2574 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | bool ValidateMapBufferOES(Context *context, GLenum target, GLenum access) |
| 2578 | { |
| 2579 | if (!context->getExtensions().mapBuffer) |
| 2580 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2581 | context->handleError(InvalidOperation() << "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2582 | return false; |
| 2583 | } |
| 2584 | |
| 2585 | if (!ValidBufferTarget(context, target)) |
| 2586 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2587 | context->handleError(InvalidEnum() << "Invalid buffer target."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2588 | return false; |
| 2589 | } |
| 2590 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2591 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2592 | |
| 2593 | if (buffer == nullptr) |
| 2594 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2595 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2596 | return false; |
| 2597 | } |
| 2598 | |
| 2599 | if (access != GL_WRITE_ONLY_OES) |
| 2600 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2601 | context->handleError(InvalidEnum() << "Non-write buffer mapping not supported."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2602 | return false; |
| 2603 | } |
| 2604 | |
| 2605 | if (buffer->isMapped()) |
| 2606 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2607 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2608 | return false; |
| 2609 | } |
| 2610 | |
| 2611 | return true; |
| 2612 | } |
| 2613 | |
| 2614 | bool ValidateUnmapBufferOES(Context *context, GLenum target) |
| 2615 | { |
| 2616 | if (!context->getExtensions().mapBuffer) |
| 2617 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2618 | context->handleError(InvalidOperation() << "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2619 | return false; |
| 2620 | } |
| 2621 | |
| 2622 | return ValidateUnmapBufferBase(context, target); |
| 2623 | } |
| 2624 | |
| 2625 | bool ValidateMapBufferRangeEXT(Context *context, |
| 2626 | GLenum target, |
| 2627 | GLintptr offset, |
| 2628 | GLsizeiptr length, |
| 2629 | GLbitfield access) |
| 2630 | { |
| 2631 | if (!context->getExtensions().mapBufferRange) |
| 2632 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2633 | context->handleError(InvalidOperation() << "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2634 | return false; |
| 2635 | } |
| 2636 | |
| 2637 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 2638 | } |
| 2639 | |
| 2640 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
| 2641 | GLenum target, |
| 2642 | GLintptr offset, |
| 2643 | GLsizeiptr length) |
| 2644 | { |
| 2645 | if (!context->getExtensions().mapBufferRange) |
| 2646 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2647 | context->handleError(InvalidOperation() << "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2648 | return false; |
| 2649 | } |
| 2650 | |
| 2651 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 2652 | } |
| 2653 | |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2654 | bool ValidateBindTexture(Context *context, GLenum target, GLuint texture) |
| 2655 | { |
| 2656 | Texture *textureObject = context->getTexture(texture); |
| 2657 | if (textureObject && textureObject->getTarget() != target && texture != 0) |
| 2658 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2659 | context->handleError(InvalidOperation() << "Invalid texture"); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2660 | return false; |
| 2661 | } |
| 2662 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 2663 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 2664 | !context->isTextureGenerated(texture)) |
| 2665 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2666 | context->handleError(InvalidOperation() << "Texture was not generated"); |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 2667 | return false; |
| 2668 | } |
| 2669 | |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2670 | switch (target) |
| 2671 | { |
| 2672 | case GL_TEXTURE_2D: |
| 2673 | case GL_TEXTURE_CUBE_MAP: |
| 2674 | break; |
| 2675 | |
| 2676 | case GL_TEXTURE_3D: |
| 2677 | case GL_TEXTURE_2D_ARRAY: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2678 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2679 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2680 | context->handleError(InvalidEnum() << "GLES 3.0 disabled"); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2681 | return false; |
| 2682 | } |
| 2683 | break; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 2684 | |
| 2685 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 2686 | if (context->getClientVersion() < Version(3, 1)) |
| 2687 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2688 | context->handleError(InvalidEnum() << "Context does not support GLES3.1"); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 2689 | return false; |
| 2690 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 2691 | break; |
| 2692 | |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2693 | case GL_TEXTURE_EXTERNAL_OES: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 2694 | if (!context->getExtensions().eglImageExternal && |
| 2695 | !context->getExtensions().eglStreamConsumerExternal) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2696 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2697 | context->handleError(InvalidEnum() << "External texture extension not enabled"); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2698 | return false; |
| 2699 | } |
| 2700 | break; |
| 2701 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2702 | context->handleError(InvalidEnum() << "Invalid target"); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2703 | return false; |
| 2704 | } |
| 2705 | |
| 2706 | return true; |
| 2707 | } |
| 2708 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2709 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 2710 | GLuint program, |
| 2711 | GLint location, |
| 2712 | const GLchar *name) |
| 2713 | { |
| 2714 | if (!context->getExtensions().bindUniformLocation) |
| 2715 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2716 | context->handleError(InvalidOperation() |
| 2717 | << "GL_CHROMIUM_bind_uniform_location is not available."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2718 | return false; |
| 2719 | } |
| 2720 | |
| 2721 | Program *programObject = GetValidProgram(context, program); |
| 2722 | if (!programObject) |
| 2723 | { |
| 2724 | return false; |
| 2725 | } |
| 2726 | |
| 2727 | if (location < 0) |
| 2728 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2729 | context->handleError(InvalidValue() << "Location cannot be less than 0."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2730 | return false; |
| 2731 | } |
| 2732 | |
| 2733 | const Caps &caps = context->getCaps(); |
| 2734 | if (static_cast<size_t>(location) >= |
| 2735 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 2736 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2737 | context->handleError(InvalidValue() << "Location must be less than " |
| 2738 | "(MAX_VERTEX_UNIFORM_VECTORS + " |
| 2739 | "MAX_FRAGMENT_UNIFORM_VECTORS) * 4"); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2740 | return false; |
| 2741 | } |
| 2742 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 2743 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 2744 | // shader-related entry points |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 2745 | if (context->getExtensions().webglCompatibility && |
| 2746 | !IsValidESSLString(name, strlen(name), false)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 2747 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2748 | context->handleError(InvalidValue() << "Uniform name contains invalid characters"); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 2749 | return false; |
| 2750 | } |
| 2751 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2752 | if (strncmp(name, "gl_", 3) == 0) |
| 2753 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2754 | context->handleError(InvalidOperation() |
| 2755 | << "Name cannot start with the reserved \"gl_\" prefix."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2756 | return false; |
| 2757 | } |
| 2758 | |
| 2759 | return true; |
| 2760 | } |
| 2761 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2762 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 2763 | { |
| 2764 | if (!context->getExtensions().framebufferMixedSamples) |
| 2765 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2766 | context->handleError(InvalidOperation() |
| 2767 | << "GL_CHROMIUM_framebuffer_mixed_samples is not available."); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 2768 | return false; |
| 2769 | } |
| 2770 | switch (components) |
| 2771 | { |
| 2772 | case GL_RGB: |
| 2773 | case GL_RGBA: |
| 2774 | case GL_ALPHA: |
| 2775 | case GL_NONE: |
| 2776 | break; |
| 2777 | default: |
| 2778 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2779 | InvalidEnum() |
| 2780 | << "GLenum components is not one of GL_RGB, GL_RGBA, GL_ALPHA or GL_NONE."); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 2781 | return false; |
| 2782 | } |
| 2783 | |
| 2784 | return true; |
| 2785 | } |
| 2786 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2787 | // CHROMIUM_path_rendering |
| 2788 | |
| 2789 | bool ValidateMatrix(Context *context, GLenum matrixMode, const GLfloat *matrix) |
| 2790 | { |
| 2791 | if (!context->getExtensions().pathRendering) |
| 2792 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2793 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2794 | return false; |
| 2795 | } |
| 2796 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 2797 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2798 | context->handleError(InvalidEnum() << "Invalid matrix mode."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2799 | return false; |
| 2800 | } |
| 2801 | if (matrix == nullptr) |
| 2802 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2803 | context->handleError(InvalidOperation() << "Invalid matrix."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2804 | return false; |
| 2805 | } |
| 2806 | return true; |
| 2807 | } |
| 2808 | |
| 2809 | bool ValidateMatrixMode(Context *context, GLenum matrixMode) |
| 2810 | { |
| 2811 | if (!context->getExtensions().pathRendering) |
| 2812 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2813 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2814 | return false; |
| 2815 | } |
| 2816 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 2817 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2818 | context->handleError(InvalidEnum() << "Invalid matrix mode."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2819 | return false; |
| 2820 | } |
| 2821 | return true; |
| 2822 | } |
| 2823 | |
| 2824 | bool ValidateGenPaths(Context *context, GLsizei range) |
| 2825 | { |
| 2826 | if (!context->getExtensions().pathRendering) |
| 2827 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2828 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2829 | return false; |
| 2830 | } |
| 2831 | |
| 2832 | // range = 0 is undefined in NV_path_rendering. |
| 2833 | // we add stricter semantic check here and require a non zero positive range. |
| 2834 | if (range <= 0) |
| 2835 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2836 | context->handleError(InvalidValue() << "Invalid range."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2837 | return false; |
| 2838 | } |
| 2839 | |
| 2840 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 2841 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2842 | context->handleError(InvalidOperation() << "Range overflow."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2843 | return false; |
| 2844 | } |
| 2845 | |
| 2846 | return true; |
| 2847 | } |
| 2848 | |
| 2849 | bool ValidateDeletePaths(Context *context, GLuint path, GLsizei range) |
| 2850 | { |
| 2851 | if (!context->getExtensions().pathRendering) |
| 2852 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2853 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2854 | return false; |
| 2855 | } |
| 2856 | |
| 2857 | // range = 0 is undefined in NV_path_rendering. |
| 2858 | // we add stricter semantic check here and require a non zero positive range. |
| 2859 | if (range <= 0) |
| 2860 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2861 | context->handleError(InvalidValue() << "Invalid range."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2862 | return false; |
| 2863 | } |
| 2864 | |
| 2865 | angle::CheckedNumeric<std::uint32_t> checkedRange(path); |
| 2866 | checkedRange += range; |
| 2867 | |
| 2868 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 2869 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2870 | context->handleError(InvalidOperation() << "Range overflow."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2871 | return false; |
| 2872 | } |
| 2873 | return true; |
| 2874 | } |
| 2875 | |
| 2876 | bool ValidatePathCommands(Context *context, |
| 2877 | GLuint path, |
| 2878 | GLsizei numCommands, |
| 2879 | const GLubyte *commands, |
| 2880 | GLsizei numCoords, |
| 2881 | GLenum coordType, |
| 2882 | const void *coords) |
| 2883 | { |
| 2884 | if (!context->getExtensions().pathRendering) |
| 2885 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2886 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2887 | return false; |
| 2888 | } |
| 2889 | if (!context->hasPath(path)) |
| 2890 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2891 | context->handleError(InvalidOperation() << "No such path object."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2892 | return false; |
| 2893 | } |
| 2894 | |
| 2895 | if (numCommands < 0) |
| 2896 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2897 | context->handleError(InvalidValue() << "Invalid number of commands."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2898 | return false; |
| 2899 | } |
| 2900 | else if (numCommands > 0) |
| 2901 | { |
| 2902 | if (!commands) |
| 2903 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2904 | context->handleError(InvalidValue() << "No commands array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2905 | return false; |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | if (numCoords < 0) |
| 2910 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2911 | context->handleError(InvalidValue() << "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2912 | return false; |
| 2913 | } |
| 2914 | else if (numCoords > 0) |
| 2915 | { |
| 2916 | if (!coords) |
| 2917 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2918 | context->handleError(InvalidValue() << "No coordinate array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2919 | return false; |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | std::uint32_t coordTypeSize = 0; |
| 2924 | switch (coordType) |
| 2925 | { |
| 2926 | case GL_BYTE: |
| 2927 | coordTypeSize = sizeof(GLbyte); |
| 2928 | break; |
| 2929 | |
| 2930 | case GL_UNSIGNED_BYTE: |
| 2931 | coordTypeSize = sizeof(GLubyte); |
| 2932 | break; |
| 2933 | |
| 2934 | case GL_SHORT: |
| 2935 | coordTypeSize = sizeof(GLshort); |
| 2936 | break; |
| 2937 | |
| 2938 | case GL_UNSIGNED_SHORT: |
| 2939 | coordTypeSize = sizeof(GLushort); |
| 2940 | break; |
| 2941 | |
| 2942 | case GL_FLOAT: |
| 2943 | coordTypeSize = sizeof(GLfloat); |
| 2944 | break; |
| 2945 | |
| 2946 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2947 | context->handleError(InvalidEnum() << "Invalid coordinate type."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2948 | return false; |
| 2949 | } |
| 2950 | |
| 2951 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 2952 | checkedSize += (coordTypeSize * numCoords); |
| 2953 | if (!checkedSize.IsValid()) |
| 2954 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2955 | context->handleError(InvalidOperation() << "Coord size overflow."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2956 | return false; |
| 2957 | } |
| 2958 | |
| 2959 | // early return skips command data validation when it doesn't exist. |
| 2960 | if (!commands) |
| 2961 | return true; |
| 2962 | |
| 2963 | GLsizei expectedNumCoords = 0; |
| 2964 | for (GLsizei i = 0; i < numCommands; ++i) |
| 2965 | { |
| 2966 | switch (commands[i]) |
| 2967 | { |
| 2968 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 2969 | break; |
| 2970 | case GL_MOVE_TO_CHROMIUM: |
| 2971 | case GL_LINE_TO_CHROMIUM: |
| 2972 | expectedNumCoords += 2; |
| 2973 | break; |
| 2974 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 2975 | expectedNumCoords += 4; |
| 2976 | break; |
| 2977 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 2978 | expectedNumCoords += 6; |
| 2979 | break; |
| 2980 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 2981 | expectedNumCoords += 5; |
| 2982 | break; |
| 2983 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2984 | context->handleError(InvalidEnum() << "Invalid command."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2985 | return false; |
| 2986 | } |
| 2987 | } |
| 2988 | if (expectedNumCoords != numCoords) |
| 2989 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2990 | context->handleError(InvalidValue() << "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 2991 | return false; |
| 2992 | } |
| 2993 | |
| 2994 | return true; |
| 2995 | } |
| 2996 | |
| 2997 | bool ValidateSetPathParameter(Context *context, GLuint path, GLenum pname, GLfloat value) |
| 2998 | { |
| 2999 | if (!context->getExtensions().pathRendering) |
| 3000 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3001 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3002 | return false; |
| 3003 | } |
| 3004 | if (!context->hasPath(path)) |
| 3005 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3006 | context->handleError(InvalidOperation() << "No such path object."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3007 | return false; |
| 3008 | } |
| 3009 | |
| 3010 | switch (pname) |
| 3011 | { |
| 3012 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3013 | if (value < 0.0f) |
| 3014 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3015 | context->handleError(InvalidValue() << "Invalid stroke width."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3016 | return false; |
| 3017 | } |
| 3018 | break; |
| 3019 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3020 | switch (static_cast<GLenum>(value)) |
| 3021 | { |
| 3022 | case GL_FLAT_CHROMIUM: |
| 3023 | case GL_SQUARE_CHROMIUM: |
| 3024 | case GL_ROUND_CHROMIUM: |
| 3025 | break; |
| 3026 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3027 | context->handleError(InvalidEnum() << "Invalid end caps."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3028 | return false; |
| 3029 | } |
| 3030 | break; |
| 3031 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3032 | switch (static_cast<GLenum>(value)) |
| 3033 | { |
| 3034 | case GL_MITER_REVERT_CHROMIUM: |
| 3035 | case GL_BEVEL_CHROMIUM: |
| 3036 | case GL_ROUND_CHROMIUM: |
| 3037 | break; |
| 3038 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3039 | context->handleError(InvalidEnum() << "Invalid join style."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3040 | return false; |
| 3041 | } |
| 3042 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3043 | if (value < 0.0f) |
| 3044 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3045 | context->handleError(InvalidValue() << "Invalid miter limit."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3046 | return false; |
| 3047 | } |
| 3048 | break; |
| 3049 | |
| 3050 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3051 | // no errors, only clamping. |
| 3052 | break; |
| 3053 | |
| 3054 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3055 | context->handleError(InvalidEnum() << "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3056 | return false; |
| 3057 | } |
| 3058 | return true; |
| 3059 | } |
| 3060 | |
| 3061 | bool ValidateGetPathParameter(Context *context, GLuint path, GLenum pname, GLfloat *value) |
| 3062 | { |
| 3063 | if (!context->getExtensions().pathRendering) |
| 3064 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3065 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3066 | return false; |
| 3067 | } |
| 3068 | |
| 3069 | if (!context->hasPath(path)) |
| 3070 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3071 | context->handleError(InvalidOperation() << "No such path object."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3072 | return false; |
| 3073 | } |
| 3074 | if (!value) |
| 3075 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3076 | context->handleError(InvalidValue() << "No value array."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3077 | return false; |
| 3078 | } |
| 3079 | |
| 3080 | switch (pname) |
| 3081 | { |
| 3082 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3083 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3084 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3085 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3086 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3087 | break; |
| 3088 | |
| 3089 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3090 | context->handleError(InvalidEnum() << "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3091 | return false; |
| 3092 | } |
| 3093 | |
| 3094 | return true; |
| 3095 | } |
| 3096 | |
| 3097 | bool ValidatePathStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
| 3098 | { |
| 3099 | if (!context->getExtensions().pathRendering) |
| 3100 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3101 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3102 | return false; |
| 3103 | } |
| 3104 | |
| 3105 | switch (func) |
| 3106 | { |
| 3107 | case GL_NEVER: |
| 3108 | case GL_ALWAYS: |
| 3109 | case GL_LESS: |
| 3110 | case GL_LEQUAL: |
| 3111 | case GL_EQUAL: |
| 3112 | case GL_GEQUAL: |
| 3113 | case GL_GREATER: |
| 3114 | case GL_NOTEQUAL: |
| 3115 | break; |
| 3116 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3117 | context->handleError(InvalidEnum() << "Invalid stencil function."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3118 | return false; |
| 3119 | } |
| 3120 | |
| 3121 | return true; |
| 3122 | } |
| 3123 | |
| 3124 | // Note that the spec specifies that for the path drawing commands |
| 3125 | // if the path object is not an existing path object the command |
| 3126 | // does nothing and no error is generated. |
| 3127 | // However if the path object exists but has not been specified any |
| 3128 | // commands then an error is generated. |
| 3129 | |
| 3130 | bool ValidateStencilFillPath(Context *context, GLuint path, GLenum fillMode, GLuint mask) |
| 3131 | { |
| 3132 | if (!context->getExtensions().pathRendering) |
| 3133 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3134 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3135 | return false; |
| 3136 | } |
| 3137 | if (context->hasPath(path) && !context->hasPathData(path)) |
| 3138 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3139 | context->handleError(InvalidOperation() << "No such path object."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3140 | return false; |
| 3141 | } |
| 3142 | |
| 3143 | switch (fillMode) |
| 3144 | { |
| 3145 | case GL_COUNT_UP_CHROMIUM: |
| 3146 | case GL_COUNT_DOWN_CHROMIUM: |
| 3147 | break; |
| 3148 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3149 | context->handleError(InvalidEnum() << "Invalid fill mode."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3150 | return false; |
| 3151 | } |
| 3152 | |
| 3153 | if (!isPow2(mask + 1)) |
| 3154 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3155 | context->handleError(InvalidValue() << "Invalid stencil bit mask."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3156 | return false; |
| 3157 | } |
| 3158 | |
| 3159 | return true; |
| 3160 | } |
| 3161 | |
| 3162 | bool ValidateStencilStrokePath(Context *context, GLuint path, GLint reference, GLuint mask) |
| 3163 | { |
| 3164 | if (!context->getExtensions().pathRendering) |
| 3165 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3166 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3167 | return false; |
| 3168 | } |
| 3169 | if (context->hasPath(path) && !context->hasPathData(path)) |
| 3170 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3171 | context->handleError(InvalidOperation() << "No such path or path has no data."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3172 | return false; |
| 3173 | } |
| 3174 | |
| 3175 | return true; |
| 3176 | } |
| 3177 | |
| 3178 | bool ValidateCoverPath(Context *context, GLuint path, GLenum coverMode) |
| 3179 | { |
| 3180 | if (!context->getExtensions().pathRendering) |
| 3181 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3182 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3183 | return false; |
| 3184 | } |
| 3185 | if (context->hasPath(path) && !context->hasPathData(path)) |
| 3186 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3187 | context->handleError(InvalidOperation() << "No such path object."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3188 | return false; |
| 3189 | } |
| 3190 | |
| 3191 | switch (coverMode) |
| 3192 | { |
| 3193 | case GL_CONVEX_HULL_CHROMIUM: |
| 3194 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3195 | break; |
| 3196 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3197 | context->handleError(InvalidEnum() << "Invalid cover mode."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3198 | return false; |
| 3199 | } |
| 3200 | return true; |
| 3201 | } |
| 3202 | |
| 3203 | bool ValidateStencilThenCoverFillPath(Context *context, |
| 3204 | GLuint path, |
| 3205 | GLenum fillMode, |
| 3206 | GLuint mask, |
| 3207 | GLenum coverMode) |
| 3208 | { |
| 3209 | return ValidateStencilFillPath(context, path, fillMode, mask) && |
| 3210 | ValidateCoverPath(context, path, coverMode); |
| 3211 | } |
| 3212 | |
| 3213 | bool ValidateStencilThenCoverStrokePath(Context *context, |
| 3214 | GLuint path, |
| 3215 | GLint reference, |
| 3216 | GLuint mask, |
| 3217 | GLenum coverMode) |
| 3218 | { |
| 3219 | return ValidateStencilStrokePath(context, path, reference, mask) && |
| 3220 | ValidateCoverPath(context, path, coverMode); |
| 3221 | } |
| 3222 | |
| 3223 | bool ValidateIsPath(Context *context) |
| 3224 | { |
| 3225 | if (!context->getExtensions().pathRendering) |
| 3226 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3227 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3228 | return false; |
| 3229 | } |
| 3230 | return true; |
| 3231 | } |
| 3232 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3233 | bool ValidateCoverFillPathInstanced(Context *context, |
| 3234 | GLsizei numPaths, |
| 3235 | GLenum pathNameType, |
| 3236 | const void *paths, |
| 3237 | GLuint pathBase, |
| 3238 | GLenum coverMode, |
| 3239 | GLenum transformType, |
| 3240 | const GLfloat *transformValues) |
| 3241 | { |
| 3242 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3243 | transformType, transformValues)) |
| 3244 | return false; |
| 3245 | |
| 3246 | switch (coverMode) |
| 3247 | { |
| 3248 | case GL_CONVEX_HULL_CHROMIUM: |
| 3249 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3250 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3251 | break; |
| 3252 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3253 | context->handleError(InvalidEnum() << "Invalid cover mode."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3254 | return false; |
| 3255 | } |
| 3256 | |
| 3257 | return true; |
| 3258 | } |
| 3259 | |
| 3260 | bool ValidateCoverStrokePathInstanced(Context *context, |
| 3261 | GLsizei numPaths, |
| 3262 | GLenum pathNameType, |
| 3263 | const void *paths, |
| 3264 | GLuint pathBase, |
| 3265 | GLenum coverMode, |
| 3266 | GLenum transformType, |
| 3267 | const GLfloat *transformValues) |
| 3268 | { |
| 3269 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3270 | transformType, transformValues)) |
| 3271 | return false; |
| 3272 | |
| 3273 | switch (coverMode) |
| 3274 | { |
| 3275 | case GL_CONVEX_HULL_CHROMIUM: |
| 3276 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3277 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3278 | break; |
| 3279 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3280 | context->handleError(InvalidEnum() << "Invalid cover mode."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3281 | return false; |
| 3282 | } |
| 3283 | |
| 3284 | return true; |
| 3285 | } |
| 3286 | |
| 3287 | bool ValidateStencilFillPathInstanced(Context *context, |
| 3288 | GLsizei numPaths, |
| 3289 | GLenum pathNameType, |
| 3290 | const void *paths, |
| 3291 | GLuint pathBase, |
| 3292 | GLenum fillMode, |
| 3293 | GLuint mask, |
| 3294 | GLenum transformType, |
| 3295 | const GLfloat *transformValues) |
| 3296 | { |
| 3297 | |
| 3298 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3299 | transformType, transformValues)) |
| 3300 | return false; |
| 3301 | |
| 3302 | switch (fillMode) |
| 3303 | { |
| 3304 | case GL_COUNT_UP_CHROMIUM: |
| 3305 | case GL_COUNT_DOWN_CHROMIUM: |
| 3306 | break; |
| 3307 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3308 | context->handleError(InvalidEnum() << "Invalid fill mode."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3309 | return false; |
| 3310 | } |
| 3311 | if (!isPow2(mask + 1)) |
| 3312 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3313 | context->handleError(InvalidValue() << "Invalid stencil bit mask."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3314 | return false; |
| 3315 | } |
| 3316 | return true; |
| 3317 | } |
| 3318 | |
| 3319 | bool ValidateStencilStrokePathInstanced(Context *context, |
| 3320 | GLsizei numPaths, |
| 3321 | GLenum pathNameType, |
| 3322 | const void *paths, |
| 3323 | GLuint pathBase, |
| 3324 | GLint reference, |
| 3325 | GLuint mask, |
| 3326 | GLenum transformType, |
| 3327 | const GLfloat *transformValues) |
| 3328 | { |
| 3329 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3330 | transformType, transformValues)) |
| 3331 | return false; |
| 3332 | |
| 3333 | // no more validation here. |
| 3334 | |
| 3335 | return true; |
| 3336 | } |
| 3337 | |
| 3338 | bool ValidateStencilThenCoverFillPathInstanced(Context *context, |
| 3339 | GLsizei numPaths, |
| 3340 | GLenum pathNameType, |
| 3341 | const void *paths, |
| 3342 | GLuint pathBase, |
| 3343 | GLenum fillMode, |
| 3344 | GLuint mask, |
| 3345 | GLenum coverMode, |
| 3346 | GLenum transformType, |
| 3347 | const GLfloat *transformValues) |
| 3348 | { |
| 3349 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3350 | transformType, transformValues)) |
| 3351 | return false; |
| 3352 | |
| 3353 | switch (coverMode) |
| 3354 | { |
| 3355 | case GL_CONVEX_HULL_CHROMIUM: |
| 3356 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3357 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3358 | break; |
| 3359 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3360 | context->handleError(InvalidEnum() << "Invalid cover mode."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3361 | return false; |
| 3362 | } |
| 3363 | |
| 3364 | switch (fillMode) |
| 3365 | { |
| 3366 | case GL_COUNT_UP_CHROMIUM: |
| 3367 | case GL_COUNT_DOWN_CHROMIUM: |
| 3368 | break; |
| 3369 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3370 | context->handleError(InvalidEnum() << "Invalid fill mode."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3371 | return false; |
| 3372 | } |
| 3373 | if (!isPow2(mask + 1)) |
| 3374 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3375 | context->handleError(InvalidValue() << "Invalid stencil bit mask."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3376 | return false; |
| 3377 | } |
| 3378 | |
| 3379 | return true; |
| 3380 | } |
| 3381 | |
| 3382 | bool ValidateStencilThenCoverStrokePathInstanced(Context *context, |
| 3383 | GLsizei numPaths, |
| 3384 | GLenum pathNameType, |
| 3385 | const void *paths, |
| 3386 | GLuint pathBase, |
| 3387 | GLint reference, |
| 3388 | GLuint mask, |
| 3389 | GLenum coverMode, |
| 3390 | GLenum transformType, |
| 3391 | const GLfloat *transformValues) |
| 3392 | { |
| 3393 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3394 | transformType, transformValues)) |
| 3395 | return false; |
| 3396 | |
| 3397 | switch (coverMode) |
| 3398 | { |
| 3399 | case GL_CONVEX_HULL_CHROMIUM: |
| 3400 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3401 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3402 | break; |
| 3403 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3404 | context->handleError(InvalidEnum() << "Invalid cover mode."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3405 | return false; |
| 3406 | } |
| 3407 | |
| 3408 | return true; |
| 3409 | } |
| 3410 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3411 | bool ValidateBindFragmentInputLocation(Context *context, |
| 3412 | GLuint program, |
| 3413 | GLint location, |
| 3414 | const GLchar *name) |
| 3415 | { |
| 3416 | if (!context->getExtensions().pathRendering) |
| 3417 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3418 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3419 | return false; |
| 3420 | } |
| 3421 | |
| 3422 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 3423 | if (location >= MaxLocation) |
| 3424 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3425 | context->handleError(InvalidValue() << "Location exceeds max varying."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3426 | return false; |
| 3427 | } |
| 3428 | |
| 3429 | const auto *programObject = context->getProgram(program); |
| 3430 | if (!programObject) |
| 3431 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3432 | context->handleError(InvalidOperation() << "No such program."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3433 | return false; |
| 3434 | } |
| 3435 | |
| 3436 | if (!name) |
| 3437 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3438 | context->handleError(InvalidValue() << "No name given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3439 | return false; |
| 3440 | } |
| 3441 | |
| 3442 | if (angle::BeginsWith(name, "gl_")) |
| 3443 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3444 | context->handleError(InvalidOperation() << "Cannot bind a built-in variable."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3445 | return false; |
| 3446 | } |
| 3447 | |
| 3448 | return true; |
| 3449 | } |
| 3450 | |
| 3451 | bool ValidateProgramPathFragmentInputGen(Context *context, |
| 3452 | GLuint program, |
| 3453 | GLint location, |
| 3454 | GLenum genMode, |
| 3455 | GLint components, |
| 3456 | const GLfloat *coeffs) |
| 3457 | { |
| 3458 | if (!context->getExtensions().pathRendering) |
| 3459 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3460 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3461 | return false; |
| 3462 | } |
| 3463 | |
| 3464 | const auto *programObject = context->getProgram(program); |
| 3465 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 3466 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3467 | context->handleError(InvalidOperation() << "No such program."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3468 | return false; |
| 3469 | } |
| 3470 | |
| 3471 | if (!programObject->isLinked()) |
| 3472 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3473 | context->handleError(InvalidOperation() << "Program is not linked."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3474 | return false; |
| 3475 | } |
| 3476 | |
| 3477 | switch (genMode) |
| 3478 | { |
| 3479 | case GL_NONE: |
| 3480 | if (components != 0) |
| 3481 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3482 | context->handleError(InvalidValue() << "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3483 | return false; |
| 3484 | } |
| 3485 | break; |
| 3486 | |
| 3487 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 3488 | case GL_EYE_LINEAR_CHROMIUM: |
| 3489 | case GL_CONSTANT_CHROMIUM: |
| 3490 | if (components < 1 || components > 4) |
| 3491 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3492 | context->handleError(InvalidValue() << "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3493 | return false; |
| 3494 | } |
| 3495 | if (!coeffs) |
| 3496 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3497 | context->handleError(InvalidValue() << "No coefficients array given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3498 | return false; |
| 3499 | } |
| 3500 | break; |
| 3501 | |
| 3502 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3503 | context->handleError(InvalidEnum() << "Invalid gen mode."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3504 | return false; |
| 3505 | } |
| 3506 | |
| 3507 | // If the location is -1 then the command is silently ignored |
| 3508 | // and no further validation is needed. |
| 3509 | if (location == -1) |
| 3510 | return true; |
| 3511 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 3512 | const auto &binding = programObject->getFragmentInputBindingInfo(context, location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3513 | |
| 3514 | if (!binding.valid) |
| 3515 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3516 | context->handleError(InvalidOperation() << "No such binding."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3517 | return false; |
| 3518 | } |
| 3519 | |
| 3520 | if (binding.type != GL_NONE) |
| 3521 | { |
| 3522 | GLint expectedComponents = 0; |
| 3523 | switch (binding.type) |
| 3524 | { |
| 3525 | case GL_FLOAT: |
| 3526 | expectedComponents = 1; |
| 3527 | break; |
| 3528 | case GL_FLOAT_VEC2: |
| 3529 | expectedComponents = 2; |
| 3530 | break; |
| 3531 | case GL_FLOAT_VEC3: |
| 3532 | expectedComponents = 3; |
| 3533 | break; |
| 3534 | case GL_FLOAT_VEC4: |
| 3535 | expectedComponents = 4; |
| 3536 | break; |
| 3537 | default: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3538 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3539 | InvalidOperation() |
| 3540 | << "Fragment input type is not a floating point scalar or vector."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3541 | return false; |
| 3542 | } |
| 3543 | if (expectedComponents != components && genMode != GL_NONE) |
| 3544 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3545 | context->handleError(InvalidOperation() << "Unexpected number of components"); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3546 | return false; |
| 3547 | } |
| 3548 | } |
| 3549 | return true; |
| 3550 | } |
| 3551 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3552 | bool ValidateCopyTextureCHROMIUM(Context *context, |
| 3553 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3554 | GLint sourceLevel, |
| 3555 | GLenum destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3556 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3557 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3558 | GLint internalFormat, |
| 3559 | GLenum destType, |
| 3560 | GLboolean unpackFlipY, |
| 3561 | GLboolean unpackPremultiplyAlpha, |
| 3562 | GLboolean unpackUnmultiplyAlpha) |
| 3563 | { |
| 3564 | if (!context->getExtensions().copyTexture) |
| 3565 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3566 | context->handleError(InvalidOperation() |
| 3567 | << "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3568 | return false; |
| 3569 | } |
| 3570 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3571 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3572 | if (source == nullptr) |
| 3573 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3574 | context->handleError(InvalidValue() << "Source texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3575 | return false; |
| 3576 | } |
| 3577 | |
| 3578 | if (!IsValidCopyTextureSourceTarget(context, source->getTarget())) |
| 3579 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3580 | context->handleError(InvalidValue() << "Source texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3581 | return false; |
| 3582 | } |
| 3583 | |
| 3584 | GLenum sourceTarget = source->getTarget(); |
| 3585 | ASSERT(sourceTarget != GL_TEXTURE_CUBE_MAP); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3586 | |
| 3587 | if (!IsValidCopyTextureSourceLevel(context, source->getTarget(), sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3588 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3589 | context->handleError(InvalidValue() << "Source texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3590 | return false; |
| 3591 | } |
| 3592 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3593 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 3594 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 3595 | if (sourceWidth == 0 || sourceHeight == 0) |
| 3596 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3597 | context->handleError(InvalidValue() |
| 3598 | << "The source level of the source texture must be defined."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3599 | return false; |
| 3600 | } |
| 3601 | |
| 3602 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 3603 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3604 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3605 | context->handleError(InvalidOperation() << "Source texture internal format is invalid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3606 | return false; |
| 3607 | } |
| 3608 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3609 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3610 | if (dest == nullptr) |
| 3611 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3612 | context->handleError(InvalidValue() |
| 3613 | << "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3614 | return false; |
| 3615 | } |
| 3616 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3617 | if (!IsValidCopyTextureDestinationTarget(context, dest->getTarget(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3618 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3619 | context->handleError(InvalidValue() << "Destination texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3620 | return false; |
| 3621 | } |
| 3622 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3623 | if (!IsValidCopyTextureDestinationLevel(context, destTarget, destLevel, sourceWidth, |
| 3624 | sourceHeight)) |
| 3625 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3626 | context->handleError(InvalidValue() << "Destination texture level is not valid."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3627 | return false; |
| 3628 | } |
| 3629 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3630 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 3631 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3632 | context->handleError(InvalidOperation() |
| 3633 | << "Destination internal format and type combination is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3634 | return false; |
| 3635 | } |
| 3636 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3637 | if (IsCubeMapTextureTarget(destTarget) && sourceWidth != sourceHeight) |
| 3638 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3639 | context->handleError( |
| 3640 | InvalidValue() << "Destination width and height must be equal for cube map textures."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3641 | return false; |
| 3642 | } |
| 3643 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3644 | if (dest->getImmutableFormat()) |
| 3645 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3646 | context->handleError(InvalidOperation() << "Destination texture is immutable."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3647 | return false; |
| 3648 | } |
| 3649 | |
| 3650 | return true; |
| 3651 | } |
| 3652 | |
| 3653 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
| 3654 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3655 | GLint sourceLevel, |
| 3656 | GLenum destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3657 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3658 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3659 | GLint xoffset, |
| 3660 | GLint yoffset, |
| 3661 | GLint x, |
| 3662 | GLint y, |
| 3663 | GLsizei width, |
| 3664 | GLsizei height, |
| 3665 | GLboolean unpackFlipY, |
| 3666 | GLboolean unpackPremultiplyAlpha, |
| 3667 | GLboolean unpackUnmultiplyAlpha) |
| 3668 | { |
| 3669 | if (!context->getExtensions().copyTexture) |
| 3670 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3671 | context->handleError(InvalidOperation() |
| 3672 | << "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3673 | return false; |
| 3674 | } |
| 3675 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3676 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3677 | if (source == nullptr) |
| 3678 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3679 | context->handleError(InvalidValue() << "Source texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3680 | return false; |
| 3681 | } |
| 3682 | |
| 3683 | if (!IsValidCopyTextureSourceTarget(context, source->getTarget())) |
| 3684 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3685 | context->handleError(InvalidValue() << "Source texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3686 | return false; |
| 3687 | } |
| 3688 | |
| 3689 | GLenum sourceTarget = source->getTarget(); |
| 3690 | ASSERT(sourceTarget != GL_TEXTURE_CUBE_MAP); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3691 | |
| 3692 | if (!IsValidCopyTextureSourceLevel(context, source->getTarget(), sourceLevel)) |
| 3693 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3694 | context->handleError(InvalidValue() << "Source texture level is not valid."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3695 | return false; |
| 3696 | } |
| 3697 | |
| 3698 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 3699 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3700 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3701 | context->handleError(InvalidValue() |
| 3702 | << "The source level of the source texture must be defined."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3703 | return false; |
| 3704 | } |
| 3705 | |
| 3706 | if (x < 0 || y < 0) |
| 3707 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3708 | context->handleError(InvalidValue() << "x and y cannot be negative."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3709 | return false; |
| 3710 | } |
| 3711 | |
| 3712 | if (width < 0 || height < 0) |
| 3713 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3714 | context->handleError(InvalidValue() << "width and height cannot be negative."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3715 | return false; |
| 3716 | } |
| 3717 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3718 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 3719 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3720 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3721 | context->handleError(InvalidValue() << "Source texture not large enough to copy from."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3722 | return false; |
| 3723 | } |
| 3724 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3725 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 3726 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3727 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3728 | context->handleError(InvalidOperation() << "Source texture internal format is invalid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3729 | return false; |
| 3730 | } |
| 3731 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3732 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3733 | if (dest == nullptr) |
| 3734 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3735 | context->handleError(InvalidValue() |
| 3736 | << "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3737 | return false; |
| 3738 | } |
| 3739 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3740 | if (!IsValidCopyTextureDestinationTarget(context, dest->getTarget(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3741 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3742 | context->handleError(InvalidValue() << "Destination texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3743 | return false; |
| 3744 | } |
| 3745 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3746 | if (!IsValidCopyTextureDestinationLevel(context, destTarget, destLevel, width, height)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3747 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3748 | context->handleError(InvalidValue() << "Destination texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3749 | return false; |
| 3750 | } |
| 3751 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3752 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 3753 | { |
Geoff Lang | bb1b19b | 2017-06-16 16:59:00 -0400 | [diff] [blame] | 3754 | context |
| 3755 | ->handleError(InvalidOperation() |
| 3756 | << "The destination level of the destination texture must be defined."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3757 | return false; |
| 3758 | } |
| 3759 | |
| 3760 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 3761 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3762 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3763 | context->handleError(InvalidOperation() |
| 3764 | << "Destination internal format and type combination is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3765 | return false; |
| 3766 | } |
| 3767 | |
| 3768 | if (xoffset < 0 || yoffset < 0) |
| 3769 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3770 | context->handleError(InvalidValue() << "xoffset and yoffset cannot be negative."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3771 | return false; |
| 3772 | } |
| 3773 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3774 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 3775 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3776 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3777 | context->handleError(InvalidValue() << "Destination texture not large enough to copy to."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3778 | return false; |
| 3779 | } |
| 3780 | |
| 3781 | return true; |
| 3782 | } |
| 3783 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3784 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId) |
| 3785 | { |
| 3786 | if (!context->getExtensions().copyCompressedTexture) |
| 3787 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3788 | context->handleError(InvalidOperation() |
| 3789 | << "GL_CHROMIUM_copy_compressed_texture extension not available."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3790 | return false; |
| 3791 | } |
| 3792 | |
| 3793 | const gl::Texture *source = context->getTexture(sourceId); |
| 3794 | if (source == nullptr) |
| 3795 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3796 | context->handleError(InvalidValue() << "Source texture is not a valid texture object."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3797 | return false; |
| 3798 | } |
| 3799 | |
| 3800 | if (source->getTarget() != GL_TEXTURE_2D) |
| 3801 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3802 | context->handleError(InvalidValue() << "Source texture must be of type GL_TEXTURE_2D."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3803 | return false; |
| 3804 | } |
| 3805 | |
| 3806 | if (source->getWidth(GL_TEXTURE_2D, 0) == 0 || source->getHeight(GL_TEXTURE_2D, 0) == 0) |
| 3807 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3808 | context->handleError(InvalidValue() << "Source texture must level 0 defined."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3809 | return false; |
| 3810 | } |
| 3811 | |
| 3812 | const gl::Format &sourceFormat = source->getFormat(GL_TEXTURE_2D, 0); |
| 3813 | if (!sourceFormat.info->compressed) |
| 3814 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3815 | context->handleError(InvalidOperation() |
| 3816 | << "Source texture must have a compressed internal format."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3817 | return false; |
| 3818 | } |
| 3819 | |
| 3820 | const gl::Texture *dest = context->getTexture(destId); |
| 3821 | if (dest == nullptr) |
| 3822 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3823 | context->handleError(InvalidValue() |
| 3824 | << "Destination texture is not a valid texture object."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3825 | return false; |
| 3826 | } |
| 3827 | |
| 3828 | if (dest->getTarget() != GL_TEXTURE_2D) |
| 3829 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3830 | context->handleError(InvalidValue() |
| 3831 | << "Destination texture must be of type GL_TEXTURE_2D."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3832 | return false; |
| 3833 | } |
| 3834 | |
| 3835 | if (dest->getImmutableFormat()) |
| 3836 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3837 | context->handleError(InvalidOperation() << "Destination cannot be immutable."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3838 | return false; |
| 3839 | } |
| 3840 | |
| 3841 | return true; |
| 3842 | } |
| 3843 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3844 | bool ValidateCreateShader(Context *context, GLenum type) |
| 3845 | { |
| 3846 | switch (type) |
| 3847 | { |
| 3848 | case GL_VERTEX_SHADER: |
| 3849 | case GL_FRAGMENT_SHADER: |
| 3850 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 3851 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3852 | case GL_COMPUTE_SHADER: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 3853 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3854 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3855 | context->handleError(InvalidEnum() << "GL_COMPUTE_SHADER requires OpenGL ES 3.1."); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 3856 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3857 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 3858 | break; |
| 3859 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3860 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3861 | context->handleError(InvalidEnum() << "Unknown shader type."); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3862 | return false; |
| 3863 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3864 | |
| 3865 | return true; |
| 3866 | } |
| 3867 | |
| 3868 | bool ValidateBufferData(ValidationContext *context, |
| 3869 | GLenum target, |
| 3870 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3871 | const void *data, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3872 | GLenum usage) |
| 3873 | { |
| 3874 | if (size < 0) |
| 3875 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3876 | context->handleError(InvalidValue()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3877 | return false; |
| 3878 | } |
| 3879 | |
| 3880 | switch (usage) |
| 3881 | { |
| 3882 | case GL_STREAM_DRAW: |
| 3883 | case GL_STATIC_DRAW: |
| 3884 | case GL_DYNAMIC_DRAW: |
| 3885 | break; |
| 3886 | |
| 3887 | case GL_STREAM_READ: |
| 3888 | case GL_STREAM_COPY: |
| 3889 | case GL_STATIC_READ: |
| 3890 | case GL_STATIC_COPY: |
| 3891 | case GL_DYNAMIC_READ: |
| 3892 | case GL_DYNAMIC_COPY: |
| 3893 | if (context->getClientMajorVersion() < 3) |
| 3894 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3895 | context->handleError(InvalidEnum()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3896 | return false; |
| 3897 | } |
| 3898 | break; |
| 3899 | |
| 3900 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3901 | context->handleError(InvalidEnum()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3902 | return false; |
| 3903 | } |
| 3904 | |
| 3905 | if (!ValidBufferTarget(context, target)) |
| 3906 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3907 | context->handleError(InvalidEnum()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3908 | return false; |
| 3909 | } |
| 3910 | |
| 3911 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 3912 | |
| 3913 | if (!buffer) |
| 3914 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3915 | context->handleError(InvalidOperation()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3916 | return false; |
| 3917 | } |
| 3918 | |
| 3919 | return true; |
| 3920 | } |
| 3921 | |
| 3922 | bool ValidateBufferSubData(ValidationContext *context, |
| 3923 | GLenum target, |
| 3924 | GLintptr offset, |
| 3925 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3926 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3927 | { |
| 3928 | if (size < 0 || offset < 0) |
| 3929 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3930 | context->handleError(InvalidValue()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3931 | return false; |
| 3932 | } |
| 3933 | |
| 3934 | if (!ValidBufferTarget(context, target)) |
| 3935 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3936 | context->handleError(InvalidEnum()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3937 | return false; |
| 3938 | } |
| 3939 | |
| 3940 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 3941 | |
| 3942 | if (!buffer) |
| 3943 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3944 | context->handleError(InvalidOperation()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3945 | return false; |
| 3946 | } |
| 3947 | |
| 3948 | if (buffer->isMapped()) |
| 3949 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3950 | context->handleError(InvalidOperation()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3951 | return false; |
| 3952 | } |
| 3953 | |
| 3954 | // Check for possible overflow of size + offset |
| 3955 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 3956 | checkedSize += offset; |
| 3957 | if (!checkedSize.IsValid()) |
| 3958 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3959 | context->handleError(OutOfMemory()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3960 | return false; |
| 3961 | } |
| 3962 | |
| 3963 | if (size + offset > buffer->getSize()) |
| 3964 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3965 | context->handleError(InvalidValue()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3966 | return false; |
| 3967 | } |
| 3968 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 3969 | return true; |
| 3970 | } |
| 3971 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 3972 | bool ValidateRequestExtensionANGLE(ValidationContext *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 3973 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 3974 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 3975 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3976 | context->handleError(InvalidOperation() << "GL_ANGLE_request_extension is not available."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 3977 | return false; |
| 3978 | } |
| 3979 | |
| 3980 | const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap(); |
| 3981 | auto extension = extensionInfos.find(name); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 3982 | if (extension == extensionInfos.end() || !extension->second.Requestable) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 3983 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3984 | context->handleError(InvalidOperation() << "Extension " << name << " is not requestable."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 3985 | return false; |
| 3986 | } |
| 3987 | |
| 3988 | return true; |
| 3989 | } |
| 3990 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 3991 | bool ValidateActiveTexture(ValidationContext *context, GLenum texture) |
| 3992 | { |
| 3993 | if (texture < GL_TEXTURE0 || |
| 3994 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 3995 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3996 | context->handleError(InvalidEnum()); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 3997 | return false; |
| 3998 | } |
| 3999 | |
| 4000 | return true; |
| 4001 | } |
| 4002 | |
| 4003 | bool ValidateAttachShader(ValidationContext *context, GLuint program, GLuint shader) |
| 4004 | { |
| 4005 | Program *programObject = GetValidProgram(context, program); |
| 4006 | if (!programObject) |
| 4007 | { |
| 4008 | return false; |
| 4009 | } |
| 4010 | |
| 4011 | Shader *shaderObject = GetValidShader(context, shader); |
| 4012 | if (!shaderObject) |
| 4013 | { |
| 4014 | return false; |
| 4015 | } |
| 4016 | |
| 4017 | switch (shaderObject->getType()) |
| 4018 | { |
| 4019 | case GL_VERTEX_SHADER: |
| 4020 | { |
| 4021 | if (programObject->getAttachedVertexShader()) |
| 4022 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4023 | context->handleError(InvalidOperation()); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4024 | return false; |
| 4025 | } |
| 4026 | break; |
| 4027 | } |
| 4028 | case GL_FRAGMENT_SHADER: |
| 4029 | { |
| 4030 | if (programObject->getAttachedFragmentShader()) |
| 4031 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4032 | context->handleError(InvalidOperation()); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4033 | return false; |
| 4034 | } |
| 4035 | break; |
| 4036 | } |
| 4037 | case GL_COMPUTE_SHADER: |
| 4038 | { |
| 4039 | if (programObject->getAttachedComputeShader()) |
| 4040 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4041 | context->handleError(InvalidOperation()); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4042 | return false; |
| 4043 | } |
| 4044 | break; |
| 4045 | } |
| 4046 | default: |
| 4047 | UNREACHABLE(); |
| 4048 | break; |
| 4049 | } |
| 4050 | |
| 4051 | return true; |
| 4052 | } |
| 4053 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4054 | bool ValidateBindAttribLocation(ValidationContext *context, |
| 4055 | GLuint program, |
| 4056 | GLuint index, |
| 4057 | const GLchar *name) |
| 4058 | { |
| 4059 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4060 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4061 | context->handleError(InvalidValue() << "Index exceeds MAX_VERTEX_ATTRIBS"); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4062 | return false; |
| 4063 | } |
| 4064 | |
| 4065 | if (strncmp(name, "gl_", 3) == 0) |
| 4066 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4067 | context->handleError(InvalidOperation() << "Cannot Bind built-in attributes"); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4068 | return false; |
| 4069 | } |
| 4070 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4071 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 4072 | // shader-related entry points |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 4073 | if (context->getExtensions().webglCompatibility && |
| 4074 | !IsValidESSLString(name, strlen(name), false)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4075 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4076 | context->handleError(InvalidValue() << "Attribute name contains invalid characters"); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4077 | return false; |
| 4078 | } |
| 4079 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4080 | return GetValidProgram(context, program) != nullptr; |
| 4081 | } |
| 4082 | |
| 4083 | bool ValidateBindBuffer(ValidationContext *context, GLenum target, GLuint buffer) |
| 4084 | { |
| 4085 | if (!ValidBufferTarget(context, target)) |
| 4086 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4087 | context->handleError(InvalidEnum() << "Invalid Buffer target"); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4088 | return false; |
| 4089 | } |
| 4090 | |
| 4091 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4092 | !context->isBufferGenerated(buffer)) |
| 4093 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4094 | context->handleError(InvalidOperation() << "Buffer was not generated"); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4095 | return false; |
| 4096 | } |
| 4097 | |
| 4098 | return true; |
| 4099 | } |
| 4100 | |
| 4101 | bool ValidateBindFramebuffer(ValidationContext *context, GLenum target, GLuint framebuffer) |
| 4102 | { |
| 4103 | if (!ValidFramebufferTarget(target)) |
| 4104 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4105 | context->handleError(InvalidEnum() << "Invalid Framebuffer target"); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4106 | return false; |
| 4107 | } |
| 4108 | |
| 4109 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4110 | !context->isFramebufferGenerated(framebuffer)) |
| 4111 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4112 | context->handleError(InvalidOperation() << "Framebuffer was not generated"); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4113 | return false; |
| 4114 | } |
| 4115 | |
| 4116 | return true; |
| 4117 | } |
| 4118 | |
| 4119 | bool ValidateBindRenderbuffer(ValidationContext *context, GLenum target, GLuint renderbuffer) |
| 4120 | { |
| 4121 | if (target != GL_RENDERBUFFER) |
| 4122 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4123 | context->handleError(InvalidEnum() << "Invalid Renderbuffer target"); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4124 | return false; |
| 4125 | } |
| 4126 | |
| 4127 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4128 | !context->isRenderbufferGenerated(renderbuffer)) |
| 4129 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4130 | context->handleError(InvalidOperation() << "Renderbuffer was not generated"); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4131 | return false; |
| 4132 | } |
| 4133 | |
| 4134 | return true; |
| 4135 | } |
| 4136 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4137 | static bool ValidBlendEquationMode(GLenum mode) |
| 4138 | { |
| 4139 | switch (mode) |
| 4140 | { |
| 4141 | case GL_FUNC_ADD: |
| 4142 | case GL_FUNC_SUBTRACT: |
| 4143 | case GL_FUNC_REVERSE_SUBTRACT: |
| 4144 | case GL_MIN: |
| 4145 | case GL_MAX: |
| 4146 | return true; |
| 4147 | |
| 4148 | default: |
| 4149 | return false; |
| 4150 | } |
| 4151 | } |
| 4152 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4153 | bool ValidateBlendColor(ValidationContext *context, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4154 | GLfloat red, |
| 4155 | GLfloat green, |
| 4156 | GLfloat blue, |
| 4157 | GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4158 | { |
| 4159 | return true; |
| 4160 | } |
| 4161 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4162 | bool ValidateBlendEquation(ValidationContext *context, GLenum mode) |
| 4163 | { |
| 4164 | if (!ValidBlendEquationMode(mode)) |
| 4165 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4166 | context->handleError(InvalidEnum() << "Invalid blend equation"); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4167 | return false; |
| 4168 | } |
| 4169 | |
| 4170 | return true; |
| 4171 | } |
| 4172 | |
| 4173 | bool ValidateBlendEquationSeparate(ValidationContext *context, GLenum modeRGB, GLenum modeAlpha) |
| 4174 | { |
| 4175 | if (!ValidBlendEquationMode(modeRGB)) |
| 4176 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4177 | context->handleError(InvalidEnum() << "Invalid RGB blend equation"); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4178 | return false; |
| 4179 | } |
| 4180 | |
| 4181 | if (!ValidBlendEquationMode(modeAlpha)) |
| 4182 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4183 | context->handleError(InvalidEnum() << "Invalid alpha blend equation"); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4184 | return false; |
| 4185 | } |
| 4186 | |
| 4187 | return true; |
| 4188 | } |
| 4189 | |
| 4190 | bool ValidateBlendFunc(ValidationContext *context, GLenum sfactor, GLenum dfactor) |
| 4191 | { |
| 4192 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 4193 | } |
| 4194 | |
| 4195 | static bool ValidSrcBlendFunc(GLenum srcBlend) |
| 4196 | { |
| 4197 | switch (srcBlend) |
| 4198 | { |
| 4199 | case GL_ZERO: |
| 4200 | case GL_ONE: |
| 4201 | case GL_SRC_COLOR: |
| 4202 | case GL_ONE_MINUS_SRC_COLOR: |
| 4203 | case GL_DST_COLOR: |
| 4204 | case GL_ONE_MINUS_DST_COLOR: |
| 4205 | case GL_SRC_ALPHA: |
| 4206 | case GL_ONE_MINUS_SRC_ALPHA: |
| 4207 | case GL_DST_ALPHA: |
| 4208 | case GL_ONE_MINUS_DST_ALPHA: |
| 4209 | case GL_CONSTANT_COLOR: |
| 4210 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 4211 | case GL_CONSTANT_ALPHA: |
| 4212 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 4213 | case GL_SRC_ALPHA_SATURATE: |
| 4214 | return true; |
| 4215 | |
| 4216 | default: |
| 4217 | return false; |
| 4218 | } |
| 4219 | } |
| 4220 | |
| 4221 | static bool ValidDstBlendFunc(GLenum dstBlend, GLint contextMajorVersion) |
| 4222 | { |
| 4223 | switch (dstBlend) |
| 4224 | { |
| 4225 | case GL_ZERO: |
| 4226 | case GL_ONE: |
| 4227 | case GL_SRC_COLOR: |
| 4228 | case GL_ONE_MINUS_SRC_COLOR: |
| 4229 | case GL_DST_COLOR: |
| 4230 | case GL_ONE_MINUS_DST_COLOR: |
| 4231 | case GL_SRC_ALPHA: |
| 4232 | case GL_ONE_MINUS_SRC_ALPHA: |
| 4233 | case GL_DST_ALPHA: |
| 4234 | case GL_ONE_MINUS_DST_ALPHA: |
| 4235 | case GL_CONSTANT_COLOR: |
| 4236 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 4237 | case GL_CONSTANT_ALPHA: |
| 4238 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 4239 | return true; |
| 4240 | |
| 4241 | case GL_SRC_ALPHA_SATURATE: |
| 4242 | return (contextMajorVersion >= 3); |
| 4243 | |
| 4244 | default: |
| 4245 | return false; |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | bool ValidateBlendFuncSeparate(ValidationContext *context, |
| 4250 | GLenum srcRGB, |
| 4251 | GLenum dstRGB, |
| 4252 | GLenum srcAlpha, |
| 4253 | GLenum dstAlpha) |
| 4254 | { |
| 4255 | if (!ValidSrcBlendFunc(srcRGB)) |
| 4256 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4257 | context->handleError(InvalidEnum() << "Invalid blend function"); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4258 | return false; |
| 4259 | } |
| 4260 | |
| 4261 | if (!ValidDstBlendFunc(dstRGB, context->getClientMajorVersion())) |
| 4262 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4263 | context->handleError(InvalidEnum() << "Invalid blend function"); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4264 | return false; |
| 4265 | } |
| 4266 | |
| 4267 | if (!ValidSrcBlendFunc(srcAlpha)) |
| 4268 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4269 | context->handleError(InvalidEnum() << "Invalid blend function"); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4270 | return false; |
| 4271 | } |
| 4272 | |
| 4273 | if (!ValidDstBlendFunc(dstAlpha, context->getClientMajorVersion())) |
| 4274 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4275 | context->handleError(InvalidEnum() << "Invalid blend function"); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4276 | return false; |
| 4277 | } |
| 4278 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4279 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 4280 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4281 | { |
| 4282 | bool constantColorUsed = |
| 4283 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 4284 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 4285 | |
| 4286 | bool constantAlphaUsed = |
| 4287 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 4288 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 4289 | |
| 4290 | if (constantColorUsed && constantAlphaUsed) |
| 4291 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4292 | const char *msg; |
| 4293 | if (context->getExtensions().webglCompatibility) |
| 4294 | { |
| 4295 | msg = |
| 4296 | "Invalid simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and " |
| 4297 | "GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR."; |
| 4298 | } |
| 4299 | else |
| 4300 | { |
| 4301 | msg = |
| 4302 | "Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and " |
| 4303 | "GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR not supported by this " |
| 4304 | "implementation."; |
| 4305 | ERR() << msg; |
| 4306 | } |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4307 | context->handleError(InvalidOperation() << msg); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4308 | return false; |
| 4309 | } |
| 4310 | } |
| 4311 | |
| 4312 | return true; |
| 4313 | } |
| 4314 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4315 | bool ValidateGetString(Context *context, GLenum name) |
| 4316 | { |
| 4317 | switch (name) |
| 4318 | { |
| 4319 | case GL_VENDOR: |
| 4320 | case GL_RENDERER: |
| 4321 | case GL_VERSION: |
| 4322 | case GL_SHADING_LANGUAGE_VERSION: |
| 4323 | case GL_EXTENSIONS: |
| 4324 | break; |
| 4325 | |
| 4326 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 4327 | if (!context->getExtensions().requestExtension) |
| 4328 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4329 | context->handleError(InvalidEnum() << "Invalid name."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4330 | return false; |
| 4331 | } |
| 4332 | break; |
| 4333 | |
| 4334 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4335 | context->handleError(InvalidEnum() << "Invalid name."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4336 | return false; |
| 4337 | } |
| 4338 | |
| 4339 | return true; |
| 4340 | } |
| 4341 | |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4342 | bool ValidateLineWidth(ValidationContext *context, GLfloat width) |
| 4343 | { |
| 4344 | if (width <= 0.0f || isNaN(width)) |
| 4345 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4346 | context->handleError(InvalidValue() << "Invalid width value."); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4347 | return false; |
| 4348 | } |
| 4349 | |
| 4350 | return true; |
| 4351 | } |
| 4352 | |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4353 | bool ValidateVertexAttribPointer(ValidationContext *context, |
| 4354 | GLuint index, |
| 4355 | GLint size, |
| 4356 | GLenum type, |
| 4357 | GLboolean normalized, |
| 4358 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4359 | const void *ptr) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4360 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4361 | if (!ValidateVertexFormatBase(context, index, size, type, false)) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4362 | { |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4363 | return false; |
| 4364 | } |
| 4365 | |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4366 | if (stride < 0) |
| 4367 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4368 | context->handleError(InvalidValue() << "stride cannot be negative."); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4369 | return false; |
| 4370 | } |
| 4371 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4372 | const Caps &caps = context->getCaps(); |
| 4373 | if (context->getClientVersion() >= ES_3_1) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4374 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4375 | if (stride > caps.maxVertexAttribStride) |
| 4376 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4377 | context->handleError(InvalidValue() |
| 4378 | << "stride cannot be greater than MAX_VERTEX_ATTRIB_STRIDE."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4379 | return false; |
| 4380 | } |
| 4381 | |
| 4382 | if (index >= caps.maxVertexAttribBindings) |
| 4383 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4384 | context->handleError(InvalidValue() |
| 4385 | << "index must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4386 | return false; |
| 4387 | } |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | // [OpenGL ES 3.0.2] Section 2.8 page 24: |
| 4391 | // An INVALID_OPERATION error is generated when a non-zero vertex array object |
| 4392 | // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point, |
| 4393 | // and the pointer argument is not NULL. |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 4394 | bool nullBufferAllowed = context->getGLState().areClientArraysEnabled() && |
| 4395 | context->getGLState().getVertexArray()->id() == 0; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4396 | if (!nullBufferAllowed && context->getGLState().getArrayBufferId() == 0 && ptr != nullptr) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4397 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4398 | context |
| 4399 | ->handleError(InvalidOperation() |
| 4400 | << "Client data cannot be used with a non-default vertex array object."); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4401 | return false; |
| 4402 | } |
| 4403 | |
| 4404 | if (context->getExtensions().webglCompatibility) |
| 4405 | { |
| 4406 | // WebGL 1.0 [Section 6.14] Fixed point support |
| 4407 | // The WebGL API does not support the GL_FIXED data type. |
| 4408 | if (type == GL_FIXED) |
| 4409 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4410 | context->handleError(InvalidEnum() << "GL_FIXED is not supported in WebGL."); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4411 | return false; |
| 4412 | } |
| 4413 | |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 4414 | if (!ValidateWebGLVertexAttribPointer(context, type, normalized, stride, ptr, false)) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4415 | { |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4416 | return false; |
| 4417 | } |
| 4418 | } |
| 4419 | |
| 4420 | return true; |
| 4421 | } |
| 4422 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4423 | bool ValidateDepthRangef(ValidationContext *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4424 | { |
| 4425 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 4426 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4427 | context->handleError(InvalidOperation() << "Depth near > far."); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4428 | return false; |
| 4429 | } |
| 4430 | |
| 4431 | return true; |
| 4432 | } |
| 4433 | |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4434 | bool ValidateRenderbufferStorage(ValidationContext *context, |
| 4435 | GLenum target, |
| 4436 | GLenum internalformat, |
| 4437 | GLsizei width, |
| 4438 | GLsizei height) |
| 4439 | { |
| 4440 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 4441 | height); |
| 4442 | } |
| 4443 | |
| 4444 | bool ValidateRenderbufferStorageMultisampleANGLE(ValidationContext *context, |
| 4445 | GLenum target, |
| 4446 | GLsizei samples, |
| 4447 | GLenum internalformat, |
| 4448 | GLsizei width, |
| 4449 | GLsizei height) |
| 4450 | { |
| 4451 | if (!context->getExtensions().framebufferMultisample) |
| 4452 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4453 | context->handleError(InvalidOperation() |
| 4454 | << "GL_ANGLE_framebuffer_multisample not available"); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4455 | return false; |
| 4456 | } |
| 4457 | |
| 4458 | // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal |
| 4459 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_OPERATION is |
| 4460 | // generated. |
| 4461 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 4462 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4463 | context->handleError(InvalidValue()); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4464 | return false; |
| 4465 | } |
| 4466 | |
| 4467 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 4468 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 4469 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 4470 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 4471 | if (context->getClientMajorVersion() >= 3) |
| 4472 | { |
| 4473 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 4474 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 4475 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4476 | context->handleError(OutOfMemory()); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4477 | return false; |
| 4478 | } |
| 4479 | } |
| 4480 | |
| 4481 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 4482 | width, height); |
| 4483 | } |
| 4484 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4485 | bool ValidateCheckFramebufferStatus(ValidationContext *context, GLenum target) |
| 4486 | { |
| 4487 | if (!ValidFramebufferTarget(target)) |
| 4488 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4489 | context->handleError(InvalidEnum() << "Invalid Framebuffer target"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4490 | return false; |
| 4491 | } |
| 4492 | |
| 4493 | return true; |
| 4494 | } |
| 4495 | |
| 4496 | bool ValidateClearColor(ValidationContext *context, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4497 | GLfloat red, |
| 4498 | GLfloat green, |
| 4499 | GLfloat blue, |
| 4500 | GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4501 | { |
| 4502 | return true; |
| 4503 | } |
| 4504 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4505 | bool ValidateClearDepthf(ValidationContext *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4506 | { |
| 4507 | return true; |
| 4508 | } |
| 4509 | |
| 4510 | bool ValidateClearStencil(ValidationContext *context, GLint s) |
| 4511 | { |
| 4512 | return true; |
| 4513 | } |
| 4514 | |
| 4515 | bool ValidateColorMask(ValidationContext *context, |
| 4516 | GLboolean red, |
| 4517 | GLboolean green, |
| 4518 | GLboolean blue, |
| 4519 | GLboolean alpha) |
| 4520 | { |
| 4521 | return true; |
| 4522 | } |
| 4523 | |
| 4524 | bool ValidateCompileShader(ValidationContext *context, GLuint shader) |
| 4525 | { |
| 4526 | return true; |
| 4527 | } |
| 4528 | |
| 4529 | bool ValidateCreateProgram(ValidationContext *context) |
| 4530 | { |
| 4531 | return true; |
| 4532 | } |
| 4533 | |
| 4534 | bool ValidateCullFace(ValidationContext *context, GLenum mode) |
| 4535 | { |
| 4536 | switch (mode) |
| 4537 | { |
| 4538 | case GL_FRONT: |
| 4539 | case GL_BACK: |
| 4540 | case GL_FRONT_AND_BACK: |
| 4541 | break; |
| 4542 | |
| 4543 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4544 | context->handleError(InvalidEnum() << "Invalid cull face parameter"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4545 | return false; |
| 4546 | } |
| 4547 | |
| 4548 | return true; |
| 4549 | } |
| 4550 | |
| 4551 | bool ValidateDeleteProgram(ValidationContext *context, GLuint program) |
| 4552 | { |
| 4553 | if (program == 0) |
| 4554 | { |
| 4555 | return false; |
| 4556 | } |
| 4557 | |
| 4558 | if (!context->getProgram(program)) |
| 4559 | { |
| 4560 | if (context->getShader(program)) |
| 4561 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4562 | context->handleError(InvalidOperation() << "Shader handle passed to DeleteProgram"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4563 | return false; |
| 4564 | } |
| 4565 | else |
| 4566 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4567 | context->handleError(InvalidValue() << "Invalid program handle"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4568 | return false; |
| 4569 | } |
| 4570 | } |
| 4571 | |
| 4572 | return true; |
| 4573 | } |
| 4574 | |
| 4575 | bool ValidateDeleteShader(ValidationContext *context, GLuint shader) |
| 4576 | { |
| 4577 | if (shader == 0) |
| 4578 | { |
| 4579 | return false; |
| 4580 | } |
| 4581 | |
| 4582 | if (!context->getShader(shader)) |
| 4583 | { |
| 4584 | if (context->getProgram(shader)) |
| 4585 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4586 | context->handleError(InvalidOperation() << "Program handle passed to DeleteShader"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4587 | return false; |
| 4588 | } |
| 4589 | else |
| 4590 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4591 | context->handleError(InvalidValue() << "Invalid shader handle"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4592 | return false; |
| 4593 | } |
| 4594 | } |
| 4595 | |
| 4596 | return true; |
| 4597 | } |
| 4598 | |
| 4599 | bool ValidateDepthFunc(ValidationContext *context, GLenum func) |
| 4600 | { |
| 4601 | switch (func) |
| 4602 | { |
| 4603 | case GL_NEVER: |
| 4604 | case GL_ALWAYS: |
| 4605 | case GL_LESS: |
| 4606 | case GL_LEQUAL: |
| 4607 | case GL_EQUAL: |
| 4608 | case GL_GREATER: |
| 4609 | case GL_GEQUAL: |
| 4610 | case GL_NOTEQUAL: |
| 4611 | break; |
| 4612 | |
| 4613 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4614 | context->handleError(InvalidEnum() << "Invalid depth function"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4615 | return false; |
| 4616 | } |
| 4617 | |
| 4618 | return true; |
| 4619 | } |
| 4620 | |
| 4621 | bool ValidateDepthMask(ValidationContext *context, GLboolean flag) |
| 4622 | { |
| 4623 | return true; |
| 4624 | } |
| 4625 | |
| 4626 | bool ValidateDetachShader(ValidationContext *context, GLuint program, GLuint shader) |
| 4627 | { |
| 4628 | Program *programObject = GetValidProgram(context, program); |
| 4629 | if (!programObject) |
| 4630 | { |
| 4631 | return false; |
| 4632 | } |
| 4633 | |
| 4634 | Shader *shaderObject = GetValidShader(context, shader); |
| 4635 | if (!shaderObject) |
| 4636 | { |
| 4637 | return false; |
| 4638 | } |
| 4639 | |
| 4640 | const Shader *attachedShader = nullptr; |
| 4641 | |
| 4642 | switch (shaderObject->getType()) |
| 4643 | { |
| 4644 | case GL_VERTEX_SHADER: |
| 4645 | { |
| 4646 | attachedShader = programObject->getAttachedVertexShader(); |
| 4647 | break; |
| 4648 | } |
| 4649 | case GL_FRAGMENT_SHADER: |
| 4650 | { |
| 4651 | attachedShader = programObject->getAttachedFragmentShader(); |
| 4652 | break; |
| 4653 | } |
| 4654 | case GL_COMPUTE_SHADER: |
| 4655 | { |
| 4656 | attachedShader = programObject->getAttachedComputeShader(); |
| 4657 | break; |
| 4658 | } |
| 4659 | default: |
| 4660 | UNREACHABLE(); |
| 4661 | return false; |
| 4662 | } |
| 4663 | |
| 4664 | if (attachedShader != shaderObject) |
| 4665 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4666 | context->handleError(InvalidOperation() << "Cannot detach non-attached shader."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4667 | return false; |
| 4668 | } |
| 4669 | |
| 4670 | return true; |
| 4671 | } |
| 4672 | |
| 4673 | bool ValidateDisableVertexAttribArray(ValidationContext *context, GLuint index) |
| 4674 | { |
| 4675 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4676 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4677 | context->handleError(InvalidValue() << "Attrib array index out of range"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4678 | return false; |
| 4679 | } |
| 4680 | |
| 4681 | return true; |
| 4682 | } |
| 4683 | |
| 4684 | bool ValidateEnableVertexAttribArray(ValidationContext *context, GLuint index) |
| 4685 | { |
| 4686 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4687 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4688 | context->handleError(InvalidValue() << "Attrib array index out of range"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4689 | return false; |
| 4690 | } |
| 4691 | |
| 4692 | return true; |
| 4693 | } |
| 4694 | |
| 4695 | bool ValidateFinish(ValidationContext *context) |
| 4696 | { |
| 4697 | return true; |
| 4698 | } |
| 4699 | |
| 4700 | bool ValidateFlush(ValidationContext *context) |
| 4701 | { |
| 4702 | return true; |
| 4703 | } |
| 4704 | |
| 4705 | bool ValidateFrontFace(ValidationContext *context, GLenum mode) |
| 4706 | { |
| 4707 | switch (mode) |
| 4708 | { |
| 4709 | case GL_CW: |
| 4710 | case GL_CCW: |
| 4711 | break; |
| 4712 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4713 | context->handleError(InvalidEnum() << "Invalid mode for FrontFace"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4714 | return false; |
| 4715 | } |
| 4716 | |
| 4717 | return true; |
| 4718 | } |
| 4719 | |
| 4720 | bool ValidateGetActiveAttrib(ValidationContext *context, |
| 4721 | GLuint program, |
| 4722 | GLuint index, |
| 4723 | GLsizei bufsize, |
| 4724 | GLsizei *length, |
| 4725 | GLint *size, |
| 4726 | GLenum *type, |
| 4727 | GLchar *name) |
| 4728 | { |
| 4729 | if (bufsize < 0) |
| 4730 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4731 | context->handleError(InvalidValue() << "bufsize must be non-negative."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4732 | return false; |
| 4733 | } |
| 4734 | |
| 4735 | Program *programObject = GetValidProgram(context, program); |
| 4736 | |
| 4737 | if (!programObject) |
| 4738 | { |
| 4739 | return false; |
| 4740 | } |
| 4741 | |
| 4742 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 4743 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4744 | context->handleError(InvalidValue() << "index exeeds program active attribute count."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4745 | return false; |
| 4746 | } |
| 4747 | |
| 4748 | return true; |
| 4749 | } |
| 4750 | |
| 4751 | bool ValidateGetActiveUniform(ValidationContext *context, |
| 4752 | GLuint program, |
| 4753 | GLuint index, |
| 4754 | GLsizei bufsize, |
| 4755 | GLsizei *length, |
| 4756 | GLint *size, |
| 4757 | GLenum *type, |
| 4758 | GLchar *name) |
| 4759 | { |
| 4760 | if (bufsize < 0) |
| 4761 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4762 | context->handleError(InvalidValue() << "bufsize must be non-negative."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4763 | return false; |
| 4764 | } |
| 4765 | |
| 4766 | Program *programObject = GetValidProgram(context, program); |
| 4767 | |
| 4768 | if (!programObject) |
| 4769 | { |
| 4770 | return false; |
| 4771 | } |
| 4772 | |
| 4773 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 4774 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4775 | context->handleError(InvalidValue() << "index exceeds program active uniform count."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4776 | return false; |
| 4777 | } |
| 4778 | |
| 4779 | return true; |
| 4780 | } |
| 4781 | |
| 4782 | bool ValidateGetAttachedShaders(ValidationContext *context, |
| 4783 | GLuint program, |
| 4784 | GLsizei maxcount, |
| 4785 | GLsizei *count, |
| 4786 | GLuint *shaders) |
| 4787 | { |
| 4788 | if (maxcount < 0) |
| 4789 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4790 | context->handleError(InvalidValue() << "max count must be non-negative."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4791 | return false; |
| 4792 | } |
| 4793 | |
| 4794 | Program *programObject = GetValidProgram(context, program); |
| 4795 | |
| 4796 | if (!programObject) |
| 4797 | { |
| 4798 | return false; |
| 4799 | } |
| 4800 | |
| 4801 | return true; |
| 4802 | } |
| 4803 | |
| 4804 | bool ValidateGetAttribLocation(ValidationContext *context, GLuint program, const GLchar *name) |
| 4805 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4806 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 4807 | // shader-related entry points |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 4808 | if (context->getExtensions().webglCompatibility && |
| 4809 | !IsValidESSLString(name, strlen(name), false)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4810 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4811 | context->handleError(InvalidValue() << "Attribute name contains invalid characters"); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4812 | return false; |
| 4813 | } |
| 4814 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4815 | Program *programObject = GetValidProgram(context, program); |
| 4816 | |
| 4817 | if (!programObject) |
| 4818 | { |
| 4819 | return false; |
| 4820 | } |
| 4821 | |
| 4822 | if (!programObject->isLinked()) |
| 4823 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4824 | context->handleError(InvalidOperation() << "program not linked."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4825 | return false; |
| 4826 | } |
| 4827 | |
| 4828 | return true; |
| 4829 | } |
| 4830 | |
| 4831 | bool ValidateGetBooleanv(ValidationContext *context, GLenum pname, GLboolean *params) |
| 4832 | { |
| 4833 | GLenum nativeType; |
| 4834 | unsigned int numParams = 0; |
| 4835 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 4836 | } |
| 4837 | |
| 4838 | bool ValidateGetError(ValidationContext *context) |
| 4839 | { |
| 4840 | return true; |
| 4841 | } |
| 4842 | |
| 4843 | bool ValidateGetFloatv(ValidationContext *context, GLenum pname, GLfloat *params) |
| 4844 | { |
| 4845 | GLenum nativeType; |
| 4846 | unsigned int numParams = 0; |
| 4847 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 4848 | } |
| 4849 | |
| 4850 | bool ValidateGetIntegerv(ValidationContext *context, GLenum pname, GLint *params) |
| 4851 | { |
| 4852 | GLenum nativeType; |
| 4853 | unsigned int numParams = 0; |
| 4854 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 4855 | } |
| 4856 | |
| 4857 | bool ValidateGetProgramInfoLog(ValidationContext *context, |
| 4858 | GLuint program, |
| 4859 | GLsizei bufsize, |
| 4860 | GLsizei *length, |
| 4861 | GLchar *infolog) |
| 4862 | { |
| 4863 | if (bufsize < 0) |
| 4864 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4865 | context->handleError(InvalidValue() << "bufsize must be non-negative."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4866 | return false; |
| 4867 | } |
| 4868 | |
| 4869 | Program *programObject = GetValidProgram(context, program); |
| 4870 | if (!programObject) |
| 4871 | { |
| 4872 | return false; |
| 4873 | } |
| 4874 | |
| 4875 | return true; |
| 4876 | } |
| 4877 | |
| 4878 | bool ValidateGetShaderInfoLog(ValidationContext *context, |
| 4879 | GLuint shader, |
| 4880 | GLsizei bufsize, |
| 4881 | GLsizei *length, |
| 4882 | GLchar *infolog) |
| 4883 | { |
| 4884 | if (bufsize < 0) |
| 4885 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4886 | context->handleError(InvalidValue() << "bufsize must be non-negative."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4887 | return false; |
| 4888 | } |
| 4889 | |
| 4890 | Shader *shaderObject = GetValidShader(context, shader); |
| 4891 | if (!shaderObject) |
| 4892 | { |
| 4893 | return false; |
| 4894 | } |
| 4895 | |
| 4896 | return true; |
| 4897 | } |
| 4898 | |
| 4899 | bool ValidateGetShaderPrecisionFormat(ValidationContext *context, |
| 4900 | GLenum shadertype, |
| 4901 | GLenum precisiontype, |
| 4902 | GLint *range, |
| 4903 | GLint *precision) |
| 4904 | { |
| 4905 | switch (shadertype) |
| 4906 | { |
| 4907 | case GL_VERTEX_SHADER: |
| 4908 | case GL_FRAGMENT_SHADER: |
| 4909 | break; |
| 4910 | case GL_COMPUTE_SHADER: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4911 | context->handleError(InvalidOperation() |
| 4912 | << "compute shader precision not yet implemented."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4913 | return false; |
| 4914 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4915 | context->handleError(InvalidEnum() << "invalid shader type."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4916 | return false; |
| 4917 | } |
| 4918 | |
| 4919 | switch (precisiontype) |
| 4920 | { |
| 4921 | case GL_LOW_FLOAT: |
| 4922 | case GL_MEDIUM_FLOAT: |
| 4923 | case GL_HIGH_FLOAT: |
| 4924 | case GL_LOW_INT: |
| 4925 | case GL_MEDIUM_INT: |
| 4926 | case GL_HIGH_INT: |
| 4927 | break; |
| 4928 | |
| 4929 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4930 | context->handleError(InvalidEnum() << "invalid precision type."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4931 | return false; |
| 4932 | } |
| 4933 | |
| 4934 | return true; |
| 4935 | } |
| 4936 | |
| 4937 | bool ValidateGetShaderSource(ValidationContext *context, |
| 4938 | GLuint shader, |
| 4939 | GLsizei bufsize, |
| 4940 | GLsizei *length, |
| 4941 | GLchar *source) |
| 4942 | { |
| 4943 | if (bufsize < 0) |
| 4944 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4945 | context->handleError(InvalidValue() << "bufsize must be non-negative."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4946 | return false; |
| 4947 | } |
| 4948 | |
| 4949 | Shader *shaderObject = GetValidShader(context, shader); |
| 4950 | if (!shaderObject) |
| 4951 | { |
| 4952 | return false; |
| 4953 | } |
| 4954 | |
| 4955 | return true; |
| 4956 | } |
| 4957 | |
| 4958 | bool ValidateGetUniformLocation(ValidationContext *context, GLuint program, const GLchar *name) |
| 4959 | { |
| 4960 | if (strstr(name, "gl_") == name) |
| 4961 | { |
| 4962 | return false; |
| 4963 | } |
| 4964 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4965 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 4966 | // shader-related entry points |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 4967 | if (context->getExtensions().webglCompatibility && |
| 4968 | !IsValidESSLString(name, strlen(name), false)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4969 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4970 | context->handleError(InvalidValue() << "Uniform name contains invalid characters"); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4971 | return false; |
| 4972 | } |
| 4973 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4974 | Program *programObject = GetValidProgram(context, program); |
| 4975 | |
| 4976 | if (!programObject) |
| 4977 | { |
| 4978 | return false; |
| 4979 | } |
| 4980 | |
| 4981 | if (!programObject->isLinked()) |
| 4982 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4983 | context->handleError(InvalidOperation() << "program is not linked."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4984 | return false; |
| 4985 | } |
| 4986 | |
| 4987 | return true; |
| 4988 | } |
| 4989 | |
| 4990 | bool ValidateHint(ValidationContext *context, GLenum target, GLenum mode) |
| 4991 | { |
| 4992 | switch (mode) |
| 4993 | { |
| 4994 | case GL_FASTEST: |
| 4995 | case GL_NICEST: |
| 4996 | case GL_DONT_CARE: |
| 4997 | break; |
| 4998 | |
| 4999 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5000 | context->handleError(InvalidEnum() << "invalid hint mode."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5001 | return false; |
| 5002 | } |
| 5003 | |
| 5004 | switch (target) |
| 5005 | { |
| 5006 | case GL_GENERATE_MIPMAP_HINT: |
| 5007 | break; |
| 5008 | |
| 5009 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: |
| 5010 | if (!context->getExtensions().standardDerivatives) |
| 5011 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5012 | context->handleError(InvalidOperation() |
| 5013 | << "hint requires OES_standard_derivatives."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5014 | return false; |
| 5015 | } |
| 5016 | break; |
| 5017 | |
| 5018 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5019 | context->handleError(InvalidEnum() << "invalid hint target."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5020 | return false; |
| 5021 | } |
| 5022 | |
| 5023 | return true; |
| 5024 | } |
| 5025 | |
| 5026 | bool ValidateIsBuffer(ValidationContext *context, GLuint buffer) |
| 5027 | { |
| 5028 | return true; |
| 5029 | } |
| 5030 | |
| 5031 | bool ValidateIsFramebuffer(ValidationContext *context, GLuint framebuffer) |
| 5032 | { |
| 5033 | return true; |
| 5034 | } |
| 5035 | |
| 5036 | bool ValidateIsProgram(ValidationContext *context, GLuint program) |
| 5037 | { |
| 5038 | return true; |
| 5039 | } |
| 5040 | |
| 5041 | bool ValidateIsRenderbuffer(ValidationContext *context, GLuint renderbuffer) |
| 5042 | { |
| 5043 | return true; |
| 5044 | } |
| 5045 | |
| 5046 | bool ValidateIsShader(ValidationContext *context, GLuint shader) |
| 5047 | { |
| 5048 | return true; |
| 5049 | } |
| 5050 | |
| 5051 | bool ValidateIsTexture(ValidationContext *context, GLuint texture) |
| 5052 | { |
| 5053 | return true; |
| 5054 | } |
| 5055 | |
| 5056 | bool ValidatePixelStorei(ValidationContext *context, GLenum pname, GLint param) |
| 5057 | { |
| 5058 | if (context->getClientMajorVersion() < 3) |
| 5059 | { |
| 5060 | switch (pname) |
| 5061 | { |
| 5062 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5063 | case GL_UNPACK_SKIP_IMAGES: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5064 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5065 | return false; |
| 5066 | |
| 5067 | case GL_UNPACK_ROW_LENGTH: |
| 5068 | case GL_UNPACK_SKIP_ROWS: |
| 5069 | case GL_UNPACK_SKIP_PIXELS: |
| 5070 | if (!context->getExtensions().unpackSubimage) |
| 5071 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5072 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5073 | return false; |
| 5074 | } |
| 5075 | break; |
| 5076 | |
| 5077 | case GL_PACK_ROW_LENGTH: |
| 5078 | case GL_PACK_SKIP_ROWS: |
| 5079 | case GL_PACK_SKIP_PIXELS: |
| 5080 | if (!context->getExtensions().packSubimage) |
| 5081 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5082 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5083 | return false; |
| 5084 | } |
| 5085 | break; |
| 5086 | } |
| 5087 | } |
| 5088 | |
| 5089 | if (param < 0) |
| 5090 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5091 | context->handleError(InvalidValue() << "Cannot use negative values in PixelStorei"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5092 | return false; |
| 5093 | } |
| 5094 | |
| 5095 | switch (pname) |
| 5096 | { |
| 5097 | case GL_UNPACK_ALIGNMENT: |
| 5098 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5099 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5100 | context->handleError(InvalidValue()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5101 | return false; |
| 5102 | } |
| 5103 | break; |
| 5104 | |
| 5105 | case GL_PACK_ALIGNMENT: |
| 5106 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5107 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5108 | context->handleError(InvalidValue()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5109 | return false; |
| 5110 | } |
| 5111 | break; |
| 5112 | |
| 5113 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
| 5114 | case GL_UNPACK_ROW_LENGTH: |
| 5115 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5116 | case GL_UNPACK_SKIP_IMAGES: |
| 5117 | case GL_UNPACK_SKIP_ROWS: |
| 5118 | case GL_UNPACK_SKIP_PIXELS: |
| 5119 | case GL_PACK_ROW_LENGTH: |
| 5120 | case GL_PACK_SKIP_ROWS: |
| 5121 | case GL_PACK_SKIP_PIXELS: |
| 5122 | break; |
| 5123 | |
| 5124 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5125 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5126 | return false; |
| 5127 | } |
| 5128 | |
| 5129 | return true; |
| 5130 | } |
| 5131 | |
| 5132 | bool ValidatePolygonOffset(ValidationContext *context, GLfloat factor, GLfloat units) |
| 5133 | { |
| 5134 | return true; |
| 5135 | } |
| 5136 | |
| 5137 | bool ValidateReleaseShaderCompiler(ValidationContext *context) |
| 5138 | { |
| 5139 | return true; |
| 5140 | } |
| 5141 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5142 | bool ValidateSampleCoverage(ValidationContext *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5143 | { |
| 5144 | return true; |
| 5145 | } |
| 5146 | |
| 5147 | bool ValidateScissor(ValidationContext *context, GLint x, GLint y, GLsizei width, GLsizei height) |
| 5148 | { |
| 5149 | if (width < 0 || height < 0) |
| 5150 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5151 | context->handleError(InvalidValue() << "Scissor width and height must be non-negative."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5152 | return false; |
| 5153 | } |
| 5154 | |
| 5155 | return true; |
| 5156 | } |
| 5157 | |
| 5158 | bool ValidateShaderBinary(ValidationContext *context, |
| 5159 | GLsizei n, |
| 5160 | const GLuint *shaders, |
| 5161 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5162 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5163 | GLsizei length) |
| 5164 | { |
| 5165 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5166 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5167 | shaderBinaryFormats.end()) |
| 5168 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5169 | context->handleError(InvalidEnum() << "Invalid shader binary format."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5170 | return false; |
| 5171 | } |
| 5172 | |
| 5173 | return true; |
| 5174 | } |
| 5175 | |
| 5176 | bool ValidateShaderSource(ValidationContext *context, |
| 5177 | GLuint shader, |
| 5178 | GLsizei count, |
| 5179 | const GLchar *const *string, |
| 5180 | const GLint *length) |
| 5181 | { |
| 5182 | if (count < 0) |
| 5183 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5184 | context->handleError(InvalidValue() << "Count must be non-negative."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5185 | return false; |
| 5186 | } |
| 5187 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5188 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5189 | // shader-related entry points |
| 5190 | if (context->getExtensions().webglCompatibility) |
| 5191 | { |
| 5192 | for (GLsizei i = 0; i < count; i++) |
| 5193 | { |
| 5194 | size_t len = length ? static_cast<size_t>(length[i]) : strlen(string[i]); |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 5195 | |
| 5196 | // Backslash as line-continuation is allowed in WebGL 2.0. |
| 5197 | if (!IsValidESSLString(string[i], len, context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5198 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5199 | context->handleError(InvalidValue() << "Shader source contains invalid characters"); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5200 | return false; |
| 5201 | } |
| 5202 | } |
| 5203 | } |
| 5204 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5205 | Shader *shaderObject = GetValidShader(context, shader); |
| 5206 | if (!shaderObject) |
| 5207 | { |
| 5208 | return false; |
| 5209 | } |
| 5210 | |
| 5211 | return true; |
| 5212 | } |
| 5213 | |
| 5214 | bool ValidateStencilFunc(ValidationContext *context, GLenum func, GLint ref, GLuint mask) |
| 5215 | { |
| 5216 | if (!IsValidStencilFunc(func)) |
| 5217 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5218 | context->handleError(InvalidEnum() << "Invalid stencil function."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5219 | return false; |
| 5220 | } |
| 5221 | |
| 5222 | return true; |
| 5223 | } |
| 5224 | |
| 5225 | bool ValidateStencilFuncSeparate(ValidationContext *context, |
| 5226 | GLenum face, |
| 5227 | GLenum func, |
| 5228 | GLint ref, |
| 5229 | GLuint mask) |
| 5230 | { |
| 5231 | if (!IsValidStencilFace(face)) |
| 5232 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5233 | context->handleError(InvalidEnum() << "Invalid stencil face."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5234 | return false; |
| 5235 | } |
| 5236 | |
| 5237 | if (!IsValidStencilFunc(func)) |
| 5238 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5239 | context->handleError(InvalidEnum() << "Invalid stencil function."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5240 | return false; |
| 5241 | } |
| 5242 | |
| 5243 | return true; |
| 5244 | } |
| 5245 | |
| 5246 | bool ValidateStencilMask(ValidationContext *context, GLuint mask) |
| 5247 | { |
| 5248 | return true; |
| 5249 | } |
| 5250 | |
| 5251 | bool ValidateStencilMaskSeparate(ValidationContext *context, GLenum face, GLuint mask) |
| 5252 | { |
| 5253 | if (!IsValidStencilFace(face)) |
| 5254 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5255 | context->handleError(InvalidEnum() << "Invalid stencil face."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5256 | return false; |
| 5257 | } |
| 5258 | |
| 5259 | return true; |
| 5260 | } |
| 5261 | |
| 5262 | bool ValidateStencilOp(ValidationContext *context, GLenum fail, GLenum zfail, GLenum zpass) |
| 5263 | { |
| 5264 | if (!IsValidStencilOp(fail)) |
| 5265 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5266 | context->handleError(InvalidEnum() << "Invalid stencil fail op."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5267 | return false; |
| 5268 | } |
| 5269 | |
| 5270 | if (!IsValidStencilOp(zfail)) |
| 5271 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5272 | context->handleError(InvalidEnum() << "Invalid stencil z fail op."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5273 | return false; |
| 5274 | } |
| 5275 | |
| 5276 | if (!IsValidStencilOp(zpass)) |
| 5277 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5278 | context->handleError(InvalidEnum() << "Invalid stencil z pass op."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5279 | return false; |
| 5280 | } |
| 5281 | |
| 5282 | return true; |
| 5283 | } |
| 5284 | |
| 5285 | bool ValidateStencilOpSeparate(ValidationContext *context, |
| 5286 | GLenum face, |
| 5287 | GLenum fail, |
| 5288 | GLenum zfail, |
| 5289 | GLenum zpass) |
| 5290 | { |
| 5291 | if (!IsValidStencilFace(face)) |
| 5292 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5293 | context->handleError(InvalidEnum() << "Invalid stencil face."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5294 | return false; |
| 5295 | } |
| 5296 | |
| 5297 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 5298 | } |
| 5299 | |
| 5300 | bool ValidateUniform1f(ValidationContext *context, GLint location, GLfloat x) |
| 5301 | { |
| 5302 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 5303 | } |
| 5304 | |
| 5305 | bool ValidateUniform1fv(ValidationContext *context, GLint location, GLsizei count, const GLfloat *v) |
| 5306 | { |
| 5307 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 5308 | } |
| 5309 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5310 | bool ValidateUniform1i(ValidationContext *context, GLint location, GLint x) |
| 5311 | { |
| 5312 | return ValidateUniform1iv(context, location, 1, &x); |
| 5313 | } |
| 5314 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5315 | bool ValidateUniform2f(ValidationContext *context, GLint location, GLfloat x, GLfloat y) |
| 5316 | { |
| 5317 | return ValidateUniform(context, GL_FLOAT_VEC2, location, 1); |
| 5318 | } |
| 5319 | |
| 5320 | bool ValidateUniform2fv(ValidationContext *context, GLint location, GLsizei count, const GLfloat *v) |
| 5321 | { |
| 5322 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 5323 | } |
| 5324 | |
| 5325 | bool ValidateUniform2i(ValidationContext *context, GLint location, GLint x, GLint y) |
| 5326 | { |
| 5327 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 5328 | } |
| 5329 | |
| 5330 | bool ValidateUniform2iv(ValidationContext *context, GLint location, GLsizei count, const GLint *v) |
| 5331 | { |
| 5332 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 5333 | } |
| 5334 | |
| 5335 | bool ValidateUniform3f(ValidationContext *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
| 5336 | { |
| 5337 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 5338 | } |
| 5339 | |
| 5340 | bool ValidateUniform3fv(ValidationContext *context, GLint location, GLsizei count, const GLfloat *v) |
| 5341 | { |
| 5342 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 5343 | } |
| 5344 | |
| 5345 | bool ValidateUniform3i(ValidationContext *context, GLint location, GLint x, GLint y, GLint z) |
| 5346 | { |
| 5347 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 5348 | } |
| 5349 | |
| 5350 | bool ValidateUniform3iv(ValidationContext *context, GLint location, GLsizei count, const GLint *v) |
| 5351 | { |
| 5352 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 5353 | } |
| 5354 | |
| 5355 | bool ValidateUniform4f(ValidationContext *context, |
| 5356 | GLint location, |
| 5357 | GLfloat x, |
| 5358 | GLfloat y, |
| 5359 | GLfloat z, |
| 5360 | GLfloat w) |
| 5361 | { |
| 5362 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 5363 | } |
| 5364 | |
| 5365 | bool ValidateUniform4fv(ValidationContext *context, GLint location, GLsizei count, const GLfloat *v) |
| 5366 | { |
| 5367 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 5368 | } |
| 5369 | |
| 5370 | bool ValidateUniform4i(ValidationContext *context, |
| 5371 | GLint location, |
| 5372 | GLint x, |
| 5373 | GLint y, |
| 5374 | GLint z, |
| 5375 | GLint w) |
| 5376 | { |
| 5377 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 5378 | } |
| 5379 | |
| 5380 | bool ValidateUniform4iv(ValidationContext *context, GLint location, GLsizei count, const GLint *v) |
| 5381 | { |
| 5382 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 5383 | } |
| 5384 | |
| 5385 | bool ValidateUniformMatrix2fv(ValidationContext *context, |
| 5386 | GLint location, |
| 5387 | GLsizei count, |
| 5388 | GLboolean transpose, |
| 5389 | const GLfloat *value) |
| 5390 | { |
| 5391 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 5392 | } |
| 5393 | |
| 5394 | bool ValidateUniformMatrix3fv(ValidationContext *context, |
| 5395 | GLint location, |
| 5396 | GLsizei count, |
| 5397 | GLboolean transpose, |
| 5398 | const GLfloat *value) |
| 5399 | { |
| 5400 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 5401 | } |
| 5402 | |
| 5403 | bool ValidateUniformMatrix4fv(ValidationContext *context, |
| 5404 | GLint location, |
| 5405 | GLsizei count, |
| 5406 | GLboolean transpose, |
| 5407 | const GLfloat *value) |
| 5408 | { |
| 5409 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 5410 | } |
| 5411 | |
| 5412 | bool ValidateValidateProgram(ValidationContext *context, GLuint program) |
| 5413 | { |
| 5414 | Program *programObject = GetValidProgram(context, program); |
| 5415 | |
| 5416 | if (!programObject) |
| 5417 | { |
| 5418 | return false; |
| 5419 | } |
| 5420 | |
| 5421 | return true; |
| 5422 | } |
| 5423 | |
| 5424 | bool ValidateVertexAttribIndex(ValidationContext *context, GLuint index) |
| 5425 | { |
| 5426 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5427 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5428 | context->handleError(InvalidValue() << "Vertex attrib index out of range."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5429 | return false; |
| 5430 | } |
| 5431 | |
| 5432 | return true; |
| 5433 | } |
| 5434 | |
| 5435 | bool ValidateVertexAttrib1f(ValidationContext *context, GLuint index, GLfloat x) |
| 5436 | { |
| 5437 | return ValidateVertexAttribIndex(context, index); |
| 5438 | } |
| 5439 | |
| 5440 | bool ValidateVertexAttrib1fv(ValidationContext *context, GLuint index, const GLfloat *values) |
| 5441 | { |
| 5442 | return ValidateVertexAttribIndex(context, index); |
| 5443 | } |
| 5444 | |
| 5445 | bool ValidateVertexAttrib2f(ValidationContext *context, GLuint index, GLfloat x, GLfloat y) |
| 5446 | { |
| 5447 | return ValidateVertexAttribIndex(context, index); |
| 5448 | } |
| 5449 | |
| 5450 | bool ValidateVertexAttrib2fv(ValidationContext *context, GLuint index, const GLfloat *values) |
| 5451 | { |
| 5452 | return ValidateVertexAttribIndex(context, index); |
| 5453 | } |
| 5454 | |
| 5455 | bool ValidateVertexAttrib3f(ValidationContext *context, |
| 5456 | GLuint index, |
| 5457 | GLfloat x, |
| 5458 | GLfloat y, |
| 5459 | GLfloat z) |
| 5460 | { |
| 5461 | return ValidateVertexAttribIndex(context, index); |
| 5462 | } |
| 5463 | |
| 5464 | bool ValidateVertexAttrib3fv(ValidationContext *context, GLuint index, const GLfloat *values) |
| 5465 | { |
| 5466 | return ValidateVertexAttribIndex(context, index); |
| 5467 | } |
| 5468 | |
| 5469 | bool ValidateVertexAttrib4f(ValidationContext *context, |
| 5470 | GLuint index, |
| 5471 | GLfloat x, |
| 5472 | GLfloat y, |
| 5473 | GLfloat z, |
| 5474 | GLfloat w) |
| 5475 | { |
| 5476 | return ValidateVertexAttribIndex(context, index); |
| 5477 | } |
| 5478 | |
| 5479 | bool ValidateVertexAttrib4fv(ValidationContext *context, GLuint index, const GLfloat *values) |
| 5480 | { |
| 5481 | return ValidateVertexAttribIndex(context, index); |
| 5482 | } |
| 5483 | |
| 5484 | bool ValidateViewport(ValidationContext *context, GLint x, GLint y, GLsizei width, GLsizei height) |
| 5485 | { |
| 5486 | if (width < 0 || height < 0) |
| 5487 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5488 | context->handleError(InvalidValue() << "Viewport width and height must be non-negative."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5489 | return false; |
| 5490 | } |
| 5491 | |
| 5492 | return true; |
| 5493 | } |
| 5494 | |
| 5495 | bool ValidateDrawArrays(ValidationContext *context, GLenum mode, GLint first, GLsizei count) |
| 5496 | { |
| 5497 | return ValidateDrawArraysCommon(context, mode, first, count, 1); |
| 5498 | } |
| 5499 | |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5500 | bool ValidateDrawElements(ValidationContext *context, |
| 5501 | GLenum mode, |
| 5502 | GLsizei count, |
| 5503 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5504 | const void *indices) |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5505 | { |
| 5506 | return ValidateDrawElementsCommon(context, mode, count, type, indices, 1); |
| 5507 | } |
| 5508 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5509 | bool ValidateGetFramebufferAttachmentParameteriv(ValidationContext *context, |
| 5510 | GLenum target, |
| 5511 | GLenum attachment, |
| 5512 | GLenum pname, |
| 5513 | GLint *params) |
| 5514 | { |
| 5515 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 5516 | nullptr); |
| 5517 | } |
| 5518 | |
| 5519 | bool ValidateGetProgramiv(ValidationContext *context, GLuint program, GLenum pname, GLint *params) |
| 5520 | { |
| 5521 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 5522 | } |
| 5523 | |
| 5524 | bool ValidateCopyTexImage2D(ValidationContext *context, |
| 5525 | GLenum target, |
| 5526 | GLint level, |
| 5527 | GLenum internalformat, |
| 5528 | GLint x, |
| 5529 | GLint y, |
| 5530 | GLsizei width, |
| 5531 | GLsizei height, |
| 5532 | GLint border) |
| 5533 | { |
| 5534 | if (context->getClientMajorVersion() < 3) |
| 5535 | { |
| 5536 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 5537 | 0, x, y, width, height, border); |
| 5538 | } |
| 5539 | |
| 5540 | ASSERT(context->getClientMajorVersion() == 3); |
| 5541 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 5542 | 0, x, y, width, height, border); |
| 5543 | } |
| 5544 | |
| 5545 | bool ValidateCopyTexSubImage2D(Context *context, |
| 5546 | GLenum target, |
| 5547 | GLint level, |
| 5548 | GLint xoffset, |
| 5549 | GLint yoffset, |
| 5550 | GLint x, |
| 5551 | GLint y, |
| 5552 | GLsizei width, |
| 5553 | GLsizei height) |
| 5554 | { |
| 5555 | if (context->getClientMajorVersion() < 3) |
| 5556 | { |
| 5557 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 5558 | yoffset, x, y, width, height, 0); |
| 5559 | } |
| 5560 | |
| 5561 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 5562 | yoffset, 0, x, y, width, height, 0); |
| 5563 | } |
| 5564 | |
| 5565 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 5566 | { |
| 5567 | return ValidateGenOrDelete(context, n); |
| 5568 | } |
| 5569 | |
| 5570 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 5571 | { |
| 5572 | return ValidateGenOrDelete(context, n); |
| 5573 | } |
| 5574 | |
| 5575 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 5576 | { |
| 5577 | return ValidateGenOrDelete(context, n); |
| 5578 | } |
| 5579 | |
| 5580 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 5581 | { |
| 5582 | return ValidateGenOrDelete(context, n); |
| 5583 | } |
| 5584 | |
| 5585 | bool ValidateDisable(Context *context, GLenum cap) |
| 5586 | { |
| 5587 | if (!ValidCap(context, cap, false)) |
| 5588 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5589 | context->handleError(InvalidEnum() << "Invalid cap."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5590 | return false; |
| 5591 | } |
| 5592 | |
| 5593 | return true; |
| 5594 | } |
| 5595 | |
| 5596 | bool ValidateEnable(Context *context, GLenum cap) |
| 5597 | { |
| 5598 | if (!ValidCap(context, cap, false)) |
| 5599 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5600 | context->handleError(InvalidEnum() << "Invalid cap."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5601 | return false; |
| 5602 | } |
| 5603 | |
| 5604 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 5605 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 5606 | { |
| 5607 | const char *errorMessage = "Current renderer doesn't support alpha-to-coverage"; |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5608 | context->handleError(InvalidOperation() << errorMessage); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5609 | |
| 5610 | // We also output an error message to the debugger window if tracing is active, so that |
| 5611 | // developers can see the error message. |
| 5612 | ERR() << errorMessage; |
| 5613 | return false; |
| 5614 | } |
| 5615 | |
| 5616 | return true; |
| 5617 | } |
| 5618 | |
| 5619 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 5620 | GLenum target, |
| 5621 | GLenum attachment, |
| 5622 | GLenum renderbuffertarget, |
| 5623 | GLuint renderbuffer) |
| 5624 | { |
| 5625 | if (!ValidFramebufferTarget(target) || |
| 5626 | (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)) |
| 5627 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5628 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5629 | return false; |
| 5630 | } |
| 5631 | |
| 5632 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 5633 | renderbuffertarget, renderbuffer); |
| 5634 | } |
| 5635 | |
| 5636 | bool ValidateFramebufferTexture2D(Context *context, |
| 5637 | GLenum target, |
| 5638 | GLenum attachment, |
| 5639 | GLenum textarget, |
| 5640 | GLuint texture, |
| 5641 | GLint level) |
| 5642 | { |
| 5643 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 5644 | // extension |
| 5645 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 5646 | level != 0) |
| 5647 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5648 | context->handleError(InvalidValue()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5649 | return false; |
| 5650 | } |
| 5651 | |
| 5652 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 5653 | { |
| 5654 | return false; |
| 5655 | } |
| 5656 | |
| 5657 | if (texture != 0) |
| 5658 | { |
| 5659 | gl::Texture *tex = context->getTexture(texture); |
| 5660 | ASSERT(tex); |
| 5661 | |
| 5662 | const gl::Caps &caps = context->getCaps(); |
| 5663 | |
| 5664 | switch (textarget) |
| 5665 | { |
| 5666 | case GL_TEXTURE_2D: |
| 5667 | { |
| 5668 | if (level > gl::log2(caps.max2DTextureSize)) |
| 5669 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5670 | context->handleError(InvalidValue()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5671 | return false; |
| 5672 | } |
| 5673 | if (tex->getTarget() != GL_TEXTURE_2D) |
| 5674 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5675 | context->handleError(InvalidOperation() |
| 5676 | << "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5677 | return false; |
| 5678 | } |
| 5679 | } |
| 5680 | break; |
| 5681 | |
| 5682 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 5683 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 5684 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 5685 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 5686 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 5687 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 5688 | { |
| 5689 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 5690 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5691 | context->handleError(InvalidValue()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5692 | return false; |
| 5693 | } |
| 5694 | if (tex->getTarget() != GL_TEXTURE_CUBE_MAP) |
| 5695 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5696 | context->handleError(InvalidOperation() |
| 5697 | << "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5698 | return false; |
| 5699 | } |
| 5700 | } |
| 5701 | break; |
| 5702 | |
| 5703 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 5704 | { |
| 5705 | if (context->getClientVersion() < ES_3_1) |
| 5706 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5707 | context->handleError(InvalidOperation() |
| 5708 | << "Texture target requires at least OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5709 | return false; |
| 5710 | } |
| 5711 | |
| 5712 | if (level != 0) |
| 5713 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5714 | context->handleError(InvalidValue() |
| 5715 | << "Level must be 0 for TEXTURE_2D_MULTISAMPLE."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5716 | return false; |
| 5717 | } |
| 5718 | if (tex->getTarget() != GL_TEXTURE_2D_MULTISAMPLE) |
| 5719 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5720 | context->handleError(InvalidOperation() |
| 5721 | << "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5722 | return false; |
| 5723 | } |
| 5724 | } |
| 5725 | break; |
| 5726 | |
| 5727 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5728 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5729 | return false; |
| 5730 | } |
| 5731 | |
| 5732 | const Format &format = tex->getFormat(textarget, level); |
| 5733 | if (format.info->compressed) |
| 5734 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5735 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5736 | return false; |
| 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | return true; |
| 5741 | } |
| 5742 | |
| 5743 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 5744 | { |
| 5745 | return ValidateGenOrDelete(context, n); |
| 5746 | } |
| 5747 | |
| 5748 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 5749 | { |
| 5750 | return ValidateGenOrDelete(context, n); |
| 5751 | } |
| 5752 | |
| 5753 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 5754 | { |
| 5755 | return ValidateGenOrDelete(context, n); |
| 5756 | } |
| 5757 | |
| 5758 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 5759 | { |
| 5760 | return ValidateGenOrDelete(context, n); |
| 5761 | } |
| 5762 | |
| 5763 | bool ValidateGenerateMipmap(Context *context, GLenum target) |
| 5764 | { |
| 5765 | if (!ValidTextureTarget(context, target)) |
| 5766 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5767 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5768 | return false; |
| 5769 | } |
| 5770 | |
| 5771 | Texture *texture = context->getTargetTexture(target); |
| 5772 | |
| 5773 | if (texture == nullptr) |
| 5774 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5775 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5776 | return false; |
| 5777 | } |
| 5778 | |
| 5779 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 5780 | |
| 5781 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 5782 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 5783 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 5784 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5785 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5786 | return false; |
| 5787 | } |
| 5788 | |
| 5789 | GLenum baseTarget = (target == GL_TEXTURE_CUBE_MAP) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : target; |
| 5790 | const auto &format = texture->getFormat(baseTarget, effectiveBaseLevel); |
| 5791 | const TextureCaps &formatCaps = context->getTextureCaps().get(format.info->sizedInternalFormat); |
| 5792 | |
| 5793 | // GenerateMipmap should not generate an INVALID_OPERATION for textures created with |
| 5794 | // unsized formats or that are color renderable and filterable. Since we do not track if |
| 5795 | // the texture was created with sized or unsized format (only sized formats are stored), |
| 5796 | // it is not possible to make sure the the LUMA formats can generate mipmaps (they should |
| 5797 | // be able to) because they aren't color renderable. Simply do a special case for LUMA |
| 5798 | // textures since they're the only texture format that can be created with unsized formats |
| 5799 | // that is not color renderable. New unsized formats are unlikely to be added, since ES2 |
| 5800 | // was the last version to use add them. |
| 5801 | if (format.info->depthBits > 0 || format.info->stencilBits > 0 || !formatCaps.filterable || |
| 5802 | (!formatCaps.renderable && !format.info->isLUMA()) || format.info->compressed) |
| 5803 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5804 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5805 | return false; |
| 5806 | } |
| 5807 | |
Geoff Lang | 65ac5b9 | 2017-05-01 13:16:30 -0400 | [diff] [blame] | 5808 | // ES3 and WebGL grant mipmap generation for sRGB textures but GL_EXT_sRGB does not. |
| 5809 | bool supportsSRGBMipmapGeneration = |
| 5810 | context->getClientVersion() >= ES_3_0 || context->getExtensions().webglCompatibility; |
| 5811 | if (!supportsSRGBMipmapGeneration && format.info->colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5812 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5813 | context->handleError(InvalidOperation() |
| 5814 | << "Mipmap generation of sRGB textures is not allowed."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5815 | return false; |
| 5816 | } |
| 5817 | |
| 5818 | // Non-power of 2 ES2 check |
| 5819 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 5820 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 5821 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 5822 | { |
| 5823 | ASSERT(target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5824 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5825 | return false; |
| 5826 | } |
| 5827 | |
| 5828 | // Cube completeness check |
| 5829 | if (target == GL_TEXTURE_CUBE_MAP && !texture->getTextureState().isCubeComplete()) |
| 5830 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5831 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5832 | return false; |
| 5833 | } |
| 5834 | |
| 5835 | return true; |
| 5836 | } |
| 5837 | |
| 5838 | bool ValidateGetBufferParameteriv(ValidationContext *context, |
| 5839 | GLenum target, |
| 5840 | GLenum pname, |
| 5841 | GLint *params) |
| 5842 | { |
| 5843 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 5844 | } |
| 5845 | |
| 5846 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 5847 | GLenum target, |
| 5848 | GLenum pname, |
| 5849 | GLint *params) |
| 5850 | { |
| 5851 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 5852 | } |
| 5853 | |
| 5854 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 5855 | { |
| 5856 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 5857 | } |
| 5858 | |
| 5859 | bool ValidateGetTexParameterfv(Context *context, GLenum target, GLenum pname, GLfloat *params) |
| 5860 | { |
| 5861 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 5862 | } |
| 5863 | |
| 5864 | bool ValidateGetTexParameteriv(Context *context, GLenum target, GLenum pname, GLint *params) |
| 5865 | { |
| 5866 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 5867 | } |
| 5868 | |
| 5869 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
| 5870 | { |
| 5871 | return ValidateGetUniformBase(context, program, location); |
| 5872 | } |
| 5873 | |
| 5874 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
| 5875 | { |
| 5876 | return ValidateGetUniformBase(context, program, location); |
| 5877 | } |
| 5878 | |
| 5879 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 5880 | { |
| 5881 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 5882 | } |
| 5883 | |
| 5884 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 5885 | { |
| 5886 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 5887 | } |
| 5888 | |
| 5889 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 5890 | { |
| 5891 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 5892 | } |
| 5893 | |
| 5894 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 5895 | { |
| 5896 | if (!ValidCap(context, cap, true)) |
| 5897 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5898 | context->handleError(InvalidEnum() << "Invalid cap."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5899 | return false; |
| 5900 | } |
| 5901 | |
| 5902 | return true; |
| 5903 | } |
| 5904 | |
| 5905 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 5906 | { |
| 5907 | if (context->hasActiveTransformFeedback(program)) |
| 5908 | { |
| 5909 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5910 | context->handleError(InvalidOperation() << "Cannot link program while program is " |
| 5911 | "associated with an active transform " |
| 5912 | "feedback object."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5913 | return false; |
| 5914 | } |
| 5915 | |
| 5916 | Program *programObject = GetValidProgram(context, program); |
| 5917 | if (!programObject) |
| 5918 | { |
| 5919 | return false; |
| 5920 | } |
| 5921 | |
| 5922 | return true; |
| 5923 | } |
| 5924 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5925 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5926 | GLint x, |
| 5927 | GLint y, |
| 5928 | GLsizei width, |
| 5929 | GLsizei height, |
| 5930 | GLenum format, |
| 5931 | GLenum type, |
| 5932 | void *pixels) |
| 5933 | { |
| 5934 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 5935 | nullptr, pixels); |
| 5936 | } |
| 5937 | |
| 5938 | bool ValidateTexParameterf(Context *context, GLenum target, GLenum pname, GLfloat param) |
| 5939 | { |
| 5940 | return ValidateTexParameterBase(context, target, pname, -1, ¶m); |
| 5941 | } |
| 5942 | |
| 5943 | bool ValidateTexParameterfv(Context *context, GLenum target, GLenum pname, const GLfloat *params) |
| 5944 | { |
| 5945 | return ValidateTexParameterBase(context, target, pname, -1, params); |
| 5946 | } |
| 5947 | |
| 5948 | bool ValidateTexParameteri(Context *context, GLenum target, GLenum pname, GLint param) |
| 5949 | { |
| 5950 | return ValidateTexParameterBase(context, target, pname, -1, ¶m); |
| 5951 | } |
| 5952 | |
| 5953 | bool ValidateTexParameteriv(Context *context, GLenum target, GLenum pname, const GLint *params) |
| 5954 | { |
| 5955 | return ValidateTexParameterBase(context, target, pname, -1, params); |
| 5956 | } |
| 5957 | |
| 5958 | bool ValidateUseProgram(Context *context, GLuint program) |
| 5959 | { |
| 5960 | if (program != 0) |
| 5961 | { |
| 5962 | Program *programObject = context->getProgram(program); |
| 5963 | if (!programObject) |
| 5964 | { |
| 5965 | // ES 3.1.0 section 7.3 page 72 |
| 5966 | if (context->getShader(program)) |
| 5967 | { |
| 5968 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5969 | InvalidOperation() |
| 5970 | << "Attempted to use a single shader instead of a shader program."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5971 | return false; |
| 5972 | } |
| 5973 | else |
| 5974 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5975 | context->handleError(InvalidValue() << "Program invalid."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5976 | return false; |
| 5977 | } |
| 5978 | } |
| 5979 | if (!programObject->isLinked()) |
| 5980 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5981 | context->handleError(InvalidOperation() << "Program not linked."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5982 | return false; |
| 5983 | } |
| 5984 | } |
| 5985 | if (context->getGLState().isTransformFeedbackActiveUnpaused()) |
| 5986 | { |
| 5987 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5988 | context |
| 5989 | ->handleError(InvalidOperation() |
| 5990 | << "Cannot change active program while transform feedback is unpaused."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5991 | return false; |
| 5992 | } |
| 5993 | |
| 5994 | return true; |
| 5995 | } |
| 5996 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 5997 | } // namespace gl |