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