Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Stuart Morgan | 9d73796 | 2019-08-14 12:25:12 -0700 | [diff] [blame] | 2 | // Copyright 2013 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, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 73 | PathID pathBase) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 74 | { |
| 75 | const auto *array = static_cast<const T *>(paths); |
| 76 | |
| 77 | for (GLsizei i = 0; i < numPaths; ++i) |
| 78 | { |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 79 | const GLuint pathName = array[i] + pathBase.value; |
| 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, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 93 | PathID pathBase, |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 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 | d9c1710 | 2019-07-10 14:56:26 -0400 | [diff] [blame] | 1313 | if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, 0, |
| 1314 | width, height, 1, texture->getWidth(target, level), |
| 1315 | texture->getHeight(target, level), |
| 1316 | texture->getDepth(target, level))) |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1317 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1318 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1319 | return false; |
| 1320 | } |
| 1321 | |
| 1322 | if (format != actualInternalFormat) |
| 1323 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1324 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1325 | return false; |
| 1326 | } |
| 1327 | } |
| 1328 | else |
| 1329 | { |
Geoff Lang | d9c1710 | 2019-07-10 14:56:26 -0400 | [diff] [blame] | 1330 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height, 1)) |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1331 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1332 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1333 | return false; |
| 1334 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | else |
| 1338 | { |
| 1339 | // validate <type> by itself (used as secondary key below) |
| 1340 | switch (type) |
| 1341 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1342 | case GL_UNSIGNED_BYTE: |
| 1343 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1344 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1345 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1346 | case GL_UNSIGNED_SHORT: |
| 1347 | case GL_UNSIGNED_INT: |
| 1348 | case GL_UNSIGNED_INT_24_8_OES: |
| 1349 | case GL_HALF_FLOAT_OES: |
| 1350 | case GL_FLOAT: |
| 1351 | break; |
Jaedon Lee | 3b46885 | 2019-07-30 16:50:36 +0900 | [diff] [blame] | 1352 | case GL_UNSIGNED_INT_2_10_10_10_REV_EXT: |
| 1353 | if (!context->getExtensions().textureFormat2101010REV) |
| 1354 | { |
| 1355 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1356 | return false; |
| 1357 | } |
| 1358 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1359 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1360 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1361 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | // validate <format> + <type> combinations |
| 1365 | // - invalid <format> -> sets INVALID_ENUM |
| 1366 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 1367 | switch (format) |
| 1368 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1369 | case GL_ALPHA: |
| 1370 | case GL_LUMINANCE: |
| 1371 | case GL_LUMINANCE_ALPHA: |
| 1372 | switch (type) |
| 1373 | { |
| 1374 | case GL_UNSIGNED_BYTE: |
| 1375 | case GL_FLOAT: |
| 1376 | case GL_HALF_FLOAT_OES: |
| 1377 | break; |
| 1378 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1379 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1380 | return false; |
| 1381 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1382 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1383 | case GL_RED: |
| 1384 | case GL_RG: |
| 1385 | if (!context->getExtensions().textureRG) |
| 1386 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1387 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1388 | return false; |
| 1389 | } |
| 1390 | switch (type) |
| 1391 | { |
| 1392 | case GL_UNSIGNED_BYTE: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1393 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1394 | case GL_FLOAT: |
| 1395 | case GL_HALF_FLOAT_OES: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1396 | if (!context->getExtensions().textureFloat) |
| 1397 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1398 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1399 | return false; |
| 1400 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1401 | break; |
| 1402 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1403 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1404 | return false; |
| 1405 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1406 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1407 | case GL_RGB: |
| 1408 | switch (type) |
| 1409 | { |
| 1410 | case GL_UNSIGNED_BYTE: |
| 1411 | case GL_UNSIGNED_SHORT_5_6_5: |
Jaedon Lee | 3b46885 | 2019-07-30 16:50:36 +0900 | [diff] [blame] | 1412 | case GL_UNSIGNED_INT_2_10_10_10_REV_EXT: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1413 | case GL_FLOAT: |
| 1414 | case GL_HALF_FLOAT_OES: |
| 1415 | break; |
| 1416 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1417 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1418 | return false; |
| 1419 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1420 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1421 | case GL_RGBA: |
| 1422 | switch (type) |
| 1423 | { |
| 1424 | case GL_UNSIGNED_BYTE: |
| 1425 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1426 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1427 | case GL_FLOAT: |
| 1428 | case GL_HALF_FLOAT_OES: |
Jaedon Lee | 3b46885 | 2019-07-30 16:50:36 +0900 | [diff] [blame] | 1429 | case GL_UNSIGNED_INT_2_10_10_10_REV_EXT: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1430 | break; |
| 1431 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1432 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1433 | return false; |
| 1434 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1435 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1436 | case GL_BGRA_EXT: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1437 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1438 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1439 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1440 | return false; |
| 1441 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1442 | switch (type) |
| 1443 | { |
| 1444 | case GL_UNSIGNED_BYTE: |
| 1445 | break; |
| 1446 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1447 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1448 | return false; |
| 1449 | } |
| 1450 | break; |
| 1451 | case GL_SRGB_EXT: |
| 1452 | case GL_SRGB_ALPHA_EXT: |
| 1453 | if (!context->getExtensions().sRGB) |
| 1454 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1455 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1456 | return false; |
| 1457 | } |
| 1458 | switch (type) |
| 1459 | { |
| 1460 | case GL_UNSIGNED_BYTE: |
| 1461 | break; |
| 1462 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1463 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1464 | return false; |
| 1465 | } |
| 1466 | break; |
| 1467 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1468 | // handled below |
| 1469 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1470 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1471 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1472 | break; |
| 1473 | case GL_DEPTH_COMPONENT: |
| 1474 | switch (type) |
| 1475 | { |
| 1476 | case GL_UNSIGNED_SHORT: |
| 1477 | case GL_UNSIGNED_INT: |
| 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 | case GL_DEPTH_STENCIL_OES: |
| 1485 | switch (type) |
| 1486 | { |
| 1487 | case GL_UNSIGNED_INT_24_8_OES: |
| 1488 | break; |
| 1489 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1490 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1491 | return false; |
| 1492 | } |
| 1493 | break; |
| 1494 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1495 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1496 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | switch (format) |
| 1500 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1501 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1502 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1503 | if (context->getExtensions().textureCompressionDXT1) |
| 1504 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1505 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1506 | return false; |
| 1507 | } |
| 1508 | else |
| 1509 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1510 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1511 | return false; |
| 1512 | } |
| 1513 | break; |
| 1514 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1515 | if (context->getExtensions().textureCompressionDXT3) |
| 1516 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1517 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1518 | return false; |
| 1519 | } |
| 1520 | else |
| 1521 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1522 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1523 | return false; |
| 1524 | } |
| 1525 | break; |
| 1526 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1527 | if (context->getExtensions().textureCompressionDXT5) |
| 1528 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1529 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1530 | return false; |
| 1531 | } |
| 1532 | else |
| 1533 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1534 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1535 | return false; |
| 1536 | } |
| 1537 | break; |
| 1538 | case GL_ETC1_RGB8_OES: |
| 1539 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1540 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1541 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1542 | return false; |
| 1543 | } |
| 1544 | else |
| 1545 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1546 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1547 | return false; |
| 1548 | } |
| 1549 | break; |
| 1550 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1551 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1552 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1553 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1554 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1555 | if (context->getExtensions().lossyETCDecode) |
| 1556 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1557 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1558 | return false; |
| 1559 | } |
| 1560 | else |
| 1561 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -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 | } |
| 1565 | break; |
| 1566 | case GL_DEPTH_COMPONENT: |
| 1567 | case GL_DEPTH_STENCIL_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1568 | if (!context->getExtensions().depthTextureANGLE && |
| 1569 | !(context->getExtensions().packedDepthStencil && |
| 1570 | context->getExtensions().depthTextureOES)) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1571 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1572 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1573 | return false; |
| 1574 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1575 | if (target != TextureTarget::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1576 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1577 | context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1578 | return false; |
| 1579 | } |
| 1580 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1581 | // but ANGLE_depth_texture does not |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1582 | if (!context->getExtensions().depthTextureOES) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1583 | { |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1584 | if (pixels != nullptr) |
| 1585 | { |
| 1586 | context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull); |
| 1587 | return false; |
| 1588 | } |
| 1589 | if (level != 0) |
| 1590 | { |
| 1591 | context->validationError(GL_INVALID_OPERATION, kLevelNotZero); |
| 1592 | return false; |
| 1593 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1594 | } |
| 1595 | break; |
| 1596 | default: |
| 1597 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1598 | } |
| 1599 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1600 | if (!isSubImage) |
| 1601 | { |
| 1602 | switch (internalformat) |
| 1603 | { |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1604 | // Core ES 2.0 formats |
| 1605 | case GL_ALPHA: |
| 1606 | case GL_LUMINANCE: |
| 1607 | case GL_LUMINANCE_ALPHA: |
| 1608 | case GL_RGB: |
| 1609 | case GL_RGBA: |
| 1610 | break; |
| 1611 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1612 | case GL_RGBA32F: |
| 1613 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1614 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1615 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1616 | return false; |
| 1617 | } |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1618 | |
| 1619 | nonEqualFormatsAllowed = true; |
| 1620 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1621 | if (type != GL_FLOAT) |
| 1622 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1623 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1624 | return false; |
| 1625 | } |
| 1626 | if (format != GL_RGBA) |
| 1627 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1628 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1629 | return false; |
| 1630 | } |
| 1631 | break; |
| 1632 | |
| 1633 | case GL_RGB32F: |
| 1634 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1635 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1636 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1637 | return false; |
| 1638 | } |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1639 | |
| 1640 | nonEqualFormatsAllowed = true; |
| 1641 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1642 | if (type != GL_FLOAT) |
| 1643 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1644 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1645 | return false; |
| 1646 | } |
| 1647 | if (format != GL_RGB) |
| 1648 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1649 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1650 | return false; |
| 1651 | } |
| 1652 | break; |
| 1653 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1654 | case GL_BGRA_EXT: |
| 1655 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1656 | { |
| 1657 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1658 | return false; |
| 1659 | } |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1660 | break; |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1661 | |
| 1662 | case GL_DEPTH_COMPONENT: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1663 | if (!(context->getExtensions().depthTextureAny())) |
| 1664 | { |
| 1665 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1666 | return false; |
| 1667 | } |
| 1668 | break; |
| 1669 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1670 | case GL_DEPTH_STENCIL: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1671 | if (!(context->getExtensions().depthTextureANGLE || |
| 1672 | context->getExtensions().packedDepthStencil)) |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1673 | { |
| 1674 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1675 | return false; |
| 1676 | } |
| 1677 | break; |
| 1678 | |
| 1679 | case GL_RED: |
| 1680 | case GL_RG: |
| 1681 | if (!context->getExtensions().textureRG) |
| 1682 | { |
| 1683 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1684 | return false; |
| 1685 | } |
| 1686 | break; |
| 1687 | |
| 1688 | case GL_SRGB_EXT: |
| 1689 | case GL_SRGB_ALPHA_EXT: |
| 1690 | if (!context->getExtensions().sRGB) |
| 1691 | { |
| 1692 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1693 | return false; |
| 1694 | } |
| 1695 | break; |
| 1696 | |
Jaedon Lee | 3b46885 | 2019-07-30 16:50:36 +0900 | [diff] [blame] | 1697 | case GL_RGB10_A2_EXT: |
| 1698 | if (!context->getExtensions().textureFormat2101010REV) |
| 1699 | { |
| 1700 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1701 | return false; |
| 1702 | } |
| 1703 | |
| 1704 | if (type != GL_UNSIGNED_INT_2_10_10_10_REV_EXT || format != GL_RGBA) |
| 1705 | { |
| 1706 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
| 1707 | return false; |
| 1708 | } |
| 1709 | |
| 1710 | nonEqualFormatsAllowed = true; |
| 1711 | |
| 1712 | break; |
| 1713 | |
| 1714 | case GL_RGB5_A1: |
| 1715 | if (context->getExtensions().textureFormat2101010REV && |
| 1716 | type == GL_UNSIGNED_INT_2_10_10_10_REV_EXT && format == GL_RGBA) |
| 1717 | { |
| 1718 | nonEqualFormatsAllowed = true; |
| 1719 | } |
| 1720 | |
| 1721 | break; |
| 1722 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1723 | default: |
| 1724 | context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat); |
| 1725 | return false; |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1726 | } |
| 1727 | } |
| 1728 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1729 | if (type == GL_FLOAT) |
| 1730 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1731 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1732 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1733 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1734 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | else if (type == GL_HALF_FLOAT_OES) |
| 1738 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1739 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1740 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1741 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1742 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1743 | } |
| 1744 | } |
| 1745 | } |
| 1746 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1747 | if (isSubImage) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1748 | { |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1749 | const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info; |
| 1750 | if (textureInternalFormat.internalFormat == GL_NONE) |
| 1751 | { |
| 1752 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel); |
| 1753 | return false; |
| 1754 | } |
| 1755 | |
Tim Van Patten | 5f388c2 | 2019-03-14 09:54:23 -0600 | [diff] [blame] | 1756 | if (format != textureInternalFormat.format) |
| 1757 | { |
| 1758 | context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch); |
| 1759 | return false; |
| 1760 | } |
| 1761 | |
| 1762 | if (context->getExtensions().webglCompatibility) |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1763 | { |
| 1764 | if (GetInternalFormatInfo(format, type).sizedInternalFormat != |
| 1765 | textureInternalFormat.sizedInternalFormat) |
| 1766 | { |
Tim Van Patten | 5f388c2 | 2019-03-14 09:54:23 -0600 | [diff] [blame] | 1767 | context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch); |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1768 | return false; |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1773 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 1774 | { |
| 1775 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
| 1776 | return false; |
| 1777 | } |
| 1778 | |
| 1779 | if (width > 0 && height > 0 && pixels == nullptr && |
| 1780 | context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr) |
| 1781 | { |
| 1782 | context->validationError(GL_INVALID_VALUE, kPixelDataNull); |
| 1783 | return false; |
| 1784 | } |
| 1785 | } |
| 1786 | else |
| 1787 | { |
| 1788 | if (texture->getImmutableFormat()) |
| 1789 | { |
| 1790 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
| 1791 | return false; |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | // From GL_CHROMIUM_color_buffer_float_rgb[a]: |
| 1796 | // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for |
| 1797 | // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the |
| 1798 | // internalformat parameter and format parameter of TexImage2D must match is lifted for this |
| 1799 | // case. |
| 1800 | if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed) |
| 1801 | { |
| 1802 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1803 | return false; |
| 1804 | } |
| 1805 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1806 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
| 1807 | return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels, |
| 1808 | imageSize); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1809 | } |
| 1810 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1811 | bool ValidateES2TexStorageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1812 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1813 | GLsizei levels, |
| 1814 | GLenum internalformat, |
| 1815 | GLsizei width, |
| 1816 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1817 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1818 | if (target != TextureType::_2D && target != TextureType::CubeMap && |
| 1819 | target != TextureType::Rectangle) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1820 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1821 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1822 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | if (width < 1 || height < 1 || levels < 1) |
| 1826 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1827 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1828 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1829 | } |
| 1830 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1831 | if (target == TextureType::CubeMap && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1832 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1833 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1834 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1838 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1839 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1840 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1841 | } |
| 1842 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1843 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1844 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1845 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1846 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1847 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1848 | } |
| 1849 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1850 | const gl::Caps &caps = context->getCaps(); |
| 1851 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1852 | switch (target) |
| 1853 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1854 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1855 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1856 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1857 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1858 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1859 | return false; |
| 1860 | } |
| 1861 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1862 | case TextureType::Rectangle: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1863 | if (levels != 1) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1864 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1865 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1866 | return false; |
| 1867 | } |
| 1868 | |
| 1869 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1870 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1871 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1872 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1873 | return false; |
| 1874 | } |
| 1875 | if (formatInfo.compressed) |
| 1876 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1877 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1878 | return false; |
| 1879 | } |
| 1880 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1881 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1882 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1883 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1884 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1885 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1886 | return false; |
| 1887 | } |
| 1888 | break; |
| 1889 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1890 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1891 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1892 | } |
| 1893 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1894 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1895 | { |
| 1896 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1897 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1898 | context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1899 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | switch (internalformat) |
| 1904 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1905 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1906 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1907 | if (!context->getExtensions().textureCompressionDXT1) |
| 1908 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1909 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1910 | return false; |
| 1911 | } |
| 1912 | break; |
| 1913 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1914 | if (!context->getExtensions().textureCompressionDXT3) |
| 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_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1921 | if (!context->getExtensions().textureCompressionDXT5) |
| 1922 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1923 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1924 | return false; |
| 1925 | } |
| 1926 | break; |
| 1927 | case GL_ETC1_RGB8_OES: |
| 1928 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1929 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1930 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1931 | return false; |
| 1932 | } |
| 1933 | break; |
| 1934 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1935 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1936 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1937 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1938 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1939 | if (!context->getExtensions().lossyETCDecode) |
| 1940 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1941 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1942 | return false; |
| 1943 | } |
| 1944 | break; |
| 1945 | case GL_RGBA32F_EXT: |
| 1946 | case GL_RGB32F_EXT: |
| 1947 | case GL_ALPHA32F_EXT: |
| 1948 | case GL_LUMINANCE32F_EXT: |
| 1949 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 1950 | if (!context->getExtensions().textureFloat) |
| 1951 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1952 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1953 | return false; |
| 1954 | } |
| 1955 | break; |
| 1956 | case GL_RGBA16F_EXT: |
| 1957 | case GL_RGB16F_EXT: |
| 1958 | case GL_ALPHA16F_EXT: |
| 1959 | case GL_LUMINANCE16F_EXT: |
| 1960 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 1961 | if (!context->getExtensions().textureHalfFloat) |
| 1962 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1963 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1964 | return false; |
| 1965 | } |
| 1966 | break; |
| 1967 | case GL_R8_EXT: |
| 1968 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1969 | if (!context->getExtensions().textureRG) |
| 1970 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1971 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1972 | return false; |
| 1973 | } |
| 1974 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1975 | case GL_R16F_EXT: |
| 1976 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1977 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 1978 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1979 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1980 | return false; |
| 1981 | } |
| 1982 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1983 | case GL_R32F_EXT: |
| 1984 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1985 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1986 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1987 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1988 | return false; |
| 1989 | } |
| 1990 | break; |
| 1991 | case GL_DEPTH_COMPONENT16: |
| 1992 | case GL_DEPTH_COMPONENT32_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1993 | if (!(context->getExtensions().depthTextureAny())) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1994 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1995 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1996 | return false; |
| 1997 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1998 | if (target != TextureType::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1999 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2000 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2001 | return false; |
| 2002 | } |
| 2003 | // ANGLE_depth_texture only supports 1-level textures |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 2004 | if (!context->getExtensions().depthTextureOES) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2005 | { |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 2006 | if (levels != 1) |
| 2007 | { |
| 2008 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
| 2009 | return false; |
| 2010 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2011 | } |
| 2012 | break; |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 2013 | case GL_DEPTH24_STENCIL8_OES: |
| 2014 | if (!(context->getExtensions().depthTextureANGLE || |
| 2015 | (context->getExtensions().packedDepthStencil && |
| 2016 | context->getExtensions().textureStorage))) |
| 2017 | { |
| 2018 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 2019 | return false; |
| 2020 | } |
| 2021 | if (target != TextureType::_2D) |
| 2022 | { |
| 2023 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
| 2024 | return false; |
| 2025 | } |
| 2026 | if (!context->getExtensions().packedDepthStencil) |
| 2027 | { |
| 2028 | // ANGLE_depth_texture only supports 1-level textures |
| 2029 | if (levels != 1) |
| 2030 | { |
| 2031 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
| 2032 | return false; |
| 2033 | } |
| 2034 | } |
| 2035 | break; |
| 2036 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2037 | default: |
| 2038 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2039 | } |
| 2040 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 2041 | gl::Texture *texture = context->getTextureByType(target); |
Jamie Madill | f703443 | 2019-09-21 14:10:35 -0400 | [diff] [blame^] | 2042 | if (!texture || texture->id().value == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2043 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2044 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2045 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2046 | } |
| 2047 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2048 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2049 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2050 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2051 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | return true; |
| 2055 | } |
| 2056 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2057 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 2058 | GLenum target, |
| 2059 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2060 | const GLenum *attachments) |
| 2061 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2062 | if (!context->getExtensions().discardFramebuffer) |
| 2063 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2064 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2065 | return false; |
| 2066 | } |
| 2067 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2068 | bool defaultFramebuffer = false; |
| 2069 | |
| 2070 | switch (target) |
| 2071 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2072 | case GL_FRAMEBUFFER: |
| 2073 | defaultFramebuffer = |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 2074 | (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->isDefault()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2075 | break; |
| 2076 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2077 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2078 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2081 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 2082 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2085 | bool ValidateBindVertexArrayOES(Context *context, VertexArrayID array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2086 | { |
| 2087 | if (!context->getExtensions().vertexArrayObject) |
| 2088 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2089 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2090 | return false; |
| 2091 | } |
| 2092 | |
| 2093 | return ValidateBindVertexArrayBase(context, array); |
| 2094 | } |
| 2095 | |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2096 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const VertexArrayID *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2097 | { |
| 2098 | if (!context->getExtensions().vertexArrayObject) |
| 2099 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2100 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2101 | return false; |
| 2102 | } |
| 2103 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2104 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2107 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n, VertexArrayID *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2108 | { |
| 2109 | if (!context->getExtensions().vertexArrayObject) |
| 2110 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2111 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2112 | return false; |
| 2113 | } |
| 2114 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2115 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2118 | bool ValidateIsVertexArrayOES(Context *context, VertexArrayID array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2119 | { |
| 2120 | if (!context->getExtensions().vertexArrayObject) |
| 2121 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2122 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2123 | return false; |
| 2124 | } |
| 2125 | |
| 2126 | return true; |
| 2127 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2128 | |
| 2129 | bool ValidateProgramBinaryOES(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 2130 | ShaderProgramID program, |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2131 | GLenum binaryFormat, |
| 2132 | const void *binary, |
| 2133 | GLint length) |
| 2134 | { |
| 2135 | if (!context->getExtensions().getProgramBinary) |
| 2136 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2137 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2138 | return false; |
| 2139 | } |
| 2140 | |
| 2141 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 2142 | } |
| 2143 | |
| 2144 | bool ValidateGetProgramBinaryOES(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 2145 | ShaderProgramID program, |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2146 | GLsizei bufSize, |
| 2147 | GLsizei *length, |
| 2148 | GLenum *binaryFormat, |
| 2149 | void *binary) |
| 2150 | { |
| 2151 | if (!context->getExtensions().getProgramBinary) |
| 2152 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2153 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2154 | return false; |
| 2155 | } |
| 2156 | |
| 2157 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 2158 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2159 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2160 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 2161 | { |
| 2162 | switch (source) |
| 2163 | { |
| 2164 | case GL_DEBUG_SOURCE_API: |
| 2165 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 2166 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 2167 | case GL_DEBUG_SOURCE_OTHER: |
| 2168 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 2169 | return !mustBeThirdPartyOrApplication; |
| 2170 | |
| 2171 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 2172 | case GL_DEBUG_SOURCE_APPLICATION: |
| 2173 | return true; |
| 2174 | |
| 2175 | default: |
| 2176 | return false; |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | static bool ValidDebugType(GLenum type) |
| 2181 | { |
| 2182 | switch (type) |
| 2183 | { |
| 2184 | case GL_DEBUG_TYPE_ERROR: |
| 2185 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 2186 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 2187 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 2188 | case GL_DEBUG_TYPE_PORTABILITY: |
| 2189 | case GL_DEBUG_TYPE_OTHER: |
| 2190 | case GL_DEBUG_TYPE_MARKER: |
| 2191 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 2192 | case GL_DEBUG_TYPE_POP_GROUP: |
| 2193 | return true; |
| 2194 | |
| 2195 | default: |
| 2196 | return false; |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | static bool ValidDebugSeverity(GLenum severity) |
| 2201 | { |
| 2202 | switch (severity) |
| 2203 | { |
| 2204 | case GL_DEBUG_SEVERITY_HIGH: |
| 2205 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 2206 | case GL_DEBUG_SEVERITY_LOW: |
| 2207 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 2208 | return true; |
| 2209 | |
| 2210 | default: |
| 2211 | return false; |
| 2212 | } |
| 2213 | } |
| 2214 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2215 | bool ValidateDebugMessageControlKHR(Context *context, |
| 2216 | GLenum source, |
| 2217 | GLenum type, |
| 2218 | GLenum severity, |
| 2219 | GLsizei count, |
| 2220 | const GLuint *ids, |
| 2221 | GLboolean enabled) |
| 2222 | { |
| 2223 | if (!context->getExtensions().debug) |
| 2224 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2225 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2226 | return false; |
| 2227 | } |
| 2228 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2229 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 2230 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2231 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2232 | return false; |
| 2233 | } |
| 2234 | |
| 2235 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 2236 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2237 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2238 | return false; |
| 2239 | } |
| 2240 | |
| 2241 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 2242 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2243 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2244 | return false; |
| 2245 | } |
| 2246 | |
| 2247 | if (count > 0) |
| 2248 | { |
| 2249 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 2250 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2251 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2252 | return false; |
| 2253 | } |
| 2254 | |
| 2255 | if (severity != GL_DONT_CARE) |
| 2256 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2257 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2258 | return false; |
| 2259 | } |
| 2260 | } |
| 2261 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2262 | return true; |
| 2263 | } |
| 2264 | |
| 2265 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 2266 | GLenum source, |
| 2267 | GLenum type, |
| 2268 | GLuint id, |
| 2269 | GLenum severity, |
| 2270 | GLsizei length, |
| 2271 | const GLchar *buf) |
| 2272 | { |
| 2273 | if (!context->getExtensions().debug) |
| 2274 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2275 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2276 | return false; |
| 2277 | } |
| 2278 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2279 | if (!context->getState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2280 | { |
| 2281 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 2282 | // not generate an error. |
| 2283 | return false; |
| 2284 | } |
| 2285 | |
| 2286 | if (!ValidDebugSeverity(severity)) |
| 2287 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2288 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2289 | return false; |
| 2290 | } |
| 2291 | |
| 2292 | if (!ValidDebugType(type)) |
| 2293 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2294 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2295 | return false; |
| 2296 | } |
| 2297 | |
| 2298 | if (!ValidDebugSource(source, true)) |
| 2299 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2300 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2301 | return false; |
| 2302 | } |
| 2303 | |
| 2304 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 2305 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2306 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2307 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2308 | return false; |
| 2309 | } |
| 2310 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2311 | return true; |
| 2312 | } |
| 2313 | |
| 2314 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 2315 | GLDEBUGPROCKHR callback, |
| 2316 | const void *userParam) |
| 2317 | { |
| 2318 | if (!context->getExtensions().debug) |
| 2319 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2320 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2321 | return false; |
| 2322 | } |
| 2323 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2324 | return true; |
| 2325 | } |
| 2326 | |
| 2327 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 2328 | GLuint count, |
| 2329 | GLsizei bufSize, |
| 2330 | GLenum *sources, |
| 2331 | GLenum *types, |
| 2332 | GLuint *ids, |
| 2333 | GLenum *severities, |
| 2334 | GLsizei *lengths, |
| 2335 | GLchar *messageLog) |
| 2336 | { |
| 2337 | if (!context->getExtensions().debug) |
| 2338 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2339 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2340 | return false; |
| 2341 | } |
| 2342 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2343 | if (bufSize < 0 && messageLog != nullptr) |
| 2344 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2345 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2346 | return false; |
| 2347 | } |
| 2348 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2349 | return true; |
| 2350 | } |
| 2351 | |
| 2352 | bool ValidatePushDebugGroupKHR(Context *context, |
| 2353 | GLenum source, |
| 2354 | GLuint id, |
| 2355 | GLsizei length, |
| 2356 | const GLchar *message) |
| 2357 | { |
| 2358 | if (!context->getExtensions().debug) |
| 2359 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2360 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2361 | return false; |
| 2362 | } |
| 2363 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2364 | if (!ValidDebugSource(source, true)) |
| 2365 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2366 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2367 | return false; |
| 2368 | } |
| 2369 | |
| 2370 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 2371 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2372 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2373 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2374 | return false; |
| 2375 | } |
| 2376 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2377 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2378 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 2379 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2380 | context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2381 | return false; |
| 2382 | } |
| 2383 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2384 | return true; |
| 2385 | } |
| 2386 | |
| 2387 | bool ValidatePopDebugGroupKHR(Context *context) |
| 2388 | { |
| 2389 | if (!context->getExtensions().debug) |
| 2390 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2391 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2392 | return false; |
| 2393 | } |
| 2394 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2395 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2396 | if (currentStackSize <= 1) |
| 2397 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2398 | context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2399 | return false; |
| 2400 | } |
| 2401 | |
| 2402 | return true; |
| 2403 | } |
| 2404 | |
| 2405 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 2406 | { |
| 2407 | switch (identifier) |
| 2408 | { |
| 2409 | case GL_BUFFER: |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 2410 | if (context->getBuffer({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2411 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2412 | context->validationError(GL_INVALID_VALUE, kInvalidBufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2413 | return false; |
| 2414 | } |
| 2415 | return true; |
| 2416 | |
| 2417 | case GL_SHADER: |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 2418 | if (context->getShader({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2419 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2420 | context->validationError(GL_INVALID_VALUE, kInvalidShaderName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2421 | return false; |
| 2422 | } |
| 2423 | return true; |
| 2424 | |
| 2425 | case GL_PROGRAM: |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 2426 | if (context->getProgramNoResolveLink({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2427 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2428 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2429 | return false; |
| 2430 | } |
| 2431 | return true; |
| 2432 | |
| 2433 | case GL_VERTEX_ARRAY: |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2434 | if (context->getVertexArray({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2435 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2436 | context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2437 | return false; |
| 2438 | } |
| 2439 | return true; |
| 2440 | |
| 2441 | case GL_QUERY: |
Jiacheng Lu | 814a0a1 | 2019-08-22 11:50:43 -0600 | [diff] [blame] | 2442 | if (context->getQuery({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2443 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2444 | context->validationError(GL_INVALID_VALUE, kInvalidQueryName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2445 | return false; |
| 2446 | } |
| 2447 | return true; |
| 2448 | |
| 2449 | case GL_TRANSFORM_FEEDBACK: |
Jiacheng Lu | c3f7873 | 2019-08-30 15:00:52 -0600 | [diff] [blame] | 2450 | if (context->getTransformFeedback({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2451 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2452 | context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2453 | return false; |
| 2454 | } |
| 2455 | return true; |
| 2456 | |
| 2457 | case GL_SAMPLER: |
Jiacheng Lu | ee79e2f | 2019-08-20 11:28:36 -0600 | [diff] [blame] | 2458 | if (context->getSampler({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2459 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2460 | context->validationError(GL_INVALID_VALUE, kInvalidSamplerName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2461 | return false; |
| 2462 | } |
| 2463 | return true; |
| 2464 | |
| 2465 | case GL_TEXTURE: |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 2466 | if (context->getTexture({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2467 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2468 | context->validationError(GL_INVALID_VALUE, kInvalidTextureName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2469 | return false; |
| 2470 | } |
| 2471 | return true; |
| 2472 | |
| 2473 | case GL_RENDERBUFFER: |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 2474 | if (!context->isRenderbuffer({name})) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2475 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2476 | context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2477 | return false; |
| 2478 | } |
| 2479 | return true; |
| 2480 | |
| 2481 | case GL_FRAMEBUFFER: |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 2482 | if (context->getFramebuffer({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2483 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2484 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2485 | return false; |
| 2486 | } |
| 2487 | return true; |
| 2488 | |
| 2489 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2490 | context->validationError(GL_INVALID_ENUM, kInvalidIndentifier); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2491 | return false; |
| 2492 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2493 | } |
| 2494 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2495 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2496 | { |
| 2497 | size_t labelLength = 0; |
| 2498 | |
| 2499 | if (length < 0) |
| 2500 | { |
| 2501 | if (label != nullptr) |
| 2502 | { |
| 2503 | labelLength = strlen(label); |
| 2504 | } |
| 2505 | } |
| 2506 | else |
| 2507 | { |
| 2508 | labelLength = static_cast<size_t>(length); |
| 2509 | } |
| 2510 | |
| 2511 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2512 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2513 | context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2514 | return false; |
| 2515 | } |
| 2516 | |
| 2517 | return true; |
| 2518 | } |
| 2519 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2520 | bool ValidateObjectLabelKHR(Context *context, |
| 2521 | GLenum identifier, |
| 2522 | GLuint name, |
| 2523 | GLsizei length, |
| 2524 | const GLchar *label) |
| 2525 | { |
| 2526 | if (!context->getExtensions().debug) |
| 2527 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2528 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2529 | return false; |
| 2530 | } |
| 2531 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2532 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2533 | { |
| 2534 | return false; |
| 2535 | } |
| 2536 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2537 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2538 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2539 | return false; |
| 2540 | } |
| 2541 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2542 | return true; |
| 2543 | } |
| 2544 | |
| 2545 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2546 | GLenum identifier, |
| 2547 | GLuint name, |
| 2548 | GLsizei bufSize, |
| 2549 | GLsizei *length, |
| 2550 | 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 (bufSize < 0) |
| 2559 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2560 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2561 | return false; |
| 2562 | } |
| 2563 | |
| 2564 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2565 | { |
| 2566 | return false; |
| 2567 | } |
| 2568 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2569 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2573 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 2574 | if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2575 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2576 | context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2577 | return false; |
| 2578 | } |
| 2579 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2580 | return true; |
| 2581 | } |
| 2582 | |
| 2583 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2584 | const void *ptr, |
| 2585 | GLsizei length, |
| 2586 | const GLchar *label) |
| 2587 | { |
| 2588 | if (!context->getExtensions().debug) |
| 2589 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2590 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2591 | return false; |
| 2592 | } |
| 2593 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2594 | if (!ValidateObjectPtrName(context, ptr)) |
| 2595 | { |
| 2596 | return false; |
| 2597 | } |
| 2598 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2599 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2600 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2601 | return false; |
| 2602 | } |
| 2603 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2604 | return true; |
| 2605 | } |
| 2606 | |
| 2607 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2608 | const void *ptr, |
| 2609 | GLsizei bufSize, |
| 2610 | GLsizei *length, |
| 2611 | GLchar *label) |
| 2612 | { |
| 2613 | if (!context->getExtensions().debug) |
| 2614 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2615 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2616 | return false; |
| 2617 | } |
| 2618 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2619 | if (bufSize < 0) |
| 2620 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2621 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2622 | return false; |
| 2623 | } |
| 2624 | |
| 2625 | if (!ValidateObjectPtrName(context, ptr)) |
| 2626 | { |
| 2627 | return false; |
| 2628 | } |
| 2629 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2630 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2634 | { |
| 2635 | if (!context->getExtensions().debug) |
| 2636 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2637 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2638 | return false; |
| 2639 | } |
| 2640 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2641 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2642 | switch (pname) |
| 2643 | { |
| 2644 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2645 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2646 | break; |
| 2647 | |
| 2648 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2649 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2650 | return false; |
| 2651 | } |
| 2652 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2653 | return true; |
| 2654 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2655 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 2656 | bool ValidateGetPointervRobustANGLERobustANGLE(Context *context, |
| 2657 | GLenum pname, |
| 2658 | GLsizei bufSize, |
| 2659 | GLsizei *length, |
| 2660 | void **params) |
| 2661 | { |
| 2662 | UNIMPLEMENTED(); |
| 2663 | return false; |
| 2664 | } |
| 2665 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2666 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2667 | GLint srcX0, |
| 2668 | GLint srcY0, |
| 2669 | GLint srcX1, |
| 2670 | GLint srcY1, |
| 2671 | GLint dstX0, |
| 2672 | GLint dstY0, |
| 2673 | GLint dstX1, |
| 2674 | GLint dstY1, |
| 2675 | GLbitfield mask, |
| 2676 | GLenum filter) |
| 2677 | { |
| 2678 | if (!context->getExtensions().framebufferBlit) |
| 2679 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2680 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2681 | return false; |
| 2682 | } |
| 2683 | |
| 2684 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2685 | { |
| 2686 | // TODO(jmadill): Determine if this should be available on other implementations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2687 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2688 | return false; |
| 2689 | } |
| 2690 | |
| 2691 | if (filter == GL_LINEAR) |
| 2692 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2693 | context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2694 | return false; |
| 2695 | } |
| 2696 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2697 | Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 2698 | Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2699 | |
| 2700 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2701 | { |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 2702 | const FramebufferAttachment *readColorAttachment = |
| 2703 | readFramebuffer->getReadColorAttachment(); |
| 2704 | const FramebufferAttachment *drawColorAttachment = |
| 2705 | drawFramebuffer->getFirstColorAttachment(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2706 | |
| 2707 | if (readColorAttachment && drawColorAttachment) |
| 2708 | { |
| 2709 | if (!(readColorAttachment->type() == GL_TEXTURE && |
Kenneth Russell | cbdf861 | 2019-07-09 20:30:45 -0700 | [diff] [blame] | 2710 | (readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D || |
| 2711 | readColorAttachment->getTextureImageIndex().getType() == |
| 2712 | TextureType::Rectangle)) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2713 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2714 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2715 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2716 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2717 | kBlitExtensionFromInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2718 | return false; |
| 2719 | } |
| 2720 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2721 | for (size_t drawbufferIdx = 0; |
| 2722 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2723 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2724 | const FramebufferAttachment *attachment = |
| 2725 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2726 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2727 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2728 | if (!(attachment->type() == GL_TEXTURE && |
Kenneth Russell | cbdf861 | 2019-07-09 20:30:45 -0700 | [diff] [blame] | 2729 | (attachment->getTextureImageIndex().getType() == TextureType::_2D || |
| 2730 | attachment->getTextureImageIndex().getType() == |
| 2731 | TextureType::Rectangle)) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2732 | attachment->type() != GL_RENDERBUFFER && |
| 2733 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2734 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2735 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2736 | kBlitExtensionToInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2737 | return false; |
| 2738 | } |
| 2739 | |
| 2740 | // Return an error if the destination formats do not match |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 2741 | if (!Format::EquivalentForBlit(attachment->getFormat(), |
| 2742 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2743 | { |
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 | kBlitExtensionFormatMismatch); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2746 | return false; |
| 2747 | } |
| 2748 | } |
| 2749 | } |
| 2750 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2751 | GLint samples = readFramebuffer->getSamples(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2752 | if (samples != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2753 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2754 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2755 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2756 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2757 | kBlitExtensionMultisampledWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2758 | return false; |
| 2759 | } |
| 2760 | } |
| 2761 | } |
| 2762 | |
| 2763 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2764 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2765 | for (size_t i = 0; i < 2; i++) |
| 2766 | { |
| 2767 | if (mask & masks[i]) |
| 2768 | { |
| 2769 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2770 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2771 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2772 | drawFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2773 | |
| 2774 | if (readBuffer && drawBuffer) |
| 2775 | { |
| 2776 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2777 | dstX0, dstY0, dstX1, dstY1)) |
| 2778 | { |
| 2779 | // only whole-buffer copies are permitted |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2780 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2781 | kBlitExtensionDepthStencilWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2782 | return false; |
| 2783 | } |
| 2784 | |
| 2785 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2786 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2787 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2788 | kBlitExtensionMultisampledDepthOrStencil); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2789 | return false; |
| 2790 | } |
| 2791 | } |
| 2792 | } |
| 2793 | } |
| 2794 | |
| 2795 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2796 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2797 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2798 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2799 | bool ValidateClear(Context *context, GLbitfield mask) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2800 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2801 | Framebuffer *fbo = context->getState().getDrawFramebuffer(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2802 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2803 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2804 | if (!ValidateFramebufferComplete(context, fbo)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2805 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2806 | return false; |
| 2807 | } |
| 2808 | |
| 2809 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2810 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2811 | context->validationError(GL_INVALID_VALUE, kInvalidClearMask); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2812 | return false; |
| 2813 | } |
| 2814 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2815 | if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2816 | { |
| 2817 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2818 | GL_SIGNED_NORMALIZED}; |
| 2819 | |
Corentin Wallez | 59c4159 | 2017-07-11 13:19:54 -0400 | [diff] [blame] | 2820 | for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2821 | drawBufferIdx++) |
| 2822 | { |
| 2823 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2824 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2825 | { |
| 2826 | return false; |
| 2827 | } |
| 2828 | } |
| 2829 | } |
| 2830 | |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame] | 2831 | if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery) |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2832 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2833 | const State &state = context->getState(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2834 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2835 | if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed)) |
| 2836 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2837 | context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2838 | return false; |
| 2839 | } |
| 2840 | } |
| 2841 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2842 | return true; |
| 2843 | } |
| 2844 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2845 | bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2846 | { |
| 2847 | if (!context->getExtensions().drawBuffers) |
| 2848 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2849 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2850 | return false; |
| 2851 | } |
| 2852 | |
| 2853 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2854 | } |
| 2855 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2856 | bool ValidateTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2857 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2858 | GLint level, |
| 2859 | GLint internalformat, |
| 2860 | GLsizei width, |
| 2861 | GLsizei height, |
| 2862 | GLint border, |
| 2863 | GLenum format, |
| 2864 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2865 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2866 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2867 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2868 | { |
| 2869 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2870 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2871 | } |
| 2872 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2873 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2874 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2875 | 0, 0, width, height, 1, border, format, type, -1, |
| 2876 | pixels); |
| 2877 | } |
| 2878 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 2879 | bool ValidateTexImage2DRobustANGLE(Context *context, |
| 2880 | TextureTarget target, |
| 2881 | GLint level, |
| 2882 | GLint internalformat, |
| 2883 | GLsizei width, |
| 2884 | GLsizei height, |
| 2885 | GLint border, |
| 2886 | GLenum format, |
| 2887 | GLenum type, |
| 2888 | GLsizei bufSize, |
| 2889 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2890 | { |
| 2891 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2892 | { |
| 2893 | return false; |
| 2894 | } |
| 2895 | |
| 2896 | if (context->getClientMajorVersion() < 3) |
| 2897 | { |
| 2898 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2899 | 0, 0, width, height, border, format, type, bufSize, |
| 2900 | pixels); |
| 2901 | } |
| 2902 | |
| 2903 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2904 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2905 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2906 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | bool ValidateTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2910 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2911 | GLint level, |
| 2912 | GLint xoffset, |
| 2913 | GLint yoffset, |
| 2914 | GLsizei width, |
| 2915 | GLsizei height, |
| 2916 | GLenum format, |
| 2917 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2918 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2919 | { |
| 2920 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2921 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2922 | { |
| 2923 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2924 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2925 | } |
| 2926 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2927 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2928 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2929 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 2930 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2931 | } |
| 2932 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2933 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2934 | TextureTarget target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2935 | GLint level, |
| 2936 | GLint xoffset, |
| 2937 | GLint yoffset, |
| 2938 | GLsizei width, |
| 2939 | GLsizei height, |
| 2940 | GLenum format, |
| 2941 | GLenum type, |
| 2942 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2943 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2944 | { |
| 2945 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2946 | { |
| 2947 | return false; |
| 2948 | } |
| 2949 | |
| 2950 | if (context->getClientMajorVersion() < 3) |
| 2951 | { |
| 2952 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2953 | yoffset, width, height, 0, format, type, bufSize, |
| 2954 | pixels); |
| 2955 | } |
| 2956 | |
| 2957 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2958 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2959 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 2960 | pixels); |
| 2961 | } |
| 2962 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 2963 | bool ValidateTexSubImage3DOES(Context *context, |
| 2964 | TextureTarget target, |
| 2965 | GLint level, |
| 2966 | GLint xoffset, |
| 2967 | GLint yoffset, |
| 2968 | GLint zoffset, |
| 2969 | GLsizei width, |
| 2970 | GLsizei height, |
| 2971 | GLsizei depth, |
| 2972 | GLenum format, |
| 2973 | GLenum type, |
| 2974 | const void *pixels) |
| 2975 | { |
| 2976 | return ValidateTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, height, |
| 2977 | depth, format, type, pixels); |
| 2978 | } |
| 2979 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2980 | bool ValidateCompressedTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2981 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2982 | GLint level, |
| 2983 | GLenum internalformat, |
| 2984 | GLsizei width, |
| 2985 | GLsizei height, |
| 2986 | GLint border, |
| 2987 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2988 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2989 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2990 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2991 | { |
| 2992 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2993 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2994 | { |
| 2995 | return false; |
| 2996 | } |
| 2997 | } |
| 2998 | else |
| 2999 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3000 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3001 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3002 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3003 | data)) |
| 3004 | { |
| 3005 | return false; |
| 3006 | } |
| 3007 | } |
| 3008 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3009 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3010 | |
| 3011 | GLuint blockSize = 0; |
| 3012 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3013 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3014 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3015 | return false; |
| 3016 | } |
| 3017 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3018 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3019 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3020 | context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3021 | return false; |
| 3022 | } |
| 3023 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3024 | if (target == TextureTarget::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 3025 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3026 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 3027 | return false; |
| 3028 | } |
| 3029 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3030 | return true; |
| 3031 | } |
| 3032 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3033 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3034 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3035 | GLint level, |
| 3036 | GLenum internalformat, |
| 3037 | GLsizei width, |
| 3038 | GLsizei height, |
| 3039 | GLint border, |
| 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 ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 3050 | border, imageSize, data); |
| 3051 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3052 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 3053 | bool ValidateCompressedTexImage3DOES(Context *context, |
| 3054 | TextureTarget target, |
| 3055 | GLint level, |
| 3056 | GLenum internalformat, |
| 3057 | GLsizei width, |
| 3058 | GLsizei height, |
| 3059 | GLsizei depth, |
| 3060 | GLint border, |
| 3061 | GLsizei imageSize, |
| 3062 | const void *data) |
| 3063 | { |
| 3064 | return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height, |
| 3065 | depth, border, imageSize, data); |
| 3066 | } |
| 3067 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3068 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3069 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3070 | GLint level, |
| 3071 | GLint xoffset, |
| 3072 | GLint yoffset, |
| 3073 | GLsizei width, |
| 3074 | GLsizei height, |
| 3075 | GLenum format, |
| 3076 | GLsizei imageSize, |
| 3077 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3078 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3079 | { |
| 3080 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 3081 | { |
| 3082 | return false; |
| 3083 | } |
| 3084 | |
| 3085 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 3086 | format, imageSize, data); |
| 3087 | } |
| 3088 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3089 | bool ValidateCompressedTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3090 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3091 | GLint level, |
| 3092 | GLint xoffset, |
| 3093 | GLint yoffset, |
| 3094 | GLsizei width, |
| 3095 | GLsizei height, |
| 3096 | GLenum format, |
| 3097 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3098 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3099 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3100 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3101 | { |
| 3102 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 3103 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3104 | { |
| 3105 | return false; |
| 3106 | } |
| 3107 | } |
| 3108 | else |
| 3109 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3110 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3111 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 3112 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3113 | data)) |
| 3114 | { |
| 3115 | return false; |
| 3116 | } |
| 3117 | } |
| 3118 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3119 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3120 | GLuint blockSize = 0; |
| 3121 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3122 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3123 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3124 | return false; |
| 3125 | } |
| 3126 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3127 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3128 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3129 | context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3130 | return false; |
| 3131 | } |
| 3132 | |
| 3133 | return true; |
| 3134 | } |
| 3135 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 3136 | bool ValidateCompressedTexSubImage3DOES(Context *context, |
| 3137 | TextureTarget target, |
| 3138 | GLint level, |
| 3139 | GLint xoffset, |
| 3140 | GLint yoffset, |
| 3141 | GLint zoffset, |
| 3142 | GLsizei width, |
| 3143 | GLsizei height, |
| 3144 | GLsizei depth, |
| 3145 | GLenum format, |
| 3146 | GLsizei imageSize, |
| 3147 | const void *data) |
| 3148 | { |
| 3149 | return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, |
| 3150 | height, depth, format, imageSize, data); |
| 3151 | } |
| 3152 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3153 | bool ValidateGetBufferPointervOES(Context *context, |
| 3154 | BufferBinding target, |
| 3155 | GLenum pname, |
| 3156 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3157 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3158 | if (!context->getExtensions().mapBuffer) |
| 3159 | { |
| 3160 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3161 | return false; |
| 3162 | } |
| 3163 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3164 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3165 | } |
| 3166 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3167 | bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3168 | { |
| 3169 | if (!context->getExtensions().mapBuffer) |
| 3170 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3171 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3172 | return false; |
| 3173 | } |
| 3174 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3175 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3176 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3177 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3178 | return false; |
| 3179 | } |
| 3180 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3181 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3182 | |
| 3183 | if (buffer == nullptr) |
| 3184 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3185 | context->validationError(GL_INVALID_OPERATION, kBufferNotMappable); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3186 | return false; |
| 3187 | } |
| 3188 | |
| 3189 | if (access != GL_WRITE_ONLY_OES) |
| 3190 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3191 | context->validationError(GL_INVALID_ENUM, kInvalidAccessBits); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3192 | return false; |
| 3193 | } |
| 3194 | |
| 3195 | if (buffer->isMapped()) |
| 3196 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3197 | context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3198 | return false; |
| 3199 | } |
| 3200 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3201 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3202 | } |
| 3203 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3204 | bool ValidateUnmapBufferOES(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3205 | { |
| 3206 | if (!context->getExtensions().mapBuffer) |
| 3207 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3208 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3209 | return false; |
| 3210 | } |
| 3211 | |
| 3212 | return ValidateUnmapBufferBase(context, target); |
| 3213 | } |
| 3214 | |
| 3215 | bool ValidateMapBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3216 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3217 | GLintptr offset, |
| 3218 | GLsizeiptr length, |
| 3219 | GLbitfield access) |
| 3220 | { |
| 3221 | if (!context->getExtensions().mapBufferRange) |
| 3222 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3223 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3224 | return false; |
| 3225 | } |
| 3226 | |
| 3227 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 3228 | } |
| 3229 | |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3230 | bool ValidateBufferStorageMemEXT(Context *context, |
| 3231 | TextureType target, |
| 3232 | GLsizeiptr size, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3233 | MemoryObjectID memory, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3234 | GLuint64 offset) |
| 3235 | { |
| 3236 | if (!context->getExtensions().memoryObject) |
| 3237 | { |
| 3238 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3239 | return false; |
| 3240 | } |
| 3241 | |
| 3242 | UNIMPLEMENTED(); |
| 3243 | return false; |
| 3244 | } |
| 3245 | |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3246 | bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, MemoryObjectID *memoryObjects) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3247 | { |
| 3248 | if (!context->getExtensions().memoryObject) |
| 3249 | { |
| 3250 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3251 | return false; |
| 3252 | } |
| 3253 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3254 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3255 | } |
| 3256 | |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3257 | bool ValidateDeleteMemoryObjectsEXT(Context *context, |
| 3258 | GLsizei n, |
| 3259 | const MemoryObjectID *memoryObjects) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3260 | { |
| 3261 | if (!context->getExtensions().memoryObject) |
| 3262 | { |
| 3263 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3264 | return false; |
| 3265 | } |
| 3266 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3267 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | bool ValidateGetMemoryObjectParameterivEXT(Context *context, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3271 | MemoryObjectID memoryObject, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3272 | GLenum pname, |
| 3273 | GLint *params) |
| 3274 | { |
| 3275 | if (!context->getExtensions().memoryObject) |
| 3276 | { |
| 3277 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3278 | return false; |
| 3279 | } |
| 3280 | |
| 3281 | UNIMPLEMENTED(); |
| 3282 | return false; |
| 3283 | } |
| 3284 | |
| 3285 | bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data) |
| 3286 | { |
| 3287 | if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore) |
| 3288 | { |
| 3289 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3290 | return false; |
| 3291 | } |
| 3292 | |
| 3293 | UNIMPLEMENTED(); |
| 3294 | return false; |
| 3295 | } |
| 3296 | |
| 3297 | bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data) |
| 3298 | { |
| 3299 | if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore) |
| 3300 | { |
| 3301 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3302 | return false; |
| 3303 | } |
| 3304 | |
| 3305 | UNIMPLEMENTED(); |
| 3306 | return false; |
| 3307 | } |
| 3308 | |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3309 | bool ValidateIsMemoryObjectEXT(Context *context, MemoryObjectID memoryObject) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3310 | { |
| 3311 | if (!context->getExtensions().memoryObject) |
| 3312 | { |
| 3313 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3314 | return false; |
| 3315 | } |
| 3316 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3317 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | bool ValidateMemoryObjectParameterivEXT(Context *context, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3321 | MemoryObjectID memoryObject, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3322 | GLenum pname, |
| 3323 | const GLint *params) |
| 3324 | { |
| 3325 | if (!context->getExtensions().memoryObject) |
| 3326 | { |
| 3327 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3328 | return false; |
| 3329 | } |
| 3330 | |
| 3331 | UNIMPLEMENTED(); |
| 3332 | return false; |
| 3333 | } |
| 3334 | |
| 3335 | bool ValidateTexStorageMem2DEXT(Context *context, |
| 3336 | TextureType target, |
| 3337 | GLsizei levels, |
| 3338 | GLenum internalFormat, |
| 3339 | GLsizei width, |
| 3340 | GLsizei height, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3341 | MemoryObjectID memory, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3342 | GLuint64 offset) |
| 3343 | { |
| 3344 | if (!context->getExtensions().memoryObject) |
| 3345 | { |
| 3346 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3347 | return false; |
| 3348 | } |
| 3349 | |
Michael Spang | f02a767 | 2019-04-09 18:45:23 -0400 | [diff] [blame] | 3350 | if (context->getClientMajorVersion() < 3) |
| 3351 | { |
| 3352 | return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width, |
| 3353 | height); |
| 3354 | } |
| 3355 | |
| 3356 | ASSERT(context->getClientMajorVersion() >= 3); |
| 3357 | return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height, |
| 3358 | 1); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | bool ValidateTexStorageMem3DEXT(Context *context, |
| 3362 | TextureType target, |
| 3363 | GLsizei levels, |
| 3364 | GLenum internalFormat, |
| 3365 | GLsizei width, |
| 3366 | GLsizei height, |
| 3367 | GLsizei depth, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3368 | MemoryObjectID memory, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3369 | GLuint64 offset) |
| 3370 | { |
| 3371 | if (!context->getExtensions().memoryObject) |
| 3372 | { |
| 3373 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3374 | return false; |
| 3375 | } |
| 3376 | |
| 3377 | UNIMPLEMENTED(); |
| 3378 | return false; |
| 3379 | } |
| 3380 | |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3381 | bool ValidateImportMemoryFdEXT(Context *context, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3382 | MemoryObjectID memory, |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3383 | GLuint64 size, |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3384 | HandleType handleType, |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3385 | GLint fd) |
| 3386 | { |
| 3387 | if (!context->getExtensions().memoryObjectFd) |
| 3388 | { |
| 3389 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3390 | return false; |
| 3391 | } |
| 3392 | |
Michael Spang | 3b2c6bf | 2019-04-16 17:19:50 -0400 | [diff] [blame] | 3393 | switch (handleType) |
| 3394 | { |
| 3395 | case HandleType::OpaqueFd: |
| 3396 | break; |
| 3397 | default: |
| 3398 | context->validationError(GL_INVALID_ENUM, kInvalidHandleType); |
| 3399 | return false; |
| 3400 | } |
| 3401 | |
| 3402 | return true; |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3403 | } |
| 3404 | |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3405 | bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const SemaphoreID *semaphores) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3406 | { |
| 3407 | if (!context->getExtensions().semaphore) |
| 3408 | { |
| 3409 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3410 | return false; |
| 3411 | } |
| 3412 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 3413 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3414 | } |
| 3415 | |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3416 | bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, SemaphoreID *semaphores) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3417 | { |
| 3418 | if (!context->getExtensions().semaphore) |
| 3419 | { |
| 3420 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3421 | return false; |
| 3422 | } |
| 3423 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 3424 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | bool ValidateGetSemaphoreParameterui64vEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3428 | SemaphoreID semaphore, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3429 | GLenum pname, |
| 3430 | GLuint64 *params) |
| 3431 | { |
| 3432 | if (!context->getExtensions().semaphore) |
| 3433 | { |
| 3434 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3435 | return false; |
| 3436 | } |
| 3437 | |
| 3438 | UNIMPLEMENTED(); |
| 3439 | return false; |
| 3440 | } |
| 3441 | |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3442 | bool ValidateIsSemaphoreEXT(Context *context, SemaphoreID semaphore) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3443 | { |
| 3444 | if (!context->getExtensions().semaphore) |
| 3445 | { |
| 3446 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3447 | return false; |
| 3448 | } |
| 3449 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 3450 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | bool ValidateSemaphoreParameterui64vEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3454 | SemaphoreID semaphore, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3455 | GLenum pname, |
| 3456 | const GLuint64 *params) |
| 3457 | { |
| 3458 | if (!context->getExtensions().semaphore) |
| 3459 | { |
| 3460 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3461 | return false; |
| 3462 | } |
| 3463 | |
| 3464 | UNIMPLEMENTED(); |
| 3465 | return false; |
| 3466 | } |
| 3467 | |
| 3468 | bool ValidateSignalSemaphoreEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3469 | SemaphoreID semaphore, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3470 | GLuint numBufferBarriers, |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 3471 | const BufferID *buffers, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3472 | GLuint numTextureBarriers, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 3473 | const TextureID *textures, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3474 | const GLenum *dstLayouts) |
| 3475 | { |
| 3476 | if (!context->getExtensions().semaphore) |
| 3477 | { |
| 3478 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3479 | return false; |
| 3480 | } |
| 3481 | |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 3482 | for (GLuint i = 0; i < numTextureBarriers; ++i) |
| 3483 | { |
| 3484 | if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i]))) |
| 3485 | { |
| 3486 | context->validationError(GL_INVALID_ENUM, kInvalidImageLayout); |
| 3487 | return false; |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | bool ValidateWaitSemaphoreEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3495 | SemaphoreID semaphore, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3496 | GLuint numBufferBarriers, |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 3497 | const BufferID *buffers, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3498 | GLuint numTextureBarriers, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 3499 | const TextureID *textures, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3500 | const GLenum *srcLayouts) |
| 3501 | { |
| 3502 | if (!context->getExtensions().semaphore) |
| 3503 | { |
| 3504 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3505 | return false; |
| 3506 | } |
| 3507 | |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 3508 | for (GLuint i = 0; i < numTextureBarriers; ++i) |
| 3509 | { |
| 3510 | if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i]))) |
| 3511 | { |
| 3512 | context->validationError(GL_INVALID_ENUM, kInvalidImageLayout); |
| 3513 | return false; |
| 3514 | } |
| 3515 | } |
| 3516 | |
| 3517 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3518 | } |
| 3519 | |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3520 | bool ValidateImportSemaphoreFdEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3521 | SemaphoreID semaphore, |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3522 | HandleType handleType, |
| 3523 | GLint fd) |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3524 | { |
| 3525 | if (!context->getExtensions().semaphoreFd) |
| 3526 | { |
| 3527 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3528 | return false; |
| 3529 | } |
| 3530 | |
Michael Spang | 6bb193c | 2019-05-22 16:32:21 -0400 | [diff] [blame] | 3531 | switch (handleType) |
| 3532 | { |
| 3533 | case HandleType::OpaqueFd: |
| 3534 | break; |
| 3535 | default: |
| 3536 | context->validationError(GL_INVALID_ENUM, kInvalidHandleType); |
| 3537 | return false; |
| 3538 | } |
| 3539 | |
| 3540 | return true; |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3541 | } |
| 3542 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3543 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3544 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3545 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3546 | ASSERT(buffer != nullptr); |
| 3547 | |
| 3548 | // 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] | 3549 | if (context->getState().isTransformFeedbackActive()) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3550 | { |
Shahbaz Youssefi | 8af6c6f | 2019-06-18 15:43:44 -0400 | [diff] [blame] | 3551 | TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback(); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3552 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 3553 | { |
| 3554 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 3555 | if (transformFeedbackBuffer.get() == buffer) |
| 3556 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3557 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3558 | return false; |
| 3559 | } |
| 3560 | } |
| 3561 | } |
| 3562 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3563 | if (context->getExtensions().webglCompatibility && |
| 3564 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3565 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3566 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3567 | return false; |
| 3568 | } |
| 3569 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3570 | return true; |
| 3571 | } |
| 3572 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3573 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3574 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3575 | GLintptr offset, |
| 3576 | GLsizeiptr length) |
| 3577 | { |
| 3578 | if (!context->getExtensions().mapBufferRange) |
| 3579 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3580 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3581 | return false; |
| 3582 | } |
| 3583 | |
| 3584 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 3585 | } |
| 3586 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3587 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 3588 | ShaderProgramID program, |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3589 | GLint location, |
| 3590 | const GLchar *name) |
| 3591 | { |
| 3592 | if (!context->getExtensions().bindUniformLocation) |
| 3593 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3594 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3595 | return false; |
| 3596 | } |
| 3597 | |
| 3598 | Program *programObject = GetValidProgram(context, program); |
| 3599 | if (!programObject) |
| 3600 | { |
| 3601 | return false; |
| 3602 | } |
| 3603 | |
| 3604 | if (location < 0) |
| 3605 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3606 | context->validationError(GL_INVALID_VALUE, kNegativeLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3607 | return false; |
| 3608 | } |
| 3609 | |
| 3610 | const Caps &caps = context->getCaps(); |
| 3611 | if (static_cast<size_t>(location) >= |
| 3612 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3613 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3614 | context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3615 | return false; |
| 3616 | } |
| 3617 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3618 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3619 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3620 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3621 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3622 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3623 | return false; |
| 3624 | } |
| 3625 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3626 | if (strncmp(name, "gl_", 3) == 0) |
| 3627 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3628 | context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3629 | return false; |
| 3630 | } |
| 3631 | |
| 3632 | return true; |
| 3633 | } |
| 3634 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3635 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3636 | { |
| 3637 | if (!context->getExtensions().framebufferMixedSamples) |
| 3638 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3639 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3640 | return false; |
| 3641 | } |
| 3642 | switch (components) |
| 3643 | { |
| 3644 | case GL_RGB: |
| 3645 | case GL_RGBA: |
| 3646 | case GL_ALPHA: |
| 3647 | case GL_NONE: |
| 3648 | break; |
| 3649 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3650 | context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3651 | return false; |
| 3652 | } |
| 3653 | |
| 3654 | return true; |
| 3655 | } |
| 3656 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3657 | // CHROMIUM_path_rendering |
| 3658 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3659 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3660 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3661 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3662 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3663 | return false; |
| 3664 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3665 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3666 | if (matrix == nullptr) |
| 3667 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3668 | context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3669 | return false; |
| 3670 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3671 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3672 | return true; |
| 3673 | } |
| 3674 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3675 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3676 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3677 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3678 | } |
| 3679 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3680 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3681 | { |
| 3682 | if (!context->getExtensions().pathRendering) |
| 3683 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3684 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3685 | return false; |
| 3686 | } |
| 3687 | |
| 3688 | // range = 0 is undefined in NV_path_rendering. |
| 3689 | // we add stricter semantic check here and require a non zero positive range. |
| 3690 | if (range <= 0) |
| 3691 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3692 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3693 | return false; |
| 3694 | } |
| 3695 | |
| 3696 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3697 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3698 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3699 | return false; |
| 3700 | } |
| 3701 | |
| 3702 | return true; |
| 3703 | } |
| 3704 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3705 | bool ValidateDeletePathsCHROMIUM(Context *context, PathID path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3706 | { |
| 3707 | if (!context->getExtensions().pathRendering) |
| 3708 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3709 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3710 | return false; |
| 3711 | } |
| 3712 | |
| 3713 | // range = 0 is undefined in NV_path_rendering. |
| 3714 | // we add stricter semantic check here and require a non zero positive range. |
| 3715 | if (range <= 0) |
| 3716 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3717 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3718 | return false; |
| 3719 | } |
| 3720 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3721 | angle::CheckedNumeric<std::uint32_t> checkedRange(path.value); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3722 | checkedRange += range; |
| 3723 | |
| 3724 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3725 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3726 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3727 | return false; |
| 3728 | } |
| 3729 | return true; |
| 3730 | } |
| 3731 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3732 | bool ValidatePathCommandsCHROMIUM(Context *context, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3733 | PathID path, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3734 | GLsizei numCommands, |
| 3735 | const GLubyte *commands, |
| 3736 | GLsizei numCoords, |
| 3737 | GLenum coordType, |
| 3738 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3739 | { |
| 3740 | if (!context->getExtensions().pathRendering) |
| 3741 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3742 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3743 | return false; |
| 3744 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3745 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3746 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3747 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3748 | return false; |
| 3749 | } |
| 3750 | |
| 3751 | if (numCommands < 0) |
| 3752 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3753 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3754 | return false; |
| 3755 | } |
| 3756 | else if (numCommands > 0) |
| 3757 | { |
| 3758 | if (!commands) |
| 3759 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3760 | context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3761 | return false; |
| 3762 | } |
| 3763 | } |
| 3764 | |
| 3765 | if (numCoords < 0) |
| 3766 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3767 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3768 | return false; |
| 3769 | } |
| 3770 | else if (numCoords > 0) |
| 3771 | { |
| 3772 | if (!coords) |
| 3773 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3774 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3775 | return false; |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | std::uint32_t coordTypeSize = 0; |
| 3780 | switch (coordType) |
| 3781 | { |
| 3782 | case GL_BYTE: |
| 3783 | coordTypeSize = sizeof(GLbyte); |
| 3784 | break; |
| 3785 | |
| 3786 | case GL_UNSIGNED_BYTE: |
| 3787 | coordTypeSize = sizeof(GLubyte); |
| 3788 | break; |
| 3789 | |
| 3790 | case GL_SHORT: |
| 3791 | coordTypeSize = sizeof(GLshort); |
| 3792 | break; |
| 3793 | |
| 3794 | case GL_UNSIGNED_SHORT: |
| 3795 | coordTypeSize = sizeof(GLushort); |
| 3796 | break; |
| 3797 | |
| 3798 | case GL_FLOAT: |
| 3799 | coordTypeSize = sizeof(GLfloat); |
| 3800 | break; |
| 3801 | |
| 3802 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3803 | context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3804 | return false; |
| 3805 | } |
| 3806 | |
| 3807 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3808 | checkedSize += (coordTypeSize * numCoords); |
| 3809 | if (!checkedSize.IsValid()) |
| 3810 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3811 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3812 | return false; |
| 3813 | } |
| 3814 | |
| 3815 | // early return skips command data validation when it doesn't exist. |
| 3816 | if (!commands) |
| 3817 | return true; |
| 3818 | |
| 3819 | GLsizei expectedNumCoords = 0; |
| 3820 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3821 | { |
| 3822 | switch (commands[i]) |
| 3823 | { |
| 3824 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3825 | break; |
| 3826 | case GL_MOVE_TO_CHROMIUM: |
| 3827 | case GL_LINE_TO_CHROMIUM: |
| 3828 | expectedNumCoords += 2; |
| 3829 | break; |
| 3830 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3831 | expectedNumCoords += 4; |
| 3832 | break; |
| 3833 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3834 | expectedNumCoords += 6; |
| 3835 | break; |
| 3836 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3837 | expectedNumCoords += 5; |
| 3838 | break; |
| 3839 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3840 | context->validationError(GL_INVALID_ENUM, kInvalidPathCommand); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3841 | return false; |
| 3842 | } |
| 3843 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3844 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3845 | if (expectedNumCoords != numCoords) |
| 3846 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3847 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3848 | return false; |
| 3849 | } |
| 3850 | |
| 3851 | return true; |
| 3852 | } |
| 3853 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3854 | bool ValidatePathParameterfCHROMIUM(Context *context, PathID path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3855 | { |
| 3856 | if (!context->getExtensions().pathRendering) |
| 3857 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3858 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3859 | return false; |
| 3860 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3861 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3862 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3863 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3864 | return false; |
| 3865 | } |
| 3866 | |
| 3867 | switch (pname) |
| 3868 | { |
| 3869 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3870 | if (value < 0.0f) |
| 3871 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3872 | context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3873 | return false; |
| 3874 | } |
| 3875 | break; |
| 3876 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3877 | switch (static_cast<GLenum>(value)) |
| 3878 | { |
| 3879 | case GL_FLAT_CHROMIUM: |
| 3880 | case GL_SQUARE_CHROMIUM: |
| 3881 | case GL_ROUND_CHROMIUM: |
| 3882 | break; |
| 3883 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3884 | context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3885 | return false; |
| 3886 | } |
| 3887 | break; |
| 3888 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3889 | switch (static_cast<GLenum>(value)) |
| 3890 | { |
| 3891 | case GL_MITER_REVERT_CHROMIUM: |
| 3892 | case GL_BEVEL_CHROMIUM: |
| 3893 | case GL_ROUND_CHROMIUM: |
| 3894 | break; |
| 3895 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3896 | context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3897 | return false; |
| 3898 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3899 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3900 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3901 | if (value < 0.0f) |
| 3902 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3903 | context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3904 | return false; |
| 3905 | } |
| 3906 | break; |
| 3907 | |
| 3908 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3909 | // no errors, only clamping. |
| 3910 | break; |
| 3911 | |
| 3912 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3913 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3914 | return false; |
| 3915 | } |
| 3916 | return true; |
| 3917 | } |
| 3918 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3919 | bool ValidatePathParameteriCHROMIUM(Context *context, PathID path, GLenum pname, GLint value) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3920 | { |
| 3921 | // TODO(jmadill): Use proper clamping cast. |
| 3922 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 3923 | } |
| 3924 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3925 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, PathID path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3926 | { |
| 3927 | if (!context->getExtensions().pathRendering) |
| 3928 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3929 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3930 | return false; |
| 3931 | } |
| 3932 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3933 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3934 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3935 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3936 | return false; |
| 3937 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3938 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3939 | if (!value) |
| 3940 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3941 | context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3942 | return false; |
| 3943 | } |
| 3944 | |
| 3945 | switch (pname) |
| 3946 | { |
| 3947 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3948 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3949 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3950 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3951 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3952 | break; |
| 3953 | |
| 3954 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3955 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3956 | return false; |
| 3957 | } |
| 3958 | |
| 3959 | return true; |
| 3960 | } |
| 3961 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3962 | bool ValidateGetPathParameterivCHROMIUM(Context *context, PathID path, GLenum pname, GLint *value) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3963 | { |
| 3964 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 3965 | reinterpret_cast<GLfloat *>(value)); |
| 3966 | } |
| 3967 | |
| 3968 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3969 | { |
| 3970 | if (!context->getExtensions().pathRendering) |
| 3971 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3972 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3973 | return false; |
| 3974 | } |
| 3975 | |
| 3976 | switch (func) |
| 3977 | { |
| 3978 | case GL_NEVER: |
| 3979 | case GL_ALWAYS: |
| 3980 | case GL_LESS: |
| 3981 | case GL_LEQUAL: |
| 3982 | case GL_EQUAL: |
| 3983 | case GL_GEQUAL: |
| 3984 | case GL_GREATER: |
| 3985 | case GL_NOTEQUAL: |
| 3986 | break; |
| 3987 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3988 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3989 | return false; |
| 3990 | } |
| 3991 | |
| 3992 | return true; |
| 3993 | } |
| 3994 | |
| 3995 | // Note that the spec specifies that for the path drawing commands |
| 3996 | // if the path object is not an existing path object the command |
| 3997 | // does nothing and no error is generated. |
| 3998 | // However if the path object exists but has not been specified any |
| 3999 | // commands then an error is generated. |
| 4000 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4001 | bool ValidateStencilFillPathCHROMIUM(Context *context, PathID path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4002 | { |
| 4003 | if (!context->getExtensions().pathRendering) |
| 4004 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4005 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4006 | return false; |
| 4007 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 4008 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4009 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4010 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4011 | return false; |
| 4012 | } |
| 4013 | |
| 4014 | switch (fillMode) |
| 4015 | { |
Chris Dalton | a9dfb3b | 2019-06-26 18:36:10 -0600 | [diff] [blame] | 4016 | case GL_INVERT: |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4017 | case GL_COUNT_UP_CHROMIUM: |
| 4018 | case GL_COUNT_DOWN_CHROMIUM: |
| 4019 | break; |
| 4020 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4021 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4022 | return false; |
| 4023 | } |
| 4024 | |
| 4025 | if (!isPow2(mask + 1)) |
| 4026 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4027 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4028 | return false; |
| 4029 | } |
| 4030 | |
| 4031 | return true; |
| 4032 | } |
| 4033 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4034 | bool ValidateStencilStrokePathCHROMIUM(Context *context, PathID path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4035 | { |
| 4036 | if (!context->getExtensions().pathRendering) |
| 4037 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4038 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4039 | return false; |
| 4040 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4041 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 4042 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4043 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4044 | context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4045 | return false; |
| 4046 | } |
| 4047 | |
| 4048 | return true; |
| 4049 | } |
| 4050 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4051 | bool ValidateCoverPathCHROMIUM(Context *context, PathID path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4052 | { |
| 4053 | if (!context->getExtensions().pathRendering) |
| 4054 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4055 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4056 | return false; |
| 4057 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 4058 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4059 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4060 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4061 | return false; |
| 4062 | } |
| 4063 | |
| 4064 | switch (coverMode) |
| 4065 | { |
| 4066 | case GL_CONVEX_HULL_CHROMIUM: |
| 4067 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4068 | break; |
| 4069 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4070 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4071 | return false; |
| 4072 | } |
| 4073 | return true; |
| 4074 | } |
| 4075 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4076 | bool ValidateCoverFillPathCHROMIUM(Context *context, PathID path, GLenum coverMode) |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4077 | { |
| 4078 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 4079 | } |
| 4080 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4081 | bool ValidateCoverStrokePathCHROMIUM(Context *context, PathID path, GLenum coverMode) |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4082 | { |
| 4083 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 4084 | } |
| 4085 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4086 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4087 | PathID path, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4088 | GLenum fillMode, |
| 4089 | GLuint mask, |
| 4090 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4091 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4092 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 4093 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4094 | } |
| 4095 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4096 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4097 | PathID path, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4098 | GLint reference, |
| 4099 | GLuint mask, |
| 4100 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4101 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4102 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 4103 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4104 | } |
| 4105 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4106 | bool ValidateIsPathCHROMIUM(Context *context, PathID path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4107 | { |
| 4108 | if (!context->getExtensions().pathRendering) |
| 4109 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4110 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4111 | return false; |
| 4112 | } |
| 4113 | return true; |
| 4114 | } |
| 4115 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4116 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 4117 | GLsizei numPaths, |
| 4118 | GLenum pathNameType, |
| 4119 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4120 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4121 | GLenum coverMode, |
| 4122 | GLenum transformType, |
| 4123 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4124 | { |
| 4125 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4126 | transformType, transformValues)) |
| 4127 | return false; |
| 4128 | |
| 4129 | switch (coverMode) |
| 4130 | { |
| 4131 | case GL_CONVEX_HULL_CHROMIUM: |
| 4132 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4133 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4134 | break; |
| 4135 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4136 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4137 | return false; |
| 4138 | } |
| 4139 | |
| 4140 | return true; |
| 4141 | } |
| 4142 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4143 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 4144 | GLsizei numPaths, |
| 4145 | GLenum pathNameType, |
| 4146 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4147 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4148 | GLenum coverMode, |
| 4149 | GLenum transformType, |
| 4150 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4151 | { |
| 4152 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4153 | transformType, transformValues)) |
| 4154 | return false; |
| 4155 | |
| 4156 | switch (coverMode) |
| 4157 | { |
| 4158 | case GL_CONVEX_HULL_CHROMIUM: |
| 4159 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4160 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4161 | break; |
| 4162 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4163 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4164 | return false; |
| 4165 | } |
| 4166 | |
| 4167 | return true; |
| 4168 | } |
| 4169 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4170 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 4171 | GLsizei numPaths, |
| 4172 | GLenum pathNameType, |
| 4173 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4174 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4175 | GLenum fillMode, |
| 4176 | GLuint mask, |
| 4177 | GLenum transformType, |
| 4178 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4179 | { |
| 4180 | |
| 4181 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4182 | transformType, transformValues)) |
| 4183 | return false; |
| 4184 | |
| 4185 | switch (fillMode) |
| 4186 | { |
Chris Dalton | a9dfb3b | 2019-06-26 18:36:10 -0600 | [diff] [blame] | 4187 | case GL_INVERT: |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4188 | case GL_COUNT_UP_CHROMIUM: |
| 4189 | case GL_COUNT_DOWN_CHROMIUM: |
| 4190 | break; |
| 4191 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4192 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4193 | return false; |
| 4194 | } |
| 4195 | if (!isPow2(mask + 1)) |
| 4196 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4197 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4198 | return false; |
| 4199 | } |
| 4200 | return true; |
| 4201 | } |
| 4202 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4203 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 4204 | GLsizei numPaths, |
| 4205 | GLenum pathNameType, |
| 4206 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4207 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4208 | GLint reference, |
| 4209 | GLuint mask, |
| 4210 | GLenum transformType, |
| 4211 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4212 | { |
| 4213 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4214 | transformType, transformValues)) |
| 4215 | return false; |
| 4216 | |
| 4217 | // no more validation here. |
| 4218 | |
| 4219 | return true; |
| 4220 | } |
| 4221 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4222 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 4223 | GLsizei numPaths, |
| 4224 | GLenum pathNameType, |
| 4225 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4226 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4227 | GLenum fillMode, |
| 4228 | GLuint mask, |
| 4229 | GLenum coverMode, |
| 4230 | GLenum transformType, |
| 4231 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4232 | { |
| 4233 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4234 | transformType, transformValues)) |
| 4235 | return false; |
| 4236 | |
| 4237 | switch (coverMode) |
| 4238 | { |
| 4239 | case GL_CONVEX_HULL_CHROMIUM: |
| 4240 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4241 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4242 | break; |
| 4243 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4244 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4245 | return false; |
| 4246 | } |
| 4247 | |
| 4248 | switch (fillMode) |
| 4249 | { |
Chris Dalton | a9dfb3b | 2019-06-26 18:36:10 -0600 | [diff] [blame] | 4250 | case GL_INVERT: |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4251 | case GL_COUNT_UP_CHROMIUM: |
| 4252 | case GL_COUNT_DOWN_CHROMIUM: |
| 4253 | break; |
| 4254 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4255 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4256 | return false; |
| 4257 | } |
| 4258 | if (!isPow2(mask + 1)) |
| 4259 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4260 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4261 | return false; |
| 4262 | } |
| 4263 | |
| 4264 | return true; |
| 4265 | } |
| 4266 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4267 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 4268 | GLsizei numPaths, |
| 4269 | GLenum pathNameType, |
| 4270 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4271 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4272 | GLint reference, |
| 4273 | GLuint mask, |
| 4274 | GLenum coverMode, |
| 4275 | GLenum transformType, |
| 4276 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4277 | { |
| 4278 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4279 | transformType, transformValues)) |
| 4280 | return false; |
| 4281 | |
| 4282 | switch (coverMode) |
| 4283 | { |
| 4284 | case GL_CONVEX_HULL_CHROMIUM: |
| 4285 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4286 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4287 | break; |
| 4288 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4289 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4290 | return false; |
| 4291 | } |
| 4292 | |
| 4293 | return true; |
| 4294 | } |
| 4295 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4296 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 4297 | ShaderProgramID program, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4298 | GLint location, |
| 4299 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4300 | { |
| 4301 | if (!context->getExtensions().pathRendering) |
| 4302 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4303 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4304 | return false; |
| 4305 | } |
| 4306 | |
| 4307 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 4308 | if (location >= MaxLocation) |
| 4309 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4310 | context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4311 | return false; |
| 4312 | } |
| 4313 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4314 | const auto *programObject = context->getProgramNoResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4315 | if (!programObject) |
| 4316 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4317 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4318 | return false; |
| 4319 | } |
| 4320 | |
| 4321 | if (!name) |
| 4322 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4323 | context->validationError(GL_INVALID_VALUE, kMissingName); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4324 | return false; |
| 4325 | } |
| 4326 | |
| 4327 | if (angle::BeginsWith(name, "gl_")) |
| 4328 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4329 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4330 | return false; |
| 4331 | } |
| 4332 | |
| 4333 | return true; |
| 4334 | } |
| 4335 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4336 | bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 4337 | ShaderProgramID program, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4338 | GLint location, |
| 4339 | GLenum genMode, |
| 4340 | GLint components, |
| 4341 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4342 | { |
| 4343 | if (!context->getExtensions().pathRendering) |
| 4344 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4345 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4346 | return false; |
| 4347 | } |
| 4348 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4349 | const auto *programObject = context->getProgramResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4350 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 4351 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4352 | context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4353 | return false; |
| 4354 | } |
| 4355 | |
| 4356 | if (!programObject->isLinked()) |
| 4357 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4358 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4359 | return false; |
| 4360 | } |
| 4361 | |
| 4362 | switch (genMode) |
| 4363 | { |
| 4364 | case GL_NONE: |
| 4365 | if (components != 0) |
| 4366 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4367 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4368 | return false; |
| 4369 | } |
| 4370 | break; |
| 4371 | |
| 4372 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 4373 | case GL_EYE_LINEAR_CHROMIUM: |
| 4374 | case GL_CONSTANT_CHROMIUM: |
| 4375 | if (components < 1 || components > 4) |
| 4376 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4377 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4378 | return false; |
| 4379 | } |
| 4380 | if (!coeffs) |
| 4381 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4382 | context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4383 | return false; |
| 4384 | } |
| 4385 | break; |
| 4386 | |
| 4387 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4388 | context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4389 | return false; |
| 4390 | } |
| 4391 | |
| 4392 | // If the location is -1 then the command is silently ignored |
| 4393 | // and no further validation is needed. |
| 4394 | if (location == -1) |
| 4395 | return true; |
| 4396 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 4397 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4398 | |
| 4399 | if (!binding.valid) |
| 4400 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4401 | context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4402 | return false; |
| 4403 | } |
| 4404 | |
| 4405 | if (binding.type != GL_NONE) |
| 4406 | { |
| 4407 | GLint expectedComponents = 0; |
| 4408 | switch (binding.type) |
| 4409 | { |
| 4410 | case GL_FLOAT: |
| 4411 | expectedComponents = 1; |
| 4412 | break; |
| 4413 | case GL_FLOAT_VEC2: |
| 4414 | expectedComponents = 2; |
| 4415 | break; |
| 4416 | case GL_FLOAT_VEC3: |
| 4417 | expectedComponents = 3; |
| 4418 | break; |
| 4419 | case GL_FLOAT_VEC4: |
| 4420 | expectedComponents = 4; |
| 4421 | break; |
| 4422 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4423 | context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4424 | return false; |
| 4425 | } |
| 4426 | if (expectedComponents != components && genMode != GL_NONE) |
| 4427 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4428 | context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4429 | return false; |
| 4430 | } |
| 4431 | } |
| 4432 | return true; |
| 4433 | } |
| 4434 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4435 | bool ValidateCopyTextureCHROMIUM(Context *context, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4436 | TextureID sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4437 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4438 | TextureTarget destTarget, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4439 | TextureID destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4440 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4441 | GLint internalFormat, |
| 4442 | GLenum destType, |
| 4443 | GLboolean unpackFlipY, |
| 4444 | GLboolean unpackPremultiplyAlpha, |
| 4445 | GLboolean unpackUnmultiplyAlpha) |
| 4446 | { |
| 4447 | if (!context->getExtensions().copyTexture) |
| 4448 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4449 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4450 | return false; |
| 4451 | } |
| 4452 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4453 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4454 | if (source == nullptr) |
| 4455 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4456 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4457 | return false; |
| 4458 | } |
| 4459 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4460 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4461 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4462 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
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 | TextureType sourceType = source->getType(); |
| 4467 | ASSERT(sourceType != TextureType::CubeMap); |
| 4468 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4469 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4470 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4471 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4472 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4473 | return false; |
| 4474 | } |
| 4475 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4476 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 4477 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 4478 | if (sourceWidth == 0 || sourceHeight == 0) |
| 4479 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4480 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4481 | return false; |
| 4482 | } |
| 4483 | |
| 4484 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 4485 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4486 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4487 | context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4488 | return false; |
| 4489 | } |
| 4490 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4491 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4492 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4493 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4494 | return false; |
| 4495 | } |
| 4496 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4497 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4498 | if (dest == nullptr) |
| 4499 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4500 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4501 | return false; |
| 4502 | } |
| 4503 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4504 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4505 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4506 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4507 | return false; |
| 4508 | } |
| 4509 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4510 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4511 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4512 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4513 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4514 | return false; |
| 4515 | } |
| 4516 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4517 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 4518 | { |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4519 | return false; |
| 4520 | } |
| 4521 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4522 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4523 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4524 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4525 | return false; |
| 4526 | } |
| 4527 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4528 | if (dest->getImmutableFormat()) |
| 4529 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4530 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4531 | return false; |
| 4532 | } |
| 4533 | |
| 4534 | return true; |
| 4535 | } |
| 4536 | |
| 4537 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4538 | TextureID sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4539 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4540 | TextureTarget destTarget, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4541 | TextureID destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4542 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4543 | GLint xoffset, |
| 4544 | GLint yoffset, |
| 4545 | GLint x, |
| 4546 | GLint y, |
| 4547 | GLsizei width, |
| 4548 | GLsizei height, |
| 4549 | GLboolean unpackFlipY, |
| 4550 | GLboolean unpackPremultiplyAlpha, |
| 4551 | GLboolean unpackUnmultiplyAlpha) |
| 4552 | { |
| 4553 | if (!context->getExtensions().copyTexture) |
| 4554 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4555 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4556 | return false; |
| 4557 | } |
| 4558 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4559 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4560 | if (source == nullptr) |
| 4561 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4562 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4563 | return false; |
| 4564 | } |
| 4565 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4566 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4567 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4568 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4569 | return false; |
| 4570 | } |
| 4571 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4572 | TextureType sourceType = source->getType(); |
| 4573 | ASSERT(sourceType != TextureType::CubeMap); |
| 4574 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4575 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4576 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4577 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4578 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4579 | return false; |
| 4580 | } |
| 4581 | |
| 4582 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4583 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4584 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4585 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4586 | return false; |
| 4587 | } |
| 4588 | |
| 4589 | if (x < 0 || y < 0) |
| 4590 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4591 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4592 | return false; |
| 4593 | } |
| 4594 | |
| 4595 | if (width < 0 || height < 0) |
| 4596 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4597 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4598 | return false; |
| 4599 | } |
| 4600 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4601 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4602 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4603 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4604 | context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4605 | return false; |
| 4606 | } |
| 4607 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4608 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4609 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4610 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4611 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4612 | return false; |
| 4613 | } |
| 4614 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4615 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4616 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4617 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4618 | return false; |
| 4619 | } |
| 4620 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4621 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4622 | if (dest == nullptr) |
| 4623 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4624 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4625 | return false; |
| 4626 | } |
| 4627 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4628 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4629 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4630 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4631 | return false; |
| 4632 | } |
| 4633 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4634 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4635 | true)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4636 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4637 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4638 | return false; |
| 4639 | } |
| 4640 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4641 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4642 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4643 | context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4644 | return false; |
| 4645 | } |
| 4646 | |
| 4647 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4648 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4649 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4650 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4651 | return false; |
| 4652 | } |
| 4653 | |
| 4654 | if (xoffset < 0 || yoffset < 0) |
| 4655 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4656 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4657 | return false; |
| 4658 | } |
| 4659 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4660 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4661 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4662 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4663 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4664 | return false; |
| 4665 | } |
| 4666 | |
| 4667 | return true; |
| 4668 | } |
| 4669 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4670 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, TextureID sourceId, TextureID destId) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4671 | { |
| 4672 | if (!context->getExtensions().copyCompressedTexture) |
| 4673 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4674 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4675 | return false; |
| 4676 | } |
| 4677 | |
| 4678 | const gl::Texture *source = context->getTexture(sourceId); |
| 4679 | if (source == nullptr) |
| 4680 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4681 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4682 | return false; |
| 4683 | } |
| 4684 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4685 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4686 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4687 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4688 | return false; |
| 4689 | } |
| 4690 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4691 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4692 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4693 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4694 | context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4695 | return false; |
| 4696 | } |
| 4697 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4698 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4699 | if (!sourceFormat.info->compressed) |
| 4700 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4701 | context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4702 | return false; |
| 4703 | } |
| 4704 | |
| 4705 | const gl::Texture *dest = context->getTexture(destId); |
| 4706 | if (dest == nullptr) |
| 4707 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4708 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4709 | return false; |
| 4710 | } |
| 4711 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4712 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4713 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4714 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4715 | return false; |
| 4716 | } |
| 4717 | |
| 4718 | if (dest->getImmutableFormat()) |
| 4719 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4720 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4721 | return false; |
| 4722 | } |
| 4723 | |
| 4724 | return true; |
| 4725 | } |
| 4726 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4727 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4728 | { |
| 4729 | switch (type) |
| 4730 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4731 | case ShaderType::Vertex: |
| 4732 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4733 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4734 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4735 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4736 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4737 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4738 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4739 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4740 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4741 | break; |
| 4742 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4743 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4744 | if (!context->getExtensions().geometryShader) |
| 4745 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4746 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4747 | return false; |
| 4748 | } |
| 4749 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4750 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4751 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4752 | return false; |
| 4753 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4754 | |
| 4755 | return true; |
| 4756 | } |
| 4757 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4758 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4759 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4760 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4761 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4762 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4763 | { |
| 4764 | if (size < 0) |
| 4765 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4766 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4767 | return false; |
| 4768 | } |
| 4769 | |
| 4770 | switch (usage) |
| 4771 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4772 | case BufferUsage::StreamDraw: |
| 4773 | case BufferUsage::StaticDraw: |
| 4774 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4775 | break; |
| 4776 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4777 | case BufferUsage::StreamRead: |
| 4778 | case BufferUsage::StaticRead: |
| 4779 | case BufferUsage::DynamicRead: |
| 4780 | case BufferUsage::StreamCopy: |
| 4781 | case BufferUsage::StaticCopy: |
| 4782 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4783 | if (context->getClientMajorVersion() < 3) |
| 4784 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4785 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4786 | return false; |
| 4787 | } |
| 4788 | break; |
| 4789 | |
| 4790 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4791 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4792 | return false; |
| 4793 | } |
| 4794 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4795 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4796 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4797 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4798 | return false; |
| 4799 | } |
| 4800 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4801 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4802 | |
| 4803 | if (!buffer) |
| 4804 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4805 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4806 | return false; |
| 4807 | } |
| 4808 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4809 | if (context->getExtensions().webglCompatibility && |
| 4810 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4811 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4812 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4813 | return false; |
| 4814 | } |
| 4815 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4816 | return true; |
| 4817 | } |
| 4818 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4819 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4820 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4821 | GLintptr offset, |
| 4822 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4823 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4824 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4825 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4826 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4827 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4828 | return false; |
| 4829 | } |
| 4830 | |
| 4831 | if (offset < 0) |
| 4832 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4833 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4834 | return false; |
| 4835 | } |
| 4836 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4837 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4838 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4839 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4840 | return false; |
| 4841 | } |
| 4842 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4843 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4844 | |
| 4845 | if (!buffer) |
| 4846 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4847 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4848 | return false; |
| 4849 | } |
| 4850 | |
| 4851 | if (buffer->isMapped()) |
| 4852 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4853 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4854 | return false; |
| 4855 | } |
| 4856 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4857 | if (context->getExtensions().webglCompatibility && |
| 4858 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4859 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4860 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4861 | return false; |
| 4862 | } |
| 4863 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4864 | // Check for possible overflow of size + offset |
| 4865 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4866 | checkedSize += offset; |
| 4867 | if (!checkedSize.IsValid()) |
| 4868 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4869 | context->validationError(GL_INVALID_VALUE, kParamOverflow); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4870 | return false; |
| 4871 | } |
| 4872 | |
| 4873 | if (size + offset > buffer->getSize()) |
| 4874 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4875 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4876 | return false; |
| 4877 | } |
| 4878 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4879 | return true; |
| 4880 | } |
| 4881 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4882 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4883 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4884 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4885 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4886 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4887 | return false; |
| 4888 | } |
| 4889 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4890 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4891 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4892 | context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4893 | return false; |
| 4894 | } |
| 4895 | |
| 4896 | return true; |
| 4897 | } |
| 4898 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4899 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4900 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4901 | if (context->getClientMajorVersion() < 2) |
| 4902 | { |
| 4903 | return ValidateMultitextureUnit(context, texture); |
| 4904 | } |
| 4905 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4906 | if (texture < GL_TEXTURE0 || |
| 4907 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4908 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4909 | context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4910 | return false; |
| 4911 | } |
| 4912 | |
| 4913 | return true; |
| 4914 | } |
| 4915 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 4916 | bool ValidateAttachShader(Context *context, ShaderProgramID program, ShaderProgramID shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4917 | { |
| 4918 | Program *programObject = GetValidProgram(context, program); |
| 4919 | if (!programObject) |
| 4920 | { |
| 4921 | return false; |
| 4922 | } |
| 4923 | |
| 4924 | Shader *shaderObject = GetValidShader(context, shader); |
| 4925 | if (!shaderObject) |
| 4926 | { |
| 4927 | return false; |
| 4928 | } |
| 4929 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4930 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4931 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4932 | context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4933 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | return true; |
| 4937 | } |
| 4938 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 4939 | bool ValidateBindAttribLocation(Context *context, |
| 4940 | ShaderProgramID program, |
| 4941 | GLuint index, |
| 4942 | const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4943 | { |
| 4944 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4945 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4946 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4947 | return false; |
| 4948 | } |
| 4949 | |
| 4950 | if (strncmp(name, "gl_", 3) == 0) |
| 4951 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4952 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4953 | return false; |
| 4954 | } |
| 4955 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4956 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4957 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4958 | const size_t length = strlen(name); |
| 4959 | |
| 4960 | if (!IsValidESSLString(name, length)) |
| 4961 | { |
| 4962 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 4963 | // for shader-related entry points |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4964 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4965 | return false; |
| 4966 | } |
| 4967 | |
| 4968 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 4969 | { |
| 4970 | return false; |
| 4971 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4972 | } |
| 4973 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4974 | return GetValidProgram(context, program) != nullptr; |
| 4975 | } |
| 4976 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 4977 | bool ValidateBindFramebuffer(Context *context, GLenum target, FramebufferID framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4978 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4979 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4980 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4981 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4982 | return false; |
| 4983 | } |
| 4984 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4985 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4986 | !context->isFramebufferGenerated(framebuffer)) |
| 4987 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4988 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4989 | return false; |
| 4990 | } |
| 4991 | |
| 4992 | return true; |
| 4993 | } |
| 4994 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 4995 | bool ValidateBindRenderbuffer(Context *context, GLenum target, RenderbufferID renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4996 | { |
| 4997 | if (target != GL_RENDERBUFFER) |
| 4998 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4999 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5000 | return false; |
| 5001 | } |
| 5002 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 5003 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5004 | !context->isRenderbufferGenerated(renderbuffer)) |
| 5005 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5006 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5007 | return false; |
| 5008 | } |
| 5009 | |
| 5010 | return true; |
| 5011 | } |
| 5012 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5013 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5014 | { |
| 5015 | switch (mode) |
| 5016 | { |
| 5017 | case GL_FUNC_ADD: |
| 5018 | case GL_FUNC_SUBTRACT: |
| 5019 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5020 | return true; |
| 5021 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5022 | case GL_MIN: |
| 5023 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5024 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5025 | |
| 5026 | default: |
| 5027 | return false; |
| 5028 | } |
| 5029 | } |
| 5030 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5031 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5032 | { |
| 5033 | return true; |
| 5034 | } |
| 5035 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5036 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5037 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5038 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5039 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5040 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5041 | return false; |
| 5042 | } |
| 5043 | |
| 5044 | return true; |
| 5045 | } |
| 5046 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5047 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5048 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5049 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5050 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5051 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5052 | return false; |
| 5053 | } |
| 5054 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5055 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5056 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5057 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5058 | return false; |
| 5059 | } |
| 5060 | |
| 5061 | return true; |
| 5062 | } |
| 5063 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5064 | bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5065 | { |
| 5066 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 5067 | } |
| 5068 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5069 | bool ValidateBlendFuncSeparate(Context *context, |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5070 | GLenum srcRGB, |
| 5071 | GLenum dstRGB, |
| 5072 | GLenum srcAlpha, |
| 5073 | GLenum dstAlpha) |
| 5074 | { |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5075 | if (!ValidSrcBlendFunc(context, srcRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5076 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5077 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5078 | return false; |
| 5079 | } |
| 5080 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5081 | if (!ValidDstBlendFunc(context, dstRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5082 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5083 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5084 | return false; |
| 5085 | } |
| 5086 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5087 | if (!ValidSrcBlendFunc(context, srcAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5088 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5089 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5090 | return false; |
| 5091 | } |
| 5092 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5093 | if (!ValidDstBlendFunc(context, dstAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5094 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5095 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5096 | return false; |
| 5097 | } |
| 5098 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 5099 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 5100 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5101 | { |
| 5102 | bool constantColorUsed = |
| 5103 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 5104 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 5105 | |
| 5106 | bool constantAlphaUsed = |
| 5107 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 5108 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 5109 | |
| 5110 | if (constantColorUsed && constantAlphaUsed) |
| 5111 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 5112 | if (context->getExtensions().webglCompatibility) |
| 5113 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5114 | context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor); |
| 5115 | return false; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 5116 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5117 | |
| 5118 | WARN() << kConstantColorAlphaLimitation; |
| 5119 | context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5120 | return false; |
| 5121 | } |
| 5122 | } |
| 5123 | |
| 5124 | return true; |
| 5125 | } |
| 5126 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 5127 | bool ValidateGetString(Context *context, GLenum name) |
| 5128 | { |
| 5129 | switch (name) |
| 5130 | { |
| 5131 | case GL_VENDOR: |
| 5132 | case GL_RENDERER: |
| 5133 | case GL_VERSION: |
| 5134 | case GL_SHADING_LANGUAGE_VERSION: |
| 5135 | case GL_EXTENSIONS: |
| 5136 | break; |
| 5137 | |
| 5138 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 5139 | if (!context->getExtensions().requestExtension) |
| 5140 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5141 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 5142 | return false; |
| 5143 | } |
| 5144 | break; |
| 5145 | |
| 5146 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5147 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 5148 | return false; |
| 5149 | } |
| 5150 | |
| 5151 | return true; |
| 5152 | } |
| 5153 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5154 | bool ValidateLineWidth(Context *context, GLfloat width) |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 5155 | { |
| 5156 | if (width <= 0.0f || isNaN(width)) |
| 5157 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5158 | context->validationError(GL_INVALID_VALUE, kInvalidWidth); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 5159 | return false; |
| 5160 | } |
| 5161 | |
| 5162 | return true; |
| 5163 | } |
| 5164 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5165 | bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 5166 | { |
| 5167 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 5168 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5169 | context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 5170 | return false; |
| 5171 | } |
| 5172 | |
| 5173 | return true; |
| 5174 | } |
| 5175 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5176 | bool ValidateRenderbufferStorage(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5177 | GLenum target, |
| 5178 | GLenum internalformat, |
| 5179 | GLsizei width, |
| 5180 | GLsizei height) |
| 5181 | { |
| 5182 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 5183 | height); |
| 5184 | } |
| 5185 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5186 | bool ValidateRenderbufferStorageMultisampleANGLE(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5187 | GLenum target, |
| 5188 | GLsizei samples, |
| 5189 | GLenum internalformat, |
| 5190 | GLsizei width, |
| 5191 | GLsizei height) |
| 5192 | { |
| 5193 | if (!context->getExtensions().framebufferMultisample) |
| 5194 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5195 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5196 | return false; |
| 5197 | } |
| 5198 | |
| 5199 | // 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] | 5200 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5201 | // generated. |
| 5202 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 5203 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5204 | context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5205 | return false; |
| 5206 | } |
| 5207 | |
| 5208 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 5209 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 5210 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 5211 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 5212 | if (context->getClientMajorVersion() >= 3) |
| 5213 | { |
| 5214 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 5215 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 5216 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5217 | context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5218 | return false; |
| 5219 | } |
| 5220 | } |
| 5221 | |
| 5222 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 5223 | width, height); |
| 5224 | } |
| 5225 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5226 | bool ValidateCheckFramebufferStatus(Context *context, GLenum target) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5227 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5228 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5229 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5230 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5231 | return false; |
| 5232 | } |
| 5233 | |
| 5234 | return true; |
| 5235 | } |
| 5236 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5237 | bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5238 | { |
| 5239 | return true; |
| 5240 | } |
| 5241 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5242 | bool ValidateClearDepthf(Context *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5243 | { |
| 5244 | return true; |
| 5245 | } |
| 5246 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5247 | bool ValidateClearStencil(Context *context, GLint s) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5248 | { |
| 5249 | return true; |
| 5250 | } |
| 5251 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5252 | bool ValidateColorMask(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5253 | GLboolean red, |
| 5254 | GLboolean green, |
| 5255 | GLboolean blue, |
| 5256 | GLboolean alpha) |
| 5257 | { |
| 5258 | return true; |
| 5259 | } |
| 5260 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5261 | bool ValidateCompileShader(Context *context, ShaderProgramID shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5262 | { |
| 5263 | return true; |
| 5264 | } |
| 5265 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5266 | bool ValidateCreateProgram(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5267 | { |
| 5268 | return true; |
| 5269 | } |
| 5270 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5271 | bool ValidateCullFace(Context *context, CullFaceMode mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5272 | { |
| 5273 | switch (mode) |
| 5274 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 5275 | case CullFaceMode::Front: |
| 5276 | case CullFaceMode::Back: |
| 5277 | case CullFaceMode::FrontAndBack: |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5278 | break; |
| 5279 | |
| 5280 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5281 | context->validationError(GL_INVALID_ENUM, kInvalidCullMode); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5282 | return false; |
| 5283 | } |
| 5284 | |
| 5285 | return true; |
| 5286 | } |
| 5287 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5288 | bool ValidateDeleteProgram(Context *context, ShaderProgramID program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5289 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5290 | if (program.value == 0) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5291 | { |
| 5292 | return false; |
| 5293 | } |
| 5294 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5295 | if (!context->getProgramResolveLink(program)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5296 | { |
| 5297 | if (context->getShader(program)) |
| 5298 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5299 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5300 | return false; |
| 5301 | } |
| 5302 | else |
| 5303 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5304 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5305 | return false; |
| 5306 | } |
| 5307 | } |
| 5308 | |
| 5309 | return true; |
| 5310 | } |
| 5311 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5312 | bool ValidateDeleteShader(Context *context, ShaderProgramID shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5313 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5314 | if (shader.value == 0) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5315 | { |
| 5316 | return false; |
| 5317 | } |
| 5318 | |
| 5319 | if (!context->getShader(shader)) |
| 5320 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5321 | if (context->getProgramResolveLink(shader)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5322 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5323 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5324 | return false; |
| 5325 | } |
| 5326 | else |
| 5327 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5328 | context->validationError(GL_INVALID_VALUE, kExpectedShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5329 | return false; |
| 5330 | } |
| 5331 | } |
| 5332 | |
| 5333 | return true; |
| 5334 | } |
| 5335 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5336 | bool ValidateDepthFunc(Context *context, GLenum func) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5337 | { |
| 5338 | switch (func) |
| 5339 | { |
| 5340 | case GL_NEVER: |
| 5341 | case GL_ALWAYS: |
| 5342 | case GL_LESS: |
| 5343 | case GL_LEQUAL: |
| 5344 | case GL_EQUAL: |
| 5345 | case GL_GREATER: |
| 5346 | case GL_GEQUAL: |
| 5347 | case GL_NOTEQUAL: |
| 5348 | break; |
| 5349 | |
| 5350 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5351 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5352 | return false; |
| 5353 | } |
| 5354 | |
| 5355 | return true; |
| 5356 | } |
| 5357 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5358 | bool ValidateDepthMask(Context *context, GLboolean flag) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5359 | { |
| 5360 | return true; |
| 5361 | } |
| 5362 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5363 | bool ValidateDetachShader(Context *context, ShaderProgramID program, ShaderProgramID shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5364 | { |
| 5365 | Program *programObject = GetValidProgram(context, program); |
| 5366 | if (!programObject) |
| 5367 | { |
| 5368 | return false; |
| 5369 | } |
| 5370 | |
| 5371 | Shader *shaderObject = GetValidShader(context, shader); |
| 5372 | if (!shaderObject) |
| 5373 | { |
| 5374 | return false; |
| 5375 | } |
| 5376 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 5377 | const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5378 | if (attachedShader != shaderObject) |
| 5379 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5380 | context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5381 | return false; |
| 5382 | } |
| 5383 | |
| 5384 | return true; |
| 5385 | } |
| 5386 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5387 | bool ValidateDisableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5388 | { |
| 5389 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5390 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5391 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5392 | return false; |
| 5393 | } |
| 5394 | |
| 5395 | return true; |
| 5396 | } |
| 5397 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5398 | bool ValidateEnableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5399 | { |
| 5400 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5401 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5402 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5403 | return false; |
| 5404 | } |
| 5405 | |
| 5406 | return true; |
| 5407 | } |
| 5408 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5409 | bool ValidateFinish(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5410 | { |
| 5411 | return true; |
| 5412 | } |
| 5413 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5414 | bool ValidateFlush(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5415 | { |
| 5416 | return true; |
| 5417 | } |
| 5418 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5419 | bool ValidateFrontFace(Context *context, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5420 | { |
| 5421 | switch (mode) |
| 5422 | { |
| 5423 | case GL_CW: |
| 5424 | case GL_CCW: |
| 5425 | break; |
| 5426 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5427 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5428 | return false; |
| 5429 | } |
| 5430 | |
| 5431 | return true; |
| 5432 | } |
| 5433 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5434 | bool ValidateGetActiveAttrib(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5435 | ShaderProgramID program, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5436 | GLuint index, |
| 5437 | GLsizei bufsize, |
| 5438 | GLsizei *length, |
| 5439 | GLint *size, |
| 5440 | GLenum *type, |
| 5441 | GLchar *name) |
| 5442 | { |
| 5443 | if (bufsize < 0) |
| 5444 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5445 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5446 | return false; |
| 5447 | } |
| 5448 | |
| 5449 | Program *programObject = GetValidProgram(context, program); |
| 5450 | |
| 5451 | if (!programObject) |
| 5452 | { |
| 5453 | return false; |
| 5454 | } |
| 5455 | |
| 5456 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 5457 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5458 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5459 | return false; |
| 5460 | } |
| 5461 | |
| 5462 | return true; |
| 5463 | } |
| 5464 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5465 | bool ValidateGetActiveUniform(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5466 | ShaderProgramID program, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5467 | GLuint index, |
| 5468 | GLsizei bufsize, |
| 5469 | GLsizei *length, |
| 5470 | GLint *size, |
| 5471 | GLenum *type, |
| 5472 | GLchar *name) |
| 5473 | { |
| 5474 | if (bufsize < 0) |
| 5475 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5476 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5477 | return false; |
| 5478 | } |
| 5479 | |
| 5480 | Program *programObject = GetValidProgram(context, program); |
| 5481 | |
| 5482 | if (!programObject) |
| 5483 | { |
| 5484 | return false; |
| 5485 | } |
| 5486 | |
| 5487 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 5488 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5489 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5490 | return false; |
| 5491 | } |
| 5492 | |
| 5493 | return true; |
| 5494 | } |
| 5495 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5496 | bool ValidateGetAttachedShaders(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5497 | ShaderProgramID program, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5498 | GLsizei maxcount, |
| 5499 | GLsizei *count, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5500 | ShaderProgramID *shaders) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5501 | { |
| 5502 | if (maxcount < 0) |
| 5503 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5504 | context->validationError(GL_INVALID_VALUE, kNegativeMaxCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5505 | return false; |
| 5506 | } |
| 5507 | |
| 5508 | Program *programObject = GetValidProgram(context, program); |
| 5509 | |
| 5510 | if (!programObject) |
| 5511 | { |
| 5512 | return false; |
| 5513 | } |
| 5514 | |
| 5515 | return true; |
| 5516 | } |
| 5517 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5518 | bool ValidateGetAttribLocation(Context *context, ShaderProgramID program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5519 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5520 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5521 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5522 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5523 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5524 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5525 | return false; |
| 5526 | } |
| 5527 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5528 | Program *programObject = GetValidProgram(context, program); |
| 5529 | |
| 5530 | if (!programObject) |
| 5531 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5532 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5533 | return false; |
| 5534 | } |
| 5535 | |
| 5536 | if (!programObject->isLinked()) |
| 5537 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5538 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5539 | return false; |
| 5540 | } |
| 5541 | |
| 5542 | return true; |
| 5543 | } |
| 5544 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5545 | bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5546 | { |
| 5547 | GLenum nativeType; |
| 5548 | unsigned int numParams = 0; |
| 5549 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5550 | } |
| 5551 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5552 | bool ValidateGetError(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5553 | { |
| 5554 | return true; |
| 5555 | } |
| 5556 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5557 | bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5558 | { |
| 5559 | GLenum nativeType; |
| 5560 | unsigned int numParams = 0; |
| 5561 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5562 | } |
| 5563 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5564 | bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5565 | { |
| 5566 | GLenum nativeType; |
| 5567 | unsigned int numParams = 0; |
| 5568 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5569 | } |
| 5570 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5571 | bool ValidateGetProgramInfoLog(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5572 | ShaderProgramID program, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5573 | GLsizei bufsize, |
| 5574 | GLsizei *length, |
| 5575 | GLchar *infolog) |
| 5576 | { |
| 5577 | if (bufsize < 0) |
| 5578 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5579 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5580 | return false; |
| 5581 | } |
| 5582 | |
| 5583 | Program *programObject = GetValidProgram(context, program); |
| 5584 | if (!programObject) |
| 5585 | { |
| 5586 | return false; |
| 5587 | } |
| 5588 | |
| 5589 | return true; |
| 5590 | } |
| 5591 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5592 | bool ValidateGetShaderInfoLog(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5593 | ShaderProgramID shader, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5594 | GLsizei bufsize, |
| 5595 | GLsizei *length, |
| 5596 | GLchar *infolog) |
| 5597 | { |
| 5598 | if (bufsize < 0) |
| 5599 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5600 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5601 | return false; |
| 5602 | } |
| 5603 | |
| 5604 | Shader *shaderObject = GetValidShader(context, shader); |
| 5605 | if (!shaderObject) |
| 5606 | { |
| 5607 | return false; |
| 5608 | } |
| 5609 | |
| 5610 | return true; |
| 5611 | } |
| 5612 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5613 | bool ValidateGetShaderPrecisionFormat(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5614 | GLenum shadertype, |
| 5615 | GLenum precisiontype, |
| 5616 | GLint *range, |
| 5617 | GLint *precision) |
| 5618 | { |
| 5619 | switch (shadertype) |
| 5620 | { |
| 5621 | case GL_VERTEX_SHADER: |
| 5622 | case GL_FRAGMENT_SHADER: |
| 5623 | break; |
| 5624 | case GL_COMPUTE_SHADER: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5625 | context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5626 | return false; |
| 5627 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5628 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5629 | return false; |
| 5630 | } |
| 5631 | |
| 5632 | switch (precisiontype) |
| 5633 | { |
| 5634 | case GL_LOW_FLOAT: |
| 5635 | case GL_MEDIUM_FLOAT: |
| 5636 | case GL_HIGH_FLOAT: |
| 5637 | case GL_LOW_INT: |
| 5638 | case GL_MEDIUM_INT: |
| 5639 | case GL_HIGH_INT: |
| 5640 | break; |
| 5641 | |
| 5642 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5643 | context->validationError(GL_INVALID_ENUM, kInvalidPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5644 | return false; |
| 5645 | } |
| 5646 | |
| 5647 | return true; |
| 5648 | } |
| 5649 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5650 | bool ValidateGetShaderSource(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5651 | ShaderProgramID shader, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5652 | GLsizei bufsize, |
| 5653 | GLsizei *length, |
| 5654 | GLchar *source) |
| 5655 | { |
| 5656 | if (bufsize < 0) |
| 5657 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5658 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5659 | return false; |
| 5660 | } |
| 5661 | |
| 5662 | Shader *shaderObject = GetValidShader(context, shader); |
| 5663 | if (!shaderObject) |
| 5664 | { |
| 5665 | return false; |
| 5666 | } |
| 5667 | |
| 5668 | return true; |
| 5669 | } |
| 5670 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5671 | bool ValidateGetUniformLocation(Context *context, ShaderProgramID program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5672 | { |
| 5673 | if (strstr(name, "gl_") == name) |
| 5674 | { |
| 5675 | return false; |
| 5676 | } |
| 5677 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5678 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5679 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5680 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5681 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5682 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5683 | return false; |
| 5684 | } |
| 5685 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5686 | Program *programObject = GetValidProgram(context, program); |
| 5687 | |
| 5688 | if (!programObject) |
| 5689 | { |
| 5690 | return false; |
| 5691 | } |
| 5692 | |
| 5693 | if (!programObject->isLinked()) |
| 5694 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5695 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5696 | return false; |
| 5697 | } |
| 5698 | |
| 5699 | return true; |
| 5700 | } |
| 5701 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5702 | bool ValidateHint(Context *context, GLenum target, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5703 | { |
| 5704 | switch (mode) |
| 5705 | { |
| 5706 | case GL_FASTEST: |
| 5707 | case GL_NICEST: |
| 5708 | case GL_DONT_CARE: |
| 5709 | break; |
| 5710 | |
| 5711 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5712 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5713 | return false; |
| 5714 | } |
| 5715 | |
| 5716 | switch (target) |
| 5717 | { |
| 5718 | case GL_GENERATE_MIPMAP_HINT: |
| 5719 | break; |
| 5720 | |
Geoff Lang | e7bd218 | 2017-06-16 16:13:13 -0400 | [diff] [blame] | 5721 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: |
| 5722 | if (context->getClientVersion() < ES_3_0 && |
| 5723 | !context->getExtensions().standardDerivatives) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5724 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5725 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5726 | return false; |
| 5727 | } |
| 5728 | break; |
| 5729 | |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5730 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 5731 | case GL_POINT_SMOOTH_HINT: |
| 5732 | case GL_LINE_SMOOTH_HINT: |
| 5733 | case GL_FOG_HINT: |
| 5734 | if (context->getClientMajorVersion() >= 2) |
| 5735 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5736 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5737 | return false; |
| 5738 | } |
| 5739 | break; |
| 5740 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5741 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5742 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5743 | return false; |
| 5744 | } |
| 5745 | |
| 5746 | return true; |
| 5747 | } |
| 5748 | |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 5749 | bool ValidateIsBuffer(Context *context, BufferID buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5750 | { |
| 5751 | return true; |
| 5752 | } |
| 5753 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 5754 | bool ValidateIsFramebuffer(Context *context, FramebufferID framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5755 | { |
| 5756 | return true; |
| 5757 | } |
| 5758 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5759 | bool ValidateIsProgram(Context *context, ShaderProgramID program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5760 | { |
| 5761 | return true; |
| 5762 | } |
| 5763 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 5764 | bool ValidateIsRenderbuffer(Context *context, RenderbufferID renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5765 | { |
| 5766 | return true; |
| 5767 | } |
| 5768 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5769 | bool ValidateIsShader(Context *context, ShaderProgramID shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5770 | { |
| 5771 | return true; |
| 5772 | } |
| 5773 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 5774 | bool ValidateIsTexture(Context *context, TextureID texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5775 | { |
| 5776 | return true; |
| 5777 | } |
| 5778 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5779 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5780 | { |
| 5781 | if (context->getClientMajorVersion() < 3) |
| 5782 | { |
| 5783 | switch (pname) |
| 5784 | { |
| 5785 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5786 | case GL_UNPACK_SKIP_IMAGES: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5787 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5788 | return false; |
| 5789 | |
| 5790 | case GL_UNPACK_ROW_LENGTH: |
| 5791 | case GL_UNPACK_SKIP_ROWS: |
| 5792 | case GL_UNPACK_SKIP_PIXELS: |
| 5793 | if (!context->getExtensions().unpackSubimage) |
| 5794 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5795 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5796 | return false; |
| 5797 | } |
| 5798 | break; |
| 5799 | |
| 5800 | case GL_PACK_ROW_LENGTH: |
| 5801 | case GL_PACK_SKIP_ROWS: |
| 5802 | case GL_PACK_SKIP_PIXELS: |
| 5803 | if (!context->getExtensions().packSubimage) |
| 5804 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5805 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5806 | return false; |
| 5807 | } |
| 5808 | break; |
| 5809 | } |
| 5810 | } |
| 5811 | |
| 5812 | if (param < 0) |
| 5813 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5814 | context->validationError(GL_INVALID_VALUE, kNegativeParam); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5815 | return false; |
| 5816 | } |
| 5817 | |
| 5818 | switch (pname) |
| 5819 | { |
| 5820 | case GL_UNPACK_ALIGNMENT: |
| 5821 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5822 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5823 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5824 | return false; |
| 5825 | } |
| 5826 | break; |
| 5827 | |
| 5828 | case GL_PACK_ALIGNMENT: |
| 5829 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5830 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5831 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5832 | return false; |
| 5833 | } |
| 5834 | break; |
| 5835 | |
| 5836 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5837 | if (!context->getExtensions().packReverseRowOrder) |
| 5838 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5839 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5840 | } |
| 5841 | break; |
| 5842 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5843 | case GL_UNPACK_ROW_LENGTH: |
| 5844 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5845 | case GL_UNPACK_SKIP_IMAGES: |
| 5846 | case GL_UNPACK_SKIP_ROWS: |
| 5847 | case GL_UNPACK_SKIP_PIXELS: |
| 5848 | case GL_PACK_ROW_LENGTH: |
| 5849 | case GL_PACK_SKIP_ROWS: |
| 5850 | case GL_PACK_SKIP_PIXELS: |
| 5851 | break; |
| 5852 | |
| 5853 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5854 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5855 | return false; |
| 5856 | } |
| 5857 | |
| 5858 | return true; |
| 5859 | } |
| 5860 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5861 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5862 | { |
| 5863 | return true; |
| 5864 | } |
| 5865 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5866 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5867 | { |
| 5868 | return true; |
| 5869 | } |
| 5870 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5871 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5872 | { |
| 5873 | return true; |
| 5874 | } |
| 5875 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5876 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5877 | { |
| 5878 | if (width < 0 || height < 0) |
| 5879 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5880 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5881 | return false; |
| 5882 | } |
| 5883 | |
| 5884 | return true; |
| 5885 | } |
| 5886 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5887 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5888 | GLsizei n, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5889 | const ShaderProgramID *shaders, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5890 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5891 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5892 | GLsizei length) |
| 5893 | { |
| 5894 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5895 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5896 | shaderBinaryFormats.end()) |
| 5897 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5898 | context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5899 | return false; |
| 5900 | } |
| 5901 | |
| 5902 | return true; |
| 5903 | } |
| 5904 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5905 | bool ValidateShaderSource(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5906 | ShaderProgramID shader, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5907 | GLsizei count, |
| 5908 | const GLchar *const *string, |
| 5909 | const GLint *length) |
| 5910 | { |
| 5911 | if (count < 0) |
| 5912 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5913 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5914 | return false; |
| 5915 | } |
| 5916 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5917 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5918 | // shader-related entry points |
| 5919 | if (context->getExtensions().webglCompatibility) |
| 5920 | { |
| 5921 | for (GLsizei i = 0; i < count; i++) |
| 5922 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5923 | size_t len = |
| 5924 | (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] | 5925 | |
| 5926 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5927 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 5928 | context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5929 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5930 | context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5931 | return false; |
| 5932 | } |
| 5933 | } |
| 5934 | } |
| 5935 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5936 | Shader *shaderObject = GetValidShader(context, shader); |
| 5937 | if (!shaderObject) |
| 5938 | { |
| 5939 | return false; |
| 5940 | } |
| 5941 | |
| 5942 | return true; |
| 5943 | } |
| 5944 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5945 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5946 | { |
| 5947 | if (!IsValidStencilFunc(func)) |
| 5948 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5949 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5950 | return false; |
| 5951 | } |
| 5952 | |
| 5953 | return true; |
| 5954 | } |
| 5955 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5956 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5957 | { |
| 5958 | if (!IsValidStencilFace(face)) |
| 5959 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5960 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5961 | return false; |
| 5962 | } |
| 5963 | |
| 5964 | if (!IsValidStencilFunc(func)) |
| 5965 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5966 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5967 | return false; |
| 5968 | } |
| 5969 | |
| 5970 | return true; |
| 5971 | } |
| 5972 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5973 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5974 | { |
| 5975 | return true; |
| 5976 | } |
| 5977 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5978 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5979 | { |
| 5980 | if (!IsValidStencilFace(face)) |
| 5981 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5982 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5983 | return false; |
| 5984 | } |
| 5985 | |
| 5986 | return true; |
| 5987 | } |
| 5988 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5989 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5990 | { |
| 5991 | if (!IsValidStencilOp(fail)) |
| 5992 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5993 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5994 | return false; |
| 5995 | } |
| 5996 | |
| 5997 | if (!IsValidStencilOp(zfail)) |
| 5998 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5999 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6000 | return false; |
| 6001 | } |
| 6002 | |
| 6003 | if (!IsValidStencilOp(zpass)) |
| 6004 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6005 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6006 | return false; |
| 6007 | } |
| 6008 | |
| 6009 | return true; |
| 6010 | } |
| 6011 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6012 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6013 | GLenum face, |
| 6014 | GLenum fail, |
| 6015 | GLenum zfail, |
| 6016 | GLenum zpass) |
| 6017 | { |
| 6018 | if (!IsValidStencilFace(face)) |
| 6019 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6020 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6021 | return false; |
| 6022 | } |
| 6023 | |
| 6024 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 6025 | } |
| 6026 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6027 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6028 | { |
| 6029 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 6030 | } |
| 6031 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6032 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6033 | { |
| 6034 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 6035 | } |
| 6036 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6037 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6038 | { |
| 6039 | return ValidateUniform1iv(context, location, 1, &x); |
| 6040 | } |
| 6041 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6042 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6043 | { |
| 6044 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 6045 | } |
| 6046 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6047 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6048 | { |
| 6049 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 6050 | } |
| 6051 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6052 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6053 | { |
| 6054 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 6055 | } |
| 6056 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6057 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6058 | { |
| 6059 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 6060 | } |
| 6061 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6062 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6063 | { |
| 6064 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 6065 | } |
| 6066 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6067 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6068 | { |
| 6069 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 6070 | } |
| 6071 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6072 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6073 | { |
| 6074 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 6075 | } |
| 6076 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6077 | 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] | 6078 | { |
| 6079 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 6080 | } |
| 6081 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6082 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6083 | { |
| 6084 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 6085 | } |
| 6086 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6087 | 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] | 6088 | { |
| 6089 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 6090 | } |
| 6091 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6092 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6093 | { |
| 6094 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 6095 | } |
| 6096 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6097 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6098 | GLint location, |
| 6099 | GLsizei count, |
| 6100 | GLboolean transpose, |
| 6101 | const GLfloat *value) |
| 6102 | { |
| 6103 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 6104 | } |
| 6105 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6106 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6107 | GLint location, |
| 6108 | GLsizei count, |
| 6109 | GLboolean transpose, |
| 6110 | const GLfloat *value) |
| 6111 | { |
| 6112 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 6113 | } |
| 6114 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6115 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6116 | GLint location, |
| 6117 | GLsizei count, |
| 6118 | GLboolean transpose, |
| 6119 | const GLfloat *value) |
| 6120 | { |
| 6121 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 6122 | } |
| 6123 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6124 | bool ValidateValidateProgram(Context *context, ShaderProgramID program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6125 | { |
| 6126 | Program *programObject = GetValidProgram(context, program); |
| 6127 | |
| 6128 | if (!programObject) |
| 6129 | { |
| 6130 | return false; |
| 6131 | } |
| 6132 | |
| 6133 | return true; |
| 6134 | } |
| 6135 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6136 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6137 | { |
| 6138 | return ValidateVertexAttribIndex(context, index); |
| 6139 | } |
| 6140 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6141 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6142 | { |
| 6143 | return ValidateVertexAttribIndex(context, index); |
| 6144 | } |
| 6145 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6146 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6147 | { |
| 6148 | return ValidateVertexAttribIndex(context, index); |
| 6149 | } |
| 6150 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6151 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6152 | { |
| 6153 | return ValidateVertexAttribIndex(context, index); |
| 6154 | } |
| 6155 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6156 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6157 | { |
| 6158 | return ValidateVertexAttribIndex(context, index); |
| 6159 | } |
| 6160 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6161 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6162 | { |
| 6163 | return ValidateVertexAttribIndex(context, index); |
| 6164 | } |
| 6165 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6166 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6167 | GLuint index, |
| 6168 | GLfloat x, |
| 6169 | GLfloat y, |
| 6170 | GLfloat z, |
| 6171 | GLfloat w) |
| 6172 | { |
| 6173 | return ValidateVertexAttribIndex(context, index); |
| 6174 | } |
| 6175 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6176 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6177 | { |
| 6178 | return ValidateVertexAttribIndex(context, index); |
| 6179 | } |
| 6180 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6181 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6182 | { |
| 6183 | if (width < 0 || height < 0) |
| 6184 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6185 | context->validationError(GL_INVALID_VALUE, kViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6186 | return false; |
| 6187 | } |
| 6188 | |
| 6189 | return true; |
| 6190 | } |
| 6191 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 6192 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6193 | GLenum target, |
| 6194 | GLenum attachment, |
| 6195 | GLenum pname, |
| 6196 | GLint *params) |
| 6197 | { |
| 6198 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 6199 | nullptr); |
| 6200 | } |
| 6201 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6202 | bool ValidateGetProgramiv(Context *context, ShaderProgramID program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6203 | { |
| 6204 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 6205 | } |
| 6206 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6207 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6208 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6209 | GLint level, |
| 6210 | GLenum internalformat, |
| 6211 | GLint x, |
| 6212 | GLint y, |
| 6213 | GLsizei width, |
| 6214 | GLsizei height, |
| 6215 | GLint border) |
| 6216 | { |
| 6217 | if (context->getClientMajorVersion() < 3) |
| 6218 | { |
| 6219 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 6220 | 0, x, y, width, height, border); |
| 6221 | } |
| 6222 | |
| 6223 | ASSERT(context->getClientMajorVersion() == 3); |
| 6224 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 6225 | 0, x, y, width, height, border); |
| 6226 | } |
| 6227 | |
| 6228 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6229 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6230 | GLint level, |
| 6231 | GLint xoffset, |
| 6232 | GLint yoffset, |
| 6233 | GLint x, |
| 6234 | GLint y, |
| 6235 | GLsizei width, |
| 6236 | GLsizei height) |
| 6237 | { |
| 6238 | if (context->getClientMajorVersion() < 3) |
| 6239 | { |
| 6240 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 6241 | yoffset, x, y, width, height, 0); |
| 6242 | } |
| 6243 | |
| 6244 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 6245 | yoffset, 0, x, y, width, height, 0); |
| 6246 | } |
| 6247 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6248 | bool ValidateCopyTexSubImage3DOES(Context *context, |
| 6249 | TextureTarget target, |
| 6250 | GLint level, |
| 6251 | GLint xoffset, |
| 6252 | GLint yoffset, |
| 6253 | GLint zoffset, |
| 6254 | GLint x, |
| 6255 | GLint y, |
| 6256 | GLsizei width, |
| 6257 | GLsizei height) |
| 6258 | { |
| 6259 | return ValidateCopyTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, x, y, width, |
| 6260 | height); |
| 6261 | } |
| 6262 | |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 6263 | bool ValidateDeleteBuffers(Context *context, GLint n, const BufferID *buffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6264 | { |
| 6265 | return ValidateGenOrDelete(context, n); |
| 6266 | } |
| 6267 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 6268 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const FramebufferID *framebuffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6269 | { |
| 6270 | return ValidateGenOrDelete(context, n); |
| 6271 | } |
| 6272 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 6273 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const RenderbufferID *renderbuffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6274 | { |
| 6275 | return ValidateGenOrDelete(context, n); |
| 6276 | } |
| 6277 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6278 | bool ValidateDeleteTextures(Context *context, GLint n, const TextureID *textures) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6279 | { |
| 6280 | return ValidateGenOrDelete(context, n); |
| 6281 | } |
| 6282 | |
| 6283 | bool ValidateDisable(Context *context, GLenum cap) |
| 6284 | { |
| 6285 | if (!ValidCap(context, cap, false)) |
| 6286 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6287 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6288 | return false; |
| 6289 | } |
| 6290 | |
| 6291 | return true; |
| 6292 | } |
| 6293 | |
| 6294 | bool ValidateEnable(Context *context, GLenum cap) |
| 6295 | { |
| 6296 | if (!ValidCap(context, cap, false)) |
| 6297 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6298 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6299 | return false; |
| 6300 | } |
| 6301 | |
| 6302 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 6303 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 6304 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6305 | context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6306 | |
| 6307 | // We also output an error message to the debugger window if tracing is active, so that |
| 6308 | // developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6309 | ERR() << kNoSampleAlphaToCoveragesLimitation; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6310 | return false; |
| 6311 | } |
| 6312 | |
| 6313 | return true; |
| 6314 | } |
| 6315 | |
| 6316 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 6317 | GLenum target, |
| 6318 | GLenum attachment, |
| 6319 | GLenum renderbuffertarget, |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 6320 | RenderbufferID renderbuffer) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6321 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 6322 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6323 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6324 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6325 | return false; |
| 6326 | } |
| 6327 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 6328 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer.value != 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6329 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6330 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6331 | return false; |
| 6332 | } |
| 6333 | |
| 6334 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 6335 | renderbuffertarget, renderbuffer); |
| 6336 | } |
| 6337 | |
| 6338 | bool ValidateFramebufferTexture2D(Context *context, |
| 6339 | GLenum target, |
| 6340 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6341 | TextureTarget textarget, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6342 | TextureID texture, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6343 | GLint level) |
| 6344 | { |
| 6345 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 6346 | // extension |
| 6347 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 6348 | level != 0) |
| 6349 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6350 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6351 | return false; |
| 6352 | } |
| 6353 | |
| 6354 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 6355 | { |
| 6356 | return false; |
| 6357 | } |
| 6358 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6359 | if (texture.value != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6360 | { |
| 6361 | gl::Texture *tex = context->getTexture(texture); |
| 6362 | ASSERT(tex); |
| 6363 | |
| 6364 | const gl::Caps &caps = context->getCaps(); |
| 6365 | |
| 6366 | switch (textarget) |
| 6367 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6368 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6369 | { |
| 6370 | if (level > gl::log2(caps.max2DTextureSize)) |
| 6371 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6372 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6373 | return false; |
| 6374 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6375 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6376 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6377 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6378 | return false; |
| 6379 | } |
| 6380 | } |
| 6381 | break; |
| 6382 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6383 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6384 | { |
| 6385 | if (level != 0) |
| 6386 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6387 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6388 | return false; |
| 6389 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6390 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6391 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6392 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6393 | return false; |
| 6394 | } |
| 6395 | } |
| 6396 | break; |
| 6397 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6398 | case TextureTarget::CubeMapNegativeX: |
| 6399 | case TextureTarget::CubeMapNegativeY: |
| 6400 | case TextureTarget::CubeMapNegativeZ: |
| 6401 | case TextureTarget::CubeMapPositiveX: |
| 6402 | case TextureTarget::CubeMapPositiveY: |
| 6403 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6404 | { |
| 6405 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 6406 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6407 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6408 | return false; |
| 6409 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6410 | if (tex->getType() != TextureType::CubeMap) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6411 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6412 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6413 | return false; |
| 6414 | } |
| 6415 | } |
| 6416 | break; |
| 6417 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6418 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6419 | { |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6420 | if (context->getClientVersion() < ES_3_1 && |
| 6421 | !context->getExtensions().textureMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6422 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6423 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6424 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6425 | return false; |
| 6426 | } |
| 6427 | |
| 6428 | if (level != 0) |
| 6429 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6430 | context->validationError(GL_INVALID_VALUE, kLevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6431 | return false; |
| 6432 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6433 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6434 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6435 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6436 | return false; |
| 6437 | } |
| 6438 | } |
| 6439 | break; |
| 6440 | |
| 6441 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6442 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6443 | return false; |
| 6444 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | return true; |
| 6448 | } |
| 6449 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6450 | bool ValidateFramebufferTexture3DOES(Context *context, |
| 6451 | GLenum target, |
| 6452 | GLenum attachment, |
| 6453 | TextureTarget textargetPacked, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6454 | TextureID texture, |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6455 | GLint level, |
| 6456 | GLint zoffset) |
| 6457 | { |
Cody Northrop | 90958e3 | 2019-08-07 16:26:14 -0600 | [diff] [blame] | 6458 | // We don't call into a base ValidateFramebufferTexture3D here because |
| 6459 | // it doesn't exist for OpenGL ES. This function is replaced by |
| 6460 | // FramebufferTextureLayer in ES 3.x, which has broader support. |
| 6461 | if (!context->getExtensions().texture3DOES) |
| 6462 | { |
| 6463 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 6464 | return false; |
| 6465 | } |
| 6466 | |
| 6467 | // Attachments are required to be bound to level 0 without ES3 or the |
| 6468 | // GL_OES_fbo_render_mipmap extension |
| 6469 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 6470 | level != 0) |
| 6471 | { |
| 6472 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel); |
| 6473 | return false; |
| 6474 | } |
| 6475 | |
| 6476 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 6477 | { |
| 6478 | return false; |
| 6479 | } |
| 6480 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6481 | if (texture.value != 0) |
Cody Northrop | 90958e3 | 2019-08-07 16:26:14 -0600 | [diff] [blame] | 6482 | { |
| 6483 | gl::Texture *tex = context->getTexture(texture); |
| 6484 | ASSERT(tex); |
| 6485 | |
| 6486 | const gl::Caps &caps = context->getCaps(); |
| 6487 | |
| 6488 | switch (textargetPacked) |
| 6489 | { |
| 6490 | case TextureTarget::_3D: |
| 6491 | { |
| 6492 | if (level > gl::log2(caps.max3DTextureSize)) |
| 6493 | { |
| 6494 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
| 6495 | return false; |
| 6496 | } |
| 6497 | if (static_cast<size_t>(zoffset) >= caps.max3DTextureSize) |
| 6498 | { |
| 6499 | context->validationError(GL_INVALID_VALUE, kInvalidZOffset); |
| 6500 | return false; |
| 6501 | } |
| 6502 | if (tex->getType() != TextureType::_3D) |
| 6503 | { |
| 6504 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureType); |
| 6505 | return false; |
| 6506 | } |
| 6507 | } |
| 6508 | break; |
| 6509 | |
| 6510 | default: |
| 6511 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
| 6512 | return false; |
| 6513 | } |
| 6514 | } |
| 6515 | |
| 6516 | return true; |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6517 | } |
| 6518 | |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 6519 | bool ValidateGenBuffers(Context *context, GLint n, BufferID *buffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6520 | { |
| 6521 | return ValidateGenOrDelete(context, n); |
| 6522 | } |
| 6523 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 6524 | bool ValidateGenFramebuffers(Context *context, GLint n, FramebufferID *framebuffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6525 | { |
| 6526 | return ValidateGenOrDelete(context, n); |
| 6527 | } |
| 6528 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 6529 | bool ValidateGenRenderbuffers(Context *context, GLint n, RenderbufferID *renderbuffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6530 | { |
| 6531 | return ValidateGenOrDelete(context, n); |
| 6532 | } |
| 6533 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6534 | bool ValidateGenTextures(Context *context, GLint n, TextureID *textures) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6535 | { |
| 6536 | return ValidateGenOrDelete(context, n); |
| 6537 | } |
| 6538 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6539 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6540 | { |
| 6541 | if (!ValidTextureTarget(context, target)) |
| 6542 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6543 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6544 | return false; |
| 6545 | } |
| 6546 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 6547 | Texture *texture = context->getTextureByType(target); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6548 | |
| 6549 | if (texture == nullptr) |
| 6550 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6551 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6552 | return false; |
| 6553 | } |
| 6554 | |
| 6555 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 6556 | |
| 6557 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 6558 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 6559 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 6560 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6561 | context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6562 | return false; |
| 6563 | } |
| 6564 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6565 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 6566 | ? TextureTarget::CubeMapPositiveX |
| 6567 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6568 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 6569 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 6570 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6571 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6572 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6573 | return false; |
| 6574 | } |
| 6575 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6576 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 6577 | bool formatUnsized = !format.sized; |
| 6578 | bool formatColorRenderableAndFilterable = |
| 6579 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6580 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6581 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6582 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6583 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6584 | return false; |
| 6585 | } |
| 6586 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6587 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 6588 | // generation |
| 6589 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 6590 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6591 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6592 | return false; |
| 6593 | } |
| 6594 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 6595 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 6596 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 6597 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6598 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6599 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6600 | return false; |
| 6601 | } |
| 6602 | |
| 6603 | // Non-power of 2 ES2 check |
| 6604 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 6605 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 6606 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 6607 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6608 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 6609 | target == TextureType::CubeMap); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6610 | context->validationError(GL_INVALID_OPERATION, kTextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6611 | return false; |
| 6612 | } |
| 6613 | |
| 6614 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6615 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6616 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6617 | context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6618 | return false; |
| 6619 | } |
| 6620 | |
James Darpinian | 83b2f0e | 2018-11-27 15:56:01 -0800 | [diff] [blame] | 6621 | if (context->getExtensions().webglCompatibility && |
| 6622 | (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 || |
| 6623 | texture->getHeight(baseTarget, effectiveBaseLevel) == 0)) |
| 6624 | { |
| 6625 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize); |
| 6626 | return false; |
| 6627 | } |
| 6628 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6629 | return true; |
| 6630 | } |
| 6631 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6632 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 6633 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6634 | GLenum pname, |
| 6635 | GLint *params) |
| 6636 | { |
| 6637 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 6638 | } |
| 6639 | |
| 6640 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6641 | GLenum target, |
| 6642 | GLenum pname, |
| 6643 | GLint *params) |
| 6644 | { |
| 6645 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6646 | } |
| 6647 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6648 | bool ValidateGetShaderiv(Context *context, ShaderProgramID shader, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6649 | { |
| 6650 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6651 | } |
| 6652 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6653 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6654 | { |
| 6655 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6656 | } |
| 6657 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6658 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6659 | { |
| 6660 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6661 | } |
| 6662 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6663 | bool ValidateGetTexParameterIivOES(Context *context, |
| 6664 | TextureType target, |
| 6665 | GLenum pname, |
| 6666 | GLint *params) |
| 6667 | { |
| 6668 | if (context->getClientMajorVersion() < 3) |
| 6669 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6670 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6671 | return false; |
| 6672 | } |
| 6673 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6674 | } |
| 6675 | |
| 6676 | bool ValidateGetTexParameterIuivOES(Context *context, |
| 6677 | TextureType target, |
| 6678 | GLenum pname, |
| 6679 | GLuint *params) |
| 6680 | { |
| 6681 | if (context->getClientMajorVersion() < 3) |
| 6682 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6683 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6684 | return false; |
| 6685 | } |
| 6686 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6687 | } |
| 6688 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6689 | bool ValidateGetUniformfv(Context *context, |
| 6690 | ShaderProgramID program, |
| 6691 | GLint location, |
| 6692 | GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6693 | { |
| 6694 | return ValidateGetUniformBase(context, program, location); |
| 6695 | } |
| 6696 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6697 | bool ValidateGetUniformiv(Context *context, ShaderProgramID program, GLint location, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6698 | { |
| 6699 | return ValidateGetUniformBase(context, program, location); |
| 6700 | } |
| 6701 | |
| 6702 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6703 | { |
| 6704 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6705 | } |
| 6706 | |
| 6707 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6708 | { |
| 6709 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6710 | } |
| 6711 | |
| 6712 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6713 | { |
| 6714 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6715 | } |
| 6716 | |
| 6717 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6718 | { |
| 6719 | if (!ValidCap(context, cap, true)) |
| 6720 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6721 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6722 | return false; |
| 6723 | } |
| 6724 | |
| 6725 | return true; |
| 6726 | } |
| 6727 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6728 | bool ValidateLinkProgram(Context *context, ShaderProgramID program) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6729 | { |
| 6730 | if (context->hasActiveTransformFeedback(program)) |
| 6731 | { |
| 6732 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6733 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6734 | return false; |
| 6735 | } |
| 6736 | |
| 6737 | Program *programObject = GetValidProgram(context, program); |
| 6738 | if (!programObject) |
| 6739 | { |
| 6740 | return false; |
| 6741 | } |
| 6742 | |
| 6743 | return true; |
| 6744 | } |
| 6745 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6746 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6747 | GLint x, |
| 6748 | GLint y, |
| 6749 | GLsizei width, |
| 6750 | GLsizei height, |
| 6751 | GLenum format, |
| 6752 | GLenum type, |
| 6753 | void *pixels) |
| 6754 | { |
| 6755 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6756 | nullptr, pixels); |
| 6757 | } |
| 6758 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6759 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6760 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6761 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6762 | } |
| 6763 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6764 | bool ValidateTexParameterfv(Context *context, |
| 6765 | TextureType target, |
| 6766 | GLenum pname, |
| 6767 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6768 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6769 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6770 | } |
| 6771 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6772 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6773 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6774 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6775 | } |
| 6776 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6777 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6778 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6779 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6780 | } |
| 6781 | |
| 6782 | bool ValidateTexParameterIivOES(Context *context, |
| 6783 | TextureType target, |
| 6784 | GLenum pname, |
| 6785 | const GLint *params) |
| 6786 | { |
| 6787 | if (context->getClientMajorVersion() < 3) |
| 6788 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6789 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6790 | return false; |
| 6791 | } |
| 6792 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6793 | } |
| 6794 | |
| 6795 | bool ValidateTexParameterIuivOES(Context *context, |
| 6796 | TextureType target, |
| 6797 | GLenum pname, |
| 6798 | const GLuint *params) |
| 6799 | { |
| 6800 | if (context->getClientMajorVersion() < 3) |
| 6801 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6802 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6803 | return false; |
| 6804 | } |
| 6805 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6806 | } |
| 6807 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6808 | bool ValidateUseProgram(Context *context, ShaderProgramID program) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6809 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6810 | if (program.value != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6811 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 6812 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6813 | if (!programObject) |
| 6814 | { |
| 6815 | // ES 3.1.0 section 7.3 page 72 |
| 6816 | if (context->getShader(program)) |
| 6817 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6818 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6819 | return false; |
| 6820 | } |
| 6821 | else |
| 6822 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6823 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6824 | return false; |
| 6825 | } |
| 6826 | } |
| 6827 | if (!programObject->isLinked()) |
| 6828 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6829 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6830 | return false; |
| 6831 | } |
| 6832 | } |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 6833 | if (context->getState().isTransformFeedbackActiveUnpaused()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6834 | { |
| 6835 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6836 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6837 | return false; |
| 6838 | } |
| 6839 | |
| 6840 | return true; |
| 6841 | } |
| 6842 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6843 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const FenceNVID *fences) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6844 | { |
| 6845 | if (!context->getExtensions().fence) |
| 6846 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6847 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6848 | return false; |
| 6849 | } |
| 6850 | |
| 6851 | if (n < 0) |
| 6852 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6853 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6854 | return false; |
| 6855 | } |
| 6856 | |
| 6857 | return true; |
| 6858 | } |
| 6859 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6860 | bool ValidateFinishFenceNV(Context *context, FenceNVID fence) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6861 | { |
| 6862 | if (!context->getExtensions().fence) |
| 6863 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6864 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6865 | return false; |
| 6866 | } |
| 6867 | |
| 6868 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6869 | |
| 6870 | if (fenceObject == nullptr) |
| 6871 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6872 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6873 | return false; |
| 6874 | } |
| 6875 | |
| 6876 | if (!fenceObject->isSet()) |
| 6877 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6878 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6879 | return false; |
| 6880 | } |
| 6881 | |
| 6882 | return true; |
| 6883 | } |
| 6884 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6885 | bool ValidateGenFencesNV(Context *context, GLsizei n, FenceNVID *fences) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6886 | { |
| 6887 | if (!context->getExtensions().fence) |
| 6888 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6889 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6890 | return false; |
| 6891 | } |
| 6892 | |
| 6893 | if (n < 0) |
| 6894 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6895 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6896 | return false; |
| 6897 | } |
| 6898 | |
| 6899 | return true; |
| 6900 | } |
| 6901 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6902 | bool ValidateGetFenceivNV(Context *context, FenceNVID fence, GLenum pname, GLint *params) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6903 | { |
| 6904 | if (!context->getExtensions().fence) |
| 6905 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6906 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6907 | return false; |
| 6908 | } |
| 6909 | |
| 6910 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6911 | |
| 6912 | if (fenceObject == nullptr) |
| 6913 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6914 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6915 | return false; |
| 6916 | } |
| 6917 | |
| 6918 | if (!fenceObject->isSet()) |
| 6919 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6920 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6921 | return false; |
| 6922 | } |
| 6923 | |
| 6924 | switch (pname) |
| 6925 | { |
| 6926 | case GL_FENCE_STATUS_NV: |
| 6927 | case GL_FENCE_CONDITION_NV: |
| 6928 | break; |
| 6929 | |
| 6930 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6931 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6932 | return false; |
| 6933 | } |
| 6934 | |
| 6935 | return true; |
| 6936 | } |
| 6937 | |
| 6938 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 6939 | { |
| 6940 | if (!context->getExtensions().robustness) |
| 6941 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6942 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6943 | return false; |
| 6944 | } |
| 6945 | |
| 6946 | return true; |
| 6947 | } |
| 6948 | |
| 6949 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6950 | ShaderProgramID shader, |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6951 | GLsizei bufsize, |
| 6952 | GLsizei *length, |
| 6953 | GLchar *source) |
| 6954 | { |
| 6955 | if (!context->getExtensions().translatedShaderSource) |
| 6956 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6957 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6958 | return false; |
| 6959 | } |
| 6960 | |
| 6961 | if (bufsize < 0) |
| 6962 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6963 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6964 | return false; |
| 6965 | } |
| 6966 | |
| 6967 | Shader *shaderObject = context->getShader(shader); |
| 6968 | |
| 6969 | if (!shaderObject) |
| 6970 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6971 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6972 | return false; |
| 6973 | } |
| 6974 | |
| 6975 | return true; |
| 6976 | } |
| 6977 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6978 | bool ValidateIsFenceNV(Context *context, FenceNVID fence) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6979 | { |
| 6980 | if (!context->getExtensions().fence) |
| 6981 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6982 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6983 | return false; |
| 6984 | } |
| 6985 | |
| 6986 | return true; |
| 6987 | } |
| 6988 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6989 | bool ValidateSetFenceNV(Context *context, FenceNVID fence, GLenum condition) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6990 | { |
| 6991 | if (!context->getExtensions().fence) |
| 6992 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6993 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6994 | return false; |
| 6995 | } |
| 6996 | |
| 6997 | if (condition != GL_ALL_COMPLETED_NV) |
| 6998 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6999 | context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7000 | return false; |
| 7001 | } |
| 7002 | |
| 7003 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 7004 | |
| 7005 | if (fenceObject == nullptr) |
| 7006 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7007 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7008 | return false; |
| 7009 | } |
| 7010 | |
| 7011 | return true; |
| 7012 | } |
| 7013 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 7014 | bool ValidateTestFenceNV(Context *context, FenceNVID fence) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7015 | { |
| 7016 | if (!context->getExtensions().fence) |
| 7017 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7018 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7019 | return false; |
| 7020 | } |
| 7021 | |
| 7022 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 7023 | |
| 7024 | if (fenceObject == nullptr) |
| 7025 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7026 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7027 | return false; |
| 7028 | } |
| 7029 | |
| 7030 | if (fenceObject->isSet() != GL_TRUE) |
| 7031 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7032 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7033 | return false; |
| 7034 | } |
| 7035 | |
| 7036 | return true; |
| 7037 | } |
| 7038 | |
| 7039 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 7040 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7041 | GLsizei levels, |
| 7042 | GLenum internalformat, |
| 7043 | GLsizei width, |
| 7044 | GLsizei height) |
| 7045 | { |
| 7046 | if (!context->getExtensions().textureStorage) |
| 7047 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7048 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7049 | return false; |
| 7050 | } |
| 7051 | |
| 7052 | if (context->getClientMajorVersion() < 3) |
| 7053 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 7054 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7055 | height); |
| 7056 | } |
| 7057 | |
| 7058 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 7059 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7060 | 1); |
| 7061 | } |
| 7062 | |
| 7063 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 7064 | { |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 7065 | if (!context->getExtensions().instancedArraysANGLE) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7066 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7067 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7068 | return false; |
| 7069 | } |
| 7070 | |
| 7071 | if (index >= MAX_VERTEX_ATTRIBS) |
| 7072 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7073 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7074 | return false; |
| 7075 | } |
| 7076 | |
| 7077 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 7078 | { |
| 7079 | if (index == 0 && divisor != 0) |
| 7080 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 7081 | context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7082 | |
| 7083 | // We also output an error message to the debugger window if tracing is active, so |
| 7084 | // that developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 7085 | ERR() << kAttributeZeroRequiresDivisorLimitation; |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7086 | return false; |
| 7087 | } |
| 7088 | } |
| 7089 | |
| 7090 | return true; |
| 7091 | } |
| 7092 | |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 7093 | bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor) |
| 7094 | { |
| 7095 | if (!context->getExtensions().instancedArraysEXT) |
| 7096 | { |
| 7097 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 7098 | return false; |
| 7099 | } |
| 7100 | |
| 7101 | if (index >= MAX_VERTEX_ATTRIBS) |
| 7102 | { |
| 7103 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
| 7104 | return false; |
| 7105 | } |
| 7106 | |
| 7107 | return true; |
| 7108 | } |
| 7109 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7110 | bool ValidateTexImage3DOES(Context *context, |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 7111 | TextureTarget target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7112 | GLint level, |
| 7113 | GLenum internalformat, |
| 7114 | GLsizei width, |
| 7115 | GLsizei height, |
| 7116 | GLsizei depth, |
| 7117 | GLint border, |
| 7118 | GLenum format, |
| 7119 | GLenum type, |
| 7120 | const void *pixels) |
| 7121 | { |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 7122 | return ValidateTexImage3D(context, target, level, internalformat, width, height, depth, border, |
| 7123 | format, type, pixels); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7124 | } |
| 7125 | |
| 7126 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 7127 | { |
| 7128 | if (!context->getExtensions().debugMarker) |
| 7129 | { |
| 7130 | // The debug marker calls should not set error state |
| 7131 | // 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] | 7132 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7133 | return false; |
| 7134 | } |
| 7135 | |
| 7136 | return true; |
| 7137 | } |
| 7138 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7139 | bool ValidateTexStorage1DEXT(Context *context, |
| 7140 | GLenum target, |
| 7141 | GLsizei levels, |
| 7142 | GLenum internalformat, |
| 7143 | GLsizei width) |
| 7144 | { |
| 7145 | UNIMPLEMENTED(); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7146 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7147 | return false; |
| 7148 | } |
| 7149 | |
| 7150 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 7151 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7152 | GLsizei levels, |
| 7153 | GLenum internalformat, |
| 7154 | GLsizei width, |
| 7155 | GLsizei height, |
| 7156 | GLsizei depth) |
| 7157 | { |
| 7158 | if (!context->getExtensions().textureStorage) |
| 7159 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7160 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7161 | return false; |
| 7162 | } |
| 7163 | |
| 7164 | if (context->getClientMajorVersion() < 3) |
| 7165 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7166 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7167 | return false; |
| 7168 | } |
| 7169 | |
| 7170 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 7171 | depth); |
| 7172 | } |
| 7173 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 7174 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 7175 | { |
| 7176 | if (!context->getExtensions().parallelShaderCompile) |
| 7177 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7178 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 7179 | return false; |
| 7180 | } |
| 7181 | return true; |
| 7182 | } |
| 7183 | |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7184 | bool ValidateMultiDrawArraysANGLE(Context *context, |
| 7185 | PrimitiveMode mode, |
| 7186 | const GLint *firsts, |
| 7187 | const GLsizei *counts, |
| 7188 | GLsizei drawcount) |
| 7189 | { |
| 7190 | if (!context->getExtensions().multiDraw) |
| 7191 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7192 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7193 | return false; |
| 7194 | } |
| 7195 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 7196 | { |
| 7197 | if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID])) |
| 7198 | { |
| 7199 | return false; |
| 7200 | } |
| 7201 | } |
| 7202 | return true; |
| 7203 | } |
| 7204 | |
| 7205 | bool ValidateMultiDrawElementsANGLE(Context *context, |
| 7206 | PrimitiveMode mode, |
| 7207 | const GLsizei *counts, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 7208 | DrawElementsType type, |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 7209 | const GLvoid *const *indices, |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7210 | GLsizei drawcount) |
| 7211 | { |
| 7212 | if (!context->getExtensions().multiDraw) |
| 7213 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7214 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7215 | return false; |
| 7216 | } |
| 7217 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 7218 | { |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 7219 | if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID])) |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7220 | { |
| 7221 | return false; |
| 7222 | } |
| 7223 | } |
| 7224 | return true; |
| 7225 | } |
| 7226 | |
Clemen Deng | ce33059 | 2019-07-16 10:02:21 -0400 | [diff] [blame] | 7227 | bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertexConvention modePacked) |
Jeff Gilbert | 465d609 | 2019-01-02 16:21:18 -0800 | [diff] [blame] | 7228 | { |
| 7229 | if (!context->getExtensions().provokingVertex) |
| 7230 | { |
| 7231 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 7232 | return false; |
| 7233 | } |
| 7234 | |
| 7235 | switch (modePacked) |
| 7236 | { |
Clemen Deng | ce33059 | 2019-07-16 10:02:21 -0400 | [diff] [blame] | 7237 | case ProvokingVertexConvention::FirstVertexConvention: |
| 7238 | case ProvokingVertexConvention::LastVertexConvention: |
Jeff Gilbert | 465d609 | 2019-01-02 16:21:18 -0800 | [diff] [blame] | 7239 | break; |
| 7240 | default: |
| 7241 | context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex); |
| 7242 | return false; |
| 7243 | } |
| 7244 | |
| 7245 | return true; |
| 7246 | } |
| 7247 | |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 7248 | bool ValidateFramebufferTexture2DMultisampleEXT(Context *context, |
| 7249 | GLenum target, |
| 7250 | GLenum attachment, |
| 7251 | GLenum textarget, |
| 7252 | GLuint texture, |
| 7253 | GLint level, |
| 7254 | GLsizei samples) |
| 7255 | { |
| 7256 | return true; |
| 7257 | } |
| 7258 | |
| 7259 | bool ValidateRenderbufferStorageMultisampleEXT(Context *context, |
| 7260 | GLenum target, |
| 7261 | GLsizei samples, |
| 7262 | GLenum internalformat, |
| 7263 | GLsizei width, |
| 7264 | GLsizei height) |
| 7265 | { |
| 7266 | return true; |
| 7267 | } |
| 7268 | |
Jamie Madill | a541048 | 2019-01-31 19:55:55 -0500 | [diff] [blame] | 7269 | void RecordBindTextureTypeError(Context *context, TextureType target) |
| 7270 | { |
| 7271 | ASSERT(!context->getStateCache().isValidBindTextureType(target)); |
| 7272 | |
| 7273 | switch (target) |
| 7274 | { |
| 7275 | case TextureType::Rectangle: |
| 7276 | ASSERT(!context->getExtensions().textureRectangle); |
| 7277 | context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported); |
| 7278 | break; |
| 7279 | |
| 7280 | case TextureType::_3D: |
| 7281 | case TextureType::_2DArray: |
| 7282 | ASSERT(context->getClientMajorVersion() < 3); |
| 7283 | context->validationError(GL_INVALID_ENUM, kES3Required); |
| 7284 | break; |
| 7285 | |
| 7286 | case TextureType::_2DMultisample: |
| 7287 | ASSERT(context->getClientVersion() < Version(3, 1) && |
| 7288 | !context->getExtensions().textureMultisample); |
| 7289 | context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required); |
| 7290 | break; |
| 7291 | |
| 7292 | case TextureType::_2DMultisampleArray: |
| 7293 | ASSERT(!context->getExtensions().textureStorageMultisample2DArray); |
| 7294 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
| 7295 | break; |
| 7296 | |
| 7297 | case TextureType::External: |
| 7298 | ASSERT(!context->getExtensions().eglImageExternal && |
| 7299 | !context->getExtensions().eglStreamConsumerExternal); |
| 7300 | context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported); |
| 7301 | break; |
| 7302 | |
| 7303 | default: |
| 7304 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
| 7305 | } |
| 7306 | } |
| 7307 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 7308 | } // namespace gl |