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