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 | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 18 | #include "libANGLE/Fence.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 19 | #include "libANGLE/Framebuffer.h" |
| 20 | #include "libANGLE/FramebufferAttachment.h" |
| 21 | #include "libANGLE/Renderbuffer.h" |
| 22 | #include "libANGLE/Shader.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 23 | #include "libANGLE/Texture.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 24 | #include "libANGLE/Uniform.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 25 | #include "libANGLE/VertexArray.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 26 | #include "libANGLE/formatutils.h" |
| 27 | #include "libANGLE/validationES.h" |
| 28 | #include "libANGLE/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 29 | |
| 30 | namespace gl |
| 31 | { |
| 32 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 33 | namespace |
| 34 | { |
| 35 | |
| 36 | bool IsPartialBlit(gl::Context *context, |
| 37 | const FramebufferAttachment *readBuffer, |
| 38 | const FramebufferAttachment *writeBuffer, |
| 39 | GLint srcX0, |
| 40 | GLint srcY0, |
| 41 | GLint srcX1, |
| 42 | GLint srcY1, |
| 43 | GLint dstX0, |
| 44 | GLint dstY0, |
| 45 | GLint dstX1, |
| 46 | GLint dstY1) |
| 47 | { |
| 48 | const Extents &writeSize = writeBuffer->getSize(); |
| 49 | const Extents &readSize = readBuffer->getSize(); |
| 50 | |
| 51 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width || |
| 52 | dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height) |
| 53 | { |
| 54 | return true; |
| 55 | } |
| 56 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 57 | if (context->getGLState().isScissorTestEnabled()) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 58 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 59 | const Rectangle &scissor = context->getGLState().getScissor(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 60 | return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width || |
| 61 | scissor.height < writeSize.height; |
| 62 | } |
| 63 | |
| 64 | return false; |
| 65 | } |
| 66 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 67 | template <typename T> |
| 68 | bool ValidatePathInstances(gl::Context *context, |
| 69 | GLsizei numPaths, |
| 70 | const void *paths, |
| 71 | GLuint pathBase) |
| 72 | { |
| 73 | const auto *array = static_cast<const T *>(paths); |
| 74 | |
| 75 | for (GLsizei i = 0; i < numPaths; ++i) |
| 76 | { |
| 77 | const GLuint pathName = array[i] + pathBase; |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 78 | if (context->isPathGenerated(pathName) && !context->isPath(pathName)) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 79 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 80 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 81 | return false; |
| 82 | } |
| 83 | } |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | bool ValidateInstancedPathParameters(gl::Context *context, |
| 88 | GLsizei numPaths, |
| 89 | GLenum pathNameType, |
| 90 | const void *paths, |
| 91 | GLuint pathBase, |
| 92 | GLenum transformType, |
| 93 | const GLfloat *transformValues) |
| 94 | { |
| 95 | if (!context->getExtensions().pathRendering) |
| 96 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 97 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 98 | return false; |
| 99 | } |
| 100 | |
| 101 | if (paths == nullptr) |
| 102 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 103 | context->handleError(InvalidValue() << "No path name array."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 104 | return false; |
| 105 | } |
| 106 | |
| 107 | if (numPaths < 0) |
| 108 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 109 | context->handleError(InvalidValue() << "Invalid (negative) numPaths."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 110 | return false; |
| 111 | } |
| 112 | |
| 113 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths)) |
| 114 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 115 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 116 | return false; |
| 117 | } |
| 118 | |
| 119 | std::uint32_t pathNameTypeSize = 0; |
| 120 | std::uint32_t componentCount = 0; |
| 121 | |
| 122 | switch (pathNameType) |
| 123 | { |
| 124 | case GL_UNSIGNED_BYTE: |
| 125 | pathNameTypeSize = sizeof(GLubyte); |
| 126 | if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase)) |
| 127 | return false; |
| 128 | break; |
| 129 | |
| 130 | case GL_BYTE: |
| 131 | pathNameTypeSize = sizeof(GLbyte); |
| 132 | if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase)) |
| 133 | return false; |
| 134 | break; |
| 135 | |
| 136 | case GL_UNSIGNED_SHORT: |
| 137 | pathNameTypeSize = sizeof(GLushort); |
| 138 | if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase)) |
| 139 | return false; |
| 140 | break; |
| 141 | |
| 142 | case GL_SHORT: |
| 143 | pathNameTypeSize = sizeof(GLshort); |
| 144 | if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase)) |
| 145 | return false; |
| 146 | break; |
| 147 | |
| 148 | case GL_UNSIGNED_INT: |
| 149 | pathNameTypeSize = sizeof(GLuint); |
| 150 | if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase)) |
| 151 | return false; |
| 152 | break; |
| 153 | |
| 154 | case GL_INT: |
| 155 | pathNameTypeSize = sizeof(GLint); |
| 156 | if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase)) |
| 157 | return false; |
| 158 | break; |
| 159 | |
| 160 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 161 | context->handleError(InvalidEnum() << "Invalid path name type."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 162 | return false; |
| 163 | } |
| 164 | |
| 165 | switch (transformType) |
| 166 | { |
| 167 | case GL_NONE: |
| 168 | componentCount = 0; |
| 169 | break; |
| 170 | case GL_TRANSLATE_X_CHROMIUM: |
| 171 | case GL_TRANSLATE_Y_CHROMIUM: |
| 172 | componentCount = 1; |
| 173 | break; |
| 174 | case GL_TRANSLATE_2D_CHROMIUM: |
| 175 | componentCount = 2; |
| 176 | break; |
| 177 | case GL_TRANSLATE_3D_CHROMIUM: |
| 178 | componentCount = 3; |
| 179 | break; |
| 180 | case GL_AFFINE_2D_CHROMIUM: |
| 181 | case GL_TRANSPOSE_AFFINE_2D_CHROMIUM: |
| 182 | componentCount = 6; |
| 183 | break; |
| 184 | case GL_AFFINE_3D_CHROMIUM: |
| 185 | case GL_TRANSPOSE_AFFINE_3D_CHROMIUM: |
| 186 | componentCount = 12; |
| 187 | break; |
| 188 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 189 | context->handleError(InvalidEnum() << "Invalid transformation."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 190 | return false; |
| 191 | } |
| 192 | if (componentCount != 0 && transformValues == nullptr) |
| 193 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 194 | context->handleError(InvalidValue() << "No transform array given."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 195 | return false; |
| 196 | } |
| 197 | |
| 198 | angle::CheckedNumeric<std::uint32_t> checkedSize(0); |
| 199 | checkedSize += (numPaths * pathNameTypeSize); |
| 200 | checkedSize += (numPaths * sizeof(GLfloat) * componentCount); |
| 201 | if (!checkedSize.IsValid()) |
| 202 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 203 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | |
| 207 | return true; |
| 208 | } |
| 209 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 210 | bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 211 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 212 | // Table 1.1 from the CHROMIUM_copy_texture spec |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 213 | switch (GetUnsizedFormat(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 214 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 215 | case GL_RED: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 216 | case GL_ALPHA: |
| 217 | case GL_LUMINANCE: |
| 218 | case GL_LUMINANCE_ALPHA: |
| 219 | case GL_RGB: |
| 220 | case GL_RGBA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 221 | case GL_RGB8: |
| 222 | case GL_RGBA8: |
| 223 | case GL_BGRA_EXT: |
| 224 | case GL_BGRA8_EXT: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 225 | return true; |
| 226 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 227 | default: |
| 228 | return false; |
| 229 | } |
| 230 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 231 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 232 | bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat) |
| 233 | { |
| 234 | return IsValidCopyTextureSourceInternalFormatEnum(internalFormat); |
| 235 | } |
| 236 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 237 | bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat) |
| 238 | { |
| 239 | // Table 1.0 from the CHROMIUM_copy_texture spec |
| 240 | switch (internalFormat) |
| 241 | { |
| 242 | case GL_RGB: |
| 243 | case GL_RGBA: |
| 244 | case GL_RGB8: |
| 245 | case GL_RGBA8: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 246 | case GL_BGRA_EXT: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 247 | case GL_BGRA8_EXT: |
| 248 | case GL_SRGB_EXT: |
| 249 | case GL_SRGB_ALPHA_EXT: |
| 250 | case GL_R8: |
| 251 | case GL_R8UI: |
| 252 | case GL_RG8: |
| 253 | case GL_RG8UI: |
| 254 | case GL_SRGB8: |
| 255 | case GL_RGB565: |
| 256 | case GL_RGB8UI: |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 257 | case GL_RGB10_A2: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 258 | case GL_SRGB8_ALPHA8: |
| 259 | case GL_RGB5_A1: |
| 260 | case GL_RGBA4: |
| 261 | case GL_RGBA8UI: |
| 262 | case GL_RGB9_E5: |
| 263 | case GL_R16F: |
| 264 | case GL_R32F: |
| 265 | case GL_RG16F: |
| 266 | case GL_RG32F: |
| 267 | case GL_RGB16F: |
| 268 | case GL_RGB32F: |
| 269 | case GL_RGBA16F: |
| 270 | case GL_RGBA32F: |
| 271 | case GL_R11F_G11F_B10F: |
Brandon Jones | 340b7b8 | 2017-06-26 13:02:31 -0700 | [diff] [blame] | 272 | case GL_LUMINANCE: |
| 273 | case GL_LUMINANCE_ALPHA: |
| 274 | case GL_ALPHA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 275 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 276 | |
| 277 | default: |
| 278 | return false; |
| 279 | } |
| 280 | } |
| 281 | |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 282 | bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat) |
| 283 | { |
| 284 | return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat); |
| 285 | } |
| 286 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 287 | bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type) |
| 288 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 289 | if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 290 | { |
Brandon Jones | 4e6f2ae | 2018-09-19 11:09:51 -0700 | [diff] [blame] | 291 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 292 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 295 | if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat)) |
| 296 | { |
Brandon Jones | 4e6f2ae | 2018-09-19 11:09:51 -0700 | [diff] [blame] | 297 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 298 | return false; |
| 299 | } |
| 300 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 301 | const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type); |
| 302 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 303 | { |
Brandon Jones | 4e6f2ae | 2018-09-19 11:09:51 -0700 | [diff] [blame] | 304 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 305 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | return true; |
| 309 | } |
| 310 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 311 | bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 312 | { |
| 313 | switch (target) |
| 314 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 315 | case TextureTarget::_2D: |
| 316 | case TextureTarget::CubeMapNegativeX: |
| 317 | case TextureTarget::CubeMapNegativeY: |
| 318 | case TextureTarget::CubeMapNegativeZ: |
| 319 | case TextureTarget::CubeMapPositiveX: |
| 320 | case TextureTarget::CubeMapPositiveY: |
| 321 | case TextureTarget::CubeMapPositiveZ: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 322 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 323 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 324 | case TextureTarget::Rectangle: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 325 | return context->getExtensions().textureRectangle; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 326 | |
| 327 | default: |
| 328 | return false; |
| 329 | } |
| 330 | } |
| 331 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 332 | bool IsValidCopyTextureDestinationTarget(Context *context, |
| 333 | TextureType textureType, |
| 334 | TextureTarget target) |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 335 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 336 | return TextureTargetToType(target) == textureType; |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 337 | } |
| 338 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 339 | bool IsValidCopyTextureSourceTarget(Context *context, TextureType type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 340 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 341 | switch (type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 342 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 343 | case TextureType::_2D: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 344 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 345 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 346 | return context->getExtensions().textureRectangle; |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 347 | |
| 348 | // TODO(geofflang): accept GL_TEXTURE_EXTERNAL_OES if the texture_external extension is |
| 349 | // supported |
| 350 | |
| 351 | default: |
| 352 | return false; |
| 353 | } |
| 354 | } |
| 355 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 356 | bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 357 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 358 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 359 | { |
| 360 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 363 | if (level > 0 && context->getClientVersion() < ES_3_0) |
| 364 | { |
| 365 | return false; |
| 366 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 367 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 368 | return true; |
| 369 | } |
| 370 | |
| 371 | bool IsValidCopyTextureDestinationLevel(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 372 | TextureType type, |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 373 | GLint level, |
| 374 | GLsizei width, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 375 | GLsizei height, |
| 376 | bool isSubImage) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 377 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 378 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 379 | { |
| 380 | return false; |
| 381 | } |
| 382 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 383 | if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage)) |
| 384 | { |
| 385 | return false; |
| 386 | } |
| 387 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 388 | const Caps &caps = context->getCaps(); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 389 | switch (type) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 390 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 391 | case TextureType::_2D: |
| 392 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 393 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
| 394 | case TextureType::Rectangle: |
| 395 | ASSERT(level == 0); |
| 396 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 397 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 398 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 399 | case TextureType::CubeMap: |
| 400 | return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) && |
| 401 | static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level); |
| 402 | default: |
| 403 | return true; |
| 404 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 407 | bool IsValidStencilFunc(GLenum func) |
| 408 | { |
| 409 | switch (func) |
| 410 | { |
| 411 | case GL_NEVER: |
| 412 | case GL_ALWAYS: |
| 413 | case GL_LESS: |
| 414 | case GL_LEQUAL: |
| 415 | case GL_EQUAL: |
| 416 | case GL_GEQUAL: |
| 417 | case GL_GREATER: |
| 418 | case GL_NOTEQUAL: |
| 419 | return true; |
| 420 | |
| 421 | default: |
| 422 | return false; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | bool IsValidStencilFace(GLenum face) |
| 427 | { |
| 428 | switch (face) |
| 429 | { |
| 430 | case GL_FRONT: |
| 431 | case GL_BACK: |
| 432 | case GL_FRONT_AND_BACK: |
| 433 | return true; |
| 434 | |
| 435 | default: |
| 436 | return false; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | bool IsValidStencilOp(GLenum op) |
| 441 | { |
| 442 | switch (op) |
| 443 | { |
| 444 | case GL_ZERO: |
| 445 | case GL_KEEP: |
| 446 | case GL_REPLACE: |
| 447 | case GL_INCR: |
| 448 | case GL_DECR: |
| 449 | case GL_INVERT: |
| 450 | case GL_INCR_WRAP: |
| 451 | case GL_DECR_WRAP: |
| 452 | return true; |
| 453 | |
| 454 | default: |
| 455 | return false; |
| 456 | } |
| 457 | } |
| 458 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 459 | bool ValidateES2CopyTexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 460 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 461 | GLint level, |
| 462 | GLenum internalformat, |
| 463 | bool isSubImage, |
| 464 | GLint xoffset, |
| 465 | GLint yoffset, |
| 466 | GLint x, |
| 467 | GLint y, |
| 468 | GLsizei width, |
| 469 | GLsizei height, |
| 470 | GLint border) |
| 471 | { |
| 472 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 473 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 474 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 475 | return false; |
| 476 | } |
| 477 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 478 | TextureType texType = TextureTargetToType(target); |
| 479 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 480 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 481 | context->handleError(InvalidValue() << "Invalid texture dimensions."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 482 | return false; |
| 483 | } |
| 484 | |
| 485 | Format textureFormat = Format::Invalid(); |
| 486 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 487 | xoffset, yoffset, 0, x, y, width, height, border, |
| 488 | &textureFormat)) |
| 489 | { |
| 490 | return false; |
| 491 | } |
| 492 | |
| 493 | const gl::Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
| 494 | GLenum colorbufferFormat = |
| 495 | framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat; |
| 496 | const auto &formatInfo = *textureFormat.info; |
| 497 | |
| 498 | // [OpenGL ES 2.0.24] table 3.9 |
| 499 | if (isSubImage) |
| 500 | { |
| 501 | switch (formatInfo.format) |
| 502 | { |
| 503 | case GL_ALPHA: |
| 504 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 505 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 506 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 507 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 508 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 509 | return false; |
| 510 | } |
| 511 | break; |
| 512 | case GL_LUMINANCE: |
| 513 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 514 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 515 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 516 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT && |
| 517 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 518 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 519 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 520 | return false; |
| 521 | } |
| 522 | break; |
| 523 | case GL_RED_EXT: |
| 524 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 525 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 526 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 527 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F && |
| 528 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 529 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 530 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 531 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 532 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 533 | return false; |
| 534 | } |
| 535 | break; |
| 536 | case GL_RG_EXT: |
| 537 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 538 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 539 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 540 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 541 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 542 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 543 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 544 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | break; |
| 548 | case GL_RGB: |
| 549 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 550 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 551 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 552 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 553 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 554 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 555 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 556 | return false; |
| 557 | } |
| 558 | break; |
| 559 | case GL_LUMINANCE_ALPHA: |
| 560 | case GL_RGBA: |
| 561 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 562 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F && |
| 563 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 564 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 565 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 566 | return false; |
| 567 | } |
| 568 | break; |
| 569 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 570 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 571 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 572 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 573 | case GL_ETC1_RGB8_OES: |
| 574 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 575 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 576 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 577 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 578 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame^] | 579 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 580 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 581 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 582 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
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 | case GL_DEPTH_COMPONENT: |
| 586 | case GL_DEPTH_STENCIL_OES: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 587 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 588 | return false; |
| 589 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 590 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 591 | return false; |
| 592 | } |
| 593 | |
| 594 | if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat) |
| 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 | } |
| 600 | else |
| 601 | { |
| 602 | switch (internalformat) |
| 603 | { |
| 604 | case GL_ALPHA: |
| 605 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
| 606 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 607 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 608 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 609 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 610 | return false; |
| 611 | } |
| 612 | break; |
| 613 | case GL_LUMINANCE: |
| 614 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 615 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 616 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 617 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 618 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 619 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 620 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 621 | return false; |
| 622 | } |
| 623 | break; |
| 624 | case GL_RED_EXT: |
| 625 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 626 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 627 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 628 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 629 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 630 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 631 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 632 | return false; |
| 633 | } |
| 634 | break; |
| 635 | case GL_RG_EXT: |
| 636 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 637 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 638 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 639 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 640 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 641 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 642 | return false; |
| 643 | } |
| 644 | break; |
| 645 | case GL_RGB: |
| 646 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 647 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 648 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 649 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 650 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 651 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 652 | return false; |
| 653 | } |
| 654 | break; |
| 655 | case GL_LUMINANCE_ALPHA: |
| 656 | case GL_RGBA: |
| 657 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 658 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 659 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 660 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 661 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 662 | return false; |
| 663 | } |
| 664 | break; |
| 665 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 666 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 667 | if (context->getExtensions().textureCompressionDXT1) |
| 668 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 669 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 670 | return false; |
| 671 | } |
| 672 | else |
| 673 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 674 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 675 | return false; |
| 676 | } |
| 677 | break; |
| 678 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 679 | if (context->getExtensions().textureCompressionDXT3) |
| 680 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 681 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 682 | return false; |
| 683 | } |
| 684 | else |
| 685 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 686 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 687 | return false; |
| 688 | } |
| 689 | break; |
| 690 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 691 | if (context->getExtensions().textureCompressionDXT5) |
| 692 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 693 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | else |
| 697 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 698 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 699 | return false; |
| 700 | } |
| 701 | break; |
| 702 | case GL_ETC1_RGB8_OES: |
| 703 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 704 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 705 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 706 | return false; |
| 707 | } |
| 708 | else |
| 709 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 710 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 711 | return false; |
| 712 | } |
| 713 | break; |
| 714 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 715 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 716 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 717 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 718 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 719 | if (context->getExtensions().lossyETCDecode) |
| 720 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 721 | context->handleError(InvalidOperation() |
| 722 | << "ETC lossy decode formats can't be copied to."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 723 | return false; |
| 724 | } |
| 725 | else |
| 726 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 727 | context->handleError(InvalidEnum() |
| 728 | << "ANGLE_lossy_etc_decode extension is not supported."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 729 | return false; |
| 730 | } |
| 731 | break; |
| 732 | case GL_DEPTH_COMPONENT: |
| 733 | case GL_DEPTH_COMPONENT16: |
| 734 | case GL_DEPTH_COMPONENT32_OES: |
| 735 | case GL_DEPTH_STENCIL_OES: |
| 736 | case GL_DEPTH24_STENCIL8_OES: |
| 737 | if (context->getExtensions().depthTextures) |
| 738 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 739 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 740 | return false; |
| 741 | } |
| 742 | else |
| 743 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 744 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 745 | return false; |
| 746 | } |
| 747 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 748 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 749 | return false; |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 754 | return (width > 0 && height > 0); |
| 755 | } |
| 756 | |
| 757 | bool ValidCap(const Context *context, GLenum cap, bool queryOnly) |
| 758 | { |
| 759 | switch (cap) |
| 760 | { |
| 761 | // EXT_multisample_compatibility |
| 762 | case GL_MULTISAMPLE_EXT: |
| 763 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 764 | return context->getExtensions().multisampleCompatibility; |
| 765 | |
| 766 | case GL_CULL_FACE: |
| 767 | case GL_POLYGON_OFFSET_FILL: |
| 768 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 769 | case GL_SAMPLE_COVERAGE: |
| 770 | case GL_SCISSOR_TEST: |
| 771 | case GL_STENCIL_TEST: |
| 772 | case GL_DEPTH_TEST: |
| 773 | case GL_BLEND: |
| 774 | case GL_DITHER: |
| 775 | return true; |
| 776 | |
| 777 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 778 | case GL_RASTERIZER_DISCARD: |
| 779 | return (context->getClientMajorVersion() >= 3); |
| 780 | |
| 781 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 782 | case GL_DEBUG_OUTPUT: |
| 783 | return context->getExtensions().debug; |
| 784 | |
| 785 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 786 | return queryOnly && context->getExtensions().bindGeneratesResource; |
| 787 | |
| 788 | case GL_CLIENT_ARRAYS_ANGLE: |
| 789 | return queryOnly && context->getExtensions().clientArrays; |
| 790 | |
| 791 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 792 | return context->getExtensions().sRGBWriteControl; |
| 793 | |
| 794 | case GL_SAMPLE_MASK: |
| 795 | return context->getClientVersion() >= Version(3, 1); |
| 796 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 797 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 798 | return queryOnly && context->getExtensions().robustResourceInitialization; |
| 799 | |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 800 | // GLES1 emulation: GLES1-specific caps |
| 801 | case GL_ALPHA_TEST: |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 802 | case GL_VERTEX_ARRAY: |
| 803 | case GL_NORMAL_ARRAY: |
| 804 | case GL_COLOR_ARRAY: |
| 805 | case GL_TEXTURE_COORD_ARRAY: |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 806 | case GL_TEXTURE_2D: |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 807 | case GL_LIGHTING: |
| 808 | case GL_LIGHT0: |
| 809 | case GL_LIGHT1: |
| 810 | case GL_LIGHT2: |
| 811 | case GL_LIGHT3: |
| 812 | case GL_LIGHT4: |
| 813 | case GL_LIGHT5: |
| 814 | case GL_LIGHT6: |
| 815 | case GL_LIGHT7: |
| 816 | case GL_NORMALIZE: |
| 817 | case GL_RESCALE_NORMAL: |
| 818 | case GL_COLOR_MATERIAL: |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 819 | case GL_CLIP_PLANE0: |
| 820 | case GL_CLIP_PLANE1: |
| 821 | case GL_CLIP_PLANE2: |
| 822 | case GL_CLIP_PLANE3: |
| 823 | case GL_CLIP_PLANE4: |
| 824 | case GL_CLIP_PLANE5: |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 825 | case GL_FOG: |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 826 | case GL_POINT_SMOOTH: |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 827 | case GL_LINE_SMOOTH: |
| 828 | case GL_COLOR_LOGIC_OP: |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 829 | return context->getClientVersion() < Version(2, 0); |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 830 | case GL_POINT_SIZE_ARRAY_OES: |
| 831 | return context->getClientVersion() < Version(2, 0) && |
| 832 | context->getExtensions().pointSizeArray; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 833 | case GL_TEXTURE_CUBE_MAP: |
| 834 | return context->getClientVersion() < Version(2, 0) && |
| 835 | context->getExtensions().textureCubeMap; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 836 | case GL_POINT_SPRITE_OES: |
| 837 | return context->getClientVersion() < Version(2, 0) && |
| 838 | context->getExtensions().pointSprite; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 839 | default: |
| 840 | return false; |
| 841 | } |
| 842 | } |
| 843 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 844 | // Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section |
| 845 | // 3.1. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 846 | bool IsValidESSLCharacter(unsigned char c) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 847 | { |
| 848 | // Printing characters are valid except " $ ` @ \ ' DEL. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 849 | if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' && |
| 850 | c != '\'') |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 851 | { |
| 852 | return true; |
| 853 | } |
| 854 | |
| 855 | // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid. |
| 856 | if (c >= 9 && c <= 13) |
| 857 | { |
| 858 | return true; |
| 859 | } |
| 860 | |
| 861 | return false; |
| 862 | } |
| 863 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 864 | bool IsValidESSLString(const char *str, size_t len) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 865 | { |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 866 | for (size_t i = 0; i < len; i++) |
| 867 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 868 | if (!IsValidESSLCharacter(str[i])) |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 869 | { |
| 870 | return false; |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | return true; |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 875 | } |
| 876 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 877 | bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed) |
| 878 | { |
| 879 | enum class ParseState |
| 880 | { |
| 881 | // Have not seen an ASCII non-whitespace character yet on |
| 882 | // this line. Possible that we might see a preprocessor |
| 883 | // directive. |
| 884 | BEGINING_OF_LINE, |
| 885 | |
| 886 | // Have seen at least one ASCII non-whitespace character |
| 887 | // on this line. |
| 888 | MIDDLE_OF_LINE, |
| 889 | |
| 890 | // Handling a preprocessor directive. Passes through all |
| 891 | // characters up to the end of the line. Disables comment |
| 892 | // processing. |
| 893 | IN_PREPROCESSOR_DIRECTIVE, |
| 894 | |
| 895 | // Handling a single-line comment. The comment text is |
| 896 | // replaced with a single space. |
| 897 | IN_SINGLE_LINE_COMMENT, |
| 898 | |
| 899 | // Handling a multi-line comment. Newlines are passed |
| 900 | // through to preserve line numbers. |
| 901 | IN_MULTI_LINE_COMMENT |
| 902 | }; |
| 903 | |
| 904 | ParseState state = ParseState::BEGINING_OF_LINE; |
| 905 | size_t pos = 0; |
| 906 | |
| 907 | while (pos < len) |
| 908 | { |
| 909 | char c = str[pos]; |
| 910 | char next = pos + 1 < len ? str[pos + 1] : 0; |
| 911 | |
| 912 | // Check for newlines |
| 913 | if (c == '\n' || c == '\r') |
| 914 | { |
| 915 | if (state != ParseState::IN_MULTI_LINE_COMMENT) |
| 916 | { |
| 917 | state = ParseState::BEGINING_OF_LINE; |
| 918 | } |
| 919 | |
| 920 | pos++; |
| 921 | continue; |
| 922 | } |
| 923 | |
| 924 | switch (state) |
| 925 | { |
| 926 | case ParseState::BEGINING_OF_LINE: |
| 927 | if (c == ' ') |
| 928 | { |
| 929 | // Maintain the BEGINING_OF_LINE state until a non-space is seen |
| 930 | pos++; |
| 931 | } |
| 932 | else if (c == '#') |
| 933 | { |
| 934 | state = ParseState::IN_PREPROCESSOR_DIRECTIVE; |
| 935 | pos++; |
| 936 | } |
| 937 | else |
| 938 | { |
| 939 | // Don't advance, re-process this character with the MIDDLE_OF_LINE state |
| 940 | state = ParseState::MIDDLE_OF_LINE; |
| 941 | } |
| 942 | break; |
| 943 | |
| 944 | case ParseState::MIDDLE_OF_LINE: |
| 945 | if (c == '/' && next == '/') |
| 946 | { |
| 947 | state = ParseState::IN_SINGLE_LINE_COMMENT; |
| 948 | pos++; |
| 949 | } |
| 950 | else if (c == '/' && next == '*') |
| 951 | { |
| 952 | state = ParseState::IN_MULTI_LINE_COMMENT; |
| 953 | pos++; |
| 954 | } |
| 955 | else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r')) |
| 956 | { |
| 957 | // Skip line continuation characters |
| 958 | } |
| 959 | else if (!IsValidESSLCharacter(c)) |
| 960 | { |
| 961 | return false; |
| 962 | } |
| 963 | pos++; |
| 964 | break; |
| 965 | |
| 966 | case ParseState::IN_PREPROCESSOR_DIRECTIVE: |
Bryan Bernhart (Intel Americas Inc) | 335d8bf | 2017-10-23 15:41:43 -0700 | [diff] [blame] | 967 | // Line-continuation characters may not be permitted. |
| 968 | // Otherwise, just pass it through. Do not parse comments in this state. |
| 969 | if (!lineContinuationAllowed && c == '\\') |
| 970 | { |
| 971 | return false; |
| 972 | } |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 973 | pos++; |
| 974 | break; |
| 975 | |
| 976 | case ParseState::IN_SINGLE_LINE_COMMENT: |
| 977 | // Line-continuation characters are processed before comment processing. |
| 978 | // Advance string if a new line character is immediately behind |
| 979 | // line-continuation character. |
| 980 | if (c == '\\' && (next == '\n' || next == '\r')) |
| 981 | { |
| 982 | pos++; |
| 983 | } |
| 984 | pos++; |
| 985 | break; |
| 986 | |
| 987 | case ParseState::IN_MULTI_LINE_COMMENT: |
| 988 | if (c == '*' && next == '/') |
| 989 | { |
| 990 | state = ParseState::MIDDLE_OF_LINE; |
| 991 | pos++; |
| 992 | } |
| 993 | pos++; |
| 994 | break; |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | return true; |
| 999 | } |
| 1000 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1001 | bool ValidateWebGLNamePrefix(Context *context, const GLchar *name) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1002 | { |
| 1003 | ASSERT(context->isWebGL()); |
| 1004 | |
| 1005 | // WebGL 1.0 [Section 6.16] GLSL Constructs |
| 1006 | // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL. |
| 1007 | if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0) |
| 1008 | { |
| 1009 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), WebglBindAttribLocationReservedPrefix); |
| 1010 | return false; |
| 1011 | } |
| 1012 | |
| 1013 | return true; |
| 1014 | } |
| 1015 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1016 | bool ValidateWebGLNameLength(Context *context, size_t length) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1017 | { |
| 1018 | ASSERT(context->isWebGL()); |
| 1019 | |
| 1020 | if (context->isWebGL1() && length > 256) |
| 1021 | { |
| 1022 | // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths |
| 1023 | // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute |
| 1024 | // locations. |
| 1025 | ANGLE_VALIDATION_ERR(context, InvalidValue(), WebglNameLengthLimitExceeded); |
| 1026 | |
| 1027 | return false; |
| 1028 | } |
| 1029 | else if (length > 1024) |
| 1030 | { |
| 1031 | // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of |
| 1032 | // uniform and attribute locations. |
| 1033 | ANGLE_VALIDATION_ERR(context, InvalidValue(), Webgl2NameLengthLimitExceeded); |
| 1034 | return false; |
| 1035 | } |
| 1036 | |
| 1037 | return true; |
| 1038 | } |
| 1039 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1040 | bool ValidateMatrixMode(Context *context, GLenum matrixMode) |
| 1041 | { |
| 1042 | if (!context->getExtensions().pathRendering) |
| 1043 | { |
| 1044 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
| 1045 | return false; |
| 1046 | } |
| 1047 | |
| 1048 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 1049 | { |
| 1050 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMatrixMode); |
| 1051 | return false; |
| 1052 | } |
| 1053 | return true; |
| 1054 | } |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 1055 | |
| 1056 | bool ValidBlendFunc(const Context *context, GLenum val) |
| 1057 | { |
| 1058 | const gl::Extensions &ext = context->getExtensions(); |
| 1059 | |
| 1060 | // these are always valid for src and dst. |
| 1061 | switch (val) |
| 1062 | { |
| 1063 | case GL_ZERO: |
| 1064 | case GL_ONE: |
| 1065 | case GL_SRC_COLOR: |
| 1066 | case GL_ONE_MINUS_SRC_COLOR: |
| 1067 | case GL_DST_COLOR: |
| 1068 | case GL_ONE_MINUS_DST_COLOR: |
| 1069 | case GL_SRC_ALPHA: |
| 1070 | case GL_ONE_MINUS_SRC_ALPHA: |
| 1071 | case GL_DST_ALPHA: |
| 1072 | case GL_ONE_MINUS_DST_ALPHA: |
| 1073 | case GL_CONSTANT_COLOR: |
| 1074 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 1075 | case GL_CONSTANT_ALPHA: |
| 1076 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 1077 | return true; |
| 1078 | |
| 1079 | // EXT_blend_func_extended. |
| 1080 | case GL_SRC1_COLOR_EXT: |
| 1081 | case GL_SRC1_ALPHA_EXT: |
| 1082 | case GL_ONE_MINUS_SRC1_COLOR_EXT: |
| 1083 | case GL_ONE_MINUS_SRC1_ALPHA_EXT: |
| 1084 | case GL_SRC_ALPHA_SATURATE_EXT: |
| 1085 | return ext.blendFuncExtended; |
| 1086 | |
| 1087 | default: |
| 1088 | return false; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | bool ValidSrcBlendFunc(const Context *context, GLenum val) |
| 1093 | { |
| 1094 | if (ValidBlendFunc(context, val)) |
| 1095 | return true; |
| 1096 | |
| 1097 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1098 | return true; |
| 1099 | |
| 1100 | return false; |
| 1101 | } |
| 1102 | |
| 1103 | bool ValidDstBlendFunc(const Context *context, GLenum val) |
| 1104 | { |
| 1105 | if (ValidBlendFunc(context, val)) |
| 1106 | return true; |
| 1107 | |
| 1108 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1109 | { |
| 1110 | if (context->getClientMajorVersion() >= 3) |
| 1111 | return true; |
| 1112 | } |
| 1113 | |
| 1114 | return false; |
| 1115 | } |
| 1116 | |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1117 | void RecordBindTextureTypeError(Context *context, TextureType target) |
| 1118 | { |
| 1119 | ASSERT(!context->getStateCache().isValidBindTextureType(target)); |
| 1120 | |
| 1121 | switch (target) |
| 1122 | { |
| 1123 | case TextureType::Rectangle: |
| 1124 | ASSERT(!context->getExtensions().textureRectangle); |
| 1125 | context->handleError(InvalidEnum() |
| 1126 | << "Context does not support GL_ANGLE_texture_rectangle"); |
| 1127 | break; |
| 1128 | |
| 1129 | case TextureType::_3D: |
| 1130 | case TextureType::_2DArray: |
| 1131 | ASSERT(context->getClientMajorVersion() < 3); |
| 1132 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
| 1133 | break; |
| 1134 | |
| 1135 | case TextureType::_2DMultisample: |
| 1136 | ASSERT(context->getClientVersion() < Version(3, 1)); |
| 1137 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
| 1138 | break; |
| 1139 | |
| 1140 | case TextureType::_2DMultisampleArray: |
| 1141 | ASSERT(!context->getExtensions().textureStorageMultisample2DArray); |
| 1142 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), MultisampleArrayExtensionRequired); |
| 1143 | break; |
| 1144 | |
| 1145 | case TextureType::External: |
| 1146 | ASSERT(!context->getExtensions().eglImageExternal && |
| 1147 | !context->getExtensions().eglStreamConsumerExternal); |
| 1148 | context->handleError(InvalidEnum() << "External texture extension not enabled"); |
| 1149 | break; |
| 1150 | |
| 1151 | default: |
| 1152 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
| 1153 | } |
| 1154 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1155 | } // anonymous namespace |
| 1156 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1157 | bool ValidateES2TexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1158 | TextureTarget target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1159 | GLint level, |
| 1160 | GLenum internalformat, |
| 1161 | bool isCompressed, |
| 1162 | bool isSubImage, |
| 1163 | GLint xoffset, |
| 1164 | GLint yoffset, |
| 1165 | GLsizei width, |
| 1166 | GLsizei height, |
| 1167 | GLint border, |
| 1168 | GLenum format, |
| 1169 | GLenum type, |
| 1170 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1171 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1172 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1173 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1174 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1175 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1176 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1177 | } |
| 1178 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1179 | TextureType texType = TextureTargetToType(target); |
| 1180 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1181 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1182 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1183 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1186 | if (!ValidMipLevel(context, texType, level)) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1187 | { |
| 1188 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
| 1189 | return false; |
| 1190 | } |
| 1191 | |
| 1192 | if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width || |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1193 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1194 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1195 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1196 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1197 | } |
| 1198 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1199 | // From GL_CHROMIUM_color_buffer_float_rgb[a]: |
| 1200 | // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for |
| 1201 | // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the |
| 1202 | // internalformat parameter and format parameter of TexImage2D must match is lifted for this |
| 1203 | // case. |
| 1204 | bool nonEqualFormatsAllowed = |
| 1205 | (internalformat == GL_RGB32F && context->getExtensions().colorBufferFloatRGB) || |
| 1206 | (internalformat == GL_RGBA32F && context->getExtensions().colorBufferFloatRGBA); |
| 1207 | |
| 1208 | if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1209 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1210 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1211 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1212 | } |
| 1213 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1214 | const gl::Caps &caps = context->getCaps(); |
| 1215 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1216 | switch (texType) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1217 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1218 | case TextureType::_2D: |
| 1219 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 1220 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 1221 | { |
| 1222 | context->handleError(InvalidValue()); |
| 1223 | return false; |
| 1224 | } |
| 1225 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1226 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1227 | case TextureType::Rectangle: |
| 1228 | ASSERT(level == 0); |
| 1229 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1230 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1231 | { |
| 1232 | context->handleError(InvalidValue()); |
| 1233 | return false; |
| 1234 | } |
| 1235 | if (isCompressed) |
| 1236 | { |
| 1237 | context->handleError(InvalidEnum() |
| 1238 | << "Rectangle texture cannot have a compressed format."); |
| 1239 | return false; |
| 1240 | } |
| 1241 | break; |
| 1242 | |
| 1243 | case TextureType::CubeMap: |
| 1244 | if (!isSubImage && width != height) |
| 1245 | { |
| 1246 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapFacesEqualDimensions); |
| 1247 | return false; |
| 1248 | } |
| 1249 | |
| 1250 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 1251 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 1252 | { |
| 1253 | context->handleError(InvalidValue()); |
| 1254 | return false; |
| 1255 | } |
| 1256 | break; |
| 1257 | |
| 1258 | default: |
| 1259 | context->handleError(InvalidEnum()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1260 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1261 | } |
| 1262 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1263 | gl::Texture *texture = context->getTargetTexture(texType); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1264 | if (!texture) |
| 1265 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1266 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1267 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1268 | } |
| 1269 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1270 | if (isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1271 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1272 | const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info; |
| 1273 | if (textureInternalFormat.internalFormat == GL_NONE) |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 1274 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1275 | context->handleError(InvalidOperation() << "Texture level does not exist."); |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 1276 | return false; |
| 1277 | } |
| 1278 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1279 | if (format != GL_NONE) |
| 1280 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1281 | if (GetInternalFormatInfo(format, type).sizedInternalFormat != |
| 1282 | textureInternalFormat.sizedInternalFormat) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1283 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1284 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TypeMismatch); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1285 | return false; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1290 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 1291 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1292 | context->handleError(InvalidValue()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1293 | return false; |
| 1294 | } |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1295 | |
| 1296 | if (width > 0 && height > 0 && pixels == nullptr && |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1297 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr) |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1298 | { |
| 1299 | ANGLE_VALIDATION_ERR(context, InvalidValue(), PixelDataNull); |
| 1300 | return false; |
| 1301 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1302 | } |
| 1303 | else |
| 1304 | { |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1305 | if (texture->getImmutableFormat()) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1306 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1307 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1308 | return false; |
| 1309 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | // Verify zero border |
| 1313 | if (border != 0) |
| 1314 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1315 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1316 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1317 | } |
| 1318 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1319 | if (isCompressed) |
| 1320 | { |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1321 | GLenum actualInternalFormat = |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1322 | isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat |
| 1323 | : internalformat; |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1324 | |
| 1325 | const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat); |
| 1326 | |
| 1327 | if (!internalFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1328 | { |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1329 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidInternalFormat); |
| 1330 | return false; |
| 1331 | } |
| 1332 | |
| 1333 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), |
| 1334 | context->getExtensions())) |
| 1335 | { |
| 1336 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidInternalFormat); |
| 1337 | return false; |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1338 | } |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1339 | |
| 1340 | if (isSubImage) |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1341 | { |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1342 | // From the OES_compressed_ETC1_RGB8_texture spec: |
| 1343 | // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or |
| 1344 | // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format |
| 1345 | // ETC1_RGB8_OES. |
| 1346 | if (actualInternalFormat == GL_ETC1_RGB8_OES) |
| 1347 | { |
| 1348 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
| 1349 | return false; |
| 1350 | } |
| 1351 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1352 | if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width, |
| 1353 | height, texture->getWidth(target, level), |
| 1354 | texture->getHeight(target, level))) |
| 1355 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1356 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1357 | return false; |
| 1358 | } |
| 1359 | |
| 1360 | if (format != actualInternalFormat) |
| 1361 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1362 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1363 | return false; |
| 1364 | } |
| 1365 | } |
| 1366 | else |
| 1367 | { |
| 1368 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 1369 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1370 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1371 | return false; |
| 1372 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | else |
| 1376 | { |
| 1377 | // validate <type> by itself (used as secondary key below) |
| 1378 | switch (type) |
| 1379 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1380 | case GL_UNSIGNED_BYTE: |
| 1381 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1382 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1383 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1384 | case GL_UNSIGNED_SHORT: |
| 1385 | case GL_UNSIGNED_INT: |
| 1386 | case GL_UNSIGNED_INT_24_8_OES: |
| 1387 | case GL_HALF_FLOAT_OES: |
| 1388 | case GL_FLOAT: |
| 1389 | break; |
| 1390 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1391 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1392 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | // validate <format> + <type> combinations |
| 1396 | // - invalid <format> -> sets INVALID_ENUM |
| 1397 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 1398 | switch (format) |
| 1399 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1400 | case GL_ALPHA: |
| 1401 | case GL_LUMINANCE: |
| 1402 | case GL_LUMINANCE_ALPHA: |
| 1403 | switch (type) |
| 1404 | { |
| 1405 | case GL_UNSIGNED_BYTE: |
| 1406 | case GL_FLOAT: |
| 1407 | case GL_HALF_FLOAT_OES: |
| 1408 | break; |
| 1409 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1410 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1411 | return false; |
| 1412 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1413 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1414 | case GL_RED: |
| 1415 | case GL_RG: |
| 1416 | if (!context->getExtensions().textureRG) |
| 1417 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1418 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1419 | return false; |
| 1420 | } |
| 1421 | switch (type) |
| 1422 | { |
| 1423 | case GL_UNSIGNED_BYTE: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1424 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1425 | case GL_FLOAT: |
| 1426 | case GL_HALF_FLOAT_OES: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1427 | if (!context->getExtensions().textureFloat) |
| 1428 | { |
| 1429 | context->handleError(InvalidEnum()); |
| 1430 | return false; |
| 1431 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1432 | break; |
| 1433 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1434 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1435 | return false; |
| 1436 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1437 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1438 | case GL_RGB: |
| 1439 | switch (type) |
| 1440 | { |
| 1441 | case GL_UNSIGNED_BYTE: |
| 1442 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1443 | case GL_FLOAT: |
| 1444 | case GL_HALF_FLOAT_OES: |
| 1445 | break; |
| 1446 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1447 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1448 | return false; |
| 1449 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1450 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1451 | case GL_RGBA: |
| 1452 | switch (type) |
| 1453 | { |
| 1454 | case GL_UNSIGNED_BYTE: |
| 1455 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1456 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1457 | case GL_FLOAT: |
| 1458 | case GL_HALF_FLOAT_OES: |
| 1459 | break; |
| 1460 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1461 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1462 | return false; |
| 1463 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1464 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1465 | case GL_BGRA_EXT: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1466 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1467 | { |
| 1468 | context->handleError(InvalidEnum()); |
| 1469 | return false; |
| 1470 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1471 | switch (type) |
| 1472 | { |
| 1473 | case GL_UNSIGNED_BYTE: |
| 1474 | break; |
| 1475 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1476 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1477 | return false; |
| 1478 | } |
| 1479 | break; |
| 1480 | case GL_SRGB_EXT: |
| 1481 | case GL_SRGB_ALPHA_EXT: |
| 1482 | if (!context->getExtensions().sRGB) |
| 1483 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1484 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1485 | return false; |
| 1486 | } |
| 1487 | switch (type) |
| 1488 | { |
| 1489 | case GL_UNSIGNED_BYTE: |
| 1490 | break; |
| 1491 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1492 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1493 | return false; |
| 1494 | } |
| 1495 | break; |
| 1496 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1497 | // handled below |
| 1498 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1499 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1500 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1501 | break; |
| 1502 | case GL_DEPTH_COMPONENT: |
| 1503 | switch (type) |
| 1504 | { |
| 1505 | case GL_UNSIGNED_SHORT: |
| 1506 | case GL_UNSIGNED_INT: |
| 1507 | break; |
| 1508 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1509 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1510 | return false; |
| 1511 | } |
| 1512 | break; |
| 1513 | case GL_DEPTH_STENCIL_OES: |
| 1514 | switch (type) |
| 1515 | { |
| 1516 | case GL_UNSIGNED_INT_24_8_OES: |
| 1517 | break; |
| 1518 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1519 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1520 | return false; |
| 1521 | } |
| 1522 | break; |
| 1523 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1524 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1525 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | switch (format) |
| 1529 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1530 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1531 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1532 | if (context->getExtensions().textureCompressionDXT1) |
| 1533 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1534 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1535 | return false; |
| 1536 | } |
| 1537 | else |
| 1538 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1539 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1540 | return false; |
| 1541 | } |
| 1542 | break; |
| 1543 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1544 | if (context->getExtensions().textureCompressionDXT3) |
| 1545 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1546 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1547 | return false; |
| 1548 | } |
| 1549 | else |
| 1550 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1551 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1552 | return false; |
| 1553 | } |
| 1554 | break; |
| 1555 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1556 | if (context->getExtensions().textureCompressionDXT5) |
| 1557 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1558 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1559 | return false; |
| 1560 | } |
| 1561 | else |
| 1562 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1563 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1564 | return false; |
| 1565 | } |
| 1566 | break; |
| 1567 | case GL_ETC1_RGB8_OES: |
| 1568 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1569 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1570 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1571 | return false; |
| 1572 | } |
| 1573 | else |
| 1574 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1575 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1576 | return false; |
| 1577 | } |
| 1578 | break; |
| 1579 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1580 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1581 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1582 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1583 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1584 | if (context->getExtensions().lossyETCDecode) |
| 1585 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1586 | context->handleError(InvalidOperation() |
| 1587 | << "ETC lossy decode formats can't work with this type."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1588 | return false; |
| 1589 | } |
| 1590 | else |
| 1591 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1592 | context->handleError(InvalidEnum() |
| 1593 | << "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1594 | return false; |
| 1595 | } |
| 1596 | break; |
| 1597 | case GL_DEPTH_COMPONENT: |
| 1598 | case GL_DEPTH_STENCIL_OES: |
| 1599 | if (!context->getExtensions().depthTextures) |
| 1600 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1601 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1602 | return false; |
| 1603 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1604 | if (target != TextureTarget::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1605 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1606 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTargetAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1607 | return false; |
| 1608 | } |
| 1609 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1610 | // but ANGLE_depth_texture does not |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1611 | if (pixels != nullptr) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1612 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1613 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), PixelDataNotNull); |
| 1614 | return false; |
| 1615 | } |
| 1616 | if (level != 0) |
| 1617 | { |
| 1618 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), LevelNotZero); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1619 | return false; |
| 1620 | } |
| 1621 | break; |
| 1622 | default: |
| 1623 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1624 | } |
| 1625 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1626 | if (!isSubImage) |
| 1627 | { |
| 1628 | switch (internalformat) |
| 1629 | { |
| 1630 | case GL_RGBA32F: |
| 1631 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1632 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1633 | context->handleError(InvalidValue() |
| 1634 | << "Sized GL_RGBA32F internal format requires " |
| 1635 | "GL_CHROMIUM_color_buffer_float_rgba"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1636 | return false; |
| 1637 | } |
| 1638 | if (type != GL_FLOAT) |
| 1639 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1640 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1641 | return false; |
| 1642 | } |
| 1643 | if (format != GL_RGBA) |
| 1644 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1645 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1646 | return false; |
| 1647 | } |
| 1648 | break; |
| 1649 | |
| 1650 | case GL_RGB32F: |
| 1651 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1652 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1653 | context->handleError(InvalidValue() |
| 1654 | << "Sized GL_RGB32F internal format requires " |
| 1655 | "GL_CHROMIUM_color_buffer_float_rgb"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1656 | return false; |
| 1657 | } |
| 1658 | if (type != GL_FLOAT) |
| 1659 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1660 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1661 | return false; |
| 1662 | } |
| 1663 | if (format != GL_RGB) |
| 1664 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1665 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1666 | return false; |
| 1667 | } |
| 1668 | break; |
| 1669 | |
| 1670 | default: |
| 1671 | break; |
| 1672 | } |
| 1673 | } |
| 1674 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1675 | if (type == GL_FLOAT) |
| 1676 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1677 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1678 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1679 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1680 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1681 | } |
| 1682 | } |
| 1683 | else if (type == GL_HALF_FLOAT_OES) |
| 1684 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1685 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1686 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1687 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1688 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1689 | } |
| 1690 | } |
| 1691 | } |
| 1692 | |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 1693 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1694 | if (!ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1695 | imageSize)) |
| 1696 | { |
| 1697 | return false; |
| 1698 | } |
| 1699 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1700 | return true; |
| 1701 | } |
| 1702 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1703 | bool ValidateES2TexStorageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1704 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1705 | GLsizei levels, |
| 1706 | GLenum internalformat, |
| 1707 | GLsizei width, |
| 1708 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1709 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1710 | if (target != TextureType::_2D && target != TextureType::CubeMap && |
| 1711 | target != TextureType::Rectangle) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1712 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1713 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1714 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | if (width < 1 || height < 1 || levels < 1) |
| 1718 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1719 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1720 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1721 | } |
| 1722 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1723 | if (target == TextureType::CubeMap && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1724 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1725 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1726 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1730 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1731 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1732 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1733 | } |
| 1734 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1735 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1736 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1737 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1738 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1739 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1740 | } |
| 1741 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1742 | const gl::Caps &caps = context->getCaps(); |
| 1743 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1744 | switch (target) |
| 1745 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1746 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1747 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1748 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1749 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1750 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1751 | return false; |
| 1752 | } |
| 1753 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1754 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1755 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1756 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize || levels != 1) |
| 1757 | { |
| 1758 | context->handleError(InvalidValue()); |
| 1759 | return false; |
| 1760 | } |
| 1761 | if (formatInfo.compressed) |
| 1762 | { |
| 1763 | context->handleError(InvalidEnum() |
| 1764 | << "Rectangle texture cannot have a compressed format."); |
| 1765 | return false; |
| 1766 | } |
| 1767 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1768 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1769 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1770 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1771 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1772 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1773 | return false; |
| 1774 | } |
| 1775 | break; |
| 1776 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1777 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1778 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1779 | } |
| 1780 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1781 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1782 | { |
| 1783 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1784 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1785 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1786 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | switch (internalformat) |
| 1791 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1792 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1793 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1794 | if (!context->getExtensions().textureCompressionDXT1) |
| 1795 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1796 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1797 | return false; |
| 1798 | } |
| 1799 | break; |
| 1800 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1801 | if (!context->getExtensions().textureCompressionDXT3) |
| 1802 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1803 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1804 | return false; |
| 1805 | } |
| 1806 | break; |
| 1807 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1808 | if (!context->getExtensions().textureCompressionDXT5) |
| 1809 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1810 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1811 | return false; |
| 1812 | } |
| 1813 | break; |
| 1814 | case GL_ETC1_RGB8_OES: |
| 1815 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1816 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1817 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1818 | return false; |
| 1819 | } |
| 1820 | break; |
| 1821 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1822 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1823 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1824 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1825 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1826 | if (!context->getExtensions().lossyETCDecode) |
| 1827 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1828 | context->handleError(InvalidEnum() |
| 1829 | << "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1830 | return false; |
| 1831 | } |
| 1832 | break; |
| 1833 | case GL_RGBA32F_EXT: |
| 1834 | case GL_RGB32F_EXT: |
| 1835 | case GL_ALPHA32F_EXT: |
| 1836 | case GL_LUMINANCE32F_EXT: |
| 1837 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 1838 | if (!context->getExtensions().textureFloat) |
| 1839 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1840 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1841 | return false; |
| 1842 | } |
| 1843 | break; |
| 1844 | case GL_RGBA16F_EXT: |
| 1845 | case GL_RGB16F_EXT: |
| 1846 | case GL_ALPHA16F_EXT: |
| 1847 | case GL_LUMINANCE16F_EXT: |
| 1848 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 1849 | if (!context->getExtensions().textureHalfFloat) |
| 1850 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1851 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1852 | return false; |
| 1853 | } |
| 1854 | break; |
| 1855 | case GL_R8_EXT: |
| 1856 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1857 | if (!context->getExtensions().textureRG) |
| 1858 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1859 | context->handleError(InvalidEnum()); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1860 | return false; |
| 1861 | } |
| 1862 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1863 | case GL_R16F_EXT: |
| 1864 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1865 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 1866 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1867 | context->handleError(InvalidEnum()); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1868 | return false; |
| 1869 | } |
| 1870 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1871 | case GL_R32F_EXT: |
| 1872 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1873 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1874 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1875 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1876 | return false; |
| 1877 | } |
| 1878 | break; |
| 1879 | case GL_DEPTH_COMPONENT16: |
| 1880 | case GL_DEPTH_COMPONENT32_OES: |
| 1881 | case GL_DEPTH24_STENCIL8_OES: |
| 1882 | if (!context->getExtensions().depthTextures) |
| 1883 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1884 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1885 | return false; |
| 1886 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1887 | if (target != TextureType::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1888 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1889 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1890 | return false; |
| 1891 | } |
| 1892 | // ANGLE_depth_texture only supports 1-level textures |
| 1893 | if (levels != 1) |
| 1894 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1895 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1896 | return false; |
| 1897 | } |
| 1898 | break; |
| 1899 | default: |
| 1900 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1901 | } |
| 1902 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1903 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1904 | if (!texture || texture->id() == 0) |
| 1905 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1906 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1907 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1908 | } |
| 1909 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1910 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1911 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1912 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1913 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | return true; |
| 1917 | } |
| 1918 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1919 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 1920 | GLenum target, |
| 1921 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1922 | const GLenum *attachments) |
| 1923 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1924 | if (!context->getExtensions().discardFramebuffer) |
| 1925 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1926 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1927 | return false; |
| 1928 | } |
| 1929 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1930 | bool defaultFramebuffer = false; |
| 1931 | |
| 1932 | switch (target) |
| 1933 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1934 | case GL_FRAMEBUFFER: |
| 1935 | defaultFramebuffer = |
| 1936 | (context->getGLState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
| 1937 | break; |
| 1938 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1939 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1940 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1943 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1944 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1947 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 1948 | { |
| 1949 | if (!context->getExtensions().vertexArrayObject) |
| 1950 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1951 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1952 | return false; |
| 1953 | } |
| 1954 | |
| 1955 | return ValidateBindVertexArrayBase(context, array); |
| 1956 | } |
| 1957 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1958 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1959 | { |
| 1960 | if (!context->getExtensions().vertexArrayObject) |
| 1961 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1962 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1963 | return false; |
| 1964 | } |
| 1965 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1966 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1969 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1970 | { |
| 1971 | if (!context->getExtensions().vertexArrayObject) |
| 1972 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1973 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1974 | return false; |
| 1975 | } |
| 1976 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1977 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1980 | bool ValidateIsVertexArrayOES(Context *context, GLuint array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1981 | { |
| 1982 | if (!context->getExtensions().vertexArrayObject) |
| 1983 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1984 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1985 | return false; |
| 1986 | } |
| 1987 | |
| 1988 | return true; |
| 1989 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1990 | |
| 1991 | bool ValidateProgramBinaryOES(Context *context, |
| 1992 | GLuint program, |
| 1993 | GLenum binaryFormat, |
| 1994 | const void *binary, |
| 1995 | GLint length) |
| 1996 | { |
| 1997 | if (!context->getExtensions().getProgramBinary) |
| 1998 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1999 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2000 | return false; |
| 2001 | } |
| 2002 | |
| 2003 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 2004 | } |
| 2005 | |
| 2006 | bool ValidateGetProgramBinaryOES(Context *context, |
| 2007 | GLuint program, |
| 2008 | GLsizei bufSize, |
| 2009 | GLsizei *length, |
| 2010 | GLenum *binaryFormat, |
| 2011 | void *binary) |
| 2012 | { |
| 2013 | if (!context->getExtensions().getProgramBinary) |
| 2014 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2015 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2016 | return false; |
| 2017 | } |
| 2018 | |
| 2019 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 2020 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2021 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2022 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 2023 | { |
| 2024 | switch (source) |
| 2025 | { |
| 2026 | case GL_DEBUG_SOURCE_API: |
| 2027 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 2028 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 2029 | case GL_DEBUG_SOURCE_OTHER: |
| 2030 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 2031 | return !mustBeThirdPartyOrApplication; |
| 2032 | |
| 2033 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 2034 | case GL_DEBUG_SOURCE_APPLICATION: |
| 2035 | return true; |
| 2036 | |
| 2037 | default: |
| 2038 | return false; |
| 2039 | } |
| 2040 | } |
| 2041 | |
| 2042 | static bool ValidDebugType(GLenum type) |
| 2043 | { |
| 2044 | switch (type) |
| 2045 | { |
| 2046 | case GL_DEBUG_TYPE_ERROR: |
| 2047 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 2048 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 2049 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 2050 | case GL_DEBUG_TYPE_PORTABILITY: |
| 2051 | case GL_DEBUG_TYPE_OTHER: |
| 2052 | case GL_DEBUG_TYPE_MARKER: |
| 2053 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 2054 | case GL_DEBUG_TYPE_POP_GROUP: |
| 2055 | return true; |
| 2056 | |
| 2057 | default: |
| 2058 | return false; |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | static bool ValidDebugSeverity(GLenum severity) |
| 2063 | { |
| 2064 | switch (severity) |
| 2065 | { |
| 2066 | case GL_DEBUG_SEVERITY_HIGH: |
| 2067 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 2068 | case GL_DEBUG_SEVERITY_LOW: |
| 2069 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 2070 | return true; |
| 2071 | |
| 2072 | default: |
| 2073 | return false; |
| 2074 | } |
| 2075 | } |
| 2076 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2077 | bool ValidateDebugMessageControlKHR(Context *context, |
| 2078 | GLenum source, |
| 2079 | GLenum type, |
| 2080 | GLenum severity, |
| 2081 | GLsizei count, |
| 2082 | const GLuint *ids, |
| 2083 | GLboolean enabled) |
| 2084 | { |
| 2085 | if (!context->getExtensions().debug) |
| 2086 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2087 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2088 | return false; |
| 2089 | } |
| 2090 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2091 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 2092 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2093 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2094 | return false; |
| 2095 | } |
| 2096 | |
| 2097 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 2098 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2099 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2100 | return false; |
| 2101 | } |
| 2102 | |
| 2103 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 2104 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2105 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2106 | return false; |
| 2107 | } |
| 2108 | |
| 2109 | if (count > 0) |
| 2110 | { |
| 2111 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 2112 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2113 | context->handleError( |
| 2114 | InvalidOperation() |
| 2115 | << "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] | 2116 | return false; |
| 2117 | } |
| 2118 | |
| 2119 | if (severity != GL_DONT_CARE) |
| 2120 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2121 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2122 | InvalidOperation() |
| 2123 | << "If count is greater than zero, severity must be GL_DONT_CARE."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2124 | return false; |
| 2125 | } |
| 2126 | } |
| 2127 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2128 | return true; |
| 2129 | } |
| 2130 | |
| 2131 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 2132 | GLenum source, |
| 2133 | GLenum type, |
| 2134 | GLuint id, |
| 2135 | GLenum severity, |
| 2136 | GLsizei length, |
| 2137 | const GLchar *buf) |
| 2138 | { |
| 2139 | if (!context->getExtensions().debug) |
| 2140 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2141 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2142 | return false; |
| 2143 | } |
| 2144 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2145 | if (!context->getGLState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2146 | { |
| 2147 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 2148 | // not generate an error. |
| 2149 | return false; |
| 2150 | } |
| 2151 | |
| 2152 | if (!ValidDebugSeverity(severity)) |
| 2153 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2154 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2155 | return false; |
| 2156 | } |
| 2157 | |
| 2158 | if (!ValidDebugType(type)) |
| 2159 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2160 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2161 | return false; |
| 2162 | } |
| 2163 | |
| 2164 | if (!ValidDebugSource(source, true)) |
| 2165 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2166 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2167 | return false; |
| 2168 | } |
| 2169 | |
| 2170 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 2171 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2172 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2173 | context->handleError(InvalidValue() |
| 2174 | << "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2175 | return false; |
| 2176 | } |
| 2177 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2178 | return true; |
| 2179 | } |
| 2180 | |
| 2181 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 2182 | GLDEBUGPROCKHR callback, |
| 2183 | const void *userParam) |
| 2184 | { |
| 2185 | if (!context->getExtensions().debug) |
| 2186 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2187 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2188 | return false; |
| 2189 | } |
| 2190 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2191 | return true; |
| 2192 | } |
| 2193 | |
| 2194 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 2195 | GLuint count, |
| 2196 | GLsizei bufSize, |
| 2197 | GLenum *sources, |
| 2198 | GLenum *types, |
| 2199 | GLuint *ids, |
| 2200 | GLenum *severities, |
| 2201 | GLsizei *lengths, |
| 2202 | GLchar *messageLog) |
| 2203 | { |
| 2204 | if (!context->getExtensions().debug) |
| 2205 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2206 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2207 | return false; |
| 2208 | } |
| 2209 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2210 | if (bufSize < 0 && messageLog != nullptr) |
| 2211 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2212 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2213 | return false; |
| 2214 | } |
| 2215 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2216 | return true; |
| 2217 | } |
| 2218 | |
| 2219 | bool ValidatePushDebugGroupKHR(Context *context, |
| 2220 | GLenum source, |
| 2221 | GLuint id, |
| 2222 | GLsizei length, |
| 2223 | const GLchar *message) |
| 2224 | { |
| 2225 | if (!context->getExtensions().debug) |
| 2226 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2227 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2228 | return false; |
| 2229 | } |
| 2230 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2231 | if (!ValidDebugSource(source, true)) |
| 2232 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2233 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2234 | return false; |
| 2235 | } |
| 2236 | |
| 2237 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 2238 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2239 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2240 | context->handleError(InvalidValue() |
| 2241 | << "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2242 | return false; |
| 2243 | } |
| 2244 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2245 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2246 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 2247 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2248 | context |
| 2249 | ->handleError(StackOverflow() |
| 2250 | << "Cannot push more than GL_MAX_DEBUG_GROUP_STACK_DEPTH debug groups."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2251 | return false; |
| 2252 | } |
| 2253 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2254 | return true; |
| 2255 | } |
| 2256 | |
| 2257 | bool ValidatePopDebugGroupKHR(Context *context) |
| 2258 | { |
| 2259 | if (!context->getExtensions().debug) |
| 2260 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2261 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2262 | return false; |
| 2263 | } |
| 2264 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2265 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2266 | if (currentStackSize <= 1) |
| 2267 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2268 | context->handleError(StackUnderflow() << "Cannot pop the default debug group."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2269 | return false; |
| 2270 | } |
| 2271 | |
| 2272 | return true; |
| 2273 | } |
| 2274 | |
| 2275 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 2276 | { |
| 2277 | switch (identifier) |
| 2278 | { |
| 2279 | case GL_BUFFER: |
| 2280 | if (context->getBuffer(name) == nullptr) |
| 2281 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2282 | context->handleError(InvalidValue() << "name is not a valid buffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2283 | return false; |
| 2284 | } |
| 2285 | return true; |
| 2286 | |
| 2287 | case GL_SHADER: |
| 2288 | if (context->getShader(name) == nullptr) |
| 2289 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2290 | context->handleError(InvalidValue() << "name is not a valid shader."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2291 | return false; |
| 2292 | } |
| 2293 | return true; |
| 2294 | |
| 2295 | case GL_PROGRAM: |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2296 | if (context->getProgramNoResolveLink(name) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2297 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2298 | context->handleError(InvalidValue() << "name is not a valid program."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2299 | return false; |
| 2300 | } |
| 2301 | return true; |
| 2302 | |
| 2303 | case GL_VERTEX_ARRAY: |
| 2304 | if (context->getVertexArray(name) == nullptr) |
| 2305 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2306 | context->handleError(InvalidValue() << "name is not a valid vertex array."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2307 | return false; |
| 2308 | } |
| 2309 | return true; |
| 2310 | |
| 2311 | case GL_QUERY: |
| 2312 | if (context->getQuery(name) == nullptr) |
| 2313 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2314 | context->handleError(InvalidValue() << "name is not a valid query."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2315 | return false; |
| 2316 | } |
| 2317 | return true; |
| 2318 | |
| 2319 | case GL_TRANSFORM_FEEDBACK: |
| 2320 | if (context->getTransformFeedback(name) == nullptr) |
| 2321 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2322 | context->handleError(InvalidValue() << "name is not a valid transform feedback."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2323 | return false; |
| 2324 | } |
| 2325 | return true; |
| 2326 | |
| 2327 | case GL_SAMPLER: |
| 2328 | if (context->getSampler(name) == nullptr) |
| 2329 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2330 | context->handleError(InvalidValue() << "name is not a valid sampler."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2331 | return false; |
| 2332 | } |
| 2333 | return true; |
| 2334 | |
| 2335 | case GL_TEXTURE: |
| 2336 | if (context->getTexture(name) == nullptr) |
| 2337 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2338 | context->handleError(InvalidValue() << "name is not a valid texture."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2339 | return false; |
| 2340 | } |
| 2341 | return true; |
| 2342 | |
| 2343 | case GL_RENDERBUFFER: |
| 2344 | if (context->getRenderbuffer(name) == nullptr) |
| 2345 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2346 | context->handleError(InvalidValue() << "name is not a valid renderbuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2347 | return false; |
| 2348 | } |
| 2349 | return true; |
| 2350 | |
| 2351 | case GL_FRAMEBUFFER: |
| 2352 | if (context->getFramebuffer(name) == nullptr) |
| 2353 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2354 | context->handleError(InvalidValue() << "name is not a valid framebuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2355 | return false; |
| 2356 | } |
| 2357 | return true; |
| 2358 | |
| 2359 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2360 | context->handleError(InvalidEnum() << "Invalid identifier."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2361 | return false; |
| 2362 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2363 | } |
| 2364 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2365 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2366 | { |
| 2367 | size_t labelLength = 0; |
| 2368 | |
| 2369 | if (length < 0) |
| 2370 | { |
| 2371 | if (label != nullptr) |
| 2372 | { |
| 2373 | labelLength = strlen(label); |
| 2374 | } |
| 2375 | } |
| 2376 | else |
| 2377 | { |
| 2378 | labelLength = static_cast<size_t>(length); |
| 2379 | } |
| 2380 | |
| 2381 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2382 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2383 | context->handleError(InvalidValue() << "Label length is larger than GL_MAX_LABEL_LENGTH."); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2384 | return false; |
| 2385 | } |
| 2386 | |
| 2387 | return true; |
| 2388 | } |
| 2389 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2390 | bool ValidateObjectLabelKHR(Context *context, |
| 2391 | GLenum identifier, |
| 2392 | GLuint name, |
| 2393 | GLsizei length, |
| 2394 | const GLchar *label) |
| 2395 | { |
| 2396 | if (!context->getExtensions().debug) |
| 2397 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2398 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2399 | return false; |
| 2400 | } |
| 2401 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2402 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2403 | { |
| 2404 | return false; |
| 2405 | } |
| 2406 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2407 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2408 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2409 | return false; |
| 2410 | } |
| 2411 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2412 | return true; |
| 2413 | } |
| 2414 | |
| 2415 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2416 | GLenum identifier, |
| 2417 | GLuint name, |
| 2418 | GLsizei bufSize, |
| 2419 | GLsizei *length, |
| 2420 | GLchar *label) |
| 2421 | { |
| 2422 | if (!context->getExtensions().debug) |
| 2423 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2424 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2425 | return false; |
| 2426 | } |
| 2427 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2428 | if (bufSize < 0) |
| 2429 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2430 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2431 | return false; |
| 2432 | } |
| 2433 | |
| 2434 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2435 | { |
| 2436 | return false; |
| 2437 | } |
| 2438 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2439 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2443 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 2444 | if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2445 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2446 | context->handleError(InvalidValue() << "name is not a valid sync."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2447 | return false; |
| 2448 | } |
| 2449 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2450 | return true; |
| 2451 | } |
| 2452 | |
| 2453 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2454 | const void *ptr, |
| 2455 | GLsizei length, |
| 2456 | const GLchar *label) |
| 2457 | { |
| 2458 | if (!context->getExtensions().debug) |
| 2459 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2460 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2461 | return false; |
| 2462 | } |
| 2463 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2464 | if (!ValidateObjectPtrName(context, ptr)) |
| 2465 | { |
| 2466 | return false; |
| 2467 | } |
| 2468 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2469 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2470 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2471 | return false; |
| 2472 | } |
| 2473 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2474 | return true; |
| 2475 | } |
| 2476 | |
| 2477 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2478 | const void *ptr, |
| 2479 | GLsizei bufSize, |
| 2480 | GLsizei *length, |
| 2481 | GLchar *label) |
| 2482 | { |
| 2483 | if (!context->getExtensions().debug) |
| 2484 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2485 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2486 | return false; |
| 2487 | } |
| 2488 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2489 | if (bufSize < 0) |
| 2490 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2491 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2492 | return false; |
| 2493 | } |
| 2494 | |
| 2495 | if (!ValidateObjectPtrName(context, ptr)) |
| 2496 | { |
| 2497 | return false; |
| 2498 | } |
| 2499 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2500 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2504 | { |
| 2505 | if (!context->getExtensions().debug) |
| 2506 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2507 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2508 | return false; |
| 2509 | } |
| 2510 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2511 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2512 | switch (pname) |
| 2513 | { |
| 2514 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2515 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2516 | break; |
| 2517 | |
| 2518 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2519 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2520 | return false; |
| 2521 | } |
| 2522 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2523 | return true; |
| 2524 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2525 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 2526 | bool ValidateGetPointervRobustANGLERobustANGLE(Context *context, |
| 2527 | GLenum pname, |
| 2528 | GLsizei bufSize, |
| 2529 | GLsizei *length, |
| 2530 | void **params) |
| 2531 | { |
| 2532 | UNIMPLEMENTED(); |
| 2533 | return false; |
| 2534 | } |
| 2535 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2536 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2537 | GLint srcX0, |
| 2538 | GLint srcY0, |
| 2539 | GLint srcX1, |
| 2540 | GLint srcY1, |
| 2541 | GLint dstX0, |
| 2542 | GLint dstY0, |
| 2543 | GLint dstX1, |
| 2544 | GLint dstY1, |
| 2545 | GLbitfield mask, |
| 2546 | GLenum filter) |
| 2547 | { |
| 2548 | if (!context->getExtensions().framebufferBlit) |
| 2549 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 2550 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitExtensionNotAvailable); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2551 | return false; |
| 2552 | } |
| 2553 | |
| 2554 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2555 | { |
| 2556 | // TODO(jmadill): Determine if this should be available on other implementations. |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 2557 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitExtensionScaleOrFlip); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2558 | return false; |
| 2559 | } |
| 2560 | |
| 2561 | if (filter == GL_LINEAR) |
| 2562 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 2563 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), BlitExtensionLinear); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2564 | return false; |
| 2565 | } |
| 2566 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2567 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2568 | Framebuffer *drawFramebuffer = context->getGLState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2569 | |
| 2570 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2571 | { |
| 2572 | const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 2573 | const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer(); |
| 2574 | |
| 2575 | if (readColorAttachment && drawColorAttachment) |
| 2576 | { |
| 2577 | if (!(readColorAttachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2578 | readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2579 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2580 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2581 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 2582 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2583 | BlitExtensionFromInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2584 | return false; |
| 2585 | } |
| 2586 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2587 | for (size_t drawbufferIdx = 0; |
| 2588 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2589 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2590 | const FramebufferAttachment *attachment = |
| 2591 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2592 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2593 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2594 | if (!(attachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2595 | attachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2596 | attachment->type() != GL_RENDERBUFFER && |
| 2597 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2598 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 2599 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2600 | BlitExtensionToInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2601 | return false; |
| 2602 | } |
| 2603 | |
| 2604 | // Return an error if the destination formats do not match |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 2605 | if (!Format::EquivalentForBlit(attachment->getFormat(), |
| 2606 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2607 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 2608 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2609 | BlitExtensionFormatMismatch); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2610 | return false; |
| 2611 | } |
| 2612 | } |
| 2613 | } |
| 2614 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2615 | GLint samples = readFramebuffer->getSamples(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2616 | if (samples != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2617 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2618 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2619 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 2620 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2621 | BlitExtensionMultisampledWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2622 | return false; |
| 2623 | } |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2628 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2629 | for (size_t i = 0; i < 2; i++) |
| 2630 | { |
| 2631 | if (mask & masks[i]) |
| 2632 | { |
| 2633 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2634 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2635 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2636 | drawFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2637 | |
| 2638 | if (readBuffer && drawBuffer) |
| 2639 | { |
| 2640 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2641 | dstX0, dstY0, dstX1, dstY1)) |
| 2642 | { |
| 2643 | // only whole-buffer copies are permitted |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 2644 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2645 | BlitExtensionDepthStencilWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2646 | return false; |
| 2647 | } |
| 2648 | |
| 2649 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2650 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 2651 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2652 | BlitExtensionMultisampledDepthOrStencil); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2653 | return false; |
| 2654 | } |
| 2655 | } |
| 2656 | } |
| 2657 | } |
| 2658 | |
| 2659 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2660 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2661 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2662 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2663 | bool ValidateClear(Context *context, GLbitfield mask) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2664 | { |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 2665 | Framebuffer *fbo = context->getGLState().getDrawFramebuffer(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2666 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2667 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2668 | if (!ValidateFramebufferComplete(context, fbo)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2669 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2670 | return false; |
| 2671 | } |
| 2672 | |
| 2673 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2674 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2675 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidClearMask); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2676 | return false; |
| 2677 | } |
| 2678 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2679 | if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2680 | { |
| 2681 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2682 | GL_SIGNED_NORMALIZED}; |
| 2683 | |
Corentin Wallez | 59c4159 | 2017-07-11 13:19:54 -0400 | [diff] [blame] | 2684 | for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2685 | drawBufferIdx++) |
| 2686 | { |
| 2687 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2688 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2689 | { |
| 2690 | return false; |
| 2691 | } |
| 2692 | } |
| 2693 | } |
| 2694 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2695 | if (extensions.multiview && extensions.disjointTimerQuery) |
| 2696 | { |
| 2697 | const State &state = context->getGLState(); |
| 2698 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2699 | if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed)) |
| 2700 | { |
| 2701 | context->handleError(InvalidOperation() << "There is an active query for target " |
| 2702 | "GL_TIME_ELAPSED_EXT when the number of " |
| 2703 | "views in the active draw framebuffer is " |
| 2704 | "greater than 1."); |
| 2705 | return false; |
| 2706 | } |
| 2707 | } |
| 2708 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2709 | return true; |
| 2710 | } |
| 2711 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2712 | bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2713 | { |
| 2714 | if (!context->getExtensions().drawBuffers) |
| 2715 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2716 | context->handleError(InvalidOperation() << "Extension not supported."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2717 | return false; |
| 2718 | } |
| 2719 | |
| 2720 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2721 | } |
| 2722 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2723 | bool ValidateTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2724 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2725 | GLint level, |
| 2726 | GLint internalformat, |
| 2727 | GLsizei width, |
| 2728 | GLsizei height, |
| 2729 | GLint border, |
| 2730 | GLenum format, |
| 2731 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2732 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2733 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2734 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2735 | { |
| 2736 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2737 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2738 | } |
| 2739 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2740 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2741 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2742 | 0, 0, width, height, 1, border, format, type, -1, |
| 2743 | pixels); |
| 2744 | } |
| 2745 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 2746 | bool ValidateTexImage2DRobustANGLE(Context *context, |
| 2747 | TextureTarget target, |
| 2748 | GLint level, |
| 2749 | GLint internalformat, |
| 2750 | GLsizei width, |
| 2751 | GLsizei height, |
| 2752 | GLint border, |
| 2753 | GLenum format, |
| 2754 | GLenum type, |
| 2755 | GLsizei bufSize, |
| 2756 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2757 | { |
| 2758 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2759 | { |
| 2760 | return false; |
| 2761 | } |
| 2762 | |
| 2763 | if (context->getClientMajorVersion() < 3) |
| 2764 | { |
| 2765 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2766 | 0, 0, width, height, border, format, type, bufSize, |
| 2767 | pixels); |
| 2768 | } |
| 2769 | |
| 2770 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2771 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2772 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2773 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | bool ValidateTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2777 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2778 | GLint level, |
| 2779 | GLint xoffset, |
| 2780 | GLint yoffset, |
| 2781 | GLsizei width, |
| 2782 | GLsizei height, |
| 2783 | GLenum format, |
| 2784 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2785 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2786 | { |
| 2787 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2788 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2789 | { |
| 2790 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2791 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2792 | } |
| 2793 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2794 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2795 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2796 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 2797 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2798 | } |
| 2799 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2800 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2801 | TextureTarget target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2802 | GLint level, |
| 2803 | GLint xoffset, |
| 2804 | GLint yoffset, |
| 2805 | GLsizei width, |
| 2806 | GLsizei height, |
| 2807 | GLenum format, |
| 2808 | GLenum type, |
| 2809 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2810 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2811 | { |
| 2812 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2813 | { |
| 2814 | return false; |
| 2815 | } |
| 2816 | |
| 2817 | if (context->getClientMajorVersion() < 3) |
| 2818 | { |
| 2819 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2820 | yoffset, width, height, 0, format, type, bufSize, |
| 2821 | pixels); |
| 2822 | } |
| 2823 | |
| 2824 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2825 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2826 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 2827 | pixels); |
| 2828 | } |
| 2829 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2830 | bool ValidateCompressedTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2831 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2832 | GLint level, |
| 2833 | GLenum internalformat, |
| 2834 | GLsizei width, |
| 2835 | GLsizei height, |
| 2836 | GLint border, |
| 2837 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2838 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2839 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2840 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2841 | { |
| 2842 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2843 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2844 | { |
| 2845 | return false; |
| 2846 | } |
| 2847 | } |
| 2848 | else |
| 2849 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2850 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2851 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2852 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2853 | data)) |
| 2854 | { |
| 2855 | return false; |
| 2856 | } |
| 2857 | } |
| 2858 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2859 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2860 | |
| 2861 | GLuint blockSize = 0; |
| 2862 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2863 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2864 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2865 | return false; |
| 2866 | } |
| 2867 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2868 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2869 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2870 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CompressedTextureDimensionsMustMatchData); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2871 | return false; |
| 2872 | } |
| 2873 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2874 | if (target == TextureTarget::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2875 | { |
| 2876 | context->handleError(InvalidEnum() << "Rectangle texture cannot have a compressed format."); |
| 2877 | return false; |
| 2878 | } |
| 2879 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2880 | return true; |
| 2881 | } |
| 2882 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2883 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2884 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2885 | GLint level, |
| 2886 | GLenum internalformat, |
| 2887 | GLsizei width, |
| 2888 | GLsizei height, |
| 2889 | GLint border, |
| 2890 | GLsizei imageSize, |
| 2891 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2892 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2893 | { |
| 2894 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2895 | { |
| 2896 | return false; |
| 2897 | } |
| 2898 | |
| 2899 | return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 2900 | border, imageSize, data); |
| 2901 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2902 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2903 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2904 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2905 | GLint level, |
| 2906 | GLint xoffset, |
| 2907 | GLint yoffset, |
| 2908 | GLsizei width, |
| 2909 | GLsizei height, |
| 2910 | GLenum format, |
| 2911 | GLsizei imageSize, |
| 2912 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2913 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2914 | { |
| 2915 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2916 | { |
| 2917 | return false; |
| 2918 | } |
| 2919 | |
| 2920 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 2921 | format, imageSize, data); |
| 2922 | } |
| 2923 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2924 | bool ValidateCompressedTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2925 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2926 | GLint level, |
| 2927 | GLint xoffset, |
| 2928 | GLint yoffset, |
| 2929 | GLsizei width, |
| 2930 | GLsizei height, |
| 2931 | GLenum format, |
| 2932 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2933 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2934 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2935 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2936 | { |
| 2937 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2938 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2939 | { |
| 2940 | return false; |
| 2941 | } |
| 2942 | } |
| 2943 | else |
| 2944 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2945 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2946 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2947 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2948 | data)) |
| 2949 | { |
| 2950 | return false; |
| 2951 | } |
| 2952 | } |
| 2953 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2954 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2955 | GLuint blockSize = 0; |
| 2956 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2957 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2958 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2959 | return false; |
| 2960 | } |
| 2961 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2962 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2963 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2964 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2965 | return false; |
| 2966 | } |
| 2967 | |
| 2968 | return true; |
| 2969 | } |
| 2970 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2971 | bool ValidateGetBufferPointervOES(Context *context, |
| 2972 | BufferBinding target, |
| 2973 | GLenum pname, |
| 2974 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2975 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2976 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2977 | } |
| 2978 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2979 | bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2980 | { |
| 2981 | if (!context->getExtensions().mapBuffer) |
| 2982 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2983 | context->handleError(InvalidOperation() << "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2984 | return false; |
| 2985 | } |
| 2986 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 2987 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2988 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2989 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2990 | return false; |
| 2991 | } |
| 2992 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2993 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2994 | |
| 2995 | if (buffer == nullptr) |
| 2996 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2997 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2998 | return false; |
| 2999 | } |
| 3000 | |
| 3001 | if (access != GL_WRITE_ONLY_OES) |
| 3002 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3003 | context->handleError(InvalidEnum() << "Non-write buffer mapping not supported."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3004 | return false; |
| 3005 | } |
| 3006 | |
| 3007 | if (buffer->isMapped()) |
| 3008 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3009 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3010 | return false; |
| 3011 | } |
| 3012 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3013 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3014 | } |
| 3015 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3016 | bool ValidateUnmapBufferOES(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3017 | { |
| 3018 | if (!context->getExtensions().mapBuffer) |
| 3019 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3020 | context->handleError(InvalidOperation() << "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3021 | return false; |
| 3022 | } |
| 3023 | |
| 3024 | return ValidateUnmapBufferBase(context, target); |
| 3025 | } |
| 3026 | |
| 3027 | bool ValidateMapBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3028 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3029 | GLintptr offset, |
| 3030 | GLsizeiptr length, |
| 3031 | GLbitfield access) |
| 3032 | { |
| 3033 | if (!context->getExtensions().mapBufferRange) |
| 3034 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3035 | context->handleError(InvalidOperation() << "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3036 | return false; |
| 3037 | } |
| 3038 | |
| 3039 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 3040 | } |
| 3041 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3042 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3043 | { |
| 3044 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 3045 | ASSERT(buffer != nullptr); |
| 3046 | |
| 3047 | // Check if this buffer is currently being used as a transform feedback output buffer |
| 3048 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
| 3049 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 3050 | { |
| 3051 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 3052 | { |
| 3053 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 3054 | if (transformFeedbackBuffer.get() == buffer) |
| 3055 | { |
| 3056 | context->handleError(InvalidOperation() |
| 3057 | << "Buffer is currently bound for transform feedback."); |
| 3058 | return false; |
| 3059 | } |
| 3060 | } |
| 3061 | } |
| 3062 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3063 | if (context->getExtensions().webglCompatibility && |
| 3064 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3065 | { |
| 3066 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferBoundForTransformFeedback); |
| 3067 | return false; |
| 3068 | } |
| 3069 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3070 | return true; |
| 3071 | } |
| 3072 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3073 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3074 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3075 | GLintptr offset, |
| 3076 | GLsizeiptr length) |
| 3077 | { |
| 3078 | if (!context->getExtensions().mapBufferRange) |
| 3079 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3080 | context->handleError(InvalidOperation() << "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3081 | return false; |
| 3082 | } |
| 3083 | |
| 3084 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 3085 | } |
| 3086 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3087 | bool ValidateBindTexture(Context *context, TextureType target, GLuint texture) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3088 | { |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 3089 | if (!context->getStateCache().isValidBindTextureType(target)) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3090 | { |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 3091 | RecordBindTextureTypeError(context, target); |
| 3092 | return false; |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3093 | } |
| 3094 | |
Jamie Madill | 0fdb956 | 2018-09-17 17:18:43 -0400 | [diff] [blame] | 3095 | if (texture == 0) |
| 3096 | { |
| 3097 | return true; |
| 3098 | } |
| 3099 | |
| 3100 | Texture *textureObject = context->getTexture(texture); |
| 3101 | if (textureObject && textureObject->getType() != target) |
| 3102 | { |
| 3103 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TypeMismatch); |
| 3104 | return false; |
| 3105 | } |
| 3106 | |
| 3107 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 3108 | !context->isTextureGenerated(texture)) |
| 3109 | { |
| 3110 | context->handleError(InvalidOperation() << "Texture was not generated"); |
| 3111 | return false; |
| 3112 | } |
| 3113 | |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3114 | return true; |
| 3115 | } |
| 3116 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3117 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 3118 | GLuint program, |
| 3119 | GLint location, |
| 3120 | const GLchar *name) |
| 3121 | { |
| 3122 | if (!context->getExtensions().bindUniformLocation) |
| 3123 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3124 | context->handleError(InvalidOperation() |
| 3125 | << "GL_CHROMIUM_bind_uniform_location is not available."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3126 | return false; |
| 3127 | } |
| 3128 | |
| 3129 | Program *programObject = GetValidProgram(context, program); |
| 3130 | if (!programObject) |
| 3131 | { |
| 3132 | return false; |
| 3133 | } |
| 3134 | |
| 3135 | if (location < 0) |
| 3136 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3137 | context->handleError(InvalidValue() << "Location cannot be less than 0."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3138 | return false; |
| 3139 | } |
| 3140 | |
| 3141 | const Caps &caps = context->getCaps(); |
| 3142 | if (static_cast<size_t>(location) >= |
| 3143 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3144 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3145 | context->handleError(InvalidValue() << "Location must be less than " |
| 3146 | "(MAX_VERTEX_UNIFORM_VECTORS + " |
| 3147 | "MAX_FRAGMENT_UNIFORM_VECTORS) * 4"); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3148 | return false; |
| 3149 | } |
| 3150 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3151 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3152 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3153 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3154 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3155 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3156 | return false; |
| 3157 | } |
| 3158 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3159 | if (strncmp(name, "gl_", 3) == 0) |
| 3160 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3161 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3162 | return false; |
| 3163 | } |
| 3164 | |
| 3165 | return true; |
| 3166 | } |
| 3167 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3168 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3169 | { |
| 3170 | if (!context->getExtensions().framebufferMixedSamples) |
| 3171 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3172 | context->handleError(InvalidOperation() |
| 3173 | << "GL_CHROMIUM_framebuffer_mixed_samples is not available."); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3174 | return false; |
| 3175 | } |
| 3176 | switch (components) |
| 3177 | { |
| 3178 | case GL_RGB: |
| 3179 | case GL_RGBA: |
| 3180 | case GL_ALPHA: |
| 3181 | case GL_NONE: |
| 3182 | break; |
| 3183 | default: |
| 3184 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3185 | InvalidEnum() |
| 3186 | << "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] | 3187 | return false; |
| 3188 | } |
| 3189 | |
| 3190 | return true; |
| 3191 | } |
| 3192 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3193 | // CHROMIUM_path_rendering |
| 3194 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3195 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3196 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3197 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3198 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3199 | return false; |
| 3200 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3201 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3202 | if (matrix == nullptr) |
| 3203 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3204 | context->handleError(InvalidOperation() << "Invalid matrix."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3205 | return false; |
| 3206 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3207 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3208 | return true; |
| 3209 | } |
| 3210 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3211 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3212 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3213 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3214 | } |
| 3215 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3216 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3217 | { |
| 3218 | if (!context->getExtensions().pathRendering) |
| 3219 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3220 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3221 | return false; |
| 3222 | } |
| 3223 | |
| 3224 | // range = 0 is undefined in NV_path_rendering. |
| 3225 | // we add stricter semantic check here and require a non zero positive range. |
| 3226 | if (range <= 0) |
| 3227 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3228 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3229 | return false; |
| 3230 | } |
| 3231 | |
| 3232 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3233 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3234 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3235 | return false; |
| 3236 | } |
| 3237 | |
| 3238 | return true; |
| 3239 | } |
| 3240 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3241 | bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3242 | { |
| 3243 | if (!context->getExtensions().pathRendering) |
| 3244 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3245 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3246 | return false; |
| 3247 | } |
| 3248 | |
| 3249 | // range = 0 is undefined in NV_path_rendering. |
| 3250 | // we add stricter semantic check here and require a non zero positive range. |
| 3251 | if (range <= 0) |
| 3252 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3253 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3254 | return false; |
| 3255 | } |
| 3256 | |
| 3257 | angle::CheckedNumeric<std::uint32_t> checkedRange(path); |
| 3258 | checkedRange += range; |
| 3259 | |
| 3260 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3261 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3262 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3263 | return false; |
| 3264 | } |
| 3265 | return true; |
| 3266 | } |
| 3267 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3268 | bool ValidatePathCommandsCHROMIUM(Context *context, |
| 3269 | GLuint path, |
| 3270 | GLsizei numCommands, |
| 3271 | const GLubyte *commands, |
| 3272 | GLsizei numCoords, |
| 3273 | GLenum coordType, |
| 3274 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3275 | { |
| 3276 | if (!context->getExtensions().pathRendering) |
| 3277 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3278 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3279 | return false; |
| 3280 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3281 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3282 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3283 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3284 | return false; |
| 3285 | } |
| 3286 | |
| 3287 | if (numCommands < 0) |
| 3288 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3289 | context->handleError(InvalidValue() << "Invalid number of commands."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3290 | return false; |
| 3291 | } |
| 3292 | else if (numCommands > 0) |
| 3293 | { |
| 3294 | if (!commands) |
| 3295 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3296 | context->handleError(InvalidValue() << "No commands array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3297 | return false; |
| 3298 | } |
| 3299 | } |
| 3300 | |
| 3301 | if (numCoords < 0) |
| 3302 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3303 | context->handleError(InvalidValue() << "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3304 | return false; |
| 3305 | } |
| 3306 | else if (numCoords > 0) |
| 3307 | { |
| 3308 | if (!coords) |
| 3309 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3310 | context->handleError(InvalidValue() << "No coordinate array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3311 | return false; |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | std::uint32_t coordTypeSize = 0; |
| 3316 | switch (coordType) |
| 3317 | { |
| 3318 | case GL_BYTE: |
| 3319 | coordTypeSize = sizeof(GLbyte); |
| 3320 | break; |
| 3321 | |
| 3322 | case GL_UNSIGNED_BYTE: |
| 3323 | coordTypeSize = sizeof(GLubyte); |
| 3324 | break; |
| 3325 | |
| 3326 | case GL_SHORT: |
| 3327 | coordTypeSize = sizeof(GLshort); |
| 3328 | break; |
| 3329 | |
| 3330 | case GL_UNSIGNED_SHORT: |
| 3331 | coordTypeSize = sizeof(GLushort); |
| 3332 | break; |
| 3333 | |
| 3334 | case GL_FLOAT: |
| 3335 | coordTypeSize = sizeof(GLfloat); |
| 3336 | break; |
| 3337 | |
| 3338 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3339 | context->handleError(InvalidEnum() << "Invalid coordinate type."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3340 | return false; |
| 3341 | } |
| 3342 | |
| 3343 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3344 | checkedSize += (coordTypeSize * numCoords); |
| 3345 | if (!checkedSize.IsValid()) |
| 3346 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3347 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3348 | return false; |
| 3349 | } |
| 3350 | |
| 3351 | // early return skips command data validation when it doesn't exist. |
| 3352 | if (!commands) |
| 3353 | return true; |
| 3354 | |
| 3355 | GLsizei expectedNumCoords = 0; |
| 3356 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3357 | { |
| 3358 | switch (commands[i]) |
| 3359 | { |
| 3360 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3361 | break; |
| 3362 | case GL_MOVE_TO_CHROMIUM: |
| 3363 | case GL_LINE_TO_CHROMIUM: |
| 3364 | expectedNumCoords += 2; |
| 3365 | break; |
| 3366 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3367 | expectedNumCoords += 4; |
| 3368 | break; |
| 3369 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3370 | expectedNumCoords += 6; |
| 3371 | break; |
| 3372 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3373 | expectedNumCoords += 5; |
| 3374 | break; |
| 3375 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3376 | context->handleError(InvalidEnum() << "Invalid command."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3377 | return false; |
| 3378 | } |
| 3379 | } |
| 3380 | if (expectedNumCoords != numCoords) |
| 3381 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3382 | context->handleError(InvalidValue() << "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3383 | return false; |
| 3384 | } |
| 3385 | |
| 3386 | return true; |
| 3387 | } |
| 3388 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3389 | bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3390 | { |
| 3391 | if (!context->getExtensions().pathRendering) |
| 3392 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3393 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3394 | return false; |
| 3395 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3396 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3397 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3398 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3399 | return false; |
| 3400 | } |
| 3401 | |
| 3402 | switch (pname) |
| 3403 | { |
| 3404 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3405 | if (value < 0.0f) |
| 3406 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3407 | context->handleError(InvalidValue() << "Invalid stroke width."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3408 | return false; |
| 3409 | } |
| 3410 | break; |
| 3411 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3412 | switch (static_cast<GLenum>(value)) |
| 3413 | { |
| 3414 | case GL_FLAT_CHROMIUM: |
| 3415 | case GL_SQUARE_CHROMIUM: |
| 3416 | case GL_ROUND_CHROMIUM: |
| 3417 | break; |
| 3418 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3419 | context->handleError(InvalidEnum() << "Invalid end caps."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3420 | return false; |
| 3421 | } |
| 3422 | break; |
| 3423 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3424 | switch (static_cast<GLenum>(value)) |
| 3425 | { |
| 3426 | case GL_MITER_REVERT_CHROMIUM: |
| 3427 | case GL_BEVEL_CHROMIUM: |
| 3428 | case GL_ROUND_CHROMIUM: |
| 3429 | break; |
| 3430 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3431 | context->handleError(InvalidEnum() << "Invalid join style."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3432 | return false; |
| 3433 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3434 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3435 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3436 | if (value < 0.0f) |
| 3437 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3438 | context->handleError(InvalidValue() << "Invalid miter limit."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3439 | return false; |
| 3440 | } |
| 3441 | break; |
| 3442 | |
| 3443 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3444 | // no errors, only clamping. |
| 3445 | break; |
| 3446 | |
| 3447 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3448 | context->handleError(InvalidEnum() << "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3449 | return false; |
| 3450 | } |
| 3451 | return true; |
| 3452 | } |
| 3453 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3454 | bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value) |
| 3455 | { |
| 3456 | // TODO(jmadill): Use proper clamping cast. |
| 3457 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 3458 | } |
| 3459 | |
| 3460 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3461 | { |
| 3462 | if (!context->getExtensions().pathRendering) |
| 3463 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3464 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3465 | return false; |
| 3466 | } |
| 3467 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3468 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3469 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3470 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3471 | return false; |
| 3472 | } |
| 3473 | if (!value) |
| 3474 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3475 | context->handleError(InvalidValue() << "No value array."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3476 | return false; |
| 3477 | } |
| 3478 | |
| 3479 | switch (pname) |
| 3480 | { |
| 3481 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3482 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3483 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3484 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3485 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3486 | break; |
| 3487 | |
| 3488 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3489 | context->handleError(InvalidEnum() << "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3490 | return false; |
| 3491 | } |
| 3492 | |
| 3493 | return true; |
| 3494 | } |
| 3495 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3496 | bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value) |
| 3497 | { |
| 3498 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 3499 | reinterpret_cast<GLfloat *>(value)); |
| 3500 | } |
| 3501 | |
| 3502 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3503 | { |
| 3504 | if (!context->getExtensions().pathRendering) |
| 3505 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3506 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3507 | return false; |
| 3508 | } |
| 3509 | |
| 3510 | switch (func) |
| 3511 | { |
| 3512 | case GL_NEVER: |
| 3513 | case GL_ALWAYS: |
| 3514 | case GL_LESS: |
| 3515 | case GL_LEQUAL: |
| 3516 | case GL_EQUAL: |
| 3517 | case GL_GEQUAL: |
| 3518 | case GL_GREATER: |
| 3519 | case GL_NOTEQUAL: |
| 3520 | break; |
| 3521 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3522 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3523 | return false; |
| 3524 | } |
| 3525 | |
| 3526 | return true; |
| 3527 | } |
| 3528 | |
| 3529 | // Note that the spec specifies that for the path drawing commands |
| 3530 | // if the path object is not an existing path object the command |
| 3531 | // does nothing and no error is generated. |
| 3532 | // However if the path object exists but has not been specified any |
| 3533 | // commands then an error is generated. |
| 3534 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3535 | bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3536 | { |
| 3537 | if (!context->getExtensions().pathRendering) |
| 3538 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3539 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3540 | return false; |
| 3541 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3542 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3543 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3544 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3545 | return false; |
| 3546 | } |
| 3547 | |
| 3548 | switch (fillMode) |
| 3549 | { |
| 3550 | case GL_COUNT_UP_CHROMIUM: |
| 3551 | case GL_COUNT_DOWN_CHROMIUM: |
| 3552 | break; |
| 3553 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3554 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3555 | return false; |
| 3556 | } |
| 3557 | |
| 3558 | if (!isPow2(mask + 1)) |
| 3559 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3560 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3561 | return false; |
| 3562 | } |
| 3563 | |
| 3564 | return true; |
| 3565 | } |
| 3566 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3567 | bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3568 | { |
| 3569 | if (!context->getExtensions().pathRendering) |
| 3570 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3571 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3572 | return false; |
| 3573 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3574 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3575 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3576 | 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] | 3577 | return false; |
| 3578 | } |
| 3579 | |
| 3580 | return true; |
| 3581 | } |
| 3582 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3583 | bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3584 | { |
| 3585 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3586 | } |
| 3587 | |
| 3588 | bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3589 | { |
| 3590 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3591 | } |
| 3592 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3593 | bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3594 | { |
| 3595 | if (!context->getExtensions().pathRendering) |
| 3596 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3597 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3598 | return false; |
| 3599 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3600 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3601 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3602 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3603 | return false; |
| 3604 | } |
| 3605 | |
| 3606 | switch (coverMode) |
| 3607 | { |
| 3608 | case GL_CONVEX_HULL_CHROMIUM: |
| 3609 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3610 | break; |
| 3611 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3612 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3613 | return false; |
| 3614 | } |
| 3615 | return true; |
| 3616 | } |
| 3617 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3618 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
| 3619 | GLuint path, |
| 3620 | GLenum fillMode, |
| 3621 | GLuint mask, |
| 3622 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3623 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3624 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 3625 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3626 | } |
| 3627 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3628 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
| 3629 | GLuint path, |
| 3630 | GLint reference, |
| 3631 | GLuint mask, |
| 3632 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3633 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3634 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 3635 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3636 | } |
| 3637 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3638 | bool ValidateIsPathCHROMIUM(Context *context, GLuint path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3639 | { |
| 3640 | if (!context->getExtensions().pathRendering) |
| 3641 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3642 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3643 | return false; |
| 3644 | } |
| 3645 | return true; |
| 3646 | } |
| 3647 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3648 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 3649 | GLsizei numPaths, |
| 3650 | GLenum pathNameType, |
| 3651 | const void *paths, |
| 3652 | GLuint pathBase, |
| 3653 | GLenum coverMode, |
| 3654 | GLenum transformType, |
| 3655 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3656 | { |
| 3657 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3658 | transformType, transformValues)) |
| 3659 | return false; |
| 3660 | |
| 3661 | switch (coverMode) |
| 3662 | { |
| 3663 | case GL_CONVEX_HULL_CHROMIUM: |
| 3664 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3665 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3666 | break; |
| 3667 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3668 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3669 | return false; |
| 3670 | } |
| 3671 | |
| 3672 | return true; |
| 3673 | } |
| 3674 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3675 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3676 | GLsizei numPaths, |
| 3677 | GLenum pathNameType, |
| 3678 | const void *paths, |
| 3679 | GLuint pathBase, |
| 3680 | GLenum coverMode, |
| 3681 | GLenum transformType, |
| 3682 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3683 | { |
| 3684 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3685 | transformType, transformValues)) |
| 3686 | return false; |
| 3687 | |
| 3688 | switch (coverMode) |
| 3689 | { |
| 3690 | case GL_CONVEX_HULL_CHROMIUM: |
| 3691 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3692 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3693 | break; |
| 3694 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3695 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3696 | return false; |
| 3697 | } |
| 3698 | |
| 3699 | return true; |
| 3700 | } |
| 3701 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3702 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 3703 | GLsizei numPaths, |
| 3704 | GLenum pathNameType, |
| 3705 | const void *paths, |
| 3706 | GLuint pathBase, |
| 3707 | GLenum fillMode, |
| 3708 | GLuint mask, |
| 3709 | GLenum transformType, |
| 3710 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3711 | { |
| 3712 | |
| 3713 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3714 | transformType, transformValues)) |
| 3715 | return false; |
| 3716 | |
| 3717 | switch (fillMode) |
| 3718 | { |
| 3719 | case GL_COUNT_UP_CHROMIUM: |
| 3720 | case GL_COUNT_DOWN_CHROMIUM: |
| 3721 | break; |
| 3722 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3723 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3724 | return false; |
| 3725 | } |
| 3726 | if (!isPow2(mask + 1)) |
| 3727 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3728 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3729 | return false; |
| 3730 | } |
| 3731 | return true; |
| 3732 | } |
| 3733 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3734 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 3735 | GLsizei numPaths, |
| 3736 | GLenum pathNameType, |
| 3737 | const void *paths, |
| 3738 | GLuint pathBase, |
| 3739 | GLint reference, |
| 3740 | GLuint mask, |
| 3741 | GLenum transformType, |
| 3742 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3743 | { |
| 3744 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3745 | transformType, transformValues)) |
| 3746 | return false; |
| 3747 | |
| 3748 | // no more validation here. |
| 3749 | |
| 3750 | return true; |
| 3751 | } |
| 3752 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3753 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 3754 | GLsizei numPaths, |
| 3755 | GLenum pathNameType, |
| 3756 | const void *paths, |
| 3757 | GLuint pathBase, |
| 3758 | GLenum fillMode, |
| 3759 | GLuint mask, |
| 3760 | GLenum coverMode, |
| 3761 | GLenum transformType, |
| 3762 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3763 | { |
| 3764 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3765 | transformType, transformValues)) |
| 3766 | return false; |
| 3767 | |
| 3768 | switch (coverMode) |
| 3769 | { |
| 3770 | case GL_CONVEX_HULL_CHROMIUM: |
| 3771 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3772 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3773 | break; |
| 3774 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3775 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3776 | return false; |
| 3777 | } |
| 3778 | |
| 3779 | switch (fillMode) |
| 3780 | { |
| 3781 | case GL_COUNT_UP_CHROMIUM: |
| 3782 | case GL_COUNT_DOWN_CHROMIUM: |
| 3783 | break; |
| 3784 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3785 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3786 | return false; |
| 3787 | } |
| 3788 | if (!isPow2(mask + 1)) |
| 3789 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3790 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3791 | return false; |
| 3792 | } |
| 3793 | |
| 3794 | return true; |
| 3795 | } |
| 3796 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3797 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3798 | GLsizei numPaths, |
| 3799 | GLenum pathNameType, |
| 3800 | const void *paths, |
| 3801 | GLuint pathBase, |
| 3802 | GLint reference, |
| 3803 | GLuint mask, |
| 3804 | GLenum coverMode, |
| 3805 | GLenum transformType, |
| 3806 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3807 | { |
| 3808 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3809 | transformType, transformValues)) |
| 3810 | return false; |
| 3811 | |
| 3812 | switch (coverMode) |
| 3813 | { |
| 3814 | case GL_CONVEX_HULL_CHROMIUM: |
| 3815 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3816 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3817 | break; |
| 3818 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3819 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3820 | return false; |
| 3821 | } |
| 3822 | |
| 3823 | return true; |
| 3824 | } |
| 3825 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3826 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
| 3827 | GLuint program, |
| 3828 | GLint location, |
| 3829 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3830 | { |
| 3831 | if (!context->getExtensions().pathRendering) |
| 3832 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3833 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3834 | return false; |
| 3835 | } |
| 3836 | |
| 3837 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 3838 | if (location >= MaxLocation) |
| 3839 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3840 | context->handleError(InvalidValue() << "Location exceeds max varying."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3841 | return false; |
| 3842 | } |
| 3843 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3844 | const auto *programObject = context->getProgramNoResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3845 | if (!programObject) |
| 3846 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3847 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3848 | return false; |
| 3849 | } |
| 3850 | |
| 3851 | if (!name) |
| 3852 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3853 | context->handleError(InvalidValue() << "No name given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3854 | return false; |
| 3855 | } |
| 3856 | |
| 3857 | if (angle::BeginsWith(name, "gl_")) |
| 3858 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3859 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3860 | return false; |
| 3861 | } |
| 3862 | |
| 3863 | return true; |
| 3864 | } |
| 3865 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3866 | bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
| 3867 | GLuint program, |
| 3868 | GLint location, |
| 3869 | GLenum genMode, |
| 3870 | GLint components, |
| 3871 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3872 | { |
| 3873 | if (!context->getExtensions().pathRendering) |
| 3874 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3875 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3876 | return false; |
| 3877 | } |
| 3878 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3879 | const auto *programObject = context->getProgramResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3880 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 3881 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3882 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3883 | return false; |
| 3884 | } |
| 3885 | |
| 3886 | if (!programObject->isLinked()) |
| 3887 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3888 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3889 | return false; |
| 3890 | } |
| 3891 | |
| 3892 | switch (genMode) |
| 3893 | { |
| 3894 | case GL_NONE: |
| 3895 | if (components != 0) |
| 3896 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3897 | context->handleError(InvalidValue() << "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3898 | return false; |
| 3899 | } |
| 3900 | break; |
| 3901 | |
| 3902 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 3903 | case GL_EYE_LINEAR_CHROMIUM: |
| 3904 | case GL_CONSTANT_CHROMIUM: |
| 3905 | if (components < 1 || components > 4) |
| 3906 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3907 | context->handleError(InvalidValue() << "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3908 | return false; |
| 3909 | } |
| 3910 | if (!coeffs) |
| 3911 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3912 | context->handleError(InvalidValue() << "No coefficients array given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3913 | return false; |
| 3914 | } |
| 3915 | break; |
| 3916 | |
| 3917 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3918 | context->handleError(InvalidEnum() << "Invalid gen mode."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3919 | return false; |
| 3920 | } |
| 3921 | |
| 3922 | // If the location is -1 then the command is silently ignored |
| 3923 | // and no further validation is needed. |
| 3924 | if (location == -1) |
| 3925 | return true; |
| 3926 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3927 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3928 | |
| 3929 | if (!binding.valid) |
| 3930 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3931 | context->handleError(InvalidOperation() << "No such binding."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3932 | return false; |
| 3933 | } |
| 3934 | |
| 3935 | if (binding.type != GL_NONE) |
| 3936 | { |
| 3937 | GLint expectedComponents = 0; |
| 3938 | switch (binding.type) |
| 3939 | { |
| 3940 | case GL_FLOAT: |
| 3941 | expectedComponents = 1; |
| 3942 | break; |
| 3943 | case GL_FLOAT_VEC2: |
| 3944 | expectedComponents = 2; |
| 3945 | break; |
| 3946 | case GL_FLOAT_VEC3: |
| 3947 | expectedComponents = 3; |
| 3948 | break; |
| 3949 | case GL_FLOAT_VEC4: |
| 3950 | expectedComponents = 4; |
| 3951 | break; |
| 3952 | default: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3953 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3954 | InvalidOperation() |
| 3955 | << "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] | 3956 | return false; |
| 3957 | } |
| 3958 | if (expectedComponents != components && genMode != GL_NONE) |
| 3959 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3960 | context->handleError(InvalidOperation() << "Unexpected number of components"); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3961 | return false; |
| 3962 | } |
| 3963 | } |
| 3964 | return true; |
| 3965 | } |
| 3966 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3967 | bool ValidateCopyTextureCHROMIUM(Context *context, |
| 3968 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3969 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3970 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3971 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3972 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3973 | GLint internalFormat, |
| 3974 | GLenum destType, |
| 3975 | GLboolean unpackFlipY, |
| 3976 | GLboolean unpackPremultiplyAlpha, |
| 3977 | GLboolean unpackUnmultiplyAlpha) |
| 3978 | { |
| 3979 | if (!context->getExtensions().copyTexture) |
| 3980 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3981 | context->handleError(InvalidOperation() |
| 3982 | << "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3983 | return false; |
| 3984 | } |
| 3985 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3986 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3987 | if (source == nullptr) |
| 3988 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3989 | context->handleError(InvalidValue() << "Source texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3990 | return false; |
| 3991 | } |
| 3992 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3993 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3994 | { |
Brandon Jones | 4e6f2ae | 2018-09-19 11:09:51 -0700 | [diff] [blame] | 3995 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3996 | return false; |
| 3997 | } |
| 3998 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3999 | TextureType sourceType = source->getType(); |
| 4000 | ASSERT(sourceType != TextureType::CubeMap); |
| 4001 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4002 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4003 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4004 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4005 | context->handleError(InvalidValue() << "Source texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4006 | return false; |
| 4007 | } |
| 4008 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4009 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 4010 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 4011 | if (sourceWidth == 0 || sourceHeight == 0) |
| 4012 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4013 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4014 | return false; |
| 4015 | } |
| 4016 | |
| 4017 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 4018 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4019 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4020 | context->handleError(InvalidOperation() << "Source texture internal format is invalid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4021 | return false; |
| 4022 | } |
| 4023 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4024 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4025 | { |
| 4026 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
| 4027 | return false; |
| 4028 | } |
| 4029 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4030 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4031 | if (dest == nullptr) |
| 4032 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4033 | context->handleError(InvalidValue() |
| 4034 | << "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4035 | return false; |
| 4036 | } |
| 4037 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4038 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4039 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4040 | context->handleError(InvalidValue() << "Destination texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4041 | return false; |
| 4042 | } |
| 4043 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4044 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4045 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4046 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4047 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4048 | return false; |
| 4049 | } |
| 4050 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4051 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 4052 | { |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4053 | return false; |
| 4054 | } |
| 4055 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4056 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4057 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4058 | context->handleError( |
| 4059 | InvalidValue() << "Destination width and height must be equal for cube map textures."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4060 | return false; |
| 4061 | } |
| 4062 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4063 | if (dest->getImmutableFormat()) |
| 4064 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4065 | context->handleError(InvalidOperation() << "Destination texture is immutable."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4066 | return false; |
| 4067 | } |
| 4068 | |
| 4069 | return true; |
| 4070 | } |
| 4071 | |
| 4072 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
| 4073 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4074 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4075 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4076 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4077 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4078 | GLint xoffset, |
| 4079 | GLint yoffset, |
| 4080 | GLint x, |
| 4081 | GLint y, |
| 4082 | GLsizei width, |
| 4083 | GLsizei height, |
| 4084 | GLboolean unpackFlipY, |
| 4085 | GLboolean unpackPremultiplyAlpha, |
| 4086 | GLboolean unpackUnmultiplyAlpha) |
| 4087 | { |
| 4088 | if (!context->getExtensions().copyTexture) |
| 4089 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4090 | context->handleError(InvalidOperation() |
| 4091 | << "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4092 | return false; |
| 4093 | } |
| 4094 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4095 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4096 | if (source == nullptr) |
| 4097 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4098 | context->handleError(InvalidValue() << "Source texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4099 | return false; |
| 4100 | } |
| 4101 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4102 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4103 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4104 | context->handleError(InvalidValue() << "Source texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4105 | return false; |
| 4106 | } |
| 4107 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4108 | TextureType sourceType = source->getType(); |
| 4109 | ASSERT(sourceType != TextureType::CubeMap); |
| 4110 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4111 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4112 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4113 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4114 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4115 | return false; |
| 4116 | } |
| 4117 | |
| 4118 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4119 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4120 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4121 | context->handleError(InvalidValue() |
| 4122 | << "The source level of the source texture must be defined."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4123 | return false; |
| 4124 | } |
| 4125 | |
| 4126 | if (x < 0 || y < 0) |
| 4127 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4128 | context->handleError(InvalidValue() << "x and y cannot be negative."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4129 | return false; |
| 4130 | } |
| 4131 | |
| 4132 | if (width < 0 || height < 0) |
| 4133 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4134 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4135 | return false; |
| 4136 | } |
| 4137 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4138 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4139 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4140 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4141 | ANGLE_VALIDATION_ERR(context, InvalidValue(), SourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4142 | return false; |
| 4143 | } |
| 4144 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4145 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4146 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4147 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4148 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4149 | return false; |
| 4150 | } |
| 4151 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4152 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4153 | { |
| 4154 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
| 4155 | return false; |
| 4156 | } |
| 4157 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4158 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4159 | if (dest == nullptr) |
| 4160 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4161 | context->handleError(InvalidValue() |
| 4162 | << "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4163 | return false; |
| 4164 | } |
| 4165 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4166 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4167 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4168 | context->handleError(InvalidValue() << "Destination texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4169 | return false; |
| 4170 | } |
| 4171 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4172 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4173 | true)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4174 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4175 | context->handleError(InvalidValue() << "Destination texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4176 | return false; |
| 4177 | } |
| 4178 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4179 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4180 | { |
Geoff Lang | bb1b19b | 2017-06-16 16:59:00 -0400 | [diff] [blame] | 4181 | context |
| 4182 | ->handleError(InvalidOperation() |
| 4183 | << "The destination level of the destination texture must be defined."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4184 | return false; |
| 4185 | } |
| 4186 | |
| 4187 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4188 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4189 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4190 | context->handleError(InvalidOperation() |
| 4191 | << "Destination internal format and type combination is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4192 | return false; |
| 4193 | } |
| 4194 | |
| 4195 | if (xoffset < 0 || yoffset < 0) |
| 4196 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4197 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4198 | return false; |
| 4199 | } |
| 4200 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4201 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4202 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4203 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4204 | context->handleError(InvalidValue() << "Destination texture not large enough to copy to."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4205 | return false; |
| 4206 | } |
| 4207 | |
| 4208 | return true; |
| 4209 | } |
| 4210 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4211 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId) |
| 4212 | { |
| 4213 | if (!context->getExtensions().copyCompressedTexture) |
| 4214 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4215 | context->handleError(InvalidOperation() |
| 4216 | << "GL_CHROMIUM_copy_compressed_texture extension not available."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4217 | return false; |
| 4218 | } |
| 4219 | |
| 4220 | const gl::Texture *source = context->getTexture(sourceId); |
| 4221 | if (source == nullptr) |
| 4222 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4223 | context->handleError(InvalidValue() << "Source texture is not a valid texture object."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4224 | return false; |
| 4225 | } |
| 4226 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4227 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4228 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4229 | context->handleError(InvalidValue() << "Source texture must be of type GL_TEXTURE_2D."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4230 | return false; |
| 4231 | } |
| 4232 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4233 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4234 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4235 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4236 | context->handleError(InvalidValue() << "Source texture must level 0 defined."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4237 | return false; |
| 4238 | } |
| 4239 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4240 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4241 | if (!sourceFormat.info->compressed) |
| 4242 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4243 | context->handleError(InvalidOperation() |
| 4244 | << "Source texture must have a compressed internal format."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4245 | return false; |
| 4246 | } |
| 4247 | |
| 4248 | const gl::Texture *dest = context->getTexture(destId); |
| 4249 | if (dest == nullptr) |
| 4250 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4251 | context->handleError(InvalidValue() |
| 4252 | << "Destination texture is not a valid texture object."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4253 | return false; |
| 4254 | } |
| 4255 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4256 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4257 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4258 | context->handleError(InvalidValue() |
| 4259 | << "Destination texture must be of type GL_TEXTURE_2D."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4260 | return false; |
| 4261 | } |
| 4262 | |
| 4263 | if (dest->getImmutableFormat()) |
| 4264 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4265 | context->handleError(InvalidOperation() << "Destination cannot be immutable."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4266 | return false; |
| 4267 | } |
| 4268 | |
| 4269 | return true; |
| 4270 | } |
| 4271 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4272 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4273 | { |
| 4274 | switch (type) |
| 4275 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4276 | case ShaderType::Vertex: |
| 4277 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4278 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4279 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4280 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4281 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4282 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4283 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4284 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4285 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4286 | break; |
| 4287 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4288 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4289 | if (!context->getExtensions().geometryShader) |
| 4290 | { |
| 4291 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidShaderType); |
| 4292 | return false; |
| 4293 | } |
| 4294 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4295 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4296 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4297 | return false; |
| 4298 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4299 | |
| 4300 | return true; |
| 4301 | } |
| 4302 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4303 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4304 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4305 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4306 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4307 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4308 | { |
| 4309 | if (size < 0) |
| 4310 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4311 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4312 | return false; |
| 4313 | } |
| 4314 | |
| 4315 | switch (usage) |
| 4316 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4317 | case BufferUsage::StreamDraw: |
| 4318 | case BufferUsage::StaticDraw: |
| 4319 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4320 | break; |
| 4321 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4322 | case BufferUsage::StreamRead: |
| 4323 | case BufferUsage::StaticRead: |
| 4324 | case BufferUsage::DynamicRead: |
| 4325 | case BufferUsage::StreamCopy: |
| 4326 | case BufferUsage::StaticCopy: |
| 4327 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4328 | if (context->getClientMajorVersion() < 3) |
| 4329 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4330 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4331 | return false; |
| 4332 | } |
| 4333 | break; |
| 4334 | |
| 4335 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4336 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4337 | return false; |
| 4338 | } |
| 4339 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4340 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4341 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4342 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4343 | return false; |
| 4344 | } |
| 4345 | |
| 4346 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 4347 | |
| 4348 | if (!buffer) |
| 4349 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4350 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4351 | return false; |
| 4352 | } |
| 4353 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4354 | if (context->getExtensions().webglCompatibility && |
| 4355 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4356 | { |
| 4357 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferBoundForTransformFeedback); |
| 4358 | return false; |
| 4359 | } |
| 4360 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4361 | return true; |
| 4362 | } |
| 4363 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4364 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4365 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4366 | GLintptr offset, |
| 4367 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4368 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4369 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4370 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4371 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4372 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
| 4373 | return false; |
| 4374 | } |
| 4375 | |
| 4376 | if (offset < 0) |
| 4377 | { |
| 4378 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4379 | return false; |
| 4380 | } |
| 4381 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4382 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4383 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4384 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4385 | return false; |
| 4386 | } |
| 4387 | |
| 4388 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 4389 | |
| 4390 | if (!buffer) |
| 4391 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4392 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4393 | return false; |
| 4394 | } |
| 4395 | |
| 4396 | if (buffer->isMapped()) |
| 4397 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4398 | context->handleError(InvalidOperation()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4399 | return false; |
| 4400 | } |
| 4401 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4402 | if (context->getExtensions().webglCompatibility && |
| 4403 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4404 | { |
| 4405 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferBoundForTransformFeedback); |
| 4406 | return false; |
| 4407 | } |
| 4408 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4409 | // Check for possible overflow of size + offset |
| 4410 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4411 | checkedSize += offset; |
| 4412 | if (!checkedSize.IsValid()) |
| 4413 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4414 | context->handleError(OutOfMemory()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4415 | return false; |
| 4416 | } |
| 4417 | |
| 4418 | if (size + offset > buffer->getSize()) |
| 4419 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4420 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4421 | return false; |
| 4422 | } |
| 4423 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4424 | return true; |
| 4425 | } |
| 4426 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4427 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4428 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4429 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4430 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4431 | context->handleError(InvalidOperation() << "GL_ANGLE_request_extension is not available."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4432 | return false; |
| 4433 | } |
| 4434 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4435 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4436 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4437 | context->handleError(InvalidOperation() << "Extension " << name << " is not requestable."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4438 | return false; |
| 4439 | } |
| 4440 | |
| 4441 | return true; |
| 4442 | } |
| 4443 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4444 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4445 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4446 | if (context->getClientMajorVersion() < 2) |
| 4447 | { |
| 4448 | return ValidateMultitextureUnit(context, texture); |
| 4449 | } |
| 4450 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4451 | if (texture < GL_TEXTURE0 || |
| 4452 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4453 | { |
Lingfeng Yang | 96310cd | 2018-03-28 11:56:28 -0700 | [diff] [blame] | 4454 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4455 | return false; |
| 4456 | } |
| 4457 | |
| 4458 | return true; |
| 4459 | } |
| 4460 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4461 | bool ValidateAttachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4462 | { |
| 4463 | Program *programObject = GetValidProgram(context, program); |
| 4464 | if (!programObject) |
| 4465 | { |
| 4466 | return false; |
| 4467 | } |
| 4468 | |
| 4469 | Shader *shaderObject = GetValidShader(context, shader); |
| 4470 | if (!shaderObject) |
| 4471 | { |
| 4472 | return false; |
| 4473 | } |
| 4474 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4475 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4476 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4477 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ShaderAttachmentHasShader); |
| 4478 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | return true; |
| 4482 | } |
| 4483 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4484 | bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4485 | { |
| 4486 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4487 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4488 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4489 | return false; |
| 4490 | } |
| 4491 | |
| 4492 | if (strncmp(name, "gl_", 3) == 0) |
| 4493 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4494 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4495 | return false; |
| 4496 | } |
| 4497 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4498 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4499 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4500 | const size_t length = strlen(name); |
| 4501 | |
| 4502 | if (!IsValidESSLString(name, length)) |
| 4503 | { |
| 4504 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 4505 | // for shader-related entry points |
| 4506 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidNameCharacters); |
| 4507 | return false; |
| 4508 | } |
| 4509 | |
| 4510 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 4511 | { |
| 4512 | return false; |
| 4513 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4514 | } |
| 4515 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4516 | return GetValidProgram(context, program) != nullptr; |
| 4517 | } |
| 4518 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4519 | bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4520 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4521 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4522 | { |
Jamie Madill | a139f01 | 2018-10-10 16:13:03 -0400 | [diff] [blame] | 4523 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4524 | return false; |
| 4525 | } |
| 4526 | |
| 4527 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4528 | !context->isFramebufferGenerated(framebuffer)) |
| 4529 | { |
Jamie Madill | a139f01 | 2018-10-10 16:13:03 -0400 | [diff] [blame] | 4530 | context->validationError(GL_INVALID_OPERATION, kErrorObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4531 | return false; |
| 4532 | } |
| 4533 | |
| 4534 | return true; |
| 4535 | } |
| 4536 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4537 | bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4538 | { |
| 4539 | if (target != GL_RENDERBUFFER) |
| 4540 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4541 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4542 | return false; |
| 4543 | } |
| 4544 | |
| 4545 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4546 | !context->isRenderbufferGenerated(renderbuffer)) |
| 4547 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4548 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4549 | return false; |
| 4550 | } |
| 4551 | |
| 4552 | return true; |
| 4553 | } |
| 4554 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4555 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4556 | { |
| 4557 | switch (mode) |
| 4558 | { |
| 4559 | case GL_FUNC_ADD: |
| 4560 | case GL_FUNC_SUBTRACT: |
| 4561 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4562 | return true; |
| 4563 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4564 | case GL_MIN: |
| 4565 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4566 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4567 | |
| 4568 | default: |
| 4569 | return false; |
| 4570 | } |
| 4571 | } |
| 4572 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4573 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4574 | { |
| 4575 | return true; |
| 4576 | } |
| 4577 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4578 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4579 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4580 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4581 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4582 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4583 | return false; |
| 4584 | } |
| 4585 | |
| 4586 | return true; |
| 4587 | } |
| 4588 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4589 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4590 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4591 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4592 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4593 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4594 | return false; |
| 4595 | } |
| 4596 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4597 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4598 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4599 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4600 | return false; |
| 4601 | } |
| 4602 | |
| 4603 | return true; |
| 4604 | } |
| 4605 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4606 | bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4607 | { |
| 4608 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 4609 | } |
| 4610 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4611 | bool ValidateBlendFuncSeparate(Context *context, |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4612 | GLenum srcRGB, |
| 4613 | GLenum dstRGB, |
| 4614 | GLenum srcAlpha, |
| 4615 | GLenum dstAlpha) |
| 4616 | { |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4617 | if (!ValidSrcBlendFunc(context, srcRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4618 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4619 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4620 | return false; |
| 4621 | } |
| 4622 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4623 | if (!ValidDstBlendFunc(context, dstRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4624 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4625 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4626 | return false; |
| 4627 | } |
| 4628 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4629 | if (!ValidSrcBlendFunc(context, srcAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4630 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4631 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4632 | return false; |
| 4633 | } |
| 4634 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4635 | if (!ValidDstBlendFunc(context, dstAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4636 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4637 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4638 | return false; |
| 4639 | } |
| 4640 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4641 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 4642 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4643 | { |
| 4644 | bool constantColorUsed = |
| 4645 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 4646 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 4647 | |
| 4648 | bool constantAlphaUsed = |
| 4649 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 4650 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 4651 | |
| 4652 | if (constantColorUsed && constantAlphaUsed) |
| 4653 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4654 | const char *msg; |
| 4655 | if (context->getExtensions().webglCompatibility) |
| 4656 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4657 | msg = kErrorInvalidConstantColor; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4658 | } |
| 4659 | else |
| 4660 | { |
| 4661 | msg = |
| 4662 | "Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and " |
| 4663 | "GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR not supported by this " |
| 4664 | "implementation."; |
Jamie Madill | a2f043d | 2018-07-10 17:21:20 -0400 | [diff] [blame] | 4665 | WARN() << msg; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4666 | } |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4667 | context->handleError(InvalidOperation() << msg); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4668 | return false; |
| 4669 | } |
| 4670 | } |
| 4671 | |
| 4672 | return true; |
| 4673 | } |
| 4674 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4675 | bool ValidateGetString(Context *context, GLenum name) |
| 4676 | { |
| 4677 | switch (name) |
| 4678 | { |
| 4679 | case GL_VENDOR: |
| 4680 | case GL_RENDERER: |
| 4681 | case GL_VERSION: |
| 4682 | case GL_SHADING_LANGUAGE_VERSION: |
| 4683 | case GL_EXTENSIONS: |
| 4684 | break; |
| 4685 | |
| 4686 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 4687 | if (!context->getExtensions().requestExtension) |
| 4688 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4689 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4690 | return false; |
| 4691 | } |
| 4692 | break; |
| 4693 | |
| 4694 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4695 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4696 | return false; |
| 4697 | } |
| 4698 | |
| 4699 | return true; |
| 4700 | } |
| 4701 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4702 | bool ValidateLineWidth(Context *context, GLfloat width) |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4703 | { |
| 4704 | if (width <= 0.0f || isNaN(width)) |
| 4705 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4706 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidWidth); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4707 | return false; |
| 4708 | } |
| 4709 | |
| 4710 | return true; |
| 4711 | } |
| 4712 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4713 | bool ValidateVertexAttribPointer(Context *context, |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4714 | GLuint index, |
| 4715 | GLint size, |
| 4716 | GLenum type, |
| 4717 | GLboolean normalized, |
| 4718 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4719 | const void *ptr) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4720 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4721 | if (!ValidateVertexFormatBase(context, index, size, type, false)) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4722 | { |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4723 | return false; |
| 4724 | } |
| 4725 | |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4726 | if (stride < 0) |
| 4727 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4728 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStride); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4729 | return false; |
| 4730 | } |
| 4731 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4732 | const Caps &caps = context->getCaps(); |
| 4733 | if (context->getClientVersion() >= ES_3_1) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4734 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4735 | if (stride > caps.maxVertexAttribStride) |
| 4736 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4737 | context->handleError(InvalidValue() |
| 4738 | << "stride cannot be greater than MAX_VERTEX_ATTRIB_STRIDE."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4739 | return false; |
| 4740 | } |
| 4741 | |
| 4742 | if (index >= caps.maxVertexAttribBindings) |
| 4743 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4744 | context->handleError(InvalidValue() |
| 4745 | << "index must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4746 | return false; |
| 4747 | } |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4748 | } |
| 4749 | |
| 4750 | // [OpenGL ES 3.0.2] Section 2.8 page 24: |
| 4751 | // An INVALID_OPERATION error is generated when a non-zero vertex array object |
| 4752 | // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point, |
| 4753 | // and the pointer argument is not NULL. |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 4754 | bool nullBufferAllowed = context->getGLState().areClientArraysEnabled() && |
| 4755 | context->getGLState().getVertexArray()->id() == 0; |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4756 | if (!nullBufferAllowed && context->getGLState().getTargetBuffer(BufferBinding::Array) == 0 && |
| 4757 | ptr != nullptr) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4758 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4759 | context |
| 4760 | ->handleError(InvalidOperation() |
| 4761 | << "Client data cannot be used with a non-default vertex array object."); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4762 | return false; |
| 4763 | } |
| 4764 | |
| 4765 | if (context->getExtensions().webglCompatibility) |
| 4766 | { |
| 4767 | // WebGL 1.0 [Section 6.14] Fixed point support |
| 4768 | // The WebGL API does not support the GL_FIXED data type. |
| 4769 | if (type == GL_FIXED) |
| 4770 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4771 | context->handleError(InvalidEnum() << "GL_FIXED is not supported in WebGL."); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4772 | return false; |
| 4773 | } |
| 4774 | |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 4775 | if (!ValidateWebGLVertexAttribPointer(context, type, normalized, stride, ptr, false)) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4776 | { |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4777 | return false; |
| 4778 | } |
| 4779 | } |
| 4780 | |
| 4781 | return true; |
| 4782 | } |
| 4783 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4784 | bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4785 | { |
| 4786 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 4787 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4788 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDepthRange); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4789 | return false; |
| 4790 | } |
| 4791 | |
| 4792 | return true; |
| 4793 | } |
| 4794 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4795 | bool ValidateRenderbufferStorage(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4796 | GLenum target, |
| 4797 | GLenum internalformat, |
| 4798 | GLsizei width, |
| 4799 | GLsizei height) |
| 4800 | { |
| 4801 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 4802 | height); |
| 4803 | } |
| 4804 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4805 | bool ValidateRenderbufferStorageMultisampleANGLE(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4806 | GLenum target, |
| 4807 | GLsizei samples, |
| 4808 | GLenum internalformat, |
| 4809 | GLsizei width, |
| 4810 | GLsizei height) |
| 4811 | { |
| 4812 | if (!context->getExtensions().framebufferMultisample) |
| 4813 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4814 | context->handleError(InvalidOperation() |
| 4815 | << "GL_ANGLE_framebuffer_multisample not available"); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4816 | return false; |
| 4817 | } |
| 4818 | |
| 4819 | // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal |
| 4820 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_OPERATION is |
| 4821 | // generated. |
| 4822 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 4823 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4824 | context->handleError(InvalidValue()); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4825 | return false; |
| 4826 | } |
| 4827 | |
| 4828 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 4829 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 4830 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 4831 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 4832 | if (context->getClientMajorVersion() >= 3) |
| 4833 | { |
| 4834 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 4835 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 4836 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4837 | context->handleError(OutOfMemory()); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4838 | return false; |
| 4839 | } |
| 4840 | } |
| 4841 | |
| 4842 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 4843 | width, height); |
| 4844 | } |
| 4845 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4846 | bool ValidateCheckFramebufferStatus(Context *context, GLenum target) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4847 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4848 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4849 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4850 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4851 | return false; |
| 4852 | } |
| 4853 | |
| 4854 | return true; |
| 4855 | } |
| 4856 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4857 | bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4858 | { |
| 4859 | return true; |
| 4860 | } |
| 4861 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4862 | bool ValidateClearDepthf(Context *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4863 | { |
| 4864 | return true; |
| 4865 | } |
| 4866 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4867 | bool ValidateClearStencil(Context *context, GLint s) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4868 | { |
| 4869 | return true; |
| 4870 | } |
| 4871 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4872 | bool ValidateColorMask(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4873 | GLboolean red, |
| 4874 | GLboolean green, |
| 4875 | GLboolean blue, |
| 4876 | GLboolean alpha) |
| 4877 | { |
| 4878 | return true; |
| 4879 | } |
| 4880 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4881 | bool ValidateCompileShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4882 | { |
| 4883 | return true; |
| 4884 | } |
| 4885 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4886 | bool ValidateCreateProgram(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4887 | { |
| 4888 | return true; |
| 4889 | } |
| 4890 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4891 | bool ValidateCullFace(Context *context, CullFaceMode mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4892 | { |
| 4893 | switch (mode) |
| 4894 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4895 | case CullFaceMode::Front: |
| 4896 | case CullFaceMode::Back: |
| 4897 | case CullFaceMode::FrontAndBack: |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4898 | break; |
| 4899 | |
| 4900 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4901 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCullMode); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4902 | return false; |
| 4903 | } |
| 4904 | |
| 4905 | return true; |
| 4906 | } |
| 4907 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4908 | bool ValidateDeleteProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4909 | { |
| 4910 | if (program == 0) |
| 4911 | { |
| 4912 | return false; |
| 4913 | } |
| 4914 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4915 | if (!context->getProgramResolveLink(program)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4916 | { |
| 4917 | if (context->getShader(program)) |
| 4918 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4919 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4920 | return false; |
| 4921 | } |
| 4922 | else |
| 4923 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4924 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4925 | return false; |
| 4926 | } |
| 4927 | } |
| 4928 | |
| 4929 | return true; |
| 4930 | } |
| 4931 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4932 | bool ValidateDeleteShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4933 | { |
| 4934 | if (shader == 0) |
| 4935 | { |
| 4936 | return false; |
| 4937 | } |
| 4938 | |
| 4939 | if (!context->getShader(shader)) |
| 4940 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4941 | if (context->getProgramResolveLink(shader)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4942 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4943 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4944 | return false; |
| 4945 | } |
| 4946 | else |
| 4947 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4948 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ExpectedShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4949 | return false; |
| 4950 | } |
| 4951 | } |
| 4952 | |
| 4953 | return true; |
| 4954 | } |
| 4955 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4956 | bool ValidateDepthFunc(Context *context, GLenum func) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4957 | { |
| 4958 | switch (func) |
| 4959 | { |
| 4960 | case GL_NEVER: |
| 4961 | case GL_ALWAYS: |
| 4962 | case GL_LESS: |
| 4963 | case GL_LEQUAL: |
| 4964 | case GL_EQUAL: |
| 4965 | case GL_GREATER: |
| 4966 | case GL_GEQUAL: |
| 4967 | case GL_NOTEQUAL: |
| 4968 | break; |
| 4969 | |
| 4970 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4971 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4972 | return false; |
| 4973 | } |
| 4974 | |
| 4975 | return true; |
| 4976 | } |
| 4977 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4978 | bool ValidateDepthMask(Context *context, GLboolean flag) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4979 | { |
| 4980 | return true; |
| 4981 | } |
| 4982 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4983 | bool ValidateDetachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4984 | { |
| 4985 | Program *programObject = GetValidProgram(context, program); |
| 4986 | if (!programObject) |
| 4987 | { |
| 4988 | return false; |
| 4989 | } |
| 4990 | |
| 4991 | Shader *shaderObject = GetValidShader(context, shader); |
| 4992 | if (!shaderObject) |
| 4993 | { |
| 4994 | return false; |
| 4995 | } |
| 4996 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4997 | const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4998 | if (attachedShader != shaderObject) |
| 4999 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5000 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ShaderToDetachMustBeAttached); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5001 | return false; |
| 5002 | } |
| 5003 | |
| 5004 | return true; |
| 5005 | } |
| 5006 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5007 | bool ValidateDisableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5008 | { |
| 5009 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5010 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5011 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5012 | return false; |
| 5013 | } |
| 5014 | |
| 5015 | return true; |
| 5016 | } |
| 5017 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5018 | bool ValidateEnableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5019 | { |
| 5020 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5021 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5022 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5023 | return false; |
| 5024 | } |
| 5025 | |
| 5026 | return true; |
| 5027 | } |
| 5028 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5029 | bool ValidateFinish(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5030 | { |
| 5031 | return true; |
| 5032 | } |
| 5033 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5034 | bool ValidateFlush(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5035 | { |
| 5036 | return true; |
| 5037 | } |
| 5038 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5039 | bool ValidateFrontFace(Context *context, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5040 | { |
| 5041 | switch (mode) |
| 5042 | { |
| 5043 | case GL_CW: |
| 5044 | case GL_CCW: |
| 5045 | break; |
| 5046 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5047 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5048 | return false; |
| 5049 | } |
| 5050 | |
| 5051 | return true; |
| 5052 | } |
| 5053 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5054 | bool ValidateGetActiveAttrib(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5055 | GLuint program, |
| 5056 | GLuint index, |
| 5057 | GLsizei bufsize, |
| 5058 | GLsizei *length, |
| 5059 | GLint *size, |
| 5060 | GLenum *type, |
| 5061 | GLchar *name) |
| 5062 | { |
| 5063 | if (bufsize < 0) |
| 5064 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5065 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5066 | return false; |
| 5067 | } |
| 5068 | |
| 5069 | Program *programObject = GetValidProgram(context, program); |
| 5070 | |
| 5071 | if (!programObject) |
| 5072 | { |
| 5073 | return false; |
| 5074 | } |
| 5075 | |
| 5076 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 5077 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5078 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5079 | return false; |
| 5080 | } |
| 5081 | |
| 5082 | return true; |
| 5083 | } |
| 5084 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5085 | bool ValidateGetActiveUniform(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5086 | GLuint program, |
| 5087 | GLuint index, |
| 5088 | GLsizei bufsize, |
| 5089 | GLsizei *length, |
| 5090 | GLint *size, |
| 5091 | GLenum *type, |
| 5092 | GLchar *name) |
| 5093 | { |
| 5094 | if (bufsize < 0) |
| 5095 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5096 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5097 | return false; |
| 5098 | } |
| 5099 | |
| 5100 | Program *programObject = GetValidProgram(context, program); |
| 5101 | |
| 5102 | if (!programObject) |
| 5103 | { |
| 5104 | return false; |
| 5105 | } |
| 5106 | |
| 5107 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 5108 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5109 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5110 | return false; |
| 5111 | } |
| 5112 | |
| 5113 | return true; |
| 5114 | } |
| 5115 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5116 | bool ValidateGetAttachedShaders(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5117 | GLuint program, |
| 5118 | GLsizei maxcount, |
| 5119 | GLsizei *count, |
| 5120 | GLuint *shaders) |
| 5121 | { |
| 5122 | if (maxcount < 0) |
| 5123 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5124 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeMaxCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5125 | return false; |
| 5126 | } |
| 5127 | |
| 5128 | Program *programObject = GetValidProgram(context, program); |
| 5129 | |
| 5130 | if (!programObject) |
| 5131 | { |
| 5132 | return false; |
| 5133 | } |
| 5134 | |
| 5135 | return true; |
| 5136 | } |
| 5137 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5138 | bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5139 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5140 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5141 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5142 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5143 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5144 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5145 | return false; |
| 5146 | } |
| 5147 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5148 | Program *programObject = GetValidProgram(context, program); |
| 5149 | |
| 5150 | if (!programObject) |
| 5151 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5152 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotBound); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5153 | return false; |
| 5154 | } |
| 5155 | |
| 5156 | if (!programObject->isLinked()) |
| 5157 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5158 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5159 | return false; |
| 5160 | } |
| 5161 | |
| 5162 | return true; |
| 5163 | } |
| 5164 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5165 | bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5166 | { |
| 5167 | GLenum nativeType; |
| 5168 | unsigned int numParams = 0; |
| 5169 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5170 | } |
| 5171 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5172 | bool ValidateGetError(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5173 | { |
| 5174 | return true; |
| 5175 | } |
| 5176 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5177 | bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5178 | { |
| 5179 | GLenum nativeType; |
| 5180 | unsigned int numParams = 0; |
| 5181 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5182 | } |
| 5183 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5184 | bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5185 | { |
| 5186 | GLenum nativeType; |
| 5187 | unsigned int numParams = 0; |
| 5188 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5189 | } |
| 5190 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5191 | bool ValidateGetProgramInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5192 | GLuint program, |
| 5193 | GLsizei bufsize, |
| 5194 | GLsizei *length, |
| 5195 | GLchar *infolog) |
| 5196 | { |
| 5197 | if (bufsize < 0) |
| 5198 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5199 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5200 | return false; |
| 5201 | } |
| 5202 | |
| 5203 | Program *programObject = GetValidProgram(context, program); |
| 5204 | if (!programObject) |
| 5205 | { |
| 5206 | return false; |
| 5207 | } |
| 5208 | |
| 5209 | return true; |
| 5210 | } |
| 5211 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5212 | bool ValidateGetShaderInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5213 | GLuint shader, |
| 5214 | GLsizei bufsize, |
| 5215 | GLsizei *length, |
| 5216 | GLchar *infolog) |
| 5217 | { |
| 5218 | if (bufsize < 0) |
| 5219 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5220 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5221 | return false; |
| 5222 | } |
| 5223 | |
| 5224 | Shader *shaderObject = GetValidShader(context, shader); |
| 5225 | if (!shaderObject) |
| 5226 | { |
| 5227 | return false; |
| 5228 | } |
| 5229 | |
| 5230 | return true; |
| 5231 | } |
| 5232 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5233 | bool ValidateGetShaderPrecisionFormat(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5234 | GLenum shadertype, |
| 5235 | GLenum precisiontype, |
| 5236 | GLint *range, |
| 5237 | GLint *precision) |
| 5238 | { |
| 5239 | switch (shadertype) |
| 5240 | { |
| 5241 | case GL_VERTEX_SHADER: |
| 5242 | case GL_FRAGMENT_SHADER: |
| 5243 | break; |
| 5244 | case GL_COMPUTE_SHADER: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5245 | context->handleError(InvalidOperation() |
| 5246 | << "compute shader precision not yet implemented."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5247 | return false; |
| 5248 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5249 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidShaderType); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5250 | return false; |
| 5251 | } |
| 5252 | |
| 5253 | switch (precisiontype) |
| 5254 | { |
| 5255 | case GL_LOW_FLOAT: |
| 5256 | case GL_MEDIUM_FLOAT: |
| 5257 | case GL_HIGH_FLOAT: |
| 5258 | case GL_LOW_INT: |
| 5259 | case GL_MEDIUM_INT: |
| 5260 | case GL_HIGH_INT: |
| 5261 | break; |
| 5262 | |
| 5263 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5264 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5265 | return false; |
| 5266 | } |
| 5267 | |
| 5268 | return true; |
| 5269 | } |
| 5270 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5271 | bool ValidateGetShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5272 | GLuint shader, |
| 5273 | GLsizei bufsize, |
| 5274 | GLsizei *length, |
| 5275 | GLchar *source) |
| 5276 | { |
| 5277 | if (bufsize < 0) |
| 5278 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5279 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5280 | return false; |
| 5281 | } |
| 5282 | |
| 5283 | Shader *shaderObject = GetValidShader(context, shader); |
| 5284 | if (!shaderObject) |
| 5285 | { |
| 5286 | return false; |
| 5287 | } |
| 5288 | |
| 5289 | return true; |
| 5290 | } |
| 5291 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5292 | bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5293 | { |
| 5294 | if (strstr(name, "gl_") == name) |
| 5295 | { |
| 5296 | return false; |
| 5297 | } |
| 5298 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5299 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5300 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5301 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5302 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5303 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5304 | return false; |
| 5305 | } |
| 5306 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5307 | Program *programObject = GetValidProgram(context, program); |
| 5308 | |
| 5309 | if (!programObject) |
| 5310 | { |
| 5311 | return false; |
| 5312 | } |
| 5313 | |
| 5314 | if (!programObject->isLinked()) |
| 5315 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5316 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5317 | return false; |
| 5318 | } |
| 5319 | |
| 5320 | return true; |
| 5321 | } |
| 5322 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5323 | bool ValidateHint(Context *context, GLenum target, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5324 | { |
| 5325 | switch (mode) |
| 5326 | { |
| 5327 | case GL_FASTEST: |
| 5328 | case GL_NICEST: |
| 5329 | case GL_DONT_CARE: |
| 5330 | break; |
| 5331 | |
| 5332 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5333 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5334 | return false; |
| 5335 | } |
| 5336 | |
| 5337 | switch (target) |
| 5338 | { |
| 5339 | case GL_GENERATE_MIPMAP_HINT: |
| 5340 | break; |
| 5341 | |
Geoff Lang | e7bd218 | 2017-06-16 16:13:13 -0400 | [diff] [blame] | 5342 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: |
| 5343 | if (context->getClientVersion() < ES_3_0 && |
| 5344 | !context->getExtensions().standardDerivatives) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5345 | { |
Brandon Jones | 72f58fa | 2017-09-19 10:47:41 -0700 | [diff] [blame] | 5346 | context->handleError(InvalidEnum() << "hint requires OES_standard_derivatives."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5347 | return false; |
| 5348 | } |
| 5349 | break; |
| 5350 | |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5351 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 5352 | case GL_POINT_SMOOTH_HINT: |
| 5353 | case GL_LINE_SMOOTH_HINT: |
| 5354 | case GL_FOG_HINT: |
| 5355 | if (context->getClientMajorVersion() >= 2) |
| 5356 | { |
| 5357 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5358 | return false; |
| 5359 | } |
| 5360 | break; |
| 5361 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5362 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5363 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5364 | return false; |
| 5365 | } |
| 5366 | |
| 5367 | return true; |
| 5368 | } |
| 5369 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5370 | bool ValidateIsBuffer(Context *context, GLuint buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5371 | { |
| 5372 | return true; |
| 5373 | } |
| 5374 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5375 | bool ValidateIsFramebuffer(Context *context, GLuint framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5376 | { |
| 5377 | return true; |
| 5378 | } |
| 5379 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5380 | bool ValidateIsProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5381 | { |
| 5382 | return true; |
| 5383 | } |
| 5384 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5385 | bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5386 | { |
| 5387 | return true; |
| 5388 | } |
| 5389 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5390 | bool ValidateIsShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5391 | { |
| 5392 | return true; |
| 5393 | } |
| 5394 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5395 | bool ValidateIsTexture(Context *context, GLuint texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5396 | { |
| 5397 | return true; |
| 5398 | } |
| 5399 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5400 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5401 | { |
| 5402 | if (context->getClientMajorVersion() < 3) |
| 5403 | { |
| 5404 | switch (pname) |
| 5405 | { |
| 5406 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5407 | case GL_UNPACK_SKIP_IMAGES: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5408 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5409 | return false; |
| 5410 | |
| 5411 | case GL_UNPACK_ROW_LENGTH: |
| 5412 | case GL_UNPACK_SKIP_ROWS: |
| 5413 | case GL_UNPACK_SKIP_PIXELS: |
| 5414 | if (!context->getExtensions().unpackSubimage) |
| 5415 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5416 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5417 | return false; |
| 5418 | } |
| 5419 | break; |
| 5420 | |
| 5421 | case GL_PACK_ROW_LENGTH: |
| 5422 | case GL_PACK_SKIP_ROWS: |
| 5423 | case GL_PACK_SKIP_PIXELS: |
| 5424 | if (!context->getExtensions().packSubimage) |
| 5425 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5426 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5427 | return false; |
| 5428 | } |
| 5429 | break; |
| 5430 | } |
| 5431 | } |
| 5432 | |
| 5433 | if (param < 0) |
| 5434 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5435 | context->handleError(InvalidValue() << "Cannot use negative values in PixelStorei"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5436 | return false; |
| 5437 | } |
| 5438 | |
| 5439 | switch (pname) |
| 5440 | { |
| 5441 | case GL_UNPACK_ALIGNMENT: |
| 5442 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5443 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5444 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5445 | return false; |
| 5446 | } |
| 5447 | break; |
| 5448 | |
| 5449 | case GL_PACK_ALIGNMENT: |
| 5450 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5451 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5452 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5453 | return false; |
| 5454 | } |
| 5455 | break; |
| 5456 | |
| 5457 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5458 | if (!context->getExtensions().packReverseRowOrder) |
| 5459 | { |
| 5460 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5461 | } |
| 5462 | break; |
| 5463 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5464 | case GL_UNPACK_ROW_LENGTH: |
| 5465 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5466 | case GL_UNPACK_SKIP_IMAGES: |
| 5467 | case GL_UNPACK_SKIP_ROWS: |
| 5468 | case GL_UNPACK_SKIP_PIXELS: |
| 5469 | case GL_PACK_ROW_LENGTH: |
| 5470 | case GL_PACK_SKIP_ROWS: |
| 5471 | case GL_PACK_SKIP_PIXELS: |
| 5472 | break; |
| 5473 | |
| 5474 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5475 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5476 | return false; |
| 5477 | } |
| 5478 | |
| 5479 | return true; |
| 5480 | } |
| 5481 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5482 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5483 | { |
| 5484 | return true; |
| 5485 | } |
| 5486 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5487 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5488 | { |
| 5489 | return true; |
| 5490 | } |
| 5491 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5492 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5493 | { |
| 5494 | return true; |
| 5495 | } |
| 5496 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5497 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5498 | { |
| 5499 | if (width < 0 || height < 0) |
| 5500 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5501 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5502 | return false; |
| 5503 | } |
| 5504 | |
| 5505 | return true; |
| 5506 | } |
| 5507 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5508 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5509 | GLsizei n, |
| 5510 | const GLuint *shaders, |
| 5511 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5512 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5513 | GLsizei length) |
| 5514 | { |
| 5515 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5516 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5517 | shaderBinaryFormats.end()) |
| 5518 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5519 | context->handleError(InvalidEnum() << "Invalid shader binary format."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5520 | return false; |
| 5521 | } |
| 5522 | |
| 5523 | return true; |
| 5524 | } |
| 5525 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5526 | bool ValidateShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5527 | GLuint shader, |
| 5528 | GLsizei count, |
| 5529 | const GLchar *const *string, |
| 5530 | const GLint *length) |
| 5531 | { |
| 5532 | if (count < 0) |
| 5533 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5534 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5535 | return false; |
| 5536 | } |
| 5537 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5538 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5539 | // shader-related entry points |
| 5540 | if (context->getExtensions().webglCompatibility) |
| 5541 | { |
| 5542 | for (GLsizei i = 0; i < count; i++) |
| 5543 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5544 | size_t len = |
| 5545 | (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] | 5546 | |
| 5547 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5548 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 5549 | context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5550 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5551 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5552 | return false; |
| 5553 | } |
| 5554 | } |
| 5555 | } |
| 5556 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5557 | Shader *shaderObject = GetValidShader(context, shader); |
| 5558 | if (!shaderObject) |
| 5559 | { |
| 5560 | return false; |
| 5561 | } |
| 5562 | |
| 5563 | return true; |
| 5564 | } |
| 5565 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5566 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5567 | { |
| 5568 | if (!IsValidStencilFunc(func)) |
| 5569 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5570 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5571 | return false; |
| 5572 | } |
| 5573 | |
| 5574 | return true; |
| 5575 | } |
| 5576 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5577 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5578 | { |
| 5579 | if (!IsValidStencilFace(face)) |
| 5580 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5581 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5582 | return false; |
| 5583 | } |
| 5584 | |
| 5585 | if (!IsValidStencilFunc(func)) |
| 5586 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5587 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5588 | return false; |
| 5589 | } |
| 5590 | |
| 5591 | return true; |
| 5592 | } |
| 5593 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5594 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5595 | { |
| 5596 | return true; |
| 5597 | } |
| 5598 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5599 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5600 | { |
| 5601 | if (!IsValidStencilFace(face)) |
| 5602 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5603 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5604 | return false; |
| 5605 | } |
| 5606 | |
| 5607 | return true; |
| 5608 | } |
| 5609 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5610 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5611 | { |
| 5612 | if (!IsValidStencilOp(fail)) |
| 5613 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5614 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5615 | return false; |
| 5616 | } |
| 5617 | |
| 5618 | if (!IsValidStencilOp(zfail)) |
| 5619 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5620 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5621 | return false; |
| 5622 | } |
| 5623 | |
| 5624 | if (!IsValidStencilOp(zpass)) |
| 5625 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5626 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5627 | return false; |
| 5628 | } |
| 5629 | |
| 5630 | return true; |
| 5631 | } |
| 5632 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5633 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5634 | GLenum face, |
| 5635 | GLenum fail, |
| 5636 | GLenum zfail, |
| 5637 | GLenum zpass) |
| 5638 | { |
| 5639 | if (!IsValidStencilFace(face)) |
| 5640 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5641 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5642 | return false; |
| 5643 | } |
| 5644 | |
| 5645 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 5646 | } |
| 5647 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5648 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5649 | { |
| 5650 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 5651 | } |
| 5652 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5653 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5654 | { |
| 5655 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 5656 | } |
| 5657 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5658 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5659 | { |
| 5660 | return ValidateUniform1iv(context, location, 1, &x); |
| 5661 | } |
| 5662 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5663 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5664 | { |
| 5665 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 5666 | } |
| 5667 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5668 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5669 | { |
| 5670 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 5671 | } |
| 5672 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5673 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5674 | { |
| 5675 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 5676 | } |
| 5677 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5678 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5679 | { |
| 5680 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 5681 | } |
| 5682 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5683 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5684 | { |
| 5685 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 5686 | } |
| 5687 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5688 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5689 | { |
| 5690 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 5691 | } |
| 5692 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5693 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5694 | { |
| 5695 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 5696 | } |
| 5697 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5698 | bool ValidateUniform4f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5699 | { |
| 5700 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 5701 | } |
| 5702 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5703 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5704 | { |
| 5705 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 5706 | } |
| 5707 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5708 | bool ValidateUniform4i(Context *context, GLint location, GLint x, GLint y, GLint z, GLint w) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5709 | { |
| 5710 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 5711 | } |
| 5712 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5713 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5714 | { |
| 5715 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 5716 | } |
| 5717 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5718 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5719 | GLint location, |
| 5720 | GLsizei count, |
| 5721 | GLboolean transpose, |
| 5722 | const GLfloat *value) |
| 5723 | { |
| 5724 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 5725 | } |
| 5726 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5727 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5728 | GLint location, |
| 5729 | GLsizei count, |
| 5730 | GLboolean transpose, |
| 5731 | const GLfloat *value) |
| 5732 | { |
| 5733 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 5734 | } |
| 5735 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5736 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5737 | GLint location, |
| 5738 | GLsizei count, |
| 5739 | GLboolean transpose, |
| 5740 | const GLfloat *value) |
| 5741 | { |
| 5742 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 5743 | } |
| 5744 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5745 | bool ValidateValidateProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5746 | { |
| 5747 | Program *programObject = GetValidProgram(context, program); |
| 5748 | |
| 5749 | if (!programObject) |
| 5750 | { |
| 5751 | return false; |
| 5752 | } |
| 5753 | |
| 5754 | return true; |
| 5755 | } |
| 5756 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5757 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5758 | { |
| 5759 | return ValidateVertexAttribIndex(context, index); |
| 5760 | } |
| 5761 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5762 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5763 | { |
| 5764 | return ValidateVertexAttribIndex(context, index); |
| 5765 | } |
| 5766 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5767 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5768 | { |
| 5769 | return ValidateVertexAttribIndex(context, index); |
| 5770 | } |
| 5771 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5772 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5773 | { |
| 5774 | return ValidateVertexAttribIndex(context, index); |
| 5775 | } |
| 5776 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5777 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5778 | { |
| 5779 | return ValidateVertexAttribIndex(context, index); |
| 5780 | } |
| 5781 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5782 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5783 | { |
| 5784 | return ValidateVertexAttribIndex(context, index); |
| 5785 | } |
| 5786 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5787 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5788 | GLuint index, |
| 5789 | GLfloat x, |
| 5790 | GLfloat y, |
| 5791 | GLfloat z, |
| 5792 | GLfloat w) |
| 5793 | { |
| 5794 | return ValidateVertexAttribIndex(context, index); |
| 5795 | } |
| 5796 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5797 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5798 | { |
| 5799 | return ValidateVertexAttribIndex(context, index); |
| 5800 | } |
| 5801 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5802 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5803 | { |
| 5804 | if (width < 0 || height < 0) |
| 5805 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5806 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5807 | return false; |
| 5808 | } |
| 5809 | |
| 5810 | return true; |
| 5811 | } |
| 5812 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5813 | bool ValidateDrawElements(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 5814 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5815 | GLsizei count, |
| 5816 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5817 | const void *indices) |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5818 | { |
| 5819 | return ValidateDrawElementsCommon(context, mode, count, type, indices, 1); |
| 5820 | } |
| 5821 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 5822 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5823 | GLenum target, |
| 5824 | GLenum attachment, |
| 5825 | GLenum pname, |
| 5826 | GLint *params) |
| 5827 | { |
| 5828 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 5829 | nullptr); |
| 5830 | } |
| 5831 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5832 | bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5833 | { |
| 5834 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 5835 | } |
| 5836 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5837 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5838 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5839 | GLint level, |
| 5840 | GLenum internalformat, |
| 5841 | GLint x, |
| 5842 | GLint y, |
| 5843 | GLsizei width, |
| 5844 | GLsizei height, |
| 5845 | GLint border) |
| 5846 | { |
| 5847 | if (context->getClientMajorVersion() < 3) |
| 5848 | { |
| 5849 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 5850 | 0, x, y, width, height, border); |
| 5851 | } |
| 5852 | |
| 5853 | ASSERT(context->getClientMajorVersion() == 3); |
| 5854 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 5855 | 0, x, y, width, height, border); |
| 5856 | } |
| 5857 | |
| 5858 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5859 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5860 | GLint level, |
| 5861 | GLint xoffset, |
| 5862 | GLint yoffset, |
| 5863 | GLint x, |
| 5864 | GLint y, |
| 5865 | GLsizei width, |
| 5866 | GLsizei height) |
| 5867 | { |
| 5868 | if (context->getClientMajorVersion() < 3) |
| 5869 | { |
| 5870 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 5871 | yoffset, x, y, width, height, 0); |
| 5872 | } |
| 5873 | |
| 5874 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 5875 | yoffset, 0, x, y, width, height, 0); |
| 5876 | } |
| 5877 | |
| 5878 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 5879 | { |
| 5880 | return ValidateGenOrDelete(context, n); |
| 5881 | } |
| 5882 | |
| 5883 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 5884 | { |
| 5885 | return ValidateGenOrDelete(context, n); |
| 5886 | } |
| 5887 | |
| 5888 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 5889 | { |
| 5890 | return ValidateGenOrDelete(context, n); |
| 5891 | } |
| 5892 | |
| 5893 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 5894 | { |
| 5895 | return ValidateGenOrDelete(context, n); |
| 5896 | } |
| 5897 | |
| 5898 | bool ValidateDisable(Context *context, GLenum cap) |
| 5899 | { |
| 5900 | if (!ValidCap(context, cap, false)) |
| 5901 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5902 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5903 | return false; |
| 5904 | } |
| 5905 | |
| 5906 | return true; |
| 5907 | } |
| 5908 | |
| 5909 | bool ValidateEnable(Context *context, GLenum cap) |
| 5910 | { |
| 5911 | if (!ValidCap(context, cap, false)) |
| 5912 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5913 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5914 | return false; |
| 5915 | } |
| 5916 | |
| 5917 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 5918 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 5919 | { |
| 5920 | const char *errorMessage = "Current renderer doesn't support alpha-to-coverage"; |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5921 | context->handleError(InvalidOperation() << errorMessage); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5922 | |
| 5923 | // We also output an error message to the debugger window if tracing is active, so that |
| 5924 | // developers can see the error message. |
| 5925 | ERR() << errorMessage; |
| 5926 | return false; |
| 5927 | } |
| 5928 | |
| 5929 | return true; |
| 5930 | } |
| 5931 | |
| 5932 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 5933 | GLenum target, |
| 5934 | GLenum attachment, |
| 5935 | GLenum renderbuffertarget, |
| 5936 | GLuint renderbuffer) |
| 5937 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5938 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5939 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5940 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
| 5941 | return false; |
| 5942 | } |
| 5943 | |
| 5944 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0) |
| 5945 | { |
| 5946 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5947 | return false; |
| 5948 | } |
| 5949 | |
| 5950 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 5951 | renderbuffertarget, renderbuffer); |
| 5952 | } |
| 5953 | |
| 5954 | bool ValidateFramebufferTexture2D(Context *context, |
| 5955 | GLenum target, |
| 5956 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5957 | TextureTarget textarget, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5958 | GLuint texture, |
| 5959 | GLint level) |
| 5960 | { |
| 5961 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 5962 | // extension |
| 5963 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 5964 | level != 0) |
| 5965 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5966 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5967 | return false; |
| 5968 | } |
| 5969 | |
| 5970 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 5971 | { |
| 5972 | return false; |
| 5973 | } |
| 5974 | |
| 5975 | if (texture != 0) |
| 5976 | { |
| 5977 | gl::Texture *tex = context->getTexture(texture); |
| 5978 | ASSERT(tex); |
| 5979 | |
| 5980 | const gl::Caps &caps = context->getCaps(); |
| 5981 | |
| 5982 | switch (textarget) |
| 5983 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5984 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5985 | { |
| 5986 | if (level > gl::log2(caps.max2DTextureSize)) |
| 5987 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5988 | context->handleError(InvalidValue()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5989 | return false; |
| 5990 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 5991 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5992 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5993 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5994 | return false; |
| 5995 | } |
| 5996 | } |
| 5997 | break; |
| 5998 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5999 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6000 | { |
| 6001 | if (level != 0) |
| 6002 | { |
| 6003 | context->handleError(InvalidValue()); |
| 6004 | return false; |
| 6005 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6006 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6007 | { |
| 6008 | context->handleError(InvalidOperation() |
| 6009 | << "Textarget must match the texture target type."); |
| 6010 | return false; |
| 6011 | } |
| 6012 | } |
| 6013 | break; |
| 6014 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6015 | case TextureTarget::CubeMapNegativeX: |
| 6016 | case TextureTarget::CubeMapNegativeY: |
| 6017 | case TextureTarget::CubeMapNegativeZ: |
| 6018 | case TextureTarget::CubeMapPositiveX: |
| 6019 | case TextureTarget::CubeMapPositiveY: |
| 6020 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6021 | { |
| 6022 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 6023 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6024 | context->handleError(InvalidValue()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6025 | return false; |
| 6026 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6027 | if (tex->getType() != TextureType::CubeMap) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6028 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6029 | context->handleError(InvalidOperation() |
| 6030 | << "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6031 | return false; |
| 6032 | } |
| 6033 | } |
| 6034 | break; |
| 6035 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6036 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6037 | { |
| 6038 | if (context->getClientVersion() < ES_3_1) |
| 6039 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 6040 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6041 | return false; |
| 6042 | } |
| 6043 | |
| 6044 | if (level != 0) |
| 6045 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 6046 | ANGLE_VALIDATION_ERR(context, InvalidValue(), LevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6047 | return false; |
| 6048 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6049 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6050 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6051 | context->handleError(InvalidOperation() |
| 6052 | << "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6053 | return false; |
| 6054 | } |
| 6055 | } |
| 6056 | break; |
| 6057 | |
| 6058 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6059 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6060 | return false; |
| 6061 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | return true; |
| 6065 | } |
| 6066 | |
| 6067 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 6068 | { |
| 6069 | return ValidateGenOrDelete(context, n); |
| 6070 | } |
| 6071 | |
| 6072 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 6073 | { |
| 6074 | return ValidateGenOrDelete(context, n); |
| 6075 | } |
| 6076 | |
| 6077 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 6078 | { |
| 6079 | return ValidateGenOrDelete(context, n); |
| 6080 | } |
| 6081 | |
| 6082 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 6083 | { |
| 6084 | return ValidateGenOrDelete(context, n); |
| 6085 | } |
| 6086 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6087 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6088 | { |
| 6089 | if (!ValidTextureTarget(context, target)) |
| 6090 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6091 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6092 | return false; |
| 6093 | } |
| 6094 | |
| 6095 | Texture *texture = context->getTargetTexture(target); |
| 6096 | |
| 6097 | if (texture == nullptr) |
| 6098 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6099 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6100 | return false; |
| 6101 | } |
| 6102 | |
| 6103 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 6104 | |
| 6105 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 6106 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 6107 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 6108 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6109 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6110 | return false; |
| 6111 | } |
| 6112 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6113 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 6114 | ? TextureTarget::CubeMapPositiveX |
| 6115 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6116 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 6117 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 6118 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6119 | { |
| 6120 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed); |
| 6121 | return false; |
| 6122 | } |
| 6123 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6124 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 6125 | bool formatUnsized = !format.sized; |
| 6126 | bool formatColorRenderableAndFilterable = |
| 6127 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6128 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6129 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6130 | { |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6131 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6132 | return false; |
| 6133 | } |
| 6134 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6135 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 6136 | // generation |
| 6137 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 6138 | { |
| 6139 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed); |
| 6140 | return false; |
| 6141 | } |
| 6142 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 6143 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 6144 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 6145 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6146 | { |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6147 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6148 | return false; |
| 6149 | } |
| 6150 | |
| 6151 | // Non-power of 2 ES2 check |
| 6152 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 6153 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 6154 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 6155 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6156 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 6157 | target == TextureType::CubeMap); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6158 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6159 | return false; |
| 6160 | } |
| 6161 | |
| 6162 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6163 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6164 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6165 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), CubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6166 | return false; |
| 6167 | } |
| 6168 | |
| 6169 | return true; |
| 6170 | } |
| 6171 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6172 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 6173 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6174 | GLenum pname, |
| 6175 | GLint *params) |
| 6176 | { |
| 6177 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 6178 | } |
| 6179 | |
| 6180 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6181 | GLenum target, |
| 6182 | GLenum pname, |
| 6183 | GLint *params) |
| 6184 | { |
| 6185 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6186 | } |
| 6187 | |
| 6188 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 6189 | { |
| 6190 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6191 | } |
| 6192 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6193 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6194 | { |
| 6195 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6196 | } |
| 6197 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6198 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6199 | { |
| 6200 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6201 | } |
| 6202 | |
| 6203 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
| 6204 | { |
| 6205 | return ValidateGetUniformBase(context, program, location); |
| 6206 | } |
| 6207 | |
| 6208 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
| 6209 | { |
| 6210 | return ValidateGetUniformBase(context, program, location); |
| 6211 | } |
| 6212 | |
| 6213 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6214 | { |
| 6215 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6216 | } |
| 6217 | |
| 6218 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6219 | { |
| 6220 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6221 | } |
| 6222 | |
| 6223 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6224 | { |
| 6225 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6226 | } |
| 6227 | |
| 6228 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6229 | { |
| 6230 | if (!ValidCap(context, cap, true)) |
| 6231 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6232 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6233 | return false; |
| 6234 | } |
| 6235 | |
| 6236 | return true; |
| 6237 | } |
| 6238 | |
| 6239 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 6240 | { |
| 6241 | if (context->hasActiveTransformFeedback(program)) |
| 6242 | { |
| 6243 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6244 | context->handleError(InvalidOperation() << "Cannot link program while program is " |
| 6245 | "associated with an active transform " |
| 6246 | "feedback object."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6247 | return false; |
| 6248 | } |
| 6249 | |
| 6250 | Program *programObject = GetValidProgram(context, program); |
| 6251 | if (!programObject) |
| 6252 | { |
| 6253 | return false; |
| 6254 | } |
| 6255 | |
| 6256 | return true; |
| 6257 | } |
| 6258 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6259 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6260 | GLint x, |
| 6261 | GLint y, |
| 6262 | GLsizei width, |
| 6263 | GLsizei height, |
| 6264 | GLenum format, |
| 6265 | GLenum type, |
| 6266 | void *pixels) |
| 6267 | { |
| 6268 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6269 | nullptr, pixels); |
| 6270 | } |
| 6271 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6272 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6273 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6274 | return ValidateTexParameterBase(context, target, pname, 1, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6275 | } |
| 6276 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6277 | bool ValidateTexParameterfv(Context *context, |
| 6278 | TextureType target, |
| 6279 | GLenum pname, |
| 6280 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6281 | { |
| 6282 | return ValidateTexParameterBase(context, target, pname, -1, params); |
| 6283 | } |
| 6284 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6285 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6286 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6287 | return ValidateTexParameterBase(context, target, pname, 1, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6288 | } |
| 6289 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6290 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6291 | { |
| 6292 | return ValidateTexParameterBase(context, target, pname, -1, params); |
| 6293 | } |
| 6294 | |
| 6295 | bool ValidateUseProgram(Context *context, GLuint program) |
| 6296 | { |
| 6297 | if (program != 0) |
| 6298 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 6299 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6300 | if (!programObject) |
| 6301 | { |
| 6302 | // ES 3.1.0 section 7.3 page 72 |
| 6303 | if (context->getShader(program)) |
| 6304 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6305 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6306 | return false; |
| 6307 | } |
| 6308 | else |
| 6309 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6310 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6311 | return false; |
| 6312 | } |
| 6313 | } |
| 6314 | if (!programObject->isLinked()) |
| 6315 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6316 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6317 | return false; |
| 6318 | } |
| 6319 | } |
| 6320 | if (context->getGLState().isTransformFeedbackActiveUnpaused()) |
| 6321 | { |
| 6322 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6323 | context |
| 6324 | ->handleError(InvalidOperation() |
| 6325 | << "Cannot change active program while transform feedback is unpaused."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6326 | return false; |
| 6327 | } |
| 6328 | |
| 6329 | return true; |
| 6330 | } |
| 6331 | |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6332 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences) |
| 6333 | { |
| 6334 | if (!context->getExtensions().fence) |
| 6335 | { |
| 6336 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6337 | return false; |
| 6338 | } |
| 6339 | |
| 6340 | if (n < 0) |
| 6341 | { |
| 6342 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 6343 | return false; |
| 6344 | } |
| 6345 | |
| 6346 | return true; |
| 6347 | } |
| 6348 | |
| 6349 | bool ValidateFinishFenceNV(Context *context, GLuint fence) |
| 6350 | { |
| 6351 | if (!context->getExtensions().fence) |
| 6352 | { |
| 6353 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6354 | return false; |
| 6355 | } |
| 6356 | |
| 6357 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6358 | |
| 6359 | if (fenceObject == nullptr) |
| 6360 | { |
| 6361 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFence); |
| 6362 | return false; |
| 6363 | } |
| 6364 | |
| 6365 | if (!fenceObject->isSet()) |
| 6366 | { |
| 6367 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFenceState); |
| 6368 | return false; |
| 6369 | } |
| 6370 | |
| 6371 | return true; |
| 6372 | } |
| 6373 | |
| 6374 | bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences) |
| 6375 | { |
| 6376 | if (!context->getExtensions().fence) |
| 6377 | { |
| 6378 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6379 | return false; |
| 6380 | } |
| 6381 | |
| 6382 | if (n < 0) |
| 6383 | { |
| 6384 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 6385 | return false; |
| 6386 | } |
| 6387 | |
| 6388 | return true; |
| 6389 | } |
| 6390 | |
| 6391 | bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params) |
| 6392 | { |
| 6393 | if (!context->getExtensions().fence) |
| 6394 | { |
| 6395 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6396 | return false; |
| 6397 | } |
| 6398 | |
| 6399 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6400 | |
| 6401 | if (fenceObject == nullptr) |
| 6402 | { |
| 6403 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFence); |
| 6404 | return false; |
| 6405 | } |
| 6406 | |
| 6407 | if (!fenceObject->isSet()) |
| 6408 | { |
| 6409 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFenceState); |
| 6410 | return false; |
| 6411 | } |
| 6412 | |
| 6413 | switch (pname) |
| 6414 | { |
| 6415 | case GL_FENCE_STATUS_NV: |
| 6416 | case GL_FENCE_CONDITION_NV: |
| 6417 | break; |
| 6418 | |
| 6419 | default: |
| 6420 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
| 6421 | return false; |
| 6422 | } |
| 6423 | |
| 6424 | return true; |
| 6425 | } |
| 6426 | |
| 6427 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 6428 | { |
| 6429 | if (!context->getExtensions().robustness) |
| 6430 | { |
| 6431 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6432 | return false; |
| 6433 | } |
| 6434 | |
| 6435 | return true; |
| 6436 | } |
| 6437 | |
| 6438 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
| 6439 | GLuint shader, |
| 6440 | GLsizei bufsize, |
| 6441 | GLsizei *length, |
| 6442 | GLchar *source) |
| 6443 | { |
| 6444 | if (!context->getExtensions().translatedShaderSource) |
| 6445 | { |
| 6446 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6447 | return false; |
| 6448 | } |
| 6449 | |
| 6450 | if (bufsize < 0) |
| 6451 | { |
| 6452 | context->handleError(InvalidValue()); |
| 6453 | return false; |
| 6454 | } |
| 6455 | |
| 6456 | Shader *shaderObject = context->getShader(shader); |
| 6457 | |
| 6458 | if (!shaderObject) |
| 6459 | { |
| 6460 | context->handleError(InvalidOperation()); |
| 6461 | return false; |
| 6462 | } |
| 6463 | |
| 6464 | return true; |
| 6465 | } |
| 6466 | |
| 6467 | bool ValidateIsFenceNV(Context *context, GLuint fence) |
| 6468 | { |
| 6469 | if (!context->getExtensions().fence) |
| 6470 | { |
| 6471 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6472 | return false; |
| 6473 | } |
| 6474 | |
| 6475 | return true; |
| 6476 | } |
| 6477 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6478 | bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition) |
| 6479 | { |
| 6480 | if (!context->getExtensions().fence) |
| 6481 | { |
| 6482 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6483 | return false; |
| 6484 | } |
| 6485 | |
| 6486 | if (condition != GL_ALL_COMPLETED_NV) |
| 6487 | { |
| 6488 | context->handleError(InvalidEnum()); |
| 6489 | return false; |
| 6490 | } |
| 6491 | |
| 6492 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6493 | |
| 6494 | if (fenceObject == nullptr) |
| 6495 | { |
| 6496 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFence); |
| 6497 | return false; |
| 6498 | } |
| 6499 | |
| 6500 | return true; |
| 6501 | } |
| 6502 | |
| 6503 | bool ValidateTestFenceNV(Context *context, GLuint fence) |
| 6504 | { |
| 6505 | if (!context->getExtensions().fence) |
| 6506 | { |
| 6507 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6508 | return false; |
| 6509 | } |
| 6510 | |
| 6511 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6512 | |
| 6513 | if (fenceObject == nullptr) |
| 6514 | { |
| 6515 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFence); |
| 6516 | return false; |
| 6517 | } |
| 6518 | |
| 6519 | if (fenceObject->isSet() != GL_TRUE) |
| 6520 | { |
| 6521 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFenceState); |
| 6522 | return false; |
| 6523 | } |
| 6524 | |
| 6525 | return true; |
| 6526 | } |
| 6527 | |
| 6528 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6529 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6530 | GLsizei levels, |
| 6531 | GLenum internalformat, |
| 6532 | GLsizei width, |
| 6533 | GLsizei height) |
| 6534 | { |
| 6535 | if (!context->getExtensions().textureStorage) |
| 6536 | { |
| 6537 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6538 | return false; |
| 6539 | } |
| 6540 | |
| 6541 | if (context->getClientMajorVersion() < 3) |
| 6542 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6543 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6544 | height); |
| 6545 | } |
| 6546 | |
| 6547 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6548 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6549 | 1); |
| 6550 | } |
| 6551 | |
| 6552 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 6553 | { |
| 6554 | if (!context->getExtensions().instancedArrays) |
| 6555 | { |
| 6556 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6557 | return false; |
| 6558 | } |
| 6559 | |
| 6560 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6561 | { |
| 6562 | context->handleError(InvalidValue()); |
| 6563 | return false; |
| 6564 | } |
| 6565 | |
| 6566 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 6567 | { |
| 6568 | if (index == 0 && divisor != 0) |
| 6569 | { |
| 6570 | const char *errorMessage = |
| 6571 | "The current context doesn't support setting a non-zero divisor on the " |
| 6572 | "attribute with index zero. " |
| 6573 | "Please reorder the attributes in your vertex shader so that attribute zero " |
| 6574 | "can have a zero divisor."; |
| 6575 | context->handleError(InvalidOperation() << errorMessage); |
| 6576 | |
| 6577 | // We also output an error message to the debugger window if tracing is active, so |
| 6578 | // that developers can see the error message. |
| 6579 | ERR() << errorMessage; |
| 6580 | return false; |
| 6581 | } |
| 6582 | } |
| 6583 | |
| 6584 | return true; |
| 6585 | } |
| 6586 | |
| 6587 | bool ValidateTexImage3DOES(Context *context, |
| 6588 | GLenum target, |
| 6589 | GLint level, |
| 6590 | GLenum internalformat, |
| 6591 | GLsizei width, |
| 6592 | GLsizei height, |
| 6593 | GLsizei depth, |
| 6594 | GLint border, |
| 6595 | GLenum format, |
| 6596 | GLenum type, |
| 6597 | const void *pixels) |
| 6598 | { |
| 6599 | UNIMPLEMENTED(); // FIXME |
| 6600 | return false; |
| 6601 | } |
| 6602 | |
| 6603 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 6604 | { |
| 6605 | if (!context->getExtensions().debugMarker) |
| 6606 | { |
| 6607 | // The debug marker calls should not set error state |
| 6608 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 6609 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6610 | return false; |
| 6611 | } |
| 6612 | |
| 6613 | return true; |
| 6614 | } |
| 6615 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6616 | bool ValidateTexStorage1DEXT(Context *context, |
| 6617 | GLenum target, |
| 6618 | GLsizei levels, |
| 6619 | GLenum internalformat, |
| 6620 | GLsizei width) |
| 6621 | { |
| 6622 | UNIMPLEMENTED(); |
| 6623 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6624 | return false; |
| 6625 | } |
| 6626 | |
| 6627 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6628 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6629 | GLsizei levels, |
| 6630 | GLenum internalformat, |
| 6631 | GLsizei width, |
| 6632 | GLsizei height, |
| 6633 | GLsizei depth) |
| 6634 | { |
| 6635 | if (!context->getExtensions().textureStorage) |
| 6636 | { |
| 6637 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6638 | return false; |
| 6639 | } |
| 6640 | |
| 6641 | if (context->getClientMajorVersion() < 3) |
| 6642 | { |
| 6643 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6644 | return false; |
| 6645 | } |
| 6646 | |
| 6647 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 6648 | depth); |
| 6649 | } |
| 6650 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6651 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 6652 | { |
| 6653 | if (!context->getExtensions().parallelShaderCompile) |
| 6654 | { |
| 6655 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6656 | return false; |
| 6657 | } |
| 6658 | return true; |
| 6659 | } |
| 6660 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6661 | } // namespace gl |