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 | |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES2_autogen.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" |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 28 | #include "libANGLE/validationES2.h" |
| 29 | #include "libANGLE/validationES3_autogen.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 30 | |
| 31 | namespace gl |
| 32 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 33 | using namespace err; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 34 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 35 | namespace |
| 36 | { |
| 37 | |
| 38 | bool IsPartialBlit(gl::Context *context, |
| 39 | const FramebufferAttachment *readBuffer, |
| 40 | const FramebufferAttachment *writeBuffer, |
| 41 | GLint srcX0, |
| 42 | GLint srcY0, |
| 43 | GLint srcX1, |
| 44 | GLint srcY1, |
| 45 | GLint dstX0, |
| 46 | GLint dstY0, |
| 47 | GLint dstX1, |
| 48 | GLint dstY1) |
| 49 | { |
| 50 | const Extents &writeSize = writeBuffer->getSize(); |
| 51 | const Extents &readSize = readBuffer->getSize(); |
| 52 | |
| 53 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width || |
| 54 | dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height) |
| 55 | { |
| 56 | return true; |
| 57 | } |
| 58 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 59 | if (context->getState().isScissorTestEnabled()) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 60 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 61 | const Rectangle &scissor = context->getState().getScissor(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 62 | return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width || |
| 63 | scissor.height < writeSize.height; |
| 64 | } |
| 65 | |
| 66 | return false; |
| 67 | } |
| 68 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 69 | template <typename T> |
| 70 | bool ValidatePathInstances(gl::Context *context, |
| 71 | GLsizei numPaths, |
| 72 | const void *paths, |
| 73 | GLuint pathBase) |
| 74 | { |
| 75 | const auto *array = static_cast<const T *>(paths); |
| 76 | |
| 77 | for (GLsizei i = 0; i < numPaths; ++i) |
| 78 | { |
| 79 | const GLuint pathName = array[i] + pathBase; |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 80 | if (context->isPathGenerated(pathName) && !context->isPath(pathName)) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 81 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 82 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 83 | return false; |
| 84 | } |
| 85 | } |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool ValidateInstancedPathParameters(gl::Context *context, |
| 90 | GLsizei numPaths, |
| 91 | GLenum pathNameType, |
| 92 | const void *paths, |
| 93 | GLuint pathBase, |
| 94 | GLenum transformType, |
| 95 | const GLfloat *transformValues) |
| 96 | { |
| 97 | if (!context->getExtensions().pathRendering) |
| 98 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 99 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
| 103 | if (paths == nullptr) |
| 104 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 105 | context->validationError(GL_INVALID_VALUE, kInvalidPathNameArray); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 106 | return false; |
| 107 | } |
| 108 | |
| 109 | if (numPaths < 0) |
| 110 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 111 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumPaths); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 112 | return false; |
| 113 | } |
| 114 | |
| 115 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths)) |
| 116 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 117 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 118 | return false; |
| 119 | } |
| 120 | |
| 121 | std::uint32_t pathNameTypeSize = 0; |
| 122 | std::uint32_t componentCount = 0; |
| 123 | |
| 124 | switch (pathNameType) |
| 125 | { |
| 126 | case GL_UNSIGNED_BYTE: |
| 127 | pathNameTypeSize = sizeof(GLubyte); |
| 128 | if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase)) |
| 129 | return false; |
| 130 | break; |
| 131 | |
| 132 | case GL_BYTE: |
| 133 | pathNameTypeSize = sizeof(GLbyte); |
| 134 | if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase)) |
| 135 | return false; |
| 136 | break; |
| 137 | |
| 138 | case GL_UNSIGNED_SHORT: |
| 139 | pathNameTypeSize = sizeof(GLushort); |
| 140 | if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase)) |
| 141 | return false; |
| 142 | break; |
| 143 | |
| 144 | case GL_SHORT: |
| 145 | pathNameTypeSize = sizeof(GLshort); |
| 146 | if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase)) |
| 147 | return false; |
| 148 | break; |
| 149 | |
| 150 | case GL_UNSIGNED_INT: |
| 151 | pathNameTypeSize = sizeof(GLuint); |
| 152 | if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase)) |
| 153 | return false; |
| 154 | break; |
| 155 | |
| 156 | case GL_INT: |
| 157 | pathNameTypeSize = sizeof(GLint); |
| 158 | if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase)) |
| 159 | return false; |
| 160 | break; |
| 161 | |
| 162 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 163 | context->validationError(GL_INVALID_ENUM, kInvalidPathNameType); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 164 | return false; |
| 165 | } |
| 166 | |
| 167 | switch (transformType) |
| 168 | { |
| 169 | case GL_NONE: |
| 170 | componentCount = 0; |
| 171 | break; |
| 172 | case GL_TRANSLATE_X_CHROMIUM: |
| 173 | case GL_TRANSLATE_Y_CHROMIUM: |
| 174 | componentCount = 1; |
| 175 | break; |
| 176 | case GL_TRANSLATE_2D_CHROMIUM: |
| 177 | componentCount = 2; |
| 178 | break; |
| 179 | case GL_TRANSLATE_3D_CHROMIUM: |
| 180 | componentCount = 3; |
| 181 | break; |
| 182 | case GL_AFFINE_2D_CHROMIUM: |
| 183 | case GL_TRANSPOSE_AFFINE_2D_CHROMIUM: |
| 184 | componentCount = 6; |
| 185 | break; |
| 186 | case GL_AFFINE_3D_CHROMIUM: |
| 187 | case GL_TRANSPOSE_AFFINE_3D_CHROMIUM: |
| 188 | componentCount = 12; |
| 189 | break; |
| 190 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 191 | context->validationError(GL_INVALID_ENUM, kInvalidTransformation); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 192 | return false; |
| 193 | } |
| 194 | if (componentCount != 0 && transformValues == nullptr) |
| 195 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 196 | context->validationError(GL_INVALID_VALUE, kNoTransformArray); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 197 | return false; |
| 198 | } |
| 199 | |
| 200 | angle::CheckedNumeric<std::uint32_t> checkedSize(0); |
| 201 | checkedSize += (numPaths * pathNameTypeSize); |
| 202 | checkedSize += (numPaths * sizeof(GLfloat) * componentCount); |
| 203 | if (!checkedSize.IsValid()) |
| 204 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 205 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 206 | return false; |
| 207 | } |
| 208 | |
| 209 | return true; |
| 210 | } |
| 211 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 212 | bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 213 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 214 | // Table 1.1 from the CHROMIUM_copy_texture spec |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 215 | switch (GetUnsizedFormat(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 216 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 217 | case GL_RED: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 218 | case GL_ALPHA: |
| 219 | case GL_LUMINANCE: |
| 220 | case GL_LUMINANCE_ALPHA: |
| 221 | case GL_RGB: |
| 222 | case GL_RGBA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 223 | case GL_RGB8: |
| 224 | case GL_RGBA8: |
| 225 | case GL_BGRA_EXT: |
| 226 | case GL_BGRA8_EXT: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 227 | return true; |
| 228 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 229 | default: |
| 230 | return false; |
| 231 | } |
| 232 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 233 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 234 | bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat) |
| 235 | { |
| 236 | return IsValidCopyTextureSourceInternalFormatEnum(internalFormat); |
| 237 | } |
| 238 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 239 | bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat) |
| 240 | { |
| 241 | // Table 1.0 from the CHROMIUM_copy_texture spec |
| 242 | switch (internalFormat) |
| 243 | { |
| 244 | case GL_RGB: |
| 245 | case GL_RGBA: |
| 246 | case GL_RGB8: |
| 247 | case GL_RGBA8: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 248 | case GL_BGRA_EXT: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 249 | case GL_BGRA8_EXT: |
| 250 | case GL_SRGB_EXT: |
| 251 | case GL_SRGB_ALPHA_EXT: |
| 252 | case GL_R8: |
| 253 | case GL_R8UI: |
| 254 | case GL_RG8: |
| 255 | case GL_RG8UI: |
| 256 | case GL_SRGB8: |
| 257 | case GL_RGB565: |
| 258 | case GL_RGB8UI: |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 259 | case GL_RGB10_A2: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 260 | case GL_SRGB8_ALPHA8: |
| 261 | case GL_RGB5_A1: |
| 262 | case GL_RGBA4: |
| 263 | case GL_RGBA8UI: |
| 264 | case GL_RGB9_E5: |
| 265 | case GL_R16F: |
| 266 | case GL_R32F: |
| 267 | case GL_RG16F: |
| 268 | case GL_RG32F: |
| 269 | case GL_RGB16F: |
| 270 | case GL_RGB32F: |
| 271 | case GL_RGBA16F: |
| 272 | case GL_RGBA32F: |
| 273 | case GL_R11F_G11F_B10F: |
Brandon Jones | 340b7b8 | 2017-06-26 13:02:31 -0700 | [diff] [blame] | 274 | case GL_LUMINANCE: |
| 275 | case GL_LUMINANCE_ALPHA: |
| 276 | case GL_ALPHA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 277 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 278 | |
| 279 | default: |
| 280 | return false; |
| 281 | } |
| 282 | } |
| 283 | |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 284 | bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat) |
| 285 | { |
| 286 | return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat); |
| 287 | } |
| 288 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 289 | bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type) |
| 290 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 291 | if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 292 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 293 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 294 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 297 | if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat)) |
| 298 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 299 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 303 | const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type); |
| 304 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 305 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 306 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 307 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return true; |
| 311 | } |
| 312 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 313 | bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 314 | { |
| 315 | switch (target) |
| 316 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 317 | case TextureTarget::_2D: |
| 318 | case TextureTarget::CubeMapNegativeX: |
| 319 | case TextureTarget::CubeMapNegativeY: |
| 320 | case TextureTarget::CubeMapNegativeZ: |
| 321 | case TextureTarget::CubeMapPositiveX: |
| 322 | case TextureTarget::CubeMapPositiveY: |
| 323 | case TextureTarget::CubeMapPositiveZ: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 324 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 325 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 326 | case TextureTarget::Rectangle: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 327 | return context->getExtensions().textureRectangle; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 328 | |
| 329 | default: |
| 330 | return false; |
| 331 | } |
| 332 | } |
| 333 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 334 | bool IsValidCopyTextureDestinationTarget(Context *context, |
| 335 | TextureType textureType, |
| 336 | TextureTarget target) |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 337 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 338 | return TextureTargetToType(target) == textureType; |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 339 | } |
| 340 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 341 | bool IsValidCopyTextureSourceTarget(Context *context, TextureType type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 342 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 343 | switch (type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 344 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 345 | case TextureType::_2D: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 346 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 347 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 348 | return context->getExtensions().textureRectangle; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 349 | case TextureType::External: |
| 350 | return context->getExtensions().eglImageExternal; |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 351 | default: |
| 352 | return false; |
| 353 | } |
| 354 | } |
| 355 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 356 | bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 357 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 358 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 359 | { |
| 360 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 363 | if (level > 0 && context->getClientVersion() < ES_3_0) |
| 364 | { |
| 365 | return false; |
| 366 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 367 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 368 | return true; |
| 369 | } |
| 370 | |
| 371 | bool IsValidCopyTextureDestinationLevel(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 372 | TextureType type, |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 373 | GLint level, |
| 374 | GLsizei width, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 375 | GLsizei height, |
| 376 | bool isSubImage) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 377 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 378 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 379 | { |
| 380 | return false; |
| 381 | } |
| 382 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 383 | if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage)) |
| 384 | { |
| 385 | return false; |
| 386 | } |
| 387 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 388 | const Caps &caps = context->getCaps(); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 389 | switch (type) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 390 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 391 | case TextureType::_2D: |
| 392 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 393 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
| 394 | case TextureType::Rectangle: |
| 395 | ASSERT(level == 0); |
| 396 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 397 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 398 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 399 | case TextureType::CubeMap: |
| 400 | return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) && |
| 401 | static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level); |
| 402 | default: |
| 403 | return true; |
| 404 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 407 | bool IsValidStencilFunc(GLenum func) |
| 408 | { |
| 409 | switch (func) |
| 410 | { |
| 411 | case GL_NEVER: |
| 412 | case GL_ALWAYS: |
| 413 | case GL_LESS: |
| 414 | case GL_LEQUAL: |
| 415 | case GL_EQUAL: |
| 416 | case GL_GEQUAL: |
| 417 | case GL_GREATER: |
| 418 | case GL_NOTEQUAL: |
| 419 | return true; |
| 420 | |
| 421 | default: |
| 422 | return false; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | bool IsValidStencilFace(GLenum face) |
| 427 | { |
| 428 | switch (face) |
| 429 | { |
| 430 | case GL_FRONT: |
| 431 | case GL_BACK: |
| 432 | case GL_FRONT_AND_BACK: |
| 433 | return true; |
| 434 | |
| 435 | default: |
| 436 | return false; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | bool IsValidStencilOp(GLenum op) |
| 441 | { |
| 442 | switch (op) |
| 443 | { |
| 444 | case GL_ZERO: |
| 445 | case GL_KEEP: |
| 446 | case GL_REPLACE: |
| 447 | case GL_INCR: |
| 448 | case GL_DECR: |
| 449 | case GL_INVERT: |
| 450 | case GL_INCR_WRAP: |
| 451 | case GL_DECR_WRAP: |
| 452 | return true; |
| 453 | |
| 454 | default: |
| 455 | return false; |
| 456 | } |
| 457 | } |
| 458 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 459 | bool ValidateES2CopyTexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 460 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 461 | GLint level, |
| 462 | GLenum internalformat, |
| 463 | bool isSubImage, |
| 464 | GLint xoffset, |
| 465 | GLint yoffset, |
| 466 | GLint x, |
| 467 | GLint y, |
| 468 | GLsizei width, |
| 469 | GLsizei height, |
| 470 | GLint border) |
| 471 | { |
| 472 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 474 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 475 | return false; |
| 476 | } |
| 477 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 478 | TextureType texType = TextureTargetToType(target); |
| 479 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 480 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 481 | // Error is already handled. |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 482 | return false; |
| 483 | } |
| 484 | |
| 485 | Format textureFormat = Format::Invalid(); |
| 486 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 487 | xoffset, yoffset, 0, x, y, width, height, border, |
| 488 | &textureFormat)) |
| 489 | { |
| 490 | return false; |
| 491 | } |
| 492 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 493 | const gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 494 | GLenum colorbufferFormat = |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 495 | framebuffer->getReadColorAttachment()->getFormat().info->sizedInternalFormat; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 496 | const auto &formatInfo = *textureFormat.info; |
| 497 | |
| 498 | // [OpenGL ES 2.0.24] table 3.9 |
| 499 | if (isSubImage) |
| 500 | { |
| 501 | switch (formatInfo.format) |
| 502 | { |
| 503 | case GL_ALPHA: |
| 504 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 505 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 506 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 507 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 508 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 509 | return false; |
| 510 | } |
| 511 | break; |
| 512 | case GL_LUMINANCE: |
| 513 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 514 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 515 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 516 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT && |
| 517 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 518 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 519 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 520 | return false; |
| 521 | } |
| 522 | break; |
| 523 | case GL_RED_EXT: |
| 524 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 525 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 526 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 527 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F && |
| 528 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 529 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 530 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 531 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 532 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 533 | return false; |
| 534 | } |
| 535 | break; |
| 536 | case GL_RG_EXT: |
| 537 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 538 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 539 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 540 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 541 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 542 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 543 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 544 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | break; |
| 548 | case GL_RGB: |
| 549 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 550 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 551 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 552 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 553 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 554 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 555 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 556 | return false; |
| 557 | } |
| 558 | break; |
| 559 | case GL_LUMINANCE_ALPHA: |
| 560 | case GL_RGBA: |
| 561 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 562 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F && |
| 563 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 564 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 565 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 566 | return false; |
| 567 | } |
| 568 | break; |
| 569 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 570 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 571 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 572 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 573 | case GL_ETC1_RGB8_OES: |
| 574 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 575 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 576 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 577 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 578 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 579 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 580 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 581 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 582 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 583 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 584 | return false; |
| 585 | case GL_DEPTH_COMPONENT: |
| 586 | case GL_DEPTH_STENCIL_OES: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 587 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 588 | return false; |
| 589 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 590 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 591 | return false; |
| 592 | } |
| 593 | |
| 594 | if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat) |
| 595 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 596 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 597 | return false; |
| 598 | } |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | switch (internalformat) |
| 603 | { |
| 604 | case GL_ALPHA: |
| 605 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
| 606 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 607 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 608 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 609 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 610 | return false; |
| 611 | } |
| 612 | break; |
| 613 | case GL_LUMINANCE: |
| 614 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 615 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 616 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 617 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 618 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 619 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 620 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 621 | return false; |
| 622 | } |
| 623 | break; |
| 624 | case GL_RED_EXT: |
| 625 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 626 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 627 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 628 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 629 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 630 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 631 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 632 | return false; |
| 633 | } |
| 634 | break; |
| 635 | case GL_RG_EXT: |
| 636 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 637 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 638 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 639 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 640 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 641 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 642 | return false; |
| 643 | } |
| 644 | break; |
| 645 | case GL_RGB: |
| 646 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 647 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 648 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 649 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 650 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 651 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 652 | return false; |
| 653 | } |
| 654 | break; |
| 655 | case GL_LUMINANCE_ALPHA: |
| 656 | case GL_RGBA: |
| 657 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 658 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 659 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 660 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 661 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 662 | return false; |
| 663 | } |
| 664 | break; |
| 665 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 666 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 667 | if (context->getExtensions().textureCompressionDXT1) |
| 668 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 669 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 670 | return false; |
| 671 | } |
| 672 | else |
| 673 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 674 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 675 | return false; |
| 676 | } |
| 677 | break; |
| 678 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 679 | if (context->getExtensions().textureCompressionDXT3) |
| 680 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 681 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 682 | return false; |
| 683 | } |
| 684 | else |
| 685 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 686 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 687 | return false; |
| 688 | } |
| 689 | break; |
| 690 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 691 | if (context->getExtensions().textureCompressionDXT5) |
| 692 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 693 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | else |
| 697 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 698 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 699 | return false; |
| 700 | } |
| 701 | break; |
| 702 | case GL_ETC1_RGB8_OES: |
| 703 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 704 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 705 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 706 | return false; |
| 707 | } |
| 708 | else |
| 709 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 710 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 711 | return false; |
| 712 | } |
| 713 | break; |
| 714 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 715 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 716 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 717 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 718 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 719 | if (context->getExtensions().lossyETCDecode) |
| 720 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 721 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 722 | return false; |
| 723 | } |
| 724 | else |
| 725 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 726 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 727 | return false; |
| 728 | } |
| 729 | break; |
| 730 | case GL_DEPTH_COMPONENT: |
| 731 | case GL_DEPTH_COMPONENT16: |
| 732 | case GL_DEPTH_COMPONENT32_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 733 | if (context->getExtensions().depthTextureAny()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 734 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 735 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 736 | return false; |
| 737 | } |
| 738 | else |
| 739 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 740 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 741 | return false; |
| 742 | } |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 743 | break; |
| 744 | case GL_DEPTH_STENCIL_OES: |
| 745 | case GL_DEPTH24_STENCIL8_OES: |
| 746 | if (context->getExtensions().depthTextureAny() || |
| 747 | context->getExtensions().packedDepthStencil) |
| 748 | { |
| 749 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
| 750 | return false; |
| 751 | } |
| 752 | else |
| 753 | { |
| 754 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 755 | return false; |
| 756 | } |
| 757 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 758 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 759 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 760 | return false; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 765 | return (width > 0 && height > 0); |
| 766 | } |
| 767 | |
| 768 | bool ValidCap(const Context *context, GLenum cap, bool queryOnly) |
| 769 | { |
| 770 | switch (cap) |
| 771 | { |
| 772 | // EXT_multisample_compatibility |
| 773 | case GL_MULTISAMPLE_EXT: |
| 774 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 775 | return context->getExtensions().multisampleCompatibility; |
| 776 | |
| 777 | case GL_CULL_FACE: |
| 778 | case GL_POLYGON_OFFSET_FILL: |
| 779 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 780 | case GL_SAMPLE_COVERAGE: |
| 781 | case GL_SCISSOR_TEST: |
| 782 | case GL_STENCIL_TEST: |
| 783 | case GL_DEPTH_TEST: |
| 784 | case GL_BLEND: |
| 785 | case GL_DITHER: |
| 786 | return true; |
| 787 | |
| 788 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 789 | case GL_RASTERIZER_DISCARD: |
| 790 | return (context->getClientMajorVersion() >= 3); |
| 791 | |
| 792 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 793 | case GL_DEBUG_OUTPUT: |
| 794 | return context->getExtensions().debug; |
| 795 | |
| 796 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 797 | return queryOnly && context->getExtensions().bindGeneratesResource; |
| 798 | |
| 799 | case GL_CLIENT_ARRAYS_ANGLE: |
| 800 | return queryOnly && context->getExtensions().clientArrays; |
| 801 | |
| 802 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 803 | return context->getExtensions().sRGBWriteControl; |
| 804 | |
| 805 | case GL_SAMPLE_MASK: |
| 806 | return context->getClientVersion() >= Version(3, 1); |
| 807 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 808 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 809 | return queryOnly && context->getExtensions().robustResourceInitialization; |
| 810 | |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 811 | // GLES1 emulation: GLES1-specific caps |
| 812 | case GL_ALPHA_TEST: |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 813 | case GL_VERTEX_ARRAY: |
| 814 | case GL_NORMAL_ARRAY: |
| 815 | case GL_COLOR_ARRAY: |
| 816 | case GL_TEXTURE_COORD_ARRAY: |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 817 | case GL_TEXTURE_2D: |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 818 | case GL_LIGHTING: |
| 819 | case GL_LIGHT0: |
| 820 | case GL_LIGHT1: |
| 821 | case GL_LIGHT2: |
| 822 | case GL_LIGHT3: |
| 823 | case GL_LIGHT4: |
| 824 | case GL_LIGHT5: |
| 825 | case GL_LIGHT6: |
| 826 | case GL_LIGHT7: |
| 827 | case GL_NORMALIZE: |
| 828 | case GL_RESCALE_NORMAL: |
| 829 | case GL_COLOR_MATERIAL: |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 830 | case GL_CLIP_PLANE0: |
| 831 | case GL_CLIP_PLANE1: |
| 832 | case GL_CLIP_PLANE2: |
| 833 | case GL_CLIP_PLANE3: |
| 834 | case GL_CLIP_PLANE4: |
| 835 | case GL_CLIP_PLANE5: |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 836 | case GL_FOG: |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 837 | case GL_POINT_SMOOTH: |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 838 | case GL_LINE_SMOOTH: |
| 839 | case GL_COLOR_LOGIC_OP: |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 840 | return context->getClientVersion() < Version(2, 0); |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 841 | case GL_POINT_SIZE_ARRAY_OES: |
| 842 | return context->getClientVersion() < Version(2, 0) && |
| 843 | context->getExtensions().pointSizeArray; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 844 | case GL_TEXTURE_CUBE_MAP: |
| 845 | return context->getClientVersion() < Version(2, 0) && |
| 846 | context->getExtensions().textureCubeMap; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 847 | case GL_POINT_SPRITE_OES: |
| 848 | return context->getClientVersion() < Version(2, 0) && |
| 849 | context->getExtensions().pointSprite; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 850 | default: |
| 851 | return false; |
| 852 | } |
| 853 | } |
| 854 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 855 | // Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section |
| 856 | // 3.1. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 857 | bool IsValidESSLCharacter(unsigned char c) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 858 | { |
| 859 | // Printing characters are valid except " $ ` @ \ ' DEL. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 860 | if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' && |
| 861 | c != '\'') |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 862 | { |
| 863 | return true; |
| 864 | } |
| 865 | |
| 866 | // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid. |
| 867 | if (c >= 9 && c <= 13) |
| 868 | { |
| 869 | return true; |
| 870 | } |
| 871 | |
| 872 | return false; |
| 873 | } |
| 874 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 875 | bool IsValidESSLString(const char *str, size_t len) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 876 | { |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 877 | for (size_t i = 0; i < len; i++) |
| 878 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 879 | if (!IsValidESSLCharacter(str[i])) |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 880 | { |
| 881 | return false; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | return true; |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 886 | } |
| 887 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 888 | bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed) |
| 889 | { |
| 890 | enum class ParseState |
| 891 | { |
| 892 | // Have not seen an ASCII non-whitespace character yet on |
| 893 | // this line. Possible that we might see a preprocessor |
| 894 | // directive. |
| 895 | BEGINING_OF_LINE, |
| 896 | |
| 897 | // Have seen at least one ASCII non-whitespace character |
| 898 | // on this line. |
| 899 | MIDDLE_OF_LINE, |
| 900 | |
| 901 | // Handling a preprocessor directive. Passes through all |
| 902 | // characters up to the end of the line. Disables comment |
| 903 | // processing. |
| 904 | IN_PREPROCESSOR_DIRECTIVE, |
| 905 | |
| 906 | // Handling a single-line comment. The comment text is |
| 907 | // replaced with a single space. |
| 908 | IN_SINGLE_LINE_COMMENT, |
| 909 | |
| 910 | // Handling a multi-line comment. Newlines are passed |
| 911 | // through to preserve line numbers. |
| 912 | IN_MULTI_LINE_COMMENT |
| 913 | }; |
| 914 | |
| 915 | ParseState state = ParseState::BEGINING_OF_LINE; |
| 916 | size_t pos = 0; |
| 917 | |
| 918 | while (pos < len) |
| 919 | { |
| 920 | char c = str[pos]; |
| 921 | char next = pos + 1 < len ? str[pos + 1] : 0; |
| 922 | |
| 923 | // Check for newlines |
| 924 | if (c == '\n' || c == '\r') |
| 925 | { |
| 926 | if (state != ParseState::IN_MULTI_LINE_COMMENT) |
| 927 | { |
| 928 | state = ParseState::BEGINING_OF_LINE; |
| 929 | } |
| 930 | |
| 931 | pos++; |
| 932 | continue; |
| 933 | } |
| 934 | |
| 935 | switch (state) |
| 936 | { |
| 937 | case ParseState::BEGINING_OF_LINE: |
| 938 | if (c == ' ') |
| 939 | { |
| 940 | // Maintain the BEGINING_OF_LINE state until a non-space is seen |
| 941 | pos++; |
| 942 | } |
| 943 | else if (c == '#') |
| 944 | { |
| 945 | state = ParseState::IN_PREPROCESSOR_DIRECTIVE; |
| 946 | pos++; |
| 947 | } |
| 948 | else |
| 949 | { |
| 950 | // Don't advance, re-process this character with the MIDDLE_OF_LINE state |
| 951 | state = ParseState::MIDDLE_OF_LINE; |
| 952 | } |
| 953 | break; |
| 954 | |
| 955 | case ParseState::MIDDLE_OF_LINE: |
| 956 | if (c == '/' && next == '/') |
| 957 | { |
| 958 | state = ParseState::IN_SINGLE_LINE_COMMENT; |
| 959 | pos++; |
| 960 | } |
| 961 | else if (c == '/' && next == '*') |
| 962 | { |
| 963 | state = ParseState::IN_MULTI_LINE_COMMENT; |
| 964 | pos++; |
| 965 | } |
| 966 | else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r')) |
| 967 | { |
| 968 | // Skip line continuation characters |
| 969 | } |
| 970 | else if (!IsValidESSLCharacter(c)) |
| 971 | { |
| 972 | return false; |
| 973 | } |
| 974 | pos++; |
| 975 | break; |
| 976 | |
| 977 | case ParseState::IN_PREPROCESSOR_DIRECTIVE: |
Bryan Bernhart (Intel Americas Inc) | 335d8bf | 2017-10-23 15:41:43 -0700 | [diff] [blame] | 978 | // Line-continuation characters may not be permitted. |
| 979 | // Otherwise, just pass it through. Do not parse comments in this state. |
| 980 | if (!lineContinuationAllowed && c == '\\') |
| 981 | { |
| 982 | return false; |
| 983 | } |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 984 | pos++; |
| 985 | break; |
| 986 | |
| 987 | case ParseState::IN_SINGLE_LINE_COMMENT: |
| 988 | // Line-continuation characters are processed before comment processing. |
| 989 | // Advance string if a new line character is immediately behind |
| 990 | // line-continuation character. |
| 991 | if (c == '\\' && (next == '\n' || next == '\r')) |
| 992 | { |
| 993 | pos++; |
| 994 | } |
| 995 | pos++; |
| 996 | break; |
| 997 | |
| 998 | case ParseState::IN_MULTI_LINE_COMMENT: |
| 999 | if (c == '*' && next == '/') |
| 1000 | { |
| 1001 | state = ParseState::MIDDLE_OF_LINE; |
| 1002 | pos++; |
| 1003 | } |
| 1004 | pos++; |
| 1005 | break; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | return true; |
| 1010 | } |
| 1011 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1012 | bool ValidateWebGLNamePrefix(Context *context, const GLchar *name) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1013 | { |
| 1014 | ASSERT(context->isWebGL()); |
| 1015 | |
| 1016 | // WebGL 1.0 [Section 6.16] GLSL Constructs |
| 1017 | // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL. |
| 1018 | if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0) |
| 1019 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1020 | context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1021 | return false; |
| 1022 | } |
| 1023 | |
| 1024 | return true; |
| 1025 | } |
| 1026 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1027 | bool ValidateWebGLNameLength(Context *context, size_t length) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1028 | { |
| 1029 | ASSERT(context->isWebGL()); |
| 1030 | |
| 1031 | if (context->isWebGL1() && length > 256) |
| 1032 | { |
| 1033 | // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths |
| 1034 | // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute |
| 1035 | // locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1036 | context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1037 | |
| 1038 | return false; |
| 1039 | } |
| 1040 | else if (length > 1024) |
| 1041 | { |
| 1042 | // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of |
| 1043 | // uniform and attribute locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1044 | context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1045 | return false; |
| 1046 | } |
| 1047 | |
| 1048 | return true; |
| 1049 | } |
| 1050 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1051 | bool ValidateMatrixMode(Context *context, GLenum matrixMode) |
| 1052 | { |
| 1053 | if (!context->getExtensions().pathRendering) |
| 1054 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1055 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1056 | return false; |
| 1057 | } |
| 1058 | |
| 1059 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 1060 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1061 | context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1062 | return false; |
| 1063 | } |
| 1064 | return true; |
| 1065 | } |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 1066 | |
| 1067 | bool ValidBlendFunc(const Context *context, GLenum val) |
| 1068 | { |
| 1069 | const gl::Extensions &ext = context->getExtensions(); |
| 1070 | |
| 1071 | // these are always valid for src and dst. |
| 1072 | switch (val) |
| 1073 | { |
| 1074 | case GL_ZERO: |
| 1075 | case GL_ONE: |
| 1076 | case GL_SRC_COLOR: |
| 1077 | case GL_ONE_MINUS_SRC_COLOR: |
| 1078 | case GL_DST_COLOR: |
| 1079 | case GL_ONE_MINUS_DST_COLOR: |
| 1080 | case GL_SRC_ALPHA: |
| 1081 | case GL_ONE_MINUS_SRC_ALPHA: |
| 1082 | case GL_DST_ALPHA: |
| 1083 | case GL_ONE_MINUS_DST_ALPHA: |
| 1084 | case GL_CONSTANT_COLOR: |
| 1085 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 1086 | case GL_CONSTANT_ALPHA: |
| 1087 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 1088 | return true; |
| 1089 | |
| 1090 | // EXT_blend_func_extended. |
| 1091 | case GL_SRC1_COLOR_EXT: |
| 1092 | case GL_SRC1_ALPHA_EXT: |
| 1093 | case GL_ONE_MINUS_SRC1_COLOR_EXT: |
| 1094 | case GL_ONE_MINUS_SRC1_ALPHA_EXT: |
| 1095 | case GL_SRC_ALPHA_SATURATE_EXT: |
| 1096 | return ext.blendFuncExtended; |
| 1097 | |
| 1098 | default: |
| 1099 | return false; |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | bool ValidSrcBlendFunc(const Context *context, GLenum val) |
| 1104 | { |
| 1105 | if (ValidBlendFunc(context, val)) |
| 1106 | return true; |
| 1107 | |
| 1108 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1109 | return true; |
| 1110 | |
| 1111 | return false; |
| 1112 | } |
| 1113 | |
| 1114 | bool ValidDstBlendFunc(const Context *context, GLenum val) |
| 1115 | { |
| 1116 | if (ValidBlendFunc(context, val)) |
| 1117 | return true; |
| 1118 | |
| 1119 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1120 | { |
| 1121 | if (context->getClientMajorVersion() >= 3) |
| 1122 | return true; |
| 1123 | } |
| 1124 | |
| 1125 | return false; |
| 1126 | } |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 1127 | |
| 1128 | bool IsValidImageLayout(ImageLayout layout) |
| 1129 | { |
| 1130 | switch (layout) |
| 1131 | { |
Michael Spang | 6c824a1 | 2019-06-18 15:43:33 -0400 | [diff] [blame] | 1132 | case ImageLayout::Undefined: |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 1133 | case ImageLayout::General: |
| 1134 | case ImageLayout::ColorAttachment: |
| 1135 | case ImageLayout::DepthStencilAttachment: |
| 1136 | case ImageLayout::DepthStencilReadOnlyAttachment: |
| 1137 | case ImageLayout::ShaderReadOnly: |
| 1138 | case ImageLayout::TransferSrc: |
| 1139 | case ImageLayout::TransferDst: |
| 1140 | case ImageLayout::DepthReadOnlyStencilAttachment: |
| 1141 | case ImageLayout::DepthAttachmentStencilReadOnly: |
| 1142 | return true; |
| 1143 | |
| 1144 | default: |
| 1145 | return false; |
| 1146 | } |
| 1147 | } |
| 1148 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1149 | bool ValidateES2TexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1150 | TextureTarget target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1151 | GLint level, |
| 1152 | GLenum internalformat, |
| 1153 | bool isCompressed, |
| 1154 | bool isSubImage, |
| 1155 | GLint xoffset, |
| 1156 | GLint yoffset, |
| 1157 | GLsizei width, |
| 1158 | GLsizei height, |
| 1159 | GLint border, |
| 1160 | GLenum format, |
| 1161 | GLenum type, |
| 1162 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1163 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1164 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1165 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1166 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1167 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1168 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1169 | } |
| 1170 | |
Geoff Lang | 857880e | 2019-05-27 13:39:15 -0400 | [diff] [blame] | 1171 | return ValidateES2TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 1172 | isSubImage, xoffset, yoffset, width, height, border, |
| 1173 | format, type, imageSize, pixels); |
| 1174 | } |
| 1175 | |
| 1176 | } // anonymous namespace |
| 1177 | |
| 1178 | bool ValidateES2TexImageParametersBase(Context *context, |
| 1179 | TextureTarget target, |
| 1180 | GLint level, |
| 1181 | GLenum internalformat, |
| 1182 | bool isCompressed, |
| 1183 | bool isSubImage, |
| 1184 | GLint xoffset, |
| 1185 | GLint yoffset, |
| 1186 | GLsizei width, |
| 1187 | GLsizei height, |
| 1188 | GLint border, |
| 1189 | GLenum format, |
| 1190 | GLenum type, |
| 1191 | GLsizei imageSize, |
| 1192 | const void *pixels) |
| 1193 | { |
| 1194 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1195 | TextureType texType = TextureTargetToType(target); |
| 1196 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1197 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1198 | // Error already handled. |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1199 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1200 | } |
| 1201 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1202 | if (!ValidMipLevel(context, texType, level)) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1203 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1204 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1205 | return false; |
| 1206 | } |
| 1207 | |
| 1208 | if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width || |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1209 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1210 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1211 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1212 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1213 | } |
| 1214 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1215 | const gl::Caps &caps = context->getCaps(); |
| 1216 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1217 | switch (texType) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1218 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1219 | case TextureType::_2D: |
Geoff Lang | 857880e | 2019-05-27 13:39:15 -0400 | [diff] [blame] | 1220 | case TextureType::External: |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1221 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 1222 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 1223 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1224 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1225 | return false; |
| 1226 | } |
| 1227 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1228 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1229 | case TextureType::Rectangle: |
| 1230 | ASSERT(level == 0); |
| 1231 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1232 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1233 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1234 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1235 | return false; |
| 1236 | } |
| 1237 | if (isCompressed) |
| 1238 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1239 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1240 | return false; |
| 1241 | } |
| 1242 | break; |
| 1243 | |
| 1244 | case TextureType::CubeMap: |
| 1245 | if (!isSubImage && width != height) |
| 1246 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1247 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1248 | return false; |
| 1249 | } |
| 1250 | |
| 1251 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 1252 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 1253 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1254 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1255 | return false; |
| 1256 | } |
| 1257 | break; |
| 1258 | |
| 1259 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1260 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1261 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1262 | } |
| 1263 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 1264 | gl::Texture *texture = context->getTextureByType(texType); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1265 | if (!texture) |
| 1266 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1267 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1268 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1269 | } |
| 1270 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1271 | // Verify zero border |
| 1272 | if (border != 0) |
| 1273 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1274 | context->validationError(GL_INVALID_VALUE, kInvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1275 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1276 | } |
| 1277 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1278 | bool nonEqualFormatsAllowed = false; |
| 1279 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1280 | if (isCompressed) |
| 1281 | { |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1282 | GLenum actualInternalFormat = |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1283 | isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat |
| 1284 | : internalformat; |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1285 | |
| 1286 | const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat); |
| 1287 | |
| 1288 | if (!internalFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1289 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1290 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1291 | return false; |
| 1292 | } |
| 1293 | |
| 1294 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), |
| 1295 | context->getExtensions())) |
| 1296 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1297 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1298 | return false; |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1299 | } |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1300 | |
| 1301 | if (isSubImage) |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1302 | { |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1303 | // From the OES_compressed_ETC1_RGB8_texture spec: |
| 1304 | // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or |
| 1305 | // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format |
| 1306 | // ETC1_RGB8_OES. |
| 1307 | if (actualInternalFormat == GL_ETC1_RGB8_OES) |
| 1308 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1309 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1310 | return false; |
| 1311 | } |
| 1312 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1313 | if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width, |
| 1314 | height, texture->getWidth(target, level), |
| 1315 | texture->getHeight(target, level))) |
| 1316 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1317 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1318 | return false; |
| 1319 | } |
| 1320 | |
| 1321 | if (format != actualInternalFormat) |
| 1322 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1323 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1324 | return false; |
| 1325 | } |
| 1326 | } |
| 1327 | else |
| 1328 | { |
| 1329 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 1330 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1331 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1332 | return false; |
| 1333 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1334 | } |
| 1335 | } |
| 1336 | else |
| 1337 | { |
| 1338 | // validate <type> by itself (used as secondary key below) |
| 1339 | switch (type) |
| 1340 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1341 | case GL_UNSIGNED_BYTE: |
| 1342 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1343 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1344 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1345 | case GL_UNSIGNED_SHORT: |
| 1346 | case GL_UNSIGNED_INT: |
| 1347 | case GL_UNSIGNED_INT_24_8_OES: |
| 1348 | case GL_HALF_FLOAT_OES: |
| 1349 | case GL_FLOAT: |
| 1350 | break; |
| 1351 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1352 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1353 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | // validate <format> + <type> combinations |
| 1357 | // - invalid <format> -> sets INVALID_ENUM |
| 1358 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 1359 | switch (format) |
| 1360 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1361 | case GL_ALPHA: |
| 1362 | case GL_LUMINANCE: |
| 1363 | case GL_LUMINANCE_ALPHA: |
| 1364 | switch (type) |
| 1365 | { |
| 1366 | case GL_UNSIGNED_BYTE: |
| 1367 | case GL_FLOAT: |
| 1368 | case GL_HALF_FLOAT_OES: |
| 1369 | break; |
| 1370 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1371 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1372 | return false; |
| 1373 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1374 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1375 | case GL_RED: |
| 1376 | case GL_RG: |
| 1377 | if (!context->getExtensions().textureRG) |
| 1378 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1379 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1380 | return false; |
| 1381 | } |
| 1382 | switch (type) |
| 1383 | { |
| 1384 | case GL_UNSIGNED_BYTE: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1385 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1386 | case GL_FLOAT: |
| 1387 | case GL_HALF_FLOAT_OES: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1388 | if (!context->getExtensions().textureFloat) |
| 1389 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1390 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1391 | return false; |
| 1392 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1393 | break; |
| 1394 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1395 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1396 | return false; |
| 1397 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1398 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1399 | case GL_RGB: |
| 1400 | switch (type) |
| 1401 | { |
| 1402 | case GL_UNSIGNED_BYTE: |
| 1403 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1404 | case GL_FLOAT: |
| 1405 | case GL_HALF_FLOAT_OES: |
| 1406 | break; |
| 1407 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1408 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1409 | return false; |
| 1410 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1411 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1412 | case GL_RGBA: |
| 1413 | switch (type) |
| 1414 | { |
| 1415 | case GL_UNSIGNED_BYTE: |
| 1416 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1417 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1418 | case GL_FLOAT: |
| 1419 | case GL_HALF_FLOAT_OES: |
| 1420 | break; |
| 1421 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1422 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1423 | return false; |
| 1424 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1425 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1426 | case GL_BGRA_EXT: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1427 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1428 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1429 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1430 | return false; |
| 1431 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1432 | switch (type) |
| 1433 | { |
| 1434 | case GL_UNSIGNED_BYTE: |
| 1435 | break; |
| 1436 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1437 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1438 | return false; |
| 1439 | } |
| 1440 | break; |
| 1441 | case GL_SRGB_EXT: |
| 1442 | case GL_SRGB_ALPHA_EXT: |
| 1443 | if (!context->getExtensions().sRGB) |
| 1444 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1445 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1446 | return false; |
| 1447 | } |
| 1448 | switch (type) |
| 1449 | { |
| 1450 | case GL_UNSIGNED_BYTE: |
| 1451 | break; |
| 1452 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1453 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1454 | return false; |
| 1455 | } |
| 1456 | break; |
| 1457 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1458 | // handled below |
| 1459 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1460 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1461 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1462 | break; |
| 1463 | case GL_DEPTH_COMPONENT: |
| 1464 | switch (type) |
| 1465 | { |
| 1466 | case GL_UNSIGNED_SHORT: |
| 1467 | case GL_UNSIGNED_INT: |
| 1468 | break; |
| 1469 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1470 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1471 | return false; |
| 1472 | } |
| 1473 | break; |
| 1474 | case GL_DEPTH_STENCIL_OES: |
| 1475 | switch (type) |
| 1476 | { |
| 1477 | case GL_UNSIGNED_INT_24_8_OES: |
| 1478 | break; |
| 1479 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1480 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1481 | return false; |
| 1482 | } |
| 1483 | break; |
| 1484 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1485 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1486 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | switch (format) |
| 1490 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1491 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1492 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1493 | if (context->getExtensions().textureCompressionDXT1) |
| 1494 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1495 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1496 | return false; |
| 1497 | } |
| 1498 | else |
| 1499 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1500 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1501 | return false; |
| 1502 | } |
| 1503 | break; |
| 1504 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1505 | if (context->getExtensions().textureCompressionDXT3) |
| 1506 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1507 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1508 | return false; |
| 1509 | } |
| 1510 | else |
| 1511 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1512 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1513 | return false; |
| 1514 | } |
| 1515 | break; |
| 1516 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1517 | if (context->getExtensions().textureCompressionDXT5) |
| 1518 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1519 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1520 | return false; |
| 1521 | } |
| 1522 | else |
| 1523 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1524 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1525 | return false; |
| 1526 | } |
| 1527 | break; |
| 1528 | case GL_ETC1_RGB8_OES: |
| 1529 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1530 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1531 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1532 | return false; |
| 1533 | } |
| 1534 | else |
| 1535 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1536 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1537 | return false; |
| 1538 | } |
| 1539 | break; |
| 1540 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1541 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1542 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1543 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1544 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1545 | if (context->getExtensions().lossyETCDecode) |
| 1546 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1547 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1548 | return false; |
| 1549 | } |
| 1550 | else |
| 1551 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1552 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1553 | return false; |
| 1554 | } |
| 1555 | break; |
| 1556 | case GL_DEPTH_COMPONENT: |
| 1557 | case GL_DEPTH_STENCIL_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1558 | if (!context->getExtensions().depthTextureANGLE && |
| 1559 | !(context->getExtensions().packedDepthStencil && |
| 1560 | context->getExtensions().depthTextureOES)) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1561 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1562 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1563 | return false; |
| 1564 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1565 | if (target != TextureTarget::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1566 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1567 | context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1568 | return false; |
| 1569 | } |
| 1570 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1571 | // but ANGLE_depth_texture does not |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1572 | if (!context->getExtensions().depthTextureOES) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1573 | { |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1574 | if (pixels != nullptr) |
| 1575 | { |
| 1576 | context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull); |
| 1577 | return false; |
| 1578 | } |
| 1579 | if (level != 0) |
| 1580 | { |
| 1581 | context->validationError(GL_INVALID_OPERATION, kLevelNotZero); |
| 1582 | return false; |
| 1583 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1584 | } |
| 1585 | break; |
| 1586 | default: |
| 1587 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1588 | } |
| 1589 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1590 | if (!isSubImage) |
| 1591 | { |
| 1592 | switch (internalformat) |
| 1593 | { |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1594 | // Core ES 2.0 formats |
| 1595 | case GL_ALPHA: |
| 1596 | case GL_LUMINANCE: |
| 1597 | case GL_LUMINANCE_ALPHA: |
| 1598 | case GL_RGB: |
| 1599 | case GL_RGBA: |
| 1600 | break; |
| 1601 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1602 | case GL_RGBA32F: |
| 1603 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1604 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1605 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1606 | return false; |
| 1607 | } |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1608 | |
| 1609 | nonEqualFormatsAllowed = true; |
| 1610 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1611 | if (type != GL_FLOAT) |
| 1612 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1613 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1614 | return false; |
| 1615 | } |
| 1616 | if (format != GL_RGBA) |
| 1617 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1618 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1619 | return false; |
| 1620 | } |
| 1621 | break; |
| 1622 | |
| 1623 | case GL_RGB32F: |
| 1624 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1625 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1626 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1627 | return false; |
| 1628 | } |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1629 | |
| 1630 | nonEqualFormatsAllowed = true; |
| 1631 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1632 | if (type != GL_FLOAT) |
| 1633 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1634 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1635 | return false; |
| 1636 | } |
| 1637 | if (format != GL_RGB) |
| 1638 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1639 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1640 | return false; |
| 1641 | } |
| 1642 | break; |
| 1643 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1644 | case GL_BGRA_EXT: |
| 1645 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1646 | { |
| 1647 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1648 | return false; |
| 1649 | } |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1650 | break; |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1651 | |
| 1652 | case GL_DEPTH_COMPONENT: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1653 | if (!(context->getExtensions().depthTextureAny())) |
| 1654 | { |
| 1655 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1656 | return false; |
| 1657 | } |
| 1658 | break; |
| 1659 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1660 | case GL_DEPTH_STENCIL: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1661 | if (!(context->getExtensions().depthTextureANGLE || |
| 1662 | context->getExtensions().packedDepthStencil)) |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1663 | { |
| 1664 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1665 | return false; |
| 1666 | } |
| 1667 | break; |
| 1668 | |
| 1669 | case GL_RED: |
| 1670 | case GL_RG: |
| 1671 | if (!context->getExtensions().textureRG) |
| 1672 | { |
| 1673 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1674 | return false; |
| 1675 | } |
| 1676 | break; |
| 1677 | |
| 1678 | case GL_SRGB_EXT: |
| 1679 | case GL_SRGB_ALPHA_EXT: |
| 1680 | if (!context->getExtensions().sRGB) |
| 1681 | { |
| 1682 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1683 | return false; |
| 1684 | } |
| 1685 | break; |
| 1686 | |
| 1687 | default: |
| 1688 | context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat); |
| 1689 | return false; |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1690 | } |
| 1691 | } |
| 1692 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1693 | if (type == GL_FLOAT) |
| 1694 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1695 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1696 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1697 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1698 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | else if (type == GL_HALF_FLOAT_OES) |
| 1702 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1703 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1704 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1705 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1706 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1711 | if (isSubImage) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1712 | { |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1713 | const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info; |
| 1714 | if (textureInternalFormat.internalFormat == GL_NONE) |
| 1715 | { |
| 1716 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel); |
| 1717 | return false; |
| 1718 | } |
| 1719 | |
Tim Van Patten | 5f388c2 | 2019-03-14 09:54:23 -0600 | [diff] [blame] | 1720 | if (format != textureInternalFormat.format) |
| 1721 | { |
| 1722 | context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch); |
| 1723 | return false; |
| 1724 | } |
| 1725 | |
| 1726 | if (context->getExtensions().webglCompatibility) |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1727 | { |
| 1728 | if (GetInternalFormatInfo(format, type).sizedInternalFormat != |
| 1729 | textureInternalFormat.sizedInternalFormat) |
| 1730 | { |
Tim Van Patten | 5f388c2 | 2019-03-14 09:54:23 -0600 | [diff] [blame] | 1731 | context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch); |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1732 | return false; |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1737 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 1738 | { |
| 1739 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
| 1740 | return false; |
| 1741 | } |
| 1742 | |
| 1743 | if (width > 0 && height > 0 && pixels == nullptr && |
| 1744 | context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr) |
| 1745 | { |
| 1746 | context->validationError(GL_INVALID_VALUE, kPixelDataNull); |
| 1747 | return false; |
| 1748 | } |
| 1749 | } |
| 1750 | else |
| 1751 | { |
| 1752 | if (texture->getImmutableFormat()) |
| 1753 | { |
| 1754 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
| 1755 | return false; |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | // From GL_CHROMIUM_color_buffer_float_rgb[a]: |
| 1760 | // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for |
| 1761 | // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the |
| 1762 | // internalformat parameter and format parameter of TexImage2D must match is lifted for this |
| 1763 | // case. |
| 1764 | if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed) |
| 1765 | { |
| 1766 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1767 | return false; |
| 1768 | } |
| 1769 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1770 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
| 1771 | return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels, |
| 1772 | imageSize); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1773 | } |
| 1774 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1775 | bool ValidateES2TexStorageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1776 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1777 | GLsizei levels, |
| 1778 | GLenum internalformat, |
| 1779 | GLsizei width, |
| 1780 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1781 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1782 | if (target != TextureType::_2D && target != TextureType::CubeMap && |
| 1783 | target != TextureType::Rectangle) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1784 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1785 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1786 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | if (width < 1 || height < 1 || levels < 1) |
| 1790 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1791 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1792 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1793 | } |
| 1794 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1795 | if (target == TextureType::CubeMap && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1796 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1797 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1798 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1802 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1803 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1804 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1805 | } |
| 1806 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1807 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1808 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1809 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1810 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1811 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1814 | const gl::Caps &caps = context->getCaps(); |
| 1815 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1816 | switch (target) |
| 1817 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1818 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1819 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1820 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1821 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1822 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1823 | return false; |
| 1824 | } |
| 1825 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1826 | case TextureType::Rectangle: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1827 | if (levels != 1) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1828 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1829 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1830 | return false; |
| 1831 | } |
| 1832 | |
| 1833 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1834 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1835 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1836 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1837 | return false; |
| 1838 | } |
| 1839 | if (formatInfo.compressed) |
| 1840 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1841 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1842 | return false; |
| 1843 | } |
| 1844 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1845 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1846 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1847 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1848 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1849 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1850 | return false; |
| 1851 | } |
| 1852 | break; |
| 1853 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1854 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1855 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1856 | } |
| 1857 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1858 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1859 | { |
| 1860 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1861 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1862 | context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1863 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | switch (internalformat) |
| 1868 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1869 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1870 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1871 | if (!context->getExtensions().textureCompressionDXT1) |
| 1872 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1873 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1874 | return false; |
| 1875 | } |
| 1876 | break; |
| 1877 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1878 | if (!context->getExtensions().textureCompressionDXT3) |
| 1879 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1880 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1881 | return false; |
| 1882 | } |
| 1883 | break; |
| 1884 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1885 | if (!context->getExtensions().textureCompressionDXT5) |
| 1886 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1887 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1888 | return false; |
| 1889 | } |
| 1890 | break; |
| 1891 | case GL_ETC1_RGB8_OES: |
| 1892 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1893 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1894 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1895 | return false; |
| 1896 | } |
| 1897 | break; |
| 1898 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1899 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1900 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1901 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1902 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1903 | if (!context->getExtensions().lossyETCDecode) |
| 1904 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1905 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1906 | return false; |
| 1907 | } |
| 1908 | break; |
| 1909 | case GL_RGBA32F_EXT: |
| 1910 | case GL_RGB32F_EXT: |
| 1911 | case GL_ALPHA32F_EXT: |
| 1912 | case GL_LUMINANCE32F_EXT: |
| 1913 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 1914 | if (!context->getExtensions().textureFloat) |
| 1915 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1916 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1917 | return false; |
| 1918 | } |
| 1919 | break; |
| 1920 | case GL_RGBA16F_EXT: |
| 1921 | case GL_RGB16F_EXT: |
| 1922 | case GL_ALPHA16F_EXT: |
| 1923 | case GL_LUMINANCE16F_EXT: |
| 1924 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 1925 | if (!context->getExtensions().textureHalfFloat) |
| 1926 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1927 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1928 | return false; |
| 1929 | } |
| 1930 | break; |
| 1931 | case GL_R8_EXT: |
| 1932 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1933 | if (!context->getExtensions().textureRG) |
| 1934 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1935 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1936 | return false; |
| 1937 | } |
| 1938 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1939 | case GL_R16F_EXT: |
| 1940 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1941 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 1942 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1943 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1944 | return false; |
| 1945 | } |
| 1946 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1947 | case GL_R32F_EXT: |
| 1948 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1949 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1950 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1951 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1952 | return false; |
| 1953 | } |
| 1954 | break; |
| 1955 | case GL_DEPTH_COMPONENT16: |
| 1956 | case GL_DEPTH_COMPONENT32_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1957 | if (!(context->getExtensions().depthTextureAny())) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1958 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1959 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1960 | return false; |
| 1961 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1962 | if (target != TextureType::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1963 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1964 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1965 | return false; |
| 1966 | } |
| 1967 | // ANGLE_depth_texture only supports 1-level textures |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1968 | if (!context->getExtensions().depthTextureOES) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1969 | { |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1970 | if (levels != 1) |
| 1971 | { |
| 1972 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
| 1973 | return false; |
| 1974 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1975 | } |
| 1976 | break; |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1977 | case GL_DEPTH24_STENCIL8_OES: |
| 1978 | if (!(context->getExtensions().depthTextureANGLE || |
| 1979 | (context->getExtensions().packedDepthStencil && |
| 1980 | context->getExtensions().textureStorage))) |
| 1981 | { |
| 1982 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1983 | return false; |
| 1984 | } |
| 1985 | if (target != TextureType::_2D) |
| 1986 | { |
| 1987 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
| 1988 | return false; |
| 1989 | } |
| 1990 | if (!context->getExtensions().packedDepthStencil) |
| 1991 | { |
| 1992 | // ANGLE_depth_texture only supports 1-level textures |
| 1993 | if (levels != 1) |
| 1994 | { |
| 1995 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
| 1996 | return false; |
| 1997 | } |
| 1998 | } |
| 1999 | break; |
| 2000 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2001 | default: |
| 2002 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2003 | } |
| 2004 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 2005 | gl::Texture *texture = context->getTextureByType(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2006 | if (!texture || texture->id() == 0) |
| 2007 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2008 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2009 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2010 | } |
| 2011 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2012 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2013 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2014 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2015 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | return true; |
| 2019 | } |
| 2020 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2021 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 2022 | GLenum target, |
| 2023 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2024 | const GLenum *attachments) |
| 2025 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2026 | if (!context->getExtensions().discardFramebuffer) |
| 2027 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2028 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2029 | return false; |
| 2030 | } |
| 2031 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2032 | bool defaultFramebuffer = false; |
| 2033 | |
| 2034 | switch (target) |
| 2035 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2036 | case GL_FRAMEBUFFER: |
| 2037 | defaultFramebuffer = |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2038 | (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2039 | break; |
| 2040 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2041 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2042 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2045 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 2046 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2049 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 2050 | { |
| 2051 | if (!context->getExtensions().vertexArrayObject) |
| 2052 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2053 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2054 | return false; |
| 2055 | } |
| 2056 | |
| 2057 | return ValidateBindVertexArrayBase(context, array); |
| 2058 | } |
| 2059 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 2060 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2061 | { |
| 2062 | if (!context->getExtensions().vertexArrayObject) |
| 2063 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2064 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2065 | return false; |
| 2066 | } |
| 2067 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2068 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 2071 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2072 | { |
| 2073 | if (!context->getExtensions().vertexArrayObject) |
| 2074 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2075 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2076 | return false; |
| 2077 | } |
| 2078 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2079 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 2082 | bool ValidateIsVertexArrayOES(Context *context, GLuint array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2083 | { |
| 2084 | if (!context->getExtensions().vertexArrayObject) |
| 2085 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2086 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2087 | return false; |
| 2088 | } |
| 2089 | |
| 2090 | return true; |
| 2091 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2092 | |
| 2093 | bool ValidateProgramBinaryOES(Context *context, |
| 2094 | GLuint program, |
| 2095 | GLenum binaryFormat, |
| 2096 | const void *binary, |
| 2097 | GLint length) |
| 2098 | { |
| 2099 | if (!context->getExtensions().getProgramBinary) |
| 2100 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2101 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2102 | return false; |
| 2103 | } |
| 2104 | |
| 2105 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 2106 | } |
| 2107 | |
| 2108 | bool ValidateGetProgramBinaryOES(Context *context, |
| 2109 | GLuint program, |
| 2110 | GLsizei bufSize, |
| 2111 | GLsizei *length, |
| 2112 | GLenum *binaryFormat, |
| 2113 | void *binary) |
| 2114 | { |
| 2115 | if (!context->getExtensions().getProgramBinary) |
| 2116 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2117 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2118 | return false; |
| 2119 | } |
| 2120 | |
| 2121 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 2122 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2123 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2124 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 2125 | { |
| 2126 | switch (source) |
| 2127 | { |
| 2128 | case GL_DEBUG_SOURCE_API: |
| 2129 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 2130 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 2131 | case GL_DEBUG_SOURCE_OTHER: |
| 2132 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 2133 | return !mustBeThirdPartyOrApplication; |
| 2134 | |
| 2135 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 2136 | case GL_DEBUG_SOURCE_APPLICATION: |
| 2137 | return true; |
| 2138 | |
| 2139 | default: |
| 2140 | return false; |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | static bool ValidDebugType(GLenum type) |
| 2145 | { |
| 2146 | switch (type) |
| 2147 | { |
| 2148 | case GL_DEBUG_TYPE_ERROR: |
| 2149 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 2150 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 2151 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 2152 | case GL_DEBUG_TYPE_PORTABILITY: |
| 2153 | case GL_DEBUG_TYPE_OTHER: |
| 2154 | case GL_DEBUG_TYPE_MARKER: |
| 2155 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 2156 | case GL_DEBUG_TYPE_POP_GROUP: |
| 2157 | return true; |
| 2158 | |
| 2159 | default: |
| 2160 | return false; |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | static bool ValidDebugSeverity(GLenum severity) |
| 2165 | { |
| 2166 | switch (severity) |
| 2167 | { |
| 2168 | case GL_DEBUG_SEVERITY_HIGH: |
| 2169 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 2170 | case GL_DEBUG_SEVERITY_LOW: |
| 2171 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 2172 | return true; |
| 2173 | |
| 2174 | default: |
| 2175 | return false; |
| 2176 | } |
| 2177 | } |
| 2178 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2179 | bool ValidateDebugMessageControlKHR(Context *context, |
| 2180 | GLenum source, |
| 2181 | GLenum type, |
| 2182 | GLenum severity, |
| 2183 | GLsizei count, |
| 2184 | const GLuint *ids, |
| 2185 | GLboolean enabled) |
| 2186 | { |
| 2187 | if (!context->getExtensions().debug) |
| 2188 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2189 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2190 | return false; |
| 2191 | } |
| 2192 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2193 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 2194 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2195 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2196 | return false; |
| 2197 | } |
| 2198 | |
| 2199 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 2200 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2201 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2202 | return false; |
| 2203 | } |
| 2204 | |
| 2205 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 2206 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2207 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2208 | return false; |
| 2209 | } |
| 2210 | |
| 2211 | if (count > 0) |
| 2212 | { |
| 2213 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 2214 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2215 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2216 | return false; |
| 2217 | } |
| 2218 | |
| 2219 | if (severity != GL_DONT_CARE) |
| 2220 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2221 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2222 | return false; |
| 2223 | } |
| 2224 | } |
| 2225 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2226 | return true; |
| 2227 | } |
| 2228 | |
| 2229 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 2230 | GLenum source, |
| 2231 | GLenum type, |
| 2232 | GLuint id, |
| 2233 | GLenum severity, |
| 2234 | GLsizei length, |
| 2235 | const GLchar *buf) |
| 2236 | { |
| 2237 | if (!context->getExtensions().debug) |
| 2238 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2239 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2240 | return false; |
| 2241 | } |
| 2242 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2243 | if (!context->getState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2244 | { |
| 2245 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 2246 | // not generate an error. |
| 2247 | return false; |
| 2248 | } |
| 2249 | |
| 2250 | if (!ValidDebugSeverity(severity)) |
| 2251 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2252 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2253 | return false; |
| 2254 | } |
| 2255 | |
| 2256 | if (!ValidDebugType(type)) |
| 2257 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2258 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2259 | return false; |
| 2260 | } |
| 2261 | |
| 2262 | if (!ValidDebugSource(source, true)) |
| 2263 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2264 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2265 | return false; |
| 2266 | } |
| 2267 | |
| 2268 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 2269 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2270 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2271 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2272 | return false; |
| 2273 | } |
| 2274 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2275 | return true; |
| 2276 | } |
| 2277 | |
| 2278 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 2279 | GLDEBUGPROCKHR callback, |
| 2280 | const void *userParam) |
| 2281 | { |
| 2282 | if (!context->getExtensions().debug) |
| 2283 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2284 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2285 | return false; |
| 2286 | } |
| 2287 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2288 | return true; |
| 2289 | } |
| 2290 | |
| 2291 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 2292 | GLuint count, |
| 2293 | GLsizei bufSize, |
| 2294 | GLenum *sources, |
| 2295 | GLenum *types, |
| 2296 | GLuint *ids, |
| 2297 | GLenum *severities, |
| 2298 | GLsizei *lengths, |
| 2299 | GLchar *messageLog) |
| 2300 | { |
| 2301 | if (!context->getExtensions().debug) |
| 2302 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2303 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2304 | return false; |
| 2305 | } |
| 2306 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2307 | if (bufSize < 0 && messageLog != nullptr) |
| 2308 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2309 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2310 | return false; |
| 2311 | } |
| 2312 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2313 | return true; |
| 2314 | } |
| 2315 | |
| 2316 | bool ValidatePushDebugGroupKHR(Context *context, |
| 2317 | GLenum source, |
| 2318 | GLuint id, |
| 2319 | GLsizei length, |
| 2320 | const GLchar *message) |
| 2321 | { |
| 2322 | if (!context->getExtensions().debug) |
| 2323 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2324 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2325 | return false; |
| 2326 | } |
| 2327 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2328 | if (!ValidDebugSource(source, true)) |
| 2329 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2330 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2331 | return false; |
| 2332 | } |
| 2333 | |
| 2334 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 2335 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2336 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2337 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2338 | return false; |
| 2339 | } |
| 2340 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2341 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2342 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 2343 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2344 | context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2345 | return false; |
| 2346 | } |
| 2347 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2348 | return true; |
| 2349 | } |
| 2350 | |
| 2351 | bool ValidatePopDebugGroupKHR(Context *context) |
| 2352 | { |
| 2353 | if (!context->getExtensions().debug) |
| 2354 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2355 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2356 | return false; |
| 2357 | } |
| 2358 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2359 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2360 | if (currentStackSize <= 1) |
| 2361 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2362 | context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2363 | return false; |
| 2364 | } |
| 2365 | |
| 2366 | return true; |
| 2367 | } |
| 2368 | |
| 2369 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 2370 | { |
| 2371 | switch (identifier) |
| 2372 | { |
| 2373 | case GL_BUFFER: |
| 2374 | if (context->getBuffer(name) == nullptr) |
| 2375 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2376 | context->validationError(GL_INVALID_VALUE, kInvalidBufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2377 | return false; |
| 2378 | } |
| 2379 | return true; |
| 2380 | |
| 2381 | case GL_SHADER: |
| 2382 | if (context->getShader(name) == nullptr) |
| 2383 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2384 | context->validationError(GL_INVALID_VALUE, kInvalidShaderName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2385 | return false; |
| 2386 | } |
| 2387 | return true; |
| 2388 | |
| 2389 | case GL_PROGRAM: |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2390 | if (context->getProgramNoResolveLink(name) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2391 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2392 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2393 | return false; |
| 2394 | } |
| 2395 | return true; |
| 2396 | |
| 2397 | case GL_VERTEX_ARRAY: |
| 2398 | if (context->getVertexArray(name) == nullptr) |
| 2399 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2400 | context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2401 | return false; |
| 2402 | } |
| 2403 | return true; |
| 2404 | |
| 2405 | case GL_QUERY: |
| 2406 | if (context->getQuery(name) == nullptr) |
| 2407 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2408 | context->validationError(GL_INVALID_VALUE, kInvalidQueryName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2409 | return false; |
| 2410 | } |
| 2411 | return true; |
| 2412 | |
| 2413 | case GL_TRANSFORM_FEEDBACK: |
| 2414 | if (context->getTransformFeedback(name) == nullptr) |
| 2415 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2416 | context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2417 | return false; |
| 2418 | } |
| 2419 | return true; |
| 2420 | |
| 2421 | case GL_SAMPLER: |
| 2422 | if (context->getSampler(name) == nullptr) |
| 2423 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2424 | context->validationError(GL_INVALID_VALUE, kInvalidSamplerName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2425 | return false; |
| 2426 | } |
| 2427 | return true; |
| 2428 | |
| 2429 | case GL_TEXTURE: |
| 2430 | if (context->getTexture(name) == nullptr) |
| 2431 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2432 | context->validationError(GL_INVALID_VALUE, kInvalidTextureName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2433 | return false; |
| 2434 | } |
| 2435 | return true; |
| 2436 | |
| 2437 | case GL_RENDERBUFFER: |
| 2438 | if (context->getRenderbuffer(name) == nullptr) |
| 2439 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2440 | context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2441 | return false; |
| 2442 | } |
| 2443 | return true; |
| 2444 | |
| 2445 | case GL_FRAMEBUFFER: |
| 2446 | if (context->getFramebuffer(name) == nullptr) |
| 2447 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2448 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2449 | return false; |
| 2450 | } |
| 2451 | return true; |
| 2452 | |
| 2453 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2454 | context->validationError(GL_INVALID_ENUM, kInvalidIndentifier); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2455 | return false; |
| 2456 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2457 | } |
| 2458 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2459 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2460 | { |
| 2461 | size_t labelLength = 0; |
| 2462 | |
| 2463 | if (length < 0) |
| 2464 | { |
| 2465 | if (label != nullptr) |
| 2466 | { |
| 2467 | labelLength = strlen(label); |
| 2468 | } |
| 2469 | } |
| 2470 | else |
| 2471 | { |
| 2472 | labelLength = static_cast<size_t>(length); |
| 2473 | } |
| 2474 | |
| 2475 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2476 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2477 | context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2478 | return false; |
| 2479 | } |
| 2480 | |
| 2481 | return true; |
| 2482 | } |
| 2483 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2484 | bool ValidateObjectLabelKHR(Context *context, |
| 2485 | GLenum identifier, |
| 2486 | GLuint name, |
| 2487 | GLsizei length, |
| 2488 | const GLchar *label) |
| 2489 | { |
| 2490 | if (!context->getExtensions().debug) |
| 2491 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2492 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2493 | return false; |
| 2494 | } |
| 2495 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2496 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2497 | { |
| 2498 | return false; |
| 2499 | } |
| 2500 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2501 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2502 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2503 | return false; |
| 2504 | } |
| 2505 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2506 | return true; |
| 2507 | } |
| 2508 | |
| 2509 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2510 | GLenum identifier, |
| 2511 | GLuint name, |
| 2512 | GLsizei bufSize, |
| 2513 | GLsizei *length, |
| 2514 | GLchar *label) |
| 2515 | { |
| 2516 | if (!context->getExtensions().debug) |
| 2517 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2518 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2519 | return false; |
| 2520 | } |
| 2521 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2522 | if (bufSize < 0) |
| 2523 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2524 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2525 | return false; |
| 2526 | } |
| 2527 | |
| 2528 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2529 | { |
| 2530 | return false; |
| 2531 | } |
| 2532 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2533 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2537 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 2538 | if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2539 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2540 | context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2541 | return false; |
| 2542 | } |
| 2543 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2544 | return true; |
| 2545 | } |
| 2546 | |
| 2547 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2548 | const void *ptr, |
| 2549 | GLsizei length, |
| 2550 | const GLchar *label) |
| 2551 | { |
| 2552 | if (!context->getExtensions().debug) |
| 2553 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2554 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2555 | return false; |
| 2556 | } |
| 2557 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2558 | if (!ValidateObjectPtrName(context, ptr)) |
| 2559 | { |
| 2560 | return false; |
| 2561 | } |
| 2562 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2563 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2564 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2565 | return false; |
| 2566 | } |
| 2567 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2568 | return true; |
| 2569 | } |
| 2570 | |
| 2571 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2572 | const void *ptr, |
| 2573 | GLsizei bufSize, |
| 2574 | GLsizei *length, |
| 2575 | GLchar *label) |
| 2576 | { |
| 2577 | if (!context->getExtensions().debug) |
| 2578 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2579 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2580 | return false; |
| 2581 | } |
| 2582 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2583 | if (bufSize < 0) |
| 2584 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2585 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2586 | return false; |
| 2587 | } |
| 2588 | |
| 2589 | if (!ValidateObjectPtrName(context, ptr)) |
| 2590 | { |
| 2591 | return false; |
| 2592 | } |
| 2593 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2594 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2598 | { |
| 2599 | if (!context->getExtensions().debug) |
| 2600 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2601 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2602 | return false; |
| 2603 | } |
| 2604 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2605 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2606 | switch (pname) |
| 2607 | { |
| 2608 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2609 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2610 | break; |
| 2611 | |
| 2612 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2613 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2614 | return false; |
| 2615 | } |
| 2616 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2617 | return true; |
| 2618 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2619 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 2620 | bool ValidateGetPointervRobustANGLERobustANGLE(Context *context, |
| 2621 | GLenum pname, |
| 2622 | GLsizei bufSize, |
| 2623 | GLsizei *length, |
| 2624 | void **params) |
| 2625 | { |
| 2626 | UNIMPLEMENTED(); |
| 2627 | return false; |
| 2628 | } |
| 2629 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2630 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2631 | GLint srcX0, |
| 2632 | GLint srcY0, |
| 2633 | GLint srcX1, |
| 2634 | GLint srcY1, |
| 2635 | GLint dstX0, |
| 2636 | GLint dstY0, |
| 2637 | GLint dstX1, |
| 2638 | GLint dstY1, |
| 2639 | GLbitfield mask, |
| 2640 | GLenum filter) |
| 2641 | { |
| 2642 | if (!context->getExtensions().framebufferBlit) |
| 2643 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2644 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2645 | return false; |
| 2646 | } |
| 2647 | |
| 2648 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2649 | { |
| 2650 | // TODO(jmadill): Determine if this should be available on other implementations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2651 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2652 | return false; |
| 2653 | } |
| 2654 | |
| 2655 | if (filter == GL_LINEAR) |
| 2656 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2657 | context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2658 | return false; |
| 2659 | } |
| 2660 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2661 | Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 2662 | Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2663 | |
| 2664 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2665 | { |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 2666 | const FramebufferAttachment *readColorAttachment = |
| 2667 | readFramebuffer->getReadColorAttachment(); |
| 2668 | const FramebufferAttachment *drawColorAttachment = |
| 2669 | drawFramebuffer->getFirstColorAttachment(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2670 | |
| 2671 | if (readColorAttachment && drawColorAttachment) |
| 2672 | { |
| 2673 | if (!(readColorAttachment->type() == GL_TEXTURE && |
Kenneth Russell | cbdf861 | 2019-07-09 20:30:45 -0700 | [diff] [blame^] | 2674 | (readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D || |
| 2675 | readColorAttachment->getTextureImageIndex().getType() == |
| 2676 | TextureType::Rectangle)) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2677 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2678 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2679 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2680 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2681 | kBlitExtensionFromInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2682 | return false; |
| 2683 | } |
| 2684 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2685 | for (size_t drawbufferIdx = 0; |
| 2686 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2687 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2688 | const FramebufferAttachment *attachment = |
| 2689 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2690 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2691 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2692 | if (!(attachment->type() == GL_TEXTURE && |
Kenneth Russell | cbdf861 | 2019-07-09 20:30:45 -0700 | [diff] [blame^] | 2693 | (attachment->getTextureImageIndex().getType() == TextureType::_2D || |
| 2694 | attachment->getTextureImageIndex().getType() == |
| 2695 | TextureType::Rectangle)) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2696 | attachment->type() != GL_RENDERBUFFER && |
| 2697 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2698 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2699 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2700 | kBlitExtensionToInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2701 | return false; |
| 2702 | } |
| 2703 | |
| 2704 | // Return an error if the destination formats do not match |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 2705 | if (!Format::EquivalentForBlit(attachment->getFormat(), |
| 2706 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2707 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2708 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2709 | kBlitExtensionFormatMismatch); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2710 | return false; |
| 2711 | } |
| 2712 | } |
| 2713 | } |
| 2714 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2715 | GLint samples = readFramebuffer->getSamples(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2716 | if (samples != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2717 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2718 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2719 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2720 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2721 | kBlitExtensionMultisampledWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2722 | return false; |
| 2723 | } |
| 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2728 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2729 | for (size_t i = 0; i < 2; i++) |
| 2730 | { |
| 2731 | if (mask & masks[i]) |
| 2732 | { |
| 2733 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2734 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2735 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2736 | drawFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2737 | |
| 2738 | if (readBuffer && drawBuffer) |
| 2739 | { |
| 2740 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2741 | dstX0, dstY0, dstX1, dstY1)) |
| 2742 | { |
| 2743 | // only whole-buffer copies are permitted |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2744 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2745 | kBlitExtensionDepthStencilWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2746 | return false; |
| 2747 | } |
| 2748 | |
| 2749 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2750 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2751 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2752 | kBlitExtensionMultisampledDepthOrStencil); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2753 | return false; |
| 2754 | } |
| 2755 | } |
| 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2760 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2761 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2762 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2763 | bool ValidateClear(Context *context, GLbitfield mask) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2764 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2765 | Framebuffer *fbo = context->getState().getDrawFramebuffer(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2766 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2767 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2768 | if (!ValidateFramebufferComplete(context, fbo)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2769 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2770 | return false; |
| 2771 | } |
| 2772 | |
| 2773 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2774 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2775 | context->validationError(GL_INVALID_VALUE, kInvalidClearMask); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2776 | return false; |
| 2777 | } |
| 2778 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2779 | if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2780 | { |
| 2781 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2782 | GL_SIGNED_NORMALIZED}; |
| 2783 | |
Corentin Wallez | 59c4159 | 2017-07-11 13:19:54 -0400 | [diff] [blame] | 2784 | for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2785 | drawBufferIdx++) |
| 2786 | { |
| 2787 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2788 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2789 | { |
| 2790 | return false; |
| 2791 | } |
| 2792 | } |
| 2793 | } |
| 2794 | |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame] | 2795 | if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery) |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2796 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2797 | const State &state = context->getState(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2798 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2799 | if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed)) |
| 2800 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2801 | context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2802 | return false; |
| 2803 | } |
| 2804 | } |
| 2805 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2806 | return true; |
| 2807 | } |
| 2808 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2809 | bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2810 | { |
| 2811 | if (!context->getExtensions().drawBuffers) |
| 2812 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2813 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2814 | return false; |
| 2815 | } |
| 2816 | |
| 2817 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2818 | } |
| 2819 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2820 | bool ValidateTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2821 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2822 | GLint level, |
| 2823 | GLint internalformat, |
| 2824 | GLsizei width, |
| 2825 | GLsizei height, |
| 2826 | GLint border, |
| 2827 | GLenum format, |
| 2828 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2829 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2830 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2831 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2832 | { |
| 2833 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2834 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2835 | } |
| 2836 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2837 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2838 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2839 | 0, 0, width, height, 1, border, format, type, -1, |
| 2840 | pixels); |
| 2841 | } |
| 2842 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 2843 | bool ValidateTexImage2DRobustANGLE(Context *context, |
| 2844 | TextureTarget target, |
| 2845 | GLint level, |
| 2846 | GLint internalformat, |
| 2847 | GLsizei width, |
| 2848 | GLsizei height, |
| 2849 | GLint border, |
| 2850 | GLenum format, |
| 2851 | GLenum type, |
| 2852 | GLsizei bufSize, |
| 2853 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2854 | { |
| 2855 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2856 | { |
| 2857 | return false; |
| 2858 | } |
| 2859 | |
| 2860 | if (context->getClientMajorVersion() < 3) |
| 2861 | { |
| 2862 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2863 | 0, 0, width, height, border, format, type, bufSize, |
| 2864 | pixels); |
| 2865 | } |
| 2866 | |
| 2867 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2868 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2869 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2870 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | bool ValidateTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2874 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2875 | GLint level, |
| 2876 | GLint xoffset, |
| 2877 | GLint yoffset, |
| 2878 | GLsizei width, |
| 2879 | GLsizei height, |
| 2880 | GLenum format, |
| 2881 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2882 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2883 | { |
| 2884 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2885 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2886 | { |
| 2887 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2888 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2889 | } |
| 2890 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2891 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2892 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2893 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 2894 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2895 | } |
| 2896 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2897 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2898 | TextureTarget target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2899 | GLint level, |
| 2900 | GLint xoffset, |
| 2901 | GLint yoffset, |
| 2902 | GLsizei width, |
| 2903 | GLsizei height, |
| 2904 | GLenum format, |
| 2905 | GLenum type, |
| 2906 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2907 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2908 | { |
| 2909 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2910 | { |
| 2911 | return false; |
| 2912 | } |
| 2913 | |
| 2914 | if (context->getClientMajorVersion() < 3) |
| 2915 | { |
| 2916 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2917 | yoffset, width, height, 0, format, type, bufSize, |
| 2918 | pixels); |
| 2919 | } |
| 2920 | |
| 2921 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2922 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2923 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 2924 | pixels); |
| 2925 | } |
| 2926 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 2927 | bool ValidateTexSubImage3DOES(Context *context, |
| 2928 | TextureTarget target, |
| 2929 | GLint level, |
| 2930 | GLint xoffset, |
| 2931 | GLint yoffset, |
| 2932 | GLint zoffset, |
| 2933 | GLsizei width, |
| 2934 | GLsizei height, |
| 2935 | GLsizei depth, |
| 2936 | GLenum format, |
| 2937 | GLenum type, |
| 2938 | const void *pixels) |
| 2939 | { |
| 2940 | return ValidateTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, height, |
| 2941 | depth, format, type, pixels); |
| 2942 | } |
| 2943 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2944 | bool ValidateCompressedTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2945 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2946 | GLint level, |
| 2947 | GLenum internalformat, |
| 2948 | GLsizei width, |
| 2949 | GLsizei height, |
| 2950 | GLint border, |
| 2951 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2952 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2953 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2954 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2955 | { |
| 2956 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2957 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2958 | { |
| 2959 | return false; |
| 2960 | } |
| 2961 | } |
| 2962 | else |
| 2963 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2964 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2965 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2966 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2967 | data)) |
| 2968 | { |
| 2969 | return false; |
| 2970 | } |
| 2971 | } |
| 2972 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2973 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2974 | |
| 2975 | GLuint blockSize = 0; |
| 2976 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2977 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2978 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2979 | return false; |
| 2980 | } |
| 2981 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2982 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2983 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2984 | context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2985 | return false; |
| 2986 | } |
| 2987 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2988 | if (target == TextureTarget::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2989 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2990 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2991 | return false; |
| 2992 | } |
| 2993 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2994 | return true; |
| 2995 | } |
| 2996 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2997 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2998 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2999 | GLint level, |
| 3000 | GLenum internalformat, |
| 3001 | GLsizei width, |
| 3002 | GLsizei height, |
| 3003 | GLint border, |
| 3004 | GLsizei imageSize, |
| 3005 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3006 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3007 | { |
| 3008 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 3009 | { |
| 3010 | return false; |
| 3011 | } |
| 3012 | |
| 3013 | return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 3014 | border, imageSize, data); |
| 3015 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3016 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 3017 | bool ValidateCompressedTexImage3DOES(Context *context, |
| 3018 | TextureTarget target, |
| 3019 | GLint level, |
| 3020 | GLenum internalformat, |
| 3021 | GLsizei width, |
| 3022 | GLsizei height, |
| 3023 | GLsizei depth, |
| 3024 | GLint border, |
| 3025 | GLsizei imageSize, |
| 3026 | const void *data) |
| 3027 | { |
| 3028 | return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height, |
| 3029 | depth, border, imageSize, data); |
| 3030 | } |
| 3031 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3032 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3033 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3034 | GLint level, |
| 3035 | GLint xoffset, |
| 3036 | GLint yoffset, |
| 3037 | GLsizei width, |
| 3038 | GLsizei height, |
| 3039 | GLenum format, |
| 3040 | GLsizei imageSize, |
| 3041 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3042 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3043 | { |
| 3044 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 3045 | { |
| 3046 | return false; |
| 3047 | } |
| 3048 | |
| 3049 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 3050 | format, imageSize, data); |
| 3051 | } |
| 3052 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3053 | bool ValidateCompressedTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3054 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3055 | GLint level, |
| 3056 | GLint xoffset, |
| 3057 | GLint yoffset, |
| 3058 | GLsizei width, |
| 3059 | GLsizei height, |
| 3060 | GLenum format, |
| 3061 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3062 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3063 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3064 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3065 | { |
| 3066 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 3067 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3068 | { |
| 3069 | return false; |
| 3070 | } |
| 3071 | } |
| 3072 | else |
| 3073 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3074 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3075 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 3076 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3077 | data)) |
| 3078 | { |
| 3079 | return false; |
| 3080 | } |
| 3081 | } |
| 3082 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3083 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3084 | GLuint blockSize = 0; |
| 3085 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3086 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3087 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3088 | return false; |
| 3089 | } |
| 3090 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3091 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3092 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3093 | context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3094 | return false; |
| 3095 | } |
| 3096 | |
| 3097 | return true; |
| 3098 | } |
| 3099 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 3100 | bool ValidateCompressedTexSubImage3DOES(Context *context, |
| 3101 | TextureTarget target, |
| 3102 | GLint level, |
| 3103 | GLint xoffset, |
| 3104 | GLint yoffset, |
| 3105 | GLint zoffset, |
| 3106 | GLsizei width, |
| 3107 | GLsizei height, |
| 3108 | GLsizei depth, |
| 3109 | GLenum format, |
| 3110 | GLsizei imageSize, |
| 3111 | const void *data) |
| 3112 | { |
| 3113 | return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, |
| 3114 | height, depth, format, imageSize, data); |
| 3115 | } |
| 3116 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3117 | bool ValidateGetBufferPointervOES(Context *context, |
| 3118 | BufferBinding target, |
| 3119 | GLenum pname, |
| 3120 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3121 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3122 | if (!context->getExtensions().mapBuffer) |
| 3123 | { |
| 3124 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3125 | return false; |
| 3126 | } |
| 3127 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3128 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3129 | } |
| 3130 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3131 | bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3132 | { |
| 3133 | if (!context->getExtensions().mapBuffer) |
| 3134 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3135 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3136 | return false; |
| 3137 | } |
| 3138 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3139 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3140 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3141 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3142 | return false; |
| 3143 | } |
| 3144 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3145 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3146 | |
| 3147 | if (buffer == nullptr) |
| 3148 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3149 | context->validationError(GL_INVALID_OPERATION, kBufferNotMappable); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3150 | return false; |
| 3151 | } |
| 3152 | |
| 3153 | if (access != GL_WRITE_ONLY_OES) |
| 3154 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3155 | context->validationError(GL_INVALID_ENUM, kInvalidAccessBits); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3156 | return false; |
| 3157 | } |
| 3158 | |
| 3159 | if (buffer->isMapped()) |
| 3160 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3161 | context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3162 | return false; |
| 3163 | } |
| 3164 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3165 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3166 | } |
| 3167 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3168 | bool ValidateUnmapBufferOES(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3169 | { |
| 3170 | if (!context->getExtensions().mapBuffer) |
| 3171 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3172 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3173 | return false; |
| 3174 | } |
| 3175 | |
| 3176 | return ValidateUnmapBufferBase(context, target); |
| 3177 | } |
| 3178 | |
| 3179 | bool ValidateMapBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3180 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3181 | GLintptr offset, |
| 3182 | GLsizeiptr length, |
| 3183 | GLbitfield access) |
| 3184 | { |
| 3185 | if (!context->getExtensions().mapBufferRange) |
| 3186 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3187 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3188 | return false; |
| 3189 | } |
| 3190 | |
| 3191 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 3192 | } |
| 3193 | |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3194 | bool ValidateBufferStorageMemEXT(Context *context, |
| 3195 | TextureType target, |
| 3196 | GLsizeiptr size, |
| 3197 | GLuint memory, |
| 3198 | GLuint64 offset) |
| 3199 | { |
| 3200 | if (!context->getExtensions().memoryObject) |
| 3201 | { |
| 3202 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3203 | return false; |
| 3204 | } |
| 3205 | |
| 3206 | UNIMPLEMENTED(); |
| 3207 | return false; |
| 3208 | } |
| 3209 | |
| 3210 | bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects) |
| 3211 | { |
| 3212 | if (!context->getExtensions().memoryObject) |
| 3213 | { |
| 3214 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3215 | return false; |
| 3216 | } |
| 3217 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3218 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects) |
| 3222 | { |
| 3223 | if (!context->getExtensions().memoryObject) |
| 3224 | { |
| 3225 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3226 | return false; |
| 3227 | } |
| 3228 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3229 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | bool ValidateGetMemoryObjectParameterivEXT(Context *context, |
| 3233 | GLuint memoryObject, |
| 3234 | GLenum pname, |
| 3235 | GLint *params) |
| 3236 | { |
| 3237 | if (!context->getExtensions().memoryObject) |
| 3238 | { |
| 3239 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3240 | return false; |
| 3241 | } |
| 3242 | |
| 3243 | UNIMPLEMENTED(); |
| 3244 | return false; |
| 3245 | } |
| 3246 | |
| 3247 | bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data) |
| 3248 | { |
| 3249 | if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore) |
| 3250 | { |
| 3251 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3252 | return false; |
| 3253 | } |
| 3254 | |
| 3255 | UNIMPLEMENTED(); |
| 3256 | return false; |
| 3257 | } |
| 3258 | |
| 3259 | bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data) |
| 3260 | { |
| 3261 | if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore) |
| 3262 | { |
| 3263 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3264 | return false; |
| 3265 | } |
| 3266 | |
| 3267 | UNIMPLEMENTED(); |
| 3268 | return false; |
| 3269 | } |
| 3270 | |
| 3271 | bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject) |
| 3272 | { |
| 3273 | if (!context->getExtensions().memoryObject) |
| 3274 | { |
| 3275 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3276 | return false; |
| 3277 | } |
| 3278 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3279 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | bool ValidateMemoryObjectParameterivEXT(Context *context, |
| 3283 | GLuint memoryObject, |
| 3284 | GLenum pname, |
| 3285 | const GLint *params) |
| 3286 | { |
| 3287 | if (!context->getExtensions().memoryObject) |
| 3288 | { |
| 3289 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3290 | return false; |
| 3291 | } |
| 3292 | |
| 3293 | UNIMPLEMENTED(); |
| 3294 | return false; |
| 3295 | } |
| 3296 | |
| 3297 | bool ValidateTexStorageMem2DEXT(Context *context, |
| 3298 | TextureType target, |
| 3299 | GLsizei levels, |
| 3300 | GLenum internalFormat, |
| 3301 | GLsizei width, |
| 3302 | GLsizei height, |
| 3303 | GLuint memory, |
| 3304 | GLuint64 offset) |
| 3305 | { |
| 3306 | if (!context->getExtensions().memoryObject) |
| 3307 | { |
| 3308 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3309 | return false; |
| 3310 | } |
| 3311 | |
Michael Spang | f02a767 | 2019-04-09 18:45:23 -0400 | [diff] [blame] | 3312 | if (context->getClientMajorVersion() < 3) |
| 3313 | { |
| 3314 | return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width, |
| 3315 | height); |
| 3316 | } |
| 3317 | |
| 3318 | ASSERT(context->getClientMajorVersion() >= 3); |
| 3319 | return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height, |
| 3320 | 1); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | bool ValidateTexStorageMem3DEXT(Context *context, |
| 3324 | TextureType target, |
| 3325 | GLsizei levels, |
| 3326 | GLenum internalFormat, |
| 3327 | GLsizei width, |
| 3328 | GLsizei height, |
| 3329 | GLsizei depth, |
| 3330 | GLuint memory, |
| 3331 | GLuint64 offset) |
| 3332 | { |
| 3333 | if (!context->getExtensions().memoryObject) |
| 3334 | { |
| 3335 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3336 | return false; |
| 3337 | } |
| 3338 | |
| 3339 | UNIMPLEMENTED(); |
| 3340 | return false; |
| 3341 | } |
| 3342 | |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3343 | bool ValidateImportMemoryFdEXT(Context *context, |
| 3344 | GLuint memory, |
| 3345 | GLuint64 size, |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3346 | HandleType handleType, |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3347 | GLint fd) |
| 3348 | { |
| 3349 | if (!context->getExtensions().memoryObjectFd) |
| 3350 | { |
| 3351 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3352 | return false; |
| 3353 | } |
| 3354 | |
Michael Spang | 3b2c6bf | 2019-04-16 17:19:50 -0400 | [diff] [blame] | 3355 | switch (handleType) |
| 3356 | { |
| 3357 | case HandleType::OpaqueFd: |
| 3358 | break; |
| 3359 | default: |
| 3360 | context->validationError(GL_INVALID_ENUM, kInvalidHandleType); |
| 3361 | return false; |
| 3362 | } |
| 3363 | |
| 3364 | return true; |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3365 | } |
| 3366 | |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3367 | bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores) |
| 3368 | { |
| 3369 | if (!context->getExtensions().semaphore) |
| 3370 | { |
| 3371 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3372 | return false; |
| 3373 | } |
| 3374 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 3375 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores) |
| 3379 | { |
| 3380 | if (!context->getExtensions().semaphore) |
| 3381 | { |
| 3382 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3383 | return false; |
| 3384 | } |
| 3385 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 3386 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | bool ValidateGetSemaphoreParameterui64vEXT(Context *context, |
| 3390 | GLuint semaphore, |
| 3391 | GLenum pname, |
| 3392 | GLuint64 *params) |
| 3393 | { |
| 3394 | if (!context->getExtensions().semaphore) |
| 3395 | { |
| 3396 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3397 | return false; |
| 3398 | } |
| 3399 | |
| 3400 | UNIMPLEMENTED(); |
| 3401 | return false; |
| 3402 | } |
| 3403 | |
| 3404 | bool ValidateIsSemaphoreEXT(Context *context, GLuint semaphore) |
| 3405 | { |
| 3406 | if (!context->getExtensions().semaphore) |
| 3407 | { |
| 3408 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3409 | return false; |
| 3410 | } |
| 3411 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 3412 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | bool ValidateSemaphoreParameterui64vEXT(Context *context, |
| 3416 | GLuint semaphore, |
| 3417 | GLenum pname, |
| 3418 | const GLuint64 *params) |
| 3419 | { |
| 3420 | if (!context->getExtensions().semaphore) |
| 3421 | { |
| 3422 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3423 | return false; |
| 3424 | } |
| 3425 | |
| 3426 | UNIMPLEMENTED(); |
| 3427 | return false; |
| 3428 | } |
| 3429 | |
| 3430 | bool ValidateSignalSemaphoreEXT(Context *context, |
| 3431 | GLuint semaphore, |
| 3432 | GLuint numBufferBarriers, |
| 3433 | const GLuint *buffers, |
| 3434 | GLuint numTextureBarriers, |
| 3435 | const GLuint *textures, |
| 3436 | const GLenum *dstLayouts) |
| 3437 | { |
| 3438 | if (!context->getExtensions().semaphore) |
| 3439 | { |
| 3440 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3441 | return false; |
| 3442 | } |
| 3443 | |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 3444 | for (GLuint i = 0; i < numTextureBarriers; ++i) |
| 3445 | { |
| 3446 | if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i]))) |
| 3447 | { |
| 3448 | context->validationError(GL_INVALID_ENUM, kInvalidImageLayout); |
| 3449 | return false; |
| 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | bool ValidateWaitSemaphoreEXT(Context *context, |
| 3457 | GLuint semaphore, |
| 3458 | GLuint numBufferBarriers, |
| 3459 | const GLuint *buffers, |
| 3460 | GLuint numTextureBarriers, |
| 3461 | const GLuint *textures, |
| 3462 | const GLenum *srcLayouts) |
| 3463 | { |
| 3464 | if (!context->getExtensions().semaphore) |
| 3465 | { |
| 3466 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3467 | return false; |
| 3468 | } |
| 3469 | |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 3470 | for (GLuint i = 0; i < numTextureBarriers; ++i) |
| 3471 | { |
| 3472 | if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i]))) |
| 3473 | { |
| 3474 | context->validationError(GL_INVALID_ENUM, kInvalidImageLayout); |
| 3475 | return false; |
| 3476 | } |
| 3477 | } |
| 3478 | |
| 3479 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3480 | } |
| 3481 | |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3482 | bool ValidateImportSemaphoreFdEXT(Context *context, |
| 3483 | GLuint semaphore, |
| 3484 | HandleType handleType, |
| 3485 | GLint fd) |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3486 | { |
| 3487 | if (!context->getExtensions().semaphoreFd) |
| 3488 | { |
| 3489 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3490 | return false; |
| 3491 | } |
| 3492 | |
Michael Spang | 6bb193c | 2019-05-22 16:32:21 -0400 | [diff] [blame] | 3493 | switch (handleType) |
| 3494 | { |
| 3495 | case HandleType::OpaqueFd: |
| 3496 | break; |
| 3497 | default: |
| 3498 | context->validationError(GL_INVALID_ENUM, kInvalidHandleType); |
| 3499 | return false; |
| 3500 | } |
| 3501 | |
| 3502 | return true; |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3503 | } |
| 3504 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3505 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3506 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3507 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3508 | ASSERT(buffer != nullptr); |
| 3509 | |
| 3510 | // Check if this buffer is currently being used as a transform feedback output buffer |
Shahbaz Youssefi | 8af6c6f | 2019-06-18 15:43:44 -0400 | [diff] [blame] | 3511 | if (context->getState().isTransformFeedbackActive()) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3512 | { |
Shahbaz Youssefi | 8af6c6f | 2019-06-18 15:43:44 -0400 | [diff] [blame] | 3513 | TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback(); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3514 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 3515 | { |
| 3516 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 3517 | if (transformFeedbackBuffer.get() == buffer) |
| 3518 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3519 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3520 | return false; |
| 3521 | } |
| 3522 | } |
| 3523 | } |
| 3524 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3525 | if (context->getExtensions().webglCompatibility && |
| 3526 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3527 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3528 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3529 | return false; |
| 3530 | } |
| 3531 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3532 | return true; |
| 3533 | } |
| 3534 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3535 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3536 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3537 | GLintptr offset, |
| 3538 | GLsizeiptr length) |
| 3539 | { |
| 3540 | if (!context->getExtensions().mapBufferRange) |
| 3541 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3542 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3543 | return false; |
| 3544 | } |
| 3545 | |
| 3546 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 3547 | } |
| 3548 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3549 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 3550 | GLuint program, |
| 3551 | GLint location, |
| 3552 | const GLchar *name) |
| 3553 | { |
| 3554 | if (!context->getExtensions().bindUniformLocation) |
| 3555 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3556 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3557 | return false; |
| 3558 | } |
| 3559 | |
| 3560 | Program *programObject = GetValidProgram(context, program); |
| 3561 | if (!programObject) |
| 3562 | { |
| 3563 | return false; |
| 3564 | } |
| 3565 | |
| 3566 | if (location < 0) |
| 3567 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3568 | context->validationError(GL_INVALID_VALUE, kNegativeLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3569 | return false; |
| 3570 | } |
| 3571 | |
| 3572 | const Caps &caps = context->getCaps(); |
| 3573 | if (static_cast<size_t>(location) >= |
| 3574 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3575 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3576 | context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3577 | return false; |
| 3578 | } |
| 3579 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3580 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3581 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3582 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3583 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3584 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3585 | return false; |
| 3586 | } |
| 3587 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3588 | if (strncmp(name, "gl_", 3) == 0) |
| 3589 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3590 | context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3591 | return false; |
| 3592 | } |
| 3593 | |
| 3594 | return true; |
| 3595 | } |
| 3596 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3597 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3598 | { |
| 3599 | if (!context->getExtensions().framebufferMixedSamples) |
| 3600 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3601 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3602 | return false; |
| 3603 | } |
| 3604 | switch (components) |
| 3605 | { |
| 3606 | case GL_RGB: |
| 3607 | case GL_RGBA: |
| 3608 | case GL_ALPHA: |
| 3609 | case GL_NONE: |
| 3610 | break; |
| 3611 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3612 | context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3613 | return false; |
| 3614 | } |
| 3615 | |
| 3616 | return true; |
| 3617 | } |
| 3618 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3619 | // CHROMIUM_path_rendering |
| 3620 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3621 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3622 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3623 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3624 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3625 | return false; |
| 3626 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3627 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3628 | if (matrix == nullptr) |
| 3629 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3630 | context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3631 | return false; |
| 3632 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3633 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3634 | return true; |
| 3635 | } |
| 3636 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3637 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3638 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3639 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3640 | } |
| 3641 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3642 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3643 | { |
| 3644 | if (!context->getExtensions().pathRendering) |
| 3645 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3646 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3647 | return false; |
| 3648 | } |
| 3649 | |
| 3650 | // range = 0 is undefined in NV_path_rendering. |
| 3651 | // we add stricter semantic check here and require a non zero positive range. |
| 3652 | if (range <= 0) |
| 3653 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3654 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3655 | return false; |
| 3656 | } |
| 3657 | |
| 3658 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3659 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3660 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3661 | return false; |
| 3662 | } |
| 3663 | |
| 3664 | return true; |
| 3665 | } |
| 3666 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3667 | bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3668 | { |
| 3669 | if (!context->getExtensions().pathRendering) |
| 3670 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3671 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3672 | return false; |
| 3673 | } |
| 3674 | |
| 3675 | // range = 0 is undefined in NV_path_rendering. |
| 3676 | // we add stricter semantic check here and require a non zero positive range. |
| 3677 | if (range <= 0) |
| 3678 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3679 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3680 | return false; |
| 3681 | } |
| 3682 | |
| 3683 | angle::CheckedNumeric<std::uint32_t> checkedRange(path); |
| 3684 | checkedRange += range; |
| 3685 | |
| 3686 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3687 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3688 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3689 | return false; |
| 3690 | } |
| 3691 | return true; |
| 3692 | } |
| 3693 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3694 | bool ValidatePathCommandsCHROMIUM(Context *context, |
| 3695 | GLuint path, |
| 3696 | GLsizei numCommands, |
| 3697 | const GLubyte *commands, |
| 3698 | GLsizei numCoords, |
| 3699 | GLenum coordType, |
| 3700 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3701 | { |
| 3702 | if (!context->getExtensions().pathRendering) |
| 3703 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3704 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3705 | return false; |
| 3706 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3707 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3708 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3709 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3710 | return false; |
| 3711 | } |
| 3712 | |
| 3713 | if (numCommands < 0) |
| 3714 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3715 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3716 | return false; |
| 3717 | } |
| 3718 | else if (numCommands > 0) |
| 3719 | { |
| 3720 | if (!commands) |
| 3721 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3722 | context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3723 | return false; |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | if (numCoords < 0) |
| 3728 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3729 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3730 | return false; |
| 3731 | } |
| 3732 | else if (numCoords > 0) |
| 3733 | { |
| 3734 | if (!coords) |
| 3735 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3736 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3737 | return false; |
| 3738 | } |
| 3739 | } |
| 3740 | |
| 3741 | std::uint32_t coordTypeSize = 0; |
| 3742 | switch (coordType) |
| 3743 | { |
| 3744 | case GL_BYTE: |
| 3745 | coordTypeSize = sizeof(GLbyte); |
| 3746 | break; |
| 3747 | |
| 3748 | case GL_UNSIGNED_BYTE: |
| 3749 | coordTypeSize = sizeof(GLubyte); |
| 3750 | break; |
| 3751 | |
| 3752 | case GL_SHORT: |
| 3753 | coordTypeSize = sizeof(GLshort); |
| 3754 | break; |
| 3755 | |
| 3756 | case GL_UNSIGNED_SHORT: |
| 3757 | coordTypeSize = sizeof(GLushort); |
| 3758 | break; |
| 3759 | |
| 3760 | case GL_FLOAT: |
| 3761 | coordTypeSize = sizeof(GLfloat); |
| 3762 | break; |
| 3763 | |
| 3764 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3765 | context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3766 | return false; |
| 3767 | } |
| 3768 | |
| 3769 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3770 | checkedSize += (coordTypeSize * numCoords); |
| 3771 | if (!checkedSize.IsValid()) |
| 3772 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3773 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3774 | return false; |
| 3775 | } |
| 3776 | |
| 3777 | // early return skips command data validation when it doesn't exist. |
| 3778 | if (!commands) |
| 3779 | return true; |
| 3780 | |
| 3781 | GLsizei expectedNumCoords = 0; |
| 3782 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3783 | { |
| 3784 | switch (commands[i]) |
| 3785 | { |
| 3786 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3787 | break; |
| 3788 | case GL_MOVE_TO_CHROMIUM: |
| 3789 | case GL_LINE_TO_CHROMIUM: |
| 3790 | expectedNumCoords += 2; |
| 3791 | break; |
| 3792 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3793 | expectedNumCoords += 4; |
| 3794 | break; |
| 3795 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3796 | expectedNumCoords += 6; |
| 3797 | break; |
| 3798 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3799 | expectedNumCoords += 5; |
| 3800 | break; |
| 3801 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3802 | context->validationError(GL_INVALID_ENUM, kInvalidPathCommand); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3803 | return false; |
| 3804 | } |
| 3805 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3806 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3807 | if (expectedNumCoords != numCoords) |
| 3808 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3809 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3810 | return false; |
| 3811 | } |
| 3812 | |
| 3813 | return true; |
| 3814 | } |
| 3815 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3816 | bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3817 | { |
| 3818 | if (!context->getExtensions().pathRendering) |
| 3819 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3820 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3821 | return false; |
| 3822 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3823 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3824 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3825 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3826 | return false; |
| 3827 | } |
| 3828 | |
| 3829 | switch (pname) |
| 3830 | { |
| 3831 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3832 | if (value < 0.0f) |
| 3833 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3834 | context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3835 | return false; |
| 3836 | } |
| 3837 | break; |
| 3838 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3839 | switch (static_cast<GLenum>(value)) |
| 3840 | { |
| 3841 | case GL_FLAT_CHROMIUM: |
| 3842 | case GL_SQUARE_CHROMIUM: |
| 3843 | case GL_ROUND_CHROMIUM: |
| 3844 | break; |
| 3845 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3846 | context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3847 | return false; |
| 3848 | } |
| 3849 | break; |
| 3850 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3851 | switch (static_cast<GLenum>(value)) |
| 3852 | { |
| 3853 | case GL_MITER_REVERT_CHROMIUM: |
| 3854 | case GL_BEVEL_CHROMIUM: |
| 3855 | case GL_ROUND_CHROMIUM: |
| 3856 | break; |
| 3857 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3858 | context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3859 | return false; |
| 3860 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3861 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3862 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3863 | if (value < 0.0f) |
| 3864 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3865 | context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3866 | return false; |
| 3867 | } |
| 3868 | break; |
| 3869 | |
| 3870 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3871 | // no errors, only clamping. |
| 3872 | break; |
| 3873 | |
| 3874 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3875 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3876 | return false; |
| 3877 | } |
| 3878 | return true; |
| 3879 | } |
| 3880 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3881 | bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value) |
| 3882 | { |
| 3883 | // TODO(jmadill): Use proper clamping cast. |
| 3884 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 3885 | } |
| 3886 | |
| 3887 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3888 | { |
| 3889 | if (!context->getExtensions().pathRendering) |
| 3890 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3891 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3892 | return false; |
| 3893 | } |
| 3894 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3895 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3896 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3897 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3898 | return false; |
| 3899 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3900 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3901 | if (!value) |
| 3902 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3903 | context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3904 | return false; |
| 3905 | } |
| 3906 | |
| 3907 | switch (pname) |
| 3908 | { |
| 3909 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3910 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3911 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3912 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3913 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3914 | break; |
| 3915 | |
| 3916 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3917 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3918 | return false; |
| 3919 | } |
| 3920 | |
| 3921 | return true; |
| 3922 | } |
| 3923 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3924 | bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value) |
| 3925 | { |
| 3926 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 3927 | reinterpret_cast<GLfloat *>(value)); |
| 3928 | } |
| 3929 | |
| 3930 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3931 | { |
| 3932 | if (!context->getExtensions().pathRendering) |
| 3933 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3934 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3935 | return false; |
| 3936 | } |
| 3937 | |
| 3938 | switch (func) |
| 3939 | { |
| 3940 | case GL_NEVER: |
| 3941 | case GL_ALWAYS: |
| 3942 | case GL_LESS: |
| 3943 | case GL_LEQUAL: |
| 3944 | case GL_EQUAL: |
| 3945 | case GL_GEQUAL: |
| 3946 | case GL_GREATER: |
| 3947 | case GL_NOTEQUAL: |
| 3948 | break; |
| 3949 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3950 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3951 | return false; |
| 3952 | } |
| 3953 | |
| 3954 | return true; |
| 3955 | } |
| 3956 | |
| 3957 | // Note that the spec specifies that for the path drawing commands |
| 3958 | // if the path object is not an existing path object the command |
| 3959 | // does nothing and no error is generated. |
| 3960 | // However if the path object exists but has not been specified any |
| 3961 | // commands then an error is generated. |
| 3962 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3963 | bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3964 | { |
| 3965 | if (!context->getExtensions().pathRendering) |
| 3966 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3967 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3968 | return false; |
| 3969 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3970 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3971 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3972 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3973 | return false; |
| 3974 | } |
| 3975 | |
| 3976 | switch (fillMode) |
| 3977 | { |
Chris Dalton | a9dfb3b | 2019-06-26 18:36:10 -0600 | [diff] [blame] | 3978 | case GL_INVERT: |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3979 | case GL_COUNT_UP_CHROMIUM: |
| 3980 | case GL_COUNT_DOWN_CHROMIUM: |
| 3981 | break; |
| 3982 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3983 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3984 | return false; |
| 3985 | } |
| 3986 | |
| 3987 | if (!isPow2(mask + 1)) |
| 3988 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3989 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3990 | return false; |
| 3991 | } |
| 3992 | |
| 3993 | return true; |
| 3994 | } |
| 3995 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3996 | bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3997 | { |
| 3998 | if (!context->getExtensions().pathRendering) |
| 3999 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4000 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4001 | return false; |
| 4002 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4003 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 4004 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4005 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4006 | context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4007 | return false; |
| 4008 | } |
| 4009 | |
| 4010 | return true; |
| 4011 | } |
| 4012 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4013 | bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4014 | { |
| 4015 | if (!context->getExtensions().pathRendering) |
| 4016 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4017 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4018 | return false; |
| 4019 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 4020 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4021 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4022 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4023 | return false; |
| 4024 | } |
| 4025 | |
| 4026 | switch (coverMode) |
| 4027 | { |
| 4028 | case GL_CONVEX_HULL_CHROMIUM: |
| 4029 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4030 | break; |
| 4031 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4032 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4033 | return false; |
| 4034 | } |
| 4035 | return true; |
| 4036 | } |
| 4037 | |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4038 | bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 4039 | { |
| 4040 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 4041 | } |
| 4042 | |
| 4043 | bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 4044 | { |
| 4045 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 4046 | } |
| 4047 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4048 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
| 4049 | GLuint path, |
| 4050 | GLenum fillMode, |
| 4051 | GLuint mask, |
| 4052 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4053 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4054 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 4055 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4056 | } |
| 4057 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4058 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
| 4059 | GLuint path, |
| 4060 | GLint reference, |
| 4061 | GLuint mask, |
| 4062 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4063 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4064 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 4065 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4066 | } |
| 4067 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4068 | bool ValidateIsPathCHROMIUM(Context *context, GLuint path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4069 | { |
| 4070 | if (!context->getExtensions().pathRendering) |
| 4071 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4072 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4073 | return false; |
| 4074 | } |
| 4075 | return true; |
| 4076 | } |
| 4077 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4078 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 4079 | GLsizei numPaths, |
| 4080 | GLenum pathNameType, |
| 4081 | const void *paths, |
| 4082 | GLuint pathBase, |
| 4083 | GLenum coverMode, |
| 4084 | GLenum transformType, |
| 4085 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4086 | { |
| 4087 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4088 | transformType, transformValues)) |
| 4089 | return false; |
| 4090 | |
| 4091 | switch (coverMode) |
| 4092 | { |
| 4093 | case GL_CONVEX_HULL_CHROMIUM: |
| 4094 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4095 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4096 | break; |
| 4097 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4098 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4099 | return false; |
| 4100 | } |
| 4101 | |
| 4102 | return true; |
| 4103 | } |
| 4104 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4105 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 4106 | GLsizei numPaths, |
| 4107 | GLenum pathNameType, |
| 4108 | const void *paths, |
| 4109 | GLuint pathBase, |
| 4110 | GLenum coverMode, |
| 4111 | GLenum transformType, |
| 4112 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4113 | { |
| 4114 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4115 | transformType, transformValues)) |
| 4116 | return false; |
| 4117 | |
| 4118 | switch (coverMode) |
| 4119 | { |
| 4120 | case GL_CONVEX_HULL_CHROMIUM: |
| 4121 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4122 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4123 | break; |
| 4124 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4125 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4126 | return false; |
| 4127 | } |
| 4128 | |
| 4129 | return true; |
| 4130 | } |
| 4131 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4132 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 4133 | GLsizei numPaths, |
| 4134 | GLenum pathNameType, |
| 4135 | const void *paths, |
| 4136 | GLuint pathBase, |
| 4137 | GLenum fillMode, |
| 4138 | GLuint mask, |
| 4139 | GLenum transformType, |
| 4140 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4141 | { |
| 4142 | |
| 4143 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4144 | transformType, transformValues)) |
| 4145 | return false; |
| 4146 | |
| 4147 | switch (fillMode) |
| 4148 | { |
Chris Dalton | a9dfb3b | 2019-06-26 18:36:10 -0600 | [diff] [blame] | 4149 | case GL_INVERT: |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4150 | case GL_COUNT_UP_CHROMIUM: |
| 4151 | case GL_COUNT_DOWN_CHROMIUM: |
| 4152 | break; |
| 4153 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4154 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4155 | return false; |
| 4156 | } |
| 4157 | if (!isPow2(mask + 1)) |
| 4158 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4159 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4160 | return false; |
| 4161 | } |
| 4162 | return true; |
| 4163 | } |
| 4164 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4165 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 4166 | GLsizei numPaths, |
| 4167 | GLenum pathNameType, |
| 4168 | const void *paths, |
| 4169 | GLuint pathBase, |
| 4170 | GLint reference, |
| 4171 | GLuint mask, |
| 4172 | GLenum transformType, |
| 4173 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4174 | { |
| 4175 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4176 | transformType, transformValues)) |
| 4177 | return false; |
| 4178 | |
| 4179 | // no more validation here. |
| 4180 | |
| 4181 | return true; |
| 4182 | } |
| 4183 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4184 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 4185 | GLsizei numPaths, |
| 4186 | GLenum pathNameType, |
| 4187 | const void *paths, |
| 4188 | GLuint pathBase, |
| 4189 | GLenum fillMode, |
| 4190 | GLuint mask, |
| 4191 | GLenum coverMode, |
| 4192 | GLenum transformType, |
| 4193 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4194 | { |
| 4195 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4196 | transformType, transformValues)) |
| 4197 | return false; |
| 4198 | |
| 4199 | switch (coverMode) |
| 4200 | { |
| 4201 | case GL_CONVEX_HULL_CHROMIUM: |
| 4202 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4203 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4204 | break; |
| 4205 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4206 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4207 | return false; |
| 4208 | } |
| 4209 | |
| 4210 | switch (fillMode) |
| 4211 | { |
Chris Dalton | a9dfb3b | 2019-06-26 18:36:10 -0600 | [diff] [blame] | 4212 | case GL_INVERT: |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4213 | case GL_COUNT_UP_CHROMIUM: |
| 4214 | case GL_COUNT_DOWN_CHROMIUM: |
| 4215 | break; |
| 4216 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4217 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4218 | return false; |
| 4219 | } |
| 4220 | if (!isPow2(mask + 1)) |
| 4221 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4222 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4223 | return false; |
| 4224 | } |
| 4225 | |
| 4226 | return true; |
| 4227 | } |
| 4228 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4229 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 4230 | GLsizei numPaths, |
| 4231 | GLenum pathNameType, |
| 4232 | const void *paths, |
| 4233 | GLuint pathBase, |
| 4234 | GLint reference, |
| 4235 | GLuint mask, |
| 4236 | GLenum coverMode, |
| 4237 | GLenum transformType, |
| 4238 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4239 | { |
| 4240 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4241 | transformType, transformValues)) |
| 4242 | return false; |
| 4243 | |
| 4244 | switch (coverMode) |
| 4245 | { |
| 4246 | case GL_CONVEX_HULL_CHROMIUM: |
| 4247 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4248 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4249 | break; |
| 4250 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4251 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4252 | return false; |
| 4253 | } |
| 4254 | |
| 4255 | return true; |
| 4256 | } |
| 4257 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4258 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
| 4259 | GLuint program, |
| 4260 | GLint location, |
| 4261 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4262 | { |
| 4263 | if (!context->getExtensions().pathRendering) |
| 4264 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4265 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4266 | return false; |
| 4267 | } |
| 4268 | |
| 4269 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 4270 | if (location >= MaxLocation) |
| 4271 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4272 | context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4273 | return false; |
| 4274 | } |
| 4275 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4276 | const auto *programObject = context->getProgramNoResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4277 | if (!programObject) |
| 4278 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4279 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4280 | return false; |
| 4281 | } |
| 4282 | |
| 4283 | if (!name) |
| 4284 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4285 | context->validationError(GL_INVALID_VALUE, kMissingName); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4286 | return false; |
| 4287 | } |
| 4288 | |
| 4289 | if (angle::BeginsWith(name, "gl_")) |
| 4290 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4291 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4292 | return false; |
| 4293 | } |
| 4294 | |
| 4295 | return true; |
| 4296 | } |
| 4297 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4298 | bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
| 4299 | GLuint program, |
| 4300 | GLint location, |
| 4301 | GLenum genMode, |
| 4302 | GLint components, |
| 4303 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4304 | { |
| 4305 | if (!context->getExtensions().pathRendering) |
| 4306 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4307 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4308 | return false; |
| 4309 | } |
| 4310 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4311 | const auto *programObject = context->getProgramResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4312 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 4313 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4314 | context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4315 | return false; |
| 4316 | } |
| 4317 | |
| 4318 | if (!programObject->isLinked()) |
| 4319 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4320 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4321 | return false; |
| 4322 | } |
| 4323 | |
| 4324 | switch (genMode) |
| 4325 | { |
| 4326 | case GL_NONE: |
| 4327 | if (components != 0) |
| 4328 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4329 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4330 | return false; |
| 4331 | } |
| 4332 | break; |
| 4333 | |
| 4334 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 4335 | case GL_EYE_LINEAR_CHROMIUM: |
| 4336 | case GL_CONSTANT_CHROMIUM: |
| 4337 | if (components < 1 || components > 4) |
| 4338 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4339 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4340 | return false; |
| 4341 | } |
| 4342 | if (!coeffs) |
| 4343 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4344 | context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4345 | return false; |
| 4346 | } |
| 4347 | break; |
| 4348 | |
| 4349 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4350 | context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4351 | return false; |
| 4352 | } |
| 4353 | |
| 4354 | // If the location is -1 then the command is silently ignored |
| 4355 | // and no further validation is needed. |
| 4356 | if (location == -1) |
| 4357 | return true; |
| 4358 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 4359 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4360 | |
| 4361 | if (!binding.valid) |
| 4362 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4363 | context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4364 | return false; |
| 4365 | } |
| 4366 | |
| 4367 | if (binding.type != GL_NONE) |
| 4368 | { |
| 4369 | GLint expectedComponents = 0; |
| 4370 | switch (binding.type) |
| 4371 | { |
| 4372 | case GL_FLOAT: |
| 4373 | expectedComponents = 1; |
| 4374 | break; |
| 4375 | case GL_FLOAT_VEC2: |
| 4376 | expectedComponents = 2; |
| 4377 | break; |
| 4378 | case GL_FLOAT_VEC3: |
| 4379 | expectedComponents = 3; |
| 4380 | break; |
| 4381 | case GL_FLOAT_VEC4: |
| 4382 | expectedComponents = 4; |
| 4383 | break; |
| 4384 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4385 | context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4386 | return false; |
| 4387 | } |
| 4388 | if (expectedComponents != components && genMode != GL_NONE) |
| 4389 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4390 | context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4391 | return false; |
| 4392 | } |
| 4393 | } |
| 4394 | return true; |
| 4395 | } |
| 4396 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4397 | bool ValidateCopyTextureCHROMIUM(Context *context, |
| 4398 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4399 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4400 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4401 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4402 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4403 | GLint internalFormat, |
| 4404 | GLenum destType, |
| 4405 | GLboolean unpackFlipY, |
| 4406 | GLboolean unpackPremultiplyAlpha, |
| 4407 | GLboolean unpackUnmultiplyAlpha) |
| 4408 | { |
| 4409 | if (!context->getExtensions().copyTexture) |
| 4410 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4411 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4412 | return false; |
| 4413 | } |
| 4414 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4415 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4416 | if (source == nullptr) |
| 4417 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4418 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4419 | return false; |
| 4420 | } |
| 4421 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4422 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4423 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4424 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4425 | return false; |
| 4426 | } |
| 4427 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4428 | TextureType sourceType = source->getType(); |
| 4429 | ASSERT(sourceType != TextureType::CubeMap); |
| 4430 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4431 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4432 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4433 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4434 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4435 | return false; |
| 4436 | } |
| 4437 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4438 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 4439 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 4440 | if (sourceWidth == 0 || sourceHeight == 0) |
| 4441 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4442 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4443 | return false; |
| 4444 | } |
| 4445 | |
| 4446 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 4447 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4448 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4449 | context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4450 | return false; |
| 4451 | } |
| 4452 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4453 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4454 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4455 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4456 | return false; |
| 4457 | } |
| 4458 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4459 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4460 | if (dest == nullptr) |
| 4461 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4462 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4463 | return false; |
| 4464 | } |
| 4465 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4466 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4467 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4468 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4469 | return false; |
| 4470 | } |
| 4471 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4472 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4473 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4474 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4475 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4476 | return false; |
| 4477 | } |
| 4478 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4479 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 4480 | { |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4481 | return false; |
| 4482 | } |
| 4483 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4484 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4485 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4486 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4487 | return false; |
| 4488 | } |
| 4489 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4490 | if (dest->getImmutableFormat()) |
| 4491 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4492 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4493 | return false; |
| 4494 | } |
| 4495 | |
| 4496 | return true; |
| 4497 | } |
| 4498 | |
| 4499 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
| 4500 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4501 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4502 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4503 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4504 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4505 | GLint xoffset, |
| 4506 | GLint yoffset, |
| 4507 | GLint x, |
| 4508 | GLint y, |
| 4509 | GLsizei width, |
| 4510 | GLsizei height, |
| 4511 | GLboolean unpackFlipY, |
| 4512 | GLboolean unpackPremultiplyAlpha, |
| 4513 | GLboolean unpackUnmultiplyAlpha) |
| 4514 | { |
| 4515 | if (!context->getExtensions().copyTexture) |
| 4516 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4517 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4518 | return false; |
| 4519 | } |
| 4520 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4521 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4522 | if (source == nullptr) |
| 4523 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4524 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4525 | return false; |
| 4526 | } |
| 4527 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4528 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4529 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4530 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4531 | return false; |
| 4532 | } |
| 4533 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4534 | TextureType sourceType = source->getType(); |
| 4535 | ASSERT(sourceType != TextureType::CubeMap); |
| 4536 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4537 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4538 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4539 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4540 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4541 | return false; |
| 4542 | } |
| 4543 | |
| 4544 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4545 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4546 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4547 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4548 | return false; |
| 4549 | } |
| 4550 | |
| 4551 | if (x < 0 || y < 0) |
| 4552 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4553 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4554 | return false; |
| 4555 | } |
| 4556 | |
| 4557 | if (width < 0 || height < 0) |
| 4558 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4559 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4560 | return false; |
| 4561 | } |
| 4562 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4563 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4564 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4565 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4566 | context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4567 | return false; |
| 4568 | } |
| 4569 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4570 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4571 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4572 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4573 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4574 | return false; |
| 4575 | } |
| 4576 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4577 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4578 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4579 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4580 | return false; |
| 4581 | } |
| 4582 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4583 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4584 | if (dest == nullptr) |
| 4585 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4586 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4587 | return false; |
| 4588 | } |
| 4589 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4590 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4591 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4592 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4593 | return false; |
| 4594 | } |
| 4595 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4596 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4597 | true)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4598 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4599 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4600 | return false; |
| 4601 | } |
| 4602 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4603 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4604 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4605 | context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4606 | return false; |
| 4607 | } |
| 4608 | |
| 4609 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4610 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4611 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4612 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4613 | return false; |
| 4614 | } |
| 4615 | |
| 4616 | if (xoffset < 0 || yoffset < 0) |
| 4617 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4618 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4619 | return false; |
| 4620 | } |
| 4621 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4622 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4623 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4624 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4625 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4626 | return false; |
| 4627 | } |
| 4628 | |
| 4629 | return true; |
| 4630 | } |
| 4631 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4632 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId) |
| 4633 | { |
| 4634 | if (!context->getExtensions().copyCompressedTexture) |
| 4635 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4636 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4637 | return false; |
| 4638 | } |
| 4639 | |
| 4640 | const gl::Texture *source = context->getTexture(sourceId); |
| 4641 | if (source == nullptr) |
| 4642 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4643 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4644 | return false; |
| 4645 | } |
| 4646 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4647 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4648 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4649 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4650 | return false; |
| 4651 | } |
| 4652 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4653 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4654 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4655 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4656 | context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4657 | return false; |
| 4658 | } |
| 4659 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4660 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4661 | if (!sourceFormat.info->compressed) |
| 4662 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4663 | context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4664 | return false; |
| 4665 | } |
| 4666 | |
| 4667 | const gl::Texture *dest = context->getTexture(destId); |
| 4668 | if (dest == nullptr) |
| 4669 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4670 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4671 | return false; |
| 4672 | } |
| 4673 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4674 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4675 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4676 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4677 | return false; |
| 4678 | } |
| 4679 | |
| 4680 | if (dest->getImmutableFormat()) |
| 4681 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4682 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4683 | return false; |
| 4684 | } |
| 4685 | |
| 4686 | return true; |
| 4687 | } |
| 4688 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4689 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4690 | { |
| 4691 | switch (type) |
| 4692 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4693 | case ShaderType::Vertex: |
| 4694 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4695 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4696 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4697 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4698 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4699 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4700 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4701 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4702 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4703 | break; |
| 4704 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4705 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4706 | if (!context->getExtensions().geometryShader) |
| 4707 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4708 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4709 | return false; |
| 4710 | } |
| 4711 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4712 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4713 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4714 | return false; |
| 4715 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4716 | |
| 4717 | return true; |
| 4718 | } |
| 4719 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4720 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4721 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4722 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4723 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4724 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4725 | { |
| 4726 | if (size < 0) |
| 4727 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4728 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4729 | return false; |
| 4730 | } |
| 4731 | |
| 4732 | switch (usage) |
| 4733 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4734 | case BufferUsage::StreamDraw: |
| 4735 | case BufferUsage::StaticDraw: |
| 4736 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4737 | break; |
| 4738 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4739 | case BufferUsage::StreamRead: |
| 4740 | case BufferUsage::StaticRead: |
| 4741 | case BufferUsage::DynamicRead: |
| 4742 | case BufferUsage::StreamCopy: |
| 4743 | case BufferUsage::StaticCopy: |
| 4744 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4745 | if (context->getClientMajorVersion() < 3) |
| 4746 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4747 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4748 | return false; |
| 4749 | } |
| 4750 | break; |
| 4751 | |
| 4752 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4753 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4754 | return false; |
| 4755 | } |
| 4756 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4757 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4758 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4759 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4760 | return false; |
| 4761 | } |
| 4762 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4763 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4764 | |
| 4765 | if (!buffer) |
| 4766 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4767 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4768 | return false; |
| 4769 | } |
| 4770 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4771 | if (context->getExtensions().webglCompatibility && |
| 4772 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4773 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4774 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4775 | return false; |
| 4776 | } |
| 4777 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4778 | return true; |
| 4779 | } |
| 4780 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4781 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4782 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4783 | GLintptr offset, |
| 4784 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4785 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4786 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4787 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4788 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4789 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4790 | return false; |
| 4791 | } |
| 4792 | |
| 4793 | if (offset < 0) |
| 4794 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4795 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4796 | return false; |
| 4797 | } |
| 4798 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4799 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4800 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4801 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4802 | return false; |
| 4803 | } |
| 4804 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4805 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4806 | |
| 4807 | if (!buffer) |
| 4808 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4809 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4810 | return false; |
| 4811 | } |
| 4812 | |
| 4813 | if (buffer->isMapped()) |
| 4814 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4815 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4816 | return false; |
| 4817 | } |
| 4818 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4819 | if (context->getExtensions().webglCompatibility && |
| 4820 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4821 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4822 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4823 | return false; |
| 4824 | } |
| 4825 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4826 | // Check for possible overflow of size + offset |
| 4827 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4828 | checkedSize += offset; |
| 4829 | if (!checkedSize.IsValid()) |
| 4830 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4831 | context->validationError(GL_INVALID_VALUE, kParamOverflow); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4832 | return false; |
| 4833 | } |
| 4834 | |
| 4835 | if (size + offset > buffer->getSize()) |
| 4836 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4837 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4838 | return false; |
| 4839 | } |
| 4840 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4841 | return true; |
| 4842 | } |
| 4843 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4844 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4845 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4846 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4847 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4848 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4849 | return false; |
| 4850 | } |
| 4851 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4852 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4853 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4854 | context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4855 | return false; |
| 4856 | } |
| 4857 | |
| 4858 | return true; |
| 4859 | } |
| 4860 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4861 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4862 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4863 | if (context->getClientMajorVersion() < 2) |
| 4864 | { |
| 4865 | return ValidateMultitextureUnit(context, texture); |
| 4866 | } |
| 4867 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4868 | if (texture < GL_TEXTURE0 || |
| 4869 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4870 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4871 | context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4872 | return false; |
| 4873 | } |
| 4874 | |
| 4875 | return true; |
| 4876 | } |
| 4877 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4878 | bool ValidateAttachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4879 | { |
| 4880 | Program *programObject = GetValidProgram(context, program); |
| 4881 | if (!programObject) |
| 4882 | { |
| 4883 | return false; |
| 4884 | } |
| 4885 | |
| 4886 | Shader *shaderObject = GetValidShader(context, shader); |
| 4887 | if (!shaderObject) |
| 4888 | { |
| 4889 | return false; |
| 4890 | } |
| 4891 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4892 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4893 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4894 | context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4895 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4896 | } |
| 4897 | |
| 4898 | return true; |
| 4899 | } |
| 4900 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4901 | bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4902 | { |
| 4903 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4904 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4905 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4906 | return false; |
| 4907 | } |
| 4908 | |
| 4909 | if (strncmp(name, "gl_", 3) == 0) |
| 4910 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4911 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4912 | return false; |
| 4913 | } |
| 4914 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4915 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4916 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4917 | const size_t length = strlen(name); |
| 4918 | |
| 4919 | if (!IsValidESSLString(name, length)) |
| 4920 | { |
| 4921 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 4922 | // for shader-related entry points |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4923 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4924 | return false; |
| 4925 | } |
| 4926 | |
| 4927 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 4928 | { |
| 4929 | return false; |
| 4930 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4931 | } |
| 4932 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4933 | return GetValidProgram(context, program) != nullptr; |
| 4934 | } |
| 4935 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4936 | bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4937 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4938 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4939 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4940 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4941 | return false; |
| 4942 | } |
| 4943 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4944 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4945 | !context->isFramebufferGenerated(framebuffer)) |
| 4946 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4947 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4948 | return false; |
| 4949 | } |
| 4950 | |
| 4951 | return true; |
| 4952 | } |
| 4953 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4954 | bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4955 | { |
| 4956 | if (target != GL_RENDERBUFFER) |
| 4957 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4958 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4959 | return false; |
| 4960 | } |
| 4961 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4962 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4963 | !context->isRenderbufferGenerated(renderbuffer)) |
| 4964 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4965 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4966 | return false; |
| 4967 | } |
| 4968 | |
| 4969 | return true; |
| 4970 | } |
| 4971 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4972 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4973 | { |
| 4974 | switch (mode) |
| 4975 | { |
| 4976 | case GL_FUNC_ADD: |
| 4977 | case GL_FUNC_SUBTRACT: |
| 4978 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4979 | return true; |
| 4980 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4981 | case GL_MIN: |
| 4982 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4983 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4984 | |
| 4985 | default: |
| 4986 | return false; |
| 4987 | } |
| 4988 | } |
| 4989 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4990 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4991 | { |
| 4992 | return true; |
| 4993 | } |
| 4994 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4995 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4996 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4997 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4998 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4999 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5000 | return false; |
| 5001 | } |
| 5002 | |
| 5003 | return true; |
| 5004 | } |
| 5005 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5006 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5007 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5008 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5009 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5010 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5011 | return false; |
| 5012 | } |
| 5013 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5014 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5015 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5016 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5017 | return false; |
| 5018 | } |
| 5019 | |
| 5020 | return true; |
| 5021 | } |
| 5022 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5023 | bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5024 | { |
| 5025 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 5026 | } |
| 5027 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5028 | bool ValidateBlendFuncSeparate(Context *context, |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5029 | GLenum srcRGB, |
| 5030 | GLenum dstRGB, |
| 5031 | GLenum srcAlpha, |
| 5032 | GLenum dstAlpha) |
| 5033 | { |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5034 | if (!ValidSrcBlendFunc(context, srcRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5035 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5036 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5037 | return false; |
| 5038 | } |
| 5039 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5040 | if (!ValidDstBlendFunc(context, dstRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5041 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5042 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5043 | return false; |
| 5044 | } |
| 5045 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5046 | if (!ValidSrcBlendFunc(context, srcAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5047 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5048 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5049 | return false; |
| 5050 | } |
| 5051 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5052 | if (!ValidDstBlendFunc(context, dstAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5053 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5054 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5055 | return false; |
| 5056 | } |
| 5057 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 5058 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 5059 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5060 | { |
| 5061 | bool constantColorUsed = |
| 5062 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 5063 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 5064 | |
| 5065 | bool constantAlphaUsed = |
| 5066 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 5067 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 5068 | |
| 5069 | if (constantColorUsed && constantAlphaUsed) |
| 5070 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 5071 | if (context->getExtensions().webglCompatibility) |
| 5072 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5073 | context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor); |
| 5074 | return false; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 5075 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5076 | |
| 5077 | WARN() << kConstantColorAlphaLimitation; |
| 5078 | context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5079 | return false; |
| 5080 | } |
| 5081 | } |
| 5082 | |
| 5083 | return true; |
| 5084 | } |
| 5085 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 5086 | bool ValidateGetString(Context *context, GLenum name) |
| 5087 | { |
| 5088 | switch (name) |
| 5089 | { |
| 5090 | case GL_VENDOR: |
| 5091 | case GL_RENDERER: |
| 5092 | case GL_VERSION: |
| 5093 | case GL_SHADING_LANGUAGE_VERSION: |
| 5094 | case GL_EXTENSIONS: |
| 5095 | break; |
| 5096 | |
| 5097 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 5098 | if (!context->getExtensions().requestExtension) |
| 5099 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5100 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 5101 | return false; |
| 5102 | } |
| 5103 | break; |
| 5104 | |
| 5105 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5106 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 5107 | return false; |
| 5108 | } |
| 5109 | |
| 5110 | return true; |
| 5111 | } |
| 5112 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5113 | bool ValidateLineWidth(Context *context, GLfloat width) |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 5114 | { |
| 5115 | if (width <= 0.0f || isNaN(width)) |
| 5116 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5117 | context->validationError(GL_INVALID_VALUE, kInvalidWidth); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 5118 | return false; |
| 5119 | } |
| 5120 | |
| 5121 | return true; |
| 5122 | } |
| 5123 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5124 | bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 5125 | { |
| 5126 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 5127 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5128 | context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 5129 | return false; |
| 5130 | } |
| 5131 | |
| 5132 | return true; |
| 5133 | } |
| 5134 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5135 | bool ValidateRenderbufferStorage(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5136 | GLenum target, |
| 5137 | GLenum internalformat, |
| 5138 | GLsizei width, |
| 5139 | GLsizei height) |
| 5140 | { |
| 5141 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 5142 | height); |
| 5143 | } |
| 5144 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5145 | bool ValidateRenderbufferStorageMultisampleANGLE(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5146 | GLenum target, |
| 5147 | GLsizei samples, |
| 5148 | GLenum internalformat, |
| 5149 | GLsizei width, |
| 5150 | GLsizei height) |
| 5151 | { |
| 5152 | if (!context->getExtensions().framebufferMultisample) |
| 5153 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5154 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5155 | return false; |
| 5156 | } |
| 5157 | |
| 5158 | // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5159 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5160 | // generated. |
| 5161 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 5162 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5163 | context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5164 | return false; |
| 5165 | } |
| 5166 | |
| 5167 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 5168 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 5169 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 5170 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 5171 | if (context->getClientMajorVersion() >= 3) |
| 5172 | { |
| 5173 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 5174 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 5175 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5176 | context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5177 | return false; |
| 5178 | } |
| 5179 | } |
| 5180 | |
| 5181 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 5182 | width, height); |
| 5183 | } |
| 5184 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5185 | bool ValidateCheckFramebufferStatus(Context *context, GLenum target) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5186 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5187 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5188 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5189 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5190 | return false; |
| 5191 | } |
| 5192 | |
| 5193 | return true; |
| 5194 | } |
| 5195 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5196 | bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5197 | { |
| 5198 | return true; |
| 5199 | } |
| 5200 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5201 | bool ValidateClearDepthf(Context *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5202 | { |
| 5203 | return true; |
| 5204 | } |
| 5205 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5206 | bool ValidateClearStencil(Context *context, GLint s) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5207 | { |
| 5208 | return true; |
| 5209 | } |
| 5210 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5211 | bool ValidateColorMask(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5212 | GLboolean red, |
| 5213 | GLboolean green, |
| 5214 | GLboolean blue, |
| 5215 | GLboolean alpha) |
| 5216 | { |
| 5217 | return true; |
| 5218 | } |
| 5219 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5220 | bool ValidateCompileShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5221 | { |
| 5222 | return true; |
| 5223 | } |
| 5224 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5225 | bool ValidateCreateProgram(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5226 | { |
| 5227 | return true; |
| 5228 | } |
| 5229 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5230 | bool ValidateCullFace(Context *context, CullFaceMode mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5231 | { |
| 5232 | switch (mode) |
| 5233 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 5234 | case CullFaceMode::Front: |
| 5235 | case CullFaceMode::Back: |
| 5236 | case CullFaceMode::FrontAndBack: |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5237 | break; |
| 5238 | |
| 5239 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5240 | context->validationError(GL_INVALID_ENUM, kInvalidCullMode); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5241 | return false; |
| 5242 | } |
| 5243 | |
| 5244 | return true; |
| 5245 | } |
| 5246 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5247 | bool ValidateDeleteProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5248 | { |
| 5249 | if (program == 0) |
| 5250 | { |
| 5251 | return false; |
| 5252 | } |
| 5253 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5254 | if (!context->getProgramResolveLink(program)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5255 | { |
| 5256 | if (context->getShader(program)) |
| 5257 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5258 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5259 | return false; |
| 5260 | } |
| 5261 | else |
| 5262 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5263 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5264 | return false; |
| 5265 | } |
| 5266 | } |
| 5267 | |
| 5268 | return true; |
| 5269 | } |
| 5270 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5271 | bool ValidateDeleteShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5272 | { |
| 5273 | if (shader == 0) |
| 5274 | { |
| 5275 | return false; |
| 5276 | } |
| 5277 | |
| 5278 | if (!context->getShader(shader)) |
| 5279 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5280 | if (context->getProgramResolveLink(shader)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5281 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5282 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5283 | return false; |
| 5284 | } |
| 5285 | else |
| 5286 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5287 | context->validationError(GL_INVALID_VALUE, kExpectedShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5288 | return false; |
| 5289 | } |
| 5290 | } |
| 5291 | |
| 5292 | return true; |
| 5293 | } |
| 5294 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5295 | bool ValidateDepthFunc(Context *context, GLenum func) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5296 | { |
| 5297 | switch (func) |
| 5298 | { |
| 5299 | case GL_NEVER: |
| 5300 | case GL_ALWAYS: |
| 5301 | case GL_LESS: |
| 5302 | case GL_LEQUAL: |
| 5303 | case GL_EQUAL: |
| 5304 | case GL_GREATER: |
| 5305 | case GL_GEQUAL: |
| 5306 | case GL_NOTEQUAL: |
| 5307 | break; |
| 5308 | |
| 5309 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5310 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5311 | return false; |
| 5312 | } |
| 5313 | |
| 5314 | return true; |
| 5315 | } |
| 5316 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5317 | bool ValidateDepthMask(Context *context, GLboolean flag) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5318 | { |
| 5319 | return true; |
| 5320 | } |
| 5321 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5322 | bool ValidateDetachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5323 | { |
| 5324 | Program *programObject = GetValidProgram(context, program); |
| 5325 | if (!programObject) |
| 5326 | { |
| 5327 | return false; |
| 5328 | } |
| 5329 | |
| 5330 | Shader *shaderObject = GetValidShader(context, shader); |
| 5331 | if (!shaderObject) |
| 5332 | { |
| 5333 | return false; |
| 5334 | } |
| 5335 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 5336 | const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5337 | if (attachedShader != shaderObject) |
| 5338 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5339 | context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5340 | return false; |
| 5341 | } |
| 5342 | |
| 5343 | return true; |
| 5344 | } |
| 5345 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5346 | bool ValidateDisableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5347 | { |
| 5348 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5349 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5350 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5351 | return false; |
| 5352 | } |
| 5353 | |
| 5354 | return true; |
| 5355 | } |
| 5356 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5357 | bool ValidateEnableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5358 | { |
| 5359 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5360 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5361 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5362 | return false; |
| 5363 | } |
| 5364 | |
| 5365 | return true; |
| 5366 | } |
| 5367 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5368 | bool ValidateFinish(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5369 | { |
| 5370 | return true; |
| 5371 | } |
| 5372 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5373 | bool ValidateFlush(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5374 | { |
| 5375 | return true; |
| 5376 | } |
| 5377 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5378 | bool ValidateFrontFace(Context *context, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5379 | { |
| 5380 | switch (mode) |
| 5381 | { |
| 5382 | case GL_CW: |
| 5383 | case GL_CCW: |
| 5384 | break; |
| 5385 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5386 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5387 | return false; |
| 5388 | } |
| 5389 | |
| 5390 | return true; |
| 5391 | } |
| 5392 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5393 | bool ValidateGetActiveAttrib(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5394 | GLuint program, |
| 5395 | GLuint index, |
| 5396 | GLsizei bufsize, |
| 5397 | GLsizei *length, |
| 5398 | GLint *size, |
| 5399 | GLenum *type, |
| 5400 | GLchar *name) |
| 5401 | { |
| 5402 | if (bufsize < 0) |
| 5403 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5404 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5405 | return false; |
| 5406 | } |
| 5407 | |
| 5408 | Program *programObject = GetValidProgram(context, program); |
| 5409 | |
| 5410 | if (!programObject) |
| 5411 | { |
| 5412 | return false; |
| 5413 | } |
| 5414 | |
| 5415 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 5416 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5417 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5418 | return false; |
| 5419 | } |
| 5420 | |
| 5421 | return true; |
| 5422 | } |
| 5423 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5424 | bool ValidateGetActiveUniform(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5425 | GLuint program, |
| 5426 | GLuint index, |
| 5427 | GLsizei bufsize, |
| 5428 | GLsizei *length, |
| 5429 | GLint *size, |
| 5430 | GLenum *type, |
| 5431 | GLchar *name) |
| 5432 | { |
| 5433 | if (bufsize < 0) |
| 5434 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5435 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5436 | return false; |
| 5437 | } |
| 5438 | |
| 5439 | Program *programObject = GetValidProgram(context, program); |
| 5440 | |
| 5441 | if (!programObject) |
| 5442 | { |
| 5443 | return false; |
| 5444 | } |
| 5445 | |
| 5446 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 5447 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5448 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5449 | return false; |
| 5450 | } |
| 5451 | |
| 5452 | return true; |
| 5453 | } |
| 5454 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5455 | bool ValidateGetAttachedShaders(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5456 | GLuint program, |
| 5457 | GLsizei maxcount, |
| 5458 | GLsizei *count, |
| 5459 | GLuint *shaders) |
| 5460 | { |
| 5461 | if (maxcount < 0) |
| 5462 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5463 | context->validationError(GL_INVALID_VALUE, kNegativeMaxCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5464 | return false; |
| 5465 | } |
| 5466 | |
| 5467 | Program *programObject = GetValidProgram(context, program); |
| 5468 | |
| 5469 | if (!programObject) |
| 5470 | { |
| 5471 | return false; |
| 5472 | } |
| 5473 | |
| 5474 | return true; |
| 5475 | } |
| 5476 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5477 | bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5478 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5479 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5480 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5481 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5482 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5483 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5484 | return false; |
| 5485 | } |
| 5486 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5487 | Program *programObject = GetValidProgram(context, program); |
| 5488 | |
| 5489 | if (!programObject) |
| 5490 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5491 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5492 | return false; |
| 5493 | } |
| 5494 | |
| 5495 | if (!programObject->isLinked()) |
| 5496 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5497 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5498 | return false; |
| 5499 | } |
| 5500 | |
| 5501 | return true; |
| 5502 | } |
| 5503 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5504 | bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5505 | { |
| 5506 | GLenum nativeType; |
| 5507 | unsigned int numParams = 0; |
| 5508 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5509 | } |
| 5510 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5511 | bool ValidateGetError(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5512 | { |
| 5513 | return true; |
| 5514 | } |
| 5515 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5516 | bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5517 | { |
| 5518 | GLenum nativeType; |
| 5519 | unsigned int numParams = 0; |
| 5520 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5521 | } |
| 5522 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5523 | bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5524 | { |
| 5525 | GLenum nativeType; |
| 5526 | unsigned int numParams = 0; |
| 5527 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5528 | } |
| 5529 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5530 | bool ValidateGetProgramInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5531 | GLuint program, |
| 5532 | GLsizei bufsize, |
| 5533 | GLsizei *length, |
| 5534 | GLchar *infolog) |
| 5535 | { |
| 5536 | if (bufsize < 0) |
| 5537 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5538 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5539 | return false; |
| 5540 | } |
| 5541 | |
| 5542 | Program *programObject = GetValidProgram(context, program); |
| 5543 | if (!programObject) |
| 5544 | { |
| 5545 | return false; |
| 5546 | } |
| 5547 | |
| 5548 | return true; |
| 5549 | } |
| 5550 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5551 | bool ValidateGetShaderInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5552 | GLuint shader, |
| 5553 | GLsizei bufsize, |
| 5554 | GLsizei *length, |
| 5555 | GLchar *infolog) |
| 5556 | { |
| 5557 | if (bufsize < 0) |
| 5558 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5559 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5560 | return false; |
| 5561 | } |
| 5562 | |
| 5563 | Shader *shaderObject = GetValidShader(context, shader); |
| 5564 | if (!shaderObject) |
| 5565 | { |
| 5566 | return false; |
| 5567 | } |
| 5568 | |
| 5569 | return true; |
| 5570 | } |
| 5571 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5572 | bool ValidateGetShaderPrecisionFormat(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5573 | GLenum shadertype, |
| 5574 | GLenum precisiontype, |
| 5575 | GLint *range, |
| 5576 | GLint *precision) |
| 5577 | { |
| 5578 | switch (shadertype) |
| 5579 | { |
| 5580 | case GL_VERTEX_SHADER: |
| 5581 | case GL_FRAGMENT_SHADER: |
| 5582 | break; |
| 5583 | case GL_COMPUTE_SHADER: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5584 | context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5585 | return false; |
| 5586 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5587 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5588 | return false; |
| 5589 | } |
| 5590 | |
| 5591 | switch (precisiontype) |
| 5592 | { |
| 5593 | case GL_LOW_FLOAT: |
| 5594 | case GL_MEDIUM_FLOAT: |
| 5595 | case GL_HIGH_FLOAT: |
| 5596 | case GL_LOW_INT: |
| 5597 | case GL_MEDIUM_INT: |
| 5598 | case GL_HIGH_INT: |
| 5599 | break; |
| 5600 | |
| 5601 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5602 | context->validationError(GL_INVALID_ENUM, kInvalidPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5603 | return false; |
| 5604 | } |
| 5605 | |
| 5606 | return true; |
| 5607 | } |
| 5608 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5609 | bool ValidateGetShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5610 | GLuint shader, |
| 5611 | GLsizei bufsize, |
| 5612 | GLsizei *length, |
| 5613 | GLchar *source) |
| 5614 | { |
| 5615 | if (bufsize < 0) |
| 5616 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5617 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5618 | return false; |
| 5619 | } |
| 5620 | |
| 5621 | Shader *shaderObject = GetValidShader(context, shader); |
| 5622 | if (!shaderObject) |
| 5623 | { |
| 5624 | return false; |
| 5625 | } |
| 5626 | |
| 5627 | return true; |
| 5628 | } |
| 5629 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5630 | bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5631 | { |
| 5632 | if (strstr(name, "gl_") == name) |
| 5633 | { |
| 5634 | return false; |
| 5635 | } |
| 5636 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5637 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5638 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5639 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5640 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5641 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5642 | return false; |
| 5643 | } |
| 5644 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5645 | Program *programObject = GetValidProgram(context, program); |
| 5646 | |
| 5647 | if (!programObject) |
| 5648 | { |
| 5649 | return false; |
| 5650 | } |
| 5651 | |
| 5652 | if (!programObject->isLinked()) |
| 5653 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5654 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5655 | return false; |
| 5656 | } |
| 5657 | |
| 5658 | return true; |
| 5659 | } |
| 5660 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5661 | bool ValidateHint(Context *context, GLenum target, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5662 | { |
| 5663 | switch (mode) |
| 5664 | { |
| 5665 | case GL_FASTEST: |
| 5666 | case GL_NICEST: |
| 5667 | case GL_DONT_CARE: |
| 5668 | break; |
| 5669 | |
| 5670 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5671 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5672 | return false; |
| 5673 | } |
| 5674 | |
| 5675 | switch (target) |
| 5676 | { |
| 5677 | case GL_GENERATE_MIPMAP_HINT: |
| 5678 | break; |
| 5679 | |
Geoff Lang | e7bd218 | 2017-06-16 16:13:13 -0400 | [diff] [blame] | 5680 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: |
| 5681 | if (context->getClientVersion() < ES_3_0 && |
| 5682 | !context->getExtensions().standardDerivatives) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5683 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5684 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5685 | return false; |
| 5686 | } |
| 5687 | break; |
| 5688 | |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5689 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 5690 | case GL_POINT_SMOOTH_HINT: |
| 5691 | case GL_LINE_SMOOTH_HINT: |
| 5692 | case GL_FOG_HINT: |
| 5693 | if (context->getClientMajorVersion() >= 2) |
| 5694 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5695 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5696 | return false; |
| 5697 | } |
| 5698 | break; |
| 5699 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5700 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5701 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5702 | return false; |
| 5703 | } |
| 5704 | |
| 5705 | return true; |
| 5706 | } |
| 5707 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5708 | bool ValidateIsBuffer(Context *context, GLuint buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5709 | { |
| 5710 | return true; |
| 5711 | } |
| 5712 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5713 | bool ValidateIsFramebuffer(Context *context, GLuint framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5714 | { |
| 5715 | return true; |
| 5716 | } |
| 5717 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5718 | bool ValidateIsProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5719 | { |
| 5720 | return true; |
| 5721 | } |
| 5722 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5723 | bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5724 | { |
| 5725 | return true; |
| 5726 | } |
| 5727 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5728 | bool ValidateIsShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5729 | { |
| 5730 | return true; |
| 5731 | } |
| 5732 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5733 | bool ValidateIsTexture(Context *context, GLuint texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5734 | { |
| 5735 | return true; |
| 5736 | } |
| 5737 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5738 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5739 | { |
| 5740 | if (context->getClientMajorVersion() < 3) |
| 5741 | { |
| 5742 | switch (pname) |
| 5743 | { |
| 5744 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5745 | case GL_UNPACK_SKIP_IMAGES: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5746 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5747 | return false; |
| 5748 | |
| 5749 | case GL_UNPACK_ROW_LENGTH: |
| 5750 | case GL_UNPACK_SKIP_ROWS: |
| 5751 | case GL_UNPACK_SKIP_PIXELS: |
| 5752 | if (!context->getExtensions().unpackSubimage) |
| 5753 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5754 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5755 | return false; |
| 5756 | } |
| 5757 | break; |
| 5758 | |
| 5759 | case GL_PACK_ROW_LENGTH: |
| 5760 | case GL_PACK_SKIP_ROWS: |
| 5761 | case GL_PACK_SKIP_PIXELS: |
| 5762 | if (!context->getExtensions().packSubimage) |
| 5763 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5764 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5765 | return false; |
| 5766 | } |
| 5767 | break; |
| 5768 | } |
| 5769 | } |
| 5770 | |
| 5771 | if (param < 0) |
| 5772 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5773 | context->validationError(GL_INVALID_VALUE, kNegativeParam); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5774 | return false; |
| 5775 | } |
| 5776 | |
| 5777 | switch (pname) |
| 5778 | { |
| 5779 | case GL_UNPACK_ALIGNMENT: |
| 5780 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5781 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5782 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5783 | return false; |
| 5784 | } |
| 5785 | break; |
| 5786 | |
| 5787 | case GL_PACK_ALIGNMENT: |
| 5788 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5789 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5790 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5791 | return false; |
| 5792 | } |
| 5793 | break; |
| 5794 | |
| 5795 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5796 | if (!context->getExtensions().packReverseRowOrder) |
| 5797 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5798 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5799 | } |
| 5800 | break; |
| 5801 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5802 | case GL_UNPACK_ROW_LENGTH: |
| 5803 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5804 | case GL_UNPACK_SKIP_IMAGES: |
| 5805 | case GL_UNPACK_SKIP_ROWS: |
| 5806 | case GL_UNPACK_SKIP_PIXELS: |
| 5807 | case GL_PACK_ROW_LENGTH: |
| 5808 | case GL_PACK_SKIP_ROWS: |
| 5809 | case GL_PACK_SKIP_PIXELS: |
| 5810 | break; |
| 5811 | |
| 5812 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5813 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5814 | return false; |
| 5815 | } |
| 5816 | |
| 5817 | return true; |
| 5818 | } |
| 5819 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5820 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5821 | { |
| 5822 | return true; |
| 5823 | } |
| 5824 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5825 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5826 | { |
| 5827 | return true; |
| 5828 | } |
| 5829 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5830 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5831 | { |
| 5832 | return true; |
| 5833 | } |
| 5834 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5835 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5836 | { |
| 5837 | if (width < 0 || height < 0) |
| 5838 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5839 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5840 | return false; |
| 5841 | } |
| 5842 | |
| 5843 | return true; |
| 5844 | } |
| 5845 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5846 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5847 | GLsizei n, |
| 5848 | const GLuint *shaders, |
| 5849 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5850 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5851 | GLsizei length) |
| 5852 | { |
| 5853 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5854 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5855 | shaderBinaryFormats.end()) |
| 5856 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5857 | context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5858 | return false; |
| 5859 | } |
| 5860 | |
| 5861 | return true; |
| 5862 | } |
| 5863 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5864 | bool ValidateShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5865 | GLuint shader, |
| 5866 | GLsizei count, |
| 5867 | const GLchar *const *string, |
| 5868 | const GLint *length) |
| 5869 | { |
| 5870 | if (count < 0) |
| 5871 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5872 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5873 | return false; |
| 5874 | } |
| 5875 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5876 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5877 | // shader-related entry points |
| 5878 | if (context->getExtensions().webglCompatibility) |
| 5879 | { |
| 5880 | for (GLsizei i = 0; i < count; i++) |
| 5881 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5882 | size_t len = |
| 5883 | (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] | 5884 | |
| 5885 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5886 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 5887 | context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5888 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5889 | context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5890 | return false; |
| 5891 | } |
| 5892 | } |
| 5893 | } |
| 5894 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5895 | Shader *shaderObject = GetValidShader(context, shader); |
| 5896 | if (!shaderObject) |
| 5897 | { |
| 5898 | return false; |
| 5899 | } |
| 5900 | |
| 5901 | return true; |
| 5902 | } |
| 5903 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5904 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5905 | { |
| 5906 | if (!IsValidStencilFunc(func)) |
| 5907 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5908 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5909 | return false; |
| 5910 | } |
| 5911 | |
| 5912 | return true; |
| 5913 | } |
| 5914 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5915 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5916 | { |
| 5917 | if (!IsValidStencilFace(face)) |
| 5918 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5919 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5920 | return false; |
| 5921 | } |
| 5922 | |
| 5923 | if (!IsValidStencilFunc(func)) |
| 5924 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5925 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5926 | return false; |
| 5927 | } |
| 5928 | |
| 5929 | return true; |
| 5930 | } |
| 5931 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5932 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5933 | { |
| 5934 | return true; |
| 5935 | } |
| 5936 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5937 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5938 | { |
| 5939 | if (!IsValidStencilFace(face)) |
| 5940 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5941 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5942 | return false; |
| 5943 | } |
| 5944 | |
| 5945 | return true; |
| 5946 | } |
| 5947 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5948 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5949 | { |
| 5950 | if (!IsValidStencilOp(fail)) |
| 5951 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5952 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5953 | return false; |
| 5954 | } |
| 5955 | |
| 5956 | if (!IsValidStencilOp(zfail)) |
| 5957 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5958 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5959 | return false; |
| 5960 | } |
| 5961 | |
| 5962 | if (!IsValidStencilOp(zpass)) |
| 5963 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5964 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5965 | return false; |
| 5966 | } |
| 5967 | |
| 5968 | return true; |
| 5969 | } |
| 5970 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5971 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5972 | GLenum face, |
| 5973 | GLenum fail, |
| 5974 | GLenum zfail, |
| 5975 | GLenum zpass) |
| 5976 | { |
| 5977 | if (!IsValidStencilFace(face)) |
| 5978 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5979 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5980 | return false; |
| 5981 | } |
| 5982 | |
| 5983 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 5984 | } |
| 5985 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5986 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5987 | { |
| 5988 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 5989 | } |
| 5990 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5991 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5992 | { |
| 5993 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 5994 | } |
| 5995 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5996 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5997 | { |
| 5998 | return ValidateUniform1iv(context, location, 1, &x); |
| 5999 | } |
| 6000 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6001 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6002 | { |
| 6003 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 6004 | } |
| 6005 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6006 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6007 | { |
| 6008 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 6009 | } |
| 6010 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6011 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6012 | { |
| 6013 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 6014 | } |
| 6015 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6016 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6017 | { |
| 6018 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 6019 | } |
| 6020 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6021 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6022 | { |
| 6023 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 6024 | } |
| 6025 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6026 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6027 | { |
| 6028 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 6029 | } |
| 6030 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6031 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6032 | { |
| 6033 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 6034 | } |
| 6035 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6036 | 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] | 6037 | { |
| 6038 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 6039 | } |
| 6040 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6041 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6042 | { |
| 6043 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 6044 | } |
| 6045 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6046 | 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] | 6047 | { |
| 6048 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 6049 | } |
| 6050 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6051 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6052 | { |
| 6053 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 6054 | } |
| 6055 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6056 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6057 | GLint location, |
| 6058 | GLsizei count, |
| 6059 | GLboolean transpose, |
| 6060 | const GLfloat *value) |
| 6061 | { |
| 6062 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 6063 | } |
| 6064 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6065 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6066 | GLint location, |
| 6067 | GLsizei count, |
| 6068 | GLboolean transpose, |
| 6069 | const GLfloat *value) |
| 6070 | { |
| 6071 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 6072 | } |
| 6073 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6074 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6075 | GLint location, |
| 6076 | GLsizei count, |
| 6077 | GLboolean transpose, |
| 6078 | const GLfloat *value) |
| 6079 | { |
| 6080 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 6081 | } |
| 6082 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6083 | bool ValidateValidateProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6084 | { |
| 6085 | Program *programObject = GetValidProgram(context, program); |
| 6086 | |
| 6087 | if (!programObject) |
| 6088 | { |
| 6089 | return false; |
| 6090 | } |
| 6091 | |
| 6092 | return true; |
| 6093 | } |
| 6094 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6095 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6096 | { |
| 6097 | return ValidateVertexAttribIndex(context, index); |
| 6098 | } |
| 6099 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6100 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6101 | { |
| 6102 | return ValidateVertexAttribIndex(context, index); |
| 6103 | } |
| 6104 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6105 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6106 | { |
| 6107 | return ValidateVertexAttribIndex(context, index); |
| 6108 | } |
| 6109 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6110 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6111 | { |
| 6112 | return ValidateVertexAttribIndex(context, index); |
| 6113 | } |
| 6114 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6115 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6116 | { |
| 6117 | return ValidateVertexAttribIndex(context, index); |
| 6118 | } |
| 6119 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6120 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6121 | { |
| 6122 | return ValidateVertexAttribIndex(context, index); |
| 6123 | } |
| 6124 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6125 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6126 | GLuint index, |
| 6127 | GLfloat x, |
| 6128 | GLfloat y, |
| 6129 | GLfloat z, |
| 6130 | GLfloat w) |
| 6131 | { |
| 6132 | return ValidateVertexAttribIndex(context, index); |
| 6133 | } |
| 6134 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6135 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6136 | { |
| 6137 | return ValidateVertexAttribIndex(context, index); |
| 6138 | } |
| 6139 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6140 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6141 | { |
| 6142 | if (width < 0 || height < 0) |
| 6143 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6144 | context->validationError(GL_INVALID_VALUE, kViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6145 | return false; |
| 6146 | } |
| 6147 | |
| 6148 | return true; |
| 6149 | } |
| 6150 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 6151 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6152 | GLenum target, |
| 6153 | GLenum attachment, |
| 6154 | GLenum pname, |
| 6155 | GLint *params) |
| 6156 | { |
| 6157 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 6158 | nullptr); |
| 6159 | } |
| 6160 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6161 | bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6162 | { |
| 6163 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 6164 | } |
| 6165 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6166 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6167 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6168 | GLint level, |
| 6169 | GLenum internalformat, |
| 6170 | GLint x, |
| 6171 | GLint y, |
| 6172 | GLsizei width, |
| 6173 | GLsizei height, |
| 6174 | GLint border) |
| 6175 | { |
| 6176 | if (context->getClientMajorVersion() < 3) |
| 6177 | { |
| 6178 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 6179 | 0, x, y, width, height, border); |
| 6180 | } |
| 6181 | |
| 6182 | ASSERT(context->getClientMajorVersion() == 3); |
| 6183 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 6184 | 0, x, y, width, height, border); |
| 6185 | } |
| 6186 | |
| 6187 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6188 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6189 | GLint level, |
| 6190 | GLint xoffset, |
| 6191 | GLint yoffset, |
| 6192 | GLint x, |
| 6193 | GLint y, |
| 6194 | GLsizei width, |
| 6195 | GLsizei height) |
| 6196 | { |
| 6197 | if (context->getClientMajorVersion() < 3) |
| 6198 | { |
| 6199 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 6200 | yoffset, x, y, width, height, 0); |
| 6201 | } |
| 6202 | |
| 6203 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 6204 | yoffset, 0, x, y, width, height, 0); |
| 6205 | } |
| 6206 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6207 | bool ValidateCopyTexSubImage3DOES(Context *context, |
| 6208 | TextureTarget target, |
| 6209 | GLint level, |
| 6210 | GLint xoffset, |
| 6211 | GLint yoffset, |
| 6212 | GLint zoffset, |
| 6213 | GLint x, |
| 6214 | GLint y, |
| 6215 | GLsizei width, |
| 6216 | GLsizei height) |
| 6217 | { |
| 6218 | return ValidateCopyTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, x, y, width, |
| 6219 | height); |
| 6220 | } |
| 6221 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6222 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 6223 | { |
| 6224 | return ValidateGenOrDelete(context, n); |
| 6225 | } |
| 6226 | |
| 6227 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 6228 | { |
| 6229 | return ValidateGenOrDelete(context, n); |
| 6230 | } |
| 6231 | |
| 6232 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 6233 | { |
| 6234 | return ValidateGenOrDelete(context, n); |
| 6235 | } |
| 6236 | |
| 6237 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 6238 | { |
| 6239 | return ValidateGenOrDelete(context, n); |
| 6240 | } |
| 6241 | |
| 6242 | bool ValidateDisable(Context *context, GLenum cap) |
| 6243 | { |
| 6244 | if (!ValidCap(context, cap, false)) |
| 6245 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6246 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6247 | return false; |
| 6248 | } |
| 6249 | |
| 6250 | return true; |
| 6251 | } |
| 6252 | |
| 6253 | bool ValidateEnable(Context *context, GLenum cap) |
| 6254 | { |
| 6255 | if (!ValidCap(context, cap, false)) |
| 6256 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6257 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6258 | return false; |
| 6259 | } |
| 6260 | |
| 6261 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 6262 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 6263 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6264 | context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6265 | |
| 6266 | // We also output an error message to the debugger window if tracing is active, so that |
| 6267 | // developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6268 | ERR() << kNoSampleAlphaToCoveragesLimitation; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6269 | return false; |
| 6270 | } |
| 6271 | |
| 6272 | return true; |
| 6273 | } |
| 6274 | |
| 6275 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 6276 | GLenum target, |
| 6277 | GLenum attachment, |
| 6278 | GLenum renderbuffertarget, |
| 6279 | GLuint renderbuffer) |
| 6280 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 6281 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6282 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6283 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6284 | return false; |
| 6285 | } |
| 6286 | |
| 6287 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0) |
| 6288 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6289 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6290 | return false; |
| 6291 | } |
| 6292 | |
| 6293 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 6294 | renderbuffertarget, renderbuffer); |
| 6295 | } |
| 6296 | |
| 6297 | bool ValidateFramebufferTexture2D(Context *context, |
| 6298 | GLenum target, |
| 6299 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6300 | TextureTarget textarget, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6301 | GLuint texture, |
| 6302 | GLint level) |
| 6303 | { |
| 6304 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 6305 | // extension |
| 6306 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 6307 | level != 0) |
| 6308 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6309 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6310 | return false; |
| 6311 | } |
| 6312 | |
| 6313 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 6314 | { |
| 6315 | return false; |
| 6316 | } |
| 6317 | |
| 6318 | if (texture != 0) |
| 6319 | { |
| 6320 | gl::Texture *tex = context->getTexture(texture); |
| 6321 | ASSERT(tex); |
| 6322 | |
| 6323 | const gl::Caps &caps = context->getCaps(); |
| 6324 | |
| 6325 | switch (textarget) |
| 6326 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6327 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6328 | { |
| 6329 | if (level > gl::log2(caps.max2DTextureSize)) |
| 6330 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6331 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6332 | return false; |
| 6333 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6334 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6335 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6336 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6337 | return false; |
| 6338 | } |
| 6339 | } |
| 6340 | break; |
| 6341 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6342 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6343 | { |
| 6344 | if (level != 0) |
| 6345 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6346 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6347 | return false; |
| 6348 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6349 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6350 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6351 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6352 | return false; |
| 6353 | } |
| 6354 | } |
| 6355 | break; |
| 6356 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6357 | case TextureTarget::CubeMapNegativeX: |
| 6358 | case TextureTarget::CubeMapNegativeY: |
| 6359 | case TextureTarget::CubeMapNegativeZ: |
| 6360 | case TextureTarget::CubeMapPositiveX: |
| 6361 | case TextureTarget::CubeMapPositiveY: |
| 6362 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6363 | { |
| 6364 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 6365 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6366 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6367 | return false; |
| 6368 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6369 | if (tex->getType() != TextureType::CubeMap) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6370 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6371 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6372 | return false; |
| 6373 | } |
| 6374 | } |
| 6375 | break; |
| 6376 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6377 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6378 | { |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6379 | if (context->getClientVersion() < ES_3_1 && |
| 6380 | !context->getExtensions().textureMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6381 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6382 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6383 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6384 | return false; |
| 6385 | } |
| 6386 | |
| 6387 | if (level != 0) |
| 6388 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6389 | context->validationError(GL_INVALID_VALUE, kLevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6390 | return false; |
| 6391 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6392 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6393 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6394 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6395 | return false; |
| 6396 | } |
| 6397 | } |
| 6398 | break; |
| 6399 | |
| 6400 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6401 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6402 | return false; |
| 6403 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | return true; |
| 6407 | } |
| 6408 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6409 | bool ValidateFramebufferTexture3DOES(Context *context, |
| 6410 | GLenum target, |
| 6411 | GLenum attachment, |
| 6412 | TextureTarget textargetPacked, |
| 6413 | GLuint texture, |
| 6414 | GLint level, |
| 6415 | GLint zoffset) |
| 6416 | { |
| 6417 | UNIMPLEMENTED(); |
| 6418 | return false; |
| 6419 | } |
| 6420 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6421 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 6422 | { |
| 6423 | return ValidateGenOrDelete(context, n); |
| 6424 | } |
| 6425 | |
| 6426 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 6427 | { |
| 6428 | return ValidateGenOrDelete(context, n); |
| 6429 | } |
| 6430 | |
| 6431 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 6432 | { |
| 6433 | return ValidateGenOrDelete(context, n); |
| 6434 | } |
| 6435 | |
| 6436 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 6437 | { |
| 6438 | return ValidateGenOrDelete(context, n); |
| 6439 | } |
| 6440 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6441 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6442 | { |
| 6443 | if (!ValidTextureTarget(context, target)) |
| 6444 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6445 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6446 | return false; |
| 6447 | } |
| 6448 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 6449 | Texture *texture = context->getTextureByType(target); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6450 | |
| 6451 | if (texture == nullptr) |
| 6452 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6453 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6454 | return false; |
| 6455 | } |
| 6456 | |
| 6457 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 6458 | |
| 6459 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 6460 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 6461 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 6462 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6463 | context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6464 | return false; |
| 6465 | } |
| 6466 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6467 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 6468 | ? TextureTarget::CubeMapPositiveX |
| 6469 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6470 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 6471 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 6472 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6474 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6475 | return false; |
| 6476 | } |
| 6477 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6478 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 6479 | bool formatUnsized = !format.sized; |
| 6480 | bool formatColorRenderableAndFilterable = |
| 6481 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6482 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6483 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6484 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6485 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6486 | return false; |
| 6487 | } |
| 6488 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6489 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 6490 | // generation |
| 6491 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 6492 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6493 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6494 | return false; |
| 6495 | } |
| 6496 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 6497 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 6498 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 6499 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6500 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6501 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6502 | return false; |
| 6503 | } |
| 6504 | |
| 6505 | // Non-power of 2 ES2 check |
| 6506 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 6507 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 6508 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 6509 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6510 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 6511 | target == TextureType::CubeMap); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6512 | context->validationError(GL_INVALID_OPERATION, kTextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6513 | return false; |
| 6514 | } |
| 6515 | |
| 6516 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6517 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6518 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6519 | context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6520 | return false; |
| 6521 | } |
| 6522 | |
James Darpinian | 83b2f0e | 2018-11-27 15:56:01 -0800 | [diff] [blame] | 6523 | if (context->getExtensions().webglCompatibility && |
| 6524 | (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 || |
| 6525 | texture->getHeight(baseTarget, effectiveBaseLevel) == 0)) |
| 6526 | { |
| 6527 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize); |
| 6528 | return false; |
| 6529 | } |
| 6530 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6531 | return true; |
| 6532 | } |
| 6533 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6534 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 6535 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6536 | GLenum pname, |
| 6537 | GLint *params) |
| 6538 | { |
| 6539 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 6540 | } |
| 6541 | |
| 6542 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6543 | GLenum target, |
| 6544 | GLenum pname, |
| 6545 | GLint *params) |
| 6546 | { |
| 6547 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6548 | } |
| 6549 | |
| 6550 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 6551 | { |
| 6552 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6553 | } |
| 6554 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6555 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6556 | { |
| 6557 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6558 | } |
| 6559 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6560 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6561 | { |
| 6562 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6563 | } |
| 6564 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6565 | bool ValidateGetTexParameterIivOES(Context *context, |
| 6566 | TextureType target, |
| 6567 | GLenum pname, |
| 6568 | GLint *params) |
| 6569 | { |
| 6570 | if (context->getClientMajorVersion() < 3) |
| 6571 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6572 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6573 | return false; |
| 6574 | } |
| 6575 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6576 | } |
| 6577 | |
| 6578 | bool ValidateGetTexParameterIuivOES(Context *context, |
| 6579 | TextureType target, |
| 6580 | GLenum pname, |
| 6581 | GLuint *params) |
| 6582 | { |
| 6583 | if (context->getClientMajorVersion() < 3) |
| 6584 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6585 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6586 | return false; |
| 6587 | } |
| 6588 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6589 | } |
| 6590 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6591 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
| 6592 | { |
| 6593 | return ValidateGetUniformBase(context, program, location); |
| 6594 | } |
| 6595 | |
| 6596 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
| 6597 | { |
| 6598 | return ValidateGetUniformBase(context, program, location); |
| 6599 | } |
| 6600 | |
| 6601 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6602 | { |
| 6603 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6604 | } |
| 6605 | |
| 6606 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6607 | { |
| 6608 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6609 | } |
| 6610 | |
| 6611 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6612 | { |
| 6613 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6614 | } |
| 6615 | |
| 6616 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6617 | { |
| 6618 | if (!ValidCap(context, cap, true)) |
| 6619 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6620 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6621 | return false; |
| 6622 | } |
| 6623 | |
| 6624 | return true; |
| 6625 | } |
| 6626 | |
| 6627 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 6628 | { |
| 6629 | if (context->hasActiveTransformFeedback(program)) |
| 6630 | { |
| 6631 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6632 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6633 | return false; |
| 6634 | } |
| 6635 | |
| 6636 | Program *programObject = GetValidProgram(context, program); |
| 6637 | if (!programObject) |
| 6638 | { |
| 6639 | return false; |
| 6640 | } |
| 6641 | |
| 6642 | return true; |
| 6643 | } |
| 6644 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6645 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6646 | GLint x, |
| 6647 | GLint y, |
| 6648 | GLsizei width, |
| 6649 | GLsizei height, |
| 6650 | GLenum format, |
| 6651 | GLenum type, |
| 6652 | void *pixels) |
| 6653 | { |
| 6654 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6655 | nullptr, pixels); |
| 6656 | } |
| 6657 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6658 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6659 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6660 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6661 | } |
| 6662 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6663 | bool ValidateTexParameterfv(Context *context, |
| 6664 | TextureType target, |
| 6665 | GLenum pname, |
| 6666 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6667 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6668 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6669 | } |
| 6670 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6671 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6672 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6673 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6674 | } |
| 6675 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6676 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6677 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6678 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6679 | } |
| 6680 | |
| 6681 | bool ValidateTexParameterIivOES(Context *context, |
| 6682 | TextureType target, |
| 6683 | GLenum pname, |
| 6684 | const GLint *params) |
| 6685 | { |
| 6686 | if (context->getClientMajorVersion() < 3) |
| 6687 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6688 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6689 | return false; |
| 6690 | } |
| 6691 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6692 | } |
| 6693 | |
| 6694 | bool ValidateTexParameterIuivOES(Context *context, |
| 6695 | TextureType target, |
| 6696 | GLenum pname, |
| 6697 | const GLuint *params) |
| 6698 | { |
| 6699 | if (context->getClientMajorVersion() < 3) |
| 6700 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6701 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6702 | return false; |
| 6703 | } |
| 6704 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6705 | } |
| 6706 | |
| 6707 | bool ValidateUseProgram(Context *context, GLuint program) |
| 6708 | { |
| 6709 | if (program != 0) |
| 6710 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 6711 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6712 | if (!programObject) |
| 6713 | { |
| 6714 | // ES 3.1.0 section 7.3 page 72 |
| 6715 | if (context->getShader(program)) |
| 6716 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6717 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6718 | return false; |
| 6719 | } |
| 6720 | else |
| 6721 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6722 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6723 | return false; |
| 6724 | } |
| 6725 | } |
| 6726 | if (!programObject->isLinked()) |
| 6727 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6728 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6729 | return false; |
| 6730 | } |
| 6731 | } |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 6732 | if (context->getState().isTransformFeedbackActiveUnpaused()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6733 | { |
| 6734 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6735 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6736 | return false; |
| 6737 | } |
| 6738 | |
| 6739 | return true; |
| 6740 | } |
| 6741 | |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6742 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences) |
| 6743 | { |
| 6744 | if (!context->getExtensions().fence) |
| 6745 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6746 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6747 | return false; |
| 6748 | } |
| 6749 | |
| 6750 | if (n < 0) |
| 6751 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6752 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6753 | return false; |
| 6754 | } |
| 6755 | |
| 6756 | return true; |
| 6757 | } |
| 6758 | |
| 6759 | bool ValidateFinishFenceNV(Context *context, GLuint fence) |
| 6760 | { |
| 6761 | if (!context->getExtensions().fence) |
| 6762 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6763 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6764 | return false; |
| 6765 | } |
| 6766 | |
| 6767 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6768 | |
| 6769 | if (fenceObject == nullptr) |
| 6770 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6771 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6772 | return false; |
| 6773 | } |
| 6774 | |
| 6775 | if (!fenceObject->isSet()) |
| 6776 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6777 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6778 | return false; |
| 6779 | } |
| 6780 | |
| 6781 | return true; |
| 6782 | } |
| 6783 | |
| 6784 | bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences) |
| 6785 | { |
| 6786 | if (!context->getExtensions().fence) |
| 6787 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6788 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6789 | return false; |
| 6790 | } |
| 6791 | |
| 6792 | if (n < 0) |
| 6793 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6794 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6795 | return false; |
| 6796 | } |
| 6797 | |
| 6798 | return true; |
| 6799 | } |
| 6800 | |
| 6801 | bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params) |
| 6802 | { |
| 6803 | if (!context->getExtensions().fence) |
| 6804 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6805 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6806 | return false; |
| 6807 | } |
| 6808 | |
| 6809 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6810 | |
| 6811 | if (fenceObject == nullptr) |
| 6812 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6813 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6814 | return false; |
| 6815 | } |
| 6816 | |
| 6817 | if (!fenceObject->isSet()) |
| 6818 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6819 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6820 | return false; |
| 6821 | } |
| 6822 | |
| 6823 | switch (pname) |
| 6824 | { |
| 6825 | case GL_FENCE_STATUS_NV: |
| 6826 | case GL_FENCE_CONDITION_NV: |
| 6827 | break; |
| 6828 | |
| 6829 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6830 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6831 | return false; |
| 6832 | } |
| 6833 | |
| 6834 | return true; |
| 6835 | } |
| 6836 | |
| 6837 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 6838 | { |
| 6839 | if (!context->getExtensions().robustness) |
| 6840 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6841 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6842 | return false; |
| 6843 | } |
| 6844 | |
| 6845 | return true; |
| 6846 | } |
| 6847 | |
| 6848 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
| 6849 | GLuint shader, |
| 6850 | GLsizei bufsize, |
| 6851 | GLsizei *length, |
| 6852 | GLchar *source) |
| 6853 | { |
| 6854 | if (!context->getExtensions().translatedShaderSource) |
| 6855 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6856 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6857 | return false; |
| 6858 | } |
| 6859 | |
| 6860 | if (bufsize < 0) |
| 6861 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6862 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6863 | return false; |
| 6864 | } |
| 6865 | |
| 6866 | Shader *shaderObject = context->getShader(shader); |
| 6867 | |
| 6868 | if (!shaderObject) |
| 6869 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6870 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6871 | return false; |
| 6872 | } |
| 6873 | |
| 6874 | return true; |
| 6875 | } |
| 6876 | |
| 6877 | bool ValidateIsFenceNV(Context *context, GLuint fence) |
| 6878 | { |
| 6879 | if (!context->getExtensions().fence) |
| 6880 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6881 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6882 | return false; |
| 6883 | } |
| 6884 | |
| 6885 | return true; |
| 6886 | } |
| 6887 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6888 | bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition) |
| 6889 | { |
| 6890 | if (!context->getExtensions().fence) |
| 6891 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6892 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6893 | return false; |
| 6894 | } |
| 6895 | |
| 6896 | if (condition != GL_ALL_COMPLETED_NV) |
| 6897 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6898 | context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6899 | return false; |
| 6900 | } |
| 6901 | |
| 6902 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6903 | |
| 6904 | if (fenceObject == nullptr) |
| 6905 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6906 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6907 | return false; |
| 6908 | } |
| 6909 | |
| 6910 | return true; |
| 6911 | } |
| 6912 | |
| 6913 | bool ValidateTestFenceNV(Context *context, GLuint fence) |
| 6914 | { |
| 6915 | if (!context->getExtensions().fence) |
| 6916 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6917 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6918 | return false; |
| 6919 | } |
| 6920 | |
| 6921 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6922 | |
| 6923 | if (fenceObject == nullptr) |
| 6924 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6925 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6926 | return false; |
| 6927 | } |
| 6928 | |
| 6929 | if (fenceObject->isSet() != GL_TRUE) |
| 6930 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6931 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6932 | return false; |
| 6933 | } |
| 6934 | |
| 6935 | return true; |
| 6936 | } |
| 6937 | |
| 6938 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6939 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6940 | GLsizei levels, |
| 6941 | GLenum internalformat, |
| 6942 | GLsizei width, |
| 6943 | GLsizei height) |
| 6944 | { |
| 6945 | if (!context->getExtensions().textureStorage) |
| 6946 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6947 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6948 | return false; |
| 6949 | } |
| 6950 | |
| 6951 | if (context->getClientMajorVersion() < 3) |
| 6952 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6953 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6954 | height); |
| 6955 | } |
| 6956 | |
| 6957 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6958 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6959 | 1); |
| 6960 | } |
| 6961 | |
| 6962 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 6963 | { |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 6964 | if (!context->getExtensions().instancedArraysANGLE) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6965 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6966 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6967 | return false; |
| 6968 | } |
| 6969 | |
| 6970 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6971 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6972 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6973 | return false; |
| 6974 | } |
| 6975 | |
| 6976 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 6977 | { |
| 6978 | if (index == 0 && divisor != 0) |
| 6979 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6980 | context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6981 | |
| 6982 | // We also output an error message to the debugger window if tracing is active, so |
| 6983 | // that developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6984 | ERR() << kAttributeZeroRequiresDivisorLimitation; |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6985 | return false; |
| 6986 | } |
| 6987 | } |
| 6988 | |
| 6989 | return true; |
| 6990 | } |
| 6991 | |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 6992 | bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor) |
| 6993 | { |
| 6994 | if (!context->getExtensions().instancedArraysEXT) |
| 6995 | { |
| 6996 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 6997 | return false; |
| 6998 | } |
| 6999 | |
| 7000 | if (index >= MAX_VERTEX_ATTRIBS) |
| 7001 | { |
| 7002 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
| 7003 | return false; |
| 7004 | } |
| 7005 | |
| 7006 | return true; |
| 7007 | } |
| 7008 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7009 | bool ValidateTexImage3DOES(Context *context, |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 7010 | TextureTarget target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7011 | GLint level, |
| 7012 | GLenum internalformat, |
| 7013 | GLsizei width, |
| 7014 | GLsizei height, |
| 7015 | GLsizei depth, |
| 7016 | GLint border, |
| 7017 | GLenum format, |
| 7018 | GLenum type, |
| 7019 | const void *pixels) |
| 7020 | { |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 7021 | return ValidateTexImage3D(context, target, level, internalformat, width, height, depth, border, |
| 7022 | format, type, pixels); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7023 | } |
| 7024 | |
| 7025 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 7026 | { |
| 7027 | if (!context->getExtensions().debugMarker) |
| 7028 | { |
| 7029 | // The debug marker calls should not set error state |
| 7030 | // However, it seems reasonable to set an error state if the extension is not enabled |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7031 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7032 | return false; |
| 7033 | } |
| 7034 | |
| 7035 | return true; |
| 7036 | } |
| 7037 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7038 | bool ValidateTexStorage1DEXT(Context *context, |
| 7039 | GLenum target, |
| 7040 | GLsizei levels, |
| 7041 | GLenum internalformat, |
| 7042 | GLsizei width) |
| 7043 | { |
| 7044 | UNIMPLEMENTED(); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7045 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7046 | return false; |
| 7047 | } |
| 7048 | |
| 7049 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 7050 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7051 | GLsizei levels, |
| 7052 | GLenum internalformat, |
| 7053 | GLsizei width, |
| 7054 | GLsizei height, |
| 7055 | GLsizei depth) |
| 7056 | { |
| 7057 | if (!context->getExtensions().textureStorage) |
| 7058 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7059 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7060 | return false; |
| 7061 | } |
| 7062 | |
| 7063 | if (context->getClientMajorVersion() < 3) |
| 7064 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7065 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7066 | return false; |
| 7067 | } |
| 7068 | |
| 7069 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 7070 | depth); |
| 7071 | } |
| 7072 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 7073 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 7074 | { |
| 7075 | if (!context->getExtensions().parallelShaderCompile) |
| 7076 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7077 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 7078 | return false; |
| 7079 | } |
| 7080 | return true; |
| 7081 | } |
| 7082 | |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7083 | bool ValidateMultiDrawArraysANGLE(Context *context, |
| 7084 | PrimitiveMode mode, |
| 7085 | const GLint *firsts, |
| 7086 | const GLsizei *counts, |
| 7087 | GLsizei drawcount) |
| 7088 | { |
| 7089 | if (!context->getExtensions().multiDraw) |
| 7090 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7091 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7092 | return false; |
| 7093 | } |
| 7094 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 7095 | { |
| 7096 | if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID])) |
| 7097 | { |
| 7098 | return false; |
| 7099 | } |
| 7100 | } |
| 7101 | return true; |
| 7102 | } |
| 7103 | |
| 7104 | bool ValidateMultiDrawElementsANGLE(Context *context, |
| 7105 | PrimitiveMode mode, |
| 7106 | const GLsizei *counts, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 7107 | DrawElementsType type, |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 7108 | const GLvoid *const *indices, |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7109 | GLsizei drawcount) |
| 7110 | { |
| 7111 | if (!context->getExtensions().multiDraw) |
| 7112 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7113 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7114 | return false; |
| 7115 | } |
| 7116 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 7117 | { |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 7118 | if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID])) |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7119 | { |
| 7120 | return false; |
| 7121 | } |
| 7122 | } |
| 7123 | return true; |
| 7124 | } |
| 7125 | |
Jeff Gilbert | 465d609 | 2019-01-02 16:21:18 -0800 | [diff] [blame] | 7126 | bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked) |
| 7127 | { |
| 7128 | if (!context->getExtensions().provokingVertex) |
| 7129 | { |
| 7130 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 7131 | return false; |
| 7132 | } |
| 7133 | |
| 7134 | switch (modePacked) |
| 7135 | { |
| 7136 | case ProvokingVertex::FirstVertexConvention: |
| 7137 | case ProvokingVertex::LastVertexConvention: |
| 7138 | break; |
| 7139 | default: |
| 7140 | context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex); |
| 7141 | return false; |
| 7142 | } |
| 7143 | |
| 7144 | return true; |
| 7145 | } |
| 7146 | |
Jamie Madill | a541048 | 2019-01-31 19:55:55 -0500 | [diff] [blame] | 7147 | void RecordBindTextureTypeError(Context *context, TextureType target) |
| 7148 | { |
| 7149 | ASSERT(!context->getStateCache().isValidBindTextureType(target)); |
| 7150 | |
| 7151 | switch (target) |
| 7152 | { |
| 7153 | case TextureType::Rectangle: |
| 7154 | ASSERT(!context->getExtensions().textureRectangle); |
| 7155 | context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported); |
| 7156 | break; |
| 7157 | |
| 7158 | case TextureType::_3D: |
| 7159 | case TextureType::_2DArray: |
| 7160 | ASSERT(context->getClientMajorVersion() < 3); |
| 7161 | context->validationError(GL_INVALID_ENUM, kES3Required); |
| 7162 | break; |
| 7163 | |
| 7164 | case TextureType::_2DMultisample: |
| 7165 | ASSERT(context->getClientVersion() < Version(3, 1) && |
| 7166 | !context->getExtensions().textureMultisample); |
| 7167 | context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required); |
| 7168 | break; |
| 7169 | |
| 7170 | case TextureType::_2DMultisampleArray: |
| 7171 | ASSERT(!context->getExtensions().textureStorageMultisample2DArray); |
| 7172 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
| 7173 | break; |
| 7174 | |
| 7175 | case TextureType::External: |
| 7176 | ASSERT(!context->getExtensions().eglImageExternal && |
| 7177 | !context->getExtensions().eglStreamConsumerExternal); |
| 7178 | context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported); |
| 7179 | break; |
| 7180 | |
| 7181 | default: |
| 7182 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
| 7183 | } |
| 7184 | } |
| 7185 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 7186 | } // namespace gl |