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 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 291 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 294 | if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat)) |
| 295 | { |
| 296 | context->handleError(InvalidOperation() |
| 297 | << "Invalid combination of type and internalFormat."); |
| 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 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 304 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | return true; |
| 308 | } |
| 309 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 310 | bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 311 | { |
| 312 | switch (target) |
| 313 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 314 | case TextureTarget::_2D: |
| 315 | case TextureTarget::CubeMapNegativeX: |
| 316 | case TextureTarget::CubeMapNegativeY: |
| 317 | case TextureTarget::CubeMapNegativeZ: |
| 318 | case TextureTarget::CubeMapPositiveX: |
| 319 | case TextureTarget::CubeMapPositiveY: |
| 320 | case TextureTarget::CubeMapPositiveZ: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 321 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 322 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 323 | case TextureTarget::Rectangle: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 324 | return context->getExtensions().textureRectangle; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 325 | |
| 326 | default: |
| 327 | return false; |
| 328 | } |
| 329 | } |
| 330 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 331 | bool IsValidCopyTextureDestinationTarget(Context *context, |
| 332 | TextureType textureType, |
| 333 | TextureTarget target) |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 334 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 335 | return TextureTargetToType(target) == textureType; |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 336 | } |
| 337 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 338 | bool IsValidCopyTextureSourceTarget(Context *context, TextureType type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 339 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 340 | switch (type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 341 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 342 | case TextureType::_2D: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 343 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 344 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 345 | return context->getExtensions().textureRectangle; |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 346 | |
| 347 | // TODO(geofflang): accept GL_TEXTURE_EXTERNAL_OES if the texture_external extension is |
| 348 | // supported |
| 349 | |
| 350 | default: |
| 351 | return false; |
| 352 | } |
| 353 | } |
| 354 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 355 | bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 356 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 357 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 358 | { |
| 359 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 362 | if (level > 0 && context->getClientVersion() < ES_3_0) |
| 363 | { |
| 364 | return false; |
| 365 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 366 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 367 | return true; |
| 368 | } |
| 369 | |
| 370 | bool IsValidCopyTextureDestinationLevel(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 371 | TextureType type, |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 372 | GLint level, |
| 373 | GLsizei width, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 374 | GLsizei height, |
| 375 | bool isSubImage) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 376 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 377 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 378 | { |
| 379 | return false; |
| 380 | } |
| 381 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 382 | if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage)) |
| 383 | { |
| 384 | return false; |
| 385 | } |
| 386 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 387 | const Caps &caps = context->getCaps(); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 388 | switch (type) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 389 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 390 | case TextureType::_2D: |
| 391 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 392 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
| 393 | case TextureType::Rectangle: |
| 394 | ASSERT(level == 0); |
| 395 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 396 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 397 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 398 | case TextureType::CubeMap: |
| 399 | return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) && |
| 400 | static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level); |
| 401 | default: |
| 402 | return true; |
| 403 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 406 | bool IsValidStencilFunc(GLenum func) |
| 407 | { |
| 408 | switch (func) |
| 409 | { |
| 410 | case GL_NEVER: |
| 411 | case GL_ALWAYS: |
| 412 | case GL_LESS: |
| 413 | case GL_LEQUAL: |
| 414 | case GL_EQUAL: |
| 415 | case GL_GEQUAL: |
| 416 | case GL_GREATER: |
| 417 | case GL_NOTEQUAL: |
| 418 | return true; |
| 419 | |
| 420 | default: |
| 421 | return false; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | bool IsValidStencilFace(GLenum face) |
| 426 | { |
| 427 | switch (face) |
| 428 | { |
| 429 | case GL_FRONT: |
| 430 | case GL_BACK: |
| 431 | case GL_FRONT_AND_BACK: |
| 432 | return true; |
| 433 | |
| 434 | default: |
| 435 | return false; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | bool IsValidStencilOp(GLenum op) |
| 440 | { |
| 441 | switch (op) |
| 442 | { |
| 443 | case GL_ZERO: |
| 444 | case GL_KEEP: |
| 445 | case GL_REPLACE: |
| 446 | case GL_INCR: |
| 447 | case GL_DECR: |
| 448 | case GL_INVERT: |
| 449 | case GL_INCR_WRAP: |
| 450 | case GL_DECR_WRAP: |
| 451 | return true; |
| 452 | |
| 453 | default: |
| 454 | return false; |
| 455 | } |
| 456 | } |
| 457 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 458 | bool ValidateES2CopyTexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 459 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 460 | GLint level, |
| 461 | GLenum internalformat, |
| 462 | bool isSubImage, |
| 463 | GLint xoffset, |
| 464 | GLint yoffset, |
| 465 | GLint x, |
| 466 | GLint y, |
| 467 | GLsizei width, |
| 468 | GLsizei height, |
| 469 | GLint border) |
| 470 | { |
| 471 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 472 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 473 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 474 | return false; |
| 475 | } |
| 476 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 477 | TextureType texType = TextureTargetToType(target); |
| 478 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 479 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 480 | context->handleError(InvalidValue() << "Invalid texture dimensions."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 481 | return false; |
| 482 | } |
| 483 | |
| 484 | Format textureFormat = Format::Invalid(); |
| 485 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 486 | xoffset, yoffset, 0, x, y, width, height, border, |
| 487 | &textureFormat)) |
| 488 | { |
| 489 | return false; |
| 490 | } |
| 491 | |
| 492 | const gl::Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
| 493 | GLenum colorbufferFormat = |
| 494 | framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat; |
| 495 | const auto &formatInfo = *textureFormat.info; |
| 496 | |
| 497 | // [OpenGL ES 2.0.24] table 3.9 |
| 498 | if (isSubImage) |
| 499 | { |
| 500 | switch (formatInfo.format) |
| 501 | { |
| 502 | case GL_ALPHA: |
| 503 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 504 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 505 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 506 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 507 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 508 | return false; |
| 509 | } |
| 510 | break; |
| 511 | case GL_LUMINANCE: |
| 512 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 513 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 514 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 515 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT && |
| 516 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 517 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 518 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 519 | return false; |
| 520 | } |
| 521 | break; |
| 522 | case GL_RED_EXT: |
| 523 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 524 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 525 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 526 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F && |
| 527 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 528 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 529 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 530 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 531 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 532 | return false; |
| 533 | } |
| 534 | break; |
| 535 | case GL_RG_EXT: |
| 536 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 537 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 538 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 539 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 540 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 541 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 542 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 543 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 544 | return false; |
| 545 | } |
| 546 | break; |
| 547 | case GL_RGB: |
| 548 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 549 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 550 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 551 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 552 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 553 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 554 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 555 | return false; |
| 556 | } |
| 557 | break; |
| 558 | case GL_LUMINANCE_ALPHA: |
| 559 | case GL_RGBA: |
| 560 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 561 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F && |
| 562 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 563 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 564 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 565 | return false; |
| 566 | } |
| 567 | break; |
| 568 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 569 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 570 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 571 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 572 | case GL_ETC1_RGB8_OES: |
| 573 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 574 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 575 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 576 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 577 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 578 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 579 | return false; |
| 580 | case GL_DEPTH_COMPONENT: |
| 581 | case GL_DEPTH_STENCIL_OES: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 582 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 583 | return false; |
| 584 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 585 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 586 | return false; |
| 587 | } |
| 588 | |
| 589 | if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat) |
| 590 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 591 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 592 | return false; |
| 593 | } |
| 594 | } |
| 595 | else |
| 596 | { |
| 597 | switch (internalformat) |
| 598 | { |
| 599 | case GL_ALPHA: |
| 600 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
| 601 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 602 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 603 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 604 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 605 | return false; |
| 606 | } |
| 607 | break; |
| 608 | case GL_LUMINANCE: |
| 609 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 610 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 611 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 612 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 613 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 614 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 615 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 616 | return false; |
| 617 | } |
| 618 | break; |
| 619 | case GL_RED_EXT: |
| 620 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 621 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 622 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 623 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 624 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 625 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 626 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 627 | return false; |
| 628 | } |
| 629 | break; |
| 630 | case GL_RG_EXT: |
| 631 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 632 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 633 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 634 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 635 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 636 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 637 | return false; |
| 638 | } |
| 639 | break; |
| 640 | case GL_RGB: |
| 641 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 642 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 643 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 644 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 645 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 646 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 647 | return false; |
| 648 | } |
| 649 | break; |
| 650 | case GL_LUMINANCE_ALPHA: |
| 651 | case GL_RGBA: |
| 652 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 653 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 654 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 655 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 656 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 657 | return false; |
| 658 | } |
| 659 | break; |
| 660 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 661 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 662 | if (context->getExtensions().textureCompressionDXT1) |
| 663 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 664 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 665 | return false; |
| 666 | } |
| 667 | else |
| 668 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 669 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 670 | return false; |
| 671 | } |
| 672 | break; |
| 673 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 674 | if (context->getExtensions().textureCompressionDXT3) |
| 675 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 676 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 677 | return false; |
| 678 | } |
| 679 | else |
| 680 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 681 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 682 | return false; |
| 683 | } |
| 684 | break; |
| 685 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 686 | if (context->getExtensions().textureCompressionDXT5) |
| 687 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 688 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 689 | return false; |
| 690 | } |
| 691 | else |
| 692 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 693 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | break; |
| 697 | case GL_ETC1_RGB8_OES: |
| 698 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 699 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 700 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 701 | return false; |
| 702 | } |
| 703 | else |
| 704 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 705 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 706 | return false; |
| 707 | } |
| 708 | break; |
| 709 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 710 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 711 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 712 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 713 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 714 | if (context->getExtensions().lossyETCDecode) |
| 715 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 716 | context->handleError(InvalidOperation() |
| 717 | << "ETC lossy decode formats can't be copied to."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 718 | return false; |
| 719 | } |
| 720 | else |
| 721 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 722 | context->handleError(InvalidEnum() |
| 723 | << "ANGLE_lossy_etc_decode extension is not supported."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 724 | return false; |
| 725 | } |
| 726 | break; |
| 727 | case GL_DEPTH_COMPONENT: |
| 728 | case GL_DEPTH_COMPONENT16: |
| 729 | case GL_DEPTH_COMPONENT32_OES: |
| 730 | case GL_DEPTH_STENCIL_OES: |
| 731 | case GL_DEPTH24_STENCIL8_OES: |
| 732 | if (context->getExtensions().depthTextures) |
| 733 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 734 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 735 | return false; |
| 736 | } |
| 737 | else |
| 738 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 739 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 740 | return false; |
| 741 | } |
| 742 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 743 | context->handleError(InvalidEnum()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 744 | return false; |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 749 | return (width > 0 && height > 0); |
| 750 | } |
| 751 | |
| 752 | bool ValidCap(const Context *context, GLenum cap, bool queryOnly) |
| 753 | { |
| 754 | switch (cap) |
| 755 | { |
| 756 | // EXT_multisample_compatibility |
| 757 | case GL_MULTISAMPLE_EXT: |
| 758 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 759 | return context->getExtensions().multisampleCompatibility; |
| 760 | |
| 761 | case GL_CULL_FACE: |
| 762 | case GL_POLYGON_OFFSET_FILL: |
| 763 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 764 | case GL_SAMPLE_COVERAGE: |
| 765 | case GL_SCISSOR_TEST: |
| 766 | case GL_STENCIL_TEST: |
| 767 | case GL_DEPTH_TEST: |
| 768 | case GL_BLEND: |
| 769 | case GL_DITHER: |
| 770 | return true; |
| 771 | |
| 772 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 773 | case GL_RASTERIZER_DISCARD: |
| 774 | return (context->getClientMajorVersion() >= 3); |
| 775 | |
| 776 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 777 | case GL_DEBUG_OUTPUT: |
| 778 | return context->getExtensions().debug; |
| 779 | |
| 780 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 781 | return queryOnly && context->getExtensions().bindGeneratesResource; |
| 782 | |
| 783 | case GL_CLIENT_ARRAYS_ANGLE: |
| 784 | return queryOnly && context->getExtensions().clientArrays; |
| 785 | |
| 786 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 787 | return context->getExtensions().sRGBWriteControl; |
| 788 | |
| 789 | case GL_SAMPLE_MASK: |
| 790 | return context->getClientVersion() >= Version(3, 1); |
| 791 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 792 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 793 | return queryOnly && context->getExtensions().robustResourceInitialization; |
| 794 | |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 795 | // GLES1 emulation: GLES1-specific caps |
| 796 | case GL_ALPHA_TEST: |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 797 | case GL_VERTEX_ARRAY: |
| 798 | case GL_NORMAL_ARRAY: |
| 799 | case GL_COLOR_ARRAY: |
| 800 | case GL_TEXTURE_COORD_ARRAY: |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 801 | case GL_TEXTURE_2D: |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 802 | case GL_LIGHTING: |
| 803 | case GL_LIGHT0: |
| 804 | case GL_LIGHT1: |
| 805 | case GL_LIGHT2: |
| 806 | case GL_LIGHT3: |
| 807 | case GL_LIGHT4: |
| 808 | case GL_LIGHT5: |
| 809 | case GL_LIGHT6: |
| 810 | case GL_LIGHT7: |
| 811 | case GL_NORMALIZE: |
| 812 | case GL_RESCALE_NORMAL: |
| 813 | case GL_COLOR_MATERIAL: |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 814 | case GL_CLIP_PLANE0: |
| 815 | case GL_CLIP_PLANE1: |
| 816 | case GL_CLIP_PLANE2: |
| 817 | case GL_CLIP_PLANE3: |
| 818 | case GL_CLIP_PLANE4: |
| 819 | case GL_CLIP_PLANE5: |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 820 | case GL_FOG: |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 821 | case GL_POINT_SMOOTH: |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 822 | return context->getClientVersion() < Version(2, 0); |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 823 | case GL_POINT_SIZE_ARRAY_OES: |
| 824 | return context->getClientVersion() < Version(2, 0) && |
| 825 | context->getExtensions().pointSizeArray; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 826 | case GL_TEXTURE_CUBE_MAP: |
| 827 | return context->getClientVersion() < Version(2, 0) && |
| 828 | context->getExtensions().textureCubeMap; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 829 | case GL_POINT_SPRITE_OES: |
| 830 | return context->getClientVersion() < Version(2, 0) && |
| 831 | context->getExtensions().pointSprite; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 832 | default: |
| 833 | return false; |
| 834 | } |
| 835 | } |
| 836 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 837 | // Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section |
| 838 | // 3.1. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 839 | bool IsValidESSLCharacter(unsigned char c) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 840 | { |
| 841 | // Printing characters are valid except " $ ` @ \ ' DEL. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 842 | if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' && |
| 843 | c != '\'') |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 844 | { |
| 845 | return true; |
| 846 | } |
| 847 | |
| 848 | // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid. |
| 849 | if (c >= 9 && c <= 13) |
| 850 | { |
| 851 | return true; |
| 852 | } |
| 853 | |
| 854 | return false; |
| 855 | } |
| 856 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 857 | bool IsValidESSLString(const char *str, size_t len) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 858 | { |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 859 | for (size_t i = 0; i < len; i++) |
| 860 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 861 | if (!IsValidESSLCharacter(str[i])) |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 862 | { |
| 863 | return false; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | return true; |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 868 | } |
| 869 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 870 | bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed) |
| 871 | { |
| 872 | enum class ParseState |
| 873 | { |
| 874 | // Have not seen an ASCII non-whitespace character yet on |
| 875 | // this line. Possible that we might see a preprocessor |
| 876 | // directive. |
| 877 | BEGINING_OF_LINE, |
| 878 | |
| 879 | // Have seen at least one ASCII non-whitespace character |
| 880 | // on this line. |
| 881 | MIDDLE_OF_LINE, |
| 882 | |
| 883 | // Handling a preprocessor directive. Passes through all |
| 884 | // characters up to the end of the line. Disables comment |
| 885 | // processing. |
| 886 | IN_PREPROCESSOR_DIRECTIVE, |
| 887 | |
| 888 | // Handling a single-line comment. The comment text is |
| 889 | // replaced with a single space. |
| 890 | IN_SINGLE_LINE_COMMENT, |
| 891 | |
| 892 | // Handling a multi-line comment. Newlines are passed |
| 893 | // through to preserve line numbers. |
| 894 | IN_MULTI_LINE_COMMENT |
| 895 | }; |
| 896 | |
| 897 | ParseState state = ParseState::BEGINING_OF_LINE; |
| 898 | size_t pos = 0; |
| 899 | |
| 900 | while (pos < len) |
| 901 | { |
| 902 | char c = str[pos]; |
| 903 | char next = pos + 1 < len ? str[pos + 1] : 0; |
| 904 | |
| 905 | // Check for newlines |
| 906 | if (c == '\n' || c == '\r') |
| 907 | { |
| 908 | if (state != ParseState::IN_MULTI_LINE_COMMENT) |
| 909 | { |
| 910 | state = ParseState::BEGINING_OF_LINE; |
| 911 | } |
| 912 | |
| 913 | pos++; |
| 914 | continue; |
| 915 | } |
| 916 | |
| 917 | switch (state) |
| 918 | { |
| 919 | case ParseState::BEGINING_OF_LINE: |
| 920 | if (c == ' ') |
| 921 | { |
| 922 | // Maintain the BEGINING_OF_LINE state until a non-space is seen |
| 923 | pos++; |
| 924 | } |
| 925 | else if (c == '#') |
| 926 | { |
| 927 | state = ParseState::IN_PREPROCESSOR_DIRECTIVE; |
| 928 | pos++; |
| 929 | } |
| 930 | else |
| 931 | { |
| 932 | // Don't advance, re-process this character with the MIDDLE_OF_LINE state |
| 933 | state = ParseState::MIDDLE_OF_LINE; |
| 934 | } |
| 935 | break; |
| 936 | |
| 937 | case ParseState::MIDDLE_OF_LINE: |
| 938 | if (c == '/' && next == '/') |
| 939 | { |
| 940 | state = ParseState::IN_SINGLE_LINE_COMMENT; |
| 941 | pos++; |
| 942 | } |
| 943 | else if (c == '/' && next == '*') |
| 944 | { |
| 945 | state = ParseState::IN_MULTI_LINE_COMMENT; |
| 946 | pos++; |
| 947 | } |
| 948 | else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r')) |
| 949 | { |
| 950 | // Skip line continuation characters |
| 951 | } |
| 952 | else if (!IsValidESSLCharacter(c)) |
| 953 | { |
| 954 | return false; |
| 955 | } |
| 956 | pos++; |
| 957 | break; |
| 958 | |
| 959 | case ParseState::IN_PREPROCESSOR_DIRECTIVE: |
Bryan Bernhart (Intel Americas Inc) | 335d8bf | 2017-10-23 15:41:43 -0700 | [diff] [blame] | 960 | // Line-continuation characters may not be permitted. |
| 961 | // Otherwise, just pass it through. Do not parse comments in this state. |
| 962 | if (!lineContinuationAllowed && c == '\\') |
| 963 | { |
| 964 | return false; |
| 965 | } |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 966 | pos++; |
| 967 | break; |
| 968 | |
| 969 | case ParseState::IN_SINGLE_LINE_COMMENT: |
| 970 | // Line-continuation characters are processed before comment processing. |
| 971 | // Advance string if a new line character is immediately behind |
| 972 | // line-continuation character. |
| 973 | if (c == '\\' && (next == '\n' || next == '\r')) |
| 974 | { |
| 975 | pos++; |
| 976 | } |
| 977 | pos++; |
| 978 | break; |
| 979 | |
| 980 | case ParseState::IN_MULTI_LINE_COMMENT: |
| 981 | if (c == '*' && next == '/') |
| 982 | { |
| 983 | state = ParseState::MIDDLE_OF_LINE; |
| 984 | pos++; |
| 985 | } |
| 986 | pos++; |
| 987 | break; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | return true; |
| 992 | } |
| 993 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 994 | bool ValidateWebGLNamePrefix(Context *context, const GLchar *name) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 995 | { |
| 996 | ASSERT(context->isWebGL()); |
| 997 | |
| 998 | // WebGL 1.0 [Section 6.16] GLSL Constructs |
| 999 | // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL. |
| 1000 | if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0) |
| 1001 | { |
| 1002 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), WebglBindAttribLocationReservedPrefix); |
| 1003 | return false; |
| 1004 | } |
| 1005 | |
| 1006 | return true; |
| 1007 | } |
| 1008 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1009 | bool ValidateWebGLNameLength(Context *context, size_t length) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1010 | { |
| 1011 | ASSERT(context->isWebGL()); |
| 1012 | |
| 1013 | if (context->isWebGL1() && length > 256) |
| 1014 | { |
| 1015 | // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths |
| 1016 | // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute |
| 1017 | // locations. |
| 1018 | ANGLE_VALIDATION_ERR(context, InvalidValue(), WebglNameLengthLimitExceeded); |
| 1019 | |
| 1020 | return false; |
| 1021 | } |
| 1022 | else if (length > 1024) |
| 1023 | { |
| 1024 | // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of |
| 1025 | // uniform and attribute locations. |
| 1026 | ANGLE_VALIDATION_ERR(context, InvalidValue(), Webgl2NameLengthLimitExceeded); |
| 1027 | return false; |
| 1028 | } |
| 1029 | |
| 1030 | return true; |
| 1031 | } |
| 1032 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1033 | bool ValidateMatrixMode(Context *context, GLenum matrixMode) |
| 1034 | { |
| 1035 | if (!context->getExtensions().pathRendering) |
| 1036 | { |
| 1037 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
| 1038 | return false; |
| 1039 | } |
| 1040 | |
| 1041 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 1042 | { |
| 1043 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMatrixMode); |
| 1044 | return false; |
| 1045 | } |
| 1046 | return true; |
| 1047 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1048 | } // anonymous namespace |
| 1049 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1050 | bool ValidateES2TexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1051 | TextureTarget target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1052 | GLint level, |
| 1053 | GLenum internalformat, |
| 1054 | bool isCompressed, |
| 1055 | bool isSubImage, |
| 1056 | GLint xoffset, |
| 1057 | GLint yoffset, |
| 1058 | GLsizei width, |
| 1059 | GLsizei height, |
| 1060 | GLint border, |
| 1061 | GLenum format, |
| 1062 | GLenum type, |
| 1063 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1064 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1065 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1066 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1067 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1068 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1069 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1070 | } |
| 1071 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1072 | TextureType texType = TextureTargetToType(target); |
| 1073 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1074 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1075 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1076 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1077 | } |
| 1078 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1079 | if (!ValidMipLevel(context, texType, level)) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1080 | { |
| 1081 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
| 1082 | return false; |
| 1083 | } |
| 1084 | |
| 1085 | if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width || |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1086 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1087 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1088 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1089 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1092 | // From GL_CHROMIUM_color_buffer_float_rgb[a]: |
| 1093 | // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for |
| 1094 | // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the |
| 1095 | // internalformat parameter and format parameter of TexImage2D must match is lifted for this |
| 1096 | // case. |
| 1097 | bool nonEqualFormatsAllowed = |
| 1098 | (internalformat == GL_RGB32F && context->getExtensions().colorBufferFloatRGB) || |
| 1099 | (internalformat == GL_RGBA32F && context->getExtensions().colorBufferFloatRGBA); |
| 1100 | |
| 1101 | if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1102 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1103 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1104 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1105 | } |
| 1106 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1107 | const gl::Caps &caps = context->getCaps(); |
| 1108 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1109 | switch (texType) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1110 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1111 | case TextureType::_2D: |
| 1112 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 1113 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 1114 | { |
| 1115 | context->handleError(InvalidValue()); |
| 1116 | return false; |
| 1117 | } |
| 1118 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1119 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1120 | case TextureType::Rectangle: |
| 1121 | ASSERT(level == 0); |
| 1122 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1123 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1124 | { |
| 1125 | context->handleError(InvalidValue()); |
| 1126 | return false; |
| 1127 | } |
| 1128 | if (isCompressed) |
| 1129 | { |
| 1130 | context->handleError(InvalidEnum() |
| 1131 | << "Rectangle texture cannot have a compressed format."); |
| 1132 | return false; |
| 1133 | } |
| 1134 | break; |
| 1135 | |
| 1136 | case TextureType::CubeMap: |
| 1137 | if (!isSubImage && width != height) |
| 1138 | { |
| 1139 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapFacesEqualDimensions); |
| 1140 | return false; |
| 1141 | } |
| 1142 | |
| 1143 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 1144 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 1145 | { |
| 1146 | context->handleError(InvalidValue()); |
| 1147 | return false; |
| 1148 | } |
| 1149 | break; |
| 1150 | |
| 1151 | default: |
| 1152 | context->handleError(InvalidEnum()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1153 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1154 | } |
| 1155 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1156 | gl::Texture *texture = context->getTargetTexture(texType); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1157 | if (!texture) |
| 1158 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1159 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1160 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1161 | } |
| 1162 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1163 | if (isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1164 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1165 | const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info; |
| 1166 | if (textureInternalFormat.internalFormat == GL_NONE) |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 1167 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1168 | context->handleError(InvalidOperation() << "Texture level does not exist."); |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 1169 | return false; |
| 1170 | } |
| 1171 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1172 | if (format != GL_NONE) |
| 1173 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1174 | if (GetInternalFormatInfo(format, type).sizedInternalFormat != |
| 1175 | textureInternalFormat.sizedInternalFormat) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1176 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1177 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TypeMismatch); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1178 | return false; |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1183 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 1184 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1185 | context->handleError(InvalidValue()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1186 | return false; |
| 1187 | } |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1188 | |
| 1189 | if (width > 0 && height > 0 && pixels == nullptr && |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1190 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr) |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1191 | { |
| 1192 | ANGLE_VALIDATION_ERR(context, InvalidValue(), PixelDataNull); |
| 1193 | return false; |
| 1194 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1195 | } |
| 1196 | else |
| 1197 | { |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1198 | if (texture->getImmutableFormat()) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1199 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1200 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1201 | return false; |
| 1202 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | // Verify zero border |
| 1206 | if (border != 0) |
| 1207 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1208 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1209 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1212 | if (isCompressed) |
| 1213 | { |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1214 | GLenum actualInternalFormat = |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1215 | isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat |
| 1216 | : internalformat; |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1217 | |
| 1218 | const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat); |
| 1219 | |
| 1220 | if (!internalFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1221 | { |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1222 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidInternalFormat); |
| 1223 | return false; |
| 1224 | } |
| 1225 | |
| 1226 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), |
| 1227 | context->getExtensions())) |
| 1228 | { |
| 1229 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidInternalFormat); |
| 1230 | return false; |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1231 | } |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1232 | |
| 1233 | if (isSubImage) |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1234 | { |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1235 | // From the OES_compressed_ETC1_RGB8_texture spec: |
| 1236 | // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or |
| 1237 | // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format |
| 1238 | // ETC1_RGB8_OES. |
| 1239 | if (actualInternalFormat == GL_ETC1_RGB8_OES) |
| 1240 | { |
| 1241 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
| 1242 | return false; |
| 1243 | } |
| 1244 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1245 | if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width, |
| 1246 | height, texture->getWidth(target, level), |
| 1247 | texture->getHeight(target, level))) |
| 1248 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1249 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1250 | return false; |
| 1251 | } |
| 1252 | |
| 1253 | if (format != actualInternalFormat) |
| 1254 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1255 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1256 | return false; |
| 1257 | } |
| 1258 | } |
| 1259 | else |
| 1260 | { |
| 1261 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 1262 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1263 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1264 | return false; |
| 1265 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | else |
| 1269 | { |
| 1270 | // validate <type> by itself (used as secondary key below) |
| 1271 | switch (type) |
| 1272 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1273 | case GL_UNSIGNED_BYTE: |
| 1274 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1275 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1276 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1277 | case GL_UNSIGNED_SHORT: |
| 1278 | case GL_UNSIGNED_INT: |
| 1279 | case GL_UNSIGNED_INT_24_8_OES: |
| 1280 | case GL_HALF_FLOAT_OES: |
| 1281 | case GL_FLOAT: |
| 1282 | break; |
| 1283 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1284 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1285 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | // validate <format> + <type> combinations |
| 1289 | // - invalid <format> -> sets INVALID_ENUM |
| 1290 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 1291 | switch (format) |
| 1292 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1293 | case GL_ALPHA: |
| 1294 | case GL_LUMINANCE: |
| 1295 | case GL_LUMINANCE_ALPHA: |
| 1296 | switch (type) |
| 1297 | { |
| 1298 | case GL_UNSIGNED_BYTE: |
| 1299 | case GL_FLOAT: |
| 1300 | case GL_HALF_FLOAT_OES: |
| 1301 | break; |
| 1302 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1303 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1304 | return false; |
| 1305 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1306 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1307 | case GL_RED: |
| 1308 | case GL_RG: |
| 1309 | if (!context->getExtensions().textureRG) |
| 1310 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1311 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1312 | return false; |
| 1313 | } |
| 1314 | switch (type) |
| 1315 | { |
| 1316 | case GL_UNSIGNED_BYTE: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1317 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1318 | case GL_FLOAT: |
| 1319 | case GL_HALF_FLOAT_OES: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1320 | if (!context->getExtensions().textureFloat) |
| 1321 | { |
| 1322 | context->handleError(InvalidEnum()); |
| 1323 | return false; |
| 1324 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1325 | break; |
| 1326 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1327 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1328 | return false; |
| 1329 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1330 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1331 | case GL_RGB: |
| 1332 | switch (type) |
| 1333 | { |
| 1334 | case GL_UNSIGNED_BYTE: |
| 1335 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1336 | case GL_FLOAT: |
| 1337 | case GL_HALF_FLOAT_OES: |
| 1338 | break; |
| 1339 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1340 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1341 | return false; |
| 1342 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1343 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1344 | case GL_RGBA: |
| 1345 | switch (type) |
| 1346 | { |
| 1347 | case GL_UNSIGNED_BYTE: |
| 1348 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1349 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1350 | case GL_FLOAT: |
| 1351 | case GL_HALF_FLOAT_OES: |
| 1352 | break; |
| 1353 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1354 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1355 | return false; |
| 1356 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1357 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1358 | case GL_BGRA_EXT: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1359 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1360 | { |
| 1361 | context->handleError(InvalidEnum()); |
| 1362 | return false; |
| 1363 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1364 | switch (type) |
| 1365 | { |
| 1366 | case GL_UNSIGNED_BYTE: |
| 1367 | break; |
| 1368 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1369 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1370 | return false; |
| 1371 | } |
| 1372 | break; |
| 1373 | case GL_SRGB_EXT: |
| 1374 | case GL_SRGB_ALPHA_EXT: |
| 1375 | if (!context->getExtensions().sRGB) |
| 1376 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1377 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1378 | return false; |
| 1379 | } |
| 1380 | switch (type) |
| 1381 | { |
| 1382 | case GL_UNSIGNED_BYTE: |
| 1383 | break; |
| 1384 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1385 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1386 | return false; |
| 1387 | } |
| 1388 | break; |
| 1389 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1390 | // handled below |
| 1391 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1392 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1393 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1394 | break; |
| 1395 | case GL_DEPTH_COMPONENT: |
| 1396 | switch (type) |
| 1397 | { |
| 1398 | case GL_UNSIGNED_SHORT: |
| 1399 | case GL_UNSIGNED_INT: |
| 1400 | break; |
| 1401 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1402 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1403 | return false; |
| 1404 | } |
| 1405 | break; |
| 1406 | case GL_DEPTH_STENCIL_OES: |
| 1407 | switch (type) |
| 1408 | { |
| 1409 | case GL_UNSIGNED_INT_24_8_OES: |
| 1410 | break; |
| 1411 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1412 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1413 | return false; |
| 1414 | } |
| 1415 | break; |
| 1416 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1417 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1418 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | switch (format) |
| 1422 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1423 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1424 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1425 | if (context->getExtensions().textureCompressionDXT1) |
| 1426 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1427 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1428 | return false; |
| 1429 | } |
| 1430 | else |
| 1431 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1432 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1433 | return false; |
| 1434 | } |
| 1435 | break; |
| 1436 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1437 | if (context->getExtensions().textureCompressionDXT3) |
| 1438 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1439 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1440 | return false; |
| 1441 | } |
| 1442 | else |
| 1443 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1444 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1445 | return false; |
| 1446 | } |
| 1447 | break; |
| 1448 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1449 | if (context->getExtensions().textureCompressionDXT5) |
| 1450 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1451 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1452 | return false; |
| 1453 | } |
| 1454 | else |
| 1455 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1456 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1457 | return false; |
| 1458 | } |
| 1459 | break; |
| 1460 | case GL_ETC1_RGB8_OES: |
| 1461 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1462 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1463 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1464 | return false; |
| 1465 | } |
| 1466 | else |
| 1467 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1468 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1469 | return false; |
| 1470 | } |
| 1471 | break; |
| 1472 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1473 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1474 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1475 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1476 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1477 | if (context->getExtensions().lossyETCDecode) |
| 1478 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1479 | context->handleError(InvalidOperation() |
| 1480 | << "ETC lossy decode formats can't work with this type."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1481 | return false; |
| 1482 | } |
| 1483 | else |
| 1484 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1485 | context->handleError(InvalidEnum() |
| 1486 | << "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1487 | return false; |
| 1488 | } |
| 1489 | break; |
| 1490 | case GL_DEPTH_COMPONENT: |
| 1491 | case GL_DEPTH_STENCIL_OES: |
| 1492 | if (!context->getExtensions().depthTextures) |
| 1493 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1494 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1495 | return false; |
| 1496 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1497 | if (target != TextureTarget::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1498 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1499 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTargetAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1500 | return false; |
| 1501 | } |
| 1502 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1503 | // but ANGLE_depth_texture does not |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1504 | if (pixels != nullptr) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1505 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1506 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), PixelDataNotNull); |
| 1507 | return false; |
| 1508 | } |
| 1509 | if (level != 0) |
| 1510 | { |
| 1511 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), LevelNotZero); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1512 | return false; |
| 1513 | } |
| 1514 | break; |
| 1515 | default: |
| 1516 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1517 | } |
| 1518 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1519 | if (!isSubImage) |
| 1520 | { |
| 1521 | switch (internalformat) |
| 1522 | { |
| 1523 | case GL_RGBA32F: |
| 1524 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1525 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1526 | context->handleError(InvalidValue() |
| 1527 | << "Sized GL_RGBA32F internal format requires " |
| 1528 | "GL_CHROMIUM_color_buffer_float_rgba"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1529 | return false; |
| 1530 | } |
| 1531 | if (type != GL_FLOAT) |
| 1532 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1533 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1534 | return false; |
| 1535 | } |
| 1536 | if (format != GL_RGBA) |
| 1537 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1538 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1539 | return false; |
| 1540 | } |
| 1541 | break; |
| 1542 | |
| 1543 | case GL_RGB32F: |
| 1544 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1545 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1546 | context->handleError(InvalidValue() |
| 1547 | << "Sized GL_RGB32F internal format requires " |
| 1548 | "GL_CHROMIUM_color_buffer_float_rgb"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1549 | return false; |
| 1550 | } |
| 1551 | if (type != GL_FLOAT) |
| 1552 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1553 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1554 | return false; |
| 1555 | } |
| 1556 | if (format != GL_RGB) |
| 1557 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1558 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1559 | return false; |
| 1560 | } |
| 1561 | break; |
| 1562 | |
| 1563 | default: |
| 1564 | break; |
| 1565 | } |
| 1566 | } |
| 1567 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1568 | if (type == GL_FLOAT) |
| 1569 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1570 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1571 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1572 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1573 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | else if (type == GL_HALF_FLOAT_OES) |
| 1577 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1578 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1579 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1580 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1581 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | } |
| 1585 | |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 1586 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1587 | if (!ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1588 | imageSize)) |
| 1589 | { |
| 1590 | return false; |
| 1591 | } |
| 1592 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1593 | return true; |
| 1594 | } |
| 1595 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1596 | bool ValidateES2TexStorageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1597 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1598 | GLsizei levels, |
| 1599 | GLenum internalformat, |
| 1600 | GLsizei width, |
| 1601 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1602 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1603 | if (target != TextureType::_2D && target != TextureType::CubeMap && |
| 1604 | target != TextureType::Rectangle) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1605 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1606 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1607 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | if (width < 1 || height < 1 || levels < 1) |
| 1611 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1612 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1613 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1614 | } |
| 1615 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1616 | if (target == TextureType::CubeMap && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1617 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1618 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1619 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1623 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1624 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1625 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1626 | } |
| 1627 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1628 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1629 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1630 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1631 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1632 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1633 | } |
| 1634 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1635 | const gl::Caps &caps = context->getCaps(); |
| 1636 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1637 | switch (target) |
| 1638 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1639 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1640 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1641 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1642 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1643 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1644 | return false; |
| 1645 | } |
| 1646 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1647 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1648 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1649 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize || levels != 1) |
| 1650 | { |
| 1651 | context->handleError(InvalidValue()); |
| 1652 | return false; |
| 1653 | } |
| 1654 | if (formatInfo.compressed) |
| 1655 | { |
| 1656 | context->handleError(InvalidEnum() |
| 1657 | << "Rectangle texture cannot have a compressed format."); |
| 1658 | return false; |
| 1659 | } |
| 1660 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1661 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1662 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1663 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1664 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1665 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1666 | return false; |
| 1667 | } |
| 1668 | break; |
| 1669 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1670 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1671 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1672 | } |
| 1673 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1674 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1675 | { |
| 1676 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1677 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1678 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1679 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | switch (internalformat) |
| 1684 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1685 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1686 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1687 | if (!context->getExtensions().textureCompressionDXT1) |
| 1688 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1689 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1690 | return false; |
| 1691 | } |
| 1692 | break; |
| 1693 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1694 | if (!context->getExtensions().textureCompressionDXT3) |
| 1695 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1696 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1697 | return false; |
| 1698 | } |
| 1699 | break; |
| 1700 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1701 | if (!context->getExtensions().textureCompressionDXT5) |
| 1702 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1703 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1704 | return false; |
| 1705 | } |
| 1706 | break; |
| 1707 | case GL_ETC1_RGB8_OES: |
| 1708 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1709 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1710 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1711 | return false; |
| 1712 | } |
| 1713 | break; |
| 1714 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1715 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1716 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1717 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1718 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1719 | if (!context->getExtensions().lossyETCDecode) |
| 1720 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1721 | context->handleError(InvalidEnum() |
| 1722 | << "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1723 | return false; |
| 1724 | } |
| 1725 | break; |
| 1726 | case GL_RGBA32F_EXT: |
| 1727 | case GL_RGB32F_EXT: |
| 1728 | case GL_ALPHA32F_EXT: |
| 1729 | case GL_LUMINANCE32F_EXT: |
| 1730 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 1731 | if (!context->getExtensions().textureFloat) |
| 1732 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1733 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1734 | return false; |
| 1735 | } |
| 1736 | break; |
| 1737 | case GL_RGBA16F_EXT: |
| 1738 | case GL_RGB16F_EXT: |
| 1739 | case GL_ALPHA16F_EXT: |
| 1740 | case GL_LUMINANCE16F_EXT: |
| 1741 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 1742 | if (!context->getExtensions().textureHalfFloat) |
| 1743 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1744 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1745 | return false; |
| 1746 | } |
| 1747 | break; |
| 1748 | case GL_R8_EXT: |
| 1749 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1750 | if (!context->getExtensions().textureRG) |
| 1751 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1752 | context->handleError(InvalidEnum()); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1753 | return false; |
| 1754 | } |
| 1755 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1756 | case GL_R16F_EXT: |
| 1757 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1758 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 1759 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1760 | context->handleError(InvalidEnum()); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1761 | return false; |
| 1762 | } |
| 1763 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1764 | case GL_R32F_EXT: |
| 1765 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1766 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1767 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1768 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1769 | return false; |
| 1770 | } |
| 1771 | break; |
| 1772 | case GL_DEPTH_COMPONENT16: |
| 1773 | case GL_DEPTH_COMPONENT32_OES: |
| 1774 | case GL_DEPTH24_STENCIL8_OES: |
| 1775 | if (!context->getExtensions().depthTextures) |
| 1776 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1777 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1778 | return false; |
| 1779 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1780 | if (target != TextureType::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1781 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1782 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1783 | return false; |
| 1784 | } |
| 1785 | // ANGLE_depth_texture only supports 1-level textures |
| 1786 | if (levels != 1) |
| 1787 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1788 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1789 | return false; |
| 1790 | } |
| 1791 | break; |
| 1792 | default: |
| 1793 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1794 | } |
| 1795 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1796 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1797 | if (!texture || texture->id() == 0) |
| 1798 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1799 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1800 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1801 | } |
| 1802 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1803 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1804 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1805 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1806 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | return true; |
| 1810 | } |
| 1811 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1812 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 1813 | GLenum target, |
| 1814 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1815 | const GLenum *attachments) |
| 1816 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1817 | if (!context->getExtensions().discardFramebuffer) |
| 1818 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1819 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1820 | return false; |
| 1821 | } |
| 1822 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1823 | bool defaultFramebuffer = false; |
| 1824 | |
| 1825 | switch (target) |
| 1826 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1827 | case GL_FRAMEBUFFER: |
| 1828 | defaultFramebuffer = |
| 1829 | (context->getGLState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
| 1830 | break; |
| 1831 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1832 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1833 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1836 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1837 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1840 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 1841 | { |
| 1842 | if (!context->getExtensions().vertexArrayObject) |
| 1843 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1844 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1845 | return false; |
| 1846 | } |
| 1847 | |
| 1848 | return ValidateBindVertexArrayBase(context, array); |
| 1849 | } |
| 1850 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1851 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1852 | { |
| 1853 | if (!context->getExtensions().vertexArrayObject) |
| 1854 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1855 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1856 | return false; |
| 1857 | } |
| 1858 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1859 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1862 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1863 | { |
| 1864 | if (!context->getExtensions().vertexArrayObject) |
| 1865 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1866 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1867 | return false; |
| 1868 | } |
| 1869 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1870 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1873 | bool ValidateIsVertexArrayOES(Context *context, GLuint array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1874 | { |
| 1875 | if (!context->getExtensions().vertexArrayObject) |
| 1876 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1877 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1878 | return false; |
| 1879 | } |
| 1880 | |
| 1881 | return true; |
| 1882 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1883 | |
| 1884 | bool ValidateProgramBinaryOES(Context *context, |
| 1885 | GLuint program, |
| 1886 | GLenum binaryFormat, |
| 1887 | const void *binary, |
| 1888 | GLint length) |
| 1889 | { |
| 1890 | if (!context->getExtensions().getProgramBinary) |
| 1891 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1892 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1893 | return false; |
| 1894 | } |
| 1895 | |
| 1896 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1897 | } |
| 1898 | |
| 1899 | bool ValidateGetProgramBinaryOES(Context *context, |
| 1900 | GLuint program, |
| 1901 | GLsizei bufSize, |
| 1902 | GLsizei *length, |
| 1903 | GLenum *binaryFormat, |
| 1904 | void *binary) |
| 1905 | { |
| 1906 | if (!context->getExtensions().getProgramBinary) |
| 1907 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1908 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1909 | return false; |
| 1910 | } |
| 1911 | |
| 1912 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1913 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1914 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1915 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 1916 | { |
| 1917 | switch (source) |
| 1918 | { |
| 1919 | case GL_DEBUG_SOURCE_API: |
| 1920 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 1921 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 1922 | case GL_DEBUG_SOURCE_OTHER: |
| 1923 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 1924 | return !mustBeThirdPartyOrApplication; |
| 1925 | |
| 1926 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 1927 | case GL_DEBUG_SOURCE_APPLICATION: |
| 1928 | return true; |
| 1929 | |
| 1930 | default: |
| 1931 | return false; |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | static bool ValidDebugType(GLenum type) |
| 1936 | { |
| 1937 | switch (type) |
| 1938 | { |
| 1939 | case GL_DEBUG_TYPE_ERROR: |
| 1940 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 1941 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 1942 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 1943 | case GL_DEBUG_TYPE_PORTABILITY: |
| 1944 | case GL_DEBUG_TYPE_OTHER: |
| 1945 | case GL_DEBUG_TYPE_MARKER: |
| 1946 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 1947 | case GL_DEBUG_TYPE_POP_GROUP: |
| 1948 | return true; |
| 1949 | |
| 1950 | default: |
| 1951 | return false; |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | static bool ValidDebugSeverity(GLenum severity) |
| 1956 | { |
| 1957 | switch (severity) |
| 1958 | { |
| 1959 | case GL_DEBUG_SEVERITY_HIGH: |
| 1960 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 1961 | case GL_DEBUG_SEVERITY_LOW: |
| 1962 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 1963 | return true; |
| 1964 | |
| 1965 | default: |
| 1966 | return false; |
| 1967 | } |
| 1968 | } |
| 1969 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1970 | bool ValidateDebugMessageControlKHR(Context *context, |
| 1971 | GLenum source, |
| 1972 | GLenum type, |
| 1973 | GLenum severity, |
| 1974 | GLsizei count, |
| 1975 | const GLuint *ids, |
| 1976 | GLboolean enabled) |
| 1977 | { |
| 1978 | if (!context->getExtensions().debug) |
| 1979 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1980 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1981 | return false; |
| 1982 | } |
| 1983 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1984 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 1985 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1986 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1987 | return false; |
| 1988 | } |
| 1989 | |
| 1990 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 1991 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1992 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1993 | return false; |
| 1994 | } |
| 1995 | |
| 1996 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 1997 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1998 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1999 | return false; |
| 2000 | } |
| 2001 | |
| 2002 | if (count > 0) |
| 2003 | { |
| 2004 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 2005 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2006 | context->handleError( |
| 2007 | InvalidOperation() |
| 2008 | << "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] | 2009 | return false; |
| 2010 | } |
| 2011 | |
| 2012 | if (severity != GL_DONT_CARE) |
| 2013 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2014 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2015 | InvalidOperation() |
| 2016 | << "If count is greater than zero, severity must be GL_DONT_CARE."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2017 | return false; |
| 2018 | } |
| 2019 | } |
| 2020 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2021 | return true; |
| 2022 | } |
| 2023 | |
| 2024 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 2025 | GLenum source, |
| 2026 | GLenum type, |
| 2027 | GLuint id, |
| 2028 | GLenum severity, |
| 2029 | GLsizei length, |
| 2030 | const GLchar *buf) |
| 2031 | { |
| 2032 | if (!context->getExtensions().debug) |
| 2033 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2034 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2035 | return false; |
| 2036 | } |
| 2037 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2038 | if (!context->getGLState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2039 | { |
| 2040 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 2041 | // not generate an error. |
| 2042 | return false; |
| 2043 | } |
| 2044 | |
| 2045 | if (!ValidDebugSeverity(severity)) |
| 2046 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2047 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2048 | return false; |
| 2049 | } |
| 2050 | |
| 2051 | if (!ValidDebugType(type)) |
| 2052 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2053 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2054 | return false; |
| 2055 | } |
| 2056 | |
| 2057 | if (!ValidDebugSource(source, true)) |
| 2058 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2059 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2060 | return false; |
| 2061 | } |
| 2062 | |
| 2063 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 2064 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2065 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2066 | context->handleError(InvalidValue() |
| 2067 | << "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2068 | return false; |
| 2069 | } |
| 2070 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2071 | return true; |
| 2072 | } |
| 2073 | |
| 2074 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 2075 | GLDEBUGPROCKHR callback, |
| 2076 | const void *userParam) |
| 2077 | { |
| 2078 | if (!context->getExtensions().debug) |
| 2079 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2080 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2081 | return false; |
| 2082 | } |
| 2083 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2084 | return true; |
| 2085 | } |
| 2086 | |
| 2087 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 2088 | GLuint count, |
| 2089 | GLsizei bufSize, |
| 2090 | GLenum *sources, |
| 2091 | GLenum *types, |
| 2092 | GLuint *ids, |
| 2093 | GLenum *severities, |
| 2094 | GLsizei *lengths, |
| 2095 | GLchar *messageLog) |
| 2096 | { |
| 2097 | if (!context->getExtensions().debug) |
| 2098 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2099 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2100 | return false; |
| 2101 | } |
| 2102 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2103 | if (bufSize < 0 && messageLog != nullptr) |
| 2104 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2105 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2106 | return false; |
| 2107 | } |
| 2108 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2109 | return true; |
| 2110 | } |
| 2111 | |
| 2112 | bool ValidatePushDebugGroupKHR(Context *context, |
| 2113 | GLenum source, |
| 2114 | GLuint id, |
| 2115 | GLsizei length, |
| 2116 | const GLchar *message) |
| 2117 | { |
| 2118 | if (!context->getExtensions().debug) |
| 2119 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2120 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2121 | return false; |
| 2122 | } |
| 2123 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2124 | if (!ValidDebugSource(source, true)) |
| 2125 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2126 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2127 | return false; |
| 2128 | } |
| 2129 | |
| 2130 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 2131 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2132 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2133 | context->handleError(InvalidValue() |
| 2134 | << "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2135 | return false; |
| 2136 | } |
| 2137 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2138 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2139 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 2140 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2141 | context |
| 2142 | ->handleError(StackOverflow() |
| 2143 | << "Cannot push more than GL_MAX_DEBUG_GROUP_STACK_DEPTH debug groups."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2144 | return false; |
| 2145 | } |
| 2146 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2147 | return true; |
| 2148 | } |
| 2149 | |
| 2150 | bool ValidatePopDebugGroupKHR(Context *context) |
| 2151 | { |
| 2152 | if (!context->getExtensions().debug) |
| 2153 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2154 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2155 | return false; |
| 2156 | } |
| 2157 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2158 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2159 | if (currentStackSize <= 1) |
| 2160 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2161 | context->handleError(StackUnderflow() << "Cannot pop the default debug group."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2162 | return false; |
| 2163 | } |
| 2164 | |
| 2165 | return true; |
| 2166 | } |
| 2167 | |
| 2168 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 2169 | { |
| 2170 | switch (identifier) |
| 2171 | { |
| 2172 | case GL_BUFFER: |
| 2173 | if (context->getBuffer(name) == nullptr) |
| 2174 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2175 | context->handleError(InvalidValue() << "name is not a valid buffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2176 | return false; |
| 2177 | } |
| 2178 | return true; |
| 2179 | |
| 2180 | case GL_SHADER: |
| 2181 | if (context->getShader(name) == nullptr) |
| 2182 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2183 | context->handleError(InvalidValue() << "name is not a valid shader."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2184 | return false; |
| 2185 | } |
| 2186 | return true; |
| 2187 | |
| 2188 | case GL_PROGRAM: |
| 2189 | if (context->getProgram(name) == nullptr) |
| 2190 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2191 | context->handleError(InvalidValue() << "name is not a valid program."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2192 | return false; |
| 2193 | } |
| 2194 | return true; |
| 2195 | |
| 2196 | case GL_VERTEX_ARRAY: |
| 2197 | if (context->getVertexArray(name) == nullptr) |
| 2198 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2199 | context->handleError(InvalidValue() << "name is not a valid vertex array."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2200 | return false; |
| 2201 | } |
| 2202 | return true; |
| 2203 | |
| 2204 | case GL_QUERY: |
| 2205 | if (context->getQuery(name) == nullptr) |
| 2206 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2207 | context->handleError(InvalidValue() << "name is not a valid query."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2208 | return false; |
| 2209 | } |
| 2210 | return true; |
| 2211 | |
| 2212 | case GL_TRANSFORM_FEEDBACK: |
| 2213 | if (context->getTransformFeedback(name) == nullptr) |
| 2214 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2215 | context->handleError(InvalidValue() << "name is not a valid transform feedback."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2216 | return false; |
| 2217 | } |
| 2218 | return true; |
| 2219 | |
| 2220 | case GL_SAMPLER: |
| 2221 | if (context->getSampler(name) == nullptr) |
| 2222 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2223 | context->handleError(InvalidValue() << "name is not a valid sampler."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2224 | return false; |
| 2225 | } |
| 2226 | return true; |
| 2227 | |
| 2228 | case GL_TEXTURE: |
| 2229 | if (context->getTexture(name) == nullptr) |
| 2230 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2231 | context->handleError(InvalidValue() << "name is not a valid texture."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2232 | return false; |
| 2233 | } |
| 2234 | return true; |
| 2235 | |
| 2236 | case GL_RENDERBUFFER: |
| 2237 | if (context->getRenderbuffer(name) == nullptr) |
| 2238 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2239 | context->handleError(InvalidValue() << "name is not a valid renderbuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2240 | return false; |
| 2241 | } |
| 2242 | return true; |
| 2243 | |
| 2244 | case GL_FRAMEBUFFER: |
| 2245 | if (context->getFramebuffer(name) == nullptr) |
| 2246 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2247 | context->handleError(InvalidValue() << "name is not a valid framebuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2248 | return false; |
| 2249 | } |
| 2250 | return true; |
| 2251 | |
| 2252 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2253 | context->handleError(InvalidEnum() << "Invalid identifier."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2254 | return false; |
| 2255 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2256 | } |
| 2257 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2258 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2259 | { |
| 2260 | size_t labelLength = 0; |
| 2261 | |
| 2262 | if (length < 0) |
| 2263 | { |
| 2264 | if (label != nullptr) |
| 2265 | { |
| 2266 | labelLength = strlen(label); |
| 2267 | } |
| 2268 | } |
| 2269 | else |
| 2270 | { |
| 2271 | labelLength = static_cast<size_t>(length); |
| 2272 | } |
| 2273 | |
| 2274 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2275 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2276 | context->handleError(InvalidValue() << "Label length is larger than GL_MAX_LABEL_LENGTH."); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2277 | return false; |
| 2278 | } |
| 2279 | |
| 2280 | return true; |
| 2281 | } |
| 2282 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2283 | bool ValidateObjectLabelKHR(Context *context, |
| 2284 | GLenum identifier, |
| 2285 | GLuint name, |
| 2286 | GLsizei length, |
| 2287 | const GLchar *label) |
| 2288 | { |
| 2289 | if (!context->getExtensions().debug) |
| 2290 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2291 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2292 | return false; |
| 2293 | } |
| 2294 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2295 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2296 | { |
| 2297 | return false; |
| 2298 | } |
| 2299 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2300 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2301 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2302 | return false; |
| 2303 | } |
| 2304 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2305 | return true; |
| 2306 | } |
| 2307 | |
| 2308 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2309 | GLenum identifier, |
| 2310 | GLuint name, |
| 2311 | GLsizei bufSize, |
| 2312 | GLsizei *length, |
| 2313 | GLchar *label) |
| 2314 | { |
| 2315 | if (!context->getExtensions().debug) |
| 2316 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2317 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2318 | return false; |
| 2319 | } |
| 2320 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2321 | if (bufSize < 0) |
| 2322 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2323 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2324 | return false; |
| 2325 | } |
| 2326 | |
| 2327 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2328 | { |
| 2329 | return false; |
| 2330 | } |
| 2331 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2332 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2336 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 2337 | if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2338 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2339 | context->handleError(InvalidValue() << "name is not a valid sync."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2340 | return false; |
| 2341 | } |
| 2342 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2343 | return true; |
| 2344 | } |
| 2345 | |
| 2346 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2347 | const void *ptr, |
| 2348 | GLsizei length, |
| 2349 | const GLchar *label) |
| 2350 | { |
| 2351 | if (!context->getExtensions().debug) |
| 2352 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2353 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2354 | return false; |
| 2355 | } |
| 2356 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2357 | if (!ValidateObjectPtrName(context, ptr)) |
| 2358 | { |
| 2359 | return false; |
| 2360 | } |
| 2361 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2362 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2363 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2364 | return false; |
| 2365 | } |
| 2366 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2367 | return true; |
| 2368 | } |
| 2369 | |
| 2370 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2371 | const void *ptr, |
| 2372 | GLsizei bufSize, |
| 2373 | GLsizei *length, |
| 2374 | GLchar *label) |
| 2375 | { |
| 2376 | if (!context->getExtensions().debug) |
| 2377 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2378 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2379 | return false; |
| 2380 | } |
| 2381 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2382 | if (bufSize < 0) |
| 2383 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2384 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2385 | return false; |
| 2386 | } |
| 2387 | |
| 2388 | if (!ValidateObjectPtrName(context, ptr)) |
| 2389 | { |
| 2390 | return false; |
| 2391 | } |
| 2392 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2393 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2397 | { |
| 2398 | if (!context->getExtensions().debug) |
| 2399 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2400 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2401 | return false; |
| 2402 | } |
| 2403 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2404 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2405 | switch (pname) |
| 2406 | { |
| 2407 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2408 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2409 | break; |
| 2410 | |
| 2411 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2412 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2413 | return false; |
| 2414 | } |
| 2415 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2416 | return true; |
| 2417 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2418 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 2419 | bool ValidateGetPointervRobustANGLERobustANGLE(Context *context, |
| 2420 | GLenum pname, |
| 2421 | GLsizei bufSize, |
| 2422 | GLsizei *length, |
| 2423 | void **params) |
| 2424 | { |
| 2425 | UNIMPLEMENTED(); |
| 2426 | return false; |
| 2427 | } |
| 2428 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2429 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2430 | GLint srcX0, |
| 2431 | GLint srcY0, |
| 2432 | GLint srcX1, |
| 2433 | GLint srcY1, |
| 2434 | GLint dstX0, |
| 2435 | GLint dstY0, |
| 2436 | GLint dstX1, |
| 2437 | GLint dstY1, |
| 2438 | GLbitfield mask, |
| 2439 | GLenum filter) |
| 2440 | { |
| 2441 | if (!context->getExtensions().framebufferBlit) |
| 2442 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame^] | 2443 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitExtensionNotAvailable); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2444 | return false; |
| 2445 | } |
| 2446 | |
| 2447 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2448 | { |
| 2449 | // TODO(jmadill): Determine if this should be available on other implementations. |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame^] | 2450 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitExtensionScaleOrFlip); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2451 | return false; |
| 2452 | } |
| 2453 | |
| 2454 | if (filter == GL_LINEAR) |
| 2455 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame^] | 2456 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), BlitExtensionLinear); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2457 | return false; |
| 2458 | } |
| 2459 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2460 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2461 | Framebuffer *drawFramebuffer = context->getGLState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2462 | |
| 2463 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2464 | { |
| 2465 | const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 2466 | const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer(); |
| 2467 | |
| 2468 | if (readColorAttachment && drawColorAttachment) |
| 2469 | { |
| 2470 | if (!(readColorAttachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2471 | readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2472 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2473 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2474 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame^] | 2475 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2476 | BlitExtensionFromInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2477 | return false; |
| 2478 | } |
| 2479 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2480 | for (size_t drawbufferIdx = 0; |
| 2481 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2482 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2483 | const FramebufferAttachment *attachment = |
| 2484 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2485 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2486 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2487 | if (!(attachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2488 | attachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2489 | attachment->type() != GL_RENDERBUFFER && |
| 2490 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2491 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame^] | 2492 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2493 | BlitExtensionToInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2494 | return false; |
| 2495 | } |
| 2496 | |
| 2497 | // Return an error if the destination formats do not match |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 2498 | if (!Format::EquivalentForBlit(attachment->getFormat(), |
| 2499 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2500 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame^] | 2501 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2502 | BlitExtensionFormatMismatch); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2503 | return false; |
| 2504 | } |
| 2505 | } |
| 2506 | } |
| 2507 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2508 | GLint samples = readFramebuffer->getSamples(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2509 | if (samples != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2510 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2511 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2512 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame^] | 2513 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2514 | BlitExtensionMultisampledWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2515 | return false; |
| 2516 | } |
| 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2521 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2522 | for (size_t i = 0; i < 2; i++) |
| 2523 | { |
| 2524 | if (mask & masks[i]) |
| 2525 | { |
| 2526 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2527 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2528 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2529 | drawFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2530 | |
| 2531 | if (readBuffer && drawBuffer) |
| 2532 | { |
| 2533 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2534 | dstX0, dstY0, dstX1, dstY1)) |
| 2535 | { |
| 2536 | // only whole-buffer copies are permitted |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame^] | 2537 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2538 | BlitExtensionDepthStencilWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2539 | return false; |
| 2540 | } |
| 2541 | |
| 2542 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2543 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame^] | 2544 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2545 | BlitExtensionMultisampledDepthOrStencil); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2546 | return false; |
| 2547 | } |
| 2548 | } |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2553 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2554 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2555 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2556 | bool ValidateClear(Context *context, GLbitfield mask) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2557 | { |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2558 | Framebuffer *fbo = context->getGLState().getDrawFramebuffer(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2559 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2560 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2561 | if (!ValidateFramebufferComplete(context, fbo)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2562 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2563 | return false; |
| 2564 | } |
| 2565 | |
| 2566 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2567 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2568 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidClearMask); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2569 | return false; |
| 2570 | } |
| 2571 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2572 | if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2573 | { |
| 2574 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2575 | GL_SIGNED_NORMALIZED}; |
| 2576 | |
Corentin Wallez | 59c4159 | 2017-07-11 13:19:54 -0400 | [diff] [blame] | 2577 | for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2578 | drawBufferIdx++) |
| 2579 | { |
| 2580 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2581 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2582 | { |
| 2583 | return false; |
| 2584 | } |
| 2585 | } |
| 2586 | } |
| 2587 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2588 | if (extensions.multiview && extensions.disjointTimerQuery) |
| 2589 | { |
| 2590 | const State &state = context->getGLState(); |
| 2591 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2592 | if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed)) |
| 2593 | { |
| 2594 | context->handleError(InvalidOperation() << "There is an active query for target " |
| 2595 | "GL_TIME_ELAPSED_EXT when the number of " |
| 2596 | "views in the active draw framebuffer is " |
| 2597 | "greater than 1."); |
| 2598 | return false; |
| 2599 | } |
| 2600 | } |
| 2601 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2602 | return true; |
| 2603 | } |
| 2604 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2605 | bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2606 | { |
| 2607 | if (!context->getExtensions().drawBuffers) |
| 2608 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2609 | context->handleError(InvalidOperation() << "Extension not supported."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2610 | return false; |
| 2611 | } |
| 2612 | |
| 2613 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2614 | } |
| 2615 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2616 | bool ValidateTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2617 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2618 | GLint level, |
| 2619 | GLint internalformat, |
| 2620 | GLsizei width, |
| 2621 | GLsizei height, |
| 2622 | GLint border, |
| 2623 | GLenum format, |
| 2624 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2625 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2626 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2627 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2628 | { |
| 2629 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2630 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2631 | } |
| 2632 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2633 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2634 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2635 | 0, 0, width, height, 1, border, format, type, -1, |
| 2636 | pixels); |
| 2637 | } |
| 2638 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 2639 | bool ValidateTexImage2DRobustANGLE(Context *context, |
| 2640 | TextureTarget target, |
| 2641 | GLint level, |
| 2642 | GLint internalformat, |
| 2643 | GLsizei width, |
| 2644 | GLsizei height, |
| 2645 | GLint border, |
| 2646 | GLenum format, |
| 2647 | GLenum type, |
| 2648 | GLsizei bufSize, |
| 2649 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2650 | { |
| 2651 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2652 | { |
| 2653 | return false; |
| 2654 | } |
| 2655 | |
| 2656 | if (context->getClientMajorVersion() < 3) |
| 2657 | { |
| 2658 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2659 | 0, 0, width, height, border, format, type, bufSize, |
| 2660 | pixels); |
| 2661 | } |
| 2662 | |
| 2663 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2664 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2665 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2666 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2667 | } |
| 2668 | |
| 2669 | bool ValidateTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2670 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2671 | GLint level, |
| 2672 | GLint xoffset, |
| 2673 | GLint yoffset, |
| 2674 | GLsizei width, |
| 2675 | GLsizei height, |
| 2676 | GLenum format, |
| 2677 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2678 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2679 | { |
| 2680 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2681 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2682 | { |
| 2683 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2684 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2685 | } |
| 2686 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2687 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2688 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2689 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 2690 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2691 | } |
| 2692 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2693 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2694 | TextureTarget target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2695 | GLint level, |
| 2696 | GLint xoffset, |
| 2697 | GLint yoffset, |
| 2698 | GLsizei width, |
| 2699 | GLsizei height, |
| 2700 | GLenum format, |
| 2701 | GLenum type, |
| 2702 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2703 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2704 | { |
| 2705 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2706 | { |
| 2707 | return false; |
| 2708 | } |
| 2709 | |
| 2710 | if (context->getClientMajorVersion() < 3) |
| 2711 | { |
| 2712 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2713 | yoffset, width, height, 0, format, type, bufSize, |
| 2714 | pixels); |
| 2715 | } |
| 2716 | |
| 2717 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2718 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2719 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 2720 | pixels); |
| 2721 | } |
| 2722 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2723 | bool ValidateCompressedTexImage2D(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 | GLenum internalformat, |
| 2727 | GLsizei width, |
| 2728 | GLsizei height, |
| 2729 | GLint border, |
| 2730 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2731 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2732 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2733 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2734 | { |
| 2735 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2736 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2737 | { |
| 2738 | return false; |
| 2739 | } |
| 2740 | } |
| 2741 | else |
| 2742 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2743 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2744 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2745 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2746 | data)) |
| 2747 | { |
| 2748 | return false; |
| 2749 | } |
| 2750 | } |
| 2751 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2752 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2753 | |
| 2754 | GLuint blockSize = 0; |
| 2755 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2756 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2757 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2758 | return false; |
| 2759 | } |
| 2760 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2761 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2762 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2763 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CompressedTextureDimensionsMustMatchData); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2764 | return false; |
| 2765 | } |
| 2766 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2767 | if (target == TextureTarget::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2768 | { |
| 2769 | context->handleError(InvalidEnum() << "Rectangle texture cannot have a compressed format."); |
| 2770 | return false; |
| 2771 | } |
| 2772 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2773 | return true; |
| 2774 | } |
| 2775 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2776 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2777 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2778 | GLint level, |
| 2779 | GLenum internalformat, |
| 2780 | GLsizei width, |
| 2781 | GLsizei height, |
| 2782 | GLint border, |
| 2783 | GLsizei imageSize, |
| 2784 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2785 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2786 | { |
| 2787 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2788 | { |
| 2789 | return false; |
| 2790 | } |
| 2791 | |
| 2792 | return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 2793 | border, imageSize, data); |
| 2794 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2795 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2796 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2797 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2798 | GLint level, |
| 2799 | GLint xoffset, |
| 2800 | GLint yoffset, |
| 2801 | GLsizei width, |
| 2802 | GLsizei height, |
| 2803 | GLenum format, |
| 2804 | GLsizei imageSize, |
| 2805 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2806 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2807 | { |
| 2808 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2809 | { |
| 2810 | return false; |
| 2811 | } |
| 2812 | |
| 2813 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 2814 | format, imageSize, data); |
| 2815 | } |
| 2816 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2817 | bool ValidateCompressedTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2818 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2819 | GLint level, |
| 2820 | GLint xoffset, |
| 2821 | GLint yoffset, |
| 2822 | GLsizei width, |
| 2823 | GLsizei height, |
| 2824 | GLenum format, |
| 2825 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2826 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2827 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2828 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2829 | { |
| 2830 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2831 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2832 | { |
| 2833 | return false; |
| 2834 | } |
| 2835 | } |
| 2836 | else |
| 2837 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2838 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2839 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2840 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2841 | data)) |
| 2842 | { |
| 2843 | return false; |
| 2844 | } |
| 2845 | } |
| 2846 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2847 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2848 | GLuint blockSize = 0; |
| 2849 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2850 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2851 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2852 | return false; |
| 2853 | } |
| 2854 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2855 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2856 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2857 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2858 | return false; |
| 2859 | } |
| 2860 | |
| 2861 | return true; |
| 2862 | } |
| 2863 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2864 | bool ValidateGetBufferPointervOES(Context *context, |
| 2865 | BufferBinding target, |
| 2866 | GLenum pname, |
| 2867 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2868 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2869 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2870 | } |
| 2871 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2872 | bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2873 | { |
| 2874 | if (!context->getExtensions().mapBuffer) |
| 2875 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2876 | context->handleError(InvalidOperation() << "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2877 | return false; |
| 2878 | } |
| 2879 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 2880 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2881 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2882 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2883 | return false; |
| 2884 | } |
| 2885 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2886 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2887 | |
| 2888 | if (buffer == nullptr) |
| 2889 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2890 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2891 | return false; |
| 2892 | } |
| 2893 | |
| 2894 | if (access != GL_WRITE_ONLY_OES) |
| 2895 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2896 | context->handleError(InvalidEnum() << "Non-write buffer mapping not supported."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2897 | return false; |
| 2898 | } |
| 2899 | |
| 2900 | if (buffer->isMapped()) |
| 2901 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2902 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2903 | return false; |
| 2904 | } |
| 2905 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 2906 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2907 | } |
| 2908 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2909 | bool ValidateUnmapBufferOES(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2910 | { |
| 2911 | if (!context->getExtensions().mapBuffer) |
| 2912 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2913 | context->handleError(InvalidOperation() << "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2914 | return false; |
| 2915 | } |
| 2916 | |
| 2917 | return ValidateUnmapBufferBase(context, target); |
| 2918 | } |
| 2919 | |
| 2920 | bool ValidateMapBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2921 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2922 | GLintptr offset, |
| 2923 | GLsizeiptr length, |
| 2924 | GLbitfield access) |
| 2925 | { |
| 2926 | if (!context->getExtensions().mapBufferRange) |
| 2927 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2928 | context->handleError(InvalidOperation() << "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2929 | return false; |
| 2930 | } |
| 2931 | |
| 2932 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 2933 | } |
| 2934 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2935 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 2936 | { |
| 2937 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 2938 | ASSERT(buffer != nullptr); |
| 2939 | |
| 2940 | // Check if this buffer is currently being used as a transform feedback output buffer |
| 2941 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
| 2942 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 2943 | { |
| 2944 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 2945 | { |
| 2946 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 2947 | if (transformFeedbackBuffer.get() == buffer) |
| 2948 | { |
| 2949 | context->handleError(InvalidOperation() |
| 2950 | << "Buffer is currently bound for transform feedback."); |
| 2951 | return false; |
| 2952 | } |
| 2953 | } |
| 2954 | } |
| 2955 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2956 | if (context->getExtensions().webglCompatibility && |
| 2957 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2958 | { |
| 2959 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferBoundForTransformFeedback); |
| 2960 | return false; |
| 2961 | } |
| 2962 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 2963 | return true; |
| 2964 | } |
| 2965 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2966 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2967 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2968 | GLintptr offset, |
| 2969 | GLsizeiptr length) |
| 2970 | { |
| 2971 | if (!context->getExtensions().mapBufferRange) |
| 2972 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2973 | context->handleError(InvalidOperation() << "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2974 | return false; |
| 2975 | } |
| 2976 | |
| 2977 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 2978 | } |
| 2979 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2980 | bool ValidateBindTexture(Context *context, TextureType target, GLuint texture) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2981 | { |
| 2982 | Texture *textureObject = context->getTexture(texture); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2983 | if (textureObject && textureObject->getType() != target && texture != 0) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2984 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2985 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TypeMismatch); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2986 | return false; |
| 2987 | } |
| 2988 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 2989 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 2990 | !context->isTextureGenerated(texture)) |
| 2991 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2992 | context->handleError(InvalidOperation() << "Texture was not generated"); |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 2993 | return false; |
| 2994 | } |
| 2995 | |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2996 | switch (target) |
| 2997 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2998 | case TextureType::_2D: |
| 2999 | case TextureType::CubeMap: |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3000 | break; |
| 3001 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3002 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 3003 | if (!context->getExtensions().textureRectangle) |
| 3004 | { |
| 3005 | context->handleError(InvalidEnum() |
| 3006 | << "Context does not support GL_ANGLE_texture_rectangle"); |
| 3007 | return false; |
| 3008 | } |
| 3009 | break; |
| 3010 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3011 | case TextureType::_3D: |
| 3012 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3013 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3014 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3015 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3016 | return false; |
| 3017 | } |
| 3018 | break; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 3019 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3020 | case TextureType::_2DMultisample: |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 3021 | if (context->getClientVersion() < Version(3, 1)) |
| 3022 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3023 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 3024 | return false; |
| 3025 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 3026 | break; |
| 3027 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3028 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3029 | if (!context->getExtensions().eglImageExternal && |
| 3030 | !context->getExtensions().eglStreamConsumerExternal) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3031 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3032 | context->handleError(InvalidEnum() << "External texture extension not enabled"); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3033 | return false; |
| 3034 | } |
| 3035 | break; |
| 3036 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3037 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3038 | return false; |
| 3039 | } |
| 3040 | |
| 3041 | return true; |
| 3042 | } |
| 3043 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3044 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 3045 | GLuint program, |
| 3046 | GLint location, |
| 3047 | const GLchar *name) |
| 3048 | { |
| 3049 | if (!context->getExtensions().bindUniformLocation) |
| 3050 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3051 | context->handleError(InvalidOperation() |
| 3052 | << "GL_CHROMIUM_bind_uniform_location is not available."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3053 | return false; |
| 3054 | } |
| 3055 | |
| 3056 | Program *programObject = GetValidProgram(context, program); |
| 3057 | if (!programObject) |
| 3058 | { |
| 3059 | return false; |
| 3060 | } |
| 3061 | |
| 3062 | if (location < 0) |
| 3063 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3064 | context->handleError(InvalidValue() << "Location cannot be less than 0."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3065 | return false; |
| 3066 | } |
| 3067 | |
| 3068 | const Caps &caps = context->getCaps(); |
| 3069 | if (static_cast<size_t>(location) >= |
| 3070 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3071 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3072 | context->handleError(InvalidValue() << "Location must be less than " |
| 3073 | "(MAX_VERTEX_UNIFORM_VECTORS + " |
| 3074 | "MAX_FRAGMENT_UNIFORM_VECTORS) * 4"); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3075 | return false; |
| 3076 | } |
| 3077 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3078 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3079 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3080 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3081 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3082 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3083 | return false; |
| 3084 | } |
| 3085 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3086 | if (strncmp(name, "gl_", 3) == 0) |
| 3087 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3088 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3089 | return false; |
| 3090 | } |
| 3091 | |
| 3092 | return true; |
| 3093 | } |
| 3094 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3095 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3096 | { |
| 3097 | if (!context->getExtensions().framebufferMixedSamples) |
| 3098 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3099 | context->handleError(InvalidOperation() |
| 3100 | << "GL_CHROMIUM_framebuffer_mixed_samples is not available."); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3101 | return false; |
| 3102 | } |
| 3103 | switch (components) |
| 3104 | { |
| 3105 | case GL_RGB: |
| 3106 | case GL_RGBA: |
| 3107 | case GL_ALPHA: |
| 3108 | case GL_NONE: |
| 3109 | break; |
| 3110 | default: |
| 3111 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3112 | InvalidEnum() |
| 3113 | << "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] | 3114 | return false; |
| 3115 | } |
| 3116 | |
| 3117 | return true; |
| 3118 | } |
| 3119 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3120 | // CHROMIUM_path_rendering |
| 3121 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3122 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3123 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3124 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3125 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3126 | return false; |
| 3127 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3128 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3129 | if (matrix == nullptr) |
| 3130 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3131 | context->handleError(InvalidOperation() << "Invalid matrix."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3132 | return false; |
| 3133 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3134 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3135 | return true; |
| 3136 | } |
| 3137 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3138 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3139 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3140 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3141 | } |
| 3142 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3143 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3144 | { |
| 3145 | if (!context->getExtensions().pathRendering) |
| 3146 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3147 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3148 | return false; |
| 3149 | } |
| 3150 | |
| 3151 | // range = 0 is undefined in NV_path_rendering. |
| 3152 | // we add stricter semantic check here and require a non zero positive range. |
| 3153 | if (range <= 0) |
| 3154 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3155 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3156 | return false; |
| 3157 | } |
| 3158 | |
| 3159 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3160 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3161 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3162 | return false; |
| 3163 | } |
| 3164 | |
| 3165 | return true; |
| 3166 | } |
| 3167 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3168 | bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3169 | { |
| 3170 | if (!context->getExtensions().pathRendering) |
| 3171 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3172 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3173 | return false; |
| 3174 | } |
| 3175 | |
| 3176 | // range = 0 is undefined in NV_path_rendering. |
| 3177 | // we add stricter semantic check here and require a non zero positive range. |
| 3178 | if (range <= 0) |
| 3179 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3180 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3181 | return false; |
| 3182 | } |
| 3183 | |
| 3184 | angle::CheckedNumeric<std::uint32_t> checkedRange(path); |
| 3185 | checkedRange += range; |
| 3186 | |
| 3187 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3188 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3189 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3190 | return false; |
| 3191 | } |
| 3192 | return true; |
| 3193 | } |
| 3194 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3195 | bool ValidatePathCommandsCHROMIUM(Context *context, |
| 3196 | GLuint path, |
| 3197 | GLsizei numCommands, |
| 3198 | const GLubyte *commands, |
| 3199 | GLsizei numCoords, |
| 3200 | GLenum coordType, |
| 3201 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3202 | { |
| 3203 | if (!context->getExtensions().pathRendering) |
| 3204 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3205 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3206 | return false; |
| 3207 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3208 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3209 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3210 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3211 | return false; |
| 3212 | } |
| 3213 | |
| 3214 | if (numCommands < 0) |
| 3215 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3216 | context->handleError(InvalidValue() << "Invalid number of commands."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3217 | return false; |
| 3218 | } |
| 3219 | else if (numCommands > 0) |
| 3220 | { |
| 3221 | if (!commands) |
| 3222 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3223 | context->handleError(InvalidValue() << "No commands array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3224 | return false; |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | if (numCoords < 0) |
| 3229 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3230 | context->handleError(InvalidValue() << "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3231 | return false; |
| 3232 | } |
| 3233 | else if (numCoords > 0) |
| 3234 | { |
| 3235 | if (!coords) |
| 3236 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3237 | context->handleError(InvalidValue() << "No coordinate array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3238 | return false; |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | std::uint32_t coordTypeSize = 0; |
| 3243 | switch (coordType) |
| 3244 | { |
| 3245 | case GL_BYTE: |
| 3246 | coordTypeSize = sizeof(GLbyte); |
| 3247 | break; |
| 3248 | |
| 3249 | case GL_UNSIGNED_BYTE: |
| 3250 | coordTypeSize = sizeof(GLubyte); |
| 3251 | break; |
| 3252 | |
| 3253 | case GL_SHORT: |
| 3254 | coordTypeSize = sizeof(GLshort); |
| 3255 | break; |
| 3256 | |
| 3257 | case GL_UNSIGNED_SHORT: |
| 3258 | coordTypeSize = sizeof(GLushort); |
| 3259 | break; |
| 3260 | |
| 3261 | case GL_FLOAT: |
| 3262 | coordTypeSize = sizeof(GLfloat); |
| 3263 | break; |
| 3264 | |
| 3265 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3266 | context->handleError(InvalidEnum() << "Invalid coordinate type."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3267 | return false; |
| 3268 | } |
| 3269 | |
| 3270 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3271 | checkedSize += (coordTypeSize * numCoords); |
| 3272 | if (!checkedSize.IsValid()) |
| 3273 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3274 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3275 | return false; |
| 3276 | } |
| 3277 | |
| 3278 | // early return skips command data validation when it doesn't exist. |
| 3279 | if (!commands) |
| 3280 | return true; |
| 3281 | |
| 3282 | GLsizei expectedNumCoords = 0; |
| 3283 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3284 | { |
| 3285 | switch (commands[i]) |
| 3286 | { |
| 3287 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3288 | break; |
| 3289 | case GL_MOVE_TO_CHROMIUM: |
| 3290 | case GL_LINE_TO_CHROMIUM: |
| 3291 | expectedNumCoords += 2; |
| 3292 | break; |
| 3293 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3294 | expectedNumCoords += 4; |
| 3295 | break; |
| 3296 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3297 | expectedNumCoords += 6; |
| 3298 | break; |
| 3299 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3300 | expectedNumCoords += 5; |
| 3301 | break; |
| 3302 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3303 | context->handleError(InvalidEnum() << "Invalid command."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3304 | return false; |
| 3305 | } |
| 3306 | } |
| 3307 | if (expectedNumCoords != numCoords) |
| 3308 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3309 | context->handleError(InvalidValue() << "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3310 | return false; |
| 3311 | } |
| 3312 | |
| 3313 | return true; |
| 3314 | } |
| 3315 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3316 | bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3317 | { |
| 3318 | if (!context->getExtensions().pathRendering) |
| 3319 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3320 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3321 | return false; |
| 3322 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3323 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3324 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3325 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3326 | return false; |
| 3327 | } |
| 3328 | |
| 3329 | switch (pname) |
| 3330 | { |
| 3331 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3332 | if (value < 0.0f) |
| 3333 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3334 | context->handleError(InvalidValue() << "Invalid stroke width."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3335 | return false; |
| 3336 | } |
| 3337 | break; |
| 3338 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3339 | switch (static_cast<GLenum>(value)) |
| 3340 | { |
| 3341 | case GL_FLAT_CHROMIUM: |
| 3342 | case GL_SQUARE_CHROMIUM: |
| 3343 | case GL_ROUND_CHROMIUM: |
| 3344 | break; |
| 3345 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3346 | context->handleError(InvalidEnum() << "Invalid end caps."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3347 | return false; |
| 3348 | } |
| 3349 | break; |
| 3350 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3351 | switch (static_cast<GLenum>(value)) |
| 3352 | { |
| 3353 | case GL_MITER_REVERT_CHROMIUM: |
| 3354 | case GL_BEVEL_CHROMIUM: |
| 3355 | case GL_ROUND_CHROMIUM: |
| 3356 | break; |
| 3357 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3358 | context->handleError(InvalidEnum() << "Invalid join style."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3359 | return false; |
| 3360 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3361 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3362 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3363 | if (value < 0.0f) |
| 3364 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3365 | context->handleError(InvalidValue() << "Invalid miter limit."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3366 | return false; |
| 3367 | } |
| 3368 | break; |
| 3369 | |
| 3370 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3371 | // no errors, only clamping. |
| 3372 | break; |
| 3373 | |
| 3374 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3375 | context->handleError(InvalidEnum() << "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3376 | return false; |
| 3377 | } |
| 3378 | return true; |
| 3379 | } |
| 3380 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3381 | bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value) |
| 3382 | { |
| 3383 | // TODO(jmadill): Use proper clamping cast. |
| 3384 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 3385 | } |
| 3386 | |
| 3387 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3388 | { |
| 3389 | if (!context->getExtensions().pathRendering) |
| 3390 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3391 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3392 | return false; |
| 3393 | } |
| 3394 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3395 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3396 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3397 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3398 | return false; |
| 3399 | } |
| 3400 | if (!value) |
| 3401 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3402 | context->handleError(InvalidValue() << "No value array."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3403 | return false; |
| 3404 | } |
| 3405 | |
| 3406 | switch (pname) |
| 3407 | { |
| 3408 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3409 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3410 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3411 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3412 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3413 | break; |
| 3414 | |
| 3415 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3416 | context->handleError(InvalidEnum() << "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3417 | return false; |
| 3418 | } |
| 3419 | |
| 3420 | return true; |
| 3421 | } |
| 3422 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3423 | bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value) |
| 3424 | { |
| 3425 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 3426 | reinterpret_cast<GLfloat *>(value)); |
| 3427 | } |
| 3428 | |
| 3429 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3430 | { |
| 3431 | if (!context->getExtensions().pathRendering) |
| 3432 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3433 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3434 | return false; |
| 3435 | } |
| 3436 | |
| 3437 | switch (func) |
| 3438 | { |
| 3439 | case GL_NEVER: |
| 3440 | case GL_ALWAYS: |
| 3441 | case GL_LESS: |
| 3442 | case GL_LEQUAL: |
| 3443 | case GL_EQUAL: |
| 3444 | case GL_GEQUAL: |
| 3445 | case GL_GREATER: |
| 3446 | case GL_NOTEQUAL: |
| 3447 | break; |
| 3448 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3449 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3450 | return false; |
| 3451 | } |
| 3452 | |
| 3453 | return true; |
| 3454 | } |
| 3455 | |
| 3456 | // Note that the spec specifies that for the path drawing commands |
| 3457 | // if the path object is not an existing path object the command |
| 3458 | // does nothing and no error is generated. |
| 3459 | // However if the path object exists but has not been specified any |
| 3460 | // commands then an error is generated. |
| 3461 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3462 | bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3463 | { |
| 3464 | if (!context->getExtensions().pathRendering) |
| 3465 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3466 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3467 | return false; |
| 3468 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3469 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3470 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3471 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3472 | return false; |
| 3473 | } |
| 3474 | |
| 3475 | switch (fillMode) |
| 3476 | { |
| 3477 | case GL_COUNT_UP_CHROMIUM: |
| 3478 | case GL_COUNT_DOWN_CHROMIUM: |
| 3479 | break; |
| 3480 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3481 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3482 | return false; |
| 3483 | } |
| 3484 | |
| 3485 | if (!isPow2(mask + 1)) |
| 3486 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3487 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3488 | return false; |
| 3489 | } |
| 3490 | |
| 3491 | return true; |
| 3492 | } |
| 3493 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3494 | bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3495 | { |
| 3496 | if (!context->getExtensions().pathRendering) |
| 3497 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3498 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3499 | return false; |
| 3500 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3501 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3502 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3503 | 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] | 3504 | return false; |
| 3505 | } |
| 3506 | |
| 3507 | return true; |
| 3508 | } |
| 3509 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3510 | bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3511 | { |
| 3512 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3513 | } |
| 3514 | |
| 3515 | bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3516 | { |
| 3517 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3518 | } |
| 3519 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3520 | bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3521 | { |
| 3522 | if (!context->getExtensions().pathRendering) |
| 3523 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3524 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3525 | return false; |
| 3526 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3527 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3528 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3529 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3530 | return false; |
| 3531 | } |
| 3532 | |
| 3533 | switch (coverMode) |
| 3534 | { |
| 3535 | case GL_CONVEX_HULL_CHROMIUM: |
| 3536 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3537 | break; |
| 3538 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3539 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3540 | return false; |
| 3541 | } |
| 3542 | return true; |
| 3543 | } |
| 3544 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3545 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
| 3546 | GLuint path, |
| 3547 | GLenum fillMode, |
| 3548 | GLuint mask, |
| 3549 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3550 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3551 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 3552 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3553 | } |
| 3554 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3555 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
| 3556 | GLuint path, |
| 3557 | GLint reference, |
| 3558 | GLuint mask, |
| 3559 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3560 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3561 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 3562 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3563 | } |
| 3564 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3565 | bool ValidateIsPathCHROMIUM(Context *context, GLuint path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3566 | { |
| 3567 | if (!context->getExtensions().pathRendering) |
| 3568 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3569 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3570 | return false; |
| 3571 | } |
| 3572 | return true; |
| 3573 | } |
| 3574 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3575 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 3576 | GLsizei numPaths, |
| 3577 | GLenum pathNameType, |
| 3578 | const void *paths, |
| 3579 | GLuint pathBase, |
| 3580 | GLenum coverMode, |
| 3581 | GLenum transformType, |
| 3582 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3583 | { |
| 3584 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3585 | transformType, transformValues)) |
| 3586 | return false; |
| 3587 | |
| 3588 | switch (coverMode) |
| 3589 | { |
| 3590 | case GL_CONVEX_HULL_CHROMIUM: |
| 3591 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3592 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3593 | break; |
| 3594 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3595 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3596 | return false; |
| 3597 | } |
| 3598 | |
| 3599 | return true; |
| 3600 | } |
| 3601 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3602 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3603 | GLsizei numPaths, |
| 3604 | GLenum pathNameType, |
| 3605 | const void *paths, |
| 3606 | GLuint pathBase, |
| 3607 | GLenum coverMode, |
| 3608 | GLenum transformType, |
| 3609 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3610 | { |
| 3611 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3612 | transformType, transformValues)) |
| 3613 | return false; |
| 3614 | |
| 3615 | switch (coverMode) |
| 3616 | { |
| 3617 | case GL_CONVEX_HULL_CHROMIUM: |
| 3618 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3619 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3620 | break; |
| 3621 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3622 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3623 | return false; |
| 3624 | } |
| 3625 | |
| 3626 | return true; |
| 3627 | } |
| 3628 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3629 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 3630 | GLsizei numPaths, |
| 3631 | GLenum pathNameType, |
| 3632 | const void *paths, |
| 3633 | GLuint pathBase, |
| 3634 | GLenum fillMode, |
| 3635 | GLuint mask, |
| 3636 | GLenum transformType, |
| 3637 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3638 | { |
| 3639 | |
| 3640 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3641 | transformType, transformValues)) |
| 3642 | return false; |
| 3643 | |
| 3644 | switch (fillMode) |
| 3645 | { |
| 3646 | case GL_COUNT_UP_CHROMIUM: |
| 3647 | case GL_COUNT_DOWN_CHROMIUM: |
| 3648 | break; |
| 3649 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3650 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3651 | return false; |
| 3652 | } |
| 3653 | if (!isPow2(mask + 1)) |
| 3654 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3655 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3656 | return false; |
| 3657 | } |
| 3658 | return true; |
| 3659 | } |
| 3660 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3661 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 3662 | GLsizei numPaths, |
| 3663 | GLenum pathNameType, |
| 3664 | const void *paths, |
| 3665 | GLuint pathBase, |
| 3666 | GLint reference, |
| 3667 | GLuint mask, |
| 3668 | GLenum transformType, |
| 3669 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3670 | { |
| 3671 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3672 | transformType, transformValues)) |
| 3673 | return false; |
| 3674 | |
| 3675 | // no more validation here. |
| 3676 | |
| 3677 | return true; |
| 3678 | } |
| 3679 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3680 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 3681 | GLsizei numPaths, |
| 3682 | GLenum pathNameType, |
| 3683 | const void *paths, |
| 3684 | GLuint pathBase, |
| 3685 | GLenum fillMode, |
| 3686 | GLuint mask, |
| 3687 | GLenum coverMode, |
| 3688 | GLenum transformType, |
| 3689 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3690 | { |
| 3691 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3692 | transformType, transformValues)) |
| 3693 | return false; |
| 3694 | |
| 3695 | switch (coverMode) |
| 3696 | { |
| 3697 | case GL_CONVEX_HULL_CHROMIUM: |
| 3698 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3699 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3700 | break; |
| 3701 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3702 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3703 | return false; |
| 3704 | } |
| 3705 | |
| 3706 | switch (fillMode) |
| 3707 | { |
| 3708 | case GL_COUNT_UP_CHROMIUM: |
| 3709 | case GL_COUNT_DOWN_CHROMIUM: |
| 3710 | break; |
| 3711 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3712 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3713 | return false; |
| 3714 | } |
| 3715 | if (!isPow2(mask + 1)) |
| 3716 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3717 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3718 | return false; |
| 3719 | } |
| 3720 | |
| 3721 | return true; |
| 3722 | } |
| 3723 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3724 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3725 | GLsizei numPaths, |
| 3726 | GLenum pathNameType, |
| 3727 | const void *paths, |
| 3728 | GLuint pathBase, |
| 3729 | GLint reference, |
| 3730 | GLuint mask, |
| 3731 | GLenum coverMode, |
| 3732 | GLenum transformType, |
| 3733 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3734 | { |
| 3735 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3736 | transformType, transformValues)) |
| 3737 | return false; |
| 3738 | |
| 3739 | switch (coverMode) |
| 3740 | { |
| 3741 | case GL_CONVEX_HULL_CHROMIUM: |
| 3742 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3743 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3744 | break; |
| 3745 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3746 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3747 | return false; |
| 3748 | } |
| 3749 | |
| 3750 | return true; |
| 3751 | } |
| 3752 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3753 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
| 3754 | GLuint program, |
| 3755 | GLint location, |
| 3756 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3757 | { |
| 3758 | if (!context->getExtensions().pathRendering) |
| 3759 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3760 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3761 | return false; |
| 3762 | } |
| 3763 | |
| 3764 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 3765 | if (location >= MaxLocation) |
| 3766 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3767 | context->handleError(InvalidValue() << "Location exceeds max varying."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3768 | return false; |
| 3769 | } |
| 3770 | |
| 3771 | const auto *programObject = context->getProgram(program); |
| 3772 | if (!programObject) |
| 3773 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3774 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3775 | return false; |
| 3776 | } |
| 3777 | |
| 3778 | if (!name) |
| 3779 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3780 | context->handleError(InvalidValue() << "No name given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3781 | return false; |
| 3782 | } |
| 3783 | |
| 3784 | if (angle::BeginsWith(name, "gl_")) |
| 3785 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3786 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3787 | return false; |
| 3788 | } |
| 3789 | |
| 3790 | return true; |
| 3791 | } |
| 3792 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3793 | bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
| 3794 | GLuint program, |
| 3795 | GLint location, |
| 3796 | GLenum genMode, |
| 3797 | GLint components, |
| 3798 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3799 | { |
| 3800 | if (!context->getExtensions().pathRendering) |
| 3801 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3802 | context->handleError(InvalidOperation() << "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3803 | return false; |
| 3804 | } |
| 3805 | |
| 3806 | const auto *programObject = context->getProgram(program); |
| 3807 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 3808 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3809 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3810 | return false; |
| 3811 | } |
| 3812 | |
| 3813 | if (!programObject->isLinked()) |
| 3814 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3815 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3816 | return false; |
| 3817 | } |
| 3818 | |
| 3819 | switch (genMode) |
| 3820 | { |
| 3821 | case GL_NONE: |
| 3822 | if (components != 0) |
| 3823 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3824 | context->handleError(InvalidValue() << "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3825 | return false; |
| 3826 | } |
| 3827 | break; |
| 3828 | |
| 3829 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 3830 | case GL_EYE_LINEAR_CHROMIUM: |
| 3831 | case GL_CONSTANT_CHROMIUM: |
| 3832 | if (components < 1 || components > 4) |
| 3833 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3834 | context->handleError(InvalidValue() << "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3835 | return false; |
| 3836 | } |
| 3837 | if (!coeffs) |
| 3838 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3839 | context->handleError(InvalidValue() << "No coefficients array given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3840 | return false; |
| 3841 | } |
| 3842 | break; |
| 3843 | |
| 3844 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3845 | context->handleError(InvalidEnum() << "Invalid gen mode."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3846 | return false; |
| 3847 | } |
| 3848 | |
| 3849 | // If the location is -1 then the command is silently ignored |
| 3850 | // and no further validation is needed. |
| 3851 | if (location == -1) |
| 3852 | return true; |
| 3853 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3854 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3855 | |
| 3856 | if (!binding.valid) |
| 3857 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3858 | context->handleError(InvalidOperation() << "No such binding."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3859 | return false; |
| 3860 | } |
| 3861 | |
| 3862 | if (binding.type != GL_NONE) |
| 3863 | { |
| 3864 | GLint expectedComponents = 0; |
| 3865 | switch (binding.type) |
| 3866 | { |
| 3867 | case GL_FLOAT: |
| 3868 | expectedComponents = 1; |
| 3869 | break; |
| 3870 | case GL_FLOAT_VEC2: |
| 3871 | expectedComponents = 2; |
| 3872 | break; |
| 3873 | case GL_FLOAT_VEC3: |
| 3874 | expectedComponents = 3; |
| 3875 | break; |
| 3876 | case GL_FLOAT_VEC4: |
| 3877 | expectedComponents = 4; |
| 3878 | break; |
| 3879 | default: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3880 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3881 | InvalidOperation() |
| 3882 | << "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] | 3883 | return false; |
| 3884 | } |
| 3885 | if (expectedComponents != components && genMode != GL_NONE) |
| 3886 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3887 | context->handleError(InvalidOperation() << "Unexpected number of components"); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3888 | return false; |
| 3889 | } |
| 3890 | } |
| 3891 | return true; |
| 3892 | } |
| 3893 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3894 | bool ValidateCopyTextureCHROMIUM(Context *context, |
| 3895 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3896 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3897 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3898 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3899 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3900 | GLint internalFormat, |
| 3901 | GLenum destType, |
| 3902 | GLboolean unpackFlipY, |
| 3903 | GLboolean unpackPremultiplyAlpha, |
| 3904 | GLboolean unpackUnmultiplyAlpha) |
| 3905 | { |
| 3906 | if (!context->getExtensions().copyTexture) |
| 3907 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3908 | context->handleError(InvalidOperation() |
| 3909 | << "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3910 | return false; |
| 3911 | } |
| 3912 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3913 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3914 | if (source == nullptr) |
| 3915 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3916 | context->handleError(InvalidValue() << "Source texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3917 | return false; |
| 3918 | } |
| 3919 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3920 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3921 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3922 | context->handleError(InvalidValue() << "Source texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3923 | return false; |
| 3924 | } |
| 3925 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3926 | TextureType sourceType = source->getType(); |
| 3927 | ASSERT(sourceType != TextureType::CubeMap); |
| 3928 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3929 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3930 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3931 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3932 | context->handleError(InvalidValue() << "Source texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3933 | return false; |
| 3934 | } |
| 3935 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3936 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 3937 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 3938 | if (sourceWidth == 0 || sourceHeight == 0) |
| 3939 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3940 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3941 | return false; |
| 3942 | } |
| 3943 | |
| 3944 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 3945 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3946 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3947 | context->handleError(InvalidOperation() << "Source texture internal format is invalid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3948 | return false; |
| 3949 | } |
| 3950 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 3951 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 3952 | { |
| 3953 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
| 3954 | return false; |
| 3955 | } |
| 3956 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3957 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3958 | if (dest == nullptr) |
| 3959 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3960 | context->handleError(InvalidValue() |
| 3961 | << "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3962 | return false; |
| 3963 | } |
| 3964 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3965 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3966 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3967 | context->handleError(InvalidValue() << "Destination texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3968 | return false; |
| 3969 | } |
| 3970 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3971 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 3972 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3973 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3974 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3975 | return false; |
| 3976 | } |
| 3977 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3978 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 3979 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3980 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3981 | return false; |
| 3982 | } |
| 3983 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3984 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3985 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3986 | context->handleError( |
| 3987 | InvalidValue() << "Destination width and height must be equal for cube map textures."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3988 | return false; |
| 3989 | } |
| 3990 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3991 | if (dest->getImmutableFormat()) |
| 3992 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3993 | context->handleError(InvalidOperation() << "Destination texture is immutable."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3994 | return false; |
| 3995 | } |
| 3996 | |
| 3997 | return true; |
| 3998 | } |
| 3999 | |
| 4000 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
| 4001 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4002 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4003 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4004 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4005 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4006 | GLint xoffset, |
| 4007 | GLint yoffset, |
| 4008 | GLint x, |
| 4009 | GLint y, |
| 4010 | GLsizei width, |
| 4011 | GLsizei height, |
| 4012 | GLboolean unpackFlipY, |
| 4013 | GLboolean unpackPremultiplyAlpha, |
| 4014 | GLboolean unpackUnmultiplyAlpha) |
| 4015 | { |
| 4016 | if (!context->getExtensions().copyTexture) |
| 4017 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4018 | context->handleError(InvalidOperation() |
| 4019 | << "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4020 | return false; |
| 4021 | } |
| 4022 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4023 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4024 | if (source == nullptr) |
| 4025 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4026 | context->handleError(InvalidValue() << "Source texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4027 | return false; |
| 4028 | } |
| 4029 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4030 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4031 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4032 | context->handleError(InvalidValue() << "Source texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4033 | return false; |
| 4034 | } |
| 4035 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4036 | TextureType sourceType = source->getType(); |
| 4037 | ASSERT(sourceType != TextureType::CubeMap); |
| 4038 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4039 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4040 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4041 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4042 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4043 | return false; |
| 4044 | } |
| 4045 | |
| 4046 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4047 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4048 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4049 | context->handleError(InvalidValue() |
| 4050 | << "The source level of the source texture must be defined."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4051 | return false; |
| 4052 | } |
| 4053 | |
| 4054 | if (x < 0 || y < 0) |
| 4055 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4056 | context->handleError(InvalidValue() << "x and y cannot be negative."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4057 | return false; |
| 4058 | } |
| 4059 | |
| 4060 | if (width < 0 || height < 0) |
| 4061 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4062 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4063 | return false; |
| 4064 | } |
| 4065 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4066 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4067 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4068 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4069 | ANGLE_VALIDATION_ERR(context, InvalidValue(), SourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4070 | return false; |
| 4071 | } |
| 4072 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4073 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4074 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4075 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4076 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4077 | return false; |
| 4078 | } |
| 4079 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4080 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4081 | { |
| 4082 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
| 4083 | return false; |
| 4084 | } |
| 4085 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4086 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4087 | if (dest == nullptr) |
| 4088 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4089 | context->handleError(InvalidValue() |
| 4090 | << "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4091 | return false; |
| 4092 | } |
| 4093 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4094 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4095 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4096 | context->handleError(InvalidValue() << "Destination texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4097 | return false; |
| 4098 | } |
| 4099 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4100 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4101 | true)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4102 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4103 | context->handleError(InvalidValue() << "Destination texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4104 | return false; |
| 4105 | } |
| 4106 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4107 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4108 | { |
Geoff Lang | bb1b19b | 2017-06-16 16:59:00 -0400 | [diff] [blame] | 4109 | context |
| 4110 | ->handleError(InvalidOperation() |
| 4111 | << "The destination level of the destination texture must be defined."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4112 | return false; |
| 4113 | } |
| 4114 | |
| 4115 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4116 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4117 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4118 | context->handleError(InvalidOperation() |
| 4119 | << "Destination internal format and type combination is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4120 | return false; |
| 4121 | } |
| 4122 | |
| 4123 | if (xoffset < 0 || yoffset < 0) |
| 4124 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4125 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4126 | return false; |
| 4127 | } |
| 4128 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4129 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4130 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4131 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4132 | context->handleError(InvalidValue() << "Destination texture not large enough to copy to."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4133 | return false; |
| 4134 | } |
| 4135 | |
| 4136 | return true; |
| 4137 | } |
| 4138 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4139 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId) |
| 4140 | { |
| 4141 | if (!context->getExtensions().copyCompressedTexture) |
| 4142 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4143 | context->handleError(InvalidOperation() |
| 4144 | << "GL_CHROMIUM_copy_compressed_texture extension not available."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4145 | return false; |
| 4146 | } |
| 4147 | |
| 4148 | const gl::Texture *source = context->getTexture(sourceId); |
| 4149 | if (source == nullptr) |
| 4150 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4151 | context->handleError(InvalidValue() << "Source texture is not a valid texture object."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4152 | return false; |
| 4153 | } |
| 4154 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4155 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4156 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4157 | context->handleError(InvalidValue() << "Source texture must be of type GL_TEXTURE_2D."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4158 | return false; |
| 4159 | } |
| 4160 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4161 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4162 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4163 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4164 | context->handleError(InvalidValue() << "Source texture must level 0 defined."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4165 | return false; |
| 4166 | } |
| 4167 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4168 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4169 | if (!sourceFormat.info->compressed) |
| 4170 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4171 | context->handleError(InvalidOperation() |
| 4172 | << "Source texture must have a compressed internal format."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4173 | return false; |
| 4174 | } |
| 4175 | |
| 4176 | const gl::Texture *dest = context->getTexture(destId); |
| 4177 | if (dest == nullptr) |
| 4178 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4179 | context->handleError(InvalidValue() |
| 4180 | << "Destination texture is not a valid texture object."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4181 | return false; |
| 4182 | } |
| 4183 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4184 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4185 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4186 | context->handleError(InvalidValue() |
| 4187 | << "Destination texture must be of type GL_TEXTURE_2D."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4188 | return false; |
| 4189 | } |
| 4190 | |
| 4191 | if (dest->getImmutableFormat()) |
| 4192 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4193 | context->handleError(InvalidOperation() << "Destination cannot be immutable."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4194 | return false; |
| 4195 | } |
| 4196 | |
| 4197 | return true; |
| 4198 | } |
| 4199 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4200 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4201 | { |
| 4202 | switch (type) |
| 4203 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4204 | case ShaderType::Vertex: |
| 4205 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4206 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4207 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4208 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4209 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4210 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4211 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4212 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4213 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4214 | break; |
| 4215 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4216 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4217 | if (!context->getExtensions().geometryShader) |
| 4218 | { |
| 4219 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidShaderType); |
| 4220 | return false; |
| 4221 | } |
| 4222 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4223 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4224 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4225 | return false; |
| 4226 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4227 | |
| 4228 | return true; |
| 4229 | } |
| 4230 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4231 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4232 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4233 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4234 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4235 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4236 | { |
| 4237 | if (size < 0) |
| 4238 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4239 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4240 | return false; |
| 4241 | } |
| 4242 | |
| 4243 | switch (usage) |
| 4244 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4245 | case BufferUsage::StreamDraw: |
| 4246 | case BufferUsage::StaticDraw: |
| 4247 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4248 | break; |
| 4249 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4250 | case BufferUsage::StreamRead: |
| 4251 | case BufferUsage::StaticRead: |
| 4252 | case BufferUsage::DynamicRead: |
| 4253 | case BufferUsage::StreamCopy: |
| 4254 | case BufferUsage::StaticCopy: |
| 4255 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4256 | if (context->getClientMajorVersion() < 3) |
| 4257 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4258 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4259 | return false; |
| 4260 | } |
| 4261 | break; |
| 4262 | |
| 4263 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4264 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4265 | return false; |
| 4266 | } |
| 4267 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4268 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4269 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4270 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4271 | return false; |
| 4272 | } |
| 4273 | |
| 4274 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 4275 | |
| 4276 | if (!buffer) |
| 4277 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4278 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4279 | return false; |
| 4280 | } |
| 4281 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4282 | if (context->getExtensions().webglCompatibility && |
| 4283 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4284 | { |
| 4285 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferBoundForTransformFeedback); |
| 4286 | return false; |
| 4287 | } |
| 4288 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4289 | return true; |
| 4290 | } |
| 4291 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4292 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4293 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4294 | GLintptr offset, |
| 4295 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4296 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4297 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4298 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4299 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4300 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
| 4301 | return false; |
| 4302 | } |
| 4303 | |
| 4304 | if (offset < 0) |
| 4305 | { |
| 4306 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4307 | return false; |
| 4308 | } |
| 4309 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4310 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4311 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4312 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4313 | return false; |
| 4314 | } |
| 4315 | |
| 4316 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 4317 | |
| 4318 | if (!buffer) |
| 4319 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4320 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4321 | return false; |
| 4322 | } |
| 4323 | |
| 4324 | if (buffer->isMapped()) |
| 4325 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4326 | context->handleError(InvalidOperation()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4327 | return false; |
| 4328 | } |
| 4329 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4330 | if (context->getExtensions().webglCompatibility && |
| 4331 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4332 | { |
| 4333 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferBoundForTransformFeedback); |
| 4334 | return false; |
| 4335 | } |
| 4336 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4337 | // Check for possible overflow of size + offset |
| 4338 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4339 | checkedSize += offset; |
| 4340 | if (!checkedSize.IsValid()) |
| 4341 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4342 | context->handleError(OutOfMemory()); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4343 | return false; |
| 4344 | } |
| 4345 | |
| 4346 | if (size + offset > buffer->getSize()) |
| 4347 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4348 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4349 | return false; |
| 4350 | } |
| 4351 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4352 | return true; |
| 4353 | } |
| 4354 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4355 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4356 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4357 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4358 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4359 | context->handleError(InvalidOperation() << "GL_ANGLE_request_extension is not available."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4360 | return false; |
| 4361 | } |
| 4362 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4363 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4364 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4365 | context->handleError(InvalidOperation() << "Extension " << name << " is not requestable."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4366 | return false; |
| 4367 | } |
| 4368 | |
| 4369 | return true; |
| 4370 | } |
| 4371 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4372 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4373 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4374 | if (context->getClientMajorVersion() < 2) |
| 4375 | { |
| 4376 | return ValidateMultitextureUnit(context, texture); |
| 4377 | } |
| 4378 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4379 | if (texture < GL_TEXTURE0 || |
| 4380 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4381 | { |
Lingfeng Yang | 96310cd | 2018-03-28 11:56:28 -0700 | [diff] [blame] | 4382 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4383 | return false; |
| 4384 | } |
| 4385 | |
| 4386 | return true; |
| 4387 | } |
| 4388 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4389 | bool ValidateAttachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4390 | { |
| 4391 | Program *programObject = GetValidProgram(context, program); |
| 4392 | if (!programObject) |
| 4393 | { |
| 4394 | return false; |
| 4395 | } |
| 4396 | |
| 4397 | Shader *shaderObject = GetValidShader(context, shader); |
| 4398 | if (!shaderObject) |
| 4399 | { |
| 4400 | return false; |
| 4401 | } |
| 4402 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4403 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4404 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4405 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ShaderAttachmentHasShader); |
| 4406 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | return true; |
| 4410 | } |
| 4411 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4412 | bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4413 | { |
| 4414 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4415 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4416 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4417 | return false; |
| 4418 | } |
| 4419 | |
| 4420 | if (strncmp(name, "gl_", 3) == 0) |
| 4421 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4422 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4423 | return false; |
| 4424 | } |
| 4425 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4426 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4427 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4428 | const size_t length = strlen(name); |
| 4429 | |
| 4430 | if (!IsValidESSLString(name, length)) |
| 4431 | { |
| 4432 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 4433 | // for shader-related entry points |
| 4434 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidNameCharacters); |
| 4435 | return false; |
| 4436 | } |
| 4437 | |
| 4438 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 4439 | { |
| 4440 | return false; |
| 4441 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4442 | } |
| 4443 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4444 | return GetValidProgram(context, program) != nullptr; |
| 4445 | } |
| 4446 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4447 | bool ValidateBindBuffer(Context *context, BufferBinding target, GLuint buffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4448 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4449 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4450 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4451 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4452 | return false; |
| 4453 | } |
| 4454 | |
| 4455 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4456 | !context->isBufferGenerated(buffer)) |
| 4457 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4458 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4459 | return false; |
| 4460 | } |
| 4461 | |
| 4462 | return true; |
| 4463 | } |
| 4464 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4465 | bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4466 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4467 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4468 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4469 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4470 | return false; |
| 4471 | } |
| 4472 | |
| 4473 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4474 | !context->isFramebufferGenerated(framebuffer)) |
| 4475 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4476 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4477 | return false; |
| 4478 | } |
| 4479 | |
| 4480 | return true; |
| 4481 | } |
| 4482 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4483 | bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4484 | { |
| 4485 | if (target != GL_RENDERBUFFER) |
| 4486 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4487 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4488 | return false; |
| 4489 | } |
| 4490 | |
| 4491 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4492 | !context->isRenderbufferGenerated(renderbuffer)) |
| 4493 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4494 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4495 | return false; |
| 4496 | } |
| 4497 | |
| 4498 | return true; |
| 4499 | } |
| 4500 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4501 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4502 | { |
| 4503 | switch (mode) |
| 4504 | { |
| 4505 | case GL_FUNC_ADD: |
| 4506 | case GL_FUNC_SUBTRACT: |
| 4507 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4508 | return true; |
| 4509 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4510 | case GL_MIN: |
| 4511 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4512 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4513 | |
| 4514 | default: |
| 4515 | return false; |
| 4516 | } |
| 4517 | } |
| 4518 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4519 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4520 | { |
| 4521 | return true; |
| 4522 | } |
| 4523 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4524 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4525 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4526 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4527 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4528 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4529 | return false; |
| 4530 | } |
| 4531 | |
| 4532 | return true; |
| 4533 | } |
| 4534 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4535 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4536 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4537 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4538 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4539 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4540 | return false; |
| 4541 | } |
| 4542 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4543 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4544 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4545 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4546 | return false; |
| 4547 | } |
| 4548 | |
| 4549 | return true; |
| 4550 | } |
| 4551 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4552 | bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4553 | { |
| 4554 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 4555 | } |
| 4556 | |
| 4557 | static bool ValidSrcBlendFunc(GLenum srcBlend) |
| 4558 | { |
| 4559 | switch (srcBlend) |
| 4560 | { |
| 4561 | case GL_ZERO: |
| 4562 | case GL_ONE: |
| 4563 | case GL_SRC_COLOR: |
| 4564 | case GL_ONE_MINUS_SRC_COLOR: |
| 4565 | case GL_DST_COLOR: |
| 4566 | case GL_ONE_MINUS_DST_COLOR: |
| 4567 | case GL_SRC_ALPHA: |
| 4568 | case GL_ONE_MINUS_SRC_ALPHA: |
| 4569 | case GL_DST_ALPHA: |
| 4570 | case GL_ONE_MINUS_DST_ALPHA: |
| 4571 | case GL_CONSTANT_COLOR: |
| 4572 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 4573 | case GL_CONSTANT_ALPHA: |
| 4574 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 4575 | case GL_SRC_ALPHA_SATURATE: |
| 4576 | return true; |
| 4577 | |
| 4578 | default: |
| 4579 | return false; |
| 4580 | } |
| 4581 | } |
| 4582 | |
| 4583 | static bool ValidDstBlendFunc(GLenum dstBlend, GLint contextMajorVersion) |
| 4584 | { |
| 4585 | switch (dstBlend) |
| 4586 | { |
| 4587 | case GL_ZERO: |
| 4588 | case GL_ONE: |
| 4589 | case GL_SRC_COLOR: |
| 4590 | case GL_ONE_MINUS_SRC_COLOR: |
| 4591 | case GL_DST_COLOR: |
| 4592 | case GL_ONE_MINUS_DST_COLOR: |
| 4593 | case GL_SRC_ALPHA: |
| 4594 | case GL_ONE_MINUS_SRC_ALPHA: |
| 4595 | case GL_DST_ALPHA: |
| 4596 | case GL_ONE_MINUS_DST_ALPHA: |
| 4597 | case GL_CONSTANT_COLOR: |
| 4598 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 4599 | case GL_CONSTANT_ALPHA: |
| 4600 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 4601 | return true; |
| 4602 | |
| 4603 | case GL_SRC_ALPHA_SATURATE: |
| 4604 | return (contextMajorVersion >= 3); |
| 4605 | |
| 4606 | default: |
| 4607 | return false; |
| 4608 | } |
| 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 | { |
| 4617 | if (!ValidSrcBlendFunc(srcRGB)) |
| 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 | |
| 4623 | if (!ValidDstBlendFunc(dstRGB, context->getClientMajorVersion())) |
| 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 | |
| 4629 | if (!ValidSrcBlendFunc(srcAlpha)) |
| 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 | |
| 4635 | if (!ValidDstBlendFunc(dstAlpha, context->getClientMajorVersion())) |
| 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 | |
| 4915 | if (!context->getProgram(program)) |
| 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 | { |
| 4941 | if (context->getProgram(shader)) |
| 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 | |
| 5351 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5352 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5353 | return false; |
| 5354 | } |
| 5355 | |
| 5356 | return true; |
| 5357 | } |
| 5358 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5359 | bool ValidateIsBuffer(Context *context, GLuint buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5360 | { |
| 5361 | return true; |
| 5362 | } |
| 5363 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5364 | bool ValidateIsFramebuffer(Context *context, GLuint framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5365 | { |
| 5366 | return true; |
| 5367 | } |
| 5368 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5369 | bool ValidateIsProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5370 | { |
| 5371 | return true; |
| 5372 | } |
| 5373 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5374 | bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5375 | { |
| 5376 | return true; |
| 5377 | } |
| 5378 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5379 | bool ValidateIsShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5380 | { |
| 5381 | return true; |
| 5382 | } |
| 5383 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5384 | bool ValidateIsTexture(Context *context, GLuint texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5385 | { |
| 5386 | return true; |
| 5387 | } |
| 5388 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5389 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5390 | { |
| 5391 | if (context->getClientMajorVersion() < 3) |
| 5392 | { |
| 5393 | switch (pname) |
| 5394 | { |
| 5395 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5396 | case GL_UNPACK_SKIP_IMAGES: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5397 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5398 | return false; |
| 5399 | |
| 5400 | case GL_UNPACK_ROW_LENGTH: |
| 5401 | case GL_UNPACK_SKIP_ROWS: |
| 5402 | case GL_UNPACK_SKIP_PIXELS: |
| 5403 | if (!context->getExtensions().unpackSubimage) |
| 5404 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5405 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5406 | return false; |
| 5407 | } |
| 5408 | break; |
| 5409 | |
| 5410 | case GL_PACK_ROW_LENGTH: |
| 5411 | case GL_PACK_SKIP_ROWS: |
| 5412 | case GL_PACK_SKIP_PIXELS: |
| 5413 | if (!context->getExtensions().packSubimage) |
| 5414 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5415 | context->handleError(InvalidEnum()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5416 | return false; |
| 5417 | } |
| 5418 | break; |
| 5419 | } |
| 5420 | } |
| 5421 | |
| 5422 | if (param < 0) |
| 5423 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5424 | context->handleError(InvalidValue() << "Cannot use negative values in PixelStorei"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5425 | return false; |
| 5426 | } |
| 5427 | |
| 5428 | switch (pname) |
| 5429 | { |
| 5430 | case GL_UNPACK_ALIGNMENT: |
| 5431 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5432 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5433 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5434 | return false; |
| 5435 | } |
| 5436 | break; |
| 5437 | |
| 5438 | case GL_PACK_ALIGNMENT: |
| 5439 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5440 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5441 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5442 | return false; |
| 5443 | } |
| 5444 | break; |
| 5445 | |
| 5446 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5447 | if (!context->getExtensions().packReverseRowOrder) |
| 5448 | { |
| 5449 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5450 | } |
| 5451 | break; |
| 5452 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5453 | case GL_UNPACK_ROW_LENGTH: |
| 5454 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5455 | case GL_UNPACK_SKIP_IMAGES: |
| 5456 | case GL_UNPACK_SKIP_ROWS: |
| 5457 | case GL_UNPACK_SKIP_PIXELS: |
| 5458 | case GL_PACK_ROW_LENGTH: |
| 5459 | case GL_PACK_SKIP_ROWS: |
| 5460 | case GL_PACK_SKIP_PIXELS: |
| 5461 | break; |
| 5462 | |
| 5463 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5464 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5465 | return false; |
| 5466 | } |
| 5467 | |
| 5468 | return true; |
| 5469 | } |
| 5470 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5471 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5472 | { |
| 5473 | return true; |
| 5474 | } |
| 5475 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5476 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5477 | { |
| 5478 | return true; |
| 5479 | } |
| 5480 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5481 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5482 | { |
| 5483 | return true; |
| 5484 | } |
| 5485 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5486 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5487 | { |
| 5488 | if (width < 0 || height < 0) |
| 5489 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5490 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5491 | return false; |
| 5492 | } |
| 5493 | |
| 5494 | return true; |
| 5495 | } |
| 5496 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5497 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5498 | GLsizei n, |
| 5499 | const GLuint *shaders, |
| 5500 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5501 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5502 | GLsizei length) |
| 5503 | { |
| 5504 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5505 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5506 | shaderBinaryFormats.end()) |
| 5507 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5508 | context->handleError(InvalidEnum() << "Invalid shader binary format."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5509 | return false; |
| 5510 | } |
| 5511 | |
| 5512 | return true; |
| 5513 | } |
| 5514 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5515 | bool ValidateShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5516 | GLuint shader, |
| 5517 | GLsizei count, |
| 5518 | const GLchar *const *string, |
| 5519 | const GLint *length) |
| 5520 | { |
| 5521 | if (count < 0) |
| 5522 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5523 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5524 | return false; |
| 5525 | } |
| 5526 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5527 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5528 | // shader-related entry points |
| 5529 | if (context->getExtensions().webglCompatibility) |
| 5530 | { |
| 5531 | for (GLsizei i = 0; i < count; i++) |
| 5532 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5533 | size_t len = |
| 5534 | (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] | 5535 | |
| 5536 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5537 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 5538 | context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5539 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5540 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5541 | return false; |
| 5542 | } |
| 5543 | } |
| 5544 | } |
| 5545 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5546 | Shader *shaderObject = GetValidShader(context, shader); |
| 5547 | if (!shaderObject) |
| 5548 | { |
| 5549 | return false; |
| 5550 | } |
| 5551 | |
| 5552 | return true; |
| 5553 | } |
| 5554 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5555 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5556 | { |
| 5557 | if (!IsValidStencilFunc(func)) |
| 5558 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5559 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5560 | return false; |
| 5561 | } |
| 5562 | |
| 5563 | return true; |
| 5564 | } |
| 5565 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5566 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5567 | { |
| 5568 | if (!IsValidStencilFace(face)) |
| 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 | if (!IsValidStencilFunc(func)) |
| 5575 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5576 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5577 | return false; |
| 5578 | } |
| 5579 | |
| 5580 | return true; |
| 5581 | } |
| 5582 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5583 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5584 | { |
| 5585 | return true; |
| 5586 | } |
| 5587 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5588 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5589 | { |
| 5590 | if (!IsValidStencilFace(face)) |
| 5591 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5592 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5593 | return false; |
| 5594 | } |
| 5595 | |
| 5596 | return true; |
| 5597 | } |
| 5598 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5599 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5600 | { |
| 5601 | if (!IsValidStencilOp(fail)) |
| 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 | if (!IsValidStencilOp(zfail)) |
| 5608 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5609 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5610 | return false; |
| 5611 | } |
| 5612 | |
| 5613 | if (!IsValidStencilOp(zpass)) |
| 5614 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5615 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5616 | return false; |
| 5617 | } |
| 5618 | |
| 5619 | return true; |
| 5620 | } |
| 5621 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5622 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5623 | GLenum face, |
| 5624 | GLenum fail, |
| 5625 | GLenum zfail, |
| 5626 | GLenum zpass) |
| 5627 | { |
| 5628 | if (!IsValidStencilFace(face)) |
| 5629 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5630 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5631 | return false; |
| 5632 | } |
| 5633 | |
| 5634 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 5635 | } |
| 5636 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5637 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5638 | { |
| 5639 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 5640 | } |
| 5641 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5642 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5643 | { |
| 5644 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 5645 | } |
| 5646 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5647 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5648 | { |
| 5649 | return ValidateUniform1iv(context, location, 1, &x); |
| 5650 | } |
| 5651 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5652 | bool ValidateUniform2f(Context *context, GLint location, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5653 | { |
| 5654 | return ValidateUniform(context, GL_FLOAT_VEC2, location, 1); |
| 5655 | } |
| 5656 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5657 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5658 | { |
| 5659 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 5660 | } |
| 5661 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5662 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5663 | { |
| 5664 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 5665 | } |
| 5666 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5667 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5668 | { |
| 5669 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 5670 | } |
| 5671 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5672 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5673 | { |
| 5674 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 5675 | } |
| 5676 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5677 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5678 | { |
| 5679 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 5680 | } |
| 5681 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5682 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5683 | { |
| 5684 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 5685 | } |
| 5686 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5687 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5688 | { |
| 5689 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 5690 | } |
| 5691 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5692 | 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] | 5693 | { |
| 5694 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 5695 | } |
| 5696 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5697 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5698 | { |
| 5699 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 5700 | } |
| 5701 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5702 | 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] | 5703 | { |
| 5704 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 5705 | } |
| 5706 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5707 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5708 | { |
| 5709 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 5710 | } |
| 5711 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5712 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5713 | GLint location, |
| 5714 | GLsizei count, |
| 5715 | GLboolean transpose, |
| 5716 | const GLfloat *value) |
| 5717 | { |
| 5718 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 5719 | } |
| 5720 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5721 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5722 | GLint location, |
| 5723 | GLsizei count, |
| 5724 | GLboolean transpose, |
| 5725 | const GLfloat *value) |
| 5726 | { |
| 5727 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 5728 | } |
| 5729 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5730 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5731 | GLint location, |
| 5732 | GLsizei count, |
| 5733 | GLboolean transpose, |
| 5734 | const GLfloat *value) |
| 5735 | { |
| 5736 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 5737 | } |
| 5738 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5739 | bool ValidateValidateProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5740 | { |
| 5741 | Program *programObject = GetValidProgram(context, program); |
| 5742 | |
| 5743 | if (!programObject) |
| 5744 | { |
| 5745 | return false; |
| 5746 | } |
| 5747 | |
| 5748 | return true; |
| 5749 | } |
| 5750 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5751 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5752 | { |
| 5753 | return ValidateVertexAttribIndex(context, index); |
| 5754 | } |
| 5755 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5756 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5757 | { |
| 5758 | return ValidateVertexAttribIndex(context, index); |
| 5759 | } |
| 5760 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5761 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5762 | { |
| 5763 | return ValidateVertexAttribIndex(context, index); |
| 5764 | } |
| 5765 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5766 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5767 | { |
| 5768 | return ValidateVertexAttribIndex(context, index); |
| 5769 | } |
| 5770 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5771 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5772 | { |
| 5773 | return ValidateVertexAttribIndex(context, index); |
| 5774 | } |
| 5775 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5776 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5777 | { |
| 5778 | return ValidateVertexAttribIndex(context, index); |
| 5779 | } |
| 5780 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5781 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5782 | GLuint index, |
| 5783 | GLfloat x, |
| 5784 | GLfloat y, |
| 5785 | GLfloat z, |
| 5786 | GLfloat w) |
| 5787 | { |
| 5788 | return ValidateVertexAttribIndex(context, index); |
| 5789 | } |
| 5790 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5791 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5792 | { |
| 5793 | return ValidateVertexAttribIndex(context, index); |
| 5794 | } |
| 5795 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5796 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5797 | { |
| 5798 | if (width < 0 || height < 0) |
| 5799 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5800 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5801 | return false; |
| 5802 | } |
| 5803 | |
| 5804 | return true; |
| 5805 | } |
| 5806 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 5807 | bool ValidateDrawArrays(Context *context, PrimitiveMode mode, GLint first, GLsizei count) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5808 | { |
| 5809 | return ValidateDrawArraysCommon(context, mode, first, count, 1); |
| 5810 | } |
| 5811 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5812 | bool ValidateDrawElements(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 5813 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5814 | GLsizei count, |
| 5815 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5816 | const void *indices) |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5817 | { |
| 5818 | return ValidateDrawElementsCommon(context, mode, count, type, indices, 1); |
| 5819 | } |
| 5820 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 5821 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5822 | GLenum target, |
| 5823 | GLenum attachment, |
| 5824 | GLenum pname, |
| 5825 | GLint *params) |
| 5826 | { |
| 5827 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 5828 | nullptr); |
| 5829 | } |
| 5830 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5831 | bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5832 | { |
| 5833 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 5834 | } |
| 5835 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5836 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5837 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5838 | GLint level, |
| 5839 | GLenum internalformat, |
| 5840 | GLint x, |
| 5841 | GLint y, |
| 5842 | GLsizei width, |
| 5843 | GLsizei height, |
| 5844 | GLint border) |
| 5845 | { |
| 5846 | if (context->getClientMajorVersion() < 3) |
| 5847 | { |
| 5848 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 5849 | 0, x, y, width, height, border); |
| 5850 | } |
| 5851 | |
| 5852 | ASSERT(context->getClientMajorVersion() == 3); |
| 5853 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 5854 | 0, x, y, width, height, border); |
| 5855 | } |
| 5856 | |
| 5857 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5858 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5859 | GLint level, |
| 5860 | GLint xoffset, |
| 5861 | GLint yoffset, |
| 5862 | GLint x, |
| 5863 | GLint y, |
| 5864 | GLsizei width, |
| 5865 | GLsizei height) |
| 5866 | { |
| 5867 | if (context->getClientMajorVersion() < 3) |
| 5868 | { |
| 5869 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 5870 | yoffset, x, y, width, height, 0); |
| 5871 | } |
| 5872 | |
| 5873 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 5874 | yoffset, 0, x, y, width, height, 0); |
| 5875 | } |
| 5876 | |
| 5877 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 5878 | { |
| 5879 | return ValidateGenOrDelete(context, n); |
| 5880 | } |
| 5881 | |
| 5882 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 5883 | { |
| 5884 | return ValidateGenOrDelete(context, n); |
| 5885 | } |
| 5886 | |
| 5887 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 5888 | { |
| 5889 | return ValidateGenOrDelete(context, n); |
| 5890 | } |
| 5891 | |
| 5892 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 5893 | { |
| 5894 | return ValidateGenOrDelete(context, n); |
| 5895 | } |
| 5896 | |
| 5897 | bool ValidateDisable(Context *context, GLenum cap) |
| 5898 | { |
| 5899 | if (!ValidCap(context, cap, false)) |
| 5900 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5901 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5902 | return false; |
| 5903 | } |
| 5904 | |
| 5905 | return true; |
| 5906 | } |
| 5907 | |
| 5908 | bool ValidateEnable(Context *context, GLenum cap) |
| 5909 | { |
| 5910 | if (!ValidCap(context, cap, false)) |
| 5911 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5912 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5913 | return false; |
| 5914 | } |
| 5915 | |
| 5916 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 5917 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 5918 | { |
| 5919 | const char *errorMessage = "Current renderer doesn't support alpha-to-coverage"; |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5920 | context->handleError(InvalidOperation() << errorMessage); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5921 | |
| 5922 | // We also output an error message to the debugger window if tracing is active, so that |
| 5923 | // developers can see the error message. |
| 5924 | ERR() << errorMessage; |
| 5925 | return false; |
| 5926 | } |
| 5927 | |
| 5928 | return true; |
| 5929 | } |
| 5930 | |
| 5931 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 5932 | GLenum target, |
| 5933 | GLenum attachment, |
| 5934 | GLenum renderbuffertarget, |
| 5935 | GLuint renderbuffer) |
| 5936 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5937 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5938 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5939 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
| 5940 | return false; |
| 5941 | } |
| 5942 | |
| 5943 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0) |
| 5944 | { |
| 5945 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5946 | return false; |
| 5947 | } |
| 5948 | |
| 5949 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 5950 | renderbuffertarget, renderbuffer); |
| 5951 | } |
| 5952 | |
| 5953 | bool ValidateFramebufferTexture2D(Context *context, |
| 5954 | GLenum target, |
| 5955 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5956 | TextureTarget textarget, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5957 | GLuint texture, |
| 5958 | GLint level) |
| 5959 | { |
| 5960 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 5961 | // extension |
| 5962 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 5963 | level != 0) |
| 5964 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5965 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5966 | return false; |
| 5967 | } |
| 5968 | |
| 5969 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 5970 | { |
| 5971 | return false; |
| 5972 | } |
| 5973 | |
| 5974 | if (texture != 0) |
| 5975 | { |
| 5976 | gl::Texture *tex = context->getTexture(texture); |
| 5977 | ASSERT(tex); |
| 5978 | |
| 5979 | const gl::Caps &caps = context->getCaps(); |
| 5980 | |
| 5981 | switch (textarget) |
| 5982 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5983 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5984 | { |
| 5985 | if (level > gl::log2(caps.max2DTextureSize)) |
| 5986 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5987 | context->handleError(InvalidValue()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5988 | return false; |
| 5989 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 5990 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5991 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5992 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5993 | return false; |
| 5994 | } |
| 5995 | } |
| 5996 | break; |
| 5997 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5998 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5999 | { |
| 6000 | if (level != 0) |
| 6001 | { |
| 6002 | context->handleError(InvalidValue()); |
| 6003 | return false; |
| 6004 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6005 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6006 | { |
| 6007 | context->handleError(InvalidOperation() |
| 6008 | << "Textarget must match the texture target type."); |
| 6009 | return false; |
| 6010 | } |
| 6011 | } |
| 6012 | break; |
| 6013 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6014 | case TextureTarget::CubeMapNegativeX: |
| 6015 | case TextureTarget::CubeMapNegativeY: |
| 6016 | case TextureTarget::CubeMapNegativeZ: |
| 6017 | case TextureTarget::CubeMapPositiveX: |
| 6018 | case TextureTarget::CubeMapPositiveY: |
| 6019 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6020 | { |
| 6021 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 6022 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6023 | context->handleError(InvalidValue()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6024 | return false; |
| 6025 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6026 | if (tex->getType() != TextureType::CubeMap) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6027 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6028 | context->handleError(InvalidOperation() |
| 6029 | << "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6030 | return false; |
| 6031 | } |
| 6032 | } |
| 6033 | break; |
| 6034 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6035 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6036 | { |
| 6037 | if (context->getClientVersion() < ES_3_1) |
| 6038 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 6039 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6040 | return false; |
| 6041 | } |
| 6042 | |
| 6043 | if (level != 0) |
| 6044 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 6045 | ANGLE_VALIDATION_ERR(context, InvalidValue(), LevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6046 | return false; |
| 6047 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6048 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6049 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6050 | context->handleError(InvalidOperation() |
| 6051 | << "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6052 | return false; |
| 6053 | } |
| 6054 | } |
| 6055 | break; |
| 6056 | |
| 6057 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6058 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6059 | return false; |
| 6060 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | return true; |
| 6064 | } |
| 6065 | |
| 6066 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 6067 | { |
| 6068 | return ValidateGenOrDelete(context, n); |
| 6069 | } |
| 6070 | |
| 6071 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 6072 | { |
| 6073 | return ValidateGenOrDelete(context, n); |
| 6074 | } |
| 6075 | |
| 6076 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 6077 | { |
| 6078 | return ValidateGenOrDelete(context, n); |
| 6079 | } |
| 6080 | |
| 6081 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 6082 | { |
| 6083 | return ValidateGenOrDelete(context, n); |
| 6084 | } |
| 6085 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6086 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6087 | { |
| 6088 | if (!ValidTextureTarget(context, target)) |
| 6089 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6090 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6091 | return false; |
| 6092 | } |
| 6093 | |
| 6094 | Texture *texture = context->getTargetTexture(target); |
| 6095 | |
| 6096 | if (texture == nullptr) |
| 6097 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6098 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6099 | return false; |
| 6100 | } |
| 6101 | |
| 6102 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 6103 | |
| 6104 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 6105 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 6106 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 6107 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6108 | context->handleError(InvalidOperation()); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6109 | return false; |
| 6110 | } |
| 6111 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6112 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 6113 | ? TextureTarget::CubeMapPositiveX |
| 6114 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6115 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 6116 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 6117 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6118 | { |
| 6119 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed); |
| 6120 | return false; |
| 6121 | } |
| 6122 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6123 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 6124 | bool formatUnsized = !format.sized; |
| 6125 | bool formatColorRenderableAndFilterable = |
| 6126 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6127 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6128 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6129 | { |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6130 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6131 | return false; |
| 6132 | } |
| 6133 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6134 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 6135 | // generation |
| 6136 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 6137 | { |
| 6138 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed); |
| 6139 | return false; |
| 6140 | } |
| 6141 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 6142 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 6143 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 6144 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6145 | { |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6146 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6147 | return false; |
| 6148 | } |
| 6149 | |
| 6150 | // Non-power of 2 ES2 check |
| 6151 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 6152 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 6153 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 6154 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6155 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 6156 | target == TextureType::CubeMap); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6157 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6158 | return false; |
| 6159 | } |
| 6160 | |
| 6161 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6162 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6163 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6164 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), CubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6165 | return false; |
| 6166 | } |
| 6167 | |
| 6168 | return true; |
| 6169 | } |
| 6170 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6171 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 6172 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6173 | GLenum pname, |
| 6174 | GLint *params) |
| 6175 | { |
| 6176 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 6177 | } |
| 6178 | |
| 6179 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6180 | GLenum target, |
| 6181 | GLenum pname, |
| 6182 | GLint *params) |
| 6183 | { |
| 6184 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6185 | } |
| 6186 | |
| 6187 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 6188 | { |
| 6189 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6190 | } |
| 6191 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6192 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6193 | { |
| 6194 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6195 | } |
| 6196 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6197 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6198 | { |
| 6199 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6200 | } |
| 6201 | |
| 6202 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
| 6203 | { |
| 6204 | return ValidateGetUniformBase(context, program, location); |
| 6205 | } |
| 6206 | |
| 6207 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
| 6208 | { |
| 6209 | return ValidateGetUniformBase(context, program, location); |
| 6210 | } |
| 6211 | |
| 6212 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6213 | { |
| 6214 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6215 | } |
| 6216 | |
| 6217 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6218 | { |
| 6219 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6220 | } |
| 6221 | |
| 6222 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6223 | { |
| 6224 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6225 | } |
| 6226 | |
| 6227 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6228 | { |
| 6229 | if (!ValidCap(context, cap, true)) |
| 6230 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6231 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6232 | return false; |
| 6233 | } |
| 6234 | |
| 6235 | return true; |
| 6236 | } |
| 6237 | |
| 6238 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 6239 | { |
| 6240 | if (context->hasActiveTransformFeedback(program)) |
| 6241 | { |
| 6242 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6243 | context->handleError(InvalidOperation() << "Cannot link program while program is " |
| 6244 | "associated with an active transform " |
| 6245 | "feedback object."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6246 | return false; |
| 6247 | } |
| 6248 | |
| 6249 | Program *programObject = GetValidProgram(context, program); |
| 6250 | if (!programObject) |
| 6251 | { |
| 6252 | return false; |
| 6253 | } |
| 6254 | |
| 6255 | return true; |
| 6256 | } |
| 6257 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6258 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6259 | GLint x, |
| 6260 | GLint y, |
| 6261 | GLsizei width, |
| 6262 | GLsizei height, |
| 6263 | GLenum format, |
| 6264 | GLenum type, |
| 6265 | void *pixels) |
| 6266 | { |
| 6267 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6268 | nullptr, pixels); |
| 6269 | } |
| 6270 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6271 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6272 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6273 | return ValidateTexParameterBase(context, target, pname, 1, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6274 | } |
| 6275 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6276 | bool ValidateTexParameterfv(Context *context, |
| 6277 | TextureType target, |
| 6278 | GLenum pname, |
| 6279 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6280 | { |
| 6281 | return ValidateTexParameterBase(context, target, pname, -1, params); |
| 6282 | } |
| 6283 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6284 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6285 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6286 | return ValidateTexParameterBase(context, target, pname, 1, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6287 | } |
| 6288 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6289 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6290 | { |
| 6291 | return ValidateTexParameterBase(context, target, pname, -1, params); |
| 6292 | } |
| 6293 | |
| 6294 | bool ValidateUseProgram(Context *context, GLuint program) |
| 6295 | { |
| 6296 | if (program != 0) |
| 6297 | { |
| 6298 | Program *programObject = context->getProgram(program); |
| 6299 | if (!programObject) |
| 6300 | { |
| 6301 | // ES 3.1.0 section 7.3 page 72 |
| 6302 | if (context->getShader(program)) |
| 6303 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6304 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6305 | return false; |
| 6306 | } |
| 6307 | else |
| 6308 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6309 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6310 | return false; |
| 6311 | } |
| 6312 | } |
| 6313 | if (!programObject->isLinked()) |
| 6314 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6315 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6316 | return false; |
| 6317 | } |
| 6318 | } |
| 6319 | if (context->getGLState().isTransformFeedbackActiveUnpaused()) |
| 6320 | { |
| 6321 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6322 | context |
| 6323 | ->handleError(InvalidOperation() |
| 6324 | << "Cannot change active program while transform feedback is unpaused."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6325 | return false; |
| 6326 | } |
| 6327 | |
| 6328 | return true; |
| 6329 | } |
| 6330 | |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6331 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences) |
| 6332 | { |
| 6333 | if (!context->getExtensions().fence) |
| 6334 | { |
| 6335 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6336 | return false; |
| 6337 | } |
| 6338 | |
| 6339 | if (n < 0) |
| 6340 | { |
| 6341 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 6342 | return false; |
| 6343 | } |
| 6344 | |
| 6345 | return true; |
| 6346 | } |
| 6347 | |
| 6348 | bool ValidateFinishFenceNV(Context *context, GLuint fence) |
| 6349 | { |
| 6350 | if (!context->getExtensions().fence) |
| 6351 | { |
| 6352 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6353 | return false; |
| 6354 | } |
| 6355 | |
| 6356 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6357 | |
| 6358 | if (fenceObject == nullptr) |
| 6359 | { |
| 6360 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFence); |
| 6361 | return false; |
| 6362 | } |
| 6363 | |
| 6364 | if (!fenceObject->isSet()) |
| 6365 | { |
| 6366 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFenceState); |
| 6367 | return false; |
| 6368 | } |
| 6369 | |
| 6370 | return true; |
| 6371 | } |
| 6372 | |
| 6373 | bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences) |
| 6374 | { |
| 6375 | if (!context->getExtensions().fence) |
| 6376 | { |
| 6377 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6378 | return false; |
| 6379 | } |
| 6380 | |
| 6381 | if (n < 0) |
| 6382 | { |
| 6383 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 6384 | return false; |
| 6385 | } |
| 6386 | |
| 6387 | return true; |
| 6388 | } |
| 6389 | |
| 6390 | bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params) |
| 6391 | { |
| 6392 | if (!context->getExtensions().fence) |
| 6393 | { |
| 6394 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6395 | return false; |
| 6396 | } |
| 6397 | |
| 6398 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6399 | |
| 6400 | if (fenceObject == nullptr) |
| 6401 | { |
| 6402 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFence); |
| 6403 | return false; |
| 6404 | } |
| 6405 | |
| 6406 | if (!fenceObject->isSet()) |
| 6407 | { |
| 6408 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFenceState); |
| 6409 | return false; |
| 6410 | } |
| 6411 | |
| 6412 | switch (pname) |
| 6413 | { |
| 6414 | case GL_FENCE_STATUS_NV: |
| 6415 | case GL_FENCE_CONDITION_NV: |
| 6416 | break; |
| 6417 | |
| 6418 | default: |
| 6419 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
| 6420 | return false; |
| 6421 | } |
| 6422 | |
| 6423 | return true; |
| 6424 | } |
| 6425 | |
| 6426 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 6427 | { |
| 6428 | if (!context->getExtensions().robustness) |
| 6429 | { |
| 6430 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6431 | return false; |
| 6432 | } |
| 6433 | |
| 6434 | return true; |
| 6435 | } |
| 6436 | |
| 6437 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
| 6438 | GLuint shader, |
| 6439 | GLsizei bufsize, |
| 6440 | GLsizei *length, |
| 6441 | GLchar *source) |
| 6442 | { |
| 6443 | if (!context->getExtensions().translatedShaderSource) |
| 6444 | { |
| 6445 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6446 | return false; |
| 6447 | } |
| 6448 | |
| 6449 | if (bufsize < 0) |
| 6450 | { |
| 6451 | context->handleError(InvalidValue()); |
| 6452 | return false; |
| 6453 | } |
| 6454 | |
| 6455 | Shader *shaderObject = context->getShader(shader); |
| 6456 | |
| 6457 | if (!shaderObject) |
| 6458 | { |
| 6459 | context->handleError(InvalidOperation()); |
| 6460 | return false; |
| 6461 | } |
| 6462 | |
| 6463 | return true; |
| 6464 | } |
| 6465 | |
| 6466 | bool ValidateIsFenceNV(Context *context, GLuint fence) |
| 6467 | { |
| 6468 | if (!context->getExtensions().fence) |
| 6469 | { |
| 6470 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6471 | return false; |
| 6472 | } |
| 6473 | |
| 6474 | return true; |
| 6475 | } |
| 6476 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6477 | bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition) |
| 6478 | { |
| 6479 | if (!context->getExtensions().fence) |
| 6480 | { |
| 6481 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6482 | return false; |
| 6483 | } |
| 6484 | |
| 6485 | if (condition != GL_ALL_COMPLETED_NV) |
| 6486 | { |
| 6487 | context->handleError(InvalidEnum()); |
| 6488 | return false; |
| 6489 | } |
| 6490 | |
| 6491 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6492 | |
| 6493 | if (fenceObject == nullptr) |
| 6494 | { |
| 6495 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFence); |
| 6496 | return false; |
| 6497 | } |
| 6498 | |
| 6499 | return true; |
| 6500 | } |
| 6501 | |
| 6502 | bool ValidateTestFenceNV(Context *context, GLuint fence) |
| 6503 | { |
| 6504 | if (!context->getExtensions().fence) |
| 6505 | { |
| 6506 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NVFenceNotSupported); |
| 6507 | return false; |
| 6508 | } |
| 6509 | |
| 6510 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6511 | |
| 6512 | if (fenceObject == nullptr) |
| 6513 | { |
| 6514 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFence); |
| 6515 | return false; |
| 6516 | } |
| 6517 | |
| 6518 | if (fenceObject->isSet() != GL_TRUE) |
| 6519 | { |
| 6520 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidFenceState); |
| 6521 | return false; |
| 6522 | } |
| 6523 | |
| 6524 | return true; |
| 6525 | } |
| 6526 | |
| 6527 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6528 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6529 | GLsizei levels, |
| 6530 | GLenum internalformat, |
| 6531 | GLsizei width, |
| 6532 | GLsizei height) |
| 6533 | { |
| 6534 | if (!context->getExtensions().textureStorage) |
| 6535 | { |
| 6536 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6537 | return false; |
| 6538 | } |
| 6539 | |
| 6540 | if (context->getClientMajorVersion() < 3) |
| 6541 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6542 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6543 | height); |
| 6544 | } |
| 6545 | |
| 6546 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6547 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6548 | 1); |
| 6549 | } |
| 6550 | |
| 6551 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 6552 | { |
| 6553 | if (!context->getExtensions().instancedArrays) |
| 6554 | { |
| 6555 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6556 | return false; |
| 6557 | } |
| 6558 | |
| 6559 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6560 | { |
| 6561 | context->handleError(InvalidValue()); |
| 6562 | return false; |
| 6563 | } |
| 6564 | |
| 6565 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 6566 | { |
| 6567 | if (index == 0 && divisor != 0) |
| 6568 | { |
| 6569 | const char *errorMessage = |
| 6570 | "The current context doesn't support setting a non-zero divisor on the " |
| 6571 | "attribute with index zero. " |
| 6572 | "Please reorder the attributes in your vertex shader so that attribute zero " |
| 6573 | "can have a zero divisor."; |
| 6574 | context->handleError(InvalidOperation() << errorMessage); |
| 6575 | |
| 6576 | // We also output an error message to the debugger window if tracing is active, so |
| 6577 | // that developers can see the error message. |
| 6578 | ERR() << errorMessage; |
| 6579 | return false; |
| 6580 | } |
| 6581 | } |
| 6582 | |
| 6583 | return true; |
| 6584 | } |
| 6585 | |
| 6586 | bool ValidateTexImage3DOES(Context *context, |
| 6587 | GLenum target, |
| 6588 | GLint level, |
| 6589 | GLenum internalformat, |
| 6590 | GLsizei width, |
| 6591 | GLsizei height, |
| 6592 | GLsizei depth, |
| 6593 | GLint border, |
| 6594 | GLenum format, |
| 6595 | GLenum type, |
| 6596 | const void *pixels) |
| 6597 | { |
| 6598 | UNIMPLEMENTED(); // FIXME |
| 6599 | return false; |
| 6600 | } |
| 6601 | |
| 6602 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 6603 | { |
| 6604 | if (!context->getExtensions().debugMarker) |
| 6605 | { |
| 6606 | // The debug marker calls should not set error state |
| 6607 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 6608 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6609 | return false; |
| 6610 | } |
| 6611 | |
| 6612 | return true; |
| 6613 | } |
| 6614 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6615 | bool ValidateTexStorage1DEXT(Context *context, |
| 6616 | GLenum target, |
| 6617 | GLsizei levels, |
| 6618 | GLenum internalformat, |
| 6619 | GLsizei width) |
| 6620 | { |
| 6621 | UNIMPLEMENTED(); |
| 6622 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6623 | return false; |
| 6624 | } |
| 6625 | |
| 6626 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6627 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6628 | GLsizei levels, |
| 6629 | GLenum internalformat, |
| 6630 | GLsizei width, |
| 6631 | GLsizei height, |
| 6632 | GLsizei depth) |
| 6633 | { |
| 6634 | if (!context->getExtensions().textureStorage) |
| 6635 | { |
| 6636 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6637 | return false; |
| 6638 | } |
| 6639 | |
| 6640 | if (context->getClientMajorVersion() < 3) |
| 6641 | { |
| 6642 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6643 | return false; |
| 6644 | } |
| 6645 | |
| 6646 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 6647 | depth); |
| 6648 | } |
| 6649 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6650 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 6651 | { |
| 6652 | if (!context->getExtensions().parallelShaderCompile) |
| 6653 | { |
| 6654 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 6655 | return false; |
| 6656 | } |
| 6657 | return true; |
| 6658 | } |
| 6659 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6660 | } // namespace gl |