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; |
Le Quyen | 6e65398 | 2019-10-09 15:19:02 +0800 | [diff] [blame^] | 730 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 731 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 732 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
| 733 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: |
| 734 | if (context->getExtensions().compressedTexturePVRTC) |
| 735 | { |
| 736 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
| 737 | return false; |
| 738 | } |
| 739 | else |
| 740 | { |
| 741 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 742 | return false; |
| 743 | } |
| 744 | break; |
| 745 | case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT: |
| 746 | case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT: |
| 747 | case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT: |
| 748 | case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT: |
| 749 | if (context->getExtensions().compressedTexturePVRTCsRGB) |
| 750 | { |
| 751 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
| 752 | return false; |
| 753 | } |
| 754 | else |
| 755 | { |
| 756 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 757 | return false; |
| 758 | } |
| 759 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 760 | case GL_DEPTH_COMPONENT: |
| 761 | case GL_DEPTH_COMPONENT16: |
| 762 | case GL_DEPTH_COMPONENT32_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 763 | if (context->getExtensions().depthTextureAny()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 764 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 765 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 766 | return false; |
| 767 | } |
| 768 | else |
| 769 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 770 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 771 | return false; |
| 772 | } |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 773 | break; |
| 774 | case GL_DEPTH_STENCIL_OES: |
| 775 | case GL_DEPTH24_STENCIL8_OES: |
| 776 | if (context->getExtensions().depthTextureAny() || |
| 777 | context->getExtensions().packedDepthStencil) |
| 778 | { |
| 779 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
| 780 | return false; |
| 781 | } |
| 782 | else |
| 783 | { |
| 784 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 785 | return false; |
| 786 | } |
| 787 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 788 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 789 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 790 | return false; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 795 | return (width > 0 && height > 0); |
| 796 | } |
| 797 | |
| 798 | bool ValidCap(const Context *context, GLenum cap, bool queryOnly) |
| 799 | { |
| 800 | switch (cap) |
| 801 | { |
| 802 | // EXT_multisample_compatibility |
| 803 | case GL_MULTISAMPLE_EXT: |
| 804 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 805 | return context->getExtensions().multisampleCompatibility; |
| 806 | |
| 807 | case GL_CULL_FACE: |
| 808 | case GL_POLYGON_OFFSET_FILL: |
| 809 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 810 | case GL_SAMPLE_COVERAGE: |
| 811 | case GL_SCISSOR_TEST: |
| 812 | case GL_STENCIL_TEST: |
| 813 | case GL_DEPTH_TEST: |
| 814 | case GL_BLEND: |
| 815 | case GL_DITHER: |
| 816 | return true; |
| 817 | |
| 818 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 819 | case GL_RASTERIZER_DISCARD: |
| 820 | return (context->getClientMajorVersion() >= 3); |
| 821 | |
| 822 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 823 | case GL_DEBUG_OUTPUT: |
| 824 | return context->getExtensions().debug; |
| 825 | |
| 826 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 827 | return queryOnly && context->getExtensions().bindGeneratesResource; |
| 828 | |
| 829 | case GL_CLIENT_ARRAYS_ANGLE: |
| 830 | return queryOnly && context->getExtensions().clientArrays; |
| 831 | |
| 832 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 833 | return context->getExtensions().sRGBWriteControl; |
| 834 | |
| 835 | case GL_SAMPLE_MASK: |
| 836 | return context->getClientVersion() >= Version(3, 1); |
| 837 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 838 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 839 | return queryOnly && context->getExtensions().robustResourceInitialization; |
| 840 | |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 841 | // GLES1 emulation: GLES1-specific caps |
| 842 | case GL_ALPHA_TEST: |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 843 | case GL_VERTEX_ARRAY: |
| 844 | case GL_NORMAL_ARRAY: |
| 845 | case GL_COLOR_ARRAY: |
| 846 | case GL_TEXTURE_COORD_ARRAY: |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 847 | case GL_TEXTURE_2D: |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 848 | case GL_LIGHTING: |
| 849 | case GL_LIGHT0: |
| 850 | case GL_LIGHT1: |
| 851 | case GL_LIGHT2: |
| 852 | case GL_LIGHT3: |
| 853 | case GL_LIGHT4: |
| 854 | case GL_LIGHT5: |
| 855 | case GL_LIGHT6: |
| 856 | case GL_LIGHT7: |
| 857 | case GL_NORMALIZE: |
| 858 | case GL_RESCALE_NORMAL: |
| 859 | case GL_COLOR_MATERIAL: |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 860 | case GL_CLIP_PLANE0: |
| 861 | case GL_CLIP_PLANE1: |
| 862 | case GL_CLIP_PLANE2: |
| 863 | case GL_CLIP_PLANE3: |
| 864 | case GL_CLIP_PLANE4: |
| 865 | case GL_CLIP_PLANE5: |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 866 | case GL_FOG: |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 867 | case GL_POINT_SMOOTH: |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 868 | case GL_LINE_SMOOTH: |
| 869 | case GL_COLOR_LOGIC_OP: |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 870 | return context->getClientVersion() < Version(2, 0); |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 871 | case GL_POINT_SIZE_ARRAY_OES: |
| 872 | return context->getClientVersion() < Version(2, 0) && |
| 873 | context->getExtensions().pointSizeArray; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 874 | case GL_TEXTURE_CUBE_MAP: |
| 875 | return context->getClientVersion() < Version(2, 0) && |
| 876 | context->getExtensions().textureCubeMap; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 877 | case GL_POINT_SPRITE_OES: |
| 878 | return context->getClientVersion() < Version(2, 0) && |
| 879 | context->getExtensions().pointSprite; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 880 | default: |
| 881 | return false; |
| 882 | } |
| 883 | } |
| 884 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 885 | // Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section |
| 886 | // 3.1. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 887 | bool IsValidESSLCharacter(unsigned char c) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 888 | { |
| 889 | // Printing characters are valid except " $ ` @ \ ' DEL. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 890 | if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' && |
| 891 | c != '\'') |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 892 | { |
| 893 | return true; |
| 894 | } |
| 895 | |
| 896 | // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid. |
| 897 | if (c >= 9 && c <= 13) |
| 898 | { |
| 899 | return true; |
| 900 | } |
| 901 | |
| 902 | return false; |
| 903 | } |
| 904 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 905 | bool IsValidESSLString(const char *str, size_t len) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 906 | { |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 907 | for (size_t i = 0; i < len; i++) |
| 908 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 909 | if (!IsValidESSLCharacter(str[i])) |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 910 | { |
| 911 | return false; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | return true; |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 916 | } |
| 917 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 918 | bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed) |
| 919 | { |
| 920 | enum class ParseState |
| 921 | { |
| 922 | // Have not seen an ASCII non-whitespace character yet on |
| 923 | // this line. Possible that we might see a preprocessor |
| 924 | // directive. |
| 925 | BEGINING_OF_LINE, |
| 926 | |
| 927 | // Have seen at least one ASCII non-whitespace character |
| 928 | // on this line. |
| 929 | MIDDLE_OF_LINE, |
| 930 | |
| 931 | // Handling a preprocessor directive. Passes through all |
| 932 | // characters up to the end of the line. Disables comment |
| 933 | // processing. |
| 934 | IN_PREPROCESSOR_DIRECTIVE, |
| 935 | |
| 936 | // Handling a single-line comment. The comment text is |
| 937 | // replaced with a single space. |
| 938 | IN_SINGLE_LINE_COMMENT, |
| 939 | |
| 940 | // Handling a multi-line comment. Newlines are passed |
| 941 | // through to preserve line numbers. |
| 942 | IN_MULTI_LINE_COMMENT |
| 943 | }; |
| 944 | |
| 945 | ParseState state = ParseState::BEGINING_OF_LINE; |
| 946 | size_t pos = 0; |
| 947 | |
| 948 | while (pos < len) |
| 949 | { |
| 950 | char c = str[pos]; |
| 951 | char next = pos + 1 < len ? str[pos + 1] : 0; |
| 952 | |
| 953 | // Check for newlines |
| 954 | if (c == '\n' || c == '\r') |
| 955 | { |
| 956 | if (state != ParseState::IN_MULTI_LINE_COMMENT) |
| 957 | { |
| 958 | state = ParseState::BEGINING_OF_LINE; |
| 959 | } |
| 960 | |
| 961 | pos++; |
| 962 | continue; |
| 963 | } |
| 964 | |
| 965 | switch (state) |
| 966 | { |
| 967 | case ParseState::BEGINING_OF_LINE: |
| 968 | if (c == ' ') |
| 969 | { |
| 970 | // Maintain the BEGINING_OF_LINE state until a non-space is seen |
| 971 | pos++; |
| 972 | } |
| 973 | else if (c == '#') |
| 974 | { |
| 975 | state = ParseState::IN_PREPROCESSOR_DIRECTIVE; |
| 976 | pos++; |
| 977 | } |
| 978 | else |
| 979 | { |
| 980 | // Don't advance, re-process this character with the MIDDLE_OF_LINE state |
| 981 | state = ParseState::MIDDLE_OF_LINE; |
| 982 | } |
| 983 | break; |
| 984 | |
| 985 | case ParseState::MIDDLE_OF_LINE: |
| 986 | if (c == '/' && next == '/') |
| 987 | { |
| 988 | state = ParseState::IN_SINGLE_LINE_COMMENT; |
| 989 | pos++; |
| 990 | } |
| 991 | else if (c == '/' && next == '*') |
| 992 | { |
| 993 | state = ParseState::IN_MULTI_LINE_COMMENT; |
| 994 | pos++; |
| 995 | } |
| 996 | else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r')) |
| 997 | { |
| 998 | // Skip line continuation characters |
| 999 | } |
| 1000 | else if (!IsValidESSLCharacter(c)) |
| 1001 | { |
| 1002 | return false; |
| 1003 | } |
| 1004 | pos++; |
| 1005 | break; |
| 1006 | |
| 1007 | case ParseState::IN_PREPROCESSOR_DIRECTIVE: |
Bryan Bernhart (Intel Americas Inc) | 335d8bf | 2017-10-23 15:41:43 -0700 | [diff] [blame] | 1008 | // Line-continuation characters may not be permitted. |
| 1009 | // Otherwise, just pass it through. Do not parse comments in this state. |
| 1010 | if (!lineContinuationAllowed && c == '\\') |
| 1011 | { |
| 1012 | return false; |
| 1013 | } |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 1014 | pos++; |
| 1015 | break; |
| 1016 | |
| 1017 | case ParseState::IN_SINGLE_LINE_COMMENT: |
| 1018 | // Line-continuation characters are processed before comment processing. |
| 1019 | // Advance string if a new line character is immediately behind |
| 1020 | // line-continuation character. |
| 1021 | if (c == '\\' && (next == '\n' || next == '\r')) |
| 1022 | { |
| 1023 | pos++; |
| 1024 | } |
| 1025 | pos++; |
| 1026 | break; |
| 1027 | |
| 1028 | case ParseState::IN_MULTI_LINE_COMMENT: |
| 1029 | if (c == '*' && next == '/') |
| 1030 | { |
| 1031 | state = ParseState::MIDDLE_OF_LINE; |
| 1032 | pos++; |
| 1033 | } |
| 1034 | pos++; |
| 1035 | break; |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | return true; |
| 1040 | } |
| 1041 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1042 | bool ValidateWebGLNamePrefix(Context *context, const GLchar *name) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1043 | { |
| 1044 | ASSERT(context->isWebGL()); |
| 1045 | |
| 1046 | // WebGL 1.0 [Section 6.16] GLSL Constructs |
| 1047 | // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL. |
| 1048 | if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0) |
| 1049 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1050 | context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1051 | return false; |
| 1052 | } |
| 1053 | |
| 1054 | return true; |
| 1055 | } |
| 1056 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1057 | bool ValidateWebGLNameLength(Context *context, size_t length) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1058 | { |
| 1059 | ASSERT(context->isWebGL()); |
| 1060 | |
| 1061 | if (context->isWebGL1() && length > 256) |
| 1062 | { |
| 1063 | // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths |
| 1064 | // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute |
| 1065 | // locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1066 | context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1067 | |
| 1068 | return false; |
| 1069 | } |
| 1070 | else if (length > 1024) |
| 1071 | { |
| 1072 | // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of |
| 1073 | // uniform and attribute locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1074 | context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1075 | return false; |
| 1076 | } |
| 1077 | |
| 1078 | return true; |
| 1079 | } |
| 1080 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1081 | bool ValidateMatrixMode(Context *context, GLenum matrixMode) |
| 1082 | { |
| 1083 | if (!context->getExtensions().pathRendering) |
| 1084 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1085 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1086 | return false; |
| 1087 | } |
| 1088 | |
| 1089 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 1090 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1091 | context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1092 | return false; |
| 1093 | } |
| 1094 | return true; |
| 1095 | } |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 1096 | |
| 1097 | bool ValidBlendFunc(const Context *context, GLenum val) |
| 1098 | { |
| 1099 | const gl::Extensions &ext = context->getExtensions(); |
| 1100 | |
| 1101 | // these are always valid for src and dst. |
| 1102 | switch (val) |
| 1103 | { |
| 1104 | case GL_ZERO: |
| 1105 | case GL_ONE: |
| 1106 | case GL_SRC_COLOR: |
| 1107 | case GL_ONE_MINUS_SRC_COLOR: |
| 1108 | case GL_DST_COLOR: |
| 1109 | case GL_ONE_MINUS_DST_COLOR: |
| 1110 | case GL_SRC_ALPHA: |
| 1111 | case GL_ONE_MINUS_SRC_ALPHA: |
| 1112 | case GL_DST_ALPHA: |
| 1113 | case GL_ONE_MINUS_DST_ALPHA: |
| 1114 | case GL_CONSTANT_COLOR: |
| 1115 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 1116 | case GL_CONSTANT_ALPHA: |
| 1117 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 1118 | return true; |
| 1119 | |
| 1120 | // EXT_blend_func_extended. |
| 1121 | case GL_SRC1_COLOR_EXT: |
| 1122 | case GL_SRC1_ALPHA_EXT: |
| 1123 | case GL_ONE_MINUS_SRC1_COLOR_EXT: |
| 1124 | case GL_ONE_MINUS_SRC1_ALPHA_EXT: |
| 1125 | case GL_SRC_ALPHA_SATURATE_EXT: |
| 1126 | return ext.blendFuncExtended; |
| 1127 | |
| 1128 | default: |
| 1129 | return false; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | bool ValidSrcBlendFunc(const Context *context, GLenum val) |
| 1134 | { |
| 1135 | if (ValidBlendFunc(context, val)) |
| 1136 | return true; |
| 1137 | |
| 1138 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1139 | return true; |
| 1140 | |
| 1141 | return false; |
| 1142 | } |
| 1143 | |
| 1144 | bool ValidDstBlendFunc(const Context *context, GLenum val) |
| 1145 | { |
| 1146 | if (ValidBlendFunc(context, val)) |
| 1147 | return true; |
| 1148 | |
| 1149 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1150 | { |
| 1151 | if (context->getClientMajorVersion() >= 3) |
| 1152 | return true; |
| 1153 | } |
| 1154 | |
| 1155 | return false; |
| 1156 | } |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 1157 | |
| 1158 | bool IsValidImageLayout(ImageLayout layout) |
| 1159 | { |
| 1160 | switch (layout) |
| 1161 | { |
Michael Spang | 6c824a1 | 2019-06-18 15:43:33 -0400 | [diff] [blame] | 1162 | case ImageLayout::Undefined: |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 1163 | case ImageLayout::General: |
| 1164 | case ImageLayout::ColorAttachment: |
| 1165 | case ImageLayout::DepthStencilAttachment: |
| 1166 | case ImageLayout::DepthStencilReadOnlyAttachment: |
| 1167 | case ImageLayout::ShaderReadOnly: |
| 1168 | case ImageLayout::TransferSrc: |
| 1169 | case ImageLayout::TransferDst: |
| 1170 | case ImageLayout::DepthReadOnlyStencilAttachment: |
| 1171 | case ImageLayout::DepthAttachmentStencilReadOnly: |
| 1172 | return true; |
| 1173 | |
| 1174 | default: |
| 1175 | return false; |
| 1176 | } |
| 1177 | } |
| 1178 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1179 | bool ValidateES2TexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1180 | TextureTarget target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1181 | GLint level, |
| 1182 | GLenum internalformat, |
| 1183 | bool isCompressed, |
| 1184 | bool isSubImage, |
| 1185 | GLint xoffset, |
| 1186 | GLint yoffset, |
| 1187 | GLsizei width, |
| 1188 | GLsizei height, |
| 1189 | GLint border, |
| 1190 | GLenum format, |
| 1191 | GLenum type, |
| 1192 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1193 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1194 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1195 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1196 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1197 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1198 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1199 | } |
| 1200 | |
Geoff Lang | 857880e | 2019-05-27 13:39:15 -0400 | [diff] [blame] | 1201 | return ValidateES2TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 1202 | isSubImage, xoffset, yoffset, width, height, border, |
| 1203 | format, type, imageSize, pixels); |
| 1204 | } |
| 1205 | |
| 1206 | } // anonymous namespace |
| 1207 | |
| 1208 | bool ValidateES2TexImageParametersBase(Context *context, |
| 1209 | TextureTarget target, |
| 1210 | GLint level, |
| 1211 | GLenum internalformat, |
| 1212 | bool isCompressed, |
| 1213 | bool isSubImage, |
| 1214 | GLint xoffset, |
| 1215 | GLint yoffset, |
| 1216 | GLsizei width, |
| 1217 | GLsizei height, |
| 1218 | GLint border, |
| 1219 | GLenum format, |
| 1220 | GLenum type, |
| 1221 | GLsizei imageSize, |
| 1222 | const void *pixels) |
| 1223 | { |
| 1224 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1225 | TextureType texType = TextureTargetToType(target); |
| 1226 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1227 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1228 | // Error already handled. |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1229 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1232 | if (!ValidMipLevel(context, texType, level)) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1233 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1234 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1235 | return false; |
| 1236 | } |
| 1237 | |
| 1238 | if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width || |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1239 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1240 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1241 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1242 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1243 | } |
| 1244 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1245 | const gl::Caps &caps = context->getCaps(); |
| 1246 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1247 | switch (texType) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1248 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1249 | case TextureType::_2D: |
Geoff Lang | 857880e | 2019-05-27 13:39:15 -0400 | [diff] [blame] | 1250 | case TextureType::External: |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1251 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 1252 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> 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; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1258 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1259 | case TextureType::Rectangle: |
| 1260 | ASSERT(level == 0); |
| 1261 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1262 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1263 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1264 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1265 | return false; |
| 1266 | } |
| 1267 | if (isCompressed) |
| 1268 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1269 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1270 | return false; |
| 1271 | } |
| 1272 | break; |
| 1273 | |
| 1274 | case TextureType::CubeMap: |
| 1275 | if (!isSubImage && width != height) |
| 1276 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1277 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1278 | return false; |
| 1279 | } |
| 1280 | |
| 1281 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 1282 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 1283 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1284 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1285 | return false; |
| 1286 | } |
| 1287 | break; |
| 1288 | |
| 1289 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1290 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1291 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1292 | } |
| 1293 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 1294 | gl::Texture *texture = context->getTextureByType(texType); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1295 | if (!texture) |
| 1296 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1297 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1298 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1299 | } |
| 1300 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1301 | // Verify zero border |
| 1302 | if (border != 0) |
| 1303 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1304 | context->validationError(GL_INVALID_VALUE, kInvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1305 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1306 | } |
| 1307 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1308 | bool nonEqualFormatsAllowed = false; |
| 1309 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1310 | if (isCompressed) |
| 1311 | { |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1312 | GLenum actualInternalFormat = |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1313 | isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat |
| 1314 | : internalformat; |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1315 | |
| 1316 | const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat); |
| 1317 | |
| 1318 | if (!internalFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1319 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1320 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1321 | return false; |
| 1322 | } |
| 1323 | |
| 1324 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), |
| 1325 | context->getExtensions())) |
| 1326 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1327 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1328 | return false; |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1329 | } |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1330 | |
| 1331 | if (isSubImage) |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1332 | { |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1333 | // From the OES_compressed_ETC1_RGB8_texture spec: |
| 1334 | // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or |
| 1335 | // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format |
| 1336 | // ETC1_RGB8_OES. |
| 1337 | if (actualInternalFormat == GL_ETC1_RGB8_OES) |
| 1338 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1339 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1340 | return false; |
| 1341 | } |
| 1342 | |
Geoff Lang | d9c1710 | 2019-07-10 14:56:26 -0400 | [diff] [blame] | 1343 | if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, 0, |
| 1344 | width, height, 1, texture->getWidth(target, level), |
| 1345 | texture->getHeight(target, level), |
| 1346 | texture->getDepth(target, level))) |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1347 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1348 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1349 | return false; |
| 1350 | } |
| 1351 | |
| 1352 | if (format != actualInternalFormat) |
| 1353 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1354 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1355 | return false; |
| 1356 | } |
| 1357 | } |
| 1358 | else |
| 1359 | { |
Geoff Lang | d9c1710 | 2019-07-10 14:56:26 -0400 | [diff] [blame] | 1360 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height, 1)) |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1361 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1362 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1363 | return false; |
| 1364 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | else |
| 1368 | { |
| 1369 | // validate <type> by itself (used as secondary key below) |
| 1370 | switch (type) |
| 1371 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1372 | case GL_UNSIGNED_BYTE: |
| 1373 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1374 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1375 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1376 | case GL_UNSIGNED_SHORT: |
| 1377 | case GL_UNSIGNED_INT: |
| 1378 | case GL_UNSIGNED_INT_24_8_OES: |
| 1379 | case GL_HALF_FLOAT_OES: |
| 1380 | case GL_FLOAT: |
| 1381 | break; |
Jaedon Lee | 3b46885 | 2019-07-30 16:50:36 +0900 | [diff] [blame] | 1382 | case GL_UNSIGNED_INT_2_10_10_10_REV_EXT: |
| 1383 | if (!context->getExtensions().textureFormat2101010REV) |
| 1384 | { |
| 1385 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1386 | return false; |
| 1387 | } |
| 1388 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1389 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1390 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1391 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | // validate <format> + <type> combinations |
| 1395 | // - invalid <format> -> sets INVALID_ENUM |
| 1396 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 1397 | switch (format) |
| 1398 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1399 | case GL_ALPHA: |
| 1400 | case GL_LUMINANCE: |
| 1401 | case GL_LUMINANCE_ALPHA: |
| 1402 | switch (type) |
| 1403 | { |
| 1404 | case GL_UNSIGNED_BYTE: |
| 1405 | case GL_FLOAT: |
| 1406 | case GL_HALF_FLOAT_OES: |
| 1407 | break; |
| 1408 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1409 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1410 | return false; |
| 1411 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1412 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1413 | case GL_RED: |
| 1414 | case GL_RG: |
| 1415 | if (!context->getExtensions().textureRG) |
| 1416 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1417 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1418 | return false; |
| 1419 | } |
| 1420 | switch (type) |
| 1421 | { |
| 1422 | case GL_UNSIGNED_BYTE: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1423 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1424 | case GL_FLOAT: |
| 1425 | case GL_HALF_FLOAT_OES: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1426 | if (!context->getExtensions().textureFloat) |
| 1427 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1428 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1429 | return false; |
| 1430 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1431 | break; |
| 1432 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1433 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1434 | return false; |
| 1435 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1436 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1437 | case GL_RGB: |
| 1438 | switch (type) |
| 1439 | { |
| 1440 | case GL_UNSIGNED_BYTE: |
| 1441 | case GL_UNSIGNED_SHORT_5_6_5: |
Jaedon Lee | 3b46885 | 2019-07-30 16:50:36 +0900 | [diff] [blame] | 1442 | case GL_UNSIGNED_INT_2_10_10_10_REV_EXT: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1443 | case GL_FLOAT: |
| 1444 | case GL_HALF_FLOAT_OES: |
| 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 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1450 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1451 | case GL_RGBA: |
| 1452 | switch (type) |
| 1453 | { |
| 1454 | case GL_UNSIGNED_BYTE: |
| 1455 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1456 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1457 | case GL_FLOAT: |
| 1458 | case GL_HALF_FLOAT_OES: |
Jaedon Lee | 3b46885 | 2019-07-30 16:50:36 +0900 | [diff] [blame] | 1459 | case GL_UNSIGNED_INT_2_10_10_10_REV_EXT: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1460 | break; |
| 1461 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1462 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1463 | return false; |
| 1464 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1465 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1466 | case GL_BGRA_EXT: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1467 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1468 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1469 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1470 | return false; |
| 1471 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1472 | switch (type) |
| 1473 | { |
| 1474 | case GL_UNSIGNED_BYTE: |
| 1475 | break; |
| 1476 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1477 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1478 | return false; |
| 1479 | } |
| 1480 | break; |
| 1481 | case GL_SRGB_EXT: |
| 1482 | case GL_SRGB_ALPHA_EXT: |
| 1483 | if (!context->getExtensions().sRGB) |
| 1484 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1485 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1486 | return false; |
| 1487 | } |
| 1488 | switch (type) |
| 1489 | { |
| 1490 | case GL_UNSIGNED_BYTE: |
| 1491 | break; |
| 1492 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1493 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1494 | return false; |
| 1495 | } |
| 1496 | break; |
| 1497 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1498 | // handled below |
| 1499 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1500 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1501 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1502 | break; |
| 1503 | case GL_DEPTH_COMPONENT: |
| 1504 | switch (type) |
| 1505 | { |
| 1506 | case GL_UNSIGNED_SHORT: |
| 1507 | case GL_UNSIGNED_INT: |
| 1508 | break; |
| 1509 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1510 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1511 | return false; |
| 1512 | } |
| 1513 | break; |
| 1514 | case GL_DEPTH_STENCIL_OES: |
| 1515 | switch (type) |
| 1516 | { |
| 1517 | case GL_UNSIGNED_INT_24_8_OES: |
| 1518 | break; |
| 1519 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1520 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1521 | return false; |
| 1522 | } |
| 1523 | break; |
| 1524 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1525 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1526 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | switch (format) |
| 1530 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1531 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1532 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1533 | if (context->getExtensions().textureCompressionDXT1) |
| 1534 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1535 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1536 | return false; |
| 1537 | } |
| 1538 | else |
| 1539 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1540 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1541 | return false; |
| 1542 | } |
| 1543 | break; |
| 1544 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1545 | if (context->getExtensions().textureCompressionDXT3) |
| 1546 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1547 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1548 | return false; |
| 1549 | } |
| 1550 | else |
| 1551 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1552 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1553 | return false; |
| 1554 | } |
| 1555 | break; |
| 1556 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1557 | if (context->getExtensions().textureCompressionDXT5) |
| 1558 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1559 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1560 | return false; |
| 1561 | } |
| 1562 | else |
| 1563 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1564 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1565 | return false; |
| 1566 | } |
| 1567 | break; |
| 1568 | case GL_ETC1_RGB8_OES: |
| 1569 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1570 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1571 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1572 | return false; |
| 1573 | } |
| 1574 | else |
| 1575 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1576 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1577 | return false; |
| 1578 | } |
| 1579 | break; |
| 1580 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1581 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1582 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1583 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1584 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1585 | if (context->getExtensions().lossyETCDecode) |
| 1586 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1587 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1588 | return false; |
| 1589 | } |
| 1590 | else |
| 1591 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1592 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1593 | return false; |
| 1594 | } |
| 1595 | break; |
Le Quyen | 6e65398 | 2019-10-09 15:19:02 +0800 | [diff] [blame^] | 1596 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 1597 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 1598 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
| 1599 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: |
| 1600 | if (context->getExtensions().compressedTexturePVRTC) |
| 1601 | { |
| 1602 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
| 1603 | return false; |
| 1604 | } |
| 1605 | else |
| 1606 | { |
| 1607 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1608 | return false; |
| 1609 | } |
| 1610 | break; |
| 1611 | case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT: |
| 1612 | case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT: |
| 1613 | case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT: |
| 1614 | case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT: |
| 1615 | if (context->getExtensions().compressedTexturePVRTCsRGB) |
| 1616 | { |
| 1617 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
| 1618 | return false; |
| 1619 | } |
| 1620 | else |
| 1621 | { |
| 1622 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1623 | return false; |
| 1624 | } |
| 1625 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1626 | case GL_DEPTH_COMPONENT: |
| 1627 | case GL_DEPTH_STENCIL_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1628 | if (!context->getExtensions().depthTextureANGLE && |
| 1629 | !(context->getExtensions().packedDepthStencil && |
| 1630 | context->getExtensions().depthTextureOES)) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1631 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1632 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1633 | return false; |
| 1634 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1635 | if (target != TextureTarget::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1636 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1637 | context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1638 | return false; |
| 1639 | } |
| 1640 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1641 | // but ANGLE_depth_texture does not |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1642 | if (!context->getExtensions().depthTextureOES) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1643 | { |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1644 | if (pixels != nullptr) |
| 1645 | { |
| 1646 | context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull); |
| 1647 | return false; |
| 1648 | } |
| 1649 | if (level != 0) |
| 1650 | { |
| 1651 | context->validationError(GL_INVALID_OPERATION, kLevelNotZero); |
| 1652 | return false; |
| 1653 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1654 | } |
| 1655 | break; |
| 1656 | default: |
| 1657 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1658 | } |
| 1659 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1660 | if (!isSubImage) |
| 1661 | { |
| 1662 | switch (internalformat) |
| 1663 | { |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1664 | // Core ES 2.0 formats |
| 1665 | case GL_ALPHA: |
| 1666 | case GL_LUMINANCE: |
| 1667 | case GL_LUMINANCE_ALPHA: |
| 1668 | case GL_RGB: |
| 1669 | case GL_RGBA: |
| 1670 | break; |
| 1671 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1672 | case GL_RGBA32F: |
| 1673 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1674 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1675 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1676 | return false; |
| 1677 | } |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1678 | |
| 1679 | nonEqualFormatsAllowed = true; |
| 1680 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1681 | if (type != GL_FLOAT) |
| 1682 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1683 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1684 | return false; |
| 1685 | } |
| 1686 | if (format != GL_RGBA) |
| 1687 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1688 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1689 | return false; |
| 1690 | } |
| 1691 | break; |
| 1692 | |
| 1693 | case GL_RGB32F: |
| 1694 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1695 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1696 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1697 | return false; |
| 1698 | } |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1699 | |
| 1700 | nonEqualFormatsAllowed = true; |
| 1701 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1702 | if (type != GL_FLOAT) |
| 1703 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1704 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1705 | return false; |
| 1706 | } |
| 1707 | if (format != GL_RGB) |
| 1708 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1709 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1710 | return false; |
| 1711 | } |
| 1712 | break; |
| 1713 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1714 | case GL_BGRA_EXT: |
| 1715 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1716 | { |
| 1717 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1718 | return false; |
| 1719 | } |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1720 | break; |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1721 | |
| 1722 | case GL_DEPTH_COMPONENT: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1723 | if (!(context->getExtensions().depthTextureAny())) |
| 1724 | { |
| 1725 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1726 | return false; |
| 1727 | } |
| 1728 | break; |
| 1729 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1730 | case GL_DEPTH_STENCIL: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1731 | if (!(context->getExtensions().depthTextureANGLE || |
| 1732 | context->getExtensions().packedDepthStencil)) |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1733 | { |
| 1734 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1735 | return false; |
| 1736 | } |
| 1737 | break; |
| 1738 | |
| 1739 | case GL_RED: |
| 1740 | case GL_RG: |
| 1741 | if (!context->getExtensions().textureRG) |
| 1742 | { |
| 1743 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1744 | return false; |
| 1745 | } |
| 1746 | break; |
| 1747 | |
| 1748 | case GL_SRGB_EXT: |
| 1749 | case GL_SRGB_ALPHA_EXT: |
| 1750 | if (!context->getExtensions().sRGB) |
| 1751 | { |
| 1752 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1753 | return false; |
| 1754 | } |
| 1755 | break; |
| 1756 | |
Jaedon Lee | 3b46885 | 2019-07-30 16:50:36 +0900 | [diff] [blame] | 1757 | case GL_RGB10_A2_EXT: |
| 1758 | if (!context->getExtensions().textureFormat2101010REV) |
| 1759 | { |
| 1760 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1761 | return false; |
| 1762 | } |
| 1763 | |
| 1764 | if (type != GL_UNSIGNED_INT_2_10_10_10_REV_EXT || format != GL_RGBA) |
| 1765 | { |
| 1766 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
| 1767 | return false; |
| 1768 | } |
| 1769 | |
| 1770 | nonEqualFormatsAllowed = true; |
| 1771 | |
| 1772 | break; |
| 1773 | |
| 1774 | case GL_RGB5_A1: |
| 1775 | if (context->getExtensions().textureFormat2101010REV && |
| 1776 | type == GL_UNSIGNED_INT_2_10_10_10_REV_EXT && format == GL_RGBA) |
| 1777 | { |
| 1778 | nonEqualFormatsAllowed = true; |
| 1779 | } |
| 1780 | |
| 1781 | break; |
| 1782 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1783 | default: |
| 1784 | context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat); |
| 1785 | return false; |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1786 | } |
| 1787 | } |
| 1788 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1789 | if (type == GL_FLOAT) |
| 1790 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1791 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1792 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1793 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1794 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | else if (type == GL_HALF_FLOAT_OES) |
| 1798 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1799 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1800 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1801 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1802 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1803 | } |
| 1804 | } |
| 1805 | } |
| 1806 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1807 | if (isSubImage) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1808 | { |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1809 | const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info; |
| 1810 | if (textureInternalFormat.internalFormat == GL_NONE) |
| 1811 | { |
| 1812 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel); |
| 1813 | return false; |
| 1814 | } |
| 1815 | |
Tim Van Patten | 5f388c2 | 2019-03-14 09:54:23 -0600 | [diff] [blame] | 1816 | if (format != textureInternalFormat.format) |
| 1817 | { |
| 1818 | context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch); |
| 1819 | return false; |
| 1820 | } |
| 1821 | |
| 1822 | if (context->getExtensions().webglCompatibility) |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1823 | { |
| 1824 | if (GetInternalFormatInfo(format, type).sizedInternalFormat != |
| 1825 | textureInternalFormat.sizedInternalFormat) |
| 1826 | { |
Tim Van Patten | 5f388c2 | 2019-03-14 09:54:23 -0600 | [diff] [blame] | 1827 | context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch); |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1828 | return false; |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1833 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 1834 | { |
| 1835 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
| 1836 | return false; |
| 1837 | } |
| 1838 | |
| 1839 | if (width > 0 && height > 0 && pixels == nullptr && |
| 1840 | context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr) |
| 1841 | { |
| 1842 | context->validationError(GL_INVALID_VALUE, kPixelDataNull); |
| 1843 | return false; |
| 1844 | } |
| 1845 | } |
| 1846 | else |
| 1847 | { |
| 1848 | if (texture->getImmutableFormat()) |
| 1849 | { |
| 1850 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
| 1851 | return false; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | // From GL_CHROMIUM_color_buffer_float_rgb[a]: |
| 1856 | // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for |
| 1857 | // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the |
| 1858 | // internalformat parameter and format parameter of TexImage2D must match is lifted for this |
| 1859 | // case. |
| 1860 | if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed) |
| 1861 | { |
| 1862 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1863 | return false; |
| 1864 | } |
| 1865 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1866 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
| 1867 | return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels, |
| 1868 | imageSize); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1869 | } |
| 1870 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1871 | bool ValidateES2TexStorageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1872 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1873 | GLsizei levels, |
| 1874 | GLenum internalformat, |
| 1875 | GLsizei width, |
| 1876 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1877 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1878 | if (target != TextureType::_2D && target != TextureType::CubeMap && |
| 1879 | target != TextureType::Rectangle) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1880 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1881 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1882 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | if (width < 1 || height < 1 || levels < 1) |
| 1886 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1887 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1888 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1889 | } |
| 1890 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1891 | if (target == TextureType::CubeMap && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1892 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1893 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1894 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1898 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1899 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1900 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1901 | } |
| 1902 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1903 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1904 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1905 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1906 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1907 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1908 | } |
| 1909 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1910 | const gl::Caps &caps = context->getCaps(); |
| 1911 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1912 | switch (target) |
| 1913 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1914 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1915 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1916 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1917 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1918 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1919 | return false; |
| 1920 | } |
| 1921 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1922 | case TextureType::Rectangle: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1923 | if (levels != 1) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1924 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1925 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1926 | return false; |
| 1927 | } |
| 1928 | |
| 1929 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1930 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1931 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1932 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1933 | return false; |
| 1934 | } |
| 1935 | if (formatInfo.compressed) |
| 1936 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1937 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1938 | return false; |
| 1939 | } |
| 1940 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1941 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1942 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1943 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1944 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1945 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1946 | return false; |
| 1947 | } |
| 1948 | break; |
| 1949 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1950 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1951 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1952 | } |
| 1953 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1954 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1955 | { |
| 1956 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1957 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1958 | context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1959 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | switch (internalformat) |
| 1964 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1965 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1966 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1967 | if (!context->getExtensions().textureCompressionDXT1) |
| 1968 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1969 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1970 | return false; |
| 1971 | } |
| 1972 | break; |
| 1973 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1974 | if (!context->getExtensions().textureCompressionDXT3) |
| 1975 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1976 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1977 | return false; |
| 1978 | } |
| 1979 | break; |
| 1980 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1981 | if (!context->getExtensions().textureCompressionDXT5) |
| 1982 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1983 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1984 | return false; |
| 1985 | } |
| 1986 | break; |
| 1987 | case GL_ETC1_RGB8_OES: |
| 1988 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1989 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1990 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1991 | return false; |
| 1992 | } |
| 1993 | break; |
| 1994 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1995 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1996 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1997 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1998 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1999 | if (!context->getExtensions().lossyETCDecode) |
| 2000 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2001 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2002 | return false; |
| 2003 | } |
| 2004 | break; |
Le Quyen | 6e65398 | 2019-10-09 15:19:02 +0800 | [diff] [blame^] | 2005 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 2006 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 2007 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
| 2008 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: |
| 2009 | if (!context->getExtensions().compressedTexturePVRTC) |
| 2010 | { |
| 2011 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 2012 | return false; |
| 2013 | } |
| 2014 | break; |
| 2015 | case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT: |
| 2016 | case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT: |
| 2017 | case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT: |
| 2018 | case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT: |
| 2019 | if (!context->getExtensions().compressedTexturePVRTCsRGB) |
| 2020 | { |
| 2021 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 2022 | return false; |
| 2023 | } |
| 2024 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2025 | case GL_RGBA32F_EXT: |
| 2026 | case GL_RGB32F_EXT: |
| 2027 | case GL_ALPHA32F_EXT: |
| 2028 | case GL_LUMINANCE32F_EXT: |
| 2029 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 2030 | if (!context->getExtensions().textureFloat) |
| 2031 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2032 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2033 | return false; |
| 2034 | } |
| 2035 | break; |
| 2036 | case GL_RGBA16F_EXT: |
| 2037 | case GL_RGB16F_EXT: |
| 2038 | case GL_ALPHA16F_EXT: |
| 2039 | case GL_LUMINANCE16F_EXT: |
| 2040 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 2041 | if (!context->getExtensions().textureHalfFloat) |
| 2042 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2043 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2044 | return false; |
| 2045 | } |
| 2046 | break; |
| 2047 | case GL_R8_EXT: |
| 2048 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2049 | if (!context->getExtensions().textureRG) |
| 2050 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2051 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2052 | return false; |
| 2053 | } |
| 2054 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2055 | case GL_R16F_EXT: |
| 2056 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2057 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 2058 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2059 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2060 | return false; |
| 2061 | } |
| 2062 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2063 | case GL_R32F_EXT: |
| 2064 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2065 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2066 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2067 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2068 | return false; |
| 2069 | } |
| 2070 | break; |
| 2071 | case GL_DEPTH_COMPONENT16: |
| 2072 | case GL_DEPTH_COMPONENT32_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 2073 | if (!(context->getExtensions().depthTextureAny())) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2074 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2075 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2076 | return false; |
| 2077 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2078 | if (target != TextureType::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2079 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2080 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2081 | return false; |
| 2082 | } |
| 2083 | // ANGLE_depth_texture only supports 1-level textures |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 2084 | if (!context->getExtensions().depthTextureOES) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2085 | { |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 2086 | if (levels != 1) |
| 2087 | { |
| 2088 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
| 2089 | return false; |
| 2090 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2091 | } |
| 2092 | break; |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 2093 | case GL_DEPTH24_STENCIL8_OES: |
| 2094 | if (!(context->getExtensions().depthTextureANGLE || |
| 2095 | (context->getExtensions().packedDepthStencil && |
| 2096 | context->getExtensions().textureStorage))) |
| 2097 | { |
| 2098 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 2099 | return false; |
| 2100 | } |
| 2101 | if (target != TextureType::_2D) |
| 2102 | { |
| 2103 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
| 2104 | return false; |
| 2105 | } |
| 2106 | if (!context->getExtensions().packedDepthStencil) |
| 2107 | { |
| 2108 | // ANGLE_depth_texture only supports 1-level textures |
| 2109 | if (levels != 1) |
| 2110 | { |
| 2111 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
| 2112 | return false; |
| 2113 | } |
| 2114 | } |
| 2115 | break; |
| 2116 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2117 | default: |
| 2118 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2119 | } |
| 2120 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 2121 | gl::Texture *texture = context->getTextureByType(target); |
Jamie Madill | f703443 | 2019-09-21 14:10:35 -0400 | [diff] [blame] | 2122 | if (!texture || texture->id().value == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2123 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2124 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2125 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2126 | } |
| 2127 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2128 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2129 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2130 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2131 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | return true; |
| 2135 | } |
| 2136 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2137 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 2138 | GLenum target, |
| 2139 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2140 | const GLenum *attachments) |
| 2141 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2142 | if (!context->getExtensions().discardFramebuffer) |
| 2143 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2144 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2145 | return false; |
| 2146 | } |
| 2147 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2148 | bool defaultFramebuffer = false; |
| 2149 | |
| 2150 | switch (target) |
| 2151 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2152 | case GL_FRAMEBUFFER: |
| 2153 | defaultFramebuffer = |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 2154 | (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->isDefault()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2155 | break; |
| 2156 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2157 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2158 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2161 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 2162 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2165 | bool ValidateBindVertexArrayOES(Context *context, VertexArrayID array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2166 | { |
| 2167 | if (!context->getExtensions().vertexArrayObject) |
| 2168 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2169 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2170 | return false; |
| 2171 | } |
| 2172 | |
| 2173 | return ValidateBindVertexArrayBase(context, array); |
| 2174 | } |
| 2175 | |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2176 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const VertexArrayID *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2177 | { |
| 2178 | if (!context->getExtensions().vertexArrayObject) |
| 2179 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2180 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2181 | return false; |
| 2182 | } |
| 2183 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2184 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2187 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n, VertexArrayID *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2188 | { |
| 2189 | if (!context->getExtensions().vertexArrayObject) |
| 2190 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2191 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2192 | return false; |
| 2193 | } |
| 2194 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2195 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2198 | bool ValidateIsVertexArrayOES(Context *context, VertexArrayID array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2199 | { |
| 2200 | if (!context->getExtensions().vertexArrayObject) |
| 2201 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2202 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2203 | return false; |
| 2204 | } |
| 2205 | |
| 2206 | return true; |
| 2207 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2208 | |
| 2209 | bool ValidateProgramBinaryOES(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 2210 | ShaderProgramID program, |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2211 | GLenum binaryFormat, |
| 2212 | const void *binary, |
| 2213 | GLint length) |
| 2214 | { |
| 2215 | if (!context->getExtensions().getProgramBinary) |
| 2216 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2217 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2218 | return false; |
| 2219 | } |
| 2220 | |
| 2221 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 2222 | } |
| 2223 | |
| 2224 | bool ValidateGetProgramBinaryOES(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 2225 | ShaderProgramID program, |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2226 | GLsizei bufSize, |
| 2227 | GLsizei *length, |
| 2228 | GLenum *binaryFormat, |
| 2229 | void *binary) |
| 2230 | { |
| 2231 | if (!context->getExtensions().getProgramBinary) |
| 2232 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2233 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2234 | return false; |
| 2235 | } |
| 2236 | |
| 2237 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 2238 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2239 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2240 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 2241 | { |
| 2242 | switch (source) |
| 2243 | { |
| 2244 | case GL_DEBUG_SOURCE_API: |
| 2245 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 2246 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 2247 | case GL_DEBUG_SOURCE_OTHER: |
| 2248 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 2249 | return !mustBeThirdPartyOrApplication; |
| 2250 | |
| 2251 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 2252 | case GL_DEBUG_SOURCE_APPLICATION: |
| 2253 | return true; |
| 2254 | |
| 2255 | default: |
| 2256 | return false; |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | static bool ValidDebugType(GLenum type) |
| 2261 | { |
| 2262 | switch (type) |
| 2263 | { |
| 2264 | case GL_DEBUG_TYPE_ERROR: |
| 2265 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 2266 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 2267 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 2268 | case GL_DEBUG_TYPE_PORTABILITY: |
| 2269 | case GL_DEBUG_TYPE_OTHER: |
| 2270 | case GL_DEBUG_TYPE_MARKER: |
| 2271 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 2272 | case GL_DEBUG_TYPE_POP_GROUP: |
| 2273 | return true; |
| 2274 | |
| 2275 | default: |
| 2276 | return false; |
| 2277 | } |
| 2278 | } |
| 2279 | |
| 2280 | static bool ValidDebugSeverity(GLenum severity) |
| 2281 | { |
| 2282 | switch (severity) |
| 2283 | { |
| 2284 | case GL_DEBUG_SEVERITY_HIGH: |
| 2285 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 2286 | case GL_DEBUG_SEVERITY_LOW: |
| 2287 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 2288 | return true; |
| 2289 | |
| 2290 | default: |
| 2291 | return false; |
| 2292 | } |
| 2293 | } |
| 2294 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2295 | bool ValidateDebugMessageControlKHR(Context *context, |
| 2296 | GLenum source, |
| 2297 | GLenum type, |
| 2298 | GLenum severity, |
| 2299 | GLsizei count, |
| 2300 | const GLuint *ids, |
| 2301 | GLboolean enabled) |
| 2302 | { |
| 2303 | if (!context->getExtensions().debug) |
| 2304 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2305 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2306 | return false; |
| 2307 | } |
| 2308 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2309 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 2310 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2311 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2312 | return false; |
| 2313 | } |
| 2314 | |
| 2315 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 2316 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2317 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2318 | return false; |
| 2319 | } |
| 2320 | |
| 2321 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 2322 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2323 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2324 | return false; |
| 2325 | } |
| 2326 | |
| 2327 | if (count > 0) |
| 2328 | { |
| 2329 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 2330 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2331 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2332 | return false; |
| 2333 | } |
| 2334 | |
| 2335 | if (severity != GL_DONT_CARE) |
| 2336 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2337 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2338 | return false; |
| 2339 | } |
| 2340 | } |
| 2341 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2342 | return true; |
| 2343 | } |
| 2344 | |
| 2345 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 2346 | GLenum source, |
| 2347 | GLenum type, |
| 2348 | GLuint id, |
| 2349 | GLenum severity, |
| 2350 | GLsizei length, |
| 2351 | const GLchar *buf) |
| 2352 | { |
| 2353 | if (!context->getExtensions().debug) |
| 2354 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2355 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2356 | return false; |
| 2357 | } |
| 2358 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2359 | if (!context->getState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2360 | { |
| 2361 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 2362 | // not generate an error. |
| 2363 | return false; |
| 2364 | } |
| 2365 | |
| 2366 | if (!ValidDebugSeverity(severity)) |
| 2367 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2368 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2369 | return false; |
| 2370 | } |
| 2371 | |
| 2372 | if (!ValidDebugType(type)) |
| 2373 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2374 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2375 | return false; |
| 2376 | } |
| 2377 | |
| 2378 | if (!ValidDebugSource(source, true)) |
| 2379 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2380 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2381 | return false; |
| 2382 | } |
| 2383 | |
| 2384 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 2385 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2386 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2387 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2388 | return false; |
| 2389 | } |
| 2390 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2391 | return true; |
| 2392 | } |
| 2393 | |
| 2394 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 2395 | GLDEBUGPROCKHR callback, |
| 2396 | const void *userParam) |
| 2397 | { |
| 2398 | if (!context->getExtensions().debug) |
| 2399 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2400 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2401 | return false; |
| 2402 | } |
| 2403 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2404 | return true; |
| 2405 | } |
| 2406 | |
| 2407 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 2408 | GLuint count, |
| 2409 | GLsizei bufSize, |
| 2410 | GLenum *sources, |
| 2411 | GLenum *types, |
| 2412 | GLuint *ids, |
| 2413 | GLenum *severities, |
| 2414 | GLsizei *lengths, |
| 2415 | GLchar *messageLog) |
| 2416 | { |
| 2417 | if (!context->getExtensions().debug) |
| 2418 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2419 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2420 | return false; |
| 2421 | } |
| 2422 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2423 | if (bufSize < 0 && messageLog != nullptr) |
| 2424 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2425 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2426 | return false; |
| 2427 | } |
| 2428 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2429 | return true; |
| 2430 | } |
| 2431 | |
| 2432 | bool ValidatePushDebugGroupKHR(Context *context, |
| 2433 | GLenum source, |
| 2434 | GLuint id, |
| 2435 | GLsizei length, |
| 2436 | const GLchar *message) |
| 2437 | { |
| 2438 | if (!context->getExtensions().debug) |
| 2439 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2440 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2441 | return false; |
| 2442 | } |
| 2443 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2444 | if (!ValidDebugSource(source, true)) |
| 2445 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2446 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2447 | return false; |
| 2448 | } |
| 2449 | |
| 2450 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 2451 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2452 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2453 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2454 | return false; |
| 2455 | } |
| 2456 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2457 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2458 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 2459 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2460 | context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2461 | return false; |
| 2462 | } |
| 2463 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2464 | return true; |
| 2465 | } |
| 2466 | |
| 2467 | bool ValidatePopDebugGroupKHR(Context *context) |
| 2468 | { |
| 2469 | if (!context->getExtensions().debug) |
| 2470 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2471 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2472 | return false; |
| 2473 | } |
| 2474 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2475 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2476 | if (currentStackSize <= 1) |
| 2477 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2478 | context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2479 | return false; |
| 2480 | } |
| 2481 | |
| 2482 | return true; |
| 2483 | } |
| 2484 | |
| 2485 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 2486 | { |
| 2487 | switch (identifier) |
| 2488 | { |
| 2489 | case GL_BUFFER: |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 2490 | if (context->getBuffer({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2491 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2492 | context->validationError(GL_INVALID_VALUE, kInvalidBufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2493 | return false; |
| 2494 | } |
| 2495 | return true; |
| 2496 | |
| 2497 | case GL_SHADER: |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 2498 | if (context->getShader({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2499 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2500 | context->validationError(GL_INVALID_VALUE, kInvalidShaderName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2501 | return false; |
| 2502 | } |
| 2503 | return true; |
| 2504 | |
| 2505 | case GL_PROGRAM: |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 2506 | if (context->getProgramNoResolveLink({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2507 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2508 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2509 | return false; |
| 2510 | } |
| 2511 | return true; |
| 2512 | |
| 2513 | case GL_VERTEX_ARRAY: |
Jiacheng Lu | feb8507 | 2019-09-03 13:22:04 -0400 | [diff] [blame] | 2514 | if (context->getVertexArray({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2515 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2516 | context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2517 | return false; |
| 2518 | } |
| 2519 | return true; |
| 2520 | |
| 2521 | case GL_QUERY: |
Jiacheng Lu | 814a0a1 | 2019-08-22 11:50:43 -0600 | [diff] [blame] | 2522 | if (context->getQuery({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2523 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2524 | context->validationError(GL_INVALID_VALUE, kInvalidQueryName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2525 | return false; |
| 2526 | } |
| 2527 | return true; |
| 2528 | |
| 2529 | case GL_TRANSFORM_FEEDBACK: |
Jiacheng Lu | c3f7873 | 2019-08-30 15:00:52 -0600 | [diff] [blame] | 2530 | if (context->getTransformFeedback({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2531 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2532 | context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2533 | return false; |
| 2534 | } |
| 2535 | return true; |
| 2536 | |
| 2537 | case GL_SAMPLER: |
Jiacheng Lu | ee79e2f | 2019-08-20 11:28:36 -0600 | [diff] [blame] | 2538 | if (context->getSampler({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2539 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2540 | context->validationError(GL_INVALID_VALUE, kInvalidSamplerName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2541 | return false; |
| 2542 | } |
| 2543 | return true; |
| 2544 | |
| 2545 | case GL_TEXTURE: |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 2546 | if (context->getTexture({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2547 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2548 | context->validationError(GL_INVALID_VALUE, kInvalidTextureName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2549 | return false; |
| 2550 | } |
| 2551 | return true; |
| 2552 | |
| 2553 | case GL_RENDERBUFFER: |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 2554 | if (!context->isRenderbuffer({name})) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2555 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2556 | context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2557 | return false; |
| 2558 | } |
| 2559 | return true; |
| 2560 | |
| 2561 | case GL_FRAMEBUFFER: |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 2562 | if (context->getFramebuffer({name}) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2563 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2564 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2565 | return false; |
| 2566 | } |
| 2567 | return true; |
| 2568 | |
| 2569 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2570 | context->validationError(GL_INVALID_ENUM, kInvalidIndentifier); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2571 | return false; |
| 2572 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2573 | } |
| 2574 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2575 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2576 | { |
| 2577 | size_t labelLength = 0; |
| 2578 | |
| 2579 | if (length < 0) |
| 2580 | { |
| 2581 | if (label != nullptr) |
| 2582 | { |
| 2583 | labelLength = strlen(label); |
| 2584 | } |
| 2585 | } |
| 2586 | else |
| 2587 | { |
| 2588 | labelLength = static_cast<size_t>(length); |
| 2589 | } |
| 2590 | |
| 2591 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2592 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2593 | context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2594 | return false; |
| 2595 | } |
| 2596 | |
| 2597 | return true; |
| 2598 | } |
| 2599 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2600 | bool ValidateObjectLabelKHR(Context *context, |
| 2601 | GLenum identifier, |
| 2602 | GLuint name, |
| 2603 | GLsizei length, |
| 2604 | const GLchar *label) |
| 2605 | { |
| 2606 | if (!context->getExtensions().debug) |
| 2607 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2608 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2609 | return false; |
| 2610 | } |
| 2611 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2612 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2613 | { |
| 2614 | return false; |
| 2615 | } |
| 2616 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2617 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2618 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2619 | return false; |
| 2620 | } |
| 2621 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2622 | return true; |
| 2623 | } |
| 2624 | |
| 2625 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2626 | GLenum identifier, |
| 2627 | GLuint name, |
| 2628 | GLsizei bufSize, |
| 2629 | GLsizei *length, |
| 2630 | GLchar *label) |
| 2631 | { |
| 2632 | if (!context->getExtensions().debug) |
| 2633 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2634 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2635 | return false; |
| 2636 | } |
| 2637 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2638 | if (bufSize < 0) |
| 2639 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2640 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2641 | return false; |
| 2642 | } |
| 2643 | |
| 2644 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2645 | { |
| 2646 | return false; |
| 2647 | } |
| 2648 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2649 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2653 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 2654 | if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2655 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2656 | context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2657 | return false; |
| 2658 | } |
| 2659 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2660 | return true; |
| 2661 | } |
| 2662 | |
| 2663 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2664 | const void *ptr, |
| 2665 | GLsizei length, |
| 2666 | const GLchar *label) |
| 2667 | { |
| 2668 | if (!context->getExtensions().debug) |
| 2669 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2670 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2671 | return false; |
| 2672 | } |
| 2673 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2674 | if (!ValidateObjectPtrName(context, ptr)) |
| 2675 | { |
| 2676 | return false; |
| 2677 | } |
| 2678 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2679 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2680 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2681 | return false; |
| 2682 | } |
| 2683 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2684 | return true; |
| 2685 | } |
| 2686 | |
| 2687 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2688 | const void *ptr, |
| 2689 | GLsizei bufSize, |
| 2690 | GLsizei *length, |
| 2691 | GLchar *label) |
| 2692 | { |
| 2693 | if (!context->getExtensions().debug) |
| 2694 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2695 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2696 | return false; |
| 2697 | } |
| 2698 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2699 | if (bufSize < 0) |
| 2700 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2701 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2702 | return false; |
| 2703 | } |
| 2704 | |
| 2705 | if (!ValidateObjectPtrName(context, ptr)) |
| 2706 | { |
| 2707 | return false; |
| 2708 | } |
| 2709 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2710 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2714 | { |
| 2715 | if (!context->getExtensions().debug) |
| 2716 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2717 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2718 | return false; |
| 2719 | } |
| 2720 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2721 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2722 | switch (pname) |
| 2723 | { |
| 2724 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2725 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2726 | break; |
| 2727 | |
| 2728 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2729 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2730 | return false; |
| 2731 | } |
| 2732 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2733 | return true; |
| 2734 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2735 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 2736 | bool ValidateGetPointervRobustANGLERobustANGLE(Context *context, |
| 2737 | GLenum pname, |
| 2738 | GLsizei bufSize, |
| 2739 | GLsizei *length, |
| 2740 | void **params) |
| 2741 | { |
| 2742 | UNIMPLEMENTED(); |
| 2743 | return false; |
| 2744 | } |
| 2745 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2746 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2747 | GLint srcX0, |
| 2748 | GLint srcY0, |
| 2749 | GLint srcX1, |
| 2750 | GLint srcY1, |
| 2751 | GLint dstX0, |
| 2752 | GLint dstY0, |
| 2753 | GLint dstX1, |
| 2754 | GLint dstY1, |
| 2755 | GLbitfield mask, |
| 2756 | GLenum filter) |
| 2757 | { |
| 2758 | if (!context->getExtensions().framebufferBlit) |
| 2759 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2760 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2761 | return false; |
| 2762 | } |
| 2763 | |
| 2764 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2765 | { |
| 2766 | // TODO(jmadill): Determine if this should be available on other implementations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2767 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2768 | return false; |
| 2769 | } |
| 2770 | |
| 2771 | if (filter == GL_LINEAR) |
| 2772 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2773 | context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2774 | return false; |
| 2775 | } |
| 2776 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2777 | Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 2778 | Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2779 | |
| 2780 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2781 | { |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 2782 | const FramebufferAttachment *readColorAttachment = |
| 2783 | readFramebuffer->getReadColorAttachment(); |
| 2784 | const FramebufferAttachment *drawColorAttachment = |
| 2785 | drawFramebuffer->getFirstColorAttachment(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2786 | |
| 2787 | if (readColorAttachment && drawColorAttachment) |
| 2788 | { |
| 2789 | if (!(readColorAttachment->type() == GL_TEXTURE && |
Kenneth Russell | cbdf861 | 2019-07-09 20:30:45 -0700 | [diff] [blame] | 2790 | (readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D || |
| 2791 | readColorAttachment->getTextureImageIndex().getType() == |
| 2792 | TextureType::Rectangle)) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2793 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2794 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2795 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2796 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2797 | kBlitExtensionFromInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2798 | return false; |
| 2799 | } |
| 2800 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2801 | for (size_t drawbufferIdx = 0; |
| 2802 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2803 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2804 | const FramebufferAttachment *attachment = |
| 2805 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2806 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2807 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2808 | if (!(attachment->type() == GL_TEXTURE && |
Kenneth Russell | cbdf861 | 2019-07-09 20:30:45 -0700 | [diff] [blame] | 2809 | (attachment->getTextureImageIndex().getType() == TextureType::_2D || |
| 2810 | attachment->getTextureImageIndex().getType() == |
| 2811 | TextureType::Rectangle)) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2812 | attachment->type() != GL_RENDERBUFFER && |
| 2813 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2814 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2815 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2816 | kBlitExtensionToInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2817 | return false; |
| 2818 | } |
| 2819 | |
| 2820 | // Return an error if the destination formats do not match |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 2821 | if (!Format::EquivalentForBlit(attachment->getFormat(), |
| 2822 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2823 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2824 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2825 | kBlitExtensionFormatMismatch); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2826 | return false; |
| 2827 | } |
| 2828 | } |
| 2829 | } |
| 2830 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2831 | GLint samples = readFramebuffer->getSamples(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2832 | if (samples != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2833 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2834 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2835 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2836 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2837 | kBlitExtensionMultisampledWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2838 | return false; |
| 2839 | } |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2844 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2845 | for (size_t i = 0; i < 2; i++) |
| 2846 | { |
| 2847 | if (mask & masks[i]) |
| 2848 | { |
| 2849 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2850 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2851 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2852 | drawFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2853 | |
| 2854 | if (readBuffer && drawBuffer) |
| 2855 | { |
| 2856 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2857 | dstX0, dstY0, dstX1, dstY1)) |
| 2858 | { |
| 2859 | // only whole-buffer copies are permitted |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2860 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2861 | kBlitExtensionDepthStencilWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2862 | return false; |
| 2863 | } |
| 2864 | |
| 2865 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2866 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2867 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2868 | kBlitExtensionMultisampledDepthOrStencil); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2869 | return false; |
| 2870 | } |
| 2871 | } |
| 2872 | } |
| 2873 | } |
| 2874 | |
| 2875 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2876 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2877 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2878 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2879 | bool ValidateClear(Context *context, GLbitfield mask) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2880 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2881 | Framebuffer *fbo = context->getState().getDrawFramebuffer(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2882 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2883 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2884 | if (!ValidateFramebufferComplete(context, fbo)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2885 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2886 | return false; |
| 2887 | } |
| 2888 | |
| 2889 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2890 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2891 | context->validationError(GL_INVALID_VALUE, kInvalidClearMask); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2892 | return false; |
| 2893 | } |
| 2894 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2895 | if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2896 | { |
| 2897 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2898 | GL_SIGNED_NORMALIZED}; |
| 2899 | |
Corentin Wallez | 59c4159 | 2017-07-11 13:19:54 -0400 | [diff] [blame] | 2900 | for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2901 | drawBufferIdx++) |
| 2902 | { |
| 2903 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2904 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2905 | { |
| 2906 | return false; |
| 2907 | } |
| 2908 | } |
| 2909 | } |
| 2910 | |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame] | 2911 | if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery) |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2912 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2913 | const State &state = context->getState(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2914 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2915 | if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed)) |
| 2916 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2917 | context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2918 | return false; |
| 2919 | } |
| 2920 | } |
| 2921 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2922 | return true; |
| 2923 | } |
| 2924 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2925 | bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2926 | { |
| 2927 | if (!context->getExtensions().drawBuffers) |
| 2928 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2929 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2930 | return false; |
| 2931 | } |
| 2932 | |
| 2933 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2934 | } |
| 2935 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2936 | bool ValidateTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2937 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2938 | GLint level, |
| 2939 | GLint internalformat, |
| 2940 | GLsizei width, |
| 2941 | GLsizei height, |
| 2942 | GLint border, |
| 2943 | GLenum format, |
| 2944 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2945 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2946 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2947 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2948 | { |
| 2949 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2950 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2951 | } |
| 2952 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2953 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2954 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2955 | 0, 0, width, height, 1, border, format, type, -1, |
| 2956 | pixels); |
| 2957 | } |
| 2958 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 2959 | bool ValidateTexImage2DRobustANGLE(Context *context, |
| 2960 | TextureTarget target, |
| 2961 | GLint level, |
| 2962 | GLint internalformat, |
| 2963 | GLsizei width, |
| 2964 | GLsizei height, |
| 2965 | GLint border, |
| 2966 | GLenum format, |
| 2967 | GLenum type, |
| 2968 | GLsizei bufSize, |
| 2969 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2970 | { |
| 2971 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2972 | { |
| 2973 | return false; |
| 2974 | } |
| 2975 | |
| 2976 | if (context->getClientMajorVersion() < 3) |
| 2977 | { |
| 2978 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2979 | 0, 0, width, height, border, format, type, bufSize, |
| 2980 | pixels); |
| 2981 | } |
| 2982 | |
| 2983 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2984 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2985 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2986 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | bool ValidateTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2990 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2991 | GLint level, |
| 2992 | GLint xoffset, |
| 2993 | GLint yoffset, |
| 2994 | GLsizei width, |
| 2995 | GLsizei height, |
| 2996 | GLenum format, |
| 2997 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2998 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2999 | { |
| 3000 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3001 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3002 | { |
| 3003 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3004 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3005 | } |
| 3006 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3007 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3008 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3009 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 3010 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3011 | } |
| 3012 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 3013 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3014 | TextureTarget target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 3015 | GLint level, |
| 3016 | GLint xoffset, |
| 3017 | GLint yoffset, |
| 3018 | GLsizei width, |
| 3019 | GLsizei height, |
| 3020 | GLenum format, |
| 3021 | GLenum type, |
| 3022 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3023 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 3024 | { |
| 3025 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3026 | { |
| 3027 | return false; |
| 3028 | } |
| 3029 | |
| 3030 | if (context->getClientMajorVersion() < 3) |
| 3031 | { |
| 3032 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 3033 | yoffset, width, height, 0, format, type, bufSize, |
| 3034 | pixels); |
| 3035 | } |
| 3036 | |
| 3037 | ASSERT(context->getClientMajorVersion() >= 3); |
| 3038 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 3039 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 3040 | pixels); |
| 3041 | } |
| 3042 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 3043 | bool ValidateTexSubImage3DOES(Context *context, |
| 3044 | TextureTarget target, |
| 3045 | GLint level, |
| 3046 | GLint xoffset, |
| 3047 | GLint yoffset, |
| 3048 | GLint zoffset, |
| 3049 | GLsizei width, |
| 3050 | GLsizei height, |
| 3051 | GLsizei depth, |
| 3052 | GLenum format, |
| 3053 | GLenum type, |
| 3054 | const void *pixels) |
| 3055 | { |
| 3056 | return ValidateTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, height, |
| 3057 | depth, format, type, pixels); |
| 3058 | } |
| 3059 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3060 | bool ValidateCompressedTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3061 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3062 | GLint level, |
| 3063 | GLenum internalformat, |
| 3064 | GLsizei width, |
| 3065 | GLsizei height, |
| 3066 | GLint border, |
| 3067 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3068 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3069 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3070 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3071 | { |
| 3072 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3073 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3074 | { |
| 3075 | return false; |
| 3076 | } |
| 3077 | } |
| 3078 | else |
| 3079 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3080 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3081 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3082 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3083 | data)) |
| 3084 | { |
| 3085 | return false; |
| 3086 | } |
| 3087 | } |
| 3088 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3089 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3090 | |
| 3091 | GLuint blockSize = 0; |
| 3092 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3093 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3094 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3095 | return false; |
| 3096 | } |
| 3097 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3098 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3099 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3100 | context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3101 | return false; |
| 3102 | } |
| 3103 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3104 | if (target == TextureTarget::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 3105 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3106 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 3107 | return false; |
| 3108 | } |
| 3109 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3110 | return true; |
| 3111 | } |
| 3112 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3113 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3114 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3115 | GLint level, |
| 3116 | GLenum internalformat, |
| 3117 | GLsizei width, |
| 3118 | GLsizei height, |
| 3119 | GLint border, |
| 3120 | GLsizei imageSize, |
| 3121 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3122 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3123 | { |
| 3124 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 3125 | { |
| 3126 | return false; |
| 3127 | } |
| 3128 | |
| 3129 | return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 3130 | border, imageSize, data); |
| 3131 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3132 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 3133 | bool ValidateCompressedTexImage3DOES(Context *context, |
| 3134 | TextureTarget target, |
| 3135 | GLint level, |
| 3136 | GLenum internalformat, |
| 3137 | GLsizei width, |
| 3138 | GLsizei height, |
| 3139 | GLsizei depth, |
| 3140 | GLint border, |
| 3141 | GLsizei imageSize, |
| 3142 | const void *data) |
| 3143 | { |
| 3144 | return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height, |
| 3145 | depth, border, imageSize, data); |
| 3146 | } |
| 3147 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3148 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3149 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3150 | GLint level, |
| 3151 | GLint xoffset, |
| 3152 | GLint yoffset, |
| 3153 | GLsizei width, |
| 3154 | GLsizei height, |
| 3155 | GLenum format, |
| 3156 | GLsizei imageSize, |
| 3157 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3158 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 3159 | { |
| 3160 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 3161 | { |
| 3162 | return false; |
| 3163 | } |
| 3164 | |
| 3165 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 3166 | format, imageSize, data); |
| 3167 | } |
| 3168 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3169 | bool ValidateCompressedTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3170 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3171 | GLint level, |
| 3172 | GLint xoffset, |
| 3173 | GLint yoffset, |
| 3174 | GLsizei width, |
| 3175 | GLsizei height, |
| 3176 | GLenum format, |
| 3177 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3178 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3179 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3180 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3181 | { |
| 3182 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 3183 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3184 | { |
| 3185 | return false; |
| 3186 | } |
| 3187 | } |
| 3188 | else |
| 3189 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3190 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3191 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 3192 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3193 | data)) |
| 3194 | { |
| 3195 | return false; |
| 3196 | } |
| 3197 | } |
| 3198 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3199 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3200 | GLuint blockSize = 0; |
| 3201 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3202 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3203 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3204 | return false; |
| 3205 | } |
| 3206 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3207 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3208 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3209 | context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3210 | return false; |
| 3211 | } |
| 3212 | |
| 3213 | return true; |
| 3214 | } |
| 3215 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 3216 | bool ValidateCompressedTexSubImage3DOES(Context *context, |
| 3217 | TextureTarget target, |
| 3218 | GLint level, |
| 3219 | GLint xoffset, |
| 3220 | GLint yoffset, |
| 3221 | GLint zoffset, |
| 3222 | GLsizei width, |
| 3223 | GLsizei height, |
| 3224 | GLsizei depth, |
| 3225 | GLenum format, |
| 3226 | GLsizei imageSize, |
| 3227 | const void *data) |
| 3228 | { |
| 3229 | return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, |
| 3230 | height, depth, format, imageSize, data); |
| 3231 | } |
| 3232 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3233 | bool ValidateGetBufferPointervOES(Context *context, |
| 3234 | BufferBinding target, |
| 3235 | GLenum pname, |
| 3236 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3237 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3238 | if (!context->getExtensions().mapBuffer) |
| 3239 | { |
| 3240 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3241 | return false; |
| 3242 | } |
| 3243 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3244 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3245 | } |
| 3246 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3247 | bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3248 | { |
| 3249 | if (!context->getExtensions().mapBuffer) |
| 3250 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3251 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3252 | return false; |
| 3253 | } |
| 3254 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3255 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3256 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3257 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3258 | return false; |
| 3259 | } |
| 3260 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3261 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3262 | |
| 3263 | if (buffer == nullptr) |
| 3264 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3265 | context->validationError(GL_INVALID_OPERATION, kBufferNotMappable); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3266 | return false; |
| 3267 | } |
| 3268 | |
| 3269 | if (access != GL_WRITE_ONLY_OES) |
| 3270 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3271 | context->validationError(GL_INVALID_ENUM, kInvalidAccessBits); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3272 | return false; |
| 3273 | } |
| 3274 | |
| 3275 | if (buffer->isMapped()) |
| 3276 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3277 | context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3278 | return false; |
| 3279 | } |
| 3280 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3281 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3282 | } |
| 3283 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3284 | bool ValidateUnmapBufferOES(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3285 | { |
| 3286 | if (!context->getExtensions().mapBuffer) |
| 3287 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3288 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3289 | return false; |
| 3290 | } |
| 3291 | |
| 3292 | return ValidateUnmapBufferBase(context, target); |
| 3293 | } |
| 3294 | |
| 3295 | bool ValidateMapBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3296 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3297 | GLintptr offset, |
| 3298 | GLsizeiptr length, |
| 3299 | GLbitfield access) |
| 3300 | { |
| 3301 | if (!context->getExtensions().mapBufferRange) |
| 3302 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3303 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3304 | return false; |
| 3305 | } |
| 3306 | |
| 3307 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 3308 | } |
| 3309 | |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3310 | bool ValidateBufferStorageMemEXT(Context *context, |
| 3311 | TextureType target, |
| 3312 | GLsizeiptr size, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3313 | MemoryObjectID memory, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3314 | GLuint64 offset) |
| 3315 | { |
| 3316 | if (!context->getExtensions().memoryObject) |
| 3317 | { |
| 3318 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3319 | return false; |
| 3320 | } |
| 3321 | |
| 3322 | UNIMPLEMENTED(); |
| 3323 | return false; |
| 3324 | } |
| 3325 | |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3326 | bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, MemoryObjectID *memoryObjects) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3327 | { |
| 3328 | if (!context->getExtensions().memoryObject) |
| 3329 | { |
| 3330 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3331 | return false; |
| 3332 | } |
| 3333 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3334 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3335 | } |
| 3336 | |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3337 | bool ValidateDeleteMemoryObjectsEXT(Context *context, |
| 3338 | GLsizei n, |
| 3339 | const MemoryObjectID *memoryObjects) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3340 | { |
| 3341 | if (!context->getExtensions().memoryObject) |
| 3342 | { |
| 3343 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3344 | return false; |
| 3345 | } |
| 3346 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3347 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | bool ValidateGetMemoryObjectParameterivEXT(Context *context, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3351 | MemoryObjectID memoryObject, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3352 | GLenum pname, |
| 3353 | GLint *params) |
| 3354 | { |
| 3355 | if (!context->getExtensions().memoryObject) |
| 3356 | { |
| 3357 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3358 | return false; |
| 3359 | } |
| 3360 | |
| 3361 | UNIMPLEMENTED(); |
| 3362 | return false; |
| 3363 | } |
| 3364 | |
| 3365 | bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data) |
| 3366 | { |
| 3367 | if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore) |
| 3368 | { |
| 3369 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3370 | return false; |
| 3371 | } |
| 3372 | |
| 3373 | UNIMPLEMENTED(); |
| 3374 | return false; |
| 3375 | } |
| 3376 | |
| 3377 | bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data) |
| 3378 | { |
| 3379 | if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore) |
| 3380 | { |
| 3381 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3382 | return false; |
| 3383 | } |
| 3384 | |
| 3385 | UNIMPLEMENTED(); |
| 3386 | return false; |
| 3387 | } |
| 3388 | |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3389 | bool ValidateIsMemoryObjectEXT(Context *context, MemoryObjectID memoryObject) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3390 | { |
| 3391 | if (!context->getExtensions().memoryObject) |
| 3392 | { |
| 3393 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3394 | return false; |
| 3395 | } |
| 3396 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3397 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | bool ValidateMemoryObjectParameterivEXT(Context *context, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3401 | MemoryObjectID memoryObject, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3402 | GLenum pname, |
| 3403 | const GLint *params) |
| 3404 | { |
| 3405 | if (!context->getExtensions().memoryObject) |
| 3406 | { |
| 3407 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3408 | return false; |
| 3409 | } |
| 3410 | |
| 3411 | UNIMPLEMENTED(); |
| 3412 | return false; |
| 3413 | } |
| 3414 | |
| 3415 | bool ValidateTexStorageMem2DEXT(Context *context, |
| 3416 | TextureType target, |
| 3417 | GLsizei levels, |
| 3418 | GLenum internalFormat, |
| 3419 | GLsizei width, |
| 3420 | GLsizei height, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3421 | MemoryObjectID memory, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3422 | GLuint64 offset) |
| 3423 | { |
| 3424 | if (!context->getExtensions().memoryObject) |
| 3425 | { |
| 3426 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3427 | return false; |
| 3428 | } |
| 3429 | |
Michael Spang | f02a767 | 2019-04-09 18:45:23 -0400 | [diff] [blame] | 3430 | if (context->getClientMajorVersion() < 3) |
| 3431 | { |
| 3432 | return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width, |
| 3433 | height); |
| 3434 | } |
| 3435 | |
| 3436 | ASSERT(context->getClientMajorVersion() >= 3); |
| 3437 | return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height, |
| 3438 | 1); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | bool ValidateTexStorageMem3DEXT(Context *context, |
| 3442 | TextureType target, |
| 3443 | GLsizei levels, |
| 3444 | GLenum internalFormat, |
| 3445 | GLsizei width, |
| 3446 | GLsizei height, |
| 3447 | GLsizei depth, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3448 | MemoryObjectID memory, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3449 | GLuint64 offset) |
| 3450 | { |
| 3451 | if (!context->getExtensions().memoryObject) |
| 3452 | { |
| 3453 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3454 | return false; |
| 3455 | } |
| 3456 | |
| 3457 | UNIMPLEMENTED(); |
| 3458 | return false; |
| 3459 | } |
| 3460 | |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3461 | bool ValidateImportMemoryFdEXT(Context *context, |
Jiacheng Lu | 9deb3bf | 2019-08-23 15:57:50 -0600 | [diff] [blame] | 3462 | MemoryObjectID memory, |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3463 | GLuint64 size, |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3464 | HandleType handleType, |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3465 | GLint fd) |
| 3466 | { |
| 3467 | if (!context->getExtensions().memoryObjectFd) |
| 3468 | { |
| 3469 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3470 | return false; |
| 3471 | } |
| 3472 | |
Michael Spang | 3b2c6bf | 2019-04-16 17:19:50 -0400 | [diff] [blame] | 3473 | switch (handleType) |
| 3474 | { |
| 3475 | case HandleType::OpaqueFd: |
| 3476 | break; |
| 3477 | default: |
| 3478 | context->validationError(GL_INVALID_ENUM, kInvalidHandleType); |
| 3479 | return false; |
| 3480 | } |
| 3481 | |
| 3482 | return true; |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3483 | } |
| 3484 | |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3485 | bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const SemaphoreID *semaphores) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3486 | { |
| 3487 | if (!context->getExtensions().semaphore) |
| 3488 | { |
| 3489 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3490 | return false; |
| 3491 | } |
| 3492 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 3493 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3494 | } |
| 3495 | |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3496 | bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, SemaphoreID *semaphores) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3497 | { |
| 3498 | if (!context->getExtensions().semaphore) |
| 3499 | { |
| 3500 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3501 | return false; |
| 3502 | } |
| 3503 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 3504 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | bool ValidateGetSemaphoreParameterui64vEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3508 | SemaphoreID semaphore, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3509 | GLenum pname, |
| 3510 | GLuint64 *params) |
| 3511 | { |
| 3512 | if (!context->getExtensions().semaphore) |
| 3513 | { |
| 3514 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3515 | return false; |
| 3516 | } |
| 3517 | |
| 3518 | UNIMPLEMENTED(); |
| 3519 | return false; |
| 3520 | } |
| 3521 | |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3522 | bool ValidateIsSemaphoreEXT(Context *context, SemaphoreID semaphore) |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3523 | { |
| 3524 | if (!context->getExtensions().semaphore) |
| 3525 | { |
| 3526 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3527 | return false; |
| 3528 | } |
| 3529 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame] | 3530 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | bool ValidateSemaphoreParameterui64vEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3534 | SemaphoreID semaphore, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3535 | GLenum pname, |
| 3536 | const GLuint64 *params) |
| 3537 | { |
| 3538 | if (!context->getExtensions().semaphore) |
| 3539 | { |
| 3540 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3541 | return false; |
| 3542 | } |
| 3543 | |
| 3544 | UNIMPLEMENTED(); |
| 3545 | return false; |
| 3546 | } |
| 3547 | |
| 3548 | bool ValidateSignalSemaphoreEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3549 | SemaphoreID semaphore, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3550 | GLuint numBufferBarriers, |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 3551 | const BufferID *buffers, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3552 | GLuint numTextureBarriers, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 3553 | const TextureID *textures, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3554 | const GLenum *dstLayouts) |
| 3555 | { |
| 3556 | if (!context->getExtensions().semaphore) |
| 3557 | { |
| 3558 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3559 | return false; |
| 3560 | } |
| 3561 | |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 3562 | for (GLuint i = 0; i < numTextureBarriers; ++i) |
| 3563 | { |
| 3564 | if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i]))) |
| 3565 | { |
| 3566 | context->validationError(GL_INVALID_ENUM, kInvalidImageLayout); |
| 3567 | return false; |
| 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | bool ValidateWaitSemaphoreEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3575 | SemaphoreID semaphore, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3576 | GLuint numBufferBarriers, |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 3577 | const BufferID *buffers, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3578 | GLuint numTextureBarriers, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 3579 | const TextureID *textures, |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3580 | const GLenum *srcLayouts) |
| 3581 | { |
| 3582 | if (!context->getExtensions().semaphore) |
| 3583 | { |
| 3584 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3585 | return false; |
| 3586 | } |
| 3587 | |
Michael Spang | ab6a59b | 2019-05-21 21:26:26 -0400 | [diff] [blame] | 3588 | for (GLuint i = 0; i < numTextureBarriers; ++i) |
| 3589 | { |
| 3590 | if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i]))) |
| 3591 | { |
| 3592 | context->validationError(GL_INVALID_ENUM, kInvalidImageLayout); |
| 3593 | return false; |
| 3594 | } |
| 3595 | } |
| 3596 | |
| 3597 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3598 | } |
| 3599 | |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3600 | bool ValidateImportSemaphoreFdEXT(Context *context, |
Jiacheng Lu | f0640bc | 2019-08-23 10:26:25 -0600 | [diff] [blame] | 3601 | SemaphoreID semaphore, |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3602 | HandleType handleType, |
| 3603 | GLint fd) |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3604 | { |
| 3605 | if (!context->getExtensions().semaphoreFd) |
| 3606 | { |
| 3607 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3608 | return false; |
| 3609 | } |
| 3610 | |
Michael Spang | 6bb193c | 2019-05-22 16:32:21 -0400 | [diff] [blame] | 3611 | switch (handleType) |
| 3612 | { |
| 3613 | case HandleType::OpaqueFd: |
| 3614 | break; |
| 3615 | default: |
| 3616 | context->validationError(GL_INVALID_ENUM, kInvalidHandleType); |
| 3617 | return false; |
| 3618 | } |
| 3619 | |
| 3620 | return true; |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3621 | } |
| 3622 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3623 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3624 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3625 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3626 | ASSERT(buffer != nullptr); |
| 3627 | |
| 3628 | // 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] | 3629 | if (context->getState().isTransformFeedbackActive()) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3630 | { |
Shahbaz Youssefi | 8af6c6f | 2019-06-18 15:43:44 -0400 | [diff] [blame] | 3631 | TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback(); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3632 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 3633 | { |
| 3634 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 3635 | if (transformFeedbackBuffer.get() == buffer) |
| 3636 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3637 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3638 | return false; |
| 3639 | } |
| 3640 | } |
| 3641 | } |
| 3642 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3643 | if (context->getExtensions().webglCompatibility && |
| 3644 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3645 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3646 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3647 | return false; |
| 3648 | } |
| 3649 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3650 | return true; |
| 3651 | } |
| 3652 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3653 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3654 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3655 | GLintptr offset, |
| 3656 | GLsizeiptr length) |
| 3657 | { |
| 3658 | if (!context->getExtensions().mapBufferRange) |
| 3659 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3660 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3661 | return false; |
| 3662 | } |
| 3663 | |
| 3664 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 3665 | } |
| 3666 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3667 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 3668 | ShaderProgramID program, |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3669 | GLint location, |
| 3670 | const GLchar *name) |
| 3671 | { |
| 3672 | if (!context->getExtensions().bindUniformLocation) |
| 3673 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3674 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3675 | return false; |
| 3676 | } |
| 3677 | |
| 3678 | Program *programObject = GetValidProgram(context, program); |
| 3679 | if (!programObject) |
| 3680 | { |
| 3681 | return false; |
| 3682 | } |
| 3683 | |
| 3684 | if (location < 0) |
| 3685 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3686 | context->validationError(GL_INVALID_VALUE, kNegativeLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3687 | return false; |
| 3688 | } |
| 3689 | |
| 3690 | const Caps &caps = context->getCaps(); |
| 3691 | if (static_cast<size_t>(location) >= |
| 3692 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3693 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3694 | context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3695 | return false; |
| 3696 | } |
| 3697 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3698 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3699 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3700 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3701 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3702 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3703 | return false; |
| 3704 | } |
| 3705 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3706 | if (strncmp(name, "gl_", 3) == 0) |
| 3707 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3708 | context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3709 | return false; |
| 3710 | } |
| 3711 | |
| 3712 | return true; |
| 3713 | } |
| 3714 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3715 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3716 | { |
| 3717 | if (!context->getExtensions().framebufferMixedSamples) |
| 3718 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3719 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3720 | return false; |
| 3721 | } |
| 3722 | switch (components) |
| 3723 | { |
| 3724 | case GL_RGB: |
| 3725 | case GL_RGBA: |
| 3726 | case GL_ALPHA: |
| 3727 | case GL_NONE: |
| 3728 | break; |
| 3729 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3730 | context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3731 | return false; |
| 3732 | } |
| 3733 | |
| 3734 | return true; |
| 3735 | } |
| 3736 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3737 | // CHROMIUM_path_rendering |
| 3738 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3739 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3740 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3741 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3742 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3743 | return false; |
| 3744 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3745 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3746 | if (matrix == nullptr) |
| 3747 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3748 | context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3749 | return false; |
| 3750 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3751 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3752 | return true; |
| 3753 | } |
| 3754 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3755 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3756 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3757 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3758 | } |
| 3759 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3760 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3761 | { |
| 3762 | if (!context->getExtensions().pathRendering) |
| 3763 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3764 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3765 | return false; |
| 3766 | } |
| 3767 | |
| 3768 | // range = 0 is undefined in NV_path_rendering. |
| 3769 | // we add stricter semantic check here and require a non zero positive range. |
| 3770 | if (range <= 0) |
| 3771 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3772 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3773 | return false; |
| 3774 | } |
| 3775 | |
| 3776 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3777 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3778 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3779 | return false; |
| 3780 | } |
| 3781 | |
| 3782 | return true; |
| 3783 | } |
| 3784 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3785 | bool ValidateDeletePathsCHROMIUM(Context *context, PathID path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3786 | { |
| 3787 | if (!context->getExtensions().pathRendering) |
| 3788 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3789 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3790 | return false; |
| 3791 | } |
| 3792 | |
| 3793 | // range = 0 is undefined in NV_path_rendering. |
| 3794 | // we add stricter semantic check here and require a non zero positive range. |
| 3795 | if (range <= 0) |
| 3796 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3797 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3798 | return false; |
| 3799 | } |
| 3800 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3801 | angle::CheckedNumeric<std::uint32_t> checkedRange(path.value); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3802 | checkedRange += range; |
| 3803 | |
| 3804 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3805 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3806 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3807 | return false; |
| 3808 | } |
| 3809 | return true; |
| 3810 | } |
| 3811 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3812 | bool ValidatePathCommandsCHROMIUM(Context *context, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3813 | PathID path, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3814 | GLsizei numCommands, |
| 3815 | const GLubyte *commands, |
| 3816 | GLsizei numCoords, |
| 3817 | GLenum coordType, |
| 3818 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3819 | { |
| 3820 | if (!context->getExtensions().pathRendering) |
| 3821 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3822 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3823 | return false; |
| 3824 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3825 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3826 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3827 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3828 | return false; |
| 3829 | } |
| 3830 | |
| 3831 | if (numCommands < 0) |
| 3832 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3833 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3834 | return false; |
| 3835 | } |
| 3836 | else if (numCommands > 0) |
| 3837 | { |
| 3838 | if (!commands) |
| 3839 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3840 | context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3841 | return false; |
| 3842 | } |
| 3843 | } |
| 3844 | |
| 3845 | if (numCoords < 0) |
| 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 | else if (numCoords > 0) |
| 3851 | { |
| 3852 | if (!coords) |
| 3853 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3854 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3855 | return false; |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | std::uint32_t coordTypeSize = 0; |
| 3860 | switch (coordType) |
| 3861 | { |
| 3862 | case GL_BYTE: |
| 3863 | coordTypeSize = sizeof(GLbyte); |
| 3864 | break; |
| 3865 | |
| 3866 | case GL_UNSIGNED_BYTE: |
| 3867 | coordTypeSize = sizeof(GLubyte); |
| 3868 | break; |
| 3869 | |
| 3870 | case GL_SHORT: |
| 3871 | coordTypeSize = sizeof(GLshort); |
| 3872 | break; |
| 3873 | |
| 3874 | case GL_UNSIGNED_SHORT: |
| 3875 | coordTypeSize = sizeof(GLushort); |
| 3876 | break; |
| 3877 | |
| 3878 | case GL_FLOAT: |
| 3879 | coordTypeSize = sizeof(GLfloat); |
| 3880 | break; |
| 3881 | |
| 3882 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3883 | context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3884 | return false; |
| 3885 | } |
| 3886 | |
| 3887 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3888 | checkedSize += (coordTypeSize * numCoords); |
| 3889 | if (!checkedSize.IsValid()) |
| 3890 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3891 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3892 | return false; |
| 3893 | } |
| 3894 | |
| 3895 | // early return skips command data validation when it doesn't exist. |
| 3896 | if (!commands) |
| 3897 | return true; |
| 3898 | |
| 3899 | GLsizei expectedNumCoords = 0; |
| 3900 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3901 | { |
| 3902 | switch (commands[i]) |
| 3903 | { |
| 3904 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3905 | break; |
| 3906 | case GL_MOVE_TO_CHROMIUM: |
| 3907 | case GL_LINE_TO_CHROMIUM: |
| 3908 | expectedNumCoords += 2; |
| 3909 | break; |
| 3910 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3911 | expectedNumCoords += 4; |
| 3912 | break; |
| 3913 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3914 | expectedNumCoords += 6; |
| 3915 | break; |
| 3916 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3917 | expectedNumCoords += 5; |
| 3918 | break; |
| 3919 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3920 | context->validationError(GL_INVALID_ENUM, kInvalidPathCommand); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3921 | return false; |
| 3922 | } |
| 3923 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3924 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3925 | if (expectedNumCoords != numCoords) |
| 3926 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3927 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3928 | return false; |
| 3929 | } |
| 3930 | |
| 3931 | return true; |
| 3932 | } |
| 3933 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3934 | bool ValidatePathParameterfCHROMIUM(Context *context, PathID path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3935 | { |
| 3936 | if (!context->getExtensions().pathRendering) |
| 3937 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3938 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3939 | return false; |
| 3940 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3941 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3942 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3943 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3944 | return false; |
| 3945 | } |
| 3946 | |
| 3947 | switch (pname) |
| 3948 | { |
| 3949 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3950 | if (value < 0.0f) |
| 3951 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3952 | context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3953 | return false; |
| 3954 | } |
| 3955 | break; |
| 3956 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3957 | switch (static_cast<GLenum>(value)) |
| 3958 | { |
| 3959 | case GL_FLAT_CHROMIUM: |
| 3960 | case GL_SQUARE_CHROMIUM: |
| 3961 | case GL_ROUND_CHROMIUM: |
| 3962 | break; |
| 3963 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3964 | context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3965 | return false; |
| 3966 | } |
| 3967 | break; |
| 3968 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3969 | switch (static_cast<GLenum>(value)) |
| 3970 | { |
| 3971 | case GL_MITER_REVERT_CHROMIUM: |
| 3972 | case GL_BEVEL_CHROMIUM: |
| 3973 | case GL_ROUND_CHROMIUM: |
| 3974 | break; |
| 3975 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3976 | context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3977 | return false; |
| 3978 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3979 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3980 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3981 | if (value < 0.0f) |
| 3982 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3983 | context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3984 | return false; |
| 3985 | } |
| 3986 | break; |
| 3987 | |
| 3988 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3989 | // no errors, only clamping. |
| 3990 | break; |
| 3991 | |
| 3992 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3993 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3994 | return false; |
| 3995 | } |
| 3996 | return true; |
| 3997 | } |
| 3998 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 3999 | bool ValidatePathParameteriCHROMIUM(Context *context, PathID path, GLenum pname, GLint value) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4000 | { |
| 4001 | // TODO(jmadill): Use proper clamping cast. |
| 4002 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 4003 | } |
| 4004 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4005 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, PathID path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4006 | { |
| 4007 | if (!context->getExtensions().pathRendering) |
| 4008 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4009 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4010 | return false; |
| 4011 | } |
| 4012 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 4013 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4014 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4015 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4016 | return false; |
| 4017 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4018 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4019 | if (!value) |
| 4020 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4021 | context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4022 | return false; |
| 4023 | } |
| 4024 | |
| 4025 | switch (pname) |
| 4026 | { |
| 4027 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 4028 | case GL_PATH_END_CAPS_CHROMIUM: |
| 4029 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 4030 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 4031 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 4032 | break; |
| 4033 | |
| 4034 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4035 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4036 | return false; |
| 4037 | } |
| 4038 | |
| 4039 | return true; |
| 4040 | } |
| 4041 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4042 | bool ValidateGetPathParameterivCHROMIUM(Context *context, PathID path, GLenum pname, GLint *value) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4043 | { |
| 4044 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 4045 | reinterpret_cast<GLfloat *>(value)); |
| 4046 | } |
| 4047 | |
| 4048 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4049 | { |
| 4050 | if (!context->getExtensions().pathRendering) |
| 4051 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4052 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4053 | return false; |
| 4054 | } |
| 4055 | |
| 4056 | switch (func) |
| 4057 | { |
| 4058 | case GL_NEVER: |
| 4059 | case GL_ALWAYS: |
| 4060 | case GL_LESS: |
| 4061 | case GL_LEQUAL: |
| 4062 | case GL_EQUAL: |
| 4063 | case GL_GEQUAL: |
| 4064 | case GL_GREATER: |
| 4065 | case GL_NOTEQUAL: |
| 4066 | break; |
| 4067 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4068 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4069 | return false; |
| 4070 | } |
| 4071 | |
| 4072 | return true; |
| 4073 | } |
| 4074 | |
| 4075 | // Note that the spec specifies that for the path drawing commands |
| 4076 | // if the path object is not an existing path object the command |
| 4077 | // does nothing and no error is generated. |
| 4078 | // However if the path object exists but has not been specified any |
| 4079 | // commands then an error is generated. |
| 4080 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4081 | bool ValidateStencilFillPathCHROMIUM(Context *context, PathID path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4082 | { |
| 4083 | if (!context->getExtensions().pathRendering) |
| 4084 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4085 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4086 | return false; |
| 4087 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 4088 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4089 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4090 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4091 | return false; |
| 4092 | } |
| 4093 | |
| 4094 | switch (fillMode) |
| 4095 | { |
Chris Dalton | a9dfb3b | 2019-06-26 18:36:10 -0600 | [diff] [blame] | 4096 | case GL_INVERT: |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4097 | case GL_COUNT_UP_CHROMIUM: |
| 4098 | case GL_COUNT_DOWN_CHROMIUM: |
| 4099 | break; |
| 4100 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4101 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4102 | return false; |
| 4103 | } |
| 4104 | |
| 4105 | if (!isPow2(mask + 1)) |
| 4106 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4107 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4108 | return false; |
| 4109 | } |
| 4110 | |
| 4111 | return true; |
| 4112 | } |
| 4113 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4114 | bool ValidateStencilStrokePathCHROMIUM(Context *context, PathID path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4115 | { |
| 4116 | if (!context->getExtensions().pathRendering) |
| 4117 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4118 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4119 | return false; |
| 4120 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4121 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 4122 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4123 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4124 | context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4125 | return false; |
| 4126 | } |
| 4127 | |
| 4128 | return true; |
| 4129 | } |
| 4130 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4131 | bool ValidateCoverPathCHROMIUM(Context *context, PathID path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4132 | { |
| 4133 | if (!context->getExtensions().pathRendering) |
| 4134 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4135 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4136 | return false; |
| 4137 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 4138 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4139 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4140 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4141 | return false; |
| 4142 | } |
| 4143 | |
| 4144 | switch (coverMode) |
| 4145 | { |
| 4146 | case GL_CONVEX_HULL_CHROMIUM: |
| 4147 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4148 | break; |
| 4149 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4150 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4151 | return false; |
| 4152 | } |
| 4153 | return true; |
| 4154 | } |
| 4155 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4156 | bool ValidateCoverFillPathCHROMIUM(Context *context, PathID path, GLenum coverMode) |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4157 | { |
| 4158 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 4159 | } |
| 4160 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4161 | bool ValidateCoverStrokePathCHROMIUM(Context *context, PathID path, GLenum coverMode) |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4162 | { |
| 4163 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 4164 | } |
| 4165 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4166 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4167 | PathID path, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4168 | GLenum fillMode, |
| 4169 | GLuint mask, |
| 4170 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4171 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4172 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 4173 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4174 | } |
| 4175 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4176 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4177 | PathID path, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4178 | GLint reference, |
| 4179 | GLuint mask, |
| 4180 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4181 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4182 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 4183 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4184 | } |
| 4185 | |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4186 | bool ValidateIsPathCHROMIUM(Context *context, PathID path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4187 | { |
| 4188 | if (!context->getExtensions().pathRendering) |
| 4189 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4190 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 4191 | return false; |
| 4192 | } |
| 4193 | return true; |
| 4194 | } |
| 4195 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4196 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 4197 | GLsizei numPaths, |
| 4198 | GLenum pathNameType, |
| 4199 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4200 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4201 | GLenum coverMode, |
| 4202 | GLenum transformType, |
| 4203 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4204 | { |
| 4205 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4206 | transformType, transformValues)) |
| 4207 | return false; |
| 4208 | |
| 4209 | switch (coverMode) |
| 4210 | { |
| 4211 | case GL_CONVEX_HULL_CHROMIUM: |
| 4212 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4213 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4214 | break; |
| 4215 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4216 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4217 | return false; |
| 4218 | } |
| 4219 | |
| 4220 | return true; |
| 4221 | } |
| 4222 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4223 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 4224 | GLsizei numPaths, |
| 4225 | GLenum pathNameType, |
| 4226 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4227 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4228 | GLenum coverMode, |
| 4229 | GLenum transformType, |
| 4230 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4231 | { |
| 4232 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4233 | transformType, transformValues)) |
| 4234 | return false; |
| 4235 | |
| 4236 | switch (coverMode) |
| 4237 | { |
| 4238 | case GL_CONVEX_HULL_CHROMIUM: |
| 4239 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4240 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4241 | break; |
| 4242 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4243 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4244 | return false; |
| 4245 | } |
| 4246 | |
| 4247 | return true; |
| 4248 | } |
| 4249 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4250 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 4251 | GLsizei numPaths, |
| 4252 | GLenum pathNameType, |
| 4253 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4254 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4255 | GLenum fillMode, |
| 4256 | GLuint mask, |
| 4257 | GLenum transformType, |
| 4258 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4259 | { |
| 4260 | |
| 4261 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4262 | transformType, transformValues)) |
| 4263 | return false; |
| 4264 | |
| 4265 | switch (fillMode) |
| 4266 | { |
Chris Dalton | a9dfb3b | 2019-06-26 18:36:10 -0600 | [diff] [blame] | 4267 | case GL_INVERT: |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4268 | case GL_COUNT_UP_CHROMIUM: |
| 4269 | case GL_COUNT_DOWN_CHROMIUM: |
| 4270 | break; |
| 4271 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4272 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4273 | return false; |
| 4274 | } |
| 4275 | if (!isPow2(mask + 1)) |
| 4276 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4277 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4278 | return false; |
| 4279 | } |
| 4280 | return true; |
| 4281 | } |
| 4282 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4283 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 4284 | GLsizei numPaths, |
| 4285 | GLenum pathNameType, |
| 4286 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4287 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4288 | GLint reference, |
| 4289 | GLuint mask, |
| 4290 | GLenum transformType, |
| 4291 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4292 | { |
| 4293 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4294 | transformType, transformValues)) |
| 4295 | return false; |
| 4296 | |
| 4297 | // no more validation here. |
| 4298 | |
| 4299 | return true; |
| 4300 | } |
| 4301 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4302 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 4303 | GLsizei numPaths, |
| 4304 | GLenum pathNameType, |
| 4305 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4306 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4307 | GLenum fillMode, |
| 4308 | GLuint mask, |
| 4309 | GLenum coverMode, |
| 4310 | GLenum transformType, |
| 4311 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4312 | { |
| 4313 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4314 | transformType, transformValues)) |
| 4315 | return false; |
| 4316 | |
| 4317 | switch (coverMode) |
| 4318 | { |
| 4319 | case GL_CONVEX_HULL_CHROMIUM: |
| 4320 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4321 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4322 | break; |
| 4323 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4324 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4325 | return false; |
| 4326 | } |
| 4327 | |
| 4328 | switch (fillMode) |
| 4329 | { |
Chris Dalton | a9dfb3b | 2019-06-26 18:36:10 -0600 | [diff] [blame] | 4330 | case GL_INVERT: |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4331 | case GL_COUNT_UP_CHROMIUM: |
| 4332 | case GL_COUNT_DOWN_CHROMIUM: |
| 4333 | break; |
| 4334 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4335 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4336 | return false; |
| 4337 | } |
| 4338 | if (!isPow2(mask + 1)) |
| 4339 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4340 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4341 | return false; |
| 4342 | } |
| 4343 | |
| 4344 | return true; |
| 4345 | } |
| 4346 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4347 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 4348 | GLsizei numPaths, |
| 4349 | GLenum pathNameType, |
| 4350 | const void *paths, |
Jiacheng Lu | 7b5744f | 2019-08-22 16:26:35 -0600 | [diff] [blame] | 4351 | PathID pathBase, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4352 | GLint reference, |
| 4353 | GLuint mask, |
| 4354 | GLenum coverMode, |
| 4355 | GLenum transformType, |
| 4356 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4357 | { |
| 4358 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4359 | transformType, transformValues)) |
| 4360 | return false; |
| 4361 | |
| 4362 | switch (coverMode) |
| 4363 | { |
| 4364 | case GL_CONVEX_HULL_CHROMIUM: |
| 4365 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4366 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4367 | break; |
| 4368 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4369 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4370 | return false; |
| 4371 | } |
| 4372 | |
| 4373 | return true; |
| 4374 | } |
| 4375 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4376 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 4377 | ShaderProgramID program, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4378 | GLint location, |
| 4379 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4380 | { |
| 4381 | if (!context->getExtensions().pathRendering) |
| 4382 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4383 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4384 | return false; |
| 4385 | } |
| 4386 | |
| 4387 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 4388 | if (location >= MaxLocation) |
| 4389 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4390 | context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4391 | return false; |
| 4392 | } |
| 4393 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4394 | const auto *programObject = context->getProgramNoResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4395 | if (!programObject) |
| 4396 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4397 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4398 | return false; |
| 4399 | } |
| 4400 | |
| 4401 | if (!name) |
| 4402 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4403 | context->validationError(GL_INVALID_VALUE, kMissingName); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4404 | return false; |
| 4405 | } |
| 4406 | |
| 4407 | if (angle::BeginsWith(name, "gl_")) |
| 4408 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4409 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4410 | return false; |
| 4411 | } |
| 4412 | |
| 4413 | return true; |
| 4414 | } |
| 4415 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4416 | bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 4417 | ShaderProgramID program, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4418 | GLint location, |
| 4419 | GLenum genMode, |
| 4420 | GLint components, |
| 4421 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4422 | { |
| 4423 | if (!context->getExtensions().pathRendering) |
| 4424 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4425 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4426 | return false; |
| 4427 | } |
| 4428 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4429 | const auto *programObject = context->getProgramResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4430 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 4431 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4432 | context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4433 | return false; |
| 4434 | } |
| 4435 | |
| 4436 | if (!programObject->isLinked()) |
| 4437 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4438 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4439 | return false; |
| 4440 | } |
| 4441 | |
| 4442 | switch (genMode) |
| 4443 | { |
| 4444 | case GL_NONE: |
| 4445 | if (components != 0) |
| 4446 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4447 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4448 | return false; |
| 4449 | } |
| 4450 | break; |
| 4451 | |
| 4452 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 4453 | case GL_EYE_LINEAR_CHROMIUM: |
| 4454 | case GL_CONSTANT_CHROMIUM: |
| 4455 | if (components < 1 || components > 4) |
| 4456 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4457 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4458 | return false; |
| 4459 | } |
| 4460 | if (!coeffs) |
| 4461 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4462 | context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4463 | return false; |
| 4464 | } |
| 4465 | break; |
| 4466 | |
| 4467 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4468 | context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4469 | return false; |
| 4470 | } |
| 4471 | |
| 4472 | // If the location is -1 then the command is silently ignored |
| 4473 | // and no further validation is needed. |
| 4474 | if (location == -1) |
| 4475 | return true; |
| 4476 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 4477 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4478 | |
| 4479 | if (!binding.valid) |
| 4480 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4481 | context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4482 | return false; |
| 4483 | } |
| 4484 | |
| 4485 | if (binding.type != GL_NONE) |
| 4486 | { |
| 4487 | GLint expectedComponents = 0; |
| 4488 | switch (binding.type) |
| 4489 | { |
| 4490 | case GL_FLOAT: |
| 4491 | expectedComponents = 1; |
| 4492 | break; |
| 4493 | case GL_FLOAT_VEC2: |
| 4494 | expectedComponents = 2; |
| 4495 | break; |
| 4496 | case GL_FLOAT_VEC3: |
| 4497 | expectedComponents = 3; |
| 4498 | break; |
| 4499 | case GL_FLOAT_VEC4: |
| 4500 | expectedComponents = 4; |
| 4501 | break; |
| 4502 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4503 | context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4504 | return false; |
| 4505 | } |
| 4506 | if (expectedComponents != components && genMode != GL_NONE) |
| 4507 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4508 | context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4509 | return false; |
| 4510 | } |
| 4511 | } |
| 4512 | return true; |
| 4513 | } |
| 4514 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4515 | bool ValidateCopyTextureCHROMIUM(Context *context, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4516 | TextureID sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4517 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4518 | TextureTarget destTarget, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4519 | TextureID destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4520 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4521 | GLint internalFormat, |
| 4522 | GLenum destType, |
| 4523 | GLboolean unpackFlipY, |
| 4524 | GLboolean unpackPremultiplyAlpha, |
| 4525 | GLboolean unpackUnmultiplyAlpha) |
| 4526 | { |
| 4527 | if (!context->getExtensions().copyTexture) |
| 4528 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4529 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4530 | return false; |
| 4531 | } |
| 4532 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4533 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4534 | if (source == nullptr) |
| 4535 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4536 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4537 | return false; |
| 4538 | } |
| 4539 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4540 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4541 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4542 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4543 | return false; |
| 4544 | } |
| 4545 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4546 | TextureType sourceType = source->getType(); |
| 4547 | ASSERT(sourceType != TextureType::CubeMap); |
| 4548 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4549 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4550 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4551 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4552 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4553 | return false; |
| 4554 | } |
| 4555 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4556 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 4557 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 4558 | if (sourceWidth == 0 || sourceHeight == 0) |
| 4559 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4560 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4561 | return false; |
| 4562 | } |
| 4563 | |
| 4564 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 4565 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4566 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4567 | context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4568 | return false; |
| 4569 | } |
| 4570 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4571 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4572 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4573 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4574 | return false; |
| 4575 | } |
| 4576 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4577 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4578 | if (dest == nullptr) |
| 4579 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4580 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4581 | return false; |
| 4582 | } |
| 4583 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4584 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4585 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4586 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4587 | return false; |
| 4588 | } |
| 4589 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4590 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4591 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4592 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4593 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4594 | return false; |
| 4595 | } |
| 4596 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4597 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 4598 | { |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4599 | return false; |
| 4600 | } |
| 4601 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4602 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4603 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4604 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4605 | return false; |
| 4606 | } |
| 4607 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4608 | if (dest->getImmutableFormat()) |
| 4609 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4610 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4611 | return false; |
| 4612 | } |
| 4613 | |
| 4614 | return true; |
| 4615 | } |
| 4616 | |
| 4617 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4618 | TextureID sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4619 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4620 | TextureTarget destTarget, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4621 | TextureID destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4622 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4623 | GLint xoffset, |
| 4624 | GLint yoffset, |
| 4625 | GLint x, |
| 4626 | GLint y, |
| 4627 | GLsizei width, |
| 4628 | GLsizei height, |
| 4629 | GLboolean unpackFlipY, |
| 4630 | GLboolean unpackPremultiplyAlpha, |
| 4631 | GLboolean unpackUnmultiplyAlpha) |
| 4632 | { |
| 4633 | if (!context->getExtensions().copyTexture) |
| 4634 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4635 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4636 | return false; |
| 4637 | } |
| 4638 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4639 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4640 | if (source == nullptr) |
| 4641 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4642 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4643 | return false; |
| 4644 | } |
| 4645 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4646 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4647 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4648 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4649 | return false; |
| 4650 | } |
| 4651 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4652 | TextureType sourceType = source->getType(); |
| 4653 | ASSERT(sourceType != TextureType::CubeMap); |
| 4654 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4655 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4656 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4657 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4658 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4659 | return false; |
| 4660 | } |
| 4661 | |
| 4662 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4663 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4664 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4665 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4666 | return false; |
| 4667 | } |
| 4668 | |
| 4669 | if (x < 0 || y < 0) |
| 4670 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4671 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4672 | return false; |
| 4673 | } |
| 4674 | |
| 4675 | if (width < 0 || height < 0) |
| 4676 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4677 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4678 | return false; |
| 4679 | } |
| 4680 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4681 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4682 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4683 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4684 | context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4685 | return false; |
| 4686 | } |
| 4687 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4688 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4689 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4690 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4691 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4692 | return false; |
| 4693 | } |
| 4694 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4695 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4696 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4697 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4698 | return false; |
| 4699 | } |
| 4700 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4701 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4702 | if (dest == nullptr) |
| 4703 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4704 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4705 | return false; |
| 4706 | } |
| 4707 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4708 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4709 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4710 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4711 | return false; |
| 4712 | } |
| 4713 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4714 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4715 | true)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4716 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4717 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4718 | return false; |
| 4719 | } |
| 4720 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4721 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4722 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4723 | context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4724 | return false; |
| 4725 | } |
| 4726 | |
| 4727 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4728 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4729 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4730 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4731 | return false; |
| 4732 | } |
| 4733 | |
| 4734 | if (xoffset < 0 || yoffset < 0) |
| 4735 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4736 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4737 | return false; |
| 4738 | } |
| 4739 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4740 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4741 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4742 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4743 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4744 | return false; |
| 4745 | } |
| 4746 | |
| 4747 | return true; |
| 4748 | } |
| 4749 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 4750 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, TextureID sourceId, TextureID destId) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4751 | { |
| 4752 | if (!context->getExtensions().copyCompressedTexture) |
| 4753 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4754 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4755 | return false; |
| 4756 | } |
| 4757 | |
| 4758 | const gl::Texture *source = context->getTexture(sourceId); |
| 4759 | if (source == nullptr) |
| 4760 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4761 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4762 | return false; |
| 4763 | } |
| 4764 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4765 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4766 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4767 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4768 | return false; |
| 4769 | } |
| 4770 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4771 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4772 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4773 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4774 | context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4775 | return false; |
| 4776 | } |
| 4777 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4778 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4779 | if (!sourceFormat.info->compressed) |
| 4780 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4781 | context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4782 | return false; |
| 4783 | } |
| 4784 | |
| 4785 | const gl::Texture *dest = context->getTexture(destId); |
| 4786 | if (dest == nullptr) |
| 4787 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4788 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4789 | return false; |
| 4790 | } |
| 4791 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4792 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4793 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4794 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4795 | return false; |
| 4796 | } |
| 4797 | |
| 4798 | if (dest->getImmutableFormat()) |
| 4799 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4800 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4801 | return false; |
| 4802 | } |
| 4803 | |
| 4804 | return true; |
| 4805 | } |
| 4806 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4807 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4808 | { |
| 4809 | switch (type) |
| 4810 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4811 | case ShaderType::Vertex: |
| 4812 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4813 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4814 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4815 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4816 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4817 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4818 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4819 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4820 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4821 | break; |
| 4822 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4823 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4824 | if (!context->getExtensions().geometryShader) |
| 4825 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4826 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4827 | return false; |
| 4828 | } |
| 4829 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4830 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4831 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4832 | return false; |
| 4833 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4834 | |
| 4835 | return true; |
| 4836 | } |
| 4837 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4838 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4839 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4840 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4841 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4842 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4843 | { |
| 4844 | if (size < 0) |
| 4845 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4846 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4847 | return false; |
| 4848 | } |
| 4849 | |
| 4850 | switch (usage) |
| 4851 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4852 | case BufferUsage::StreamDraw: |
| 4853 | case BufferUsage::StaticDraw: |
| 4854 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4855 | break; |
| 4856 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4857 | case BufferUsage::StreamRead: |
| 4858 | case BufferUsage::StaticRead: |
| 4859 | case BufferUsage::DynamicRead: |
| 4860 | case BufferUsage::StreamCopy: |
| 4861 | case BufferUsage::StaticCopy: |
| 4862 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4863 | if (context->getClientMajorVersion() < 3) |
| 4864 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4865 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4866 | return false; |
| 4867 | } |
| 4868 | break; |
| 4869 | |
| 4870 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4871 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4872 | return false; |
| 4873 | } |
| 4874 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4875 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4876 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4877 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4878 | return false; |
| 4879 | } |
| 4880 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4881 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4882 | |
| 4883 | if (!buffer) |
| 4884 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4885 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4886 | return false; |
| 4887 | } |
| 4888 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4889 | if (context->getExtensions().webglCompatibility && |
| 4890 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4891 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4892 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4893 | return false; |
| 4894 | } |
| 4895 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4896 | return true; |
| 4897 | } |
| 4898 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4899 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4900 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4901 | GLintptr offset, |
| 4902 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4903 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4904 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4905 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4906 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4907 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4908 | return false; |
| 4909 | } |
| 4910 | |
| 4911 | if (offset < 0) |
| 4912 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4913 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4914 | return false; |
| 4915 | } |
| 4916 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4917 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4918 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4919 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4920 | return false; |
| 4921 | } |
| 4922 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4923 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4924 | |
| 4925 | if (!buffer) |
| 4926 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4927 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4928 | return false; |
| 4929 | } |
| 4930 | |
| 4931 | if (buffer->isMapped()) |
| 4932 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4933 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4934 | return false; |
| 4935 | } |
| 4936 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4937 | if (context->getExtensions().webglCompatibility && |
| 4938 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4939 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4940 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4941 | return false; |
| 4942 | } |
| 4943 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4944 | // Check for possible overflow of size + offset |
| 4945 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4946 | checkedSize += offset; |
| 4947 | if (!checkedSize.IsValid()) |
| 4948 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4949 | context->validationError(GL_INVALID_VALUE, kParamOverflow); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4950 | return false; |
| 4951 | } |
| 4952 | |
| 4953 | if (size + offset > buffer->getSize()) |
| 4954 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4955 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4956 | return false; |
| 4957 | } |
| 4958 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4959 | return true; |
| 4960 | } |
| 4961 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4962 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4963 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4964 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4965 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4966 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4967 | return false; |
| 4968 | } |
| 4969 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4970 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4971 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4972 | context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4973 | return false; |
| 4974 | } |
| 4975 | |
| 4976 | return true; |
| 4977 | } |
| 4978 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4979 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4980 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4981 | if (context->getClientMajorVersion() < 2) |
| 4982 | { |
| 4983 | return ValidateMultitextureUnit(context, texture); |
| 4984 | } |
| 4985 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4986 | if (texture < GL_TEXTURE0 || |
| 4987 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4988 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4989 | context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4990 | return false; |
| 4991 | } |
| 4992 | |
| 4993 | return true; |
| 4994 | } |
| 4995 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 4996 | bool ValidateAttachShader(Context *context, ShaderProgramID program, ShaderProgramID shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4997 | { |
| 4998 | Program *programObject = GetValidProgram(context, program); |
| 4999 | if (!programObject) |
| 5000 | { |
| 5001 | return false; |
| 5002 | } |
| 5003 | |
| 5004 | Shader *shaderObject = GetValidShader(context, shader); |
| 5005 | if (!shaderObject) |
| 5006 | { |
| 5007 | return false; |
| 5008 | } |
| 5009 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 5010 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 5011 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5012 | context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 5013 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | return true; |
| 5017 | } |
| 5018 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5019 | bool ValidateBindAttribLocation(Context *context, |
| 5020 | ShaderProgramID program, |
| 5021 | GLuint index, |
| 5022 | const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5023 | { |
| 5024 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5025 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5026 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5027 | return false; |
| 5028 | } |
| 5029 | |
| 5030 | if (strncmp(name, "gl_", 3) == 0) |
| 5031 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5032 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5033 | return false; |
| 5034 | } |
| 5035 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 5036 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5037 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 5038 | const size_t length = strlen(name); |
| 5039 | |
| 5040 | if (!IsValidESSLString(name, length)) |
| 5041 | { |
| 5042 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 5043 | // for shader-related entry points |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5044 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 5045 | return false; |
| 5046 | } |
| 5047 | |
| 5048 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 5049 | { |
| 5050 | return false; |
| 5051 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5052 | } |
| 5053 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5054 | return GetValidProgram(context, program) != nullptr; |
| 5055 | } |
| 5056 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 5057 | bool ValidateBindFramebuffer(Context *context, GLenum target, FramebufferID framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5058 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5059 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5060 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5061 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5062 | return false; |
| 5063 | } |
| 5064 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 5065 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5066 | !context->isFramebufferGenerated(framebuffer)) |
| 5067 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5068 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5069 | return false; |
| 5070 | } |
| 5071 | |
| 5072 | return true; |
| 5073 | } |
| 5074 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 5075 | bool ValidateBindRenderbuffer(Context *context, GLenum target, RenderbufferID renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5076 | { |
| 5077 | if (target != GL_RENDERBUFFER) |
| 5078 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5079 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5080 | return false; |
| 5081 | } |
| 5082 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 5083 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5084 | !context->isRenderbufferGenerated(renderbuffer)) |
| 5085 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5086 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 5087 | return false; |
| 5088 | } |
| 5089 | |
| 5090 | return true; |
| 5091 | } |
| 5092 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5093 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5094 | { |
| 5095 | switch (mode) |
| 5096 | { |
| 5097 | case GL_FUNC_ADD: |
| 5098 | case GL_FUNC_SUBTRACT: |
| 5099 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5100 | return true; |
| 5101 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5102 | case GL_MIN: |
| 5103 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5104 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5105 | |
| 5106 | default: |
| 5107 | return false; |
| 5108 | } |
| 5109 | } |
| 5110 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5111 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5112 | { |
| 5113 | return true; |
| 5114 | } |
| 5115 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5116 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5117 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5118 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5119 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5120 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5121 | return false; |
| 5122 | } |
| 5123 | |
| 5124 | return true; |
| 5125 | } |
| 5126 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5127 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5128 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5129 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5130 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5131 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5132 | return false; |
| 5133 | } |
| 5134 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 5135 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5136 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5137 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5138 | return false; |
| 5139 | } |
| 5140 | |
| 5141 | return true; |
| 5142 | } |
| 5143 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5144 | bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5145 | { |
| 5146 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 5147 | } |
| 5148 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5149 | bool ValidateBlendFuncSeparate(Context *context, |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5150 | GLenum srcRGB, |
| 5151 | GLenum dstRGB, |
| 5152 | GLenum srcAlpha, |
| 5153 | GLenum dstAlpha) |
| 5154 | { |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5155 | if (!ValidSrcBlendFunc(context, srcRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5156 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5157 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5158 | return false; |
| 5159 | } |
| 5160 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5161 | if (!ValidDstBlendFunc(context, dstRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5162 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5163 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5164 | return false; |
| 5165 | } |
| 5166 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5167 | if (!ValidSrcBlendFunc(context, srcAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5168 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5169 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5170 | return false; |
| 5171 | } |
| 5172 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 5173 | if (!ValidDstBlendFunc(context, dstAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5174 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5175 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5176 | return false; |
| 5177 | } |
| 5178 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 5179 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 5180 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5181 | { |
| 5182 | bool constantColorUsed = |
| 5183 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 5184 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 5185 | |
| 5186 | bool constantAlphaUsed = |
| 5187 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 5188 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 5189 | |
| 5190 | if (constantColorUsed && constantAlphaUsed) |
| 5191 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 5192 | if (context->getExtensions().webglCompatibility) |
| 5193 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5194 | context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor); |
| 5195 | return false; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 5196 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5197 | |
| 5198 | WARN() << kConstantColorAlphaLimitation; |
| 5199 | context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 5200 | return false; |
| 5201 | } |
| 5202 | } |
| 5203 | |
| 5204 | return true; |
| 5205 | } |
| 5206 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 5207 | bool ValidateGetString(Context *context, GLenum name) |
| 5208 | { |
| 5209 | switch (name) |
| 5210 | { |
| 5211 | case GL_VENDOR: |
| 5212 | case GL_RENDERER: |
| 5213 | case GL_VERSION: |
| 5214 | case GL_SHADING_LANGUAGE_VERSION: |
| 5215 | case GL_EXTENSIONS: |
| 5216 | break; |
| 5217 | |
| 5218 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 5219 | if (!context->getExtensions().requestExtension) |
| 5220 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5221 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 5222 | return false; |
| 5223 | } |
| 5224 | break; |
| 5225 | |
| 5226 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5227 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 5228 | return false; |
| 5229 | } |
| 5230 | |
| 5231 | return true; |
| 5232 | } |
| 5233 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5234 | bool ValidateLineWidth(Context *context, GLfloat width) |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 5235 | { |
| 5236 | if (width <= 0.0f || isNaN(width)) |
| 5237 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5238 | context->validationError(GL_INVALID_VALUE, kInvalidWidth); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 5239 | return false; |
| 5240 | } |
| 5241 | |
| 5242 | return true; |
| 5243 | } |
| 5244 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5245 | bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 5246 | { |
| 5247 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 5248 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5249 | context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 5250 | return false; |
| 5251 | } |
| 5252 | |
| 5253 | return true; |
| 5254 | } |
| 5255 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5256 | bool ValidateRenderbufferStorage(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5257 | GLenum target, |
| 5258 | GLenum internalformat, |
| 5259 | GLsizei width, |
| 5260 | GLsizei height) |
| 5261 | { |
| 5262 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 5263 | height); |
| 5264 | } |
| 5265 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5266 | bool ValidateRenderbufferStorageMultisampleANGLE(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5267 | GLenum target, |
| 5268 | GLsizei samples, |
| 5269 | GLenum internalformat, |
| 5270 | GLsizei width, |
| 5271 | GLsizei height) |
| 5272 | { |
| 5273 | if (!context->getExtensions().framebufferMultisample) |
| 5274 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5275 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5276 | return false; |
| 5277 | } |
| 5278 | |
| 5279 | // 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] | 5280 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5281 | // generated. |
| 5282 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 5283 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5284 | context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5285 | return false; |
| 5286 | } |
| 5287 | |
| 5288 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 5289 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 5290 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 5291 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 5292 | if (context->getClientMajorVersion() >= 3) |
| 5293 | { |
| 5294 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 5295 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 5296 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5297 | context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5298 | return false; |
| 5299 | } |
| 5300 | } |
| 5301 | |
| 5302 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 5303 | width, height); |
| 5304 | } |
| 5305 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5306 | bool ValidateCheckFramebufferStatus(Context *context, GLenum target) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5307 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5308 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5309 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5310 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5311 | return false; |
| 5312 | } |
| 5313 | |
| 5314 | return true; |
| 5315 | } |
| 5316 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5317 | bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5318 | { |
| 5319 | return true; |
| 5320 | } |
| 5321 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5322 | bool ValidateClearDepthf(Context *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5323 | { |
| 5324 | return true; |
| 5325 | } |
| 5326 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5327 | bool ValidateClearStencil(Context *context, GLint s) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5328 | { |
| 5329 | return true; |
| 5330 | } |
| 5331 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5332 | bool ValidateColorMask(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5333 | GLboolean red, |
| 5334 | GLboolean green, |
| 5335 | GLboolean blue, |
| 5336 | GLboolean alpha) |
| 5337 | { |
| 5338 | return true; |
| 5339 | } |
| 5340 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5341 | bool ValidateCompileShader(Context *context, ShaderProgramID shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5342 | { |
| 5343 | return true; |
| 5344 | } |
| 5345 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5346 | bool ValidateCreateProgram(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5347 | { |
| 5348 | return true; |
| 5349 | } |
| 5350 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5351 | bool ValidateCullFace(Context *context, CullFaceMode mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5352 | { |
| 5353 | switch (mode) |
| 5354 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 5355 | case CullFaceMode::Front: |
| 5356 | case CullFaceMode::Back: |
| 5357 | case CullFaceMode::FrontAndBack: |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5358 | break; |
| 5359 | |
| 5360 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5361 | context->validationError(GL_INVALID_ENUM, kInvalidCullMode); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5362 | return false; |
| 5363 | } |
| 5364 | |
| 5365 | return true; |
| 5366 | } |
| 5367 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5368 | bool ValidateDeleteProgram(Context *context, ShaderProgramID program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5369 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5370 | if (program.value == 0) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5371 | { |
| 5372 | return false; |
| 5373 | } |
| 5374 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5375 | if (!context->getProgramResolveLink(program)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5376 | { |
| 5377 | if (context->getShader(program)) |
| 5378 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5379 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5380 | return false; |
| 5381 | } |
| 5382 | else |
| 5383 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5384 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5385 | return false; |
| 5386 | } |
| 5387 | } |
| 5388 | |
| 5389 | return true; |
| 5390 | } |
| 5391 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5392 | bool ValidateDeleteShader(Context *context, ShaderProgramID shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5393 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5394 | if (shader.value == 0) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5395 | { |
| 5396 | return false; |
| 5397 | } |
| 5398 | |
| 5399 | if (!context->getShader(shader)) |
| 5400 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5401 | if (context->getProgramResolveLink(shader)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5402 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5403 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5404 | return false; |
| 5405 | } |
| 5406 | else |
| 5407 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5408 | context->validationError(GL_INVALID_VALUE, kExpectedShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5409 | return false; |
| 5410 | } |
| 5411 | } |
| 5412 | |
| 5413 | return true; |
| 5414 | } |
| 5415 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5416 | bool ValidateDepthFunc(Context *context, GLenum func) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5417 | { |
| 5418 | switch (func) |
| 5419 | { |
| 5420 | case GL_NEVER: |
| 5421 | case GL_ALWAYS: |
| 5422 | case GL_LESS: |
| 5423 | case GL_LEQUAL: |
| 5424 | case GL_EQUAL: |
| 5425 | case GL_GREATER: |
| 5426 | case GL_GEQUAL: |
| 5427 | case GL_NOTEQUAL: |
| 5428 | break; |
| 5429 | |
| 5430 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5431 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5432 | return false; |
| 5433 | } |
| 5434 | |
| 5435 | return true; |
| 5436 | } |
| 5437 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5438 | bool ValidateDepthMask(Context *context, GLboolean flag) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5439 | { |
| 5440 | return true; |
| 5441 | } |
| 5442 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5443 | bool ValidateDetachShader(Context *context, ShaderProgramID program, ShaderProgramID shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5444 | { |
| 5445 | Program *programObject = GetValidProgram(context, program); |
| 5446 | if (!programObject) |
| 5447 | { |
| 5448 | return false; |
| 5449 | } |
| 5450 | |
| 5451 | Shader *shaderObject = GetValidShader(context, shader); |
| 5452 | if (!shaderObject) |
| 5453 | { |
| 5454 | return false; |
| 5455 | } |
| 5456 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 5457 | const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5458 | if (attachedShader != shaderObject) |
| 5459 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5460 | context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5461 | return false; |
| 5462 | } |
| 5463 | |
| 5464 | return true; |
| 5465 | } |
| 5466 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5467 | bool ValidateDisableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5468 | { |
| 5469 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5470 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5471 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5472 | return false; |
| 5473 | } |
| 5474 | |
| 5475 | return true; |
| 5476 | } |
| 5477 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5478 | bool ValidateEnableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5479 | { |
| 5480 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5481 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5482 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5483 | return false; |
| 5484 | } |
| 5485 | |
| 5486 | return true; |
| 5487 | } |
| 5488 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5489 | bool ValidateFinish(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5490 | { |
| 5491 | return true; |
| 5492 | } |
| 5493 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5494 | bool ValidateFlush(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5495 | { |
| 5496 | return true; |
| 5497 | } |
| 5498 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5499 | bool ValidateFrontFace(Context *context, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5500 | { |
| 5501 | switch (mode) |
| 5502 | { |
| 5503 | case GL_CW: |
| 5504 | case GL_CCW: |
| 5505 | break; |
| 5506 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5507 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5508 | return false; |
| 5509 | } |
| 5510 | |
| 5511 | return true; |
| 5512 | } |
| 5513 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5514 | bool ValidateGetActiveAttrib(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5515 | ShaderProgramID program, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5516 | GLuint index, |
| 5517 | GLsizei bufsize, |
| 5518 | GLsizei *length, |
| 5519 | GLint *size, |
| 5520 | GLenum *type, |
| 5521 | GLchar *name) |
| 5522 | { |
| 5523 | if (bufsize < 0) |
| 5524 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5525 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5526 | return false; |
| 5527 | } |
| 5528 | |
| 5529 | Program *programObject = GetValidProgram(context, program); |
| 5530 | |
| 5531 | if (!programObject) |
| 5532 | { |
| 5533 | return false; |
| 5534 | } |
| 5535 | |
| 5536 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 5537 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5538 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
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 ValidateGetActiveUniform(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5546 | ShaderProgramID program, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5547 | GLuint index, |
| 5548 | GLsizei bufsize, |
| 5549 | GLsizei *length, |
| 5550 | GLint *size, |
| 5551 | GLenum *type, |
| 5552 | GLchar *name) |
| 5553 | { |
| 5554 | if (bufsize < 0) |
| 5555 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5556 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5557 | return false; |
| 5558 | } |
| 5559 | |
| 5560 | Program *programObject = GetValidProgram(context, program); |
| 5561 | |
| 5562 | if (!programObject) |
| 5563 | { |
| 5564 | return false; |
| 5565 | } |
| 5566 | |
| 5567 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 5568 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5569 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5570 | return false; |
| 5571 | } |
| 5572 | |
| 5573 | return true; |
| 5574 | } |
| 5575 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5576 | bool ValidateGetAttachedShaders(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5577 | ShaderProgramID program, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5578 | GLsizei maxcount, |
| 5579 | GLsizei *count, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5580 | ShaderProgramID *shaders) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5581 | { |
| 5582 | if (maxcount < 0) |
| 5583 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5584 | context->validationError(GL_INVALID_VALUE, kNegativeMaxCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5585 | return false; |
| 5586 | } |
| 5587 | |
| 5588 | Program *programObject = GetValidProgram(context, program); |
| 5589 | |
| 5590 | if (!programObject) |
| 5591 | { |
| 5592 | return false; |
| 5593 | } |
| 5594 | |
| 5595 | return true; |
| 5596 | } |
| 5597 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5598 | bool ValidateGetAttribLocation(Context *context, ShaderProgramID program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5599 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5600 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5601 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5602 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5603 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5604 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5605 | return false; |
| 5606 | } |
| 5607 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5608 | Program *programObject = GetValidProgram(context, program); |
| 5609 | |
| 5610 | if (!programObject) |
| 5611 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5612 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5613 | return false; |
| 5614 | } |
| 5615 | |
| 5616 | if (!programObject->isLinked()) |
| 5617 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5618 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5619 | return false; |
| 5620 | } |
| 5621 | |
| 5622 | return true; |
| 5623 | } |
| 5624 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5625 | bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5626 | { |
| 5627 | GLenum nativeType; |
| 5628 | unsigned int numParams = 0; |
| 5629 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5630 | } |
| 5631 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5632 | bool ValidateGetError(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5633 | { |
| 5634 | return true; |
| 5635 | } |
| 5636 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5637 | bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5638 | { |
| 5639 | GLenum nativeType; |
| 5640 | unsigned int numParams = 0; |
| 5641 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5642 | } |
| 5643 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5644 | bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5645 | { |
| 5646 | GLenum nativeType; |
| 5647 | unsigned int numParams = 0; |
| 5648 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5649 | } |
| 5650 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5651 | bool ValidateGetProgramInfoLog(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5652 | ShaderProgramID program, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5653 | GLsizei bufsize, |
| 5654 | GLsizei *length, |
| 5655 | GLchar *infolog) |
| 5656 | { |
| 5657 | if (bufsize < 0) |
| 5658 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5659 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5660 | return false; |
| 5661 | } |
| 5662 | |
| 5663 | Program *programObject = GetValidProgram(context, program); |
| 5664 | if (!programObject) |
| 5665 | { |
| 5666 | return false; |
| 5667 | } |
| 5668 | |
| 5669 | return true; |
| 5670 | } |
| 5671 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5672 | bool ValidateGetShaderInfoLog(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5673 | ShaderProgramID shader, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5674 | GLsizei bufsize, |
| 5675 | GLsizei *length, |
| 5676 | GLchar *infolog) |
| 5677 | { |
| 5678 | if (bufsize < 0) |
| 5679 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5680 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5681 | return false; |
| 5682 | } |
| 5683 | |
| 5684 | Shader *shaderObject = GetValidShader(context, shader); |
| 5685 | if (!shaderObject) |
| 5686 | { |
| 5687 | return false; |
| 5688 | } |
| 5689 | |
| 5690 | return true; |
| 5691 | } |
| 5692 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5693 | bool ValidateGetShaderPrecisionFormat(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5694 | GLenum shadertype, |
| 5695 | GLenum precisiontype, |
| 5696 | GLint *range, |
| 5697 | GLint *precision) |
| 5698 | { |
| 5699 | switch (shadertype) |
| 5700 | { |
| 5701 | case GL_VERTEX_SHADER: |
| 5702 | case GL_FRAGMENT_SHADER: |
| 5703 | break; |
| 5704 | case GL_COMPUTE_SHADER: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5705 | context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5706 | return false; |
| 5707 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5708 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5709 | return false; |
| 5710 | } |
| 5711 | |
| 5712 | switch (precisiontype) |
| 5713 | { |
| 5714 | case GL_LOW_FLOAT: |
| 5715 | case GL_MEDIUM_FLOAT: |
| 5716 | case GL_HIGH_FLOAT: |
| 5717 | case GL_LOW_INT: |
| 5718 | case GL_MEDIUM_INT: |
| 5719 | case GL_HIGH_INT: |
| 5720 | break; |
| 5721 | |
| 5722 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5723 | context->validationError(GL_INVALID_ENUM, kInvalidPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5724 | return false; |
| 5725 | } |
| 5726 | |
| 5727 | return true; |
| 5728 | } |
| 5729 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5730 | bool ValidateGetShaderSource(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5731 | ShaderProgramID shader, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5732 | GLsizei bufsize, |
| 5733 | GLsizei *length, |
| 5734 | GLchar *source) |
| 5735 | { |
| 5736 | if (bufsize < 0) |
| 5737 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5738 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5739 | return false; |
| 5740 | } |
| 5741 | |
| 5742 | Shader *shaderObject = GetValidShader(context, shader); |
| 5743 | if (!shaderObject) |
| 5744 | { |
| 5745 | return false; |
| 5746 | } |
| 5747 | |
| 5748 | return true; |
| 5749 | } |
| 5750 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5751 | bool ValidateGetUniformLocation(Context *context, ShaderProgramID program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5752 | { |
| 5753 | if (strstr(name, "gl_") == name) |
| 5754 | { |
| 5755 | return false; |
| 5756 | } |
| 5757 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5758 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5759 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5760 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5761 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5762 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5763 | return false; |
| 5764 | } |
| 5765 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5766 | Program *programObject = GetValidProgram(context, program); |
| 5767 | |
| 5768 | if (!programObject) |
| 5769 | { |
| 5770 | return false; |
| 5771 | } |
| 5772 | |
| 5773 | if (!programObject->isLinked()) |
| 5774 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5775 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5776 | return false; |
| 5777 | } |
| 5778 | |
| 5779 | return true; |
| 5780 | } |
| 5781 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5782 | bool ValidateHint(Context *context, GLenum target, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5783 | { |
| 5784 | switch (mode) |
| 5785 | { |
| 5786 | case GL_FASTEST: |
| 5787 | case GL_NICEST: |
| 5788 | case GL_DONT_CARE: |
| 5789 | break; |
| 5790 | |
| 5791 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5792 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5793 | return false; |
| 5794 | } |
| 5795 | |
| 5796 | switch (target) |
| 5797 | { |
| 5798 | case GL_GENERATE_MIPMAP_HINT: |
| 5799 | break; |
| 5800 | |
Geoff Lang | e7bd218 | 2017-06-16 16:13:13 -0400 | [diff] [blame] | 5801 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: |
| 5802 | if (context->getClientVersion() < ES_3_0 && |
| 5803 | !context->getExtensions().standardDerivatives) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5804 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5805 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5806 | return false; |
| 5807 | } |
| 5808 | break; |
| 5809 | |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5810 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 5811 | case GL_POINT_SMOOTH_HINT: |
| 5812 | case GL_LINE_SMOOTH_HINT: |
| 5813 | case GL_FOG_HINT: |
| 5814 | if (context->getClientMajorVersion() >= 2) |
| 5815 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5816 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5817 | return false; |
| 5818 | } |
| 5819 | break; |
| 5820 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5821 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5822 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5823 | return false; |
| 5824 | } |
| 5825 | |
| 5826 | return true; |
| 5827 | } |
| 5828 | |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 5829 | bool ValidateIsBuffer(Context *context, BufferID buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5830 | { |
| 5831 | return true; |
| 5832 | } |
| 5833 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 5834 | bool ValidateIsFramebuffer(Context *context, FramebufferID framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5835 | { |
| 5836 | return true; |
| 5837 | } |
| 5838 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5839 | bool ValidateIsProgram(Context *context, ShaderProgramID program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5840 | { |
| 5841 | return true; |
| 5842 | } |
| 5843 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 5844 | bool ValidateIsRenderbuffer(Context *context, RenderbufferID renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5845 | { |
| 5846 | return true; |
| 5847 | } |
| 5848 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5849 | bool ValidateIsShader(Context *context, ShaderProgramID shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5850 | { |
| 5851 | return true; |
| 5852 | } |
| 5853 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 5854 | bool ValidateIsTexture(Context *context, TextureID texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5855 | { |
| 5856 | return true; |
| 5857 | } |
| 5858 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5859 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5860 | { |
| 5861 | if (context->getClientMajorVersion() < 3) |
| 5862 | { |
| 5863 | switch (pname) |
| 5864 | { |
| 5865 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5866 | case GL_UNPACK_SKIP_IMAGES: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5867 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5868 | return false; |
| 5869 | |
| 5870 | case GL_UNPACK_ROW_LENGTH: |
| 5871 | case GL_UNPACK_SKIP_ROWS: |
| 5872 | case GL_UNPACK_SKIP_PIXELS: |
| 5873 | if (!context->getExtensions().unpackSubimage) |
| 5874 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5875 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5876 | return false; |
| 5877 | } |
| 5878 | break; |
| 5879 | |
| 5880 | case GL_PACK_ROW_LENGTH: |
| 5881 | case GL_PACK_SKIP_ROWS: |
| 5882 | case GL_PACK_SKIP_PIXELS: |
| 5883 | if (!context->getExtensions().packSubimage) |
| 5884 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5885 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5886 | return false; |
| 5887 | } |
| 5888 | break; |
| 5889 | } |
| 5890 | } |
| 5891 | |
| 5892 | if (param < 0) |
| 5893 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5894 | context->validationError(GL_INVALID_VALUE, kNegativeParam); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5895 | return false; |
| 5896 | } |
| 5897 | |
| 5898 | switch (pname) |
| 5899 | { |
| 5900 | case GL_UNPACK_ALIGNMENT: |
| 5901 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5902 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5903 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5904 | return false; |
| 5905 | } |
| 5906 | break; |
| 5907 | |
| 5908 | case GL_PACK_ALIGNMENT: |
| 5909 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5910 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5911 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5912 | return false; |
| 5913 | } |
| 5914 | break; |
| 5915 | |
| 5916 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5917 | if (!context->getExtensions().packReverseRowOrder) |
| 5918 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5919 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5920 | } |
| 5921 | break; |
| 5922 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5923 | case GL_UNPACK_ROW_LENGTH: |
| 5924 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5925 | case GL_UNPACK_SKIP_IMAGES: |
| 5926 | case GL_UNPACK_SKIP_ROWS: |
| 5927 | case GL_UNPACK_SKIP_PIXELS: |
| 5928 | case GL_PACK_ROW_LENGTH: |
| 5929 | case GL_PACK_SKIP_ROWS: |
| 5930 | case GL_PACK_SKIP_PIXELS: |
| 5931 | break; |
| 5932 | |
| 5933 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5934 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5935 | return false; |
| 5936 | } |
| 5937 | |
| 5938 | return true; |
| 5939 | } |
| 5940 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5941 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5942 | { |
| 5943 | return true; |
| 5944 | } |
| 5945 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5946 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5947 | { |
| 5948 | return true; |
| 5949 | } |
| 5950 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5951 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5952 | { |
| 5953 | return true; |
| 5954 | } |
| 5955 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5956 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5957 | { |
| 5958 | if (width < 0 || height < 0) |
| 5959 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5960 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5961 | return false; |
| 5962 | } |
| 5963 | |
| 5964 | return true; |
| 5965 | } |
| 5966 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5967 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5968 | GLsizei n, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5969 | const ShaderProgramID *shaders, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5970 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5971 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5972 | GLsizei length) |
| 5973 | { |
| 5974 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5975 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5976 | shaderBinaryFormats.end()) |
| 5977 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5978 | context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5979 | return false; |
| 5980 | } |
| 5981 | |
| 5982 | return true; |
| 5983 | } |
| 5984 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5985 | bool ValidateShaderSource(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 5986 | ShaderProgramID shader, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5987 | GLsizei count, |
| 5988 | const GLchar *const *string, |
| 5989 | const GLint *length) |
| 5990 | { |
| 5991 | if (count < 0) |
| 5992 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5993 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5994 | return false; |
| 5995 | } |
| 5996 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5997 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5998 | // shader-related entry points |
| 5999 | if (context->getExtensions().webglCompatibility) |
| 6000 | { |
| 6001 | for (GLsizei i = 0; i < count; i++) |
| 6002 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 6003 | size_t len = |
| 6004 | (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] | 6005 | |
| 6006 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 6007 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 6008 | context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 6009 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6010 | context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 6011 | return false; |
| 6012 | } |
| 6013 | } |
| 6014 | } |
| 6015 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6016 | Shader *shaderObject = GetValidShader(context, shader); |
| 6017 | if (!shaderObject) |
| 6018 | { |
| 6019 | return false; |
| 6020 | } |
| 6021 | |
| 6022 | return true; |
| 6023 | } |
| 6024 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6025 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6026 | { |
| 6027 | if (!IsValidStencilFunc(func)) |
| 6028 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6029 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6030 | return false; |
| 6031 | } |
| 6032 | |
| 6033 | return true; |
| 6034 | } |
| 6035 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6036 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6037 | { |
| 6038 | if (!IsValidStencilFace(face)) |
| 6039 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6040 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6041 | return false; |
| 6042 | } |
| 6043 | |
| 6044 | if (!IsValidStencilFunc(func)) |
| 6045 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6046 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6047 | return false; |
| 6048 | } |
| 6049 | |
| 6050 | return true; |
| 6051 | } |
| 6052 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6053 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6054 | { |
| 6055 | return true; |
| 6056 | } |
| 6057 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6058 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6059 | { |
| 6060 | if (!IsValidStencilFace(face)) |
| 6061 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6062 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6063 | return false; |
| 6064 | } |
| 6065 | |
| 6066 | return true; |
| 6067 | } |
| 6068 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6069 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6070 | { |
| 6071 | if (!IsValidStencilOp(fail)) |
| 6072 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6073 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6074 | return false; |
| 6075 | } |
| 6076 | |
| 6077 | if (!IsValidStencilOp(zfail)) |
| 6078 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6079 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6080 | return false; |
| 6081 | } |
| 6082 | |
| 6083 | if (!IsValidStencilOp(zpass)) |
| 6084 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6085 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6086 | return false; |
| 6087 | } |
| 6088 | |
| 6089 | return true; |
| 6090 | } |
| 6091 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6092 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6093 | GLenum face, |
| 6094 | GLenum fail, |
| 6095 | GLenum zfail, |
| 6096 | GLenum zpass) |
| 6097 | { |
| 6098 | if (!IsValidStencilFace(face)) |
| 6099 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6100 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6101 | return false; |
| 6102 | } |
| 6103 | |
| 6104 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 6105 | } |
| 6106 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6107 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6108 | { |
| 6109 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 6110 | } |
| 6111 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6112 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6113 | { |
| 6114 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 6115 | } |
| 6116 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6117 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6118 | { |
| 6119 | return ValidateUniform1iv(context, location, 1, &x); |
| 6120 | } |
| 6121 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6122 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6123 | { |
| 6124 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 6125 | } |
| 6126 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6127 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6128 | { |
| 6129 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 6130 | } |
| 6131 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6132 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6133 | { |
| 6134 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 6135 | } |
| 6136 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6137 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6138 | { |
| 6139 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 6140 | } |
| 6141 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6142 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6143 | { |
| 6144 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 6145 | } |
| 6146 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6147 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6148 | { |
| 6149 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 6150 | } |
| 6151 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6152 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6153 | { |
| 6154 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 6155 | } |
| 6156 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6157 | 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] | 6158 | { |
| 6159 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 6160 | } |
| 6161 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6162 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6163 | { |
| 6164 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 6165 | } |
| 6166 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6167 | 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] | 6168 | { |
| 6169 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 6170 | } |
| 6171 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6172 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6173 | { |
| 6174 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 6175 | } |
| 6176 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6177 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6178 | GLint location, |
| 6179 | GLsizei count, |
| 6180 | GLboolean transpose, |
| 6181 | const GLfloat *value) |
| 6182 | { |
| 6183 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 6184 | } |
| 6185 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6186 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6187 | GLint location, |
| 6188 | GLsizei count, |
| 6189 | GLboolean transpose, |
| 6190 | const GLfloat *value) |
| 6191 | { |
| 6192 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 6193 | } |
| 6194 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6195 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6196 | GLint location, |
| 6197 | GLsizei count, |
| 6198 | GLboolean transpose, |
| 6199 | const GLfloat *value) |
| 6200 | { |
| 6201 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 6202 | } |
| 6203 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6204 | bool ValidateValidateProgram(Context *context, ShaderProgramID program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6205 | { |
| 6206 | Program *programObject = GetValidProgram(context, program); |
| 6207 | |
| 6208 | if (!programObject) |
| 6209 | { |
| 6210 | return false; |
| 6211 | } |
| 6212 | |
| 6213 | return true; |
| 6214 | } |
| 6215 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6216 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6217 | { |
| 6218 | return ValidateVertexAttribIndex(context, index); |
| 6219 | } |
| 6220 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6221 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6222 | { |
| 6223 | return ValidateVertexAttribIndex(context, index); |
| 6224 | } |
| 6225 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6226 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6227 | { |
| 6228 | return ValidateVertexAttribIndex(context, index); |
| 6229 | } |
| 6230 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6231 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6232 | { |
| 6233 | return ValidateVertexAttribIndex(context, index); |
| 6234 | } |
| 6235 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6236 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6237 | { |
| 6238 | return ValidateVertexAttribIndex(context, index); |
| 6239 | } |
| 6240 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6241 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6242 | { |
| 6243 | return ValidateVertexAttribIndex(context, index); |
| 6244 | } |
| 6245 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6246 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6247 | GLuint index, |
| 6248 | GLfloat x, |
| 6249 | GLfloat y, |
| 6250 | GLfloat z, |
| 6251 | GLfloat w) |
| 6252 | { |
| 6253 | return ValidateVertexAttribIndex(context, index); |
| 6254 | } |
| 6255 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6256 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6257 | { |
| 6258 | return ValidateVertexAttribIndex(context, index); |
| 6259 | } |
| 6260 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6261 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6262 | { |
| 6263 | if (width < 0 || height < 0) |
| 6264 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6265 | context->validationError(GL_INVALID_VALUE, kViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6266 | return false; |
| 6267 | } |
| 6268 | |
| 6269 | return true; |
| 6270 | } |
| 6271 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 6272 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6273 | GLenum target, |
| 6274 | GLenum attachment, |
| 6275 | GLenum pname, |
| 6276 | GLint *params) |
| 6277 | { |
| 6278 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 6279 | nullptr); |
| 6280 | } |
| 6281 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6282 | bool ValidateGetProgramiv(Context *context, ShaderProgramID program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6283 | { |
| 6284 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 6285 | } |
| 6286 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6287 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6288 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6289 | GLint level, |
| 6290 | GLenum internalformat, |
| 6291 | GLint x, |
| 6292 | GLint y, |
| 6293 | GLsizei width, |
| 6294 | GLsizei height, |
| 6295 | GLint border) |
| 6296 | { |
| 6297 | if (context->getClientMajorVersion() < 3) |
| 6298 | { |
| 6299 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 6300 | 0, x, y, width, height, border); |
| 6301 | } |
| 6302 | |
| 6303 | ASSERT(context->getClientMajorVersion() == 3); |
| 6304 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 6305 | 0, x, y, width, height, border); |
| 6306 | } |
| 6307 | |
| 6308 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6309 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6310 | GLint level, |
| 6311 | GLint xoffset, |
| 6312 | GLint yoffset, |
| 6313 | GLint x, |
| 6314 | GLint y, |
| 6315 | GLsizei width, |
| 6316 | GLsizei height) |
| 6317 | { |
| 6318 | if (context->getClientMajorVersion() < 3) |
| 6319 | { |
| 6320 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 6321 | yoffset, x, y, width, height, 0); |
| 6322 | } |
| 6323 | |
| 6324 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 6325 | yoffset, 0, x, y, width, height, 0); |
| 6326 | } |
| 6327 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6328 | bool ValidateCopyTexSubImage3DOES(Context *context, |
| 6329 | TextureTarget target, |
| 6330 | GLint level, |
| 6331 | GLint xoffset, |
| 6332 | GLint yoffset, |
| 6333 | GLint zoffset, |
| 6334 | GLint x, |
| 6335 | GLint y, |
| 6336 | GLsizei width, |
| 6337 | GLsizei height) |
| 6338 | { |
| 6339 | return ValidateCopyTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, x, y, width, |
| 6340 | height); |
| 6341 | } |
| 6342 | |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 6343 | bool ValidateDeleteBuffers(Context *context, GLint n, const BufferID *buffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6344 | { |
| 6345 | return ValidateGenOrDelete(context, n); |
| 6346 | } |
| 6347 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 6348 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const FramebufferID *framebuffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6349 | { |
| 6350 | return ValidateGenOrDelete(context, n); |
| 6351 | } |
| 6352 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 6353 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const RenderbufferID *renderbuffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6354 | { |
| 6355 | return ValidateGenOrDelete(context, n); |
| 6356 | } |
| 6357 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6358 | bool ValidateDeleteTextures(Context *context, GLint n, const TextureID *textures) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6359 | { |
| 6360 | return ValidateGenOrDelete(context, n); |
| 6361 | } |
| 6362 | |
| 6363 | bool ValidateDisable(Context *context, GLenum cap) |
| 6364 | { |
| 6365 | if (!ValidCap(context, cap, false)) |
| 6366 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6367 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6368 | return false; |
| 6369 | } |
| 6370 | |
| 6371 | return true; |
| 6372 | } |
| 6373 | |
| 6374 | bool ValidateEnable(Context *context, GLenum cap) |
| 6375 | { |
| 6376 | if (!ValidCap(context, cap, false)) |
| 6377 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6378 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6379 | return false; |
| 6380 | } |
| 6381 | |
| 6382 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 6383 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 6384 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6385 | context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6386 | |
| 6387 | // We also output an error message to the debugger window if tracing is active, so that |
| 6388 | // developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6389 | ERR() << kNoSampleAlphaToCoveragesLimitation; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6390 | return false; |
| 6391 | } |
| 6392 | |
| 6393 | return true; |
| 6394 | } |
| 6395 | |
| 6396 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 6397 | GLenum target, |
| 6398 | GLenum attachment, |
| 6399 | GLenum renderbuffertarget, |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 6400 | RenderbufferID renderbuffer) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6401 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 6402 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6403 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6404 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6405 | return false; |
| 6406 | } |
| 6407 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 6408 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer.value != 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6409 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6410 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6411 | return false; |
| 6412 | } |
| 6413 | |
| 6414 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 6415 | renderbuffertarget, renderbuffer); |
| 6416 | } |
| 6417 | |
| 6418 | bool ValidateFramebufferTexture2D(Context *context, |
| 6419 | GLenum target, |
| 6420 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6421 | TextureTarget textarget, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6422 | TextureID texture, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6423 | GLint level) |
| 6424 | { |
| 6425 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 6426 | // extension |
| 6427 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 6428 | level != 0) |
| 6429 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6430 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6431 | return false; |
| 6432 | } |
| 6433 | |
| 6434 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 6435 | { |
| 6436 | return false; |
| 6437 | } |
| 6438 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6439 | if (texture.value != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6440 | { |
| 6441 | gl::Texture *tex = context->getTexture(texture); |
| 6442 | ASSERT(tex); |
| 6443 | |
| 6444 | const gl::Caps &caps = context->getCaps(); |
| 6445 | |
| 6446 | switch (textarget) |
| 6447 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6448 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6449 | { |
| 6450 | if (level > gl::log2(caps.max2DTextureSize)) |
| 6451 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6452 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6453 | return false; |
| 6454 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6455 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6456 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6457 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6458 | return false; |
| 6459 | } |
| 6460 | } |
| 6461 | break; |
| 6462 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6463 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6464 | { |
| 6465 | if (level != 0) |
| 6466 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6467 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6468 | return false; |
| 6469 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6470 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6471 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6472 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6473 | return false; |
| 6474 | } |
| 6475 | } |
| 6476 | break; |
| 6477 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6478 | case TextureTarget::CubeMapNegativeX: |
| 6479 | case TextureTarget::CubeMapNegativeY: |
| 6480 | case TextureTarget::CubeMapNegativeZ: |
| 6481 | case TextureTarget::CubeMapPositiveX: |
| 6482 | case TextureTarget::CubeMapPositiveY: |
| 6483 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6484 | { |
| 6485 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 6486 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6487 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6488 | return false; |
| 6489 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6490 | if (tex->getType() != TextureType::CubeMap) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6491 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6492 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6493 | return false; |
| 6494 | } |
| 6495 | } |
| 6496 | break; |
| 6497 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6498 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6499 | { |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6500 | if (context->getClientVersion() < ES_3_1 && |
| 6501 | !context->getExtensions().textureMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6502 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6503 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6504 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6505 | return false; |
| 6506 | } |
| 6507 | |
| 6508 | if (level != 0) |
| 6509 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6510 | context->validationError(GL_INVALID_VALUE, kLevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6511 | return false; |
| 6512 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6513 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6514 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6515 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6516 | return false; |
| 6517 | } |
| 6518 | } |
| 6519 | break; |
| 6520 | |
| 6521 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6522 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6523 | return false; |
| 6524 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6525 | } |
| 6526 | |
| 6527 | return true; |
| 6528 | } |
| 6529 | |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6530 | bool ValidateFramebufferTexture3DOES(Context *context, |
| 6531 | GLenum target, |
| 6532 | GLenum attachment, |
| 6533 | TextureTarget textargetPacked, |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6534 | TextureID texture, |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6535 | GLint level, |
| 6536 | GLint zoffset) |
| 6537 | { |
Cody Northrop | 90958e3 | 2019-08-07 16:26:14 -0600 | [diff] [blame] | 6538 | // We don't call into a base ValidateFramebufferTexture3D here because |
| 6539 | // it doesn't exist for OpenGL ES. This function is replaced by |
| 6540 | // FramebufferTextureLayer in ES 3.x, which has broader support. |
| 6541 | if (!context->getExtensions().texture3DOES) |
| 6542 | { |
| 6543 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 6544 | return false; |
| 6545 | } |
| 6546 | |
| 6547 | // Attachments are required to be bound to level 0 without ES3 or the |
| 6548 | // GL_OES_fbo_render_mipmap extension |
| 6549 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 6550 | level != 0) |
| 6551 | { |
| 6552 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel); |
| 6553 | return false; |
| 6554 | } |
| 6555 | |
| 6556 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 6557 | { |
| 6558 | return false; |
| 6559 | } |
| 6560 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6561 | if (texture.value != 0) |
Cody Northrop | 90958e3 | 2019-08-07 16:26:14 -0600 | [diff] [blame] | 6562 | { |
| 6563 | gl::Texture *tex = context->getTexture(texture); |
| 6564 | ASSERT(tex); |
| 6565 | |
| 6566 | const gl::Caps &caps = context->getCaps(); |
| 6567 | |
| 6568 | switch (textargetPacked) |
| 6569 | { |
| 6570 | case TextureTarget::_3D: |
| 6571 | { |
| 6572 | if (level > gl::log2(caps.max3DTextureSize)) |
| 6573 | { |
| 6574 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
| 6575 | return false; |
| 6576 | } |
| 6577 | if (static_cast<size_t>(zoffset) >= caps.max3DTextureSize) |
| 6578 | { |
| 6579 | context->validationError(GL_INVALID_VALUE, kInvalidZOffset); |
| 6580 | return false; |
| 6581 | } |
| 6582 | if (tex->getType() != TextureType::_3D) |
| 6583 | { |
| 6584 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureType); |
| 6585 | return false; |
| 6586 | } |
| 6587 | } |
| 6588 | break; |
| 6589 | |
| 6590 | default: |
| 6591 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
| 6592 | return false; |
| 6593 | } |
| 6594 | } |
| 6595 | |
| 6596 | return true; |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 6597 | } |
| 6598 | |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 6599 | bool ValidateGenBuffers(Context *context, GLint n, BufferID *buffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6600 | { |
| 6601 | return ValidateGenOrDelete(context, n); |
| 6602 | } |
| 6603 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 6604 | bool ValidateGenFramebuffers(Context *context, GLint n, FramebufferID *framebuffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6605 | { |
| 6606 | return ValidateGenOrDelete(context, n); |
| 6607 | } |
| 6608 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 6609 | bool ValidateGenRenderbuffers(Context *context, GLint n, RenderbufferID *renderbuffers) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6610 | { |
| 6611 | return ValidateGenOrDelete(context, n); |
| 6612 | } |
| 6613 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 6614 | bool ValidateGenTextures(Context *context, GLint n, TextureID *textures) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6615 | { |
| 6616 | return ValidateGenOrDelete(context, n); |
| 6617 | } |
| 6618 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6619 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6620 | { |
| 6621 | if (!ValidTextureTarget(context, target)) |
| 6622 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6623 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6624 | return false; |
| 6625 | } |
| 6626 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 6627 | Texture *texture = context->getTextureByType(target); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6628 | |
| 6629 | if (texture == nullptr) |
| 6630 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6631 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6632 | return false; |
| 6633 | } |
| 6634 | |
| 6635 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 6636 | |
| 6637 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 6638 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 6639 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 6640 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6641 | context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6642 | return false; |
| 6643 | } |
| 6644 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6645 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 6646 | ? TextureTarget::CubeMapPositiveX |
| 6647 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6648 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 6649 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 6650 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6651 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6652 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6653 | return false; |
| 6654 | } |
| 6655 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6656 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 6657 | bool formatUnsized = !format.sized; |
| 6658 | bool formatColorRenderableAndFilterable = |
| 6659 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6660 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6661 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6662 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6663 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6664 | return false; |
| 6665 | } |
| 6666 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6667 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 6668 | // generation |
| 6669 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 6670 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6671 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6672 | return false; |
| 6673 | } |
| 6674 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 6675 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 6676 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 6677 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6678 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6679 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6680 | return false; |
| 6681 | } |
| 6682 | |
| 6683 | // Non-power of 2 ES2 check |
| 6684 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 6685 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 6686 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 6687 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6688 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 6689 | target == TextureType::CubeMap); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6690 | context->validationError(GL_INVALID_OPERATION, kTextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6691 | return false; |
| 6692 | } |
| 6693 | |
| 6694 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6695 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6696 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6697 | context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6698 | return false; |
| 6699 | } |
| 6700 | |
James Darpinian | 83b2f0e | 2018-11-27 15:56:01 -0800 | [diff] [blame] | 6701 | if (context->getExtensions().webglCompatibility && |
| 6702 | (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 || |
| 6703 | texture->getHeight(baseTarget, effectiveBaseLevel) == 0)) |
| 6704 | { |
| 6705 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize); |
| 6706 | return false; |
| 6707 | } |
| 6708 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6709 | return true; |
| 6710 | } |
| 6711 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6712 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 6713 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6714 | GLenum pname, |
| 6715 | GLint *params) |
| 6716 | { |
| 6717 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 6718 | } |
| 6719 | |
| 6720 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6721 | GLenum target, |
| 6722 | GLenum pname, |
| 6723 | GLint *params) |
| 6724 | { |
| 6725 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6726 | } |
| 6727 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6728 | bool ValidateGetShaderiv(Context *context, ShaderProgramID shader, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6729 | { |
| 6730 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6731 | } |
| 6732 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6733 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6734 | { |
| 6735 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6736 | } |
| 6737 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6738 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6739 | { |
| 6740 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6741 | } |
| 6742 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6743 | bool ValidateGetTexParameterIivOES(Context *context, |
| 6744 | TextureType target, |
| 6745 | GLenum pname, |
| 6746 | GLint *params) |
| 6747 | { |
| 6748 | if (context->getClientMajorVersion() < 3) |
| 6749 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6750 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6751 | return false; |
| 6752 | } |
| 6753 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6754 | } |
| 6755 | |
| 6756 | bool ValidateGetTexParameterIuivOES(Context *context, |
| 6757 | TextureType target, |
| 6758 | GLenum pname, |
| 6759 | GLuint *params) |
| 6760 | { |
| 6761 | if (context->getClientMajorVersion() < 3) |
| 6762 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6763 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6764 | return false; |
| 6765 | } |
| 6766 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6767 | } |
| 6768 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6769 | bool ValidateGetUniformfv(Context *context, |
| 6770 | ShaderProgramID program, |
| 6771 | GLint location, |
| 6772 | GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6773 | { |
| 6774 | return ValidateGetUniformBase(context, program, location); |
| 6775 | } |
| 6776 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6777 | bool ValidateGetUniformiv(Context *context, ShaderProgramID program, GLint location, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6778 | { |
| 6779 | return ValidateGetUniformBase(context, program, location); |
| 6780 | } |
| 6781 | |
| 6782 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6783 | { |
| 6784 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6785 | } |
| 6786 | |
| 6787 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6788 | { |
| 6789 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6790 | } |
| 6791 | |
| 6792 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6793 | { |
| 6794 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6795 | } |
| 6796 | |
| 6797 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6798 | { |
| 6799 | if (!ValidCap(context, cap, true)) |
| 6800 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6801 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6802 | return false; |
| 6803 | } |
| 6804 | |
| 6805 | return true; |
| 6806 | } |
| 6807 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6808 | bool ValidateLinkProgram(Context *context, ShaderProgramID program) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6809 | { |
| 6810 | if (context->hasActiveTransformFeedback(program)) |
| 6811 | { |
| 6812 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6813 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6814 | return false; |
| 6815 | } |
| 6816 | |
| 6817 | Program *programObject = GetValidProgram(context, program); |
| 6818 | if (!programObject) |
| 6819 | { |
| 6820 | return false; |
| 6821 | } |
| 6822 | |
| 6823 | return true; |
| 6824 | } |
| 6825 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6826 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6827 | GLint x, |
| 6828 | GLint y, |
| 6829 | GLsizei width, |
| 6830 | GLsizei height, |
| 6831 | GLenum format, |
| 6832 | GLenum type, |
| 6833 | void *pixels) |
| 6834 | { |
| 6835 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6836 | nullptr, pixels); |
| 6837 | } |
| 6838 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6839 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6840 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6841 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6842 | } |
| 6843 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6844 | bool ValidateTexParameterfv(Context *context, |
| 6845 | TextureType target, |
| 6846 | GLenum pname, |
| 6847 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6848 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6849 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6850 | } |
| 6851 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6852 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6853 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6854 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6855 | } |
| 6856 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6857 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6858 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6859 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6860 | } |
| 6861 | |
| 6862 | bool ValidateTexParameterIivOES(Context *context, |
| 6863 | TextureType target, |
| 6864 | GLenum pname, |
| 6865 | const GLint *params) |
| 6866 | { |
| 6867 | if (context->getClientMajorVersion() < 3) |
| 6868 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6869 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6870 | return false; |
| 6871 | } |
| 6872 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6873 | } |
| 6874 | |
| 6875 | bool ValidateTexParameterIuivOES(Context *context, |
| 6876 | TextureType target, |
| 6877 | GLenum pname, |
| 6878 | const GLuint *params) |
| 6879 | { |
| 6880 | if (context->getClientMajorVersion() < 3) |
| 6881 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6882 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6883 | return false; |
| 6884 | } |
| 6885 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6886 | } |
| 6887 | |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6888 | bool ValidateUseProgram(Context *context, ShaderProgramID program) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6889 | { |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 6890 | if (program.value != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6891 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 6892 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6893 | if (!programObject) |
| 6894 | { |
| 6895 | // ES 3.1.0 section 7.3 page 72 |
| 6896 | if (context->getShader(program)) |
| 6897 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6898 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6899 | return false; |
| 6900 | } |
| 6901 | else |
| 6902 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6903 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6904 | return false; |
| 6905 | } |
| 6906 | } |
| 6907 | if (!programObject->isLinked()) |
| 6908 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6909 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6910 | return false; |
| 6911 | } |
| 6912 | } |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 6913 | if (context->getState().isTransformFeedbackActiveUnpaused()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6914 | { |
| 6915 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6916 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6917 | return false; |
| 6918 | } |
| 6919 | |
| 6920 | return true; |
| 6921 | } |
| 6922 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6923 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const FenceNVID *fences) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6924 | { |
| 6925 | if (!context->getExtensions().fence) |
| 6926 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6927 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6928 | return false; |
| 6929 | } |
| 6930 | |
| 6931 | if (n < 0) |
| 6932 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6933 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6934 | return false; |
| 6935 | } |
| 6936 | |
| 6937 | return true; |
| 6938 | } |
| 6939 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6940 | bool ValidateFinishFenceNV(Context *context, FenceNVID fence) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6941 | { |
| 6942 | if (!context->getExtensions().fence) |
| 6943 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6944 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6945 | return false; |
| 6946 | } |
| 6947 | |
| 6948 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6949 | |
| 6950 | if (fenceObject == nullptr) |
| 6951 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6952 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6953 | return false; |
| 6954 | } |
| 6955 | |
| 6956 | if (!fenceObject->isSet()) |
| 6957 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6958 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6959 | return false; |
| 6960 | } |
| 6961 | |
| 6962 | return true; |
| 6963 | } |
| 6964 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6965 | bool ValidateGenFencesNV(Context *context, GLsizei n, FenceNVID *fences) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6966 | { |
| 6967 | if (!context->getExtensions().fence) |
| 6968 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6969 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6970 | return false; |
| 6971 | } |
| 6972 | |
| 6973 | if (n < 0) |
| 6974 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6975 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6976 | return false; |
| 6977 | } |
| 6978 | |
| 6979 | return true; |
| 6980 | } |
| 6981 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 6982 | bool ValidateGetFenceivNV(Context *context, FenceNVID fence, GLenum pname, GLint *params) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6983 | { |
| 6984 | if (!context->getExtensions().fence) |
| 6985 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6986 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6987 | return false; |
| 6988 | } |
| 6989 | |
| 6990 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6991 | |
| 6992 | if (fenceObject == nullptr) |
| 6993 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6994 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6995 | return false; |
| 6996 | } |
| 6997 | |
| 6998 | if (!fenceObject->isSet()) |
| 6999 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7000 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 7001 | return false; |
| 7002 | } |
| 7003 | |
| 7004 | switch (pname) |
| 7005 | { |
| 7006 | case GL_FENCE_STATUS_NV: |
| 7007 | case GL_FENCE_CONDITION_NV: |
| 7008 | break; |
| 7009 | |
| 7010 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7011 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 7012 | return false; |
| 7013 | } |
| 7014 | |
| 7015 | return true; |
| 7016 | } |
| 7017 | |
| 7018 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 7019 | { |
| 7020 | if (!context->getExtensions().robustness) |
| 7021 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7022 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 7023 | return false; |
| 7024 | } |
| 7025 | |
| 7026 | return true; |
| 7027 | } |
| 7028 | |
| 7029 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
Jiacheng Lu | 120b61d | 2019-08-21 12:51:58 -0600 | [diff] [blame] | 7030 | ShaderProgramID shader, |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 7031 | GLsizei bufsize, |
| 7032 | GLsizei *length, |
| 7033 | GLchar *source) |
| 7034 | { |
| 7035 | if (!context->getExtensions().translatedShaderSource) |
| 7036 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7037 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 7038 | return false; |
| 7039 | } |
| 7040 | |
| 7041 | if (bufsize < 0) |
| 7042 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7043 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 7044 | return false; |
| 7045 | } |
| 7046 | |
| 7047 | Shader *shaderObject = context->getShader(shader); |
| 7048 | |
| 7049 | if (!shaderObject) |
| 7050 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7051 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 7052 | return false; |
| 7053 | } |
| 7054 | |
| 7055 | return true; |
| 7056 | } |
| 7057 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 7058 | bool ValidateIsFenceNV(Context *context, FenceNVID fence) |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 7059 | { |
| 7060 | if (!context->getExtensions().fence) |
| 7061 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7062 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 7063 | return false; |
| 7064 | } |
| 7065 | |
| 7066 | return true; |
| 7067 | } |
| 7068 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 7069 | bool ValidateSetFenceNV(Context *context, FenceNVID fence, GLenum condition) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7070 | { |
| 7071 | if (!context->getExtensions().fence) |
| 7072 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7073 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7074 | return false; |
| 7075 | } |
| 7076 | |
| 7077 | if (condition != GL_ALL_COMPLETED_NV) |
| 7078 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7079 | context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7080 | return false; |
| 7081 | } |
| 7082 | |
| 7083 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 7084 | |
| 7085 | if (fenceObject == nullptr) |
| 7086 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7087 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7088 | return false; |
| 7089 | } |
| 7090 | |
| 7091 | return true; |
| 7092 | } |
| 7093 | |
Jiacheng Lu | 962503e | 2019-08-21 13:18:30 -0600 | [diff] [blame] | 7094 | bool ValidateTestFenceNV(Context *context, FenceNVID fence) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7095 | { |
| 7096 | if (!context->getExtensions().fence) |
| 7097 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7098 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7099 | return false; |
| 7100 | } |
| 7101 | |
| 7102 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 7103 | |
| 7104 | if (fenceObject == nullptr) |
| 7105 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7106 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7107 | return false; |
| 7108 | } |
| 7109 | |
| 7110 | if (fenceObject->isSet() != GL_TRUE) |
| 7111 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7112 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7113 | return false; |
| 7114 | } |
| 7115 | |
| 7116 | return true; |
| 7117 | } |
| 7118 | |
| 7119 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 7120 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7121 | GLsizei levels, |
| 7122 | GLenum internalformat, |
| 7123 | GLsizei width, |
| 7124 | GLsizei height) |
| 7125 | { |
| 7126 | if (!context->getExtensions().textureStorage) |
| 7127 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7128 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7129 | return false; |
| 7130 | } |
| 7131 | |
| 7132 | if (context->getClientMajorVersion() < 3) |
| 7133 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 7134 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7135 | height); |
| 7136 | } |
| 7137 | |
| 7138 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 7139 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7140 | 1); |
| 7141 | } |
| 7142 | |
| 7143 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 7144 | { |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 7145 | if (!context->getExtensions().instancedArraysANGLE) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7146 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7147 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7148 | return false; |
| 7149 | } |
| 7150 | |
| 7151 | if (index >= MAX_VERTEX_ATTRIBS) |
| 7152 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7153 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7154 | return false; |
| 7155 | } |
| 7156 | |
| 7157 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 7158 | { |
| 7159 | if (index == 0 && divisor != 0) |
| 7160 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 7161 | context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7162 | |
| 7163 | // We also output an error message to the debugger window if tracing is active, so |
| 7164 | // that developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 7165 | ERR() << kAttributeZeroRequiresDivisorLimitation; |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7166 | return false; |
| 7167 | } |
| 7168 | } |
| 7169 | |
| 7170 | return true; |
| 7171 | } |
| 7172 | |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 7173 | bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor) |
| 7174 | { |
| 7175 | if (!context->getExtensions().instancedArraysEXT) |
| 7176 | { |
| 7177 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 7178 | return false; |
| 7179 | } |
| 7180 | |
| 7181 | if (index >= MAX_VERTEX_ATTRIBS) |
| 7182 | { |
| 7183 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
| 7184 | return false; |
| 7185 | } |
| 7186 | |
| 7187 | return true; |
| 7188 | } |
| 7189 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7190 | bool ValidateTexImage3DOES(Context *context, |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 7191 | TextureTarget target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7192 | GLint level, |
| 7193 | GLenum internalformat, |
| 7194 | GLsizei width, |
| 7195 | GLsizei height, |
| 7196 | GLsizei depth, |
| 7197 | GLint border, |
| 7198 | GLenum format, |
| 7199 | GLenum type, |
| 7200 | const void *pixels) |
| 7201 | { |
Cody Northrop | 5faff91 | 2019-06-28 14:04:50 -0600 | [diff] [blame] | 7202 | return ValidateTexImage3D(context, target, level, internalformat, width, height, depth, border, |
| 7203 | format, type, pixels); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7204 | } |
| 7205 | |
| 7206 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 7207 | { |
| 7208 | if (!context->getExtensions().debugMarker) |
| 7209 | { |
| 7210 | // The debug marker calls should not set error state |
| 7211 | // 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] | 7212 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 7213 | return false; |
| 7214 | } |
| 7215 | |
| 7216 | return true; |
| 7217 | } |
| 7218 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7219 | bool ValidateTexStorage1DEXT(Context *context, |
| 7220 | GLenum target, |
| 7221 | GLsizei levels, |
| 7222 | GLenum internalformat, |
| 7223 | GLsizei width) |
| 7224 | { |
| 7225 | UNIMPLEMENTED(); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7226 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7227 | return false; |
| 7228 | } |
| 7229 | |
| 7230 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 7231 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7232 | GLsizei levels, |
| 7233 | GLenum internalformat, |
| 7234 | GLsizei width, |
| 7235 | GLsizei height, |
| 7236 | GLsizei depth) |
| 7237 | { |
| 7238 | if (!context->getExtensions().textureStorage) |
| 7239 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7240 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7241 | return false; |
| 7242 | } |
| 7243 | |
| 7244 | if (context->getClientMajorVersion() < 3) |
| 7245 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7246 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 7247 | return false; |
| 7248 | } |
| 7249 | |
| 7250 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 7251 | depth); |
| 7252 | } |
| 7253 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 7254 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 7255 | { |
| 7256 | if (!context->getExtensions().parallelShaderCompile) |
| 7257 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7258 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 7259 | return false; |
| 7260 | } |
| 7261 | return true; |
| 7262 | } |
| 7263 | |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7264 | bool ValidateMultiDrawArraysANGLE(Context *context, |
| 7265 | PrimitiveMode mode, |
| 7266 | const GLint *firsts, |
| 7267 | const GLsizei *counts, |
| 7268 | GLsizei drawcount) |
| 7269 | { |
| 7270 | if (!context->getExtensions().multiDraw) |
| 7271 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7272 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7273 | return false; |
| 7274 | } |
| 7275 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 7276 | { |
| 7277 | if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID])) |
| 7278 | { |
| 7279 | return false; |
| 7280 | } |
| 7281 | } |
| 7282 | return true; |
| 7283 | } |
| 7284 | |
| 7285 | bool ValidateMultiDrawElementsANGLE(Context *context, |
| 7286 | PrimitiveMode mode, |
| 7287 | const GLsizei *counts, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 7288 | DrawElementsType type, |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 7289 | const GLvoid *const *indices, |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7290 | GLsizei drawcount) |
| 7291 | { |
| 7292 | if (!context->getExtensions().multiDraw) |
| 7293 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 7294 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7295 | return false; |
| 7296 | } |
| 7297 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 7298 | { |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 7299 | if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID])) |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 7300 | { |
| 7301 | return false; |
| 7302 | } |
| 7303 | } |
| 7304 | return true; |
| 7305 | } |
| 7306 | |
Clemen Deng | ce33059 | 2019-07-16 10:02:21 -0400 | [diff] [blame] | 7307 | bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertexConvention modePacked) |
Jeff Gilbert | 465d609 | 2019-01-02 16:21:18 -0800 | [diff] [blame] | 7308 | { |
| 7309 | if (!context->getExtensions().provokingVertex) |
| 7310 | { |
| 7311 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 7312 | return false; |
| 7313 | } |
| 7314 | |
| 7315 | switch (modePacked) |
| 7316 | { |
Clemen Deng | ce33059 | 2019-07-16 10:02:21 -0400 | [diff] [blame] | 7317 | case ProvokingVertexConvention::FirstVertexConvention: |
| 7318 | case ProvokingVertexConvention::LastVertexConvention: |
Jeff Gilbert | 465d609 | 2019-01-02 16:21:18 -0800 | [diff] [blame] | 7319 | break; |
| 7320 | default: |
| 7321 | context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex); |
| 7322 | return false; |
| 7323 | } |
| 7324 | |
| 7325 | return true; |
| 7326 | } |
| 7327 | |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 7328 | bool ValidateFramebufferTexture2DMultisampleEXT(Context *context, |
| 7329 | GLenum target, |
| 7330 | GLenum attachment, |
| 7331 | GLenum textarget, |
| 7332 | GLuint texture, |
| 7333 | GLint level, |
| 7334 | GLsizei samples) |
| 7335 | { |
| 7336 | return true; |
| 7337 | } |
| 7338 | |
| 7339 | bool ValidateRenderbufferStorageMultisampleEXT(Context *context, |
| 7340 | GLenum target, |
| 7341 | GLsizei samples, |
| 7342 | GLenum internalformat, |
| 7343 | GLsizei width, |
| 7344 | GLsizei height) |
| 7345 | { |
| 7346 | return true; |
| 7347 | } |
| 7348 | |
Jamie Madill | a541048 | 2019-01-31 19:55:55 -0500 | [diff] [blame] | 7349 | void RecordBindTextureTypeError(Context *context, TextureType target) |
| 7350 | { |
| 7351 | ASSERT(!context->getStateCache().isValidBindTextureType(target)); |
| 7352 | |
| 7353 | switch (target) |
| 7354 | { |
| 7355 | case TextureType::Rectangle: |
| 7356 | ASSERT(!context->getExtensions().textureRectangle); |
| 7357 | context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported); |
| 7358 | break; |
| 7359 | |
| 7360 | case TextureType::_3D: |
| 7361 | case TextureType::_2DArray: |
| 7362 | ASSERT(context->getClientMajorVersion() < 3); |
| 7363 | context->validationError(GL_INVALID_ENUM, kES3Required); |
| 7364 | break; |
| 7365 | |
| 7366 | case TextureType::_2DMultisample: |
| 7367 | ASSERT(context->getClientVersion() < Version(3, 1) && |
| 7368 | !context->getExtensions().textureMultisample); |
| 7369 | context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required); |
| 7370 | break; |
| 7371 | |
| 7372 | case TextureType::_2DMultisampleArray: |
| 7373 | ASSERT(!context->getExtensions().textureStorageMultisample2DArray); |
| 7374 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
| 7375 | break; |
| 7376 | |
| 7377 | case TextureType::External: |
| 7378 | ASSERT(!context->getExtensions().eglImageExternal && |
| 7379 | !context->getExtensions().eglStreamConsumerExternal); |
| 7380 | context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported); |
| 7381 | break; |
| 7382 | |
| 7383 | default: |
| 7384 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
| 7385 | } |
| 7386 | } |
| 7387 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 7388 | } // namespace gl |