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